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..5fffd10078a --- /dev/null +++ b/com.unity.render-pipelines.core/ShaderLibrary/DotsDeformation.hlsl @@ -0,0 +1,81 @@ +#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 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) + // 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; + 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.core/ShaderLibrary/DotsDeformation.hlsl.meta b/com.unity.render-pipelines.core/ShaderLibrary/DotsDeformation.hlsl.meta new file mode 100644 index 00000000000..f9ad7ae3ea0 --- /dev/null +++ b/com.unity.render-pipelines.core/ShaderLibrary/DotsDeformation.hlsl.meta @@ -0,0 +1,10 @@ +fileFormatVersion: 2 +guid: 77f492e3ea5a550419a4c41d15917d2e +ShaderImporter: + externalObjects: {} + defaultTextures: [] + nonModifiableTextures: [] + preprocessorOverride: 0 + userData: + assetBundleName: + assetBundleVariant: diff --git a/com.unity.render-pipelines.high-definition/CHANGELOG.md b/com.unity.render-pipelines.high-definition/CHANGELOG.md index 391bb96688d..4cf035ac25c 100644 --- a/com.unity.render-pipelines.high-definition/CHANGELOG.md +++ b/com.unity.render-pipelines.high-definition/CHANGELOG.md @@ -21,6 +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 V2. ### Fixed - Fixed computation of geometric normal in path tracing (case 1293029). @@ -113,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.render-pipelines.high-definition/Editor/Material/ShaderGraph/HDStructFields.cs b/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/HDStructFields.cs index 21abde9304d..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.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.cs b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.cs index 25bcafaf651..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,6 +1339,8 @@ void UpdateShaderVariablesGlobalCB(HDCamera hdCamera, CommandBuffer cmd) m_ShaderVariablesGlobalCB._EnableRecursiveRayTracing = 0; m_ShaderVariablesGlobalCB._SpecularOcclusionBlend = 1.0f; } + + 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 new file mode 100644 index 00000000000..e2c56bc3afe --- /dev/null +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/DotsDeformation.hlsl @@ -0,0 +1,66 @@ +#if defined(DOTS_INSTANCING_ON) +struct DeformedVertexData +{ + float3 Position; + float3 Normal; + float3 Tangent; +}; + +uniform StructuredBuffer _DeformedMeshData; +uniform StructuredBuffer _PreviousFrameDeformedMeshData; + +// 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) + // w = skinned motion vectors + const int4 deformProperty = asint(unity_DOTSDeformationParams); + const int doSkinning = deformProperty.z; + if (doSkinning == 1) + { + const uint streamIndex = _HybridDeformedVertexStreamIndex; + const uint startIndex = deformProperty[streamIndex]; + const DeformedVertexData vertexData = _DeformedMeshData[startIndex + input.vertexID]; + + input.positionOS = vertexData.Position; +#ifdef ATTRIBUTES_NEED_NORMAL + input.normalOS = vertexData.Normal; +#endif +#ifdef ATTRIBUTES_NEED_TANGENT + input.tangentOS = float4(vertexData.Tangent, 0); +#endif + } +} + +// Reads vertex position for compute skinned meshes in Hybdrid Renderer +// 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 + // z = deformation check (0 = no deformation, 1 = has deformation) + // w = skinned motion vectors + const int4 deformProperty = asint(unity_DOTSDeformationParams); + const int computeSkin = deformProperty.z; + const uint streamIndex = _HybridDeformedVertexStreamIndex; + if (computeSkin == 1) + { + const uint currMeshStart = deformProperty[streamIndex]; + const uint currStreamIndex = _HybridDeformedVertexStreamIndex; + currPos = _DeformedMeshData[currMeshStart + vertexID].Position; + } + + const int skinMotionVec = deformProperty.w; + if (skinMotionVec == 1) + { + const uint prevStreamIndex = streamIndex ^ 1; + const int prevMeshStart = deformProperty[prevStreamIndex]; + + 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/DotsDeformation.hlsl.meta b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/DotsDeformation.hlsl.meta new file mode 100644 index 00000000000..e916b6c2752 --- /dev/null +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/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.high-definition/Runtime/RenderPipeline/ShaderPass/MotionVectorVertexShaderCommon.hlsl b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/MotionVectorVertexShaderCommon.hlsl index 3fbb684ce00..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 @@ -107,7 +106,13 @@ PackedVaryingsType MotionVectorVS(inout VaryingsType varyingsType, AttributesMes { bool hasDeformation = unity_MotionVectorsParams.x > 0.0; // Skin or morph target - float3 effectivePositionOS = (hasDeformation ? inputPass.previousPositionOS : inputMesh.positionOS); + float3 deformedPrevPos = inputPass.previousPositionOS; + +#if defined(DOTS_INSTANCING_ON) + FetchComputeVertexPosition(inputMesh.positionOS, deformedPrevPos, inputMesh.vertexID); +#endif + float3 effectivePositionOS = (hasDeformation) ? deformedPrevPos : inputMesh.positionOS; + #if defined(_ADD_PRECOMPUTED_VELOCITY) effectivePositionOS -= inputPass.precomputedVelocity; #endif @@ -115,7 +120,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/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.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/VertMesh.hlsl b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/VertMesh.hlsl index 9f2520d3287..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 @@ -126,6 +126,8 @@ VaryingsToDS InterpolateWithBaryCoordsToDS(VaryingsToDS input0, VaryingsToDS inp #define PackVaryingsType PackVaryingsToPS #endif +#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. VaryingsMeshType VertMesh(AttributesMesh input, float3 worldSpaceOffset) @@ -135,6 +137,10 @@ VaryingsMeshType VertMesh(AttributesMesh input, float3 worldSpaceOffset) UNITY_SETUP_INSTANCE_ID(input); UNITY_TRANSFER_INSTANCE_ID(input, output); +#if defined(DOTS_INSTANCING_ON) + FetchComputeVertexData(input); +#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..a7c0a1e1d5c 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl +++ b/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl @@ -372,6 +372,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_MotionVectorsParams) + UNITY_DOTS_INSTANCED_PROP(float4, unity_DOTSDeformationParams) UNITY_DOTS_INSTANCING_END(BuiltinPropertyMetadata) // Note: Macros for unity_ObjectToWorld and unity_WorldToObject are declared elsewhere @@ -391,7 +393,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_MotionVectorsParams UNITY_ACCESS_DOTS_INSTANCED_PROP_FROM_MACRO(float4, Metadata_unity_MotionVectorsParams) +#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.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 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 a884b754e73..de70b44b601 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,14 @@ 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) + FetchComputeVertexData(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..a06fb3e354b 100644 --- a/com.unity.render-pipelines.universal/Editor/ShaderGraph/Includes/PBRGBufferPass.hlsl +++ b/com.unity.render-pipelines.universal/Editor/ShaderGraph/Includes/PBRGBufferPass.hlsl @@ -32,9 +32,14 @@ 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) + FetchComputeVertexData(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..b4aad8ba04c 100644 --- a/com.unity.render-pipelines.universal/Editor/ShaderGraph/Includes/ShadowCasterPass.hlsl +++ b/com.unity.render-pipelines.universal/Editor/ShaderGraph/Includes/ShadowCasterPass.hlsl @@ -1,9 +1,14 @@ #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) + FetchComputeVertexData(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/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/ShaderLibrary/UniversalDOTSInstancing.hlsl b/com.unity.render-pipelines.universal/ShaderLibrary/UniversalDOTSInstancing.hlsl index 202173d5b18..6725daced41 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_DOTSDeformationParams) 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_DOTSDeformationParams UNITY_ACCESS_DOTS_INSTANCED_PROP_FROM_MACRO(float4, Metadata_unity_DOTSDeformationParams) #endif #endif 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/CHANGELOG.md b/com.unity.shadergraph/CHANGELOG.md index 40a966b7494..7bc7850c5f2 100644 --- a/com.unity.shadergraph/CHANGELOG.md +++ b/com.unity.shadergraph/CHANGELOG.md @@ -25,6 +25,9 @@ The version number for this package has increased due to a version update of a r - 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 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] - All textures in a ShaderGraph, even those not used, will now be pulled into an Exported Package [1283902] 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. | 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: diff --git a/com.unity.shadergraph/Editor/Generation/Descriptors/PragmaDescriptor.cs b/com.unity.shadergraph/Editor/Generation/Descriptors/PragmaDescriptor.cs index 7fd170c9467..0b784b2c025 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 { diff --git a/com.unity.shadergraph/Editor/Generation/TargetResources/StructFields.cs b/com.unity.shadergraph/Editor/Generation/TargetResources/StructFields.cs index dcd2f04cc96..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 @@ -57,6 +62,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); } 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; }