Skip to content
Snippets Groups Projects
Commit 0b96d149 authored by Mathias Paulin's avatar Mathias Paulin :speech_balloon:
Browse files

small improvement in the simpleViewer

parent 4db71905
Branches
No related tags found
No related merge requests found
...@@ -182,55 +182,43 @@ void AddCustomAttributeToMeshes() { ...@@ -182,55 +182,43 @@ void AddCustomAttributeToMeshes() {
{ {
auto theMesh = ro->getMesh(); auto theMesh = ro->getMesh();
/* Could be helpfull if one can do auto displayMesh =
auto displayable = dynamic_cast<Ra::Engine::Data::CoreGeometryDisplayable< ??? dynamic_cast<Ra::Engine::Data::AttribArrayDisplayable*>( theMesh.get() );
>*>( theMesh.get() );
*/ LOG( logINFO ) << "\t\tMesh " << displayMesh->getName() << " is processed.";
auto displayMesh = dynamic_cast<Ra::Engine::Data::Mesh*>( theMesh.get() ); auto& coreMesh = displayMesh->getAttribArrayGeometry();
if ( displayMesh )
auto addAttrib = [&coreMesh, displayMesh]( const std::string& name,
auto value ) {
coreMesh.addAttrib<Ra::Core::Vector4>( "myCustomAttrib", value );
};
auto meshTypeHash = typeid( *( theMesh.get() ) ).hash_code();
if ( meshTypeHash == typeid( Ra::Engine::Data::Mesh ).hash_code() )
{ {
LOG( logINFO ) << "\t\tMesh " << displayMesh->getName() addAttrib( "myCustomAttrib",
<< " (TriangleMesh) is processed."; Ra::Core::Vector4Array{displayMesh->getNumVertices(),
displayMesh->addAttrib<Ra::Core::Vector4>( /*Ra::Core::Utils::Color::White()*/ {
"myCustomAttrib", 0.7_ra, 0.8_ra, 0.8_ra, 1_ra}} );
Ra::Core::Vector4Array{displayMesh->getNumVertices(), }
Ra::Core::Utils::Color::Yellow()} ); else if ( meshTypeHash == typeid( Ra::Engine::Data::PolyMesh ).hash_code() )
displayMesh->setDirty( "myCustomAttrib" ); {
addAttrib( "myCustomAttrib",
Ra::Core::Vector4Array{
displayMesh->getNumVertices(),
Ra::Core::Utils::Color{0.8_ra, 0.7_ra, 0.8_ra}} );
}
else if ( meshTypeHash == typeid( Ra::Engine::Data::PointCloud ).hash_code() )
{
addAttrib( "myCustomAttrib",
Ra::Core::Vector4Array{
displayMesh->getNumVertices(),
Ra::Core::Utils::Color{0.3_ra, 0.3_ra, 0.8_ra}} );
} }
else else
{ {
auto polyMesh = dynamic_cast<Ra::Engine::Data::PolyMesh*>( theMesh.get() ); LOG( logINFO ) << "\t\tMesh " << theMesh->getName()
if ( polyMesh ) << " is nor a trianglemesh, nor a polymesh, nor a "
{ "point cloud ... skipping";
LOG( logINFO ) << "\t\tMesh " << polyMesh->getName()
<< " (PolyMesh) is processed.";
polyMesh->addAttrib<Ra::Core::Vector4>(
"myCustomAttrib",
Ra::Core::Vector4Array{polyMesh->getNumVertices(),
Ra::Core::Utils::Color::Magenta()} );
polyMesh->setDirty( "myCustomAttrib" );
}
else
{
auto pointCloud =
dynamic_cast<Ra::Engine::Data::PointCloud*>( theMesh.get() );
if ( pointCloud )
{
LOG( logINFO ) << "\t\tPointCloud " << pointCloud->getName()
<< " is processed.";
pointCloud->addAttrib<Ra::Core::Vector4>(
"myCustomAttrib",
Ra::Core::Vector4Array{pointCloud->getNumVertices(),
Ra::Core::Utils::Color::Blue()} );
pointCloud->setDirty( "myCustomAttrib" );
}
else
{
LOG( logINFO ) << "\t\tMesh " << theMesh->getName()
<< " is nor a trianglemesh, nor a polymesh, nor a "
"point cloud ... skipping";
}
}
} }
} }
} }
...@@ -273,13 +261,16 @@ const std::string customVertexAttrib{"in vec4 myCustomAttrib;\n" ...@@ -273,13 +261,16 @@ const std::string customVertexAttrib{"in vec4 myCustomAttrib;\n"
* Note that this string could also be loaded from a file and/or manually edited if you * Note that this string could also be loaded from a file and/or manually edited if you
* add an edition widget as in Radium app demo * add an edition widget as in Radium app demo
*/ */
const std::string customFragmentColor{ const std::string customFragmentColor{
"in vec4 fragCustomAttrib;\n" "in vec4 fragCustomAttrib;\n"
"\nvec4 computeCustomColor(Material mat, vec3 lightDir, vec3 viewDir) {\n" "\nvec4 computeCustomColor(Material mat, vec3 lightDir, vec3 viewDir, vec3 normal_world) {\n"
"vec3 diffColor; \n" "vec3 diffColor; \n"
"vec3 specColor; \n" "vec3 specColor; \n"
"getSeparateBSDFComponent( mat, getPerVertexTexCoord(), lightDir, viewDir,\n" "getSeparateBSDFComponent( mat, getPerVertexTexCoord(), lightDir, viewDir,\n"
"vec3(0, 0, 1), diffColor, specColor );\n" "vec3(0, 0, 1), diffColor, specColor );\n"
"vec3 col = normal_world*0.5+0.5;\n"
"col *= fragCustomAttrib.rgb;\n"
"return vec4( (specColor+fragCustomAttrib.rgb)*max(lightDir.z, 0), 1); \n" "return vec4( (specColor+fragCustomAttrib.rgb)*max(lightDir.z, 0), 1); \n"
"}\n"}; "}\n"};
......
...@@ -190,7 +190,8 @@ bool CustomAttribToColorPass::buildRenderTechnique( ...@@ -190,7 +190,8 @@ bool CustomAttribToColorPass::buildRenderTechnique(
"layout (location = 5) in vec3 in_viewVector;\n" "layout (location = 5) in vec3 in_viewVector;\n"
"layout (location = 6) in vec3 in_lightVector;\n" "layout (location = 6) in vec3 in_lightVector;\n"
"layout (location = 0) out vec4 out_color;\n" "layout (location = 0) out vec4 out_color;\n"
"vec4 computeCustomColor(Material mat, vec3 light_dir, vec3 view_dir);\n" "vec4 computeCustomColor(Material mat, vec3 light_dir, vec3 view_dir, vec3 "
"normal_world);\n"
"void main()\n" "void main()\n"
"{\n" "{\n"
"vec3 normalWorld = getWorldSpaceNormal();\n" "vec3 normalWorld = getWorldSpaceNormal();\n"
...@@ -208,7 +209,7 @@ bool CustomAttribToColorPass::buildRenderTechnique( ...@@ -208,7 +209,7 @@ bool CustomAttribToColorPass::buildRenderTechnique(
"world2local[2] = vec3(tangentWorld.z, binormalWorld.z, normalWorld.z);\n" "world2local[2] = vec3(tangentWorld.z, binormalWorld.z, normalWorld.z);\n"
"vec3 lightDir = normalize(world2local * in_lightVector);\n" "vec3 lightDir = normalize(world2local * in_lightVector);\n"
"vec3 viewDir = normalize(world2local * in_viewVector);\n" "vec3 viewDir = normalize(world2local * in_viewVector);\n"
"out_color = computeCustomColor(material, lightDir, viewDir);\n" "out_color = computeCustomColor(material, lightDir, viewDir, normalWorld);\n"
"}\n"}; "}\n"};
Ra::Engine::Data::ShaderConfiguration theConfig{"CustomAtt2ClrPass::CustomColorProgram" + Ra::Engine::Data::ShaderConfiguration theConfig{"CustomAtt2ClrPass::CustomColorProgram" +
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment