Add slang shaders for additional samples
This commit is contained in:
parent
afbc3a5bb7
commit
4df49dba71
5 changed files with 266 additions and 0 deletions
45
shaders/slang/bloom/colorpass.slang
Normal file
45
shaders/slang/bloom/colorpass.slang
Normal file
|
|
@ -0,0 +1,45 @@
|
||||||
|
/* Copyright (c) 2025, Sascha Willems
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: MIT
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
struct VSInput
|
||||||
|
{
|
||||||
|
float4 Pos;
|
||||||
|
float2 UV;
|
||||||
|
float3 Color;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct VSOutput
|
||||||
|
{
|
||||||
|
float4 Pos : SV_POSITION;
|
||||||
|
float3 Color;
|
||||||
|
float2 UV;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct UBO
|
||||||
|
{
|
||||||
|
float4x4 projection;
|
||||||
|
float4x4 view;
|
||||||
|
float4x4 model;
|
||||||
|
};
|
||||||
|
ConstantBuffer<UBO> ubo;
|
||||||
|
|
||||||
|
Sampler2D colorMapSampler;
|
||||||
|
|
||||||
|
[shader("vertex")]
|
||||||
|
VSOutput vertexMain(VSInput input)
|
||||||
|
{
|
||||||
|
VSOutput output;
|
||||||
|
output.UV = input.UV;
|
||||||
|
output.Color = input.Color;
|
||||||
|
output.Pos = mul(ubo.projection, mul(ubo.view, mul(ubo.model, input.Pos)));
|
||||||
|
return output;
|
||||||
|
}
|
||||||
|
|
||||||
|
[shader("fragment")]
|
||||||
|
float4 fragmentMain(VSOutput input)
|
||||||
|
{
|
||||||
|
return float4(input.Color, 1);
|
||||||
|
}
|
||||||
63
shaders/slang/bloom/gaussblur.slang
Normal file
63
shaders/slang/bloom/gaussblur.slang
Normal file
|
|
@ -0,0 +1,63 @@
|
||||||
|
/* Copyright (c) 2025, Sascha Willems
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: MIT
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
struct VSOutput
|
||||||
|
{
|
||||||
|
float4 Pos : SV_POSITION;
|
||||||
|
float2 UV;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct UBO
|
||||||
|
{
|
||||||
|
float blurScale;
|
||||||
|
float blurStrength;
|
||||||
|
};
|
||||||
|
ConstantBuffer<UBO> ubo;
|
||||||
|
|
||||||
|
Sampler2D samplerColor;
|
||||||
|
|
||||||
|
[[SpecializationConstant]] const int blurdirection = 0;
|
||||||
|
|
||||||
|
[shader("vertex")]
|
||||||
|
VSOutput vertexMain(uint VertexIndex: SV_VertexID)
|
||||||
|
{
|
||||||
|
VSOutput output;
|
||||||
|
output.UV = float2((VertexIndex << 1) & 2, VertexIndex & 2);
|
||||||
|
output.Pos = float4(output.UV * 2.0f - 1.0f, 0.0f, 1.0f);
|
||||||
|
return output;
|
||||||
|
}
|
||||||
|
|
||||||
|
[shader("fragment")]
|
||||||
|
float4 fragmentMain(VSOutput input)
|
||||||
|
{
|
||||||
|
float weight[5];
|
||||||
|
weight[0] = 0.227027;
|
||||||
|
weight[1] = 0.1945946;
|
||||||
|
weight[2] = 0.1216216;
|
||||||
|
weight[3] = 0.054054;
|
||||||
|
weight[4] = 0.016216;
|
||||||
|
|
||||||
|
float2 textureSize;
|
||||||
|
samplerColor.GetDimensions(textureSize.x, textureSize.y);
|
||||||
|
float2 tex_offset = 1.0 / textureSize * ubo.blurScale; // gets size of single texel
|
||||||
|
float3 result = samplerColor.Sample(input.UV).rgb * weight[0]; // current fragment's contribution
|
||||||
|
for(int i = 1; i < 5; ++i)
|
||||||
|
{
|
||||||
|
if (blurdirection == 1)
|
||||||
|
{
|
||||||
|
// H
|
||||||
|
result += samplerColor.Sample(input.UV + float2(tex_offset.x * i, 0.0)).rgb * weight[i] * ubo.blurScale;
|
||||||
|
result += samplerColor.Sample(input.UV - float2(tex_offset.x * i, 0.0)).rgb * weight[i] * ubo.blurScale;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// V
|
||||||
|
result += samplerColor.Sample(input.UV + float2(0.0, tex_offset.y * i)).rgb * weight[i] * ubo.blurScale;
|
||||||
|
result += samplerColor.Sample(input.UV - float2(0.0, tex_offset.y * i)).rgb * weight[i] * ubo.blurScale;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return float4(result, 1.0);
|
||||||
|
}
|
||||||
70
shaders/slang/bloom/phongpass.slang
Normal file
70
shaders/slang/bloom/phongpass.slang
Normal file
|
|
@ -0,0 +1,70 @@
|
||||||
|
/* Copyright (c) 2025, Sascha Willems
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: MIT
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
struct VSInput
|
||||||
|
{
|
||||||
|
float4 Pos;
|
||||||
|
float2 UV;
|
||||||
|
float3 Color;
|
||||||
|
float3 Normal;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct VSOutput
|
||||||
|
{
|
||||||
|
float4 Pos : SV_POSITION;
|
||||||
|
float3 Normal;
|
||||||
|
float2 UV;
|
||||||
|
float3 Color;
|
||||||
|
float3 ViewVec;
|
||||||
|
float3 LightVec;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct UBO
|
||||||
|
{
|
||||||
|
float4x4 projection;
|
||||||
|
float4x4 view;
|
||||||
|
float4x4 model;
|
||||||
|
};
|
||||||
|
ConstantBuffer<UBO> ubo;
|
||||||
|
|
||||||
|
Sampler2D colorMapSampler;
|
||||||
|
|
||||||
|
[shader("vertex")]
|
||||||
|
VSOutput vertexMain(VSInput input)
|
||||||
|
{
|
||||||
|
VSOutput output;
|
||||||
|
output.Normal = input.Normal;
|
||||||
|
output.Color = input.Color;
|
||||||
|
output.UV = input.UV;
|
||||||
|
output.Pos = mul(ubo.projection, mul(ubo.view, mul(ubo.model, input.Pos)));
|
||||||
|
|
||||||
|
float3 lightPos = float3(-5.0, -5.0, 0.0);
|
||||||
|
float4 pos = mul(ubo.view, mul(ubo.model, input.Pos));
|
||||||
|
output.Normal = mul((float4x3)mul(ubo.view, ubo.model), input.Normal).xyz;
|
||||||
|
output.LightVec = lightPos - pos.xyz;
|
||||||
|
output.ViewVec = -pos.xyz;
|
||||||
|
return output;
|
||||||
|
}
|
||||||
|
|
||||||
|
[shader("fragment")]
|
||||||
|
float4 fragmentMain(VSOutput input)
|
||||||
|
{
|
||||||
|
float3 ambient = float3(0.0f, 0.0f, 0.0f);
|
||||||
|
|
||||||
|
// Adjust light calculations for glow color
|
||||||
|
if ((input.Color.r >= 0.9) || (input.Color.g >= 0.9) || (input.Color.b >= 0.9))
|
||||||
|
{
|
||||||
|
ambient = input.Color * 0.25;
|
||||||
|
}
|
||||||
|
|
||||||
|
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.75f, 0.75f, 0.75f);
|
||||||
|
return float4(ambient + diffuse + specular, 1.0);
|
||||||
|
}
|
||||||
41
shaders/slang/bloom/skybox.slang
Normal file
41
shaders/slang/bloom/skybox.slang
Normal file
|
|
@ -0,0 +1,41 @@
|
||||||
|
/* Copyright (c) 2025, Sascha Willems
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: MIT
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
struct VSInput
|
||||||
|
{
|
||||||
|
float3 Pos;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct VSOutput
|
||||||
|
{
|
||||||
|
float4 Pos : SV_POSITION;
|
||||||
|
float3 UVW;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct UBO
|
||||||
|
{
|
||||||
|
float4x4 projection;
|
||||||
|
float4x4 view;
|
||||||
|
float4x4 model;
|
||||||
|
};
|
||||||
|
ConstantBuffer<UBO> ubo;
|
||||||
|
|
||||||
|
SamplerCube samplerCubeMap;
|
||||||
|
|
||||||
|
[shader("vertex")]
|
||||||
|
VSOutput vertexMain(VSInput input)
|
||||||
|
{
|
||||||
|
VSOutput output;
|
||||||
|
output.UVW = input.Pos;
|
||||||
|
output.Pos = mul(ubo.projection, mul(ubo.view, mul(ubo.model, float4(input.Pos.xyz, 1.0))));
|
||||||
|
return output;
|
||||||
|
}
|
||||||
|
|
||||||
|
[shader("fragment")]
|
||||||
|
float4 fragmentMain(VSOutput input)
|
||||||
|
{
|
||||||
|
return samplerCubeMap.Sample(input.UVW);
|
||||||
|
}
|
||||||
47
shaders/slang/dynamicuniformbuffer/base.slang
Normal file
47
shaders/slang/dynamicuniformbuffer/base.slang
Normal file
|
|
@ -0,0 +1,47 @@
|
||||||
|
/* Copyright (c) 2025, Sascha Willems
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: MIT
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
struct VSInput
|
||||||
|
{
|
||||||
|
float3 Pos;
|
||||||
|
float3 Color;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct VSOutput
|
||||||
|
{
|
||||||
|
float4 Pos : SV_POSITION;
|
||||||
|
float3 Color;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct UboView
|
||||||
|
{
|
||||||
|
float4x4 projection;
|
||||||
|
float4x4 view;
|
||||||
|
};
|
||||||
|
ConstantBuffer<UboView> uboView;
|
||||||
|
|
||||||
|
struct UboInstance
|
||||||
|
{
|
||||||
|
float4x4 model;
|
||||||
|
};
|
||||||
|
ConstantBuffer<UboInstance> uboInstance;
|
||||||
|
|
||||||
|
[shader("vertex")]
|
||||||
|
VSOutput vertexMain(VSInput input)
|
||||||
|
{
|
||||||
|
VSOutput output;
|
||||||
|
output.Color = input.Color;
|
||||||
|
float4x4 modelView = mul(uboView.view, uboInstance.model);
|
||||||
|
float3 worldPos = mul(modelView, float4(input.Pos, 1.0)).xyz;
|
||||||
|
output.Pos = mul(uboView.projection, mul(modelView, float4(input.Pos.xyz, 1.0)));
|
||||||
|
return output;
|
||||||
|
}
|
||||||
|
|
||||||
|
[shader("fragment")]
|
||||||
|
float4 fragmentMain(VSOutput input)
|
||||||
|
{
|
||||||
|
return float4(input.Color, 1.0);
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue