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

Light editor column registration #5857

Merged

Conversation

ericmehl
Copy link
Collaborator

This adds the ability to register a column in the Light Editor for editing a parameter anywhere within a light's shader network. Previously only parameters on the light itself were editable.

Fixes #5561.

Checklist

  • I have read the contribution guidelines.
  • I have updated the documentation, if applicable.
  • I have tested my change(s) in the test suite, and added new test cases where necessary.
  • My code follows the Gaffer project's prevailing coding style and conventions.

@ericmehl
Copy link
Collaborator Author

I'm marking this as draft for now - the ability to edit the original nodes of a light's shader network is still a work in progress. I think I have enough functionality there to talk through my approach and validate it or not. But there are a number of edge cases still to be addressed like handling spline plug connections, component connections, etc.

Also note that the first two commits are from #5846 and will be dropped when that is merged.

@ericmehl ericmehl force-pushed the lightEditorColumnRegistration branch from b921d97 to 0c0c74b Compare May 14, 2024 22:11
@ericmehl
Copy link
Collaborator Author

After talking through it with @johnhaddon, we decided to use the existing NetworkBuilder in GafferScene::Shader instead of duplicating what was turning out to be quite a bit of functionality. Instead, I've added a new parameterSource() method to both GafferScene::ShaderPlug and GafferScene::Shader (protected in the latter). This queries the NetworkBuilder::m_shaders map to see what shader node generated a particular shader handle.

I think I've gotten the gist of what we talked about right, and the tests I added for the initial round are passing and interactive tests are working.

I didn't do anything with the concept of adding syntax to tweak plugs to allow something like input(surfaceShader.color).tint in order to tweak parameters where you know the relationship to a shader handle but not necessarily the target shader handle itself.

But I think it's ready for a new look, especially for the API that I've added in abbfde2

{
if( const auto shaderPlug = runTimeCast<ShaderPlug>( plug ) )
{
return const_cast<ValuePlug *>( shaderPlug->parameterSource( m_parameter ) );
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is my main concern for the new API - is this const_cast a valid solution? The NetworkBuilder works with const plugs throughout, which does seem right considering what NetworkBuilder is meant to do.

Just to see how it would go, I tried making the return plug non-const, but the ripple effects of that went all the way up to the Shader API. Which doesn't seem like a good thing.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think a const_cast is a valid solution, but I don't think this is the place for it. You're right that NetworkBuilder should continue to work with const plugs, because it must never modify the graph. And it's also right that ShaderPlug::parameterSource() const should return a const result (if the caller only has const access to ShaderPlug, they should only be able to use it to get const access to the rest of the graph). But here we have non-const access to ShaderPlug, so ShaderPlug should also provide us with a non-const overload for parameterSource() that returns us a non-const plug.

Copy link
Member

@johnhaddon johnhaddon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks Eric - the new direction on this is feeling much better. Detailed comments inline - I think we're close enough that you can just squash and rebase away as you address them...
Cheers...
John

python/GafferSceneUI/LightEditor.py Outdated Show resolved Hide resolved
python/GafferSceneUITest/LightEditorTest.py Outdated Show resolved Hide resolved
src/GafferSceneUI/ParameterInspector.cpp Outdated Show resolved Hide resolved
include/GafferScene/Shader.h Outdated Show resolved Hide resolved
include/GafferScene/ShaderPlug.h Show resolved Hide resolved
{
if( const auto shaderPlug = runTimeCast<ShaderPlug>( plug ) )
{
return const_cast<ValuePlug *>( shaderPlug->parameterSource( m_parameter ) );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think a const_cast is a valid solution, but I don't think this is the place for it. You're right that NetworkBuilder should continue to work with const plugs, because it must never modify the graph. And it's also right that ShaderPlug::parameterSource() const should return a const result (if the caller only has const access to ShaderPlug, they should only be able to use it to get const access to the rest of the graph). But here we have non-const access to ShaderPlug, so ShaderPlug should also provide us with a non-const overload for parameterSource() that returns us a non-const plug.

src/GafferScene/ShaderPlug.cpp Outdated Show resolved Hide resolved
src/GafferSceneUI/ParameterInspector.cpp Show resolved Hide resolved
src/GafferSceneUI/ParameterInspector.cpp Outdated Show resolved Hide resolved
Changes.md Outdated Show resolved Hide resolved
Previously we were only considering parameter names when looking for a
`TweakPlug` to use as the inspection source. Considering the shader name
allows inspections to recognize and modify tweaks to shaders other than
the output shader.
This opens the way for the `ParameterInspector` to be able to inspect
any parameter within a shader network. Because node names and shader
names are deduplicated independently, the best way to figure out what
node generated a `ShaderNetwork` handle is build the `ShaderNetwork` and
query the `NetworkBuilder` internal shader map.

Future optimizations could be made to only generate the network elements
that are needed for this query (for example, not populating parameter
values).
This allows registration of columns for parameters that are not on the
light itself, but in a shader connected to the light. This commit
requires the use of an Edit Scope to make changes to such parameters
in the Light Editor.
@ericmehl ericmehl force-pushed the lightEditorColumnRegistration branch from 0c0c74b to 6ffbc98 Compare May 17, 2024 15:40
@ericmehl
Copy link
Collaborator Author

I addressed all the notes above, thanks for all the improvements @johnhaddon. I didn't mark them "fixed" individually because I also squashed them into the original commits as I went, but I can note them if that makes the review easier.

The commit sequence is hopefully easier to follow now, and I reworked the tests to put the majority of new tests in a single test in ParameterInspectorTest in 880f828. I changed that to test using shaders instead of a light to keep it in the relevant commit.

Marking as ready for (another) review!

@ericmehl ericmehl marked this pull request as ready for review May 17, 2024 16:32
@johnhaddon johnhaddon merged commit 50ff71c into GafferHQ:1.4_maintenance May 20, 2024
5 checks passed
@johnhaddon
Copy link
Member

Thanks Eric!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants