mirror of
https://github.com/libretro/glsl-shaders.git
synced 2024-11-23 07:40:29 +00:00
update crt-hyllian shaders and presets, move hyllians crt stuff into … (#136)
* update crt-hyllian shaders and presets, move hyllians crt stuff into a dedicated dir * fix glow mask
This commit is contained in:
parent
bd6cc0c838
commit
d95c2454cc
@ -24,6 +24,7 @@
|
||||
*/
|
||||
|
||||
// Parameter lines go here:
|
||||
#pragma parameter SB_BLUR_LEVEL "Smart Blur Level" 0.66 0.00 1.00 0.02
|
||||
#pragma parameter SB_RED_THRESHOLD "Smart Blur Red Threshold" 0.2 0.0 0.6 0.01
|
||||
#pragma parameter SB_GREEN_THRESHOLD "Smart Blur Green Threshold" 0.2 0.0 0.6 0.01
|
||||
#pragma parameter SB_BLUE_THRESHOLD "Smart Blur Blue Threshold" 0.2 0.0 0.6 0.01
|
||||
@ -69,10 +70,12 @@ uniform COMPAT_PRECISION vec2 InputSize;
|
||||
#define OutSize vec4(OutputSize, 1.0 / OutputSize)
|
||||
|
||||
#ifdef PARAMETER_UNIFORM
|
||||
uniform COMPAT_PRECISION float SB_BLUR_LEVEL;
|
||||
uniform COMPAT_PRECISION float SB_RED_THRESHOLD;
|
||||
uniform COMPAT_PRECISION float SB_GREEN_THRESHOLD;
|
||||
uniform COMPAT_PRECISION float SB_BLUE_THRESHOLD;
|
||||
#else
|
||||
#define SB_BLUR_LEVEL 0.66
|
||||
#define SB_RED_THRESHOLD 0.2
|
||||
#define SB_GREEN_THRESHOLD 0.2
|
||||
#define SB_BLUE_THRESHOLD 0.2
|
||||
@ -133,10 +136,12 @@ COMPAT_VARYING vec4 t3;
|
||||
#define OutSize vec4(OutputSize, 1.0 / OutputSize)
|
||||
|
||||
#ifdef PARAMETER_UNIFORM
|
||||
uniform COMPAT_PRECISION float SB_BLUR_LEVEL;
|
||||
uniform COMPAT_PRECISION float SB_RED_THRESHOLD;
|
||||
uniform COMPAT_PRECISION float SB_GREEN_THRESHOLD;
|
||||
uniform COMPAT_PRECISION float SB_BLUE_THRESHOLD;
|
||||
#else
|
||||
#define SB_BLUR_LEVEL 0.66
|
||||
#define SB_RED_THRESHOLD 0.2
|
||||
#define SB_GREEN_THRESHOLD 0.2
|
||||
#define SB_BLUE_THRESHOLD 0.2
|
||||
@ -172,8 +177,8 @@ void main()
|
||||
|
||||
if (eq(E,F) && eq(E,H) && eq(E,I) && eq(E,B) && eq(E,C) && eq(E,A) && eq(E,D) && eq(E,G))
|
||||
{
|
||||
sum = (E+A+C+D+F+G+I+B+H)/9.0;
|
||||
E = sum;
|
||||
sum = (A+C+D+F+G+I+B+H)/8.0;
|
||||
E = mix(E, sum, SB_BLUR_LEVEL);
|
||||
}
|
||||
|
||||
FragColor = vec4(E, 1.0);
|
||||
|
@ -1,5 +1,5 @@
|
||||
shaders = 1
|
||||
|
||||
shader0 = shaders/crt-hyllian-3d.glsl
|
||||
shader0 = shaders/hyllian/crt-hyllian-3d.glsl
|
||||
filter_linear0 = true
|
||||
srgb_framebuffer0 = true
|
||||
|
@ -4,7 +4,7 @@ shader0 = shaders/glow/linearize.glsl
|
||||
filter_linear0 = false
|
||||
srgb_framebuffer0 = true
|
||||
|
||||
shader1 = shaders/crt-hyllian-glow/crt-hyllian.glsl
|
||||
shader1 = shaders/hyllian/crt-hyllian-glow/crt-hyllian-glow.glsl
|
||||
filter_linear1 = false
|
||||
scale_type1 = viewport
|
||||
scale1 = 1.0
|
||||
@ -26,5 +26,5 @@ shader4 = shaders/glow/blur_vert.glsl
|
||||
filter_linear4 = true
|
||||
srgb_framebuffer4 = true
|
||||
|
||||
shader5 = shaders/crt-hyllian-glow/resolve2.glsl
|
||||
shader5 = shaders/hyllian/crt-hyllian-glow/resolve2.glsl
|
||||
filter_linear5 = true
|
||||
|
@ -1,6 +1,6 @@
|
||||
shaders = 2
|
||||
|
||||
shader0 = shaders/crt-hyllian-multipass/crt-hyllian-pass0.glsl
|
||||
shader0 = shaders/hyllian/crt-hyllian-multipass/crt-hyllian-pass0.glsl
|
||||
filter_linear0 = false
|
||||
srgb_framebuffer0 = true
|
||||
scale_type_x0 = viewport
|
||||
@ -8,6 +8,6 @@ scale_type_y0 = source
|
||||
scale_x0 = 1.0
|
||||
scale_y0 = 1.0
|
||||
|
||||
shader1 = shaders/crt-hyllian-multipass/crt-hyllian-pass1.glsl
|
||||
shader1 = shaders/hyllian/crt-hyllian-multipass/crt-hyllian-pass1.glsl
|
||||
filter_linear1 = false
|
||||
srgb_framebuffer1 = false
|
||||
|
@ -1,5 +1,5 @@
|
||||
shaders = 1
|
||||
|
||||
shader0 = shaders/crt-hyllian.glsl
|
||||
shader0 = shaders/hyllian/crt-hyllian.glsl
|
||||
filter_linear0 = false
|
||||
srgb_framebuffer0 = true
|
||||
|
@ -1,284 +0,0 @@
|
||||
#version 130
|
||||
|
||||
/*
|
||||
Hyllian's CRT Shader
|
||||
|
||||
Copyright (C) 2011-2015 Hyllian - sergiogdb@gmail.com
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
|
||||
*/
|
||||
|
||||
#pragma parameter PHOSPHOR "CRT - Phosphor ON/OFF" 0.0 0.0 1.0 1.0
|
||||
#pragma parameter VSCANLINES "CRT - Scanlines Direction" 0.0 0.0 1.0 1.0
|
||||
#pragma parameter InputGamma "CRT - Input gamma" 2.2 0.0 5.0 0.1
|
||||
#pragma parameter OutputGamma "CRT - Output Gamma" 2.2 0.0 5.0 0.1
|
||||
#pragma parameter SHARPNESS "CRT - Sharpness Hack" 2.0 1.0 5.0 1.0
|
||||
#pragma parameter COLOR_BOOST "CRT - Color Boost" 1.3 1.0 2.0 0.05
|
||||
#pragma parameter RED_BOOST "CRT - Red Boost" 1.0 1.0 2.0 0.01
|
||||
#pragma parameter GREEN_BOOST "CRT - Green Boost" 1.0 1.0 2.0 0.01
|
||||
#pragma parameter BLUE_BOOST "CRT - Blue Boost" 1.0 1.0 2.0 0.01
|
||||
#pragma parameter SCANLINES_STRENGTH "CRT - Scanline Strength" 1.0 0.0 1.0 0.02
|
||||
#pragma parameter BEAM_MIN_WIDTH "CRT - Min Beam Width" 0.60 0.0 1.0 0.02
|
||||
#pragma parameter BEAM_MAX_WIDTH "CRT - Max Beam Width" 0.80 0.0 1.0 0.02
|
||||
#pragma parameter CRT_ANTI_RINGING "CRT - Anti-Ringing" 0.8 0.0 1.0 0.1
|
||||
|
||||
#define GAMMA_IN(color) pow(color, vec3(InputGamma, InputGamma, InputGamma))
|
||||
#define GAMMA_OUT(color) pow(color, vec3(1.0 / OutputGamma, 1.0 / OutputGamma, 1.0 / OutputGamma))
|
||||
|
||||
// Horizontal cubic filter.
|
||||
|
||||
// Some known filters use these values:
|
||||
|
||||
// B = 0.0, C = 0.0 => Hermite cubic filter.
|
||||
// B = 1.0, C = 0.0 => Cubic B-Spline filter.
|
||||
// B = 0.0, C = 0.5 => Catmull-Rom Spline filter. This is the default used in this shader.
|
||||
// B = C = 1.0/3.0 => Mitchell-Netravali cubic filter.
|
||||
// B = 0.3782, C = 0.3109 => Robidoux filter.
|
||||
// B = 0.2620, C = 0.3690 => Robidoux Sharp filter.
|
||||
// B = 0.36, C = 0.28 => My best config for ringing elimination in pixel art (Hyllian).
|
||||
|
||||
// For more info, see: http://www.imagemagick.org/Usage/img_diagrams/cubic_survey.gif
|
||||
|
||||
#if defined(VERTEX)
|
||||
|
||||
#if __VERSION__ >= 130
|
||||
#define COMPAT_VARYING out
|
||||
#define COMPAT_ATTRIBUTE in
|
||||
#define COMPAT_TEXTURE texture
|
||||
#else
|
||||
#define COMPAT_VARYING varying
|
||||
#define COMPAT_ATTRIBUTE attribute
|
||||
#define COMPAT_TEXTURE texture2D
|
||||
#endif
|
||||
|
||||
#ifdef GL_ES
|
||||
#define COMPAT_PRECISION mediump
|
||||
#else
|
||||
#define COMPAT_PRECISION
|
||||
#endif
|
||||
|
||||
COMPAT_ATTRIBUTE vec4 VertexCoord;
|
||||
COMPAT_ATTRIBUTE vec4 COLOR;
|
||||
COMPAT_ATTRIBUTE vec4 TexCoord;
|
||||
COMPAT_VARYING vec4 COL0;
|
||||
COMPAT_VARYING vec4 TEX0;
|
||||
|
||||
vec4 _oPosition1;
|
||||
uniform mat4 MVPMatrix;
|
||||
uniform COMPAT_PRECISION int FrameDirection;
|
||||
uniform COMPAT_PRECISION int FrameCount;
|
||||
uniform COMPAT_PRECISION vec2 OutputSize;
|
||||
uniform COMPAT_PRECISION vec2 TextureSize;
|
||||
uniform COMPAT_PRECISION vec2 InputSize;
|
||||
|
||||
// compatibility #defines
|
||||
#define vTexCoord TEX0.xy
|
||||
#define SourceSize vec4(TextureSize, 1.0 / TextureSize) //either TextureSize or InputSize
|
||||
#define OutSize vec4(OutputSize, 1.0 / OutputSize)
|
||||
|
||||
#ifdef PARAMETER_UNIFORM
|
||||
uniform COMPAT_PRECISION float PHOSPHOR;
|
||||
uniform COMPAT_PRECISION float VSCANLINES;
|
||||
uniform COMPAT_PRECISION float InputGamma;
|
||||
uniform COMPAT_PRECISION float OutputGamma;
|
||||
uniform COMPAT_PRECISION float SHARPNESS;
|
||||
uniform COMPAT_PRECISION float COLOR_BOOST;
|
||||
uniform COMPAT_PRECISION float RED_BOOST;
|
||||
uniform COMPAT_PRECISION float GREEN_BOOST;
|
||||
uniform COMPAT_PRECISION float BLUE_BOOST;
|
||||
uniform COMPAT_PRECISION float SCANLINES_STRENGTH;
|
||||
uniform COMPAT_PRECISION float BEAM_MIN_WIDTH;
|
||||
uniform COMPAT_PRECISION float BEAM_MAX_WIDTH;
|
||||
uniform COMPAT_PRECISION float CRT_ANTI_RINGING;
|
||||
#else
|
||||
#define PHOSPHOR 0.0
|
||||
#define VSCANLINES 0.0
|
||||
#define InputGamma 2.2
|
||||
#define OutputGamma 2.2
|
||||
#define SHARPNESS 2.0
|
||||
#define COLOR_BOOST 1.3
|
||||
#define RED_BOOST 1.0
|
||||
#define GREEN_BOOST 1.0
|
||||
#define BLUE_BOOST 1.0
|
||||
#define SCANLINES_STRENGTH 1.0
|
||||
#define BEAM_MIN_WIDTH 0.60
|
||||
#define BEAM_MAX_WIDTH 0.80
|
||||
#define CRT_ANTI_RINGING 0.8
|
||||
#endif
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = MVPMatrix * VertexCoord;
|
||||
TEX0.xy = TexCoord.xy;
|
||||
}
|
||||
|
||||
#elif defined(FRAGMENT)
|
||||
|
||||
#ifdef GL_ES
|
||||
#ifdef GL_FRAGMENT_PRECISION_HIGH
|
||||
precision highp float;
|
||||
#else
|
||||
precision mediump float;
|
||||
#endif
|
||||
#define COMPAT_PRECISION mediump
|
||||
#else
|
||||
#define COMPAT_PRECISION
|
||||
#endif
|
||||
|
||||
#if __VERSION__ >= 130
|
||||
#define COMPAT_VARYING in
|
||||
#define COMPAT_TEXTURE texture
|
||||
out COMPAT_PRECISION vec4 FragColor;
|
||||
#else
|
||||
#define COMPAT_VARYING varying
|
||||
#define FragColor gl_FragColor
|
||||
#define COMPAT_TEXTURE texture2D
|
||||
#endif
|
||||
|
||||
uniform COMPAT_PRECISION int FrameDirection;
|
||||
uniform COMPAT_PRECISION int FrameCount;
|
||||
uniform COMPAT_PRECISION vec2 OutputSize;
|
||||
uniform COMPAT_PRECISION vec2 TextureSize;
|
||||
uniform COMPAT_PRECISION vec2 InputSize;
|
||||
uniform sampler2D Texture;
|
||||
COMPAT_VARYING vec4 TEX0;
|
||||
|
||||
// compatibility #defines
|
||||
#define Source Texture
|
||||
#define vTexCoord TEX0.xy
|
||||
|
||||
#define SourceSize vec4(TextureSize, 1.0 / TextureSize) //either TextureSize or InputSize
|
||||
#define OutSize vec4(OutputSize, 1.0 / OutputSize)
|
||||
|
||||
#ifdef PARAMETER_UNIFORM
|
||||
uniform COMPAT_PRECISION float PHOSPHOR;
|
||||
uniform COMPAT_PRECISION float VSCANLINES;
|
||||
uniform COMPAT_PRECISION float InputGamma;
|
||||
uniform COMPAT_PRECISION float OutputGamma;
|
||||
uniform COMPAT_PRECISION float SHARPNESS;
|
||||
uniform COMPAT_PRECISION float COLOR_BOOST;
|
||||
uniform COMPAT_PRECISION float RED_BOOST;
|
||||
uniform COMPAT_PRECISION float GREEN_BOOST;
|
||||
uniform COMPAT_PRECISION float BLUE_BOOST;
|
||||
uniform COMPAT_PRECISION float SCANLINES_STRENGTH;
|
||||
uniform COMPAT_PRECISION float BEAM_MIN_WIDTH;
|
||||
uniform COMPAT_PRECISION float BEAM_MAX_WIDTH;
|
||||
uniform COMPAT_PRECISION float CRT_ANTI_RINGING;
|
||||
#else
|
||||
#define PHOSPHOR 0.0
|
||||
#define VSCANLINES 0.0
|
||||
#define InputGamma 2.2
|
||||
#define OutputGamma 2.2
|
||||
#define SHARPNESS 2.0
|
||||
#define COLOR_BOOST 1.3
|
||||
#define RED_BOOST 1.0
|
||||
#define GREEN_BOOST 1.0
|
||||
#define BLUE_BOOST 1.0
|
||||
#define SCANLINES_STRENGTH 1.0
|
||||
#define BEAM_MIN_WIDTH 0.60
|
||||
#define BEAM_MAX_WIDTH 0.80
|
||||
#define CRT_ANTI_RINGING 0.8
|
||||
#endif
|
||||
|
||||
// Change these params to configure the horizontal filter.
|
||||
float B = 0.0;
|
||||
float C = 0.5;
|
||||
|
||||
mat4 invX = mat4(
|
||||
(-B - 6.0*C)/6.0, (3.0*B + 12.0*C)/6.0, (-3.0*B - 6.0*C)/6.0, B/6.0,
|
||||
(12.0 - 9.0*B - 6.0*C)/6.0, (-18.0 + 12.0*B + 6.0*C)/6.0, 0.0, (6.0 - 2.0*B)/6.0,
|
||||
-(12.0 - 9.0*B - 6.0*C)/6.0, (18.0 - 15.0*B - 12.0*C)/6.0, (3.0*B + 6.0*C)/6.0, B/6.0,
|
||||
(B + 6.0*C)/6.0, -C, 0.0, 0.0
|
||||
);
|
||||
|
||||
void main()
|
||||
{
|
||||
vec3 color;
|
||||
|
||||
vec2 TexSize = vec2(SHARPNESS*SourceSize.x, SourceSize.y);
|
||||
|
||||
vec2 dx = mix(vec2(1.0/TexSize.x, 0.0), vec2(0.0, 1.0/TexSize.y), VSCANLINES);
|
||||
vec2 dy = mix(vec2(0.0, 1.0/TexSize.y), vec2(1.0/TexSize.x, 0.0), VSCANLINES);
|
||||
|
||||
vec2 pix_coord = vTexCoord*TexSize + vec2(-0.5, 0.5);
|
||||
|
||||
vec2 tc = mix((floor(pix_coord) + vec2(0.5, 0.5))/TexSize, (floor(pix_coord) + vec2(1.0, -0.5))/TexSize, VSCANLINES);
|
||||
|
||||
vec2 fp = mix(fract(pix_coord), fract(pix_coord.yx), VSCANLINES);
|
||||
|
||||
vec3 c00 = GAMMA_IN(COMPAT_TEXTURE(Source, tc - dx - dy).xyz);
|
||||
vec3 c01 = GAMMA_IN(COMPAT_TEXTURE(Source, tc - dy).xyz);
|
||||
vec3 c02 = GAMMA_IN(COMPAT_TEXTURE(Source, tc + dx - dy).xyz);
|
||||
vec3 c03 = GAMMA_IN(COMPAT_TEXTURE(Source, tc + 2.0*dx - dy).xyz);
|
||||
vec3 c10 = GAMMA_IN(COMPAT_TEXTURE(Source, tc - dx ).xyz);
|
||||
vec3 c11 = GAMMA_IN(COMPAT_TEXTURE(Source, tc ).xyz);
|
||||
vec3 c12 = GAMMA_IN(COMPAT_TEXTURE(Source, tc + dx ).xyz);
|
||||
vec3 c13 = GAMMA_IN(COMPAT_TEXTURE(Source, tc + 2.0*dx ).xyz);
|
||||
|
||||
// Get min/max samples
|
||||
vec3 min_sample = min(min(c01, c11), min(c02, c12));
|
||||
vec3 max_sample = max(max(c01, c11), max(c02, c12));
|
||||
|
||||
mat4x3 color_matrix0 = mat4x3(c00, c01, c02, c03);
|
||||
mat4x3 color_matrix1 = mat4x3(c10, c11, c12, c13);
|
||||
|
||||
vec4 invX_Px = vec4(fp.x*fp.x*fp.x, fp.x*fp.x, fp.x, 1.0) * invX;
|
||||
vec3 color0 = color_matrix0 * invX_Px;
|
||||
vec3 color1 = color_matrix1 * invX_Px;
|
||||
|
||||
// Anti-ringing
|
||||
vec3 aux = color0;
|
||||
color0 = clamp(color0, min_sample, max_sample);
|
||||
color0 = mix(aux, color0, CRT_ANTI_RINGING);
|
||||
aux = color1;
|
||||
color1 = clamp(color1, min_sample, max_sample);
|
||||
color1 = mix(aux, color1, CRT_ANTI_RINGING);
|
||||
|
||||
float pos0 = fp.y;
|
||||
float pos1 = 1 - fp.y;
|
||||
|
||||
vec3 lum0 = mix(vec3(BEAM_MIN_WIDTH), vec3(BEAM_MAX_WIDTH), color0);
|
||||
vec3 lum1 = mix(vec3(BEAM_MIN_WIDTH), vec3(BEAM_MAX_WIDTH), color1);
|
||||
|
||||
vec3 d0 = clamp(pos0/(lum0 + 0.0000001), 0.0, 1.0);
|
||||
vec3 d1 = clamp(pos1/(lum1 + 0.0000001), 0.0, 1.0);
|
||||
|
||||
d0 = exp(-10.0*SCANLINES_STRENGTH*d0*d0);
|
||||
d1 = exp(-10.0*SCANLINES_STRENGTH*d1*d1);
|
||||
|
||||
color = clamp(color0*d0 + color1*d1, 0.0, 1.0);
|
||||
|
||||
color *= COLOR_BOOST*vec3(RED_BOOST, GREEN_BOOST, BLUE_BOOST);
|
||||
|
||||
float mod_factor = mix(vTexCoord.x * OutputSize.x, vTexCoord.y * OutputSize.y, VSCANLINES);
|
||||
|
||||
vec3 dotMaskWeights = mix(
|
||||
vec3(1.0, 0.7, 1.0),
|
||||
vec3(0.7, 1.0, 0.7),
|
||||
floor(mod(mod_factor, 2.0))
|
||||
);
|
||||
|
||||
color.rgb *= mix(vec3(1.0), dotMaskWeights, PHOSPHOR);
|
||||
|
||||
color = GAMMA_OUT(color);
|
||||
|
||||
FragColor = vec4(color, 1.0);
|
||||
}
|
||||
#endif
|
@ -1,117 +0,0 @@
|
||||
// version directive if necessary
|
||||
|
||||
// good place for credits/license
|
||||
|
||||
#pragma parameter BLOOM_STRENGTH "Bloom Strength" 0.45 0.0 1.0 0.01
|
||||
#pragma parameter SOURCE_BOOST "Bloom Color Boost" 1.15 1.0 1.3 0.01
|
||||
|
||||
#define INV_OUTPUT_GAMMA (1.0 / 2.2)
|
||||
#define saturate(c) clamp(c, 0.0, 1.0)
|
||||
|
||||
#if defined(VERTEX)
|
||||
|
||||
#if __VERSION__ >= 130
|
||||
#define COMPAT_VARYING out
|
||||
#define COMPAT_ATTRIBUTE in
|
||||
#define COMPAT_TEXTURE texture
|
||||
#else
|
||||
#define COMPAT_VARYING varying
|
||||
#define COMPAT_ATTRIBUTE attribute
|
||||
#define COMPAT_TEXTURE texture2D
|
||||
#endif
|
||||
|
||||
#ifdef GL_ES
|
||||
#define COMPAT_PRECISION mediump
|
||||
#else
|
||||
#define COMPAT_PRECISION
|
||||
#endif
|
||||
|
||||
COMPAT_ATTRIBUTE vec4 VertexCoord;
|
||||
COMPAT_ATTRIBUTE vec4 COLOR;
|
||||
COMPAT_ATTRIBUTE vec4 TexCoord;
|
||||
COMPAT_VARYING vec4 COL0;
|
||||
COMPAT_VARYING vec4 TEX0;
|
||||
|
||||
vec4 _oPosition1;
|
||||
uniform mat4 MVPMatrix;
|
||||
uniform COMPAT_PRECISION int FrameDirection;
|
||||
uniform COMPAT_PRECISION int FrameCount;
|
||||
uniform COMPAT_PRECISION vec2 OutputSize;
|
||||
uniform COMPAT_PRECISION vec2 TextureSize;
|
||||
uniform COMPAT_PRECISION vec2 InputSize;
|
||||
|
||||
// compatibility #defines
|
||||
#define vTexCoord TEX0.xy
|
||||
#define SourceSize vec4(TextureSize, 1.0 / TextureSize) //either TextureSize or InputSize
|
||||
#define OutSize vec4(OutputSize, 1.0 / OutputSize)
|
||||
|
||||
#ifdef PARAMETER_UNIFORM
|
||||
uniform COMPAT_PRECISION float BLOOM_STRENGTH;
|
||||
uniform COMPAT_PRECISION float SOURCE_BOOST;
|
||||
#else
|
||||
#define BLOOM_STRENGTH 0.45
|
||||
#define SOURCE_BOOST 1.15
|
||||
#endif
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = MVPMatrix * VertexCoord;
|
||||
TEX0.xy = TexCoord.xy;
|
||||
}
|
||||
|
||||
#elif defined(FRAGMENT)
|
||||
|
||||
#ifdef GL_ES
|
||||
#ifdef GL_FRAGMENT_PRECISION_HIGH
|
||||
precision highp float;
|
||||
#else
|
||||
precision mediump float;
|
||||
#endif
|
||||
#define COMPAT_PRECISION mediump
|
||||
#else
|
||||
#define COMPAT_PRECISION
|
||||
#endif
|
||||
|
||||
#if __VERSION__ >= 130
|
||||
#define COMPAT_VARYING in
|
||||
#define COMPAT_TEXTURE texture
|
||||
out COMPAT_PRECISION vec4 FragColor;
|
||||
#else
|
||||
#define COMPAT_VARYING varying
|
||||
#define FragColor gl_FragColor
|
||||
#define COMPAT_TEXTURE texture2D
|
||||
#endif
|
||||
|
||||
uniform COMPAT_PRECISION int FrameDirection;
|
||||
uniform COMPAT_PRECISION int FrameCount;
|
||||
uniform COMPAT_PRECISION vec2 OutputSize;
|
||||
uniform COMPAT_PRECISION vec2 TextureSize;
|
||||
uniform COMPAT_PRECISION vec2 InputSize;
|
||||
uniform sampler2D Texture;
|
||||
uniform sampler2D Pass2Texture;
|
||||
#define CRT_PASS Pass2Texture
|
||||
COMPAT_VARYING vec4 TEX0;
|
||||
|
||||
// compatibility #defines
|
||||
#define Source Texture
|
||||
#define vTexCoord TEX0.xy
|
||||
|
||||
#define SourceSize vec4(TextureSize, 1.0 / TextureSize) //either TextureSize or InputSize
|
||||
#define OutSize vec4(OutputSize, 1.0 / OutputSize)
|
||||
|
||||
#ifdef PARAMETER_UNIFORM
|
||||
uniform COMPAT_PRECISION float BLOOM_STRENGTH;
|
||||
uniform COMPAT_PRECISION float SOURCE_BOOST;
|
||||
#else
|
||||
#define BLOOM_STRENGTH 0.45
|
||||
#define SOURCE_BOOST 1.15
|
||||
#endif
|
||||
|
||||
void main()
|
||||
{
|
||||
vec3 source = SOURCE_BOOST * COMPAT_TEXTURE(CRT_PASS, vTexCoord).rgb;
|
||||
vec3 bloom = COMPAT_TEXTURE(Source, vTexCoord).rgb;
|
||||
source += BLOOM_STRENGTH * bloom;
|
||||
FragColor = vec4(pow(saturate(source), vec3(INV_OUTPUT_GAMMA,INV_OUTPUT_GAMMA,INV_OUTPUT_GAMMA)), 1.0);
|
||||
}
|
||||
#endif
|
306
crt/shaders/hyllian/crt-hyllian-curvature-glow.glsl
Normal file
306
crt/shaders/hyllian/crt-hyllian-curvature-glow.glsl
Normal file
@ -0,0 +1,306 @@
|
||||
/*
|
||||
Hyllian's CRT Shader
|
||||
|
||||
Copyright (C) 2011-2020 Hyllian - sergiogdb@gmail.com
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
|
||||
*/
|
||||
|
||||
#version 120
|
||||
|
||||
#pragma parameter BEAM_PROFILE "BEAM PROFILE (BP)" 0.0 0.0 6.0 1.0
|
||||
#pragma parameter BEAM_MIN_WIDTH " Custom [If BP=0.00] MIN BEAM WIDTH" 0.86 0.0 1.0 0.02
|
||||
#pragma parameter BEAM_MAX_WIDTH " Custom [If BP=0.00] MAX BEAM WIDTH" 1.0 0.0 1.0 0.02
|
||||
#pragma parameter SCANLINES_STRENGTH " Custom [If BP=0.00] SCANLINES STRENGTH" 0.58 0.0 1.0 0.02
|
||||
#pragma parameter COLOR_BOOST " Custom [If BP=0.00] COLOR BOOST" 1.25 1.0 2.0 0.05
|
||||
#pragma parameter HFILTER_SHARPNESS "HORIZONTAL FILTER SHARPNESS" 1.0 0.0 1.0 0.02
|
||||
#pragma parameter CRT_ANTI_RINGING "ANTI RINGING" 1.0 0.0 1.0 0.1
|
||||
#pragma parameter InputGamma "INPUT GAMMA" 2.4 0.0 5.0 0.1
|
||||
#pragma parameter OutputGamma "OUTPUT GAMMA" 2.2 0.0 5.0 0.1
|
||||
#pragma parameter VSCANLINES "SCANLINES DIRECTION" 0.0 0.0 1.0 1.0
|
||||
#pragma parameter CRT_CURVATURE "CRT-Curvature" 1.0 0.0 1.0 1.0
|
||||
#pragma parameter CRT_warpX "CRT-Curvature X-Axis" 0.031 0.0 0.125 0.01
|
||||
#pragma parameter CRT_warpY "CRT-Curvature Y-Axis" 0.041 0.0 0.125 0.01
|
||||
#pragma parameter CRT_cornersize "CRT-Corner Size" 0.01 0.001 1.0 0.005
|
||||
#define cornersize CRT_cornersize
|
||||
#pragma parameter CRT_cornersmooth "CRT-Corner Smoothness" 1000.0 80.0 2000.0 100.0
|
||||
#define cornersmooth CRT_cornersmooth
|
||||
|
||||
#define GAMMA_IN(color) pow(color, vec4(InputGamma, InputGamma, InputGamma, InputGamma))
|
||||
#define GAMMA_OUT(color) pow(color, vec4(1.0 / OutputGamma, 1.0 / OutputGamma, 1.0 / OutputGamma, 1.0 / OutputGamma))
|
||||
|
||||
|
||||
#define texCoord TEX0
|
||||
|
||||
#if defined(VERTEX)
|
||||
|
||||
#if __VERSION__ >= 130
|
||||
#define OUT out
|
||||
#define IN in
|
||||
#define tex2D texture
|
||||
#else
|
||||
#define OUT varying
|
||||
#define IN attribute
|
||||
#define tex2D texture2D
|
||||
#endif
|
||||
|
||||
#ifdef GL_ES
|
||||
#define PRECISION mediump
|
||||
#else
|
||||
#define PRECISION
|
||||
#endif
|
||||
|
||||
|
||||
IN vec4 VertexCoord;
|
||||
IN vec4 Color;
|
||||
IN vec2 TexCoord;
|
||||
OUT vec4 color;
|
||||
OUT vec2 texCoord;
|
||||
|
||||
uniform mat4 MVPMatrix;
|
||||
uniform PRECISION int FrameDirection;
|
||||
uniform PRECISION int FrameCount;
|
||||
uniform PRECISION vec2 OutputSize;
|
||||
uniform PRECISION vec2 TextureSize;
|
||||
uniform PRECISION vec2 InputSize;
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = MVPMatrix * VertexCoord;
|
||||
color = Color;
|
||||
texCoord = TexCoord;
|
||||
}
|
||||
|
||||
|
||||
#elif defined(FRAGMENT)
|
||||
|
||||
#if __VERSION__ >= 130
|
||||
#define IN in
|
||||
#define tex2D texture
|
||||
out vec4 FragColor;
|
||||
#else
|
||||
#define IN varying
|
||||
#define FragColor gl_FragColor
|
||||
#define tex2D texture2D
|
||||
#endif
|
||||
|
||||
#ifdef GL_ES
|
||||
#ifdef GL_FRAGMENT_PRECISION_HIGH
|
||||
precision highp float;
|
||||
#else
|
||||
precision mediump float;
|
||||
#endif
|
||||
#define PRECISION mediump
|
||||
#else
|
||||
#define PRECISION
|
||||
#endif
|
||||
|
||||
uniform PRECISION int FrameDirection;
|
||||
uniform PRECISION int FrameCount;
|
||||
uniform PRECISION vec2 OutputSize;
|
||||
uniform PRECISION vec2 TextureSize;
|
||||
uniform PRECISION vec2 InputSize;
|
||||
uniform sampler2D s_p;
|
||||
IN vec2 texCoord;
|
||||
|
||||
#ifdef PARAMETER_UNIFORM
|
||||
uniform PRECISION float BEAM_PROFILE;
|
||||
uniform PRECISION float BEAM_MIN_WIDTH;
|
||||
uniform PRECISION float BEAM_MAX_WIDTH;
|
||||
uniform PRECISION float SCANLINES_STRENGTH;
|
||||
uniform PRECISION float COLOR_BOOST;
|
||||
uniform PRECISION float HFILTER_SHARPNESS;
|
||||
uniform PRECISION float CRT_ANTI_RINGING;
|
||||
uniform PRECISION float InputGamma;
|
||||
uniform PRECISION float OutputGamma;
|
||||
uniform PRECISION float VSCANLINES;
|
||||
uniform PRECISION float CRT_CURVATURE;
|
||||
uniform PRECISION float CRT_warpX;
|
||||
uniform PRECISION float CRT_warpY;
|
||||
uniform PRECISION float CRT_cornersize;
|
||||
uniform PRECISION float CRT_cornersmooth;
|
||||
#else
|
||||
#define BEAM_PROFILE 0.0
|
||||
#define BEAM_MIN_WIDTH 0.86
|
||||
#define BEAM_MAX_WIDTH 1.0
|
||||
#define SCANLINES_STRENGTH 0.58
|
||||
#define COLOR_BOOST 1.25
|
||||
#define HFILTER_SHARPNESS 1.0
|
||||
#define CRT_ANTI_RINGING 1.0
|
||||
#define InputGamma 2.4
|
||||
#define OutputGamma 2.2
|
||||
#define VSCANLINES 0.0
|
||||
#define CRT_CURVATURE 1.0
|
||||
#define CRT_warpX 0.031
|
||||
#define CRT_warpY 0.041
|
||||
#define CRT_cornersize 0.01
|
||||
#define CRT_cornersmooth 1000.0
|
||||
#endif
|
||||
// END PARAMETERS //
|
||||
|
||||
|
||||
|
||||
const vec2 corner_aspect = vec2(1.0, 0.75);
|
||||
vec2 CRT_Distortion = vec2(CRT_warpX, CRT_warpY) * 15.;
|
||||
|
||||
|
||||
float corner(vec2 coord)
|
||||
{
|
||||
coord = (coord - vec2(0.5)) + vec2(0.5, 0.5);
|
||||
coord = min(coord, vec2(1.0) - coord) * corner_aspect;
|
||||
vec2 cdist = vec2(cornersize);
|
||||
coord = (cdist - min(coord, cdist));
|
||||
float dist = sqrt(dot(coord, coord));
|
||||
|
||||
return clamp((cdist.x - dist)*cornersmooth, 0.0, 1.0);
|
||||
}
|
||||
|
||||
|
||||
vec2 Warp(vec2 texCoord){
|
||||
|
||||
vec2 curvedCoords = texCoord * 2.0 - 1.0;
|
||||
float curvedCoordsDistance = sqrt(curvedCoords.x*curvedCoords.x+curvedCoords.y*curvedCoords.y);
|
||||
|
||||
curvedCoords = curvedCoords / curvedCoordsDistance;
|
||||
|
||||
curvedCoords = curvedCoords * (1.0-pow(vec2(1.0-(curvedCoordsDistance/1.4142135623730950488016887242097)),(1.0/(1.0+CRT_Distortion*0.2))));
|
||||
|
||||
curvedCoords = curvedCoords / (1.0-pow(vec2(0.29289321881345247559915563789515),(1.0/(vec2(1.0)+CRT_Distortion*0.2))));
|
||||
|
||||
curvedCoords = curvedCoords * 0.5 + 0.5;
|
||||
return curvedCoords;
|
||||
}
|
||||
|
||||
|
||||
// Horizontal cubic filter.
|
||||
|
||||
// Some known filters use these values:
|
||||
|
||||
// B = 0.0, C = 0.0 => Hermite cubic filter.
|
||||
// B = 1.0, C = 0.0 => Cubic B-Spline filter.
|
||||
// B = 0.0, C = 0.5 => Catmull-Rom Spline filter. This is the default used in this shader.
|
||||
// B = C = 1.0/3.0 => Mitchell-Netravali cubic filter.
|
||||
// B = 0.3782, C = 0.3109 => Robidoux filter.
|
||||
// B = 0.2620, C = 0.3690 => Robidoux Sharp filter.
|
||||
|
||||
float B = 1.0 - HFILTER_SHARPNESS;
|
||||
float C = HFILTER_SHARPNESS*0.5; // B+2C=1 Mitchel-Netravali recommendation line.
|
||||
|
||||
mat4 invX = mat4( (-B - 6.0*C)/6.0, (12.0 - 9.0*B - 6.0*C)/6.0, -(12.0 - 9.0*B - 6.0*C)/6.0, (B + 6.0*C)/6.0,
|
||||
(3.0*B + 12.0*C)/6.0, (-18.0 + 12.0*B + 6.0*C)/6.0, (18.0 - 15.0*B - 12.0*C)/6.0, -C,
|
||||
(-3.0*B - 6.0*C)/6.0, 0.0, (3.0*B + 6.0*C)/6.0, 0.0,
|
||||
B/6.0, (6.0 - 2.0*B)/6.0, B/6.0, 0.0);
|
||||
|
||||
|
||||
|
||||
#define scanlines_strength (4.0*profile.x)
|
||||
#define beam_min_width profile.y
|
||||
#define beam_max_width profile.z
|
||||
#define color_boost profile.w
|
||||
|
||||
vec4 get_beam_profile()
|
||||
{
|
||||
vec4 bp = vec4(SCANLINES_STRENGTH, BEAM_MIN_WIDTH, BEAM_MAX_WIDTH, COLOR_BOOST);
|
||||
|
||||
if (BEAM_PROFILE == 1.0) bp = vec4(0.40, 1.00, 1.00, 1.00); // Catmull-rom
|
||||
if (BEAM_PROFILE == 2.0) bp = vec4(0.72, 1.00, 1.00, 1.25); // Catmull-rom
|
||||
if (BEAM_PROFILE == 3.0) bp = vec4(0.60, 0.50, 1.00, 1.25); // Hermite
|
||||
if (BEAM_PROFILE == 4.0) bp = vec4(0.60, 0.72, 1.00, 1.25); // Hermite
|
||||
if (BEAM_PROFILE == 5.0) bp = vec4(0.68, 0.68, 1.00, 1.25); // Hermite
|
||||
if (BEAM_PROFILE == 6.0) bp = vec4(0.70, 0.50, 1.00, 1.80); // Catmull-rom
|
||||
|
||||
return bp;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void main()
|
||||
{
|
||||
vec4 profile = get_beam_profile();
|
||||
|
||||
vec2 dx = mix(vec2(1.0/TextureSize.x, 0.0), vec2(0.0, 1.0/TextureSize.y), VSCANLINES);
|
||||
vec2 dy = mix(vec2(0.0, 1.0/TextureSize.y), vec2(1.0/TextureSize.x, 0.0), VSCANLINES);
|
||||
|
||||
// vec2 pix_coord = texCoord.xy*TextureSize + vec2(-0.5, 0.5);
|
||||
|
||||
vec2 pp = texCoord.xy;
|
||||
pp = (CRT_CURVATURE > 0.5) ? (Warp(pp*TextureSize.xy/InputSize.xy)*InputSize.xy/TextureSize.xy) : pp;
|
||||
|
||||
|
||||
vec2 pix_coord = pp.xy*TextureSize + vec2(-0.5, 0.5);
|
||||
|
||||
vec2 tc = mix((floor(pix_coord) + vec2(0.5, 0.5))/TextureSize, (floor(pix_coord) + vec2(1.0, -0.5))/TextureSize, VSCANLINES);
|
||||
|
||||
vec2 fp = mix(fract(pix_coord), fract(pix_coord.yx), VSCANLINES);
|
||||
|
||||
vec4 c00 = GAMMA_IN(tex2D(s_p, tc - dx - dy).xyzw);
|
||||
vec4 c01 = GAMMA_IN(tex2D(s_p, tc - dy).xyzw);
|
||||
vec4 c02 = GAMMA_IN(tex2D(s_p, tc + dx - dy).xyzw);
|
||||
vec4 c03 = GAMMA_IN(tex2D(s_p, tc + 2.0*dx - dy).xyzw);
|
||||
vec4 c10 = GAMMA_IN(tex2D(s_p, tc - dx).xyzw);
|
||||
vec4 c11 = GAMMA_IN(tex2D(s_p, tc ).xyzw);
|
||||
vec4 c12 = GAMMA_IN(tex2D(s_p, tc + dx).xyzw);
|
||||
vec4 c13 = GAMMA_IN(tex2D(s_p, tc + 2.0*dx).xyzw);
|
||||
|
||||
mat4 color_matrix0 = mat4(c00, c01, c02, c03);
|
||||
mat4 color_matrix1 = mat4(c10, c11, c12, c13);
|
||||
|
||||
vec4 lobes = vec4(fp.x*fp.x*fp.x, fp.x*fp.x, fp.x, 1.0);
|
||||
|
||||
vec4 invX_Px = invX * lobes;
|
||||
vec4 color0 = color_matrix0 * invX_Px;
|
||||
vec4 color1 = color_matrix1 * invX_Px;
|
||||
|
||||
// Get min/max samples
|
||||
vec4 min_sample0 = min(c01,c02);
|
||||
vec4 max_sample0 = max(c01,c02);
|
||||
vec4 min_sample1 = min(c11,c12);
|
||||
vec4 max_sample1 = max(c11,c12);
|
||||
|
||||
// Anti-ringing
|
||||
vec4 aux = color0;
|
||||
color0 = clamp(color0, min_sample0, max_sample0);
|
||||
color0 = mix(aux, color0, CRT_ANTI_RINGING);
|
||||
aux = color1;
|
||||
color1 = clamp(color1, min_sample1, max_sample1);
|
||||
color1 = mix(aux, color1, CRT_ANTI_RINGING);
|
||||
|
||||
float pos0 = fp.y;
|
||||
float pos1 = 1.0 - fp.y;
|
||||
|
||||
vec4 lum0 = mix(vec4(beam_min_width), vec4(beam_max_width), color0);
|
||||
vec4 lum1 = mix(vec4(beam_min_width), vec4(beam_max_width), color1);
|
||||
|
||||
vec4 d0 = scanlines_strength*pos0/(lum0+0.0000001);
|
||||
vec4 d1 = scanlines_strength*pos1/(lum1+0.0000001);
|
||||
|
||||
d0 = exp(-d0*d0);
|
||||
d1 = exp(-d1*d1);
|
||||
|
||||
vec4 color = color_boost*(color0*d0+color1*d1);
|
||||
|
||||
color = GAMMA_OUT(color);
|
||||
|
||||
FragColor = vec4(color);
|
||||
|
||||
FragColor *= (CRT_CURVATURE > 0.5) ? corner(pp*TextureSize.xy/InputSize.xy) : 1.0;
|
||||
}
|
||||
#endif
|
621
crt/shaders/hyllian/crt-hyllian-curvature.glsl
Normal file
621
crt/shaders/hyllian/crt-hyllian-curvature.glsl
Normal file
@ -0,0 +1,621 @@
|
||||
/*
|
||||
Hyllian's CRT Shader
|
||||
|
||||
Copyright (C) 2011-2020 Hyllian - sergiogdb@gmail.com
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
|
||||
*/
|
||||
|
||||
#version 120
|
||||
|
||||
#pragma parameter BEAM_PROFILE "BEAM PROFILE (BP)" 0.0 0.0 6.0 1.0
|
||||
#pragma parameter BEAM_MIN_WIDTH " Custom [If BP=0.00] MIN BEAM WIDTH" 0.86 0.0 1.0 0.02
|
||||
#pragma parameter BEAM_MAX_WIDTH " Custom [If BP=0.00] MAX BEAM WIDTH" 1.0 0.0 1.0 0.02
|
||||
#pragma parameter SCANLINES_STRENGTH " Custom [If BP=0.00] SCANLINES STRENGTH" 0.58 0.0 1.0 0.02
|
||||
#pragma parameter COLOR_BOOST " Custom [If BP=0.00] COLOR BOOST" 1.25 1.0 2.0 0.05
|
||||
#pragma parameter HFILTER_SHARPNESS "HORIZONTAL FILTER SHARPNESS" 1.0 0.0 1.0 0.02
|
||||
#pragma parameter PHOSPHOR_LAYOUT "PHOSPHOR LAYOUT" 4.0 0.0 19.0 1.0
|
||||
#pragma parameter MASK_INTENSITY "MASK INTENSITY" 0.5 0.0 1.0 0.1
|
||||
#pragma parameter CRT_ANTI_RINGING "ANTI RINGING" 1.0 0.0 1.0 0.1
|
||||
#pragma parameter InputGamma "INPUT GAMMA" 2.4 0.0 5.0 0.1
|
||||
#pragma parameter OutputGamma "OUTPUT GAMMA" 2.2 0.0 5.0 0.1
|
||||
#pragma parameter VSCANLINES "SCANLINES DIRECTION" 0.0 0.0 1.0 1.0
|
||||
#pragma parameter CRT_CURVATURE "CRT-Curvature" 1.0 0.0 1.0 1.0
|
||||
#pragma parameter CRT_warpX "CRT-Curvature X-Axis" 0.031 0.0 0.125 0.01
|
||||
#pragma parameter CRT_warpY "CRT-Curvature Y-Axis" 0.041 0.0 0.125 0.01
|
||||
#pragma parameter CRT_cornersize "CRT-Corner Size" 0.01 0.001 1.0 0.005
|
||||
#define cornersize CRT_cornersize
|
||||
#pragma parameter CRT_cornersmooth "CRT-Corner Smoothness" 1000.0 80.0 2000.0 100.0
|
||||
#define cornersmooth CRT_cornersmooth
|
||||
|
||||
#define GAMMA_IN(color) pow(color, vec4(InputGamma, InputGamma, InputGamma, InputGamma))
|
||||
#define GAMMA_OUT(color) pow(color, vec4(1.0 / OutputGamma, 1.0 / OutputGamma, 1.0 / OutputGamma, 1.0 / OutputGamma))
|
||||
|
||||
|
||||
#define texCoord TEX0
|
||||
|
||||
#if defined(VERTEX)
|
||||
|
||||
#if __VERSION__ >= 130
|
||||
#define OUT out
|
||||
#define IN in
|
||||
#define tex2D texture
|
||||
#else
|
||||
#define OUT varying
|
||||
#define IN attribute
|
||||
#define tex2D texture2D
|
||||
#endif
|
||||
|
||||
#ifdef GL_ES
|
||||
#define PRECISION mediump
|
||||
#else
|
||||
#define PRECISION
|
||||
#endif
|
||||
|
||||
|
||||
IN vec4 VertexCoord;
|
||||
IN vec4 Color;
|
||||
IN vec2 TexCoord;
|
||||
OUT vec4 color;
|
||||
OUT vec2 texCoord;
|
||||
|
||||
uniform mat4 MVPMatrix;
|
||||
uniform PRECISION int FrameDirection;
|
||||
uniform PRECISION int FrameCount;
|
||||
uniform PRECISION vec2 OutputSize;
|
||||
uniform PRECISION vec2 TextureSize;
|
||||
uniform PRECISION vec2 InputSize;
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = MVPMatrix * VertexCoord;
|
||||
color = Color;
|
||||
texCoord = TexCoord;
|
||||
}
|
||||
|
||||
|
||||
#elif defined(FRAGMENT)
|
||||
|
||||
#if __VERSION__ >= 130
|
||||
#define IN in
|
||||
#define tex2D texture
|
||||
out vec4 FragColor;
|
||||
#else
|
||||
#define IN varying
|
||||
#define FragColor gl_FragColor
|
||||
#define tex2D texture2D
|
||||
#endif
|
||||
|
||||
#ifdef GL_ES
|
||||
#ifdef GL_FRAGMENT_PRECISION_HIGH
|
||||
precision highp float;
|
||||
#else
|
||||
precision mediump float;
|
||||
#endif
|
||||
#define PRECISION mediump
|
||||
#else
|
||||
#define PRECISION
|
||||
#endif
|
||||
|
||||
uniform PRECISION int FrameDirection;
|
||||
uniform PRECISION int FrameCount;
|
||||
uniform PRECISION vec2 OutputSize;
|
||||
uniform PRECISION vec2 TextureSize;
|
||||
uniform PRECISION vec2 InputSize;
|
||||
uniform sampler2D s_p;
|
||||
IN vec2 texCoord;
|
||||
|
||||
#ifdef PARAMETER_UNIFORM
|
||||
uniform PRECISION float BEAM_PROFILE;
|
||||
uniform PRECISION float BEAM_MIN_WIDTH;
|
||||
uniform PRECISION float BEAM_MAX_WIDTH;
|
||||
uniform PRECISION float SCANLINES_STRENGTH;
|
||||
uniform PRECISION float COLOR_BOOST;
|
||||
uniform PRECISION float HFILTER_SHARPNESS;
|
||||
uniform PRECISION float PHOSPHOR_LAYOUT;
|
||||
uniform PRECISION float MASK_INTENSITY;
|
||||
uniform PRECISION float CRT_ANTI_RINGING;
|
||||
uniform PRECISION float InputGamma;
|
||||
uniform PRECISION float OutputGamma;
|
||||
uniform PRECISION float VSCANLINES;
|
||||
uniform PRECISION float CRT_CURVATURE;
|
||||
uniform PRECISION float CRT_warpX;
|
||||
uniform PRECISION float CRT_warpY;
|
||||
uniform PRECISION float CRT_cornersize;
|
||||
uniform PRECISION float CRT_cornersmooth;
|
||||
#else
|
||||
#define BEAM_PROFILE 0.0
|
||||
#define BEAM_MIN_WIDTH 0.86
|
||||
#define BEAM_MAX_WIDTH 1.0
|
||||
#define SCANLINES_STRENGTH 0.58
|
||||
#define COLOR_BOOST 1.25
|
||||
#define HFILTER_SHARPNESS 1.0
|
||||
#define PHOSPHOR_LAYOUT 4.0
|
||||
#define MASK_INTENSITY 0.5
|
||||
#define CRT_ANTI_RINGING 1.0
|
||||
#define InputGamma 2.4
|
||||
#define OutputGamma 2.2
|
||||
#define VSCANLINES 0.0
|
||||
#define CRT_CURVATURE 1.0
|
||||
#define CRT_warpX 0.031
|
||||
#define CRT_warpY 0.041
|
||||
#define CRT_cornersize 0.01
|
||||
#define CRT_cornersmooth 1000.0
|
||||
#endif
|
||||
// END PARAMETERS //
|
||||
|
||||
|
||||
/*
|
||||
A collection of CRT mask effects that work with LCD subpixel structures for
|
||||
small details
|
||||
|
||||
author: hunterk
|
||||
license: public domain
|
||||
|
||||
How to use it:
|
||||
|
||||
Multiply your image by the vec3 output:
|
||||
FragColor.rgb *= mask_weights(gl_FragCoord.xy, 1.0, 1);
|
||||
|
||||
The function needs to be tiled across the screen using the physical pixels, e.g.
|
||||
gl_FragCoord (the "vec2 coord" input). In the case of slang shaders, we use
|
||||
(vTexCoord.st * OutputSize.xy).
|
||||
|
||||
The "mask_intensity" (float value between 0.0 and 1.0) is how strong the mask
|
||||
effect should be. Full-strength red, green and blue subpixels on a white pixel
|
||||
are the ideal, and are achieved with an intensity of 1.0, though this darkens
|
||||
the image significantly and may not always be desirable.
|
||||
|
||||
The "phosphor_layout" (int value between 0 and 19) determines which phophor
|
||||
layout to apply. 0 is no mask/passthru.
|
||||
|
||||
Many of these mask arrays are adapted from cgwg's crt-geom-deluxe LUTs, and
|
||||
those have their filenames included for easy identification
|
||||
*/
|
||||
|
||||
vec3 mask_weights(vec2 coord, float mask_intensity, int phosphor_layout){
|
||||
vec3 weights = vec3(1.,1.,1.);
|
||||
float on = 1.;
|
||||
float off = 1.-mask_intensity;
|
||||
vec3 red = vec3(on, off, off);
|
||||
vec3 green = vec3(off, on, off);
|
||||
vec3 blue = vec3(off, off, on );
|
||||
vec3 magenta = vec3(on, off, on );
|
||||
vec3 yellow = vec3(on, on, off);
|
||||
vec3 cyan = vec3(off, on, on );
|
||||
vec3 black = vec3(off, off, off);
|
||||
vec3 white = vec3(on, on, on );
|
||||
int w, z = 0;
|
||||
|
||||
// This pattern is used by a few layouts, so we'll define it here
|
||||
vec3 aperture_weights = mix(magenta, green, floor(mod(coord.x, 2.0)));
|
||||
|
||||
if(phosphor_layout == 0) return weights;
|
||||
|
||||
else if(phosphor_layout == 1){
|
||||
// classic aperture for RGB panels; good for 1080p, too small for 4K+
|
||||
// aka aperture_1_2_bgr
|
||||
weights = aperture_weights;
|
||||
return weights;
|
||||
}
|
||||
|
||||
else if(phosphor_layout == 2){
|
||||
// 2x2 shadow mask for RGB panels; good for 1080p, too small for 4K+
|
||||
// aka delta_1_2x1_bgr
|
||||
vec3 inverse_aperture = mix(green, magenta, floor(mod(coord.x, 2.0)));
|
||||
weights = mix(aperture_weights, inverse_aperture, floor(mod(coord.y, 2.0)));
|
||||
return weights;
|
||||
}
|
||||
|
||||
else if(phosphor_layout == 3){
|
||||
// slot mask for RGB panels; looks okay at 1080p, looks better at 4K
|
||||
// {magenta, green, black, black},
|
||||
// {magenta, green, magenta, green},
|
||||
// {black, black, magenta, green}
|
||||
|
||||
// GLSL can't do 2D arrays until version 430, so do this stupid thing instead for compatibility's sake:
|
||||
// First lay out the horizontal pixels in arrays
|
||||
vec3 slotmask_x1[4] = vec3[](magenta, green, black, black);
|
||||
vec3 slotmask_x2[4] = vec3[](magenta, green, magenta, green);
|
||||
vec3 slotmask_x3[4] = vec3[](black, black, magenta, green);
|
||||
|
||||
// find the vertical index
|
||||
w = int(floor(mod(coord.y, 3.0)));
|
||||
|
||||
// find the horizontal index
|
||||
z = int(floor(mod(coord.x, 4.0)));
|
||||
|
||||
// do a big, dumb comparison in place of a 2D array
|
||||
weights = (w == 1) ? slotmask_x1[z] : (w == 2) ? slotmask_x2[z] : slotmask_x3[z];
|
||||
}
|
||||
|
||||
if(phosphor_layout == 4){
|
||||
// classic aperture for RBG panels; good for 1080p, too small for 4K+
|
||||
weights = mix(yellow, blue, floor(mod(coord.x, 2.0)));
|
||||
return weights;
|
||||
}
|
||||
|
||||
else if(phosphor_layout == 5){
|
||||
// 2x2 shadow mask for RBG panels; good for 1080p, too small for 4K+
|
||||
vec3 inverse_aperture = mix(blue, yellow, floor(mod(coord.x, 2.0)));
|
||||
weights = mix(mix(yellow, blue, floor(mod(coord.x, 2.0))), inverse_aperture, floor(mod(coord.y, 2.0)));
|
||||
return weights;
|
||||
}
|
||||
|
||||
else if(phosphor_layout == 6){
|
||||
// aperture_1_4_rgb; good for simulating lower
|
||||
vec3 ap4[4] = vec3[](red, green, blue, black);
|
||||
|
||||
z = int(floor(mod(coord.x, 4.0)));
|
||||
|
||||
weights = ap4[z];
|
||||
return weights;
|
||||
}
|
||||
|
||||
else if(phosphor_layout == 7){
|
||||
// aperture_2_5_bgr
|
||||
vec3 ap3[5] = vec3[](red, magenta, blue, green, green);
|
||||
|
||||
z = int(floor(mod(coord.x, 5.0)));
|
||||
|
||||
weights = ap3[z];
|
||||
return weights;
|
||||
}
|
||||
|
||||
else if(phosphor_layout == 8){
|
||||
// aperture_3_6_rgb
|
||||
|
||||
vec3 big_ap[7] = vec3[](red, red, yellow, green, cyan, blue, blue);
|
||||
|
||||
w = int(floor(mod(coord.x, 7.)));
|
||||
|
||||
weights = big_ap[w];
|
||||
return weights;
|
||||
}
|
||||
|
||||
else if(phosphor_layout == 9){
|
||||
// reduced TVL aperture for RGB panels
|
||||
// aperture_2_4_rgb
|
||||
|
||||
vec3 big_ap_rgb[4] = vec3[](red, yellow, cyan, blue);
|
||||
|
||||
w = int(floor(mod(coord.x, 4.)));
|
||||
|
||||
weights = big_ap_rgb[w];
|
||||
return weights;
|
||||
}
|
||||
|
||||
else if(phosphor_layout == 10){
|
||||
// reduced TVL aperture for RBG panels
|
||||
|
||||
vec3 big_ap_rbg[4] = vec3[](red, magenta, cyan, green);
|
||||
|
||||
w = int(floor(mod(coord.x, 4.)));
|
||||
|
||||
weights = big_ap_rbg[w];
|
||||
return weights;
|
||||
}
|
||||
|
||||
else if(phosphor_layout == 11){
|
||||
// delta_1_4x1_rgb; dunno why this is called 4x1 when it's obviously 4x2 /shrug
|
||||
vec3 delta_1_1[4] = vec3[](red, green, blue, black);
|
||||
vec3 delta_1_2[4] = vec3[](blue, black, red, green);
|
||||
|
||||
w = int(floor(mod(coord.y, 2.0)));
|
||||
z = int(floor(mod(coord.x, 4.0)));
|
||||
|
||||
weights = (w == 1) ? delta_1_1[z] : delta_1_2[z];
|
||||
return weights;
|
||||
}
|
||||
|
||||
else if(phosphor_layout == 12){
|
||||
// delta_2_4x1_rgb
|
||||
vec3 delta_2_1[4] = vec3[](red, yellow, cyan, blue);
|
||||
vec3 delta_2_2[4] = vec3[](cyan, blue, red, yellow);
|
||||
|
||||
z = int(floor(mod(coord.x, 4.0)));
|
||||
|
||||
weights = (w == 1) ? delta_2_1[z] : delta_2_2[z];
|
||||
return weights;
|
||||
}
|
||||
|
||||
else if(phosphor_layout == 13){
|
||||
// delta_2_4x2_rgb
|
||||
vec3 delta_1[4] = vec3[](red, yellow, cyan, blue);
|
||||
vec3 delta_2[4] = vec3[](red, yellow, cyan, blue);
|
||||
vec3 delta_3[4] = vec3[](cyan, blue, red, yellow);
|
||||
vec3 delta_4[4] = vec3[](cyan, blue, red, yellow);
|
||||
|
||||
w = int(floor(mod(coord.y, 4.0)));
|
||||
z = int(floor(mod(coord.x, 4.0)));
|
||||
|
||||
weights = (w == 1) ? delta_1[z] : (w == 2) ? delta_2[z] : (w == 3) ? delta_3[z] : delta_4[z];
|
||||
return weights;
|
||||
}
|
||||
|
||||
else if(phosphor_layout == 14){
|
||||
// slot mask for RGB panels; too low-pitch for 1080p, looks okay at 4K, but wants 8K+
|
||||
// {magenta, green, black, black, black, black},
|
||||
// {magenta, green, black, magenta, green, black},
|
||||
// {black, black, black, magenta, green, black}
|
||||
vec3 slot2_1[6] = vec3[](magenta, green, black, black, black, black);
|
||||
vec3 slot2_2[6] = vec3[](magenta, green, black, magenta, green, black);
|
||||
vec3 slot2_3[6] = vec3[](black, black, black, magenta, green, black);
|
||||
|
||||
w = int(floor(mod(coord.y, 3.0)));
|
||||
z = int(floor(mod(coord.x, 6.0)));
|
||||
|
||||
weights = (w == 1) ? slot2_1[z] : (w == 2) ? slot2_2[z] : slot2_3[z];
|
||||
return weights;
|
||||
}
|
||||
|
||||
else if(phosphor_layout == 15){
|
||||
// slot_2_4x4_rgb
|
||||
// {red, yellow, cyan, blue, red, yellow, cyan, blue },
|
||||
// {red, yellow, cyan, blue, black, black, black, black},
|
||||
// {red, yellow, cyan, blue, red, yellow, cyan, blue },
|
||||
// {black, black, black, black, red, yellow, cyan, blue }
|
||||
vec3 slotmask_RBG_x1[8] = vec3[](red, yellow, cyan, blue, red, yellow, cyan, blue );
|
||||
vec3 slotmask_RBG_x2[8] = vec3[](red, yellow, cyan, blue, black, black, black, black);
|
||||
vec3 slotmask_RBG_x3[8] = vec3[](red, yellow, cyan, blue, red, yellow, cyan, blue );
|
||||
vec3 slotmask_RBG_x4[8] = vec3[](black, black, black, black, red, yellow, cyan, blue );
|
||||
|
||||
// find the vertical index
|
||||
w = int(floor(mod(coord.y, 4.0)));
|
||||
|
||||
// find the horizontal index
|
||||
z = int(floor(mod(coord.x, 8.0)));
|
||||
|
||||
weights = (w == 1) ? slotmask_RBG_x1[z] : (w == 2) ? slotmask_RBG_x2[z] : (w == 3) ? slotmask_RBG_x3[z] : slotmask_RBG_x4[z];
|
||||
return weights;
|
||||
}
|
||||
|
||||
else if(phosphor_layout == 16){
|
||||
// slot mask for RBG panels; too low-pitch for 1080p, looks okay at 4K, but wants 8K+
|
||||
// {yellow, blue, black, black},
|
||||
// {yellow, blue, yellow, blue},
|
||||
// {black, black, yellow, blue}
|
||||
vec3 slot2_1[4] = vec3[](yellow, blue, black, black);
|
||||
vec3 slot2_2[4] = vec3[](yellow, blue, yellow, blue);
|
||||
vec3 slot2_3[4] = vec3[](black, black, yellow, blue);
|
||||
|
||||
w = int(floor(mod(coord.y, 3.0)));
|
||||
z = int(floor(mod(coord.x, 4.0)));
|
||||
|
||||
weights = (w == 1) ? slot2_1[z] : (w == 2) ? slot2_2[z] : slot2_3[z];
|
||||
return weights;
|
||||
}
|
||||
|
||||
else if(phosphor_layout == 17){
|
||||
// slot_2_5x4_bgr
|
||||
// {red, magenta, blue, green, green, red, magenta, blue, green, green},
|
||||
// {black, blue, blue, green, green, red, red, black, black, black},
|
||||
// {red, magenta, blue, green, green, red, magenta, blue, green, green},
|
||||
// {red, red, black, black, black, black, blue, blue, green, green}
|
||||
vec3 slot_1[10] = vec3[](red, magenta, blue, green, green, red, magenta, blue, green, green);
|
||||
vec3 slot_2[10] = vec3[](black, blue, blue, green, green, red, red, black, black, black);
|
||||
vec3 slot_3[10] = vec3[](red, magenta, blue, green, green, red, magenta, blue, green, green);
|
||||
vec3 slot_4[10] = vec3[](red, red, black, black, black, black, blue, blue, green, green);
|
||||
|
||||
w = int(floor(mod(coord.y, 4.0)));
|
||||
z = int(floor(mod(coord.x, 10.0)));
|
||||
|
||||
weights = (w == 1) ? slot_1[z] : (w == 2) ? slot_2[z] : (w == 3) ? slot_3[z] : slot_4[z];
|
||||
return weights;
|
||||
}
|
||||
|
||||
else if(phosphor_layout == 18){
|
||||
// same as above but for RBG panels
|
||||
// {red, yellow, green, blue, blue, red, yellow, green, blue, blue },
|
||||
// {black, green, green, blue, blue, red, red, black, black, black},
|
||||
// {red, yellow, green, blue, blue, red, yellow, green, blue, blue },
|
||||
// {red, red, black, black, black, black, green, green, blue, blue }
|
||||
vec3 slot_1[10] = vec3[](red, yellow, green, blue, blue, red, yellow, green, blue, blue );
|
||||
vec3 slot_2[10] = vec3[](black, green, green, blue, blue, red, red, black, black, black);
|
||||
vec3 slot_3[10] = vec3[](red, yellow, green, blue, blue, red, yellow, green, blue, blue );
|
||||
vec3 slot_4[10] = vec3[](red, red, black, black, black, black, green, green, blue, blue );
|
||||
|
||||
w = int(floor(mod(coord.y, 4.0)));
|
||||
z = int(floor(mod(coord.x, 10.0)));
|
||||
|
||||
weights = (w == 1) ? slot_1[z] : (w == 2) ? slot_2[z] : (w == 3) ? slot_3[z] : slot_4[z];
|
||||
return weights;
|
||||
}
|
||||
|
||||
else if(phosphor_layout == 19){
|
||||
// slot_3_7x6_rgb
|
||||
// {red, red, yellow, green, cyan, blue, blue, red, red, yellow, green, cyan, blue, blue},
|
||||
// {red, red, yellow, green, cyan, blue, blue, red, red, yellow, green, cyan, blue, blue},
|
||||
// {red, red, yellow, green, cyan, blue, blue, black, black, black, black, black, black, black},
|
||||
// {red, red, yellow, green, cyan, blue, blue, red, red, yellow, green, cyan, blue, blue},
|
||||
// {red, red, yellow, green, cyan, blue, blue, red, red, yellow, green, cyan, blue, blue},
|
||||
// {black, black, black, black, black, black, black, black, red, red, yellow, green, cyan, blue}
|
||||
|
||||
vec3 slot_1[14] = vec3[](red, red, yellow, green, cyan, blue, blue, red, red, yellow, green, cyan, blue, blue);
|
||||
vec3 slot_2[14] = vec3[](red, red, yellow, green, cyan, blue, blue, red, red, yellow, green, cyan, blue, blue);
|
||||
vec3 slot_3[14] = vec3[](red, red, yellow, green, cyan, blue, blue, black, black, black, black, black, black, black);
|
||||
vec3 slot_4[14] = vec3[](red, red, yellow, green, cyan, blue, blue, red, red, yellow, green, cyan, blue, blue);
|
||||
vec3 slot_5[14] = vec3[](red, red, yellow, green, cyan, blue, blue, red, red, yellow, green, cyan, blue, blue);
|
||||
vec3 slot_6[14] = vec3[](black, black, black, black, black, black, black, black, red, red, yellow, green, cyan, blue);
|
||||
|
||||
w = int(floor(mod(coord.y, 6.0)));
|
||||
z = int(floor(mod(coord.x, 14.0)));
|
||||
|
||||
weights = (w == 1) ? slot_1[z] : (w == 2) ? slot_2[z] : (w == 3) ? slot_3[z] : (w == 4) ? slot_4[z] : (w == 5) ? slot_5[z] : slot_6[z];
|
||||
return weights;
|
||||
}
|
||||
|
||||
else return weights;
|
||||
}
|
||||
|
||||
|
||||
const vec2 corner_aspect = vec2(1.0, 0.75);
|
||||
vec2 CRT_Distortion = vec2(CRT_warpX, CRT_warpY) * 15.;
|
||||
|
||||
|
||||
float corner(vec2 coord)
|
||||
{
|
||||
coord = (coord - vec2(0.5)) + vec2(0.5, 0.5);
|
||||
coord = min(coord, vec2(1.0) - coord) * corner_aspect;
|
||||
vec2 cdist = vec2(cornersize);
|
||||
coord = (cdist - min(coord, cdist));
|
||||
float dist = sqrt(dot(coord, coord));
|
||||
|
||||
return clamp((cdist.x - dist)*cornersmooth, 0.0, 1.0);
|
||||
}
|
||||
|
||||
|
||||
vec2 Warp(vec2 texCoord){
|
||||
vec2 curvedCoords = texCoord * 2.0 - 1.0;
|
||||
float curvedCoordsDistance = sqrt(curvedCoords.x*curvedCoords.x+curvedCoords.y*curvedCoords.y);
|
||||
|
||||
curvedCoords = curvedCoords / curvedCoordsDistance;
|
||||
|
||||
curvedCoords = curvedCoords * (1.0-pow(vec2(1.0-(curvedCoordsDistance/1.4142135623730950488016887242097)),(1.0/(1.0+CRT_Distortion*0.2))));
|
||||
|
||||
curvedCoords = curvedCoords / (1.0-pow(vec2(0.29289321881345247559915563789515),(1.0/(vec2(1.0)+CRT_Distortion*0.2))));
|
||||
|
||||
curvedCoords = curvedCoords * 0.5 + 0.5;
|
||||
return curvedCoords;
|
||||
}
|
||||
|
||||
|
||||
// Horizontal cubic filter.
|
||||
|
||||
// Some known filters use these values:
|
||||
|
||||
// B = 0.0, C = 0.0 => Hermite cubic filter.
|
||||
// B = 1.0, C = 0.0 => Cubic B-Spline filter.
|
||||
// B = 0.0, C = 0.5 => Catmull-Rom Spline filter. This is the default used in this shader.
|
||||
// B = C = 1.0/3.0 => Mitchell-Netravali cubic filter.
|
||||
// B = 0.3782, C = 0.3109 => Robidoux filter.
|
||||
// B = 0.2620, C = 0.3690 => Robidoux Sharp filter.
|
||||
|
||||
float B = 1.0 - HFILTER_SHARPNESS;
|
||||
float C = HFILTER_SHARPNESS*0.5; // B+2C=1 Mitchel-Netravali recommendation line.
|
||||
|
||||
mat4 invX = mat4( (-B - 6.0*C)/6.0, (12.0 - 9.0*B - 6.0*C)/6.0, -(12.0 - 9.0*B - 6.0*C)/6.0, (B + 6.0*C)/6.0,
|
||||
(3.0*B + 12.0*C)/6.0, (-18.0 + 12.0*B + 6.0*C)/6.0, (18.0 - 15.0*B - 12.0*C)/6.0, -C,
|
||||
(-3.0*B - 6.0*C)/6.0, 0.0, (3.0*B + 6.0*C)/6.0, 0.0,
|
||||
B/6.0, (6.0 - 2.0*B)/6.0, B/6.0, 0.0);
|
||||
|
||||
|
||||
|
||||
#define scanlines_strength (4.0*profile.x)
|
||||
#define beam_min_width profile.y
|
||||
#define beam_max_width profile.z
|
||||
#define color_boost profile.w
|
||||
|
||||
vec4 get_beam_profile()
|
||||
{
|
||||
vec4 bp = vec4(SCANLINES_STRENGTH, BEAM_MIN_WIDTH, BEAM_MAX_WIDTH, COLOR_BOOST);
|
||||
|
||||
if (BEAM_PROFILE == 1.0) bp = vec4(0.40, 1.00, 1.00, 1.00); // Catmull-rom
|
||||
if (BEAM_PROFILE == 2.0) bp = vec4(0.72, 1.00, 1.00, 1.25); // Catmull-rom
|
||||
if (BEAM_PROFILE == 3.0) bp = vec4(0.60, 0.50, 1.00, 1.25); // Hermite
|
||||
if (BEAM_PROFILE == 4.0) bp = vec4(0.60, 0.72, 1.00, 1.25); // Hermite
|
||||
if (BEAM_PROFILE == 5.0) bp = vec4(0.68, 0.68, 1.00, 1.25); // Hermite
|
||||
if (BEAM_PROFILE == 6.0) bp = vec4(0.70, 0.50, 1.00, 1.80); // Catmull-rom
|
||||
|
||||
return bp;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void main()
|
||||
{
|
||||
vec4 profile = get_beam_profile();
|
||||
|
||||
vec2 dx = mix(vec2(1.0/TextureSize.x, 0.0), vec2(0.0, 1.0/TextureSize.y), VSCANLINES);
|
||||
vec2 dy = mix(vec2(0.0, 1.0/TextureSize.y), vec2(1.0/TextureSize.x, 0.0), VSCANLINES);
|
||||
|
||||
// vec2 pix_coord = texCoord.xy*TextureSize + vec2(-0.5, 0.5);
|
||||
|
||||
vec2 pp = texCoord.xy;
|
||||
pp = (CRT_CURVATURE > 0.5) ? (Warp(pp*TextureSize.xy/InputSize.xy)*InputSize.xy/TextureSize.xy) : pp;
|
||||
|
||||
|
||||
vec2 pix_coord = pp.xy*TextureSize + vec2(-0.5, 0.5);
|
||||
|
||||
vec2 tc = mix((floor(pix_coord) + vec2(0.5, 0.5))/TextureSize, (floor(pix_coord) + vec2(1.0, -0.5))/TextureSize, VSCANLINES);
|
||||
|
||||
vec2 fp = mix(fract(pix_coord), fract(pix_coord.yx), VSCANLINES);
|
||||
|
||||
vec4 c00 = GAMMA_IN(tex2D(s_p, tc - dx - dy).xyzw);
|
||||
vec4 c01 = GAMMA_IN(tex2D(s_p, tc - dy).xyzw);
|
||||
vec4 c02 = GAMMA_IN(tex2D(s_p, tc + dx - dy).xyzw);
|
||||
vec4 c03 = GAMMA_IN(tex2D(s_p, tc + 2.0*dx - dy).xyzw);
|
||||
vec4 c10 = GAMMA_IN(tex2D(s_p, tc - dx).xyzw);
|
||||
vec4 c11 = GAMMA_IN(tex2D(s_p, tc ).xyzw);
|
||||
vec4 c12 = GAMMA_IN(tex2D(s_p, tc + dx).xyzw);
|
||||
vec4 c13 = GAMMA_IN(tex2D(s_p, tc + 2.0*dx).xyzw);
|
||||
|
||||
mat4 color_matrix0 = mat4(c00, c01, c02, c03);
|
||||
mat4 color_matrix1 = mat4(c10, c11, c12, c13);
|
||||
|
||||
vec4 lobes = vec4(fp.x*fp.x*fp.x, fp.x*fp.x, fp.x, 1.0);
|
||||
|
||||
vec4 invX_Px = invX * lobes;
|
||||
vec4 color0 = color_matrix0 * invX_Px;
|
||||
vec4 color1 = color_matrix1 * invX_Px;
|
||||
|
||||
// Get min/max samples
|
||||
vec4 min_sample0 = min(c01,c02);
|
||||
vec4 max_sample0 = max(c01,c02);
|
||||
vec4 min_sample1 = min(c11,c12);
|
||||
vec4 max_sample1 = max(c11,c12);
|
||||
|
||||
// Anti-ringing
|
||||
vec4 aux = color0;
|
||||
color0 = clamp(color0, min_sample0, max_sample0);
|
||||
color0 = mix(aux, color0, CRT_ANTI_RINGING);
|
||||
aux = color1;
|
||||
color1 = clamp(color1, min_sample1, max_sample1);
|
||||
color1 = mix(aux, color1, CRT_ANTI_RINGING);
|
||||
|
||||
float pos0 = fp.y;
|
||||
float pos1 = 1.0 - fp.y;
|
||||
|
||||
vec4 lum0 = mix(vec4(beam_min_width), vec4(beam_max_width), color0);
|
||||
vec4 lum1 = mix(vec4(beam_min_width), vec4(beam_max_width), color1);
|
||||
|
||||
vec4 d0 = scanlines_strength*pos0/(lum0+0.0000001);
|
||||
vec4 d1 = scanlines_strength*pos1/(lum1+0.0000001);
|
||||
|
||||
d0 = exp(-d0*d0);
|
||||
d1 = exp(-d1*d1);
|
||||
|
||||
vec4 color = color_boost*(color0*d0+color1*d1);
|
||||
|
||||
// vec2 mask_coords = gl_FragCoord.xy; //texCoord.xy * OutputSize.xy;
|
||||
vec2 mask_coords = (texCoord.xy * OutputSize.xy) * TextureSize.xy / InputSize.xy;
|
||||
|
||||
mask_coords = mix(mask_coords.xy, mask_coords.yx, VSCANLINES);
|
||||
|
||||
color.rgb*=mask_weights(mask_coords, MASK_INTENSITY, int(PHOSPHOR_LAYOUT));
|
||||
|
||||
color = GAMMA_OUT(color);
|
||||
|
||||
FragColor = vec4(color);
|
||||
|
||||
FragColor *= (CRT_CURVATURE > 0.5) ? corner(pp*TextureSize.xy/InputSize.xy) : 1.0;
|
||||
}
|
||||
#endif
|
@ -1,7 +1,7 @@
|
||||
/*
|
||||
Hyllian's CRT Shader
|
||||
|
||||
Copyright (C) 2011-2016 Hyllian - sergiogdb@gmail.com
|
||||
Copyright (C) 2011-2020 Hyllian - sergiogdb@gmail.com
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
@ -23,36 +23,22 @@
|
||||
|
||||
*/
|
||||
|
||||
#pragma parameter PHOSPHOR "CRT - Phosphor ON/OFF" 1.0 0.0 1.0 1.0
|
||||
#pragma parameter VSCANLINES "CRT - Scanlines Direction" 0.0 0.0 1.0 1.0
|
||||
#pragma parameter InputGamma "CRT - Input gamma" 2.4 0.0 5.0 0.1
|
||||
#pragma parameter OutputGamma "CRT - Output Gamma" 2.2 0.0 5.0 0.1
|
||||
#pragma parameter SHARPNESS "CRT - Sharpness Hack" 1.0 1.0 5.0 1.0
|
||||
#pragma parameter COLOR_BOOST "CRT - Color Boost" 1.5 1.0 2.0 0.05
|
||||
#pragma parameter RED_BOOST "CRT - Red Boost" 1.0 1.0 2.0 0.01
|
||||
#pragma parameter GREEN_BOOST "CRT - Green Boost" 1.0 1.0 2.0 0.01
|
||||
#pragma parameter BLUE_BOOST "CRT - Blue Boost" 1.0 1.0 2.0 0.01
|
||||
#pragma parameter SCANLINES_STRENGTH "CRT - Scanline Strength" 0.72 0.0 1.0 0.02
|
||||
#pragma parameter BEAM_MIN_WIDTH "CRT - Min Beam Width" 0.86 0.0 1.0 0.02
|
||||
#pragma parameter BEAM_MAX_WIDTH "CRT - Max Beam Width" 1.0 0.0 1.0 0.02
|
||||
#pragma parameter CRT_ANTI_RINGING "CRT - Anti-Ringing" 0.8 0.0 1.0 0.1
|
||||
#version 120
|
||||
|
||||
#pragma parameter BEAM_PROFILE "BEAM PROFILE (BP)" 0.0 0.0 6.0 1.0
|
||||
#pragma parameter BEAM_MIN_WIDTH " Custom [If BP=0.00] MIN BEAM WIDTH" 0.86 0.0 1.0 0.02
|
||||
#pragma parameter BEAM_MAX_WIDTH " Custom [If BP=0.00] MAX BEAM WIDTH" 1.0 0.0 1.0 0.02
|
||||
#pragma parameter SCANLINES_STRENGTH " Custom [If BP=0.00] SCANLINES STRENGTH" 0.58 0.0 1.0 0.02
|
||||
#pragma parameter COLOR_BOOST " Custom [If BP=0.00] COLOR BOOST" 1.25 1.0 2.0 0.05
|
||||
#pragma parameter HFILTER_SHARPNESS "HORIZONTAL FILTER SHARPNESS" 1.0 0.0 1.0 0.02
|
||||
#pragma parameter CRT_ANTI_RINGING "ANTI RINGING" 1.0 0.0 1.0 0.1
|
||||
#pragma parameter InputGamma "INPUT GAMMA" 2.4 0.0 5.0 0.1
|
||||
#pragma parameter OutputGamma "OUTPUT GAMMA" 2.2 0.0 5.0 0.1
|
||||
#pragma parameter VSCANLINES "SCANLINES DIRECTION" 0.0 0.0 1.0 1.0
|
||||
|
||||
#define GAMMA_IN(color) pow(color, vec4(InputGamma, InputGamma, InputGamma, InputGamma))
|
||||
#define GAMMA_OUT(color) pow(color, vec4(1.0 / OutputGamma, 1.0 / OutputGamma, 1.0 / OutputGamma, 1.0 / OutputGamma))
|
||||
|
||||
// Horizontal cubic filter.
|
||||
|
||||
// Some known filters use these values:
|
||||
|
||||
// B = 0.0, C = 0.0 => Hermite cubic filter.
|
||||
// B = 1.0, C = 0.0 => Cubic B-Spline filter.
|
||||
// B = 0.0, C = 0.5 => Catmull-Rom Spline filter. This is the default used in this shader.
|
||||
// B = C = 1.0/3.0 => Mitchell-Netravali cubic filter.
|
||||
// B = 0.3782, C = 0.3109 => Robidoux filter.
|
||||
// B = 0.2620, C = 0.3690 => Robidoux Sharp filter.
|
||||
// B = 0.36, C = 0.28 => My best config for ringing elimination in pixel art (Hyllian).
|
||||
|
||||
// For more info, see: http://www.imagemagick.org/Usage/img_diagrams/cubic_survey.gif
|
||||
|
||||
#define texCoord TEX0
|
||||
|
||||
@ -128,56 +114,84 @@ uniform sampler2D s_p;
|
||||
IN vec2 texCoord;
|
||||
|
||||
#ifdef PARAMETER_UNIFORM
|
||||
uniform PRECISION float PHOSPHOR;
|
||||
uniform PRECISION float VSCANLINES;
|
||||
uniform PRECISION float InputGamma;
|
||||
uniform PRECISION float OutputGamma;
|
||||
uniform PRECISION float SHARPNESS;
|
||||
uniform PRECISION float COLOR_BOOST;
|
||||
uniform PRECISION float RED_BOOST;
|
||||
uniform PRECISION float GREEN_BOOST;
|
||||
uniform PRECISION float BLUE_BOOST;
|
||||
uniform PRECISION float SCANLINES_STRENGTH;
|
||||
uniform PRECISION float BEAM_PROFILE;
|
||||
uniform PRECISION float BEAM_MIN_WIDTH;
|
||||
uniform PRECISION float BEAM_MAX_WIDTH;
|
||||
uniform PRECISION float SCANLINES_STRENGTH;
|
||||
uniform PRECISION float COLOR_BOOST;
|
||||
uniform PRECISION float HFILTER_SHARPNESS;
|
||||
uniform PRECISION float CRT_ANTI_RINGING;
|
||||
uniform PRECISION float InputGamma;
|
||||
uniform PRECISION float OutputGamma;
|
||||
uniform PRECISION float VSCANLINES;
|
||||
#else
|
||||
#define PHOSPHOR 1.0
|
||||
#define VSCANLINES 0.0
|
||||
#define InputGamma 2.4
|
||||
#define OutputGamma 2.2
|
||||
#define SHARPNESS 1.0
|
||||
#define COLOR_BOOST 1.5
|
||||
#define RED_BOOST 1.0
|
||||
#define GREEN_BOOST 1.0
|
||||
#define BLUE_BOOST 1.0
|
||||
#define SCANLINES_STRENGTH 0.72
|
||||
#define BEAM_PROFILE 0.0
|
||||
#define BEAM_MIN_WIDTH 0.86
|
||||
#define BEAM_MAX_WIDTH 1.0
|
||||
#define CRT_ANTI_RINGING 0.8
|
||||
#define SCANLINES_STRENGTH 0.58
|
||||
#define COLOR_BOOST 1.25
|
||||
#define HFILTER_SHARPNESS 1.0
|
||||
#define CRT_ANTI_RINGING 1.0
|
||||
#define InputGamma 2.4
|
||||
#define OutputGamma 2.2
|
||||
#define VSCANLINES 0.0
|
||||
#endif
|
||||
// END PARAMETERS //
|
||||
|
||||
// Change these params to configure the horizontal filter.
|
||||
const float B = 0.0;
|
||||
const float C = 0.5;
|
||||
|
||||
const mat4 invX = mat4( (-B - 6.0*C)/6.0, (12.0 - 9.0*B - 6.0*C)/6.0, -(12.0 - 9.0*B - 6.0*C)/6.0, (B + 6.0*C)/6.0,
|
||||
// Horizontal cubic filter.
|
||||
|
||||
// Some known filters use these values:
|
||||
|
||||
// B = 0.0, C = 0.0 => Hermite cubic filter.
|
||||
// B = 1.0, C = 0.0 => Cubic B-Spline filter.
|
||||
// B = 0.0, C = 0.5 => Catmull-Rom Spline filter. This is the default used in this shader.
|
||||
// B = C = 1.0/3.0 => Mitchell-Netravali cubic filter.
|
||||
// B = 0.3782, C = 0.3109 => Robidoux filter.
|
||||
// B = 0.2620, C = 0.3690 => Robidoux Sharp filter.
|
||||
|
||||
float B = 1.0 - HFILTER_SHARPNESS;
|
||||
float C = HFILTER_SHARPNESS*0.5; // B+2C=1 Mitchel-Netravali recommendation line.
|
||||
|
||||
mat4 invX = mat4( (-B - 6.0*C)/6.0, (12.0 - 9.0*B - 6.0*C)/6.0, -(12.0 - 9.0*B - 6.0*C)/6.0, (B + 6.0*C)/6.0,
|
||||
(3.0*B + 12.0*C)/6.0, (-18.0 + 12.0*B + 6.0*C)/6.0, (18.0 - 15.0*B - 12.0*C)/6.0, -C,
|
||||
(-3.0*B - 6.0*C)/6.0, 0.0, (3.0*B + 6.0*C)/6.0, 0.0,
|
||||
B/6.0, (6.0 - 2.0*B)/6.0, B/6.0, 0.0);
|
||||
|
||||
|
||||
|
||||
#define scanlines_strength (4.0*profile.x)
|
||||
#define beam_min_width profile.y
|
||||
#define beam_max_width profile.z
|
||||
#define color_boost profile.w
|
||||
|
||||
vec4 get_beam_profile()
|
||||
{
|
||||
vec4 bp = vec4(SCANLINES_STRENGTH, BEAM_MIN_WIDTH, BEAM_MAX_WIDTH, COLOR_BOOST);
|
||||
|
||||
if (BEAM_PROFILE == 1.0) bp = vec4(0.40, 1.00, 1.00, 1.00); // Catmull-rom
|
||||
if (BEAM_PROFILE == 2.0) bp = vec4(0.72, 1.00, 1.00, 1.25); // Catmull-rom
|
||||
if (BEAM_PROFILE == 3.0) bp = vec4(0.60, 0.50, 1.00, 1.25); // Hermite
|
||||
if (BEAM_PROFILE == 4.0) bp = vec4(0.60, 0.72, 1.00, 1.25); // Hermite
|
||||
if (BEAM_PROFILE == 5.0) bp = vec4(0.68, 0.68, 1.00, 1.25); // Hermite
|
||||
if (BEAM_PROFILE == 6.0) bp = vec4(0.70, 0.50, 1.00, 1.80); // Catmull-rom
|
||||
|
||||
return bp;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void main()
|
||||
{
|
||||
vec2 texture_size = vec2(SHARPNESS*TextureSize.x, TextureSize.y);
|
||||
vec4 profile = get_beam_profile();
|
||||
|
||||
vec4 color;
|
||||
vec2 dx = mix(vec2(1.0/texture_size.x, 0.0), vec2(0.0, 1.0/texture_size.y), VSCANLINES);
|
||||
vec2 dy = mix(vec2(0.0, 1.0/texture_size.y), vec2(1.0/texture_size.x, 0.0), VSCANLINES);
|
||||
vec2 dx = mix(vec2(1.0/TextureSize.x, 0.0), vec2(0.0, 1.0/TextureSize.y), VSCANLINES);
|
||||
vec2 dy = mix(vec2(0.0, 1.0/TextureSize.y), vec2(1.0/TextureSize.x, 0.0), VSCANLINES);
|
||||
|
||||
vec2 pix_coord = texCoord*texture_size+vec2(-0.5,0.5);
|
||||
vec2 pix_coord = texCoord.xy*TextureSize + vec2(-0.5, 0.5);
|
||||
|
||||
vec2 tc = mix((floor(pix_coord) + vec2(0.5, 0.5))/texture_size, (floor(pix_coord) + vec2(1.0, -0.5))/texture_size, VSCANLINES);
|
||||
vec2 tc = mix((floor(pix_coord) + vec2(0.5, 0.5))/TextureSize, (floor(pix_coord) + vec2(1.0, -0.5))/TextureSize, VSCANLINES);
|
||||
|
||||
vec2 fp = mix(fract(pix_coord), fract(pix_coord.yx), VSCANLINES);
|
||||
|
||||
@ -190,10 +204,6 @@ void main()
|
||||
vec4 c12 = GAMMA_IN(tex2D(s_p, tc + dx).xyzw);
|
||||
vec4 c13 = GAMMA_IN(tex2D(s_p, tc + 2.0*dx).xyzw);
|
||||
|
||||
// Get min/max samples
|
||||
vec4 min_sample = min(min(c01,c11), min(c02,c12));
|
||||
vec4 max_sample = max(max(c01,c11), max(c02,c12));
|
||||
|
||||
mat4 color_matrix0 = mat4(c00, c01, c02, c03);
|
||||
mat4 color_matrix1 = mat4(c10, c11, c12, c13);
|
||||
|
||||
@ -203,39 +213,33 @@ void main()
|
||||
vec4 color0 = color_matrix0 * invX_Px;
|
||||
vec4 color1 = color_matrix1 * invX_Px;
|
||||
|
||||
// Get min/max samples
|
||||
vec4 min_sample0 = min(c01,c02);
|
||||
vec4 max_sample0 = max(c01,c02);
|
||||
vec4 min_sample1 = min(c11,c12);
|
||||
vec4 max_sample1 = max(c11,c12);
|
||||
|
||||
// Anti-ringing
|
||||
vec4 aux = color0;
|
||||
color0 = clamp(color0, min_sample, max_sample);
|
||||
color0 = clamp(color0, min_sample0, max_sample0);
|
||||
color0 = mix(aux, color0, CRT_ANTI_RINGING);
|
||||
aux = color1;
|
||||
color1 = clamp(color1, min_sample, max_sample);
|
||||
color1 = clamp(color1, min_sample1, max_sample1);
|
||||
color1 = mix(aux, color1, CRT_ANTI_RINGING);
|
||||
|
||||
float pos0 = fp.y;
|
||||
float pos1 = 1.0 - fp.y;
|
||||
|
||||
vec4 lum0 = mix(vec4(BEAM_MIN_WIDTH), vec4(BEAM_MAX_WIDTH), color0);
|
||||
vec4 lum1 = mix(vec4(BEAM_MIN_WIDTH), vec4(BEAM_MAX_WIDTH), color1);
|
||||
vec4 lum0 = mix(vec4(beam_min_width), vec4(beam_max_width), color0);
|
||||
vec4 lum1 = mix(vec4(beam_min_width), vec4(beam_max_width), color1);
|
||||
|
||||
vec4 d0 = clamp(pos0/(lum0+0.0000001), 0.0, 1.0);
|
||||
vec4 d1 = clamp(pos1/(lum1+0.0000001), 0.0, 1.0);
|
||||
vec4 d0 = scanlines_strength*pos0/(lum0+0.0000001);
|
||||
vec4 d1 = scanlines_strength*pos1/(lum1+0.0000001);
|
||||
|
||||
d0 = exp(-10.0*SCANLINES_STRENGTH*d0*d0);
|
||||
d1 = exp(-10.0*SCANLINES_STRENGTH*d1*d1);
|
||||
d0 = exp(-d0*d0);
|
||||
d1 = exp(-d1*d1);
|
||||
|
||||
color = clamp(color0*d0+color1*d1, 0.0, 1.0);
|
||||
|
||||
color *= COLOR_BOOST*vec4(RED_BOOST, GREEN_BOOST, BLUE_BOOST, 1.0);
|
||||
|
||||
float mod_factor = texCoord.x * OutputSize.x * TextureSize.x / InputSize.x;
|
||||
|
||||
vec4 dotMaskWeights = mix(
|
||||
vec4(1.0, 0.7, 1.0, 1.),
|
||||
vec4(0.7, 1.0, 0.7, 1.),
|
||||
floor(mod(mod_factor, 2.0))
|
||||
);
|
||||
|
||||
color.rgba *= mix(vec4(1.0,1.0,1.0,1.0), dotMaskWeights, PHOSPHOR);
|
||||
vec4 color = color_boost*(color0*d0+color1*d1);
|
||||
|
||||
color = GAMMA_OUT(color);
|
||||
|
425
crt/shaders/hyllian/crt-hyllian-glow/resolve2.glsl
Normal file
425
crt/shaders/hyllian/crt-hyllian-glow/resolve2.glsl
Normal file
@ -0,0 +1,425 @@
|
||||
#version 120
|
||||
|
||||
// Parameter lines go here:
|
||||
#pragma parameter BLOOM_STRENGTH "Glow Strength" 0.45 0.0 0.8 0.05
|
||||
#pragma parameter OUTPUT_GAMMA "Monitor Gamma" 2.2 1.8 2.6 0.02
|
||||
#pragma parameter PHOSPHOR_LAYOUT "PHOSPHOR LAYOUT" 4.0 0.0 19.0 1.0
|
||||
#pragma parameter MASK_INTENSITY "MASK INTENSITY" 0.5 0.0 1.0 0.1
|
||||
|
||||
#if defined(VERTEX)
|
||||
|
||||
#if __VERSION__ >= 130
|
||||
#define COMPAT_VARYING out
|
||||
#define COMPAT_ATTRIBUTE in
|
||||
#define COMPAT_TEXTURE texture
|
||||
#else
|
||||
#define COMPAT_VARYING varying
|
||||
#define COMPAT_ATTRIBUTE attribute
|
||||
#define COMPAT_TEXTURE texture2D
|
||||
#endif
|
||||
|
||||
#ifdef GL_ES
|
||||
#define COMPAT_PRECISION mediump
|
||||
#else
|
||||
#define COMPAT_PRECISION
|
||||
#endif
|
||||
|
||||
COMPAT_ATTRIBUTE vec4 VertexCoord;
|
||||
COMPAT_ATTRIBUTE vec4 COLOR;
|
||||
COMPAT_ATTRIBUTE vec4 TexCoord;
|
||||
COMPAT_VARYING vec4 COL0;
|
||||
COMPAT_VARYING vec4 TEX0;
|
||||
|
||||
vec4 _oPosition1;
|
||||
uniform mat4 MVPMatrix;
|
||||
uniform COMPAT_PRECISION int FrameDirection;
|
||||
uniform COMPAT_PRECISION int FrameCount;
|
||||
uniform COMPAT_PRECISION vec2 OutputSize;
|
||||
uniform COMPAT_PRECISION vec2 TextureSize;
|
||||
uniform COMPAT_PRECISION vec2 InputSize;
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = MVPMatrix * VertexCoord;
|
||||
COL0 = COLOR;
|
||||
TEX0.xy = TexCoord.xy;
|
||||
}
|
||||
|
||||
#elif defined(FRAGMENT)
|
||||
|
||||
#if __VERSION__ >= 130
|
||||
#define COMPAT_VARYING in
|
||||
#define COMPAT_TEXTURE texture
|
||||
out vec4 FragColor;
|
||||
#else
|
||||
#define COMPAT_VARYING varying
|
||||
#define FragColor gl_FragColor
|
||||
#define COMPAT_TEXTURE texture2D
|
||||
#endif
|
||||
|
||||
#ifdef GL_ES
|
||||
#ifdef GL_FRAGMENT_PRECISION_HIGH
|
||||
precision highp float;
|
||||
#else
|
||||
precision mediump float;
|
||||
#endif
|
||||
#define COMPAT_PRECISION mediump
|
||||
#else
|
||||
#define COMPAT_PRECISION
|
||||
#endif
|
||||
|
||||
uniform COMPAT_PRECISION int FrameDirection;
|
||||
uniform COMPAT_PRECISION int FrameCount;
|
||||
uniform COMPAT_PRECISION vec2 OutputSize;
|
||||
uniform COMPAT_PRECISION vec2 TextureSize;
|
||||
uniform COMPAT_PRECISION vec2 InputSize;
|
||||
uniform sampler2D Texture;
|
||||
uniform sampler2D PassPrev4Texture;
|
||||
COMPAT_VARYING vec4 TEX0;
|
||||
|
||||
// compatibility #defines
|
||||
#define Source Texture
|
||||
#define vTexCoord TEX0.xy
|
||||
|
||||
#define SourceSize vec4(TextureSize, 1.0 / TextureSize) //either TextureSize or InputSize
|
||||
#define outsize vec4(OutputSize, 1.0 / OutputSize)
|
||||
|
||||
#ifdef PARAMETER_UNIFORM
|
||||
// All parameter floats need to have COMPAT_PRECISION in front of them
|
||||
uniform COMPAT_PRECISION float BLOOM_STRENGTH;
|
||||
uniform COMPAT_PRECISION float OUTPUT_GAMMA;
|
||||
uniform COMPAT_PRECISION float PHOSPHOR_LAYOUT;
|
||||
uniform COMPAT_PRECISION float MASK_INTENSITY;
|
||||
#else
|
||||
#define BLOOM_STRENGTH 0.45
|
||||
#define OUTPUT_GAMMA 2.2
|
||||
#define PHOSPHOR_LAYOUT 4.0
|
||||
#define MASK_INTENSITY 0.5
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
A collection of CRT mask effects that work with LCD subpixel structures for
|
||||
small details
|
||||
|
||||
author: hunterk
|
||||
license: public domain
|
||||
|
||||
How to use it:
|
||||
|
||||
Multiply your image by the vec3 output:
|
||||
FragColor.rgb *= mask_weights(gl_FragCoord.xy, 1.0, 1);
|
||||
|
||||
The function needs to be tiled across the screen using the physical pixels, e.g.
|
||||
gl_FragCoord (the "vec2 coord" input). In the case of slang shaders, we use
|
||||
(vTexCoord.st * OutputSize.xy).
|
||||
|
||||
The "mask_intensity" (float value between 0.0 and 1.0) is how strong the mask
|
||||
effect should be. Full-strength red, green and blue subpixels on a white pixel
|
||||
are the ideal, and are achieved with an intensity of 1.0, though this darkens
|
||||
the image significantly and may not always be desirable.
|
||||
|
||||
The "phosphor_layout" (int value between 0 and 19) determines which phophor
|
||||
layout to apply. 0 is no mask/passthru.
|
||||
|
||||
Many of these mask arrays are adapted from cgwg's crt-geom-deluxe LUTs, and
|
||||
those have their filenames included for easy identification
|
||||
*/
|
||||
|
||||
vec3 mask_weights(vec2 coord, float mask_intensity, int phosphor_layout){
|
||||
vec3 weights = vec3(1.,1.,1.);
|
||||
float on = 1.;
|
||||
float off = 1.-mask_intensity;
|
||||
vec3 red = vec3(on, off, off);
|
||||
vec3 green = vec3(off, on, off);
|
||||
vec3 blue = vec3(off, off, on );
|
||||
vec3 magenta = vec3(on, off, on );
|
||||
vec3 yellow = vec3(on, on, off);
|
||||
vec3 cyan = vec3(off, on, on );
|
||||
vec3 black = vec3(off, off, off);
|
||||
vec3 white = vec3(on, on, on );
|
||||
int w, z = 0;
|
||||
|
||||
// This pattern is used by a few layouts, so we'll define it here
|
||||
vec3 aperture_weights = mix(magenta, green, floor(mod(coord.x, 2.0)));
|
||||
|
||||
if(phosphor_layout == 0) return weights;
|
||||
|
||||
else if(phosphor_layout == 1){
|
||||
// classic aperture for RGB panels; good for 1080p, too small for 4K+
|
||||
// aka aperture_1_2_bgr
|
||||
weights = aperture_weights;
|
||||
return weights;
|
||||
}
|
||||
|
||||
else if(phosphor_layout == 2){
|
||||
// 2x2 shadow mask for RGB panels; good for 1080p, too small for 4K+
|
||||
// aka delta_1_2x1_bgr
|
||||
vec3 inverse_aperture = mix(green, magenta, floor(mod(coord.x, 2.0)));
|
||||
weights = mix(aperture_weights, inverse_aperture, floor(mod(coord.y, 2.0)));
|
||||
return weights;
|
||||
}
|
||||
|
||||
else if(phosphor_layout == 3){
|
||||
// slot mask for RGB panels; looks okay at 1080p, looks better at 4K
|
||||
// {magenta, green, black, black},
|
||||
// {magenta, green, magenta, green},
|
||||
// {black, black, magenta, green}
|
||||
|
||||
// GLSL can't do 2D arrays until version 430, so do this stupid thing instead for compatibility's sake:
|
||||
// First lay out the horizontal pixels in arrays
|
||||
vec3 slotmask_x1[4] = vec3[](magenta, green, black, black);
|
||||
vec3 slotmask_x2[4] = vec3[](magenta, green, magenta, green);
|
||||
vec3 slotmask_x3[4] = vec3[](black, black, magenta, green);
|
||||
|
||||
// find the vertical index
|
||||
w = int(floor(mod(coord.y, 3.0)));
|
||||
|
||||
// find the horizontal index
|
||||
z = int(floor(mod(coord.x, 4.0)));
|
||||
|
||||
// do a big, dumb comparison in place of a 2D array
|
||||
weights = (w == 1) ? slotmask_x1[z] : (w == 2) ? slotmask_x2[z] : slotmask_x3[z];
|
||||
}
|
||||
|
||||
if(phosphor_layout == 4){
|
||||
// classic aperture for RBG panels; good for 1080p, too small for 4K+
|
||||
weights = mix(yellow, blue, floor(mod(coord.x, 2.0)));
|
||||
return weights;
|
||||
}
|
||||
|
||||
else if(phosphor_layout == 5){
|
||||
// 2x2 shadow mask for RBG panels; good for 1080p, too small for 4K+
|
||||
vec3 inverse_aperture = mix(blue, yellow, floor(mod(coord.x, 2.0)));
|
||||
weights = mix(mix(yellow, blue, floor(mod(coord.x, 2.0))), inverse_aperture, floor(mod(coord.y, 2.0)));
|
||||
return weights;
|
||||
}
|
||||
|
||||
else if(phosphor_layout == 6){
|
||||
// aperture_1_4_rgb; good for simulating lower
|
||||
vec3 ap4[4] = vec3[](red, green, blue, black);
|
||||
|
||||
z = int(floor(mod(coord.x, 4.0)));
|
||||
|
||||
weights = ap4[z];
|
||||
return weights;
|
||||
}
|
||||
|
||||
else if(phosphor_layout == 7){
|
||||
// aperture_2_5_bgr
|
||||
vec3 ap3[5] = vec3[](red, magenta, blue, green, green);
|
||||
|
||||
z = int(floor(mod(coord.x, 5.0)));
|
||||
|
||||
weights = ap3[z];
|
||||
return weights;
|
||||
}
|
||||
|
||||
else if(phosphor_layout == 8){
|
||||
// aperture_3_6_rgb
|
||||
|
||||
vec3 big_ap[7] = vec3[](red, red, yellow, green, cyan, blue, blue);
|
||||
|
||||
w = int(floor(mod(coord.x, 7.)));
|
||||
|
||||
weights = big_ap[w];
|
||||
return weights;
|
||||
}
|
||||
|
||||
else if(phosphor_layout == 9){
|
||||
// reduced TVL aperture for RGB panels
|
||||
// aperture_2_4_rgb
|
||||
|
||||
vec3 big_ap_rgb[4] = vec3[](red, yellow, cyan, blue);
|
||||
|
||||
w = int(floor(mod(coord.x, 4.)));
|
||||
|
||||
weights = big_ap_rgb[w];
|
||||
return weights;
|
||||
}
|
||||
|
||||
else if(phosphor_layout == 10){
|
||||
// reduced TVL aperture for RBG panels
|
||||
|
||||
vec3 big_ap_rbg[4] = vec3[](red, magenta, cyan, green);
|
||||
|
||||
w = int(floor(mod(coord.x, 4.)));
|
||||
|
||||
weights = big_ap_rbg[w];
|
||||
return weights;
|
||||
}
|
||||
|
||||
else if(phosphor_layout == 11){
|
||||
// delta_1_4x1_rgb; dunno why this is called 4x1 when it's obviously 4x2 /shrug
|
||||
vec3 delta_1_1[4] = vec3[](red, green, blue, black);
|
||||
vec3 delta_1_2[4] = vec3[](blue, black, red, green);
|
||||
|
||||
w = int(floor(mod(coord.y, 2.0)));
|
||||
z = int(floor(mod(coord.x, 4.0)));
|
||||
|
||||
weights = (w == 1) ? delta_1_1[z] : delta_1_2[z];
|
||||
return weights;
|
||||
}
|
||||
|
||||
else if(phosphor_layout == 12){
|
||||
// delta_2_4x1_rgb
|
||||
vec3 delta_2_1[4] = vec3[](red, yellow, cyan, blue);
|
||||
vec3 delta_2_2[4] = vec3[](cyan, blue, red, yellow);
|
||||
|
||||
z = int(floor(mod(coord.x, 4.0)));
|
||||
|
||||
weights = (w == 1) ? delta_2_1[z] : delta_2_2[z];
|
||||
return weights;
|
||||
}
|
||||
|
||||
else if(phosphor_layout == 13){
|
||||
// delta_2_4x2_rgb
|
||||
vec3 delta_1[4] = vec3[](red, yellow, cyan, blue);
|
||||
vec3 delta_2[4] = vec3[](red, yellow, cyan, blue);
|
||||
vec3 delta_3[4] = vec3[](cyan, blue, red, yellow);
|
||||
vec3 delta_4[4] = vec3[](cyan, blue, red, yellow);
|
||||
|
||||
w = int(floor(mod(coord.y, 4.0)));
|
||||
z = int(floor(mod(coord.x, 4.0)));
|
||||
|
||||
weights = (w == 1) ? delta_1[z] : (w == 2) ? delta_2[z] : (w == 3) ? delta_3[z] : delta_4[z];
|
||||
return weights;
|
||||
}
|
||||
|
||||
else if(phosphor_layout == 14){
|
||||
// slot mask for RGB panels; too low-pitch for 1080p, looks okay at 4K, but wants 8K+
|
||||
// {magenta, green, black, black, black, black},
|
||||
// {magenta, green, black, magenta, green, black},
|
||||
// {black, black, black, magenta, green, black}
|
||||
vec3 slot2_1[6] = vec3[](magenta, green, black, black, black, black);
|
||||
vec3 slot2_2[6] = vec3[](magenta, green, black, magenta, green, black);
|
||||
vec3 slot2_3[6] = vec3[](black, black, black, magenta, green, black);
|
||||
|
||||
w = int(floor(mod(coord.y, 3.0)));
|
||||
z = int(floor(mod(coord.x, 6.0)));
|
||||
|
||||
weights = (w == 1) ? slot2_1[z] : (w == 2) ? slot2_2[z] : slot2_3[z];
|
||||
return weights;
|
||||
}
|
||||
|
||||
else if(phosphor_layout == 15){
|
||||
// slot_2_4x4_rgb
|
||||
// {red, yellow, cyan, blue, red, yellow, cyan, blue },
|
||||
// {red, yellow, cyan, blue, black, black, black, black},
|
||||
// {red, yellow, cyan, blue, red, yellow, cyan, blue },
|
||||
// {black, black, black, black, red, yellow, cyan, blue }
|
||||
vec3 slotmask_RBG_x1[8] = vec3[](red, yellow, cyan, blue, red, yellow, cyan, blue );
|
||||
vec3 slotmask_RBG_x2[8] = vec3[](red, yellow, cyan, blue, black, black, black, black);
|
||||
vec3 slotmask_RBG_x3[8] = vec3[](red, yellow, cyan, blue, red, yellow, cyan, blue );
|
||||
vec3 slotmask_RBG_x4[8] = vec3[](black, black, black, black, red, yellow, cyan, blue );
|
||||
|
||||
// find the vertical index
|
||||
w = int(floor(mod(coord.y, 4.0)));
|
||||
|
||||
// find the horizontal index
|
||||
z = int(floor(mod(coord.x, 8.0)));
|
||||
|
||||
weights = (w == 1) ? slotmask_RBG_x1[z] : (w == 2) ? slotmask_RBG_x2[z] : (w == 3) ? slotmask_RBG_x3[z] : slotmask_RBG_x4[z];
|
||||
return weights;
|
||||
}
|
||||
|
||||
else if(phosphor_layout == 16){
|
||||
// slot mask for RBG panels; too low-pitch for 1080p, looks okay at 4K, but wants 8K+
|
||||
// {yellow, blue, black, black},
|
||||
// {yellow, blue, yellow, blue},
|
||||
// {black, black, yellow, blue}
|
||||
vec3 slot2_1[4] = vec3[](yellow, blue, black, black);
|
||||
vec3 slot2_2[4] = vec3[](yellow, blue, yellow, blue);
|
||||
vec3 slot2_3[4] = vec3[](black, black, yellow, blue);
|
||||
|
||||
w = int(floor(mod(coord.y, 3.0)));
|
||||
z = int(floor(mod(coord.x, 4.0)));
|
||||
|
||||
weights = (w == 1) ? slot2_1[z] : (w == 2) ? slot2_2[z] : slot2_3[z];
|
||||
return weights;
|
||||
}
|
||||
|
||||
else if(phosphor_layout == 17){
|
||||
// slot_2_5x4_bgr
|
||||
// {red, magenta, blue, green, green, red, magenta, blue, green, green},
|
||||
// {black, blue, blue, green, green, red, red, black, black, black},
|
||||
// {red, magenta, blue, green, green, red, magenta, blue, green, green},
|
||||
// {red, red, black, black, black, black, blue, blue, green, green}
|
||||
vec3 slot_1[10] = vec3[](red, magenta, blue, green, green, red, magenta, blue, green, green);
|
||||
vec3 slot_2[10] = vec3[](black, blue, blue, green, green, red, red, black, black, black);
|
||||
vec3 slot_3[10] = vec3[](red, magenta, blue, green, green, red, magenta, blue, green, green);
|
||||
vec3 slot_4[10] = vec3[](red, red, black, black, black, black, blue, blue, green, green);
|
||||
|
||||
w = int(floor(mod(coord.y, 4.0)));
|
||||
z = int(floor(mod(coord.x, 10.0)));
|
||||
|
||||
weights = (w == 1) ? slot_1[z] : (w == 2) ? slot_2[z] : (w == 3) ? slot_3[z] : slot_4[z];
|
||||
return weights;
|
||||
}
|
||||
|
||||
else if(phosphor_layout == 18){
|
||||
// same as above but for RBG panels
|
||||
// {red, yellow, green, blue, blue, red, yellow, green, blue, blue },
|
||||
// {black, green, green, blue, blue, red, red, black, black, black},
|
||||
// {red, yellow, green, blue, blue, red, yellow, green, blue, blue },
|
||||
// {red, red, black, black, black, black, green, green, blue, blue }
|
||||
vec3 slot_1[10] = vec3[](red, yellow, green, blue, blue, red, yellow, green, blue, blue );
|
||||
vec3 slot_2[10] = vec3[](black, green, green, blue, blue, red, red, black, black, black);
|
||||
vec3 slot_3[10] = vec3[](red, yellow, green, blue, blue, red, yellow, green, blue, blue );
|
||||
vec3 slot_4[10] = vec3[](red, red, black, black, black, black, green, green, blue, blue );
|
||||
|
||||
w = int(floor(mod(coord.y, 4.0)));
|
||||
z = int(floor(mod(coord.x, 10.0)));
|
||||
|
||||
weights = (w == 1) ? slot_1[z] : (w == 2) ? slot_2[z] : (w == 3) ? slot_3[z] : slot_4[z];
|
||||
return weights;
|
||||
}
|
||||
|
||||
else if(phosphor_layout == 19){
|
||||
// slot_3_7x6_rgb
|
||||
// {red, red, yellow, green, cyan, blue, blue, red, red, yellow, green, cyan, blue, blue},
|
||||
// {red, red, yellow, green, cyan, blue, blue, red, red, yellow, green, cyan, blue, blue},
|
||||
// {red, red, yellow, green, cyan, blue, blue, black, black, black, black, black, black, black},
|
||||
// {red, red, yellow, green, cyan, blue, blue, red, red, yellow, green, cyan, blue, blue},
|
||||
// {red, red, yellow, green, cyan, blue, blue, red, red, yellow, green, cyan, blue, blue},
|
||||
// {black, black, black, black, black, black, black, black, red, red, yellow, green, cyan, blue}
|
||||
|
||||
vec3 slot_1[14] = vec3[](red, red, yellow, green, cyan, blue, blue, red, red, yellow, green, cyan, blue, blue);
|
||||
vec3 slot_2[14] = vec3[](red, red, yellow, green, cyan, blue, blue, red, red, yellow, green, cyan, blue, blue);
|
||||
vec3 slot_3[14] = vec3[](red, red, yellow, green, cyan, blue, blue, black, black, black, black, black, black, black);
|
||||
vec3 slot_4[14] = vec3[](red, red, yellow, green, cyan, blue, blue, red, red, yellow, green, cyan, blue, blue);
|
||||
vec3 slot_5[14] = vec3[](red, red, yellow, green, cyan, blue, blue, red, red, yellow, green, cyan, blue, blue);
|
||||
vec3 slot_6[14] = vec3[](black, black, black, black, black, black, black, black, red, red, yellow, green, cyan, blue);
|
||||
|
||||
w = int(floor(mod(coord.y, 6.0)));
|
||||
z = int(floor(mod(coord.x, 14.0)));
|
||||
|
||||
weights = (w == 1) ? slot_1[z] : (w == 2) ? slot_2[z] : (w == 3) ? slot_3[z] : (w == 4) ? slot_4[z] : (w == 5) ? slot_5[z] : slot_6[z];
|
||||
return weights;
|
||||
}
|
||||
|
||||
else return weights;
|
||||
}
|
||||
|
||||
|
||||
// For debugging
|
||||
#define BLOOM_ONLY 0
|
||||
|
||||
void main()
|
||||
{
|
||||
#if BLOOM_ONLY
|
||||
vec3 source = BLOOM_STRENGTH * COMPAT_TEXTURE(Source, vTexCoord).rgb;
|
||||
#else
|
||||
|
||||
vec3 source = 1.15 * COMPAT_TEXTURE(PassPrev4Texture, vTexCoord).rgb;
|
||||
vec3 bloom = COMPAT_TEXTURE(Source, vTexCoord).rgb;
|
||||
source += BLOOM_STRENGTH * bloom;
|
||||
|
||||
vec2 mask_coords = gl_FragCoord.xy; //texCoord.xy * OutputSize.xy;
|
||||
// vec2 mask_coords = (vTexCoord.xy * OutputSize.xy) * TextureSize.xy / InputSize.xy;
|
||||
|
||||
source.rgb*=mask_weights(mask_coords, MASK_INTENSITY, int(PHOSPHOR_LAYOUT));
|
||||
#endif
|
||||
FragColor = vec4(pow(clamp(source, 0.0, 1.0), vec3(1.0 / OUTPUT_GAMMA)), 1.0);
|
||||
}
|
||||
#endif
|
576
crt/shaders/hyllian/crt-hyllian.glsl
Normal file
576
crt/shaders/hyllian/crt-hyllian.glsl
Normal file
@ -0,0 +1,576 @@
|
||||
/*
|
||||
Hyllian's CRT Shader
|
||||
|
||||
Copyright (C) 2011-2020 Hyllian - sergiogdb@gmail.com
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
|
||||
*/
|
||||
|
||||
#version 120
|
||||
|
||||
#pragma parameter BEAM_PROFILE "BEAM PROFILE (BP)" 0.0 0.0 6.0 1.0
|
||||
#pragma parameter BEAM_MIN_WIDTH " Custom [If BP=0.00] MIN BEAM WIDTH" 0.86 0.0 1.0 0.02
|
||||
#pragma parameter BEAM_MAX_WIDTH " Custom [If BP=0.00] MAX BEAM WIDTH" 1.0 0.0 1.0 0.02
|
||||
#pragma parameter SCANLINES_STRENGTH " Custom [If BP=0.00] SCANLINES STRENGTH" 0.58 0.0 1.0 0.02
|
||||
#pragma parameter COLOR_BOOST " Custom [If BP=0.00] COLOR BOOST" 1.25 1.0 2.0 0.05
|
||||
#pragma parameter HFILTER_SHARPNESS "HORIZONTAL FILTER SHARPNESS" 1.0 0.0 1.0 0.02
|
||||
#pragma parameter PHOSPHOR_LAYOUT "PHOSPHOR LAYOUT" 4.0 0.0 19.0 1.0
|
||||
#pragma parameter MASK_INTENSITY "MASK INTENSITY" 0.5 0.0 1.0 0.1
|
||||
#pragma parameter CRT_ANTI_RINGING "ANTI RINGING" 1.0 0.0 1.0 0.1
|
||||
#pragma parameter InputGamma "INPUT GAMMA" 2.4 0.0 5.0 0.1
|
||||
#pragma parameter OutputGamma "OUTPUT GAMMA" 2.2 0.0 5.0 0.1
|
||||
#pragma parameter VSCANLINES "SCANLINES DIRECTION" 0.0 0.0 1.0 1.0
|
||||
|
||||
#define GAMMA_IN(color) pow(color, vec4(InputGamma, InputGamma, InputGamma, InputGamma))
|
||||
#define GAMMA_OUT(color) pow(color, vec4(1.0 / OutputGamma, 1.0 / OutputGamma, 1.0 / OutputGamma, 1.0 / OutputGamma))
|
||||
|
||||
|
||||
#define texCoord TEX0
|
||||
|
||||
#if defined(VERTEX)
|
||||
|
||||
#if __VERSION__ >= 130
|
||||
#define OUT out
|
||||
#define IN in
|
||||
#define tex2D texture
|
||||
#else
|
||||
#define OUT varying
|
||||
#define IN attribute
|
||||
#define tex2D texture2D
|
||||
#endif
|
||||
|
||||
#ifdef GL_ES
|
||||
#define PRECISION mediump
|
||||
#else
|
||||
#define PRECISION
|
||||
#endif
|
||||
|
||||
|
||||
IN vec4 VertexCoord;
|
||||
IN vec4 Color;
|
||||
IN vec2 TexCoord;
|
||||
OUT vec4 color;
|
||||
OUT vec2 texCoord;
|
||||
|
||||
uniform mat4 MVPMatrix;
|
||||
uniform PRECISION int FrameDirection;
|
||||
uniform PRECISION int FrameCount;
|
||||
uniform PRECISION vec2 OutputSize;
|
||||
uniform PRECISION vec2 TextureSize;
|
||||
uniform PRECISION vec2 InputSize;
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = MVPMatrix * VertexCoord;
|
||||
color = Color;
|
||||
texCoord = TexCoord;
|
||||
}
|
||||
|
||||
|
||||
#elif defined(FRAGMENT)
|
||||
|
||||
#if __VERSION__ >= 130
|
||||
#define IN in
|
||||
#define tex2D texture
|
||||
out vec4 FragColor;
|
||||
#else
|
||||
#define IN varying
|
||||
#define FragColor gl_FragColor
|
||||
#define tex2D texture2D
|
||||
#endif
|
||||
|
||||
#ifdef GL_ES
|
||||
#ifdef GL_FRAGMENT_PRECISION_HIGH
|
||||
precision highp float;
|
||||
#else
|
||||
precision mediump float;
|
||||
#endif
|
||||
#define PRECISION mediump
|
||||
#else
|
||||
#define PRECISION
|
||||
#endif
|
||||
|
||||
uniform PRECISION int FrameDirection;
|
||||
uniform PRECISION int FrameCount;
|
||||
uniform PRECISION vec2 OutputSize;
|
||||
uniform PRECISION vec2 TextureSize;
|
||||
uniform PRECISION vec2 InputSize;
|
||||
uniform sampler2D s_p;
|
||||
IN vec2 texCoord;
|
||||
|
||||
#ifdef PARAMETER_UNIFORM
|
||||
uniform PRECISION float BEAM_PROFILE;
|
||||
uniform PRECISION float BEAM_MIN_WIDTH;
|
||||
uniform PRECISION float BEAM_MAX_WIDTH;
|
||||
uniform PRECISION float SCANLINES_STRENGTH;
|
||||
uniform PRECISION float COLOR_BOOST;
|
||||
uniform PRECISION float HFILTER_SHARPNESS;
|
||||
uniform PRECISION float PHOSPHOR_LAYOUT;
|
||||
uniform PRECISION float MASK_INTENSITY;
|
||||
uniform PRECISION float CRT_ANTI_RINGING;
|
||||
uniform PRECISION float InputGamma;
|
||||
uniform PRECISION float OutputGamma;
|
||||
uniform PRECISION float VSCANLINES;
|
||||
#else
|
||||
#define BEAM_PROFILE 0.0
|
||||
#define BEAM_MIN_WIDTH 0.86
|
||||
#define BEAM_MAX_WIDTH 1.0
|
||||
#define SCANLINES_STRENGTH 0.58
|
||||
#define COLOR_BOOST 1.25
|
||||
#define HFILTER_SHARPNESS 1.0
|
||||
#define PHOSPHOR_LAYOUT 4.0
|
||||
#define MASK_INTENSITY 0.5
|
||||
#define CRT_ANTI_RINGING 1.0
|
||||
#define InputGamma 2.4
|
||||
#define OutputGamma 2.2
|
||||
#define VSCANLINES 0.0
|
||||
#endif
|
||||
// END PARAMETERS //
|
||||
|
||||
|
||||
/*
|
||||
A collection of CRT mask effects that work with LCD subpixel structures for
|
||||
small details
|
||||
|
||||
author: hunterk
|
||||
license: public domain
|
||||
|
||||
How to use it:
|
||||
|
||||
Multiply your image by the vec3 output:
|
||||
FragColor.rgb *= mask_weights(gl_FragCoord.xy, 1.0, 1);
|
||||
|
||||
The function needs to be tiled across the screen using the physical pixels, e.g.
|
||||
gl_FragCoord (the "vec2 coord" input). In the case of slang shaders, we use
|
||||
(vTexCoord.st * OutputSize.xy).
|
||||
|
||||
The "mask_intensity" (float value between 0.0 and 1.0) is how strong the mask
|
||||
effect should be. Full-strength red, green and blue subpixels on a white pixel
|
||||
are the ideal, and are achieved with an intensity of 1.0, though this darkens
|
||||
the image significantly and may not always be desirable.
|
||||
|
||||
The "phosphor_layout" (int value between 0 and 19) determines which phophor
|
||||
layout to apply. 0 is no mask/passthru.
|
||||
|
||||
Many of these mask arrays are adapted from cgwg's crt-geom-deluxe LUTs, and
|
||||
those have their filenames included for easy identification
|
||||
*/
|
||||
|
||||
vec3 mask_weights(vec2 coord, float mask_intensity, int phosphor_layout){
|
||||
vec3 weights = vec3(1.,1.,1.);
|
||||
float on = 1.;
|
||||
float off = 1.-mask_intensity;
|
||||
vec3 red = vec3(on, off, off);
|
||||
vec3 green = vec3(off, on, off);
|
||||
vec3 blue = vec3(off, off, on );
|
||||
vec3 magenta = vec3(on, off, on );
|
||||
vec3 yellow = vec3(on, on, off);
|
||||
vec3 cyan = vec3(off, on, on );
|
||||
vec3 black = vec3(off, off, off);
|
||||
vec3 white = vec3(on, on, on );
|
||||
int w, z = 0;
|
||||
|
||||
// This pattern is used by a few layouts, so we'll define it here
|
||||
vec3 aperture_weights = mix(magenta, green, floor(mod(coord.x, 2.0)));
|
||||
|
||||
if(phosphor_layout == 0) return weights;
|
||||
|
||||
else if(phosphor_layout == 1){
|
||||
// classic aperture for RGB panels; good for 1080p, too small for 4K+
|
||||
// aka aperture_1_2_bgr
|
||||
weights = aperture_weights;
|
||||
return weights;
|
||||
}
|
||||
|
||||
else if(phosphor_layout == 2){
|
||||
// 2x2 shadow mask for RGB panels; good for 1080p, too small for 4K+
|
||||
// aka delta_1_2x1_bgr
|
||||
vec3 inverse_aperture = mix(green, magenta, floor(mod(coord.x, 2.0)));
|
||||
weights = mix(aperture_weights, inverse_aperture, floor(mod(coord.y, 2.0)));
|
||||
return weights;
|
||||
}
|
||||
|
||||
else if(phosphor_layout == 3){
|
||||
// slot mask for RGB panels; looks okay at 1080p, looks better at 4K
|
||||
// {magenta, green, black, black},
|
||||
// {magenta, green, magenta, green},
|
||||
// {black, black, magenta, green}
|
||||
|
||||
// GLSL can't do 2D arrays until version 430, so do this stupid thing instead for compatibility's sake:
|
||||
// First lay out the horizontal pixels in arrays
|
||||
vec3 slotmask_x1[4] = vec3[](magenta, green, black, black);
|
||||
vec3 slotmask_x2[4] = vec3[](magenta, green, magenta, green);
|
||||
vec3 slotmask_x3[4] = vec3[](black, black, magenta, green);
|
||||
|
||||
// find the vertical index
|
||||
w = int(floor(mod(coord.y, 3.0)));
|
||||
|
||||
// find the horizontal index
|
||||
z = int(floor(mod(coord.x, 4.0)));
|
||||
|
||||
// do a big, dumb comparison in place of a 2D array
|
||||
weights = (w == 1) ? slotmask_x1[z] : (w == 2) ? slotmask_x2[z] : slotmask_x3[z];
|
||||
}
|
||||
|
||||
if(phosphor_layout == 4){
|
||||
// classic aperture for RBG panels; good for 1080p, too small for 4K+
|
||||
weights = mix(yellow, blue, floor(mod(coord.x, 2.0)));
|
||||
return weights;
|
||||
}
|
||||
|
||||
else if(phosphor_layout == 5){
|
||||
// 2x2 shadow mask for RBG panels; good for 1080p, too small for 4K+
|
||||
vec3 inverse_aperture = mix(blue, yellow, floor(mod(coord.x, 2.0)));
|
||||
weights = mix(mix(yellow, blue, floor(mod(coord.x, 2.0))), inverse_aperture, floor(mod(coord.y, 2.0)));
|
||||
return weights;
|
||||
}
|
||||
|
||||
else if(phosphor_layout == 6){
|
||||
// aperture_1_4_rgb; good for simulating lower
|
||||
vec3 ap4[4] = vec3[](red, green, blue, black);
|
||||
|
||||
z = int(floor(mod(coord.x, 4.0)));
|
||||
|
||||
weights = ap4[z];
|
||||
return weights;
|
||||
}
|
||||
|
||||
else if(phosphor_layout == 7){
|
||||
// aperture_2_5_bgr
|
||||
vec3 ap3[5] = vec3[](red, magenta, blue, green, green);
|
||||
|
||||
z = int(floor(mod(coord.x, 5.0)));
|
||||
|
||||
weights = ap3[z];
|
||||
return weights;
|
||||
}
|
||||
|
||||
else if(phosphor_layout == 8){
|
||||
// aperture_3_6_rgb
|
||||
|
||||
vec3 big_ap[7] = vec3[](red, red, yellow, green, cyan, blue, blue);
|
||||
|
||||
w = int(floor(mod(coord.x, 7.)));
|
||||
|
||||
weights = big_ap[w];
|
||||
return weights;
|
||||
}
|
||||
|
||||
else if(phosphor_layout == 9){
|
||||
// reduced TVL aperture for RGB panels
|
||||
// aperture_2_4_rgb
|
||||
|
||||
vec3 big_ap_rgb[4] = vec3[](red, yellow, cyan, blue);
|
||||
|
||||
w = int(floor(mod(coord.x, 4.)));
|
||||
|
||||
weights = big_ap_rgb[w];
|
||||
return weights;
|
||||
}
|
||||
|
||||
else if(phosphor_layout == 10){
|
||||
// reduced TVL aperture for RBG panels
|
||||
|
||||
vec3 big_ap_rbg[4] = vec3[](red, magenta, cyan, green);
|
||||
|
||||
w = int(floor(mod(coord.x, 4.)));
|
||||
|
||||
weights = big_ap_rbg[w];
|
||||
return weights;
|
||||
}
|
||||
|
||||
else if(phosphor_layout == 11){
|
||||
// delta_1_4x1_rgb; dunno why this is called 4x1 when it's obviously 4x2 /shrug
|
||||
vec3 delta_1_1[4] = vec3[](red, green, blue, black);
|
||||
vec3 delta_1_2[4] = vec3[](blue, black, red, green);
|
||||
|
||||
w = int(floor(mod(coord.y, 2.0)));
|
||||
z = int(floor(mod(coord.x, 4.0)));
|
||||
|
||||
weights = (w == 1) ? delta_1_1[z] : delta_1_2[z];
|
||||
return weights;
|
||||
}
|
||||
|
||||
else if(phosphor_layout == 12){
|
||||
// delta_2_4x1_rgb
|
||||
vec3 delta_2_1[4] = vec3[](red, yellow, cyan, blue);
|
||||
vec3 delta_2_2[4] = vec3[](cyan, blue, red, yellow);
|
||||
|
||||
z = int(floor(mod(coord.x, 4.0)));
|
||||
|
||||
weights = (w == 1) ? delta_2_1[z] : delta_2_2[z];
|
||||
return weights;
|
||||
}
|
||||
|
||||
else if(phosphor_layout == 13){
|
||||
// delta_2_4x2_rgb
|
||||
vec3 delta_1[4] = vec3[](red, yellow, cyan, blue);
|
||||
vec3 delta_2[4] = vec3[](red, yellow, cyan, blue);
|
||||
vec3 delta_3[4] = vec3[](cyan, blue, red, yellow);
|
||||
vec3 delta_4[4] = vec3[](cyan, blue, red, yellow);
|
||||
|
||||
w = int(floor(mod(coord.y, 4.0)));
|
||||
z = int(floor(mod(coord.x, 4.0)));
|
||||
|
||||
weights = (w == 1) ? delta_1[z] : (w == 2) ? delta_2[z] : (w == 3) ? delta_3[z] : delta_4[z];
|
||||
return weights;
|
||||
}
|
||||
|
||||
else if(phosphor_layout == 14){
|
||||
// slot mask for RGB panels; too low-pitch for 1080p, looks okay at 4K, but wants 8K+
|
||||
// {magenta, green, black, black, black, black},
|
||||
// {magenta, green, black, magenta, green, black},
|
||||
// {black, black, black, magenta, green, black}
|
||||
vec3 slot2_1[6] = vec3[](magenta, green, black, black, black, black);
|
||||
vec3 slot2_2[6] = vec3[](magenta, green, black, magenta, green, black);
|
||||
vec3 slot2_3[6] = vec3[](black, black, black, magenta, green, black);
|
||||
|
||||
w = int(floor(mod(coord.y, 3.0)));
|
||||
z = int(floor(mod(coord.x, 6.0)));
|
||||
|
||||
weights = (w == 1) ? slot2_1[z] : (w == 2) ? slot2_2[z] : slot2_3[z];
|
||||
return weights;
|
||||
}
|
||||
|
||||
else if(phosphor_layout == 15){
|
||||
// slot_2_4x4_rgb
|
||||
// {red, yellow, cyan, blue, red, yellow, cyan, blue },
|
||||
// {red, yellow, cyan, blue, black, black, black, black},
|
||||
// {red, yellow, cyan, blue, red, yellow, cyan, blue },
|
||||
// {black, black, black, black, red, yellow, cyan, blue }
|
||||
vec3 slotmask_RBG_x1[8] = vec3[](red, yellow, cyan, blue, red, yellow, cyan, blue );
|
||||
vec3 slotmask_RBG_x2[8] = vec3[](red, yellow, cyan, blue, black, black, black, black);
|
||||
vec3 slotmask_RBG_x3[8] = vec3[](red, yellow, cyan, blue, red, yellow, cyan, blue );
|
||||
vec3 slotmask_RBG_x4[8] = vec3[](black, black, black, black, red, yellow, cyan, blue );
|
||||
|
||||
// find the vertical index
|
||||
w = int(floor(mod(coord.y, 4.0)));
|
||||
|
||||
// find the horizontal index
|
||||
z = int(floor(mod(coord.x, 8.0)));
|
||||
|
||||
weights = (w == 1) ? slotmask_RBG_x1[z] : (w == 2) ? slotmask_RBG_x2[z] : (w == 3) ? slotmask_RBG_x3[z] : slotmask_RBG_x4[z];
|
||||
return weights;
|
||||
}
|
||||
|
||||
else if(phosphor_layout == 16){
|
||||
// slot mask for RBG panels; too low-pitch for 1080p, looks okay at 4K, but wants 8K+
|
||||
// {yellow, blue, black, black},
|
||||
// {yellow, blue, yellow, blue},
|
||||
// {black, black, yellow, blue}
|
||||
vec3 slot2_1[4] = vec3[](yellow, blue, black, black);
|
||||
vec3 slot2_2[4] = vec3[](yellow, blue, yellow, blue);
|
||||
vec3 slot2_3[4] = vec3[](black, black, yellow, blue);
|
||||
|
||||
w = int(floor(mod(coord.y, 3.0)));
|
||||
z = int(floor(mod(coord.x, 4.0)));
|
||||
|
||||
weights = (w == 1) ? slot2_1[z] : (w == 2) ? slot2_2[z] : slot2_3[z];
|
||||
return weights;
|
||||
}
|
||||
|
||||
else if(phosphor_layout == 17){
|
||||
// slot_2_5x4_bgr
|
||||
// {red, magenta, blue, green, green, red, magenta, blue, green, green},
|
||||
// {black, blue, blue, green, green, red, red, black, black, black},
|
||||
// {red, magenta, blue, green, green, red, magenta, blue, green, green},
|
||||
// {red, red, black, black, black, black, blue, blue, green, green}
|
||||
vec3 slot_1[10] = vec3[](red, magenta, blue, green, green, red, magenta, blue, green, green);
|
||||
vec3 slot_2[10] = vec3[](black, blue, blue, green, green, red, red, black, black, black);
|
||||
vec3 slot_3[10] = vec3[](red, magenta, blue, green, green, red, magenta, blue, green, green);
|
||||
vec3 slot_4[10] = vec3[](red, red, black, black, black, black, blue, blue, green, green);
|
||||
|
||||
w = int(floor(mod(coord.y, 4.0)));
|
||||
z = int(floor(mod(coord.x, 10.0)));
|
||||
|
||||
weights = (w == 1) ? slot_1[z] : (w == 2) ? slot_2[z] : (w == 3) ? slot_3[z] : slot_4[z];
|
||||
return weights;
|
||||
}
|
||||
|
||||
else if(phosphor_layout == 18){
|
||||
// same as above but for RBG panels
|
||||
// {red, yellow, green, blue, blue, red, yellow, green, blue, blue },
|
||||
// {black, green, green, blue, blue, red, red, black, black, black},
|
||||
// {red, yellow, green, blue, blue, red, yellow, green, blue, blue },
|
||||
// {red, red, black, black, black, black, green, green, blue, blue }
|
||||
vec3 slot_1[10] = vec3[](red, yellow, green, blue, blue, red, yellow, green, blue, blue );
|
||||
vec3 slot_2[10] = vec3[](black, green, green, blue, blue, red, red, black, black, black);
|
||||
vec3 slot_3[10] = vec3[](red, yellow, green, blue, blue, red, yellow, green, blue, blue );
|
||||
vec3 slot_4[10] = vec3[](red, red, black, black, black, black, green, green, blue, blue );
|
||||
|
||||
w = int(floor(mod(coord.y, 4.0)));
|
||||
z = int(floor(mod(coord.x, 10.0)));
|
||||
|
||||
weights = (w == 1) ? slot_1[z] : (w == 2) ? slot_2[z] : (w == 3) ? slot_3[z] : slot_4[z];
|
||||
return weights;
|
||||
}
|
||||
|
||||
else if(phosphor_layout == 19){
|
||||
// slot_3_7x6_rgb
|
||||
// {red, red, yellow, green, cyan, blue, blue, red, red, yellow, green, cyan, blue, blue},
|
||||
// {red, red, yellow, green, cyan, blue, blue, red, red, yellow, green, cyan, blue, blue},
|
||||
// {red, red, yellow, green, cyan, blue, blue, black, black, black, black, black, black, black},
|
||||
// {red, red, yellow, green, cyan, blue, blue, red, red, yellow, green, cyan, blue, blue},
|
||||
// {red, red, yellow, green, cyan, blue, blue, red, red, yellow, green, cyan, blue, blue},
|
||||
// {black, black, black, black, black, black, black, black, red, red, yellow, green, cyan, blue}
|
||||
|
||||
vec3 slot_1[14] = vec3[](red, red, yellow, green, cyan, blue, blue, red, red, yellow, green, cyan, blue, blue);
|
||||
vec3 slot_2[14] = vec3[](red, red, yellow, green, cyan, blue, blue, red, red, yellow, green, cyan, blue, blue);
|
||||
vec3 slot_3[14] = vec3[](red, red, yellow, green, cyan, blue, blue, black, black, black, black, black, black, black);
|
||||
vec3 slot_4[14] = vec3[](red, red, yellow, green, cyan, blue, blue, red, red, yellow, green, cyan, blue, blue);
|
||||
vec3 slot_5[14] = vec3[](red, red, yellow, green, cyan, blue, blue, red, red, yellow, green, cyan, blue, blue);
|
||||
vec3 slot_6[14] = vec3[](black, black, black, black, black, black, black, black, red, red, yellow, green, cyan, blue);
|
||||
|
||||
w = int(floor(mod(coord.y, 6.0)));
|
||||
z = int(floor(mod(coord.x, 14.0)));
|
||||
|
||||
weights = (w == 1) ? slot_1[z] : (w == 2) ? slot_2[z] : (w == 3) ? slot_3[z] : (w == 4) ? slot_4[z] : (w == 5) ? slot_5[z] : slot_6[z];
|
||||
return weights;
|
||||
}
|
||||
|
||||
else return weights;
|
||||
}
|
||||
|
||||
|
||||
// Horizontal cubic filter.
|
||||
|
||||
// Some known filters use these values:
|
||||
|
||||
// B = 0.0, C = 0.0 => Hermite cubic filter.
|
||||
// B = 1.0, C = 0.0 => Cubic B-Spline filter.
|
||||
// B = 0.0, C = 0.5 => Catmull-Rom Spline filter. This is the default used in this shader.
|
||||
// B = C = 1.0/3.0 => Mitchell-Netravali cubic filter.
|
||||
// B = 0.3782, C = 0.3109 => Robidoux filter.
|
||||
// B = 0.2620, C = 0.3690 => Robidoux Sharp filter.
|
||||
|
||||
float B = 1.0 - HFILTER_SHARPNESS;
|
||||
float C = HFILTER_SHARPNESS*0.5; // B+2C=1 Mitchel-Netravali recommendation line.
|
||||
|
||||
mat4 invX = mat4( (-B - 6.0*C)/6.0, (12.0 - 9.0*B - 6.0*C)/6.0, -(12.0 - 9.0*B - 6.0*C)/6.0, (B + 6.0*C)/6.0,
|
||||
(3.0*B + 12.0*C)/6.0, (-18.0 + 12.0*B + 6.0*C)/6.0, (18.0 - 15.0*B - 12.0*C)/6.0, -C,
|
||||
(-3.0*B - 6.0*C)/6.0, 0.0, (3.0*B + 6.0*C)/6.0, 0.0,
|
||||
B/6.0, (6.0 - 2.0*B)/6.0, B/6.0, 0.0);
|
||||
|
||||
|
||||
|
||||
#define scanlines_strength (4.0*profile.x)
|
||||
#define beam_min_width profile.y
|
||||
#define beam_max_width profile.z
|
||||
#define color_boost profile.w
|
||||
|
||||
vec4 get_beam_profile()
|
||||
{
|
||||
vec4 bp = vec4(SCANLINES_STRENGTH, BEAM_MIN_WIDTH, BEAM_MAX_WIDTH, COLOR_BOOST);
|
||||
|
||||
if (BEAM_PROFILE == 1.0) bp = vec4(0.40, 1.00, 1.00, 1.00); // Catmull-rom
|
||||
if (BEAM_PROFILE == 2.0) bp = vec4(0.72, 1.00, 1.00, 1.25); // Catmull-rom
|
||||
if (BEAM_PROFILE == 3.0) bp = vec4(0.60, 0.50, 1.00, 1.25); // Hermite
|
||||
if (BEAM_PROFILE == 4.0) bp = vec4(0.60, 0.72, 1.00, 1.25); // Hermite
|
||||
if (BEAM_PROFILE == 5.0) bp = vec4(0.68, 0.68, 1.00, 1.25); // Hermite
|
||||
if (BEAM_PROFILE == 6.0) bp = vec4(0.70, 0.50, 1.00, 1.80); // Catmull-rom
|
||||
|
||||
return bp;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void main()
|
||||
{
|
||||
vec4 profile = get_beam_profile();
|
||||
|
||||
vec2 dx = mix(vec2(1.0/TextureSize.x, 0.0), vec2(0.0, 1.0/TextureSize.y), VSCANLINES);
|
||||
vec2 dy = mix(vec2(0.0, 1.0/TextureSize.y), vec2(1.0/TextureSize.x, 0.0), VSCANLINES);
|
||||
|
||||
vec2 pix_coord = texCoord.xy*TextureSize + vec2(-0.5, 0.5);
|
||||
|
||||
vec2 tc = mix((floor(pix_coord) + vec2(0.5, 0.5))/TextureSize, (floor(pix_coord) + vec2(1.0, -0.5))/TextureSize, VSCANLINES);
|
||||
|
||||
vec2 fp = mix(fract(pix_coord), fract(pix_coord.yx), VSCANLINES);
|
||||
|
||||
vec4 c00 = GAMMA_IN(tex2D(s_p, tc - dx - dy).xyzw);
|
||||
vec4 c01 = GAMMA_IN(tex2D(s_p, tc - dy).xyzw);
|
||||
vec4 c02 = GAMMA_IN(tex2D(s_p, tc + dx - dy).xyzw);
|
||||
vec4 c03 = GAMMA_IN(tex2D(s_p, tc + 2.0*dx - dy).xyzw);
|
||||
vec4 c10 = GAMMA_IN(tex2D(s_p, tc - dx).xyzw);
|
||||
vec4 c11 = GAMMA_IN(tex2D(s_p, tc ).xyzw);
|
||||
vec4 c12 = GAMMA_IN(tex2D(s_p, tc + dx).xyzw);
|
||||
vec4 c13 = GAMMA_IN(tex2D(s_p, tc + 2.0*dx).xyzw);
|
||||
|
||||
mat4 color_matrix0 = mat4(c00, c01, c02, c03);
|
||||
mat4 color_matrix1 = mat4(c10, c11, c12, c13);
|
||||
|
||||
vec4 lobes = vec4(fp.x*fp.x*fp.x, fp.x*fp.x, fp.x, 1.0);
|
||||
|
||||
vec4 invX_Px = invX * lobes;
|
||||
vec4 color0 = color_matrix0 * invX_Px;
|
||||
vec4 color1 = color_matrix1 * invX_Px;
|
||||
|
||||
// Get min/max samples
|
||||
vec4 min_sample0 = min(c01,c02);
|
||||
vec4 max_sample0 = max(c01,c02);
|
||||
vec4 min_sample1 = min(c11,c12);
|
||||
vec4 max_sample1 = max(c11,c12);
|
||||
|
||||
// Anti-ringing
|
||||
vec4 aux = color0;
|
||||
color0 = clamp(color0, min_sample0, max_sample0);
|
||||
color0 = mix(aux, color0, CRT_ANTI_RINGING);
|
||||
aux = color1;
|
||||
color1 = clamp(color1, min_sample1, max_sample1);
|
||||
color1 = mix(aux, color1, CRT_ANTI_RINGING);
|
||||
|
||||
float pos0 = fp.y;
|
||||
float pos1 = 1.0 - fp.y;
|
||||
|
||||
vec4 lum0 = mix(vec4(beam_min_width), vec4(beam_max_width), color0);
|
||||
vec4 lum1 = mix(vec4(beam_min_width), vec4(beam_max_width), color1);
|
||||
|
||||
vec4 d0 = scanlines_strength*pos0/(lum0+0.0000001);
|
||||
vec4 d1 = scanlines_strength*pos1/(lum1+0.0000001);
|
||||
|
||||
d0 = exp(-d0*d0);
|
||||
d1 = exp(-d1*d1);
|
||||
|
||||
vec4 color = color_boost*(color0*d0+color1*d1);
|
||||
|
||||
/* float mod_factor = texCoord.x * OutputSize.x * TextureSize.x / InputSize.x;
|
||||
|
||||
vec4 dotMaskWeights = mix(
|
||||
vec4(1.0, 1.0-MASK_INTENSITY, 1.0, 1.),
|
||||
vec4(1.0-MASK_INTENSITY, 1.0, 1.0-MASK_INTENSITY, 1.),
|
||||
floor(mod(mod_factor, 2.0))
|
||||
);
|
||||
|
||||
color.rgba *= dotMaskWeights;
|
||||
*/
|
||||
|
||||
vec2 mask_coords = gl_FragCoord.xy; //texCoord.xy * OutputSize.xy;
|
||||
//vec2 mask_coords = (texCoord.xy * OutputSize.xy) * TextureSize.xy / InputSize.xy;
|
||||
|
||||
mask_coords = mix(mask_coords.xy, mask_coords.yx, VSCANLINES);
|
||||
|
||||
color.rgb*=mask_weights(mask_coords, MASK_INTENSITY, int(PHOSPHOR_LAYOUT));
|
||||
|
||||
color = GAMMA_OUT(color);
|
||||
|
||||
FragColor = vec4(color);
|
||||
}
|
||||
#endif
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
SGENPT-MIX - Sega Genesis Pseudo Transparency Mixer Shader - v5
|
||||
SGENPT-MIX - Sega Genesis Pseudo Transparency Mixer Shader - v8b
|
||||
|
||||
2011-2020 Hyllian - sergiogdb@gmail.com
|
||||
|
||||
@ -23,9 +23,10 @@
|
||||
|
||||
*/
|
||||
|
||||
#pragma parameter SGPT_SHARPNESS "SGENPT-MIX Sharpness" 1.0 0.0 1.0 0.1
|
||||
#pragma parameter SGPT_BLEND_OPTION "OFF | Transparency | Checkerboard" 1.0 0.0 2.0 1.0
|
||||
#pragma parameter SGPT_BLEND_LEVEL "SGENPT-MIX Blend Level" 1.0 0.0 1.0 0.1
|
||||
#pragma parameter SGPT_BLEND_OPTION "0.OFF | 1.VL | 2.CB | 3.CB-S | 4.Both | 5.Both2 | 6.Both-S" 4.0 0.0 6.0 1.0
|
||||
#pragma parameter SGPT_BLEND_LEVEL "SGENPT-MIX Both Blend Level" 1.0 0.0 1.0 0.1
|
||||
#pragma parameter SGPT_ADJUST_VIEW "SGENPT-MIX Adjust View" 0.0 0.0 1.0 1.0
|
||||
#pragma parameter SGPT_LINEAR_GAMMA "SGENPT-MIX Use Linear Gamma" 1.0 0.0 1.0 1.0
|
||||
|
||||
|
||||
#define texCoord TEX0
|
||||
@ -101,18 +102,28 @@ uniform sampler2D s_p;
|
||||
IN vec2 texCoord;
|
||||
|
||||
#ifdef PARAMETER_UNIFORM
|
||||
uniform COMPAT_PRECISION float SGPT_SHARPNESS;
|
||||
uniform COMPAT_PRECISION float SGPT_BLEND_OPTION;
|
||||
uniform COMPAT_PRECISION float SGPT_BLEND_LEVEL;
|
||||
uniform COMPAT_PRECISION float SGPT_ADJUST_VIEW;
|
||||
uniform COMPAT_PRECISION float SGPT_LINEAR_GAMMA;
|
||||
#else
|
||||
#define SGPT_SHARPNESS 1.0
|
||||
#define SGPT_BLEND_OPTION 1.0
|
||||
#define SGPT_BLEND_OPTION 4.0
|
||||
#define SGPT_BLEND_LEVEL 1.0
|
||||
#define SGPT_ADJUST_VIEW 0.0
|
||||
#define SGPT_LINEAR_GAMMA 1.0
|
||||
#endif
|
||||
|
||||
|
||||
#define GAMMA_EXP (SGPT_LINEAR_GAMMA+1.0)
|
||||
#define GAMMA_IN(color) pow(color, vec3(GAMMA_EXP, GAMMA_EXP, GAMMA_EXP))
|
||||
#define GAMMA_OUT(color) pow(color, vec3(1.0 / GAMMA_EXP, 1.0 / GAMMA_EXP, 1.0 / GAMMA_EXP))
|
||||
|
||||
|
||||
const vec3 Y = vec3(.2126, .7152, .0722);
|
||||
|
||||
vec3 min_s(vec3 central, vec3 adj1, vec3 adj2) {return min(central, max(adj1, adj2));}
|
||||
vec3 max_s(vec3 central, vec3 adj1, vec3 adj2) {return max(central, min(adj1, adj2));}
|
||||
|
||||
|
||||
void main()
|
||||
{
|
||||
@ -120,39 +131,80 @@ void main()
|
||||
vec2 dy = vec2(0.0, 1.0)/TextureSize;
|
||||
|
||||
// Reading the texels.
|
||||
vec3 C = tex2D(s_p, texCoord ).xyz;
|
||||
vec3 L = tex2D(s_p, texCoord -dx).xyz;
|
||||
vec3 R = tex2D(s_p, texCoord +dx).xyz;
|
||||
vec3 U = tex2D(s_p, texCoord -dy).xyz;
|
||||
vec3 D = tex2D(s_p, texCoord +dy).xyz;
|
||||
vec3 C = GAMMA_IN(tex2D(s_p, texCoord ).xyz);
|
||||
vec3 L = GAMMA_IN(tex2D(s_p, texCoord -dx).xyz);
|
||||
vec3 R = GAMMA_IN(tex2D(s_p, texCoord +dx).xyz);
|
||||
vec3 U = GAMMA_IN(tex2D(s_p, texCoord -dy).xyz);
|
||||
vec3 D = GAMMA_IN(tex2D(s_p, texCoord +dy).xyz);
|
||||
vec3 UL = GAMMA_IN(tex2D(s_p, texCoord -dx -dy).xyz);
|
||||
vec3 UR = GAMMA_IN(tex2D(s_p, texCoord +dx -dy).xyz);
|
||||
vec3 DL = GAMMA_IN(tex2D(s_p, texCoord -dx +dy).xyz);
|
||||
vec3 DR = GAMMA_IN(tex2D(s_p, texCoord +dx +dy).xyz);
|
||||
|
||||
vec3 color = C;
|
||||
|
||||
if (SGPT_BLEND_OPTION > 0.0)
|
||||
{
|
||||
// Get min/max samples
|
||||
vec3 min_sample = min(C, max(L, R));
|
||||
vec3 max_sample = max(C, min(L, R));
|
||||
// Get min/max samples
|
||||
vec3 min_sample = min_s(C, L, R);
|
||||
vec3 max_sample = max_s(C, L, R);
|
||||
|
||||
float diff = (1.0 - SGPT_BLEND_LEVEL) * dot(max(max(C, L), max(C, R)) - min(min(C, L), min(C, R)), Y);
|
||||
float diff = dot(max(max(C, L), max(C, R)) - min(min(C, L), min(C, R)), Y);
|
||||
|
||||
if (int(SGPT_BLEND_OPTION) == 1) // Only Vertical Lines
|
||||
{
|
||||
min_sample = max_s(min_sample, min_s(C, DL, DR), min_s(C, UL, UR));
|
||||
max_sample = min_s(max_sample, max_s(C, DL, DR), max_s(C, UL, UR));
|
||||
|
||||
diff *= (1.0 - SGPT_BLEND_LEVEL);
|
||||
|
||||
color = 0.5*( 1.0 + diff )*C + 0.25*( 1.0 - diff )*(L + R);
|
||||
}
|
||||
else if (int(SGPT_BLEND_OPTION) == 2) // Only Checkerboard
|
||||
{
|
||||
min_sample = max(min_sample, min_s(C, U, D));
|
||||
max_sample = min(max_sample, max_s(C, U, D));
|
||||
|
||||
if (SGPT_BLEND_OPTION > 1.0)
|
||||
{
|
||||
// Get min/max samples
|
||||
min_sample = max(min_sample, min(C, max(U, D)));
|
||||
max_sample = min(max_sample, max(C, min(U, D)));
|
||||
diff *= (1.0 - SGPT_BLEND_LEVEL);
|
||||
|
||||
color = 0.5*( 1.0 + diff )*C + 0.125*( 1.0 - diff )*(L + R + U + D);
|
||||
}
|
||||
color = 0.5*( 1.0 + diff )*C + 0.125*( 1.0 - diff )*(L + R + U + D);
|
||||
}
|
||||
else if (int(SGPT_BLEND_OPTION) == 3) // Only Checkerboard - Soft
|
||||
{
|
||||
min_sample = min_s(min_sample, U, D);
|
||||
max_sample = max_s(max_sample, U, D);
|
||||
|
||||
// Sharpness control
|
||||
vec3 aux = color;
|
||||
color = clamp(color, min_sample, max_sample);
|
||||
color = mix(aux, color, SGPT_SHARPNESS);
|
||||
diff *= (1.0 - SGPT_BLEND_LEVEL);
|
||||
|
||||
color = 0.5*( 1.0 + diff )*C + 0.125*( 1.0 - diff )*(L + R + U + D);
|
||||
}
|
||||
else if (int(SGPT_BLEND_OPTION) == 4) // VL-CB
|
||||
{
|
||||
diff *= (1.0 - SGPT_BLEND_LEVEL);
|
||||
|
||||
color = 0.5*( 1.0 + diff )*C + 0.25*( 1.0 - diff )*(L + R);
|
||||
}
|
||||
else if (int(SGPT_BLEND_OPTION) == 5) // VL-CB-2
|
||||
{
|
||||
min_sample = min_s(min_sample, U, D);
|
||||
max_sample = max_s(max_sample, U, D);
|
||||
|
||||
diff *= (1.0 - SGPT_BLEND_LEVEL);
|
||||
|
||||
color = 0.5*( 1.0 + diff )*C + 0.25*( 1.0 - diff )*(L + R);
|
||||
}
|
||||
else if (int(SGPT_BLEND_OPTION) == 6) // VL-CB-Soft
|
||||
{
|
||||
min_sample = min(min_sample, min(min_s(D, DL, DR), min_s(U, UL, UR)));
|
||||
max_sample = max(max_sample, max(max_s(D, DL, DR), max_s(U, UL, UR)));
|
||||
|
||||
diff *= (1.0 - SGPT_BLEND_LEVEL);
|
||||
|
||||
color = 0.5*( 1.0 + diff )*C + 0.25*( 1.0 - diff )*(L + R);
|
||||
}
|
||||
|
||||
FragColor.xyz = color;
|
||||
color = clamp(color, min_sample, max_sample);
|
||||
|
||||
color = mix(color, vec3(dot(abs(C-color), vec3(1.0, 1.0, 1.0))), SGPT_ADJUST_VIEW);
|
||||
|
||||
FragColor.xyz = GAMMA_OUT(color);
|
||||
}
|
||||
#endif
|
||||
|
94
presets/crt-hyllian-curvature-ntsc.glslp
Normal file
94
presets/crt-hyllian-curvature-ntsc.glslp
Normal file
@ -0,0 +1,94 @@
|
||||
shaders = "7"
|
||||
shader0 = "../ntsc/shaders/ntsc-pass1-composite-3phase.glsl"
|
||||
filter_linear0 = "false"
|
||||
wrap_mode0 = "clamp_to_border"
|
||||
frame_count_mod0 = "2"
|
||||
mipmap_input0 = "false"
|
||||
alias0 = ""
|
||||
float_framebuffer0 = "true"
|
||||
srgb_framebuffer0 = "false"
|
||||
scale_type_x0 = "source"
|
||||
scale_x0 = "4.000000"
|
||||
scale_type_y0 = "source"
|
||||
scale_y0 = "1.000000"
|
||||
shader1 = "../ntsc/shaders/ntsc-pass2-3phase-linear.glsl"
|
||||
filter_linear1 = "false"
|
||||
wrap_mode1 = "clamp_to_border"
|
||||
mipmap_input1 = "false"
|
||||
alias1 = ""
|
||||
float_framebuffer1 = "false"
|
||||
srgb_framebuffer1 = "true"
|
||||
scale_type_x1 = "source"
|
||||
scale_x1 = "0.500000"
|
||||
scale_type_y1 = "source"
|
||||
scale_y1 = "1.000000"
|
||||
shader2 = "../crt/shaders/hyllian/crt-hyllian-curvature-glow.glsl"
|
||||
filter_linear2 = "false"
|
||||
wrap_mode2 = "clamp_to_border"
|
||||
mipmap_input2 = "false"
|
||||
alias2 = "CRTPass"
|
||||
float_framebuffer2 = "false"
|
||||
srgb_framebuffer2 = "true"
|
||||
scale_type_x2 = "viewport"
|
||||
scale_x2 = "1.000000"
|
||||
scale_type_y2 = "viewport"
|
||||
scale_y2 = "1.000000"
|
||||
shader3 = "../crt/shaders/glow/threshold.glsl"
|
||||
filter_linear3 = "false"
|
||||
wrap_mode3 = "clamp_to_border"
|
||||
mipmap_input3 = "false"
|
||||
alias3 = ""
|
||||
float_framebuffer3 = "false"
|
||||
srgb_framebuffer3 = "true"
|
||||
shader4 = "../crt/shaders/glow/blur_horiz.glsl"
|
||||
filter_linear4 = "true"
|
||||
wrap_mode4 = "clamp_to_border"
|
||||
mipmap_input4 = "true"
|
||||
alias4 = ""
|
||||
float_framebuffer4 = "false"
|
||||
srgb_framebuffer4 = "true"
|
||||
scale_type_x4 = "viewport"
|
||||
scale_x4 = "0.250000"
|
||||
scale_type_y4 = "viewport"
|
||||
scale_y4 = "0.500000"
|
||||
shader5 = "../crt/shaders/glow/blur_vert.glsl"
|
||||
filter_linear5 = "true"
|
||||
wrap_mode5 = "clamp_to_border"
|
||||
mipmap_input5 = "false"
|
||||
alias5 = ""
|
||||
float_framebuffer5 = "false"
|
||||
srgb_framebuffer5 = "true"
|
||||
scale_type_x5 = "viewport"
|
||||
scale_x5 = "1.000000"
|
||||
scale_type_y5 = "viewport"
|
||||
scale_y5 = "1.000000"
|
||||
shader6 = "../crt/shaders/glow/resolve.glsl"
|
||||
filter_linear6 = "true"
|
||||
wrap_mode6 = "clamp_to_border"
|
||||
mipmap_input6 = "false"
|
||||
alias6 = ""
|
||||
float_framebuffer6 = "false"
|
||||
srgb_framebuffer6 = "false"
|
||||
parameters = "BEAM_PROFILE;HFILTER_PROFILE;BEAM_MIN_WIDTH;BEAM_MAX_WIDTH;SCANLINES_STRENGTH;COLOR_BOOST;HFILTER_SHARPNESS;CRT_ANTI_RINGING;InputGamma;OutputGamma;VSCANLINES;CRT_CURVATURE;CRT_warpX;CRT_warpY;CRT_cornersize;CRT_cornersmooth;GLOW_WHITEPOINT;GLOW_ROLLOFF;BLOOM_STRENGTH;OUTPUT_GAMMA;PHOSPHOR_LAYOUT;MASK_INTENSITY"
|
||||
BEAM_PROFILE = "0.000000"
|
||||
HFILTER_PROFILE = "0.000000"
|
||||
BEAM_MIN_WIDTH = "0.860000"
|
||||
BEAM_MAX_WIDTH = "1.000000"
|
||||
SCANLINES_STRENGTH = "0.580000"
|
||||
COLOR_BOOST = "1.250000"
|
||||
HFILTER_SHARPNESS = "1.000000"
|
||||
CRT_ANTI_RINGING = "1.000000"
|
||||
InputGamma = "1.000000"
|
||||
OutputGamma = "1.000000"
|
||||
VSCANLINES = "0.000000"
|
||||
CRT_CURVATURE = "1.000000"
|
||||
CRT_warpX = "0.031000"
|
||||
CRT_warpY = "0.041000"
|
||||
CRT_cornersize = "0.010000"
|
||||
CRT_cornersmooth = "1000.000000"
|
||||
GLOW_WHITEPOINT = "0.500000"
|
||||
GLOW_ROLLOFF = "1.200000"
|
||||
BLOOM_STRENGTH = "0.150000"
|
||||
OUTPUT_GAMMA = "2.200000"
|
||||
PHOSPHOR_LAYOUT = "4.000000"
|
||||
MASK_INTENSITY = "0.500000"
|
62
presets/crt-hyllian-smartblur-sgenpt.glslp
Normal file
62
presets/crt-hyllian-smartblur-sgenpt.glslp
Normal file
@ -0,0 +1,62 @@
|
||||
shaders = "4"
|
||||
shader0 = "../dithering/shaders/sgenpt-mix.glsl"
|
||||
filter_linear0 = "false"
|
||||
wrap_mode0 = "clamp_to_border"
|
||||
mipmap_input0 = "false"
|
||||
alias0 = ""
|
||||
float_framebuffer0 = "false"
|
||||
srgb_framebuffer0 = "false"
|
||||
scale_type_x0 = "source"
|
||||
scale_x0 = "2.000000"
|
||||
scale_type_y0 = "source"
|
||||
scale_y0 = "2.000000"
|
||||
shader1 = "../blurs/smart-blur.glsl"
|
||||
filter_linear1 = "false"
|
||||
wrap_mode1 = "clamp_to_border"
|
||||
mipmap_input1 = "false"
|
||||
alias1 = ""
|
||||
float_framebuffer1 = "false"
|
||||
srgb_framebuffer1 = "false"
|
||||
scale_type_x1 = "source"
|
||||
scale_x1 = "1.000000"
|
||||
scale_type_y1 = "source"
|
||||
scale_y1 = "1.000000"
|
||||
shader2 = "../stock.glsl"
|
||||
filter_linear2 = "false"
|
||||
wrap_mode2 = "clamp_to_border"
|
||||
mipmap_input2 = "false"
|
||||
alias2 = ""
|
||||
float_framebuffer2 = "false"
|
||||
srgb_framebuffer2 = "false"
|
||||
scale_type_x2 = "source"
|
||||
scale_x2 = "0.500000"
|
||||
scale_type_y2 = "source"
|
||||
scale_y2 = "0.500000"
|
||||
shader3 = "../crt/shaders/hyllian/crt-hyllian.glsl"
|
||||
filter_linear3 = "false"
|
||||
wrap_mode3 = "clamp_to_border"
|
||||
mipmap_input3 = "false"
|
||||
alias3 = ""
|
||||
float_framebuffer3 = "false"
|
||||
srgb_framebuffer3 = "false"
|
||||
parameters = "SGPT_BLEND_OPTION;SGPT_BLEND_LEVEL;SGPT_ADJUST_VIEW;SGPT_LINEAR_GAMMA;SB_BLUR_LEVEL;SB_RED_THRESHOLD;SB_GREEN_THRESHOLD;SB_BLUE_THRESHOLD;BEAM_PROFILE;BEAM_MIN_WIDTH;BEAM_MAX_WIDTH;SCANLINES_STRENGTH;COLOR_BOOST;HFILTER_SHARPNESS;PHOSPHOR_LAYOUT;MASK_INTENSITY;CRT_ANTI_RINGING;InputGamma;OutputGamma;VSCANLINES"
|
||||
SGPT_BLEND_OPTION = "2.000000"
|
||||
SGPT_BLEND_LEVEL = "0.200000"
|
||||
SGPT_ADJUST_VIEW = "0.000000"
|
||||
SGPT_LINEAR_GAMMA = "1.000000"
|
||||
SB_BLUR_LEVEL = "0.660000"
|
||||
SB_RED_THRESHOLD = "0.200000"
|
||||
SB_GREEN_THRESHOLD = "0.200000"
|
||||
SB_BLUE_THRESHOLD = "0.200000"
|
||||
BEAM_PROFILE = "0.000000"
|
||||
BEAM_MIN_WIDTH = "0.860000"
|
||||
BEAM_MAX_WIDTH = "1.000000"
|
||||
SCANLINES_STRENGTH = "0.580000"
|
||||
COLOR_BOOST = "1.250000"
|
||||
HFILTER_SHARPNESS = "1.000000"
|
||||
PHOSPHOR_LAYOUT = "4.000000"
|
||||
MASK_INTENSITY = "0.500000"
|
||||
CRT_ANTI_RINGING = "1.000000"
|
||||
InputGamma = "2.400000"
|
||||
OutputGamma = "2.200000"
|
||||
VSCANLINES = "0.000000"
|
Loading…
Reference in New Issue
Block a user