Skip to content

Commit ee535ef

Browse files
committed
Added slang shaders for sparse resident textures sample
1 parent 6183ad5 commit ee535ef

1 file changed

Lines changed: 54 additions & 0 deletions

File tree

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/* Copyright (c) 2025, Sascha Willems
2+
*
3+
* SPDX-License-Identifier: MIT
4+
*
5+
*/
6+
7+
struct VSInput
8+
{
9+
float3 Pos;
10+
float3 Normal;
11+
float2 UV;
12+
};
13+
14+
struct VSOutput
15+
{
16+
float4 Pos : SV_POSITION;
17+
float2 UV;
18+
float LodBias;
19+
};
20+
21+
struct UBO
22+
{
23+
float4x4 projection;
24+
float4x4 model;
25+
float4 viewPos;
26+
float lodBias;
27+
};
28+
ConstantBuffer<UBO> ubo;
29+
30+
Sampler2D samplerColor;
31+
32+
[shader("vertex")]
33+
VSOutput vertexMain(VSInput input)
34+
{
35+
VSOutput output;
36+
output.UV = input.UV;
37+
output.LodBias = ubo.lodBias;
38+
output.Pos = mul(ubo.projection, mul(ubo.model, float4(input.Pos.xyz, 1.0)));
39+
return output;
40+
}
41+
42+
[shader("fragment")]
43+
float4 fragmentMain(VSOutput input)
44+
{
45+
// Check if texel is resident
46+
uint status = 0;
47+
float4 sampledColor = samplerColor.Sample(input.UV, int2(0, 0), input.LodBias, status);
48+
bool texelResident = CheckAccessFullyMapped(status);
49+
if (texelResident) {
50+
return sampledColor;
51+
} else {
52+
return float4(0.0, 0.0, 0.0, 1.0);
53+
}
54+
}

0 commit comments

Comments
 (0)