Skip to content

Instantly share code, notes, and snippets.

@haxiomic
Created October 26, 2019 21:30
Show Gist options
  • Save haxiomic/d50f6c93dece8d83dda5c679847622af to your computer and use it in GitHub Desktop.
Save haxiomic/d50f6c93dece8d83dda5c679847622af to your computer and use it in GitHub Desktop.
// Author: @patriciogv
// Title: Simple Voronoi
#ifdef GL_ES
precision mediump float;
#endif
uniform vec2 u_resolution;
uniform vec2 u_mouse;
uniform float u_time;
vec2 random2( vec2 p ) {
return fract(sin(vec2(dot(p,vec2(127.1,311.7)),dot(p,vec2(269.5,183.3))))*43758.5453);
}
float lattice(vec3 p) {
return 2. * mod(p.x, 1.0) - 1.0;
}
float axial(float u) {
return abs(2.*mod(u, 1.) - 1.);
}
float midscape(vec3 p) {
return (axial(p.x) + axial(p.y) + axial(p.z))/3. - 0.5;
}
float gyroid(vec3 p) {
const float PI = 3.14159;
return sin(2.*PI*p.x)*cos(2.*PI*p.y) + sin(2.*PI*p.y)*cos(2.*PI*p.z) + sin(2.*PI*p.z)*cos(2.*PI*p.x);
}
float slice(vec2 st, float az, float el) {
float esx = cos(az);
float esy = -sin(az);
float etx = cos(el) * sin(az);
float ety = cos(el) * cos(az);
float etz = sin(el);
return
//midscape
gyroid
(vec3(esx*st.x + etx*st.y, esy*st.x + ety*st.y, etz*st.y));
}
void main() {
vec2 st = gl_FragCoord.xy/u_resolution.xy;
st.x *= u_resolution.x/u_resolution.y;
vec3 p = vec3(st * 2.0 - 1., 0.);
float s = 3.;
float el = s*u_mouse.x/u_resolution.x - s*0.5;
float az = s*u_mouse.y/u_resolution.y - s*0.5;
float scale = 0.;
float q = slice(st * 100.904, el, az);
gl_FragColor = vec4(vec3(q > 0. ? 1. : 0.), 1.);
}
@Vectornaut
Copy link

Thanks so much for working on this with me! If you don't mind, I'll throw this into a GitHub repository alongside the Processing and Julia viewers we based it on, with the eventual goal of wrapping it all up into a new full-featured viewer that the colleague who suggested the project could use.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment