From 4cc3ac41ccf3ec2a49277900a2e722fac64abe54 Mon Sep 17 00:00:00 2001 From: John Haddon Date: Wed, 2 Oct 2024 11:48:06 +0100 Subject: [PATCH] GL Renderer : Fix custom mesh light texture visualisations These were broken by cfc3857ce0da4c8f77cfc546028f5c7e64aaf585, where we assumed that such visualisations should be rendered with the Display color space. This led to them being rendered after the main Scene color space, meaning that the depth test prevented the texture visualisation from being seen. We now use a heuristic that means such visualisations are rendered first in Scene color space instead. In theory we could extend the Visualiser API to allow two states to be specified - one for Display space and one for Scene space. But that would require an ABI break, and we want this fix to go into 1.3. We also have so few uses for the visualisation state that it seems like overkill at this point. Fixes #6002. --- Changes.md | 1 + src/GafferScene/IECoreGLPreview/Renderer.cpp | 31 ++++++++++++-------- 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/Changes.md b/Changes.md index bf5c9ba090d..75fb3b43b85 100644 --- a/Changes.md +++ b/Changes.md @@ -8,6 +8,7 @@ Fixes - Fixed partial image updates when an unrelated InteractiveRender was running (#6043). - Fixed "colour tearing", where updates to some image channels became visible before updates to others. - Fixed unnecessary texture updates when specific image tiles don't change. +- Viewer : Fixed drawing of custom mesh light texture visualisers (#6002). - ArrayPlug : - Fixed error when `resize()` removed plugs with input connections. - Fixed error when `resize()` was used on an output plug. diff --git a/src/GafferScene/IECoreGLPreview/Renderer.cpp b/src/GafferScene/IECoreGLPreview/Renderer.cpp index 95dbcd0c556..bed4ea4cead 100644 --- a/src/GafferScene/IECoreGLPreview/Renderer.cpp +++ b/src/GafferScene/IECoreGLPreview/Renderer.cpp @@ -320,7 +320,7 @@ class OpenGLAttributes : public IECoreScenePreview::Renderer::AttributesInterfac public : OpenGLAttributes( const IECore::CompoundObject *attributes ) - : m_frustumMode( FrustumMode::WhenSelected ) + : m_frustumMode( FrustumMode::WhenSelected ), m_visualisationStateColorSpace( Visualisation::ColorSpace::Display ) { const FloatData *visualiserScaleData = attributes->member( "gl:visualiser:scale" ); m_visualiserScale = visualiserScaleData ? visualiserScaleData->readable() : 1.0; @@ -388,6 +388,19 @@ class OpenGLAttributes : public IECoreScenePreview::Renderer::AttributesInterfac } m_visualisationState = combinedState; + auto solidState = m_visualisationState->get(); + // The Visualiser API doesn't currently allow a colour space to + // be associated with the visualisation state. So we use a + // heuristic : if the state includes solid drawing then we + // assume Scene space. This allows custom mesh light texture + // visualisers to be shown with an appropriate colour transform. + // Otherwise we assume Display space, which gives us what we + // want for the coloured outline from our own mesh light + // visualiser. + if( !solidState || solidState->value() ) + { + m_visualisationStateColorSpace = Visualisation::ColorSpace::Scene; + } } } @@ -396,9 +409,9 @@ class OpenGLAttributes : public IECoreScenePreview::Renderer::AttributesInterfac return m_state.get(); } - const State *visualisationState() const + const State *visualisationState( Visualisation::ColorSpace colorSpace ) const { - return m_visualisationState.get(); + return colorSpace == m_visualisationStateColorSpace ? m_visualisationState.get() : nullptr; } const IECoreGLPreview::Visualisations &visualisations() const @@ -451,6 +464,7 @@ class OpenGLAttributes : public IECoreScenePreview::Renderer::AttributesInterfac FrustumMode m_frustumMode; float m_visualiserScale = 1.0f; + Visualisation::ColorSpace m_visualisationStateColorSpace; }; IE_CORE_DECLAREPTR( OpenGLAttributes ) @@ -636,19 +650,12 @@ class OpenGLObject : public IECoreScenePreview::Renderer::ObjectInterface // Objects are rendered into `ColorSpace::Scene`, with the caveat that selection // overlays and additional visualisations are drawn into `ColorSpace::Display`. - const IECoreGL::State *visualisationState = m_attributes->visualisationState(); + const IECoreGL::State *visualisationState = m_attributes->visualisationState( colorSpace ); if( m_renderable && ( colorSpace == Visualisation::ColorSpace::Scene || isSelected || visualisationState ) ) { IECoreGL::State::ScopedBinding stateScope( *m_attributes->state(), *currentState ); - // We assume that any additional state provided by visualisers - // is intended to be drawn in `ColorSpace::Display`. Currently - // the only such state is the yellow outline added by the mesh - // light visualiser, so it would be premature to extend the API - // to allow visualiser state to also be specified for - // `ColorSpace::Scene`. In fact, the potential uses for - // visualiser state seem very limited. std::optional visualisationStateScope; - if( visualisationState && colorSpace == Visualisation::ColorSpace::Display ) + if( visualisationState ) { visualisationStateScope.emplace( *visualisationState, *currentState ); }