From 5758b53a5e7de7dfcb5633bcc2449e21134ab082 Mon Sep 17 00:00:00 2001 From: Sascha Willems Date: Thu, 1 May 2025 11:34:11 +0200 Subject: [PATCH] Add slang shader for descriptor sets sample --- shaders/slang/descriptorsets/cube.slang | 51 +++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 shaders/slang/descriptorsets/cube.slang diff --git a/shaders/slang/descriptorsets/cube.slang b/shaders/slang/descriptorsets/cube.slang new file mode 100644 index 00000000..8a8b0ec9 --- /dev/null +++ b/shaders/slang/descriptorsets/cube.slang @@ -0,0 +1,51 @@ +/* Copyright (c) 2025, Sascha Willems + * + * SPDX-License-Identifier: MIT + * + */ + +struct VSInput +{ + float3 Pos; + float3 Normal; + float2 UV; + float3 Color; +}; + +struct VSOutput +{ + float4 Pos : SV_POSITION; + float3 Normal; + float3 Color; + float2 UV; +}; + +// Slang auto generates bindings by order of descriptors +// So the UBO is bound to slot 0, the sampler to slot 1 +// due to their order in the shader + +struct UBOMatrices { + float4x4 projection; + float4x4 view; + float4x4 model; +}; +ConstantBuffer uboMatrices; + +Sampler2D samplerColorMap; + +[shader("vertex")] +VSOutput vertexMain(VSInput input) +{ + VSOutput output; + output.Normal = input.Normal; + output.Color = input.Color; + output.UV = input.UV; + output.Pos = mul(uboMatrices.projection, mul(uboMatrices.view, mul(uboMatrices.model, float4(input.Pos.xyz, 1.0)))); + return output; +} + +[shader("fragment")] +float4 fragmentMain(VSOutput input) +{ + return samplerColorMap.Sample(input.UV) * float4(input.Color, 1.0); +} \ No newline at end of file