From 70d30ead4bf66b61bd7f07143ce630c617eb2298 Mon Sep 17 00:00:00 2001 From: Arzed Five Date: Sun, 24 Jul 2016 03:59:55 +0100 Subject: [PATCH] A couple of MAD optimizations, some formatting and ensure the shader works a little bit better. If the blending_mode macro on gb-pass1 is set to 0, we'll get only the green background color. --- handheld/gameboy/shader-files/gb-pass0.slang | 5 +++-- handheld/gameboy/shader-files/gb-pass1.slang | 3 ++- handheld/gameboy/shader-files/gb-pass3.slang | 20 ++++++++++---------- 3 files changed, 15 insertions(+), 13 deletions(-) diff --git a/handheld/gameboy/shader-files/gb-pass0.slang b/handheld/gameboy/shader-files/gb-pass0.slang index fb17c19..69f0671 100644 --- a/handheld/gameboy/shader-files/gb-pass0.slang +++ b/handheld/gameboy/shader-files/gb-pass0.slang @@ -59,7 +59,7 @@ layout(location = 3) out vec2 one_texel; // Largest integer scale of input video that will fit in the current output (y axis would typically be limiting on widescreens) -#define video_scale floor(global.OutputSize.y / global.SourceSize.y) +#define video_scale floor(global.OutputSize.y * global.SourceSize.w) // Size of the scaled video #define scaled_video_out (global.SourceSize.xy * vec2(video_scale)) @@ -130,7 +130,8 @@ void main() input_rgb += (prev5_rgb - input_rgb) * pow(response_time, 6.0); input_rgb += (prev6_rgb - input_rgb) * pow(response_time, 7.0); - float rgb_to_alpha = (input_rgb.r + input_rgb.g + input_rgb.b) / 3.0 + (is_on_dot * baseline_alpha); + float rgb_to_alpha = (input_rgb.r + input_rgb.g + input_rgb.b) * 0.333333333 + + (is_on_dot * baseline_alpha); // Apply foreground color and assign alpha value // Apply the foreground color to all texels - diff --git a/handheld/gameboy/shader-files/gb-pass1.slang b/handheld/gameboy/shader-files/gb-pass1.slang index 02fa760..d2fdfdf 100644 --- a/handheld/gameboy/shader-files/gb-pass1.slang +++ b/handheld/gameboy/shader-files/gb-pass1.slang @@ -14,7 +14,8 @@ layout(std140, set = 0, binding = 0) uniform UBO // 0 - only the space between dots is blending // 1 - all texels are blended -#define blending_mode 0 +/* TODO/FIXME - When set to zero, frame will be a solid green color */ +#define blending_mode 1 // The amount of alpha swapped between neighboring texels #define adjacent_texel_alpha_blending 0.1755 diff --git a/handheld/gameboy/shader-files/gb-pass3.slang b/handheld/gameboy/shader-files/gb-pass3.slang index 75ce0ca..3f2b1a1 100644 --- a/handheld/gameboy/shader-files/gb-pass3.slang +++ b/handheld/gameboy/shader-files/gb-pass3.slang @@ -39,12 +39,12 @@ layout(location = 3) out vec2 upper_bound; void main() { - gl_Position = global.MVP * Position; - vTexCoord = TexCoord; - - texel = global.SourceSize.zw; - lower_bound = vec2(0.0); - upper_bound = vec2(texel * (global.OutputSize.xy - 1.0)); + gl_Position = global.MVP * Position; + vTexCoord = TexCoord; + + texel = global.SourceSize.zw; + lower_bound = vec2(0.0); + upper_bound = vec2(texel * (global.OutputSize.xy - 1.0)); } #pragma stage fragment @@ -98,16 +98,16 @@ void main() 0.10164546793794160274995705611009, 0.08167444001912718529866079800870 ); - //sample the current fragment and apply its weight + // Sample the current fragment and apply its weight vec4 out_color = texture(Source, clamp(vTexCoord, lower_bound, upper_bound)) * weights[0]; - //iterate across the offsets in both directions sampling texels and adding their weighted alpha values to the total + // Iterate across the offsets in both directions sampling texels + // and adding their weighted alpha values to the total for (int i = 1; i < 5; i++) { out_color.a += texture(Source, clamp(vTexCoord + vec2(0.0, offsets[i] * texel.y), lower_bound, upper_bound)).a * weights[i]; out_color.a += texture(Source, clamp(vTexCoord - vec2(0.0, offsets[i] * texel.y), lower_bound, upper_bound)).a * weights[i]; } - //return the new value - FragColor = vec4(out_color.rgb, 1.0); + FragColor = out_color; }