-
Notifications
You must be signed in to change notification settings - Fork 840
[2021.2] [ShaderGraph] URP Uber Shader #3705
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
Conversation
…rGUI material inspector, cleaning up keyword code generation
…um to match the material UI
…w toggles to the SubTarget UI
…erties for missing blocks
…lds and cleaning up code
# Conflicts: # com.unity.render-pipelines.universal/Editor/ShaderGUI/BaseShaderGUI.cs # com.unity.render-pipelines.universal/Editor/ShaderGUI/ShadingModels/LitGUI.cs # com.unity.render-pipelines.universal/Editor/ShaderGraph/Targets/UniversalLitSubTarget.cs # com.unity.shadergraph/Editor/Generation/Processors/Generator.cs
…lling PreviewMaterial setup on URP Lit shadergraphs (fixup code not designed to work on shadergraphs)
@phi-lira @eh-unity @Verasl @LandonTownsendUnity This PR is ready to go from my standpoint, all yamato tests passing, all of the feedback addressed: the default behavior is now identical to the old behavior (Target control), and the property and keyword names match Lit.shader / Unlit.shader. Please check if there is anything else that should be changed! I've got tests being added in a separate branch: sg/urp-uber-tests (all green so far there as well), but would like to get this large change in to unblock dependent work and avoid continuous master merge fixups and re-running yamato tests.. |
…entirely if we know it will never use zwrite enabled
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.
LGTM. Minor comments, missing public API docs.
Also, PBRMasterGUI.cs
file was deleted but I didn't see any .meta file being deleted for that?
com.unity.render-pipelines.universal/Editor/AssetPostProcessors/MaterialPostprocessor.cs
Outdated
Show resolved
Hide resolved
com.unity.render-pipelines.universal/Editor/ShaderGUI/BaseShaderGUI.cs
Outdated
Show resolved
Hide resolved
com.unity.render-pipelines.universal/Editor/ShaderGUI/BaseShaderGUI.cs
Outdated
Show resolved
Hide resolved
if (isShaderGraph) | ||
{ | ||
// Lit.shadergraph or Unlit.shadergraph, but no material control defined | ||
// enable the pass in the material, so shader can decide... | ||
castShadows = true; | ||
} | ||
else | ||
{ | ||
// Lit.shader or Unlit.shader -- set based on transparency | ||
castShadows = Rendering.Universal.ShaderGUI.LitGUI.IsOpaque(material); | ||
} |
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.
Thanks for handling this. I'll have a discussion with @Verasl I think URP team should align with ShaderGraph (we can do in follow up PR)
com.unity.render-pipelines.universal/Editor/ShaderGUI/BaseShaderGUI.cs
Outdated
Show resolved
Hide resolved
com.unity.render-pipelines.universal/Editor/ShaderGraph/Includes/DepthNormalsOnlyPass.hlsl
Show resolved
Hide resolved
com.unity.render-pipelines.universal/Editor/ShaderGraph/Targets/UniversalTarget.cs
Outdated
Show resolved
Hide resolved
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.
Looks pretty good to me.
|
||
// when the surface options are material controlled, we must show all of these blocks | ||
// when target controlled, we can cull the unnecessary blocks | ||
context.AddBlock(BlockFields.SurfaceDescription.Specular, (workflowMode == WorkflowMode.Specular) || target.allowMaterialOverride); |
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.
Since there are these clear sections for different "kinds" of blocks, perhaps we should separate them into internal helper functions?
if (target.mayWriteDepth) | ||
result.passes.Add(CorePasses.DepthOnly(target)); | ||
|
||
result.passes.Add(LitPasses.DepthNormalOnly(target)); |
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.
FYI, I added method chaining/fluent interface support to the shadergraph collections a while back. You could write these as result.passes.Add().Add().Add()...
I think this is fine as is not necessary to change.
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.
@cinight is on this PR and will test it, I am approving without testing.
…ACE_TYPE_TRANSPARENT) warnings
# Conflicts: # com.unity.render-pipelines.universal/CHANGELOG.md # com.unity.render-pipelines.universal/Editor/ShaderGraph/Targets/UniversalTarget.cs # com.unity.render-pipelines.universal/Editor/ShaderGraph/Targets/UniversalUnlitSubTarget.cs # com.unity.shadergraph/CHANGELOG.md
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.
Developer manual testing is sufficient
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.
Approving now that the advanced controls are 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.
Purpose of this PR
This PR adds an "Allow Material Override" checkbox to Lit and Unlit subtargets, as well as controls for Cast and Receive Shadows, Depth Write and Depth Test.


By default, "Allow Material Override" will not be checked, both to preserve the behavior of existing shadergraphs, and to simplify the initial user experience. When checked, it allows the Material to control the following surface options (that were previously only controlled from the ShaderGraph):
For Lit subtargets:
For Unlit subtargets:
Example Unlit Material, when"Allow Material Override" is checked on the ShaderGraph:

