From 5a8830124bdc787a8ce6987cba0f17cdd6705881 Mon Sep 17 00:00:00 2001 From: EddyHg80 Date: Mon, 20 Dec 2021 12:19:43 +0100 Subject: [PATCH 1/2] Add configurable custom LCD shader --- res/shaders/customLCD.shader/ags001-light.fs | 36 ++++++++++ .../customLCD.shader/customLCD-brightness.fs | 9 +++ .../customLCD.shader/customLCD-pixelBounds.fs | 14 ++++ .../customLCD.shader/customLCD-subPixels.fs | 15 +++++ res/shaders/customLCD.shader/manifest.ini | 65 +++++++++++++++++++ 5 files changed, 139 insertions(+) create mode 100644 res/shaders/customLCD.shader/ags001-light.fs create mode 100644 res/shaders/customLCD.shader/customLCD-brightness.fs create mode 100644 res/shaders/customLCD.shader/customLCD-pixelBounds.fs create mode 100644 res/shaders/customLCD.shader/customLCD-subPixels.fs create mode 100644 res/shaders/customLCD.shader/manifest.ini diff --git a/res/shaders/customLCD.shader/ags001-light.fs b/res/shaders/customLCD.shader/ags001-light.fs new file mode 100644 index 00000000000..3beb19b62cb --- /dev/null +++ b/res/shaders/customLCD.shader/ags001-light.fs @@ -0,0 +1,36 @@ +varying vec2 texCoord; +uniform sampler2D tex; +uniform float reflectionBrightness; +uniform vec2 reflectionDistance; +uniform float lightBrightness; +uniform int enable; + +const float speed = 2.0; +const float decay = 2.0; +const float coeff = 2.5; + +void main() { + if(enable==1) + { + float sp = pow(speed, lightBrightness); + float dc = pow(decay, -lightBrightness); + float s = (sp - dc) / (sp + dc); + vec2 radius = (texCoord.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 = texture2D(tex, texCoord); + color.rgb += pow(bleed, pow(vec3(lightBrightness), vec3(-0.5))); + + vec4 reflection = texture2D(tex, texCoord - reflectionDistance); + color.rgb += reflection.rgb * reflectionBrightness; + color.a = 1.0; + gl_FragColor = color; + } + else + { + vec4 color = texture2D(tex, texCoord); + gl_FragColor = color; + } +} diff --git a/res/shaders/customLCD.shader/customLCD-brightness.fs b/res/shaders/customLCD.shader/customLCD-brightness.fs new file mode 100644 index 00000000000..42dfc670563 --- /dev/null +++ b/res/shaders/customLCD.shader/customLCD-brightness.fs @@ -0,0 +1,9 @@ +varying vec2 texCoord; +uniform sampler2D tex; +uniform float brightness; + +void main() { + vec4 color = texture2D(tex, texCoord); + color.rgb *= brightness; + gl_FragColor = color; +} diff --git a/res/shaders/customLCD.shader/customLCD-pixelBounds.fs b/res/shaders/customLCD.shader/customLCD-pixelBounds.fs new file mode 100644 index 00000000000..8ec47b71b81 --- /dev/null +++ b/res/shaders/customLCD.shader/customLCD-pixelBounds.fs @@ -0,0 +1,14 @@ +varying vec2 texCoord; +uniform sampler2D tex; +uniform vec2 texSize; +uniform float boundBrightness; + +void main() { + vec4 color = texture2D(tex, texCoord); + if (int(mod(texCoord.s * texSize.x * 6.0, 6.0)) == 5 || + int(mod(texCoord.t * texSize.y * 6.0, 6.0)) == 5) + { + color.rgb *= vec3(1.0, 1.0, 1.0) * boundBrightness; + } + gl_FragColor = color; +} \ No newline at end of file diff --git a/res/shaders/customLCD.shader/customLCD-subPixels.fs b/res/shaders/customLCD.shader/customLCD-subPixels.fs new file mode 100644 index 00000000000..add3828182c --- /dev/null +++ b/res/shaders/customLCD.shader/customLCD-subPixels.fs @@ -0,0 +1,15 @@ +varying vec2 texCoord; +uniform sampler2D tex; +uniform vec2 texSize; +uniform float subPixelDimming; + +void main() { + vec4 color = texture2D(tex, texCoord); + vec3 subPixels[3]; + float subPixelDimming = 1.0 - subPixelDimming; + subPixels[0] = vec3(1.0, subPixelDimming, subPixelDimming); + subPixels[1] = vec3(subPixelDimming, 1.0, subPixelDimming); + subPixels[2] = vec3(subPixelDimming, subPixelDimming, 1.0); + color.rgb *= subPixels[int(mod(texCoord.s * texSize.x * 3.0, 3.0))]; + gl_FragColor = color; +} \ No newline at end of file diff --git a/res/shaders/customLCD.shader/manifest.ini b/res/shaders/customLCD.shader/manifest.ini new file mode 100644 index 00000000000..f293d6bee66 --- /dev/null +++ b/res/shaders/customLCD.shader/manifest.ini @@ -0,0 +1,65 @@ +[shader] +name=Custom LCD +author=endrift, Dominus Iniquitatis, EddyHg80 +description=Configurable LCD emulation. +passes=4 + +[pass.0] +fragmentShader=customLCD-brightness.fs +blend=1 +width=-1 +height=-1 + +[pass.0.uniform.brightness] +type=float +default=1.1 +readableName=Brightness + +[pass.1] +fragmentShader=customLCD-subPixels.fs +blend=1 +width=-3 +height=-3 + +[pass.1.uniform.subPixelDimming] +type=float +default=0.2 +readableName=Sub pixel dimming + +[pass.2] +fragmentShader=customLCD-pixelBounds.fs +blend=1 +width=-6 +height=-6 + +[pass.2.uniform.boundBrightness] +type=float +default=0.9 +readableName=Pixel bound brightness + +[pass.3] +fragmentShader=ags001-light.fs +blend=1 +width=-6 +height=-6 + +[pass.3.uniform.enable] +type=int +default=0 +readableName=Enable AGS-001's pristine light and reflections + +[pass.3.uniform.lightBrightness] +type=float +default=0.9 +readableName=Light brightness + +[pass.3.uniform.reflectionBrightness] +type=float +default=0.07 +readableName=Reflection brightness + +[pass.3.uniform.reflectionDistance] +type=float2 +default[0]=0 +default[1]=0.025 +readableName=Reflection offset (x|y) From 598b9e237ba0d42e9b22936ff2e3dbc2acc0e386 Mon Sep 17 00:00:00 2001 From: EddyHg80 Date: Thu, 23 Dec 2021 11:09:24 +0100 Subject: [PATCH 2/2] Merge brightness and subpixels passes in custom LCD shader --- res/shaders/customLCD.shader/ags001-light.fs | 2 +- .../customLCD.shader/customLCD-brightness.fs | 9 ------ .../customLCD.shader/customLCD-subPixels.fs | 2 ++ res/shaders/customLCD.shader/manifest.ini | 30 ++++++++----------- 4 files changed, 15 insertions(+), 28 deletions(-) delete mode 100644 res/shaders/customLCD.shader/customLCD-brightness.fs diff --git a/res/shaders/customLCD.shader/ags001-light.fs b/res/shaders/customLCD.shader/ags001-light.fs index 3beb19b62cb..9cd6c74781a 100644 --- a/res/shaders/customLCD.shader/ags001-light.fs +++ b/res/shaders/customLCD.shader/ags001-light.fs @@ -1,9 +1,9 @@ varying vec2 texCoord; uniform sampler2D tex; +uniform int enable; uniform float reflectionBrightness; uniform vec2 reflectionDistance; uniform float lightBrightness; -uniform int enable; const float speed = 2.0; const float decay = 2.0; diff --git a/res/shaders/customLCD.shader/customLCD-brightness.fs b/res/shaders/customLCD.shader/customLCD-brightness.fs deleted file mode 100644 index 42dfc670563..00000000000 --- a/res/shaders/customLCD.shader/customLCD-brightness.fs +++ /dev/null @@ -1,9 +0,0 @@ -varying vec2 texCoord; -uniform sampler2D tex; -uniform float brightness; - -void main() { - vec4 color = texture2D(tex, texCoord); - color.rgb *= brightness; - gl_FragColor = color; -} diff --git a/res/shaders/customLCD.shader/customLCD-subPixels.fs b/res/shaders/customLCD.shader/customLCD-subPixels.fs index add3828182c..fab570d7135 100644 --- a/res/shaders/customLCD.shader/customLCD-subPixels.fs +++ b/res/shaders/customLCD.shader/customLCD-subPixels.fs @@ -1,6 +1,7 @@ varying vec2 texCoord; uniform sampler2D tex; uniform vec2 texSize; +uniform float brightness; uniform float subPixelDimming; void main() { @@ -10,6 +11,7 @@ void main() { subPixels[0] = vec3(1.0, subPixelDimming, subPixelDimming); subPixels[1] = vec3(subPixelDimming, 1.0, subPixelDimming); subPixels[2] = vec3(subPixelDimming, subPixelDimming, 1.0); + color.rgb *= brightness; color.rgb *= subPixels[int(mod(texCoord.s * texSize.x * 3.0, 3.0))]; gl_FragColor = color; } \ No newline at end of file diff --git a/res/shaders/customLCD.shader/manifest.ini b/res/shaders/customLCD.shader/manifest.ini index f293d6bee66..a05fb029fb7 100644 --- a/res/shaders/customLCD.shader/manifest.ini +++ b/res/shaders/customLCD.shader/manifest.ini @@ -2,63 +2,57 @@ name=Custom LCD author=endrift, Dominus Iniquitatis, EddyHg80 description=Configurable LCD emulation. -passes=4 +passes=3 [pass.0] -fragmentShader=customLCD-brightness.fs +fragmentShader=customLCD-subPixels.fs blend=1 -width=-1 -height=-1 +width=-3 +height=-3 [pass.0.uniform.brightness] type=float default=1.1 readableName=Brightness -[pass.1] -fragmentShader=customLCD-subPixels.fs -blend=1 -width=-3 -height=-3 - -[pass.1.uniform.subPixelDimming] +[pass.0.uniform.subPixelDimming] type=float default=0.2 readableName=Sub pixel dimming -[pass.2] +[pass.1] fragmentShader=customLCD-pixelBounds.fs blend=1 width=-6 height=-6 -[pass.2.uniform.boundBrightness] +[pass.1.uniform.boundBrightness] type=float default=0.9 readableName=Pixel bound brightness -[pass.3] +[pass.2] fragmentShader=ags001-light.fs blend=1 width=-6 height=-6 -[pass.3.uniform.enable] +[pass.2.uniform.enable] type=int default=0 readableName=Enable AGS-001's pristine light and reflections -[pass.3.uniform.lightBrightness] +[pass.2.uniform.lightBrightness] type=float default=0.9 readableName=Light brightness -[pass.3.uniform.reflectionBrightness] +[pass.2.uniform.reflectionBrightness] type=float default=0.07 readableName=Reflection brightness -[pass.3.uniform.reflectionDistance] +[pass.2.uniform.reflectionDistance] type=float2 default[0]=0 default[1]=0.025