From ea369330e3be1a8a3a3b8afdadeeeb733fd846cc Mon Sep 17 00:00:00 2001 From: Rinnegatamante Date: Thu, 17 Aug 2023 10:27:50 +0200 Subject: [PATCH] Added CRT filter post-processing effect. --- Data/DaedalusX64/Shaders/CRT/desc.txt | 1 + Data/DaedalusX64/Shaders/CRT/frag.cg | 66 +++++++++++++++++++ Data/DaedalusX64/Shaders/CRT/vert.cg | 14 ++++ .../SysVita/Graphics/GraphicsContextVita.cpp | 4 ++ Source/SysVita/UI/MenuBarScreen.cpp | 2 + 5 files changed, 87 insertions(+) create mode 100644 Data/DaedalusX64/Shaders/CRT/desc.txt create mode 100644 Data/DaedalusX64/Shaders/CRT/frag.cg create mode 100644 Data/DaedalusX64/Shaders/CRT/vert.cg diff --git a/Data/DaedalusX64/Shaders/CRT/desc.txt b/Data/DaedalusX64/Shaders/CRT/desc.txt new file mode 100644 index 00000000..d4cac810 --- /dev/null +++ b/Data/DaedalusX64/Shaders/CRT/desc.txt @@ -0,0 +1 @@ +Advanced CRT filter. \ No newline at end of file diff --git a/Data/DaedalusX64/Shaders/CRT/frag.cg b/Data/DaedalusX64/Shaders/CRT/frag.cg new file mode 100644 index 00000000..59ee5a08 --- /dev/null +++ b/Data/DaedalusX64/Shaders/CRT/frag.cg @@ -0,0 +1,66 @@ +/* + Source: https://www.shadertoy.com/view/Ms23DR +*/ + +float2 curve(float2 uv) +{ + uv = (uv - 0.5) * 2.0; + uv *= 1.1; + uv.x *= 1.0 + pow((abs(uv.y) / 5.0), 2.0); + uv.y *= 1.0 + pow((abs(uv.x) / 4.0), 2.0); + uv = (uv / 2.0) + 0.5; + uv = uv *0.92 + 0.04; + return uv; +} + +varying out float4 fragColor : COLOR; +varying in float2 fragCoord : WPOS; +varying in float2 v_uv : TEXCOORD0; +static float2 iResolution = float2(960.0f, 544.0f); +uniform float iTime; +uniform sampler2D s0; + +void main( ) +{ + float2 q = fragCoord.xy / iResolution.xy; + float2 uv = q; + uv = curve( uv ); + // float3 oricol = tex2D( s0, float2(q.x,q.y) ).xyz; + float3 col; + float x = sin(0.3*iTime+uv.y*21.0)*sin(0.7*iTime+uv.y*29.0)*sin(0.3+0.33*iTime+uv.y*31.0)*0.0017; + + col.r = tex2D(s0,float2(x+uv.x+0.001,uv.y+0.001)).x+0.05; + col.g = tex2D(s0,float2(x+uv.x+0.000,uv.y-0.002)).y+0.05; + col.b = tex2D(s0,float2(x+uv.x-0.002,uv.y+0.000)).z+0.05; + col.r += 0.08*tex2D(s0,0.75*float2(x+0.025, -0.027)+float2(uv.x+0.001,uv.y+0.001)).x; + col.g += 0.05*tex2D(s0,0.75*float2(x+-0.022, -0.02)+float2(uv.x+0.000,uv.y-0.002)).y; + col.b += 0.08*tex2D(s0,0.75*float2(x+-0.02, -0.018)+float2(uv.x-0.002,uv.y+0.000)).z; + + col = clamp(col*0.6+0.4*col*col*1.0,0.0,1.0); + + float vig = (0.0 + 1.0*16.0*uv.x*uv.y*(1.0-uv.x)*(1.0-uv.y)); + col *= float3(pow(vig,0.3)); + + col *= float3(0.95,1.05,0.95); + col *= 2.8; + + float scans = clamp( 0.35+0.35*sin(3.5*iTime+uv.y*iResolution.y*1.5), 0.0, 1.0); + + float s = pow(scans,1.7); + col = col*float3( 0.4+0.7*s) ; + + col *= 1.0+0.01*sin(110.0*iTime); + if (uv.x < 0.0 || uv.x > 1.0) + col *= 0.0; + if (uv.y < 0.0 || uv.y > 1.0) + col *= 0.0; + + col*=1.0-0.65*float3(clamp((fmod(fragCoord.x, 2.0)-1.0)*2.0,0.0,1.0)); + + // float comp = smoothstep( 0.1, 0.9, sin(iTime) ); + + // Remove the next line to stop cross-fade between original and postprocess +// col = mix( col, oricol, comp ); + + fragColor = float4(col,1.0); +} diff --git a/Data/DaedalusX64/Shaders/CRT/vert.cg b/Data/DaedalusX64/Shaders/CRT/vert.cg new file mode 100644 index 00000000..767c0e4b --- /dev/null +++ b/Data/DaedalusX64/Shaders/CRT/vert.cg @@ -0,0 +1,14 @@ +/* + Source: https://www.shadertoy.com/view/Ms23DR +*/ + +void main( + float3 position, + float2 texcoord, + uniform float4x4 gl_ModelViewProjectionMatrix, + out float4 vPosition : POSITION, + out float2 vTexcoord : TEXCOORD0 +) { + vPosition = mul(gl_ModelViewProjectionMatrix,float4(position, 1.f)); + vTexcoord = texcoord; +} diff --git a/Source/SysVita/Graphics/GraphicsContextVita.cpp b/Source/SysVita/Graphics/GraphicsContextVita.cpp index 17b80f67..d40d26e7 100644 --- a/Source/SysVita/Graphics/GraphicsContextVita.cpp +++ b/Source/SysVita/Graphics/GraphicsContextVita.cpp @@ -36,6 +36,7 @@ uint32_t *gColorBufferPtr; float *gTexCoordBufferPtr; bool new_frame = true; +extern int time_unif; extern float gamma_val; static GLuint emu_fb = 0xDEADBEEF, emu_fb_tex, emu_depth_buf_tex; @@ -237,6 +238,9 @@ void IGraphicsContext::UpdateFrame(bool wait_for_vbl) } i++; } + if (time_unif != -1) { + glUniform1f(time_unif, (float)sceKernelGetProcessTimeLow() / 1000000.0f); + } vglVertexAttribPointerMapped(0, vflux_vertices); vglVertexAttribPointerMapped(1, vflux_texcoords); diff --git a/Source/SysVita/UI/MenuBarScreen.cpp b/Source/SysVita/UI/MenuBarScreen.cpp index 51c6a5bd..cbff0a9e 100644 --- a/Source/SysVita/UI/MenuBarScreen.cpp +++ b/Source/SysVita/UI/MenuBarScreen.cpp @@ -113,6 +113,7 @@ PostProcessingEffect *effects_list = nullptr; Overlay *overlays_list = nullptr; Uniform prog_uniforms[8]; +int time_unif = -1; GLuint ff_icon = 0xDEADBEEF; /*GLuint achievement_icon = 0xDEADBEEF; @@ -267,6 +268,7 @@ bool setPostProcessingEffect(int idx, PostProcessingEffect *p) { glLinkProgram(program[shader_idx]); cur_prog = program[shader_idx]; glUniform1i(glGetUniformLocation(program[shader_idx], "colorMap"), 0); + time_unif = glGetUniformLocation(cur_prog, "iTime"); if (p->customizable) { sprintf(fpath, "%s%s/unif.txt", DAEDALUS_VITA_PATH_EXT("ux0:", "Shaders/"), p->name);