Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GL Renderer : Fix custom mesh light texture visualisations #6066

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
31 changes: 19 additions & 12 deletions src/GafferScene/IECoreGLPreview/Renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<FloatData>( "gl:visualiser:scale" );
m_visualiserScale = visualiserScaleData ? visualiserScaleData->readable() : 1.0;
Expand Down Expand Up @@ -388,6 +388,19 @@ class OpenGLAttributes : public IECoreScenePreview::Renderer::AttributesInterfac
}

m_visualisationState = combinedState;
auto solidState = m_visualisationState->get<IECoreGL::Primitive::DrawSolid>();
// 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;
}
}
}

Expand All @@ -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
Expand Down Expand Up @@ -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 )
Expand Down Expand Up @@ -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<IECoreGL::State::ScopedBinding> visualisationStateScope;
if( visualisationState && colorSpace == Visualisation::ColorSpace::Display )
if( visualisationState )
{
visualisationStateScope.emplace( *visualisationState, *currentState );
}
Expand Down
Loading