Skip to content

Commit ac5b927

Browse files
hedvigpastasfuture
authored andcommitted
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 Add front buffer index to access deformed vertices of current/previous frame. Actually get the the vertex position of the current frame when rendering the object itself. d3d debug pragma for HDTarget Remove skin setting component Apply skinning in motion vec pass, rename function Add motion vectors to unity instancing properties Remove compute deformation node Enable vertexID when DOTS_INSTANCING_ON is defined Remove manual adding of vertex id and defines in HD shader passes Remove skinning include and define Remove compute mesh index property when dots instancing is not defined Shader cleanup for dots deformations Rename shader file for dots skinning functions Remove changes from HDShaderPasses Remove formatting issues Remove include define Remove all changes from HDShaderPasses Remove debug pragma Update some comments Also skin vertices even if motion vectors are not skinned Remove duplicated define Add compute mesh index to URP shader variables. Add function to fetch vertices from compute buffer in ShaderVariablesFunctions Rename some functions, move fetching to different file Rename deformation function for HDRP Keep vertex ID as optional when hybrid v2 is not used Remove formatting from HDTarget Updated changelogs to be more descriptive. Rename material property Add dots skinning function to URP passes PBR-Forward/GBuffer, Lit-Forward/GBuffer, Depth/DepthNormal, ShadowCaster, Unlit, PostProcessing, ScreenSpaceShadows, SimpleLit-Forward/GBiffer, PreviewPass Remove modulus from deform vertex function Remove modulus, change to uints Remove documentation for Compute Deformation Node
1 parent 91a403a commit ac5b927

37 files changed

+311
-190
lines changed
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
#if defined(DOTS_INSTANCING_ON)
2+
struct DeformedVertexData
3+
{
4+
float3 Position;
5+
float3 Normal;
6+
float3 Tangent;
7+
};
8+
9+
int _HybridDeformedVertexStreamIndex;
10+
uniform StructuredBuffer<DeformedVertexData> _DeformedMeshData;
11+
uniform StructuredBuffer<DeformedVertexData> _PreviousFrameDeformedMeshData;
12+
13+
// Reads vertex data for compute skinned meshes in Hybdrid Renderer
14+
void FetchComputeVertexData(inout float3 pos, inout float3 nrm, inout float4 tan, in uint vertexID)
15+
{
16+
// x,y = current and previous frame indices
17+
// z = deformation check (0 = no deformation, 1 = has deformation)
18+
// w = skinned motion vectors
19+
const int4 deformProperty = asint(unity_DOTSDeformationParams);
20+
const int doSkinning = deformProperty.z;
21+
if (doSkinning == 1)
22+
{
23+
const int streamIndex = _HybridDeformedVertexStreamIndex;
24+
const int startIndex = deformProperty[streamIndex];
25+
const DeformedVertexData vertexData = _DeformedMeshData[startIndex + vertexID];
26+
27+
pos = vertexData.Position;
28+
nrm = vertexData.Normal;
29+
tan = float4(vertexData.Tangent, 0);
30+
}
31+
}
32+
33+
void FetchComputeVertexPosNrm(inout float3 pos, inout float3 nrm, in uint vertexID)
34+
{
35+
// x,y = current and previous frame indices
36+
// z = deformation check (0 = no deformation, 1 = has deformation)
37+
// w = skinned motion vectors
38+
const int4 deformProperty = asint(unity_DOTSDeformationParams);
39+
const int doSkinning = deformProperty.z;
40+
if (doSkinning == 1)
41+
{
42+
const int streamIndex = _HybridDeformedVertexStreamIndex;
43+
const int startIndex = deformProperty[streamIndex];
44+
const DeformedVertexData vertexData = _DeformedMeshData[startIndex + vertexID];
45+
46+
pos = vertexData.Position;
47+
nrm = vertexData.Normal;
48+
}
49+
}
50+
51+
void FetchComputeVertexNormal(inout float3 normal, in uint vertexID)
52+
{
53+
const int4 deformProperty = asint(unity_DOTSDeformationParams);
54+
const int doSkinning = deformProperty.z;
55+
if (doSkinning == 1)
56+
{
57+
const int streamIndex = _HybridDeformedVertexStreamIndex;
58+
const int startIndex = deformProperty[streamIndex];
59+
60+
normal = _DeformedMeshData[startIndex + vertexID].Normal;
61+
}
62+
}
63+
64+
void FetchComputeVertexPosition(inout float3 position, in uint vertexID)
65+
{
66+
const int4 deformProperty = asint(unity_DOTSDeformationParams);
67+
const int doSkinning = deformProperty.z;
68+
if (doSkinning == 1)
69+
{
70+
const int streamIndex = _HybridDeformedVertexStreamIndex;
71+
const int startIndex = deformProperty[streamIndex];
72+
73+
position = _DeformedMeshData[startIndex + vertexID].Position;
74+
}
75+
}
76+
77+
void FetchComputeVertexPosition(inout float4 position, in uint vertexID)
78+
{
79+
FetchComputeVertexPosition(position.xyz, vertexID);
80+
}
81+
#endif

com.unity.render-pipelines.core/ShaderLibrary/DotsDeformation.hlsl.meta

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

com.unity.render-pipelines.high-definition/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ The version number for this package has increased due to a version update of a r
1616
- Added light unit slider for automatic and automatic histrogram exposure limits.
1717
- Added View Bias for mesh decals.
1818
- Added support for the PlayStation 5 platform.
19+
- Added support for skinned motionvectors when using Hybrid Renderer
1920

2021
### Fixed
2122
- Fixed computation of geometric normal in path tracing (case 1293029).
@@ -108,6 +109,7 @@ The version number for this package has increased due to a version update of a r
108109
- Transparent materials created by the Model Importer are set to not cast shadows. ( case 1295747)
109110
- Change some light unit slider value ranges to better reflect the lighting scenario.
110111
- Change the tooltip for color shadows and semi-transparent shadows (case 1307704).
112+
- Compute Deformation Node no longer needs to be added manually in Shader Graph for skinning to work with Hybrid Renderer V2.
111113

112114
## [10.2.1] - 2020-11-30
113115

com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/HDShaderPasses.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,7 @@ RenderStateCollection GenerateRenderState()
357357
{
358358
var renderState = new RenderStateCollection();
359359
renderState.Add(CoreRenderStates.MotionVectors);
360+
360361
return renderState;
361362
}
362363

com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/HDStructFields.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,13 @@ public struct AttributesMesh
2828
"COLOR", subscriptOptions : StructFieldOptions.Optional);
2929
public static FieldDescriptor instanceID = new FieldDescriptor(AttributesMesh.name, "instanceID", "", ShaderValueType.Uint,
3030
"INSTANCEID_SEMANTIC", "UNITY_ANY_INSTANCING_ENABLED");
31+
#if ENABLE_HYBRID_RENDERER_V2
32+
public static FieldDescriptor vertexID = new FieldDescriptor(AttributesMesh.name, "vertexID", "", ShaderValueType.Uint,
33+
"SV_VertexID", "DOTS_INSTANCING_ON");
34+
#else
3135
public static FieldDescriptor vertexID = new FieldDescriptor(AttributesMesh.name, "vertexID", "ATTRIBUTES_NEED_VERTEXID", ShaderValueType.Uint,
3236
"SV_VertexID", subscriptOptions: StructFieldOptions.Optional);
37+
#endif
3338
}
3439

3540
public struct VaryingsMeshToPS

com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1339,6 +1339,8 @@ void UpdateShaderVariablesGlobalCB(HDCamera hdCamera, CommandBuffer cmd)
13391339
m_ShaderVariablesGlobalCB._EnableRecursiveRayTracing = 0;
13401340
m_ShaderVariablesGlobalCB._SpecularOcclusionBlend = 1.0f;
13411341
}
1342+
1343+
m_ShaderVariablesGlobalCB._HybridDeformedVertexStreamIndex = UnityEngine.Time.frameCount & 1;
13421344

