From 5fdb0ee25d5cb377e420a13bcb5c186cfd2bba97 Mon Sep 17 00:00:00 2001 From: Arzed Five Date: Wed, 7 Dec 2016 01:12:14 +0000 Subject: [PATCH] (gtu-famicom) Style nits, changed div by 2 with mul by 0.5 --- crt/shaders/gtu-famicom/DAC.slang | 89 ++++++++++-------- crt/shaders/gtu-famicom/DAC_LUT.slang | 38 ++++---- crt/shaders/gtu-famicom/combFilter.slang | 70 +++++++------- crt/shaders/gtu-famicom/lowPass.slang | 71 +++++++------- crt/shaders/gtu-famicom/scaleX.slang | 99 ++++++++++---------- crt/shaders/gtu-famicom/scaleY.slang | 114 ++++++++++++----------- 6 files changed, 251 insertions(+), 230 deletions(-) diff --git a/crt/shaders/gtu-famicom/DAC.slang b/crt/shaders/gtu-famicom/DAC.slang index 0697b88..278599f 100644 --- a/crt/shaders/gtu-famicom/DAC.slang +++ b/crt/shaders/gtu-famicom/DAC.slang @@ -2,52 +2,61 @@ layout(std140, set = 0, binding = 0) uniform UBO { - mat4 MVP; - vec4 OutputSize; - vec4 OriginalSize; - vec4 SourceSize; - uint FrameCount; + mat4 MVP; + vec4 OutputSize; + vec4 OriginalSize; + vec4 SourceSize; + uint FrameCount; } global; //////////////////////////////////////////////////////// -// GTU-famicom version 0.50 -// Author: aliaspider - aliaspider@gmail.com -// License: GPLv3 +// GTU-famicom version 0.50 +// Author: aliaspider - aliaspider@gmail.com +// License: GPLv3 //////////////////////////////////////////////////////// #define TO_INT2(X) int(floor(((X) * 3.0) + 0.5)) #define TO_INT3(X) int(floor(((X) * 7.0) + 0.5)) #define TO_INT4(X) int(floor(((X) * 15.0) + 0.5)) -bool InColorp (int p, int color) { - return ((color + p) % 12 < 6); +bool InColorp (int p, int color) +{ + return ((color + p) % 12 < 6); } float NTSCsignal(int emphasis, int level, int color, int p) { - float black=.518; - float white=1.962; + float black = .518; + float white = 1.962; - float attenuation=0.746; - const float levels[8] = float[] (0.350 , 0.518, 0.962, 1.550, - 1.094f, 1.506, 1.962, 1.962); - if(color > 13) level = 1; - float low = levels[0 + level]; - float high = levels[4 + level]; - if(color == 0) low = high; - if(color > 12) high = low; + float attenuation = 0.746; + const float levels[8] = float[] ( 0.350 , 0.518, 0.962, 1.550, + 1.094f, 1.506, 1.962, 1.962); + if (color > 13) + level = 1; + + float low = levels[0 + level]; + float high = levels[4 + level]; + + if (color == 0) + low = high; + + if (color > 12) + high = low; + + float signal = InColorp(p, color) ? high : low; + + if ((bool(emphasis & 1) && InColorp(p, 0)) || + (bool(emphasis & 2) && InColorp(p, 4)) || + (bool(emphasis & 4) && InColorp(p, 8))) + { + signal = signal * attenuation; + } - float signal = InColorp(p, color) ? high : low; + signal = (signal - black) / (white - black); - if( (bool(emphasis & 1) && InColorp(p, 0)) - || (bool(emphasis & 2) && InColorp(p, 4)) - || (bool(emphasis & 4) && InColorp(p, 8)) ) signal = signal * attenuation; - - - signal = (signal-black) / (white-black); - - return signal; + return signal; } #pragma stage vertex @@ -58,10 +67,10 @@ layout(location = 1) out float colorPhase; void main() { - gl_Position = global.MVP * Position; - vTexCoord = TexCoord; - vec2 pos = (vTexCoord.xy*global.OutputSize.xy)-0.5; - colorPhase = 8.0001 + pos.x + pos.y * 4.0001 + global.FrameCount * 4.0001; + gl_Position = global.MVP * Position; + vTexCoord = TexCoord; + vec2 pos = (vTexCoord.xy*global.OutputSize.xy) - 0.5; + colorPhase = 8.0001 + pos.x + pos.y * 4.0001 + global.FrameCount * 4.0001; } #pragma stage fragment @@ -72,12 +81,12 @@ layout(set = 0, binding = 2) uniform sampler2D Source; void main() { - vec4 c=texture(Source, vTexCoord.xy); + vec4 c = texture(Source, vTexCoord.xy); - int color = TO_INT4(c.x); - int level = TO_INT2(c.y); - int emphasis = TO_INT3(c.z); + int color = TO_INT4(c.x); + int level = TO_INT2(c.y); + int emphasis = TO_INT3(c.z); - float signal = NTSCsignal(emphasis,level,color,int(colorPhase + 0.5)); - FragColor = vec4(signal); -} \ No newline at end of file + float signal = NTSCsignal(emphasis, level, color, int(colorPhase + 0.5)); + FragColor = vec4(signal); +} diff --git a/crt/shaders/gtu-famicom/DAC_LUT.slang b/crt/shaders/gtu-famicom/DAC_LUT.slang index 9a0de0e..3bfe3ef 100644 --- a/crt/shaders/gtu-famicom/DAC_LUT.slang +++ b/crt/shaders/gtu-famicom/DAC_LUT.slang @@ -2,17 +2,17 @@ layout(std140, set = 0, binding = 0) uniform UBO { - mat4 MVP; - vec4 OutputSize; - vec4 OriginalSize; - vec4 SourceSize; - uint FrameCount; + mat4 MVP; + vec4 OutputSize; + vec4 OriginalSize; + vec4 SourceSize; + uint FrameCount; } global; //////////////////////////////////////////////////////// -// GTU-famicom version 0.50 -// Author: aliaspider - aliaspider@gmail.com -// License: GPLv3 +// GTU-famicom version 0.50 +// Author: aliaspider - aliaspider@gmail.com +// License: GPLv3 //////////////////////////////////////////////////////// #define GET_LEVEL(X) ((X)*(255.0f / (128.0f*(1.962f-.518f)))-(.518f / (1.962f-.518f))) @@ -25,10 +25,10 @@ layout(location = 1) out float colorPhase; void main() { - gl_Position = global.MVP * Position; - vTexCoord = TexCoord; - vec2 pos = (vTexCoord.xy*global.OutputSize.xy)-0.5; - colorPhase = 8.0001 + pos.x + pos.y * 4.0001 + global.FrameCount * 4.0001; + gl_Position = global.MVP * Position; + vTexCoord = TexCoord; + vec2 pos = (vTexCoord.xy*global.OutputSize.xy) - 0.5; + colorPhase = 8.0001 + pos.x + pos.y * 4.0001 + global.FrameCount * 4.0001; } #pragma stage fragment @@ -40,11 +40,11 @@ layout(set = 0, binding = 3) uniform sampler2D nestable; void main() { - vec4 c = texture(Source, vTexCoord.xy); - - vec2 pixmapCoord; - pixmapCoord.x = c.x * (15.0 / (16.0 * 4.0)) + c.y * (3.0 / 4.0) +(0.5 / (16.0 * 4.0)); - pixmapCoord.y = 1.0 - (floor(mod(colorPhase + 0.5, 12.0)) / (12.0 * 8.0) + c.z * (7.0 / 8.0) + (0.5 / (12.0 * 8.0))); + vec4 c = texture(Source, vTexCoord.xy); - FragColor = vec4(GET_LEVEL(texture(nestable, pixmapCoord.xy).r));//vec4(signal); -} \ No newline at end of file + vec2 pixmapCoord; + pixmapCoord.x = c.x * (15.0 / (16.0 * 4.0)) + c.y * (3.0 / 4.0) +(0.5 / (16.0 * 4.0)); + pixmapCoord.y = 1.0 - (floor(mod(colorPhase + 0.5, 12.0)) / (12.0 * 8.0) + c.z * (7.0 / 8.0) + (0.5 / (12.0 * 8.0))); + + FragColor = vec4(GET_LEVEL(texture(nestable, pixmapCoord.xy).r));//vec4(signal); +} diff --git a/crt/shaders/gtu-famicom/combFilter.slang b/crt/shaders/gtu-famicom/combFilter.slang index b25bb99..0fedb3d 100644 --- a/crt/shaders/gtu-famicom/combFilter.slang +++ b/crt/shaders/gtu-famicom/combFilter.slang @@ -2,12 +2,12 @@ layout(push_constant) uniform Push { - vec4 SourceSize; - vec4 OriginalSize; - vec4 OutputSize; - uint FrameCount; - float combFilter; - float phaseOffset; + vec4 SourceSize; + vec4 OriginalSize; + vec4 OutputSize; + uint FrameCount; + float combFilter; + float phaseOffset; } params; #pragma parameter combFilter "comb filter" 0.0 0.0 1.0 1.0 @@ -15,16 +15,16 @@ layout(push_constant) uniform Push layout(std140, set = 0, binding = 0) uniform UBO { - mat4 MVP; + mat4 MVP; } global; //////////////////////////////////////////////////////// -// GTU version 0.50 -// Author: aliaspider - aliaspider@gmail.com -// License: GPLv3 +// GTU version 0.50 +// Author: aliaspider - aliaspider@gmail.com +// License: GPLv3 //////////////////////////////////////////////////////// -#define pi 3.14159265358 +#define pi 3.14159265358 #pragma stage vertex layout(location = 0) in vec4 Position; @@ -34,10 +34,10 @@ layout(location = 1) out float colorPhase; void main() { - gl_Position = global.MVP * Position; - vTexCoord = TexCoord; - vec2 pos = (vTexCoord.xy * params.OutputSize.xy * params.SourceSize.xy * params.SourceSize.zw) - 0.5; - colorPhase = 8.0 + pos.x + pos.y * 4.0 + params.FrameCount * 4.0 + 4.0 + params.phaseOffset * 12.0; + gl_Position = global.MVP * Position; + vTexCoord = TexCoord; + vec2 pos = (vTexCoord.xy * params.OutputSize.xy * params.SourceSize.xy * params.SourceSize.zw) - 0.5; + colorPhase = 8.0 + pos.x + pos.y * 4.0 + params.FrameCount * 4.0 + 4.0 + params.phaseOffset * 12.0; } #pragma stage fragment @@ -49,25 +49,25 @@ layout(set = 0, binding = 2) uniform sampler2D Source; void main() { - float current = texture(Source,vTexCoord.xy).r; - - float signal, I, Q; - - if (params.combFilter > 0.0) - { - float prev6 = texture(Source, vTexCoord.xy - vec2(6.0 * (params.OutputSize.x * params.SourceSize.x * params.SourceSize.z), 0.0)).r; - signal = (current + prev6) / 2.0; - float chromaSignal = current - signal; - I = chromaSignal * cos (colorPhase * (2.0 * pi / 12.0)) * 2.0; - Q = chromaSignal * sin (colorPhase * (2.0 * pi / 12.0)) * 2.0; - } - else - { - signal = current; - I = signal * cos (colorPhase * (2.0 * pi / 12.0))*2.0; - Q = signal * sin (colorPhase * (2.0 * pi / 12.0))*2.0; - } - - FragColor = vec4(signal, I, Q, 1.0); + float current = texture(Source,vTexCoord.xy).r; + + float signal, I, Q; + + if (params.combFilter > 0.0) + { + float prev6 = texture(Source, vTexCoord.xy - vec2(6.0 * (params.OutputSize.x * params.SourceSize.x * params.SourceSize.z), 0.0)).r; + signal = (current + prev6) * 0.5; + float chromaSignal = current - signal; + I = chromaSignal * cos (colorPhase * (2.0 * pi / 12.0)) * 2.0; + Q = chromaSignal * sin (colorPhase * (2.0 * pi / 12.0)) * 2.0; + } + else + { + signal = current; + I = signal * cos (colorPhase * (2.0 * pi / 12.0))*2.0; + Q = signal * sin (colorPhase * (2.0 * pi / 12.0))*2.0; + } + + FragColor = vec4(signal, I, Q, 1.0); } diff --git a/crt/shaders/gtu-famicom/lowPass.slang b/crt/shaders/gtu-famicom/lowPass.slang index c5879bd..53e0357 100644 --- a/crt/shaders/gtu-famicom/lowPass.slang +++ b/crt/shaders/gtu-famicom/lowPass.slang @@ -2,13 +2,13 @@ layout(push_constant) uniform Push { - vec4 OutputSize; - vec4 OriginalSize; - vec4 SourceSize; - float signalResolution; - float addNoise; - float noiseStrength; - uint FrameCount; + vec4 OutputSize; + vec4 OriginalSize; + vec4 SourceSize; + float signalResolution; + float addNoise; + float noiseStrength; + uint FrameCount; } params; #pragma parameter signalResolution "Signal Resolution" 700.0 20.0 2000.0 10.0 @@ -23,12 +23,12 @@ layout(std140, set = 0, binding = 0) uniform UBO } global; //////////////////////////////////////////////////////// -// GTU-famicom version 0.50 -// Author: aliaspider - aliaspider@gmail.com -// License: GPLv3 +// GTU-famicom version 0.50 +// Author: aliaspider - aliaspider@gmail.com +// License: GPLv3 //////////////////////////////////////////////////////// -#define pi 3.14159265358 +#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)) @@ -40,13 +40,15 @@ layout(std140, set = 0, binding = 0) uniform UBO float rand2(vec2 co) { float c = 43758.5453; - float dt= dot(co.xy ,vec2(12.9898,78.233)); - float sn= mod(dt,3.14); + float dt = dot(co.xy, vec2(12.9898, 78.233)); + float sn = mod(dt, 3.14); + return fract(sin(sn) * c); } -float rand(vec2 co){ - return fract(sin(dot(co.xy, vec2(12.9898, 78.233))) * 43758.5453); +float rand(vec2 co) +{ + return fract(sin(dot(co.xy, vec2(12.9898, 78.233))) * 43758.5453); } #pragma stage vertex @@ -56,8 +58,8 @@ layout(location = 0) out vec2 vTexCoord; void main() { - gl_Position = global.MVP * Position; - vTexCoord = TexCoord; + gl_Position = global.MVP * Position; + vTexCoord = TexCoord; } #pragma stage fragment @@ -67,21 +69,22 @@ layout(set = 0, binding = 2) uniform sampler2D Source; void main() { - float offset = fract((vTexCoord.x * params.SourceSize.x) - 0.50001); - float signal = 0.0; - float range = ceil(0.50001 + params.SourceSize.x / params.signalResolution); - range = min(range, 255.0); - - float i; - for (i = 1-range; i < 1+range; i++) - signal+=VAL(i); + float offset = fract((vTexCoord.x * params.SourceSize.x) - 0.50001); + float signal = 0.0; + float range = ceil(0.50001 + params.SourceSize.x / params.signalResolution); + range = min(range, 255.0); + + float i; + for (i = 1 - range; i < 1 + range; i++) + signal += VAL(i); - if(params.addNoise > 0.0) - { - vec2 pos = (vTexCoord.xy * params.SourceSize.xy); - signal -= 0.5; - signal += (rand(vec2(pos.x * pos.y, params.FrameCount)) - 0.50001) * params.noiseStrength; - signal += 0.5; - } - FragColor = vec4(signal); -} \ No newline at end of file + if (params.addNoise > 0.0) + { + vec2 pos = (vTexCoord.xy * params.SourceSize.xy); + signal -= 0.5; + signal += (rand(vec2(pos.x * pos.y, params.FrameCount)) - 0.50001) * params.noiseStrength; + signal += 0.5; + } + + FragColor = vec4(signal); +} diff --git a/crt/shaders/gtu-famicom/scaleX.slang b/crt/shaders/gtu-famicom/scaleX.slang index 31d153f..fb153fb 100644 --- a/crt/shaders/gtu-famicom/scaleX.slang +++ b/crt/shaders/gtu-famicom/scaleX.slang @@ -2,14 +2,14 @@ layout(push_constant) uniform Push { - vec4 SourceSize; - vec4 OriginalSize; - vec4 OutputSize; - uint FrameCount; - float cropOverscan_x; - float signalResolutionY; - float signalResolutionI; - float signalResolutionQ; + vec4 SourceSize; + vec4 OriginalSize; + vec4 OutputSize; + uint FrameCount; + float cropOverscan_x; + float signalResolutionY; + float signalResolutionI; + float signalResolutionQ; } params; #pragma parameter cropOverscan_x "Crop Overscan X" 0.0 0.0 1.0 1.0 @@ -19,23 +19,25 @@ layout(push_constant) uniform Push layout(std140, set = 0, binding = 0) uniform UBO { - mat4 MVP; + mat4 MVP; } global; //////////////////////////////////////////////////////// -// GTU-famicom version 0.50 -// Author: aliaspider - aliaspider@gmail.com -// License: GPLv3 +// GTU-famicom version 0.50 +// Author: aliaspider - aliaspider@gmail.com +// License: GPLv3 //////////////////////////////////////////////////////// -#define pi 3.14159265358 +#define pi 3.14159265358 -float d(float x, float b){ -return (pi*b*min(abs(x)+0.5,1.0/b)); +float d(float x, float b) +{ + return (pi*b*min(abs(x)+0.5,1.0/b)); } -float e(float x, float b){ -return (pi*b*min(max(abs(x)-0.5,-1.0/b),1.0/b)); +float e(float x, float b) +{ + return (pi*b*min(max(abs(x)-0.5,-1.0/b),1.0/b)); } #pragma stage vertex @@ -45,10 +47,12 @@ layout(location = 0) out vec2 vTexCoord; void main() { - gl_Position = global.MVP * Position; - if (params.cropOverscan_x > 0.0) - gl_Position.x /= (240.0 / 256.0); - vTexCoord = TexCoord; + gl_Position = global.MVP * Position; + + if (params.cropOverscan_x > 0.0) + gl_Position.x /= (240.0 / 256.0); + + vTexCoord = TexCoord; } #pragma stage fragment @@ -58,31 +62,32 @@ layout(set = 0, binding = 2) uniform sampler2D Source; void main() { - float offset = fract((vTexCoord.x * params.SourceSize.x) - 0.5); - vec3 YIQ = vec3(0.0); - vec3 RGB = vec3(0.0); - float X; - vec3 c; - float Y = params.signalResolutionY * params.SourceSize.z; - float I = params.signalResolutionI * params.SourceSize.z; - float Q = params.signalResolutionQ * params.SourceSize.z; - - float range = ceil(0.5 + params.SourceSize.x / min(min(params.signalResolutionY, params.signalResolutionI), params.signalResolutionQ)); - - float i; -// for (i=-range;i 0.0) - gl_Position.y /= (224.0 / 240.0); - vTexCoord = TexCoord; + gl_Position = global.MVP * Position; + if (params.cropOverscan_y > 0.0) + gl_Position.y /= (224.0 / 240.0); + + vTexCoord = TexCoord; } #pragma stage fragment -layout(location = 0) in vec2 vTexCoord; +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); - range = min(range, 255.0); - - float i; -// for (i=-range;i 0.0) - for (i=1.0-range;i 0.0) + for (i = 1.0-range; i < range + 1.0; ++i) + tempColor += VAL(i); + else + for (i = 1.0 - range; i < range + 1.0; ++i) + tempColor += VAL_scanlines(i); + + tempColor -= vec3(params.blackLevel); + tempColor *= (params.contrast / vec3(1.0 - params.blackLevel)); + tempColor = pow(tempColor, vec3(params.gamma)); + + FragColor = vec4(tempColor, 1.0); +}