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

Shader : Support inline ContextProcessors #6211

Merged

Conversation

johnhaddon
Copy link
Member

This allows ContextProcessor, Loop and Spreadsheet nodes to be inserted inline within a shader network, receiving inputs from Shader nodes and passing outputs to Shader nodes. This opens up the possibility for several interesting workflows, one such being an "uber connection" which passes multiple textures through a single colour plug, using a ContextVariables node at the destination to choose which texture to plug in. Along the way, the context variable can be used to apply different grading etc to each texture in a very tidy way. In prototype form at Cinesite, this has already vastly simplified some complex shader networks, leading to much improved render times as well.

@johnhaddon johnhaddon self-assigned this Jan 14, 2025
Copy link
Contributor

@danieldresser-ie danieldresser-ie left a comment

Choose a reason for hiding this comment

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

As is often the case, I feel like I ought to have more to say about this much code, but I've looked through it fairly carefully, and it all looks good to me.

Just as evidence I've looked through it, one not-very-relevant thought: it feels slightly redundant in some sense to index a hash map with ShaderAndHash, when we assume that MurmurHash can never collide , so in theory you could just append the shader pointer to the hash, and just store the hash. But I don't think there would be any noticeable performance benefit to doing that, and the current code documents it's intent better, so after thinking about it I concluded that the current approach is probably correct.

source = activeInPlug->source();
}
return { nullptr, nullptr };
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we need to return a pair from this function instead of just returning source? I can't see any scenario where result.first is set to anything other than result.second->node(), unless result.second == nullptr, which would be just as easy to check for as checking if the separate first argument is nullptr?

Copy link
Member Author

Choose a reason for hiding this comment

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

All the clients of the old sourceShader() had an additional level of nesting to get the Shader and check it wasn't null, and I wanted to get rid of that. I could return a null plug if the shader is null though, and then have the clients static_cast<const Shader *>( plug->node() ) instead of doing their own checks. Maybe that's worth it?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, I was thinking of doing the test if the shader is valid and returning a null plug if it isn't valid. I have a pretty strong preference for passing around as little information as possible, and this interface feels a little odd to me - there are basically 3 return values, 2 in a pair, and 1 in reference argument. I would prefer the if there was a single return value ... but it is just aesthetics and not really that important. Kinda just felt like I should comment something after reading this much code.

Copy link
Member Author

Choose a reason for hiding this comment

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

I've pushed a fixup which just returns a const Plug * and derives the shader from that in all the clients :

e903324

Copy link
Contributor

Choose a reason for hiding this comment

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

LGTM

@johnhaddon johnhaddon force-pushed the contextProcessorsInShaders branch from e903324 to 22ac984 Compare January 17, 2025 09:29
@johnhaddon johnhaddon merged commit e32af24 into GafferHQ:1.5_maintenance Jan 17, 2025
5 checks passed
@johnhaddon johnhaddon deleted the contextProcessorsInShaders branch January 21, 2025 10:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Pending release
Development

Successfully merging this pull request may close these issues.

2 participants