update gameboy with parameters and push constants

This commit is contained in:
hunterk 2016-08-02 12:55:54 -05:00
parent e3767d39bc
commit ae4d9317c9
5 changed files with 97 additions and 65 deletions

View file

@ -1,12 +1,18 @@
#version 450
layout(push_constant) uniform Push
{
vec4 OutputSize;
vec4 OriginalSize;
vec4 SourceSize;
vec4 OriginalHistorySize1;
float baseline_alpha;
float response_time;
} registers;
layout(std140, set = 0, binding = 0) uniform UBO
{
mat4 MVP;
vec4 OutputSize;
vec4 OriginalSize;
vec4 SourceSize;
vec4 OriginalHistorySize1;
} global;
////////////////////////////////////////////////////////////////////////////////
@ -15,11 +21,11 @@ layout(std140, set = 0, binding = 0) uniform UBO
// The alpha value of dots in their "off" state
// Does not affect the border region of the screen - [0, 1]
#define baseline_alpha 0.10
#pragma parameter baseline_alpha "Baseline Alpha" 0.10 0.0 1.0 0.01
// Simulate response time
// Higher values result in longer color transition periods - [0, 1]
#define response_time 0.333
#pragma parameter response_time "LCD Response Time" 0.333 0.0 0.777 0.111
///////////////////////////////////////////////////////////////////////////
// //
@ -60,23 +66,23 @@ layout(location = 4) out vec2 HistCoord;
// 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.w)
#define video_scale floor(registers.OutputSize.y * registers.SourceSize.w)
// Size of the scaled video
#define scaled_video_out (global.SourceSize.xy * vec2(video_scale))
#define scaled_video_out (registers.SourceSize.xy * vec2(video_scale))
//it's... half a pixel
#define half_pixel (vec2(0.5) * global.OutputSize.zw)
#define half_pixel (vec2(0.5) * registers.OutputSize.zw)
void main()
{
// Remaps position to integer scaled output
gl_Position = global.MVP * Position / vec4( vec2(global.OutputSize.xy / scaled_video_out), 1.0, 1.0 );
gl_Position = global.MVP * Position / vec4( vec2(registers.OutputSize.xy / scaled_video_out), 1.0, 1.0 );
vTexCoord = TexCoord + half_pixel;
HistCoord = floor(global.OriginalHistorySize1.xy * vTexCoord);
HistCoord = (HistCoord + 0.5) * global.OriginalHistorySize1.zw;
dot_size = global.SourceSize.zw;
one_texel = 1.0 / (global.SourceSize.xy * video_scale);
HistCoord = floor(registers.OriginalHistorySize1.xy * vTexCoord);
HistCoord = (HistCoord + 0.5) * registers.OriginalHistorySize1.zw;
dot_size = registers.SourceSize.zw;
one_texel = 1.0 / (registers.SourceSize.xy * video_scale);
}
////////////////////////////////////////////////////////////////////////////////
@ -104,7 +110,7 @@ layout(set = 0, binding = 10) uniform sampler2D COLOR_PALETTE;
////////////////////////////////////////////////////////////////////////////////
#define foreground_color texture(COLOR_PALETTE, vec2(0.75, 0.5)).rgb //hardcoded to look up the foreground color from the right half of the palette image
//#define rgb_to_alpha(rgb) ( ((rgb.r + rgb.g + rgb.b) / 3.0) + (is_on_dot * vec2(baseline_alpha), 1.0) ) //averages rgb values (allows it to work with color games), modified for contrast and base alpha
//#define rgb_to_alpha(rgb) ( ((rgb.r + rgb.g + rgb.b) / 3.0) + (is_on_dot * vec2(registers.baseline_alpha), 1.0) ) //averages rgb values (allows it to work with color games), modified for contrast and base alpha
// Frame sampling definitions
@ -127,16 +133,16 @@ void main()
// Sample color from the current and previous frames, apply response time modifier
// Response time effect implmented through an exponential dropoff algorithm
vec3 input_rgb = curr_rgb;
input_rgb += (prev0_rgb - input_rgb) * response_time;
input_rgb += (prev1_rgb - input_rgb) * pow(response_time, 2.0);
input_rgb += (prev2_rgb - input_rgb) * pow(response_time, 3.0);
input_rgb += (prev3_rgb - input_rgb) * pow(response_time, 4.0);
input_rgb += (prev4_rgb - input_rgb) * pow(response_time, 5.0);
input_rgb += (prev5_rgb - input_rgb) * pow(response_time, 6.0);
input_rgb += (prev6_rgb - input_rgb) * pow(response_time, 7.0);
input_rgb += (prev0_rgb - input_rgb) * registers.response_time;
input_rgb += (prev1_rgb - input_rgb) * pow(registers.response_time, 2.0);
input_rgb += (prev2_rgb - input_rgb) * pow(registers.response_time, 3.0);
input_rgb += (prev3_rgb - input_rgb) * pow(registers.response_time, 4.0);
input_rgb += (prev4_rgb - input_rgb) * pow(registers.response_time, 5.0);
input_rgb += (prev5_rgb - input_rgb) * pow(registers.response_time, 6.0);
input_rgb += (prev6_rgb - input_rgb) * pow(registers.response_time, 7.0);
float rgb_to_alpha = (input_rgb.r + input_rgb.g + input_rgb.b) * 0.333333333
+ (is_on_dot * baseline_alpha);
+ (is_on_dot * registers.baseline_alpha);
// Apply foreground color and assign alpha value
// Apply the foreground color to all texels -

View file

@ -1,11 +1,17 @@
#version 450
layout(push_constant) uniform Push
{
vec4 OutputSize;
vec4 OriginalSize;
vec4 SourceSize;
float blending_mode;
float adjacent_texel_alpha_blending;
} registers;
layout(std140, set = 0, binding = 0) uniform UBO
{
mat4 MVP;
vec4 OutputSize;
vec4 OriginalSize;
vec4 SourceSize;
} global;
////////////////////////////////////////////////////////////////////////////////
@ -15,10 +21,10 @@ layout(std140, set = 0, binding = 0) uniform UBO
// 0 - only the space between dots is blending
// 1 - all texels are blended
/* TODO/FIXME - When set to zero, frame will be a solid green color */
#define blending_mode 1
#pragma parameter blending_mode "Blending Mode" 1.0 0.0 1.0 1.0
// The amount of alpha swapped between neighboring texels
#define adjacent_texel_alpha_blending 0.1755
#pragma parameter adjacent_texel_alpha_blending "Neighbor Blending" 0.1755 0.0 1.0 0.05
///////////////////////////////////////////////////////////////////////////
// //
@ -62,13 +68,13 @@ void main()
gl_Position = global.MVP * Position;
vTexCoord = TexCoord;
texel = global.SourceSize.zw;
texel = registers.SourceSize.zw;
blur_coords_down = vTexCoord + vec2(0.0, texel.y);
blur_coords_up = vTexCoord + vec2(0.0, -texel.y);
blur_coords_right = vTexCoord + vec2(texel.x, 0.0);
blur_coords_left = vTexCoord + vec2(-texel.x, 0.0);
blur_coords_lower_bound = vec2(0.0);
blur_coords_upper_bound = texel * (global.OutputSize.xy - vec2(2.0));
blur_coords_upper_bound = texel * (registers.OutputSize.xy - vec2(2.0));
}
////////////////////////////////////////////////////////////////////////////////
@ -91,7 +97,7 @@ layout(set = 0, binding = 2) uniform sampler2D Source;
// Fragment definitions //
////////////////////////////////////////////////////////////////////////////////
//#define blending_modifier(color) clamp((color.a == 0) + blending_mode, 0.0, 1.0)
//#define blending_modifier(color) clamp((color.a == 0) + registers.blending_mode, 0.0, 1.0)
void main()
{
@ -121,9 +127,9 @@ void main()
(out_color.a - adjacent_texel_2.a) +
(out_color.a - adjacent_texel_3.a) +
(out_color.a - adjacent_texel_4.a)
) * adjacent_texel_alpha_blending;
) * registers.adjacent_texel_alpha_blending;
out_color.a *= clamp((0.0) + blending_mode, 0.0, 1.0);
out_color.a *= clamp((0.0) + registers.blending_mode, 0.0, 1.0);
FragColor = out_color;
}

View file

@ -1,11 +1,15 @@
#version 450
layout(push_constant) uniform Push
{
vec4 OutputSize;
vec4 OriginalSize;
vec4 SourceSize;
} registers;
layout(std140, set = 0, binding = 0) uniform UBO
{
mat4 MVP;
vec4 OutputSize;
vec4 OriginalSize;
vec4 SourceSize;
} global;
///////////////////////////////////////////////////////////////////////////
@ -42,9 +46,9 @@ void main()
gl_Position = global.MVP * Position;
vTexCoord = TexCoord;
texel = global.SourceSize.zw;
texel = registers.SourceSize.zw;
lower_bound = vec2(0.0);
upper_bound = vec2(texel * (global.OutputSize.xy - 1.0));
upper_bound = vec2(texel * (registers.OutputSize.xy - 1.0));
}
#pragma stage fragment

View file

@ -1,11 +1,15 @@
#version 450
layout(push_constant) uniform Push
{
vec4 OutputSize;
vec4 OriginalSize;
vec4 SourceSize;
} registers;
layout(std140, set = 0, binding = 0) uniform UBO
{
mat4 MVP;
vec4 OutputSize;
vec4 OriginalSize;
vec4 SourceSize;
} global;
///////////////////////////////////////////////////////////////////////////
@ -42,9 +46,9 @@ void main()
gl_Position = global.MVP * Position;
vTexCoord = TexCoord;
texel = global.SourceSize.zw;
texel = registers.SourceSize.zw;
lower_bound = vec2(0.0);
upper_bound = vec2(texel * (global.OutputSize.xy - 1.0));
upper_bound = vec2(texel * (registers.OutputSize.xy - 1.0));
}
#pragma stage fragment

View file

