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

CustomAttribPass now may exports a vector field as a 2D texture

parent f4b76b1f
No related branches found
No related tags found
No related merge requests found
Pipeline #196 passed
...@@ -181,6 +181,9 @@ const std::string customFragmentColor{ ...@@ -181,6 +181,9 @@ const std::string customFragmentColor{
"if (e==1) { finalColor = finalColor*envd + specColor*envs; }\n" "if (e==1) { finalColor = finalColor*envd + specColor*envs; }\n"
"else { finalColor = (finalColor + specColor) * max(lightDir.z, 0) \n" "else { finalColor = (finalColor + specColor) * max(lightDir.z, 0) \n"
" * lightContributionFrom(light, getWorldSpacePosition().xyz); }\n" " * lightContributionFrom(light, getWorldSpacePosition().xyz); }\n"
"#ifdef EXPORT_VECTOR_FIELD\n"
"out_vector_field = vec4(getWorldSpaceTangent(), 1);\n"
"#endif\n"
"return vec4( finalColor, 1); \n" "return vec4( finalColor, 1); \n"
"}\n" "}\n"
}; };
......
...@@ -77,9 +77,18 @@ buildControllerGui( NodeBasedRenderer* renderer, const std::function<void()>& ap ...@@ -77,9 +77,18 @@ buildControllerGui( NodeBasedRenderer* renderer, const std::function<void()>& ap
controlPanel->endLayout(); controlPanel->endLayout();
controlPanel->endLayout( true ); controlPanel->endLayout( true );
// TODO : add a double slider to get the good value. ask @dlyr for its doubleSliderClass ...
controlPanel->beginLayout( QBoxLayout::LeftToRight ); controlPanel->beginLayout( QBoxLayout::LeftToRight );
controlPanel->addOption(
" Exports vector field ",
[&controller, appUpdateCallback]( bool b ) {
controller.exportVectorField( b );
appUpdateCallback();
},
// TODO : find a way to initialise this according to futre controller configuration
true /*controller.exportsVectorField()*/ );
controlPanel->addSeparator();
auto splatSizeCtrl = [&controller]( double v ) { controller.setSplatSize( v ); }; auto splatSizeCtrl = [&controller]( double v ) { controller.setSplatSize( v ); };
controlPanel->addPowerSliderInput( controlPanel->addPowerSliderInput(
"Splat size", splatSizeCtrl, controller.getSplatSize(), 0, 5 ); "Splat size", splatSizeCtrl, controller.getSplatSize(), 0, 5 );
......
...@@ -106,13 +106,13 @@ void NodeBasedRenderer::initializeInternal() { ...@@ -106,13 +106,13 @@ void NodeBasedRenderer::initializeInternal() {
// Initialize renderer resources // Initialize renderer resources
initResources(); initResources();
m_controller.configure( this, m_width, m_height );
for ( const auto& t : m_sharedTextures ) for ( const auto& t : m_sharedTextures )
{ {
m_secondaryTextures.insert( {t.first, t.second.get()} ); m_secondaryTextures.insert( {t.first, t.second.get()} );
} }
m_controller.configure( this, m_width, m_height );
// Todo cache this in an attribute ? // Todo cache this in an attribute ?
auto resourcesCheck = Ra::Core::Resources::getResourcesPath( auto resourcesCheck = Ra::Core::Resources::getResourcesPath(
reinterpret_cast<void*>( &RadiumNBR::NodeBasedRendererMagic ), {"Resources/RadiumNBR"} ); reinterpret_cast<void*>( &RadiumNBR::NodeBasedRendererMagic ), {"Resources/RadiumNBR"} );
......
...@@ -43,7 +43,6 @@ void ClearPass::resize( size_t width, size_t height ) { ...@@ -43,7 +43,6 @@ void ClearPass::resize( size_t width, size_t height ) {
} }
void ClearPass::execute( const Ra::Engine::Data::ViewingParameters& viewParams ) const { void ClearPass::execute( const Ra::Engine::Data::ViewingParameters& viewParams ) const {
using ClearColor = Ra::Core::Utils::Color;
m_fbo->bind(); m_fbo->bind();
GL_ASSERT( glDrawBuffers( 1, buffers ) ); GL_ASSERT( glDrawBuffers( 1, buffers ) );
GL_ASSERT( glDisable( GL_BLEND ) ); GL_ASSERT( glDisable( GL_BLEND ) );
......
...@@ -73,7 +73,7 @@ class PointCloudParameterProvider : public Ra::Engine::Data::ShaderParameterProv ...@@ -73,7 +73,7 @@ class PointCloudParameterProvider : public Ra::Engine::Data::ShaderParameterProv
Ra::Engine::Scene::PointCloudComponent* m_component; Ra::Engine::Scene::PointCloudComponent* m_component;
}; };
static const GLenum buffers[] = {GL_COLOR_ATTACHMENT0}; static const GLenum buffers[] = {GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1};
CustomAttribToColorPass::CustomAttribToColorPass( CustomAttribToColorPass::CustomAttribToColorPass(
const std::vector<RenderObjectPtr>* objectsToRender, const std::vector<RenderObjectPtr>* objectsToRender,
...@@ -82,12 +82,25 @@ CustomAttribToColorPass::CustomAttribToColorPass( ...@@ -82,12 +82,25 @@ CustomAttribToColorPass::CustomAttribToColorPass(
CustomAttribToColorPass::~CustomAttribToColorPass() = default; CustomAttribToColorPass::~CustomAttribToColorPass() = default;
bool CustomAttribToColorPass::initializePass( size_t /* width */, bool CustomAttribToColorPass::initializePass( size_t width,
size_t /* height */, size_t height,
Ra::Engine::Data::ShaderProgramManager* shaderMngr ) { Ra::Engine::Data::ShaderProgramManager* shaderMngr ) {
m_shaderMngr = shaderMngr; m_shaderMngr = shaderMngr;
m_fbo = std::make_unique<globjects::Framebuffer>(); m_fbo = std::make_unique<globjects::Framebuffer>();
Ra::Engine::Data::TextureParameters texparams;
texparams.width = width;
texparams.height = height;
texparams.target = GL_TEXTURE_2D;
texparams.minFilter = GL_LINEAR;
texparams.magFilter = GL_LINEAR;
texparams.internalFormat = GL_RGBA32F;
texparams.format = GL_RGBA;
texparams.type = GL_FLOAT;
texparams.name = "CustomAtt2Clr::VectorField";
m_sharedTextures.insert(
{texparams.name, std::make_shared<Ra::Engine::Data::Texture>( texparams )} );
return true; return true;
} }
...@@ -121,6 +134,8 @@ void CustomAttribToColorPass::resize( size_t width, size_t height ) { ...@@ -121,6 +134,8 @@ void CustomAttribToColorPass::resize( size_t width, size_t height ) {
m_fbo->attachTexture( GL_DEPTH_ATTACHMENT, m_fbo->attachTexture( GL_DEPTH_ATTACHMENT,
m_importedTextures["CustomAtt2Clr::Depth"]->texture() ); m_importedTextures["CustomAtt2Clr::Depth"]->texture() );
m_fbo->attachTexture( GL_COLOR_ATTACHMENT0, m_outputTexture.second->texture() ); m_fbo->attachTexture( GL_COLOR_ATTACHMENT0, m_outputTexture.second->texture() );
m_fbo->attachTexture( GL_COLOR_ATTACHMENT1,
m_sharedTextures["CustomAtt2Clr::VectorField"]->texture() );
#ifdef PASSES_LOG #ifdef PASSES_LOG
if ( m_fbo->checkStatus() != GL_FRAMEBUFFER_COMPLETE ) if ( m_fbo->checkStatus() != GL_FRAMEBUFFER_COMPLETE )
{ LOG( logERROR ) << "FBO Error (EmissivityPass::resize): " << m_fbo->checkStatus(); } { LOG( logERROR ) << "FBO Error (EmissivityPass::resize): " << m_fbo->checkStatus(); }
...@@ -132,9 +147,16 @@ void CustomAttribToColorPass::resize( size_t width, size_t height ) { ...@@ -132,9 +147,16 @@ void CustomAttribToColorPass::resize( size_t width, size_t height ) {
void CustomAttribToColorPass::execute( void CustomAttribToColorPass::execute(
const Ra::Engine::Data::ViewingParameters& viewParams ) const { const Ra::Engine::Data::ViewingParameters& viewParams ) const {
static constexpr const float clearDepth{1.0f}; static constexpr const float clearDepth{1.0f};
static const float clearColor[4] {0.f, 0.f, 0.f, 0.f};
m_fbo->bind(); m_fbo->bind();
// only draw into 1 buffers (Color) // only draw into 1 or 2 buffers depending on the export of a vector field
GL_ASSERT( glDrawBuffers( 1, buffers ) ); if ( m_exportVectorField ) {
GL_ASSERT( glDrawBuffers( 2, buffers ) );
GL_ASSERT( glClearBufferfv( GL_COLOR, 1, clearColor ) );
} else {
GL_ASSERT( glDrawBuffers( 1, buffers ) );
}
GL_ASSERT( glDepthMask( GL_TRUE ) ); GL_ASSERT( glDepthMask( GL_TRUE ) );
GL_ASSERT( glColorMask( GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE ) ); GL_ASSERT( glColorMask( GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE ) );
GL_ASSERT( glEnable( GL_DEPTH_TEST ) ); GL_ASSERT( glEnable( GL_DEPTH_TEST ) );
...@@ -253,6 +275,9 @@ bool CustomAttribToColorPass::buildRenderTechnique( ...@@ -253,6 +275,9 @@ 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"
"#ifdef EXPORT_VECTOR_FIELD\n"
"layout (location = 1) out vec4 out_vector_field;\n"
"#endif\n"
"vec4 computeCustomColor(Material mat, vec3 light_dir, vec3 view_dir, vec3 " "vec4 computeCustomColor(Material mat, vec3 light_dir, vec3 view_dir, vec3 "
"normal_world);\n" "normal_world);\n"
"void main()\n" "void main()\n"
...@@ -287,6 +312,12 @@ bool CustomAttribToColorPass::buildRenderTechnique( ...@@ -287,6 +312,12 @@ bool CustomAttribToColorPass::buildRenderTechnique(
fragmentShadersource + noopEnvMapFunction + m_customFragmentColor ); fragmentShadersource + noopEnvMapFunction + m_customFragmentColor );
} }
if ( m_exportVectorField ) {
theConfig.addProperty( "EXPORT_VECTOR_FIELD" );
} else {
theConfig.removeProperty( "EXPORT_VECTOR_FIELD" );
}
theConfig.addInclude( "\"" + mat->getMaterialName() + ".glsl\"", theConfig.addInclude( "\"" + mat->getMaterialName() + ".glsl\"",
Ra::Engine::Data::ShaderType::ShaderType_FRAGMENT ); Ra::Engine::Data::ShaderType::ShaderType_FRAGMENT );
...@@ -356,7 +387,7 @@ bool CustomAttribToColorPass::buildRenderTechnique( ...@@ -356,7 +387,7 @@ bool CustomAttribToColorPass::buildRenderTechnique(
" out_position = point[idx];\n" " out_position = point[idx];\n"
" out_texcoord = vec3( uv[idx], 0. );\n" " out_texcoord = vec3( uv[idx], 0. );\n"
" out_normal = normal;\n" " out_normal = normal;\n"
" out_tangent = in_tangent[0];\n" " out_tangent = length(in_tangent[0]) == 0 ? (point[2] - point[1]) : in_tangent[0];\n"
" out_viewVector = in_viewVector[0];\n" " out_viewVector = in_viewVector[0];\n"
" out_lightVector = in_lightVector[0];\n" " out_lightVector = in_lightVector[0];\n"
" out_vertexcolor = in_vertexColor[0];\n" " out_vertexcolor = in_vertexColor[0];\n"
......
...@@ -72,6 +72,13 @@ class CustomAttribToColorPass : public RenderPass ...@@ -72,6 +72,13 @@ class CustomAttribToColorPass : public RenderPass
/// get the strength (aka "power") of the env map /// get the strength (aka "power") of the env map
int getEnvStrength() const { return int( m_envStrength * 100 ); } int getEnvStrength() const { return int( m_envStrength * 100 ); }
/// get/set the export vector field state
void exportVectorField( bool state ) {
m_exportVectorField = state;
rebuildShaders();
};
bool exportsVectorField() const { return m_exportVectorField;}
private: private:
/// The framebuffer used to render this pass /// The framebuffer used to render this pass
std::unique_ptr<globjects::Framebuffer> m_fbo{nullptr}; std::unique_ptr<globjects::Framebuffer> m_fbo{nullptr};
...@@ -105,6 +112,9 @@ class CustomAttribToColorPass : public RenderPass ...@@ -105,6 +112,9 @@ class CustomAttribToColorPass : public RenderPass
"if (e==1) { finalColor = diffColor*envd + specColor*envs; }\n" "if (e==1) { finalColor = diffColor*envd + specColor*envs; }\n"
"else { finalColor = (diffColor + specColor) * max(lightDir.z, 0) \n" "else { finalColor = (diffColor + specColor) * max(lightDir.z, 0) \n"
" * lightContributionFrom(light, getWorldSpacePosition().xyz); }\n" " * lightContributionFrom(light, getWorldSpacePosition().xyz); }\n"
"#ifdef EXPORT_VECTOR_FIELD\n"
"out_vector_field = vec4(getWorldSpaceTangent(), 1);\n"
"#endif\n"
"return vec4( finalColor, 1); \n" "return vec4( finalColor, 1); \n"
"}\n"}; "}\n"};
...@@ -122,5 +132,8 @@ class CustomAttribToColorPass : public RenderPass ...@@ -122,5 +132,8 @@ class CustomAttribToColorPass : public RenderPass
/// The strength of the envmap /// The strength of the envmap
float m_envStrength; float m_envStrength;
/// Export a vector texture
bool m_exportVectorField{true};
}; };
} // namespace RadiumNBR } // namespace RadiumNBR
...@@ -62,6 +62,11 @@ void VisualizationController::configure( RadiumNBR::NodeBasedRenderer* renderer, ...@@ -62,6 +62,11 @@ void VisualizationController::configure( RadiumNBR::NodeBasedRenderer* renderer,
m_customPass->initializePass( w, h, shaderManager ); m_customPass->initializePass( w, h, shaderManager );
// add the pass to the renderer and activate it // add the pass to the renderer and activate it
renderer->addPass( m_customPass, m_customPass->index() ); renderer->addPass( m_customPass, m_customPass->index() );
// Add the exported (shared) texture to the set of available textures
auto &sharedTextures = renderer->sharedTextures();
for (auto t : m_customPass->getOutputImages() ) {
sharedTextures.insert( {t.first, t.second} );
}
m_customPass->activate(); m_customPass->activate();
} }
//! [Adding a CustomAttribToColorPass pass] //! [Adding a CustomAttribToColorPass pass]
...@@ -155,4 +160,13 @@ void VisualizationController::showEnvMap( bool state ) { ...@@ -155,4 +160,13 @@ void VisualizationController::showEnvMap( bool state ) {
void VisualizationController::setEnvStrength( int s ) { void VisualizationController::setEnvStrength( int s ) {
m_customPass->setEnvStrength( s ); m_customPass->setEnvStrength( s );
} }
void VisualizationController::exportVectorField( bool state ) {
m_customPass->exportVectorField( state );
}
bool VisualizationController::exportsVectorField() const {
return m_customPass->exportsVectorField();
}
} // namespace RadiumNBR } // namespace RadiumNBR
...@@ -44,6 +44,9 @@ class NodeBasedRenderer_LIBRARY_API VisualizationController ...@@ -44,6 +44,9 @@ class NodeBasedRenderer_LIBRARY_API VisualizationController
void showEnvMap( bool state ); void showEnvMap( bool state );
void setEnvStrength( int s ); void setEnvStrength( int s );
void exportVectorField( bool state );
bool exportsVectorField() const;
private: private:
/// The custom pass if needed for modification /// The custom pass if needed for modification
std::shared_ptr<RadiumNBR::CustomAttribToColorPass> m_customPass; std::shared_ptr<RadiumNBR::CustomAttribToColorPass> m_customPass;
...@@ -67,6 +70,9 @@ class NodeBasedRenderer_LIBRARY_API VisualizationController ...@@ -67,6 +70,9 @@ class NodeBasedRenderer_LIBRARY_API VisualizationController
"if (e==1) { finalColor = diffColor*envd + specColor*envs; }\n" "if (e==1) { finalColor = diffColor*envd + specColor*envs; }\n"
"else { finalColor = (diffColor + specColor) * max(lightDir.z, 0) \n" "else { finalColor = (diffColor + specColor) * max(lightDir.z, 0) \n"
" * lightContributionFrom(light, getWorldSpacePosition().xyz); }\n" " * lightContributionFrom(light, getWorldSpacePosition().xyz); }\n"
"#ifdef EXPORT_VECTOR_FIELD\n"
"out_vector_field = vec4(getWorldSpaceTangent(), 1);\n"
"#endif\n"
"return vec4( finalColor, 1); \n" "return vec4( finalColor, 1); \n"
"}\n"}; "}\n"};
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment