-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a355b75
commit 3346797
Showing
7 changed files
with
164 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
// =============================================================================== // | ||
// // | ||
// LCD Shader // | ||
// Derived from: https://github.com/LIJI32/SameBoy/blob/master/Shaders/LCD.fsh // | ||
// // | ||
// =============================================================================== // | ||
|
||
const COLOR_LOW: f32 = 0.6; | ||
const COLOR_HIGH: f32 = 1.0; | ||
const SCANLINE_DEPTH_2: f32 = 0.2; | ||
|
||
@fragment | ||
fn fs_main(in: VertexOutput) -> @location(0) vec4<f32> { | ||
var position = in.tex_coords; | ||
|
||
var pos = fract(position * globals.input_resolution); | ||
var sub_pos = fract(position * globals.input_resolution * 6); | ||
|
||
var center = textureSample(t_diffuse, s_diffuse, position, vec2(0, 0)); | ||
var left = textureSample(t_diffuse, s_diffuse, position, vec2(-1, 0)); | ||
var right = textureSample(t_diffuse, s_diffuse, position, vec2(1, 0)); | ||
|
||
if (pos.y < 1.0 / 6.0) { | ||
center = mix(center, textureSample(t_diffuse, s_diffuse, position, vec2( 0, -1)), 0.5 - sub_pos.y / 2.0); | ||
left = mix(left, textureSample(t_diffuse, s_diffuse, position, vec2(-1, -1)), 0.5 - sub_pos.y / 2.0); | ||
right = mix(right, textureSample(t_diffuse, s_diffuse, position, vec2( 1, -1)), 0.5 - sub_pos.y / 2.0); | ||
center *= sub_pos.y * SCANLINE_DEPTH_2 + (1 - SCANLINE_DEPTH_2); | ||
left *= sub_pos.y * SCANLINE_DEPTH_2 + (1 - SCANLINE_DEPTH_2); | ||
right *= sub_pos.y * SCANLINE_DEPTH_2 + (1 - SCANLINE_DEPTH_2); | ||
} | ||
else if (pos.y > 5.0 / 6.0) { | ||
center = mix(center, textureSample(t_diffuse, s_diffuse, position, vec2( 0, 1)), sub_pos.y / 2.0); | ||
left = mix(left, textureSample(t_diffuse, s_diffuse, position, vec2(-1, 1)), sub_pos.y / 2.0); | ||
right = mix(right, textureSample(t_diffuse, s_diffuse, position, vec2( 1, 1)), sub_pos.y / 2.0); | ||
center *= (1.0 - sub_pos.y) * SCANLINE_DEPTH_2 + (1 - SCANLINE_DEPTH_2); | ||
left *= (1.0 - sub_pos.y) * SCANLINE_DEPTH_2 + (1 - SCANLINE_DEPTH_2); | ||
right *= (1.0 - sub_pos.y) * SCANLINE_DEPTH_2 + (1 - SCANLINE_DEPTH_2); | ||
} | ||
|
||
|
||
var midleft = mix(left, center, 0.5); | ||
var midright = mix(right, center, 0.5); | ||
|
||
var ret = vec4(0.0, 0.0, 0.0, 0.0); | ||
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); | ||
} | ||
|
||
return ret; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// =============================================================================== // | ||
// // | ||
// Mono LCD Shader // | ||
// Derived from: https://github.com/LIJI32/SameBoy/blob/master/Shaders/MonoLCD.fsh // | ||
// // | ||
// =============================================================================== // | ||
|
||
const SCANLINE_DEPTH: f32 = 0.25; | ||
const BLOOM: f32 = 0.4; | ||
|
||
@fragment | ||
fn fs_main(in: VertexOutput) -> @location(0) vec4<f32> { | ||
var position = in.tex_coords; | ||
|
||
var pixel = position * globals.input_resolution - vec2(0.5, 0.5); | ||
|
||
var q11 = textureSample(t_diffuse, s_diffuse, (floor(pixel) + 0.5) / globals.input_resolution); | ||
var q12 = textureSample(t_diffuse, s_diffuse, (vec2(floor(pixel.x), ceil(pixel.y)) + 0.5) / globals.input_resolution); | ||
var q21 = textureSample(t_diffuse, s_diffuse, (vec2(ceil(pixel.x), floor(pixel.y)) + 0.5) / globals.input_resolution); | ||
var q22 = textureSample(t_diffuse, s_diffuse, (ceil(pixel) + 0.5) / globals.input_resolution); | ||
|
||
var s = vec2(smoothstep(0.0, 1.0, fract(pixel.x)), smoothstep(0.0, 1.0, fract(pixel.y))); | ||
|
||
var r1 = mix(q11, q21, s.x); | ||
var r2 = mix(q12, q22, s.x); | ||
|
||
var pos = fract(position * globals.input_resolution); | ||
var sub_pos = fract(position * globals.input_resolution * 6); | ||
|
||
var multiplier: f32 = 1.0; | ||
|
||
if (pos.y < 1.0 / 6.0) { | ||
multiplier *= sub_pos.y * SCANLINE_DEPTH + (1 - SCANLINE_DEPTH); | ||
} | ||
else if (pos.y > 5.0 / 6.0) { | ||
multiplier *= (1.0 - sub_pos.y) * SCANLINE_DEPTH + (1 - SCANLINE_DEPTH); | ||
} | ||
|
||
if (pos.x < 1.0 / 6.0) { | ||
multiplier *= sub_pos.x * SCANLINE_DEPTH + (1 - SCANLINE_DEPTH); | ||
} | ||
else if (pos.x > 5.0 / 6.0) { | ||
multiplier *= (1.0 - sub_pos.x) * SCANLINE_DEPTH + (1 - SCANLINE_DEPTH); | ||
} | ||
|
||
var pre_shadow = mix(textureSample(t_diffuse, s_diffuse, position) * multiplier, mix(r1, r2, s.y), BLOOM); | ||
pixel += vec2(-0.6, -0.8); | ||
|
||
q11 = textureSample(t_diffuse, s_diffuse, (floor(pixel) + 0.5) / globals.input_resolution); | ||
q12 = textureSample(t_diffuse, s_diffuse, (vec2(floor(pixel.x), ceil(pixel.y)) + 0.5) / globals.input_resolution); | ||
q21 = textureSample(t_diffuse, s_diffuse, (vec2(ceil(pixel.x), floor(pixel.y)) + 0.5) / globals.input_resolution); | ||
q22 = textureSample(t_diffuse, s_diffuse, (ceil(pixel) + 0.5) / globals.input_resolution); | ||
|
||
r1 = mix(q11, q21, fract(pixel.x)); | ||
r2 = mix(q12, q22, fract(pixel.x)); | ||
|
||
var shadow = mix(r1, r2, fract(pixel.y)); | ||
return mix(min(shadow, pre_shadow), pre_shadow, 0.75); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
@fragment | ||
fn fs_main(in: VertexOutput) -> @location(0) vec4<f32> { | ||
return textureSample(t_diffuse, s_diffuse, in.tex_coords); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters