A vkrunner shader test that renders a plasma
[require] | |
fbsize 800 600 | |
[vertex shader passthrough] | |
[fragment shader] | |
#version 450 | |
layout(location = 0) out vec4 out_color; | |
#define M_PI 3.14159 | |
const vec2 res = vec2(800.0, 600.0); | |
const float aspect = res.x / res.y; | |
float psin(float x) | |
{ | |
return sin(x) * 0.5 + 0.5; | |
} | |
float pcos(float x) | |
{ | |
return cos(x) * 0.5 + 0.5; | |
} | |
float rsin(vec2 uv, vec2 c, float freq) | |
{ | |
return psin(length(uv - c) * freq); | |
} | |
float rcos(vec2 uv, vec2 c, float freq) | |
{ | |
return pcos(length(uv - c) * freq); | |
} | |
vec3 hsv2rgb(in vec3 c) | |
{ | |
vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0); | |
vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www); | |
return c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y); | |
} | |
vec3 plasma_color(float n) | |
{ | |
return hsv2rgb(vec3(n, 0.66, 1.9)); | |
/* float t = n * M_PI * 2.0; | |
return vec3(pcos(t), psin(t), 1.0 - pcos(t)); */ | |
} | |
void main() | |
{ | |
vec2 uv = (gl_FragCoord.xy / res) * vec2(aspect, 1.0); | |
float plasma = rcos(uv + psin(uv.y * 5.0) * 0.3, vec2(0.2, 0.4), 8.0); | |
plasma += psin(uv.x * 4.0 + pcos(uv.y * 3.0) + rsin(uv, vec2(0.8, 0.6), 8.0) * 9.0); | |
plasma += pcos(uv.y * 6.0 + psin(uv.x * 1.5)); | |
plasma += psin(uv.x * uv.y * 7.0) * 3.0; | |
out_color.rgb = plasma_color(plasma); | |
out_color.a = 1.0; | |
} | |
[test] | |
draw rect -1 -1 2 2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment