/*by mu6k, Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License. I have no idea how I ended up here, but it demosceneish enough to publish. You can use the mouse to rotate the camera around the 'object'. If you can't see the shadows, increase occlusion_quality. If it doesn't compile anymore decrease object_count and render_steps. 15/06/2013: - published 16/06/2013: - modified for better performance and compatibility muuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuusk!*/ #define occlusion_enabled #define occlusion_quality 4 //#define occlusion_preview #define noise_use_smoothstep #define light_color vec3(0.1,0.4,0.6) #define light_direction normalize(vec3(.2,1.0,-0.2)) #define light_speed_modifier 1.0 #define object_color vec3(0.9,0.1,0.1) #define object_count 9 #define object_speed_modifier 1.0 #define render_steps 33 float hash(float x) { return fract(sin(x*.0127863)*17143.321); } float hash(vec2 x) { return fract(cos(dot(x.xy,vec2(2.31,53.21))*124.123)*412.0); } vec3 cc(vec3 color, float factor,float factor2) //a wierd color modifier { float w = color.x+color.y+color.z; return mix(color,vec3(w)*factor,w*factor2); } float hashmix(float x0, float x1, float interp) { x0 = hash(x0); x1 = hash(x1); #ifdef noise_use_smoothstep interp = smoothstep(0.0,1.0,interp); #endif return mix(x0,x1,interp); } float noise(float p) // 1D noise { float pm = mod(p,1.0); float pd = p-pm; return hashmix(pd,pd+1.0,pm); } vec3 rotate_y(vec3 v, float angle) { float ca = cos(angle); float sa = sin(angle); return v*mat3( +ca, +.0, -sa, +.0,+1.0, +.0, +sa, +.0, +ca); } vec3 rotate_x(vec3 v, float angle) { float ca = cos(angle); float sa = sin(angle); return v*mat3( +1.0, +.0, +.0, +.0, +ca, -sa, +.0, +sa, +ca); } float max3(float a, float b, float c)//returns the maximum of 3 values { return max(a,max(b,c)); } vec3 bpos[object_count];//position for each metaball float dist(vec3 p)//distance function { float d=1024.0; float nd; for (int i=0 ;i4.0) break; } if (dd<0.5) //close enough color = object_material(p,d); else color = background(d); //post procesing color *=.85; color = mix(color,color*color,0.3); color -= hash(color.xy+uv.xy)*.015; color -= length(uv)*.1; color =cc(color,.5,.6); fragColor = vec4(color,1.0); }