Added slang shaders for additional samples
This commit is contained in:
parent
829118736f
commit
834ee9ed83
5 changed files with 271 additions and 0 deletions
54
shaders/slang/multithreading/phong.slang
Normal file
54
shaders/slang/multithreading/phong.slang
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
/* 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;
|
||||
};
|
||||
|
||||
[shader("vertex")]
|
||||
VSOutput vertexMain(VSInput input, uniform float4x4 mvp, uniform float3 color)
|
||||
{
|
||||
VSOutput output;
|
||||
if ((input.Color.r == 1.0) && (input.Color.g == 0.0) && (input.Color.b == 0.0))
|
||||
{
|
||||
output.Color = color;
|
||||
}
|
||||
else
|
||||
{
|
||||
output.Color = input.Color;
|
||||
}
|
||||
output.Pos = mul(mvp, float4(input.Pos.xyz, 1.0));
|
||||
float4 pos = mul(mvp, float4(input.Pos, 1.0));
|
||||
output.Normal = mul((float3x3)mvp, input.Normal);
|
||||
float3 lPos = float3(0.0, 0.0, 0.0);
|
||||
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);
|
||||
float3 diffuse = max(dot(N, L), 0.0) * input.Color;
|
||||
float3 specular = pow(max(dot(R, V), 0.0), 8.0) * float3(0.75, 0.75, 0.75);
|
||||
return float4(diffuse + specular, 1.0);
|
||||
}
|
||||
58
shaders/slang/multithreading/starsphere.slang
Normal file
58
shaders/slang/multithreading/starsphere.slang
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
/* Copyright (c) 2025, Sascha Willems
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#define HASHSCALE3 float3(443.897, 441.423, 437.195)
|
||||
#define STARFREQUENCY 0.01
|
||||
|
||||
// Hash function by Dave Hoskins (https://www.shadertoy.com/view/4djSRW)
|
||||
float hash33(float3 p3)
|
||||
{
|
||||
p3 = frac(p3 * HASHSCALE3);
|
||||
p3 += dot(p3, p3.yxz+float3(19.19, 19.19, 19.19));
|
||||
return frac((p3.x + p3.y)*p3.z + (p3.x+p3.z)*p3.y + (p3.y+p3.z)*p3.x);
|
||||
}
|
||||
|
||||
float3 starField(float3 pos)
|
||||
{
|
||||
float3 color = float3(0.0, 0.0, 0.0);
|
||||
float threshhold = (1.0 - STARFREQUENCY);
|
||||
float rnd = hash33(pos);
|
||||
if (rnd >= threshhold)
|
||||
{
|
||||
float starCol = pow((rnd - threshhold) / (1.0 - threshhold), 16.0);
|
||||
color += starCol.xxx;
|
||||
}
|
||||
return color;
|
||||
}
|
||||
|
||||
struct VSInput
|
||||
{
|
||||
float3 Pos;
|
||||
}
|
||||
|
||||
struct VSOutput
|
||||
{
|
||||
float4 Pos : SV_POSITION;
|
||||
float3 UVW;
|
||||
};
|
||||
|
||||
[shader("vertex")]
|
||||
VSOutput vertexMain(VSInput input, uniform float4x4 mvp)
|
||||
{
|
||||
VSOutput output;
|
||||
output.UVW = input.Pos;
|
||||
output.Pos = mul(mvp, float4(input.Pos.xyz, 1.0));
|
||||
return output;
|
||||
}
|
||||
|
||||
[shader("fragment")]
|
||||
float4 fragmentMain(VSOutput input)
|
||||
{
|
||||
// Fake atmosphere at the bottom
|
||||
float3 atmosphere = clamp(float3(0.1, 0.15, 0.4) * (input.UVW.y + 0.25), 0.0, 1.0);
|
||||
float3 color = starField(input.UVW) + atmosphere;
|
||||
return float4(color, 1.0);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue