Skip to content

Commit b1407a8

Browse files
[Rendering] WIP on Multidraw Indirect;
1 parent cd1eecb commit b1407a8

23 files changed

+744
-147
lines changed

BuiltinResources/Hidden/Shaders/Debug/NormalDebug.shader

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,24 +28,22 @@ struct Input
2828
{
2929
float3 position : POSITION;
3030
float3 normal : NORMAL;
31+
3132
#ifdef SKINNING
3233
float4 indices : BLENDINDICES;
3334
float4 weights : BLENDWEIGHTS;
3435
#endif
36+
37+
uint baseInstance : SV_StartInstanceLocation;
38+
uint instanceID : SV_InstanceID;
3539
};
3640

3741
[shader("vertex")]
38-
VertexOutput VertexMain(Input input, uint instanceID : SV_InstanceID)
42+
VertexOutput VertexMain(Input input)
3943
{
4044
VertexOutput output;
4145

42-
float4x4 model;
43-
44-
#ifdef INSTANCING
45-
model = StapleGetInstancedTransform(instanceID);
46-
#else
47-
model = world;
48-
#endif
46+
float4x4 model = StapleWorldMatrix(input.baseInstance, input.instanceID);
4947

5048
#ifdef SKINNING
5149
model = StapleGetSkinningMatrix(model, input.indices, input.weights);

BuiltinResources/Hidden/Shaders/Debug/TangentDebug.shader

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,24 +37,22 @@ struct Input
3737
#else
3838
float3 tangent : TANGENT;
3939
#endif
40+
4041
#ifdef SKINNING
4142
float4 indices : BLENDINDICES;
4243
float4 weights : BLENDWEIGHTS;
4344
#endif
45+
46+
uint baseInstance : SV_StartInstanceLocation;
47+
uint instanceID : SV_InstanceID;
4448
};
4549

4650
[shader("vertex")]
47-
VertexOutput VertexMain(Input input, uint instanceID : SV_InstanceID)
51+
VertexOutput VertexMain(Input input)
4852
{
4953
VertexOutput output;
5054

51-
float4x4 model;
52-
53-
#ifdef INSTANCING
54-
model = StapleGetInstancedTransform(instanceID);
55-
#else
56-
model = world;
57-
#endif
55+
float4x4 model = StapleWorldMatrix(input.baseInstance, input.instanceID);
5856

5957
#ifdef SKINNING
6058
model = StapleGetSkinningMatrix(model, input.indices, input.weights);

BuiltinResources/Hidden/Shaders/Default/SolidColor.shader

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,27 +36,25 @@ cbuffer Uniforms
3636
struct Input
3737
{
3838
float3 position : POSITION;
39+
3940
#ifdef SKINNING
4041
float4 indices : BLENDINDICES;
4142
float4 weights : BLENDWEIGHTS;
4243
#endif
44+
45+
uint baseInstance : SV_StartInstanceLocation;
46+
uint instanceID : SV_InstanceID;
4347
};
4448

4549
[shader("vertex")]
46-
VertexOutput VertexMain(Input input, uint instanceID : SV_InstanceID)
50+
VertexOutput VertexMain(Input input)
4751
{
4852
VertexOutput output;
4953

5054
float3 position = input.position;
5155
float4 color = mainColor;
5256

53-
float4x4 model;
54-
55-
#ifdef INSTANCING
56-
model = StapleGetInstancedTransform(instanceID);
57-
#else
58-
model = world;
59-
#endif
57+
float4x4 model = StapleWorldMatrix(input.baseInstance, input.instanceID);
6058

6159
#ifdef SKINNING
6260
model = StapleGetSkinningMatrix(model, input.indices, input.weights);

BuiltinResources/Hidden/Shaders/Default/Standard.shader

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -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);

BuiltinResources/Hidden/Shaders/Sprite/Sprite.shader

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ End Parameters
1212
Begin Input
1313
POSITION
1414
TEXCOORD0
15+
variant: SKINNING BLENDINDICES
16+
variant: SKINNING BLENDWEIGHTS
1517
End Input
1618

1719
Begin Common
@@ -37,6 +39,14 @@ struct Input
3739
{
3840
float3 position : POSITION;
3941
float2 coord : TEXCOORD0;
42+
43+
#ifdef SKINNING
44+
float4 indices : BLENDINDICES;
45+
float4 weights : BLENDWEIGHTS;
46+
#endif
47+
48+
uint baseInstance : SV_StartInstanceLocation;
49+
uint instanceID : SV_InstanceID;
4050
};
4151

4252
[shader("vertex")]
@@ -47,9 +57,15 @@ VertexOutput VertexMain(Input input)
4757
float3 position = input.position;
4858
float4 color = mainColor;
4959

60+
float4x4 model = StapleWorldMatrix(input.baseInstance, input.instanceID);
61+
62+
#ifdef SKINNING
63+
model = StapleGetSkinningMatrix(model, input.indices, input.weights);
64+
#endif
65+
5066
output.color = color;
5167
output.coord = input.coord;
52-
output.position = mul(ProjectionViewWorld(world), float4(position, 1.0));
68+
output.position = mul(ProjectionViewWorld(model), float4(position, 1.0));
5369

5470
return output;
5571
}

Engine/Staple.Core/Rendering/Mesh/Mesh+Internal.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -963,7 +963,7 @@ internal void MarkStaticMesh()
963963

964964
internal void UpdateStaticMeshData()
965965
{
966-
if(staticMeshEntries == null)
966+
if (staticMeshEntries == null)
967967
{
968968
var vertexCount = vertices.Length;
969969
var indexCount = indices.Length;
@@ -976,7 +976,7 @@ internal void UpdateStaticMeshData()
976976
{
977977
RenderSystem.Backend.StaticMeshData.Free(staticMeshEntries);
978978

979-
RenderSystem.Backend.StaticMeshData.Allocate(vertices.Length, indices.Length);
979+
staticMeshEntries = RenderSystem.Backend.StaticMeshData.Allocate(vertices.Length, indices.Length);
980980
}
981981

982982
if (RenderSystem.Backend.StaticMeshData.TryGetPositions(staticMeshEntries, out var positions, true))
@@ -1109,7 +1109,7 @@ internal void UpdateStaticMeshData()
11091109
{
11101110
for(var i = 0; i < meshIndices.Length; i++)
11111111
{
1112-
meshIndices[i] = (uint)indices[i];
1112+
meshIndices[i] = (uint)(indices[i] + staticMeshEntries.positionEntry.start);
11131113
}
11141114
}
11151115
}

Engine/Staple.Core/Rendering/Mesh/Mesh.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1147,8 +1147,8 @@ public void SetMeshData<T>(Span<T> meshData, VertexLayout vertexLayout) where T
11471147
/// </summary>
11481148
internal void UploadMeshData()
11491149
{
1150-
if (!changed ||
1151-
(!IsStaticMesh && !(vertexBuffer?.Disposed ?? true) && !(indexBuffer?.Disposed ?? true)))
1150+
if (!changed &&
1151+
(!IsStaticMesh && ((vertexBuffer?.Disposed ?? true) == false || (indexBuffer?.Disposed ?? true) == false)))
11521152
{
11531153
return;
11541154
}

0 commit comments

Comments
 (0)