mirror of
https://github.com/italicsjenga/slang-shaders.git
synced 2025-02-17 07:27:43 +11:00
add ascii art shader and fix ds-hybrid
This commit is contained in:
parent
541b0c845c
commit
cd2d282159
2 changed files with 68 additions and 2 deletions
2
handheld/shaders/ds-hybrid-view.slang
Normal file → Executable file
2
handheld/shaders/ds-hybrid-view.slang
Normal file → Executable file
|
@ -14,7 +14,7 @@ layout(push_constant) uniform Push
|
||||||
vec4 OutputSize;
|
vec4 OutputSize;
|
||||||
uint FrameCount;
|
uint FrameCount;
|
||||||
float screen_toggle;
|
float screen_toggle;
|
||||||
float scale_correction;
|
float aspect_correction;
|
||||||
} params;
|
} params;
|
||||||
|
|
||||||
#pragma parameter screen_toggle "Screen Toggle" 0.0 0.0 0.5 0.5
|
#pragma parameter screen_toggle "Screen Toggle" 0.0 0.0 0.5 0.5
|
||||||
|
|
66
retro/shaders/ascii.slang
Executable file
66
retro/shaders/ascii.slang
Executable file
|
@ -0,0 +1,66 @@
|
||||||
|
#version 450
|
||||||
|
|
||||||
|
// Bitmap to ASCII (not really) fragment shader by movAX13h, September 2013
|
||||||
|
// --- This shader is now used in Pixi JS ---
|
||||||
|
// Pixi JS is MIT-licensed
|
||||||
|
|
||||||
|
layout(push_constant) uniform Push
|
||||||
|
{
|
||||||
|
vec4 SourceSize;
|
||||||
|
vec4 OriginalSize;
|
||||||
|
vec4 OutputSize;
|
||||||
|
uint FrameCount;
|
||||||
|
} params;
|
||||||
|
|
||||||
|
layout(std140, set = 0, binding = 0) uniform UBO
|
||||||
|
{
|
||||||
|
mat4 MVP;
|
||||||
|
} global;
|
||||||
|
|
||||||
|
float character(float n, vec2 p) // some compilers have the word "char" reserved
|
||||||
|
{
|
||||||
|
p = floor(p*vec2(4.0, -4.0) + 2.5);
|
||||||
|
if (clamp(p.x, 0.0, 4.0) == p.x && clamp(p.y, 0.0, 4.0) == p.y)
|
||||||
|
{
|
||||||
|
if (int(mod(n/exp2(p.x + 5.0*p.y), 2.0)) == 1) return 1.0;
|
||||||
|
}
|
||||||
|
return 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()
|
||||||
|
{
|
||||||
|
vec2 uv = gl_FragCoord.xy;
|
||||||
|
vec3 col = texture(Source, floor(uv/8.0)*8.0/params.OutputSize.xy + vec2(-0.21, 0.0)).rgb;
|
||||||
|
|
||||||
|
float gray = dot(col.rgb, vec3(0.299, 0.587, 0.114));
|
||||||
|
|
||||||
|
float n = 65536.0; // .
|
||||||
|
if (gray > 0.2) n = 65600.0; // :
|
||||||
|
if (gray > 0.3) n = 332772.0; // *
|
||||||
|
if (gray > 0.4) n = 15255086.0; // o
|
||||||
|
if (gray > 0.5) n = 23385164.0; // &
|
||||||
|
if (gray > 0.6) n = 15252014.0; // 8
|
||||||
|
if (gray > 0.7) n = 13199452.0; // @
|
||||||
|
if (gray > 0.8) n = 11512810.0; // #
|
||||||
|
|
||||||
|
vec2 p = mod(uv/4.0, 2.0) - vec2(1.0);
|
||||||
|
col = col*character(n, p);
|
||||||
|
|
||||||
|
FragColor = vec4(col, 1.0);
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue