@@ -63,6 +63,7 @@ struct VertexOutput
6363#if defined(VERTEX_COLORS) || defined(PER_VERTEX_LIGHTING)
6464 float4 color;
6565#endif
66+
6667 uint instanceID;
6768};
6869
@@ -75,31 +76,31 @@ struct Input
7576 float3 position : POSITION;
7677 float2 coords : TEXCOORD0;
7778 float3 normal : NORMAL;
79+
7880#ifdef NORMALMAP
7981 float3 tangent : TANGENT;
8082 float3 bitangent : BITANGENT;
8183#endif
84+
8285#if defined(VERTEX_COLORS) || defined(PER_VERTEX_LIGHTING)
8386 float4 color : COLOR0;
8487#endif
88+
8589#ifdef SKINNING
8690 float4 indices : BLENDINDICES;
8791 float4 weights : BLENDWEIGHTS;
8892#endif
93+
94+ uint baseInstance : SV_StartInstanceLocation;
95+ uint instanceID : SV_InstanceID;
8996};
9097
9198[shader("vertex")]
92- VertexOutput VertexMain(Input input, uint instanceID : SV_InstanceID )
99+ VertexOutput VertexMain(Input input)
93100{
94101 VertexOutput output;
95102
96- float4x4 model;
97-
98- #ifdef INSTANCING
99- model = StapleGetInstancedTransform(instanceID);
100- #else
101- model = world;
102- #endif
103+ float4x4 model = StapleWorldMatrix(input.baseInstance, input.instanceID);
103104
104105#ifdef SKINNING
105106 model = StapleGetSkinningMatrix(model, input.indices, input.weights);
@@ -126,7 +127,7 @@ VertexOutput VertexMain(Input input, uint instanceID : SV_InstanceID)
126127 output.lightNormal = StapleLightNormal(input.normal, model);
127128#endif
128129
129- output.instanceID = instanceID;
130+ output.instanceID = input. instanceID;
130131
131132#if defined(LIT) && defined(PER_VERTEX_LIGHTING)
132133 output.color = float4(diffuseColor.rgb * StapleProcessLights(output.worldPosition, output.lightNormal), diffuseColor.a);
0 commit comments