Skip to content

Commit 9d14038

Browse files
[Rendering] WIP on SDLGPU;
1 parent f058442 commit 9d14038

33 files changed

+2072
-705
lines changed

BuiltinResources/Hidden/Shaders/Debug/TangentDebug.shader

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ Variants BITANGENT_COLOR
22

33
Begin Parameters
44

5-
variant: BITANGENT_COLOR uniform float tangentOrBitangent
5+
variant: BITANGENT_COLOR float tangentOrBitangent
66

77
End Parameters
88

BuiltinResources/Hidden/Shaders/Default/SolidColor.shader

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ Type VertexFragment
22

33
Begin Parameters
44

5-
uniform color mainColor
5+
color mainColor
66

77
End Parameters
88

BuiltinResources/Hidden/Shaders/Default/Standard.shader

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,19 @@ Variants VERTEX_COLORS, LIT, HALF_LAMBERT, PER_VERTEX_LIGHTING, NORMALMAP, CUTOU
66

77
Begin Parameters
88

9-
uniform vec3 viewPosition;
10-
uniform texture ambientOcclusionTexture
11-
uniform color diffuseColor = #FFFFFFFF
12-
uniform texture diffuseTexture = WHITE
13-
uniform texture displacementTexture
14-
uniform color emissiveColor
15-
uniform texture emissiveTexture
16-
uniform texture heightTexture
17-
variant: NORMALMAP uniform texture normalTexture
18-
uniform color specularColor
19-
uniform texture specularTexture
20-
variant: CUTOUT uniform float cutout
21-
uniform float alphaThreshold = 0.25
9+
float3 viewPosition;
10+
texture ambientOcclusionTexture
11+
color diffuseColor = #FFFFFFFF
12+
texture diffuseTexture = WHITE
13+
texture displacementTexture
14+
color emissiveColor
15+
texture emissiveTexture
16+
texture heightTexture
17+
variant: NORMALMAP texture normalTexture
18+
color specularColor
19+
texture specularTexture
20+
variant: CUTOUT float cutout
21+
float alphaThreshold = 0.25
2222

2323
End Parameters
2424

@@ -36,7 +36,6 @@ End Instancing
3636

3737
Begin Common
3838

39-
/*
4039
[[vk::binding(StapleBufferIndexCount, StapleUniformBufferSet)]]
4140
cbuffer Uniforms
4241
{
@@ -47,7 +46,6 @@ cbuffer Uniforms
4746
float cutout;
4847
float alphaThreshold;
4948
};
50-
*/
5149

