diff --git a/com.unity.render-pipelines.high-definition/CHANGELOG.md b/com.unity.render-pipelines.high-definition/CHANGELOG.md index 2347608849d..3177bfffab1 100644 --- a/com.unity.render-pipelines.high-definition/CHANGELOG.md +++ b/com.unity.render-pipelines.high-definition/CHANGELOG.md @@ -159,6 +159,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - Fixed profiling scope for quality RTGI. - Fixed the denoising and multi-sample not being used for smooth multibounce RTReflections. - Fixed after post process rendering pass options not showing for unlit ShaderGraphs. +- Fixed scene selection pass for decal materials ### Changed - Preparation pass for RTSSShadows to be supported by render graph. 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 219fb8de831..9fd8061c53e 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 @@ -48,6 +48,12 @@ Pass $splice(HybridV1InjectedBuiltinProperties) + // -- Properties used by SceneSelectionPass + #ifdef SCENESELECTIONPASS + int _ObjectId; + int _PassValue; + #endif + // Includes $splice(PreGraphIncludes) 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 b8c619b31f6..12995051df9 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 @@ -197,11 +197,13 @@ void AddColorMaskProperty(string referenceName) #region SubShaders static class SubShaders { + // Relies on the order shader passes are declared in DecalSystem.cs public static SubShaderDescriptor Decal = new SubShaderDescriptor() { generatesPreview = true, passes = new PassCollection { + { DecalPasses.SceneSelection, new FieldCondition(DecalDefault, true) }, { DecalPasses.DBufferProjector, new FieldCondition(DecalDefault, true) }, { DecalPasses.DecalProjectorForwardEmissive, new FieldCondition(AffectsEmission, true) }, { DecalPasses.DBufferMesh, new FieldCondition(DecalDefault, true) }, @@ -215,8 +217,23 @@ static class SubShaders #region Passes public static class DecalPasses { - // CAUTION: c# code relies on the order in which the passes are declared, any change will need to be reflected in Decalsystem.cs - s_MaterialDecalNames array - // and DecalSet.InitializeMaterialValues() + // CAUTION: c# code relies on the order in which the passes are declared, any change will need to be reflected in Decalsystem.cs - enum MaterialDecalPass + + public static PassDescriptor SceneSelection = new PassDescriptor() + { + // Definition + displayName = "SceneSelectionPass", + referenceName = "SHADERPASS_DEPTH_ONLY", + lightMode = "SceneSelectionPass", + useInPreview = false, + + // Collections + renderStates = CoreRenderStates.SceneSelection, + pragmas = DecalPragmas.Instanced, + defines = DecalDefines.SceneSelection, + includes = DecalIncludes.SceneSelection, + }; + public static PassDescriptor DBufferProjector = new PassDescriptor() { // Definition @@ -504,12 +521,22 @@ static class Descriptors definition = KeywordDefinition.ShaderFeature, scope = KeywordScope.Global, }; + + public static KeywordDescriptor SceneSelection = new KeywordDescriptor() + { + displayName = "Scene selection pass", + referenceName = "SCENESELECTIONPASS", + type = KeywordType.Boolean, + definition = KeywordDefinition.Predefined, + scope = KeywordScope.Global, + }; } public static KeywordCollection Albedo = new KeywordCollection { { Descriptors.AffectsAlbedo, new FieldCondition(AffectsAlbedo, true) } }; public static KeywordCollection Normal = new KeywordCollection { { Descriptors.AffectsNormal, new FieldCondition(AffectsNormal, true) } }; public static KeywordCollection Maskmap = new KeywordCollection { { Descriptors.AffectsMaskmap, new FieldCondition(AffectsMaskMap, true) } }; public static DefineCollection Emission = new DefineCollection { { Descriptors.AffectsEmission, 1 } }; + public static DefineCollection SceneSelection = new DefineCollection { { Descriptors.SceneSelection, 1 } }; public static KeywordCollection Decals = new KeywordCollection { { Descriptors.Decals } }; } @@ -533,6 +560,13 @@ static class DecalIncludes { kDecal, IncludeLocation.Pregraph }, { kPassDecal, IncludeLocation.Postgraph }, }; + + public static IncludeCollection SceneSelection = new IncludeCollection + { + { CoreIncludes.MinimalCorePregraph }, + { kDecal, IncludeLocation.Pregraph }, + { kPassDecal, IncludeLocation.Postgraph }, + }; } #endregion } 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 b8327d6f1fd..0c675ba1d32 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 @@ -97,10 +97,45 @@ Shader "HDRP/Decal" { Tags{ "RenderPipeline" = "HDRenderPipeline"} - // c# code relies on the order in which the passes are declared, any change will need to be reflected in Decalsystem.cs - s_MaterialDecalNames and s_MaterialDecalSGNames array - // and DecalSet.InitializeMaterialValues() + // c# code relies on the order in which the passes are declared, any change will need to be reflected in + // DecalSystem.cs - enum MaterialDecalPass + // DecalSubTarget.cs - class SubShaders - Pass // 0 + // The outline selection in the editor use the vertex shader/hull/domain shader of the first pass declared. + Pass // 0 + { + Name "SceneSelectionPass" + Tags { "LightMode" = "SceneSelectionPass" } + + Cull Off + + HLSLPROGRAM + + #pragma only_renderers d3d11 playstation xboxone vulkan metal switch + + //enable GPU instancing support + #pragma instancing_options renderinglayer + #pragma multi_compile _ DOTS_INSTANCING_ON + // enable dithering LOD crossfade + #pragma multi_compile _ LOD_FADE_CROSSFADE + + // Note: Require _ObjectId and _PassValue variables + + // We reuse depth prepass for the scene selection, allow to handle alpha correctly as well as tessellation and vertex animation + #define SHADERPASS SHADERPASS_DEPTH_ONLY + #define SCENESELECTIONPASS // This will drive the output of the scene selection shader + #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" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/Decal.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/ShaderPass/DecalSharePass.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPassDecal.hlsl" + + #pragma editor_sync_compilation + + ENDHLSL + } + + Pass // 1 { Name "DBufferProjector" Tags{"LightMode" = "DBufferProjector"} // Metalness @@ -143,7 +178,7 @@ Shader "HDRP/Decal" ENDHLSL } - Pass // 1 + Pass // 2 { Name "DecalProjectorForwardEmissive" Tags{ "LightMode" = "DecalProjectorForwardEmissive" } @@ -177,7 +212,7 @@ Shader "HDRP/Decal" ENDHLSL } - Pass // 2 + Pass // 3 { Name "DBufferMesh" Tags{"LightMode" = "DBufferMesh"} @@ -221,7 +256,7 @@ Shader "HDRP/Decal" ENDHLSL } - Pass // 3 + Pass // 4 { Name "DecalMeshForwardEmissive" Tags{ "LightMode" = "DecalMeshForwardEmissive" } diff --git a/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/DecalProperties.hlsl b/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/DecalProperties.hlsl index de428ae8d3b..9b36679774e 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/DecalProperties.hlsl +++ b/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/DecalProperties.hlsl @@ -28,4 +28,9 @@ float _Smoothness; float _AO; float _Metallic; +#ifdef SCENESELECTIONPASS + int _ObjectId; + int _PassValue; +#endif + #endif diff --git a/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/DecalSystem.cs b/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/DecalSystem.cs index 0c941042b8b..05e2fb6718e 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/DecalSystem.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/DecalSystem.cs @@ -37,10 +37,11 @@ class DecalSystem // Caution: Enum num must match pass name for s_MaterialDecalPassNames array public enum MaterialDecalPass { - DBufferProjector = 0, - DecalProjectorForwardEmissive = 1, - DBufferMesh = 2, - DecalMeshForwardEmissive = 3, + SceneSelectionPass = 0, + DBufferProjector = 1, + DecalProjectorForwardEmissive = 2, + DBufferMesh = 3, + DecalMeshForwardEmissive = 4, }; public static readonly string[] s_MaterialDecalPassNames = Enum.GetNames(typeof(MaterialDecalPass)); diff --git a/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.shader b/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.shader index ec0a2c2c6b3..8785cda438a 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.shader +++ b/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.shader @@ -388,7 +388,7 @@ Shader "HDRP/Lit" ENDHLSL } - // Caution: The outline selection in the editor use the vertex shader/hull/domain shader of the first pass declare. So it should not bethe meta pass. + // Caution: The outline selection in the editor use the vertex shader/hull/domain shader of the first pass declare. So it should not be the meta pass. Pass { Name "GBuffer" diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPassDecal.hlsl b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPassDecal.hlsl index a7d812d0f23..b408bb3583f 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPassDecal.hlsl +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPassDecal.hlsl @@ -1,4 +1,4 @@ -#if (SHADERPASS != SHADERPASS_DBUFFER_PROJECTOR) && (SHADERPASS != SHADERPASS_DBUFFER_MESH) && (SHADERPASS != SHADERPASS_FORWARD_EMISSIVE_PROJECTOR) && (SHADERPASS != SHADERPASS_FORWARD_EMISSIVE_MESH) && (SHADERPASS != SHADERPASS_FORWARD_PREVIEW) +#if (SHADERPASS != SHADERPASS_DEPTH_ONLY) && (SHADERPASS != SHADERPASS_DBUFFER_PROJECTOR) && (SHADERPASS != SHADERPASS_DBUFFER_MESH) && (SHADERPASS != SHADERPASS_FORWARD_EMISSIVE_PROJECTOR) && (SHADERPASS != SHADERPASS_FORWARD_EMISSIVE_MESH) && (SHADERPASS != SHADERPASS_FORWARD_PREVIEW) #error SHADERPASS_is_not_correctly_define #endif @@ -27,13 +27,16 @@ PackedVaryingsType Vert(AttributesMesh inputMesh) void Frag( PackedVaryingsToPS packedInput, #if (SHADERPASS == SHADERPASS_DBUFFER_PROJECTOR) || (SHADERPASS == SHADERPASS_DBUFFER_MESH) OUTPUT_DBUFFER(outDBuffer) -#elif (SHADERPASS == SHADERPASS_FORWARD_PREVIEW) // Only used for preview in shader graph +#elif (SHADERPASS == SHADERPASS_DEPTH_ONLY) || (SHADERPASS == SHADERPASS_FORWARD_PREVIEW) // Only used for preview in shader graph out float4 outColor : SV_Target0 #else out float4 outEmissive : SV_Target0 #endif ) { +#if (SHADERPASS == SHADERPASS_DEPTH_ONLY) + outColor = float4(_ObjectId, _PassValue, 1.0, 1.0); +#else UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(packedInput); FragInputs input = UnpackVaryingsMeshToFragInputs(packedInput.vmesh); DecalSurfaceData surfaceData; @@ -147,4 +150,5 @@ void Frag( PackedVaryingsToPS packedInput, outEmissive.rgb = surfaceData.emissive * GetCurrentExposureMultiplier(); outEmissive.a = 1.0; #endif +#endif }