Skip to content

Commit

Permalink
Lazy-init convolution on OpenGL, and don't rebuild the map afterwards
Browse files Browse the repository at this point in the history
  • Loading branch information
ApoorvaJ committed Sep 18, 2023
1 parent 5439181 commit 14ab9e9
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
3 changes: 2 additions & 1 deletion source/MaterialXRender/LightHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ class MX_RENDER_API LightHandler
_directLighting(true),
_indirectLighting(true),
_envSampleCount(DEFAULT_ENV_SAMPLE_COUNT),
_refractionTwoSided(false)
_refractionTwoSided(false),
_envRadianceMapPreConvolved(nullptr)
{
}
virtual ~LightHandler() { }
Expand Down
7 changes: 6 additions & 1 deletion source/MaterialXView/RenderPipelineGL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,11 @@ void GLRenderPipeline::convolveEnvironment()
auto& genContext = _viewer->_genContext;
auto& lightHandler = _viewer->_lightHandler;
auto& imageHandler = _viewer->_imageHandler;
mx::GLTextureHandlerPtr glImageHandler = std::dynamic_pointer_cast<mx::GLTextureHandler>(imageHandler);

if (lightHandler->getEnvRadianceMapPreConvolved())
{
return;
}

// Create the convolution shader.
mx::GlslMaterialPtr material = nullptr;
Expand All @@ -137,6 +141,7 @@ void GLRenderPipeline::convolveEnvironment()
int numMips = srcTex->getMaxMipCount();

// Create texture to hold the convolved environment.
mx::GLTextureHandlerPtr glImageHandler = std::dynamic_pointer_cast<mx::GLTextureHandler>(imageHandler);
mx::ImagePtr outTex = mx::Image::create(w, h, 3, mx::Image::BaseType::HALF);
glImageHandler->createRenderResources(outTex, true);

Expand Down
2 changes: 1 addition & 1 deletion source/MaterialXView/RenderPipelineMetal.mm
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,6 @@
auto& genContext = _viewer->_genContext;
auto& lightHandler = _viewer->_lightHandler;
auto& imageHandler = _viewer->_imageHandler;
mx::MetalTextureHandlerPtr mtlImageHandler = std::dynamic_pointer_cast<mx::MetalTextureHandler>(imageHandler);

if (lightHandler->getEnvRadianceMapPreConvolved())
{
Expand All @@ -171,6 +170,7 @@
int w = srcTex->getWidth();
int h = srcTex->getHeight();

mx::MetalTextureHandlerPtr mtlImageHandler = std::dynamic_pointer_cast<mx::MetalTextureHandler>(imageHandler);
mx::ImagePtr outTex = mx::Image::create(w, h, 3, mx::Image::BaseType::HALF);
mtlImageHandler->createRenderResources(outTex, true);
id<MTLTexture> metalTex = mtlImageHandler->getAssociatedMetalTexture(outTex);
Expand Down

0 comments on commit 14ab9e9

Please sign in to comment.