Add slang shaders for additional samples
This commit is contained in:
parent
b3c032ef68
commit
7c115af4a3
8 changed files with 529 additions and 0 deletions
44
shaders/slang/indirectdraw/ground.slang
Normal file
44
shaders/slang/indirectdraw/ground.slang
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
/* Copyright (c) 2025, Sascha Willems
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
*/
|
||||
|
||||
struct VSInput
|
||||
{
|
||||
float4 Pos;
|
||||
float3 Normal;
|
||||
float2 UV;
|
||||
float3 Color;
|
||||
};
|
||||
|
||||
struct VSOutput
|
||||
{
|
||||
float4 Pos : SV_POSITION;
|
||||
float2 UV;
|
||||
};
|
||||
|
||||
struct UBO
|
||||
{
|
||||
float4x4 projection;
|
||||
float4x4 modelview;
|
||||
};
|
||||
ConstantBuffer<UBO> ubo;
|
||||
|
||||
[[vk::binding(2,0)]] Sampler2D samplerColor;
|
||||
|
||||
[shader("vertex")]
|
||||
VSOutput vertexMain(VSInput input)
|
||||
{
|
||||
VSOutput output;
|
||||
output.UV = input.UV * 32.0;
|
||||
output.Pos = mul(ubo.projection, mul(ubo.modelview, float4(input.Pos.xyz, 1.0)));
|
||||
return output;
|
||||
}
|
||||
|
||||
[shader("fragment")]
|
||||
float4 fragmentMain(VSOutput input)
|
||||
{
|
||||
float4 color = samplerColor.Sample(input.UV);
|
||||
return float4(color.rgb, 1.0);
|
||||
}
|
||||
104
shaders/slang/indirectdraw/indirectdraw.slang
Normal file
104
shaders/slang/indirectdraw/indirectdraw.slang
Normal file
|
|
@ -0,0 +1,104 @@
|
|||
/* Copyright (c) 2025, Sascha Willems
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
*/
|
||||
|
||||
struct VSInput
|
||||
{
|
||||
float4 Pos;
|
||||
float3 Normal;
|
||||
float2 UV;
|
||||
float3 Color;
|
||||
float3 instancePos;
|
||||
float3 instanceRot;
|
||||
float instanceScale;
|
||||
int instanceTexIndex;
|
||||
};
|
||||
|
||||
struct VSOutput
|
||||
{
|
||||
float4 Pos : SV_POSITION;
|
||||
float3 Normal;
|
||||
float3 Color;
|
||||
float3 UV;
|
||||
float3 ViewVec;
|
||||
float3 LightVec;
|
||||
};
|
||||
|
||||
struct UBO
|
||||
{
|
||||
float4x4 projection;
|
||||
float4x4 modelview;
|
||||
};
|
||||
ConstantBuffer<UBO> ubo;
|
||||
|
||||
Sampler2DArray samplerArray;
|
||||
|
||||
[shader("vertex")]
|
||||
VSOutput vertexMain(VSInput input)
|
||||
{
|
||||
VSOutput output;
|
||||
output.Color = input.Color;
|
||||
output.UV = float3(input.UV, input.instanceTexIndex);
|
||||
|
||||
float4x4 mx, my, mz;
|
||||
|
||||
// rotate around x
|
||||
float s = sin(input.instanceRot.x);
|
||||
float c = cos(input.instanceRot.x);
|
||||
|
||||
mx[0] = float4(c, s, 0.0, 0.0);
|
||||
mx[1] = float4(-s, c, 0.0, 0.0);
|
||||
mx[2] = float4(0.0, 0.0, 1.0, 0.0);
|
||||
mx[3] = float4(0.0, 0.0, 0.0, 1.0);
|
||||
|
||||
// rotate around y
|
||||
s = sin(input.instanceRot.y);
|
||||
c = cos(input.instanceRot.y);
|
||||
|
||||
my[0] = float4(c, 0.0, s, 0.0);
|
||||
my[1] = float4(0.0, 1.0, 0.0, 0.0);
|
||||
my[2] = float4(-s, 0.0, c, 0.0);
|
||||
my[3] = float4(0.0, 0.0, 0.0, 1.0);
|
||||
|
||||
// rot around z
|
||||
s = sin(input.instanceRot.z);
|
||||
c = cos(input.instanceRot.z);
|
||||
|
||||
mz[0] = float4(1.0, 0.0, 0.0, 0.0);
|
||||
mz[1] = float4(0.0, c, s, 0.0);
|
||||
mz[2] = float4(0.0, -s, c, 0.0);
|
||||
mz[3] = float4(0.0, 0.0, 0.0, 1.0);
|
||||
|
||||
float4x4 rotMat = mul(mz, mul(my, mx));
|
||||
|
||||
output.Normal = mul((float4x3)rotMat, input.Normal).xyz;
|
||||
|
||||
float4 pos = mul(rotMat, float4((input.Pos.xyz * input.instanceScale) + input.instancePos, 1.0));
|
||||
|
||||
output.Pos = mul(ubo.projection, mul(ubo.modelview, pos));
|
||||
|
||||
float4 wPos = mul(ubo.modelview, float4(pos.xyz, 1.0));
|
||||
float4 lPos = float4(0.0, -5.0, 0.0, 1.0);
|
||||
output.LightVec = lPos.xyz - pos.xyz;
|
||||
output.ViewVec = -pos.xyz;
|
||||
return output;
|
||||
}
|
||||
|
||||
[shader("fragment")]
|
||||
float4 fragmentMain(VSOutput input)
|
||||
{
|
||||
float4 color = samplerArray.Sample(input.UV);
|
||||
|
||||
if (color.a < 0.5)
|
||||
{
|
||||
clip(-1);
|
||||
}
|
||||
|
||||
float3 N = normalize(input.Normal);
|
||||
float3 L = normalize(input.LightVec);
|
||||
float3 ambient = float3(0.65, 0.65, 0.65);
|
||||
float3 diffuse = max(dot(N, L), 0.0) * input.Color;
|
||||
return float4((ambient + diffuse) * color.rgb, 1.0);
|
||||
}
|
||||
42
shaders/slang/indirectdraw/skysphere.slang
Normal file
42
shaders/slang/indirectdraw/skysphere.slang
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
/* Copyright (c) 2025, Sascha Willems
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
*/
|
||||
|
||||
struct VSInput
|
||||
{
|
||||
float4 Pos;
|
||||
float2 UV;
|
||||
};
|
||||
|
||||
struct VSOutput
|
||||
{
|
||||
float4 Pos : SV_POSITION;
|
||||
float2 UV;
|
||||
};
|
||||
|
||||
struct UBO
|
||||
{
|
||||
float4x4 projection;
|
||||
float4x4 modelview;
|
||||
};
|
||||
ConstantBuffer<UBO> ubo;
|
||||
|
||||
[shader("vertex")]
|
||||
VSOutput vertexMain(VSInput input)
|
||||
{
|
||||
VSOutput output;
|
||||
output.UV = input.UV;
|
||||
// Skysphere always at center, only use rotation part of modelview matrix
|
||||
output.Pos = mul(ubo.projection, float4(mul((float3x3)ubo.modelview, input.Pos.xyz), 1));
|
||||
return output;
|
||||
}
|
||||
|
||||
[shader("fragment")]
|
||||
float4 fragmentMain(VSOutput input)
|
||||
{
|
||||
const float4 gradientStart = float4(0.93, 0.9, 0.81, 1.0);
|
||||
const float4 gradientEnd = float4(0.35, 0.5, 1.0, 1.0);
|
||||
return lerp(gradientStart, gradientEnd, min(0.5 - (input.UV.y + 0.05), 0.5)/0.15 - 0.5);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue