crt-consumer-arcade clean-up (#565)

* crt-consumer-arcade clean-up

* Update crt-consumer-1w.glsl

* Update linear.glsl
This commit is contained in:
metallic77 authored and GitHub committed 2026-06-03 13:28:37 -05:00
1 parent 94e10586b9
commit 2b2c5ee3fd
3 files changed
+42 -75

No files matched your search

+34 -63
View File
@@ -1,25 +1,17 @@
#version 110
/*
crt-consumer-1w, A simple CRT shader by metallic 77.
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the Free
Software Foundation; either version 2 of the License, or (at your option)
any later version.
*/
#pragma parameter u_sharp "Reverse Sharpness" 0.25 0.0 0.5 0.01
#pragma parameter u_warp "Curvature" 0.04 0.0 0.15 0.01
#pragma parameter u_overscanx "Overscan Horiz." 0.3 0.3 2.0 0.05
#pragma parameter u_overscany "Overscan Vertic." 0.3 0.3 2.0 0.05
#pragma parameter u_scan "Scanlines Strength" 0.35 0.0 1.0 0.05
#pragma parameter u_mask "Mask Strength" 0.25 0.0 1.0 0.05
#pragma parameter u_wid "Mask Fine/Coarse" 2.0 2.0 3.0 1.0
#pragma parameter u_deconv "De-Convergence Horiz." 0.3 -2.0 2.0 0.05
#pragma parameter u_brightb "Bright Boost" 1.35 1.0 2.0 0.05
#pragma parameter u_vignette "Vignette" 0.15 0.0 0.5 0.01
#pragma parameter SCAN_LOW "Scanline Intensity (Dark Scenes)" 0.8 0.0 1.0 0.05
#pragma parameter SCAN_HIGH "Scanline Intensity (Bright Scenes)" 0.3 0.0 1.0 0.05
#pragma parameter MSK_SIZE "Mask Fine/Coarse" 1.0 0.6666 1.0 0.3333
#pragma parameter MASK_LOW "Mask Intensity (Dark Scenes)" 0.5 0.0 1.0 0.05
#pragma parameter MASK_HIGH "Mask Intensity (Bright Scenes)" 0.2 0.0 1.0 0.05
#if defined(VERTEX)
#if __VERSION__ >= 130
@@ -57,18 +49,15 @@ uniform COMPAT_PRECISION vec2 TextureSize;
uniform COMPAT_PRECISION vec2 InputSize;
#ifdef PARAMETER_UNIFORM
uniform COMPAT_PRECISION float u_deconv;
uniform COMPAT_PRECISION float u_wid;
uniform COMPAT_PRECISION float u_warp;
uniform COMPAT_PRECISION float u_overscanx;
uniform COMPAT_PRECISION float u_overscany;
uniform COMPAT_PRECISION float MSK_SIZE;
#else
#define u_deconv 0.5
#define u_wid 2.0
#define u_warp 0.05
#define u_overscanx 0.3
#define u_overscany 0.3
#define MSK_SIZE 1.0
#endif
void main()
@@ -76,11 +65,10 @@ void main()
gl_Position = MVPMatrix * VertexCoord;
TEX0 = TexCoord.xy*1.0001;
ogl2pos = TEX0.xy*TextureSize;
invdims = u_deconv/TextureSize;
invdims = 1.0/TextureSize;
scale = TextureSize/InputSize;
maskpos = TEX0.xy*scale*OutputSize.xy*2.0/u_wid;
maskpos = TEX0.xy*scale*OutputSize.xy*MSK_SIZE;
barrel = vec2(1.0-u_warp*u_overscanx, 1.0-u_warp*u_overscany);
}
#elif defined(FRAGMENT)
@@ -106,7 +94,6 @@ precision mediump float;
#define COMPAT_PRECISION
#endif
uniform sampler2D Texture;
COMPAT_VARYING vec2 TEX0;
COMPAT_VARYING vec2 ogl2pos;
@@ -125,64 +112,44 @@ uniform COMPAT_PRECISION vec2 TextureSize;
uniform COMPAT_PRECISION vec2 InputSize;
#ifdef PARAMETER_UNIFORM
uniform COMPAT_PRECISION float u_brightb;
uniform COMPAT_PRECISION float u_scan;
uniform COMPAT_PRECISION float u_vignette;
uniform COMPAT_PRECISION float u_warp;
uniform COMPAT_PRECISION float u_mask;
uniform COMPAT_PRECISION float u_sharp;
uniform COMPAT_PRECISION float SCAN_LOW;
uniform COMPAT_PRECISION float SCAN_HIGH;
uniform COMPAT_PRECISION float MASK_LOW;
uniform COMPAT_PRECISION float MASK_HIGH;
#else
#define u_brightb 1.25
#define u_scan 0.3
#define u_vignette 0.1
#define u_warp 0.1
#define u_mask 0.3
#define u_sharp 0.15
#define SCAN_LOW 0.8
#define SCAN_HIGH 0.3
#define MASK_LOW 0.5
#define MASK_HIGH 0.2
#endif
#define PI 3.14159265358979323846
#define TAU 6.2831852
#define pixel 1.0/TextureSize
vec3 toLinear(vec3 c) { return c * c; }
vec3 toGamma(vec3 c) { return sqrt(c); }
void main() {
// uv in [0,1]
vec2 uv = TEX0*scale;
// keep "crt frame" stable regardless of overscan
vec2 pos = uv;
// --- Barrel warp ---
// normalized coords centered at 0
vec2 n = uv * 2.0 - 1.0;
// polynomial warp
float rsq = dot(n, n);
n *= 1.0 + u_warp*rsq*1.5;
n -= n*(barrel*u_warp);
n *= barrel;
uv = (n + 1.0) * 0.5;
vec2 corn = min(pos, 1.0-pos); // This is used to mask the rounded
corn.x = 0.0012/corn.x; // corners later on
vec2 corn = min(pos, 1.0-pos);
corn.x = 0.0012/corn.x;
uv /= scale;
// pixel size for subpixel offsets
float px = invdims.x;
// chroma separation: shift R and B horizontally by +/- small amounts
vec2 offR = vec2( px, 0.0);
vec2 offB = vec2(- px, 0.0);
vec2 dx = vec2(pixel.x, 0.0);
// fetch center (G), left/right for R/B
vec3 colG = COMPAT_TEXTURE(Texture, uv).rgb;
vec3 colR = COMPAT_TEXTURE(Texture, uv + offR).rgb;
vec3 colB = COMPAT_TEXTURE(Texture, uv + offB).rgb;
// reconstruct approximate RGB (we sampled full RGB for each tap,
// but treat them as subpixel contributions)
vec3 col = vec3(colR.r, colG.g, colB.b);
vec3 col = COMPAT_TEXTURE(Texture, uv).rgb;
vec3 sharpl = COMPAT_TEXTURE(Texture, uv -dx).rgb*(-u_sharp);
vec3 sharpl2 = COMPAT_TEXTURE(Texture, uv - 2.0*dx).rgb*(u_sharp*0.1);
vec3 sharpr = COMPAT_TEXTURE(Texture, uv + dx).rgb*(-u_sharp);
@@ -190,19 +157,23 @@ void main() {
col = col*(1.0 + u_sharp*1.8) + sharpl+sharpr+sharpl2+sharpr2;
// --- Scanlines / Mask ---
float scan = 0.5*sin((uv.y*TextureSize.y-0.25)*TAU)+0.5;
float mask = 0.5*sin((maskpos.x)*PI)+0.5;
col *= mix(1.0, scan, u_scan);
col *= mix(u_brightb, mask, u_mask);
float l = max(max(col.r, col.g), col.b);
float infl = mix(SCAN_LOW, SCAN_HIGH, l);
float infl2 = mix(MASK_LOW, MASK_HIGH, l);
float scan = infl * sin((uv.y * TextureSize.y) * TAU);
float msk = infl2 * sin(maskpos.x * PI);
col += col * scan;
col += col * msk;
// --- Vignette ---
float vig = 1.0 - u_vignette * pow(length(n), 1.5);
col *= vig;
if (u_warp > 0.0){
if (corn.y <= corn.x || corn.x < 0.0001)
col = vec3(0.0);}
if (u_warp > 0.0){
if (corn.y <= corn.x || corn.x < 0.0001)
col = vec3(0.0);
}
FragColor = vec4(col, 1.0);
}
#endif
@@ -20,6 +20,7 @@
// --- REPLACED PARAMETERS FROM scanlines_test.glsl ---
#pragma parameter SCAN_LOW "Scanline Intensity (Dark Scenes)" 0.8 0.0 1.0 0.05
#pragma parameter SCAN_HIGH "Scanline Intensity (Bright Scenes)" 0.3 0.0 1.0 0.05
#pragma parameter MSK_SIZE "Mask Fine/Coarse" 1.0 0.6666 1.0 0.3333
#pragma parameter MASK_LOW "Mask Intensity (Dark Scenes)" 0.5 0.0 1.0 0.05
#pragma parameter MASK_HIGH "Mask Intensity (Bright Scenes)" 0.2 0.0 1.0 0.05
@@ -50,7 +51,6 @@ COMPAT_ATTRIBUTE vec4 COLOR;
COMPAT_ATTRIBUTE vec4 TexCoord;
COMPAT_VARYING vec4 COL0;
COMPAT_VARYING vec4 TEX0;
COMPAT_VARYING vec2 ogl2pos;
COMPAT_VARYING vec2 invdims;
COMPAT_VARYING vec2 maskpos;
COMPAT_VARYING vec2 scale;
@@ -62,6 +62,7 @@ uniform COMPAT_PRECISION int FrameCount;
uniform COMPAT_PRECISION vec2 OutputSize;
uniform COMPAT_PRECISION vec2 TextureSize;
uniform COMPAT_PRECISION vec2 InputSize;
uniform COMPAT_PRECISION float MSK_SIZE;
void main()
{
@@ -69,8 +70,7 @@ void main()
TEX0.xy = TexCoord.xy;
invdims = 1.0/TextureSize;
scale = TextureSize/InputSize;
maskpos = TEX0.xy*scale*OutputSize.xy;
ogl2pos = TEX0.xy*TextureSize;
maskpos = TEX0.xy*scale*OutputSize.xy*MSK_SIZE;
aspect = TextureSize.x / TextureSize.y;
}
@@ -100,7 +100,6 @@ precision mediump float;
uniform sampler2D Texture;
uniform sampler2D PassPrev4Texture;
COMPAT_VARYING vec4 TEX0;
COMPAT_VARYING vec2 ogl2pos;
COMPAT_VARYING vec2 invdims;
COMPAT_VARYING vec2 maskpos;
COMPAT_VARYING vec2 scale;
@@ -123,7 +122,6 @@ uniform COMPAT_PRECISION float U_VIGN;
uniform COMPAT_PRECISION float U_CRT;
uniform COMPAT_PRECISION float U_GLOW;
uniform COMPAT_PRECISION float U_CURVE;
// --- INTEGRATED scanlines_test UNIFORMS ---
uniform COMPAT_PRECISION float SCAN_LOW;
uniform COMPAT_PRECISION float SCAN_HIGH;
uniform COMPAT_PRECISION float MASK_LOW;
@@ -136,7 +134,6 @@ uniform COMPAT_PRECISION float MASK_HIGH;
#define U_CRT 1.0
#define U_GLOW 0.1
#define U_CURVE 0.1
// --- INTEGRATED scanlines_test DEFINES ---
#define SCAN_LOW 0.8
#define SCAN_HIGH 0.3
#define MASK_LOW 0.5
@@ -144,14 +141,13 @@ uniform COMPAT_PRECISION float MASK_HIGH;
#endif
#define grayweights vec3(0.3,0.59,0.11)
#define GAMMAIN(color) color*color
#define PI 3.14159265358979323846
#define tau 6.2831852
mat3 crt = mat3(
1.0, 0.05, 0.0,
1.0, 0.03, -0.02,
-0.05, 1.0, -0.05,
0.0, 0.05, 1.0
0.02, 0.06, 1.0
);
vec2 c_warp(vec2 uv)
@@ -208,7 +204,7 @@ void main()
f.y = f.y*f.y*f.y;
f.y = f.y*f.y*f.y;
vec2 pos = (near + f) / TextureSize;
vec2 pos = (near + f)*invdims;
vec3 res = COMPAT_TEXTURE(PassPrev4Texture, pos).rgb;
res += U_GLOW*grayweights*COMPAT_TEXTURE(Source, pos).rgb;
@@ -221,7 +217,7 @@ void main()
float infl2 = mix(MASK_LOW, MASK_HIGH, l);
// Draw scanlines aligned with the screen curvature
float scan = infl * sin((uv.y * TextureSize.y - 0.25) * tau);
float scan = infl * sin((uv.y * TextureSize.y) * tau);
float msk = infl2 * sin(maskpos.x * PI);
res += res * scan;
+1 -1
View File
@@ -9,7 +9,7 @@
*/
#pragma parameter u_gamma "Gamma" 1.2 1.0 2.0 0.05
#pragma parameter u_gamma "Gamma" 1.1 1.0 2.0 0.05
#if defined(VERTEX)