-
-
Notifications
You must be signed in to change notification settings - Fork 35.5k
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
WebGPURenderer: Add shadowNode
to NodeMaterial
#27625
Conversation
This is an area where I thought nodes could provide simpler and more intuitive behavior. One common issue for users at the moment is that custom shaders that discard or perturb vertices don't just render a correct shadow map. I'm wondering if the rendered shadow object could just implicitly use the discard logic used in the color node path rather than requiring the use to remake it for the shadow node. And if a user wants a different custom shadow behavior then they can plug it in. |
examples/webgpu_shadowmap.html
Outdated
materialCustomShadow.shadowNode = tslFn( () => { | ||
|
||
discardNode.discard(); | ||
|
||
return vec4( 1. ); | ||
|
||
} )(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I noticed that when commenting only this shadowNode
line out neither the object surface nor the shadow have discard behavior even those the "colorNode" is still calling the discard node. Is this correct?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah yes, it's because it wasn't a NodeMaterial (it should be MeshPhongNodeMaterial
instead of MeshPhongMaterial
)
Currently, the shadow map system already inherits from the So vertex wise shadow maps are already good and aligned with the custom node material (with What are your thoughts on this @sunag? |
Can you please explain this more? I don't really understand... |
I think that |
I added opacity and shadow color by material in this PR, I think it was closer to what I mentioned here #27625 (comment). |
I'm going to make some revisions, I think we can launch it in this release :) |
Admittedly I haven't used the nodes system extensively but one of the benefits of nodes as I've seen is the simpler ability to traverse the graph of shader operations. If "discard" operations are modeled as terminating nodes here (ie a node with no descendants), then it should be possible to find all those "discard" nodes, prune any nodes & connections that don't feed into them upstream, and generate a node graph of operations relevant for the shadow map. Am I misunderstanding something? It's definitely something for the future and the approach in this PR is good and worth having for custom shadow behavior. But I think it would be worth tracking the above since I think this is something that a node material system should enable. |
Thanks @sunag it's a lot better this way! I see @gkjohnson, it makes a lot of sense. Definitely something we can explore in the future 👍 |
This doesn't really sound similar to what internally happens in the Nodes system... The closest to this which I can recall is |
I guess what I'm getting at is that notionally this is something that should be possible when you have a shader graph - the ability to procedurally analyze, modify, and build sibling graphs is powerful. This can be used for optimization (auto deduping of nodes), material model replacement (ie change from standard to phong or custom by without losing the inputs), etc. Maybe @sunag has thoughts on how possible this is now? |
@gkjohnson I agree, I think we have already done some things in this regard, for example:
There are probably more things that I didn't remember, but there are certainly things to be developed in this regard. |
This PR adds a way to control the shadow at a fragment level (discard pixels for example).
Updated
webgpu_shadowmap example
:This contribution is funded by Utsubo