mirror of
https://github.com/italicsjenga/slang-shaders.git
synced 2025-02-17 07:27:43 +11:00
Merge pull request #73 from Monroe88/handheld-color
Handheld color shader updates
This commit is contained in:
commit
b17e116f35
10 changed files with 152 additions and 34 deletions
6
handheld/gbc-gambatte-color.slangp
Normal file
6
handheld/gbc-gambatte-color.slangp
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
shaders = 1
|
||||||
|
|
||||||
|
shader0 = shaders/color/gbc-gambatte-color.slang
|
||||||
|
filter_linear0 = false
|
||||||
|
scale_type_0 = source
|
||||||
|
scale0 = 1.0
|
|
@ -29,4 +29,4 @@ gain = "1.500000"
|
||||||
gamma = "2.200000"
|
gamma = "2.200000"
|
||||||
blacklevel = "0.000000"
|
blacklevel = "0.000000"
|
||||||
ambient = "0.000000"
|
ambient = "0.000000"
|
||||||
BGR = "1.000000"
|
BGR = "0.0"
|
||||||
|
|
|
@ -24,4 +24,4 @@ gain = "1.500000"
|
||||||
gamma = "2.200000"
|
gamma = "2.200000"
|
||||||
blacklevel = "0.000000"
|
blacklevel = "0.000000"
|
||||||
ambient = "0.000000"
|
ambient = "0.000000"
|
||||||
BGR = "1.000000"
|
BGR = "0.0"
|
||||||
|
|
|
@ -21,7 +21,7 @@ layout(std140, set = 0, binding = 0) uniform UBO
|
||||||
*/
|
*/
|
||||||
// Shader that replicates the LCD dynamics from a GameBoy Advance
|
// Shader that replicates the LCD dynamics from a GameBoy Advance
|
||||||
|
|
||||||
#pragma parameter darken_screen "Darken Screen" 0.5 0.0 2.0 0.05
|
#pragma parameter darken_screen "Darken Screen" 0.5 -0.25 2.0 0.05
|
||||||
|
|
||||||
#define target_gamma 2.2
|
#define target_gamma 2.2
|
||||||
#define display_gamma 2.2
|
#define display_gamma 2.2
|
||||||
|
@ -31,15 +31,15 @@ layout(std140, set = 0, binding = 0) uniform UBO
|
||||||
#define blr 0.0
|
#define blr 0.0
|
||||||
#define blg 0.0
|
#define blg 0.0
|
||||||
#define blb 0.0
|
#define blb 0.0
|
||||||
#define r 0.81
|
#define r 0.845
|
||||||
#define g 0.67
|
#define g 0.68
|
||||||
#define b 0.73
|
#define b 0.755
|
||||||
#define rg 0.09
|
#define rg 0.09
|
||||||
#define rb 0.15
|
#define rb 0.16
|
||||||
#define gr 0.23
|
#define gr 0.17
|
||||||
#define gb 0.12
|
#define gb 0.085
|
||||||
#define br -0.04
|
#define br -0.015
|
||||||
#define bg 0.24
|
#define bg 0.23
|
||||||
#define overscan_percent_x 0.0
|
#define overscan_percent_x 0.0
|
||||||
#define overscan_percent_y 0.0
|
#define overscan_percent_y 0.0
|
||||||
|
|
||||||
|
|
|
@ -3,13 +3,18 @@
|
||||||
/*
|
/*
|
||||||
GBC Color Correction Shader
|
GBC Color Correction Shader
|
||||||
A shader that replicates the LCD dynamics from a Game Boy Color
|
A shader that replicates the LCD dynamics from a Game Boy Color
|
||||||
Color values are derived from Gambatte's color correction implementation.
|
Color values are derived from Gambatte's color correction implementation, with some tweaks.
|
||||||
|
|
||||||
Based on Color Mangler
|
Based on Color Mangler
|
||||||
Author: hunterk
|
Author: hunterk
|
||||||
License: Public domain
|
License: Public domain
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
layout(push_constant) uniform Push
|
||||||
|
{
|
||||||
|
float darken_screen;
|
||||||
|
} params;
|
||||||
|
|
||||||
layout(std140, set = 0, binding = 0) uniform UBO
|
layout(std140, set = 0, binding = 0) uniform UBO
|
||||||
{
|
{
|
||||||
mat4 MVP;
|
mat4 MVP;
|
||||||
|
@ -18,18 +23,22 @@ layout(std140, set = 0, binding = 0) uniform UBO
|
||||||
vec4 SourceSize;
|
vec4 SourceSize;
|
||||||
} global;
|
} global;
|
||||||
|
|
||||||
|
#pragma parameter darken_screen "Darken Screen" 0.0 -0.25 2.0 0.05
|
||||||
|
|
||||||
|
#define target_gamma 2.2
|
||||||
|
#define display_gamma 2.2
|
||||||
#define blr 0.0
|
#define blr 0.0
|
||||||
#define blg 0.0
|
#define blg 0.0
|
||||||
#define blb 0.0
|
#define blb 0.0
|
||||||
#define r 0.78824
|
#define r 0.78824
|
||||||
#define g 0.72941
|
#define g 0.72941
|
||||||
#define b 0.66667
|
#define b 0.82
|
||||||
#define rg 0.00
|
#define rg 0.025
|
||||||
#define rb 0.18039
|
#define rb 0.12039
|
||||||
#define gr 0.12157
|
#define gr 0.12157
|
||||||
#define gb 0.12157
|
#define gb 0.12157
|
||||||
#define br 0.05882
|
#define br 0.0
|
||||||
#define bg 0.24314
|
#define bg 0.275000
|
||||||
|
|
||||||
#pragma stage vertex
|
#pragma stage vertex
|
||||||
layout(location = 0) in vec4 Position;
|
layout(location = 0) in vec4 Position;
|
||||||
|
@ -49,14 +58,14 @@ layout(set = 0, binding = 2) uniform sampler2D Source;
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
vec4 screen = texture(Source, vTexCoord);
|
vec4 screen = pow(texture(Source, vTexCoord), vec4(target_gamma + params.darken_screen)).rgba;
|
||||||
|
|
||||||
// r g b black
|
// red green blue alpha ; alpha does nothing for our purposes
|
||||||
mat4 color = mat4(r, rg, rb, 0.0, //red channel
|
mat4 color = mat4(r, rg, rb, 0.0, //red
|
||||||
gr, g, gb, 0.0, //green channel
|
gr, g, gb, 0.0, //green
|
||||||
br, bg, b, 0.0, //blue channel
|
br, bg, b, 0.0, //blue
|
||||||
blr, blg, blb, 0.0); //alpha channel; these numbers do nothing for our purposes.
|
blr, blg, blb, 0.0); //black
|
||||||
|
|
||||||
screen = color * screen;
|
screen = color * screen;
|
||||||
FragColor = screen;
|
FragColor = pow(screen, vec4(1.0 / display_gamma));
|
||||||
}
|
}
|
||||||
|
|
103
handheld/shaders/color/gbc-gambatte-color.slang
Normal file
103
handheld/shaders/color/gbc-gambatte-color.slang
Normal file
|
@ -0,0 +1,103 @@
|
||||||
|
#version 450
|
||||||
|
|
||||||
|
/*
|
||||||
|
Gambatte Color
|
||||||
|
A Slang/GLSL port of the color correction option on Gambatte emulator
|
||||||
|
Ported by: RiskyJumps
|
||||||
|
License: Public domain
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
OPTIONS:
|
||||||
|
|
||||||
|
INT_OPS (default: Disabled)
|
||||||
|
It's supposed to be more "accurate" but it's a waste. Not recommended
|
||||||
|
*/
|
||||||
|
//#define INT_OPS
|
||||||
|
|
||||||
|
/*
|
||||||
|
SIMULATE_INT (default: Disabled)
|
||||||
|
Only meaningful if INT_OPS is disabled. It truncates floats. Then
|
||||||
|
again, it's supposed to be more "accurate" but it looks just
|
||||||
|
too similar. It's still a waste. Not recommended.
|
||||||
|
*/
|
||||||
|
//#define SIMULATE_INT
|
||||||
|
|
||||||
|
layout(std140, set = 0, binding = 0) uniform UBO
|
||||||
|
{
|
||||||
|
mat4 MVP;
|
||||||
|
vec4 OutputSize;
|
||||||
|
vec4 OriginalSize;
|
||||||
|
vec4 SourceSize;
|
||||||
|
} global;
|
||||||
|
|
||||||
|
#pragma stage vertex
|
||||||
|
layout(location = 0) in vec4 Position;
|
||||||
|
layout(location = 1) in vec2 TexCoord;
|
||||||
|
layout(location = 0) out vec2 vTexCoord;
|
||||||
|
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
gl_Position = global.MVP * Position;
|
||||||
|
vTexCoord = TexCoord;
|
||||||
|
}
|
||||||
|
|
||||||
|
#pragma stage fragment
|
||||||
|
layout(location = 0) in vec2 vTexCoord;
|
||||||
|
layout(location = 0) out vec4 FragColor;
|
||||||
|
layout(set = 0, binding = 2) uniform sampler2D Source;
|
||||||
|
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
vec4 color = texture(Source, vTexCoord);
|
||||||
|
|
||||||
|
#ifdef INT_OPS
|
||||||
|
color.rgb *= 255.0;
|
||||||
|
|
||||||
|
int r = (int)color.r;
|
||||||
|
int g = (int)color.g;
|
||||||
|
int b = (int)color.b;
|
||||||
|
|
||||||
|
int R = (r * 13 + g * 2 + b) >> 4;
|
||||||
|
int G = (g * 3 + b) >> 2;
|
||||||
|
int B = (r * 3 + g * 2 + b * 11) >> 4;
|
||||||
|
|
||||||
|
color.rgb = vec3((float)R, (float)G, (float)B);
|
||||||
|
color.rgb /= 255.0;
|
||||||
|
|
||||||
|
FragColor = color;
|
||||||
|
return;
|
||||||
|
|
||||||
|
#else
|
||||||
|
mat3 color_correction = mat3(
|
||||||
|
13.0, 2.0, 1.0,
|
||||||
|
0.0, 3.0, 1.0,
|
||||||
|
3.0, 2.0, 11.0
|
||||||
|
);
|
||||||
|
|
||||||
|
mat3 scale = mat3(
|
||||||
|
1.0/16.0, 0.0, 0.0,
|
||||||
|
0.0, 1.0/4.0, 0.0,
|
||||||
|
0.0, 0.0, 1.0/16.0
|
||||||
|
);
|
||||||
|
|
||||||
|
color_correction *= scale;
|
||||||
|
|
||||||
|
#ifdef SIMULATE_INT
|
||||||
|
color.rgb *= 255.0;
|
||||||
|
color.rgb = floor(color.rgb);
|
||||||
|
color.rgb *= color_correction;
|
||||||
|
color.rgb = floor(color.rgb);
|
||||||
|
color.rgb /= 255.0;
|
||||||
|
FragColor = color;
|
||||||
|
return;
|
||||||
|
|
||||||
|
#else
|
||||||
|
color.rgb *= color_correction;
|
||||||
|
FragColor = color;
|
||||||
|
return;
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
||||||
|
}
|
|
@ -24,15 +24,15 @@ layout(std140, set = 0, binding = 0) uniform UBO
|
||||||
#define blr 0.0
|
#define blr 0.0
|
||||||
#define blg 0.0
|
#define blg 0.0
|
||||||
#define blb 0.0
|
#define blb 0.0
|
||||||
#define r 0.82
|
#define r 0.83
|
||||||
#define g 0.66
|
#define g 0.65
|
||||||
#define b 0.81
|
#define b 0.765
|
||||||
#define rg 0.085
|
#define rg 0.105
|
||||||
#define rb 0.085
|
#define rb 0.105
|
||||||
#define gr 0.25
|
#define gr 0.20
|
||||||
#define gb 0.105
|
#define gb 0.13
|
||||||
#define br -0.07
|
#define br -0.03
|
||||||
#define bg 0.255
|
#define bg 0.245
|
||||||
#define overscan_percent_x 0.0
|
#define overscan_percent_x 0.0
|
||||||
#define overscan_percent_y 0.0
|
#define overscan_percent_y 0.0
|
||||||
|
|
||||||
|
|
Binary file not shown.
Before Width: | Height: | Size: 33 KiB After Width: | Height: | Size: 32 KiB |
Binary file not shown.
Before Width: | Height: | Size: 33 KiB After Width: | Height: | Size: 33 KiB |
Binary file not shown.
Before Width: | Height: | Size: 33 KiB After Width: | Height: | Size: 34 KiB |
Loading…
Add table
Reference in a new issue