5250
struct VertexOutput
5351
{

BuiltinResources/Hidden/Shaders/Sprite/Sprite.shader

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ Blend SrcAlpha OneMinusSrcAlpha
44

55
Begin Parameters
66

7-
uniform color mainColor
8-
uniform texture mainTexture
7+
color mainColor
8+
texture mainTexture
99

1010
End Parameters
1111

BuiltinResources/Hidden/Shaders/UI/imgui.shader

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Blend SrcAlpha OneMinusSrcAlpha
33

44
Begin Parameters
55

6-
uniform texture mainTexture
6+
texture mainTexture
77

88
End Parameters
99

Engine/Staple.Core/MessagePackGenerated/MessagePackGenerated.cs

Lines changed: 418 additions & 222 deletions
Large diffs are not rendered by default.

Engine/Staple.Core/Rendering/Animation/SkinnedMeshRenderSystem.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -315,11 +315,11 @@ void SetupMaterial()
315315

316316
lightSystem?.ApplyLightProperties(material, RenderSystem.CurrentCamera.Item2.Position, lighting);
317317

318-
var program = material.ShaderProgram;
319-
320318
var buffer = instance.boneBuffer;
321319

322-
renderState.program = program;
320+
renderState.shader = material.shader;
321+
322+
renderState.shaderVariant = material.ShaderVariantKey;
323323

324324
renderState.readOnlyBuffers = [(SkinningBufferIndex, buffer)];
325325

Engine/Staple.Core/Rendering/Graphics.cs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,8 @@ public static void RenderGeometry(VertexBuffer vertex, IndexBuffer index,
7575

7676
if(program != null)
7777
{
78-
renderState.program = program;
78+
renderState.shader = material.shader;
79+
renderState.shaderVariant = material.ShaderVariantKey;
7980

8081
lightSystem?.ApplyLightProperties(material, RenderSystem.CurrentCamera.Item2.Position, lighting);
8182

@@ -118,13 +119,16 @@ public static void RenderSimple<T>(Span<T> vertices, VertexLayout layout, Span<u
118119

119120
lightSystem?.ApplyMaterialLighting(material, lighting);
120121

121-
renderState.program = material.ShaderProgram;
122+
var program = material.ShaderProgram;
122123

123-
if (renderState.program == null)
124+
if (program == null)
124125
{
125126
return;
126127
}
127128

129+
renderState.shader = material.shader;
130+
renderState.shaderVariant = material.ShaderVariantKey;
131+
128132
lightSystem?.ApplyLightProperties(material, RenderSystem.CurrentCamera.Item2.Position, lighting);
129133

130134
RenderSystem.Backend.RenderTransient(vertices, layout, indices, renderState);
@@ -165,13 +169,16 @@ public static void RenderSimple<T>(Span<T> vertices, VertexLayout layout, Span<u
165169

166170
lightSystem?.ApplyMaterialLighting(material, lighting);
167171

168-
renderState.program = material.ShaderProgram;
172+
var program = material.ShaderProgram;
169173

170-
if (renderState.program == null)
174+
if (program == null)
171175
{
172176
return;
173177
}
174178

179+
renderState.shader = material.shader;
180+
renderState.shaderVariant = material.ShaderVariantKey;
181+
175182
lightSystem?.ApplyLightProperties(material, RenderSystem.CurrentCamera.Item2.Position, lighting);
176183

177184
RenderSystem.Backend.RenderTransient(vertices, layout, indices, renderState);

Engine/Staple.Core/Rendering/Lighting/LightSystem.cs

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
using System;
22
using System.Collections.Generic;
3-
using System.Linq;
43
using System.Numerics;
54
using System.Runtime.InteropServices;
65

@@ -19,6 +18,23 @@ public struct LightInstance
1918
public Vector3 padding;
2019
}
2120

21+
[StructLayout(LayoutKind.Sequential, Pack = 0)]
22+
private struct LightData
23+
{
24+
public Color ambientColor;
25+
public float lightCount;
26+
public Vector3 viewPosition;
27+
}
28+
29+
[StructLayout(LayoutKind.Sequential, Pack = 0)]
30+
private struct LightDetails
31+
{
32+
public LightType type;
33+
public Vector3 position;
34+
public Color diffuse;
35+
public Color specular;
36+
}
37+
2238
/// <summary>
2339
/// Limit to 16 lights
2440
/// </summary>
@@ -268,11 +284,11 @@ static bool HandlesValid(Span<ShaderHandle> handles)
268284
var lightSpotDirectionHandle = handles[6];
269285
var lightSpotValues = handles[7];
270286

271-
material.shader.SetVector3(viewPosHandle, cameraPosition);
272-
material.shader.SetColor(lightAmbientHandle, lightAmbient);
273-
material.shader.SetVector4(lightCountHandle, lightCountValue);
274-
material.shader.SetVector4(lightTypePositionHandle, cachedLightTypePositions);
275-
material.shader.SetVector4(lightDiffuseHandle, cachedLightDiffuse);
276-
material.shader.SetVector4(lightSpotDirectionHandle, cachedLightSpotDirection);
287+
material.shader.SetVector3(material.ShaderVariantKey, viewPosHandle, cameraPosition);
288+
material.shader.SetColor(material.ShaderVariantKey, lightAmbientHandle, lightAmbient);
289+
material.shader.SetVector4(material.ShaderVariantKey, lightCountHandle, lightCountValue);
290+
material.shader.SetVector4(material.ShaderVariantKey, lightTypePositionHandle, cachedLightTypePositions);
291+
material.shader.SetVector4(material.ShaderVariantKey, lightDiffuseHandle, cachedLightDiffuse);
292+
material.shader.SetVector4(material.ShaderVariantKey, lightSpotDirectionHandle, cachedLightSpotDirection);
277293
}
278294
}

0 commit comments

Comments
 (0)