Skip to content

[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

Merged
merged 74 commits into from
Apr 29, 2021
Merged
Show file tree
Hide file tree
Changes from 54 commits
Commits
Show all changes
74 commits
Select commit Hold shift + click to select a range
613a536
Working transparent/opaque switch
Feb 27, 2021
5d4ffac
Working surface type, cull mode, and alpha clip
Feb 27, 2021
aa88cf4
Fix for Unlit alpha test shadows
Mar 1, 2021
c11b947
Workflow Mode switch working on Lit
Mar 1, 2021
9a9f688
Lit AlphaTest working
Mar 1, 2021
ff00c31
Fix for Lit ReceiveShadows checkbox
Mar 1, 2021
10b540b
Draw shadergraph properties in material inspector
Mar 1, 2021
ca653cb
Cleanup, Setting up Target defaults correctly
Mar 1, 2021
d131202
Fix for error spew from inspector on blank graphs
Mar 2, 2021
4afe766
Cast Shadows Toggle
Mar 3, 2021
954ab83
Adding LinearGrey and Red default texture options
Mar 3, 2021
24ea748
Adding stage options to Keywords, fixing Keyword control in BaseShade…
Mar 4, 2021
39ea696
Fix for collision with HDRP property names, fix keyworddescriptor wit…
Mar 5, 2021
4190ef4
Fix Previews, Convert target "Two Sided" checkbox to "Render Face" en…
Mar 26, 2021
1a47133
Fix for transparent blending with alpha
Mar 26, 2021
2c94bc6
Missing setup for transparent blending with alpha
Mar 26, 2021
6589a2d
Fix for material alpha clip when shader alpha clip disabled
Mar 26, 2021
31637a2
Make SubTarget UI the same as Material UI, and add cast/receive shado…
Mar 26, 2021
6a5c9e6
Remove debug log spew
Mar 26, 2021
7772681
Add workflow mode material control checkbox, fix default preview prop…
Mar 30, 2021
e126fca
Fixing cull mode in shadow and depth-only passes, removing unused fie…
Mar 30, 2021
8859752
Removing unused PBRMasterGUI, cleaning up code and comments, fixing e…
Apr 1, 2021
aea47f5
Fixing predefined keyword -- should not define anything
Apr 1, 2021
6b7f6bd
Merge branch 'master' into sg/urp-uber
Apr 1, 2021
c489b0c
Keyword test fix
Apr 1, 2021
7a56f74
Add "ShaderGraphShader" tag to all SubTargets. Fix for errors when c…
Apr 2, 2021
1ab31e2
Add versioning to shadergraph materials
Apr 2, 2021
8115bf5
Use UniversalMetadata approach
Apr 2, 2021
0056a1e
Cleanup warning spew
Apr 3, 2021
2aa23b7
Fix for toggles in UI
Apr 3, 2021
9fe609d
Renaming conflicting properties in test shader
Apr 5, 2021
2910fb8
Fixing a warning/error in a test shader in OpenGL (doesn't allow "__"…
Apr 5, 2021
340d10c
Fix for coat mask support when using GL
Apr 5, 2021
e77c2c7
Uniquely named URP surface properties
Apr 7, 2021
53b1b0d
Moving keyword strings to central location
Apr 7, 2021
9578886
Adding Depth Test control, fixing error when selecting Lit.shader
Apr 9, 2021
fb46581
Texture2D properties using Bump default will now be marked with [Norm…
Apr 9, 2021
50114d8
Adding zwrite controls
Apr 9, 2021
17a7867
Unify common target UI
Apr 12, 2021
3f45746
Removing unnecessarily added render pipeline assets
Apr 12, 2021
0a17c4f
Fixing shadergraph material versioning so it only applies to shadergr…
Apr 12, 2021
ae32e7c
Reverting unnecessary changes to test project
Apr 13, 2021
38d5c57
Cleaned up GUI code
Apr 13, 2021
7438249
Removing unused files, cleanup SubTargets
Apr 13, 2021
9fc1398
More target code cleanup
Apr 13, 2021
7103f4c
Adding "Allow Material Override" checkbox. Fixing a few issues with …
Apr 16, 2021
3268688
Switching to Option 3 (and cleanup)
Apr 16, 2021
5ae7a71
Adding auto-update to Materials (temp solution until AssetDB dependen…
Apr 19, 2021
8a5e821
Adding changelogs
Apr 19, 2021
80309ff
Fix for warning
Apr 19, 2021
5be1912
Removing Material v5 Versioning -- not necessary anymore with "Allow …
Apr 19, 2021
bf075b4
Code cleanup pass
Apr 19, 2021
c5869be
More code cleanup, consolidating string declarations and moving code …
Apr 20, 2021
5ef9cbe
Renaming URPLitGui to ShaderGraphLitGUI (and the same for unlit)
Apr 20, 2021
19958f1
Fixup emission properties for ShaderGraph -- don't use hard-coded Lit…
Apr 20, 2021
731d4c9
Cleaning up GI material code, introducing MaterialUpdateType, so we c…
Apr 21, 2021
41581e1
ShaderGraph Materials should always allow direct user control for dou…
Apr 21, 2021
c09117c
Merge branch 'master' into sg/urp-uber
Apr 21, 2021
8ce3904
Fix incorrect conflict merge
Apr 21, 2021
a830886
Adding 050_Shader_Graphs_Override test
Apr 21, 2021
6b6a97f
Hooking up the new test scene
Apr 22, 2021
61e1f44
Removing ZTestMode.Disabled as an option
Apr 22, 2021
4010912
Disabling DepthOnly pass when zwrite is off, removing it from shader …
Apr 22, 2021
2684ca8
Fix syntax error, moving global illumination settings to advanced sec…
Apr 22, 2021
c187236
Moving "Allow Material Override" checkbox above the "workflow mode" s…
Apr 23, 2021
828cfae
Merge branch 'sg/urp-uber-tests' into sg/urp-uber
Apr 23, 2021
5c5f64c
Addressing feedback
Apr 27, 2021
e748dc8
Getting rid of error spew by matching property type to HDRP
Apr 27, 2021
e0d8306
Fixing unreachable code warnings, and fixing colliding keyword (_SURF…
Apr 27, 2021
877125c
Merge branch 'master' into sg/urp-uber
Apr 27, 2021
bcbb7f9
Fixing merge issues
Apr 27, 2021
ce87a2f
Removing automatic RenderQueue calculation behavior from ShaderGraph …
Apr 28, 2021
f4e57f3
Ensuring the GI controls on URP ShaderGraph Materials are identical t…
Apr 28, 2021
ebe155c
Merge branch 'master' into sg/urp-uber
Apr 29, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -195,11 +195,7 @@ public void CanGetKeywordDeclarationForReals()
var sb = new ShaderStringBuilder();
foreach (var keyword in m_Collector.keywords)
{
string declaration = keyword.GetKeywordDeclarationString();
if(!string.IsNullOrEmpty(declaration))
{
sb.AppendLine(declaration);
}
keyword.AppendKeywordDeclarationStrings(sb);
Copy link
Author

Choose a reason for hiding this comment

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

This more optimal form just appends the keyword declaration string directly into the builder... no temp string GC allocs

}

Assert.AreEqual(kExpectedForRealsDeclaration.Replace("\r\n", "\n"), sb.ToString(), "Keyword declaration snippet for final shader was invalid");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ public IEnumerator RemoveInputTests()
var menuItems = m_BlackboardTestController.addBlackboardItemsMenu.GetPrivateProperty<IList>("menuItems");
Assert.IsNotNull(menuItems, "Could not retrieve reference to the menu items of the Blackboard Add Items menu");

// invoke all menu items on the "add Blackboard Items Menu" to add all property types
foreach (var item in menuItems)
{
var menuFunction = item.GetNonPrivateField<GenericMenu.MenuFunction>("func");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1124,7 +1124,7 @@
},
"m_Name": "A",
"m_DefaultReferenceName": "Vector1_e29cd19dafd54a1dbd31dcf1d75c21b2",
"m_OverrideReferenceName": "a_3_4_d__",
Copy link
Author

Choose a reason for hiding this comment

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

Fixing an issue with this test on GL devices -- not allowed to use double underscore in identifiers.

"m_OverrideReferenceName": "a_3_4_d_",
"m_GeneratePropertyBlock": true,
"m_Precision": 0,
"m_GPUInstanced": false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ static void ShaderGraphStack(Material material, HDShaderUtils.ShaderID id)
{
Shader shader = material.shader;

if (shader.IsShaderGraph())
if (shader.IsShaderGraphAsset())
{
if (shader.TryGetMetadataOfType<HDMetadata>(out var obj))
{
Expand Down Expand Up @@ -375,7 +375,7 @@ static void ShaderGraphStack(Material material, HDShaderUtils.ShaderID id)

static void MoreMaterialSurfaceOptionFromShaderGraph(Material material, HDShaderUtils.ShaderID id)
{
if (material.shader.IsShaderGraph())
if (material.IsShaderGraph())
{
// Synchronize properties we exposed from SG to the material
ResetFloatProperty(kReceivesSSR);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ protected override bool DoShadersStripper(HDRenderPipelineAsset hdrpAsset, Shade
// Cache Shader Graph lookup data so we don't continually keep reloading graphs from disk.
// TODO: Should really be able to answer the questions "is shader graph" and "uses HDLitMasterNode" without
// hitting disk on every invoke.
if (shader.IsShaderGraph())
if (shader.IsShaderGraphAsset())
{
if (shader.TryGetMetadataOfType<HDMetadata>(out var obj))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ protected override void OnGUIOpen()
DrawLitSurfaceOptions();
}

bool AreMaterialsShaderGraphs() => materials.All(m => m.shader.IsShaderGraph());
bool AreMaterialsShaderGraphs() => materials.All(m => m.IsShaderGraph());

/// <summary>Returns false if there are multiple materials selected and they have different default values for propName</summary>
float GetShaderDefaultFloatValue(string propName)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@ protected override bool showSection
return false;

// If refraction model is not enabled in SG, we don't show the section
var shader = materials[0].shader;
if (shader.IsShaderGraph())
if (materials[0].IsShaderGraph())
{
var shader = materials[0].shader;
var defaultRefractionModel = shader.GetPropertyDefaultFloatValue(shader.FindPropertyIndex(kRefractionModel));
if (defaultRefractionModel == 0)
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ public static void SetupMainTexForAlphaTestGI(this Material material, string col

static public void SetupBaseUnlitPass(this Material material)
{
if (material.shader.IsShaderGraph())
if (material.IsShaderGraph())
{
// Shader graph generate distortion pass only if required. So we can safely enable it
// all the time here.
Expand Down Expand Up @@ -360,7 +360,7 @@ static public void SetupBaseUnlitPass(this Material material)

// Shader graphs materials have their own management of motion vector pass in the material inspector
// (see DrawMotionVectorToggle())
if (!material.shader.IsShaderGraph())
if (!material.IsShaderGraph())
{
//In the case of additional velocity data we will enable the motion vector pass.
bool addPrecomputedVelocity = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ internal static bool IsHDRPShader(Shader shader, bool upgradable = false)
if (shader == null)
return false;

if (shader.IsShaderGraph())
if (shader.IsShaderGraphAsset())
{
// All HDRP shader graphs should have HD metadata
return shader.TryGetMetadataOfType<HDMetadata>(out _);
Expand All @@ -140,7 +140,7 @@ internal static bool IsUnlitHDRPShader(Shader shader)
if (shader == null)
return false;

if (shader.IsShaderGraph())
if (shader.IsShaderGraphAsset())
{
// Throw exception if no metadata is found
// This case should be handled by the Target
Expand Down Expand Up @@ -168,7 +168,7 @@ internal static string GetShaderPath(ShaderID id)

internal static ShaderID GetShaderEnumFromShader(Shader shader)
{
if (shader.IsShaderGraph())
if (shader.IsShaderGraphAsset())
{
// Throw exception if no metadata is found
// This case should be handled by the Target
Expand Down
1 change: 1 addition & 0 deletions com.unity.render-pipelines.universal/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
### Changed
- Moved fog evaluation from vertex shader to pixel shader. This improves rendering of fog for big triangles and fog quality. This can change the look of the fog slightly.
- UNITY_Z_0_FAR_FROM_CLIPSPACE now remaps to [0, far] range on all platforms consistently. Previously OpenGL platforms did not remap, discarding small amount of range [-near, 0].
- Added "Allow Material Override" option to Lit and Unlit ShaderGraph targets. When checked, allows Material to control the surface options (transparent/opaque, blend mode, etc).

### Added
- Added View Vector node to mimic old behavior of View Direction node in URP.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
using System.Collections.Generic;
using System.Linq;
using UnityEditor.Rendering.Universal.ShaderGUI;
using UnityEditor.ShaderGraph;
using UnityEngine;
using UnityEngine.Rendering.Universal;
using static Unity.Rendering.Universal.ShaderUtils;

namespace UnityEditor.Rendering.Universal
{
Expand Down Expand Up @@ -89,7 +91,7 @@ class MaterialPostprocessor : AssetPostprocessor
internal static List<string> s_ImportedAssetThatNeedSaving = new List<string>();
internal static bool s_NeedsSavingAssets = false;

internal static readonly Action<Material, ShaderPathID>[] k_Upgraders = { UpgradeV1, UpgradeV2, UpgradeV3, UpgradeV4 };
internal static readonly Action<Material, ShaderID>[] k_Upgraders = { UpgradeV1, UpgradeV2, UpgradeV3, UpgradeV4 };

static internal void SaveAssetsToDisk()
{
Expand Down Expand Up @@ -119,23 +121,28 @@ static internal void SaveAssetsToDisk()

static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetPaths)
{
var upgradeLog = "UniversalRP Material log:";
string upgradeLog = "";
var upgradeCount = 0;

foreach (var asset in importedAssets)
{
// we only care about materials
if (!asset.EndsWith(".mat", StringComparison.InvariantCultureIgnoreCase))
continue;

// load the material and look for it's Universal ShaderID
// we only care about versioning materials using a known Universal ShaderID
// this skips any materials that only target other render pipelines, are user shaders,
// or are shaders we don't care to version
var material = (Material)AssetDatabase.LoadAssetAtPath(asset, typeof(Material));
if (!ShaderUtils.IsLWShader(material.shader))
var shaderID = GetShaderID(material.shader);
if (shaderID == ShaderID.Unknown)
continue;

ShaderPathID id = ShaderUtils.GetEnumFromPath(material.shader.name);
var wasUpgraded = false;
var debug = "\n" + material.name + "(" + shaderID + ")";

var debug = "\n" + material.name;

// look for the Universal AssetVersion
AssetVersion assetVersion = null;
var allAssets = AssetDatabase.LoadAllAssetsAtPath(asset);
foreach (var subAsset in allAssets)
Expand All @@ -154,13 +161,23 @@ static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAsse
{
assetVersion.version = k_Upgraders.Length;
s_CreatedAssets.Remove(asset);
InitializeLatest(material, id);
InitializeLatest(material, shaderID);
debug += " initialized.";
}
else
{
assetVersion.version = UniversalProjectSettings.materialVersionForUpgrade;
debug += $" assumed to be version {UniversalProjectSettings.materialVersionForUpgrade} due to missing version.";
if (shaderID.IsShaderGraph())
{
// ShaderGraph materials NEVER had asset versioning applied prior to version 5.
// so if we see a ShaderGraph material with no assetVersion, set it to 4 to ensure we apply all necessary versions.
assetVersion.version = 4;
debug += $" shadergraph material assumed to be version 4 due to missing version.";
}
else
{
assetVersion.version = UniversalProjectSettings.materialVersionForUpgrade;
debug += $" assumed to be version {UniversalProjectSettings.materialVersionForUpgrade} due to missing version.";
}
}

assetVersion.hideFlags = HideFlags.HideInHierarchy | HideFlags.HideInInspector | HideFlags.NotEditable;
Expand All @@ -169,7 +186,7 @@ static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAsse

while (assetVersion.version < k_Upgraders.Length)
{
k_Upgraders[assetVersion.version](material, id);
k_Upgraders[assetVersion.version](material, shaderID);
debug += $" upgrading:v{assetVersion.version} to v{assetVersion.version + 1}";
assetVersion.version++;
wasUpgraded = true;
Expand All @@ -184,62 +201,77 @@ static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAsse
s_NeedsSavingAssets = true;
}
}

// Uncomment to show upgrade debug logs
//if (!string.IsNullOrEmpty(upgradeLog))
// Debug.Log("UniversalRP Material log: " + upgradeLog);
}

static void InitializeLatest(Material material, ShaderPathID id)
static void InitializeLatest(Material material, ShaderID id)
{
// newly created materials should reset their keywords immediately (in case inspector doesn't get invoked)
Unity.Rendering.Universal.ShaderUtils.ResetMaterialKeywords(material, id);
}

static void UpgradeV1(Material material, ShaderPathID shaderID)
static void UpgradeV1(Material material, ShaderID shaderID)
{
var shaderPath = ShaderUtils.GetShaderPath(shaderID);
if (shaderID.IsShaderGraph())
return;

var shaderPath = ShaderUtils.GetShaderPath((ShaderPathID)shaderID);
var upgradeFlag = MaterialUpgrader.UpgradeFlags.LogMessageWhenNoUpgraderFound;

switch (shaderID)
{
case ShaderPathID.Unlit:
case ShaderID.Unlit:
MaterialUpgrader.Upgrade(material, new UnlitUpdaterV1(shaderPath), upgradeFlag);
UnlitShader.SetMaterialKeywords(material);
break;
case ShaderPathID.SimpleLit:
case ShaderID.SimpleLit:
MaterialUpgrader.Upgrade(material, new SimpleLitUpdaterV1(shaderPath), upgradeFlag);
SimpleLitShader.SetMaterialKeywords(material, SimpleLitGUI.SetMaterialKeywords);
break;
case ShaderPathID.Lit:
case ShaderID.Lit:
MaterialUpgrader.Upgrade(material, new LitUpdaterV1(shaderPath), upgradeFlag);
LitShader.SetMaterialKeywords(material, LitGUI.SetMaterialKeywords);
break;
case ShaderPathID.ParticlesLit:
case ShaderID.ParticlesLit:
MaterialUpgrader.Upgrade(material, new ParticleUpdaterV1(shaderPath), upgradeFlag);
ParticlesLitShader.SetMaterialKeywords(material, LitGUI.SetMaterialKeywords, ParticleGUI.SetMaterialKeywords);
break;
case ShaderPathID.ParticlesSimpleLit:
case ShaderID.ParticlesSimpleLit:
MaterialUpgrader.Upgrade(material, new ParticleUpdaterV1(shaderPath), upgradeFlag);
ParticlesSimpleLitShader.SetMaterialKeywords(material, SimpleLitGUI.SetMaterialKeywords, ParticleGUI.SetMaterialKeywords);
break;
case ShaderPathID.ParticlesUnlit:
case ShaderID.ParticlesUnlit:
MaterialUpgrader.Upgrade(material, new ParticleUpdaterV1(shaderPath), upgradeFlag);
ParticlesUnlitShader.SetMaterialKeywords(material, null, ParticleGUI.SetMaterialKeywords);
break;
}
}

static void UpgradeV2(Material material, ShaderPathID shaderID)
static void UpgradeV2(Material material, ShaderID shaderID)
{
if (shaderID.IsShaderGraph())
return;

// fix 50 offset on shaders
if (material.HasProperty("_QueueOffset"))
BaseShaderGUI.SetupMaterialBlendMode(material);
}

static void UpgradeV3(Material material, ShaderPathID shaderID)
static void UpgradeV3(Material material, ShaderID shaderID)
{
if (shaderID.IsShaderGraph())
return;

switch (shaderID)
{
case ShaderPathID.Lit:
case ShaderPathID.SimpleLit:
case ShaderPathID.ParticlesLit:
case ShaderPathID.ParticlesSimpleLit:
case ShaderPathID.ParticlesUnlit:
case ShaderID.Lit:
case ShaderID.SimpleLit:
case ShaderID.ParticlesLit:
case ShaderID.ParticlesSimpleLit:
case ShaderID.ParticlesUnlit:
var propertyID = Shader.PropertyToID("_EmissionColor");
if (material.HasProperty(propertyID))
{
Expand All @@ -254,8 +286,9 @@ static void UpgradeV3(Material material, ShaderPathID shaderID)
}
}

static void UpgradeV4(Material material, ShaderPathID shaderID)
{}
static void UpgradeV4(Material material, ShaderID shaderID)
{
}
}

// Upgraders v1
Expand Down
Loading