From f5d9db198a34b22ac0a76ba57546692f62496230 Mon Sep 17 00:00:00 2001 From: hedvig Date: Mon, 18 Jan 2021 17:23:46 +0100 Subject: [PATCH 01/34] Compute Skinning is applied in VertMesh through defines - Add separate shader for skinning - Set DOTS_SKINNING define for all passes when hybrid v2 is enabled - Add new builtin property that determines if skinning should be applied --- .../Material/ShaderGraph/HDShaderPasses.cs | 371 ++++++++++++++++-- .../Editor/Material/ShaderGraph/HDTarget.cs | 10 + .../MotionVectorVertexShaderCommon.hlsl | 8 +- .../RenderPipeline/ShaderPass/Skinning.hlsl | 43 ++ .../ShaderPass/Skinning.hlsl.meta | 9 + .../RenderPipeline/ShaderPass/VertMesh.hlsl | 4 + .../ShaderLibrary/ShaderVariables.hlsl | 9 +- 7 files changed, 425 insertions(+), 29 deletions(-) create mode 100644 com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/Skinning.hlsl create mode 100644 com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/Skinning.hlsl.meta 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 ebd40b23756..0b58fb954aa 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 @@ -1,3 +1,7 @@ +#if ENABLE_HYBRID_RENDERER_V2 //TODO: find way to not add to all passes manually? + #define AddSkinDefineAndInclude +#endif + using System; using System.Collections.Generic; using System.Linq; @@ -6,11 +10,12 @@ using UnityEditor.ShaderGraph; using UnityEditor.ShaderGraph.Internal; + namespace UnityEditor.Rendering.HighDefinition.ShaderGraph { static class HDShaderPasses { -#region Distortion Pass + #region Distortion Pass public static PassDescriptor GenerateDistortionPass(bool supportLighting) { @@ -72,9 +77,9 @@ IncludeCollection GenerateIncludes() } -#endregion + #endregion -#region Scene Picking Pass + #region Scene Picking Pass public static PassDescriptor GenerateScenePicking() { @@ -89,10 +94,35 @@ public static PassDescriptor GenerateScenePicking() // Collections renderStates = CoreRenderStates.ScenePicking, pragmas = CorePragmas.DotsInstancedInV1AndV2EditorSync, - defines = CoreDefines.ScenePicking, + defines = GenerateDefines(), includes = GenerateIncludes(), +#if AddSkinDefineAndInclude + requiredFields = GenerateRequiredFields(), +#endif }; +#if AddSkinDefineAndInclude + FieldCollection GenerateRequiredFields() + { + return new FieldCollection + { + HDStructFields.AttributesMesh.vertexID + }; + } +#endif + + DefineCollection GenerateDefines() + { + return new DefineCollection + { + CoreDefines.ScenePicking, +#if AddSkinDefineAndInclude + { CoreKeywordDescriptors.SkinningDefine, 1 }, + //{ CoreKeywordDescriptors.ComputeSkinningDefine, 1 }, +#endif + }; + } + IncludeCollection GenerateIncludes() { var includes = new IncludeCollection(); @@ -102,6 +132,9 @@ IncludeCollection GenerateIncludes() includes.Add(CoreIncludes.CoreUtility); includes.Add(CoreIncludes.kShaderGraphFunctions, IncludeLocation.Pregraph); includes.Add(CoreIncludes.kPickingSpaceTransforms, IncludeLocation.Pregraph); +#if AddSkinDefineAndInclude + includes.Add(CoreIncludes.kSkinning, IncludeLocation.Pregraph); +#endif includes.Add(CoreIncludes.kPassDepthOnly, IncludeLocation.Postgraph); return includes; @@ -125,10 +158,35 @@ public static PassDescriptor GenerateSceneSelection(bool supportLighting) // Collections renderStates = CoreRenderStates.SceneSelection, pragmas = CorePragmas.DotsInstancedInV1AndV2EditorSync, - defines = CoreDefines.SceneSelection, + defines = GenerateDefines(), includes = GenerateIncludes(), +#if AddSkinDefineAndInclude + requiredFields = GenerateRequiredFields(), +#endif }; +#if AddSkinDefineAndInclude + FieldCollection GenerateRequiredFields() + { + return new FieldCollection + { + HDStructFields.AttributesMesh.vertexID + }; + } +#endif + + DefineCollection GenerateDefines() + { + return new DefineCollection + { + CoreDefines.SceneSelection, +#if AddSkinDefineAndInclude + { CoreKeywordDescriptors.SkinningDefine, 1 }, + //{ CoreKeywordDescriptors.ComputeSkinningDefine, 1 }, +#endif + }; + } + IncludeCollection GenerateIncludes() { var includes = new IncludeCollection(); @@ -144,6 +202,9 @@ IncludeCollection GenerateIncludes() includes.Add(CoreIncludes.kPostDecalsPlaceholder, IncludeLocation.Pregraph); } includes.Add(CoreIncludes.kShaderGraphFunctions, IncludeLocation.Pregraph); +#if AddSkinDefineAndInclude + includes.Add(CoreIncludes.kSkinning, IncludeLocation.Pregraph); +#endif includes.Add(CoreIncludes.kPassDepthOnly, IncludeLocation.Postgraph); return includes; @@ -164,7 +225,7 @@ static public PassDescriptor GenerateShadowCaster(bool supportLighting) lightMode = "ShadowCaster", useInPreview = false, - validPixelBlocks = new BlockFieldDescriptor[] + validPixelBlocks = new BlockFieldDescriptor[] { BlockFields.SurfaceDescription.Alpha, BlockFields.SurfaceDescription.AlphaClipThreshold, @@ -177,8 +238,31 @@ static public PassDescriptor GenerateShadowCaster(bool supportLighting) renderStates = CoreRenderStates.ShadowCaster, pragmas = CorePragmas.DotsInstancedInV2Only, includes = GenerateIncludes(), +#if AddSkinDefineAndInclude + requiredFields = GenerateFields(), + defines = GenerateDefines() +#endif }; +#if AddSkinDefineAndInclude + FieldCollection GenerateFields() + { + return new FieldCollection + { + HDStructFields.AttributesMesh.vertexID + }; + } + + DefineCollection GenerateDefines() + { + return new DefineCollection + { + { CoreKeywordDescriptors.SkinningDefine, 1 }, + //{ CoreKeywordDescriptors.ComputeSkinningDefine, 1 }, + }; + } +#endif + IncludeCollection GenerateIncludes() { var includes = new IncludeCollection(); @@ -194,6 +278,9 @@ IncludeCollection GenerateIncludes() includes.Add(CoreIncludes.kPostDecalsPlaceholder, IncludeLocation.Pregraph); } includes.Add(CoreIncludes.kShaderGraphFunctions, IncludeLocation.Pregraph); +#if AddSkinDefineAndInclude + includes.Add(CoreIncludes.kSkinning, IncludeLocation.Pregraph); +#endif includes.Add(CoreIncludes.kPassDepthOnly, IncludeLocation.Postgraph); return includes; @@ -218,13 +305,38 @@ public static PassDescriptor GenerateMETA(bool supportLighting) validVertexBlocks = new BlockFieldDescriptor[0], // Collections - requiredFields = CoreRequiredFields.Meta, renderStates = CoreRenderStates.Meta, pragmas = CorePragmas.DotsInstancedInV1AndV2, - defines = CoreDefines.ShaderGraphRaytracingDefault, + defines = GenerateDefines(), includes = GenerateIncludes(), +#if AddSkinDefineAndInclude + requiredFields = GenerateRequiredFields(), +#endif }; + FieldCollection GenerateRequiredFields() + { + return new FieldCollection + { + CoreRequiredFields.Meta, +#if AddSkinDefineAndInclude + HDStructFields.AttributesMesh.vertexID +#endif + }; + } + + DefineCollection GenerateDefines() + { + return new DefineCollection + { + CoreDefines.ShaderGraphRaytracingDefault, +#if AddSkinDefineAndInclude + { CoreKeywordDescriptors.SkinningDefine, 1 }, + //{ CoreKeywordDescriptors.ComputeSkinningDefine, 1 }, +#endif + }; + } + IncludeCollection GenerateIncludes() { var includes = new IncludeCollection(); @@ -240,6 +352,9 @@ IncludeCollection GenerateIncludes() includes.Add(CoreIncludes.kPostDecalsPlaceholder, IncludeLocation.Pregraph); } includes.Add(CoreIncludes.kShaderGraphFunctions, IncludeLocation.Pregraph); +#if AddSkinDefineAndInclude + includes.Add(CoreIncludes.kSkinning, IncludeLocation.Pregraph); +#endif includes.Add(CoreIncludes.kPassLightTransport, IncludeLocation.Postgraph); return includes; @@ -264,13 +379,26 @@ public static PassDescriptor GenerateDepthForwardOnlyPass(bool supportLighting) requiredFields = GenerateRequiredFields(), renderStates = GenerateRenderState(), pragmas = CorePragmas.DotsInstancedInV2Only, - defines = supportLighting ? CoreDefines.DepthForwardOnly : CoreDefines.DepthForwardOnlyUnlit, + defines = GenerateDefines(), includes = GenerateIncludes(), }; + DefineCollection GenerateDefines() + { + return new DefineCollection + { + supportLighting ? CoreDefines.DepthForwardOnly : CoreDefines.DepthForwardOnlyUnlit, +#if AddSkinDefineAndInclude + { CoreKeywordDescriptors.SkinningDefine, 1 }, + //{ CoreKeywordDescriptors.ComputeSkinningDefine, 1 }, +#endif + }; + + } + RenderStateCollection GenerateRenderState() { - var renderState = new RenderStateCollection{ CoreRenderStates.DepthOnly }; + var renderState = new RenderStateCollection { CoreRenderStates.DepthOnly }; if (!supportLighting) { @@ -297,6 +425,9 @@ FieldCollection GenerateRequiredFields() HDStructFields.AttributesMesh.color, HDStructFields.AttributesMesh.uv2, HDStructFields.AttributesMesh.uv3, +#if AddSkinDefineAndInclude + HDStructFields.AttributesMesh.vertexID, +#endif HDStructFields.FragInputs.tangentToWorld, HDStructFields.FragInputs.positionRWS, HDStructFields.FragInputs.texCoord1, @@ -318,6 +449,9 @@ IncludeCollection GenerateIncludes() if (supportLighting) includes.Add(CoreIncludes.kDecalUtilities, IncludeLocation.Pregraph); includes.Add(CoreIncludes.kShaderGraphFunctions, IncludeLocation.Pregraph); +#if AddSkinDefineAndInclude + includes.Add(CoreIncludes.kSkinning, IncludeLocation.Pregraph); +#endif includes.Add(CoreIncludes.kPassDepthOnly, IncludeLocation.Postgraph); return includes; @@ -339,13 +473,24 @@ public static PassDescriptor GenerateMotionVectors(bool supportLighting, bool su useInPreview = false, // Collections - requiredFields = CoreRequiredFields.LitFull, renderStates = GenerateRenderState(), defines = GenerateDefines(), pragmas = CorePragmas.DotsInstancedInV2Only, includes = GenerateIncludes(), + requiredFields = GenerateRequiredFields(), }; + FieldCollection GenerateRequiredFields() + { + return new FieldCollection + { + CoreRequiredFields.LitFull, +#if AddSkinDefineAndInclude + HDStructFields.AttributesMesh.vertexID +#endif + }; + } + DefineCollection GenerateDefines() { if (!supportLighting) @@ -357,8 +502,11 @@ DefineCollection GenerateDefines() // if (supportForward) // { // defines.Add(CoreKeywordDescriptors.WriteNormalBuffer, 1); - // } - + // } +#if AddSkinDefineAndInclude + defines.Add(CoreKeywordDescriptors.SkinningDefine, 1); + //defines.Add(CoreKeywordDescriptors.ComputeSkinningDefine, 1); +#endif return defines; } @@ -366,7 +514,7 @@ RenderStateCollection GenerateRenderState() { var renderState = new RenderStateCollection(); renderState.Add(CoreRenderStates.MotionVectors); - + if (!supportLighting) { // Caution: When using MSAA we have motion vector, normal and depth buffer bind. @@ -386,6 +534,7 @@ IncludeCollection GenerateIncludes() var includes = new IncludeCollection(); includes.Add(CoreIncludes.CorePregraph); + if (supportLighting) includes.Add(CoreIncludes.kNormalSurfaceGradient, IncludeLocation.Pregraph); includes.Add(CoreIncludes.kPassPlaceholder, IncludeLocation.Pregraph); @@ -396,6 +545,9 @@ IncludeCollection GenerateIncludes() includes.Add(CoreIncludes.kPostDecalsPlaceholder, IncludeLocation.Pregraph); } includes.Add(CoreIncludes.kShaderGraphFunctions, IncludeLocation.Pregraph); +#if AddSkinDefineAndInclude + includes.Add(CoreIncludes.kSkinning, IncludeLocation.Pregraph); +#endif includes.Add(CoreIncludes.kPassMotionVectors, IncludeLocation.Postgraph); return includes; @@ -410,7 +562,7 @@ IncludeCollection GenerateIncludes() public static PassDescriptor GenerateForwardOnlyPass(bool supportLighting) { return new PassDescriptor - { + { // Definition displayName = "ForwardOnly", referenceName = supportLighting ? "SHADERPASS_FORWARD" : "SHADERPASS_FORWARD_UNLIT", @@ -466,7 +618,8 @@ IncludeCollection GenerateIncludes() includes.Add(CoreIncludes.kPassForward, IncludeLocation.Postgraph); else includes.Add(CoreIncludes.kPassForwardUnlit, IncludeLocation.Postgraph); - + + return includes; } } @@ -478,7 +631,7 @@ IncludeCollection GenerateIncludes() public static PassDescriptor GenerateBackThenFront(bool supportLighting) { return new PassDescriptor - { + { // Definition displayName = "TransparentBackface", referenceName = supportLighting ? "SHADERPASS_FORWARD" : "SHADERPASS_FORWARD_UNLIT", @@ -560,13 +713,36 @@ public static PassDescriptor GenerateTransparentDepthPrepass(bool supportLightin }, // Collections - requiredFields = TransparentDepthPrepassFields, renderStates = GenerateRenderState(), pragmas = CorePragmas.DotsInstancedInV1AndV2, - defines = CoreDefines.TransparentDepthPrepass, + defines = GenerateDefines(), includes = GenerateIncludes(), + requiredFields = GenerateRequiredFields(), }; + FieldCollection GenerateRequiredFields() + { + return new FieldCollection + { + TransparentDepthPrepassFields, +#if AddSkinDefineAndInclude + HDStructFields.AttributesMesh.vertexID +#endif + }; + } + + DefineCollection GenerateDefines() + { + return new DefineCollection + { + CoreDefines.TransparentDepthPrepass, + #if AddSkinDefineAndInclude + { CoreKeywordDescriptors.SkinningDefine, 1 }, + //{ CoreKeywordDescriptors.ComputeSkinningDefine, 1 }, + #endif + }; + } + RenderStateCollection GenerateRenderState() { var renderState = new RenderStateCollection @@ -612,6 +788,9 @@ IncludeCollection GenerateIncludes() includes.Add(CoreIncludes.kPostDecalsPlaceholder, IncludeLocation.Pregraph); } includes.Add(CoreIncludes.kShaderGraphFunctions, IncludeLocation.Pregraph); +#if AddSkinDefineAndInclude + includes.Add(CoreIncludes.kSkinning, IncludeLocation.Pregraph); +#endif includes.Add(CoreIncludes.kPassDepthOnly, IncludeLocation.Postgraph); return includes; @@ -712,15 +891,33 @@ public static PassDescriptor GenerateLitDepthOnly() useInPreview = true, // Collections - requiredFields = CoreRequiredFields.LitFull, + requiredFields = DepthOnlyFields, renderStates = CoreRenderStates.DepthOnly, pragmas = CorePragmas.DotsInstancedInV1AndV2, - defines = CoreDefines.ShaderGraphRaytracingDefault, + defines = DepthOnlyDefines, keywords = LitDepthOnlyKeywords, includes = DepthOnlyIncludes, }; } + public static FieldCollection DepthOnlyFields = new FieldCollection + { + CoreRequiredFields.LitFull, +#if AddSkinDefineAndInclude + HDStructFields.AttributesMesh.vertexID +#endif + }; + + + public static DefineCollection DepthOnlyDefines = new DefineCollection + { + CoreDefines.ShaderGraphRaytracingDefault, +#if AddSkinDefineAndInclude + { CoreKeywordDescriptors.SkinningDefine, 1 }, + //{ CoreKeywordDescriptors.ComputeSkinningDefine, 1 }, +#endif + }; + public static IncludeCollection DepthOnlyIncludes = new IncludeCollection { { CoreIncludes.CorePregraph }, @@ -730,6 +927,9 @@ public static PassDescriptor GenerateLitDepthOnly() { CoreIncludes.kDecalUtilities, IncludeLocation.Pregraph }, { CoreIncludes.kPostDecalsPlaceholder, IncludeLocation.Pregraph }, { CoreIncludes.kShaderGraphFunctions, IncludeLocation.Pregraph }, +#if AddSkinDefineAndInclude + { CoreIncludes.kSkinning, IncludeLocation.Pregraph }, +#endif { CoreIncludes.kPassDepthOnly, IncludeLocation.Postgraph }, }; @@ -753,10 +953,10 @@ public static PassDescriptor GenerateGBuffer() useInPreview = true, // Collections - requiredFields = CoreRequiredFields.LitMinimal, + requiredFields = GBufferFields, renderStates = GBufferRenderState, pragmas = CorePragmas.DotsInstancedInV1AndV2, - defines = CoreDefines.ShaderGraphRaytracingDefault, + defines = GBufferDefines, keywords = GBufferKeywords, includes = GBufferIncludes, @@ -764,6 +964,24 @@ public static PassDescriptor GenerateGBuffer() }; } + public static FieldCollection GBufferFields = new FieldCollection + { + CoreRequiredFields.LitMinimal, + #if AddSkinDefineAndInclude + HDStructFields.AttributesMesh.vertexID + #endif + }; + + public static DefineCollection GBufferDefines = new DefineCollection + { + CoreDefines.ShaderGraphRaytracingDefault, +#if AddSkinDefineAndInclude + { CoreKeywordDescriptors.SkinningDefine, 1 }, + // { CoreKeywordDescriptors.ComputeSkinningDefine, 1 }, +#endif + }; + + public static KeywordCollection GBufferKeywords = new KeywordCollection { { CoreKeywordDescriptors.LightLayers }, @@ -778,6 +996,9 @@ public static PassDescriptor GenerateGBuffer() { CoreIncludes.kDecalUtilities, IncludeLocation.Pregraph }, { CoreIncludes.kPostDecalsPlaceholder, IncludeLocation.Pregraph }, { CoreIncludes.kShaderGraphFunctions, IncludeLocation.Pregraph }, + #if AddSkinDefineAndInclude + { CoreIncludes.kSkinning, IncludeLocation.Pregraph }, + #endif { CoreIncludes.kPassGBuffer, IncludeLocation.Postgraph }, }; @@ -809,7 +1030,7 @@ public static PassDescriptor GenerateLitForward() useInPreview = true, // Collections - requiredFields = CoreRequiredFields.LitMinimal, + requiredFields = ForwardFields, renderStates = CoreRenderStates.Forward, pragmas = CorePragmas.DotsInstancedInV1AndV2, defines = CoreDefines.Forward, @@ -819,6 +1040,23 @@ public static PassDescriptor GenerateLitForward() }; } + public static FieldCollection ForwardFields = new FieldCollection + { + CoreRequiredFields.LitMinimal, +#if AddSkinDefineAndInclude + HDStructFields.AttributesMesh.vertexID +#endif + }; + + public static DefineCollection ForwardDefines = new DefineCollection + { + CoreDefines.Forward, +#if AddSkinDefineAndInclude + { CoreKeywordDescriptors.SkinningDefine, 1 }, + //{ CoreKeywordDescriptors.ComputeSkinningDefine, 1 }, +#endif + }; + public static IncludeCollection ForwardIncludes = new IncludeCollection { { CoreIncludes.CorePregraph }, @@ -831,6 +1069,9 @@ public static PassDescriptor GenerateLitForward() { CoreIncludes.kDecalUtilities, IncludeLocation.Pregraph }, { CoreIncludes.kPostDecalsPlaceholder, IncludeLocation.Pregraph }, { CoreIncludes.kShaderGraphFunctions, IncludeLocation.Pregraph }, + #if AddSkinDefineAndInclude + { CoreIncludes.kSkinning, IncludeLocation.Pregraph }, + #endif { CoreIncludes.kPassForward, IncludeLocation.Postgraph }, }; @@ -851,11 +1092,30 @@ public static PassDescriptor GenerateLitRaytracingPrepass() // Collections renderStates = RayTracingPrepassRenderState, pragmas = CorePragmas.Basic, - defines = CoreDefines.ShaderGraphRaytracingDefault, + defines = LitRayTracingPrepassDefines, includes = RayTracingPrepassIncludes, +#if AddSkinDefineAndInclude + requiredFields = LitRayTracingFields, +#endif }; } +#if AddSkinDefineAndInclude + public static FieldCollection LitRayTracingFields = new FieldCollection + { + HDStructFields.AttributesMesh.vertexID + }; +#endif + + public static DefineCollection LitRayTracingPrepassDefines = new DefineCollection + { + CoreDefines.ShaderGraphRaytracingDefault, +#if AddSkinDefineAndInclude + { CoreKeywordDescriptors.SkinningDefine, 1 }, + //{ CoreKeywordDescriptors.ComputeSkinningDefine, 1 }, +#endif + }; + public static IncludeCollection RayTracingPrepassIncludes = new IncludeCollection { { CoreIncludes.CorePregraph }, @@ -865,6 +1125,9 @@ public static PassDescriptor GenerateLitRaytracingPrepass() { CoreIncludes.kDecalUtilities, IncludeLocation.Pregraph }, { CoreIncludes.kPostDecalsPlaceholder, IncludeLocation.Pregraph }, { CoreIncludes.kShaderGraphFunctions, IncludeLocation.Pregraph }, + #if AddSkinDefineAndInclude + { CoreIncludes.kSkinning, IncludeLocation.Pregraph }, + #endif { CoreIncludes.kPassConstant, IncludeLocation.Postgraph }, }; @@ -897,11 +1160,36 @@ public static PassDescriptor GenerateRaytracingIndirect(bool supportLighting) // Collections pragmas = CorePragmas.RaytracingBasic, - defines = supportLighting ? RaytracingIndirectDefines : null, keywords = supportLighting ? IndirectDiffuseKeywordCollection : null, + defines = GenerateDefines(), includes = GenerateIncludes(), +#if AddSkinDefineAndInclude + requiredFields = GenerateRequiredFields(), +#endif }; +#if AddSkinDefineAndInclude + FieldCollection GenerateRequiredFields() + { + return new FieldCollection + { + HDStructFields.AttributesMesh.vertexID + }; + } +#endif + + DefineCollection GenerateDefines() + { + return new DefineCollection + { + supportLighting ? RaytracingIndirectDefines : null, +#if AddSkinDefineAndInclude + { CoreKeywordDescriptors.SkinningDefine, 1 }, + //{ CoreKeywordDescriptors.ComputeSkinningDefine, 1 }, +#endif + }; + } + IncludeCollection GenerateIncludes() { var includes = new IncludeCollection { CoreIncludes.RaytracingCorePregraph }; @@ -925,6 +1213,9 @@ IncludeCollection GenerateIncludes() includes.Add(CoreIncludes.CoreUtility); includes.Add(CoreIncludes.kRaytracingCommon, IncludeLocation.Pregraph); includes.Add(CoreIncludes.kShaderGraphFunctions, IncludeLocation.Pregraph); +#if AddSkinDefineAndInclude + includes.Add(CoreIncludes.kSkinning, IncludeLocation.Pregraph); +#endif // post graph includes includes.Add(CoreIncludes.kPassRaytracingIndirect, IncludeLocation.Postgraph); @@ -1256,8 +1547,33 @@ public static PassDescriptor GenerateFullScreenDebug() pragmas = CorePragmas.Basic, renderStates = FullScreenDebugRenderState, includes = GenerateIncludes(), +#if AddSkinDefineAndInclude + defines = GenerateDefines(), + requiredFields = GenerateRequiredFields(), +#endif }; +#if AddSkinDefineAndInclude + FieldCollection GenerateRequiredFields() + { + return new FieldCollection + { + HDStructFields.AttributesMesh.vertexID + }; + } +#endif + +#if AddSkinDefineAndInclude + DefineCollection GenerateDefines() + { + return new DefineCollection + { + { CoreKeywordDescriptors.SkinningDefine, 1 }, + // { CoreKeywordDescriptors.ComputeSkinningDefine, 1 }, + }; + } +#endif + IncludeCollection GenerateIncludes() { return new IncludeCollection @@ -1267,6 +1583,9 @@ IncludeCollection GenerateIncludes() { CoreIncludes.kPassPlaceholder, IncludeLocation.Pregraph }, { CoreIncludes.CoreUtility }, { CoreIncludes.kShaderGraphFunctions, IncludeLocation.Pregraph }, + #if AddSkinDefineAndInclude + { CoreIncludes.kSkinning, IncludeLocation.Pregraph }, + #endif { CoreIncludes.kPassFullScreenDebug, 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 ceeb6623c4a..ea9d6cf9f2a 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 @@ -940,6 +940,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 kSkinning = "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/Skinning.hlsl"; public static IncludeCollection MinimalCorePregraph = new IncludeCollection { @@ -1334,6 +1335,15 @@ static class CoreKeywordDescriptors definition = KeywordDefinition.MultiCompile, scope = KeywordScope.Global, }; + + public static KeywordDescriptor SkinningDefine = new KeywordDescriptor() + { + displayName = "Dots Skinning", + referenceName = "DOTS_SKINNING", + type = KeywordType.Boolean, + definition = KeywordDefinition.MultiCompile, + scope = KeywordScope.Global, + }; } #endregion } diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/MotionVectorVertexShaderCommon.hlsl b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/MotionVectorVertexShaderCommon.hlsl index 3fbb684ce00..ab742a8f196 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/MotionVectorVertexShaderCommon.hlsl +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/MotionVectorVertexShaderCommon.hlsl @@ -107,7 +107,11 @@ PackedVaryingsType MotionVectorVS(inout VaryingsType varyingsType, AttributesMes { bool hasDeformation = unity_MotionVectorsParams.x > 0.0; // Skin or morph target - float3 effectivePositionOS = (hasDeformation ? inputPass.previousPositionOS : inputMesh.positionOS); +#if defined(DOTS_SKINNING) + //only if hasDeformation? + DOTS_GetPreviousDeformedPosition(inputPass.previousPositionOS, inputMesh.vertexID); +#endif + float3 effectivePositionOS = (hasDeformation ? inputPass.previousPositionOS : inputMesh.positionOS); #if defined(_ADD_PRECOMPUTED_VELOCITY) effectivePositionOS -= inputPass.precomputedVelocity; #endif @@ -115,7 +119,7 @@ PackedVaryingsType MotionVectorVS(inout VaryingsType varyingsType, AttributesMes // Need to apply any vertex animation to the previous worldspace position, if we want it to show up in the motion vector buffer #if defined(HAVE_MESH_MODIFICATION) AttributesMesh previousMesh = inputMesh; - previousMesh.positionOS = effectivePositionOS ; + previousMesh.positionOS = effectivePositionOS; previousMesh = ApplyMeshModification(previousMesh, _LastTimeParameters.xyz); float3 previousPositionRWS = TransformPreviousObjectToWorld(previousMesh.positionOS); diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/Skinning.hlsl b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/Skinning.hlsl new file mode 100644 index 00000000000..c5c9d9ceaf3 --- /dev/null +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/Skinning.hlsl @@ -0,0 +1,43 @@ +#ifndef SKINNING_INCLUDED +#define SKINNING_INCLUDED + +//TODO: defines around nrm and tan? +//LBS Node not supported (skinning in vertex shader) + +#if defined(DOTS_SKINNING) + +struct DeformedVertexData +{ + float3 Position; + float3 Normal; + float3 Tangent; +}; +uniform StructuredBuffer _DeformedMeshData; + + +void DOTS_Skinning(inout float3 position, inout float3 normal, inout float4 tangent, uint vertexID) +{ + const int doSkinning = (int)unity_SkinSetting.x; + if (doSkinning > 0) + { + const int meshIndex = (int)unity_ComputeMeshIndex.x; + const DeformedVertexData data = _DeformedMeshData[meshIndex + vertexID]; + + position = data.Position; + normal = data.Normal; + tangent = float4(data.Tangent, 0); + } +} + +void DOTS_GetPreviousDeformedPosition(inout float3 prevPos, uint vertexID) +{ + const int doSkinning = (int)unity_SkinSetting.x; + if (doSkinning > 0) + { + const int meshIndex = (int)unity_ComputeMeshIndex.x; + prevPos = float3(0, 0, 0);// _DeformedMeshData[meshIndex + vertexID].Position; //Read from other buffer + } +} +#endif + +#endif diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/Skinning.hlsl.meta b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/Skinning.hlsl.meta new file mode 100644 index 00000000000..e916b6c2752 --- /dev/null +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/Skinning.hlsl.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2 +guid: 21e613ffd8f12d84b8e1ab498b178067 +ShaderImporter: + externalObjects: {} + defaultTextures: [] + nonModifiableTextures: [] + userData: + assetBundleName: + assetBundleVariant: diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/VertMesh.hlsl b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/VertMesh.hlsl index 9f2520d3287..1636122be0e 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/VertMesh.hlsl +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/VertMesh.hlsl @@ -135,6 +135,10 @@ VaryingsMeshType VertMesh(AttributesMesh input, float3 worldSpaceOffset) UNITY_SETUP_INSTANCE_ID(input); UNITY_TRANSFER_INSTANCE_ID(input, output); +#if defined(DOTS_SKINNING) + DOTS_Skinning(input.positionOS, input.normalOS, input.tangentOS, input.vertexID); +#endif + #if defined(HAVE_MESH_MODIFICATION) input = ApplyMeshModification(input, _TimeParameters.xyz); #endif diff --git a/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl b/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl index 6f35c90e717..4dbccb629ff 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl +++ b/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl @@ -97,6 +97,9 @@ CBUFFER_START(UnityPerDraw) //W : Camera only float4 unity_MotionVectorsParams; + float4 unity_ComputeMeshIndex; + float4 unity_SkinSetting; + CBUFFER_END CBUFFER_START(UnityPerDrawRare) @@ -372,6 +375,9 @@ UNITY_DOTS_INSTANCING_START(BuiltinPropertyMetadata) UNITY_DOTS_INSTANCED_PROP(float4, unity_ProbesOcclusion) UNITY_DOTS_INSTANCED_PROP(float3x4, unity_MatrixPreviousM) UNITY_DOTS_INSTANCED_PROP(float3x4, unity_MatrixPreviousMI) + UNITY_DOTS_INSTANCED_PROP(float4, unity_ComputeMeshIndex); + UNITY_DOTS_INSTANCED_PROP(float4, unity_SkinSetting); + UNITY_DOTS_INSTANCING_END(BuiltinPropertyMetadata) // Note: Macros for unity_ObjectToWorld and unity_WorldToObject are declared elsewhere @@ -391,7 +397,8 @@ UNITY_DOTS_INSTANCING_END(BuiltinPropertyMetadata) #define unity_ProbesOcclusion UNITY_ACCESS_DOTS_INSTANCED_PROP_FROM_MACRO(float4, Metadata_unity_ProbesOcclusion) #define unity_MatrixPreviousM LoadDOTSInstancedData_float4x4_from_float3x4(UNITY_DOTS_INSTANCED_METADATA_NAME_FROM_MACRO(float3x4, Metadata_unity_MatrixPreviousM)) #define unity_MatrixPreviousMI LoadDOTSInstancedData_float4x4_from_float3x4(UNITY_DOTS_INSTANCED_METADATA_NAME_FROM_MACRO(float3x4, Metadata_unity_MatrixPreviousMI)) - +#define unity_ComputeMeshIndex UNITY_ACCESS_DOTS_INSTANCED_PROP_FROM_MACRO(float4, Metadata_unity_ComputeMeshIndex) +#define unity_SkinSetting UNITY_ACCESS_DOTS_INSTANCED_PROP_FROM_MACRO(float4, Metadata_unity_SkinSetting) #endif // Define View/Projection matrix macro From 58cbdddefa9b4f50179c4aaf372aae6c0550f6f2 Mon Sep 17 00:00:00 2001 From: Sven Santema Date: Tue, 19 Jan 2021 11:31:37 +0100 Subject: [PATCH 02/34] Add front buffer index to access deformed vertices of current/previous frame. --- .../RenderPipeline/HDRenderPipeline.cs | 2 ++ .../RenderPipeline/ShaderPass/Skinning.hlsl | 26 ++++++++++++------- .../ShaderLibrary/ShaderVariablesGlobal.cs | 2 +- .../ShaderVariablesGlobal.cs.hlsl | 2 +- 4 files changed, 21 insertions(+), 11 deletions(-) diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.cs b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.cs index 54e920f3ff8..7f4cca346b9 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.cs @@ -1345,6 +1345,8 @@ void UpdateShaderVariablesGlobalCB(HDCamera hdCamera, CommandBuffer cmd) m_ShaderVariablesGlobalCB._SpecularOcclusionBlend = 1.0f; } + m_ShaderVariablesGlobalCB._HybridDeformedVertexStreamIndex = UnityEngine.Time.frameCount % 2; + ConstantBuffer.PushGlobal(cmd, m_ShaderVariablesGlobalCB, HDShaderIDs._ShaderVariablesGlobal); } diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/Skinning.hlsl b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/Skinning.hlsl index c5c9d9ceaf3..6e705224c38 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/Skinning.hlsl +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/Skinning.hlsl @@ -12,20 +12,25 @@ struct DeformedVertexData float3 Normal; float3 Tangent; }; -uniform StructuredBuffer _DeformedMeshData; +uniform StructuredBuffer _DeformedMeshData; +uniform StructuredBuffer _PreviousFrameDeformedMeshData; void DOTS_Skinning(inout float3 position, inout float3 normal, inout float4 tangent, uint vertexID) { const int doSkinning = (int)unity_SkinSetting.x; if (doSkinning > 0) { - const int meshIndex = (int)unity_ComputeMeshIndex.x; - const DeformedVertexData data = _DeformedMeshData[meshIndex + vertexID]; - - position = data.Position; - normal = data.Normal; - tangent = float4(data.Tangent, 0); + const int streamIndex = _HybridDeformedVertexStreamIndex; + const int startIndex = asint(unity_ComputeMeshIndex)[streamIndex]; + const DeformedVertexData vertexData = _PreviousFrameDeformedMeshData[startIndex + vertexID]; + + //const int meshIndex = (int)unity_ComputeMeshIndex.x; + //const DeformedVertexData data = _DeformedMeshData[meshIndex + vertexID]; + + position = vertexData.Position; + normal = vertexData.Normal; + tangent = float4(vertexData.Tangent, 0); } } @@ -34,8 +39,11 @@ void DOTS_GetPreviousDeformedPosition(inout float3 prevPos, uint vertexID) const int doSkinning = (int)unity_SkinSetting.x; if (doSkinning > 0) { - const int meshIndex = (int)unity_ComputeMeshIndex.x; - prevPos = float3(0, 0, 0);// _DeformedMeshData[meshIndex + vertexID].Position; //Read from other buffer + //const int meshIndex = (int)unity_ComputeMeshIndex.x; + const int streamIndex = (_HybridDeformedVertexStreamIndex + 1) % 2; + const int startIndex = asint(unity_ComputeMeshIndex)[streamIndex]; + const DeformedVertexData vertexData = _PreviousFrameDeformedMeshData[startIndex + vertexID]; + prevPos = vertexData.Position; } } #endif diff --git a/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariablesGlobal.cs b/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariablesGlobal.cs index b5b148546c7..d9a59a76e5f 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariablesGlobal.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariablesGlobal.cs @@ -269,6 +269,6 @@ unsafe struct ShaderVariablesGlobal public float _GlobalTessellationFactorMultiplier; public float _SpecularOcclusionBlend; - public float _Pad9; + public int _HybridDeformedVertexStreamIndex; } } diff --git a/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariablesGlobal.cs.hlsl b/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariablesGlobal.cs.hlsl index bfaaba4b65d..5c8704f44ec 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariablesGlobal.cs.hlsl +++ b/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariablesGlobal.cs.hlsl @@ -152,7 +152,7 @@ GLOBAL_CBUFFER_START(ShaderVariablesGlobal, b0) int _TransparentCameraOnlyMotionVectors; float _GlobalTessellationFactorMultiplier; float _SpecularOcclusionBlend; - float _Pad9; + int _HybridDeformedVertexStreamIndex; CBUFFER_END From 48b1ecf56fd6e1668495ef5ddfd2fb376b93e63c Mon Sep 17 00:00:00 2001 From: Sven Santema Date: Tue, 19 Jan 2021 11:41:45 +0100 Subject: [PATCH 03/34] Actually get the the vertex position of the current frame when rendering the object itself. --- .../Runtime/RenderPipeline/ShaderPass/Skinning.hlsl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/Skinning.hlsl b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/Skinning.hlsl index 6e705224c38..4e810dff520 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/Skinning.hlsl +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/Skinning.hlsl @@ -23,7 +23,7 @@ void DOTS_Skinning(inout float3 position, inout float3 normal, inout float4 tang { const int streamIndex = _HybridDeformedVertexStreamIndex; const int startIndex = asint(unity_ComputeMeshIndex)[streamIndex]; - const DeformedVertexData vertexData = _PreviousFrameDeformedMeshData[startIndex + vertexID]; + const DeformedVertexData vertexData = _DeformedMeshData[startIndex + vertexID]; //const int meshIndex = (int)unity_ComputeMeshIndex.x; //const DeformedVertexData data = _DeformedMeshData[meshIndex + vertexID]; From a60bccc20f36532b697b068cb801704f345ea80a Mon Sep 17 00:00:00 2001 From: hedvig Date: Tue, 19 Jan 2021 13:10:07 +0100 Subject: [PATCH 04/34] d3d debug pragma for HDTarget --- .../Editor/Material/ShaderGraph/HDTarget.cs | 1 + .../Editor/Generation/Descriptors/PragmaDescriptor.cs | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) 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 ea9d6cf9f2a..0d5ba009854 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 @@ -692,6 +692,7 @@ static class CorePragmas { Pragma.Vertex("Vert") }, { Pragma.Fragment("Frag") }, { Pragma.OnlyRenderers(PragmaRenderers.GetHighEndPlatformArray()) }, + { Pragma.DX11Debug }, }; public static PragmaCollection InstancedRenderingLayer = new PragmaCollection diff --git a/com.unity.shadergraph/Editor/Generation/Descriptors/PragmaDescriptor.cs b/com.unity.shadergraph/Editor/Generation/Descriptors/PragmaDescriptor.cs index 7fd170c9467..6e098e835d7 100644 --- a/com.unity.shadergraph/Editor/Generation/Descriptors/PragmaDescriptor.cs +++ b/com.unity.shadergraph/Editor/Generation/Descriptors/PragmaDescriptor.cs @@ -1,4 +1,4 @@ -using System.Linq; +using System.Linq; namespace UnityEditor.ShaderGraph { @@ -32,5 +32,6 @@ static string GetPlatformList(Platform[] platforms) public static PragmaDescriptor DOTSInstancing => new PragmaDescriptor { value = "multi_compile _ DOTS_INSTANCING_ON" }; public static PragmaDescriptor MultiCompileFog => new PragmaDescriptor { value = "multi_compile_fog" }; public static PragmaDescriptor EditorSyncCompilation => new PragmaDescriptor { value = "editor_sync_compilation" }; + public static PragmaDescriptor DX11Debug => new PragmaDescriptor { value = "enable_d3d11_debug_symbols" }; } } From b6a4805b53b149cd7cabea40bb20e0744928c145 Mon Sep 17 00:00:00 2001 From: hedvig Date: Tue, 19 Jan 2021 13:10:42 +0100 Subject: [PATCH 05/34] Remove skin setting component --- .../Runtime/RenderPipeline/ShaderPass/Skinning.hlsl | 5 ++--- .../Runtime/ShaderLibrary/ShaderVariables.hlsl | 5 +---- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/Skinning.hlsl b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/Skinning.hlsl index 4e810dff520..6f95158c871 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/Skinning.hlsl +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/Skinning.hlsl @@ -18,7 +18,7 @@ uniform StructuredBuffer _PreviousFrameDeformedMeshData; void DOTS_Skinning(inout float3 position, inout float3 normal, inout float4 tangent, uint vertexID) { - const int doSkinning = (int)unity_SkinSetting.x; + const int doSkinning = asint(unity_ComputeMeshIndex.z); if (doSkinning > 0) { const int streamIndex = _HybridDeformedVertexStreamIndex; @@ -36,10 +36,9 @@ void DOTS_Skinning(inout float3 position, inout float3 normal, inout float4 tang void DOTS_GetPreviousDeformedPosition(inout float3 prevPos, uint vertexID) { - const int doSkinning = (int)unity_SkinSetting.x; + const int doSkinning = asint(unity_ComputeMeshIndex.z); if (doSkinning > 0) { - //const int meshIndex = (int)unity_ComputeMeshIndex.x; const int streamIndex = (_HybridDeformedVertexStreamIndex + 1) % 2; const int startIndex = asint(unity_ComputeMeshIndex)[streamIndex]; const DeformedVertexData vertexData = _PreviousFrameDeformedMeshData[startIndex + vertexID]; diff --git a/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl b/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl index 4dbccb629ff..8eb9d6356cf 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl +++ b/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl @@ -98,7 +98,6 @@ CBUFFER_START(UnityPerDraw) float4 unity_MotionVectorsParams; float4 unity_ComputeMeshIndex; - float4 unity_SkinSetting; CBUFFER_END @@ -375,8 +374,7 @@ UNITY_DOTS_INSTANCING_START(BuiltinPropertyMetadata) UNITY_DOTS_INSTANCED_PROP(float4, unity_ProbesOcclusion) UNITY_DOTS_INSTANCED_PROP(float3x4, unity_MatrixPreviousM) UNITY_DOTS_INSTANCED_PROP(float3x4, unity_MatrixPreviousMI) - UNITY_DOTS_INSTANCED_PROP(float4, unity_ComputeMeshIndex); - UNITY_DOTS_INSTANCED_PROP(float4, unity_SkinSetting); + UNITY_DOTS_INSTANCED_PROP(float4, unity_ComputeMeshIndex); UNITY_DOTS_INSTANCING_END(BuiltinPropertyMetadata) @@ -398,7 +396,6 @@ UNITY_DOTS_INSTANCING_END(BuiltinPropertyMetadata) #define unity_MatrixPreviousM LoadDOTSInstancedData_float4x4_from_float3x4(UNITY_DOTS_INSTANCED_METADATA_NAME_FROM_MACRO(float3x4, Metadata_unity_MatrixPreviousM)) #define unity_MatrixPreviousMI LoadDOTSInstancedData_float4x4_from_float3x4(UNITY_DOTS_INSTANCED_METADATA_NAME_FROM_MACRO(float3x4, Metadata_unity_MatrixPreviousMI)) #define unity_ComputeMeshIndex UNITY_ACCESS_DOTS_INSTANCED_PROP_FROM_MACRO(float4, Metadata_unity_ComputeMeshIndex) -#define unity_SkinSetting UNITY_ACCESS_DOTS_INSTANCED_PROP_FROM_MACRO(float4, Metadata_unity_SkinSetting) #endif // Define View/Projection matrix macro From b7dd69d85de153e779c2c32d72878553b14a1fc9 Mon Sep 17 00:00:00 2001 From: hedvig Date: Wed, 20 Jan 2021 13:59:30 +0100 Subject: [PATCH 06/34] Apply skinning in motion vec pass, rename function --- .../MotionVectorVertexShaderCommon.hlsl | 8 ++-- .../RenderPipeline/ShaderPass/Skinning.hlsl | 38 ++++++++++++------- .../RenderPipeline/ShaderPass/VertMesh.hlsl | 7 ++-- 3 files changed, 33 insertions(+), 20 deletions(-) diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/MotionVectorVertexShaderCommon.hlsl b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/MotionVectorVertexShaderCommon.hlsl index ab742a8f196..9006b8fc5a2 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/MotionVectorVertexShaderCommon.hlsl +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/MotionVectorVertexShaderCommon.hlsl @@ -107,11 +107,13 @@ PackedVaryingsType MotionVectorVS(inout VaryingsType varyingsType, AttributesMes { bool hasDeformation = unity_MotionVectorsParams.x > 0.0; // Skin or morph target + float3 deformedPrevPos = inputPass.previousPositionOS; #if defined(DOTS_SKINNING) - //only if hasDeformation? - DOTS_GetPreviousDeformedPosition(inputPass.previousPositionOS, inputMesh.vertexID); + //Skin even if force no motion? + DOTS_Deformation_MotionVecPass(inputMesh.positionOS, deformedPrevPos, inputMesh.vertexID); #endif - float3 effectivePositionOS = (hasDeformation ? inputPass.previousPositionOS : inputMesh.positionOS); + float3 effectivePositionOS = (hasDeformation) ? deformedPrevPos : inputMesh.positionOS; + #if defined(_ADD_PRECOMPUTED_VELOCITY) effectivePositionOS -= inputPass.precomputedVelocity; #endif diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/Skinning.hlsl b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/Skinning.hlsl index 6f95158c871..bfc45d07f65 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/Skinning.hlsl +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/Skinning.hlsl @@ -16,17 +16,18 @@ struct DeformedVertexData uniform StructuredBuffer _DeformedMeshData; uniform StructuredBuffer _PreviousFrameDeformedMeshData; -void DOTS_Skinning(inout float3 position, inout float3 normal, inout float4 tangent, uint vertexID) +void DOTS_Deformation(inout float3 position, inout float3 normal, inout float4 tangent, uint vertexID) { - const int doSkinning = asint(unity_ComputeMeshIndex.z); - if (doSkinning > 0) + // x = curr frame index + // y = prev frame index + // z = deformation check (0 = no deformation, 1 = has deformation) + const int4 deformProperty = asint(unity_ComputeMeshIndex); + const int doSkinning = deformProperty.z; + if (doSkinning == 1) { const int streamIndex = _HybridDeformedVertexStreamIndex; - const int startIndex = asint(unity_ComputeMeshIndex)[streamIndex]; + const int startIndex = deformProperty[streamIndex]; const DeformedVertexData vertexData = _DeformedMeshData[startIndex + vertexID]; - - //const int meshIndex = (int)unity_ComputeMeshIndex.x; - //const DeformedVertexData data = _DeformedMeshData[meshIndex + vertexID]; position = vertexData.Position; normal = vertexData.Normal; @@ -34,15 +35,24 @@ void DOTS_Skinning(inout float3 position, inout float3 normal, inout float4 tang } } -void DOTS_GetPreviousDeformedPosition(inout float3 prevPos, uint vertexID) +// position only for motion vec vs +void DOTS_Deformation_MotionVecPass(inout float3 currPos, inout float3 prevPos, uint vertexID) { - const int doSkinning = asint(unity_ComputeMeshIndex.z); - if (doSkinning > 0) + // x = curr frame index + // y = prev frame index + // z = deformation check (0 = no deformation, 1 = has deformation) + const int4 deformProperty = asint(unity_ComputeMeshIndex); + const int doSkinning = deformProperty.z; + if (doSkinning == 1) { - const int streamIndex = (_HybridDeformedVertexStreamIndex + 1) % 2; - const int startIndex = asint(unity_ComputeMeshIndex)[streamIndex]; - const DeformedVertexData vertexData = _PreviousFrameDeformedMeshData[startIndex + vertexID]; - prevPos = vertexData.Position; + const int currStreamIndex = _HybridDeformedVertexStreamIndex; + const int prevStreamIndex = (currStreamIndex + 1) % 2; + + const int currMeshStart = deformProperty[currStreamIndex]; + const int prevMeshStart = deformProperty[prevStreamIndex]; + + currPos = _DeformedMeshData[currMeshStart + vertexID].Position; + prevPos = _PreviousFrameDeformedMeshData[prevMeshStart + vertexID].Position; } } #endif diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/VertMesh.hlsl b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/VertMesh.hlsl index 1636122be0e..b2c470359bb 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/VertMesh.hlsl +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/VertMesh.hlsl @@ -132,12 +132,13 @@ VaryingsMeshType VertMesh(AttributesMesh input, float3 worldSpaceOffset) { VaryingsMeshType output; +#if defined(DOTS_SKINNING) + DOTS_Deformation(input.positionOS, input.normalOS, input.tangentOS, input.vertexID); +#endif + UNITY_SETUP_INSTANCE_ID(input); UNITY_TRANSFER_INSTANCE_ID(input, output); -#if defined(DOTS_SKINNING) - DOTS_Skinning(input.positionOS, input.normalOS, input.tangentOS, input.vertexID); -#endif #if defined(HAVE_MESH_MODIFICATION) input = ApplyMeshModification(input, _TimeParameters.xyz); From 81d07887f93a2f23cb4e7acd7e93822c88a22195 Mon Sep 17 00:00:00 2001 From: hedvig Date: Wed, 20 Jan 2021 15:56:37 +0100 Subject: [PATCH 07/34] Add motion vectors to unity instancing properties --- .../Runtime/ShaderLibrary/ShaderVariables.hlsl | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl b/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl index 8eb9d6356cf..5394c885599 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl +++ b/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl @@ -374,7 +374,8 @@ UNITY_DOTS_INSTANCING_START(BuiltinPropertyMetadata) UNITY_DOTS_INSTANCED_PROP(float4, unity_ProbesOcclusion) UNITY_DOTS_INSTANCED_PROP(float3x4, unity_MatrixPreviousM) UNITY_DOTS_INSTANCED_PROP(float3x4, unity_MatrixPreviousMI) - UNITY_DOTS_INSTANCED_PROP(float4, unity_ComputeMeshIndex); + UNITY_DOTS_INSTANCED_PROP(float4, unity_MotionVectorsParams) + UNITY_DOTS_INSTANCED_PROP(float4, unity_ComputeMeshIndex) UNITY_DOTS_INSTANCING_END(BuiltinPropertyMetadata) @@ -395,6 +396,7 @@ UNITY_DOTS_INSTANCING_END(BuiltinPropertyMetadata) #define unity_ProbesOcclusion UNITY_ACCESS_DOTS_INSTANCED_PROP_FROM_MACRO(float4, Metadata_unity_ProbesOcclusion) #define unity_MatrixPreviousM LoadDOTSInstancedData_float4x4_from_float3x4(UNITY_DOTS_INSTANCED_METADATA_NAME_FROM_MACRO(float3x4, Metadata_unity_MatrixPreviousM)) #define unity_MatrixPreviousMI LoadDOTSInstancedData_float4x4_from_float3x4(UNITY_DOTS_INSTANCED_METADATA_NAME_FROM_MACRO(float3x4, Metadata_unity_MatrixPreviousMI)) +#define unity_MotionVectorsParams UNITY_ACCESS_DOTS_INSTANCED_PROP_FROM_MACRO(float4, Metadata_unity_MotionVectorsParams) #define unity_ComputeMeshIndex UNITY_ACCESS_DOTS_INSTANCED_PROP_FROM_MACRO(float4, Metadata_unity_ComputeMeshIndex) #endif From 0d6a8dd8ff94e3af303be210a1a6854c598955a7 Mon Sep 17 00:00:00 2001 From: hedvig Date: Wed, 20 Jan 2021 16:21:52 +0100 Subject: [PATCH 08/34] Remove compute deformation node --- .../Mesh Deformation/ComputeDeformNode.cs | 156 ------------------ .../ComputeDeformNode.cs.meta | 11 -- 2 files changed, 167 deletions(-) delete mode 100644 com.unity.shadergraph/Editor/Data/Nodes/Mesh Deformation/ComputeDeformNode.cs delete mode 100644 com.unity.shadergraph/Editor/Data/Nodes/Mesh Deformation/ComputeDeformNode.cs.meta diff --git a/com.unity.shadergraph/Editor/Data/Nodes/Mesh Deformation/ComputeDeformNode.cs b/com.unity.shadergraph/Editor/Data/Nodes/Mesh Deformation/ComputeDeformNode.cs deleted file mode 100644 index 52d68ca293b..00000000000 --- a/com.unity.shadergraph/Editor/Data/Nodes/Mesh Deformation/ComputeDeformNode.cs +++ /dev/null @@ -1,156 +0,0 @@ -using UnityEngine; -using UnityEditor.Graphing; -using UnityEditor.ShaderGraph.Internal; - -namespace UnityEditor.ShaderGraph -{ - [Title("Input", "Mesh Deformation", "Compute Deformation")] - class ComputeDeformNode : AbstractMaterialNode, IGeneratesBodyCode, IGeneratesFunction, IMayRequirePosition, IMayRequireNormal, IMayRequireTangent, IMayRequireVertexID - { - public const int kPositionOutputSlotId = 0; - public const int kNormalOutputSlotId = 1; - public const int kTangentOutputSlotId = 2; - - public const string kOutputSlotPositionName = "Deformed Position"; - public const string kOutputSlotNormalName = "Deformed Normal"; - public const string kOutputSlotTangentName = "Deformed Tangent"; - - public ComputeDeformNode() - { - name = "Compute Deformation"; - UpdateNodeAfterDeserialization(); - } - - public sealed override void UpdateNodeAfterDeserialization() - { - AddSlot(new Vector3MaterialSlot(kPositionOutputSlotId, kOutputSlotPositionName, kOutputSlotPositionName, SlotType.Output, Vector3.zero, ShaderStageCapability.Vertex)); - AddSlot(new Vector3MaterialSlot(kNormalOutputSlotId, kOutputSlotNormalName, kOutputSlotNormalName, SlotType.Output, Vector3.zero, ShaderStageCapability.Vertex)); - AddSlot(new Vector3MaterialSlot(kTangentOutputSlotId, kOutputSlotTangentName, kOutputSlotTangentName, SlotType.Output, Vector3.zero, ShaderStageCapability.Vertex)); - RemoveSlotsNameNotMatching(new[] { kPositionOutputSlotId, kNormalOutputSlotId, kTangentOutputSlotId }); - } - - protected override void CalculateNodeHasError() - { -#if !HYBRID_RENDERER_0_6_0_OR_NEWER - owner.AddSetupError(objectId, "Could not find version 0.6.0 or newer of the Hybrid Renderer package installed in the project."); - hasError = true; -#endif -#if !ENABLE_COMPUTE_DEFORMATIONS - owner.AddSetupError(objectId, "For the Compute Deformation node to work, you must go to Project Settings>Player>Other Settings and add the ENABLE_COMPUTE_DEFORMATIONS define to Scripting Define Symbols."); - hasError = true; -#endif - } - - public bool RequiresVertexID(ShaderStageCapability stageCapability = ShaderStageCapability.All) - { - return true; - } - - public NeededCoordinateSpace RequiresPosition(ShaderStageCapability stageCapability = ShaderStageCapability.All) - { - if (stageCapability == ShaderStageCapability.Vertex || stageCapability == ShaderStageCapability.All) - return NeededCoordinateSpace.Object; - else - return NeededCoordinateSpace.None; - } - - public NeededCoordinateSpace RequiresNormal(ShaderStageCapability stageCapability = ShaderStageCapability.All) - { - if (stageCapability == ShaderStageCapability.Vertex || stageCapability == ShaderStageCapability.All) - return NeededCoordinateSpace.Object; - else - return NeededCoordinateSpace.None; - } - - public NeededCoordinateSpace RequiresTangent(ShaderStageCapability stageCapability = ShaderStageCapability.All) - { - if (stageCapability == ShaderStageCapability.Vertex || stageCapability == ShaderStageCapability.All) - return NeededCoordinateSpace.Object; - else - return NeededCoordinateSpace.None; - } - - public override void CollectShaderProperties(PropertyCollector properties, GenerationMode generationMode) - { - properties.AddShaderProperty(new Vector1ShaderProperty() - { - displayName = "Compute Mesh Buffer Index Offset", - overrideReferenceName = "_ComputeMeshIndex", - overrideHLSLDeclaration = true, - hlslDeclarationOverride = HLSLDeclaration.HybridPerInstance, -#if ENABLE_HYBRID_RENDERER_V2 - hidden = true, -#endif - value = 0 - }); - - base.CollectShaderProperties(properties, generationMode); - } - - public void GenerateNodeCode(ShaderStringBuilder sb, GenerationMode generationMode) - { -#if ENABLE_HYBRID_RENDERER_V2 - sb.AppendLine("#if defined(UNITY_DOTS_INSTANCING_ENABLED)"); -#endif - sb.AppendLine("$precision3 {0} = 0;", GetVariableNameForSlot(kPositionOutputSlotId)); - sb.AppendLine("$precision3 {0} = 0;", GetVariableNameForSlot(kNormalOutputSlotId)); - sb.AppendLine("$precision3 {0} = 0;", GetVariableNameForSlot(kTangentOutputSlotId)); - if (generationMode == GenerationMode.ForReals) - { - sb.AppendLine($"{GetFunctionName()}(" + - $"IN.VertexID, " + - $"{GetVariableNameForSlot(kPositionOutputSlotId)}, " + - $"{GetVariableNameForSlot(kNormalOutputSlotId)}, " + - $"{GetVariableNameForSlot(kTangentOutputSlotId)});"); - } -#if ENABLE_HYBRID_RENDERER_V2 - sb.AppendLine("#else"); - sb.AppendLine("$precision3 {0} = IN.ObjectSpacePosition;", GetVariableNameForSlot(kPositionOutputSlotId)); - sb.AppendLine("$precision3 {0} = IN.ObjectSpaceNormal;", GetVariableNameForSlot(kNormalOutputSlotId)); - sb.AppendLine("$precision3 {0} = IN.ObjectSpaceTangent;", GetVariableNameForSlot(kTangentOutputSlotId)); - sb.AppendLine("#endif"); -#endif - } - - public void GenerateNodeFunction(FunctionRegistry registry, GenerationMode generationMode) - { - registry.ProvideFunction("DeformedMeshData", sb => - { - sb.AppendLine("struct DeformedVertexData"); - sb.AppendLine("{"); - using (sb.IndentScope()) - { - sb.AppendLine("float3 Position;"); - sb.AppendLine("float3 Normal;"); - sb.AppendLine("float3 Tangent;"); - } - sb.AppendLine("};"); - sb.AppendLine("uniform StructuredBuffer _DeformedMeshData : register(t1);"); - }); - - registry.ProvideFunction(GetFunctionName(), sb => - { - sb.AppendLine($"void {GetFunctionName()}(" + - "uint vertexID, " + - "out $precision3 positionOut, " + - "out $precision3 normalOut, " + - "out $precision3 tangentOut)"); - - sb.AppendLine("{"); - using (sb.IndentScope()) - { - sb.AppendLine("const DeformedVertexData vertexData = _DeformedMeshData[asuint(_ComputeMeshIndex) + vertexID];"); - sb.AppendLine("positionOut = vertexData.Position;"); - sb.AppendLine("normalOut = vertexData.Normal;"); - sb.AppendLine("tangentOut = vertexData.Tangent;"); - } - sb.AppendLine("}"); - }); - } - - string GetFunctionName() - { - return $"Unity_ComputeDeformedVertex_{concretePrecision.ToShaderString()}"; - } - } -} diff --git a/com.unity.shadergraph/Editor/Data/Nodes/Mesh Deformation/ComputeDeformNode.cs.meta b/com.unity.shadergraph/Editor/Data/Nodes/Mesh Deformation/ComputeDeformNode.cs.meta deleted file mode 100644 index b3ff4c70b90..00000000000 --- a/com.unity.shadergraph/Editor/Data/Nodes/Mesh Deformation/ComputeDeformNode.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 1b8bcd39f0b64c14eba5885020ae7349 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: From 4e921d8b579314e8f7b3c1e4b4827352d039cfbd Mon Sep 17 00:00:00 2001 From: hedvig Date: Thu, 21 Jan 2021 16:34:05 +0100 Subject: [PATCH 09/34] Update changelog for HRDP and SG --- com.unity.render-pipelines.high-definition/CHANGELOG.md | 1 + com.unity.shadergraph/CHANGELOG.md | 3 +++ 2 files changed, 4 insertions(+) diff --git a/com.unity.render-pipelines.high-definition/CHANGELOG.md b/com.unity.render-pipelines.high-definition/CHANGELOG.md index f145e4e9322..62a8f09c97d 100644 --- a/com.unity.render-pipelines.high-definition/CHANGELOG.md +++ b/com.unity.render-pipelines.high-definition/CHANGELOG.md @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - Added light unit slider for automatic and automatic histrogram exposure limits. - Added View Bias for mesh decals. - Added support for the PlayStation 5 platform. +- Added support for skinned motionvectors when using Hybrid Renderer ### Fixed - Fixed computation of geometric normal in path tracing (case 1293029). diff --git a/com.unity.shadergraph/CHANGELOG.md b/com.unity.shadergraph/CHANGELOG.md index b723b36ff8a..9cb20a35536 100644 --- a/com.unity.shadergraph/CHANGELOG.md +++ b/com.unity.shadergraph/CHANGELOG.md @@ -13,6 +13,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - Texture and SamplerState types are now HLSL structures (defined in com.unity.render-pipelines.core/ShaderLibrary/Texture.hlsl). CustomFunctionNode use of the old plain types is supported, but the user should upgrade to structures to avoid bugs. - The shader graph inspector window will now switch to the "Node Settings" tab whenever a property/node/other selectable item in the graph is clicked on to save the user a click +### Removed + - Removed Compute Deformation Node + ### Fixed - Fixed an issue where shaders could be generated with CR/LF ("\r\n") instead of just LF ("\n") line endings [1286430] - All textures in a ShaderGraph, even those not used, will now be pulled into an Exported Package [1283902] From 82ffcd894de920aaead94491dff3df3cf1e9462f Mon Sep 17 00:00:00 2001 From: hedvig Date: Wed, 27 Jan 2021 11:05:46 +0100 Subject: [PATCH 10/34] Enable vertexID when DOTS_INSTANCING_ON is defined --- .../Editor/Material/ShaderGraph/HDStructFields.cs | 4 ++-- .../Runtime/RenderPipeline/ShaderPass/VaryingMesh.hlsl | 4 +++- .../Editor/Generation/TargetResources/StructFields.cs | 6 ++++-- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/HDStructFields.cs b/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/HDStructFields.cs index 21abde9304d..49e1fbe5ba6 100644 --- a/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/HDStructFields.cs +++ b/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/HDStructFields.cs @@ -28,8 +28,8 @@ public struct AttributesMesh "COLOR", subscriptOptions : StructFieldOptions.Optional); public static FieldDescriptor instanceID = new FieldDescriptor(AttributesMesh.name, "instanceID", "", ShaderValueType.Uint, "INSTANCEID_SEMANTIC", "UNITY_ANY_INSTANCING_ENABLED"); - public static FieldDescriptor vertexID = new FieldDescriptor(AttributesMesh.name, "vertexID", "ATTRIBUTES_NEED_VERTEXID", ShaderValueType.Uint, - "SV_VertexID", subscriptOptions: StructFieldOptions.Optional); + public static FieldDescriptor vertexID = new FieldDescriptor(AttributesMesh.name, "vertexID", "", ShaderValueType.Uint, + "SV_VertexID", "DOTS_INSTANCING_ON"); } public struct VaryingsMeshToPS diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/VaryingMesh.hlsl b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/VaryingMesh.hlsl index 58895bb51c3..68b9e7d753f 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/VaryingMesh.hlsl +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/VaryingMesh.hlsl @@ -22,7 +22,9 @@ struct AttributesMesh #ifdef ATTRIBUTES_NEED_COLOR float4 color : COLOR; #endif - +#ifdef DOTS_INSTANCING_ON + uint vertexID : SV_VertexID; +#endif UNITY_VERTEX_INPUT_INSTANCE_ID }; diff --git a/com.unity.shadergraph/Editor/Generation/TargetResources/StructFields.cs b/com.unity.shadergraph/Editor/Generation/TargetResources/StructFields.cs index dcd2f04cc96..d761e0c7cfb 100644 --- a/com.unity.shadergraph/Editor/Generation/TargetResources/StructFields.cs +++ b/com.unity.shadergraph/Editor/Generation/TargetResources/StructFields.cs @@ -27,8 +27,8 @@ public struct Attributes "COLOR", subscriptOptions : StructFieldOptions.Optional); public static FieldDescriptor instanceID = new FieldDescriptor(Attributes.name, "instanceID", "", ShaderValueType.Uint, "INSTANCEID_SEMANTIC", "UNITY_ANY_INSTANCING_ENABLED"); - public static FieldDescriptor vertexID = new FieldDescriptor(Attributes.name, "vertexID", "ATTRIBUTES_NEED_VERTEXID", ShaderValueType.Uint, - "SV_VertexID", subscriptOptions: StructFieldOptions.Optional); + public static FieldDescriptor vertexID = new FieldDescriptor(Attributes.name, "vertexID", "", ShaderValueType.Uint, + "SV_VertexID", "DOTS_INSTANCING_ON"); } public struct Varyings @@ -57,6 +57,8 @@ public struct Varyings subscriptOptions : StructFieldOptions.Optional); public static FieldDescriptor instanceID = new FieldDescriptor(Varyings.name, "instanceID", "", ShaderValueType.Uint, "CUSTOM_INSTANCE_ID", "UNITY_ANY_INSTANCING_ENABLED"); + public static FieldDescriptor vertexID = new FieldDescriptor(Attributes.name, "vertexID", "", ShaderValueType.Uint, + "SV_VertexID", "DOTS_INSTANCING_ON"); public static FieldDescriptor cullFace = new FieldDescriptor(Varyings.name, "cullFace", "VARYINGS_NEED_CULLFACE", "FRONT_FACE_TYPE", "FRONT_FACE_SEMANTIC", "defined(SHADER_STAGE_FRAGMENT) && defined(VARYINGS_NEED_CULLFACE)", StructFieldOptions.Generated & StructFieldOptions.Optional); } From 028e908e2626be4e195a0f6b1137aedbc3bcea9c Mon Sep 17 00:00:00 2001 From: hedvig Date: Wed, 27 Jan 2021 11:06:51 +0100 Subject: [PATCH 11/34] Remove manual adding of vertex id and defines in HD shader passes --- .../Material/ShaderGraph/HDShaderPasses.cs | 263 +----------------- 1 file changed, 11 insertions(+), 252 deletions(-) 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 eb4f57edc35..347b980133b 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 @@ -1,7 +1,3 @@ -#if ENABLE_HYBRID_RENDERER_V2 //TODO: find way to not add to all passes manually? - #define AddSkinDefineAndInclude -#endif - using System; using System.Collections.Generic; using System.Linq; @@ -96,30 +92,15 @@ public static PassDescriptor GenerateScenePicking() pragmas = CorePragmas.DotsInstancedInV1AndV2EditorSync, defines = GenerateDefines(), includes = GenerateIncludes(), -#if AddSkinDefineAndInclude - requiredFields = GenerateRequiredFields(), -#endif }; -#if AddSkinDefineAndInclude - FieldCollection GenerateRequiredFields() - { - return new FieldCollection - { - HDStructFields.AttributesMesh.vertexID - }; - } -#endif + DefineCollection GenerateDefines() { return new DefineCollection { CoreDefines.ScenePicking, -#if AddSkinDefineAndInclude - { CoreKeywordDescriptors.SkinningDefine, 1 }, - //{ CoreKeywordDescriptors.ComputeSkinningDefine, 1 }, -#endif }; } @@ -132,9 +113,6 @@ IncludeCollection GenerateIncludes() includes.Add(CoreIncludes.CoreUtility); includes.Add(CoreIncludes.kShaderGraphFunctions, IncludeLocation.Pregraph); includes.Add(CoreIncludes.kPickingSpaceTransforms, IncludeLocation.Pregraph); -#if AddSkinDefineAndInclude - includes.Add(CoreIncludes.kSkinning, IncludeLocation.Pregraph); -#endif includes.Add(CoreIncludes.kPassDepthOnly, IncludeLocation.Postgraph); return includes; @@ -160,30 +138,15 @@ public static PassDescriptor GenerateSceneSelection(bool supportLighting) pragmas = CorePragmas.DotsInstancedInV1AndV2EditorSync, defines = GenerateDefines(), includes = GenerateIncludes(), -#if AddSkinDefineAndInclude - requiredFields = GenerateRequiredFields(), -#endif }; -#if AddSkinDefineAndInclude - FieldCollection GenerateRequiredFields() - { - return new FieldCollection - { - HDStructFields.AttributesMesh.vertexID - }; - } -#endif + DefineCollection GenerateDefines() { return new DefineCollection { CoreDefines.SceneSelection, -#if AddSkinDefineAndInclude - { CoreKeywordDescriptors.SkinningDefine, 1 }, - //{ CoreKeywordDescriptors.ComputeSkinningDefine, 1 }, -#endif }; } @@ -202,9 +165,6 @@ IncludeCollection GenerateIncludes() includes.Add(CoreIncludes.kPostDecalsPlaceholder, IncludeLocation.Pregraph); } includes.Add(CoreIncludes.kShaderGraphFunctions, IncludeLocation.Pregraph); -#if AddSkinDefineAndInclude - includes.Add(CoreIncludes.kSkinning, IncludeLocation.Pregraph); -#endif includes.Add(CoreIncludes.kPassDepthOnly, IncludeLocation.Postgraph); return includes; @@ -238,30 +198,8 @@ static public PassDescriptor GenerateShadowCaster(bool supportLighting) renderStates = CoreRenderStates.ShadowCaster, pragmas = CorePragmas.DotsInstancedInV2Only, includes = GenerateIncludes(), -#if AddSkinDefineAndInclude - requiredFields = GenerateFields(), - defines = GenerateDefines() -#endif }; -#if AddSkinDefineAndInclude - FieldCollection GenerateFields() - { - return new FieldCollection - { - HDStructFields.AttributesMesh.vertexID - }; - } - - DefineCollection GenerateDefines() - { - return new DefineCollection - { - { CoreKeywordDescriptors.SkinningDefine, 1 }, - //{ CoreKeywordDescriptors.ComputeSkinningDefine, 1 }, - }; - } -#endif IncludeCollection GenerateIncludes() { @@ -278,9 +216,6 @@ IncludeCollection GenerateIncludes() includes.Add(CoreIncludes.kPostDecalsPlaceholder, IncludeLocation.Pregraph); } includes.Add(CoreIncludes.kShaderGraphFunctions, IncludeLocation.Pregraph); -#if AddSkinDefineAndInclude - includes.Add(CoreIncludes.kSkinning, IncludeLocation.Pregraph); -#endif includes.Add(CoreIncludes.kPassDepthOnly, IncludeLocation.Postgraph); return includes; @@ -309,31 +244,13 @@ public static PassDescriptor GenerateMETA(bool supportLighting) pragmas = CorePragmas.DotsInstancedInV1AndV2, defines = GenerateDefines(), includes = GenerateIncludes(), -#if AddSkinDefineAndInclude - requiredFields = GenerateRequiredFields(), -#endif + requiredFields = CoreRequiredFields.Meta, }; - - FieldCollection GenerateRequiredFields() - { - return new FieldCollection - { - CoreRequiredFields.Meta, -#if AddSkinDefineAndInclude - HDStructFields.AttributesMesh.vertexID -#endif - }; - } - DefineCollection GenerateDefines() { return new DefineCollection { CoreDefines.ShaderGraphRaytracingDefault, -#if AddSkinDefineAndInclude - { CoreKeywordDescriptors.SkinningDefine, 1 }, - //{ CoreKeywordDescriptors.ComputeSkinningDefine, 1 }, -#endif }; } @@ -352,9 +269,6 @@ IncludeCollection GenerateIncludes() includes.Add(CoreIncludes.kPostDecalsPlaceholder, IncludeLocation.Pregraph); } includes.Add(CoreIncludes.kShaderGraphFunctions, IncludeLocation.Pregraph); -#if AddSkinDefineAndInclude - includes.Add(CoreIncludes.kSkinning, IncludeLocation.Pregraph); -#endif includes.Add(CoreIncludes.kPassLightTransport, IncludeLocation.Postgraph); return includes; @@ -388,10 +302,6 @@ DefineCollection GenerateDefines() return new DefineCollection { supportLighting ? CoreDefines.DepthForwardOnly : CoreDefines.DepthForwardOnlyUnlit, -#if AddSkinDefineAndInclude - { CoreKeywordDescriptors.SkinningDefine, 1 }, - //{ CoreKeywordDescriptors.ComputeSkinningDefine, 1 }, -#endif }; } @@ -425,9 +335,6 @@ FieldCollection GenerateRequiredFields() HDStructFields.AttributesMesh.color, HDStructFields.AttributesMesh.uv2, HDStructFields.AttributesMesh.uv3, -#if AddSkinDefineAndInclude - HDStructFields.AttributesMesh.vertexID, -#endif HDStructFields.FragInputs.tangentToWorld, HDStructFields.FragInputs.positionRWS, HDStructFields.FragInputs.texCoord1, @@ -449,9 +356,6 @@ IncludeCollection GenerateIncludes() if (supportLighting) includes.Add(CoreIncludes.kDecalUtilities, IncludeLocation.Pregraph); includes.Add(CoreIncludes.kShaderGraphFunctions, IncludeLocation.Pregraph); -#if AddSkinDefineAndInclude - includes.Add(CoreIncludes.kSkinning, IncludeLocation.Pregraph); -#endif includes.Add(CoreIncludes.kPassDepthOnly, IncludeLocation.Postgraph); return includes; @@ -477,20 +381,9 @@ public static PassDescriptor GenerateMotionVectors(bool supportLighting, bool su defines = GenerateDefines(), pragmas = CorePragmas.DotsInstancedInV2Only, includes = GenerateIncludes(), - requiredFields = GenerateRequiredFields(), + requiredFields = CoreRequiredFields.LitFull, }; - FieldCollection GenerateRequiredFields() - { - return new FieldCollection - { - CoreRequiredFields.LitFull, -#if AddSkinDefineAndInclude - HDStructFields.AttributesMesh.vertexID -#endif - }; - } - DefineCollection GenerateDefines() { if (!supportLighting) @@ -506,10 +399,6 @@ DefineCollection GenerateDefines() // { // defines.Add(CoreKeywordDescriptors.WriteNormalBuffer, 1); // } -#if AddSkinDefineAndInclude - defines.Add(CoreKeywordDescriptors.SkinningDefine, 1); - //defines.Add(CoreKeywordDescriptors.ComputeSkinningDefine, 1); -#endif return defines; } @@ -548,9 +437,6 @@ IncludeCollection GenerateIncludes() includes.Add(CoreIncludes.kPostDecalsPlaceholder, IncludeLocation.Pregraph); } includes.Add(CoreIncludes.kShaderGraphFunctions, IncludeLocation.Pregraph); -#if AddSkinDefineAndInclude - includes.Add(CoreIncludes.kSkinning, IncludeLocation.Pregraph); -#endif includes.Add(CoreIncludes.kPassMotionVectors, IncludeLocation.Postgraph); return includes; @@ -720,29 +606,14 @@ public static PassDescriptor GenerateTransparentDepthPrepass(bool supportLightin pragmas = CorePragmas.DotsInstancedInV1AndV2, defines = GenerateDefines(), includes = GenerateIncludes(), - requiredFields = GenerateRequiredFields(), + requiredFields = TransparentDepthPrepassFields, }; - FieldCollection GenerateRequiredFields() - { - return new FieldCollection - { - TransparentDepthPrepassFields, -#if AddSkinDefineAndInclude - HDStructFields.AttributesMesh.vertexID -#endif - }; - } - DefineCollection GenerateDefines() { return new DefineCollection { CoreDefines.TransparentDepthPrepass, - #if AddSkinDefineAndInclude - { CoreKeywordDescriptors.SkinningDefine, 1 }, - //{ CoreKeywordDescriptors.ComputeSkinningDefine, 1 }, - #endif }; } @@ -780,9 +651,6 @@ IncludeCollection GenerateIncludes() includes.Add(CoreIncludes.kPostDecalsPlaceholder, IncludeLocation.Pregraph); } includes.Add(CoreIncludes.kShaderGraphFunctions, IncludeLocation.Pregraph); -#if AddSkinDefineAndInclude - includes.Add(CoreIncludes.kSkinning, IncludeLocation.Pregraph); -#endif includes.Add(CoreIncludes.kPassDepthOnly, IncludeLocation.Postgraph); return includes; @@ -883,7 +751,7 @@ public static PassDescriptor GenerateLitDepthOnly() useInPreview = true, // Collections - requiredFields = DepthOnlyFields, + requiredFields = CoreRequiredFields.LitFull, renderStates = CoreRenderStates.DepthOnly, pragmas = CorePragmas.DotsInstancedInV1AndV2, defines = DepthOnlyDefines, @@ -892,22 +760,9 @@ public static PassDescriptor GenerateLitDepthOnly() }; } - public static FieldCollection DepthOnlyFields = new FieldCollection - { - CoreRequiredFields.LitFull, -#if AddSkinDefineAndInclude - HDStructFields.AttributesMesh.vertexID -#endif - }; - - public static DefineCollection DepthOnlyDefines = new DefineCollection { CoreDefines.ShaderGraphRaytracingDefault, -#if AddSkinDefineAndInclude - { CoreKeywordDescriptors.SkinningDefine, 1 }, - //{ CoreKeywordDescriptors.ComputeSkinningDefine, 1 }, -#endif }; public static IncludeCollection DepthOnlyIncludes = new IncludeCollection @@ -919,9 +774,6 @@ public static PassDescriptor GenerateLitDepthOnly() { CoreIncludes.kDecalUtilities, IncludeLocation.Pregraph }, { CoreIncludes.kPostDecalsPlaceholder, IncludeLocation.Pregraph }, { CoreIncludes.kShaderGraphFunctions, IncludeLocation.Pregraph }, -#if AddSkinDefineAndInclude - { CoreIncludes.kSkinning, IncludeLocation.Pregraph }, -#endif { CoreIncludes.kPassDepthOnly, IncludeLocation.Postgraph }, }; @@ -945,7 +797,7 @@ public static PassDescriptor GenerateGBuffer() useInPreview = true, // Collections - requiredFields = GBufferFields, + requiredFields = CoreRequiredFields.LitMinimal, renderStates = GBufferRenderState, pragmas = CorePragmas.DotsInstancedInV1AndV2, defines = GBufferDefines, @@ -956,21 +808,9 @@ public static PassDescriptor GenerateGBuffer() }; } - public static FieldCollection GBufferFields = new FieldCollection - { - CoreRequiredFields.LitMinimal, - #if AddSkinDefineAndInclude - HDStructFields.AttributesMesh.vertexID - #endif - }; - public static DefineCollection GBufferDefines = new DefineCollection { CoreDefines.ShaderGraphRaytracingDefault, -#if AddSkinDefineAndInclude - { CoreKeywordDescriptors.SkinningDefine, 1 }, - // { CoreKeywordDescriptors.ComputeSkinningDefine, 1 }, -#endif }; @@ -988,9 +828,6 @@ public static PassDescriptor GenerateGBuffer() { CoreIncludes.kDecalUtilities, IncludeLocation.Pregraph }, { CoreIncludes.kPostDecalsPlaceholder, IncludeLocation.Pregraph }, { CoreIncludes.kShaderGraphFunctions, IncludeLocation.Pregraph }, - #if AddSkinDefineAndInclude - { CoreIncludes.kSkinning, IncludeLocation.Pregraph }, - #endif { CoreIncludes.kPassGBuffer, IncludeLocation.Postgraph }, }; @@ -1022,7 +859,7 @@ public static PassDescriptor GenerateLitForward() useInPreview = true, // Collections - requiredFields = ForwardFields, + requiredFields = CoreRequiredFields.LitMinimal, renderStates = CoreRenderStates.Forward, pragmas = CorePragmas.DotsInstancedInV1AndV2, defines = CoreDefines.Forward, @@ -1032,21 +869,9 @@ public static PassDescriptor GenerateLitForward() }; } - public static FieldCollection ForwardFields = new FieldCollection - { - CoreRequiredFields.LitMinimal, -#if AddSkinDefineAndInclude - HDStructFields.AttributesMesh.vertexID -#endif - }; - public static DefineCollection ForwardDefines = new DefineCollection { CoreDefines.Forward, -#if AddSkinDefineAndInclude - { CoreKeywordDescriptors.SkinningDefine, 1 }, - //{ CoreKeywordDescriptors.ComputeSkinningDefine, 1 }, -#endif }; public static IncludeCollection ForwardIncludes = new IncludeCollection @@ -1061,9 +886,6 @@ public static PassDescriptor GenerateLitForward() { CoreIncludes.kDecalUtilities, IncludeLocation.Pregraph }, { CoreIncludes.kPostDecalsPlaceholder, IncludeLocation.Pregraph }, { CoreIncludes.kShaderGraphFunctions, IncludeLocation.Pregraph }, - #if AddSkinDefineAndInclude - { CoreIncludes.kSkinning, IncludeLocation.Pregraph }, - #endif { CoreIncludes.kPassForward, IncludeLocation.Postgraph }, }; @@ -1086,26 +908,13 @@ public static PassDescriptor GenerateLitRaytracingPrepass() pragmas = CorePragmas.Basic, defines = LitRayTracingPrepassDefines, includes = RayTracingPrepassIncludes, -#if AddSkinDefineAndInclude - requiredFields = LitRayTracingFields, -#endif }; } - -#if AddSkinDefineAndInclude - public static FieldCollection LitRayTracingFields = new FieldCollection - { - HDStructFields.AttributesMesh.vertexID - }; -#endif + public static DefineCollection LitRayTracingPrepassDefines = new DefineCollection { CoreDefines.ShaderGraphRaytracingDefault, -#if AddSkinDefineAndInclude - { CoreKeywordDescriptors.SkinningDefine, 1 }, - //{ CoreKeywordDescriptors.ComputeSkinningDefine, 1 }, -#endif }; public static IncludeCollection RayTracingPrepassIncludes = new IncludeCollection @@ -1117,9 +926,6 @@ public static PassDescriptor GenerateLitRaytracingPrepass() { CoreIncludes.kDecalUtilities, IncludeLocation.Pregraph }, { CoreIncludes.kPostDecalsPlaceholder, IncludeLocation.Pregraph }, { CoreIncludes.kShaderGraphFunctions, IncludeLocation.Pregraph }, - #if AddSkinDefineAndInclude - { CoreIncludes.kSkinning, IncludeLocation.Pregraph }, - #endif { CoreIncludes.kPassConstant, IncludeLocation.Postgraph }, }; @@ -1155,30 +961,15 @@ public static PassDescriptor GenerateRaytracingIndirect(bool supportLighting) keywords = supportLighting ? IndirectDiffuseKeywordCollection : null, defines = GenerateDefines(), includes = GenerateIncludes(), -#if AddSkinDefineAndInclude - requiredFields = GenerateRequiredFields(), -#endif }; -#if AddSkinDefineAndInclude - FieldCollection GenerateRequiredFields() - { - return new FieldCollection - { - HDStructFields.AttributesMesh.vertexID - }; - } -#endif + DefineCollection GenerateDefines() { return new DefineCollection { supportLighting ? RaytracingIndirectDefines : null, -#if AddSkinDefineAndInclude - { CoreKeywordDescriptors.SkinningDefine, 1 }, - //{ CoreKeywordDescriptors.ComputeSkinningDefine, 1 }, -#endif }; } @@ -1205,10 +996,6 @@ IncludeCollection GenerateIncludes() includes.Add(CoreIncludes.CoreUtility); includes.Add(CoreIncludes.kRaytracingCommon, IncludeLocation.Pregraph); includes.Add(CoreIncludes.kShaderGraphFunctions, IncludeLocation.Pregraph); -#if AddSkinDefineAndInclude - includes.Add(CoreIncludes.kSkinning, IncludeLocation.Pregraph); -#endif - // post graph includes includes.Add(CoreIncludes.kPassRaytracingIndirect, IncludeLocation.Postgraph); @@ -1539,33 +1326,8 @@ public static PassDescriptor GenerateFullScreenDebug() pragmas = CorePragmas.Basic, renderStates = FullScreenDebugRenderState, includes = GenerateIncludes(), -#if AddSkinDefineAndInclude - defines = GenerateDefines(), - requiredFields = GenerateRequiredFields(), -#endif }; - -#if AddSkinDefineAndInclude - FieldCollection GenerateRequiredFields() - { - return new FieldCollection - { - HDStructFields.AttributesMesh.vertexID - }; - } -#endif - -#if AddSkinDefineAndInclude - DefineCollection GenerateDefines() - { - return new DefineCollection - { - { CoreKeywordDescriptors.SkinningDefine, 1 }, - // { CoreKeywordDescriptors.ComputeSkinningDefine, 1 }, - }; - } -#endif - + IncludeCollection GenerateIncludes() { return new IncludeCollection @@ -1575,9 +1337,6 @@ IncludeCollection GenerateIncludes() { CoreIncludes.kPassPlaceholder, IncludeLocation.Pregraph }, { CoreIncludes.CoreUtility }, { CoreIncludes.kShaderGraphFunctions, IncludeLocation.Pregraph }, - #if AddSkinDefineAndInclude - { CoreIncludes.kSkinning, IncludeLocation.Pregraph }, - #endif { CoreIncludes.kPassFullScreenDebug, IncludeLocation.Postgraph }, }; } From 80c2dcdd728d1b789b078650525ca5f063018816 Mon Sep 17 00:00:00 2001 From: hedvig Date: Wed, 27 Jan 2021 11:07:21 +0100 Subject: [PATCH 12/34] Remove skinning include and define --- .../Editor/Material/ShaderGraph/HDTarget.cs | 12 +----------- 1 file changed, 1 insertion(+), 11 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 6c5520362e4..aa092fe761f 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 @@ -948,8 +948,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 kSkinning = "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/Skinning.hlsl"; - + public static IncludeCollection MinimalCorePregraph = new IncludeCollection { { kShaderVariables, IncludeLocation.Pregraph }, @@ -1343,15 +1342,6 @@ static class CoreKeywordDescriptors definition = KeywordDefinition.MultiCompile, scope = KeywordScope.Global, }; - - public static KeywordDescriptor SkinningDefine = new KeywordDescriptor() - { - displayName = "Dots Skinning", - referenceName = "DOTS_SKINNING", - type = KeywordType.Boolean, - definition = KeywordDefinition.MultiCompile, - scope = KeywordScope.Global, - }; } #endregion } From 19846d90e4ccda6575c186fec92bc22ea5cec557 Mon Sep 17 00:00:00 2001 From: hedvig Date: Wed, 27 Jan 2021 11:08:16 +0100 Subject: [PATCH 13/34] Remove compute mesh index property when dots instancing is not defined --- .../Runtime/ShaderLibrary/ShaderVariables.hlsl | 3 --- 1 file changed, 3 deletions(-) diff --git a/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl b/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl index 5394c885599..a6c6f716633 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl +++ b/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl @@ -97,8 +97,6 @@ CBUFFER_START(UnityPerDraw) //W : Camera only float4 unity_MotionVectorsParams; - float4 unity_ComputeMeshIndex; - CBUFFER_END CBUFFER_START(UnityPerDrawRare) @@ -376,7 +374,6 @@ UNITY_DOTS_INSTANCING_START(BuiltinPropertyMetadata) UNITY_DOTS_INSTANCED_PROP(float3x4, unity_MatrixPreviousMI) UNITY_DOTS_INSTANCED_PROP(float4, unity_MotionVectorsParams) UNITY_DOTS_INSTANCED_PROP(float4, unity_ComputeMeshIndex) - UNITY_DOTS_INSTANCING_END(BuiltinPropertyMetadata) // Note: Macros for unity_ObjectToWorld and unity_WorldToObject are declared elsewhere From 8ee28d12c374fc8e3641fc53384d3731861fbd9f Mon Sep 17 00:00:00 2001 From: hedvig Date: Wed, 27 Jan 2021 11:14:52 +0100 Subject: [PATCH 14/34] Shader cleanup for dots deformations --- .../MotionVectorVertexShaderCommon.hlsl | 6 ++-- .../RenderPipeline/ShaderPass/Skinning.hlsl | 33 +++++++++++-------- .../RenderPipeline/ShaderPass/VertMesh.hlsl | 9 ++--- 3 files changed, 28 insertions(+), 20 deletions(-) diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/MotionVectorVertexShaderCommon.hlsl b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/MotionVectorVertexShaderCommon.hlsl index 9006b8fc5a2..51755f2a62d 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/MotionVectorVertexShaderCommon.hlsl +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/MotionVectorVertexShaderCommon.hlsl @@ -108,9 +108,9 @@ PackedVaryingsType MotionVectorVS(inout VaryingsType varyingsType, AttributesMes bool hasDeformation = unity_MotionVectorsParams.x > 0.0; // Skin or morph target float3 deformedPrevPos = inputPass.previousPositionOS; -#if defined(DOTS_SKINNING) - //Skin even if force no motion? - DOTS_Deformation_MotionVecPass(inputMesh.positionOS, deformedPrevPos, inputMesh.vertexID); + +#if defined(DOTS_INSTANCING_ON) + DOTS_Deformation_MotionVecPass(inputMesh.positionOS, deformedPrevPos, inputMesh.vertexID); #endif float3 effectivePositionOS = (hasDeformation) ? deformedPrevPos : inputMesh.positionOS; diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/Skinning.hlsl b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/Skinning.hlsl index bfc45d07f65..41a110c780f 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/Skinning.hlsl +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/Skinning.hlsl @@ -1,11 +1,7 @@ #ifndef SKINNING_INCLUDED #define SKINNING_INCLUDED -//TODO: defines around nrm and tan? -//LBS Node not supported (skinning in vertex shader) - -#if defined(DOTS_SKINNING) - +#if defined(DOTS_INSTANCING_ON) struct DeformedVertexData { float3 Position; @@ -16,33 +12,43 @@ struct DeformedVertexData uniform StructuredBuffer _DeformedMeshData; uniform StructuredBuffer _PreviousFrameDeformedMeshData; -void DOTS_Deformation(inout float3 position, inout float3 normal, inout float4 tangent, uint vertexID) +void DOTS_Deformation(inout AttributesMesh input) { // x = curr frame index // y = prev frame index // z = deformation check (0 = no deformation, 1 = has deformation) + // w = skinned motion vectors const int4 deformProperty = asint(unity_ComputeMeshIndex); const int doSkinning = deformProperty.z; if (doSkinning == 1) { - const int streamIndex = _HybridDeformedVertexStreamIndex; - const int startIndex = deformProperty[streamIndex]; - const DeformedVertexData vertexData = _DeformedMeshData[startIndex + vertexID]; + const int streamIndex = _HybridDeformedVertexStreamIndex; + const int startIndex = deformProperty[streamIndex]; + const DeformedVertexData vertexData = _DeformedMeshData[startIndex + input.vertexID]; //if vertexid defined - position = vertexData.Position; - normal = vertexData.Normal; - tangent = float4(vertexData.Tangent, 0); + input.positionOS = vertexData.Position; +#ifdef ATTRIBUTES_NEED_NORMAL + input.normalOS = vertexData.Normal; +#endif +#ifdef ATTRIBUTES_NEED_TANGENT + input.tangentOS = float4(vertexData.Tangent, 0); +#endif } } +#endif + +//LBS Node not supported (skinning in vertex shader) +#if defined(DOTS_INSTANCING_ON) // position only for motion vec vs void DOTS_Deformation_MotionVecPass(inout float3 currPos, inout float3 prevPos, uint vertexID) { // x = curr frame index // y = prev frame index // z = deformation check (0 = no deformation, 1 = has deformation) + // w = skinned motion vectors const int4 deformProperty = asint(unity_ComputeMeshIndex); - const int doSkinning = deformProperty.z; + const int doSkinning = deformProperty.w; if (doSkinning == 1) { const int currStreamIndex = _HybridDeformedVertexStreamIndex; @@ -57,4 +63,5 @@ void DOTS_Deformation_MotionVecPass(inout float3 currPos, inout float3 prevPos, } #endif + #endif diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/VertMesh.hlsl b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/VertMesh.hlsl index b2c470359bb..d7dd8b99811 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/VertMesh.hlsl +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/VertMesh.hlsl @@ -126,19 +126,20 @@ VaryingsToDS InterpolateWithBaryCoordsToDS(VaryingsToDS input0, VaryingsToDS inp #define PackVaryingsType PackVaryingsToPS #endif +#include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/Skinning.hlsl" + // TODO: Here we will also have all the vertex deformation (GPU skinning, vertex animation, morph target...) or we will need to generate a compute shaders instead (better! but require work to deal with unpacking like fp16) // Make it inout so that MotionVectorPass can get the modified input values later. VaryingsMeshType VertMesh(AttributesMesh input, float3 worldSpaceOffset) { VaryingsMeshType output; -#if defined(DOTS_SKINNING) - DOTS_Deformation(input.positionOS, input.normalOS, input.tangentOS, input.vertexID); -#endif - UNITY_SETUP_INSTANCE_ID(input); UNITY_TRANSFER_INSTANCE_ID(input, output); +#if defined(DOTS_INSTANCING_ON) + DOTS_Deformation(input); +#endif #if defined(HAVE_MESH_MODIFICATION) input = ApplyMeshModification(input, _TimeParameters.xyz); From 0145e4b4b4d45710ce308257cc1303999c6ed04f Mon Sep 17 00:00:00 2001 From: hedvig Date: Wed, 27 Jan 2021 14:54:41 +0100 Subject: [PATCH 15/34] Rename shader file for dots skinning functions --- .../ShaderPass/{Skinning.hlsl => DotsDeformation.hlsl} | 0 .../{Skinning.hlsl.meta => DotsDeformation.hlsl.meta} | 0 .../Runtime/RenderPipeline/ShaderPass/VertMesh.hlsl | 2 +- 3 files changed, 1 insertion(+), 1 deletion(-) rename com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/{Skinning.hlsl => DotsDeformation.hlsl} (100%) rename com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/{Skinning.hlsl.meta => DotsDeformation.hlsl.meta} (100%) diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/Skinning.hlsl b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/DotsDeformation.hlsl similarity index 100% rename from com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/Skinning.hlsl rename to com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/DotsDeformation.hlsl diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/Skinning.hlsl.meta b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/DotsDeformation.hlsl.meta similarity index 100% rename from com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/Skinning.hlsl.meta rename to com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/DotsDeformation.hlsl.meta diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/VertMesh.hlsl b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/VertMesh.hlsl index d7dd8b99811..94b7a4aed90 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/VertMesh.hlsl +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/VertMesh.hlsl @@ -126,7 +126,7 @@ VaryingsToDS InterpolateWithBaryCoordsToDS(VaryingsToDS input0, VaryingsToDS inp #define PackVaryingsType PackVaryingsToPS #endif -#include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/Skinning.hlsl" +#include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/DotsDeformation.hlsl" // TODO: Here we will also have all the vertex deformation (GPU skinning, vertex animation, morph target...) or we will need to generate a compute shaders instead (better! but require work to deal with unpacking like fp16) // Make it inout so that MotionVectorPass can get the modified input values later. From cf88c73ad4415eb0fd5f48ae04cefde151aa2107 Mon Sep 17 00:00:00 2001 From: hedvig Date: Wed, 27 Jan 2021 14:56:47 +0100 Subject: [PATCH 16/34] Remove changes from HDShaderPasses --- .../Material/ShaderGraph/HDShaderPasses.cs | 232 +++++------------- 1 file changed, 65 insertions(+), 167 deletions(-) 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 347b980133b..1dd4311fb72 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 @@ -6,7 +6,6 @@ using UnityEditor.ShaderGraph; using UnityEditor.ShaderGraph.Internal; - namespace UnityEditor.Rendering.HighDefinition.ShaderGraph { static class HDShaderPasses @@ -90,20 +89,10 @@ public static PassDescriptor GenerateScenePicking() // Collections renderStates = CoreRenderStates.ScenePicking, pragmas = CorePragmas.DotsInstancedInV1AndV2EditorSync, - defines = GenerateDefines(), + defines = CoreDefines.ScenePicking, includes = GenerateIncludes(), }; - - - DefineCollection GenerateDefines() - { - return new DefineCollection - { - CoreDefines.ScenePicking, - }; - } - IncludeCollection GenerateIncludes() { var includes = new IncludeCollection(); @@ -119,9 +108,9 @@ IncludeCollection GenerateIncludes() } } -#endregion + #endregion -#region Scene Selection Pass + #region Scene Selection Pass public static PassDescriptor GenerateSceneSelection(bool supportLighting) { @@ -136,20 +125,10 @@ public static PassDescriptor GenerateSceneSelection(bool supportLighting) // Collections renderStates = CoreRenderStates.SceneSelection, pragmas = CorePragmas.DotsInstancedInV1AndV2EditorSync, - defines = GenerateDefines(), + defines = CoreDefines.SceneSelection, includes = GenerateIncludes(), }; - - - DefineCollection GenerateDefines() - { - return new DefineCollection - { - CoreDefines.SceneSelection, - }; - } - IncludeCollection GenerateIncludes() { var includes = new IncludeCollection(); @@ -171,9 +150,9 @@ IncludeCollection GenerateIncludes() } } -#endregion + #endregion -#region Shadow Caster Pass + #region Shadow Caster Pass static public PassDescriptor GenerateShadowCaster(bool supportLighting) { @@ -200,7 +179,6 @@ static public PassDescriptor GenerateShadowCaster(bool supportLighting) includes = GenerateIncludes(), }; - IncludeCollection GenerateIncludes() { var includes = new IncludeCollection(); @@ -222,9 +200,9 @@ IncludeCollection GenerateIncludes() } } -#endregion + #endregion -#region META pass + #region META pass public static PassDescriptor GenerateMETA(bool supportLighting) { @@ -240,19 +218,12 @@ public static PassDescriptor GenerateMETA(bool supportLighting) validVertexBlocks = new BlockFieldDescriptor[0], // Collections + requiredFields = CoreRequiredFields.Meta, renderStates = CoreRenderStates.Meta, pragmas = CorePragmas.DotsInstancedInV1AndV2, - defines = GenerateDefines(), + defines = CoreDefines.ShaderGraphRaytracingDefault, includes = GenerateIncludes(), - requiredFields = CoreRequiredFields.Meta, }; - DefineCollection GenerateDefines() - { - return new DefineCollection - { - CoreDefines.ShaderGraphRaytracingDefault, - }; - } IncludeCollection GenerateIncludes() { @@ -275,9 +246,9 @@ IncludeCollection GenerateIncludes() } } -#endregion + #endregion -#region Depth Forward Only + #region Depth Forward Only public static PassDescriptor GenerateDepthForwardOnlyPass(bool supportLighting) { @@ -293,34 +264,13 @@ public static PassDescriptor GenerateDepthForwardOnlyPass(bool supportLighting) requiredFields = GenerateRequiredFields(), renderStates = GenerateRenderState(), pragmas = CorePragmas.DotsInstancedInV2Only, - defines = GenerateDefines(), + defines = supportLighting ? CoreDefines.DepthForwardOnly : CoreDefines.DepthForwardOnlyUnlit, includes = GenerateIncludes(), }; - DefineCollection GenerateDefines() - { - return new DefineCollection - { - supportLighting ? CoreDefines.DepthForwardOnly : CoreDefines.DepthForwardOnlyUnlit, - }; - - } - RenderStateCollection GenerateRenderState() { var renderState = new RenderStateCollection { CoreRenderStates.DepthOnly }; - - if (!supportLighting) - { - // Caution: When using MSAA we have normal and depth buffer bind. - // Unlit objects need to NOT write in normal buffer (or write 0) - Disable color mask for this RT - // Note: ShaderLab doesn't allow to have a variable on the second parameter of ColorMask - // - When MSAA: disable target 1 (normal buffer) - // - When no MSAA: disable target 0 (normal buffer) and 1 (unused) - renderState.Add(RenderState.ColorMask("ColorMask [_ColorMaskNormal]")); - renderState.Add(RenderState.ColorMask("ColorMask 0 1")); - } - return renderState; } @@ -362,9 +312,9 @@ IncludeCollection GenerateIncludes() } } -#endregion + #endregion -#region Motion Vectors + #region Motion Vectors public static PassDescriptor GenerateMotionVectors(bool supportLighting, bool supportForward) { @@ -377,11 +327,11 @@ public static PassDescriptor GenerateMotionVectors(bool supportLighting, bool su useInPreview = false, // Collections + requiredFields = CoreRequiredFields.LitFull, renderStates = GenerateRenderState(), defines = GenerateDefines(), pragmas = CorePragmas.DotsInstancedInV2Only, includes = GenerateIncludes(), - requiredFields = CoreRequiredFields.LitFull, }; DefineCollection GenerateDefines() @@ -398,7 +348,8 @@ DefineCollection GenerateDefines() // if (supportForward) // { // defines.Add(CoreKeywordDescriptors.WriteNormalBuffer, 1); - // } + // } + return defines; } @@ -406,18 +357,6 @@ RenderStateCollection GenerateRenderState() { var renderState = new RenderStateCollection(); renderState.Add(CoreRenderStates.MotionVectors); - - if (!supportLighting) - { - // Caution: When using MSAA we have motion vector, normal and depth buffer bind. - // Unlit objects need to NOT write in normal buffer (or write 0) - Disable color mask for this RT - // Note: ShaderLab doesn't allow to have a variable on the second parameter of ColorMask - // - When MSAA: disable target 2 (normal buffer) - // - When no MSAA: disable target 1 (normal buffer) and 2 (unused) - renderState.Add(RenderState.ColorMask("ColorMask [_ColorMaskNormal] 1")); - renderState.Add(RenderState.ColorMask("ColorMask 0 2")); - } - return renderState; } @@ -426,7 +365,6 @@ IncludeCollection GenerateIncludes() var includes = new IncludeCollection(); includes.Add(CoreIncludes.CorePregraph); - if (supportLighting) includes.Add(CoreIncludes.kNormalSurfaceGradient, IncludeLocation.Pregraph); includes.Add(CoreIncludes.kPassPlaceholder, IncludeLocation.Pregraph); @@ -444,9 +382,9 @@ IncludeCollection GenerateIncludes() } -#endregion + #endregion -#region Forward Only + #region Forward Only public static PassDescriptor GenerateForwardOnlyPass(bool supportLighting) { @@ -508,14 +446,13 @@ IncludeCollection GenerateIncludes() else includes.Add(CoreIncludes.kPassForwardUnlit, IncludeLocation.Postgraph); - return includes; } } -#endregion + #endregion -#region Back then front pass + #region Back then front pass public static PassDescriptor GenerateBackThenFront(bool supportLighting) { @@ -565,9 +502,9 @@ IncludeCollection GenerateIncludes() } } -#endregion + #endregion -#region Transparent Depth Prepass + #region Transparent Depth Prepass public static PassDescriptor GenerateTransparentDepthPrepass(bool supportLighting) { @@ -602,21 +539,13 @@ public static PassDescriptor GenerateTransparentDepthPrepass(bool supportLightin }, // Collections + requiredFields = TransparentDepthPrepassFields, renderStates = GenerateRenderState(), pragmas = CorePragmas.DotsInstancedInV1AndV2, - defines = GenerateDefines(), + defines = CoreDefines.TransparentDepthPrepass, includes = GenerateIncludes(), - requiredFields = TransparentDepthPrepassFields, }; - DefineCollection GenerateDefines() - { - return new DefineCollection - { - CoreDefines.TransparentDepthPrepass, - }; - } - RenderStateCollection GenerateRenderState() { var renderState = new RenderStateCollection @@ -674,9 +603,9 @@ IncludeCollection GenerateIncludes() HDStructFields.FragInputs.color, }; -#endregion + #endregion -#region Transparent Depth Postpass + #region Transparent Depth Postpass public static PassDescriptor GenerateTransparentDepthPostpass(bool supportLighting) { @@ -737,9 +666,9 @@ RenderStateCollection GenerateRenderState() } } -#endregion + #endregion -#region Lit DepthOnly + #region Lit DepthOnly public static PassDescriptor GenerateLitDepthOnly() { @@ -754,17 +683,12 @@ public static PassDescriptor GenerateLitDepthOnly() requiredFields = CoreRequiredFields.LitFull, renderStates = CoreRenderStates.DepthOnly, pragmas = CorePragmas.DotsInstancedInV1AndV2, - defines = DepthOnlyDefines, + defines = CoreDefines.ShaderGraphRaytracingDefault, keywords = LitDepthOnlyKeywords, includes = DepthOnlyIncludes, }; } - public static DefineCollection DepthOnlyDefines = new DefineCollection - { - CoreDefines.ShaderGraphRaytracingDefault, - }; - public static IncludeCollection DepthOnlyIncludes = new IncludeCollection { { CoreIncludes.CorePregraph }, @@ -782,9 +706,9 @@ public static PassDescriptor GenerateLitDepthOnly() { CoreKeywordDescriptors.WriteNormalBuffer }, }; -#endregion + #endregion -#region GBuffer + #region GBuffer public static PassDescriptor GenerateGBuffer() { @@ -800,7 +724,7 @@ public static PassDescriptor GenerateGBuffer() requiredFields = CoreRequiredFields.LitMinimal, renderStates = GBufferRenderState, pragmas = CorePragmas.DotsInstancedInV1AndV2, - defines = GBufferDefines, + defines = CoreDefines.ShaderGraphRaytracingDefault, keywords = GBufferKeywords, includes = GBufferIncludes, @@ -808,12 +732,6 @@ public static PassDescriptor GenerateGBuffer() }; } - public static DefineCollection GBufferDefines = new DefineCollection - { - CoreDefines.ShaderGraphRaytracingDefault, - }; - - public static KeywordCollection GBufferKeywords = new KeywordCollection { { CoreKeywordDescriptors.LightLayers }, @@ -844,9 +762,9 @@ public static PassDescriptor GenerateGBuffer() }) }, }; -#endregion + #endregion -#region Lit Forward + #region Lit Forward public static PassDescriptor GenerateLitForward() { @@ -869,11 +787,6 @@ public static PassDescriptor GenerateLitForward() }; } - public static DefineCollection ForwardDefines = new DefineCollection - { - CoreDefines.Forward, - }; - public static IncludeCollection ForwardIncludes = new IncludeCollection { { CoreIncludes.CorePregraph }, @@ -889,9 +802,9 @@ public static PassDescriptor GenerateLitForward() { CoreIncludes.kPassForward, IncludeLocation.Postgraph }, }; -#endregion + #endregion -#region Lit Raytracing Prepass + #region Lit Raytracing Prepass public static PassDescriptor GenerateLitRaytracingPrepass() { @@ -906,16 +819,10 @@ public static PassDescriptor GenerateLitRaytracingPrepass() // Collections renderStates = RayTracingPrepassRenderState, pragmas = CorePragmas.Basic, - defines = LitRayTracingPrepassDefines, + defines = CoreDefines.ShaderGraphRaytracingDefault, includes = RayTracingPrepassIncludes, }; } - - - public static DefineCollection LitRayTracingPrepassDefines = new DefineCollection - { - CoreDefines.ShaderGraphRaytracingDefault, - }; public static IncludeCollection RayTracingPrepassIncludes = new IncludeCollection { @@ -937,9 +844,9 @@ public static PassDescriptor GenerateLitRaytracingPrepass() // Note: we use default ZTest LEqual so if the object have already been render in depth prepass, it will re-render to tag stencil }; -#endregion + #endregion -#region Raytracing Indirect + #region Raytracing Indirect public static KeywordCollection IndirectDiffuseKeywordCollection = new KeywordCollection { @@ -958,21 +865,11 @@ public static PassDescriptor GenerateRaytracingIndirect(bool supportLighting) // Collections pragmas = CorePragmas.RaytracingBasic, + defines = supportLighting ? RaytracingIndirectDefines : null, keywords = supportLighting ? IndirectDiffuseKeywordCollection : null, - defines = GenerateDefines(), includes = GenerateIncludes(), }; - - - DefineCollection GenerateDefines() - { - return new DefineCollection - { - supportLighting ? RaytracingIndirectDefines : null, - }; - } - IncludeCollection GenerateIncludes() { var includes = new IncludeCollection { CoreIncludes.RaytracingCorePregraph }; @@ -996,6 +893,7 @@ IncludeCollection GenerateIncludes() includes.Add(CoreIncludes.CoreUtility); includes.Add(CoreIncludes.kRaytracingCommon, IncludeLocation.Pregraph); includes.Add(CoreIncludes.kShaderGraphFunctions, IncludeLocation.Pregraph); + // post graph includes includes.Add(CoreIncludes.kPassRaytracingIndirect, IncludeLocation.Postgraph); @@ -1010,9 +908,9 @@ IncludeCollection GenerateIncludes() { CoreKeywordDescriptors.HasLightloop, 1 }, }; -#endregion + #endregion -#region Raytracing Visibility + #region Raytracing Visibility public static PassDescriptor GenerateRaytracingVisibility(bool supportLighting) { @@ -1063,9 +961,9 @@ IncludeCollection GenerateIncludes() { Defines.raytracingRaytraced }, }; -#endregion + #endregion -#region Raytracing Forward + #region Raytracing Forward public static PassDescriptor GenerateRaytracingForward(bool supportLighting) { @@ -1129,9 +1027,9 @@ IncludeCollection GenerateIncludes() { CoreKeywordDescriptors.HasLightloop, 1 }, }; -#endregion + #endregion -#region Raytracing GBuffer + #region Raytracing GBuffer public static PassDescriptor GenerateRaytracingGBuffer(bool supportLighting) { @@ -1166,7 +1064,7 @@ IncludeCollection GenerateIncludes() // We want to have the normal buffer include if this is a gbuffer and unlit shader if (!supportLighting) includes.Add(CoreIncludes.kNormalBuffer, IncludeLocation.Pregraph); - + // If this is the gbuffer sub-shader, we want the standard lit data includes.Add(CoreIncludes.kStandardLit, IncludeLocation.Pregraph); @@ -1190,9 +1088,9 @@ IncludeCollection GenerateIncludes() { Defines.raytracingRaytraced }, }; -#endregion + #endregion -#region Path Tracing + #region Path Tracing public static PassDescriptor GeneratePathTracing(bool supportLighting) { @@ -1251,9 +1149,9 @@ IncludeCollection GenerateIncludes() { CoreKeywordDescriptors.HasLightloop, 1 }, }; -#endregion + #endregion -#region Raytracing Subsurface + #region Raytracing Subsurface public static PassDescriptor GenerateRaytracingSubsurface() { @@ -1308,9 +1206,9 @@ IncludeCollection GenerateIncludes() { Defines.raytracingRaytraced }, }; -#endregion + #endregion -#region FullScreen Debug + #region FullScreen Debug public static PassDescriptor GenerateFullScreenDebug() { @@ -1327,7 +1225,7 @@ public static PassDescriptor GenerateFullScreenDebug() renderStates = FullScreenDebugRenderState, includes = GenerateIncludes(), }; - + IncludeCollection GenerateIncludes() { return new IncludeCollection @@ -1349,23 +1247,23 @@ IncludeCollection GenerateIncludes() { RenderState.ZTest(ZTest.LEqual) }, }; -#endregion + #endregion -#region Define Utility + #region Define Utility public static class Defines { // Shadows - public static DefineCollection shadowLow = new DefineCollection { {CoreKeywordDescriptors.Shadow, 0} }; - public static DefineCollection shadowMedium = new DefineCollection { {CoreKeywordDescriptors.Shadow, 1} }; - public static DefineCollection shadowHigh = new DefineCollection { {CoreKeywordDescriptors.Shadow, 2} }; + public static DefineCollection shadowLow = new DefineCollection { { CoreKeywordDescriptors.Shadow, 0 } }; + public static DefineCollection shadowMedium = new DefineCollection { { CoreKeywordDescriptors.Shadow, 1 } }; + public static DefineCollection shadowHigh = new DefineCollection { { CoreKeywordDescriptors.Shadow, 2 } }; // Raytracing Quality - public static DefineCollection raytracingDefault = new DefineCollection { { RayTracingQualityNode.GetRayTracingQualityKeyword(), 0} }; - public static DefineCollection raytracingRaytraced = new DefineCollection { { RayTracingQualityNode.GetRayTracingQualityKeyword(), 1} }; + public static DefineCollection raytracingDefault = new DefineCollection { { RayTracingQualityNode.GetRayTracingQualityKeyword(), 0 } }; + public static DefineCollection raytracingRaytraced = new DefineCollection { { RayTracingQualityNode.GetRayTracingQualityKeyword(), 1 } }; } -#endregion + #endregion } } From ce95d4cfdfd3ad92fc8bbba3cd01c21b452e2b7e Mon Sep 17 00:00:00 2001 From: hedvig Date: Wed, 27 Jan 2021 15:05:34 +0100 Subject: [PATCH 17/34] Remove formatting issues --- .../Material/ShaderGraph/HDShaderPasses.cs | 92 +++++++++---------- 1 file changed, 46 insertions(+), 46 deletions(-) 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 1dd4311fb72..723688bff6b 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 @@ -10,7 +10,7 @@ namespace UnityEditor.Rendering.HighDefinition.ShaderGraph { static class HDShaderPasses { - #region Distortion Pass +#region Distortion Pass public static PassDescriptor GenerateDistortionPass(bool supportLighting) { @@ -72,9 +72,9 @@ IncludeCollection GenerateIncludes() } - #endregion +#endregion - #region Scene Picking Pass +#region Scene Picking Pass public static PassDescriptor GenerateScenePicking() { @@ -108,9 +108,9 @@ IncludeCollection GenerateIncludes() } } - #endregion +#endregion - #region Scene Selection Pass +#region Scene Selection Pass public static PassDescriptor GenerateSceneSelection(bool supportLighting) { @@ -150,9 +150,9 @@ IncludeCollection GenerateIncludes() } } - #endregion +#endregion - #region Shadow Caster Pass +#region Shadow Caster Pass static public PassDescriptor GenerateShadowCaster(bool supportLighting) { @@ -200,9 +200,9 @@ IncludeCollection GenerateIncludes() } } - #endregion +#endregion - #region META pass +#region META pass public static PassDescriptor GenerateMETA(bool supportLighting) { @@ -246,9 +246,9 @@ IncludeCollection GenerateIncludes() } } - #endregion +#endregion - #region Depth Forward Only +#region Depth Forward Only public static PassDescriptor GenerateDepthForwardOnlyPass(bool supportLighting) { @@ -312,9 +312,9 @@ IncludeCollection GenerateIncludes() } } - #endregion +#endregion - #region Motion Vectors +#region Motion Vectors public static PassDescriptor GenerateMotionVectors(bool supportLighting, bool supportForward) { @@ -382,9 +382,9 @@ IncludeCollection GenerateIncludes() } - #endregion +#endregion - #region Forward Only +#region Forward Only public static PassDescriptor GenerateForwardOnlyPass(bool supportLighting) { @@ -450,9 +450,9 @@ IncludeCollection GenerateIncludes() } } - #endregion +#endregion - #region Back then front pass +#region Back then front pass public static PassDescriptor GenerateBackThenFront(bool supportLighting) { @@ -502,9 +502,9 @@ IncludeCollection GenerateIncludes() } } - #endregion +#endregion - #region Transparent Depth Prepass +#region Transparent Depth Prepass public static PassDescriptor GenerateTransparentDepthPrepass(bool supportLighting) { @@ -603,9 +603,9 @@ IncludeCollection GenerateIncludes() HDStructFields.FragInputs.color, }; - #endregion +#endregion - #region Transparent Depth Postpass +#region Transparent Depth Postpass public static PassDescriptor GenerateTransparentDepthPostpass(bool supportLighting) { @@ -666,9 +666,9 @@ RenderStateCollection GenerateRenderState() } } - #endregion +#endregion - #region Lit DepthOnly +#region Lit DepthOnly public static PassDescriptor GenerateLitDepthOnly() { @@ -706,9 +706,9 @@ public static PassDescriptor GenerateLitDepthOnly() { CoreKeywordDescriptors.WriteNormalBuffer }, }; - #endregion +#endregion - #region GBuffer +#region GBuffer public static PassDescriptor GenerateGBuffer() { @@ -762,9 +762,9 @@ public static PassDescriptor GenerateGBuffer() }) }, }; - #endregion +#endregion - #region Lit Forward +#region Lit Forward public static PassDescriptor GenerateLitForward() { @@ -802,9 +802,9 @@ public static PassDescriptor GenerateLitForward() { CoreIncludes.kPassForward, IncludeLocation.Postgraph }, }; - #endregion +#endregion - #region Lit Raytracing Prepass +#region Lit Raytracing Prepass public static PassDescriptor GenerateLitRaytracingPrepass() { @@ -844,9 +844,9 @@ public static PassDescriptor GenerateLitRaytracingPrepass() // Note: we use default ZTest LEqual so if the object have already been render in depth prepass, it will re-render to tag stencil }; - #endregion +#endregion - #region Raytracing Indirect +#region Raytracing Indirect public static KeywordCollection IndirectDiffuseKeywordCollection = new KeywordCollection { @@ -908,9 +908,9 @@ IncludeCollection GenerateIncludes() { CoreKeywordDescriptors.HasLightloop, 1 }, }; - #endregion +#endregion - #region Raytracing Visibility +#region Raytracing Visibility public static PassDescriptor GenerateRaytracingVisibility(bool supportLighting) { @@ -961,9 +961,9 @@ IncludeCollection GenerateIncludes() { Defines.raytracingRaytraced }, }; - #endregion +#endregion - #region Raytracing Forward +#region Raytracing Forward public static PassDescriptor GenerateRaytracingForward(bool supportLighting) { @@ -1027,9 +1027,9 @@ IncludeCollection GenerateIncludes() { CoreKeywordDescriptors.HasLightloop, 1 }, }; - #endregion +#endregion - #region Raytracing GBuffer +#region Raytracing GBuffer public static PassDescriptor GenerateRaytracingGBuffer(bool supportLighting) { @@ -1088,9 +1088,9 @@ IncludeCollection GenerateIncludes() { Defines.raytracingRaytraced }, }; - #endregion +#endregion - #region Path Tracing +#region Path Tracing public static PassDescriptor GeneratePathTracing(bool supportLighting) { @@ -1149,9 +1149,9 @@ IncludeCollection GenerateIncludes() { CoreKeywordDescriptors.HasLightloop, 1 }, }; - #endregion +#endregion - #region Raytracing Subsurface +#region Raytracing Subsurface public static PassDescriptor GenerateRaytracingSubsurface() { @@ -1206,9 +1206,9 @@ IncludeCollection GenerateIncludes() { Defines.raytracingRaytraced }, }; - #endregion +#endregion - #region FullScreen Debug +#region FullScreen Debug public static PassDescriptor GenerateFullScreenDebug() { @@ -1247,9 +1247,9 @@ IncludeCollection GenerateIncludes() { RenderState.ZTest(ZTest.LEqual) }, }; - #endregion +#endregion - #region Define Utility +#region Define Utility public static class Defines { @@ -1263,7 +1263,7 @@ public static class Defines public static DefineCollection raytracingRaytraced = new DefineCollection { { RayTracingQualityNode.GetRayTracingQualityKeyword(), 1 } }; } - #endregion +#endregion } } From fe9468eaa6064b01765bed068ad01ffb6427be82 Mon Sep 17 00:00:00 2001 From: hedvig Date: Wed, 27 Jan 2021 16:22:12 +0100 Subject: [PATCH 18/34] Remove include define --- .../Runtime/RenderPipeline/ShaderPass/DotsDeformation.hlsl | 6 ------ 1 file changed, 6 deletions(-) diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/DotsDeformation.hlsl b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/DotsDeformation.hlsl index 41a110c780f..a984a7cf94d 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/DotsDeformation.hlsl +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/DotsDeformation.hlsl @@ -1,6 +1,3 @@ -#ifndef SKINNING_INCLUDED -#define SKINNING_INCLUDED - #if defined(DOTS_INSTANCING_ON) struct DeformedVertexData { @@ -62,6 +59,3 @@ void DOTS_Deformation_MotionVecPass(inout float3 currPos, inout float3 prevPos, } } #endif - - -#endif From 34db42ae533772d2e64cd5d47dc90a82c801ac8d Mon Sep 17 00:00:00 2001 From: hedvig Date: Wed, 27 Jan 2021 16:32:50 +0100 Subject: [PATCH 19/34] Remove all changes from HDShaderPasses --- .../Material/ShaderGraph/HDShaderPasses.cs | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) 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 723688bff6b..bbba4254347 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 @@ -164,7 +164,7 @@ static public PassDescriptor GenerateShadowCaster(bool supportLighting) lightMode = "ShadowCaster", useInPreview = false, - validPixelBlocks = new BlockFieldDescriptor[] + validPixelBlocks = new BlockFieldDescriptor[] { BlockFields.SurfaceDescription.Alpha, BlockFields.SurfaceDescription.AlphaClipThreshold, @@ -349,7 +349,7 @@ DefineCollection GenerateDefines() // { // defines.Add(CoreKeywordDescriptors.WriteNormalBuffer, 1); // } - + return defines; } @@ -389,7 +389,7 @@ IncludeCollection GenerateIncludes() public static PassDescriptor GenerateForwardOnlyPass(bool supportLighting) { return new PassDescriptor - { + { // Definition displayName = "ForwardOnly", referenceName = supportLighting ? "SHADERPASS_FORWARD" : "SHADERPASS_FORWARD_UNLIT", @@ -445,7 +445,7 @@ IncludeCollection GenerateIncludes() includes.Add(CoreIncludes.kPassForward, IncludeLocation.Postgraph); else includes.Add(CoreIncludes.kPassForwardUnlit, IncludeLocation.Postgraph); - + return includes; } } @@ -457,7 +457,7 @@ IncludeCollection GenerateIncludes() public static PassDescriptor GenerateBackThenFront(bool supportLighting) { return new PassDescriptor - { + { // Definition displayName = "TransparentBackface", referenceName = supportLighting ? "SHADERPASS_FORWARD" : "SHADERPASS_FORWARD_UNLIT", @@ -1064,7 +1064,7 @@ IncludeCollection GenerateIncludes() // We want to have the normal buffer include if this is a gbuffer and unlit shader if (!supportLighting) includes.Add(CoreIncludes.kNormalBuffer, IncludeLocation.Pregraph); - + // If this is the gbuffer sub-shader, we want the standard lit data includes.Add(CoreIncludes.kStandardLit, IncludeLocation.Pregraph); @@ -1254,13 +1254,13 @@ IncludeCollection GenerateIncludes() public static class Defines { // Shadows - public static DefineCollection shadowLow = new DefineCollection { { CoreKeywordDescriptors.Shadow, 0 } }; - public static DefineCollection shadowMedium = new DefineCollection { { CoreKeywordDescriptors.Shadow, 1 } }; - public static DefineCollection shadowHigh = new DefineCollection { { CoreKeywordDescriptors.Shadow, 2 } }; + public static DefineCollection shadowLow = new DefineCollection { {CoreKeywordDescriptors.Shadow, 0} }; + public static DefineCollection shadowMedium = new DefineCollection { {CoreKeywordDescriptors.Shadow, 1} }; + public static DefineCollection shadowHigh = new DefineCollection { {CoreKeywordDescriptors.Shadow, 2} }; // Raytracing Quality - public static DefineCollection raytracingDefault = new DefineCollection { { RayTracingQualityNode.GetRayTracingQualityKeyword(), 0 } }; - public static DefineCollection raytracingRaytraced = new DefineCollection { { RayTracingQualityNode.GetRayTracingQualityKeyword(), 1 } }; + public static DefineCollection raytracingDefault = new DefineCollection { { RayTracingQualityNode.GetRayTracingQualityKeyword(), 0} }; + public static DefineCollection raytracingRaytraced = new DefineCollection { { RayTracingQualityNode.GetRayTracingQualityKeyword(), 1} }; } #endregion From 2b8ea7d9c4b177c0edafe20416dc3cf4f64b3b37 Mon Sep 17 00:00:00 2001 From: hedvig Date: Wed, 27 Jan 2021 16:45:53 +0100 Subject: [PATCH 20/34] Remove debug pragma --- .../Editor/Material/ShaderGraph/HDTarget.cs | 1 - .../Editor/Generation/Descriptors/PragmaDescriptor.cs | 1 - 2 files changed, 2 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 aa092fe761f..1ad954226c3 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 @@ -692,7 +692,6 @@ static class CorePragmas { Pragma.Vertex("Vert") }, { Pragma.Fragment("Frag") }, { Pragma.OnlyRenderers(PragmaRenderers.GetHighEndPlatformArray()) }, - { Pragma.DX11Debug }, }; public static PragmaCollection InstancedRenderingLayer = new PragmaCollection diff --git a/com.unity.shadergraph/Editor/Generation/Descriptors/PragmaDescriptor.cs b/com.unity.shadergraph/Editor/Generation/Descriptors/PragmaDescriptor.cs index 6e098e835d7..0b784b2c025 100644 --- a/com.unity.shadergraph/Editor/Generation/Descriptors/PragmaDescriptor.cs +++ b/com.unity.shadergraph/Editor/Generation/Descriptors/PragmaDescriptor.cs @@ -32,6 +32,5 @@ static string GetPlatformList(Platform[] platforms) public static PragmaDescriptor DOTSInstancing => new PragmaDescriptor { value = "multi_compile _ DOTS_INSTANCING_ON" }; public static PragmaDescriptor MultiCompileFog => new PragmaDescriptor { value = "multi_compile_fog" }; public static PragmaDescriptor EditorSyncCompilation => new PragmaDescriptor { value = "editor_sync_compilation" }; - public static PragmaDescriptor DX11Debug => new PragmaDescriptor { value = "enable_d3d11_debug_symbols" }; } } From ee68b60347b364135941ea9c19aeb0ed692200ca Mon Sep 17 00:00:00 2001 From: hedvig Date: Wed, 27 Jan 2021 16:53:49 +0100 Subject: [PATCH 21/34] Update some comments Also skin vertices even if motion vectors are not skinned --- .../ShaderPass/DotsDeformation.hlsl | 25 +++++++++---------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/DotsDeformation.hlsl b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/DotsDeformation.hlsl index a984a7cf94d..b4fb3a3b549 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/DotsDeformation.hlsl +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/DotsDeformation.hlsl @@ -11,8 +11,7 @@ uniform StructuredBuffer _PreviousFrameDeformedMeshData; void DOTS_Deformation(inout AttributesMesh input) { - // x = curr frame index - // y = prev frame index + // x,y = current and previous frame indices // z = deformation check (0 = no deformation, 1 = has deformation) // w = skinned motion vectors const int4 deformProperty = asint(unity_ComputeMeshIndex); @@ -21,7 +20,7 @@ void DOTS_Deformation(inout AttributesMesh input) { const int streamIndex = _HybridDeformedVertexStreamIndex; const int startIndex = deformProperty[streamIndex]; - const DeformedVertexData vertexData = _DeformedMeshData[startIndex + input.vertexID]; //if vertexid defined + const DeformedVertexData vertexData = _DeformedMeshData[startIndex + input.vertexID]; input.positionOS = vertexData.Position; #ifdef ATTRIBUTES_NEED_NORMAL @@ -34,27 +33,27 @@ void DOTS_Deformation(inout AttributesMesh input) } #endif -//LBS Node not supported (skinning in vertex shader) - #if defined(DOTS_INSTANCING_ON) // position only for motion vec vs void DOTS_Deformation_MotionVecPass(inout float3 currPos, inout float3 prevPos, uint vertexID) { - // x = curr frame index - // y = prev frame index + // x,y = current and previous frame indices // z = deformation check (0 = no deformation, 1 = has deformation) // w = skinned motion vectors const int4 deformProperty = asint(unity_ComputeMeshIndex); - const int doSkinning = deformProperty.w; - if (doSkinning == 1) + const int computeSkin = deformProperty.z; + if (computeSkin == 1) { const int currStreamIndex = _HybridDeformedVertexStreamIndex; - const int prevStreamIndex = (currStreamIndex + 1) % 2; - const int currMeshStart = deformProperty[currStreamIndex]; - const int prevMeshStart = deformProperty[prevStreamIndex]; - currPos = _DeformedMeshData[currMeshStart + vertexID].Position; + } + + const int skinMotionVec = deformProperty.w; + if (skinMotionVec == 1) + { + const int prevStreamIndex = (_HybridDeformedVertexStreamIndex + 1) % 2; + const int prevMeshStart = deformProperty[prevStreamIndex]; prevPos = _PreviousFrameDeformedMeshData[prevMeshStart + vertexID].Position; } } From 2825bd27254ea72e621c8c94ee2d20079b8b5832 Mon Sep 17 00:00:00 2001 From: hedvig Date: Wed, 27 Jan 2021 17:00:48 +0100 Subject: [PATCH 22/34] Remove duplicated define --- .../Runtime/RenderPipeline/ShaderPass/DotsDeformation.hlsl | 2 -- 1 file changed, 2 deletions(-) diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/DotsDeformation.hlsl b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/DotsDeformation.hlsl index b4fb3a3b549..6395db98ad9 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/DotsDeformation.hlsl +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/DotsDeformation.hlsl @@ -31,9 +31,7 @@ void DOTS_Deformation(inout AttributesMesh input) #endif } } -#endif -#if defined(DOTS_INSTANCING_ON) // position only for motion vec vs void DOTS_Deformation_MotionVecPass(inout float3 currPos, inout float3 prevPos, uint vertexID) { From 69e7eae8dd4192bbd20faca0b3ae3b7c2cc369db Mon Sep 17 00:00:00 2001 From: hedvig Date: Thu, 28 Jan 2021 15:49:21 +0100 Subject: [PATCH 23/34] Add compute mesh index to URP shader variables. Add function to fetch vertices from compute buffer in ShaderVariablesFunctions --- .../ShaderGraph/Includes/PBRForwardPass.hlsl | 4 ++ .../ShaderGraph/Includes/PBRGBufferPass.hlsl | 3 ++ .../Includes/ShadowCasterPass.hlsl | 3 ++ .../ShaderVariablesFunctions.hlsl | 53 +++++++++++++++++++ .../UniversalDOTSInstancing.hlsl | 4 +- 5 files changed, 66 insertions(+), 1 deletion(-) diff --git a/com.unity.render-pipelines.universal/Editor/ShaderGraph/Includes/PBRForwardPass.hlsl b/com.unity.render-pipelines.universal/Editor/ShaderGraph/Includes/PBRForwardPass.hlsl index a884b754e73..78c2d3b1954 100644 --- a/com.unity.render-pipelines.universal/Editor/ShaderGraph/Includes/PBRForwardPass.hlsl +++ b/com.unity.render-pipelines.universal/Editor/ShaderGraph/Includes/PBRForwardPass.hlsl @@ -34,9 +34,13 @@ void BuildInputData(Varyings input, SurfaceDescription surfaceDescription, out I inputData.shadowMask = SAMPLE_SHADOWMASK(input.lightmapUV); } + PackedVaryings vert(Attributes input) { Varyings output = (Varyings)0; +#if defined(DOTS_INSTANCING_ON) + ReadComputeData(input.positionOS, input.normalOS, input.tangentOS, input.vertexID); +#endif output = BuildVaryings(input); PackedVaryings packedOutput = (PackedVaryings)0; packedOutput = PackVaryings(output); diff --git a/com.unity.render-pipelines.universal/Editor/ShaderGraph/Includes/PBRGBufferPass.hlsl b/com.unity.render-pipelines.universal/Editor/ShaderGraph/Includes/PBRGBufferPass.hlsl index 67ccdd5dc5c..a62b7a404e0 100644 --- a/com.unity.render-pipelines.universal/Editor/ShaderGraph/Includes/PBRGBufferPass.hlsl +++ b/com.unity.render-pipelines.universal/Editor/ShaderGraph/Includes/PBRGBufferPass.hlsl @@ -35,6 +35,9 @@ void BuildInputData(Varyings input, SurfaceDescription surfaceDescription, out I PackedVaryings vert(Attributes input) { Varyings output = (Varyings)0; +#if defined(DOTS_INSTANCINT_ON) + ReadComputeData(input.positionOS, input.normalOS, input.tangentOS, input.vertexID); +#endif output = BuildVaryings(input); PackedVaryings packedOutput = (PackedVaryings)0; packedOutput = PackVaryings(output); diff --git a/com.unity.render-pipelines.universal/Editor/ShaderGraph/Includes/ShadowCasterPass.hlsl b/com.unity.render-pipelines.universal/Editor/ShaderGraph/Includes/ShadowCasterPass.hlsl index a8044650bdd..4403b20d6aa 100644 --- a/com.unity.render-pipelines.universal/Editor/ShaderGraph/Includes/ShadowCasterPass.hlsl +++ b/com.unity.render-pipelines.universal/Editor/ShaderGraph/Includes/ShadowCasterPass.hlsl @@ -4,6 +4,9 @@ PackedVaryings vert(Attributes input) { Varyings output = (Varyings)0; +#if defined(DOTS_INSTANCING_ON) + ReadComputeData(input.positionOS, input.normalOS, input.tangentOS, input.vertexID); +#endif output = BuildVaryings(input); PackedVaryings packedOutput = (PackedVaryings)0; packedOutput = PackVaryings(output); diff --git a/com.unity.render-pipelines.universal/ShaderLibrary/ShaderVariablesFunctions.hlsl b/com.unity.render-pipelines.universal/ShaderLibrary/ShaderVariablesFunctions.hlsl index 53214f7c89a..e67be101b05 100644 --- a/com.unity.render-pipelines.universal/ShaderLibrary/ShaderVariablesFunctions.hlsl +++ b/com.unity.render-pipelines.universal/ShaderLibrary/ShaderVariablesFunctions.hlsl @@ -279,4 +279,57 @@ float2 GetNormalizedScreenSpaceUV(float4 positionCS) #define UnityStereoTransformScreenSpaceTex(uv) uv #endif // defined(UNITY_SINGLE_PASS_STEREO) + +#if defined(DOTS_INSTANCING_ON) +struct DeformedVertexData +{ + float3 Position; + float3 Normal; + float3 Tangent; +}; + +int _HybridDeformedVertexStreamIndex; +uniform StructuredBuffer _DeformedMeshData; +uniform StructuredBuffer _PreviousFrameDeformedMeshData; + +void ReadComputeData(inout float3 position, inout float3 normal, inout float4 tangent, in uint vertexID) +{ + // x,y = current and previous frame indices + // z = deformation check (0 = no deformation, 1 = has deformation) + // w = skinned motion vectors + const int4 deformProperty = asint(unity_ComputeMeshIndex); + const int doSkinning = deformProperty.z; + if (doSkinning == 1) + { + const int streamIndex = _HybridDeformedVertexStreamIndex; + const int startIndex = deformProperty[streamIndex]; + const DeformedVertexData vertexData = _DeformedMeshData[startIndex + vertexID]; + + position = vertexData.Position; + normal = vertexData.Normal; + tangent = float4(vertexData.Tangent, 0); + } +} + +//void ReadComputeData(inout float4 position, inout float3 normal, inout float4 tangent, in uint vertexID) +//{ +// // x,y = current and previous frame indices +// // z = deformation check (0 = no deformation, 1 = has deformation) +// // w = skinned motion vectors +// const int4 deformProperty = asint(unity_ComputeMeshIndex); +// const int doSkinning = deformProperty.z; +// if (doSkinning == 1) +// { +// const int streamIndex = _HybridDeformedVertexStreamIndex; +// const int startIndex = deformProperty[streamIndex]; +// const DeformedVertexData vertexData = _DeformedMeshData[startIndex + vertexID]; +// +// position.xyz = vertexData.Position; +// normal = vertexData.Normal; +// tangent.xyz = vertexData.Tangent; +// } +// +//} +#endif + #endif // UNITY_SHADER_VARIABLES_FUNCTIONS_INCLUDED diff --git a/com.unity.render-pipelines.universal/ShaderLibrary/UniversalDOTSInstancing.hlsl b/com.unity.render-pipelines.universal/ShaderLibrary/UniversalDOTSInstancing.hlsl index 202173d5b18..927baef13f9 100644 --- a/com.unity.render-pipelines.universal/ShaderLibrary/UniversalDOTSInstancing.hlsl +++ b/com.unity.render-pipelines.universal/ShaderLibrary/UniversalDOTSInstancing.hlsl @@ -1,4 +1,4 @@ -#ifndef UNIVERSAL_DOTS_INSTANCING_INCLUDED +#ifndef UNIVERSAL_DOTS_INSTANCING_INCLUDED #define UNIVERSAL_DOTS_INSTANCING_INCLUDED #ifdef UNITY_DOTS_INSTANCING_ENABLED @@ -25,6 +25,7 @@ UNITY_DOTS_INSTANCING_START(BuiltinPropertyMetadata) UNITY_DOTS_INSTANCED_PROP(float4, unity_SHBg) UNITY_DOTS_INSTANCED_PROP(float4, unity_SHBb) UNITY_DOTS_INSTANCED_PROP(float4, unity_SHC) + UNITY_DOTS_INSTANCED_PROP(float4, unity_ComputeMeshIndex) UNITY_DOTS_INSTANCING_END(BuiltinPropertyMetadata) // Note: Macros for unity_ObjectToWorld and unity_WorldToObject are declared in UnityInstancing.hlsl @@ -45,6 +46,7 @@ UNITY_DOTS_INSTANCING_END(BuiltinPropertyMetadata) #define unity_SHBg UNITY_ACCESS_DOTS_INSTANCED_PROP_FROM_MACRO(float4, Metadata_unity_SHBg) #define unity_SHBb UNITY_ACCESS_DOTS_INSTANCED_PROP_FROM_MACRO(float4, Metadata_unity_SHBb) #define unity_SHC UNITY_ACCESS_DOTS_INSTANCED_PROP_FROM_MACRO(float4, Metadata_unity_SHC) +#define unity_ComputeMeshIndex UNITY_ACCESS_DOTS_INSTANCED_PROP_FROM_MACRO(float4, Metadata_unity_ComputeMeshIndex) #endif #endif From 98d986e58b281aba9c7d1cf79e2cc0f957d8ea98 Mon Sep 17 00:00:00 2001 From: hedvig Date: Thu, 28 Jan 2021 16:39:18 +0100 Subject: [PATCH 24/34] Rename some functions, move fetching to different file --- .../ShaderLibrary/DotsDeformation.hlsl | 32 +++++++++++ .../ShaderLibrary/DotsDeformation.hlsl.meta | 9 ++++ .../ShaderGraph/Includes/PBRForwardPass.hlsl | 3 +- .../ShaderGraph/Includes/PBRGBufferPass.hlsl | 4 +- .../Includes/ShadowCasterPass.hlsl | 4 +- .../ShaderVariablesFunctions.hlsl | 53 ------------------- 6 files changed, 49 insertions(+), 56 deletions(-) create mode 100644 com.unity.render-pipelines.core/ShaderLibrary/DotsDeformation.hlsl create mode 100644 com.unity.render-pipelines.core/ShaderLibrary/DotsDeformation.hlsl.meta diff --git a/com.unity.render-pipelines.core/ShaderLibrary/DotsDeformation.hlsl b/com.unity.render-pipelines.core/ShaderLibrary/DotsDeformation.hlsl new file mode 100644 index 00000000000..beba8ab39d9 --- /dev/null +++ b/com.unity.render-pipelines.core/ShaderLibrary/DotsDeformation.hlsl @@ -0,0 +1,32 @@ +#if defined(DOTS_INSTANCING_ON) +struct DeformedVertexData +{ + float3 Position; + float3 Normal; + float3 Tangent; +}; + +int _HybridDeformedVertexStreamIndex; +uniform StructuredBuffer _DeformedMeshData; +uniform StructuredBuffer _PreviousFrameDeformedMeshData; + +// Reads vertex data for compute skinned meshes in Hybdrid Renderer +void FetchComputeVertexData(inout Attributes input) +{ + // x,y = current and previous frame indices + // z = deformation check (0 = no deformation, 1 = has deformation) + // w = skinned motion vectors + const int4 deformProperty = asint(unity_ComputeMeshIndex); + const int doSkinning = deformProperty.z; + if (doSkinning == 1) + { + const int streamIndex = _HybridDeformedVertexStreamIndex; + const int startIndex = deformProperty[streamIndex]; + const DeformedVertexData vertexData = _DeformedMeshData[startIndex + input.vertexID]; + + input.positionOS = vertexData.Position; + input.normalOS = vertexData.Normal; + input.tangentOS = float4(vertexData.Tangent, 0); + } +} +#endif diff --git a/com.unity.render-pipelines.core/ShaderLibrary/DotsDeformation.hlsl.meta b/com.unity.render-pipelines.core/ShaderLibrary/DotsDeformation.hlsl.meta new file mode 100644 index 00000000000..e916b6c2752 --- /dev/null +++ b/com.unity.render-pipelines.core/ShaderLibrary/DotsDeformation.hlsl.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2 +guid: 21e613ffd8f12d84b8e1ab498b178067 +ShaderImporter: + externalObjects: {} + defaultTextures: [] + nonModifiableTextures: [] + userData: + assetBundleName: + assetBundleVariant: diff --git a/com.unity.render-pipelines.universal/Editor/ShaderGraph/Includes/PBRForwardPass.hlsl b/com.unity.render-pipelines.universal/Editor/ShaderGraph/Includes/PBRForwardPass.hlsl index 78c2d3b1954..c03356737f5 100644 --- a/com.unity.render-pipelines.universal/Editor/ShaderGraph/Includes/PBRForwardPass.hlsl +++ b/com.unity.render-pipelines.universal/Editor/ShaderGraph/Includes/PBRForwardPass.hlsl @@ -34,12 +34,13 @@ void BuildInputData(Varyings input, SurfaceDescription surfaceDescription, out I inputData.shadowMask = SAMPLE_SHADOWMASK(input.lightmapUV); } +#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/DotsDeformation.hlsl" PackedVaryings vert(Attributes input) { Varyings output = (Varyings)0; #if defined(DOTS_INSTANCING_ON) - ReadComputeData(input.positionOS, input.normalOS, input.tangentOS, input.vertexID); + FetchComputeVertexData(input); #endif output = BuildVaryings(input); PackedVaryings packedOutput = (PackedVaryings)0; diff --git a/com.unity.render-pipelines.universal/Editor/ShaderGraph/Includes/PBRGBufferPass.hlsl b/com.unity.render-pipelines.universal/Editor/ShaderGraph/Includes/PBRGBufferPass.hlsl index a62b7a404e0..612140d0466 100644 --- a/com.unity.render-pipelines.universal/Editor/ShaderGraph/Includes/PBRGBufferPass.hlsl +++ b/com.unity.render-pipelines.universal/Editor/ShaderGraph/Includes/PBRGBufferPass.hlsl @@ -32,11 +32,13 @@ void BuildInputData(Varyings input, SurfaceDescription surfaceDescription, out I inputData.shadowMask = SAMPLE_SHADOWMASK(input.lightmapUV); } +#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/DotsDeformation.hlsl" + PackedVaryings vert(Attributes input) { Varyings output = (Varyings)0; #if defined(DOTS_INSTANCINT_ON) - ReadComputeData(input.positionOS, input.normalOS, input.tangentOS, input.vertexID); + FetchComputeVertexData(input); #endif output = BuildVaryings(input); PackedVaryings packedOutput = (PackedVaryings)0; diff --git a/com.unity.render-pipelines.universal/Editor/ShaderGraph/Includes/ShadowCasterPass.hlsl b/com.unity.render-pipelines.universal/Editor/ShaderGraph/Includes/ShadowCasterPass.hlsl index 4403b20d6aa..c942cad096a 100644 --- a/com.unity.render-pipelines.universal/Editor/ShaderGraph/Includes/ShadowCasterPass.hlsl +++ b/com.unity.render-pipelines.universal/Editor/ShaderGraph/Includes/ShadowCasterPass.hlsl @@ -1,11 +1,13 @@ #ifndef SG_SHADOW_PASS_INCLUDED #define SG_SHADOW_PASS_INCLUDED +#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/DotsDeformation.hlsl" + PackedVaryings vert(Attributes input) { Varyings output = (Varyings)0; #if defined(DOTS_INSTANCING_ON) - ReadComputeData(input.positionOS, input.normalOS, input.tangentOS, input.vertexID); + FetchComputeVertexData(input); #endif output = BuildVaryings(input); PackedVaryings packedOutput = (PackedVaryings)0; diff --git a/com.unity.render-pipelines.universal/ShaderLibrary/ShaderVariablesFunctions.hlsl b/com.unity.render-pipelines.universal/ShaderLibrary/ShaderVariablesFunctions.hlsl index e67be101b05..53214f7c89a 100644 --- a/com.unity.render-pipelines.universal/ShaderLibrary/ShaderVariablesFunctions.hlsl +++ b/com.unity.render-pipelines.universal/ShaderLibrary/ShaderVariablesFunctions.hlsl @@ -279,57 +279,4 @@ float2 GetNormalizedScreenSpaceUV(float4 positionCS) #define UnityStereoTransformScreenSpaceTex(uv) uv #endif // defined(UNITY_SINGLE_PASS_STEREO) - -#if defined(DOTS_INSTANCING_ON) -struct DeformedVertexData -{ - float3 Position; - float3 Normal; - float3 Tangent; -}; - -int _HybridDeformedVertexStreamIndex; -uniform StructuredBuffer _DeformedMeshData; -uniform StructuredBuffer _PreviousFrameDeformedMeshData; - -void ReadComputeData(inout float3 position, inout float3 normal, inout float4 tangent, in uint vertexID) -{ - // x,y = current and previous frame indices - // z = deformation check (0 = no deformation, 1 = has deformation) - // w = skinned motion vectors - const int4 deformProperty = asint(unity_ComputeMeshIndex); - const int doSkinning = deformProperty.z; - if (doSkinning == 1) - { - const int streamIndex = _HybridDeformedVertexStreamIndex; - const int startIndex = deformProperty[streamIndex]; - const DeformedVertexData vertexData = _DeformedMeshData[startIndex + vertexID]; - - position = vertexData.Position; - normal = vertexData.Normal; - tangent = float4(vertexData.Tangent, 0); - } -} - -//void ReadComputeData(inout float4 position, inout float3 normal, inout float4 tangent, in uint vertexID) -//{ -// // x,y = current and previous frame indices -// // z = deformation check (0 = no deformation, 1 = has deformation) -// // w = skinned motion vectors -// const int4 deformProperty = asint(unity_ComputeMeshIndex); -// const int doSkinning = deformProperty.z; -// if (doSkinning == 1) -// { -// const int streamIndex = _HybridDeformedVertexStreamIndex; -// const int startIndex = deformProperty[streamIndex]; -// const DeformedVertexData vertexData = _DeformedMeshData[startIndex + vertexID]; -// -// position.xyz = vertexData.Position; -// normal = vertexData.Normal; -// tangent.xyz = vertexData.Tangent; -// } -// -//} -#endif - #endif // UNITY_SHADER_VARIABLES_FUNCTIONS_INCLUDED From 690298f582f95fed2a8295c55dc35762b51ed94a Mon Sep 17 00:00:00 2001 From: hedvig Date: Thu, 28 Jan 2021 17:22:55 +0100 Subject: [PATCH 25/34] Rename deformation function for HDRP --- .../ShaderLibrary/DotsDeformation.hlsl | 4 ++-- .../RenderPipeline/ShaderPass/DotsDeformation.hlsl | 8 +++++--- .../ShaderPass/MotionVectorVertexShaderCommon.hlsl | 2 +- .../Runtime/RenderPipeline/ShaderPass/VertMesh.hlsl | 2 +- 4 files changed, 9 insertions(+), 7 deletions(-) diff --git a/com.unity.render-pipelines.core/ShaderLibrary/DotsDeformation.hlsl b/com.unity.render-pipelines.core/ShaderLibrary/DotsDeformation.hlsl index beba8ab39d9..b20c3dd9fa8 100644 --- a/com.unity.render-pipelines.core/ShaderLibrary/DotsDeformation.hlsl +++ b/com.unity.render-pipelines.core/ShaderLibrary/DotsDeformation.hlsl @@ -25,8 +25,8 @@ void FetchComputeVertexData(inout Attributes input) const DeformedVertexData vertexData = _DeformedMeshData[startIndex + input.vertexID]; input.positionOS = vertexData.Position; - input.normalOS = vertexData.Normal; - input.tangentOS = float4(vertexData.Tangent, 0); + input.normalOS = vertexData.Normal; + input.tangentOS = float4(vertexData.Tangent, 0); } } #endif diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/DotsDeformation.hlsl b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/DotsDeformation.hlsl index 6395db98ad9..cc223df315f 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/DotsDeformation.hlsl +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/DotsDeformation.hlsl @@ -9,7 +9,8 @@ struct DeformedVertexData uniform StructuredBuffer _DeformedMeshData; uniform StructuredBuffer _PreviousFrameDeformedMeshData; -void DOTS_Deformation(inout AttributesMesh input) +// Reads vertex data for compute skinned meshes in Hybdrid Renderer +void FetchComputeVertexData(inout AttributesMesh input) { // x,y = current and previous frame indices // z = deformation check (0 = no deformation, 1 = has deformation) @@ -32,8 +33,9 @@ void DOTS_Deformation(inout AttributesMesh input) } } -// position only for motion vec vs -void DOTS_Deformation_MotionVecPass(inout float3 currPos, inout float3 prevPos, uint vertexID) +// Reads vertex position for compute skinned meshes in Hybdrid Renderer +// also previous frame position if skinned motion vectors are used +void FetchComputeVertexPosition(inout float3 currPos, inout float3 prevPos, uint vertexID) { // x,y = current and previous frame indices // z = deformation check (0 = no deformation, 1 = has deformation) diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/MotionVectorVertexShaderCommon.hlsl b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/MotionVectorVertexShaderCommon.hlsl index 51755f2a62d..d13e4b00182 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/MotionVectorVertexShaderCommon.hlsl +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/MotionVectorVertexShaderCommon.hlsl @@ -110,7 +110,7 @@ PackedVaryingsType MotionVectorVS(inout VaryingsType varyingsType, AttributesMes float3 deformedPrevPos = inputPass.previousPositionOS; #if defined(DOTS_INSTANCING_ON) - DOTS_Deformation_MotionVecPass(inputMesh.positionOS, deformedPrevPos, inputMesh.vertexID); + FetchComputeVertexPosition(inputMesh.positionOS, deformedPrevPos, inputMesh.vertexID); #endif float3 effectivePositionOS = (hasDeformation) ? deformedPrevPos : inputMesh.positionOS; diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/VertMesh.hlsl b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/VertMesh.hlsl index 94b7a4aed90..26741e0e8ed 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/VertMesh.hlsl +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/VertMesh.hlsl @@ -138,7 +138,7 @@ VaryingsMeshType VertMesh(AttributesMesh input, float3 worldSpaceOffset) UNITY_TRANSFER_INSTANCE_ID(input, output); #if defined(DOTS_INSTANCING_ON) - DOTS_Deformation(input); + FetchComputeVertexData(input); #endif #if defined(HAVE_MESH_MODIFICATION) From b84ffcfb6d195cb9b5e0c455843bf435599f80a0 Mon Sep 17 00:00:00 2001 From: hedvig Date: Fri, 29 Jan 2021 10:15:26 +0100 Subject: [PATCH 26/34] Keep vertex ID as optional when hybrid v2 is not used --- .../Editor/Material/ShaderGraph/HDStructFields.cs | 5 +++++ .../Editor/Generation/TargetResources/StructFields.cs | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/HDStructFields.cs b/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/HDStructFields.cs index 49e1fbe5ba6..ea34185b8ac 100644 --- a/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/HDStructFields.cs +++ b/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/HDStructFields.cs @@ -28,8 +28,13 @@ public struct AttributesMesh "COLOR", subscriptOptions : StructFieldOptions.Optional); public static FieldDescriptor instanceID = new FieldDescriptor(AttributesMesh.name, "instanceID", "", ShaderValueType.Uint, "INSTANCEID_SEMANTIC", "UNITY_ANY_INSTANCING_ENABLED"); +#if ENABLE_HYBRID_RENDERER_V2 public static FieldDescriptor vertexID = new FieldDescriptor(AttributesMesh.name, "vertexID", "", ShaderValueType.Uint, "SV_VertexID", "DOTS_INSTANCING_ON"); +#else + public static FieldDescriptor vertexID = new FieldDescriptor(AttributesMesh.name, "vertexID", "ATTRIBUTES_NEED_VERTEXID", ShaderValueType.Uint, + "SV_VertexID", subscriptOptions: StructFieldOptions.Optional); +#endif } public struct VaryingsMeshToPS diff --git a/com.unity.shadergraph/Editor/Generation/TargetResources/StructFields.cs b/com.unity.shadergraph/Editor/Generation/TargetResources/StructFields.cs index d761e0c7cfb..daf10334031 100644 --- a/com.unity.shadergraph/Editor/Generation/TargetResources/StructFields.cs +++ b/com.unity.shadergraph/Editor/Generation/TargetResources/StructFields.cs @@ -27,8 +27,13 @@ public struct Attributes "COLOR", subscriptOptions : StructFieldOptions.Optional); public static FieldDescriptor instanceID = new FieldDescriptor(Attributes.name, "instanceID", "", ShaderValueType.Uint, "INSTANCEID_SEMANTIC", "UNITY_ANY_INSTANCING_ENABLED"); +#if ENABLE_HYBRID_RENDERER_V2 public static FieldDescriptor vertexID = new FieldDescriptor(Attributes.name, "vertexID", "", ShaderValueType.Uint, "SV_VertexID", "DOTS_INSTANCING_ON"); +#else + public static FieldDescriptor vertexID = new FieldDescriptor(Attributes.name, "vertexID", "ATTRIBUTES_NEED_VERTEXID", ShaderValueType.Uint, + "SV_VertexID", subscriptOptions: StructFieldOptions.Optional); +#endif } public struct Varyings From 6f3cbf126d007685b8d0e93f40634e6cf5857e8e Mon Sep 17 00:00:00 2001 From: hedvig Date: Fri, 29 Jan 2021 10:17:20 +0100 Subject: [PATCH 27/34] Remove formatting from HDTarget --- .../Editor/Material/ShaderGraph/HDTarget.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 1ad954226c3..453c67fe165 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 @@ -947,7 +947,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 static IncludeCollection MinimalCorePregraph = new IncludeCollection { { kShaderVariables, IncludeLocation.Pregraph }, From aa24bcffd37983032749f31491c1bbc7bc27e4e6 Mon Sep 17 00:00:00 2001 From: hedvig Date: Fri, 29 Jan 2021 10:40:12 +0100 Subject: [PATCH 28/34] Updated changelogs to be more descriptive. --- com.unity.render-pipelines.high-definition/CHANGELOG.md | 3 ++- com.unity.shadergraph/CHANGELOG.md | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/com.unity.render-pipelines.high-definition/CHANGELOG.md b/com.unity.render-pipelines.high-definition/CHANGELOG.md index 96ea7d0111f..4cf035ac25c 100644 --- a/com.unity.render-pipelines.high-definition/CHANGELOG.md +++ b/com.unity.render-pipelines.high-definition/CHANGELOG.md @@ -21,7 +21,7 @@ The version number for this package has increased due to a version update of a r - Added light unit slider for automatic and automatic histrogram exposure limits. - Added View Bias for mesh decals. - Added support for the PlayStation 5 platform. -- Added support for skinned motionvectors when using Hybrid Renderer +- Added support for skinned motionvectors when using Hybrid Renderer V2. ### Fixed - Fixed computation of geometric normal in path tracing (case 1293029). @@ -114,6 +114,7 @@ The version number for this package has increased due to a version update of a r - Transparent materials created by the Model Importer are set to not cast shadows. ( case 1295747) - Change some light unit slider value ranges to better reflect the lighting scenario. - Change the tooltip for color shadows and semi-transparent shadows (case 1307704). +- Compute Deformation Node no longer needs to be added manually in Shader Graph for skinning to work with Hybrid Renderer V2. ## [10.2.1] - 2020-11-30 diff --git a/com.unity.shadergraph/CHANGELOG.md b/com.unity.shadergraph/CHANGELOG.md index 86afbfcb773..7bc7850c5f2 100644 --- a/com.unity.shadergraph/CHANGELOG.md +++ b/com.unity.shadergraph/CHANGELOG.md @@ -26,7 +26,7 @@ The version number for this package has increased due to a version update of a r - The shader graph inspector window will now switch to the "Node Settings" tab whenever a property/node/other selectable item in the graph is clicked on to save the user a click ### Removed - - Removed Compute Deformation Node + - Removed Compute Deformation Node as it is no longer required for Hybrid Renderer to be able to apply compute skinning to meshes. For more information see latest documentation about Mesh Deformation in Hybrid Renderer. ### Fixed - Fixed an issue where shaders could be generated with CR/LF ("\r\n") instead of just LF ("\n") line endings [1286430] From 7ac5ee93800ad0c458d8838b1fca02fe52ead7ad Mon Sep 17 00:00:00 2001 From: hedvig Date: Fri, 29 Jan 2021 11:16:02 +0100 Subject: [PATCH 29/34] Rename material property --- .../ShaderLibrary/DotsDeformation.hlsl | 2 +- .../Runtime/RenderPipeline/ShaderPass/DotsDeformation.hlsl | 4 ++-- .../Runtime/ShaderLibrary/ShaderVariables.hlsl | 4 ++-- .../ShaderLibrary/UniversalDOTSInstancing.hlsl | 4 ++-- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/com.unity.render-pipelines.core/ShaderLibrary/DotsDeformation.hlsl b/com.unity.render-pipelines.core/ShaderLibrary/DotsDeformation.hlsl index b20c3dd9fa8..5bbd153fb7d 100644 --- a/com.unity.render-pipelines.core/ShaderLibrary/DotsDeformation.hlsl +++ b/com.unity.render-pipelines.core/ShaderLibrary/DotsDeformation.hlsl @@ -16,7 +16,7 @@ void FetchComputeVertexData(inout Attributes input) // x,y = current and previous frame indices // z = deformation check (0 = no deformation, 1 = has deformation) // w = skinned motion vectors - const int4 deformProperty = asint(unity_ComputeMeshIndex); + const int4 deformProperty = asint(unity_DOTSDeformationParams); const int doSkinning = deformProperty.z; if (doSkinning == 1) { diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/DotsDeformation.hlsl b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/DotsDeformation.hlsl index cc223df315f..ca61c452e9d 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/DotsDeformation.hlsl +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/DotsDeformation.hlsl @@ -15,7 +15,7 @@ void FetchComputeVertexData(inout AttributesMesh input) // x,y = current and previous frame indices // z = deformation check (0 = no deformation, 1 = has deformation) // w = skinned motion vectors - const int4 deformProperty = asint(unity_ComputeMeshIndex); + const int4 deformProperty = asint(unity_DOTSDeformationParams); const int doSkinning = deformProperty.z; if (doSkinning == 1) { @@ -40,7 +40,7 @@ void FetchComputeVertexPosition(inout float3 currPos, inout float3 prevPos, uint // x,y = current and previous frame indices // z = deformation check (0 = no deformation, 1 = has deformation) // w = skinned motion vectors - const int4 deformProperty = asint(unity_ComputeMeshIndex); + const int4 deformProperty = asint(unity_DOTSDeformationParams); const int computeSkin = deformProperty.z; if (computeSkin == 1) { diff --git a/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl b/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl index a6c6f716633..a7c0a1e1d5c 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl +++ b/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl @@ -373,7 +373,7 @@ UNITY_DOTS_INSTANCING_START(BuiltinPropertyMetadata) UNITY_DOTS_INSTANCED_PROP(float3x4, unity_MatrixPreviousM) UNITY_DOTS_INSTANCED_PROP(float3x4, unity_MatrixPreviousMI) UNITY_DOTS_INSTANCED_PROP(float4, unity_MotionVectorsParams) - UNITY_DOTS_INSTANCED_PROP(float4, unity_ComputeMeshIndex) + UNITY_DOTS_INSTANCED_PROP(float4, unity_DOTSDeformationParams) UNITY_DOTS_INSTANCING_END(BuiltinPropertyMetadata) // Note: Macros for unity_ObjectToWorld and unity_WorldToObject are declared elsewhere @@ -394,7 +394,7 @@ UNITY_DOTS_INSTANCING_END(BuiltinPropertyMetadata) #define unity_MatrixPreviousM LoadDOTSInstancedData_float4x4_from_float3x4(UNITY_DOTS_INSTANCED_METADATA_NAME_FROM_MACRO(float3x4, Metadata_unity_MatrixPreviousM)) #define unity_MatrixPreviousMI LoadDOTSInstancedData_float4x4_from_float3x4(UNITY_DOTS_INSTANCED_METADATA_NAME_FROM_MACRO(float3x4, Metadata_unity_MatrixPreviousMI)) #define unity_MotionVectorsParams UNITY_ACCESS_DOTS_INSTANCED_PROP_FROM_MACRO(float4, Metadata_unity_MotionVectorsParams) -#define unity_ComputeMeshIndex UNITY_ACCESS_DOTS_INSTANCED_PROP_FROM_MACRO(float4, Metadata_unity_ComputeMeshIndex) +#define unity_DOTSDeformationParams UNITY_ACCESS_DOTS_INSTANCED_PROP_FROM_MACRO(float4, Metadata_unity_DOTSDeformationParams) #endif // Define View/Projection matrix macro diff --git a/com.unity.render-pipelines.universal/ShaderLibrary/UniversalDOTSInstancing.hlsl b/com.unity.render-pipelines.universal/ShaderLibrary/UniversalDOTSInstancing.hlsl index 927baef13f9..6725daced41 100644 --- a/com.unity.render-pipelines.universal/ShaderLibrary/UniversalDOTSInstancing.hlsl +++ b/com.unity.render-pipelines.universal/ShaderLibrary/UniversalDOTSInstancing.hlsl @@ -25,7 +25,7 @@ UNITY_DOTS_INSTANCING_START(BuiltinPropertyMetadata) UNITY_DOTS_INSTANCED_PROP(float4, unity_SHBg) UNITY_DOTS_INSTANCED_PROP(float4, unity_SHBb) UNITY_DOTS_INSTANCED_PROP(float4, unity_SHC) - UNITY_DOTS_INSTANCED_PROP(float4, unity_ComputeMeshIndex) + UNITY_DOTS_INSTANCED_PROP(float4, unity_DOTSDeformationParams) UNITY_DOTS_INSTANCING_END(BuiltinPropertyMetadata) // Note: Macros for unity_ObjectToWorld and unity_WorldToObject are declared in UnityInstancing.hlsl @@ -46,7 +46,7 @@ UNITY_DOTS_INSTANCING_END(BuiltinPropertyMetadata) #define unity_SHBg UNITY_ACCESS_DOTS_INSTANCED_PROP_FROM_MACRO(float4, Metadata_unity_SHBg) #define unity_SHBb UNITY_ACCESS_DOTS_INSTANCED_PROP_FROM_MACRO(float4, Metadata_unity_SHBb) #define unity_SHC UNITY_ACCESS_DOTS_INSTANCED_PROP_FROM_MACRO(float4, Metadata_unity_SHC) -#define unity_ComputeMeshIndex UNITY_ACCESS_DOTS_INSTANCED_PROP_FROM_MACRO(float4, Metadata_unity_ComputeMeshIndex) +#define unity_DOTSDeformationParams UNITY_ACCESS_DOTS_INSTANCED_PROP_FROM_MACRO(float4, Metadata_unity_DOTSDeformationParams) #endif #endif From 3c2a52c67b04292d2e1bce62fef0a0fa752e7e3e Mon Sep 17 00:00:00 2001 From: hedvig Date: Fri, 29 Jan 2021 16:46:03 +0100 Subject: [PATCH 30/34] Add dots skinning function to URP passes PBR-Forward/GBuffer, Lit-Forward/GBuffer, Depth/DepthNormal, ShadowCaster, Unlit, PostProcessing, ScreenSpaceShadows, SimpleLit-Forward/GBiffer, PreviewPass --- .../ShaderLibrary/DotsDeformation.hlsl | 59 +++++++++++++++++-- .../Includes/DepthNormalsOnlyPass.hlsl | 6 ++ .../ShaderGraph/Includes/DepthOnlyPass.hlsl | 5 ++ .../ShaderGraph/Includes/PBRForwardPass.hlsl | 2 +- .../ShaderGraph/Includes/PBRGBufferPass.hlsl | 4 +- .../Includes/ShadowCasterPass.hlsl | 2 +- .../ShaderGraph/Includes/UnlitPass.hlsl | 8 ++- .../Shaders/DepthNormalsPass.hlsl | 8 +++ .../Shaders/DepthOnlyPass.hlsl | 8 +++ .../Shaders/LitForwardPass.hlsl | 9 +++ .../Shaders/LitGBufferPass.hlsl | 10 ++++ .../Shaders/PostProcessing/Common.hlsl | 5 ++ .../Shaders/ShadowCasterPass.hlsl | 8 +++ .../Shaders/SimpleLitForwardPass.hlsl | 7 +++ .../Shaders/SimpleLitGBufferPass.hlsl | 3 + .../Shaders/Utils/ScreenSpaceShadows.shader | 4 ++ .../ShaderGraphLibrary/PreviewPass.hlsl | 7 ++- 17 files changed, 144 insertions(+), 11 deletions(-) diff --git a/com.unity.render-pipelines.core/ShaderLibrary/DotsDeformation.hlsl b/com.unity.render-pipelines.core/ShaderLibrary/DotsDeformation.hlsl index 5bbd153fb7d..5fffd10078a 100644 --- a/com.unity.render-pipelines.core/ShaderLibrary/DotsDeformation.hlsl +++ b/com.unity.render-pipelines.core/ShaderLibrary/DotsDeformation.hlsl @@ -11,7 +11,7 @@ uniform StructuredBuffer _DeformedMeshData; uniform StructuredBuffer _PreviousFrameDeformedMeshData; // Reads vertex data for compute skinned meshes in Hybdrid Renderer -void FetchComputeVertexData(inout Attributes input) +void FetchComputeVertexData(inout float3 pos, inout float3 nrm, inout float4 tan, in uint vertexID) { // x,y = current and previous frame indices // z = deformation check (0 = no deformation, 1 = has deformation) @@ -22,11 +22,60 @@ void FetchComputeVertexData(inout Attributes input) { const int streamIndex = _HybridDeformedVertexStreamIndex; const int startIndex = deformProperty[streamIndex]; - const DeformedVertexData vertexData = _DeformedMeshData[startIndex + input.vertexID]; + const DeformedVertexData vertexData = _DeformedMeshData[startIndex + vertexID]; - input.positionOS = vertexData.Position; - input.normalOS = vertexData.Normal; - input.tangentOS = float4(vertexData.Tangent, 0); + pos = vertexData.Position; + nrm = vertexData.Normal; + tan = float4(vertexData.Tangent, 0); } } + +void FetchComputeVertexPosNrm(inout float3 pos, inout float3 nrm, in uint vertexID) +{ + // x,y = current and previous frame indices + // z = deformation check (0 = no deformation, 1 = has deformation) + // w = skinned motion vectors + const int4 deformProperty = asint(unity_DOTSDeformationParams); + const int doSkinning = deformProperty.z; + if (doSkinning == 1) + { + const int streamIndex = _HybridDeformedVertexStreamIndex; + const int startIndex = deformProperty[streamIndex]; + const DeformedVertexData vertexData = _DeformedMeshData[startIndex + vertexID]; + + pos = vertexData.Position; + nrm = vertexData.Normal; + } +} + +void FetchComputeVertexNormal(inout float3 normal, in uint vertexID) +{ + const int4 deformProperty = asint(unity_DOTSDeformationParams); + const int doSkinning = deformProperty.z; + if (doSkinning == 1) + { + const int streamIndex = _HybridDeformedVertexStreamIndex; + const int startIndex = deformProperty[streamIndex]; + + normal = _DeformedMeshData[startIndex + vertexID].Normal; + } +} + +void FetchComputeVertexPosition(inout float3 position, in uint vertexID) +{ + const int4 deformProperty = asint(unity_DOTSDeformationParams); + const int doSkinning = deformProperty.z; + if (doSkinning == 1) + { + const int streamIndex = _HybridDeformedVertexStreamIndex; + const int startIndex = deformProperty[streamIndex]; + + position = _DeformedMeshData[startIndex + vertexID].Position; + } +} + +void FetchComputeVertexPosition(inout float4 position, in uint vertexID) +{ + FetchComputeVertexPosition(position.xyz, vertexID); +} #endif diff --git a/com.unity.render-pipelines.universal/Editor/ShaderGraph/Includes/DepthNormalsOnlyPass.hlsl b/com.unity.render-pipelines.universal/Editor/ShaderGraph/Includes/DepthNormalsOnlyPass.hlsl index 9c979177551..17a602af075 100644 --- a/com.unity.render-pipelines.universal/Editor/ShaderGraph/Includes/DepthNormalsOnlyPass.hlsl +++ b/com.unity.render-pipelines.universal/Editor/ShaderGraph/Includes/DepthNormalsOnlyPass.hlsl @@ -1,10 +1,16 @@ #ifndef SG_DEPTH_ONLY_PASS_INCLUDED #define SG_DEPTH_ONLY_PASS_INCLUDED +#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/DotsDeformation.hlsl" + PackedVaryings vert(Attributes input) { Varyings output = (Varyings)0; output = BuildVaryings(input); + +#if defined(DOTS_INSTANCING_ON) + FetchComputeVertexPosNrm(input.positionOS, input.normalOS, input.vertexID); +#endif PackedVaryings packedOutput = (PackedVaryings)0; packedOutput = PackVaryings(output); return packedOutput; diff --git a/com.unity.render-pipelines.universal/Editor/ShaderGraph/Includes/DepthOnlyPass.hlsl b/com.unity.render-pipelines.universal/Editor/ShaderGraph/Includes/DepthOnlyPass.hlsl index 1a6c61d212b..323c2fc629c 100644 --- a/com.unity.render-pipelines.universal/Editor/ShaderGraph/Includes/DepthOnlyPass.hlsl +++ b/com.unity.render-pipelines.universal/Editor/ShaderGraph/Includes/DepthOnlyPass.hlsl @@ -1,9 +1,14 @@ #ifndef SG_DEPTH_ONLY_PASS_INCLUDED #define SG_DEPTH_ONLY_PASS_INCLUDED +#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/DotsDeformation.hlsl" + PackedVaryings vert(Attributes input) { Varyings output = (Varyings)0; +#if defined(DOTS_INSTANCING_ON) + FetchComputeVertexPosition(input.positionOS, input.vertexID); +#endif output = BuildVaryings(input); PackedVaryings packedOutput = (PackedVaryings)0; packedOutput = PackVaryings(output); diff --git a/com.unity.render-pipelines.universal/Editor/ShaderGraph/Includes/PBRForwardPass.hlsl b/com.unity.render-pipelines.universal/Editor/ShaderGraph/Includes/PBRForwardPass.hlsl index c03356737f5..de70b44b601 100644 --- a/com.unity.render-pipelines.universal/Editor/ShaderGraph/Includes/PBRForwardPass.hlsl +++ b/com.unity.render-pipelines.universal/Editor/ShaderGraph/Includes/PBRForwardPass.hlsl @@ -40,7 +40,7 @@ PackedVaryings vert(Attributes input) { Varyings output = (Varyings)0; #if defined(DOTS_INSTANCING_ON) - FetchComputeVertexData(input); + FetchComputeVertexData(input.positionOS, input.normalOS, input.tangentOS, input.vertexID); #endif output = BuildVaryings(input); PackedVaryings packedOutput = (PackedVaryings)0; diff --git a/com.unity.render-pipelines.universal/Editor/ShaderGraph/Includes/PBRGBufferPass.hlsl b/com.unity.render-pipelines.universal/Editor/ShaderGraph/Includes/PBRGBufferPass.hlsl index 612140d0466..a06fb3e354b 100644 --- a/com.unity.render-pipelines.universal/Editor/ShaderGraph/Includes/PBRGBufferPass.hlsl +++ b/com.unity.render-pipelines.universal/Editor/ShaderGraph/Includes/PBRGBufferPass.hlsl @@ -37,8 +37,8 @@ void BuildInputData(Varyings input, SurfaceDescription surfaceDescription, out I PackedVaryings vert(Attributes input) { Varyings output = (Varyings)0; -#if defined(DOTS_INSTANCINT_ON) - FetchComputeVertexData(input); +#if defined(DOTS_INSTANCING_ON) + FetchComputeVertexData(input.positionOS, input.normalOS, input.tangentOS, input.vertexID); #endif output = BuildVaryings(input); PackedVaryings packedOutput = (PackedVaryings)0; diff --git a/com.unity.render-pipelines.universal/Editor/ShaderGraph/Includes/ShadowCasterPass.hlsl b/com.unity.render-pipelines.universal/Editor/ShaderGraph/Includes/ShadowCasterPass.hlsl index c942cad096a..b4aad8ba04c 100644 --- a/com.unity.render-pipelines.universal/Editor/ShaderGraph/Includes/ShadowCasterPass.hlsl +++ b/com.unity.render-pipelines.universal/Editor/ShaderGraph/Includes/ShadowCasterPass.hlsl @@ -7,7 +7,7 @@ PackedVaryings vert(Attributes input) { Varyings output = (Varyings)0; #if defined(DOTS_INSTANCING_ON) - FetchComputeVertexData(input); + FetchComputeVertexData(input.positionOS, input.normalOS, input.tangentOS, input.vertexID); #endif output = BuildVaryings(input); PackedVaryings packedOutput = (PackedVaryings)0; diff --git a/com.unity.render-pipelines.universal/Editor/ShaderGraph/Includes/UnlitPass.hlsl b/com.unity.render-pipelines.universal/Editor/ShaderGraph/Includes/UnlitPass.hlsl index 701d77b29e5..241f818760a 100644 --- a/com.unity.render-pipelines.universal/Editor/ShaderGraph/Includes/UnlitPass.hlsl +++ b/com.unity.render-pipelines.universal/Editor/ShaderGraph/Includes/UnlitPass.hlsl @@ -1,6 +1,12 @@ -PackedVaryings vert(Attributes input) +#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/DotsDeformation.hlsl" + +PackedVaryings vert(Attributes input) { Varyings output = (Varyings)0; + +#if defined(DOTS_INSTANCING_ON) + FetchComputeVertexData(input.positionOS, input.normalOS, input.tangentOS, input.vertexID); +#endif output = BuildVaryings(input); PackedVaryings packedOutput = PackVaryings(output); return packedOutput; diff --git a/com.unity.render-pipelines.universal/Shaders/DepthNormalsPass.hlsl b/com.unity.render-pipelines.universal/Shaders/DepthNormalsPass.hlsl index 9f4054ea0a7..1550937e3a8 100644 --- a/com.unity.render-pipelines.universal/Shaders/DepthNormalsPass.hlsl +++ b/com.unity.render-pipelines.universal/Shaders/DepthNormalsPass.hlsl @@ -2,6 +2,7 @@ #define UNIVERSAL_DEPTH_ONLY_PASS_INCLUDED #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl" +#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/DotsDeformation.hlsl" struct Attributes { @@ -9,6 +10,9 @@ struct Attributes float4 tangentOS : TANGENT; float2 texcoord : TEXCOORD0; float3 normal : NORMAL; +#if DOTS_INSTANCING_ON + uint vertexID : SV_VertexID; +#endif UNITY_VERTEX_INPUT_INSTANCE_ID }; @@ -28,6 +32,10 @@ Varyings DepthNormalsVertex(Attributes input) UNITY_SETUP_INSTANCE_ID(input); UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output); +#if defined(DOTS_INSTANCING_ON) + FetchComputeVertexData(input.positionOS, input.normal, input.tangentOS, input.vertexID); +#endif + output.uv = TRANSFORM_TEX(input.texcoord, _BaseMap); output.positionCS = TransformObjectToHClip(input.positionOS.xyz); diff --git a/com.unity.render-pipelines.universal/Shaders/DepthOnlyPass.hlsl b/com.unity.render-pipelines.universal/Shaders/DepthOnlyPass.hlsl index 7c00bd3d336..3848b64afa2 100644 --- a/com.unity.render-pipelines.universal/Shaders/DepthOnlyPass.hlsl +++ b/com.unity.render-pipelines.universal/Shaders/DepthOnlyPass.hlsl @@ -2,11 +2,15 @@ #define UNIVERSAL_DEPTH_ONLY_PASS_INCLUDED #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl" +#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/DotsDeformation.hlsl" struct Attributes { float4 position : POSITION; float2 texcoord : TEXCOORD0; +#if DOTS_INSTANCING_ON + uint vertexID : SV_VertexID; +#endif UNITY_VERTEX_INPUT_INSTANCE_ID }; @@ -18,11 +22,15 @@ struct Varyings UNITY_VERTEX_OUTPUT_STEREO }; + Varyings DepthOnlyVertex(Attributes input) { Varyings output = (Varyings)0; UNITY_SETUP_INSTANCE_ID(input); UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output); +#if defined(DOTS_INSTANCING_ON) + FetchComputeVertexPosition(input.position, input.vertexID); +#endif output.uv = TRANSFORM_TEX(input.texcoord, _BaseMap); output.positionCS = TransformObjectToHClip(input.position.xyz); diff --git a/com.unity.render-pipelines.universal/Shaders/LitForwardPass.hlsl b/com.unity.render-pipelines.universal/Shaders/LitForwardPass.hlsl index 02f97fc041d..48b41fb8fec 100644 --- a/com.unity.render-pipelines.universal/Shaders/LitForwardPass.hlsl +++ b/com.unity.render-pipelines.universal/Shaders/LitForwardPass.hlsl @@ -21,6 +21,9 @@ struct Attributes float4 tangentOS : TANGENT; float2 texcoord : TEXCOORD0; float2 lightmapUV : TEXCOORD1; +#if DOTS_INSTANCING_ON + uint vertexID : SV_VertexID; +#endif UNITY_VERTEX_INPUT_INSTANCE_ID }; @@ -89,6 +92,8 @@ void InitializeInputData(Varyings input, half3 normalTS, out InputData inputData inputData.shadowMask = SAMPLE_SHADOWMASK(input.lightmapUV); } +#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/DotsDeformation.hlsl" + /////////////////////////////////////////////////////////////////////////////// // Vertex and Fragment functions // /////////////////////////////////////////////////////////////////////////////// @@ -102,6 +107,10 @@ Varyings LitPassVertex(Attributes input) UNITY_TRANSFER_INSTANCE_ID(input, output); UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output); +#if defined(DOTS_INSTANCING_ON) + FetchComputeVertexData(input.positionOS.xyz, input.normalOS, input.tangentOS, input.vertexID); +#endif + VertexPositionInputs vertexInput = GetVertexPositionInputs(input.positionOS.xyz); // normalWS and tangentWS already normalize. diff --git a/com.unity.render-pipelines.universal/Shaders/LitGBufferPass.hlsl b/com.unity.render-pipelines.universal/Shaders/LitGBufferPass.hlsl index 4a619cb0360..6777e3fe610 100644 --- a/com.unity.render-pipelines.universal/Shaders/LitGBufferPass.hlsl +++ b/com.unity.render-pipelines.universal/Shaders/LitGBufferPass.hlsl @@ -25,6 +25,9 @@ struct Attributes float4 tangentOS : TANGENT; float2 texcoord : TEXCOORD0; float2 lightmapUV : TEXCOORD1; +#if DOTS_INSTANCING_ON + uint vertexID : SV_VertexID; +#endif UNITY_VERTEX_INPUT_INSTANCE_ID }; @@ -93,6 +96,8 @@ void InitializeInputData(Varyings input, half3 normalTS, out InputData inputData inputData.shadowMask = SAMPLE_SHADOWMASK(input.lightmapUV); } +#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/DotsDeformation.hlsl" + /////////////////////////////////////////////////////////////////////////////// // Vertex and Fragment functions // /////////////////////////////////////////////////////////////////////////////// @@ -106,6 +111,11 @@ Varyings LitGBufferPassVertex(Attributes input) UNITY_TRANSFER_INSTANCE_ID(input, output); UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output); + +#if defined(DOTS_INSTANCING_ON) + FetchComputeVertexData(input.positionOS.xyz, input.normalOS, input.tangentOS, input.vertexID); +#endif + VertexPositionInputs vertexInput = GetVertexPositionInputs(input.positionOS.xyz); // normalWS and tangentWS already normalize. diff --git a/com.unity.render-pipelines.universal/Shaders/PostProcessing/Common.hlsl b/com.unity.render-pipelines.universal/Shaders/PostProcessing/Common.hlsl index 4da8322948e..c2690acc7d5 100644 --- a/com.unity.render-pipelines.universal/Shaders/PostProcessing/Common.hlsl +++ b/com.unity.render-pipelines.universal/Shaders/PostProcessing/Common.hlsl @@ -3,6 +3,7 @@ #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Color.hlsl" #include "Packages/com.unity.render-pipelines.universal/Shaders/Utils/Fullscreen.hlsl" +#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/DotsDeformation.hlsl" // ---------------------------------------------------------------------------------- // Render fullscreen mesh by using a matrix set directly by the pipeline instead of @@ -21,6 +22,10 @@ Varyings VertFullscreenMesh(Attributes input) UNITY_SETUP_INSTANCE_ID(input); UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output); +#if defined(DOTS_INSTANCING_ON) + FetchComputeVertexPosition(input.positionOS, input.normalOS, input.tangentOS, input.vertexID); +#endif + #if _USE_DRAW_PROCEDURAL GetProceduralQuad(input.vertexID, output.positionCS, output.uv); #else diff --git a/com.unity.render-pipelines.universal/Shaders/ShadowCasterPass.hlsl b/com.unity.render-pipelines.universal/Shaders/ShadowCasterPass.hlsl index 66353420a69..b5f6cb7366b 100644 --- a/com.unity.render-pipelines.universal/Shaders/ShadowCasterPass.hlsl +++ b/com.unity.render-pipelines.universal/Shaders/ShadowCasterPass.hlsl @@ -3,6 +3,7 @@ #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl" #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Shadows.hlsl" +#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/DotsDeformation.hlsl" float3 _LightDirection; @@ -11,6 +12,9 @@ struct Attributes float4 positionOS : POSITION; float3 normalOS : NORMAL; float2 texcoord : TEXCOORD0; +#if DOTS_INSTANCING_ON + uint vertexID : SV_VertexID; +#endif UNITY_VERTEX_INPUT_INSTANCE_ID }; @@ -41,6 +45,10 @@ Varyings ShadowPassVertex(Attributes input) Varyings output; UNITY_SETUP_INSTANCE_ID(input); +#if defined(DOTS_INSTANCING_ON) + FetchComputeVertexPosition(input.positionOS, input.vertexID); +#endif + output.uv = TRANSFORM_TEX(input.texcoord, _BaseMap); output.positionCS = GetShadowPositionHClip(input); return output; diff --git a/com.unity.render-pipelines.universal/Shaders/SimpleLitForwardPass.hlsl b/com.unity.render-pipelines.universal/Shaders/SimpleLitForwardPass.hlsl index feadc4c60c1..8759daafdc4 100644 --- a/com.unity.render-pipelines.universal/Shaders/SimpleLitForwardPass.hlsl +++ b/com.unity.render-pipelines.universal/Shaders/SimpleLitForwardPass.hlsl @@ -2,6 +2,7 @@ #define UNIVERSAL_SIMPLE_LIT_PASS_INCLUDED #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl" +#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/DotsDeformation.hlsl" struct Attributes { @@ -10,6 +11,9 @@ struct Attributes float4 tangentOS : TANGENT; float2 texcoord : TEXCOORD0; float2 lightmapUV : TEXCOORD1; +#if DOTS_INSTANCING_ON + uint vertexID : SV_VertexID; +#endif UNITY_VERTEX_INPUT_INSTANCE_ID }; @@ -85,6 +89,9 @@ Varyings LitPassVertexSimple(Attributes input) UNITY_SETUP_INSTANCE_ID(input); UNITY_TRANSFER_INSTANCE_ID(input, output); UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output); +#if defined(DOTS_INSTANCING_ON) + FetchComputeVertexData(input.positionOS.xyz, input.normalOS, input.tangentOS, input.vertexID); +#endif VertexPositionInputs vertexInput = GetVertexPositionInputs(input.positionOS.xyz); VertexNormalInputs normalInput = GetVertexNormalInputs(input.normalOS, input.tangentOS); diff --git a/com.unity.render-pipelines.universal/Shaders/SimpleLitGBufferPass.hlsl b/com.unity.render-pipelines.universal/Shaders/SimpleLitGBufferPass.hlsl index 914d176d082..1560eab674d 100644 --- a/com.unity.render-pipelines.universal/Shaders/SimpleLitGBufferPass.hlsl +++ b/com.unity.render-pipelines.universal/Shaders/SimpleLitGBufferPass.hlsl @@ -88,6 +88,9 @@ Varyings LitPassVertexSimple(Attributes input) UNITY_SETUP_INSTANCE_ID(input); UNITY_TRANSFER_INSTANCE_ID(input, output); UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output); +#if defined(DOTS_INSTANCINT_ON) + ReadComputeData(input.positionOS, input.normalOS, input.tangentOS, input.vertexID); +#endif VertexPositionInputs vertexInput = GetVertexPositionInputs(input.positionOS.xyz); VertexNormalInputs normalInput = GetVertexNormalInputs(input.normalOS, input.tangentOS); diff --git a/com.unity.render-pipelines.universal/Shaders/Utils/ScreenSpaceShadows.shader b/com.unity.render-pipelines.universal/Shaders/Utils/ScreenSpaceShadows.shader index 84047d93d55..ba19263c27d 100644 --- a/com.unity.render-pipelines.universal/Shaders/Utils/ScreenSpaceShadows.shader +++ b/com.unity.render-pipelines.universal/Shaders/Utils/ScreenSpaceShadows.shader @@ -38,6 +38,10 @@ Shader "Hidden/Universal Render Pipeline/ScreenSpaceShadows" UNITY_SETUP_INSTANCE_ID(input); UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output); +#if defined(DOTS_INSTANCING_ON) + FetchComputeVertexPosition(input.positionOS, input.vertexID); +#endif + output.positionCS = TransformObjectToHClip(input.positionOS.xyz); float4 projPos = output.positionCS * 0.5; diff --git a/com.unity.shadergraph/ShaderGraphLibrary/PreviewPass.hlsl b/com.unity.shadergraph/ShaderGraphLibrary/PreviewPass.hlsl index dd57b1cf440..f032b0cb804 100644 --- a/com.unity.shadergraph/ShaderGraphLibrary/PreviewPass.hlsl +++ b/com.unity.shadergraph/ShaderGraphLibrary/PreviewPass.hlsl @@ -1,7 +1,12 @@ -PackedVaryings vert(Attributes input) +#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/DotsDeformation.hlsl" + +PackedVaryings vert(Attributes input) { Varyings output = (Varyings)0; output = BuildVaryings(input); +#if defined(DOTS_INSTANCING_ON) + FetchComputeVertexData(input.positionOS.xyz, input.normalOS, input.tangentOS, input.vertexID); +#endif PackedVaryings packedOutput = PackVaryings(output); return packedOutput; } From 808bf7042679effa4deda6c8e241566e7d8a85f4 Mon Sep 17 00:00:00 2001 From: hedvig Date: Mon, 1 Feb 2021 13:48:16 +0100 Subject: [PATCH 31/34] Remove modulus from deform vertex function --- .../Runtime/RenderPipeline/ShaderPass/DotsDeformation.hlsl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/DotsDeformation.hlsl b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/DotsDeformation.hlsl index ca61c452e9d..3d715bbf305 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/DotsDeformation.hlsl +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/DotsDeformation.hlsl @@ -52,7 +52,7 @@ void FetchComputeVertexPosition(inout float3 currPos, inout float3 prevPos, uint const int skinMotionVec = deformProperty.w; if (skinMotionVec == 1) { - const int prevStreamIndex = (_HybridDeformedVertexStreamIndex + 1) % 2; + const int prevStreamIndex = _HybridDeformedVertexStreamIndex ^ 1; const int prevMeshStart = deformProperty[prevStreamIndex]; prevPos = _PreviousFrameDeformedMeshData[prevMeshStart + vertexID].Position; } From a3c3a8e7d78539f930a530169fbc5b0a8d2026db Mon Sep 17 00:00:00 2001 From: hedvig Date: Thu, 11 Feb 2021 15:58:44 +0100 Subject: [PATCH 32/34] Remove modulus, change to uints --- .../RenderPipeline/HDRenderPipeline.cs | 4 ++-- .../ShaderPass/DotsDeformation.hlsl | 20 ++++++++++++------- .../MotionVectorVertexShaderCommon.hlsl | 1 - 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.cs b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.cs index 83073b2a746..10aa4b0f89a 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.cs @@ -1339,8 +1339,8 @@ void UpdateShaderVariablesGlobalCB(HDCamera hdCamera, CommandBuffer cmd) m_ShaderVariablesGlobalCB._EnableRecursiveRayTracing = 0; m_ShaderVariablesGlobalCB._SpecularOcclusionBlend = 1.0f; } - - m_ShaderVariablesGlobalCB._HybridDeformedVertexStreamIndex = UnityEngine.Time.frameCount % 2; + + m_ShaderVariablesGlobalCB._HybridDeformedVertexStreamIndex = UnityEngine.Time.frameCount & 1; ConstantBuffer.PushGlobal(cmd, m_ShaderVariablesGlobalCB, HDShaderIDs._ShaderVariablesGlobal); } diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/DotsDeformation.hlsl b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/DotsDeformation.hlsl index 3d715bbf305..e2c56bc3afe 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/DotsDeformation.hlsl +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/DotsDeformation.hlsl @@ -19,8 +19,8 @@ void FetchComputeVertexData(inout AttributesMesh input) const int doSkinning = deformProperty.z; if (doSkinning == 1) { - const int streamIndex = _HybridDeformedVertexStreamIndex; - const int startIndex = deformProperty[streamIndex]; + const uint streamIndex = _HybridDeformedVertexStreamIndex; + const uint startIndex = deformProperty[streamIndex]; const DeformedVertexData vertexData = _DeformedMeshData[startIndex + input.vertexID]; input.positionOS = vertexData.Position; @@ -34,7 +34,7 @@ void FetchComputeVertexData(inout AttributesMesh input) } // Reads vertex position for compute skinned meshes in Hybdrid Renderer -// also previous frame position if skinned motion vectors are used +// and also previous frame position if skinned motion vectors are used void FetchComputeVertexPosition(inout float3 currPos, inout float3 prevPos, uint vertexID) { // x,y = current and previous frame indices @@ -42,19 +42,25 @@ void FetchComputeVertexPosition(inout float3 currPos, inout float3 prevPos, uint // w = skinned motion vectors const int4 deformProperty = asint(unity_DOTSDeformationParams); const int computeSkin = deformProperty.z; + const uint streamIndex = _HybridDeformedVertexStreamIndex; if (computeSkin == 1) { - const int currStreamIndex = _HybridDeformedVertexStreamIndex; - const int currMeshStart = deformProperty[currStreamIndex]; + const uint currMeshStart = deformProperty[streamIndex]; + const uint currStreamIndex = _HybridDeformedVertexStreamIndex; currPos = _DeformedMeshData[currMeshStart + vertexID].Position; } const int skinMotionVec = deformProperty.w; if (skinMotionVec == 1) { - const int prevStreamIndex = _HybridDeformedVertexStreamIndex ^ 1; + const uint prevStreamIndex = streamIndex ^ 1; const int prevMeshStart = deformProperty[prevStreamIndex]; - prevPos = _PreviousFrameDeformedMeshData[prevMeshStart + vertexID].Position; + + if(prevMeshStart == -1) + prevPos = _DeformedMeshData[prevMeshStart + vertexID].Position; + else + prevPos = _PreviousFrameDeformedMeshData[prevMeshStart + vertexID].Position; + } } #endif diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/MotionVectorVertexShaderCommon.hlsl b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/MotionVectorVertexShaderCommon.hlsl index d13e4b00182..4336420aa61 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/MotionVectorVertexShaderCommon.hlsl +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/MotionVectorVertexShaderCommon.hlsl @@ -87,7 +87,6 @@ void MotionVectorPositionZBias(VaryingsToPS input) PackedVaryingsType MotionVectorVS(inout VaryingsType varyingsType, AttributesMesh inputMesh, AttributesPass inputPass) { - #if !defined(TESSELLATION_ON) MotionVectorPositionZBias(varyingsType); #endif From b70a82a7bc4748c79919a3a692141ae344dcd7e8 Mon Sep 17 00:00:00 2001 From: hedvig Date: Thu, 11 Feb 2021 16:03:10 +0100 Subject: [PATCH 33/34] Remove documentation for Compute Deformation Node --- .../Documentation~/Compute-Deformation-Node.md | 12 ------------ 1 file changed, 12 deletions(-) delete mode 100644 com.unity.shadergraph/Documentation~/Compute-Deformation-Node.md diff --git a/com.unity.shadergraph/Documentation~/Compute-Deformation-Node.md b/com.unity.shadergraph/Documentation~/Compute-Deformation-Node.md deleted file mode 100644 index 7c42b23459d..00000000000 --- a/com.unity.shadergraph/Documentation~/Compute-Deformation-Node.md +++ /dev/null @@ -1,12 +0,0 @@ -# Compute Deformation Node - -## Description - -This node lets you pass compute deformed vertex data to a vertex shader, and only works with the [DOTS Hybrid Renderer](https://docs.unity3d.com/Packages/com.unity.rendering.hybrid@latest/). You must provide `DeformedVertexData` in the `_DeformedMeshData` buffer. The node uses the `_ComputeMeshIndex` property to calculate where the `DeformedVertexData` associated with the current mesh are located in the `_DeformedMeshData` buffer. To output data, you must either install both the DOTS Hybrid Renderer and DOTS Animation packages, or use a custom solution. - -## Ports -| Name | Direction | Type | Stage | Description | -|:--------- |:-----------|:--------|:-------|:------------| -| Position | Output | Vector3 | Vertex | Outputs the deformed vertex position. | -| Normal | Output | Vector3 | Vertex | Outputs the deformed vertex normal. | -| Tangent | Output | Vector3 | Vertex | Outputs the deformed vertex tangent. | From 5d3abdaa7faa116c89af43429b7deeca97aa9d59 Mon Sep 17 00:00:00 2001 From: pastasfuture Date: Tue, 16 Mar 2021 13:23:56 -0700 Subject: [PATCH 34/34] Update Core/ShaderLibrary/DotsDeformation.hlsl.meta file with newly generated unique GUID. Fixes GUID conflict with the HDRP version of DotsDeformation.hlsl.meta --- .../ShaderLibrary/DotsDeformation.hlsl.meta | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/com.unity.render-pipelines.core/ShaderLibrary/DotsDeformation.hlsl.meta b/com.unity.render-pipelines.core/ShaderLibrary/DotsDeformation.hlsl.meta index e916b6c2752..f9ad7ae3ea0 100644 --- a/com.unity.render-pipelines.core/ShaderLibrary/DotsDeformation.hlsl.meta +++ b/com.unity.render-pipelines.core/ShaderLibrary/DotsDeformation.hlsl.meta @@ -1,9 +1,10 @@ fileFormatVersion: 2 -guid: 21e613ffd8f12d84b8e1ab498b178067 +guid: 77f492e3ea5a550419a4c41d15917d2e ShaderImporter: externalObjects: {} defaultTextures: [] nonModifiableTextures: [] + preprocessorOverride: 0 userData: assetBundleName: assetBundleVariant: