Add slang shaders for additional samples

This commit is contained in:
Sascha Willems 2025-05-04 17:23:23 +02:00
parent b3c032ef68
commit 7c115af4a3
8 changed files with 529 additions and 0 deletions

View file

@ -0,0 +1,52 @@
/* Copyright (c) 2025, Sascha Willems
*
* SPDX-License-Identifier: MIT
*
*/
struct VSOutput
{
float4 Pos : SV_POSITION;
};
[[vk::input_attachment_index(0)]] [[vk::binding(0)]] SubpassInput inputColor;
[[vk::input_attachment_index(1)]] [[vk::binding(1)]] SubpassInput inputDepth;
struct UBO {
float2 brightnessContrast;
float2 range;
int attachmentIndex;
};
ConstantBuffer<UBO> ubo;
float3 brightnessContrast(float3 color, float brightness, float contrast) {
return (color - 0.5) * contrast + 0.5 + brightness;
}
[shader("vertex")]
VSOutput vertexMain(uint VertexIndex: SV_VertexID)
{
VSOutput output;
output.Pos = float4(float2((VertexIndex << 1) & 2, VertexIndex & 2) * 2.0f - 1.0f, 0.0f, 1.0f);
return output;
}
[shader("fragment")]
float4 fragmentMain()
{
// Apply brightness and contrast filer to color input
if (ubo.attachmentIndex == 0) {
// Read color from previous color input attachment
float3 color = inputColor.SubpassLoad().rgb;
return float4(brightnessContrast(color, ubo.brightnessContrast[0], ubo.brightnessContrast[1]), 1.0);
}
// Visualize depth input range
if (ubo.attachmentIndex == 1) {
// Read depth from previous depth input attachment
float depth = inputDepth.SubpassLoad().r;
return float4((depth - ubo.range[0]) * 1.0 / (ubo.range[1] - ubo.range[0]).xxx, 1.0);
}
return float4(1.0);
}

View file

@ -0,0 +1,56 @@
/* Copyright (c) 2025, Sascha Willems
*
* SPDX-License-Identifier: MIT
*
*/
struct VSInput
{
float3 Pos;
float3 Color;
float3 Normal;
};
struct VSOutput
{
float4 Pos : SV_POSITION;
float3 Color;
float3 Normal;
float3 ViewVec;
float3 LightVec;
};
struct UBO {
float4x4 projection;
float4x4 model;
float4x4 view;
};
ConstantBuffer<UBO> ubo;
[shader("vertex")]
VSOutput vertexMain(VSInput input)
{
VSOutput output;
output.Pos = mul(ubo.projection, mul(ubo.view, mul(ubo.model, float4(input.Pos, 1.0))));
output.Color = input.Color;
output.Normal = input.Normal;
output.LightVec = float3(0.0f, 5.0f, 15.0f) - input.Pos;
output.ViewVec = -input.Pos.xyz;
return output;
}
[shader("fragment")]
float4 fragmentMain(VSOutput input)
{
// Toon shading color attachment output
float intensity = dot(normalize(input.Normal), normalize(input.LightVec));
float shade = 1.0;
shade = intensity < 0.5 ? 0.75 : shade;
shade = intensity < 0.35 ? 0.6 : shade;
shade = intensity < 0.25 ? 0.5 : shade;
shade = intensity < 0.1 ? 0.25 : shade;
return float4(input.Color * 3.0 * shade, 1.0);
// Depth attachment does not need to be explicitly written
}