13431345
ConstantBuffer.PushGlobal(cmd, m_ShaderVariablesGlobalCB, HDShaderIDs._ShaderVariablesGlobal);
13441346
}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
#if defined(DOTS_INSTANCING_ON)
2+
struct DeformedVertexData
3+
{
4+
float3 Position;
5+
float3 Normal;
6+
float3 Tangent;
7+
};
8+
9+
uniform StructuredBuffer<DeformedVertexData> _DeformedMeshData;
10+
uniform StructuredBuffer<DeformedVertexData> _PreviousFrameDeformedMeshData;
11+
12+
// Reads vertex data for compute skinned meshes in Hybdrid Renderer
13+
void FetchComputeVertexData(inout AttributesMesh input)
14+
{
15+
// x,y = current and previous frame indices
16+
// z = deformation check (0 = no deformation, 1 = has deformation)
17+
// w = skinned motion vectors
18+
const int4 deformProperty = asint(unity_DOTSDeformationParams);
19+
const int doSkinning = deformProperty.z;
20+
if (doSkinning == 1)
21+
{
22+
const uint streamIndex = _HybridDeformedVertexStreamIndex;
23+
const uint startIndex = deformProperty[streamIndex];
24+
const DeformedVertexData vertexData = _DeformedMeshData[startIndex + input.vertexID];
25+
26+
input.positionOS = vertexData.Position;
27+
#ifdef ATTRIBUTES_NEED_NORMAL
28+
input.normalOS = vertexData.Normal;
29+
#endif
30+
#ifdef ATTRIBUTES_NEED_TANGENT
31+
input.tangentOS = float4(vertexData.Tangent, 0);
32+
#endif
33+
}
34+
}
35+
36+
// Reads vertex position for compute skinned meshes in Hybdrid Renderer
37+
// and also previous frame position if skinned motion vectors are used
38+
void FetchComputeVertexPosition(inout float3 currPos, inout float3 prevPos, uint vertexID)
39+
{
40+
// x,y = current and previous frame indices
41+
// z = deformation check (0 = no deformation, 1 = has deformation)
42+
// w = skinned motion vectors
43+
const int4 deformProperty = asint(unity_DOTSDeformationParams);
44+
const int computeSkin = deformProperty.z;
45+
const uint streamIndex = _HybridDeformedVertexStreamIndex;
46+
if (computeSkin == 1)
47+
{
48+
const uint currMeshStart = deformProperty[streamIndex];
49+
const uint currStreamIndex = _HybridDeformedVertexStreamIndex;
50+
currPos = _DeformedMeshData[currMeshStart + vertexID].Position;
51+
}
52+
53+
const int skinMotionVec = deformProperty.w;
54+
if (skinMotionVec == 1)
55+
{
56+
const uint prevStreamIndex = streamIndex ^ 1;
57+
const int prevMeshStart = deformProperty[prevStreamIndex];
58+
59+
if(prevMeshStart == -1)
60+
prevPos = _DeformedMeshData[prevMeshStart + vertexID].Position;
61+
else
62+
prevPos = _PreviousFrameDeformedMeshData[prevMeshStart + vertexID].Position;
63+
64+
}
65+
}
66+
#endif

com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/DotsDeformation.hlsl.meta

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/MotionVectorVertexShaderCommon.hlsl

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,6 @@ void MotionVectorPositionZBias(VaryingsToPS input)
8787

8888
PackedVaryingsType MotionVectorVS(inout VaryingsType varyingsType, AttributesMesh inputMesh, AttributesPass inputPass)
8989
{
90-
9190
#if !defined(TESSELLATION_ON)
9291
MotionVectorPositionZBias(varyingsType);
9392
#endif
@@ -107,15 +106,21 @@ PackedVaryingsType MotionVectorVS(inout VaryingsType varyingsType, AttributesMes
107106
{
108107
bool hasDeformation = unity_MotionVectorsParams.x > 0.0; // Skin or morph target
109108

110-
float3 effectivePositionOS = (hasDeformation ? inputPass.previousPositionOS : inputMesh.positionOS);
109+
float3 deformedPrevPos = inputPass.previousPositionOS;
110+
111+
#if defined(DOTS_INSTANCING_ON)
112+
FetchComputeVertexPosition(inputMesh.positionOS, deformedPrevPos, inputMesh.vertexID);
113+
#endif
114+
float3 effectivePositionOS = (hasDeformation) ? deformedPrevPos : inputMesh.positionOS;
115+
111116
#if defined(_ADD_PRECOMPUTED_VELOCITY)
112117
effectivePositionOS -= inputPass.precomputedVelocity;
113118
#endif
114119

115120
// Need to apply any vertex animation to the previous worldspace position, if we want it to show up in the motion vector buffer
116121
#if defined(HAVE_MESH_MODIFICATION)
117122
AttributesMesh previousMesh = inputMesh;
118-
previousMesh.positionOS = effectivePositionOS ;
123+
previousMesh.positionOS = effectivePositionOS;
119124

120125
previousMesh = ApplyMeshModification(previousMesh, _LastTimeParameters.xyz);
121126
float3 previousPositionRWS = TransformPreviousObjectToWorld(previousMesh.positionOS);

com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/VaryingMesh.hlsl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ struct AttributesMesh
2222
#ifdef ATTRIBUTES_NEED_COLOR
2323
float4 color : COLOR;
2424
#endif
25-
25+
#ifdef DOTS_INSTANCING_ON
26+
uint vertexID : SV_VertexID;
27+
#endif
2628
UNITY_VERTEX_INPUT_INSTANCE_ID
2729
};
2830

0 commit comments

Comments
 (0)