@ -1,52 +1,64 @@
#version 450
layout(push_constant) uniform Push
{
vec4 OutputSize;
vec4 OriginalSize;
vec4 SourceSize;
vec4 PassOutputSize1;
float contrast;
float screen_light;
float pixel_opacity;
float bg_smoothing;
float shadow_opacity;
float shadow_offset_x;
float shadow_offset_y;
float screen_offset_x;
float screen_offset_y;
} registers;
layout(std140, set = 0, binding = 0) uniform UBO
{
mat4 MVP;
vec4 OutputSize;
vec4 OriginalSize;
vec4 SourceSize;
vec4 PassOutputSize1;
} global;
////////////////////////////////////////////////////////////////////////////////
// Config //
////////////////////////////////////////////////////////////////////////////////
// Useful to fine-tune the colors.
// Higher values make the "black" color closer to black - [0, 1] [DEFAULT: 0.95]
#define contrast 0.95
#pragma parameter contrast "Contrast" 0.95 0.0 1.0 0.05
// Controls the ambient light of the screen.
// Lower values darken the screen - [0, 2] [DEFAULT: 1.00]
#define screen_light 1.00
#pragma parameter screen_light "Ambient Screen Light" 1.0 0.0 2.0 0.05
// Controls the opacity of the dot-matrix pixels.
// Lower values make pixels more transparent - [0, 1] [DEFAULT: 1.00]
#define pixel_opacity 1.00
#pragma parameter pixel_opacity "Pixel Opacity" 1.0 0.01 1.0 0.01
// Higher values suppress changes in background color directly beneath
// the foreground to improve image clarity - [0, 1] [DEFAULT: 0.75]
#define bg_smoothing 0.75
#pragma parameter bg_smoothing "Background Smooth" 0.75 0.0 1.0 0.05
// How strongly shadows affect the background
// Higher values darken the shadows - [0, 1] [DEFAULT: 0.55]
#define shadow_opacity 0.55
#pragma parameter shadow_opacity "Shadow Opacity" 0.55 0.01 1.0 0.01
// How far the shadow should be shifted to the
// right in pixels - [-infinity, infinity] [DEFAULT: 1.0]
#define shadow_offset_x 1.0
#pragma parameter shadow_offset_x "Shadow Offset Horiz" 1.0 -5.0 5.0 0.5
// How far the shadow should be shifted
// down in pixels - [-infinity, infinity] [DEFAULT: 1.5]
#define shadow_offset_y 1.5
#pragma parameter shadow_offset_y "Shadow Offset Vert" 1.0 -5.0 5.0 0.5
// Screen offset - [-infinity, infinity] [DEFAULT: 0]
#define screen_offset_x 0
#pragma parameter screen_offset_x "Screen Offset Horiz" 0.0 -5.0 5.0 0.5
// Screen offset - [-infinity, infinity] [DEFAULT: 0]
#define screen_offset_y 0
#pragma parameter screen_offset_y "Screen Offset Vert" 0.0 -5.0 5.0 0.5
///////////////////////////////////////////////////////////////////////////
// //
@ -80,7 +92,7 @@ void main()
gl_Position = global.MVP * Position;
vTexCoord = TexCoord;
texel = global.SourceSize.zw;
texel = registers.SourceSize.zw;
}
////////////////////////////////////////////////////////////////////////////////
@ -99,13 +111,13 @@ layout(set = 0, binding = 4) uniform sampler2D COLOR_PALETTE;
#define bg_color texture(COLOR_PALETTE, vec2(0.25, 0.5))
// Sample the background color from the palette
#define shadow_alpha (contrast * shadow_opacity)
#define shadow_alpha (registers.contrast * registers.shadow_opacity)
// Offset for the shadow
#define shadow_offset vec2(shadow_offset_x * texel.x, shadow_offset_y * texel.y)
#define shadow_offset vec2(registers.shadow_offset_x * texel.x, registers.shadow_offset_y * texel.y)
// Offset for the entire screen
#define screen_offset vec2(screen_offset_x * texel.x, screen_offset_y * texel.y)
#define screen_offset vec2(registers.screen_offset_x * texel.x, registers.screen_offset_y * texel.y)
////////////////////////////////////////////////////////////////////////////////
// Fragment shader //
@ -113,8 +125,8 @@ layout(set = 0, binding = 4) uniform sampler2D COLOR_PALETTE;
void main()
{
vec2 tex = floor(global.PassOutputSize1.xy * vTexCoord);
tex = (tex + 0.5) * global.PassOutputSize1.zw;
vec2 tex = floor(registers.PassOutputSize1.xy * vTexCoord);
tex = (tex + 0.5) * registers.PassOutputSize1.zw;
// Sample all the relevant textures
vec4 foreground = texture(PassOutput1, tex - screen_offset);
@ -129,7 +141,7 @@ void main()
if ( foreground.a > 0.0 )
bg_test = 1.0;
background -= (background - 0.5) * bg_smoothing * bg_test;
background -= (background - 0.5) * registers.bg_smoothing * bg_test;
// Allows for highlights,
// background = bg_color when the background color is 0.5 gray
@ -146,7 +158,7 @@ void main()
vec4 out_color = (shadows * shadows.a * shadow_alpha) + (background * (1 - shadows.a * shadow_alpha));
// Foreground is alpha blended with the shadowed background
out_color = (foreground * foreground.a * contrast) + (out_color * (screen_light - foreground.a * contrast * pixel_opacity));
out_color = (foreground * foreground.a * registers.contrast) + (out_color * (registers.screen_light - foreground.a * registers.contrast * registers.pixel_opacity));
FragColor = out_color;
}