2022-12-06 11:48:10 +11:00
|
|
|
#version 450
|
|
|
|
|
2023-09-29 00:26:48 +10:00
|
|
|
#include "config.inc"
|
2022-12-06 11:48:10 +11:00
|
|
|
#pragma stage vertex
|
|
|
|
layout(location = 0) in vec4 Position;
|
|
|
|
layout(location = 1) in vec2 TexCoord;
|
2023-04-14 01:16:48 +10:00
|
|
|
|
2022-12-06 11:48:10 +11:00
|
|
|
layout(location = 0) out vec2 vTexCoord;
|
2023-04-14 01:16:48 +10:00
|
|
|
layout(location = 1) out float vDynamicSeed;
|
2023-09-29 00:26:48 +10:00
|
|
|
layout(location = 2) out float vFlickering_power;
|
|
|
|
layout(location = 3) out float vDo_flickering;
|
2022-12-06 11:48:10 +11:00
|
|
|
|
|
|
|
#include "includes/functions.include.slang"
|
|
|
|
|
|
|
|
|
|
|
|
void main() {
|
|
|
|
gl_Position = global.MVP * Position;
|
|
|
|
vTexCoord = TexCoord;
|
2023-04-14 01:16:48 +10:00
|
|
|
|
|
|
|
//Generate a seed that changes over time for temporal random noise
|
|
|
|
vDynamicSeed = mod(params.FrameCount, 120.0001);
|
2023-09-29 00:26:48 +10:00
|
|
|
|
|
|
|
vFlickering_power = DO_PIXELGRID * PIXELGRID_INTR_FLICK_POWR;
|
|
|
|
|
|
|
|
vDo_flickering = float ( scanline_have_to_flicker(is_interlaced()) ) ;
|
2022-12-06 11:48:10 +11:00
|
|
|
}
|
|
|
|
|
2023-01-16 01:30:22 +11:00
|
|
|
|
2022-12-06 11:48:10 +11:00
|
|
|
#pragma stage fragment
|
|
|
|
layout(location = 0) in vec2 vTexCoord;
|
2023-04-14 01:16:48 +10:00
|
|
|
layout(location = 1) in float vDynamicSeed;
|
2023-09-29 00:26:48 +10:00
|
|
|
layout(location = 2) in float vFlickering_power;
|
|
|
|
layout(location = 3) in float vDo_flickering;
|
2023-04-14 01:16:48 +10:00
|
|
|
|
|
|
|
layout(location = 0) out vec4 FragColor;
|
2022-12-06 11:48:10 +11:00
|
|
|
|
|
|
|
layout(set = 0, binding = 2) uniform sampler2D Source;
|
|
|
|
|
|
|
|
#include "includes/functions.include.slang"
|
|
|
|
|
|
|
|
vec3 pixel_flickering() {
|
|
|
|
/* Simulates the flickering effect of the interlaced screens.
|
|
|
|
* As I remember, it was visible when a line and the next had high
|
|
|
|
* luminosity differences.
|
2023-03-09 04:13:42 +11:00
|
|
|
* So we need to sample the current line and the previous one
|
2022-12-06 11:48:10 +11:00
|
|
|
* (eventually applying color corrections to both).
|
2023-01-16 01:30:22 +11:00
|
|
|
*
|
2022-12-06 11:48:10 +11:00
|
|
|
* Repeating the following:
|
|
|
|
* On frame 0, return the "clean" pixel
|
|
|
|
* On frame 1, mix the upper pixel with the current one
|
|
|
|
* On frame 2, mix the lower pixel with the current one
|
2023-01-16 01:30:22 +11:00
|
|
|
*
|
2022-12-06 11:48:10 +11:00
|
|
|
* The effect of the mix is the flickering itself, and we modulate
|
|
|
|
* the mix according to the luminance difference between the current
|
|
|
|
* pixel and the mixed one.
|
2023-01-16 01:30:22 +11:00
|
|
|
*
|
2022-12-06 11:48:10 +11:00
|
|
|
* We choose to alternate on a period of 3,
|
|
|
|
* (thus considering the upper pixel and the lower one)
|
2023-01-16 01:30:22 +11:00
|
|
|
* or else the high pixel persistance of lcd displays wont allow
|
2022-12-06 11:48:10 +11:00
|
|
|
* to see the effect (the lcd panel would just mix the pixels by itself (meh).
|
|
|
|
*/
|
2023-01-16 01:30:22 +11:00
|
|
|
|
2023-04-14 01:16:48 +10:00
|
|
|
|
2023-03-09 04:13:42 +11:00
|
|
|
vec3 pixel_cur = texture(Source,vTexCoord).rgb;
|
2022-12-06 11:48:10 +11:00
|
|
|
float mymod = params.FrameCount % 3;
|
2023-01-16 01:30:22 +11:00
|
|
|
|
2022-12-06 11:48:10 +11:00
|
|
|
if (mymod == 0.0) return pixel_cur;
|
|
|
|
float line_tick = (params.OriginalSize.y > MIN_LINES_INTERLACED ) ? 1 : 2 ;
|
|
|
|
vec3 flickline;
|
|
|
|
if (mymod == 1.0 )
|
2023-03-09 04:13:42 +11:00
|
|
|
flickline = texture(Source, vTexCoord + vec2(0.0,params.OriginalSize.w/line_tick)).rgb;
|
2023-01-16 01:30:22 +11:00
|
|
|
else if (mymod == 2.0)
|
2023-03-09 04:13:42 +11:00
|
|
|
flickline = texture(Source, vTexCoord - vec2(0.0,params.OriginalSize.w/line_tick)).rgb;
|
2022-12-06 11:48:10 +11:00
|
|
|
|
2023-04-14 01:16:48 +10:00
|
|
|
float lumdiff = abs(flickline.r + flickline.g + flickline.b - pixel_cur.r - pixel_cur.g - pixel_cur.b);
|
|
|
|
|
2023-09-29 00:26:48 +10:00
|
|
|
lumdiff = min(lumdiff * vFlickering_power, 1.0);
|
2023-04-14 01:16:48 +10:00
|
|
|
return mix(pixel_cur,flickline,lumdiff);
|
|
|
|
|
2023-01-16 01:30:22 +11:00
|
|
|
|
2022-12-06 11:48:10 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void main() {
|
2023-03-09 04:13:42 +11:00
|
|
|
|
2022-12-06 11:48:10 +11:00
|
|
|
|
|
|
|
/* since flickering code needs
|
|
|
|
luminosity difference between 2 vertical lines
|
|
|
|
both have to be processed through color corrections and rgb pixel offsets.
|
|
|
|
before flickering code can operate. (pixel_no_flicker)
|
|
|
|
Therefore we call pixel_no_flicker inside it when we want flickering scanlines
|
|
|
|
and outside id when we dont.
|
|
|
|
*/
|
2023-01-16 01:30:22 +11:00
|
|
|
|
2023-03-09 04:13:42 +11:00
|
|
|
vec3 pixel_out;
|
2023-09-29 00:26:48 +10:00
|
|
|
if (DO_PIXELGRID == 0.0)
|
2023-03-09 04:13:42 +11:00
|
|
|
pixel_out = texture(Source, vTexCoord).rgb;
|
|
|
|
|
2023-09-29 00:26:48 +10:00
|
|
|
else if (vDo_flickering==1.0)
|
2023-03-09 04:13:42 +11:00
|
|
|
pixel_out = pixel_flickering();
|
|
|
|
else
|
|
|
|
//Implicit else: DO_SCANLINES == 1.0 but no flickering needed.
|
|
|
|
pixel_out = texture(Source, vTexCoord).rgb;
|
2022-12-06 11:48:10 +11:00
|
|
|
|
2023-03-09 04:13:42 +11:00
|
|
|
|
|
|
|
if (DO_RF_NOISE > 0.0) {
|
2023-04-14 01:16:48 +10:00
|
|
|
vec3 noise = vec3(random_fast(RF_NOISE_STRENGTH, vTexCoord * vDynamicSeed));
|
2023-03-09 04:13:42 +11:00
|
|
|
pixel_out += noise;
|
2022-12-06 11:48:10 +11:00
|
|
|
}
|
2023-03-09 04:13:42 +11:00
|
|
|
|
|
|
|
//Here lies the blur modifier from ntsc pass to glow.
|
|
|
|
//I'm not expecting any performance hit, since the lookup should have been cached alreadyl
|
|
|
|
float pixel_alpha = texture(Source, vTexCoord).a;
|
|
|
|
|
2023-09-29 00:26:48 +10:00
|
|
|
|
|
|
|
//dots, need in_coords = in_coords - global.flick_and_noise_passSize.zw*0.5 in pixelgrid pass
|
|
|
|
//vec2 integerCoords = floor(vTexCoord.xy * params.OutputSize.xy);
|
|
|
|
//float black = float( mod(integerCoords.x, 2.0) != 0.0 && mod(integerCoords.y, 2.0) != 0.0 );
|
|
|
|
//float black = float( mod(integerCoords.y, 2.0) != 0.0 );
|
|
|
|
//FragColor = vec4(pixel_out*black, pixel_alpha);
|
|
|
|
|
|
|
|
|
2023-03-09 04:13:42 +11:00
|
|
|
FragColor = vec4(pixel_out, pixel_alpha);
|
2023-09-29 00:26:48 +10:00
|
|
|
|
2022-12-06 11:48:10 +11:00
|
|
|
}
|
2023-01-16 01:30:22 +11:00
|
|
|
|
|
|
|
|