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() {
{
auto theMesh = ro->getMesh();
/* Could be helpfull if one can do
auto displayable = dynamic_cast<Ra::Engine::Data::CoreGeometryDisplayable< ???
>*>( theMesh.get() );
*/
auto displayMesh = dynamic_cast<Ra::Engine::Data::Mesh*>( theMesh.get() );
if ( displayMesh )
auto displayMesh =
dynamic_cast<Ra::Engine::Data::AttribArrayDisplayable*>( theMesh.get() );
LOG( logINFO ) << "\t\tMesh " << displayMesh->getName() << " is processed.";
auto& coreMesh = displayMesh->getAttribArrayGeometry();
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()
<< " (TriangleMesh) is processed.";
displayMesh->addAttrib<Ra::Core::Vector4>(
"myCustomAttrib",
Ra::Core::Vector4Array{displayMesh->getNumVertices(),
Ra::Core::Utils::Color::Yellow()} );
displayMesh->setDirty( "myCustomAttrib" );
addAttrib( "myCustomAttrib",
Ra::Core::Vector4Array{displayMesh->getNumVertices(),
/*Ra::Core::Utils::Color::White()*/ {
0.7_ra, 0.8_ra, 0.8_ra, 1_ra}} );
}
else if ( meshTypeHash == typeid( Ra::Engine::Data::PolyMesh ).hash_code() )
{
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
{
auto polyMesh = dynamic_cast<Ra::Engine::Data::PolyMesh*>( theMesh.get() );
if ( polyMesh )
{
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";
}
}
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"
* 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
*/
const std::string customFragmentColor{
"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 specColor; \n"
"getSeparateBSDFComponent( mat, getPerVertexTexCoord(), lightDir, viewDir,\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"
"}\n"};
......
......@@ -190,7 +190,8 @@ bool CustomAttribToColorPass::buildRenderTechnique(
"layout (location = 5) in vec3 in_viewVector;\n"
"layout (location = 6) in vec3 in_lightVector;\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"
"{\n"
"vec3 normalWorld = getWorldSpaceNormal();\n"
......@@ -208,7 +209,7 @@ bool CustomAttribToColorPass::buildRenderTechnique(
"world2local[2] = vec3(tangentWorld.z, binormalWorld.z, normalWorld.z);\n"
"vec3 lightDir = normalize(world2local * in_lightVector);\n"
"vec3 viewDir = normalize(world2local * in_viewVector);\n"
"out_color = computeCustomColor(material, lightDir, viewDir);\n"
"out_color = computeCustomColor(material, lightDir, viewDir, normalWorld);\n"
"}\n"};
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