From c1200518140338d3784fe73331a277e97bb73aff Mon Sep 17 00:00:00 2001 From: Sascha Willems Date: Sat, 29 Mar 2025 13:22:09 +0100 Subject: [PATCH] Slang shaders for descriptor indexing sample --- .../descriptorindexing.slang | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 shaders/slang/descriptorindexing/descriptorindexing.slang diff --git a/shaders/slang/descriptorindexing/descriptorindexing.slang b/shaders/slang/descriptorindexing/descriptorindexing.slang new file mode 100644 index 00000000..c647a2cd --- /dev/null +++ b/shaders/slang/descriptorindexing/descriptorindexing.slang @@ -0,0 +1,43 @@ +/* Copyright (c) 2025, Sascha Willems + * + * SPDX-License-Identifier: MIT + * + */ + +struct VSInput +{ + float3 Pos : POSITION0; + float2 UV; + int TextureIndex; +}; + +struct Matrices { + float4x4 projection; + float4x4 view; + float4x4 model; +}; +ConstantBuffer matrices; +Sampler2D textures[]; + +struct VSOutput +{ + float4 Pos : SV_POSITION; + int TextureIndex; + float2 UV; +}; + +[shader("vertex")] +VSOutput vertexMain(VSInput input) +{ + VSOutput output; + output.UV = input.UV; + output.TextureIndex = input.TextureIndex; + output.Pos = mul(matrices.projection, mul(matrices.view, mul(matrices.model, float4(input.Pos.xyz, 1.0)))); + return output; +} + +[shader("fragment")] +float4 fragmentMain(VSOutput input) : SV_TARGET +{ + return textures[NonUniformResourceIndex(input.TextureIndex)].Sample(input.UV); +} \ No newline at end of file