From ee535efc2fadeb7e944804339d9bdcb885b2f52c Mon Sep 17 00:00:00 2001 From: Sascha Willems Date: Wed, 21 May 2025 08:21:13 +0200 Subject: [PATCH] Added slang shaders for sparse resident textures sample --- .../sparseresidency.slang | 54 +++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 shaders/slang/texturesparseresidency/sparseresidency.slang diff --git a/shaders/slang/texturesparseresidency/sparseresidency.slang b/shaders/slang/texturesparseresidency/sparseresidency.slang new file mode 100644 index 00000000..6ad26c8a --- /dev/null +++ b/shaders/slang/texturesparseresidency/sparseresidency.slang @@ -0,0 +1,54 @@ +/* Copyright (c) 2025, Sascha Willems + * + * SPDX-License-Identifier: MIT + * + */ + +struct VSInput +{ + float3 Pos; + float3 Normal; + float2 UV; +}; + +struct VSOutput +{ + float4 Pos : SV_POSITION; + float2 UV; + float LodBias; +}; + +struct UBO +{ + float4x4 projection; + float4x4 model; + float4 viewPos; + float lodBias; +}; +ConstantBuffer ubo; + +Sampler2D samplerColor; + +[shader("vertex")] +VSOutput vertexMain(VSInput input) +{ + VSOutput output; + output.UV = input.UV; + output.LodBias = ubo.lodBias; + output.Pos = mul(ubo.projection, mul(ubo.model, float4(input.Pos.xyz, 1.0))); + return output; +} + +[shader("fragment")] +float4 fragmentMain(VSOutput input) +{ + // Check if texel is resident + uint status = 0; + float4 sampledColor = samplerColor.Sample(input.UV, int2(0, 0), input.LodBias, status); + bool texelResident = CheckAccessFullyMapped(status); + if (texelResident) { + return sampledColor; + } else { + return float4(0.0, 0.0, 0.0, 1.0); + } +} \ No newline at end of file