Morph a sphere to a cube and a cube to a sphere with GLSL

Posted by nkint on Game Development See other posts from Game Development or by nkint
Published on 2011-01-08T17:19:36Z Indexed on 2012/11/14 17:33 UTC
Read the original article Hit count: 496

Filed under:
|

I'm getting started with GLSL with quartz composer. I have a patch with a particle system in which each particle is mapped into a sphere with a blend value. With blend=0 particles are in random positions, blend=1 particles are in the sphere. The code is here:

vec3 sphere(vec2 domain)
{
    vec3 range;
    range.x = radius * cos(domain.y) * sin(domain.x);
    range.y = radius * sin(domain.y) * sin(domain.x);
    range.z = radius * cos(domain.x);
    return range;
}

// in main:

vec2 p0 = gl_Vertex.xy * twopi;
vec3 normal = sphere(p0);;
vec3 r0 = radius * normal;
vec3 vertex = r0;

normal = normal * blend + gl_Normal * (1.0 - blend);
vertex = vertex * blend + gl_Vertex.xyz * (1.0 - blend);

I'd like the particle to be on a cube if blend=0

I've tried to find but I can't figure out some parametric equation for the cube. Maybe it is not the right way?

© Game Development or respective owner

Related posts about glsl

Related posts about geometry