From a3636335584c07a9f0e6deef4e24e159c59670de Mon Sep 17 00:00:00 2001 From: Monroe88 Date: Sat, 13 Aug 2016 11:08:45 -0500 Subject: [PATCH] Add Pokefan531's newest color shaders. Keep original gba-color around as gba-color-old. --- handheld/gba-color.slangp | 5 + handheld/nds-color.slangp | 5 + handheld/psp-color.slangp | 5 + handheld/shaders/color/gba-color-old.slang | 77 ++++++++++ handheld/shaders/color/gba-color.slang | 158 +++++++++++---------- handheld/shaders/color/nds-color.slang | 75 ++++++++++ handheld/shaders/color/psp-color.slang | 75 ++++++++++ handheld/shaders/color/vba-color.slang | 81 +++++++++++ handheld/vba-color.slangp | 5 + 9 files changed, 409 insertions(+), 77 deletions(-) create mode 100644 handheld/gba-color.slangp create mode 100644 handheld/nds-color.slangp create mode 100644 handheld/psp-color.slangp create mode 100644 handheld/shaders/color/gba-color-old.slang create mode 100644 handheld/shaders/color/nds-color.slang create mode 100644 handheld/shaders/color/psp-color.slang create mode 100644 handheld/shaders/color/vba-color.slang create mode 100644 handheld/vba-color.slangp diff --git a/handheld/gba-color.slangp b/handheld/gba-color.slangp new file mode 100644 index 0000000..58c2fc4 --- /dev/null +++ b/handheld/gba-color.slangp @@ -0,0 +1,5 @@ +shaders = 1 + +shader0 = shaders/color/gba-color.slang +filter_linear0 = false +scale_type_0 = source diff --git a/handheld/nds-color.slangp b/handheld/nds-color.slangp new file mode 100644 index 0000000..dc19fc9 --- /dev/null +++ b/handheld/nds-color.slangp @@ -0,0 +1,5 @@ +shaders = 1 + +shader0 = shaders/color/nds-color.slang +filter_linear0 = false +scale_type_0 = source diff --git a/handheld/psp-color.slangp b/handheld/psp-color.slangp new file mode 100644 index 0000000..855873e --- /dev/null +++ b/handheld/psp-color.slangp @@ -0,0 +1,5 @@ +shaders = 1 + +shader0 = shaders/color/psp-color.slang +filter_linear0 = false +scale_type_0 = source diff --git a/handheld/shaders/color/gba-color-old.slang b/handheld/shaders/color/gba-color-old.slang new file mode 100644 index 0000000..6242688 --- /dev/null +++ b/handheld/shaders/color/gba-color-old.slang @@ -0,0 +1,77 @@ +#version 450 +/* + Author: Pokefan531 + License: Public domain +*/ + +// Shader that replicates the LCD dynamics from a GameBoy Advance + +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 = 1) in vec2 FragCoord; +layout(location = 0) out vec4 FragColor; +layout(set = 0, binding = 2) uniform sampler2D Source; + + +vec3 grayscale(vec3 col) +{ + // Non-conventional way to do grayscale, + // but bSNES uses this as grayscale value. + return vec3(dot(col, vec3(0.2126, 0.7152, 0.0722))); +} + +void main() +{ +//part 1 + float saturation = 1.0; + float Display_gamma = 1.02; + float CRT_gamma = 2.4; + float luminance = 1.0; + + vec3 gamma = vec3(CRT_gamma / Display_gamma); + vec3 res = texture(Source, vTexCoord).xyz; + res = mix(grayscale(res), res, saturation); // Apply saturation + res = pow(res, gamma.rgb); // Apply gamma + vec4 c = vec4(clamp(res * luminance, 0.0, 1.0), 1.0); + +//part 2 + float r = c.x; + float g = c.y; + float b = c.z; + float a = c.w; + float w = r * 0.714 + g * 0.251 + b * 0.000; + float q = r * 0.071 + g * 0.643 + b * 0.216; + float e = r * 0.071 + g * 0.216 + b * 0.643; + +//part 3 + saturation = 1.0; + Display_gamma = 3.6; + CRT_gamma = 2.4; + luminance = 1.01; + + res = vec3(w, q, e); + gamma = gamma = vec3(CRT_gamma / Display_gamma); + res = mix(grayscale(res), res, saturation); // Apply saturation + res = pow(res, gamma.rgb); // Apply gamma + + FragColor = vec4(clamp(res * luminance, 0.0, 1.0), 1.0); +} diff --git a/handheld/shaders/color/gba-color.slang b/handheld/shaders/color/gba-color.slang index 6242688..ded2878 100644 --- a/handheld/shaders/color/gba-color.slang +++ b/handheld/shaders/color/gba-color.slang @@ -1,77 +1,81 @@ -#version 450 -/* - Author: Pokefan531 - License: Public domain -*/ - -// Shader that replicates the LCD dynamics from a GameBoy Advance - -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 = 1) in vec2 FragCoord; -layout(location = 0) out vec4 FragColor; -layout(set = 0, binding = 2) uniform sampler2D Source; - - -vec3 grayscale(vec3 col) -{ - // Non-conventional way to do grayscale, - // but bSNES uses this as grayscale value. - return vec3(dot(col, vec3(0.2126, 0.7152, 0.0722))); -} - -void main() -{ -//part 1 - float saturation = 1.0; - float Display_gamma = 1.02; - float CRT_gamma = 2.4; - float luminance = 1.0; - - vec3 gamma = vec3(CRT_gamma / Display_gamma); - vec3 res = texture(Source, vTexCoord).xyz; - res = mix(grayscale(res), res, saturation); // Apply saturation - res = pow(res, gamma.rgb); // Apply gamma - vec4 c = vec4(clamp(res * luminance, 0.0, 1.0), 1.0); - -//part 2 - float r = c.x; - float g = c.y; - float b = c.z; - float a = c.w; - float w = r * 0.714 + g * 0.251 + b * 0.000; - float q = r * 0.071 + g * 0.643 + b * 0.216; - float e = r * 0.071 + g * 0.216 + b * 0.643; - -//part 3 - saturation = 1.0; - Display_gamma = 3.6; - CRT_gamma = 2.4; - luminance = 1.01; - - res = vec3(w, q, e); - gamma = gamma = vec3(CRT_gamma / Display_gamma); - res = mix(grayscale(res), res, saturation); // Apply saturation - res = pow(res, gamma.rgb); // Apply gamma - - FragColor = vec4(clamp(res * luminance, 0.0, 1.0), 1.0); -} +#version 450 + +layout(push_constant) uniform Push +{ + float display_gamma; +} params; + +layout(std140, set = 0, binding = 0) uniform UBO +{ + mat4 MVP; + vec4 OutputSize; + vec4 OriginalSize; + vec4 SourceSize; +} global; + +/* + Shader Modified: Pokefan531 + Color Mangler + Author: hunterk + License: Public domain +*/ +// Shader that replicates the LCD dynamics from a GameBoy Advance + +#pragma parameter display_gamma "Light Intensity" 1.8 1.0 2.5 0.05 + +#define target_gamma 2.2 +#define sat 1.0 +#define lum 1.0 +#define contrast 1.0 +#define blr 0.0 +#define blg 0.0 +#define blb 0.0 +#define r 0.84 +#define g 0.67 +#define b 0.74 +#define rg 0.08 +#define rb 0.17 +#define gr 0.16 +#define gb 0.09 +#define br 0.0 +#define bg 0.26 +#define overscan_percent_x 0.0 +#define overscan_percent_y 0.0 + +#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 screen = pow(texture(Source, vTexCoord), vec4(target_gamma)).rgba; + vec4 avglum = vec4(0.5); + screen = mix(screen, avglum, (1.0 - contrast)); + + // r g b black +mat4 color = mat4(r, rg, rb, 0.0, //red channel + gr, g, gb, 0.0, //green channel + br, bg, b, 0.0, //blue channel + blr, blg, blb, 0.0); //alpha channel; these numbers do nothing for our purposes. + +mat4 adjust = mat4((1.0 - sat) * 0.3086 + sat, (1.0 - sat) * 0.3086, (1.0 - sat) * 0.3086, 1.0, +(1.0 - sat) * 0.6094, (1.0 - sat) * 0.6094 + sat, (1.0 - sat) * 0.6094, 1.0, +(1.0 - sat) * 0.0820, (1.0 - sat) * 0.0820, (1.0 - sat) * 0.0820 + sat, 1.0, +0.0, 0.0, 0.0, 1.0); + color *= adjust; + screen = clamp(screen * lum, 0.0, 1.0); + screen = color * screen; + FragColor = pow(screen, vec4(1.0 / params.display_gamma)); +} \ No newline at end of file diff --git a/handheld/shaders/color/nds-color.slang b/handheld/shaders/color/nds-color.slang new file mode 100644 index 0000000..d4d6a33 --- /dev/null +++ b/handheld/shaders/color/nds-color.slang @@ -0,0 +1,75 @@ +#version 450 + +layout(std140, set = 0, binding = 0) uniform UBO +{ + mat4 MVP; + vec4 OutputSize; + vec4 OriginalSize; + vec4 SourceSize; +} global; + +/* + Shader Modified: Pokefan531 + Color Mangler + Author: hunterk + License: Public domain +*/ +// Shader that replicates the LCD dynamics from an Original Nintendo DS + +#define display_gamma 2.25 +#define target_gamma 2.2 +#define sat 1.0 +#define lum 1.0 +#define contrast 1.0 +#define blr 0.0 +#define blg 0.0 +#define blb 0.0 +#define r 0.77 +#define g 0.65 +#define b 0.74 +#define rg 0.09 +#define rb 0.09 +#define gr 0.23 +#define gb 0.11 +#define br 0.0 +#define bg 0.26 +#define overscan_percent_x 0.0 +#define overscan_percent_y 0.0 + +#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 screen = pow(texture(Source, vTexCoord), vec4(target_gamma)).rgba; + vec4 avglum = vec4(0.5); + screen = mix(screen, avglum, (1.0 - contrast)); + + // r g b black +mat4 color = mat4(r, rg, rb, 0.0, //red channel + gr, g, gb, 0.0, //green channel + br, bg, b, 0.0, //blue channel + blr, blg, blb, 0.0); //alpha channel; these numbers do nothing for our purposes. + +mat4 adjust = mat4((1.0 - sat) * 0.3086 + sat, (1.0 - sat) * 0.3086, (1.0 - sat) * 0.3086, 1.0, +(1.0 - sat) * 0.6094, (1.0 - sat) * 0.6094 + sat, (1.0 - sat) * 0.6094, 1.0, +(1.0 - sat) * 0.0820, (1.0 - sat) * 0.0820, (1.0 - sat) * 0.0820 + sat, 1.0, +0.0, 0.0, 0.0, 1.0); + color *= adjust; + screen = clamp(screen * lum, 0.0, 1.0); + screen = color * screen; + FragColor = pow(screen, vec4(1.0 / display_gamma)); +} \ No newline at end of file diff --git a/handheld/shaders/color/psp-color.slang b/handheld/shaders/color/psp-color.slang new file mode 100644 index 0000000..2c7c052 --- /dev/null +++ b/handheld/shaders/color/psp-color.slang @@ -0,0 +1,75 @@ +#version 450 + +layout(std140, set = 0, binding = 0) uniform UBO +{ + mat4 MVP; + vec4 OutputSize; + vec4 OriginalSize; + vec4 SourceSize; +} global; + +/* + Shader Modified: Pokefan531 + Color Mangler + Author: hunterk + License: Public domain +*/ +// Shader that replicates the LCD dynamics from PSP 1000 and PSP 2000 + +#define display_gamma 2.2 +#define target_gamma 2.21 +#define sat 1.0 +#define lum 1.0 +#define contrast 1.0 +#define blr 0.0 +#define blg 0.0 +#define blb 0.0 +#define r 0.97 +#define g 0.75 +#define b 0.995 +#define rg 0.01 +#define rb 0.0025 +#define gr 0.005 +#define gb 0.0025 +#define br 0.0 +#define bg 0.24 +#define overscan_percent_x 0.0 +#define overscan_percent_y 0.0 + +#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 screen = pow(texture(Source, vTexCoord), vec4(target_gamma)).rgba; + vec4 avglum = vec4(0.5); + screen = mix(screen, avglum, (1.0 - contrast)); + + // r g b black +mat4 color = mat4(r, rg, rb, 0.0, //red channel + gr, g, gb, 0.0, //green channel + br, bg, b, 0.0, //blue channel + blr, blg, blb, 0.0); //alpha channel; these numbers do nothing for our purposes. + +mat4 adjust = mat4((1.0 - sat) * 0.3086 + sat, (1.0 - sat) * 0.3086, (1.0 - sat) * 0.3086, 1.0, +(1.0 - sat) * 0.6094, (1.0 - sat) * 0.6094 + sat, (1.0 - sat) * 0.6094, 1.0, +(1.0 - sat) * 0.0820, (1.0 - sat) * 0.0820, (1.0 - sat) * 0.0820 + sat, 1.0, +0.0, 0.0, 0.0, 1.0); + color *= adjust; + screen = clamp(screen * lum, 0.0, 1.0); + screen = color * screen; + FragColor = pow(screen, vec4(1.0 / display_gamma)); +} \ No newline at end of file diff --git a/handheld/shaders/color/vba-color.slang b/handheld/shaders/color/vba-color.slang new file mode 100644 index 0000000..9c508b5 --- /dev/null +++ b/handheld/shaders/color/vba-color.slang @@ -0,0 +1,81 @@ +#version 450 + +layout(push_constant) uniform Push +{ + float target_gamma; +} params; + +layout(std140, set = 0, binding = 0) uniform UBO +{ + mat4 MVP; + vec4 OutputSize; + vec4 OriginalSize; + vec4 SourceSize; +} global; + +/* + Shader Modified: Pokefan531 + Color Mangler + Author: hunterk + License: Public domain +*/ +// Shader that replicates the LCD dynamics from a GameBoy Advance + +#pragma parameter target_gamma "Darken Intensity" 2.9 1.0 2.9 0.05 + +#define display_gamma 1.45 +#define sat 1.0 +#define lum 1.0 +#define contrast 1.0 +#define blr 0.0 +#define blg 0.0 +#define blb 0.0 +#define r 0.74 +#define g 0.68 +#define b 0.68 +#define rg 0.08 +#define rb 0.08 +#define gr 0.26 +#define gb 0.24 +#define br 0.0 +#define bg 0.24 +#define overscan_percent_x 0.0 +#define overscan_percent_y 0.0 + +#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 screen = pow(texture(Source, vTexCoord), vec4(params.target_gamma)).rgba; + vec4 avglum = vec4(0.5); + screen = mix(screen, avglum, (1.0 - contrast)); + + // r g b black +mat4 color = mat4(r, rg, rb, 0.0, //red channel + gr, g, gb, 0.0, //green channel + br, bg, b, 0.0, //blue channel + blr, blg, blb, 0.0); //alpha channel; these numbers do nothing for our purposes. + +mat4 adjust = mat4((1.0 - sat) * 0.3086 + sat, (1.0 - sat) * 0.3086, (1.0 - sat) * 0.3086, 1.0, +(1.0 - sat) * 0.6094, (1.0 - sat) * 0.6094 + sat, (1.0 - sat) * 0.6094, 1.0, +(1.0 - sat) * 0.0820, (1.0 - sat) * 0.0820, (1.0 - sat) * 0.0820 + sat, 1.0, +0.0, 0.0, 0.0, 1.0); + color *= adjust; + screen = clamp(screen * lum, 0.0, 1.0); + screen = color * screen; + FragColor = pow(screen, vec4(1.0 / display_gamma)); +} \ No newline at end of file diff --git a/handheld/vba-color.slangp b/handheld/vba-color.slangp new file mode 100644 index 0000000..93a05f5 --- /dev/null +++ b/handheld/vba-color.slangp @@ -0,0 +1,5 @@ +shaders = 1 + +shader0 = shaders/color/vba-color.slang +filter_linear0 = false +scale_type_0 = source