-
Notifications
You must be signed in to change notification settings - Fork 358
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
Unlit shader fails code generation when used with <mix>
node.
#2015
Comments
This is a great observation, @ld-kerley, and I would expect the I would guess that this is just an untested edge case for OSL shader generation, though I'm CC'ing @niklasharrysson in case he has additional insights. |
I would also expect a mix of any two surfaceshaders to work, including unlit ones. For example just to mask out difference parts of a surface horizontally. So I agree, this looks like an edge case we just haven't tested properly. The proposed fix looks good to me. At least by a quick look I can't see a good reason for not classifying |
Sounds great - I'll put together a quick PR with the proposed change. |
Digging deeper here When @niklasharrysson added the
The result of this call is used here
And without I can obviously remove the One approach might be to remove the |
The intent of the UNLIT classification is to optimize the shader and avoid adding a light loop and all other code for lighting, when this is not needed. So it serves a good purpose. But perhaps the tracking of the classification is not working as expected then. The classification of the graph should not be set to UNLIT for any inclusion of a Will need to investigate further how this tracking behaves in the case of |
I can't reproduce the second issue you got where compilation fails because of a missing DIRECTIONAL_ALBEDO_METHOD. If I change the code to your proposed change, the test case you have above works for me. No compilation errors and the rendered result looks correct. I also tried mixing a |
@niklasharrysson Thanks for clarifying for me what the intention of Sorry I wasn't clear - I get the compile errors because I think what's happening here, is that with the patch all the materials are being tagged as I think perhaps the more correct patch would be...
To just add the I did notice that with this patch then if I
returns |
Hi @ld-kerley , I'm no seeing this on my end. This is my code with the patch.
Only But I think you are right that classification tracking is not correct for the mix node. If both nodes connected upstream are UNLIT it will still just classify as a normal surface shader, since we only match the nodedef here. For a mix node we need to check the upstream nodes. So currently it will add the lighting code unnecessarily in that case. But I think this can be resolve as a separate issue. |
Given the following material:
Generating the OSL shader code yields this the following abbreviated code.
The
surface_unlit_out
variable is missing. This is due to the code generation for the mix surfaceshader nodeemitting calls for its inputs with the CLOSURE classification (see here) which unlit shaders don't have.
On initial investigations this could be resolved by changing the code in
ShaderNode.cpp
.With this patch then we generate valid OSL code.
But then I found Issue #839 - which then made me wonder if this incompatibility is intentional? The issue appears to describe the
<unlit>
material as a container for non-pbr style materials, that perhaps is intentionally incompatible with thepbrlib
nodes. If this is the case then I think we should update the specification to disallow the combination of<unlit>
with otherpbrlib
nodes, and then also introduce some sort of validation to report to the user if they unintentionally combine these two incompatible concepts.The text was updated successfully, but these errors were encountered: