From a1c66d946d2fb085858dd3ab3caea198373abff3 Mon Sep 17 00:00:00 2001 From: Monroe88 Date: Sat, 24 Mar 2018 15:08:14 -0500 Subject: [PATCH 1/4] Add AGB-001 and AGS-001 LCD shaders ported from mGBA --- handheld/agb001-gba-color-motionblur.glslp | 15 +++ handheld/agb001.glslp | 10 ++ handheld/ags001-gba-color-motionblur.glslp | 20 ++++ handheld/ags001.glslp | 10 ++ handheld/shaders/mgba/agb001.glsl | 111 +++++++++++++++++ handheld/shaders/mgba/ags001-light.glsl | 133 +++++++++++++++++++++ handheld/shaders/mgba/ags001.glsl | 111 +++++++++++++++++ 7 files changed, 410 insertions(+) create mode 100644 handheld/agb001-gba-color-motionblur.glslp create mode 100644 handheld/agb001.glslp create mode 100644 handheld/ags001-gba-color-motionblur.glslp create mode 100644 handheld/ags001.glslp create mode 100644 handheld/shaders/mgba/agb001.glsl create mode 100644 handheld/shaders/mgba/ags001-light.glsl create mode 100644 handheld/shaders/mgba/ags001.glsl diff --git a/handheld/agb001-gba-color-motionblur.glslp b/handheld/agb001-gba-color-motionblur.glslp new file mode 100644 index 00000000..58b69eb3 --- /dev/null +++ b/handheld/agb001-gba-color-motionblur.glslp @@ -0,0 +1,15 @@ +shaders = 3 + +shader0 = ../motionblur/shaders/response-time.glsl +filter_linear0 = false +scale_type0 = source +scale0 = 1.0 + +shader1 = shaders/mgba/agb001.glsl +filter_linear1 = false +scale_type1 = source +scale1 = 4.0 + +shader2 = shaders/color/gba-color.glsl +filter_linear2 = true +scale_type2 = viewport diff --git a/handheld/agb001.glslp b/handheld/agb001.glslp new file mode 100644 index 00000000..177ae74a --- /dev/null +++ b/handheld/agb001.glslp @@ -0,0 +1,10 @@ +shaders = 2 + +shader0 = shaders/mgba/agb001.glsl +filter_linear0 = false +scale_type0 = source +scale0 = 4.0 + +shader1 = ../stock.glsl +filter_linear1 = true +scale_type1 = viewport diff --git a/handheld/ags001-gba-color-motionblur.glslp b/handheld/ags001-gba-color-motionblur.glslp new file mode 100644 index 00000000..338ab0ba --- /dev/null +++ b/handheld/ags001-gba-color-motionblur.glslp @@ -0,0 +1,20 @@ +shaders = 4 + +shader0 = ../motionblur/shaders/response-time.glsl +filter_linear0 = false +scale_type0 = source +scale0 = 1.0 + +shader1 = shaders/mgba/ags001.glsl +filter_linear1 = false +scale_type1 = source +scale1 = 4.0 + +shader2 = shaders/color/gba-color.glsl +filter_linear2 = false +scale_type2 = source +scale2 = 1.0 + +shader3 = shaders/mgba/ags001-light.glsl +filter_linear3 = true +scale_type3 = viewport diff --git a/handheld/ags001.glslp b/handheld/ags001.glslp new file mode 100644 index 00000000..fe349230 --- /dev/null +++ b/handheld/ags001.glslp @@ -0,0 +1,10 @@ +shaders = 2 + +shader0 = shaders/mgba/ags001.glsl +filter_linear0 = false +scale_type0 = source +scale0 = 4.0 + +shader1 = shaders/mgba/ags001-light.glsl +filter_linear1 = true +scale_type1 = viewport diff --git a/handheld/shaders/mgba/agb001.glsl b/handheld/shaders/mgba/agb001.glsl new file mode 100644 index 00000000..ed6ebb84 --- /dev/null +++ b/handheld/shaders/mgba/agb001.glsl @@ -0,0 +1,111 @@ +/* + AGB-001 shader + A glorious recreation of the original Game Boy Advance + Author: endrift + License: MPL 2.0 + + This Source Code Form is subject to the terms of the Mozilla Public + License, v. 2.0. If a copy of the MPL was not distributed with this + file, You can obtain one at http://mozilla.org/MPL/2.0/. +*/ + +#if defined(VERTEX) + +#if __VERSION__ >= 130 +#define COMPAT_VARYING out +#define COMPAT_ATTRIBUTE in +#define COMPAT_TEXTURE texture +#else +#define COMPAT_VARYING varying +#define COMPAT_ATTRIBUTE attribute +#define COMPAT_TEXTURE texture2D +#endif + +#ifdef GL_ES +#define COMPAT_PRECISION mediump +#else +#define COMPAT_PRECISION +#endif + +COMPAT_ATTRIBUTE vec4 VertexCoord; +COMPAT_ATTRIBUTE vec4 COLOR; +COMPAT_ATTRIBUTE vec4 TexCoord; +COMPAT_VARYING vec4 COL0; +COMPAT_VARYING vec4 TEX0; + +uniform mat4 MVPMatrix; +uniform COMPAT_PRECISION int FrameDirection; +uniform COMPAT_PRECISION int FrameCount; +uniform COMPAT_PRECISION vec2 OutputSize; +uniform COMPAT_PRECISION vec2 TextureSize; +uniform COMPAT_PRECISION vec2 InputSize; + +// compatibility #defines +#define vTexCoord TEX0.xy +#define SourceSize vec4(TextureSize, 1.0 / TextureSize) //either TextureSize or InputSize +#define OutSize vec4(OutputSize, 1.0 / OutputSize) + +void main() +{ + gl_Position = MVPMatrix * VertexCoord; + TEX0.xy = TexCoord.xy; +} + +#elif defined(FRAGMENT) + +#ifdef GL_ES +#ifdef GL_FRAGMENT_PRECISION_HIGH +precision highp float; +#else +precision mediump float; +#endif +#define COMPAT_PRECISION mediump +#else +#define COMPAT_PRECISION +#endif + +#if __VERSION__ >= 130 +#define COMPAT_VARYING in +#define COMPAT_TEXTURE texture +out COMPAT_PRECISION vec4 FragColor; +#else +#define COMPAT_VARYING varying +#define FragColor gl_FragColor +#define COMPAT_TEXTURE texture2D +#endif + +uniform COMPAT_PRECISION int FrameDirection; +uniform COMPAT_PRECISION int FrameCount; +uniform COMPAT_PRECISION vec2 OutputSize; +uniform COMPAT_PRECISION vec2 TextureSize; +uniform COMPAT_PRECISION vec2 InputSize; +uniform sampler2D Texture; +COMPAT_VARYING vec4 TEX0; + +// compatibility #defines +#define Source Texture +#define vTexCoord TEX0.xy + +#define SourceSize vec4(TextureSize, 1.0 / TextureSize) //either TextureSize or InputSize +#define OutSize vec4(OutputSize, 1.0 / OutputSize) + +void main() +{ + vec4 color = COMPAT_TEXTURE(Source, vTexCoord); + vec3 arrayX[4]; + arrayX[0] = vec3(1.0, 0.2, 0.2); + arrayX[1] = vec3(0.2, 1.0, 0.2); + arrayX[2] = vec3(0.2, 0.2, 1.0); + arrayX[3] = vec3(0.4, 0.4, 0.4); + vec3 arrayY[4]; + arrayY[0] = vec3(1.0, 1.0, 1.0); + arrayY[1] = vec3(1.0, 1.0, 1.0); + arrayY[2] = vec3(1.0, 1.0, 1.0); + arrayY[3] = vec3(0.8, 0.8, 0.8); + color.rgb = pow(color.rgb * vec3(0.8, 0.8, 0.8), vec3(1.8, 1.8, 1.8)) + vec3(0.16, 0.16, 0.16); + color.rgb *= arrayX[int(mod(vTexCoord.s * SourceSize.x * 4.0, 4.0))]; + color.rgb *= arrayY[int(mod(vTexCoord.t * SourceSize.y * 4.0, 4.0))]; + color.a = 0.5; + FragColor = color; +} +#endif diff --git a/handheld/shaders/mgba/ags001-light.glsl b/handheld/shaders/mgba/ags001-light.glsl new file mode 100644 index 00000000..56be518c --- /dev/null +++ b/handheld/shaders/mgba/ags001-light.glsl @@ -0,0 +1,133 @@ +/* + AGS-001 shader + A pristine recreation of the illuminated Game Boy Advance SP + Author: endrift + License: MPL 2.0 + + This Source Code Form is subject to the terms of the Mozilla Public + License, v. 2.0. If a copy of the MPL was not distributed with this + file, You can obtain one at http://mozilla.org/MPL/2.0/. +*/ + +#pragma parameter reflectionBrightness "Reflection brightness" 0.07 0.0 1.0 0.01 +#pragma parameter reflectionDistanceX "Reflection Distance X" 0.0 -1.0 1.0 0.005 +#pragma parameter reflectionDistanceY "Reflection Distance Y" 0.025 -1.0 1.0 0.005 +#pragma parameter lightBrightness "Light brightness" 1.0 0.0 1.0 0.01 + +#if defined(VERTEX) + +#if __VERSION__ >= 130 +#define COMPAT_VARYING out +#define COMPAT_ATTRIBUTE in +#define COMPAT_TEXTURE texture +#else +#define COMPAT_VARYING varying +#define COMPAT_ATTRIBUTE attribute +#define COMPAT_TEXTURE texture2D +#endif + +#ifdef GL_ES +#define COMPAT_PRECISION mediump +#else +#define COMPAT_PRECISION +#endif + +COMPAT_ATTRIBUTE vec4 VertexCoord; +COMPAT_ATTRIBUTE vec4 COLOR; +COMPAT_ATTRIBUTE vec4 TexCoord; +COMPAT_VARYING vec4 COL0; +COMPAT_VARYING vec4 TEX0; + +uniform mat4 MVPMatrix; +uniform COMPAT_PRECISION int FrameDirection; +uniform COMPAT_PRECISION int FrameCount; +uniform COMPAT_PRECISION vec2 OutputSize; +uniform COMPAT_PRECISION vec2 TextureSize; +uniform COMPAT_PRECISION vec2 InputSize; + +// compatibility #defines +#define vTexCoord TEX0.xy +#define SourceSize vec4(TextureSize, 1.0 / TextureSize) //either TextureSize or InputSize +#define OutSize vec4(OutputSize, 1.0 / OutputSize) + +void main() +{ + gl_Position = MVPMatrix * VertexCoord; + TEX0.xy = TexCoord.xy; +} + +#elif defined(FRAGMENT) + +#ifdef GL_ES +#ifdef GL_FRAGMENT_PRECISION_HIGH +precision highp float; +#else +precision mediump float; +#endif +#define COMPAT_PRECISION mediump +#else +#define COMPAT_PRECISION +#endif + +#if __VERSION__ >= 130 +#define COMPAT_VARYING in +#define COMPAT_TEXTURE texture +out COMPAT_PRECISION vec4 FragColor; +#else +#define COMPAT_VARYING varying +#define FragColor gl_FragColor +#define COMPAT_TEXTURE texture2D +#endif + +uniform COMPAT_PRECISION int FrameDirection; +uniform COMPAT_PRECISION int FrameCount; +uniform COMPAT_PRECISION vec2 OutputSize; +uniform COMPAT_PRECISION vec2 TextureSize; +uniform COMPAT_PRECISION vec2 InputSize; +uniform sampler2D Texture; +COMPAT_VARYING vec4 TEX0; + +// compatibility #defines +#define Source Texture +#define vTexCoord TEX0.xy + +#define SourceSize vec4(TextureSize, 1.0 / TextureSize) //either TextureSize or InputSize +#define OutSize vec4(OutputSize, 1.0 / OutputSize) + +#ifdef PARAMETER_UNIFORM +uniform COMPAT_PRECISION float reflectionBrightness; +uniform COMPAT_PRECISION float reflectionDistanceX; +uniform COMPAT_PRECISION float reflectionDistanceY; +uniform COMPAT_PRECISION float lightBrightness; +#else +#define reflectionBrightness 0.07 +#define reflectionDistanceX 0.0 +#define reflectionDistanceY 0.025 +#define lightBrightness 1.0 +#endif + +const float speed = 2.0; +const float decay = 2.0; +const float coeff = 2.5; + +void main() +{ + vec2 reflectionDistance = vec2(reflectionDistanceX,reflectionDistanceY); + float sp = pow(speed, lightBrightness); + float dc = pow(decay, -lightBrightness); + float s = (sp - dc) / (sp + dc); + vec2 radius = (vTexCoord.st - vec2(0.5, 0.5)) * vec2(coeff * s); + radius = pow(abs(radius), vec2(4.0)); + vec3 bleed = vec3(0.12, 0.14, 0.19); + bleed += (dot(radius, radius) + vec3(0.02, 0.03, 0.05)) * vec3(0.14, 0.18, 0.2); + + vec4 color = COMPAT_TEXTURE(Source, vTexCoord); + color.rgb += pow(bleed, pow(vec3(lightBrightness), vec3(-0.5))); + + vec4 reflection = COMPAT_TEXTURE(Source, vTexCoord - reflectionDistance); + color.rgb += reflection.rgb * reflectionBrightness; + color.a = 1.0; + FragColor = color; + +} +#endif diff --git a/handheld/shaders/mgba/ags001.glsl b/handheld/shaders/mgba/ags001.glsl new file mode 100644 index 00000000..efcd9268 --- /dev/null +++ b/handheld/shaders/mgba/ags001.glsl @@ -0,0 +1,111 @@ +/* + AGS-001 shader + A pristine recreation of the illuminated Game Boy Advance SP + Author: endrift + License: MPL 2.0 + + This Source Code Form is subject to the terms of the Mozilla Public + License, v. 2.0. If a copy of the MPL was not distributed with this + file, You can obtain one at http://mozilla.org/MPL/2.0/. +*/ + +#if defined(VERTEX) + +#if __VERSION__ >= 130 +#define COMPAT_VARYING out +#define COMPAT_ATTRIBUTE in +#define COMPAT_TEXTURE texture +#else +#define COMPAT_VARYING varying +#define COMPAT_ATTRIBUTE attribute +#define COMPAT_TEXTURE texture2D +#endif + +#ifdef GL_ES +#define COMPAT_PRECISION mediump +#else +#define COMPAT_PRECISION +#endif + +COMPAT_ATTRIBUTE vec4 VertexCoord; +COMPAT_ATTRIBUTE vec4 COLOR; +COMPAT_ATTRIBUTE vec4 TexCoord; +COMPAT_VARYING vec4 COL0; +COMPAT_VARYING vec4 TEX0; + +uniform mat4 MVPMatrix; +uniform COMPAT_PRECISION int FrameDirection; +uniform COMPAT_PRECISION int FrameCount; +uniform COMPAT_PRECISION vec2 OutputSize; +uniform COMPAT_PRECISION vec2 TextureSize; +uniform COMPAT_PRECISION vec2 InputSize; + +// compatibility #defines +#define vTexCoord TEX0.xy +#define SourceSize vec4(TextureSize, 1.0 / TextureSize) //either TextureSize or InputSize +#define OutSize vec4(OutputSize, 1.0 / OutputSize) + +void main() +{ + gl_Position = MVPMatrix * VertexCoord; + TEX0.xy = TexCoord.xy; +} + +#elif defined(FRAGMENT) + +#ifdef GL_ES +#ifdef GL_FRAGMENT_PRECISION_HIGH +precision highp float; +#else +precision mediump float; +#endif +#define COMPAT_PRECISION mediump +#else +#define COMPAT_PRECISION +#endif + +#if __VERSION__ >= 130 +#define COMPAT_VARYING in +#define COMPAT_TEXTURE texture +out COMPAT_PRECISION vec4 FragColor; +#else +#define COMPAT_VARYING varying +#define FragColor gl_FragColor +#define COMPAT_TEXTURE texture2D +#endif + +uniform COMPAT_PRECISION int FrameDirection; +uniform COMPAT_PRECISION int FrameCount; +uniform COMPAT_PRECISION vec2 OutputSize; +uniform COMPAT_PRECISION vec2 TextureSize; +uniform COMPAT_PRECISION vec2 InputSize; +uniform sampler2D Texture; +COMPAT_VARYING vec4 TEX0; + +// compatibility #defines +#define Source Texture +#define vTexCoord TEX0.xy + +#define SourceSize vec4(TextureSize, 1.0 / TextureSize) //either TextureSize or InputSize +#define OutSize vec4(OutputSize, 1.0 / OutputSize) + +void main() +{ + vec4 color = COMPAT_TEXTURE(Source, vTexCoord); + vec3 arrayX[4]; + arrayX[0] = vec3(1.0, 0.2, 0.2); + arrayX[1] = vec3(0.2, 1.0, 0.2); + arrayX[2] = vec3(0.2, 0.2, 1.0); + arrayX[3] = vec3(0.4, 0.4, 0.4); + vec3 arrayY[4]; + arrayY[0] = vec3(1.0, 1.0, 1.0); + arrayY[1] = vec3(1.0, 1.0, 1.0); + arrayY[2] = vec3(1.0, 1.0, 1.0); + arrayY[3] = vec3(0.9, 0.9, 0.9); + color.rgb = pow(color.rgb, vec3(1.6, 1.6, 1.6)); + color.rgb *= arrayX[int(mod(vTexCoord.s * SourceSize.x * 4.0, 4.0))]; + color.rgb *= arrayY[int(mod(vTexCoord.t * SourceSize.y * 4.0, 4.0))]; + color.a = 0.8; + FragColor = color; +} +#endif From f75312b05405422f8edf84eb44991081e484d9eb Mon Sep 17 00:00:00 2001 From: Monroe88 Date: Sat, 24 Mar 2018 15:08:46 -0500 Subject: [PATCH 2/4] Add LCD shader ported from SameBoy --- .../sameboy-lcd-gbc-color-motionblur.glslp | 15 ++ handheld/sameboy-lcd.glslp | 6 + handheld/shaders/sameboy-lcd.glsl | 175 ++++++++++++++++++ 3 files changed, 196 insertions(+) create mode 100644 handheld/sameboy-lcd-gbc-color-motionblur.glslp create mode 100644 handheld/sameboy-lcd.glslp create mode 100644 handheld/shaders/sameboy-lcd.glsl diff --git a/handheld/sameboy-lcd-gbc-color-motionblur.glslp b/handheld/sameboy-lcd-gbc-color-motionblur.glslp new file mode 100644 index 00000000..e4b40416 --- /dev/null +++ b/handheld/sameboy-lcd-gbc-color-motionblur.glslp @@ -0,0 +1,15 @@ +shaders = 3 + +shader0 = ../motionblur/shaders/response-time.glsl +filter_linear0 = false +scale_type0 = source +scale0 = 1.0 + +shader1 = shaders/sameboy-lcd.glsl +filter_linear1 = false +scale_type1 = viewport +scale1 = "1.0" + +shader2 = shaders/color/gbc-color.glsl +filter_linear2 = false +scale_type2 = viewport diff --git a/handheld/sameboy-lcd.glslp b/handheld/sameboy-lcd.glslp new file mode 100644 index 00000000..f0979aaf --- /dev/null +++ b/handheld/sameboy-lcd.glslp @@ -0,0 +1,6 @@ +shaders = 1 + +shader0 = shaders/sameboy-lcd.glsl +filter_linear0 = false +scale_type0 = "viewport" +scale0 = "1.0" diff --git a/handheld/shaders/sameboy-lcd.glsl b/handheld/shaders/sameboy-lcd.glsl new file mode 100644 index 00000000..4ee47d11 --- /dev/null +++ b/handheld/shaders/sameboy-lcd.glsl @@ -0,0 +1,175 @@ +/* + SameBoy LCD shader + Author: LIJI32 + License: MIT + + Copyright (c) 2015-2016 Lior Halphon + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in all + copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. +*/ + +#if defined(VERTEX) + +#if __VERSION__ >= 130 +#define COMPAT_VARYING out +#define COMPAT_ATTRIBUTE in +#define COMPAT_TEXTURE texture +#else +#define COMPAT_VARYING varying +#define COMPAT_ATTRIBUTE attribute +#define COMPAT_TEXTURE texture2D +#endif + +#ifdef GL_ES +#define COMPAT_PRECISION mediump +#else +#define COMPAT_PRECISION +#endif + +COMPAT_ATTRIBUTE vec4 VertexCoord; +COMPAT_ATTRIBUTE vec4 COLOR; +COMPAT_ATTRIBUTE vec4 TexCoord; +COMPAT_VARYING vec4 COL0; +COMPAT_VARYING vec4 TEX0; + +uniform mat4 MVPMatrix; +uniform COMPAT_PRECISION int FrameDirection; +uniform COMPAT_PRECISION int FrameCount; +uniform COMPAT_PRECISION vec2 OutputSize; +uniform COMPAT_PRECISION vec2 TextureSize; +uniform COMPAT_PRECISION vec2 InputSize; + +// compatibility #defines +#define vTexCoord TEX0.xy +#define SourceSize vec4(TextureSize, 1.0 / TextureSize) //either TextureSize or InputSize +#define OutSize vec4(OutputSize, 1.0 / OutputSize) + +void main() +{ + gl_Position = MVPMatrix * VertexCoord; + TEX0.xy = TexCoord.xy; +} + +#elif defined(FRAGMENT) + +#ifdef GL_ES +#ifdef GL_FRAGMENT_PRECISION_HIGH +precision highp float; +#else +precision mediump float; +#endif +#define COMPAT_PRECISION mediump +#else +#define COMPAT_PRECISION +#endif + +#if __VERSION__ >= 130 +#define COMPAT_VARYING in +#define COMPAT_TEXTURE texture +out COMPAT_PRECISION vec4 FragColor; +#else +#define COMPAT_VARYING varying +#define FragColor gl_FragColor +#define COMPAT_TEXTURE texture2D +#endif + +uniform COMPAT_PRECISION int FrameDirection; +uniform COMPAT_PRECISION int FrameCount; +uniform COMPAT_PRECISION vec2 OutputSize; +uniform COMPAT_PRECISION vec2 TextureSize; +uniform COMPAT_PRECISION vec2 InputSize; +uniform sampler2D Texture; +COMPAT_VARYING vec4 TEX0; + +// compatibility #defines +#define Source Texture +#define vTexCoord TEX0.xy + +#define SourceSize vec4(TextureSize, 1.0 / TextureSize) //either TextureSize or InputSize +#define OutSize vec4(OutputSize, 1.0 / OutputSize) + +#define COLOR_LOW 0.8 +#define COLOR_HIGH 1.0 +#define SCANLINE_DEPTH 0.1 + +void main() +{ + vec2 pos = fract(vTexCoord * SourceSize.xy); + vec2 sub_pos = fract(vTexCoord * SourceSize.xy * 6); + + vec4 center = COMPAT_TEXTURE(Source, vTexCoord); + vec4 left = COMPAT_TEXTURE(Source, vTexCoord - vec2(1.0 / SourceSize.x, 0)); + vec4 right = COMPAT_TEXTURE(Source, vTexCoord + vec2(1.0 / SourceSize.x, 0)); + + if (pos.y < 1.0 / 6.0) { + center = mix(center, COMPAT_TEXTURE(Source, vTexCoord + vec2(0, -1.0 / SourceSize.y)), 0.5 - sub_pos.y / 2.0); + left = mix(left, COMPAT_TEXTURE(Source, vTexCoord + vec2(-1.0 / SourceSize.x, -1.0 / SourceSize.y)), 0.5 - sub_pos.y / 2.0); + right = mix(right, COMPAT_TEXTURE(Source, vTexCoord + vec2( 1.0 / SourceSize.x, -1.0 / SourceSize.y)), 0.5 - sub_pos.y / 2.0); + center *= sub_pos.y * SCANLINE_DEPTH + (1 - SCANLINE_DEPTH); + left *= sub_pos.y * SCANLINE_DEPTH + (1 - SCANLINE_DEPTH); + right *= sub_pos.y * SCANLINE_DEPTH + (1 - SCANLINE_DEPTH); + } + else if (pos.y > 5.0 / 6.0) { + center = mix(center, COMPAT_TEXTURE(Source, vTexCoord + vec2(0, 1.0 / SourceSize.y)), sub_pos.y / 2.0); + left = mix(left, COMPAT_TEXTURE(Source, vTexCoord + vec2(-1.0 / SourceSize.x, 1.0 / SourceSize.y)), sub_pos.y / 2.0); + right = mix(right, COMPAT_TEXTURE(Source, vTexCoord + vec2( 1.0 / SourceSize.x, 1.0 / SourceSize.y)), sub_pos.y / 2.0); + center *= (1.0 - sub_pos.y) * SCANLINE_DEPTH + (1 - SCANLINE_DEPTH); + left *= (1.0 - sub_pos.y) * SCANLINE_DEPTH + (1 - SCANLINE_DEPTH); + right *= (1.0 - sub_pos.y) * SCANLINE_DEPTH + (1 - SCANLINE_DEPTH); + } + + + vec4 midleft = mix(left, center, 0.5); + vec4 midright = mix(right, center, 0.5); + + vec4 ret; + if (pos.x < 1.0 / 6.0) { + ret = mix(vec4(COLOR_HIGH * center.r, COLOR_LOW * center.g, COLOR_HIGH * left.b, 1), + vec4(COLOR_HIGH * center.r, COLOR_LOW * center.g, COLOR_LOW * left.b, 1), + sub_pos.x); + } + else if (pos.x < 2.0 / 6.0) { + ret = mix(vec4(COLOR_HIGH * center.r, COLOR_LOW * center.g, COLOR_LOW * left.b, 1), + vec4(COLOR_HIGH * center.r, COLOR_HIGH * center.g, COLOR_LOW * midleft.b, 1), + sub_pos.x); + } + else if (pos.x < 3.0 / 6.0) { + ret = mix(vec4(COLOR_HIGH * center.r , COLOR_HIGH * center.g, COLOR_LOW * midleft.b, 1), + vec4(COLOR_LOW * midright.r, COLOR_HIGH * center.g, COLOR_LOW * center.b, 1), + sub_pos.x); + } + else if (pos.x < 4.0 / 6.0) { + ret = mix(vec4(COLOR_LOW * midright.r, COLOR_HIGH * center.g , COLOR_LOW * center.b, 1), + vec4(COLOR_LOW * right.r , COLOR_HIGH * center.g, COLOR_HIGH * center.b, 1), + sub_pos.x); + } + else if (pos.x < 5.0 / 6.0) { + ret = mix(vec4(COLOR_LOW * right.r, COLOR_HIGH * center.g , COLOR_HIGH * center.b, 1), + vec4(COLOR_LOW * right.r, COLOR_LOW * midright.g, COLOR_HIGH * center.b, 1), + sub_pos.x); + } + else { + ret = mix(vec4(COLOR_LOW * right.r, COLOR_LOW * midright.g, COLOR_HIGH * center.b, 1), + vec4(COLOR_HIGH * right.r, COLOR_LOW * right.g , COLOR_HIGH * center.b, 1), + sub_pos.x); + } + + FragColor = ret; +} +#endif From 589073d284d0716339f3f20ee4e203e8f776c286 Mon Sep 17 00:00:00 2001 From: Monroe88 Date: Sat, 24 Mar 2018 15:25:53 -0500 Subject: [PATCH 3/4] sameboy-lcd: Add parameters --- handheld/shaders/sameboy-lcd.glsl | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/handheld/shaders/sameboy-lcd.glsl b/handheld/shaders/sameboy-lcd.glsl index 4ee47d11..22320b0c 100644 --- a/handheld/shaders/sameboy-lcd.glsl +++ b/handheld/shaders/sameboy-lcd.glsl @@ -24,6 +24,10 @@ SOFTWARE. */ +#pragma parameter COLOR_LOW "Color Low" 0.8 0.0 1.5 0.05 +#pragma parameter COLOR_HIGH "Color High" 1.0 0.0 1.5 0.05 +#pragma parameter SCANLINE_DEPTH "Scanline Depth" 0.1 0.0 2.0 0.05 + #if defined(VERTEX) #if __VERSION__ >= 130 @@ -104,9 +108,15 @@ COMPAT_VARYING vec4 TEX0; #define SourceSize vec4(TextureSize, 1.0 / TextureSize) //either TextureSize or InputSize #define OutSize vec4(OutputSize, 1.0 / OutputSize) +#ifdef PARAMETER_UNIFORM +uniform COMPAT_PRECISION float COLOR_LOW; +uniform COMPAT_PRECISION float COLOR_HIGH; +uniform COMPAT_PRECISION float SCANLINE_DEPTH; +#else #define COLOR_LOW 0.8 #define COLOR_HIGH 1.0 #define SCANLINE_DEPTH 0.1 +#endif void main() { From 3931faba02b629af0805e3a419776a0e8e0d4c5e Mon Sep 17 00:00:00 2001 From: Monroe88 Date: Sat, 24 Mar 2018 15:51:40 -0500 Subject: [PATCH 4/4] sameboy-lcd: Fix compilation on GLES --- handheld/shaders/sameboy-lcd.glsl | 44 +++++++++++++++---------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/handheld/shaders/sameboy-lcd.glsl b/handheld/shaders/sameboy-lcd.glsl index 22320b0c..bdd3e573 100644 --- a/handheld/shaders/sameboy-lcd.glsl +++ b/handheld/shaders/sameboy-lcd.glsl @@ -121,27 +121,27 @@ uniform COMPAT_PRECISION float SCANLINE_DEPTH; void main() { vec2 pos = fract(vTexCoord * SourceSize.xy); - vec2 sub_pos = fract(vTexCoord * SourceSize.xy * 6); + vec2 sub_pos = fract(vTexCoord * SourceSize.xy * 6.0); vec4 center = COMPAT_TEXTURE(Source, vTexCoord); - vec4 left = COMPAT_TEXTURE(Source, vTexCoord - vec2(1.0 / SourceSize.x, 0)); - vec4 right = COMPAT_TEXTURE(Source, vTexCoord + vec2(1.0 / SourceSize.x, 0)); + vec4 left = COMPAT_TEXTURE(Source, vTexCoord - vec2(1.0 / SourceSize.x, 0.0)); + vec4 right = COMPAT_TEXTURE(Source, vTexCoord + vec2(1.0 / SourceSize.x, 0.0)); if (pos.y < 1.0 / 6.0) { - center = mix(center, COMPAT_TEXTURE(Source, vTexCoord + vec2(0, -1.0 / SourceSize.y)), 0.5 - sub_pos.y / 2.0); + center = mix(center, COMPAT_TEXTURE(Source, vTexCoord + vec2(0.0, -1.0 / SourceSize.y)), 0.5 - sub_pos.y / 2.0); left = mix(left, COMPAT_TEXTURE(Source, vTexCoord + vec2(-1.0 / SourceSize.x, -1.0 / SourceSize.y)), 0.5 - sub_pos.y / 2.0); right = mix(right, COMPAT_TEXTURE(Source, vTexCoord + vec2( 1.0 / SourceSize.x, -1.0 / SourceSize.y)), 0.5 - sub_pos.y / 2.0); - center *= sub_pos.y * SCANLINE_DEPTH + (1 - SCANLINE_DEPTH); - left *= sub_pos.y * SCANLINE_DEPTH + (1 - SCANLINE_DEPTH); - right *= sub_pos.y * SCANLINE_DEPTH + (1 - SCANLINE_DEPTH); + center *= sub_pos.y * SCANLINE_DEPTH + (1.0 - SCANLINE_DEPTH); + left *= sub_pos.y * SCANLINE_DEPTH + (1.0 - SCANLINE_DEPTH); + right *= sub_pos.y * SCANLINE_DEPTH + (1.0 - SCANLINE_DEPTH); } else if (pos.y > 5.0 / 6.0) { center = mix(center, COMPAT_TEXTURE(Source, vTexCoord + vec2(0, 1.0 / SourceSize.y)), sub_pos.y / 2.0); left = mix(left, COMPAT_TEXTURE(Source, vTexCoord + vec2(-1.0 / SourceSize.x, 1.0 / SourceSize.y)), sub_pos.y / 2.0); right = mix(right, COMPAT_TEXTURE(Source, vTexCoord + vec2( 1.0 / SourceSize.x, 1.0 / SourceSize.y)), sub_pos.y / 2.0); - center *= (1.0 - sub_pos.y) * SCANLINE_DEPTH + (1 - SCANLINE_DEPTH); - left *= (1.0 - sub_pos.y) * SCANLINE_DEPTH + (1 - SCANLINE_DEPTH); - right *= (1.0 - sub_pos.y) * SCANLINE_DEPTH + (1 - SCANLINE_DEPTH); + center *= (1.0 - sub_pos.y) * SCANLINE_DEPTH + (1.0 - SCANLINE_DEPTH); + left *= (1.0 - sub_pos.y) * SCANLINE_DEPTH + (1.0 - SCANLINE_DEPTH); + right *= (1.0 - sub_pos.y) * SCANLINE_DEPTH + (1.0 - SCANLINE_DEPTH); } @@ -150,33 +150,33 @@ void main() vec4 ret; if (pos.x < 1.0 / 6.0) { - ret = mix(vec4(COLOR_HIGH * center.r, COLOR_LOW * center.g, COLOR_HIGH * left.b, 1), - vec4(COLOR_HIGH * center.r, COLOR_LOW * center.g, COLOR_LOW * left.b, 1), + ret = mix(vec4(COLOR_HIGH * center.r, COLOR_LOW * center.g, COLOR_HIGH * left.b, 1.0), + vec4(COLOR_HIGH * center.r, COLOR_LOW * center.g, COLOR_LOW * left.b, 1.0), sub_pos.x); } else if (pos.x < 2.0 / 6.0) { - ret = mix(vec4(COLOR_HIGH * center.r, COLOR_LOW * center.g, COLOR_LOW * left.b, 1), - vec4(COLOR_HIGH * center.r, COLOR_HIGH * center.g, COLOR_LOW * midleft.b, 1), + ret = mix(vec4(COLOR_HIGH * center.r, COLOR_LOW * center.g, COLOR_LOW * left.b, 1.0), + vec4(COLOR_HIGH * center.r, COLOR_HIGH * center.g, COLOR_LOW * midleft.b, 1.0), sub_pos.x); } else if (pos.x < 3.0 / 6.0) { - ret = mix(vec4(COLOR_HIGH * center.r , COLOR_HIGH * center.g, COLOR_LOW * midleft.b, 1), - vec4(COLOR_LOW * midright.r, COLOR_HIGH * center.g, COLOR_LOW * center.b, 1), + ret = mix(vec4(COLOR_HIGH * center.r , COLOR_HIGH * center.g, COLOR_LOW * midleft.b, 1.0), + vec4(COLOR_LOW * midright.r, COLOR_HIGH * center.g, COLOR_LOW * center.b, 1.0), sub_pos.x); } else if (pos.x < 4.0 / 6.0) { - ret = mix(vec4(COLOR_LOW * midright.r, COLOR_HIGH * center.g , COLOR_LOW * center.b, 1), - vec4(COLOR_LOW * right.r , COLOR_HIGH * center.g, COLOR_HIGH * center.b, 1), + ret = mix(vec4(COLOR_LOW * midright.r, COLOR_HIGH * center.g , COLOR_LOW * center.b, 1.0), + vec4(COLOR_LOW * right.r , COLOR_HIGH * center.g, COLOR_HIGH * center.b, 1.0), sub_pos.x); } else if (pos.x < 5.0 / 6.0) { - ret = mix(vec4(COLOR_LOW * right.r, COLOR_HIGH * center.g , COLOR_HIGH * center.b, 1), - vec4(COLOR_LOW * right.r, COLOR_LOW * midright.g, COLOR_HIGH * center.b, 1), + ret = mix(vec4(COLOR_LOW * right.r, COLOR_HIGH * center.g , COLOR_HIGH * center.b, 1.0), + vec4(COLOR_LOW * right.r, COLOR_LOW * midright.g, COLOR_HIGH * center.b, 1.0), sub_pos.x); } else { - ret = mix(vec4(COLOR_LOW * right.r, COLOR_LOW * midright.g, COLOR_HIGH * center.b, 1), - vec4(COLOR_HIGH * right.r, COLOR_LOW * right.g , COLOR_HIGH * center.b, 1), + ret = mix(vec4(COLOR_LOW * right.r, COLOR_LOW * midright.g, COLOR_HIGH * center.b, 1.0), + vec4(COLOR_HIGH * right.r, COLOR_LOW * right.g , COLOR_HIGH * center.b, 1.0), sub_pos.x); }