diff --git a/engine/rend/build.zig b/engine/rend/build.zig index e4aedbd..a140fdb 100644 --- a/engine/rend/build.zig +++ b/engine/rend/build.zig @@ -32,6 +32,7 @@ pub fn build(b: *std.Build) void { } sdl3.shaderDefintion(b, mod, "../../lib/sdl3", optimize, "sample.vert", b.path("shaders/sample.vert.json")); + sdl3.shaderDefintion(b, mod, "../../lib/sdl3", optimize, "meshes.vert", b.path("shaders/meshes.vert.json")); // ========== tests ========== const tests = b.addTest(.{ diff --git a/engine/rend/shaders/meshes.vert.hlsl b/engine/rend/shaders/meshes.vert.hlsl new file mode 100644 index 0000000..d0c8af0 --- /dev/null +++ b/engine/rend/shaders/meshes.vert.hlsl @@ -0,0 +1,34 @@ +struct Input +{ + float3 Position : TEXCOORD0; + float2 TexCoord : TEXCOORD1; + uint InstanceIndex : SV_InstanceID; +}; + +struct Output +{ + float2 TexCoord : TEXCOORD0; + float4 Position : SV_Position; +}; + +struct Scene +{ + float4x4 Model; +}; + +StructuredBuffer scene: register(t0, space0); + +cbuffer Uniforms : register(b0, space1) +{ + float4x4 ViewProjection; + float time; +}; + +Output main(Input input) +{ + Output output; + output.TexCoord = input.TexCoord; + + output.Position = mul(ViewProjection, mul(float4(input.Position, 1.0), scene[input.InstanceIndex].Model)); + return output; +} diff --git a/engine/rend/shaders/meshes.vert.json b/engine/rend/shaders/meshes.vert.json new file mode 100644 index 0000000..bd492c3 --- /dev/null +++ b/engine/rend/shaders/meshes.vert.json @@ -0,0 +1,94 @@ +{ + "entryPoints" : [ + { + "name" : "main", + "mode" : "vert" + } + ], + "types" : { + "_8" : { + "name" : "Scene", + "members" : [ + { + "name" : "Model", + "type" : "mat4", + "offset" : 0, + "matrix_stride" : 16, + "row_major" : true + } + ] + }, + "_7" : { + "name" : "type.StructuredBuffer.Scene", + "members" : [ + { + "name" : "_m0", + "type" : "_8", + "array" : [ + 0 + ], + "array_size_is_literal" : [ + true + ], + "offset" : 0, + "array_stride" : 64 + } + ] + }, + "_10" : { + "name" : "type.Uniforms", + "members" : [ + { + "name" : "ViewProjection", + "type" : "mat4", + "offset" : 0, + "matrix_stride" : 16, + "row_major" : true + }, + { + "name" : "time", + "type" : "float", + "offset" : 64 + } + ] + } + }, + "inputs" : [ + { + "type" : "vec3", + "name" : "in.var.TEXCOORD0", + "location" : 0 + }, + { + "type" : "vec2", + "name" : "in.var.TEXCOORD1", + "location" : 1 + } + ], + "outputs" : [ + { + "type" : "vec2", + "name" : "out.var.TEXCOORD0", + "location" : 0 + } + ], + "ssbos" : [ + { + "type" : "_7", + "name" : "scene", + "readonly" : true, + "block_size" : 0, + "set" : 0, + "binding" : 0 + } + ], + "ubos" : [ + { + "type" : "_10", + "name" : "type.Uniforms", + "block_size" : 68, + "set" : 1, + "binding" : 0 + } + ] +} \ No newline at end of file diff --git a/projects/content/_shaders/dxil/meshes.vert.dxil b/projects/content/_shaders/dxil/meshes.vert.dxil new file mode 100644 index 0000000..1081683 Binary files /dev/null and b/projects/content/_shaders/dxil/meshes.vert.dxil differ diff --git a/projects/content/_shaders/msl/meshes.vert.msl b/projects/content/_shaders/msl/meshes.vert.msl new file mode 100644 index 0000000..b96b908 --- /dev/null +++ b/projects/content/_shaders/msl/meshes.vert.msl @@ -0,0 +1,41 @@ +#include +#include + +using namespace metal; + +struct Scene +{ + float4x4 Model; +}; + +struct type_StructuredBuffer_Scene +{ + Scene _m0[1]; +}; + +struct type_Uniforms +{ + float4x4 ViewProjection; + float time; +}; + +struct main0_out +{ + float2 out_var_TEXCOORD0 [[user(locn0)]]; + float4 gl_Position [[position]]; +}; + +struct main0_in +{ + float3 in_var_TEXCOORD0 [[attribute(0)]]; + float2 in_var_TEXCOORD1 [[attribute(1)]]; +}; + +vertex main0_out main0(main0_in in [[stage_in]], constant type_Uniforms& Uniforms [[buffer(0)]], const device type_StructuredBuffer_Scene& scene [[buffer(1)]], uint gl_InstanceIndex [[instance_id]]) +{ + main0_out out = {}; + out.out_var_TEXCOORD0 = in.in_var_TEXCOORD1; + out.gl_Position = Uniforms.ViewProjection * (float4(in.in_var_TEXCOORD0, 1.0) * scene._m0[gl_InstanceIndex].Model); + return out; +} + diff --git a/projects/content/_shaders/spv/meshes.vert.spv b/projects/content/_shaders/spv/meshes.vert.spv new file mode 100644 index 0000000..c0f9714 Binary files /dev/null and b/projects/content/_shaders/spv/meshes.vert.spv differ