Skip to content

Conversation

FrancescoC-unity
Copy link
Contributor

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.

@FrancescoC-unity FrancescoC-unity requested review from a team, alelievr and sebastienlagarde July 1, 2020 15:13
@FrancescoC-unity FrancescoC-unity requested a review from a team as a code owner July 1, 2020 15:13
@FrancescoC-unity FrancescoC-unity self-assigned this Jul 1, 2020
@sebastienlagarde
Copy link
Contributor

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)

@FrancescoC-unity
Copy link
Contributor Author

FrancescoC-unity commented Jul 1, 2020

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.

@sebastienlagarde
Copy link
Contributor

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.

Copy link
Contributor

@TomasKiniulis TomasKiniulis left a 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.

@sebastienlagarde sebastienlagarde changed the base branch from HDRP/staging to master July 3, 2020 09:20
@sebastienlagarde sebastienlagarde changed the base branch from master to HDRP/staging July 3, 2020 09:20
@sebastienlagarde
Copy link
Contributor

Merging this fix for the package.

@sebastienlagarde sebastienlagarde merged commit 4bb33d6 into HDRP/staging Jul 4, 2020
@sebastienlagarde sebastienlagarde deleted the HDRP/workaround-local-shader-keyword-issue branch July 4, 2020 19:06
ShaderUtil.UpdateShaderAsset(shaderData.shader, shaderStr, false);
}

CoreUtils.Destroy(shaderData.mat);

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...

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor Author

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.

Copy link
Contributor Author

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

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.

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.. :)

Copy link
Contributor Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants