From 67b1117ab79886d6a995fdef6893eaac37b3f4da Mon Sep 17 00:00:00 2001 From: Adrien de Tocqueville Date: Thu, 8 Oct 2020 16:23:21 +0200 Subject: [PATCH 01/12] Scene selection pass --- .../Decal/ShaderGraph/DecalPass.template | 6 +++ .../Decal/ShaderGraph/DecalSubTarget.cs | 38 ++++++++++++++- .../Runtime/Material/Decal/Decal.shader | 47 ++++++++++++++++--- .../Material/Decal/DecalProperties.hlsl | 5 ++ .../Runtime/Material/Decal/DecalSystem.cs | 9 ++-- .../Runtime/Material/Lit/Lit.shader | 2 +- .../ShaderPass/ShaderPassDecal.hlsl | 8 +++- 7 files changed, 100 insertions(+), 15 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 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 } From 53ff57b0e7ae2b62856e41660434d2816e3009e7 Mon Sep 17 00:00:00 2001 From: Adrien de Tocqueville Date: Thu, 8 Oct 2020 16:25:24 +0200 Subject: [PATCH 02/12] Don't cull backfaces --- .../Editor/Material/ShaderGraph/HDTarget.cs | 1 + .../Runtime/Material/AxF/AxF.shader | 2 +- .../Runtime/Material/LayeredLit/LayeredLit.shader | 2 +- .../Runtime/Material/LayeredLit/LayeredLitTessellation.shader | 2 +- .../Runtime/Material/Lit/Lit.shader | 2 +- .../Runtime/Material/Lit/LitTessellation.shader | 2 +- .../Runtime/Material/TerrainLit/TerrainLit.shader | 2 +- .../Runtime/Material/Unlit/Unlit.shader | 2 +- 8 files changed, 8 insertions(+), 7 deletions(-) diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/HDTarget.cs b/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/HDTarget.cs index 030f852f580..5e7486bee07 100644 --- a/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/HDTarget.cs +++ b/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/HDTarget.cs @@ -597,6 +597,7 @@ public static class Uniforms public static RenderStateCollection SceneSelection = new RenderStateCollection { + { RenderState.Cull(Cull.Off) }, { RenderState.ColorMask("ColorMask 0") }, }; diff --git a/com.unity.render-pipelines.high-definition/Runtime/Material/AxF/AxF.shader b/com.unity.render-pipelines.high-definition/Runtime/Material/AxF/AxF.shader index a9f78c77f0e..e22d60871c9 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Material/AxF/AxF.shader +++ b/com.unity.render-pipelines.high-definition/Runtime/Material/AxF/AxF.shader @@ -221,7 +221,7 @@ Shader "HDRP/AxF" Name "SceneSelectionPass" Tags { "LightMode" = "SceneSelectionPass" } - Cull[_CullMode] + Cull Off HLSLPROGRAM diff --git a/com.unity.render-pipelines.high-definition/Runtime/Material/LayeredLit/LayeredLit.shader b/com.unity.render-pipelines.high-definition/Runtime/Material/LayeredLit/LayeredLit.shader index e76a18f01ba..96062fd3663 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Material/LayeredLit/LayeredLit.shader +++ b/com.unity.render-pipelines.high-definition/Runtime/Material/LayeredLit/LayeredLit.shader @@ -528,7 +528,7 @@ Shader "HDRP/LayeredLit" Name "SceneSelectionPass" Tags{ "LightMode" = "SceneSelectionPass" } - Cull[_CullMode] + Cull Off HLSLPROGRAM diff --git a/com.unity.render-pipelines.high-definition/Runtime/Material/LayeredLit/LayeredLitTessellation.shader b/com.unity.render-pipelines.high-definition/Runtime/Material/LayeredLit/LayeredLitTessellation.shader index 2e032c70e79..da0726989bd 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Material/LayeredLit/LayeredLitTessellation.shader +++ b/com.unity.render-pipelines.high-definition/Runtime/Material/LayeredLit/LayeredLitTessellation.shader @@ -546,7 +546,7 @@ Shader "HDRP/LayeredLitTessellation" Name "SceneSelectionPass" Tags{ "LightMode" = "SceneSelectionPass" } - Cull[_CullMode] + Cull Off ZWrite On 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..dca1e9f2cd8 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 @@ -356,7 +356,7 @@ Shader "HDRP/Lit" Name "SceneSelectionPass" Tags { "LightMode" = "SceneSelectionPass" } - Cull[_CullMode] + Cull Off HLSLPROGRAM diff --git a/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/LitTessellation.shader b/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/LitTessellation.shader index 94dfc7edcb2..ae72203e1ca 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/LitTessellation.shader +++ b/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/LitTessellation.shader @@ -370,7 +370,7 @@ Shader "HDRP/LitTessellation" Name "SceneSelectionPass" Tags { "LightMode" = "SceneSelectionPass" } - Cull[_CullMode] + Cull Off HLSLPROGRAM diff --git a/com.unity.render-pipelines.high-definition/Runtime/Material/TerrainLit/TerrainLit.shader b/com.unity.render-pipelines.high-definition/Runtime/Material/TerrainLit/TerrainLit.shader index 7537dc128dd..bbecdd8688c 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Material/TerrainLit/TerrainLit.shader +++ b/com.unity.render-pipelines.high-definition/Runtime/Material/TerrainLit/TerrainLit.shader @@ -271,7 +271,7 @@ Shader "HDRP/TerrainLit" Name "SceneSelectionPass" Tags { "LightMode" = "SceneSelectionPass" } - Cull[_CullMode] + Cull Off HLSLPROGRAM diff --git a/com.unity.render-pipelines.high-definition/Runtime/Material/Unlit/Unlit.shader b/com.unity.render-pipelines.high-definition/Runtime/Material/Unlit/Unlit.shader index 23b591aa62f..3da0773be9f 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Material/Unlit/Unlit.shader +++ b/com.unity.render-pipelines.high-definition/Runtime/Material/Unlit/Unlit.shader @@ -150,7 +150,7 @@ Shader "HDRP/Unlit" Name "SceneSelectionPass" Tags{ "LightMode" = "SceneSelectionPass" } - Cull[_CullMode] + Cull Off ZWrite On From 807d6c6c549e150895c1ef4d9c20c0490291678e Mon Sep 17 00:00:00 2001 From: Adrien de Tocqueville Date: Thu, 8 Oct 2020 17:24:08 +0200 Subject: [PATCH 03/12] 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 c84edcdccf0..78252d866e2 100644 --- a/com.unity.render-pipelines.high-definition/CHANGELOG.md +++ b/com.unity.render-pipelines.high-definition/CHANGELOG.md @@ -144,6 +144,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - Fixed alpha not having TAA applied to it. - Fix issue with alpha output in forward. - Fix compilation issue on Vulkan for shaders using high quality shadows in XR mode. +- Fixed scene selection pass for decal materials ### Changed - Preparation pass for RTSSShadows to be supported by render graph. From 283f54e77162a7b0f985dcf218436fd0837b078f Mon Sep 17 00:00:00 2001 From: Adrien de Tocqueville Date: Wed, 14 Oct 2020 14:09:58 +0200 Subject: [PATCH 04/12] Lit Shader picking pass --- .../Runtime/Material/Lit/Lit.shader | 37 ++++++++++ .../Runtime/Material/Lit/LitProperties.hlsl | 3 +- .../Material/PickingSpaceTransforms.hlsl | 70 +++++++++++++++++++ .../Material/PickingSpaceTransforms.hlsl.meta | 10 +++ .../ShaderPass/ShaderPassDepthOnly.hlsl | 6 +- 5 files changed, 123 insertions(+), 3 deletions(-) create mode 100644 com.unity.render-pipelines.high-definition/Runtime/Material/PickingSpaceTransforms.hlsl create mode 100644 com.unity.render-pipelines.high-definition/Runtime/Material/PickingSpaceTransforms.hlsl.meta 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 dca1e9f2cd8..5ed89e382c7 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 @@ -351,6 +351,43 @@ Shader "HDRP/Lit" // This tags allow to use the shader replacement features Tags{ "RenderPipeline"="HDRenderPipeline" "RenderType" = "HDLitShader" } + Pass + { + Name "ScenePickingPass" + Tags { "LightMode" = "Picking" } + + Cull [_CullMode] + + HLSLPROGRAM + + #pragma only_renderers d3d11 playstation xboxone vulkan metal switch + + //enable GPU instancing support + #pragma multi_compile_instancing + #pragma instancing_options renderinglayer + #pragma multi_compile _ DOTS_INSTANCING_ON + // enable dithering LOD crossfade + #pragma multi_compile _ LOD_FADE_CROSSFADE + + // Note: Require _SelectionID variable + + // 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 SCENEPICKINGPASS // This will drive the output of the scene selection shader + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/ShaderPass/LitDepthPass.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/LitData.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/PickingSpaceTransforms.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPassDepthOnly.hlsl" + + #pragma vertex Vert + #pragma fragment Frag + + #pragma editor_sync_compilation + ENDHLSL + } + Pass { Name "SceneSelectionPass" diff --git a/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/LitProperties.hlsl b/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/LitProperties.hlsl index e0640512335..adfc167033a 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/LitProperties.hlsl +++ b/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/LitProperties.hlsl @@ -286,9 +286,10 @@ float _TessellationObjectScale; float _TessellationTilingScale; #endif -// Following two variables are feeded by the C++ Editor for Scene selection +// Following three variables are feeded by the C++ Editor for Scene selection int _ObjectId; int _PassValue; +float4 _SelectionID; CBUFFER_END diff --git a/com.unity.render-pipelines.high-definition/Runtime/Material/PickingSpaceTransforms.hlsl b/com.unity.render-pipelines.high-definition/Runtime/Material/PickingSpaceTransforms.hlsl new file mode 100644 index 00000000000..ba863795538 --- /dev/null +++ b/com.unity.render-pipelines.high-definition/Runtime/Material/PickingSpaceTransforms.hlsl @@ -0,0 +1,70 @@ +#ifndef UNITY_PICKING_SPACE_TRANSFORMS_INCLUDED +#define UNITY_PICKING_SPACE_TRANSFORMS_INCLUDED + +#ifdef SCENEPICKINGPASS + +// The picking pass uses specific matrices defined directly from the c++ (without camera relative rendering) +// So we have to redefine the space transform functions to overwrite the used matrices + +#undef SHADEROPTIONS_CAMERA_RELATIVE_RENDERING + +// Define the correct matrices +#undef unity_ObjectToWorld +#undef unity_MatrixVP +float4x4 unity_MatrixV; +float4x4 unity_MatrixVP; +float4x4 unity_WorldToObject; +float4x4 glstate_matrix_projection; + +#undef UNITY_MATRIX_M +#define UNITY_MATRIX_M unity_ObjectToWorld + +#undef UNITY_MATRIX_I_M +#define UNITY_MATRIX_I_M unity_WorldToObject + +#undef UNITY_MATRIX_V +#define UNITY_MATRIX_V unity_MatrixV + +#undef UNITY_MATRIX_VP +#define UNITY_MATRIX_VP unity_MatrixVP + +#undef UNITY_MATRIX_P +#define UNITY_MATRIX_P glstate_matrix_projection + + +// Overwrite the SpaceTransforms functions +#define GetObjectToWorldMatrix GetObjectToWorldMatrix_Picking +#define GetWorldToObjectMatrix GetWorldToObjectMatrix_Picking +#define GetWorldToViewMatrix GetWorldToViewMatrix_Picking +#define GetWorldToHClipMatrix GetWorldToHClipMatrix_Picking +#define GetViewToHClipMatrix GetViewToHClipMatrix_Picking +#define GetAbsolutePositionWS GetAbsolutePositionWS_Picking +#define GetCameraRelativePositionWS GetCameraRelativePositionWS_Picking +#define GetOddNegativeScale GetOddNegativeScale_Picking +#define TransformObjectToWorld TransformObjectToWorld_Picking +#define TransformWorldToObject TransformWorldToObject_Picking +#define TransformWorldToView TransformWorldToView_Picking +#define TransformObjectToHClip TransformObjectToHClip_Picking +#define TransformWorldToHClip TransformWorldToHClip_Picking +#define TransformWViewToHClip TransformWViewToHClip_Picking +#define TransformObjectToWorldDir TransformObjectToWorldDir_Picking +#define TransformWorldToObjectDir TransformWorldToObjectDir_Picking +#define TransformWorldToViewDir TransformWorldToViewDir_Picking +#define TransformWorldToHClipDir TransformWorldToHClipDir_Picking +#define TransformObjectToWorldNormal TransformObjectToWorldNormal_Picking +#define TransformWorldToObjectNormal TransformWorldToObjectNormal_Picking +#define CreateTangentToWorld CreateTangentToWorld_Picking +#define TransformTangentToWorld TransformTangentToWorld_Picking +#define TransformWorldToTangent TransformWorldToTangent_Picking +#define TransformTangentToObject TransformTangentToObject_Picking +#define TransformObjectToTangent TransformObjectToTangent_Picking + + +// Redefine the functions using the new macros +#undef UNITY_SPACE_TRANSFORMS_INCLUDED +#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/SpaceTransforms.hlsl" + + + +#endif +#endif diff --git a/com.unity.render-pipelines.high-definition/Runtime/Material/PickingSpaceTransforms.hlsl.meta b/com.unity.render-pipelines.high-definition/Runtime/Material/PickingSpaceTransforms.hlsl.meta new file mode 100644 index 00000000000..6af1b1fc268 --- /dev/null +++ b/com.unity.render-pipelines.high-definition/Runtime/Material/PickingSpaceTransforms.hlsl.meta @@ -0,0 +1,10 @@ +fileFormatVersion: 2 +guid: 07878c52127f8a248be207c0fb1b6e77 +ShaderImporter: + externalObjects: {} + defaultTextures: [] + nonModifiableTextures: [] + preprocessorOverride: 0 + userData: + assetBundleName: + assetBundleVariant: diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPassDepthOnly.hlsl b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPassDepthOnly.hlsl index b3d5b0aa701..342f1500fde 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPassDepthOnly.hlsl +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPassDepthOnly.hlsl @@ -11,7 +11,7 @@ PackedVaryingsType Vert(AttributesMesh inputMesh) { VaryingsType varyingsType; -#if (SHADERPASS == SHADERPASS_DEPTH_ONLY) && defined(HAVE_RECURSIVE_RENDERING) && !defined(SCENESELECTIONPASS) +#if (SHADERPASS == SHADERPASS_DEPTH_ONLY) && defined(HAVE_RECURSIVE_RENDERING) && !defined(SCENESELECTIONPASS) && !defined(SCENEPICKINGPASS) // If we have a recursive raytrace object, we will not render it. // As we don't want to rely on renderqueue to exclude the object from the list, // we cull it by settings position to NaN value. @@ -51,7 +51,7 @@ PackedVaryingsToPS VertTesselation(VaryingsToDS input) #endif void Frag( PackedVaryingsToPS packedInput - #if defined(SCENESELECTIONPASS) + #if defined(SCENESELECTIONPASS) || defined(SCENEPICKINGPASS) , out float4 outColor : SV_Target0 #else #ifdef WRITE_MSAA_DEPTH @@ -101,6 +101,8 @@ void Frag( PackedVaryingsToPS packedInput #ifdef SCENESELECTIONPASS // We use depth prepass for scene selection in the editor, this code allow to output the outline correctly outColor = float4(_ObjectId, _PassValue, 1.0, 1.0); +#elif defined(SCENEPICKINGPASS) + outColor = _SelectionID; #else // Depth and Alpha to coverage From 777de91d99abe9a161464dec0e11957ebb9f5d62 Mon Sep 17 00:00:00 2001 From: Adrien de Tocqueville Date: Thu, 15 Oct 2020 10:52:05 +0200 Subject: [PATCH 05/12] hdrp shaders --- .../Runtime/Material/AxF/AxF.shader | 29 +++++++++++++++ .../Runtime/Material/AxF/AxFProperties.hlsl | 3 +- .../Material/LayeredLit/LayeredLit.shader | 36 +++++++++++++++++++ .../Runtime/Material/Lit/Lit.shader | 3 +- .../Material/PickingSpaceTransforms.hlsl | 2 +- 5 files changed, 70 insertions(+), 3 deletions(-) diff --git a/com.unity.render-pipelines.high-definition/Runtime/Material/AxF/AxF.shader b/com.unity.render-pipelines.high-definition/Runtime/Material/AxF/AxF.shader index e22d60871c9..97ce95253f0 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Material/AxF/AxF.shader +++ b/com.unity.render-pipelines.high-definition/Runtime/Material/AxF/AxF.shader @@ -216,6 +216,35 @@ Shader "HDRP/AxF" // This tags allow to use the shader replacement features Tags{ "RenderPipeline" = "HDRenderPipeline" "RenderType" = "HDLitShader" } + Pass + { + Name "ScenePickingPass" + Tags { "LightMode" = "Picking" } + + Cull [_CullMode] + + HLSLPROGRAM + + // Note: Require _SelectionID variable + + // 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 SCENEPICKINGPASS + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/AxF/AxF.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/AxF/ShaderPass/AxFDepthPass.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/AxF/AxFData.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/PickingSpaceTransforms.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPassDepthOnly.hlsl" + + #pragma vertex Vert + #pragma fragment Frag + + #pragma editor_sync_compilation + + ENDHLSL + } + Pass { Name "SceneSelectionPass" diff --git a/com.unity.render-pipelines.high-definition/Runtime/Material/AxF/AxFProperties.hlsl b/com.unity.render-pipelines.high-definition/Runtime/Material/AxF/AxFProperties.hlsl index 7cced1b697f..f454df5ff4c 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Material/AxF/AxFProperties.hlsl +++ b/com.unity.render-pipelines.high-definition/Runtime/Material/AxF/AxFProperties.hlsl @@ -133,8 +133,9 @@ float _SpecularAAThreshold; // TODO: Fix the code in legacy unity so we can customize the behavior for GI float3 _EmissionColor; -// Following two variables are feeded by the C++ Editor for Scene selection +// Following three variables are feeded by the C++ Editor for Scene selection int _ObjectId; int _PassValue; +float4 _SelectionID; CBUFFER_END diff --git a/com.unity.render-pipelines.high-definition/Runtime/Material/LayeredLit/LayeredLit.shader b/com.unity.render-pipelines.high-definition/Runtime/Material/LayeredLit/LayeredLit.shader index 96062fd3663..ac9506ede07 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Material/LayeredLit/LayeredLit.shader +++ b/com.unity.render-pipelines.high-definition/Runtime/Material/LayeredLit/LayeredLit.shader @@ -523,6 +523,42 @@ Shader "HDRP/LayeredLit" // This tags allow to use the shader replacement features Tags{ "RenderPipeline" = "HDRenderPipeline" "RenderType" = "HDLitShader" } + Pass + { + Name "ScenePickingPass" + Tags { "LightMode" = "Picking" } + + Cull [_CullMode] + + HLSLPROGRAM + + #pragma only_renderers d3d11 playstation xboxone vulkan metal switch + //enable GPU instancing support + #pragma multi_compile_instancing + #pragma multi_compile _ DOTS_INSTANCING_ON + #pragma instancing_options renderinglayer + #pragma multi_compile _ LOD_FADE_CROSSFADE + + // Note: Require _SelectionID variable + + // 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 SCENEPICKINGPASS + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/ShaderPass/LitDepthPass.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/LayeredLit/LayeredLitData.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/PickingSpaceTransforms.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPassDepthOnly.hlsl" + + #pragma vertex Vert + #pragma fragment Frag + + #pragma editor_sync_compilation + + ENDHLSL + } + Pass { Name "SceneSelectionPass" 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 5ed89e382c7..20f73a690ae 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 @@ -373,7 +373,7 @@ Shader "HDRP/Lit" // 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 SCENEPICKINGPASS // This will drive the output of the scene selection shader + #define SCENEPICKINGPASS #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl" #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.hlsl" #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/ShaderPass/LitDepthPass.hlsl" @@ -385,6 +385,7 @@ Shader "HDRP/Lit" #pragma fragment Frag #pragma editor_sync_compilation + ENDHLSL } diff --git a/com.unity.render-pipelines.high-definition/Runtime/Material/PickingSpaceTransforms.hlsl b/com.unity.render-pipelines.high-definition/Runtime/Material/PickingSpaceTransforms.hlsl index ba863795538..90688d963d2 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Material/PickingSpaceTransforms.hlsl +++ b/com.unity.render-pipelines.high-definition/Runtime/Material/PickingSpaceTransforms.hlsl @@ -3,7 +3,7 @@ #ifdef SCENEPICKINGPASS -// The picking pass uses specific matrices defined directly from the c++ (without camera relative rendering) +// The picking pass uses custom matrices defined directly from the c++ // So we have to redefine the space transform functions to overwrite the used matrices #undef SHADEROPTIONS_CAMERA_RELATIVE_RENDERING From 88f7b8e2c2a0614381381866c6ee6cf1844758e2 Mon Sep 17 00:00:00 2001 From: Adrien de Tocqueville Date: Thu, 15 Oct 2020 11:51:22 +0200 Subject: [PATCH 06/12] Added ScenePickingPass to ShaderGraph --- .../BuildProcessors/HDRPPreprocessShaders.cs | 3 +- .../Material/ShaderGraph/HDShaderPasses.cs | 43 +++++++++++++++++++ .../Editor/Material/ShaderGraph/HDTarget.cs | 21 +++++++++ .../Material/ShaderGraph/SurfaceSubTarget.cs | 1 + .../ShaderGraph/Templates/ShaderPass.template | 5 +++ 5 files changed, 72 insertions(+), 1 deletion(-) diff --git a/com.unity.render-pipelines.high-definition/Editor/BuildProcessors/HDRPPreprocessShaders.cs b/com.unity.render-pipelines.high-definition/Editor/BuildProcessors/HDRPPreprocessShaders.cs index a3f07b5fbc2..b82ee87e056 100644 --- a/com.unity.render-pipelines.high-definition/Editor/BuildProcessors/HDRPPreprocessShaders.cs +++ b/com.unity.render-pipelines.high-definition/Editor/BuildProcessors/HDRPPreprocessShaders.cs @@ -24,7 +24,8 @@ protected override bool DoShadersStripper(HDRenderPipelineAsset hdrpAsset, Shade // Remove editor only pass bool isSceneSelectionPass = snippet.passName == "SceneSelectionPass"; - if (isSceneSelectionPass) + bool isScenePickingPass = snippet.passName == "ScenePickingPass"; + if (isSceneSelectionPass || isScenePickingPass) return true; // CAUTION: We can't identify transparent material in the stripped in a general way. diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/HDShaderPasses.cs b/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/HDShaderPasses.cs index 9806b902065..53ae58e96ea 100644 --- a/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/HDShaderPasses.cs +++ b/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/HDShaderPasses.cs @@ -74,6 +74,49 @@ IncludeCollection GenerateIncludes() #endregion +#region Scene Picking Pass + + public static PassDescriptor GenerateScenePicking(bool supportLighting) + { + return new PassDescriptor + { + // Definition + displayName = "ScenePickingPass", + referenceName = "SHADERPASS_DEPTH_ONLY", + lightMode = "Picking", + useInPreview = false, + + // Collections + renderStates = CoreRenderStates.ScenePicking, + pragmas = CorePragmas.DotsInstancedInV1AndV2EditorSync, + defines = CoreDefines.ScenePicking, + includes = GenerateIncludes(), + }; + + IncludeCollection GenerateIncludes() + { + var includes = new IncludeCollection(); + + includes.Add(CoreIncludes.CorePregraph); + if (supportLighting) + includes.Add(CoreIncludes.kNormalSurfaceGradient, IncludeLocation.Pregraph); + includes.Add(CoreIncludes.kPassPlaceholder, IncludeLocation.Pregraph); + includes.Add(CoreIncludes.CoreUtility); + if (supportLighting) + { + includes.Add(CoreIncludes.kDecalUtilities, IncludeLocation.Pregraph); + includes.Add(CoreIncludes.kPostDecalsPlaceholder, IncludeLocation.Pregraph); + } + includes.Add(CoreIncludes.kShaderGraphFunctions, IncludeLocation.Pregraph); + includes.Add(CoreIncludes.kPickingSpaceTransforms, IncludeLocation.Pregraph); + includes.Add(CoreIncludes.kPassDepthOnly, IncludeLocation.Postgraph); + + return includes; + } + } + +#endregion + #region Scene Selection Pass public static PassDescriptor GenerateSceneSelection(bool supportLighting) diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/HDTarget.cs b/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/HDTarget.cs index befd7bb5f07..b47b9cf79f8 100644 --- a/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/HDTarget.cs +++ b/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/HDTarget.cs @@ -594,6 +594,11 @@ public static class Uniforms { RenderState.ColorMask("ColorMask 0") }, }; + public static RenderStateCollection ScenePicking = new RenderStateCollection + { + { RenderState.Cull(Uniforms.cullMode) }, + }; + public static RenderStateCollection SceneSelection = new RenderStateCollection { { RenderState.Cull(Cull.Off) }, @@ -800,6 +805,12 @@ static class CoreKeywords #region Defines static class CoreDefines { + public static DefineCollection ScenePicking = new DefineCollection + { + { RayTracingQualityNode.GetRayTracingQualityKeyword(), 0 }, + { CoreKeywordDescriptors.ScenePickingPass, 1 }, + }; + public static DefineCollection SceneSelection = new DefineCollection { { RayTracingQualityNode.GetRayTracingQualityKeyword(), 0 }, @@ -925,6 +936,7 @@ static class CoreIncludes public const string kPassForwardUnlit = "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPassForwardUnlit.hlsl"; public const string kPassConstant = "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPassConstant.hlsl"; public const string kPassFullScreenDebug = "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPassFullScreenDebug.hlsl"; + public const string kPickingSpaceTransforms = "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/PickingSpaceTransforms.hlsl"; public static IncludeCollection MinimalCorePregraph = new IncludeCollection { @@ -1158,6 +1170,15 @@ static class CoreKeywordDescriptors scope = KeywordScope.Local, }; + public static KeywordDescriptor ScenePickingPass = new KeywordDescriptor() + { + displayName = "Scene Picking Pass", + referenceName = "SCENEPICKINGPASS", + type = KeywordType.Boolean, + definition = KeywordDefinition.ShaderFeature, + scope = KeywordScope.Local, + }; + public static KeywordDescriptor SceneSelectionPass = new KeywordDescriptor() { displayName = "Scene Selection Pass", diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/SurfaceSubTarget.cs b/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/SurfaceSubTarget.cs index 0faba91cd3c..644da005c21 100644 --- a/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/SurfaceSubTarget.cs +++ b/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/SurfaceSubTarget.cs @@ -79,6 +79,7 @@ PassCollection GetPasses() // Common "surface" passes HDShaderPasses.GenerateShadowCaster(supportLighting), HDShaderPasses.GenerateMETA(supportLighting), + HDShaderPasses.GenerateScenePicking(supportLighting), HDShaderPasses.GenerateSceneSelection(supportLighting), HDShaderPasses.GenerateMotionVectors(supportLighting, supportForward), { HDShaderPasses.GenerateBackThenFront(supportLighting), new FieldCondition(HDFields.TransparentBackFace, true)}, diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/Templates/ShaderPass.template b/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/Templates/ShaderPass.template index 34231b87c85..967b339a393 100644 --- a/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/Templates/ShaderPass.template +++ b/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/Templates/ShaderPass.template @@ -118,6 +118,11 @@ Pass // -- Graph Properties $splice(GraphProperties) + // -- Property used by ScenePickingPass + #ifdef SCENEPICKINGPASS + float4 _SelectionID; + #endif + // -- Properties used by SceneSelectionPass #ifdef SCENESELECTIONPASS int _ObjectId; From 330ca27bd1f296fc29c24030eca38099c465272f Mon Sep 17 00:00:00 2001 From: Adrien de Tocqueville Date: Thu, 15 Oct 2020 13:21:14 +0200 Subject: [PATCH 07/12] Fixes for decals --- .../Editor/Material/Decal/ShaderGraph/DecalSubTarget.cs | 7 ++++++- .../Runtime/Material/Decal/Decal.shader | 2 +- 2 files changed, 7 insertions(+), 2 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 d9b72c249f4..017055111f0 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 @@ -228,7 +228,7 @@ public static class DecalPasses useInPreview = false, // Collections - renderStates = CoreRenderStates.ScenePicking, + renderStates = DecalRenderStates.ScenePicking, pragmas = DecalPragmas.Instanced, defines = CoreDefines.ScenePicking, includes = DecalIncludes.ScenePicking, @@ -402,6 +402,11 @@ static class DecalRenderStates readonly static string s_DecalColorMask = "ColorMask [_DecalColorMask0]\n\tColorMask [_DecalColorMask1] 1\n\tColorMask [_DecalColorMask2] 2\n\tColorMask [_DecalColorMask3] 3"; readonly static string s_DecalBlend = "Blend 0 SrcAlpha OneMinusSrcAlpha, Zero OneMinusSrcAlpha \n\tBlend 1 SrcAlpha OneMinusSrcAlpha, Zero OneMinusSrcAlpha \n\tBlend 2 SrcAlpha OneMinusSrcAlpha, Zero OneMinusSrcAlpha \n\tBlend 3 Zero OneMinusSrcColor"; + public static RenderStateCollection ScenePicking = new RenderStateCollection + { + { RenderState.Cull(Cull.Back) }, + }; + public static RenderStateCollection DBufferProjector = new RenderStateCollection { { RenderState.Blend(s_DecalBlend) }, 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 418eadfea2a..92831b74ec9 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 @@ -128,7 +128,7 @@ Shader "HDRP/Decal" #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/Material/PickingSpaceTransforms.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/PickingSpaceTransforms.hlsl" #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPassDecal.hlsl" #pragma editor_sync_compilation From 97681b8d404d82c40de712257aa3f04009ae3803 Mon Sep 17 00:00:00 2001 From: Adrien de Tocqueville Date: Thu, 22 Oct 2020 15:44:57 +0200 Subject: [PATCH 08/12] Tessellation picking --- .../LayeredLit/LayeredLitTessellation.shader | 31 ++++++++++++++ .../Material/Lit/LitDataMeshModification.hlsl | 7 +++- .../Material/Lit/LitTessellation.shader | 31 ++++++++++++++ .../ShaderLibrary/PickingSpaceTransforms.hlsl | 42 ++++++++++++++++++- 4 files changed, 108 insertions(+), 3 deletions(-) diff --git a/com.unity.render-pipelines.high-definition/Runtime/Material/LayeredLit/LayeredLitTessellation.shader b/com.unity.render-pipelines.high-definition/Runtime/Material/LayeredLit/LayeredLitTessellation.shader index da0726989bd..1b392b3a867 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Material/LayeredLit/LayeredLitTessellation.shader +++ b/com.unity.render-pipelines.high-definition/Runtime/Material/LayeredLit/LayeredLitTessellation.shader @@ -541,6 +541,37 @@ Shader "HDRP/LayeredLitTessellation" // This tags allow to use the shader replacement features Tags{ "RenderPipeline" = "HDRenderPipeline" "RenderType" = "HDLitShader" } + Pass + { + Name "ScenePickingPass" + Tags { "LightMode" = "Picking" } + + Cull [_CullMode] + + HLSLPROGRAM + + // Note: Require _SelectionID variable + + // 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 SCENEPICKINGPASS + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/ShaderPass/LitDepthPass.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/LayeredLit/LayeredLitData.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/PickingSpaceTransforms.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPassDepthOnly.hlsl" + + #pragma vertex Vert + #pragma fragment Frag + #pragma hull Hull + #pragma domain Domain + + #pragma editor_sync_compilation + + ENDHLSL + } + Pass { Name "SceneSelectionPass" diff --git a/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/LitDataMeshModification.hlsl b/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/LitDataMeshModification.hlsl index a3ce2ef3aec..7ea5f75fe58 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/LitDataMeshModification.hlsl +++ b/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/LitDataMeshModification.hlsl @@ -58,10 +58,15 @@ float4 GetTessellationFactors(float3 p0, float3 p1, float3 p2, float3 n0, float3 // Thus the following code play with both. float frustumEps = -maxDisplacement; // "-" Expected parameter for CullTriangleEdgesFrustum +#ifndef SCENEPICKINGPASS // TODO: the only reason I test the near plane here is that I am not sure that the product of other tessellation factors // (such as screen-space/distance-based) results in the tessellation factor of 1 for the geometry behind the near plane. // If that is the case (and, IMHO, it should be), we shouldn't have to test the near plane here. bool3 frustumCullEdgesMainView = CullTriangleEdgesFrustum(p0, p1, p2, frustumEps, _FrustumPlanes, 5); // Do not test the far plane +#else + // During the scene picking pass, we have no access to camera frustum planes + bool3 frustumCullEdgesMainView = false; +#endif #if defined(SHADERPASS) && (SHADERPASS != SHADERPASS_SHADOWS) bool frustumCullCurrView = all(frustumCullEdgesMainView); @@ -71,7 +76,7 @@ float4 GetTessellationFactors(float3 p0, float3 p1, float3 p2, float3 n0, float3 bool faceCull = false; -#ifndef _DOUBLESIDED_ON +#if !defined(_DOUBLESIDED_ON) && !defined(SCENESELECTIONPASS) && !defined(SCENEPICKINGPASS) if (_TessellationBackFaceCullEpsilon > -1.0) // Is back-face culling enabled ? { // Handle transform mirroring (like negative scaling) diff --git a/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/LitTessellation.shader b/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/LitTessellation.shader index 12a50247bdc..5b67e86d5fe 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/LitTessellation.shader +++ b/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/LitTessellation.shader @@ -364,6 +364,37 @@ Shader "HDRP/LitTessellation" // This tags allow to use the shader replacement features Tags{ "RenderPipeline"="HDRenderPipeline" "RenderType" = "HDLitShader" } + Pass + { + Name "ScenePickingPass" + Tags { "LightMode" = "Picking" } + + Cull [_CullMode] + + HLSLPROGRAM + + // Note: Require _SelectionID variable + + // 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 SCENEPICKINGPASS + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/ShaderPass/LitDepthPass.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/LitData.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/PickingSpaceTransforms.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPassDepthOnly.hlsl" + + #pragma vertex Vert + #pragma fragment Frag + #pragma hull Hull + #pragma domain Domain + + #pragma editor_sync_compilation + + ENDHLSL + } + Pass { Name "SceneSelectionPass" diff --git a/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/PickingSpaceTransforms.hlsl b/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/PickingSpaceTransforms.hlsl index 90688d963d2..981b2c41bbd 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/PickingSpaceTransforms.hlsl +++ b/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/PickingSpaceTransforms.hlsl @@ -13,14 +13,13 @@ #undef unity_MatrixVP float4x4 unity_MatrixV; float4x4 unity_MatrixVP; -float4x4 unity_WorldToObject; float4x4 glstate_matrix_projection; #undef UNITY_MATRIX_M #define UNITY_MATRIX_M unity_ObjectToWorld #undef UNITY_MATRIX_I_M -#define UNITY_MATRIX_I_M unity_WorldToObject +#define UNITY_MATRIX_I_M inverse(unity_ObjectToWorld) #undef UNITY_MATRIX_V #define UNITY_MATRIX_V unity_MatrixV @@ -60,6 +59,45 @@ float4x4 glstate_matrix_projection; #define TransformObjectToTangent TransformObjectToTangent_Picking +float4x4 inverse(float4x4 m) { + float n11 = m[0][0], n12 = m[1][0], n13 = m[2][0], n14 = m[3][0]; + float n21 = m[0][1], n22 = m[1][1], n23 = m[2][1], n24 = m[3][1]; + float n31 = m[0][2], n32 = m[1][2], n33 = m[2][2], n34 = m[3][2]; + float n41 = m[0][3], n42 = m[1][3], n43 = m[2][3], n44 = m[3][3]; + + float t11 = n23 * n34 * n42 - n24 * n33 * n42 + n24 * n32 * n43 - n22 * n34 * n43 - n23 * n32 * n44 + n22 * n33 * n44; + float t12 = n14 * n33 * n42 - n13 * n34 * n42 - n14 * n32 * n43 + n12 * n34 * n43 + n13 * n32 * n44 - n12 * n33 * n44; + float t13 = n13 * n24 * n42 - n14 * n23 * n42 + n14 * n22 * n43 - n12 * n24 * n43 - n13 * n22 * n44 + n12 * n23 * n44; + float t14 = n14 * n23 * n32 - n13 * n24 * n32 - n14 * n22 * n33 + n12 * n24 * n33 + n13 * n22 * n34 - n12 * n23 * n34; + + float det = n11 * t11 + n21 * t12 + n31 * t13 + n41 * t14; + float idet = 1.0f / det; + + float4x4 ret; + + ret[0][0] = t11 * idet; + ret[0][1] = (n24 * n33 * n41 - n23 * n34 * n41 - n24 * n31 * n43 + n21 * n34 * n43 + n23 * n31 * n44 - n21 * n33 * n44) * idet; + ret[0][2] = (n22 * n34 * n41 - n24 * n32 * n41 + n24 * n31 * n42 - n21 * n34 * n42 - n22 * n31 * n44 + n21 * n32 * n44) * idet; + ret[0][3] = (n23 * n32 * n41 - n22 * n33 * n41 - n23 * n31 * n42 + n21 * n33 * n42 + n22 * n31 * n43 - n21 * n32 * n43) * idet; + + ret[1][0] = t12 * idet; + ret[1][1] = (n13 * n34 * n41 - n14 * n33 * n41 + n14 * n31 * n43 - n11 * n34 * n43 - n13 * n31 * n44 + n11 * n33 * n44) * idet; + ret[1][2] = (n14 * n32 * n41 - n12 * n34 * n41 - n14 * n31 * n42 + n11 * n34 * n42 + n12 * n31 * n44 - n11 * n32 * n44) * idet; + ret[1][3] = (n12 * n33 * n41 - n13 * n32 * n41 + n13 * n31 * n42 - n11 * n33 * n42 - n12 * n31 * n43 + n11 * n32 * n43) * idet; + + ret[2][0] = t13 * idet; + ret[2][1] = (n14 * n23 * n41 - n13 * n24 * n41 - n14 * n21 * n43 + n11 * n24 * n43 + n13 * n21 * n44 - n11 * n23 * n44) * idet; + ret[2][2] = (n12 * n24 * n41 - n14 * n22 * n41 + n14 * n21 * n42 - n11 * n24 * n42 - n12 * n21 * n44 + n11 * n22 * n44) * idet; + ret[2][3] = (n13 * n22 * n41 - n12 * n23 * n41 - n13 * n21 * n42 + n11 * n23 * n42 + n12 * n21 * n43 - n11 * n22 * n43) * idet; + + ret[3][0] = t14 * idet; + ret[3][1] = (n13 * n24 * n31 - n14 * n23 * n31 + n14 * n21 * n33 - n11 * n24 * n33 - n13 * n21 * n34 + n11 * n23 * n34) * idet; + ret[3][2] = (n14 * n22 * n31 - n12 * n24 * n31 - n14 * n21 * n32 + n11 * n24 * n32 + n12 * n21 * n34 - n11 * n22 * n34) * idet; + ret[3][3] = (n12 * n23 * n31 - n13 * n22 * n31 + n13 * n21 * n32 - n11 * n23 * n32 - n12 * n21 * n33 + n11 * n22 * n33) * idet; + + return ret; +} + // Redefine the functions using the new macros #undef UNITY_SPACE_TRANSFORMS_INCLUDED #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/SpaceTransforms.hlsl" From 0319b6b041cce5b615c82c75460172439f8851b7 Mon Sep 17 00:00:00 2001 From: Sebastien Lagarde Date: Fri, 23 Oct 2020 18:41:24 +0200 Subject: [PATCH 09/12] Update Upgrading-from-2020.1-to-2020.2.md --- .../Documentation~/Upgrading-from-2020.1-to-2020.2.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/com.unity.render-pipelines.high-definition/Documentation~/Upgrading-from-2020.1-to-2020.2.md b/com.unity.render-pipelines.high-definition/Documentation~/Upgrading-from-2020.1-to-2020.2.md index 9d82351806f..5ca855bfc01 100644 --- a/com.unity.render-pipelines.high-definition/Documentation~/Upgrading-from-2020.1-to-2020.2.md +++ b/com.unity.render-pipelines.high-definition/Documentation~/Upgrading-from-2020.1-to-2020.2.md @@ -185,6 +185,8 @@ From 10.x, HDRP includes a new optimization for [Planar Reflection Probes](Plana For example, the call in the Lit shader has been updated to: `float4 preLD = SampleEnv(lightLoopContext, lightData.envIndex, R, PerceptualRoughnessToMipmapLevel(preLightData.iblPerceptualRoughness) * lightData.roughReflections, lightData.rangeCompressionFactorCompensation, posInput.positionNDC);` +From 10.x, a new pass ScenePickingPass have been added to all the shader and master node to allow the editor to correctly handle the picking with tesselated objects and backfaced objects. + ## Raytracing From Unity 2020.2, the Raytracing Node in shader graph now apply the raytraced path (previously low path) to all raytraced effects but path tracing. From 4ebb8390b77d20962fc09bcfd4fde47ce7232baf Mon Sep 17 00:00:00 2001 From: Adrien de Tocqueville Date: Mon, 26 Oct 2020 12:02:29 +0100 Subject: [PATCH 10/12] Move function to common.hlsl --- .../ShaderLibrary/Common.hlsl | 40 ++++++++++++++++++ .../ShaderLibrary/PickingSpaceTransforms.hlsl | 42 +------------------ 2 files changed, 41 insertions(+), 41 deletions(-) diff --git a/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl b/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl index c1c6827ac77..917ac268bad 100644 --- a/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl +++ b/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl @@ -692,6 +692,46 @@ real Pow4(real x) TEMPLATE_3_FLT(RangeRemap, min, max, t, return saturate((t - min) / (max - min))) +float4x4 Inverse(float4x4 m) +{ + float n11 = m[0][0], n12 = m[1][0], n13 = m[2][0], n14 = m[3][0]; + float n21 = m[0][1], n22 = m[1][1], n23 = m[2][1], n24 = m[3][1]; + float n31 = m[0][2], n32 = m[1][2], n33 = m[2][2], n34 = m[3][2]; + float n41 = m[0][3], n42 = m[1][3], n43 = m[2][3], n44 = m[3][3]; + + float t11 = n23 * n34 * n42 - n24 * n33 * n42 + n24 * n32 * n43 - n22 * n34 * n43 - n23 * n32 * n44 + n22 * n33 * n44; + float t12 = n14 * n33 * n42 - n13 * n34 * n42 - n14 * n32 * n43 + n12 * n34 * n43 + n13 * n32 * n44 - n12 * n33 * n44; + float t13 = n13 * n24 * n42 - n14 * n23 * n42 + n14 * n22 * n43 - n12 * n24 * n43 - n13 * n22 * n44 + n12 * n23 * n44; + float t14 = n14 * n23 * n32 - n13 * n24 * n32 - n14 * n22 * n33 + n12 * n24 * n33 + n13 * n22 * n34 - n12 * n23 * n34; + + float det = n11 * t11 + n21 * t12 + n31 * t13 + n41 * t14; + float idet = 1.0f / det; + + float4x4 ret; + + ret[0][0] = t11 * idet; + ret[0][1] = (n24 * n33 * n41 - n23 * n34 * n41 - n24 * n31 * n43 + n21 * n34 * n43 + n23 * n31 * n44 - n21 * n33 * n44) * idet; + ret[0][2] = (n22 * n34 * n41 - n24 * n32 * n41 + n24 * n31 * n42 - n21 * n34 * n42 - n22 * n31 * n44 + n21 * n32 * n44) * idet; + ret[0][3] = (n23 * n32 * n41 - n22 * n33 * n41 - n23 * n31 * n42 + n21 * n33 * n42 + n22 * n31 * n43 - n21 * n32 * n43) * idet; + + ret[1][0] = t12 * idet; + ret[1][1] = (n13 * n34 * n41 - n14 * n33 * n41 + n14 * n31 * n43 - n11 * n34 * n43 - n13 * n31 * n44 + n11 * n33 * n44) * idet; + ret[1][2] = (n14 * n32 * n41 - n12 * n34 * n41 - n14 * n31 * n42 + n11 * n34 * n42 + n12 * n31 * n44 - n11 * n32 * n44) * idet; + ret[1][3] = (n12 * n33 * n41 - n13 * n32 * n41 + n13 * n31 * n42 - n11 * n33 * n42 - n12 * n31 * n43 + n11 * n32 * n43) * idet; + + ret[2][0] = t13 * idet; + ret[2][1] = (n14 * n23 * n41 - n13 * n24 * n41 - n14 * n21 * n43 + n11 * n24 * n43 + n13 * n21 * n44 - n11 * n23 * n44) * idet; + ret[2][2] = (n12 * n24 * n41 - n14 * n22 * n41 + n14 * n21 * n42 - n11 * n24 * n42 - n12 * n21 * n44 + n11 * n22 * n44) * idet; + ret[2][3] = (n13 * n22 * n41 - n12 * n23 * n41 - n13 * n21 * n42 + n11 * n23 * n42 + n12 * n21 * n43 - n11 * n22 * n43) * idet; + + ret[3][0] = t14 * idet; + ret[3][1] = (n13 * n24 * n31 - n14 * n23 * n31 + n14 * n21 * n33 - n11 * n24 * n33 - n13 * n21 * n34 + n11 * n23 * n34) * idet; + ret[3][2] = (n14 * n22 * n31 - n12 * n24 * n31 - n14 * n21 * n32 + n11 * n24 * n32 + n12 * n21 * n34 - n11 * n22 * n34) * idet; + ret[3][3] = (n12 * n23 * n31 - n13 * n22 * n31 + n13 * n21 * n32 - n11 * n23 * n32 - n12 * n21 * n33 + n11 * n22 * n33) * idet; + + return ret; +} + // ---------------------------------------------------------------------------- // Texture utilities // ---------------------------------------------------------------------------- diff --git a/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/PickingSpaceTransforms.hlsl b/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/PickingSpaceTransforms.hlsl index 981b2c41bbd..0b3be72d754 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/PickingSpaceTransforms.hlsl +++ b/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/PickingSpaceTransforms.hlsl @@ -19,7 +19,7 @@ float4x4 glstate_matrix_projection; #define UNITY_MATRIX_M unity_ObjectToWorld #undef UNITY_MATRIX_I_M -#define UNITY_MATRIX_I_M inverse(unity_ObjectToWorld) +#define UNITY_MATRIX_I_M Inverse(unity_ObjectToWorld) #undef UNITY_MATRIX_V #define UNITY_MATRIX_V unity_MatrixV @@ -59,50 +59,10 @@ float4x4 glstate_matrix_projection; #define TransformObjectToTangent TransformObjectToTangent_Picking -float4x4 inverse(float4x4 m) { - float n11 = m[0][0], n12 = m[1][0], n13 = m[2][0], n14 = m[3][0]; - float n21 = m[0][1], n22 = m[1][1], n23 = m[2][1], n24 = m[3][1]; - float n31 = m[0][2], n32 = m[1][2], n33 = m[2][2], n34 = m[3][2]; - float n41 = m[0][3], n42 = m[1][3], n43 = m[2][3], n44 = m[3][3]; - - float t11 = n23 * n34 * n42 - n24 * n33 * n42 + n24 * n32 * n43 - n22 * n34 * n43 - n23 * n32 * n44 + n22 * n33 * n44; - float t12 = n14 * n33 * n42 - n13 * n34 * n42 - n14 * n32 * n43 + n12 * n34 * n43 + n13 * n32 * n44 - n12 * n33 * n44; - float t13 = n13 * n24 * n42 - n14 * n23 * n42 + n14 * n22 * n43 - n12 * n24 * n43 - n13 * n22 * n44 + n12 * n23 * n44; - float t14 = n14 * n23 * n32 - n13 * n24 * n32 - n14 * n22 * n33 + n12 * n24 * n33 + n13 * n22 * n34 - n12 * n23 * n34; - - float det = n11 * t11 + n21 * t12 + n31 * t13 + n41 * t14; - float idet = 1.0f / det; - - float4x4 ret; - - ret[0][0] = t11 * idet; - ret[0][1] = (n24 * n33 * n41 - n23 * n34 * n41 - n24 * n31 * n43 + n21 * n34 * n43 + n23 * n31 * n44 - n21 * n33 * n44) * idet; - ret[0][2] = (n22 * n34 * n41 - n24 * n32 * n41 + n24 * n31 * n42 - n21 * n34 * n42 - n22 * n31 * n44 + n21 * n32 * n44) * idet; - ret[0][3] = (n23 * n32 * n41 - n22 * n33 * n41 - n23 * n31 * n42 + n21 * n33 * n42 + n22 * n31 * n43 - n21 * n32 * n43) * idet; - - ret[1][0] = t12 * idet; - ret[1][1] = (n13 * n34 * n41 - n14 * n33 * n41 + n14 * n31 * n43 - n11 * n34 * n43 - n13 * n31 * n44 + n11 * n33 * n44) * idet; - ret[1][2] = (n14 * n32 * n41 - n12 * n34 * n41 - n14 * n31 * n42 + n11 * n34 * n42 + n12 * n31 * n44 - n11 * n32 * n44) * idet; - ret[1][3] = (n12 * n33 * n41 - n13 * n32 * n41 + n13 * n31 * n42 - n11 * n33 * n42 - n12 * n31 * n43 + n11 * n32 * n43) * idet; - - ret[2][0] = t13 * idet; - ret[2][1] = (n14 * n23 * n41 - n13 * n24 * n41 - n14 * n21 * n43 + n11 * n24 * n43 + n13 * n21 * n44 - n11 * n23 * n44) * idet; - ret[2][2] = (n12 * n24 * n41 - n14 * n22 * n41 + n14 * n21 * n42 - n11 * n24 * n42 - n12 * n21 * n44 + n11 * n22 * n44) * idet; - ret[2][3] = (n13 * n22 * n41 - n12 * n23 * n41 - n13 * n21 * n42 + n11 * n23 * n42 + n12 * n21 * n43 - n11 * n22 * n43) * idet; - - ret[3][0] = t14 * idet; - ret[3][1] = (n13 * n24 * n31 - n14 * n23 * n31 + n14 * n21 * n33 - n11 * n24 * n33 - n13 * n21 * n34 + n11 * n23 * n34) * idet; - ret[3][2] = (n14 * n22 * n31 - n12 * n24 * n31 - n14 * n21 * n32 + n11 * n24 * n32 + n12 * n21 * n34 - n11 * n22 * n34) * idet; - ret[3][3] = (n12 * n23 * n31 - n13 * n22 * n31 + n13 * n21 * n32 - n11 * n23 * n32 - n12 * n21 * n33 + n11 * n22 * n33) * idet; - - return ret; -} - // Redefine the functions using the new macros #undef UNITY_SPACE_TRANSFORMS_INCLUDED #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/SpaceTransforms.hlsl" - #endif #endif From 450a9f0b1efc5187a783d46bf869c8f2b4ed7d95 Mon Sep 17 00:00:00 2001 From: Adrien de Tocqueville Date: Mon, 26 Oct 2020 15:15:42 +0100 Subject: [PATCH 11/12] Reorder decal passes --- .../Decal/ShaderGraph/DecalSubTarget.cs | 2 +- .../Runtime/Material/Decal/Decal.shader | 78 +++++++++---------- .../Runtime/Material/Decal/DecalSystem.cs | 9 +-- 3 files changed, 44 insertions(+), 45 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 b79374a465b..92fa4e2f24a 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 @@ -203,11 +203,11 @@ static class SubShaders generatesPreview = true, passes = new PassCollection { - { DecalPasses.ScenePicking, new FieldCondition(DecalDefault, true) }, { DecalPasses.DBufferProjector, new FieldCondition(DecalDefault, true) }, { DecalPasses.DecalProjectorForwardEmissive, new FieldCondition(AffectsEmission, true) }, { DecalPasses.DBufferMesh, new FieldCondition(DecalDefault, true) }, { DecalPasses.DecalMeshForwardEmissive, new FieldCondition(AffectsEmission, true) }, + { DecalPasses.ScenePicking, new FieldCondition(DecalDefault, true) }, { DecalPasses.Preview, new FieldCondition(Fields.IsPreview, true) }, }, }; 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 8d75f6b0010..1bf513b3060 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 @@ -101,43 +101,9 @@ Shader "HDRP/Decal" // 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 + // Caution: passes stripped in builds (like the scene picking pass) need to be put last to have consistent indices - // The outline selection in the editor use the vertex shader/hull/domain shader of the first pass declared. - Pass // 0 - { - Name "ScenePickingPass" - Tags { "LightMode" = "Picking" } - - Cull Back - - 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 _SelectionID variable - - // 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 SCENEPICKINGPASS - #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/ShaderLibrary/PickingSpaceTransforms.hlsl" - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPassDecal.hlsl" - - #pragma editor_sync_compilation - - ENDHLSL - } - - Pass // 1 + Pass // 0 { Name "DBufferProjector" Tags{"LightMode" = "DBufferProjector"} // Metalness @@ -180,7 +146,7 @@ Shader "HDRP/Decal" ENDHLSL } - Pass // 2 + Pass // 1 { Name "DecalProjectorForwardEmissive" Tags{ "LightMode" = "DecalProjectorForwardEmissive" } @@ -214,7 +180,7 @@ Shader "HDRP/Decal" ENDHLSL } - Pass // 3 + Pass // 2 { Name "DBufferMesh" Tags{"LightMode" = "DBufferMesh"} @@ -258,7 +224,7 @@ Shader "HDRP/Decal" ENDHLSL } - Pass // 4 + Pass // 3 { Name "DecalMeshForwardEmissive" Tags{ "LightMode" = "DecalMeshForwardEmissive" } @@ -293,6 +259,40 @@ Shader "HDRP/Decal" ENDHLSL } + Pass // 4 + { + Name "ScenePickingPass" + Tags { "LightMode" = "Picking" } + + Cull Back + + 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 _SelectionID variable + + // 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 SCENEPICKINGPASS + #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/ShaderLibrary/PickingSpaceTransforms.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPassDecal.hlsl" + + #pragma editor_sync_compilation + + ENDHLSL + } + } CustomEditor "Rendering.HighDefinition.DecalUI" } 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 c80b73019fa..7d5ee018e25 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,11 +37,10 @@ class DecalSystem // Caution: Enum num must match pass name for s_MaterialDecalPassNames array public enum MaterialDecalPass { - ScenePickingPass = 0, - DBufferProjector = 1, - DecalProjectorForwardEmissive = 2, - DBufferMesh = 3, - DecalMeshForwardEmissive = 4, + DBufferProjector = 0, + DecalProjectorForwardEmissive = 1, + DBufferMesh = 2, + DecalMeshForwardEmissive = 3, }; public static readonly string[] s_MaterialDecalPassNames = Enum.GetNames(typeof(MaterialDecalPass)); From 0138b6f84b88b452c9dcbc1cd8deb756f1b7561b Mon Sep 17 00:00:00 2001 From: Adrien de Tocqueville Date: Mon, 26 Oct 2020 15:26:52 +0100 Subject: [PATCH 12/12] Minor changes --- com.unity.render-pipelines.high-definition/CHANGELOG.md | 1 - .../Editor/Material/ShaderGraph/HDShaderPasses.cs | 9 +-------- .../Editor/Material/ShaderGraph/HDTarget.cs | 1 - .../Editor/Material/ShaderGraph/SurfaceSubTarget.cs | 2 +- 4 files changed, 2 insertions(+), 11 deletions(-) diff --git a/com.unity.render-pipelines.high-definition/CHANGELOG.md b/com.unity.render-pipelines.high-definition/CHANGELOG.md index 8304ea25eb3..c494a9d577a 100644 --- a/com.unity.render-pipelines.high-definition/CHANGELOG.md +++ b/com.unity.render-pipelines.high-definition/CHANGELOG.md @@ -204,7 +204,6 @@ The version number for this package has increased due to a version update of a r - Fixed cullmode for SceneSelectionPass. - Fixed issue that caused non-static object to not render at times in OnEnable reflection probes. - Baked reflection probes now correctly use static sky for ambient lighting. -- Use draggable fields for float scalable settings ### Changed - Preparation pass for RTSSShadows to be supported by render graph. diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/HDShaderPasses.cs b/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/HDShaderPasses.cs index ee2181cffcc..1da3d5ca700 100644 --- a/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/HDShaderPasses.cs +++ b/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/HDShaderPasses.cs @@ -76,7 +76,7 @@ IncludeCollection GenerateIncludes() #region Scene Picking Pass - public static PassDescriptor GenerateScenePicking(bool supportLighting) + public static PassDescriptor GenerateScenePicking() { return new PassDescriptor { @@ -98,15 +98,8 @@ IncludeCollection GenerateIncludes() var includes = new IncludeCollection(); includes.Add(CoreIncludes.CorePregraph); - if (supportLighting) - includes.Add(CoreIncludes.kNormalSurfaceGradient, IncludeLocation.Pregraph); includes.Add(CoreIncludes.kPassPlaceholder, IncludeLocation.Pregraph); includes.Add(CoreIncludes.CoreUtility); - if (supportLighting) - { - includes.Add(CoreIncludes.kDecalUtilities, IncludeLocation.Pregraph); - includes.Add(CoreIncludes.kPostDecalsPlaceholder, IncludeLocation.Pregraph); - } includes.Add(CoreIncludes.kShaderGraphFunctions, IncludeLocation.Pregraph); includes.Add(CoreIncludes.kPickingSpaceTransforms, IncludeLocation.Pregraph); includes.Add(CoreIncludes.kPassDepthOnly, IncludeLocation.Postgraph); diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/HDTarget.cs b/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/HDTarget.cs index a301a595ce4..860cec72e36 100644 --- a/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/HDTarget.cs +++ b/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/HDTarget.cs @@ -807,7 +807,6 @@ static class CoreDefines { public static DefineCollection ScenePicking = new DefineCollection { - { RayTracingQualityNode.GetRayTracingQualityKeyword(), 0 }, { CoreKeywordDescriptors.ScenePickingPass, 1 }, }; diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/SurfaceSubTarget.cs b/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/SurfaceSubTarget.cs index 57bef1335a2..4d5d56b0604 100644 --- a/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/SurfaceSubTarget.cs +++ b/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/SurfaceSubTarget.cs @@ -79,7 +79,7 @@ PassCollection GetPasses() // Common "surface" passes HDShaderPasses.GenerateShadowCaster(supportLighting), HDShaderPasses.GenerateMETA(supportLighting), - HDShaderPasses.GenerateScenePicking(supportLighting), + HDShaderPasses.GenerateScenePicking(), HDShaderPasses.GenerateSceneSelection(supportLighting), HDShaderPasses.GenerateMotionVectors(supportLighting, supportForward), { HDShaderPasses.GenerateBackThenFront(supportLighting), new FieldCondition(HDFields.TransparentBackFace, true)},