aboutsummaryrefslogtreecommitdiff
path: root/dist/post_shaders/Sharpen.fx
blob: 36850e818b9a44993f21a086f644bbcde19f497d (plain) (blame)
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
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
// SPDX-License-Identifier: GPL-3.0-or-later

texture BackBufferTex : COLOR;
sampler BackBuffer { Texture = BackBufferTex; };

uniform float Amount <
    ui_type = "slider";
    ui_label = "Amount";
    ui_min = 0.0; ui_max = 3.0; ui_step = 0.01;
> = 0.6;

void VS_PostProcess(in uint id : SV_VertexID, out float4 pos : SV_Position, out float2 uv : TEXCOORD)
{
    uv = float2(float(id & 2), float((id & 1) << 1));
    pos = float4(uv * float2(2.0, -2.0) + float2(-1.0, 1.0), 0.0, 1.0);
}

float4 PS_Sharpen(float4 pos : SV_Position, float2 uv : TEXCOORD) : SV_Target
{
    float2 texel = float2(BUFFER_RCP_WIDTH, BUFFER_RCP_HEIGHT);

    float3 centre = tex2D(BackBuffer, uv).rgb;
    float3 blur = tex2D(BackBuffer, uv + float2(-texel.x, 0.0)).rgb;
    blur += tex2D(BackBuffer, uv + float2(texel.x, 0.0)).rgb;
    blur += tex2D(BackBuffer, uv + float2(0.0, -texel.y)).rgb;
    blur += tex2D(BackBuffer, uv + float2(0.0, texel.y)).rgb;
    blur *= 0.25;

    return float4(centre + (centre - blur) * Amount, 1.0);
}

technique Sharpen <
    ui_label = "Sharpen";
    ui_tooltip = "Unsharp mask that brings back edge detail lost to scaling. Most useful after upscaling a low internal resolution.";
>
{
    pass
    {
        VertexShader = VS_PostProcess;
        PixelShader = PS_Sharpen;
    }
}