diff --git a/src/hardware/hw_defs.h b/src/hardware/hw_defs.h index 980094814..2030420c6 100644 --- a/src/hardware/hw_defs.h +++ b/src/hardware/hw_defs.h @@ -199,8 +199,7 @@ enum SHADER_POSTPROCESS_WATER, SHADER_POSTPROCESS_HEAT, - SHADER_VHS_FUZZ, - SHADER_VHS_BAR, + SHADER_VHS, NUMSHADERTARGETS }; diff --git a/src/hardware/hw_shaders.c b/src/hardware/hw_shaders.c index 33bf252ee..ae909f3b5 100644 --- a/src/hardware/hw_shaders.c +++ b/src/hardware/hw_shaders.c @@ -59,11 +59,8 @@ static struct { // heat postprocess shader {GLSL_DEFAULT_VERTEX_SHADER, GLSL_POSTPROCESS_FRAGMENT_HEAT}, - // vhs fuzz - {GLSL_DEFAULT_VERTEX_SHADER, GLSL_VHS_FUZZ_SHADER}, - - // vhs bars - {GLSL_DEFAULT_VERTEX_SHADER, GLSL_VHS_BAR_SHADER}, + // VHS effect + {GLSL_DEFAULT_VERTEX_SHADER, GLSL_VHS_SHADER}, {NULL, NULL}, }; @@ -458,8 +455,7 @@ customshaderxlat_t shaderxlat[] = {"UIColormapFade", SHADER_UI_COLORMAP_FADE}, {"PostProcessWater", SHADER_POSTPROCESS_WATER}, {"PostProcessHeat", SHADER_POSTPROCESS_HEAT}, - {"VHSFuzz", SHADER_VHS_FUZZ}, - {"VHSBar", SHADER_VHS_BAR}, + {"VHS", SHADER_VHS}, {NULL, 0}, }; diff --git a/src/hardware/hw_shaders.h b/src/hardware/hw_shaders.h index 874c79cc3..6b90172ad 100644 --- a/src/hardware/hw_shaders.h +++ b/src/hardware/hw_shaders.h @@ -409,15 +409,20 @@ "gl_FragColor = texture2D(tex, uv);\n" \ "}\0" -// screen fuzzyness +// VHS effect as a shader // basically just what we did before as a shader lul +// the bars are just the RR heat shader repurposed // thanks "stackoverflow.com/a/4275343" for the pseudo random stuff for glsl -#define GLSL_VHS_FUZZ_SHADER \ +// and thanks "thndl.com/triangle-waves" and "gamedev.stackexchange.com/q/191829" +// for the maths since im super bad at stuff +// 0.159155 = 1/pi*2 +#define GLSL_VHS_SHADER \ "#version 120\n" \ "uniform sampler2D tex;\n" \ "uniform vec2 scr_resolution;\n" \ "uniform vec2 scr_tex_size;\n" \ "uniform float vhs_time;\n" \ + "uniform float vhs_rewind;\n" \ "uniform float scr_dup;\n" \ "void main(void) {\n" \ "vec2 uv = gl_TexCoord[0].st;\n" \ @@ -426,27 +431,6 @@ "float ystep = (2.0 / scr_resolution.y) * scr_dup / 4.0;\n" \ "float rand = fract(sin((floor(y / ystep) + vhs_time) * 12.9898 + 78.233) * 43758.5453);\n" \ "uv.x -= floor(rand * 128.0) / -22000.0;\n" \ - "uv.y = clamp(uv.y, 0.0, maxuv.y - 0.0001);\n" \ - "uv.x = mod(uv.x, maxuv.x - 0.0001);\n" \ - "gl_FragColor = texture2D(tex, uv);\n" \ - "}\0" - -// repurposed the RR heat shader -// since it kinda matched the vhs bars lul -// thanks "thndl.com/triangle-waves" and "gamedev.stackexchange.com/q/191829" -// for the maths since im super bad at stuff -// 0.159155 = 1/pi*2 -#define GLSL_VHS_BAR_SHADER \ - "#version 120\n" \ - "uniform sampler2D tex;\n" \ - "uniform vec2 scr_resolution;\n" \ - "uniform vec2 scr_tex_size;\n" \ - "uniform float vhs_time;\n" \ - "uniform float vhs_rewind;\n" \ - "void main(void) {\n" \ - "vec2 uv = gl_TexCoord[0].st;\n" \ - "vec2 maxuv = scr_resolution / scr_tex_size;\n" \ - "float y = 1.0 - uv.y;\n" \ "float updistort = (vhs_rewind > 0.5) ? 0.266667 : 0.16;\n" \ "float downdistort = updistort / 2.0;\n" \ "float downspd = (vhs_rewind > 0.5) ? 2.0 : 1.0;\n" \ @@ -460,14 +444,13 @@ "vec4 color = texture2D(tex, uv);\n" \ "float downcol = step(0.00001, downbar);\n" \ "float upcol = step(0.00001, upbar);\n" \ - "color.rgb = mix(color.rgb, color.rgb * (220.0 / 255.0), downcol);\n" \ - "color.rgb = mix(color.rgb, color.rgb * (220.0 / 255.0), upcol);\n" \ + "color.rgb = mix(color.rgb, color.rgb * (210.0 / 255.0), downcol);\n" \ + "color.rgb = mix(color.rgb, color.rgb * (210.0 / 255.0), upcol);\n" \ "color.a = mix(color.a, color.a * (250.0 / 255.0), downcol);\n" \ "color.a = mix(color.a, color.a * (250.0 / 255.0), upcol);\n" \ "gl_FragColor = color;\n" \ "}\0" - // ================ // Fallback shaders // ================ diff --git a/src/hardware/r_opengl/r_opengl.c b/src/hardware/r_opengl/r_opengl.c index 602766f9f..94cb6181f 100644 --- a/src/hardware/r_opengl/r_opengl.c +++ b/src/hardware/r_opengl/r_opengl.c @@ -3906,7 +3906,7 @@ void GL_RenderVhsEffect(fixed_t upbary, fixed_t downbary, UINT8 updistort, UINT8 pglBindTexture(GL_TEXTURE_2D, screenTextures[HWD_SCREENTEXTURE_VHS]); tex_downloaded = screenTextures[HWD_SCREENTEXTURE_VHS]; - GL_SetShader(HWR_GetShaderFromTarget(SHADER_VHS_FUZZ)); + GL_SetShader(HWR_GetShaderFromTarget(SHADER_VHS)); GL_Shader_SetUniforms(NULL, NULL, NULL, NULL); pglColor4ubv(white); @@ -3916,26 +3916,6 @@ void GL_RenderVhsEffect(fixed_t upbary, fixed_t downbary, UINT8 updistort, UINT8 pglDrawArrays(GL_TRIANGLE_FAN, 0, 4); GL_UnSetShader(); - - // Upward and Downward bars - // theyre combined since the original shader also did this - // also saves us another screen copy + draw anyways - GL_MakeScreenTexture(HWD_SCREENTEXTURE_VHS); - pglActiveTexture(GL_TEXTURE0); - pglBindTexture(GL_TEXTURE_2D, screenTextures[HWD_SCREENTEXTURE_VHS]); - tex_downloaded = screenTextures[HWD_SCREENTEXTURE_VHS]; - - GL_SetShader(HWR_GetShaderFromTarget(SHADER_VHS_BAR)); - GL_Shader_SetUniforms(NULL, NULL, NULL, NULL); - pglColor4ubv(white); - - pglEnableClientState(GL_TEXTURE_COORD_ARRAY); - pglTexCoordPointer(2, GL_FLOAT, 0, fix); - pglVertexPointer(3, GL_FLOAT, 0, defaultscreenVerts); - pglDrawArrays(GL_TRIANGLE_FAN, 0, 4); - - GL_UnSetShader(); - } else // fallback fixed function version, this is quite slow {