Bring over my bag of shit shaders and use one as a placeholder for the build status indicator.
This commit is contained in:
parent
8f3a3c10c2
commit
d4d8c780a4
20 changed files with 708 additions and 9 deletions
26
assets/shaders.json
Normal file
26
assets/shaders.json
Normal file
|
@ -0,0 +1,26 @@
|
|||
{
|
||||
"ui_shader": {
|
||||
"file_name": "assets/shaders/ui_shader.frag",
|
||||
"type": "fragment"
|
||||
},
|
||||
"ERROR": {
|
||||
"file_name": "assets/shaders/ui_error.frag",
|
||||
"type": "fragment"
|
||||
},
|
||||
"rayview_sprites": {
|
||||
"file_name": "assets/shaders/rayview_sprites.frag",
|
||||
"type": "fragment"
|
||||
},
|
||||
"flame": {
|
||||
"file_name": "assets/shaders/flame_trash.frag",
|
||||
"type": "fragment"
|
||||
},
|
||||
"lightning": {
|
||||
"file_name": "assets/shaders/lightning_attack.frag",
|
||||
"type": "fragment"
|
||||
},
|
||||
"build_status": {
|
||||
"file_name": "assets/shaders/build_status.frag",
|
||||
"type": "fragment"
|
||||
}
|
||||
}
|
52
assets/shaders/brownian_noise.frag
Normal file
52
assets/shaders/brownian_noise.frag
Normal file
|
@ -0,0 +1,52 @@
|
|||
uniform vec2 u_resolution;
|
||||
uniform vec2 u_mouse;
|
||||
uniform float u_time;
|
||||
|
||||
float random (in vec2 st) {
|
||||
return fract(sin(dot(st.xy,
|
||||
vec2(12.9898,78.233)))*
|
||||
43758.5453123);
|
||||
}
|
||||
|
||||
float noise(in vec2 st) {
|
||||
vec2 i = floor(st);
|
||||
vec2 f = fract(st);
|
||||
|
||||
float a = random(i);
|
||||
float b = random(i + vec2(1.0, 0.0));
|
||||
float c = random(i + vec2(0.0, 1.0));
|
||||
float d = random(i + vec2(1.0, 1.0));
|
||||
|
||||
vec2 u = f * f * (3.0 - 2.0 * f);
|
||||
|
||||
return mix(a, b, u.x) +
|
||||
(c - a) * u.y * (1.0 - u.x) +
|
||||
(d - b) * u.x * u.y;
|
||||
}
|
||||
|
||||
float fbm(in vec2 st, int octaves) {
|
||||
float value = 0.0;
|
||||
float amplitude = 0.5;
|
||||
float frequency = 0.0;
|
||||
|
||||
for(int i = 0; i < octaves; i++) {
|
||||
value += amplitude * noise(st);
|
||||
st *= 2.0;
|
||||
amplitude *= 0.5;
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
void main() {
|
||||
vec2 st = gl_FragCoord.xy/u_resolution.xy;
|
||||
st.x *= u_resolution.x/u_resolution.y;
|
||||
|
||||
vec3 color = vec3(0.0);
|
||||
vec2 p = st * sqrt(u_mouse.x);
|
||||
int oct = sqrt(u_mouse.y);
|
||||
|
||||
color += fbm(p, oct);
|
||||
|
||||
gl_FragColor = vec4(color, 1.0);
|
||||
}
|
81
assets/shaders/build_status.frag
Normal file
81
assets/shaders/build_status.frag
Normal file
|
@ -0,0 +1,81 @@
|
|||
#version 120
|
||||
uniform vec2 u_resolution;
|
||||
uniform float u_time;
|
||||
uniform sampler2D source;
|
||||
uniform float u_mouse;
|
||||
uniform float value = 0.2;
|
||||
uniform bool is_error = false;
|
||||
uniform int line_length = 100;
|
||||
|
||||
float random (in vec2 st) {
|
||||
return fract(sin(dot(st.xy,
|
||||
vec2(12.9898,78.233)))*
|
||||
43758.5453123);
|
||||
}
|
||||
|
||||
float noise(in vec2 st) {
|
||||
vec2 i = floor(st);
|
||||
vec2 f = fract(st);
|
||||
|
||||
float a = random(i);
|
||||
float b = random(i + vec2(1.0, 0.0));
|
||||
float c = random(i + vec2(0.0, 1.0));
|
||||
float d = random(i + vec2(1.0, 1.0));
|
||||
|
||||
vec2 u = f * f * (3.0 - 2.0 * f);
|
||||
|
||||
return mix(a, b, u.x) +
|
||||
(c - a) * u.y * (1.0 - u.x) +
|
||||
(d - b) * u.x * u.y;
|
||||
}
|
||||
|
||||
float fbm(in vec2 st, int octaves=8) {
|
||||
float v = 0.0;
|
||||
float a = 0.5;
|
||||
vec2 shift = vec2(100.0);
|
||||
mat2 rot = mat2(cos(0.5), sin(0.5),
|
||||
-sin(0.5), cos(0.5));
|
||||
|
||||
for(int i = 0; i < octaves; i++) {
|
||||
v += a * noise(st);
|
||||
st = rot * st * 2.0 + shift;
|
||||
a *= 0.5;
|
||||
}
|
||||
|
||||
return v;
|
||||
}
|
||||
|
||||
void main() {
|
||||
vec2 st = gl_FragCoord.xy/u_resolution.xy * 3.0;
|
||||
vec3 color = vec3(0.0);
|
||||
|
||||
float speed = u_time;
|
||||
float value = 0.8;
|
||||
vec3 base_tone = is_error ? vec3(1.0, 0.5, 0.5) : vec3(0.5, 1.0, 0.5);
|
||||
|
||||
vec2 q = vec2(0.0);
|
||||
q.x = fbm(st);
|
||||
q.y = fbm(st + vec2(1.0));
|
||||
|
||||
vec2 r = vec2(0,0);
|
||||
r.x += fbm( st + 1.0*q + vec2(1.0, 0.0)+ 0.15* speed );
|
||||
r.y += fbm( st + 1.0*q + vec2(-1.0, 0.0)+ 0.126* speed);
|
||||
|
||||
float f = fbm(st / r);
|
||||
|
||||
color = mix(vec3(0.122777,0.122777, 0.122777) * base_tone,
|
||||
vec3(0.498039,0.498039,0.498039) * base_tone,
|
||||
clamp((f*f)*4.0,0.0,1.0));
|
||||
|
||||
color = mix(color,
|
||||
vec3(0.666667, 0.666667, 0.666667) * base_tone,
|
||||
clamp(length(r.x), 0.0, 1.0));
|
||||
|
||||
color *= (f*f*f+0.5*f*f+0.6*f) * value;
|
||||
|
||||
vec4 pixel = texture2D(source, gl_TexCoord[0].xy);
|
||||
|
||||
float mask = color.r * pixel.a;
|
||||
|
||||
gl_FragColor = gl_Color * vec4(color, mask) + pixel;
|
||||
}
|
35
assets/shaders/color_circle_cells.frag
Normal file
35
assets/shaders/color_circle_cells.frag
Normal file
|
@ -0,0 +1,35 @@
|
|||
uniform vec2 u_resolution;
|
||||
uniform vec2 u_mouse;
|
||||
uniform float u_time;
|
||||
|
||||
void main() {
|
||||
vec2 st = gl_FragCoord.xy/u_resolution.xy;
|
||||
st.x *= u_resolution.x/u_resolution.y;
|
||||
|
||||
vec3 color = vec3(0.0);
|
||||
|
||||
vec2 point[5];
|
||||
point[0] = vec2(0.83, 0.75);
|
||||
point[1] = vec2(0.60, 0.07);
|
||||
point[2] = vec2(0.28, 0.64);
|
||||
point[3] = vec2(0.31, 0.26);
|
||||
point[4] = u_mouse/u_resolution;
|
||||
|
||||
float m_dist = 1.0;
|
||||
vec2 m_point;
|
||||
|
||||
for(int i = 0; i < 5; i++) {
|
||||
float dist = distance(st, point[i]);
|
||||
if(dist < m_dist) {
|
||||
m_dist = dist;
|
||||
m_point = point[i];
|
||||
}
|
||||
}
|
||||
|
||||
color += m_dist * 2.0;
|
||||
color.rg = m_point;
|
||||
color -= abs(sin(80.0 * m_dist)) * 0.07;
|
||||
color += 1.0 - step(0.02, m_dist);
|
||||
|
||||
gl_FragColor = vec4(color, 1.0);
|
||||
}
|
41
assets/shaders/dayfour.frag
Normal file
41
assets/shaders/dayfour.frag
Normal file
|
@ -0,0 +1,41 @@
|
|||
uniform vec2 u_resolution;
|
||||
uniform vec2 u_mouse;
|
||||
uniform float u_time;
|
||||
uniform sampler2D texture;
|
||||
|
||||
vec2 random2(vec2 p) {
|
||||
return fract(sin(vec2(dot(p,vec2(127.1,311.7)),dot(p,vec2(269.5,183.3))))*43758.5453);
|
||||
}
|
||||
|
||||
void main() {
|
||||
vec2 st = gl_FragCoord.xy/u_resolution.xy;
|
||||
st.x *= u_resolution.x/u_resolution.y;
|
||||
vec3 color = vec3(0.0);
|
||||
|
||||
st *= 3.0;
|
||||
|
||||
vec2 i_st = floor(st);
|
||||
vec2 f_st = fract(st);
|
||||
|
||||
float m_dist = 1.0;
|
||||
|
||||
for(int y = -1; y <= 1; y++) {
|
||||
for(int x = -1; x <= 1; x++) {
|
||||
vec2 neighbor = vec2(float(x), float(y));
|
||||
|
||||
vec2 point = random2(i_st + neighbor);
|
||||
point = 0.5 + 0.5*sin(u_time + 6.2831 * point);
|
||||
vec2 diff = neighbor + point - f_st;
|
||||
float dist = length(diff);
|
||||
m_dist = min(m_dist, dist);
|
||||
}
|
||||
}
|
||||
|
||||
color += m_dist;
|
||||
color += 1.0 - step(0.02, m_dist);
|
||||
color += step(1.0, f_st.x) + step(1.0, f_st.y);
|
||||
|
||||
vec4 pixel = texture2D(texture, gl_TexCoord[0].xy);
|
||||
|
||||
gl_FragColor = gl_Color * vec4(color / 0.8, 1.0) * pixel;
|
||||
}
|
35
assets/shaders/daythree.frag
Normal file
35
assets/shaders/daythree.frag
Normal file
|
@ -0,0 +1,35 @@
|
|||
uniform vec2 u_resolution;
|
||||
uniform vec2 u_mouse;
|
||||
uniform float u_time;
|
||||
|
||||
float random(in vec2 st) {
|
||||
return fract(sin(dot(st.xy,
|
||||
vec2(12.9898,78.233)))
|
||||
* 43758.5453123);
|
||||
}
|
||||
|
||||
float noise(in vec2 st) {
|
||||
vec2 i = floor(st);
|
||||
vec2 f = fract(st);
|
||||
|
||||
float a = random(i);
|
||||
float b = random(i + vec2(1.0, 0.0));
|
||||
float c = random(i + vec2(0.0, 1.0));
|
||||
float d = random(i + vec2(1.0, 1.0));
|
||||
|
||||
vec2 u = f * f * (3.0 - 2.0 * f);
|
||||
|
||||
return mix(a, b, u.x) +
|
||||
(c - a) * u.y * (1.0 - u.x) +
|
||||
(d - b) * u.x * u.y;
|
||||
}
|
||||
|
||||
void main() {
|
||||
vec2 st = gl_FragCoord.xy/u_resolution.xy;
|
||||
|
||||
vec2 pos = vec2(st * 5.0);
|
||||
|
||||
float n = noise(pos);
|
||||
|
||||
gl_FragColor = vec4(vec3(n), 1.0);
|
||||
}
|
45
assets/shaders/daytwo.frag
Normal file
45
assets/shaders/daytwo.frag
Normal file
|
@ -0,0 +1,45 @@
|
|||
uniform vec2 u_resolution;
|
||||
uniform float u_time;
|
||||
|
||||
#define PI 3.14159265358979323846
|
||||
|
||||
vec2 rotate2D(vec2 st, float angle) {
|
||||
st -= 0.5;
|
||||
st = mat2(cos(angle), -sin(angle),
|
||||
sin(angle), cos(angle)) * st;
|
||||
st += 0.5;
|
||||
return st;
|
||||
}
|
||||
|
||||
float box(vec2 st, vec2 size, float smoothEdges) {
|
||||
size = vec2(0.5) - size * 0.5;
|
||||
vec2 aa = vec2(smoothEdges * 0.5);
|
||||
vec2 uv = smoothstep(size, size + aa, st);
|
||||
uv *= smoothstep(size, size+aa, vec2(1.0) - st);
|
||||
return uv.x * uv.y;
|
||||
}
|
||||
|
||||
vec2 tile(vec2 st, float zoom) {
|
||||
st *= zoom;
|
||||
return fract(st);
|
||||
}
|
||||
|
||||
float circle(vec2 st, float radius) {
|
||||
vec2 l = st - vec2(0.5);
|
||||
return 1.0 - smoothstep(radius - (radius * 0.01),
|
||||
radius+(radius * 0.01),
|
||||
dot(l,l) * 4.0);
|
||||
}
|
||||
|
||||
void main() {
|
||||
vec2 st = gl_FragCoord.xy/u_resolution;
|
||||
vec3 color = vec3(0.0);
|
||||
|
||||
st = tile(st, 4.0);
|
||||
|
||||
st = rotate2D(st, PI * sin(u_time) / 4);
|
||||
|
||||
color = vec3(box(st, vec2(0.7), 0.01));
|
||||
|
||||
gl_FragColor = vec4(color, 1.0);
|
||||
}
|
77
assets/shaders/flame_trash.frag
Normal file
77
assets/shaders/flame_trash.frag
Normal file
|
@ -0,0 +1,77 @@
|
|||
uniform vec2 u_resolution;
|
||||
uniform float u_time;
|
||||
uniform sampler2D source;
|
||||
uniform float u_mouse;
|
||||
uniform float value = 0.2;
|
||||
|
||||
float random (in vec2 st) {
|
||||
return fract(sin(dot(st.xy,
|
||||
vec2(12.9898,78.233)))*
|
||||
43758.5453123);
|
||||
}
|
||||
|
||||
float noise(in vec2 st) {
|
||||
vec2 i = floor(st);
|
||||
vec2 f = fract(st);
|
||||
|
||||
float a = random(i);
|
||||
float b = random(i + vec2(1.0, 0.0));
|
||||
float c = random(i + vec2(0.0, 1.0));
|
||||
float d = random(i + vec2(1.0, 1.0));
|
||||
|
||||
vec2 u = f * f * (3.0 - 2.0 * f);
|
||||
|
||||
return mix(a, b, u.x) +
|
||||
(c - a) * u.y * (1.0 - u.x) +
|
||||
(d - b) * u.x * u.y;
|
||||
}
|
||||
|
||||
float fbm(in vec2 st, int octaves=8) {
|
||||
float v = 0.0;
|
||||
float a = 0.5;
|
||||
vec2 shift = vec2(100.0);
|
||||
mat2 rot = mat2(cos(0.5), sin(0.5),
|
||||
-sin(0.5), cos(0.5));
|
||||
|
||||
for(int i = 0; i < octaves; i++) {
|
||||
v += a * noise(st);
|
||||
st = rot * st * 2.0 + shift;
|
||||
a *= 0.5;
|
||||
}
|
||||
|
||||
return v;
|
||||
}
|
||||
|
||||
void main() {
|
||||
vec2 st = gl_FragCoord.xy/u_resolution.xy * 3.0;
|
||||
vec3 color = vec3(0.0);
|
||||
|
||||
float speed = u_time * 10.0;
|
||||
float value = cos(u_time) * cos(u_time);
|
||||
|
||||
vec2 q = vec2(0.0);
|
||||
q.x = fbm(st + 0.00 * speed);
|
||||
q.y = fbm(st + vec2(1.0));
|
||||
|
||||
vec2 r = vec2(0,0);
|
||||
r.x += fbm( st + 1.0*q + vec2(1.0, 0.0)+ 0.15* speed );
|
||||
r.y += fbm( st + 1.0*q + vec2(-1.0, 0.0)+ 0.126* speed);
|
||||
|
||||
float f = fbm(st * r);
|
||||
|
||||
color = mix(vec3(0.666667,0.619608, 0.122777),
|
||||
vec3(0.666667,0.666667,0.498039),
|
||||
clamp((f*f)*4.0,0.0,1.0));
|
||||
|
||||
color = mix(color,
|
||||
vec3(0.666667, 0.122222, 0.0666667),
|
||||
clamp(length(r.x), 0.0, 1.0));
|
||||
|
||||
color *= (f*f*f+0.5*f*f+0.6*f) * value;
|
||||
|
||||
vec4 pixel = texture2D(source, gl_TexCoord[0].xy);
|
||||
|
||||
float mask = color.r * pixel.a;
|
||||
|
||||
gl_FragColor = gl_Color * vec4(color, mask) + pixel;
|
||||
}
|
77
assets/shaders/lightning_attack.frag
Normal file
77
assets/shaders/lightning_attack.frag
Normal file
|
@ -0,0 +1,77 @@
|
|||
uniform vec2 u_resolution;
|
||||
uniform float u_time;
|
||||
uniform sampler2D source;
|
||||
uniform float u_mouse;
|
||||
uniform float value = 0.2;
|
||||
|
||||
float random (in vec2 st) {
|
||||
return fract(sin(dot(st.xy,
|
||||
vec2(12.9898,78.233)))*
|
||||
43758.5453123);
|
||||
}
|
||||
|
||||
float noise(in vec2 st) {
|
||||
vec2 i = floor(st);
|
||||
vec2 f = fract(st);
|
||||
|
||||
float a = random(i);
|
||||
float b = random(i + vec2(1.0, 0.0));
|
||||
float c = random(i + vec2(0.0, 1.0));
|
||||
float d = random(i + vec2(1.0, 1.0));
|
||||
|
||||
vec2 u = f * f * (3.0 - 2.0 * f);
|
||||
|
||||
return mix(a, b, u.x) +
|
||||
(c - a) * u.y * (1.0 - u.x) +
|
||||
(d - b) * u.x * u.y;
|
||||
}
|
||||
|
||||
float fbm(in vec2 st, int octaves=8) {
|
||||
float v = 0.0;
|
||||
float a = 0.5;
|
||||
vec2 shift = vec2(100.0);
|
||||
mat2 rot = mat2(cos(0.5), sin(0.5),
|
||||
-sin(0.5), cos(0.5));
|
||||
|
||||
for(int i = 0; i < octaves; i++) {
|
||||
v += a * noise(st);
|
||||
st = rot * st * 2.0 + shift;
|
||||
a *= 0.5;
|
||||
}
|
||||
|
||||
return v;
|
||||
}
|
||||
|
||||
void main() {
|
||||
vec2 st = gl_FragCoord.xy/u_resolution.xy * 3.0;
|
||||
vec3 color = vec3(0.0);
|
||||
|
||||
float speed = u_time * 40.0;
|
||||
float value = cos(u_time) * cos(u_time);
|
||||
|
||||
vec2 q = vec2(0.0);
|
||||
q.x = fbm(st + 0.00 * speed);
|
||||
q.y = fbm(st + vec2(1.0));
|
||||
|
||||
vec2 r = vec2(0,0);
|
||||
r.x += fbm( st + 1.0*q + vec2(1.0, 0.0)+ 0.15* speed );
|
||||
r.y += fbm( st + 1.0*q + vec2(-1.0, 0.0)+ 0.126* speed);
|
||||
|
||||
float f = fbm(st / r);
|
||||
|
||||
color = mix(vec3(0.122777,0.619608, 0.666667),
|
||||
vec3(0.498039,0.666667,0.666667),
|
||||
clamp((f*f)*4.0,0.0,1.0));
|
||||
|
||||
color = mix(color,
|
||||
vec3(0.0666667, 0.122222, 0.666667),
|
||||
clamp(length(r.x), 0.0, 1.0));
|
||||
|
||||
color *= (f*f*f+0.5*f*f+0.6*f) * value;
|
||||
|
||||
vec4 pixel = texture2D(source, gl_TexCoord[0].xy);
|
||||
|
||||
float mask = color.r * pixel.a;
|
||||
|
||||
gl_FragColor = gl_Color * vec4(color, mask) + pixel;
|
||||
}
|
49
assets/shaders/matscalerot.frag
Normal file
49
assets/shaders/matscalerot.frag
Normal file
|
@ -0,0 +1,49 @@
|
|||
uniform vec2 u_resolution;
|
||||
uniform vec2 u_mouse;
|
||||
uniform float u_time;
|
||||
|
||||
#define PI 3.14159265359
|
||||
|
||||
mat2 scale(vec2 scale) {
|
||||
return mat2(scale.x, 0.0, 0.0, scale.y);
|
||||
}
|
||||
|
||||
float box(in vec2 st, in vec2 size) {
|
||||
size = vec2(0.5) - size * 0.5;
|
||||
|
||||
vec2 uv = smoothstep(size,
|
||||
size + vec2(0.001),
|
||||
st);
|
||||
|
||||
uv *= smoothstep(size,
|
||||
size+vec2(0.001),
|
||||
vec2(1.0) - st);
|
||||
|
||||
return uv.x * uv.y;
|
||||
}
|
||||
|
||||
float cross(in vec2 st, float size) {
|
||||
return box(st, vec2(size, size / 4.0)) +
|
||||
box(st, vec2(size / 4.0, size));
|
||||
}
|
||||
|
||||
mat2 rotate2d(float angle) {
|
||||
return mat2(cos(angle), -sin(angle),
|
||||
sin(angle), cos(angle));
|
||||
}
|
||||
|
||||
void main() {
|
||||
vec2 st = gl_FragCoord.xy / u_resolution.xy;
|
||||
vec3 color = vec3(0.0);
|
||||
|
||||
st -= vec2(0.5);
|
||||
|
||||
st = scale(vec2(sin(u_time) + 1.0)) * st;
|
||||
st = rotate2d(sin(u_time) * PI) * st;
|
||||
|
||||
st += vec2(0.5);
|
||||
|
||||
color += vec3(cross(st, 0.4));
|
||||
|
||||
gl_FragColor = vec4(color, 1.0);
|
||||
}
|
47
assets/shaders/mouse_move_boxes.frag
Normal file
47
assets/shaders/mouse_move_boxes.frag
Normal file
|
@ -0,0 +1,47 @@
|
|||
uniform vec2 u_resolution;
|
||||
uniform vec2 u_mouse;
|
||||
uniform float u_time;
|
||||
|
||||
#define PI 3.14159265358979323846
|
||||
|
||||
vec2 rotate2D(vec2 st, float angle, float view_at=0.5, float origin=0.5) {
|
||||
st -= view_at;
|
||||
st = mat2(cos(angle), -sin(angle),
|
||||
sin(angle), cos(angle)) * st;
|
||||
st += origin;
|
||||
return st;
|
||||
}
|
||||
|
||||
float box(vec2 st, vec2 size, float smoothEdges) {
|
||||
size = vec2(0.5) - size * 0.5;
|
||||
vec2 aa = vec2(smoothEdges * 0.5);
|
||||
vec2 uv = smoothstep(size, size + aa, st);
|
||||
uv *= smoothstep(size, size+aa, vec2(1.0) - st);
|
||||
return uv.x * uv.y;
|
||||
}
|
||||
|
||||
vec2 tile(vec2 st, float zoom) {
|
||||
st *= zoom;
|
||||
return fract(st);
|
||||
}
|
||||
|
||||
float circle(vec2 st, float radius) {
|
||||
vec2 l = st - vec2(0.5);
|
||||
return 1.0 - smoothstep(radius - (radius * 0.01),
|
||||
radius+(radius * 0.01),
|
||||
dot(l,l) * 4.0);
|
||||
}
|
||||
|
||||
void main() {
|
||||
vec2 st = gl_FragCoord.xy/u_resolution;
|
||||
vec3 color = vec3(0.0);
|
||||
vec2 mouse_at = smoothstep(0.1, 0.9, u_mouse/u_resolution);
|
||||
|
||||
st = tile(st, 4.0);
|
||||
|
||||
st = rotate2D(st, PI * sin(u_time) / 4, 0.5, mouse_at);
|
||||
|
||||
color = vec3(box(st, vec2(0.7), 0.01));
|
||||
|
||||
gl_FragColor = vec4(color, 1.0);
|
||||
}
|
50
assets/shaders/moving_squares_on_sprite.frag
Normal file
50
assets/shaders/moving_squares_on_sprite.frag
Normal file
|
@ -0,0 +1,50 @@
|
|||
uniform vec2 u_resolution;
|
||||
uniform vec2 u_mouse;
|
||||
uniform float u_time;
|
||||
uniform sampler2D texture;
|
||||
|
||||
#define PI 3.14159265358979323846
|
||||
|
||||
vec2 rotate2D(vec2 st, float angle, float view_at=0.5, float origin=0.5) {
|
||||
st -= view_at;
|
||||
st = mat2(cos(angle), -sin(angle),
|
||||
sin(angle), cos(angle)) * st;
|
||||
st += origin;
|
||||
return st;
|
||||
}
|
||||
|
||||
float box(vec2 st, vec2 size, float smoothEdges) {
|
||||
size = vec2(0.5) - size * 0.5;
|
||||
vec2 aa = vec2(smoothEdges * 0.5);
|
||||
vec2 uv = smoothstep(size, size + aa, st);
|
||||
uv *= smoothstep(size, size+aa, vec2(1.0) - st);
|
||||
return uv.x * uv.y;
|
||||
}
|
||||
|
||||
vec2 tile(vec2 st, float zoom) {
|
||||
st *= zoom;
|
||||
return fract(st);
|
||||
}
|
||||
|
||||
float circle(vec2 st, float radius) {
|
||||
vec2 l = st - vec2(0.5);
|
||||
return 1.0 - smoothstep(radius - (radius * 0.01),
|
||||
radius+(radius * 0.01),
|
||||
dot(l,l) * 4.0);
|
||||
}
|
||||
|
||||
void main() {
|
||||
vec4 pixel = texture2D(texture, gl_TexCoord[0].xy);
|
||||
|
||||
vec2 st = gl_FragCoord.xy/u_resolution;
|
||||
vec3 color = vec3(0.0);
|
||||
vec2 mouse_at = smoothstep(0.1, 0.9, u_mouse/u_resolution);
|
||||
|
||||
st = tile(st, 4.0);
|
||||
|
||||
st = rotate2D(st, PI * sin(u_time) / 4, 0.5, mouse_at);
|
||||
|
||||
color = vec3(box(st, vec2(0.7), 0.01));
|
||||
|
||||
gl_FragColor = gl_Color * vec4(color, 0.5) * pixel;
|
||||
}
|
18
assets/shaders/ui_error.frag
Normal file
18
assets/shaders/ui_error.frag
Normal file
|
@ -0,0 +1,18 @@
|
|||
uniform vec2 u_resolution;
|
||||
uniform vec2 u_mouse;
|
||||
uniform float u_duration;
|
||||
uniform float u_time;
|
||||
uniform float u_time_end;
|
||||
uniform sampler2D texture;
|
||||
uniform bool is_shape;
|
||||
|
||||
void main() {
|
||||
if(is_shape) {
|
||||
vec4 color = vec4(1.0, 0.0, 0.0, 1.0);
|
||||
gl_FragColor = gl_Color * color;
|
||||
} else {
|
||||
vec4 pixel = texture2D(texture, gl_TexCoord[0].xy);
|
||||
vec4 color = vec4(1.0, 0.0, 0.0, 1.0);
|
||||
gl_FragColor = gl_Color * color * pixel;
|
||||
}
|
||||
}
|
29
assets/shaders/ui_shader.frag
Normal file
29
assets/shaders/ui_shader.frag
Normal file
|
@ -0,0 +1,29 @@
|
|||
uniform vec2 u_resolution;
|
||||
uniform vec2 u_mouse;
|
||||
uniform float u_duration;
|
||||
uniform float u_time;
|
||||
uniform float u_time_end;
|
||||
uniform sampler2D texture;
|
||||
uniform bool is_shape;
|
||||
uniform bool hover;
|
||||
|
||||
vec4 blink() {
|
||||
if(hover) {
|
||||
return vec4(0.95, 0.95, 1.0, 1.0);
|
||||
} else {
|
||||
float tick = (u_time_end - u_time) / u_duration;
|
||||
float blink = mix(0.5, 1.0, tick);
|
||||
return vec4(blink, blink, blink, 1.0);
|
||||
}
|
||||
}
|
||||
|
||||
void main() {
|
||||
vec4 color = blink();
|
||||
|
||||
if(!is_shape) {
|
||||
vec4 pixel = texture2D(texture, gl_TexCoord[0].xy);
|
||||
color *= pixel;
|
||||
}
|
||||
|
||||
gl_FragColor = gl_Color * color;
|
||||
}
|
12
assets/shaders/ui_shape_shader.frag
Normal file
12
assets/shaders/ui_shape_shader.frag
Normal file
|
@ -0,0 +1,12 @@
|
|||
uniform vec2 u_resolution;
|
||||
uniform vec2 u_mouse;
|
||||
uniform float u_duration;
|
||||
uniform float u_time;
|
||||
uniform float u_time_end;
|
||||
|
||||
void main() {
|
||||
float tick = (u_time_end - u_time) / u_duration;
|
||||
float blink = smoothstep(1.0, 0.5, tick);
|
||||
vec4 color = vec4(blink, blink, blink, 1.0);
|
||||
gl_FragColor = gl_Color * color;
|
||||
}
|
11
builder.cpp
11
builder.cpp
|
@ -93,9 +93,14 @@ void Builder::BUILDING(BuildEvent) {
|
|||
auto m = parse_line(line);
|
||||
|
||||
if(m.match) {
|
||||
gui.output(fmt::format("HIT WITH {} @ {}:{}:{} {}", m.type, m.file_name, m.lnumber, m.col, m.message));
|
||||
fmt::println("HIT WITH {} @ {}:{}:{} {}", m.type, m.file_name, m.lnumber, m.col, m.message);
|
||||
|
||||
game.event(GameEvent::HIT, m.type);
|
||||
gui.update_status(game, line.size(), true);
|
||||
} else {
|
||||
gui.update_status(game, line.size(), false);
|
||||
}
|
||||
|
||||
state(BuildState::READING);
|
||||
}
|
||||
}
|
||||
|
@ -117,7 +122,7 @@ void Builder::START(BuildEvent) {
|
|||
wid = fileWatcher->addWatch(git_path, listener, true);
|
||||
fileWatcher->watch();
|
||||
|
||||
gui.update_status(game);
|
||||
gui.update_status(game, 100, false);
|
||||
|
||||
state(BuildState::WAITING);
|
||||
}
|
||||
|
@ -169,7 +174,7 @@ void Builder::READING(BuildEvent) {
|
|||
}
|
||||
|
||||
void Builder::DONE(BuildEvent) {
|
||||
gui.update_status(game);
|
||||
gui.update_status(game, 100, false);
|
||||
|
||||
if(game.is_dead()) {
|
||||
gui.you_died();
|
||||
|
|
|
@ -155,8 +155,8 @@ namespace guecs {
|
|||
rect.init(cell);
|
||||
});
|
||||
|
||||
$world.query<lel::Cell, Effect>([](auto, auto& cell, auto& shader) {
|
||||
shader.init(cell);
|
||||
$world.query<lel::Cell, Effect>([](auto, auto& cell, auto& effect) {
|
||||
effect.init(cell);
|
||||
});
|
||||
|
||||
$world.query<Rectangle, Meter>([](auto, auto& bg, auto &) {
|
||||
|
|
23
gui.cpp
23
gui.cpp
|
@ -12,6 +12,7 @@
|
|||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include "sound.hpp"
|
||||
#include "shaders.hpp"
|
||||
|
||||
using std::string, std::vector;
|
||||
|
||||
|
@ -27,7 +28,7 @@ GUI::GUI(SFMLBackend &backend) : sfml(backend) {
|
|||
"[_|_|_|_|_]"
|
||||
"[hp_bar]");
|
||||
|
||||
$gui.world().set_the<Background>({$gui.$parser, ColorValue::DARK_MID});
|
||||
$gui.world().set_the<Background>({$gui.$parser, {0,0,0,0}});
|
||||
|
||||
for(auto& [name, cell] : $gui.cells()) {
|
||||
auto ent = $gui.entity(name);
|
||||
|
@ -41,7 +42,9 @@ GUI::GUI(SFMLBackend &backend) : sfml(backend) {
|
|||
$gui.set<Textual>(status, {L""});
|
||||
|
||||
auto log = $gui.entity("log");
|
||||
$gui.set<Textual>(log, {L"LOG"});
|
||||
auto& rect = $gui.get<Rectangle>(log);
|
||||
rect.color = {255,255,255,255};
|
||||
$gui.set<Effect>(log, {1000.0, "build_status"});
|
||||
|
||||
auto clock = $gui.entity("clock");
|
||||
$gui.set<Label>(clock, {L"00:00:00", 110});
|
||||
|
@ -72,6 +75,7 @@ void GUI::main_loop() {
|
|||
}
|
||||
|
||||
void GUI::build_success() {
|
||||
$hit_error = false;
|
||||
$gui.show_sprite("face", "build_success");
|
||||
sound::stop("building");
|
||||
sound::play("build_success");
|
||||
|
@ -79,6 +83,7 @@ void GUI::build_success() {
|
|||
}
|
||||
|
||||
void GUI::build_failed(bool play_sound, const string &command) {
|
||||
$hit_error = true;
|
||||
$gui.show_sprite("face", "build_failed");
|
||||
sound::stop("building");
|
||||
|
||||
|
@ -89,7 +94,18 @@ void GUI::build_failed(bool play_sound, const string &command) {
|
|||
output(fmt::format("!!! BUILD FAILED. Your command correct? '{}'", command));
|
||||
}
|
||||
|
||||
void GUI::update_status(GameEngine &game) {
|
||||
void GUI::update_status(GameEngine &game, size_t line_length, bool is_error) {
|
||||
|
||||
auto log = $gui.entity("log");
|
||||
auto& effect = $gui.get<guecs::Effect>(log);
|
||||
effect.$shader->setUniform("line_length", (int)line_length);
|
||||
if(!$hit_error && is_error) {
|
||||
$hit_error = is_error;
|
||||
}
|
||||
|
||||
effect.$shader->setUniform("is_error", $hit_error);
|
||||
effect.run();
|
||||
|
||||
$status = fmt::format(L"HP {}\nRounds {}\nStreaks {}\nDeaths {}",
|
||||
game.hit_points, game.rounds,
|
||||
game.streak, game.deaths);
|
||||
|
@ -107,6 +123,7 @@ void GUI::you_died() {
|
|||
}
|
||||
|
||||
void GUI::building() {
|
||||
$hit_error = false;
|
||||
$gui.show_sprite("face", "building");
|
||||
output("############# START ############");
|
||||
output(">>>> Will it Build?");
|
||||
|
|
3
gui.hpp
3
gui.hpp
|
@ -15,13 +15,14 @@ class GUI {
|
|||
guecs::UI $gui;
|
||||
std::wstring $status;
|
||||
DinkyECS::Entity $hp_bar;
|
||||
bool $hit_error = false;
|
||||
|
||||
public:
|
||||
|
||||
GUI(SFMLBackend &backend);
|
||||
|
||||
void output(const string msg);
|
||||
void update_status(GameEngine &game);
|
||||
void update_status(GameEngine &game, size_t line_length, bool is_error);
|
||||
|
||||
void main_loop();
|
||||
|
||||
|
|
2
main.cpp
2
main.cpp
|
@ -3,10 +3,12 @@
|
|||
#include <fmt/core.h>
|
||||
#include "sound.hpp"
|
||||
#include "textures.hpp"
|
||||
#include "shaders.hpp"
|
||||
|
||||
int main()
|
||||
{
|
||||
sound::init();
|
||||
shaders::init();
|
||||
textures::init();
|
||||
|
||||
GameEngine game{100};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue