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,57 @@
/* Copyright (c) 2025, Sascha Willems
*
* SPDX-License-Identifier: MIT
*
*/
struct VSInput
{
float3 Pos;
float3 Normal;
float3 Color;
};
struct VSOutput
{
float4 Pos : SV_POSITION;
float3 Normal;
float3 Color;
float3 ViewVec;
float3 LightVec;
};
struct UBO
{
float4x4 projection;
float4x4 model;
float4 lightPos;
};
ConstantBuffer<UBO> ubo;
[shader("vertex")]
VSOutput vertexMain(VSInput input)
{
VSOutput output;
output.Normal = input.Normal;
output.Color = input.Color;
output.Pos = mul(ubo.projection, mul(ubo.model, float4(input.Pos.xyz, 1.0)));
float4 pos = mul(ubo.model, float4(input.Pos, 1.0));
output.Normal = mul((float4x3)ubo.model, input.Normal).xyz;
float3 lPos = mul((float4x3)ubo.model, ubo.lightPos.xyz).xyz;
output.LightVec = lPos - pos.xyz;
output.ViewVec = -pos.xyz;
return output;
}
[shader("fragment")]
float4 fragmentMain(VSOutput input)
{
float3 N = normalize(input.Normal);
float3 L = normalize(input.LightVec);
float3 V = normalize(input.ViewVec);
float3 R = reflect(-L, N);
float diffuse = max(dot(N, L), 0.0);
float3 specular = pow(max(dot(R, V), 0.0), 16.0) * float3(0.75, 0.75, 0.75);
return float4(diffuse * input.Color + specular, 1.0);
}

View file

@ -0,0 +1,37 @@
/* Copyright (c) 2025, Sascha Willems
*
* SPDX-License-Identifier: MIT
*
*/
struct VSInput
{
float2 Pos;
float2 UV;
float4 Color;
};
struct VSOutput
{
float4 Pos : SV_POSITION;
float2 UV;
float4 Color;
};
Sampler2D fontSampler;
[shader("vertex")]
VSOutput vertexMain(VSInput input, uniform float2 scale, uniform float2 translate)
{
VSOutput output;
output.UV = input.UV;
output.Color = input.Color;
output.Pos = float4(input.Pos * scale + translate, 0.0, 1.0);
return output;
}
[shader("fragment")]
float4 fragmentMain(VSOutput input)
{
return input.Color * fontSampler.Sample(input.UV);
}