diff --git a/com.unity.render-pipelines.high-definition/CHANGELOG.md b/com.unity.render-pipelines.high-definition/CHANGELOG.md index 17c57ca6cb0..f2976683c90 100644 --- a/com.unity.render-pipelines.high-definition/CHANGELOG.md +++ b/com.unity.render-pipelines.high-definition/CHANGELOG.md @@ -674,6 +674,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - Fixed issue with blue line in prefabs for volume mode. - Fixing the internsity being applied to RTAO too early leading to unexpected results (1254626). - Fix issue that caused sky to incorrectly render when using a custom projection matrix. +- Fixed null reference exception when using depth pre/post pass in shadergraph with alpha clip in the material. ### Changed - Improve MIP selection for decals on Transparents diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/Eye/ShaderGraph/CreateEyeShaderGraph.cs b/com.unity.render-pipelines.high-definition/Editor/Material/Eye/ShaderGraph/CreateEyeShaderGraph.cs index 91f5a923888..954a0ea8bc8 100644 --- a/com.unity.render-pipelines.high-definition/Editor/Material/Eye/ShaderGraph/CreateEyeShaderGraph.cs +++ b/com.unity.render-pipelines.high-definition/Editor/Material/Eye/ShaderGraph/CreateEyeShaderGraph.cs @@ -18,7 +18,7 @@ public static void CreateEyeGraph() BlockFields.VertexDescription.Tangent, BlockFields.SurfaceDescription.BaseColor, BlockFields.SurfaceDescription.NormalTS, - HDBlockFields.SurfaceDescription.IrisNormal, + HDBlockFields.SurfaceDescription.IrisNormalTS, HDBlockFields.SurfaceDescription.BentNormal, BlockFields.SurfaceDescription.Smoothness, HDBlockFields.SurfaceDescription.IOR, diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/Eye/ShaderGraph/EyeData.cs b/com.unity.render-pipelines.high-definition/Editor/Material/Eye/ShaderGraph/EyeData.cs index c8db2ed1406..e249bdbeb66 100644 --- a/com.unity.render-pipelines.high-definition/Editor/Material/Eye/ShaderGraph/EyeData.cs +++ b/com.unity.render-pipelines.high-definition/Editor/Material/Eye/ShaderGraph/EyeData.cs @@ -27,5 +27,13 @@ public bool subsurfaceScattering get => m_SubsurfaceScattering; set => m_SubsurfaceScattering = value; } + + [SerializeField] + bool m_IrisNormal = false; + public bool irisNormal + { + get => m_IrisNormal; + set => m_IrisNormal = value; + } } } diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/Eye/ShaderGraph/EyePass.template b/com.unity.render-pipelines.high-definition/Editor/Material/Eye/ShaderGraph/EyePass.template index 1cc6e8fbd65..ed71fbb46ac 100644 --- a/com.unity.render-pipelines.high-definition/Editor/Material/Eye/ShaderGraph/EyePass.template +++ b/com.unity.render-pipelines.high-definition/Editor/Material/Eye/ShaderGraph/EyePass.template @@ -182,18 +182,15 @@ Pass $SurfaceDescription.SubsurfaceMask: surfaceData.subsurfaceMask = surfaceDescription.SubsurfaceMask; - // tangent-space normal - float3 normalTS = float3(0.0f, 0.0f, 1.0f); - $SurfaceDescription.NormalTS: normalTS = surfaceDescription.NormalTS; - - // compute world space normal - GetNormalWS(fragInputs, normalTS, surfaceData.normalWS, doubleSidedConstants); - - float3 irisNormalTS = normalTS; // By default Iris normal is same as normal - $SurfaceDescription.IrisNormal: irisNormalTS = surfaceDescription.IrisNormal; - - // compute world space normal - GetNormalWS(fragInputs, irisNormalTS, surfaceData.irisNormalWS, doubleSidedConstants); + // normal delivered to master node + $SurfaceDescription.NormalOS: surfaceData.normalWS = TransformObjectToWorldNormal(surfaceDescription.NormalOS); + $SurfaceDescription.NormalTS: GetNormalWS(fragInputs, surfaceDescription.NormalTS, surfaceData.normalWS, doubleSidedConstants); + $SurfaceDescription.NormalWS: surfaceData.normalWS = surfaceDescription.NormalWS; + + surfaceData.irisNormalWS = surfaceData.normalWS; + $SurfaceDescription.IrisNormalOS: surfaceData.irisNormalWS = TransformObjectToWorldNormal(surfaceDescription.IrisNormalOS); + $SurfaceDescription.IrisNormalTS: GetNormalWS(fragInputs, surfaceDescription.IrisNormalTS, surfaceData.irisNormalWS, doubleSidedConstants); + $SurfaceDescription.IrisNormalWS: surfaceData.irisNormalWS = surfaceDescription.IrisNormalWS; surfaceData.geomNormalWS = fragInputs.tangentToWorld[2]; diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/Eye/ShaderGraph/EyeSubTarget.Migration.cs b/com.unity.render-pipelines.high-definition/Editor/Material/Eye/ShaderGraph/EyeSubTarget.Migration.cs index 5427da12051..d39bfdd48e8 100644 --- a/com.unity.render-pipelines.high-definition/Editor/Material/Eye/ShaderGraph/EyeSubTarget.Migration.cs +++ b/com.unity.render-pipelines.high-definition/Editor/Material/Eye/ShaderGraph/EyeSubTarget.Migration.cs @@ -63,7 +63,7 @@ public bool TryUpgradeFromMasterNode(IMasterNode1 masterNode, out Dictionary eyeData.subsurfaceScattering, (newValue) => eyeData.subsurfaceScattering = newValue); + AddProperty(Styles.irisNormalType, () => eyeData.irisNormal, (newValue) => eyeData.irisNormal = newValue); } } } diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/Fabric/ShaderGraph/FabricPass.template b/com.unity.render-pipelines.high-definition/Editor/Material/Fabric/ShaderGraph/FabricPass.template index d9b8648834b..abdab374d70 100644 --- a/com.unity.render-pipelines.high-definition/Editor/Material/Fabric/ShaderGraph/FabricPass.template +++ b/com.unity.render-pipelines.high-definition/Editor/Material/Fabric/ShaderGraph/FabricPass.template @@ -195,12 +195,10 @@ Pass float3 doubleSidedConstants = float3(1.0, 1.0, 1.0); #endif - // tangent-space normal - float3 normalTS = float3(0.0f, 0.0f, 1.0f); - $SurfaceDescription.NormalTS: normalTS = surfaceDescription.NormalTS; - - // compute world space normal - GetNormalWS(fragInputs, normalTS, surfaceData.normalWS, doubleSidedConstants); + // normal delivered to master node + $SurfaceDescription.NormalOS: surfaceData.normalWS = TransformObjectToWorldNormal(surfaceDescription.NormalOS); + $SurfaceDescription.NormalTS: GetNormalWS(fragInputs, surfaceDescription.NormalTS, surfaceData.normalWS, doubleSidedConstants); + $SurfaceDescription.NormalWS: surfaceData.normalWS = surfaceDescription.NormalWS; surfaceData.geomNormalWS = fragInputs.tangentToWorld[2]; surfaceData.tangentWS = normalize(fragInputs.tangentToWorld[0].xyz); // The tangent is not normalize in tangentToWorld for mikkt. TODO: Check if it expected that we normalize with Morten. Tag: SURFACE_GRADIENT diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/Hair/ShaderGraph/HairPass.template b/com.unity.render-pipelines.high-definition/Editor/Material/Hair/ShaderGraph/HairPass.template index 01dccf50d14..c4353c0c351 100644 --- a/com.unity.render-pipelines.high-definition/Editor/Material/Hair/ShaderGraph/HairPass.template +++ b/com.unity.render-pipelines.high-definition/Editor/Material/Hair/ShaderGraph/HairPass.template @@ -219,12 +219,10 @@ Pass surfaceData.geomNormalWS = fragInputs.tangentToWorld[2]; - // tangent-space normal - float3 normalTS = float3(0.0f, 0.0f, 1.0f); - $SurfaceDescription.NormalTS: normalTS = surfaceDescription.NormalTS; - - // compute world space (user-provided) normal - GetNormalWS(fragInputs, normalTS, surfaceData.normalWS, doubleSidedConstants); + // normal delivered to master node + $SurfaceDescription.NormalOS: surfaceData.normalWS = TransformObjectToWorldNormal(surfaceDescription.NormalOS); + $SurfaceDescription.NormalTS: GetNormalWS(fragInputs, surfaceDescription.NormalTS, surfaceData.normalWS, doubleSidedConstants); + $SurfaceDescription.NormalWS: surfaceData.normalWS = surfaceDescription.NormalWS; #if HAVE_DECALS if (_EnableDecals) diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/Lit/ShaderGraph/LitPass.template b/com.unity.render-pipelines.high-definition/Editor/Material/Lit/ShaderGraph/LitPass.template index fd69ae98c17..be111279479 100644 --- a/com.unity.render-pipelines.high-definition/Editor/Material/Lit/ShaderGraph/LitPass.template +++ b/com.unity.render-pipelines.high-definition/Editor/Material/Lit/ShaderGraph/LitPass.template @@ -48,9 +48,6 @@ Pass $TransparentWritesMotionVec: #define _WRITE_TRANSPARENT_MOTION_VECTOR 1 $DepthOffset: #define _DEPTHOFFSET_ON 1 $BlendMode.PreserveSpecular: #define _BLENDMODE_PRESERVE_SPECULAR_LIGHTING 1 - $NormalDropOffTS: #define _NORMAL_DROPOFF_TS 1 - $NormalDropOffOS: #define _NORMAL_DROPOFF_OS 1 - $NormalDropOffWS: #define _NORMAL_DROPOFF_WS 1 $AttributesMesh.normalOS: #define ATTRIBUTES_NEED_NORMAL $AttributesMesh.tangentOS: #define ATTRIBUTES_NEED_TANGENT $AttributesMesh.uv0: #define ATTRIBUTES_NEED_TEXCOORD0 @@ -225,19 +222,9 @@ Pass #endif // normal delivered to master node - float3 normalSrc = float3(0.0f, 0.0f, 1.0f); - $SurfaceDescription.NormalOS: normalSrc = surfaceDescription.NormalOS; - $SurfaceDescription.NormalTS: normalSrc = surfaceDescription.NormalTS; - $SurfaceDescription.NormalWS: normalSrc = surfaceDescription.NormalWS; - - // compute world space normal - #if _NORMAL_DROPOFF_TS - GetNormalWS(fragInputs, normalSrc, surfaceData.normalWS, doubleSidedConstants); - #elif _NORMAL_DROPOFF_OS - surfaceData.normalWS = TransformObjectToWorldNormal(normalSrc); - #elif _NORMAL_DROPOFF_WS - surfaceData.normalWS = normalSrc; - #endif + $SurfaceDescription.NormalOS: surfaceData.normalWS = TransformObjectToWorldNormal(surfaceDescription.NormalOS); + $SurfaceDescription.NormalTS: GetNormalWS(fragInputs, surfaceDescription.NormalTS, surfaceData.normalWS, doubleSidedConstants); + $SurfaceDescription.NormalWS: surfaceData.normalWS = surfaceDescription.NormalWS; surfaceData.geomNormalWS = fragInputs.tangentToWorld[2]; diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/LightingSubTarget.cs b/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/LightingSubTarget.cs index dd2f1689081..987b301904c 100644 --- a/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/LightingSubTarget.cs +++ b/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/LightingSubTarget.cs @@ -71,11 +71,6 @@ public override void GetFields(ref TargetFieldContext context) // Common properties to all Lit master nodes var descs = context.blocks.Select(x => x.descriptor); - // Normal dropoff space - context.AddField(Fields.NormalDropOffOS, lightingData.normalDropOffSpace == NormalDropOffSpace.Object); - context.AddField(Fields.NormalDropOffTS, lightingData.normalDropOffSpace == NormalDropOffSpace.Tangent); - context.AddField(Fields.NormalDropOffWS, lightingData.normalDropOffSpace == NormalDropOffSpace.World); - // Misc context.AddField(HDFields.BlendPreserveSpecular, systemData.surfaceType != SurfaceType.Opaque && lightingData.blendPreserveSpecular); context.AddField(HDFields.DisableDecals, !lightingData.receiveDecals); diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/StackLit/ShaderGraph/StackLitPass.template b/com.unity.render-pipelines.high-definition/Editor/Material/StackLit/ShaderGraph/StackLitPass.template index 3f9b8f0c73a..b8f15d6f920 100644 --- a/com.unity.render-pipelines.high-definition/Editor/Material/StackLit/ShaderGraph/StackLitPass.template +++ b/com.unity.render-pipelines.high-definition/Editor/Material/StackLit/ShaderGraph/StackLitPass.template @@ -139,9 +139,6 @@ Pass $StackLitDebug: #define _STACKLIT_DEBUG $DepthOffset: #define _DEPTHOFFSET_ON 1 $BlendMode.PreserveSpecular: #define _BLENDMODE_PRESERVE_SPECULAR_LIGHTING 1 - $NormalDropOffTS: #define _NORMAL_DROPOFF_TS 1 - $NormalDropOffOS: #define _NORMAL_DROPOFF_OS 1 - $NormalDropOffWS: #define _NORMAL_DROPOFF_WS 1 // StackLit.hlsl config defines (direct, no feature keywords): // _SCREENSPACE_SPECULAROCCLUSION_METHOD, _SCREENSPACE_SPECULAROCCLUSION_VISIBILITY_FROM_AO_WEIGHT, _SCREENSPACE_SPECULAROCCLUSION_VISIBILITY_DIR @@ -391,22 +388,14 @@ Pass surfaceData.geomNormalWS = fragInputs.tangentToWorld[2]; // normal delivered to master node - float3 normalSrc = float3(0.0f, 0.0f, 1.0f); - $SurfaceDescription.NormalOS: normalSrc = surfaceDescription.NormalOS; - $SurfaceDescription.NormalTS: normalSrc = surfaceDescription.NormalTS; - $SurfaceDescription.NormalWS: normalSrc = surfaceDescription.NormalWS; - - // compute world space normal - #if _NORMAL_DROPOFF_TS - GetNormalWS(fragInputs, normalSrc, surfaceData.normalWS, doubleSidedConstants); - #elif _NORMAL_DROPOFF_OS - surfaceData.normalWS = TransformObjectToWorldNormal(normalSrc); - #elif _NORMAL_DROPOFF_WS - surfaceData.normalWS = normalSrc; - #endif + $SurfaceDescription.NormalOS: surfaceData.normalWS = TransformObjectToWorldNormal(surfaceDescription.NormalOS); + $SurfaceDescription.NormalTS: GetNormalWS(fragInputs, surfaceDescription.NormalTS, surfaceData.normalWS, doubleSidedConstants); + $SurfaceDescription.NormalWS: surfaceData.normalWS = surfaceDescription.NormalWS; surfaceData.coatNormalWS = surfaceData.geomNormalWS; - $Material.CoatNormal: GetNormalWS(fragInputs, surfaceDescription.CoatNormal, surfaceData.coatNormalWS, doubleSidedConstants); + $SurfaceDescription.CoatNormalOS: surfaceData.coatNormalWS = TransformObjectToWorldNormal(surfaceDescription.CoatNormalOS); + $SurfaceDescription.CoatNormalTS: GetNormalWS(fragInputs, surfaceDescription.CoatNormalTS, surfaceData.coatNormalWS, doubleSidedConstants); + $SurfaceDescription.CoatNormalWS: surfaceData.coatNormalWS = surfaceDescription.CoatNormalWS; // surfaceData.tangentWS = normalize(fragInputs.tangentToWorld[0].xyz); // ...We don't need to normalize if we're going to call Orthonormalize anyways as long as diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/StackLit/ShaderGraph/StackLitSubTarget.Migration.cs b/com.unity.render-pipelines.high-definition/Editor/Material/StackLit/ShaderGraph/StackLitSubTarget.Migration.cs index a091f9b8ad9..e3beab194e2 100644 --- a/com.unity.render-pipelines.high-definition/Editor/Material/StackLit/ShaderGraph/StackLitSubTarget.Migration.cs +++ b/com.unity.render-pipelines.high-definition/Editor/Material/StackLit/ShaderGraph/StackLitSubTarget.Migration.cs @@ -148,7 +148,7 @@ public bool TryUpgradeFromMasterNode(IMasterNode1 masterNode, out Dictionary(CoatMaskSlotId).value == 0.0f), // context.AddField(HDFields.CoatMaskOne, coat.isOn && pass.pixelBlocks.Contains(CoatMaskSlotId) && // FindSlot(CoatMaskSlotId).value == 1.0f), - context.AddField(HDFields.CoatNormal, stackLitData.coatNormal && context.pass.validPixelBlocks.Contains(HDBlockFields.SurfaceDescription.CoatNormal)); + context.AddField(HDFields.CoatNormal, stackLitData.coatNormal + && (context.pass.validPixelBlocks.Contains(HDBlockFields.SurfaceDescription.CoatNormalOS) + || context.pass.validPixelBlocks.Contains(HDBlockFields.SurfaceDescription.CoatNormalTS) + || context.pass.validPixelBlocks.Contains(HDBlockFields.SurfaceDescription.CoatNormalWS))); context.AddField(HDFields.Iridescence, stackLitData.iridescence); context.AddField(HDFields.SubsurfaceScattering, stackLitData.subsurfaceScattering && systemData.surfaceType != SurfaceType.Transparent); context.AddField(HDFields.Transmission, stackLitData.transmission); @@ -215,7 +218,9 @@ public override void GetActiveBlocks(ref TargetActiveBlockContext context) context.AddBlock(HDBlockFields.SurfaceDescription.CoatIor, stackLitData.coat); context.AddBlock(HDBlockFields.SurfaceDescription.CoatThickness, stackLitData.coat); context.AddBlock(HDBlockFields.SurfaceDescription.CoatExtinction, stackLitData.coat); - context.AddBlock(HDBlockFields.SurfaceDescription.CoatNormal, stackLitData.coat && stackLitData.coatNormal); + context.AddBlock(HDBlockFields.SurfaceDescription.CoatNormalOS, stackLitData.coat && stackLitData.coatNormal && lightingData.normalDropOffSpace == NormalDropOffSpace.Object); + context.AddBlock(HDBlockFields.SurfaceDescription.CoatNormalTS, stackLitData.coat && stackLitData.coatNormal && lightingData.normalDropOffSpace == NormalDropOffSpace.Tangent); + context.AddBlock(HDBlockFields.SurfaceDescription.CoatNormalWS, stackLitData.coat && stackLitData.coatNormal && lightingData.normalDropOffSpace == NormalDropOffSpace.World); context.AddBlock(HDBlockFields.SurfaceDescription.CoatMask, stackLitData.coat); // Dual Specular Lobe diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/UIBlocks/SurfaceOptionUIBlock.cs b/com.unity.render-pipelines.high-definition/Editor/Material/UIBlocks/SurfaceOptionUIBlock.cs index 9cbc2afbd6e..317785bf7f5 100644 --- a/com.unity.render-pipelines.high-definition/Editor/Material/UIBlocks/SurfaceOptionUIBlock.cs +++ b/com.unity.render-pipelines.high-definition/Editor/Material/UIBlocks/SurfaceOptionUIBlock.cs @@ -422,12 +422,14 @@ void DrawAlphaCutoffGUI() { if (transparentDepthPrepassEnable != null && transparentDepthPrepassEnable.floatValue == 1.0f) { - materialEditor.ShaderProperty(alphaCutoffPrepass, Styles.alphaCutoffPrepassText); + if (alphaCutoffPrepass != null) + materialEditor.ShaderProperty(alphaCutoffPrepass, Styles.alphaCutoffPrepassText); } if (transparentDepthPostpassEnable != null && transparentDepthPostpassEnable.floatValue == 1.0f) { - materialEditor.ShaderProperty(alphaCutoffPostpass, Styles.alphaCutoffPostpassText); + if (alphaCutoffPostpass != null) + materialEditor.ShaderProperty(alphaCutoffPostpass, Styles.alphaCutoffPostpassText); } } EditorGUI.indentLevel--; diff --git a/com.unity.render-pipelines.high-definition/Editor/ShaderGraph/HDBlockFields.cs b/com.unity.render-pipelines.high-definition/Editor/ShaderGraph/HDBlockFields.cs index 3e47e0e08f8..7ef497bbec0 100644 --- a/com.unity.render-pipelines.high-definition/Editor/ShaderGraph/HDBlockFields.cs +++ b/com.unity.render-pipelines.high-definition/Editor/ShaderGraph/HDBlockFields.cs @@ -78,8 +78,12 @@ public struct SurfaceDescription // -------------------------------------------------- // Eye - public static BlockFieldDescriptor IrisNormal = new BlockFieldDescriptor(SurfaceDescription.name, "IrisNormal", "Iris Normal", "SURFACEDESCRIPTION_IRISNORMAL", + public static BlockFieldDescriptor IrisNormalTS = new BlockFieldDescriptor(SurfaceDescription.name, "IrisNormalTS", "Iris Normal (Tangent Space)", "SURFACEDESCRIPTION_IRISNORMALTS", new NormalControl(CoordinateSpace.Tangent), ShaderStage.Fragment); + public static BlockFieldDescriptor IrisNormalOS = new BlockFieldDescriptor(SurfaceDescription.name, "IrisNormalOS", "Iris Normal (Object Space)", "SURFACEDESCRIPTION_IRISNORMALOS", + new NormalControl(CoordinateSpace.Object), ShaderStage.Fragment); + public static BlockFieldDescriptor IrisNormalWS = new BlockFieldDescriptor(SurfaceDescription.name, "IrisNormalWS", "Iris Normal (World Space)", "SURFACEDESCRIPTION_IRISNORMALWS", + new NormalControl(CoordinateSpace.World), ShaderStage.Fragment); public static BlockFieldDescriptor IOR = new BlockFieldDescriptor(SurfaceDescription.name, "IOR", "SURFACEDESCRIPTION_IOR", new FloatControl(1.4f), ShaderStage.Fragment); public static BlockFieldDescriptor Mask = new BlockFieldDescriptor(SurfaceDescription.name, "Mask", "SURFACEDESCRIPTION_MASK", @@ -108,7 +112,11 @@ public struct SurfaceDescription // -------------------------------------------------- // StackLit - public static BlockFieldDescriptor CoatNormal = new BlockFieldDescriptor(SurfaceDescription.name, "CoatNormal", "Coat Normal", "SURFACEDESCRIPTION_COATNORMAL", + public static BlockFieldDescriptor CoatNormalOS = new BlockFieldDescriptor(SurfaceDescription.name, "CoatNormalOS", "Coat Normal (Object Space)", "SURFACEDESCRIPTION_COATNORMALOS", + new NormalControl(CoordinateSpace.Tangent), ShaderStage.Fragment); + public static BlockFieldDescriptor CoatNormalTS = new BlockFieldDescriptor(SurfaceDescription.name, "CoatNormalTS", "Coat Normal (Tangent Space)", "SURFACEDESCRIPTION_COATNORMALTS", + new NormalControl(CoordinateSpace.Tangent), ShaderStage.Fragment); + public static BlockFieldDescriptor CoatNormalWS = new BlockFieldDescriptor(SurfaceDescription.name, "CoatNormalWS", "Coat Normal (World Space)", "SURFACEDESCRIPTION_COATNORMALWS", new NormalControl(CoordinateSpace.Tangent), ShaderStage.Fragment); public static BlockFieldDescriptor DielectricIor = new BlockFieldDescriptor(SurfaceDescription.name, "DielectricIor", "Dielectric IOR", "SURFACEDESCRIPTION_DIELECTRICIOR", new FloatControl(1.5f), ShaderStage.Fragment);