Added slang shaders for additional samples
This commit is contained in:
parent
834ee9ed83
commit
24bc3e3aa9
5 changed files with 361 additions and 0 deletions
51
shaders/slang/radialblur/colorpass.slang
Normal file
51
shaders/slang/radialblur/colorpass.slang
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
/* Copyright (c) 2025, Sascha Willems
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
*/
|
||||
|
||||
struct VSInput
|
||||
{
|
||||
float3 Pos;
|
||||
float2 UV;
|
||||
float3 Color;
|
||||
};
|
||||
|
||||
struct VSOutput
|
||||
{
|
||||
float4 Pos : SV_POSITION;
|
||||
float3 Color;
|
||||
float2 UV;
|
||||
};
|
||||
|
||||
struct UBO
|
||||
{
|
||||
float4x4 projection;
|
||||
float4x4 model;
|
||||
float gradientPos;
|
||||
};
|
||||
ConstantBuffer<UBO> ubo;
|
||||
|
||||
Sampler2D samplerGradientRamp;
|
||||
|
||||
[shader("vertex")]
|
||||
VSOutput vertexMain(VSInput input)
|
||||
{
|
||||
VSOutput output;
|
||||
output.Color = input.Color;
|
||||
output.UV = float2(ubo.gradientPos, 0.0f);
|
||||
output.Pos = mul(ubo.projection, mul(ubo.model, float4(input.Pos, 1.0)));
|
||||
return output;
|
||||
}
|
||||
|
||||
[shader("fragment")]
|
||||
float4 fragmentMain(VSOutput input)
|
||||
{
|
||||
// Use max. color channel value to detect bright glow emitters
|
||||
if ((input.Color.r >= 0.9) || (input.Color.g >= 0.9) || (input.Color.b >= 0.9))
|
||||
{
|
||||
return float4(samplerGradientRamp.Sample(input.UV).rgb, 1);
|
||||
} else {
|
||||
return float4(input.Color, 1);
|
||||
}
|
||||
}
|
||||
67
shaders/slang/radialblur/phongpass.slang
Normal file
67
shaders/slang/radialblur/phongpass.slang
Normal file
|
|
@ -0,0 +1,67 @@
|
|||
/* 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;
|
||||
float3 Color;
|
||||
float3 EyePos;
|
||||
float3 LightVec;
|
||||
float2 UV;
|
||||
};
|
||||
|
||||
struct UBO
|
||||
{
|
||||
float4x4 projection;
|
||||
float4x4 model;
|
||||
float gradientPos;
|
||||
};
|
||||
ConstantBuffer<UBO> ubo;
|
||||
|
||||
Sampler2D samplerGradientRamp;
|
||||
|
||||
[shader("vertex")]
|
||||
VSOutput vertexMain(VSInput input)
|
||||
{
|
||||
VSOutput output;
|
||||
output.Normal = input.Normal;
|
||||
output.Color = input.Color;
|
||||
output.UV = float2(ubo.gradientPos, 0.0);
|
||||
output.Pos = mul(ubo.projection, mul(ubo.model, input.Pos));
|
||||
output.EyePos = mul(ubo.model, input.Pos).xyz;
|
||||
float4 lightPos = float4(0.0, 0.0, -5.0, 1.0); // * ubo.model;
|
||||
output.LightVec = normalize(lightPos.xyz - input.Pos.xyz);
|
||||
return output;
|
||||
}
|
||||
|
||||
[shader("fragment")]
|
||||
float4 fragmentMain(VSOutput input)
|
||||
{
|
||||
// No light calculations for glow color
|
||||
// Use max. color channel value
|
||||
// to detect bright glow emitters
|
||||
if ((input.Color.r >= 0.9) || (input.Color.g >= 0.9) || (input.Color.b >= 0.9))
|
||||
{
|
||||
return float4(samplerGradientRamp.Sample(input.UV).rgb, 1);
|
||||
} else {
|
||||
float3 Eye = normalize(-input.EyePos);
|
||||
float3 Reflected = normalize(reflect(-input.LightVec, input.Normal));
|
||||
float4 IAmbient = float4(0.2, 0.2, 0.2, 1.0);
|
||||
float4 IDiffuse = float4(0.5, 0.5, 0.5, 0.5) * max(dot(input.Normal, input.LightVec), 0.0);
|
||||
float specular = 0.25;
|
||||
float4 ISpecular = float4(0.5, 0.5, 0.5, 1.0) * pow(max(dot(Reflected, Eye), 0.0), 4.0) * specular;
|
||||
return float4((IAmbient + IDiffuse) * float4(input.Color, 1.0) + ISpecular);
|
||||
}
|
||||
}
|
||||
48
shaders/slang/radialblur/radialblur.slang
Normal file
48
shaders/slang/radialblur/radialblur.slang
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
/* Copyright (c) 2025, Sascha Willems
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
*/
|
||||
|
||||
struct VSOutput
|
||||
{
|
||||
float4 Pos : SV_POSITION;
|
||||
float2 UV;
|
||||
};
|
||||
|
||||
struct UBO
|
||||
{
|
||||
float radialBlurScale;
|
||||
float radialBlurStrength;
|
||||
float2 radialOrigin;
|
||||
};
|
||||
ConstantBuffer<UBO> ubo;
|
||||
|
||||
Sampler2D samplerColor;
|
||||
|
||||
[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)
|
||||
{
|
||||
int2 texDim;
|
||||
samplerColor.GetDimensions(texDim.x, texDim.y);
|
||||
float2 radialSize = float2(1.0 / texDim.x, 1.0 / texDim.y);
|
||||
float2 UV = input.UV;
|
||||
float4 color = float4(0.0, 0.0, 0.0, 0.0);
|
||||
UV += radialSize * 0.5 - ubo.radialOrigin;
|
||||
#define samples 32
|
||||
for (int i = 0; i < samples; i++)
|
||||
{
|
||||
float scale = 1.0 - ubo.radialBlurScale * (float(i) / float(samples - 1));
|
||||
color += samplerColor.Sample(UV * scale + ubo.radialOrigin);
|
||||
}
|
||||
return (color / samples) * ubo.radialBlurStrength;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue