mirror of
https://github.com/italicsjenga/slang-shaders.git
synced 2024-11-22 15:51:30 +11:00
Merge pull request #299 from HyperspaceMadness/master
Added Slang version of crt-gdv-mini
This commit is contained in:
commit
646550a7ef
3
crt/crt-gdv-mini.slangp
Normal file
3
crt/crt-gdv-mini.slangp
Normal file
|
@ -0,0 +1,3 @@
|
|||
shaders = 1
|
||||
|
||||
shader0 = shaders/crt-gdv-mini.slang
|
349
crt/shaders/crt-gdv-mini.slang
Normal file
349
crt/shaders/crt-gdv-mini.slang
Normal file
|
@ -0,0 +1,349 @@
|
|||
#version 450
|
||||
|
||||
/*
|
||||
CRT - Guest - Nomask w. Curvature
|
||||
With work by DariusG to create a cut down extra fast version
|
||||
|
||||
Copyright (C) 2017-2018 guest(r) - guest.r@gmail.com
|
||||
|
||||
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.
|
||||
|
||||
*/
|
||||
|
||||
layout(push_constant) uniform Push
|
||||
{
|
||||
vec4 SourceSize;
|
||||
vec4 OriginalSize;
|
||||
vec4 OutputSize;
|
||||
uint FrameCount;
|
||||
|
||||
float brightboost;
|
||||
float saturation;
|
||||
float scanline;
|
||||
float beam_min;
|
||||
float beam_max;
|
||||
float h_sharp;
|
||||
float shadowMask;
|
||||
float masksize;
|
||||
float mcut;
|
||||
float maskDark;
|
||||
float maskLight;
|
||||
float CGWG;
|
||||
float csize;
|
||||
float warpX;
|
||||
float warpY;
|
||||
float c_shape;
|
||||
float bsize1;
|
||||
float sborder;
|
||||
float gamma_out;
|
||||
} params;
|
||||
|
||||
// Parameter lines go here:
|
||||
#pragma parameter gdv_mini_title "[ GDV MINI - DariusG ]:" 0.0 0.0 1.0 1.0
|
||||
|
||||
// Gamma out adjusted from 0.5 in glsl version to 0.43 to match output of guest-advanced
|
||||
#pragma parameter gamma_out " Gamma out" 0.43 0.2 0.6 0.01
|
||||
#define gamma_out params.gamma_out
|
||||
|
||||
#pragma parameter brightboost " Bright boost -- brightboost" 1.1 0.5 2.0 0.05
|
||||
#define brightboost params.brightboost
|
||||
|
||||
// Saturation out adjusted from 1.1 in glsl version to 1.35 to match output of guest-advanced
|
||||
#pragma parameter saturation " Saturation adjustment -- saturation" 1.35 0.1 2.0 0.05
|
||||
#define saturation params.saturation
|
||||
|
||||
#pragma parameter scanline " Scanline Adjust -- scanline" 8 1 12 1
|
||||
#define scanline params.scanline
|
||||
|
||||
#pragma parameter beam_min " Scanline Dark -- beam_min" 1.7 0.5 3 0.05
|
||||
#define beam_min params.beam_min
|
||||
|
||||
#pragma parameter beam_max " Scanline Bright -- beam_max" 2.1 0.5 3 0.05
|
||||
#define beam_max params.beam_max
|
||||
|
||||
#pragma parameter h_sharp " Horizontal Sharpness -- h_sharp" 2 1 5 0.05
|
||||
#define h_sharp params.h_sharp
|
||||
|
||||
#pragma parameter shadowMask " CRT Mask: 0:CGWG, 1-4:Lottes, 5-6:Trinitron" 0.0 -1.0 8.0 1.0
|
||||
#define shadowMask params.shadowMask
|
||||
|
||||
#pragma parameter masksize " CRT Mask Size (2.0 is nice in 4k) -- masksize" 1 1 2.0 1.0
|
||||
#define masksize params.masksize
|
||||
|
||||
#pragma parameter mcut " Mask 5-7 cutoff -- mcut" 0.2 0.0 0.5 0.05
|
||||
#define mcut params.mcut
|
||||
|
||||
#pragma parameter maskDark " Lottes maskDark" 0.5 0.0 2 0.1
|
||||
#define maskDark params.maskDark
|
||||
|
||||
#pragma parameter maskLight " Lottes maskLight" 1.5 0.0 2.0 0.1
|
||||
#define maskLight params.maskLight
|
||||
|
||||
#pragma parameter CGWG " CGWG Mask Str. -- CGWG" 0.4 0 1 0.1
|
||||
#define CGWG params.CGWG
|
||||
|
||||
#pragma parameter warpX " CurvatureX (default 0.03)" 0.0 0.0 0.25 0.01
|
||||
#define warpX params.warpX // Curvature X
|
||||
|
||||
#pragma parameter warpY " CurvatureY (default 0.04)" 0.0 0.0 0.25 0.01
|
||||
#define warpY params.warpY // Curvature Y
|
||||
|
||||
// #pragma parameter csize " Corner Size" 0.0 0.0 0.25 0.005
|
||||
// #define csize params.csize // corner size
|
||||
|
||||
// #pragma parameter c_shape " Curvature Shape" 0.25 0.05 0.60 0.05
|
||||
// #define c_shape params.c_shape // curvature shape
|
||||
|
||||
// #pragma parameter bsize1 " Border Size" 0.01 0.0 3.0 0.01
|
||||
// #define bsize1 params.bsize1 // border Size
|
||||
|
||||
// #pragma parameter sborder " Border Intensity" 0.75 0.25 2.0 0.05
|
||||
// #define sborder params.sborder // border intensity
|
||||
|
||||
layout(std140, set = 0, binding = 0) uniform UBO
|
||||
{
|
||||
mat4 MVP;
|
||||
vec4 FinalViewportSize;
|
||||
vec4 OutputSize;
|
||||
} 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.0001;
|
||||
}
|
||||
|
||||
#pragma stage fragment
|
||||
layout(location = 0) in vec2 vTexCoord;
|
||||
layout(location = 1) in float maskFade;
|
||||
layout(location = 0) out vec4 FragColor;
|
||||
layout(set = 0, binding = 1) uniform sampler2D Source;
|
||||
float sw(float x, float l)
|
||||
{
|
||||
float d = x;
|
||||
float bm = scanline;
|
||||
float b = mix(beam_min,beam_max,l);
|
||||
d = exp2(-bm*pow(d,b));
|
||||
return d;
|
||||
}
|
||||
|
||||
// Shadow mask (1-4 from PD CRT Lottes shader).
|
||||
vec3 Mask(vec2 pos, vec3 c)
|
||||
{
|
||||
pos = floor(pos / masksize);
|
||||
vec3 mask = vec3(maskDark, maskDark, maskDark);
|
||||
|
||||
// No mask
|
||||
if (shadowMask == -1.0)
|
||||
{
|
||||
mask = vec3(1.0);
|
||||
}
|
||||
|
||||
// Phosphor.
|
||||
else if (shadowMask == 0.0)
|
||||
{
|
||||
pos.x = fract(pos.x*0.5);
|
||||
float mc = 1.0 - CGWG;
|
||||
if (pos.x < 0.5) { mask.r = 1.1; mask.g = mc; mask.b = 1.1; }
|
||||
else { mask.r = mc; mask.g = 1.1; mask.b = mc; }
|
||||
}
|
||||
|
||||
// Very compressed TV style shadow mask.
|
||||
else if (shadowMask == 1.0)
|
||||
{
|
||||
float line = maskLight;
|
||||
float odd = 0.0;
|
||||
|
||||
if (fract(pos.x/6.0) < 0.5)
|
||||
odd = 1.0;
|
||||
if (fract((pos.y + odd)/2.0) < 0.5)
|
||||
line = maskDark;
|
||||
|
||||
pos.x = fract(pos.x/3.0);
|
||||
|
||||
if (pos.x < 0.333) mask.r = maskLight;
|
||||
else if (pos.x < 0.666) mask.g = maskLight;
|
||||
else mask.b = maskLight;
|
||||
|
||||
mask*=line;
|
||||
}
|
||||
|
||||
// Aperture-grille.
|
||||
else if (shadowMask == 2.0)
|
||||
{
|
||||
pos.x = fract(pos.x/3.0);
|
||||
|
||||
if (pos.x < 0.333) mask.r = maskLight;
|
||||
else if (pos.x < 0.666) mask.g = maskLight;
|
||||
else mask.b = maskLight;
|
||||
}
|
||||
|
||||
// Stretched VGA style shadow mask (same as prior shaders).
|
||||
else if (shadowMask == 3.0)
|
||||
{
|
||||
pos.x += pos.y*3.0;
|
||||
pos.x = fract(pos.x/6.0);
|
||||
|
||||
if (pos.x < 0.333) mask.r = maskLight;
|
||||
else if (pos.x < 0.666) mask.g = maskLight;
|
||||
else mask.b = maskLight;
|
||||
}
|
||||
|
||||
// VGA style shadow mask.
|
||||
else if (shadowMask == 4.0)
|
||||
{
|
||||
pos.xy = floor(pos.xy*vec2(1.0, 0.5));
|
||||
pos.x += pos.y*3.0;
|
||||
pos.x = fract(pos.x/6.0);
|
||||
|
||||
if (pos.x < 0.333) mask.r = maskLight;
|
||||
else if (pos.x < 0.666) mask.g = maskLight;
|
||||
else mask.b = maskLight;
|
||||
}
|
||||
|
||||
// Alternate mask 5
|
||||
else if (shadowMask == 5.0)
|
||||
{
|
||||
float mx = max(max(c.r,c.g),c.b);
|
||||
vec3 maskTmp = vec3( min( 1.25*max(mx-mcut,0.0)/(1.0-mcut) ,maskDark + 0.2*(1.0-maskDark)*mx));
|
||||
float adj = 0.80*maskLight - 0.5*(0.80*maskLight - 1.0)*mx + 0.75*(1.0-mx);
|
||||
mask = maskTmp;
|
||||
pos.x = fract(pos.x/2.0);
|
||||
if (pos.x < 0.5)
|
||||
{ mask.r = adj;
|
||||
mask.b = adj;
|
||||
}
|
||||
else mask.g = adj;
|
||||
}
|
||||
|
||||
// Alternate mask 6
|
||||
else if (shadowMask == 6.0)
|
||||
{
|
||||
float mx = max(max(c.r,c.g),c.b);
|
||||
vec3 maskTmp = vec3( min( 1.33*max(mx-mcut,0.0)/(1.0-mcut) ,maskDark + 0.225*(1.0-maskDark)*mx));
|
||||
float adj = 0.80*maskLight - 0.5*(0.80*maskLight - 1.0)*mx + 0.75*(1.0-mx);
|
||||
mask = maskTmp;
|
||||
pos.x = fract(pos.x/3.0);
|
||||
if (pos.x < 0.333) mask.r = adj;
|
||||
else if (pos.x < 0.666) mask.g = adj;
|
||||
else mask.b = adj;
|
||||
}
|
||||
|
||||
// Alternate mask 7
|
||||
else if (shadowMask == 7.0)
|
||||
{
|
||||
float mc = 1.0 - CGWG;
|
||||
float mx = max(max(c.r,c.g),c.b);
|
||||
float maskTmp = min(1.6*max(mx-mcut,0.0)/(1.0-mcut) , mc);
|
||||
mask = vec3(maskTmp);
|
||||
pos.x = fract(pos.x/2.0);
|
||||
if (pos.x < 0.5) mask = vec3(1.0 + 0.6*(1.0-mx));
|
||||
}
|
||||
else if (shadowMask == 8.0)
|
||||
{
|
||||
float line = maskLight;
|
||||
float odd = 0.0;
|
||||
|
||||
if (fract(pos.x/4.0) < 0.5)
|
||||
odd = 1.0;
|
||||
if (fract((pos.y + odd)/2.0) < 0.5)
|
||||
line = maskDark;
|
||||
|
||||
pos.x = fract(pos.x/2.0);
|
||||
|
||||
if (pos.x < 0.5) {mask.r = maskLight; mask.b = maskLight;}
|
||||
else mask.g = maskLight;
|
||||
mask*=line;
|
||||
}
|
||||
return mask;
|
||||
}
|
||||
|
||||
|
||||
// Distortion of scanlines, and end of screen alpha.
|
||||
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;
|
||||
}
|
||||
|
||||
// Code from Guest.r's Guest Advanced shader
|
||||
// float corner(vec2 pos) {
|
||||
// vec2 b = vec2(bsize1, bsize1) * vec2(1.0, global.OutputSize.x/global.OutputSize.y) * 0.05;
|
||||
// pos = clamp(pos, 0.0, 1.0);
|
||||
// pos = abs(2.0*(pos - 0.5));
|
||||
// float csize1 = mix(400.0, 7.0, pow(4.0*csize, 0.10));
|
||||
// float crn = dot(pow(pos, csize1.xx), vec2(1.0, global.OutputSize.y/global.OutputSize.x));
|
||||
// crn = (csize == 0.0) ? max(pos.x, pos.y) : pow(crn, 1.0/csize1);
|
||||
// pos = max(pos, crn);
|
||||
// vec2 res = (bsize1 == 0.0) ? 1.0.xx : mix(0.0.xx, 1.0.xx, smoothstep(1.0.xx, 1.0.xx-b, sqrt(pos)));
|
||||
// res = pow(res, sborder.xx);
|
||||
// return sqrt(res.x*res.y);
|
||||
// }
|
||||
|
||||
void main()
|
||||
{
|
||||
vec2 pos = Warp(vTexCoord);
|
||||
|
||||
// HSM Added
|
||||
vec4 SourceSize = params.SourceSize;
|
||||
|
||||
vec2 ps = SourceSize.zw;
|
||||
vec2 OGL2Pos = pos * SourceSize.xy;
|
||||
vec2 fp = fract(OGL2Pos);
|
||||
vec2 dx = vec2(ps.x,0.0);
|
||||
vec2 dy = vec2(0.0, ps.y);
|
||||
|
||||
vec2 pC4 = floor(OGL2Pos) * ps + 0.5*ps;
|
||||
|
||||
// Reading the texels
|
||||
vec3 ul = texture(Source, pC4 ).xyz; ul*=ul;
|
||||
vec3 ur = texture(Source, pC4 + dx).xyz; ur*=ur;
|
||||
vec3 dl = texture(Source, pC4 + dy).xyz; dl*=dl;
|
||||
vec3 dr = texture(Source, pC4 + ps).xyz; dr*=dr;
|
||||
|
||||
float lx = fp.x; lx = pow(lx, h_sharp);
|
||||
float rx = 1.0 - fp.x; rx = pow(rx, h_sharp);
|
||||
|
||||
vec3 color1 = (ur*lx + ul*rx)/(lx+rx);
|
||||
vec3 color2 = (dr*lx + dl*rx)/(lx+rx);
|
||||
|
||||
// calculating scanlines
|
||||
|
||||
float f = fp.y;
|
||||
float luma1 = length(color1)*0.57735;
|
||||
float luma2 = length(color2)*0.57735;
|
||||
|
||||
vec3 color = color1*sw(f,luma1) + color2*sw(1.0-f,luma2);
|
||||
|
||||
color*=brightboost;
|
||||
color = min(color, 1.0);
|
||||
color = color * Mask(vTexCoord * global.OutputSize.xy, color);
|
||||
|
||||
color = pow(color, vec3(gamma_out, gamma_out, gamma_out));
|
||||
|
||||
float l = length(color);
|
||||
color = normalize(pow(color, vec3(saturation,saturation,saturation)))*l;
|
||||
|
||||
// Screen edge and corner masking
|
||||
// FragColor = vec4(color*corner(pos), 1.0);
|
||||
|
||||
FragColor = vec4(color, 1.0);
|
||||
}
|
Loading…
Reference in a new issue