aboutsummaryrefslogtreecommitdiff
path: root/assets/shaders/Blur.slang
blob: 17e4eae9145c489b83bb5d79283e305ff655d496 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
struct VSInput
{
    float2 position : POSITION;
    float2 texCoord : TEXCOORD0;
};

struct VSOutput
{
    float4 position : SV_Position;
    float2 texCoord : TEXCOORD0;
};

[shader("vertex")]
VSOutput vertexMain(VSInput input)
{
    VSOutput output;
    output.position = float4(input.position, 0.0, 1.0);
    output.texCoord = input.texCoord;
    return output;
}

Sampler2D u_ScreenTexture;
uniform float2 u_Resolution;
uniform float  u_BlurStrength;
uniform float  u_GlowIntensity;

[shader("fragment")]
float4 fragmentMain(VSOutput input) : SV_Target
{
    float2 texelSize = 1.0 / u_Resolution;
    float4 centerColor = u_ScreenTexture.Sample(input.texCoord);

    float brightness = (centerColor.r + centerColor.g + centerColor.b) / 3.0;
    float glowMask   = smoothstep(0.05, 0.3, brightness);

    float4 blurredColor = float4(0.0, 0.0, 0.0, 0.0);
    float  totalWeight  = 0.0;

    for (int x = -8; x <= 8; x++)
    {
        for (int y = -8; y <= 8; y++)
        {
            float2 offset = float2(x, y) * texelSize * u_BlurStrength;
            float4 sampleColor = u_ScreenTexture.Sample(input.texCoord + offset);

            float weight = exp(-float(x * x + y * y) / (2.0 * 8.0 * 8.0));
            blurredColor += sampleColor * weight;
            totalWeight  += weight;
        }
    }

    blurredColor /= totalWeight;

    float3 emissionColor = float3(1.0, 0.8, 0.6);
    float3 glowColor     = emissionColor * glowMask * u_GlowIntensity * 2.0;
    float3 auraColor     = blurredColor.rgb * glowMask * u_GlowIntensity * 0.8;
    float3 finalColor    = centerColor.rgb + glowColor + auraColor;

    return float4(finalColor, centerColor.a);
}