It achieves this by modifying the subtargets to generate properties and keywords to control the surface options, in combination with a setup function that applies state updates to the Materials to control these properties and keywords: ShaderUtils.UpdateMaterial(material). To be able to run the correct update on each material, we created a ShaderID enum to identify the various Universal shader types, extending the existing ShaderPathID to include shadergraph generated shaders. We also attach metadata to Universal ShaderGraph assets, so we can tag them with their ShaderID. The helper function ShaderUtils.GetShaderID() is provided to get the ShaderID for any shader, either hand-written or shadergraph generated.
This PR also creates two new Material Inspectors: ShaderGraphLitGUI (for Lit subtarget), and ShaderGraphUnlitGUI (For Unlit subtarget) to handle displaying the surface controls appropriately, and calling the update function when needed.
These inspectors are based off of the BaseShaderGUI base class, so some changes are made to BaseShaderGUI so that it works with ShaderGraph shaders in addition to the existing hand-written shaders.
This PR also makes a few associated changes to ShaderGraph:
Adds "ShaderGraphShader"="True" tag to all ShaderGraph-built subshaders, allowing us to easily tell when a Material is a ShaderGraph (even if the ShaderGraph is not asset based). Added "Material.IsShaderGraph" utility function, and changed the old "Shader.IsShaderGraph" function to "Shader.IsShaderGraphAsset" to make it clear it only works on Assets.
Adds "Stages" dropdown to Keywords, allowing user to set up "Fragment" or "Vertex" only keywords to reduce compiled variants.

Adds linearGrey and red options as default texture mode, and changed the "bump" option to be called "Normal Map"

Texture2D properties using Normal Map (old "bump") default will now be marked with [NormalMap] tag, so that users are reminded to assign a normal map usage texture to that property.
Adds CastsShadows option (for Materials that use Lit/Unlit SubTargets)
Adds Depth Test control (for Materials that use Lit/Unlit SubTargets)
Made the SubTarget and Material controls look identical (same naming, same options available)


Testing status
Describe what manual/automated tests were performed for this PR
Tested:
Yamato:
ShaderGraph PR Job: 🟢
https://yamato.cds.internal.unity3d.com/jobs/902-Graphics/tree/sg%252Furp-uber/.yamato%252Fall-shadergraph.yml%2523PR_ShaderGraph_trunk/6559408/job/pipeline
Universal PR Job: matches equivalent master results 🟢
https://yamato.cds.internal.unity3d.com/jobs/902-Graphics/tree/sg%252Furp-uber/.yamato%252Fall-universal_split.yml%2523PR_Universal_Split_trunk/6560960/job/pipeline
failing jobs:
URP_PostPro on Win_DX11_Standalone_XR_cache_mono_Linear on version trunk -- same 24/55 tests failed.
URP_PostPro on Win_DX11_playmode_XR_cache_mono_Linear on version trunk -- same 24/55 tests failed.
URP_PostPro on Win_DX12_Standalone_XR_cache_mono_Linear on version trunk -- same 24/55 tests failed.
URP_PostPro on OSX_Metal_playmode_cache_mono_Linear on version trunk -- success on re-run
URP_Lighting on Win_DX11_Standalone_XR_cache_mono_Linear on version trunk -- same 28/75 tests failed.
URP_Lighting on Win_DX11_playmode_XR_cache_mono_Linear on version trunk -- same 28/94 tests failed.
URP_Lighting on Win_DX12_Standalone_XR_cache_mono_Linear on version trunk -- same 28/75 tests failed.
URP_Foundation on Win_DX11_Standalone_cache_mono_Linear on version trunk -- success on re-run
URP_Foundation on Win_DX11_Standalone_XR_cache_mono_Linear on version trunk -- same 60/94 tests failed.
URP_Foundation on Win_DX11_playmode_XR_cache_mono_Linear on version trunk -- same 60/113 tests failed.
URP_Foundation on Win_DX12_Standalone_XR_cache_mono_Linear on version trunk -- same 60/94 tests failed.
URP_Foundation on OSX_Metal_playmode_cache_mono_Linear on version trunk -- success on re-run
URP_Terrain on Win_DX11_playmode_XR_cache_mono_Linear on version trunk -- same 8/68 tests failed.
URP_2D on Win_DX11_playmode_XR_cache_mono_Linear on version trunk -- same 18/74 tests failed.
URP_2D on OSX_OpenGLCore_editmode_mono_Linear on version trunk -- same 1/63 tests failed.
URP_2D on Win_DX11_editmode_mono_Linear on version trunk -- same 1/63 tests failed.
equivalent master version: ed96290
master failing job;
https://yamato.cds.internal.unity3d.com/jobs/902-Graphics/tree/master/.yamato%252Fall-universal_split.yml%2523Nightly_Universal_Split_trunk/6518789/job/pipeline
HDRP PR Job: 🟢
https://yamato.cds.internal.unity3d.com/jobs/902-Graphics/tree/sg%252Furp-uber/.yamato%252Fall-hdrp.yml%2523PR_HDRP_trunk/6433493/job/pipeline
latest after merge: lots of failures, but matches trunk 🟢
https://yamato.cds.internal.unity3d.com/jobs/902-Graphics/tree/sg%252Furp-uber/.yamato%252Fall-hdrp.yml%2523PR_HDRP_trunk/6567033/job/pipeline
rerunning:
Build HDRP on Win_DX11_mono_Linear_Standalone_cache_build_Player on version trunk
HDRP on Win_DX11_editmode_mono_Linear on version trunk
Comments to reviewers
Notes for the reviewers you have assigned.
Discovered Issues for emulating Lit.Shader / Unlit.Shader,
These won't necessarily be fixed in this PR, I'm just noting the issue for future work on the Lit.shadergraph:
Issues Found, that are Not Fixed / by design for now: