Skip to content

Instantly share code, notes, and snippets.

@Hamcha
Created November 28, 2012 13:47
Show Gist options
  • Save Hamcha/4161427 to your computer and use it in GitHub Desktop.
Save Hamcha/4161427 to your computer and use it in GitHub Desktop.
uniform vec2 resolution;
uniform float lowFreq, midFreq, highFreq;
uniform float time;
uniform vec2 mouse;
void rX(inout vec3 p, float a) { float c,s;vec3 q=p; c = cos(a); s = sin(a); p.y = c * q.y - s * q.z; p.z = s * q.y + c * q.z; }
void rY(inout vec3 p, float a) { float c,s;vec3 q=p; c = cos(a); s = sin(a); p.x = c * q.x + s * q.z; p.z = -s * q.x + c * q.z;}
float star(vec3 p, float s) { return length(p)-s; }
float starfield(vec3 p, float s, vec3 c) { vec3 q = mod(p,c)-.5*c; return star(q,s); }
vec2 map(vec3 p)
{
float a = starfield(p, .1+.05*abs(sin(time)), vec3(1.,1.,1.));
return vec2(a,1.);
}
vec2 intersect(in vec3 ro, in vec3 rd)
{
for (float t = .0; t < 100.;)
{
vec2 h = map(ro+rd*t);
if (h.x < .0001) return vec2(t,h.y);
t += h.x;
}
return vec2(0);
}
void main( void ) {
vec2 p = -1.0 + 2.0 * ( gl_FragCoord.xy / resolution.xy );
p.x *= resolution.x / resolution.y;
vec3 ro = vec3(0,0,1.0-time);
vec3 rd = normalize(vec3(p, -1.));
rX(rd,mouse.y);
rY(rd,mouse.x);
vec3 color = vec3(0);
vec2 t = intersect(ro,rd);
if (t.y > .0) {
color = vec3(t.x,1.-mod(t.x,1.),abs(sin(time/5.))+.5);
}
gl_FragColor = vec4(color,1.0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment