Skip to content

Commit

Permalink
Update lcd*x and authentic_gbc to use OriginalSize (#665)
Browse files Browse the repository at this point in the history
  • Loading branch information
fishcu authored Dec 24, 2024
1 parent e00bc15 commit 0e2513d
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 18 deletions.
15 changes: 8 additions & 7 deletions handheld/shaders/authentic_gbc/authentic_gbc.slang
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#version 450

/*
Authentic GBC v1.0 by fishku
Authentic GBC by fishku
Copyright (C) 2024
Public domain license (CC0)

Expand All @@ -15,14 +15,15 @@
https://www.reddit.com/r/AnaloguePocket/comments/1azaxgd/ive_made_some_improvements_to_my_analogue_pocket/

Changelog:
v1.1: Use OriginalSize instead of SourceSize to better work with combined presets.
v1.0: Initial release.
*/

#include "parameters.inc"
#include "shared.inc"

layout(push_constant) uniform Push {
vec4 SourceSize;
vec4 OriginalSize;
vec4 OutputSize;
float AUTH_GBC_BRIG;
}
Expand All @@ -44,7 +45,7 @@ layout(location = 5) out float subpx_orig_y;
void main() {
gl_Position = global.MVP * Position;

auth_gbc_vert_shader(param.SourceSize.xy, param.OutputSize.xy,
auth_gbc_vert_shader(param.OriginalSize.xy, param.OutputSize.xy,
param.AUTH_GBC_BRIG, TexCoord, px_rect, tx_coord,
tx_to_px, subpx_size, notch_size, subpx_orig_y);
}
Expand Down Expand Up @@ -79,10 +80,10 @@ void main() {
// Sample.
// Apply square for fast "gamma correction".
vec3 samples[] = {
texture(Source, (tx_origins[0] + 0.5) * param.SourceSize.zw).rgb,
texture(Source, (tx_origins[1] + 0.5) * param.SourceSize.zw).rgb,
texture(Source, (tx_origins[2] + 0.5) * param.SourceSize.zw).rgb,
texture(Source, (tx_origins[3] + 0.5) * param.SourceSize.zw).rgb};
texture(Source, (tx_origins[0] + 0.5) * param.OriginalSize.zw).rgb,
texture(Source, (tx_origins[1] + 0.5) * param.OriginalSize.zw).rgb,
texture(Source, (tx_origins[2] + 0.5) * param.OriginalSize.zw).rgb,
texture(Source, (tx_origins[3] + 0.5) * param.OriginalSize.zw).rgb};
samples[0] *= samples[0];
samples[1] *= samples[1];
samples[2] *= samples[2];
Expand Down
4 changes: 2 additions & 2 deletions handheld/shaders/authentic_gbc/parameters.inc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// See the main shader file for copyright and other information.

// clang-format off
#pragma parameter AUTH_GBC_SETTINGS "=== Authentic GBC v1.0 settings ===" 0.0 0.0 1.0 1.0
#pragma parameter AUTH_GBC_BRIG "Overbrighten" 0.0 -0.1 1.0 0.05
#pragma parameter AUTH_GBC_SETTINGS "=== Authentic GBC v1.1 settings ===" 0.0 0.0 1.0 1.0
#pragma parameter AUTH_GBC_BRIG "Overbrighten" 0.15 -0.1 1.0 0.05
// clang-format on
4 changes: 2 additions & 2 deletions handheld/shaders/lcd1x.slang
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,14 @@ void main()
// Generate LCD grid effect
// > Note the 0.25 pixel offset -> required to ensure that
// scanlines occur *between* pixels
vec2 pixelCoord = vTexCoord.xy * registers.SourceSize.xy;
vec2 pixelCoord = vTexCoord * registers.OriginalSize.xy;
vec2 angle = 2.0 * PI * (pixelCoord - 0.25);

float yfactor = (registers.BRIGHTEN_SCANLINES + sin(angle.y)) / (registers.BRIGHTEN_SCANLINES + 1.0);
float xfactor = (registers.BRIGHTEN_LCD + sin(angle.x)) / (registers.BRIGHTEN_LCD + 1.0);

// Get colour sample
vec3 colour = texture(Source, registers.SourceSize.zw * pixelCoord.xy).rgb;
vec3 colour = texture(Source, vTexCoord).rgb;

// Apply LCD grid effect
colour.rgb = yfactor * xfactor * colour.rgb;
Expand Down
6 changes: 3 additions & 3 deletions handheld/shaders/lcd1x_nds.slang
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,14 @@ void main()
// scanlines occur *between* pixels
// > Divide pixel coordinate by current scale factor
// (input_video_height / nds_screen_height)
vec2 pixelCoord = vTexCoord.xy * registers.SourceSize.xy;
vec2 angle = 2.0 * PI * ((pixelCoord * NDS_SCREEN_HEIGHT * registers.SourceSize.w) - 0.25);
vec2 pixelCoord = vTexCoord * registers.OriginalSize.xy;
vec2 angle = 2.0 * PI * ((pixelCoord * NDS_SCREEN_HEIGHT * registers.OriginalSize.w) - 0.25);

float yfactor = (registers.BRIGHTEN_SCANLINES + sin(angle.y)) / (registers.BRIGHTEN_SCANLINES + 1.0);
float xfactor = (registers.BRIGHTEN_LCD + sin(angle.x)) / (registers.BRIGHTEN_LCD + 1.0);

// Get colour sample
vec3 colour = texture(Source, registers.SourceSize.zw * pixelCoord.xy).rgb;
vec3 colour = texture(Source, vTexCoord).rgb;

// Apply colour correction
colour.rgb = pow(colour.rgb, vec3(TARGET_GAMMA));
Expand Down
6 changes: 3 additions & 3 deletions handheld/shaders/lcd1x_psp.slang
Original file line number Diff line number Diff line change
Expand Up @@ -93,14 +93,14 @@ void main()
// scanlines occur *between* pixels
// > Divide pixel coordinate by current scale factor
// (input_video_height / psp_screen_height)
vec2 pixelCoord = vTexCoord.xy * registers.SourceSize.xy;
vec2 angle = 2.0 * PI * ((pixelCoord * PSP_SCREEN_HEIGHT * registers.SourceSize.w) - 0.25);
vec2 pixelCoord = vTexCoord * registers.OriginalSize.xy;
vec2 angle = 2.0 * PI * ((pixelCoord * PSP_SCREEN_HEIGHT * registers.OriginalSize.w) - 0.25);

float yfactor = (registers.BRIGHTEN_SCANLINES + sin(angle.y)) / (registers.BRIGHTEN_SCANLINES + 1.0);
float xfactor = (registers.BRIGHTEN_LCD + sin(angle.x)) / (registers.BRIGHTEN_LCD + 1.0);

// Get colour sample
vec3 colour = texture(Source, registers.SourceSize.zw * pixelCoord.xy).rgb;
vec3 colour = texture(Source, vTexCoord).rgb;

// Apply colour correction
colour.rgb = pow(colour.rgb, vec3(TARGET_GAMMA));
Expand Down
2 changes: 1 addition & 1 deletion handheld/shaders/lcd3x.slang
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ layout(std140, set = 0, binding = 0) uniform UBO
mat4 MVP;
} global;

vec2 omega = vec2(3.141592654) * vec2(2.0) * params.SourceSize.xy;
vec2 omega = vec2(3.141592654) * vec2(2.0) * params.OriginalSize.xy;
const vec3 offsets = vec3(3.141592654) * vec3(1.0/2,1.0/2 - 2.0/3,1.0/2-4.0/3);

#pragma stage vertex
Expand Down

0 comments on commit 0e2513d

Please sign in to comment.