add aliaspider's GTU

This commit is contained in:
hunterk 2016-08-09 16:15:41 -05:00
parent 744aea4918
commit fdb389c549
5 changed files with 273 additions and 0 deletions

19
crt/gtu-v050.slangp Normal file
View file

@ -0,0 +1,19 @@
shaders = 3
shader0 = shaders/gtu-v050/pass1.slang
scale_type0 = source
scale0 = 1.0
float_framebuffer0 = true
shader1 = shaders/gtu-v050/pass2.slang
scale_type_x1 = viewport
scale_x1 = 1.0
scale_type_y1 = source
scale_y1 = 1.0
filter_linear1 = false
float_framebuffer1 = true
shader2 = shaders/gtu-v050/pass3.slang
scale_type2 = viewport
scale_2 = 1.0
filter_linear2 = false

View file

@ -0,0 +1,3 @@
#pragma parameter compositeConnection "Composite Connection Enable" 0.0 0.0 1.0 1.0
#define FIXNUM 6

View file

@ -0,0 +1,50 @@
#version 450
layout(push_constant) uniform Push
{
vec4 OutputSize;
vec4 OriginalSize;
vec4 SourceSize;
float compositeConnection;
} params;
layout(std140, set = 0, binding = 0) uniform UBO
{
mat4 MVP;
} global;
////////////////////////////////////////////////////////
// GTU version 0.50
// Author: aliaspider - aliaspider@gmail.com
// License: GPLv3
////////////////////////////////////////////////////////
#include "config.h"
#define RGB_to_YIQ mat3x3( 0.299 , 0.595716 , 0.211456 , 0.587 , -0.274453 , -0.522591 , 0.114 , -0.321263 , 0.311135 )
#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()
{
vec4 c = texture(Source, vTexCoord);
if(params.compositeConnection > 0.0)
c.rgb = c.rgb * RGB_to_YIQ;
FragColor = c;
}

View file

@ -0,0 +1,92 @@
#version 450
layout(push_constant) uniform Push
{
vec4 OutputSize;
vec4 OriginalSize;
vec4 SourceSize;
float signalResolution;
float signalResolutionI;
float signalResolutionQ;
float compositeConnection;
} params;
#pragma parameter signalResolution "Signal Resolution Y" 256.0 16.0 1024.0 16.0
#pragma parameter signalResolutionI "Signal Resolution I" 83.0 1.0 350.0 2.0
#pragma parameter signalResolutionQ "Signal Resolution Q" 25.0 1.0 350.0 2.0
layout(std140, set = 0, binding = 0) uniform UBO
{
mat4 MVP;
} global;
////////////////////////////////////////////////////////
// GTU version 0.50
// Author: aliaspider - aliaspider@gmail.com
// License: GPLv3
////////////////////////////////////////////////////////
#include "config.h"
#define YIQ_to_RGB mat3x3( 1.0 , 1.0 , 1.0 , 0.9563 , -0.2721 , -1.1070 , 0.6210 , -0.6474 , 1.7046 )
#define pi 3.14159265358
#define a(x) abs(x)
#define d(x,b) (pi*b*min(a(x)+0.5,1.0/b))
#define e(x,b) (pi*b*min(max(a(x)-0.5,-1.0/b),1.0/b))
#define STU(x,b) ((d(x,b)+sin(d(x,b))-e(x,b)-sin(e(x,b)))/(2.0*pi))
//#define X(i) (offset-(i))
#define GETC (texture(Source, vec2(vTexCoord.x - X * params.SourceSize.z, vTexCoord.y)).rgb)
#define VAL_composite vec3((c.x*STU(X,(params.signalResolution * params.SourceSize.z))),(c.y*STU(X,(params.signalResolutionI * params.SourceSize.z))),(c.z*STU(X,(params.signalResolutionQ * params.SourceSize.z))))
#define VAL (c*STU(X,(params.signalResolution * params.SourceSize.z)))
#define PROCESS(i) X=(offset-(i));c=GETC;tempColor+=VAL;
#define PROCESS_composite(i) X=(offset-(i));c=GETC;tempColor+=VAL_composite;
#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 offset = fract((vTexCoord.x * params.SourceSize.x) - 0.5);
vec3 tempColor = vec3(0.0);
float X;
vec3 c;
float range;
if (params.compositeConnection > 0.0)
range=ceil(0.5+params.SourceSize.x/min(min(params.signalResolution,params.signalResolutionI),params.signalResolutionQ));
else
range=ceil(0.5+params.SourceSize.x/params.signalResolution);
float i;
if(params.compositeConnection > 0.0){
for (i=-range;i<range+2.0;i++){
PROCESS_composite((offset-(i)))
}
}
else{
for (i=-range;i<range+2.0;i++){
PROCESS((offset-(i)))
}
}
if(params.compositeConnection > 0.0)
tempColor=clamp(tempColor * YIQ_to_RGB,0.0,1.0);
else
tempColor=clamp(tempColor,0.0,1.0);
// tempColor=clamp(tempColor,0.0,1.0);
FragColor = vec4(tempColor, 1.0);
}

View file

@ -0,0 +1,109 @@
#version 450
layout(push_constant) uniform Push
{
vec4 OutputSize;
vec4 OriginalSize;
vec4 SourceSize;
float noScanlines;
float tvVerticalResolution;
float blackLevel;
float contrast;
float compositeConnection;
} params;
#pragma parameter noScanlines "No Scanlines" 0.0 0.0 1.0 1.0
#pragma parameter tvVerticalResolution "TV Vertical Resolution" 250.0 20.0 1000.0 10.0
#pragma parameter blackLevel "Black Level" 0.07 -0.30 0.30 0.01
#pragma parameter contrast "Contrast" 1.0 0.0 2.0 0.1
layout(std140, set = 0, binding = 0) uniform UBO
{
mat4 MVP;
} global;
////////////////////////////////////////////////////////
// GTU version 0.50
// Author: aliaspider - aliaspider@gmail.com
// License: GPLv3
////////////////////////////////////////////////////////
#include "config.h"
#define pi 3.14159265358
#define normalGauss(x) ((exp(-(x)*(x)*0.5))/sqrt(2.0*pi))
float normalGaussIntegral(float x)
{
float a1 = 0.4361836;
float a2 = -0.1201676;
float a3 = 0.9372980;
float p = 0.3326700;
float t = 1.0 / (1.0 + p*abs(x));
return (0.5-normalGauss(x) * (t*(a1 + t*(a2 + a3*t))))*sign(x);
}
vec3 scanlines( float x , vec3 c){
float temp=sqrt(2*pi)*(params.tvVerticalResolution * params.SourceSize.w);
float rrr=0.5*(params.SourceSize.y * params.OutputSize.w);
float x1=(x+rrr)*temp;
float x2=(x-rrr)*temp;
c.r=(c.r*(normalGaussIntegral(x1)-normalGaussIntegral(x2)));
c.g=(c.g*(normalGaussIntegral(x1)-normalGaussIntegral(x2)));
c.b=(c.b*(normalGaussIntegral(x1)-normalGaussIntegral(x2)));
c*=(params.OutputSize.y * params.SourceSize.w);
return c;
}
#define Y(j) (offset.y-(j))
#define a(x) abs(x)
#define d(x,b) (pi*b*min(a(x)+0.5,1.0/b))
#define e(x,b) (pi*b*min(max(a(x)-0.5,-1.0/b),1.0/b))
#define STU(x,b) ((d(x,b)+sin(d(x,b))-e(x,b)-sin(e(x,b)))/(2.0*pi))
#define SOURCE(j) vec2(vTexCoord.x,vTexCoord.y - Y(j) * params.SourceSize.w)
#define C(j) (texture(Source, SOURCE(j)).xyz)
#define VAL(j) (C(j)*STU(Y(j),(params.tvVerticalResolution * params.SourceSize.w)))
#define VAL_scanlines(j) (scanlines(Y(j),C(j)))
#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()
{
vec2 offset = fract((vTexCoord.xy * params.SourceSize.xy) - 0.5);
vec3 tempColor = vec3(0.0);
float range=ceil(0.5+params.SourceSize.y/params.tvVerticalResolution);
float i;
if (params.noScanlines > 0.0)
for (i=-range;i<range+2.0;i++){
tempColor+=VAL(i);
}
else
for (i=-range;i<range+2.0;i++){
tempColor+=VAL_scanlines(i);
}
tempColor-=vec3(params.blackLevel);
tempColor*=(params.contrast/vec3(1.0-params.blackLevel));
FragColor = vec4(tempColor, 1.0);
}