Add slang shaders for additional samples
This commit is contained in:
parent
4df49dba71
commit
0a6c03b58c
5 changed files with 235 additions and 6 deletions
58
shaders/slang/geometryshader/mesh.slang
Normal file
58
shaders/slang/geometryshader/mesh.slang
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
/* Copyright (c) 2025, Sascha Willems
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
*/
|
||||
|
||||
struct VSInput
|
||||
{
|
||||
float4 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;
|
||||
};
|
||||
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, input.Pos));
|
||||
|
||||
float4 pos = mul(ubo.model, float4(input.Pos.xyz, 1.0));
|
||||
output.Normal = mul((float4x3)ubo.model, input.Normal).xyz;
|
||||
|
||||
float3 lightPos = float3(1.0f, -1.0f, 1.0f);
|
||||
output.LightVec = lightPos.xyz - 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);
|
||||
float3 ambient = float3(0.1, 0.1, 0.1);
|
||||
float3 diffuse = max(dot(N, L), 0.0) * float3(1.0, 1.0, 1.0);
|
||||
float3 specular = pow(max(dot(R, V), 0.0), 16.0) * float3(0.75, 0.75, 0.75);
|
||||
return float4((ambient + diffuse) * input.Color.rgb + specular, 1.0);
|
||||
}
|
||||
68
shaders/slang/geometryshader/normaldebug.slang
Normal file
68
shaders/slang/geometryshader/normaldebug.slang
Normal file
|
|
@ -0,0 +1,68 @@
|
|||
/* Copyright (c) 2025, Sascha Willems
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
*/
|
||||
|
||||
struct VSInput
|
||||
{
|
||||
float3 Pos;
|
||||
float3 Normal;
|
||||
};
|
||||
|
||||
struct VSOutput
|
||||
{
|
||||
float4 Pos : POSITION0;
|
||||
float3 Normal;
|
||||
};
|
||||
|
||||
struct GSOutput
|
||||
{
|
||||
float4 Pos : SV_POSITION;
|
||||
float3 Color;
|
||||
};
|
||||
|
||||
struct UBO
|
||||
{
|
||||
float4x4 projection;
|
||||
float4x4 model;
|
||||
};
|
||||
ConstantBuffer<UBO> ubo;
|
||||
|
||||
[shader("vertex")]
|
||||
VSOutput vertexMain(VSInput input)
|
||||
{
|
||||
VSOutput output;
|
||||
output.Normal = input.Normal;
|
||||
output.Pos = float4(input.Pos.xyz, 1.0);
|
||||
return output;
|
||||
}
|
||||
|
||||
[shader("geometry")]
|
||||
[maxvertexcount(6)]
|
||||
void geometryMain(triangle VSOutput input[3], inout LineStream<GSOutput> outStream)
|
||||
{
|
||||
float normalLength = 0.02;
|
||||
for(int i=0; i<3; i++)
|
||||
{
|
||||
float3 pos = input[i].Pos.xyz;
|
||||
float3 normal = input[i].Normal.xyz;
|
||||
|
||||
GSOutput output = (GSOutput)0;
|
||||
output.Pos = mul(ubo.projection, mul(ubo.model, float4(pos, 1.0)));
|
||||
output.Color = float3(1.0, 0.0, 0.0);
|
||||
outStream.Append( output );
|
||||
|
||||
output.Pos = mul(ubo.projection, mul(ubo.model, float4(pos + normal * normalLength, 1.0)));
|
||||
output.Color = float3(0.0, 0.0, 1.0);
|
||||
outStream.Append( output );
|
||||
|
||||
outStream.RestartStrip();
|
||||
}
|
||||
}
|
||||
|
||||
[shader("fragment")]
|
||||
float4 fragmentMain(GSOutput input)
|
||||
{
|
||||
return float4(input.Color, 1.0);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue