From 579b6e2cee77a0b688c88d61e587e8ff14d276e9 Mon Sep 17 00:00:00 2001 From: FrancescoC-Unity Date: Thu, 24 Sep 2020 11:42:13 +0200 Subject: [PATCH 1/8] Enable LOD cross fade --- .../Editor/Material/Decal/ShaderGraph/DecalData.cs | 8 ++++++++ .../Editor/Material/Decal/ShaderGraph/DecalPass.template | 5 +++++ .../Material/Decal/ShaderGraph/DecalPropertyBlock.cs | 1 + .../Editor/Material/Decal/ShaderGraph/DecalSubTarget.cs | 2 ++ .../Material/UIBlocks/DecalSurfaceOptionsUIBlock.cs | 1 + .../Runtime/Material/Decal/Decal.shader | 3 +++ .../Runtime/Material/Decal/DecalData.hlsl | 4 ++++ 7 files changed, 24 insertions(+) diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/Decal/ShaderGraph/DecalData.cs b/com.unity.render-pipelines.high-definition/Editor/Material/Decal/ShaderGraph/DecalData.cs index 1e68dcbfcfc..1dbc32acb52 100644 --- a/com.unity.render-pipelines.high-definition/Editor/Material/Decal/ShaderGraph/DecalData.cs +++ b/com.unity.render-pipelines.high-definition/Editor/Material/Decal/ShaderGraph/DecalData.cs @@ -62,6 +62,14 @@ public int drawOrder set => m_DrawOrder = value; } + [SerializeField] + bool m_SupportLodCrossFade; + public bool supportLodCrossFade + { + get => m_SupportLodCrossFade; + set => m_SupportLodCrossFade = value; + } + public bool affectsMaskmap => affectsSmoothness || affectsMetal || affectsAO; } } diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/Decal/ShaderGraph/DecalPass.template b/com.unity.render-pipelines.high-definition/Editor/Material/Decal/ShaderGraph/DecalPass.template index 0804a8cd692..4269d480eaf 100644 --- a/com.unity.render-pipelines.high-definition/Editor/Material/Decal/ShaderGraph/DecalPass.template +++ b/com.unity.render-pipelines.high-definition/Editor/Material/Decal/ShaderGraph/DecalPass.template @@ -26,6 +26,7 @@ Pass #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl" #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPass.cs.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl" // Defines $AttributesMesh.normalOS: #define ATTRIBUTES_NEED_NORMAL @@ -84,6 +85,10 @@ Pass void GetSurfaceData(FragInputs fragInputs, float3 V, PositionInputs posInput, out DecalSurfaceData surfaceData) { + #ifdef LOD_FADE_CROSSFADE // enable dithering LOD transition if user select CrossFade transition in LOD group + LODDitheringTransition(ComputeFadeMaskSeed(V, posInput.positionSS), unity_LODFade.x); + #endif + #if (SHADERPASS == SHADERPASS_DBUFFER_PROJECTOR) || (SHADERPASS == SHADERPASS_FORWARD_EMISSIVE_PROJECTOR) float4x4 normalToWorld = UNITY_ACCESS_INSTANCED_PROP(Decal, _NormalToWorld); float fadeFactor = clamp(normalToWorld[0][3], 0.0f, 1.0f); diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/Decal/ShaderGraph/DecalPropertyBlock.cs b/com.unity.render-pipelines.high-definition/Editor/Material/Decal/ShaderGraph/DecalPropertyBlock.cs index 25d5b64f758..8ac81ea3154 100644 --- a/com.unity.render-pipelines.high-definition/Editor/Material/Decal/ShaderGraph/DecalPropertyBlock.cs +++ b/com.unity.render-pipelines.high-definition/Editor/Material/Decal/ShaderGraph/DecalPropertyBlock.cs @@ -29,6 +29,7 @@ protected override void CreatePropertyGUI() AddProperty(affectAmbientOcclusionText, () => decalData.affectsAO, (newValue) => decalData.affectsAO = newValue); AddProperty(affectSmoothnessText, () => decalData.affectsSmoothness, (newValue) => decalData.affectsSmoothness = newValue); AddProperty(affectEmissionText, () => decalData.affectsEmission, (newValue) => decalData.affectsEmission = newValue); + AddProperty(supportLodCrossFadeText, () => decalData.supportLodCrossFade, (newValue) => decalData.supportLodCrossFade = newValue); } } } diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/Decal/ShaderGraph/DecalSubTarget.cs b/com.unity.render-pipelines.high-definition/Editor/Material/Decal/ShaderGraph/DecalSubTarget.cs index ecc7e30ac07..07de4c5ffd7 100644 --- a/com.unity.render-pipelines.high-definition/Editor/Material/Decal/ShaderGraph/DecalSubTarget.cs +++ b/com.unity.render-pipelines.high-definition/Editor/Material/Decal/ShaderGraph/DecalSubTarget.cs @@ -56,6 +56,7 @@ protected override IEnumerable EnumerateSubShaders() protected override void CollectPassKeywords(ref PassDescriptor pass) { pass.keywords.Add(CoreKeywordDescriptors.AlphaTest, new FieldCondition(Fields.AlphaTest, true)); + pass.keywords.Add(CoreKeywordDescriptors.LodFadeCrossfade, new FieldCondition(Fields.LodCrossFade, true)); // Emissive pass only have the emission keyword if (!(pass.lightMode == DecalSystem.s_MaterialDecalPassNames[(int)DecalSystem.MaterialDecalPass.DecalProjectorForwardEmissive] || @@ -91,6 +92,7 @@ public override void GetFields(ref TargetFieldContext context) context.AddField(AffectsMaskMap, decalData.affectsMaskmap); context.AddField(DecalDefault, decalData.affectsAlbedo || decalData.affectsNormal || decalData.affectsMetal || decalData.affectsAO || decalData.affectsSmoothness ); + context.AddField(Fields.LodCrossFade, decalData.supportLodCrossFade); } public override void GetActiveBlocks(ref TargetActiveBlockContext context) diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/UIBlocks/DecalSurfaceOptionsUIBlock.cs b/com.unity.render-pipelines.high-definition/Editor/Material/UIBlocks/DecalSurfaceOptionsUIBlock.cs index 03c33a12fce..aee95c67286 100644 --- a/com.unity.render-pipelines.high-definition/Editor/Material/UIBlocks/DecalSurfaceOptionsUIBlock.cs +++ b/com.unity.render-pipelines.high-definition/Editor/Material/UIBlocks/DecalSurfaceOptionsUIBlock.cs @@ -22,6 +22,7 @@ public class Styles public static GUIContent affectAmbientOcclusionText = new GUIContent("Affect Ambient Occlusion", "When enabled, this decal uses the smoothness channel of its Mask Map. When disabled, the decal has no smoothness effect."); public static GUIContent affectSmoothnessText = new GUIContent("Affect Smoothness", "When enabled, this decal uses the ambient occlusion channel of its Mask Map. When disabled, the decal has no ambient occlusion effect."); public static GUIContent affectEmissionText = new GUIContent("Affect Emission", "When enabled, this decal becomes emissive and appears self-illuminated. Affect Emission does not support Affects Transparents option on Decal Projector."); + public static GUIContent supportLodCrossFadeText = new GUIContent("Support LOD CrossFade", "When enabled, this decal supports LOD Cross fade."); } Expandable m_ExpandableBit; diff --git a/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/Decal.shader b/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/Decal.shader index 9fa8c422cf5..0770475de39 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/Decal.shader +++ b/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/Decal.shader @@ -78,6 +78,8 @@ Shader "HDRP/Decal" #pragma shader_feature_local _MATERIAL_AFFECTS_MASKMAP #pragma multi_compile_instancing + // enable dithering LOD crossfade + #pragma multi_compile _ LOD_FADE_CROSSFADE //------------------------------------------------------------------------------------- // Include @@ -86,6 +88,7 @@ Shader "HDRP/Decal" #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl" #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/FragInputs.hlsl" #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPass.cs.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl" // All our shaders use same name for entry point #pragma vertex Vert diff --git a/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/DecalData.hlsl b/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/DecalData.hlsl index bea55bd6254..21989feefd7 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/DecalData.hlsl +++ b/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/DecalData.hlsl @@ -6,6 +6,10 @@ void GetSurfaceData(FragInputs input, float3 V, PositionInputs posInput, out DecalSurfaceData surfaceData) { +#ifdef LOD_FADE_CROSSFADE // enable dithering LOD transition if user select CrossFade transition in LOD group + LODDitheringTransition(ComputeFadeMaskSeed(V, posInput.positionSS), unity_LODFade.x); +#endif + #if (SHADERPASS == SHADERPASS_DBUFFER_PROJECTOR) || (SHADERPASS == SHADERPASS_FORWARD_EMISSIVE_PROJECTOR) // With inspector version of decal we can use instancing to get normal to world access float4x4 normalToWorld = UNITY_ACCESS_INSTANCED_PROP(Decal, _NormalToWorld); From 321c6dfd154017c78d40b22fbde6e9383cc2b5a8 Mon Sep 17 00:00:00 2001 From: FrancescoC-Unity Date: Thu, 24 Sep 2020 11:45:16 +0200 Subject: [PATCH 2/8] Changelog --- com.unity.render-pipelines.high-definition/CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/com.unity.render-pipelines.high-definition/CHANGELOG.md b/com.unity.render-pipelines.high-definition/CHANGELOG.md index 518105d4800..d66f5cdab3c 100644 --- a/com.unity.render-pipelines.high-definition/CHANGELOG.md +++ b/com.unity.render-pipelines.high-definition/CHANGELOG.md @@ -83,6 +83,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - Fixed SSGI compilation issues on PS4. - Fixed "Screen position out of view frustum" error when camera is on exactly the planar reflection probe plane. - Workaround issue that caused objects using eye shader to not be rendered on xbox. +- Fix decal being applied twice with LOD Crossfade. ### Changed - Preparation pass for RTSSShadows to be supported by render graph. From 51c876e0c0b98787c4bee6a929347e0a5f1c7784 Mon Sep 17 00:00:00 2001 From: FrancescoC-Unity Date: Wed, 30 Sep 2020 10:50:10 +0200 Subject: [PATCH 3/8] Make changes only for mesh decals --- .../Editor/Material/Decal/ShaderGraph/DecalSubTarget.cs | 7 ++++++- .../Runtime/Material/Decal/Decal.shader | 7 +++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/Decal/ShaderGraph/DecalSubTarget.cs b/com.unity.render-pipelines.high-definition/Editor/Material/Decal/ShaderGraph/DecalSubTarget.cs index 07de4c5ffd7..5bb6e1aa6e9 100644 --- a/com.unity.render-pipelines.high-definition/Editor/Material/Decal/ShaderGraph/DecalSubTarget.cs +++ b/com.unity.render-pipelines.high-definition/Editor/Material/Decal/ShaderGraph/DecalSubTarget.cs @@ -56,7 +56,6 @@ protected override IEnumerable EnumerateSubShaders() protected override void CollectPassKeywords(ref PassDescriptor pass) { pass.keywords.Add(CoreKeywordDescriptors.AlphaTest, new FieldCondition(Fields.AlphaTest, true)); - pass.keywords.Add(CoreKeywordDescriptors.LodFadeCrossfade, new FieldCondition(Fields.LodCrossFade, true)); // Emissive pass only have the emission keyword if (!(pass.lightMode == DecalSystem.s_MaterialDecalPassNames[(int)DecalSystem.MaterialDecalPass.DecalProjectorForwardEmissive] || @@ -69,6 +68,12 @@ protected override void CollectPassKeywords(ref PassDescriptor pass) if (decalData.affectsMaskmap) pass.keywords.Add(DecalDefines.Maskmap); } + + if (pass.lightMode == DecalSystem.s_MaterialDecalPassNames[(int)DecalSystem.MaterialDecalPass.DecalMeshForwardEmissive] || + pass.lightMode == DecalSystem.s_MaterialDecalPassNames[(int)DecalSystem.MaterialDecalPass.DBufferMesh]) + { + pass.keywords.Add(CoreKeywordDescriptors.LodFadeCrossfade, new FieldCondition(Fields.LodCrossFade, true)); + } } public static FieldDescriptor AffectsAlbedo = new FieldDescriptor(kMaterial, "AffectsAlbedo", ""); diff --git a/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/Decal.shader b/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/Decal.shader index 0770475de39..91d3e153dea 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/Decal.shader +++ b/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/Decal.shader @@ -78,8 +78,6 @@ Shader "HDRP/Decal" #pragma shader_feature_local _MATERIAL_AFFECTS_MASKMAP #pragma multi_compile_instancing - // enable dithering LOD crossfade - #pragma multi_compile _ LOD_FADE_CROSSFADE //------------------------------------------------------------------------------------- // Include @@ -210,6 +208,9 @@ Shader "HDRP/Decal" HLSLPROGRAM #pragma multi_compile DECALS_3RT DECALS_4RT + // enable dithering LOD crossfade + #pragma multi_compile _ LOD_FADE_CROSSFADE + #define SHADERPASS SHADERPASS_DBUFFER_MESH #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl" #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/DecalProperties.hlsl" @@ -241,6 +242,8 @@ Shader "HDRP/Decal" Blend 0 SrcAlpha One HLSLPROGRAM + // enable dithering LOD crossfade + #pragma multi_compile _ LOD_FADE_CROSSFADE #define _MATERIAL_AFFECTS_EMISSION #define SHADERPASS SHADERPASS_FORWARD_EMISSIVE_MESH From fce459bd29327c02fe5a819ad812810f08b0e53f Mon Sep 17 00:00:00 2001 From: sebastienlagarde Date: Sat, 3 Oct 2020 23:21:07 +0200 Subject: [PATCH 4/8] Update DecalData.hlsl --- .../Runtime/Material/Decal/DecalData.hlsl | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/DecalData.hlsl b/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/DecalData.hlsl index 21989feefd7..a99f0586b26 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/DecalData.hlsl +++ b/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/DecalData.hlsl @@ -6,10 +6,6 @@ void GetSurfaceData(FragInputs input, float3 V, PositionInputs posInput, out DecalSurfaceData surfaceData) { -#ifdef LOD_FADE_CROSSFADE // enable dithering LOD transition if user select CrossFade transition in LOD group - LODDitheringTransition(ComputeFadeMaskSeed(V, posInput.positionSS), unity_LODFade.x); -#endif - #if (SHADERPASS == SHADERPASS_DBUFFER_PROJECTOR) || (SHADERPASS == SHADERPASS_FORWARD_EMISSIVE_PROJECTOR) // With inspector version of decal we can use instancing to get normal to world access float4x4 normalToWorld = UNITY_ACCESS_INSTANCED_PROP(Decal, _NormalToWorld); @@ -18,6 +14,11 @@ void GetSurfaceData(FragInputs input, float3 V, PositionInputs posInput, out Dec float2 offset = float2(normalToWorld[3][2], normalToWorld[3][3]); float2 texCoords = input.texCoord0.xy * scale + offset; #elif (SHADERPASS == SHADERPASS_DBUFFER_MESH) || (SHADERPASS == SHADERPASS_FORWARD_EMISSIVE_MESH) + + #ifdef LOD_FADE_CROSSFADE // enable dithering LOD transition if user select CrossFade transition in LOD group + LODDitheringTransition(ComputeFadeMaskSeed(V, posInput.positionSS), unity_LODFade.x); + #endif + float fadeFactor = _DecalBlend; float2 texCoords = input.texCoord0.xy; #endif From 5bbab66f535080401c7fece5d01511678d6889a1 Mon Sep 17 00:00:00 2001 From: sebastienlagarde Date: Sat, 3 Oct 2020 23:22:32 +0200 Subject: [PATCH 5/8] Update DecalSurfaceOptionsUIBlock.cs --- .../Editor/Material/UIBlocks/DecalSurfaceOptionsUIBlock.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/UIBlocks/DecalSurfaceOptionsUIBlock.cs b/com.unity.render-pipelines.high-definition/Editor/Material/UIBlocks/DecalSurfaceOptionsUIBlock.cs index aee95c67286..1ddd3295ce2 100644 --- a/com.unity.render-pipelines.high-definition/Editor/Material/UIBlocks/DecalSurfaceOptionsUIBlock.cs +++ b/com.unity.render-pipelines.high-definition/Editor/Material/UIBlocks/DecalSurfaceOptionsUIBlock.cs @@ -22,7 +22,7 @@ public class Styles public static GUIContent affectAmbientOcclusionText = new GUIContent("Affect Ambient Occlusion", "When enabled, this decal uses the smoothness channel of its Mask Map. When disabled, the decal has no smoothness effect."); public static GUIContent affectSmoothnessText = new GUIContent("Affect Smoothness", "When enabled, this decal uses the ambient occlusion channel of its Mask Map. When disabled, the decal has no ambient occlusion effect."); public static GUIContent affectEmissionText = new GUIContent("Affect Emission", "When enabled, this decal becomes emissive and appears self-illuminated. Affect Emission does not support Affects Transparents option on Decal Projector."); - public static GUIContent supportLodCrossFadeText = new GUIContent("Support LOD CrossFade", "When enabled, this decal supports LOD Cross fade."); + public static GUIContent supportLodCrossFadeText = new GUIContent("Support LOD CrossFade", "When enabled, this decal material supports LOD Cross fade if use on a mesh."); } Expandable m_ExpandableBit; From 52becc4017302880d1ed7c8276bd40accf5da79a Mon Sep 17 00:00:00 2001 From: sebastienlagarde Date: Sun, 4 Oct 2020 02:20:48 +0200 Subject: [PATCH 6/8] do some cleanup and move ComputeFadeMaskSeed in ShaderVariablesFunctions.hlsl --- .../Decal/ShaderGraph/DecalPass.template | 9 +++--- .../Runtime/Material/Material.hlsl | 31 ------------------- .../ShaderVariablesFunctions.hlsl | 31 +++++++++++++++++++ 3 files changed, 35 insertions(+), 36 deletions(-) diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/Decal/ShaderGraph/DecalPass.template b/com.unity.render-pipelines.high-definition/Editor/Material/Decal/ShaderGraph/DecalPass.template index 4269d480eaf..75f9485c2e1 100644 --- a/com.unity.render-pipelines.high-definition/Editor/Material/Decal/ShaderGraph/DecalPass.template +++ b/com.unity.render-pipelines.high-definition/Editor/Material/Decal/ShaderGraph/DecalPass.template @@ -26,7 +26,6 @@ Pass #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl" #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPass.cs.hlsl" - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl" // Defines $AttributesMesh.normalOS: #define ATTRIBUTES_NEED_NORMAL @@ -85,10 +84,6 @@ Pass void GetSurfaceData(FragInputs fragInputs, float3 V, PositionInputs posInput, out DecalSurfaceData surfaceData) { - #ifdef LOD_FADE_CROSSFADE // enable dithering LOD transition if user select CrossFade transition in LOD group - LODDitheringTransition(ComputeFadeMaskSeed(V, posInput.positionSS), unity_LODFade.x); - #endif - #if (SHADERPASS == SHADERPASS_DBUFFER_PROJECTOR) || (SHADERPASS == SHADERPASS_FORWARD_EMISSIVE_PROJECTOR) float4x4 normalToWorld = UNITY_ACCESS_INSTANCED_PROP(Decal, _NormalToWorld); float fadeFactor = clamp(normalToWorld[0][3], 0.0f, 1.0f); @@ -102,6 +97,10 @@ Pass fragInputs.tangentToWorld[2].xyz = TransformObjectToWorldDir(float3(0, 1, 0)); fragInputs.tangentToWorld[1].xyz = TransformObjectToWorldDir(float3(0, 0, 1)); #else + #ifdef LOD_FADE_CROSSFADE // enable dithering LOD transition if user select CrossFade transition in LOD group + LODDitheringTransition(ComputeFadeMaskSeed(V, posInput.positionSS), unity_LODFade.x); + #endif + float fadeFactor = 1.0; #endif diff --git a/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl b/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl index 3c08ecd5dc9..8e776624000 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl +++ b/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl @@ -125,37 +125,6 @@ void DoAlphaTest(float alpha, float alphaCutoff, out bool alphaTestResult) { alphaTestResult = alpha >= alphaCutoff; } -//----------------------------------------------------------------------------- -// LoD Fade -//----------------------------------------------------------------------------- - -// Helper for LODDitheringTransition. -uint2 ComputeFadeMaskSeed(float3 V, uint2 positionSS) -{ - uint2 fadeMaskSeed; - - if (IsPerspectiveProjection()) - { - // Start with the world-space direction V. It is independent from the orientation of the camera, - // and only depends on the position of the camera and the position of the fragment. - // Now, project and transform it into [-1, 1]. - float2 pv = PackNormalOctQuadEncode(V); - // Rescale it to account for the resolution of the screen. - pv *= _ScreenSize.xy; - // The camera only sees a small portion of the sphere, limited by hFoV and vFoV. - // Therefore, we must rescale again (before quantization), roughly, by 1/tan(FoV/2). - pv *= UNITY_MATRIX_P._m00_m11; - // Truncate and quantize. - fadeMaskSeed = asuint((int2)pv); - } - else - { - // Can't use the view direction, it is the same across the entire screen. - fadeMaskSeed = positionSS; - } - - return fadeMaskSeed; -} //----------------------------------------------------------------------------- // Reflection / Refraction hierarchy handling diff --git a/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariablesFunctions.hlsl b/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariablesFunctions.hlsl index ab9a3831ff1..c053096b816 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariablesFunctions.hlsl +++ b/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariablesFunctions.hlsl @@ -206,5 +206,36 @@ uint ScalarizeElementIndex(uint v_elementIdx, bool fastPath) return s_elementIdx; } +//----------------------------------------------------------------------------- +// LoD Fade +//----------------------------------------------------------------------------- + +// Helper for LODDitheringTransition. +uint2 ComputeFadeMaskSeed(float3 V, uint2 positionSS) +{ + uint2 fadeMaskSeed; + + if (IsPerspectiveProjection()) + { + // Start with the world-space direction V. It is independent from the orientation of the camera, + // and only depends on the position of the camera and the position of the fragment. + // Now, project and transform it into [-1, 1]. + float2 pv = PackNormalOctQuadEncode(V); + // Rescale it to account for the resolution of the screen. + pv *= _ScreenSize.xy; + // The camera only sees a small portion of the sphere, limited by hFoV and vFoV. + // Therefore, we must rescale again (before quantization), roughly, by 1/tan(FoV/2). + pv *= UNITY_MATRIX_P._m00_m11; + // Truncate and quantize. + fadeMaskSeed = asuint((int2)pv); + } + else + { + // Can't use the view direction, it is the same across the entire screen. + fadeMaskSeed = positionSS; + } + + return fadeMaskSeed; +} #endif // UNITY_SHADER_VARIABLES_FUNCTIONS_INCLUDED From 05dfe610203509b34300dd097808bf7f1103fe40 Mon Sep 17 00:00:00 2001 From: sebastienlagarde Date: Sun, 4 Oct 2020 02:29:05 +0200 Subject: [PATCH 7/8] update documentation --- .../Documentation~/Master-Node-Decal.md | 3 ++- .../Editor/Material/UIBlocks/DecalSurfaceOptionsUIBlock.cs | 2 +- .../Runtime/Material/Decal/Decal.shader | 1 - 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/com.unity.render-pipelines.high-definition/Documentation~/Master-Node-Decal.md b/com.unity.render-pipelines.high-definition/Documentation~/Master-Node-Decal.md index 89ed5c4dc0e..ee210a1d055 100644 --- a/com.unity.render-pipelines.high-definition/Documentation~/Master-Node-Decal.md +++ b/com.unity.render-pipelines.high-definition/Documentation~/Master-Node-Decal.md @@ -55,8 +55,9 @@ To view these properties, click the gear in the top right of the Master Node. | **Affects Ambient Occlusion** | Enable or disable the effect of the **Ambient Occlusion** property. | | **Affects Smoothness** | Enable or disable the effect of the **Smoothness** property. | | **Affects Emission** | Enable or disable the effect of the **Emission** property. | +| **Support LOD CrossFace** | Indicates whether dithering occurs when moving from one LOD level of the receiving Mesh to another when sampling Textures. Only use with Decal Mesh. | | **Override ShaderGUI** | Lets you override the [ShaderGUI](https://docs.unity3d.com/ScriptReference/ShaderGUI.html) that this Shader Graph uses. If `true`, the **ShaderGUI** property appears, which lets you specify the ShaderGUI to use. | -| **- ShaderGUI** | The full name of the ShaderGUI class to use, including the class path. | +| **- ShaderGUI** | The full name of the ShaderGUI class to use, including the class path. | diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/UIBlocks/DecalSurfaceOptionsUIBlock.cs b/com.unity.render-pipelines.high-definition/Editor/Material/UIBlocks/DecalSurfaceOptionsUIBlock.cs index 1ddd3295ce2..86aca5c42ce 100644 --- a/com.unity.render-pipelines.high-definition/Editor/Material/UIBlocks/DecalSurfaceOptionsUIBlock.cs +++ b/com.unity.render-pipelines.high-definition/Editor/Material/UIBlocks/DecalSurfaceOptionsUIBlock.cs @@ -22,7 +22,7 @@ public class Styles public static GUIContent affectAmbientOcclusionText = new GUIContent("Affect Ambient Occlusion", "When enabled, this decal uses the smoothness channel of its Mask Map. When disabled, the decal has no smoothness effect."); public static GUIContent affectSmoothnessText = new GUIContent("Affect Smoothness", "When enabled, this decal uses the ambient occlusion channel of its Mask Map. When disabled, the decal has no ambient occlusion effect."); public static GUIContent affectEmissionText = new GUIContent("Affect Emission", "When enabled, this decal becomes emissive and appears self-illuminated. Affect Emission does not support Affects Transparents option on Decal Projector."); - public static GUIContent supportLodCrossFadeText = new GUIContent("Support LOD CrossFade", "When enabled, this decal material supports LOD Cross fade if use on a mesh."); + public static GUIContent supportLodCrossFadeText = new GUIContent("Support LOD CrossFade", "When enabled, this decal material supports LOD Cross fade if use on a Mesh."); } Expandable m_ExpandableBit; diff --git a/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/Decal.shader b/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/Decal.shader index 91d3e153dea..b8327d6f1fd 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/Decal.shader +++ b/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/Decal.shader @@ -86,7 +86,6 @@ Shader "HDRP/Decal" #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl" #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/FragInputs.hlsl" #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPass.cs.hlsl" - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl" // All our shaders use same name for entry point #pragma vertex Vert From 7c5fdc7272e4da1cb5734675675c8947e0b9b6f3 Mon Sep 17 00:00:00 2001 From: sebastienlagarde Date: Sun, 4 Oct 2020 10:17:51 +0200 Subject: [PATCH 8/8] Update ShaderVariablesFunctions.hlsl --- .../Runtime/ShaderLibrary/ShaderVariablesFunctions.hlsl | 1 + 1 file changed, 1 insertion(+) diff --git a/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariablesFunctions.hlsl b/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariablesFunctions.hlsl index c053096b816..990e9e25c42 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariablesFunctions.hlsl +++ b/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariablesFunctions.hlsl @@ -2,6 +2,7 @@ #define UNITY_SHADER_VARIABLES_FUNCTIONS_INCLUDED #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/SpaceTransforms.hlsl" +#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Packing.hlsl" // Helper function for Rendering Layers #define DEFAULT_LIGHT_LAYERS (RENDERING_LIGHT_LAYERS_MASK >> RENDERING_LIGHT_LAYERS_MASK_SHIFT)