aboutsummaryrefslogtreecommitdiff
path: root/dist/post_shaders/Scanlines.fx
blob: 2f24dc5ed52307fbda9776f96a88a411e7b4e81d (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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
// SPDX-License-Identifier: GPL-3.0-or-later

// SPDX-FileCopyrightText: Copyright 2012 PPSSPP Project
// SPDX-License-Identifier: GPL-2.0-or-later
// Ported from scanlines.fsh in PPSSPP.


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

uniform float Density <
    ui_type = "slider";
    ui_label = "Line Density";
    ui_tooltip = "Number of scanline pairs across the screen.";
    ui_min = 60.0; ui_max = 720.0; ui_step = 10.0;
> = 340.0;

uniform float Intensity <
    ui_type = "slider";
    ui_label = "Intensity";
    ui_tooltip = "How dark the gaps between lines become.";
    ui_min = 0.0; ui_max = 1.0; ui_step = 0.05;
> = 0.5;

uniform float Tint <
    ui_type = "slider";
    ui_label = "Phosphor Tint";
    ui_tooltip = "Strength of the green-warm phosphor cast.";
    ui_min = 0.0; ui_max = 1.0; ui_step = 0.05;
> = 1.0;

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_Scanlines(float4 pos : SV_Position, float2 uv : TEXCOORD) : SV_Target
{
    float line_pos = uv.y * Density * 0.5;
    float gate = cos((frac(line_pos) - 0.5) * 3.1415926 * Intensity) * 1.5;

    float3 rgb = tex2D(BackBuffer, uv).rgb;
    float3 color = rgb * 0.5 + 0.5 * rgb * rgb * 1.2;

    float3 phosphor = lerp(float3(1.0, 1.0, 1.0), float3(0.9, 1.0, 0.7), Tint);
    color *= phosphor;

    float2 diff = uv - 0.5;
    color *= 1.1 - 0.6 * (dot(diff, diff) * 2.0);

    return float4(saturate(color * saturate(gate)), 1.0);
}

technique Scanlines <
    ui_label = "Scanlines";
    ui_tooltip = "Darkens alternating rows of pixels to imitate the horizontal scanlines of a CRT. Cheaper than the full CRT effect when you only want the lines.";
>
{
    pass
    {
        VertexShader = VS_PostProcess;
        PixelShader = PS_Scanlines;
    }
}