mirror of
https://github.com/italicsjenga/slang-shaders.git
synced 2024-11-23 00:01:31 +11:00
update crt-guest-sm to latest
This commit is contained in:
parent
a24fd351db
commit
fbc0e7a9fa
|
@ -1,8 +1,46 @@
|
|||
shaders = 2
|
||||
# This shader supports Vertical games.
|
||||
# Auto rotation must be turned OFF in Core Options.
|
||||
# Per-game presets can be saved, so it should work out OK.
|
||||
|
||||
shader0 = shaders/guest/d65-d50.slang
|
||||
filter_linear0 = false
|
||||
shaders = 6
|
||||
|
||||
shader0 = shaders/guest/crt-sm/d65-d50-sm.slang
|
||||
filter_linear0 = true
|
||||
scale_type0 = source
|
||||
scale0 = 1.0
|
||||
alias0 = WpPass
|
||||
|
||||
shader1 = shaders/guest/crt-guest-sm.slang
|
||||
shader1 = shaders/guest/crt-sm/crt-guest-sm-rot0.slang
|
||||
float_framebuffer1 = true
|
||||
filter_linear1 = true
|
||||
scale_type_x1 = source
|
||||
scale_type_y1 = source
|
||||
scale_x1 = 1.0
|
||||
scale_y1 = 3.0
|
||||
alias1 = RotPass
|
||||
|
||||
shader2 = shaders/guest/crt-sm/linearize-sm.slang
|
||||
float_framebuffer2 = true
|
||||
filter_linear2 = true
|
||||
scale_type2 = source
|
||||
scale2 = 1.0
|
||||
alias2 = LinPass
|
||||
|
||||
shader3 = shaders/guest/crt-sm/blur_horiz-sm.slang
|
||||
float_framebuffer3 = true
|
||||
filter_linear3 = true
|
||||
scale_type3 = source
|
||||
scale3 = 1.0
|
||||
|
||||
shader4 = shaders/guest/crt-sm/blur_vert-sm.slang
|
||||
float_framebuffer4 = true
|
||||
filter_linear4 = true
|
||||
scale_type4 = source
|
||||
scale4 = 1.0
|
||||
|
||||
shader5 = shaders/guest/crt-sm/crt-guest-sm.slang
|
||||
filter_linear5 = true
|
||||
scale_type_x5 = viewport
|
||||
scale_type_y5 = viewport
|
||||
scale_x5 = 1.0
|
||||
scale_y5 = 1.0
|
||||
|
|
|
@ -1,321 +0,0 @@
|
|||
#version 450
|
||||
|
||||
/*
|
||||
CRT - Guest - SM (Scanline Mask) Shader
|
||||
|
||||
Copyright (C) 2019 guest(r) - guest.r@gmail.com
|
||||
|
||||
Big thanks to Nesguy from the Libretro forums for the masks and other ideas.
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation; either version 2
|
||||
of the License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
*/
|
||||
|
||||
/* README - MASKS GUIDE
|
||||
|
||||
To obtain the best results with masks 0, 1, 3, 4:
|
||||
must leave “mask size” at 1 and the display must be set to its native resolution to result in evenly spaced “active” LCD subpixels.
|
||||
|
||||
Mask 0: Uses a magenta and green pattern for even spacing of the LCD subpixels.
|
||||
|
||||
Mask 1: Intended for displays that have RBG subpixels (as opposed to the more common RGB).
|
||||
Uses a yellow/blue pattern for even spacing of the LCD subpixels.
|
||||
|
||||
Mask 2: Common red/green/blue pattern.
|
||||
|
||||
Mask 3: This is useful for 4K displays, where masks 0 and 1 can look too fine.
|
||||
Uses a red/yellow/cyan/blue pattern to result in even spacing of the LCD subpixels.
|
||||
|
||||
Mask 4: Intended for displays that have the less common RBG subpixel pattern.
|
||||
This is useful for 4K displays, where masks 0 and 1 can look too fine.
|
||||
Uses a red/magenta/cyan/green pattern for even spacing of the LCD subpixels.
|
||||
|
||||
*/
|
||||
|
||||
layout(push_constant) uniform Push
|
||||
{
|
||||
vec4 SourceSize;
|
||||
vec4 OriginalSize;
|
||||
vec4 OutputSize;
|
||||
uint FrameCount;
|
||||
float smart, brightboost1, brightboost2, stype, scanline1, scanline2, beam_min, beam_max, s_beam, saturation1, h_sharp, mask, maskmode, maskdark, maskbright, masksize, gamma_out;
|
||||
} params;
|
||||
|
||||
// smart Y integer scaline
|
||||
#pragma parameter smart "Smart Y Integer Scaling" 0.0 0.0 1.0 1.0
|
||||
// adjust brightness dark colors
|
||||
#pragma parameter brightboost1 "Bright boost dark colors" 1.50 0.5 3.0 0.05
|
||||
// adjust brightness bright colors
|
||||
#pragma parameter brightboost2 "Bright boost bright colors" 1.10 0.5 2.0 0.05
|
||||
// scanline type
|
||||
#pragma parameter stype "Scanline Type" 0.0 0.0 2.0 1.0
|
||||
// scanline param, vertical sharpness
|
||||
#pragma parameter scanline1 "Scanline Shape Center" 8.0 2.0 14.0 0.5
|
||||
// scanline param, vertical sharpness
|
||||
#pragma parameter scanline2 "Scanline Shape Edges" 8.0 4.0 16.0 0.5
|
||||
// dark area beam min - narrow
|
||||
#pragma parameter beam_min "Scanline dark" 1.40 0.5 2.0 0.05
|
||||
// bright area beam max -wide
|
||||
#pragma parameter beam_max "Scanline bright" 1.10 0.5 2.0 0.05
|
||||
// Overgrown Bright Beam
|
||||
#pragma parameter s_beam "Overgrown Bright Beam" 0.75 0.0 1.0 0.05
|
||||
// Scanline Saturation
|
||||
#pragma parameter saturation1 "Scanline Saturation" 2.75 0.0 6.0 0.25
|
||||
// pixel sharpness
|
||||
#pragma parameter h_sharp "Horizontal sharpness" 2.0 1.0 5.0 0.05
|
||||
// crt mask
|
||||
#pragma parameter mask "CRT Mask (3&4 are 4k masks)" 0.0 0.0 4.0 1.0
|
||||
// CRT Mask Mode: Classic, Fine, Coarse
|
||||
#pragma parameter maskmode "CRT Mask Mode: Classic, Fine, Coarse" 0.0 0.0 2.0 1.0
|
||||
// CRT Mask Strength Dark Pixels
|
||||
#pragma parameter maskdark "CRT Mask Strength Dark Pixels" 1.0 0.0 1.5 0.05
|
||||
// CRT Mask Strength Bright Pixels
|
||||
#pragma parameter maskbright "CRT Mask Strength Bright Pixels" 0.20 -0.5 1.0 0.05
|
||||
// crt mask size
|
||||
#pragma parameter masksize "CRT Mask Size" 1.0 1.0 2.0 1.0
|
||||
// gamma out
|
||||
#pragma parameter gamma_out "Gamma Out" 2.40 1.0 3.0 0.05
|
||||
|
||||
#define smart params.smart
|
||||
#define brightboost1 params.brightboost1
|
||||
#define brightboost2 params.brightboost2
|
||||
#define stype params.stype
|
||||
#define scanline1 params.scanline1
|
||||
#define scanline2 params.scanline2
|
||||
#define beam_min params.beam_min
|
||||
#define beam_max params.beam_max
|
||||
#define s_beam params.s_beam
|
||||
#define saturation1 params.saturation1
|
||||
#define h_sharp params.h_sharp
|
||||
#define mask params.mask
|
||||
#define maskmode params.maskmode
|
||||
#define maskdark params.maskdark
|
||||
#define maskbright params.maskbright
|
||||
#define masksize params.masksize
|
||||
#define gamma_out params.gamma_out
|
||||
|
||||
#define TEX0 vTexCoord
|
||||
#define COMPAT_TEXTURE(c,d) texture(c,d)
|
||||
#define Texture Source
|
||||
#define InputSize SourceSize
|
||||
|
||||
layout(std140, set = 0, binding = 0) uniform UBO
|
||||
{
|
||||
mat4 MVP;
|
||||
} global;
|
||||
|
||||
#pragma stage vertex
|
||||
layout(location = 0) in vec4 Position;
|
||||
layout(location = 1) in vec2 TexCoord;
|
||||
layout(location = 0) out vec2 vTexCoord;
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = global.MVP * Position;
|
||||
vTexCoord = TexCoord;
|
||||
}
|
||||
|
||||
#pragma stage fragment
|
||||
layout(location = 0) in vec2 vTexCoord;
|
||||
layout(location = 0) out vec4 FragColor;
|
||||
layout(set = 0, binding = 2) uniform sampler2D Source;
|
||||
|
||||
float st(float x)
|
||||
{
|
||||
return exp2(-10.0*x*x);
|
||||
}
|
||||
|
||||
float st1(float x, float scan)
|
||||
{
|
||||
return exp2(-scan*x*x);
|
||||
}
|
||||
|
||||
float sw1(float x, vec3 color, float scan)
|
||||
{
|
||||
float mx = max(max(color.r,color.g),color.b);
|
||||
float ex = mix((2.75 - 1.75*stype)*beam_min, beam_max, mx);
|
||||
ex = mix(beam_max, ex, pow(x, mx + 0.25))*x;
|
||||
return exp2(-scan*ex*ex);
|
||||
}
|
||||
|
||||
float sw2(float x, vec3 color)
|
||||
{
|
||||
float mx = max(max(color.r,color.g),color.b);
|
||||
float ex = mix(2.0*beam_min, beam_max, mx);
|
||||
float m = 0.5*ex;
|
||||
x = x*ex; float xx = x*x;
|
||||
xx = mix(xx, x*xx, m);
|
||||
return exp2(-10.0*xx);
|
||||
}
|
||||
|
||||
float Overscan(float pos, float dy){
|
||||
pos=pos*2.0-1.0;
|
||||
pos*=dy;
|
||||
return pos*0.5+0.5;
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
vec2 tex = TEX0.xy * 1.000001;
|
||||
|
||||
if (smart == 1.0)
|
||||
{
|
||||
float factor = params.OutputSize.y/params.InputSize.y;
|
||||
float intfactor = round(factor);
|
||||
float diff = factor/intfactor;
|
||||
tex.y = Overscan(tex.y*(params.SourceSize.y/params.InputSize.y), diff)*(params.InputSize.y/params.SourceSize.y);
|
||||
}
|
||||
|
||||
vec2 OGL2Pos = tex * params.SourceSize.xy - vec2(0.5);
|
||||
vec2 fp = fract(OGL2Pos);
|
||||
|
||||
vec2 pC4 = (floor(OGL2Pos) + vec2(0.5)) * params.SourceSize.zw;
|
||||
|
||||
// Reading the texels
|
||||
vec3 ul = COMPAT_TEXTURE(Texture, pC4 ).xyz; ul*=ul;
|
||||
vec3 ur = COMPAT_TEXTURE(Texture, pC4 + vec2(params.SourceSize.z,0.0)).xyz; ur*=ur;
|
||||
vec3 dl = COMPAT_TEXTURE(Texture, pC4 + vec2(0.0,params.SourceSize.w)).xyz; dl*=dl;
|
||||
vec3 dr = COMPAT_TEXTURE(Texture, pC4 + params.SourceSize.zw ).xyz; dr*=dr;
|
||||
|
||||
float lx = fp.x; lx = pow(lx, h_sharp);
|
||||
float rx = 1.0 - fp.x; rx = pow(rx, h_sharp);
|
||||
|
||||
float w = 1.0/(lx+rx);
|
||||
float f1 = fp.y;
|
||||
float f2 = 1.0 - fp.y;
|
||||
float f3 = fract(tex.y * params.SourceSize.y); f3 = abs(f3-0.5);
|
||||
|
||||
vec3 color;
|
||||
float t1 = st(f1);
|
||||
float t2 = st(f2);
|
||||
float wt = 1.0/(t1+t2);
|
||||
|
||||
// calculating scanlines
|
||||
|
||||
vec3 cl = (ul*t1 + dl*t2)*wt;
|
||||
vec3 cr = (ur*t1 + dr*t2)*wt;
|
||||
|
||||
vec3 ref_ul = mix(cl, ul, s_beam);
|
||||
vec3 ref_ur = mix(cr, ur, s_beam);
|
||||
vec3 ref_dl = mix(cl, dl, s_beam);
|
||||
vec3 ref_dr = mix(cr, dr, s_beam);
|
||||
|
||||
float scan1 = mix(scanline1, scanline2, f1);
|
||||
float scan2 = mix(scanline1, scanline2, f2);
|
||||
float scan0 = mix(scanline1, scanline2, f3);
|
||||
f3 = st1(f3,scan0);
|
||||
f3 = f3*f3*(3.0-2.0*f3);
|
||||
|
||||
float w1, w2, w3, w4 = 0.0;
|
||||
|
||||
if (stype < 2.0)
|
||||
{
|
||||
w1 = sw1(f1, ref_ul, scan1);
|
||||
w2 = sw1(f2, ref_dl, scan2);
|
||||
w3 = sw1(f1, ref_ur, scan1);
|
||||
w4 = sw1(f2, ref_dr, scan2);
|
||||
}
|
||||
else
|
||||
{
|
||||
w1 = sw2(f1, ref_ul);
|
||||
w2 = sw2(f2, ref_dl);
|
||||
w3 = sw2(f1, ref_ur);
|
||||
w4 = sw2(f2, ref_dr);
|
||||
}
|
||||
|
||||
vec3 colorl = w1*ul + w2*dl;
|
||||
vec3 colorr = w3*ur + w4*dr;
|
||||
color = w*(colorr*lx + colorl*rx);
|
||||
color = min(color,1.0);
|
||||
|
||||
vec3 ctemp = w*(cr*lx + cl*rx);
|
||||
|
||||
cl*=cl*cl; cl*=cl; cr*=cr*cr; cr*=cr;
|
||||
|
||||
vec3 sctemp = w*(cr*lx + cl*rx); sctemp = pow(sctemp, vec3(1.0/6.0));
|
||||
|
||||
float mx1 = max(max(color.r,color.g),color.b);
|
||||
float sp = (stype == 1.0) ? (0.5*saturation1) : saturation1;
|
||||
vec3 saturated_color = max((1.0+sp)*color - 0.5*sp*(color+mx1), 0.0);
|
||||
color = mix(saturated_color, color, f3);
|
||||
|
||||
vec3 scan3 = vec3(0.0);
|
||||
float spos = floor((gl_FragCoord.x * 1.000001)/masksize); float spos1 = 0.0;
|
||||
|
||||
vec3 tmp1 = 0.5*(sqrt(ctemp) + sctemp);
|
||||
|
||||
color*=mix(brightboost1, brightboost2, max(max(ctemp.r,ctemp.g),ctemp.b));
|
||||
color = min(color,1.0);
|
||||
|
||||
float mboost = 1.25;
|
||||
|
||||
if (mask == 0.0)
|
||||
{
|
||||
spos1 = fract(spos*0.5);
|
||||
if (spos1 < 0.5) scan3.rb = color.rb;
|
||||
else scan3.g = color.g;
|
||||
}
|
||||
else
|
||||
if (mask == 1.0)
|
||||
{
|
||||
spos1 = fract(spos*0.5);
|
||||
if (spos1 < 0.5) scan3.rg = color.rg;
|
||||
else scan3.b = color.b;
|
||||
}
|
||||
else
|
||||
if (mask == 2.0)
|
||||
{
|
||||
mboost = 1.0;
|
||||
spos1 = fract(spos/3.0);
|
||||
if (spos1 < 0.333) scan3.r = color.r;
|
||||
else if (spos1 < 0.666) scan3.g = color.g;
|
||||
else scan3.b = color.b;
|
||||
}
|
||||
else
|
||||
if (mask == 3.0)
|
||||
{
|
||||
spos1 = fract(spos*0.25);
|
||||
if (spos1 < 0.25) scan3.r = color.r;
|
||||
else if (spos1 < 0.50) scan3.rg = color.rg;
|
||||
else if (spos1 < 0.75) scan3.gb = color.gb;
|
||||
else scan3.b = color.b;
|
||||
}
|
||||
else
|
||||
{
|
||||
spos1 = fract(spos*0.25);
|
||||
if (spos1 < 0.25) scan3.r = color.r;
|
||||
else if (spos1 < 0.50) scan3.rb = color.rb;
|
||||
else if (spos1 < 0.75) scan3.gb = color.gb;
|
||||
else scan3.g = color.g;
|
||||
}
|
||||
|
||||
vec3 lerpmask = tmp1;
|
||||
if (maskmode == 1.0) lerpmask = vec3(max(max(tmp1.r,tmp1.g),tmp1.b)); else
|
||||
if (maskmode == 2.0) lerpmask = color;
|
||||
|
||||
color = max(mix( mix(color, mboost*scan3, maskdark), mix(color, scan3, maskbright), lerpmask), 0.0);
|
||||
|
||||
vec3 color1 = pow(color, vec3(1.0/2.1));
|
||||
|
||||
if (stype != 1.0)
|
||||
{
|
||||
vec3 color2 = pow(color, vec3(1.0/gamma_out));
|
||||
mx1 = max(max(color1.r,color1.g),color1.b) + 1e-12;
|
||||
float mx2 = max(max(color2.r,color2.g),color2.b);
|
||||
color1*=mx2/mx1;
|
||||
}
|
||||
|
||||
FragColor = vec4(color1, 1.0);
|
||||
}
|
66
crt/shaders/guest/crt-sm/blur_horiz-sm.slang
Normal file
66
crt/shaders/guest/crt-sm/blur_horiz-sm.slang
Normal file
|
@ -0,0 +1,66 @@
|
|||
#version 450
|
||||
|
||||
layout(push_constant) uniform Push
|
||||
{
|
||||
vec4 SourceSize;
|
||||
vec4 OriginalSize;
|
||||
vec4 OutputSize;
|
||||
uint FrameCount;
|
||||
float TAPSH;
|
||||
float GLOW_FALLOFF_H;
|
||||
} params;
|
||||
|
||||
// Higher value, more centered glow.
|
||||
// Lower values might need more taps.
|
||||
// Adapted from crt-easymode-halation by Easymode.
|
||||
|
||||
#pragma parameter TAPSH "H. Glow Radius" 5.0 1.0 10.0 1.0
|
||||
#define TAPSH params.TAPSH
|
||||
#pragma parameter GLOW_FALLOFF_H "Horizontal Glow Grade" 0.25 0.00 1.5 0.02
|
||||
#define GLOW_FALLOFF_H params.GLOW_FALLOFF_H
|
||||
|
||||
layout(std140, set = 0, binding = 0) uniform UBO
|
||||
{
|
||||
mat4 MVP;
|
||||
} global;
|
||||
|
||||
#pragma stage vertex
|
||||
layout(location = 0) in vec4 Position;
|
||||
layout(location = 1) in vec2 TexCoord;
|
||||
layout(location = 0) out vec2 vTexCoord;
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = global.MVP * Position;
|
||||
vTexCoord = TexCoord * 1.00001;
|
||||
}
|
||||
|
||||
#pragma stage fragment
|
||||
layout(location = 0) in vec2 vTexCoord;
|
||||
layout(location = 0) out vec4 FragColor;
|
||||
layout(set = 0, binding = 2) uniform sampler2D Source;
|
||||
layout(set = 0, binding = 3) uniform sampler2D RotPass;
|
||||
|
||||
#define COMPAT_TEXTURE(c,d) texture(c,d)
|
||||
#define SourceSize params.SourceSize
|
||||
|
||||
#define kernel(x) exp(-GLOW_FALLOFF_H * (x) * (x))
|
||||
|
||||
void main()
|
||||
{
|
||||
float ratio = COMPAT_TEXTURE(RotPass, vec2(0.5,0.1)).a;
|
||||
if (vTexCoord.y > ratio) discard;
|
||||
|
||||
vec3 col = vec3(0.0); vec3 tmp;
|
||||
float dx = SourceSize.z;
|
||||
|
||||
float k_total = 0.;
|
||||
for (float i = -TAPSH; i <= TAPSH; i++)
|
||||
{
|
||||
float k = kernel(i);
|
||||
k_total += k;
|
||||
tmp = COMPAT_TEXTURE(Source, vTexCoord + vec2(float(i) * dx, 0.0)).rgb;
|
||||
col += k * tmp;
|
||||
}
|
||||
FragColor = vec4(col / k_total, ratio);
|
||||
}
|
66
crt/shaders/guest/crt-sm/blur_vert-sm.slang
Normal file
66
crt/shaders/guest/crt-sm/blur_vert-sm.slang
Normal file
|
@ -0,0 +1,66 @@
|
|||
#version 450
|
||||
|
||||
layout(push_constant) uniform Push
|
||||
{
|
||||
vec4 SourceSize;
|
||||
vec4 OriginalSize;
|
||||
vec4 OutputSize;
|
||||
uint FrameCount;
|
||||
float TAPSV;
|
||||
float GLOW_FALLOFF_V;
|
||||
} params;
|
||||
|
||||
// Higher value, more centered glow.
|
||||
// Lower values might need more taps.
|
||||
// Adapted from crt-easymode-halation by Easymode.
|
||||
|
||||
// Parameter lines go here:
|
||||
#pragma parameter TAPSV "V. Glow Radius" 5.0 1.0 10.0 1.0
|
||||
#define TAPSV params.TAPSV
|
||||
#pragma parameter GLOW_FALLOFF_V "Vertical Glow Grade" 0.25 0.00 1.5 0.02
|
||||
#define GLOW_FALLOFF_V params.GLOW_FALLOFF_V
|
||||
|
||||
layout(std140, set = 0, binding = 0) uniform UBO
|
||||
{
|
||||
mat4 MVP;
|
||||
} global;
|
||||
|
||||
#pragma stage vertex
|
||||
layout(location = 0) in vec4 Position;
|
||||
layout(location = 1) in vec2 TexCoord;
|
||||
layout(location = 0) out vec2 vTexCoord;
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = global.MVP * Position;
|
||||
vTexCoord = TexCoord * 1.00001;
|
||||
}
|
||||
|
||||
#pragma stage fragment
|
||||
layout(location = 0) in vec2 vTexCoord;
|
||||
layout(location = 0) out vec4 FragColor;
|
||||
layout(set = 0, binding = 2) uniform sampler2D Source;
|
||||
layout(set = 0, binding = 3) uniform sampler2D RotPass;
|
||||
|
||||
#define COMPAT_TEXTURE(c,d) texture(c,d)
|
||||
#define SourceSize params.SourceSize
|
||||
|
||||
#define kernel(x) exp(-GLOW_FALLOFF_V * (x) * (x))
|
||||
|
||||
void main()
|
||||
{
|
||||
float ratio = COMPAT_TEXTURE(RotPass, vec2(0.5,0.1)).a;
|
||||
if (vTexCoord.y > ratio) discard;
|
||||
|
||||
vec3 col = vec3(0.0);
|
||||
float dy = SourceSize.w;
|
||||
|
||||
float k_total = 0.;
|
||||
for (float i = -TAPSV; i <= TAPSV; i++)
|
||||
{
|
||||
float k = kernel(i);
|
||||
k_total += k;
|
||||
col += k * COMPAT_TEXTURE(Source, vTexCoord + vec2(0.0, float(i) * dy)).rgb;
|
||||
}
|
||||
FragColor = vec4(col / k_total, ratio);
|
||||
}
|
59
crt/shaders/guest/crt-sm/crt-guest-sm-rot0.slang
Normal file
59
crt/shaders/guest/crt-sm/crt-guest-sm-rot0.slang
Normal file
|
@ -0,0 +1,59 @@
|
|||
#version 450
|
||||
|
||||
layout(push_constant) uniform Push
|
||||
{
|
||||
vec4 SourceSize;
|
||||
vec4 OriginalSize;
|
||||
vec4 OutputSize;
|
||||
uint FrameCount;
|
||||
} params;
|
||||
|
||||
|
||||
#define COMPAT_TEXTURE(c,d) texture(c,d)
|
||||
#define TEX0 vTexCoord
|
||||
|
||||
layout(std140, set = 0, binding = 0) uniform UBO
|
||||
{
|
||||
mat4 MVP;
|
||||
} global;
|
||||
|
||||
#pragma stage vertex
|
||||
layout(location = 0) in vec4 Position;
|
||||
layout(location = 1) in vec2 TexCoord;
|
||||
layout(location = 0) out vec2 vTexCoord;
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = global.MVP * Position;
|
||||
vTexCoord = TexCoord * 1.00001;
|
||||
}
|
||||
|
||||
#pragma stage fragment
|
||||
layout(location = 0) in vec2 vTexCoord;
|
||||
layout(location = 0) out vec4 FragColor;
|
||||
layout(set = 0, binding = 2) uniform sampler2D Source;
|
||||
|
||||
float Overscan(float pos, float dy){
|
||||
pos=pos*2.0-1.0;
|
||||
pos*=dy;
|
||||
return pos*0.5+0.5;
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
float sm_tate = COMPAT_TEXTURE(Source, vec2(0.5)).a;
|
||||
float ratio = 1.0;
|
||||
vec2 tex = TEX0.xy; vec3 color = vec3(0.0);
|
||||
|
||||
if (sm_tate < 0.5) { ratio = 1.0/3.0; tex.y = tex.y / ratio; color = COMPAT_TEXTURE(Source, tex).rgb; }
|
||||
else
|
||||
{
|
||||
ratio = (1.0/3.0) * params.SourceSize.x / params.SourceSize.y;
|
||||
tex = tex.yx;
|
||||
tex.x = tex.x / ratio;
|
||||
tex.y = Overscan(tex.y, params.SourceSize.x / params.SourceSize.y);
|
||||
color = COMPAT_TEXTURE(Source, tex).rgb;
|
||||
}
|
||||
|
||||
FragColor = vec4(color,ratio);
|
||||
}
|
463
crt/shaders/guest/crt-sm/crt-guest-sm.slang
Normal file
463
crt/shaders/guest/crt-sm/crt-guest-sm.slang
Normal file
|
@ -0,0 +1,463 @@
|
|||
#version 450
|
||||
|
||||
/*
|
||||
CRT - Guest - SM (Scanline Mask) Shader
|
||||
|
||||
Copyright (C) 2019-2020 guest(r) - guest.r@gmail.com
|
||||
|
||||
Big thanks to Nesguy from the Libretro forums for the masks and other ideas.
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation; either version 2
|
||||
of the License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
*/
|
||||
|
||||
/* README - MASKS GUIDE
|
||||
|
||||
To obtain the best results with masks 0, 1, 3, 4:
|
||||
must leave “mask size” at 1 and the display must be set to its native resolution to result in evenly spaced “active” LCD subpixels.
|
||||
|
||||
Mask 0: Uses a magenta and green pattern for even spacing of the LCD subpixels.
|
||||
|
||||
Mask 1: Similar to Mask 0, but with "ZigZag"
|
||||
|
||||
Mask 2: Intended for displays that have RBG subpixels (as opposed to the more common RGB).
|
||||
Uses a yellow/blue pattern for even spacing of the LCD subpixels.
|
||||
|
||||
Mask 3: Common red/green/blue pattern.
|
||||
|
||||
Mask 4: This is useful for 4K displays, where masks 0 and 1 can look too fine.
|
||||
Uses a red/yellow/cyan/blue pattern to result in even spacing of the LCD subpixels.
|
||||
|
||||
Mask 5: Intended for displays that have the less common RBG subpixel pattern.
|
||||
This is useful for 4K displays, where masks 0 and 1 can look too fine.
|
||||
Uses a red/magenta/cyan/green pattern for even spacing of the LCD subpixels.
|
||||
|
||||
*/
|
||||
|
||||
layout(push_constant) uniform Push
|
||||
{
|
||||
vec4 SourceSize;
|
||||
// vec4 OriginalSize;
|
||||
vec4 OutputSize;
|
||||
|
||||
uint FrameCount;
|
||||
float smart, brightboost1, brightboost2, stype, scanline1, scanline2, beam_min, beam_max, s_beam;
|
||||
float h_sharp, cubic, mask, maskmode, maskdark, maskbright, masksize, gamma_out;
|
||||
} params;
|
||||
|
||||
layout(std140, set = 0, binding = 0) uniform UBO
|
||||
{
|
||||
mat4 MVP;
|
||||
vec4 FinalViewportSize;
|
||||
float bglow;
|
||||
float warpx;
|
||||
float warpy;
|
||||
float bloom;
|
||||
float autobrm;
|
||||
float sclip;
|
||||
} global;
|
||||
|
||||
#pragma parameter bglow "Base Glow" 0.0 0.0 1.0 0.01
|
||||
#pragma parameter bloom "Bloom" 0.40 0.0 2.0 0.05
|
||||
#pragma parameter autobrm "Automatic Brightness (Mask)" 0.5 0.0 1.0 0.1
|
||||
#pragma parameter smart "1:Smart 2:Crop 3:Overscan Y Integer Scaling" 0.0 0.0 3.0 1.0
|
||||
#pragma parameter brightboost1 "Bright boost dark colors" 1.40 0.5 5.0 0.10
|
||||
#pragma parameter brightboost2 "Bright boost bright colors" 1.15 0.5 3.0 0.05
|
||||
#pragma parameter stype "Scanline Type" 1.0 0.0 3.0 1.0
|
||||
#pragma parameter scanline1 "Scanline Shape Center" 5.0 2.0 20.0 0.5
|
||||
#pragma parameter scanline2 "Scanline Shape Edges" 7.0 4.0 20.0 0.5
|
||||
#pragma parameter beam_min "Scanline dark" 1.25 0.5 3.0 0.05
|
||||
#pragma parameter beam_max "Scanline bright" 1.10 0.5 3.0 0.05
|
||||
#pragma parameter sclip "Allow Scanline/Mask Clipping With Bloom" 0.50 0.0 1.0 0.05
|
||||
#pragma parameter s_beam "Overgrown Bright Beam" 0.70 0.0 1.0 0.05
|
||||
#pragma parameter h_sharp "Horizontal sharpness" 3.0 1.0 10.0 0.10
|
||||
#pragma parameter cubic "Cubic Filtering" 1.0 0.0 1.0 0.10
|
||||
#pragma parameter mask "CRT Mask (4&5 are 4k masks)" 0.0 0.0 5.0 1.0
|
||||
#pragma parameter maskmode "CRT Mask Mode: Classic, Fine, Coarse" 0.0 0.0 2.0 1.0
|
||||
#pragma parameter maskdark "CRT Mask Strength Dark Pixels" 1.0 0.0 1.5 0.05
|
||||
#pragma parameter maskbright "CRT Mask Strength Bright Pixels" 0.25 -0.5 1.0 0.05
|
||||
#pragma parameter masksize "CRT Mask Size" 1.0 1.0 2.0 1.0
|
||||
#pragma parameter warpx "Curvature X" 0.0 0.0 0.25 0.01
|
||||
#pragma parameter warpy "Curvature Y" 0.0 0.0 0.25 0.01
|
||||
#pragma parameter gamma_out "Gamma Out" 2.50 1.0 3.5 0.05
|
||||
|
||||
#define bglow global.bglow
|
||||
#define autobrm global.autobrm
|
||||
#define smart params.smart
|
||||
#define brightboost1 params.brightboost1
|
||||
#define brightboost2 params.brightboost2
|
||||
#define bloom global.bloom
|
||||
#define stype params.stype
|
||||
#define scanline1 params.scanline1
|
||||
#define scanline2 params.scanline2
|
||||
#define beam_min params.beam_min
|
||||
#define beam_max params.beam_max
|
||||
#define sclip global.sclip
|
||||
#define s_beam params.s_beam
|
||||
#define h_sharp params.h_sharp
|
||||
#define cubic params.cubic
|
||||
#define mask params.mask
|
||||
#define maskmode params.maskmode
|
||||
#define maskdark params.maskdark
|
||||
#define maskbright params.maskbright
|
||||
#define masksize params.masksize
|
||||
#define warpx global.warpx
|
||||
#define warpy global.warpy
|
||||
#define gamma_out params.gamma_out
|
||||
|
||||
|
||||
#define TEX0 vTexCoord
|
||||
#define COMPAT_TEXTURE(c,d) texture(c,d)
|
||||
#define Texture Source
|
||||
#define InputSize SourceSize
|
||||
#define gl_FragCoord (vTexCoord * params.OutputSize.xy)
|
||||
|
||||
#pragma stage vertex
|
||||
layout(location = 0) in vec4 Position;
|
||||
layout(location = 1) in vec2 TexCoord;
|
||||
layout(location = 0) out vec2 vTexCoord;
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = global.MVP * Position;
|
||||
vTexCoord = TexCoord;
|
||||
}
|
||||
|
||||
#pragma stage fragment
|
||||
layout(location = 0) in vec2 vTexCoord;
|
||||
layout(location = 0) out vec4 FragColor;
|
||||
layout(set = 0, binding = 2) uniform sampler2D Source;
|
||||
layout(set = 0, binding = 3) uniform sampler2D WpPass;
|
||||
layout(set = 0, binding = 4) uniform sampler2D RotPass;
|
||||
layout(set = 0, binding = 5) uniform sampler2D LinPass;
|
||||
|
||||
float st(float x)
|
||||
{
|
||||
return exp2(-10.0*x*x);
|
||||
}
|
||||
|
||||
|
||||
|
||||
vec3 sw0(float x, vec3 color, float scan)
|
||||
{
|
||||
vec3 tmp = mix(vec3(beam_min),vec3(beam_max), color);
|
||||
vec3 ex = x*tmp;
|
||||
return exp2(-scan*ex*ex);
|
||||
}
|
||||
|
||||
|
||||
vec3 sw1(float x, vec3 color, float scan)
|
||||
{
|
||||
float mx1 = max(max(color.r,color.g),color.b);
|
||||
vec3 tmp = mix(vec3(2.50*beam_min),vec3(beam_max), color);
|
||||
tmp = mix(vec3(beam_max), tmp, pow(vec3(x), color + 0.30));
|
||||
vec3 ex = vec3(x)*tmp;
|
||||
vec3 res = exp2(-scan*ex*ex);
|
||||
float mx2 = max(max(res.r,res.g),res.b);
|
||||
float br = clamp(mix(0.30, 0.55, 2.0*(beam_min-1.0)),0.10, 0.65);
|
||||
return mix(vec3(mx2), res, 0.50)/(1.0 - br + br*mx1);
|
||||
}
|
||||
|
||||
|
||||
vec3 sw2(float x, vec3 color, float scan)
|
||||
{
|
||||
float mx1 = max(max(color.r,color.g),color.b);
|
||||
vec3 ex = mix(vec3(2.0*beam_min), vec3(beam_max), color);
|
||||
vec3 m = min(0.3 + 0.35*ex, 1.0);
|
||||
ex = x*ex;
|
||||
vec3 xx = ex*ex;
|
||||
xx = mix(xx, ex*xx, m);
|
||||
vec3 res = exp2(-1.25*scan*xx);
|
||||
float mx2 = max(max(res.r,res.g),res.b);
|
||||
float br = clamp(mix(0.20, 0.55, 2.0*(beam_min-1.0)),0.10, 0.65);
|
||||
return mix(vec3(mx2), res, 0.50)/(1.0 - br + br*mx1);
|
||||
}
|
||||
|
||||
|
||||
float Overscan(float pos, float dy){
|
||||
pos=pos*2.0-1.0;
|
||||
pos*=dy;
|
||||
return pos*0.5+0.5;
|
||||
}
|
||||
|
||||
|
||||
// Distortion of scanlines, and end of screen alpha (PD CRT Lottes Curvature)
|
||||
vec2 Warp(vec2 pos)
|
||||
{
|
||||
pos = pos*2.0-1.0;
|
||||
pos *= vec2(1.0 + (pos.y*pos.y)*warpx, 1.0 + (pos.x*pos.x)*warpy);
|
||||
return pos*0.5 + 0.5;
|
||||
}
|
||||
|
||||
vec3 declip(vec3 c, float b)
|
||||
{
|
||||
float m = max(max(c.r,c.g),c.b);
|
||||
if (m > b) c = c*b/m;
|
||||
return c;
|
||||
}
|
||||
|
||||
vec3 gc (vec3 c, float bd, float mb)
|
||||
{
|
||||
float m = max(max(c.r,c.g),c.b)+0.00001;
|
||||
float b2 = mix(bd, 1.0, pow(m,0.50));
|
||||
return b2*c;
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
vec2 tex = TEX0.xy * 1.00001;
|
||||
float sm_tate = COMPAT_TEXTURE(WpPass, vec2(0.5)).a;
|
||||
float ratio = COMPAT_TEXTURE(RotPass, vec2(0.5, 0.1)).a;
|
||||
|
||||
vec4 SourceSize1 = params.SourceSize;
|
||||
float vertres = SourceSize1.y*ratio;
|
||||
|
||||
tex.y *= ratio;
|
||||
if (sm_tate > 0.25) { tex.x = Overscan(tex.x, (1.0/3.0)*SourceSize1.y/SourceSize1.x); }
|
||||
|
||||
float factor = params.OutputSize.y/vertres;
|
||||
|
||||
float gamma = COMPAT_TEXTURE(LinPass, vec2(0.5,0.1)).a;
|
||||
|
||||
if (smart == 1.0 || smart == 2.0 || smart == 3.0)
|
||||
{
|
||||
float intfactor = round(factor); if (smart == 2.0) intfactor = floor(factor); if (smart == 3.0) intfactor = ceil(factor);
|
||||
float diff = factor/intfactor;
|
||||
tex.y = Overscan(tex.y/(ratio), diff)*ratio;
|
||||
}
|
||||
|
||||
tex = Warp(tex/vec2(1.0,ratio))*vec2(1.0,ratio);
|
||||
|
||||
vec2 OGL2Pos = tex * SourceSize1.xy - vec2(0.5,0.5);
|
||||
vec2 fp = fract(OGL2Pos);
|
||||
|
||||
vec2 pC4 = (floor(OGL2Pos) + vec2(0.5)) * SourceSize1.zw;
|
||||
|
||||
// Reading the texels
|
||||
vec2 dx = vec2(SourceSize1.z,0.0);
|
||||
vec2 dy = vec2(0.0,SourceSize1.w);
|
||||
vec2 x2 = dx+dx;
|
||||
float zero = mix(0.0, exp2(-h_sharp), cubic);
|
||||
|
||||
float wl2 = 1.0 + fp.x;
|
||||
float wl1 = fp.x;
|
||||
float wr1 = 1.0 - fp.x;
|
||||
float wr2 = 2.0 - fp.x;
|
||||
|
||||
wl2*=wl2; wl2 = exp2(-h_sharp*wl2); float sl2 = wl2;
|
||||
wl1*=wl1; wl1 = exp2(-h_sharp*wl1); float sl1 = wl1;
|
||||
wr1*=wr1; wr1 = exp2(-h_sharp*wr1); float sr1 = wr1;
|
||||
wr2*=wr2; wr2 = exp2(-h_sharp*wr2); float sr2 = wr2;
|
||||
|
||||
wl2 = max(wl2 - zero, mix(0.0,mix(-0.14, -0.035, fp.x),float(cubic > 0.05)));
|
||||
wl1 = max(wl1 - zero, 0.0);
|
||||
wr1 = max(wr1 - zero, 0.0);
|
||||
wr2 = max(wr2 - zero, mix(0.0,mix(-0.14, -0.035, 1.-fp.x),float(cubic > 0.05)));
|
||||
|
||||
float wtt = 1.0/(wl2+wl1+wr1+wr2);
|
||||
float wts = 1.0/(sl2+sl1+sr1+sr2);
|
||||
|
||||
vec3 l2 = COMPAT_TEXTURE(LinPass, pC4 - dx).rgb;
|
||||
vec3 l1 = COMPAT_TEXTURE(LinPass, pC4 ).rgb;
|
||||
vec3 r1 = COMPAT_TEXTURE(LinPass, pC4 + dx).rgb;
|
||||
vec3 r2 = COMPAT_TEXTURE(LinPass, pC4 + x2).rgb;
|
||||
|
||||
vec3 color1 = (wl2*l2+wl1*l1+wr1*r1+wr2*r2)*wtt;
|
||||
|
||||
vec3 colmin = min(min(l2,l1),min(r1,r2));
|
||||
vec3 colmax = max(max(l2,l1),max(r1,r2));
|
||||
|
||||
if (cubic > 0.05) color1 = clamp(color1, colmin, colmax);
|
||||
|
||||
l1*=l1; l1*=l1; r1*=r1; r1*=r1; l2*=l2; l2*=l2; r2*=r2; r2*=r2;
|
||||
vec3 scolor1 = (sl2*l2+sl1*l1+sr1*r1+sr2*r2)*wts;
|
||||
scolor1 = pow(scolor1, vec3(1.0/4.0)); vec3 mscolor1 = scolor1;
|
||||
|
||||
scolor1 = mix(color1, scolor1, 1.1);
|
||||
|
||||
pC4+=dy;
|
||||
l2 = COMPAT_TEXTURE(LinPass, pC4 - dx).rgb;
|
||||
l1 = COMPAT_TEXTURE(LinPass, pC4 ).rgb;
|
||||
r1 = COMPAT_TEXTURE(LinPass, pC4 + dx).rgb;
|
||||
r2 = COMPAT_TEXTURE(LinPass, pC4 + x2).rgb;
|
||||
|
||||
vec3 color2 = (wl2*l2+wl1*l1+wr1*r1+wr2*r2)*wtt;
|
||||
|
||||
colmin = min(min(l2,l1),min(r1,r2));
|
||||
colmax = max(max(l2,l1),max(r1,r2));
|
||||
|
||||
if (cubic > 0.05) color2 = clamp(color2, colmin, colmax);
|
||||
|
||||
l1*=l1; l1*=l1; r1*=r1; r1*=r1; l2*=l2; l2*=l2; r2*=r2; r2*=r2;
|
||||
vec3 scolor2 = (sl2*l2+sl1*l1+sr1*r1+sr2*r2)*wts;
|
||||
scolor2 = pow(scolor2, vec3(1.0/4.0)); vec3 mscolor2 = scolor2;
|
||||
|
||||
scolor2 = mix(color2, scolor2, 1.1);
|
||||
|
||||
float f1 = fp.y;
|
||||
float f2 = 1.0 - fp.y;
|
||||
float f3 = fract(tex.y * SourceSize1.y);
|
||||
|
||||
vec3 color;
|
||||
float t1 = st(f1);
|
||||
float t2 = st(f2);
|
||||
float wt = 1.0/(t1+t2);
|
||||
|
||||
// calculating scanlines
|
||||
|
||||
float scan1 = mix(scanline1, scanline2, f1);
|
||||
float scan2 = mix(scanline1, scanline2, f2);
|
||||
|
||||
vec3 sctemp = (t1*scolor1 + t2*scolor2)*wt;
|
||||
vec3 msctemp = (t1*mscolor1 + t2*mscolor2)*wt;
|
||||
|
||||
vec3 ref1 = mix(sctemp, scolor1.rgb, s_beam); ref1 = pow(ref1, mix(vec3(1.25), vec3(0.65), ref1));
|
||||
vec3 ref2 = mix(sctemp, scolor2.rgb, s_beam); ref2 = pow(ref2, mix(vec3(1.25), vec3(0.65), ref2));
|
||||
|
||||
vec3 w1, w2 = vec3(0.0);
|
||||
|
||||
if (stype < 0.5)
|
||||
{
|
||||
w1 = sw0(f1, ref1, scan1);
|
||||
w2 = sw0(f2, ref2, scan2);
|
||||
}
|
||||
else
|
||||
if (stype < 1.5)
|
||||
{
|
||||
w1 = sw1(f1, ref1, scan1);
|
||||
w2 = sw1(f2, ref2, scan2);
|
||||
}
|
||||
else
|
||||
if (stype < 2.5)
|
||||
{
|
||||
w1 = sw2(f1, ref1, scan1);
|
||||
w2 = sw2(f2, ref2, scan2);
|
||||
}
|
||||
else
|
||||
{
|
||||
w1 = vec3(f2);
|
||||
w2 = vec3(f1);
|
||||
}
|
||||
|
||||
|
||||
vec3 ctemp = (t1*color1 + t2*color2)*wt; vec3 orig = ctemp; float pixbr = max(max(orig.r,orig.g),orig.b); vec3 one = vec3(1.0);
|
||||
vec3 tmp1 = mix(orig, msctemp, 2.0);
|
||||
ctemp = w1+w2;
|
||||
float w3 = max(max(ctemp.r,ctemp.g),ctemp.b);
|
||||
|
||||
tmp1 = pow(tmp1, vec3(0.75));
|
||||
float pixbr1 = max(max(tmp1.r,tmp1.g),tmp1.b);
|
||||
|
||||
float maskd = mix(min(maskdark,1.0), 0.25*max(maskbright,0.0), pixbr1); if (mask == 3.0 || mask == 4.0) maskd*=1.33; maskd = mix(1.0, 1.0/(1.0-0.5*maskd), autobrm);
|
||||
maskd = mix(maskd, 1.0, pow(pixbr,0.85));
|
||||
|
||||
float brightboost_d = brightboost1;
|
||||
float brightboost_b = brightboost2;
|
||||
|
||||
if (stype == 1.0) { brightboost_d = min(brightboost1, 1.40); maskd = 1.0; }
|
||||
|
||||
color1 = gc(color1, brightboost_d, maskd);
|
||||
color2 = gc(color2, brightboost_d, maskd);
|
||||
|
||||
color1 = min(color1, 1.0);
|
||||
color2 = min(color2, 1.0);
|
||||
|
||||
color = w1*color1.rgb + w2*color2.rgb;
|
||||
color = maskd*color;
|
||||
|
||||
vec3 scan3 = vec3(0.0);
|
||||
|
||||
float spos = (gl_FragCoord.x);
|
||||
float spos2 = floor(1.000001*gl_FragCoord.x/masksize) + floor(1.000001*gl_FragCoord.y/masksize);
|
||||
|
||||
spos = floor((spos * 1.000001)/masksize); float spos1 = 0.0;
|
||||
|
||||
|
||||
if (mask == 0.0 || mask == 1.0)
|
||||
{
|
||||
if (mask == 1.0) spos = spos2;
|
||||
spos1 = fract(spos*0.5);
|
||||
if (spos1 < 0.5) scan3.rb = one.rb;
|
||||
else scan3.g = one.g;
|
||||
}
|
||||
else
|
||||
if (mask == 2.0)
|
||||
{
|
||||
spos1 = fract(spos*0.5);
|
||||
if (spos1 < 0.5) scan3.rg = one.rg;
|
||||
else scan3.b = one.b;
|
||||
}
|
||||
else
|
||||
if (mask == 3.0)
|
||||
{
|
||||
spos1 = fract(spos/3.0);
|
||||
if (spos1 < 0.3333) scan3.r = one.r;
|
||||
else if (spos1 < 0.6666) scan3.g = one.g;
|
||||
else scan3.b = one.b;
|
||||
}
|
||||
else
|
||||
if (mask == 4.0)
|
||||
{
|
||||
spos1 = fract(spos*0.25);
|
||||
if (spos1 < 0.25) scan3.r = one.r;
|
||||
else if (spos1 < 0.50) scan3.rg = one.rg;
|
||||
else if (spos1 < 0.75) scan3.gb = one.gb;
|
||||
else scan3.b = one.b;
|
||||
}
|
||||
else
|
||||
{
|
||||
spos1 = fract(spos*0.25);
|
||||
if (spos1 < 0.25) scan3.r = one.r;
|
||||
else if (spos1 < 0.50) scan3.rb = one.rb;
|
||||
else if (spos1 < 0.75) scan3.gb = one.gb;
|
||||
else scan3.g = one.g;
|
||||
}
|
||||
|
||||
vec3 mixmask = tmp1;
|
||||
if (maskmode == 1.0) mixmask = vec3(pixbr1); else
|
||||
if (maskmode == 2.0) mixmask = tmp1*w3;
|
||||
|
||||
vec3 cmask = clamp(mix( mix(one, scan3, maskdark), mix(one, scan3, maskbright), mixmask), 0.0, 1.0);
|
||||
vec3 orig1 = color;
|
||||
color = color*cmask*brightboost_b;
|
||||
|
||||
vec3 Bloom = COMPAT_TEXTURE(Source, tex).rgb;
|
||||
vec3 Bglow = COMPAT_TEXTURE(LinPass, tex).rgb;
|
||||
Bglow = clamp(Bloom - Bglow,0.0,1.0);
|
||||
|
||||
vec3 Bloom1 = 2.0*Bloom*Bloom;
|
||||
Bloom1 = min(Bloom1, 0.75);
|
||||
float bmax = max(max(Bloom1.r,Bloom1.g),Bloom1.b);
|
||||
float pmax = 0.85;
|
||||
Bloom1 = min(Bloom1, pmax*bmax)/pmax;
|
||||
|
||||
Bloom1 = mix(min( Bloom1, 0.5*(orig1+color)), Bloom1, 0.5*(orig1+color));
|
||||
Bloom1 = Bloom1*mix(w1+w2,one,1.0-color);
|
||||
|
||||
Bloom1 = bloom*Bloom1*cmask;
|
||||
|
||||
color = color + Bloom1;
|
||||
color = min(color,1.0);
|
||||
color = declip(color, pow(w3, 1.0-sclip));
|
||||
|
||||
color = color + bglow*Bglow;
|
||||
color = min(color, mix(cmask,one,sclip));
|
||||
|
||||
float fgamma = 1.0/gamma_out;
|
||||
if (stype == 1.0) fgamma = gamma;
|
||||
vec3 color1g = pow(color, vec3(fgamma));
|
||||
|
||||
FragColor = vec4(color1g, 1.0);
|
||||
}
|
97
crt/shaders/guest/crt-sm/d65-d50-sm.slang
Normal file
97
crt/shaders/guest/crt-sm/d65-d50-sm.slang
Normal file
|
@ -0,0 +1,97 @@
|
|||
#version 450
|
||||
|
||||
layout(push_constant) uniform Push
|
||||
{
|
||||
vec4 SourceSize;
|
||||
vec4 OriginalSize;
|
||||
vec4 OutputSize;
|
||||
uint FrameCount;
|
||||
float WP;
|
||||
float wp_saturation;
|
||||
float tate, fliph, flipv;
|
||||
} params;
|
||||
|
||||
#pragma parameter tate "TATE Mode" 0.0 0.0 1.0 1.0
|
||||
#pragma parameter fliph "Flip The Image Horizontally" -1.0 -1.0 1.0 2.0
|
||||
#pragma parameter flipv "Flip The Image Vertically" 1.0 -1.0 1.0 2.0
|
||||
#pragma parameter WP "Color Temperature %" 0.0 -100.0 100.0 5.0
|
||||
#pragma parameter wp_saturation "Saturation Adjustment" 1.0 0.0 2.0 0.05
|
||||
|
||||
#define WP params.WP
|
||||
#define wp_saturation params.wp_saturation
|
||||
#define tate params.tate
|
||||
#define fliph params.fliph
|
||||
#define flipv params.flipv
|
||||
|
||||
#define COMPAT_TEXTURE(c,d) texture(c,d)
|
||||
#define TEX0 vTexCoord
|
||||
|
||||
layout(std140, set = 0, binding = 0) uniform UBO
|
||||
{
|
||||
mat4 MVP;
|
||||
} global;
|
||||
|
||||
#pragma stage vertex
|
||||
layout(location = 0) in vec4 Position;
|
||||
layout(location = 1) in vec2 TexCoord;
|
||||
layout(location = 0) out vec2 vTexCoord;
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = global.MVP * Position * mix(vec4(1.0), vec4(flipv, fliph, 1.0, 1.0), tate);
|
||||
vTexCoord = TexCoord;
|
||||
}
|
||||
|
||||
#pragma stage fragment
|
||||
layout(location = 0) in vec2 vTexCoord;
|
||||
layout(location = 0) out vec4 FragColor;
|
||||
layout(set = 0, binding = 2) uniform sampler2D Source;
|
||||
|
||||
const mat3 D65_to_XYZ = mat3 (
|
||||
0.4306190, 0.2220379, 0.0201853,
|
||||
0.3415419, 0.7066384, 0.1295504,
|
||||
0.1783091, 0.0713236, 0.9390944);
|
||||
|
||||
const mat3 XYZ_to_D65 = mat3 (
|
||||
3.0628971, -0.9692660, 0.0678775,
|
||||
-1.3931791, 1.8760108, -0.2288548,
|
||||
-0.4757517, 0.0415560, 1.0693490);
|
||||
|
||||
const mat3 D50_to_XYZ = mat3 (
|
||||
0.4552773, 0.2323025, 0.0145457,
|
||||
0.3675500, 0.7077956, 0.1049154,
|
||||
0.1413926, 0.0599019, 0.7057489);
|
||||
|
||||
const mat3 XYZ_to_D50 = mat3 (
|
||||
2.9603944, -0.9787684, 0.0844874,
|
||||
-1.4678519, 1.9161415, -0.2545973,
|
||||
-0.4685105, 0.0334540, 1.4216174);
|
||||
|
||||
void main()
|
||||
{
|
||||
vec3 color = COMPAT_TEXTURE(Source, TEX0.xy).rgb;
|
||||
|
||||
color = normalize(pow(color + 1e-4, vec3(wp_saturation)))*length(color);
|
||||
|
||||
float p = 2.4;
|
||||
|
||||
color = pow(color, vec3(p));
|
||||
|
||||
vec3 warmer = D50_to_XYZ*color;
|
||||
warmer = XYZ_to_D65*warmer;
|
||||
|
||||
vec3 cooler = D65_to_XYZ*color;
|
||||
cooler = XYZ_to_D50*cooler;
|
||||
|
||||
float m = abs(WP)/100.0;
|
||||
|
||||
vec3 comp = (WP < 0.0) ? cooler : warmer;
|
||||
|
||||
color = mix(color, comp, m);
|
||||
|
||||
color = pow(color, vec3(1.0/p));
|
||||
|
||||
float a = 0.0; if (tate > 0.5) a = 0.5;
|
||||
|
||||
FragColor = vec4(color,a);
|
||||
}
|
41
crt/shaders/guest/crt-sm/linearize-sm.slang
Normal file
41
crt/shaders/guest/crt-sm/linearize-sm.slang
Normal file
|
@ -0,0 +1,41 @@
|
|||
#version 450
|
||||
|
||||
layout(push_constant) uniform Push
|
||||
{
|
||||
float GAMMA_INPUT;
|
||||
} params;
|
||||
|
||||
#pragma parameter GAMMA_INPUT "Gamma Input" 2.4 0.5 5.0 0.05
|
||||
#define GAMMA_INPUT params.GAMMA_INPUT
|
||||
|
||||
layout(std140, set = 0, binding = 0) uniform UBO
|
||||
{
|
||||
mat4 MVP;
|
||||
} global;
|
||||
|
||||
#pragma stage vertex
|
||||
layout(location = 0) in vec4 Position;
|
||||
layout(location = 1) in vec2 TexCoord;
|
||||
layout(location = 0) out vec2 vTexCoord;
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = global.MVP * Position;
|
||||
vTexCoord = TexCoord;
|
||||
}
|
||||
|
||||
#pragma stage fragment
|
||||
layout(location = 0) in vec2 vTexCoord;
|
||||
layout(location = 0) out vec4 FragColor;
|
||||
layout(set = 0, binding = 2) uniform sampler2D Source;
|
||||
|
||||
void main()
|
||||
{
|
||||
float ratio = texture(Source, vec2(0.5,0.1)).a;
|
||||
if (vTexCoord.y > ratio) discard;
|
||||
float gamma = 2.4;
|
||||
if ( (GAMMA_INPUT > 0.4) || (GAMMA_INPUT < 4.1) ) gamma = GAMMA_INPUT;
|
||||
gamma = 1.0/gamma;
|
||||
|
||||
FragColor = vec4(pow(vec3(texture(Source, vTexCoord).rgb), vec3(GAMMA_INPUT)),gamma);
|
||||
}
|
Loading…
Reference in a new issue