Files
glsl_playground/basic/distance_field.glsl

22 lines
440 B
GLSL

#ifdef GL_ES
precision mediump float;
#endif
uniform vec2 u_resolution;
void main(){
vec2 st = gl_FragCoord.xy/u_resolution.xy;
st.x *= u_resolution.x/u_resolution.y;
vec3 color = vec3(0.0);
float d = 0.0;
// Remap the space to -1. to 1.
st = st *2.-1.;
// Make the distance field
d = length(st)+length(min(st,0.))+length(max(st,0.));
// Visualize the distance field
gl_FragColor = vec4(vec3(fract(d*10.0)),1.0);
}