mirror of
https://github.com/italicsjenga/slang-shaders.git
synced 2024-11-22 15:51:30 +11:00
Merge pull request #78 from Monroe88/lcd-shaders
Added LCD shaders from mGBA and SameBoy
This commit is contained in:
commit
a0a50f2286
15
handheld/agb001-gba-color-motionblur.slangp
Normal file
15
handheld/agb001-gba-color-motionblur.slangp
Normal file
|
@ -0,0 +1,15 @@
|
|||
shaders = 3
|
||||
|
||||
shader0 = ../motionblur/shaders/response-time.slang
|
||||
filter_linear0 = false
|
||||
scale_type0 = source
|
||||
scale0 = 1.0
|
||||
|
||||
shader1 = shaders/mgba/agb001.slang
|
||||
filter_linear1 = false
|
||||
scale_type1 = source
|
||||
scale1 = 4.0
|
||||
|
||||
shader2 = shaders/color/gba-color.slang
|
||||
filter_linear2 = true
|
||||
scale_type2 = viewport
|
10
handheld/agb001.slangp
Normal file
10
handheld/agb001.slangp
Normal file
|
@ -0,0 +1,10 @@
|
|||
shaders = 2
|
||||
|
||||
shader0 = shaders/mgba/agb001.slang
|
||||
filter_linear0 = false
|
||||
scale_type0 = source
|
||||
scale0 = 4.0
|
||||
|
||||
shader1 = ../stock.slang
|
||||
filter_linear1 = true
|
||||
scale_type1 = viewport
|
20
handheld/ags001-gba-color-motionblur.slangp
Normal file
20
handheld/ags001-gba-color-motionblur.slangp
Normal file
|
@ -0,0 +1,20 @@
|
|||
shaders = 4
|
||||
|
||||
shader0 = ../motionblur/shaders/response-time.slang
|
||||
filter_linear0 = false
|
||||
scale_type0 = source
|
||||
scale0 = 1.0
|
||||
|
||||
shader1 = shaders/mgba/ags001.slang
|
||||
filter_linear1 = false
|
||||
scale_type1 = source
|
||||
scale1 = 4.0
|
||||
|
||||
shader2 = shaders/color/gba-color.slang
|
||||
filter_linear2 = false
|
||||
scale_type2 = source
|
||||
scale2 = 1.0
|
||||
|
||||
shader3 = shaders/mgba/ags001-light.slang
|
||||
filter_linear3 = true
|
||||
scale_type3 = viewport
|
10
handheld/ags001.slangp
Normal file
10
handheld/ags001.slangp
Normal file
|
@ -0,0 +1,10 @@
|
|||
shaders = 2
|
||||
|
||||
shader0 = shaders/mgba/ags001.slang
|
||||
filter_linear0 = false
|
||||
scale_type0 = source
|
||||
scale0 = 4.0
|
||||
|
||||
shader1 = shaders/mgba/ags001-light.slang
|
||||
filter_linear1 = true
|
||||
scale_type1 = viewport
|
15
handheld/sameboy-lcd-gbc-color-motionblur.slangp
Normal file
15
handheld/sameboy-lcd-gbc-color-motionblur.slangp
Normal file
|
@ -0,0 +1,15 @@
|
|||
shaders = 3
|
||||
|
||||
shader0 = ../motionblur/shaders/response-time.slang
|
||||
filter_linear0 = false
|
||||
scale_type0 = source
|
||||
scale0 = 1.0
|
||||
|
||||
shader1 = shaders/sameboy-lcd.slang
|
||||
filter_linear1 = false
|
||||
scale_type1 = viewport
|
||||
scale1 = "1.0"
|
||||
|
||||
shader2 = shaders/color/gbc-color.slang
|
||||
filter_linear2 = false
|
||||
scale_type2 = viewport
|
6
handheld/sameboy-lcd.slangp
Normal file
6
handheld/sameboy-lcd.slangp
Normal file
|
@ -0,0 +1,6 @@
|
|||
shaders = 1
|
||||
|
||||
shader0 = shaders/sameboy-lcd.slang
|
||||
filter_linear0 = false
|
||||
scale_type0 = "viewport"
|
||||
scale0 = "1.0"
|
57
handheld/shaders/mgba/agb001.slang
Normal file
57
handheld/shaders/mgba/agb001.slang
Normal file
|
@ -0,0 +1,57 @@
|
|||
#version 450
|
||||
|
||||
/*
|
||||
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/.
|
||||
*/
|
||||
|
||||
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);
|
||||
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 * global.SourceSize.x * 4.0, 4.0))];
|
||||
color.rgb *= arrayY[int(mod(vTexCoord.t * global.SourceSize.y * 4.0, 4.0))];
|
||||
color.a = 0.5;
|
||||
FragColor = color;
|
||||
|
||||
}
|
74
handheld/shaders/mgba/ags001-light.slang
Normal file
74
handheld/shaders/mgba/ags001-light.slang
Normal file
|
@ -0,0 +1,74 @@
|
|||
#version 450
|
||||
|
||||
/*
|
||||
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/.
|
||||
*/
|
||||
|
||||
layout(std140, set = 0, binding = 0) uniform UBO
|
||||
{
|
||||
mat4 MVP;
|
||||
vec4 OutputSize;
|
||||
vec4 OriginalSize;
|
||||
vec4 SourceSize;
|
||||
} global;
|
||||
|
||||
layout(push_constant) uniform Push
|
||||
{
|
||||
float reflectionBrightness;
|
||||
float reflectionDistanceX;
|
||||
float reflectionDistanceY;
|
||||
float lightBrightness;
|
||||
} params;
|
||||
|
||||
#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
|
||||
|
||||
#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;
|
||||
|
||||
const float speed = 2.0;
|
||||
const float decay = 2.0;
|
||||
const float coeff = 2.5;
|
||||
|
||||
void main()
|
||||
{
|
||||
vec2 reflectionDistance = vec2(params.reflectionDistanceX,params.reflectionDistanceY);
|
||||
float sp = pow(speed, params.lightBrightness);
|
||||
float dc = pow(decay, -params.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 = texture(Source, vTexCoord);
|
||||
color.rgb += pow(bleed, pow(vec3(params.lightBrightness), vec3(-0.5)));
|
||||
|
||||
vec4 reflection = texture(Source, vTexCoord - reflectionDistance);
|
||||
color.rgb += reflection.rgb * params.reflectionBrightness;
|
||||
color.a = 1.0;
|
||||
FragColor = color;
|
||||
|
||||
}
|
57
handheld/shaders/mgba/ags001.slang
Normal file
57
handheld/shaders/mgba/ags001.slang
Normal file
|
@ -0,0 +1,57 @@
|
|||
#version 450
|
||||
|
||||
/*
|
||||
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/.
|
||||
*/
|
||||
|
||||
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);
|
||||
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 * global.SourceSize.x * 4.0, 4.0))];
|
||||
color.rgb *= arrayY[int(mod(vTexCoord.t * global.SourceSize.y * 4.0, 4.0))];
|
||||
color.a = 0.8;
|
||||
FragColor = color;
|
||||
|
||||
}
|
120
handheld/shaders/sameboy-lcd.slang
Normal file
120
handheld/shaders/sameboy-lcd.slang
Normal file
|
@ -0,0 +1,120 @@
|
|||
#version 450
|
||||
|
||||
/*
|
||||
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.
|
||||
*/
|
||||
|
||||
layout(std140, set = 0, binding = 0) uniform UBO
|
||||
{
|
||||
vec4 SourceSize;
|
||||
vec4 OriginalSize;
|
||||
vec4 OutputSize;
|
||||
mat4 MVP;
|
||||
} 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;
|
||||
|
||||
#define COLOR_LOW 0.8
|
||||
#define COLOR_HIGH 1.0
|
||||
#define SCANLINE_DEPTH 0.1
|
||||
|
||||
void main()
|
||||
{
|
||||
vec2 pos = fract(vTexCoord * global.SourceSize.xy);
|
||||
vec2 sub_pos = fract(vTexCoord * global.SourceSize.xy * 6);
|
||||
|
||||
vec4 center = texture(Source, vTexCoord);
|
||||
vec4 left = texture(Source, vTexCoord - vec2(1.0 / global.SourceSize.x, 0));
|
||||
vec4 right = texture(Source, vTexCoord + vec2(1.0 / global.SourceSize.x, 0));
|
||||
|
||||
if (pos.y < 1.0 / 6.0) {
|
||||
center = mix(center, texture(Source, vTexCoord + vec2(0, -1.0 / global.SourceSize.y)), 0.5 - sub_pos.y / 2.0);
|
||||
left = mix(left, texture(Source, vTexCoord + vec2(-1.0 / global.SourceSize.x, -1.0 / global.SourceSize.y)), 0.5 - sub_pos.y / 2.0);
|
||||
right = mix(right, texture(Source, vTexCoord + vec2( 1.0 / global.SourceSize.x, -1.0 / global.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, texture(Source, vTexCoord + vec2(0, 1.0 / global.SourceSize.y)), sub_pos.y / 2.0);
|
||||
left = mix(left, texture(Source, vTexCoord + vec2(-1.0 / global.SourceSize.x, 1.0 / global.SourceSize.y)), sub_pos.y / 2.0);
|
||||
right = mix(right, texture(Source, vTexCoord + vec2( 1.0 / global.SourceSize.x, 1.0 / global.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;
|
||||
}
|
Loading…
Reference in a new issue