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

Adding "Allow Material Override" option to BuiltIn Targets #4637

Merged
merged 16 commits into from
Jun 10, 2021

Conversation

joshua-davis
Copy link
Contributor

@joshua-davis joshua-davis commented May 25, 2021

Please read the Contributing guide before making a PR.

Checklist for PR maker

  • Have you updated the changelog? Each package has a CHANGELOG.md file.
  • Have you added a graphic test for your PR (if needed)? When you add a new feature, or discover a bug that tests don't cover, please add a graphic test.

Purpose of this PR

The BuiltIn target was implemented with material override, but this was always true and couldn't be controlled via the shader graph. This PR is making the built-in target match URP by adding an option to shader graph to specify if the surface options should be controlled by the material or by the target on the shader graph.


Testing status

  • For Material Override true (for both lit and unlit):
    • Tested that assigning a new Shader to a Material will reset keywords properly
    • Tested that newly created Materials have their keywords set up properly even if the inspector is not visible or run.
    • Tested combinations of different Target settings, to see that they modify the default properties in the generated shader, and will populate newly created Materials with those defaults.
    • Tested all cull mode settings (front/back/both) on Material
    • Tested setting Opaque/Transparent, and all blend modes on Material
    • Tested enabling/disabling alpha clipping on Material
    • Tested Depth Write and Depth Test settings on Material
  • For Material Override false (for both lit and unlit):
    • Tested that assigning a new Shader to a Material will reset keywords properly
    • Tested that newly created Materials have their keywords set up properly even if the inspector is not visible or run.
    • Tested combinations of different Target settings, to see that they modify the default properties in the generated shader, and will populate newly created Materials with those defaults.
    • Tested all cull mode settings (front/back/both) on Target
    • Tested setting Opaque/Transparent, and all blend modes on Target
    • Tested enabling/disabling alpha clipping on Target
    • Tested Depth Write and Depth Test settings on Target
  • Test swapping material's shader graph to another shader graph:
    • Swap from material override false to material override true
    • Swap from material override true to material override false
  • Tested pre-existing BuiltIn graphs get upgraded correctly (as material override true)
  • Verified that shadergraph master previews show up correctly with BuiltIn Lit/Unlit subtarget, and selecting various combinations of default surface settings on them

Additional tests for extra bugs found:

  • Set an unlit shader to transparent. Set the alpha mode to "premultiply". Set the target back to opaque. This should properly compile and draw (used to be a shader error).
  • The "Disabled" mode for ZTest is now gone
    • Setting all of the ZTest modes in the target still produce the correct value in the shader
    • Setting all of the ZTest modes on the material when in "Allow Material Override" produce the correct values (verified both from rendering and inspecting the material with the inspector's debug mode).

Comments to reviewers

In the added test project, a duplicate shader graph has to be added due to an existing bug not related to the built-in target: https://fogbugz.unity3d.com/f/cases/1328077/
A few addition bugs found:

  • Additive blend mode for material override got broken but the graphics tests weren't sensitive enough to catch it before. Updated the sensitivity on the tests
  • A shader compiler could happen in unlit if the material was opaque but the alpha mode was pre-multiply (depending on the last state it was set to).
  • The ZTest mode exposed "Disabled" which isn't valid inside a shader.
  • BuiltInUnlitSubtarget didn't inherit from the proper base class. This fixes a case where changing shaders on a material when "Allow Material Override" was true wasn't working. This is because no metadata was saved so the inspector didn't know what the inspector to use to update material keywords.

… override, the surface type was opaque, and the blend mode was pre-multiply.

The code just needed to use the local variable for alpha.
…ader. Fixed up the relevant property drawers to correclty handle the missing gap in the enum as well
Copy link
Contributor

@jessebarker jessebarker left a comment

Choose a reason for hiding this comment

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

LGTM

@joshua-davis joshua-davis marked this pull request as ready for review May 26, 2021 17:24
@joshua-davis joshua-davis requested a review from a team as a code owner May 26, 2021 17:24
@joshua-davis joshua-davis changed the title Adding "Allow Material Override" option to BuiltIn Targets (in progress) Adding "Allow Material Override" option to BuiltIn Targets May 26, 2021
@@ -179,7 +181,7 @@ public static void SetupSurface(Material material)
else if (blendMode == BlendMode.Premultiply)
SetBlendMode(material, UnityEngine.Rendering.BlendMode.One, UnityEngine.Rendering.BlendMode.OneMinusSrcAlpha);
else if (blendMode == BlendMode.Additive)
SetBlendMode(material, UnityEngine.Rendering.BlendMode.One, UnityEngine.Rendering.BlendMode.One);
SetBlendMode(material, UnityEngine.Rendering.BlendMode.SrcAlpha, UnityEngine.Rendering.BlendMode.One);
Copy link
Contributor

Choose a reason for hiding this comment

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

Was this found to be incorrect before?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was previously using SrcAlpha here:
https://github.com/Unity-Technologies/Graphics/pull/4146/files#diff-367c30015afe895e9632641c20999255654e8fd31366a60bd2ab17e195c38f77L478
When doing the material override stuff before I incorrectly changed this but the tests weren't sensitive enough to catch the error. I've upped the sensitivity so they would fail now on this change

@joshua-davis joshua-davis requested a review from a team May 27, 2021 14:38
Copy link
Contributor

@GrantLamb-Unity GrantLamb-Unity left a comment

Choose a reason for hiding this comment

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

Excellent work on testing, finding bugs, and following them up with fixes.

@joshua-davis joshua-davis merged commit 4167505 into master Jun 10, 2021
@joshua-davis joshua-davis deleted the sg/builtin-material-override branch June 10, 2021 18:01
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.

4 participants