Add slang shader for shadow mapping and shadow mapping cascades sample
This commit is contained in:
parent
126231756a
commit
153aa3b932
7 changed files with 436 additions and 8 deletions
46
shaders/slang/shadowmappingcascade/depthpass.slang
Normal file
46
shaders/slang/shadowmappingcascade/depthpass.slang
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
/* Copyright (c) 2025, Sascha Willems
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
*/
|
||||
|
||||
struct VSInput
|
||||
{
|
||||
float3 Pos;
|
||||
float2 UV;
|
||||
};
|
||||
|
||||
struct VSOutput
|
||||
{
|
||||
float4 Pos : SV_POSITION;
|
||||
float2 UV;
|
||||
};
|
||||
|
||||
// todo: pass via specialization constant
|
||||
#define SHADOW_MAP_CASCADE_COUNT 4
|
||||
|
||||
struct UBO {
|
||||
float4x4 cascadeViewProjMat[SHADOW_MAP_CASCADE_COUNT];
|
||||
};
|
||||
[[vk::binding(3, 0)]] ConstantBuffer<UBO> ubo;
|
||||
|
||||
[[vk::binding(0, 1)]] Sampler2D colorMapSampler : register(s0, space1);
|
||||
|
||||
[shader("vertex")]
|
||||
VSOutput vertexMain(VSInput input, uniform float4 meshPosition, uniform uint cascadeIndex)
|
||||
{
|
||||
VSOutput output;
|
||||
output.UV = input.UV;
|
||||
float3 pos = input.Pos + meshPosition.xyz;
|
||||
output.Pos = mul(ubo.cascadeViewProjMat[cascadeIndex], float4(pos, 1.0));
|
||||
return output;
|
||||
}
|
||||
|
||||
[shader("fragment")]
|
||||
void fragmentMain(VSOutput input)
|
||||
{
|
||||
float alpha = colorMapSampler.Sample(input.UV).a;
|
||||
if (alpha < 0.5) {
|
||||
clip(-1);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue