-
Notifications
You must be signed in to change notification settings - Fork 855
Workaround for an issue with local keyword and shadergraph preview material. #1073
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
Workaround for an issue with local keyword and shadergraph preview material. #1073
Conversation
I have a question for Shader Graph team. Can't we have all keyword use in preview local? It make no sense to have something global as there is no stripping required anyway for preview shader (global keyword are the only one which can be stripped) |
Actually I think the keyword is always declared as local, but when the definition is not there and the shader searches for one (when enabling/disabling I think), then a global one is created internally. |
ok, talked with Francesco, misunderstanded the issue. Problem is that there is no keyword ALPHA_TEST generate in the preview shader. so need to check that. |
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.
Workaround seems to work great! Not getting anymore keyword exceptions while switching between Decal/Lit/Unlit and having Alpha Clipping enabled/disabled.
Checked that Decal, Unlit, Lit material types are still rendering correctly in transparent and opaque modes.
Merging this fix for the package. |
ShaderUtil.UpdateShaderAsset(shaderData.shader, shaderStr, false); | ||
} | ||
|
||
CoreUtils.Destroy(shaderData.mat); |
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.
@sebastienlagarde Why do we want to destroy the Material here?
Does this magically set shaderData.mat to null? Otherwise the material might get stuck in a "destroyed but not null" state...
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.
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 actually got confused here and I thought it did (our HD util that destroys does set to null, while coreutils. seems not to).
I am curious on why it did not break though. Visually everything seems to work fine (and QA tested :/ )
On the why: it was a workaround that seemed to work as in the keywords were not queried wrongly but the preview material. This is something that was planned to be reverted as soon as the original bug gets fixed.
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.
Will check tomorrow morning if adding the = null makes the workaround not work anymore :D
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.
Make sure to test it with modifying the upstream graph of a preview node several times. That should cause this code to be called repeatedly.
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 tested it locally, seems to work.
I think it's because of this:
https://forum.unity.com/threads/unitys-magic-null-check-not-properly-documented.408135/
"Destroyed" objects are "equal" to null.. :)
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.
:D
Ok, to keep it clear I am gonna add the = null assignment anyway, but glad that nothing is broken.
Spent a very long time trying to debug this, the bottom line is that the issue is likely on the local_keyword system on C++ side and shader team wants to look at that more deep.
In any case the following seems to provide a workaround for https://fogbugz.unity3d.com/f/cases/1259744/
QA: Please verify if the workaround does fix the issue, but do not resolve the bug since I need to forward it later on.