Jump to content
  • Advertisement
Sign in to follow this  
urbanmonkey

SuperShapes in GLSL

This topic is 4347 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello all of you who read this, I really would like to implement the SuperShape function from pbourke into a GLSL vertex Shader. At the top of this page: http://local.wasp.uwa.edu.au/~pbourke/surfaces/supershape3d/ you'll see the formula. He was so free to make up the function allready: --------------------- void Eval(double m,double n1,double n2,double n3,double phi,double *x,double *y) { double r; double t1,t2; double a=1,b=1; t1 = cos(m * phi / 4) / a; t1 = ABS(t1); t1 = pow(t1,n2); t2 = sin(m * phi / 4) / b; t2 = ABS(t2); t2 = pow(t2,n3); r = pow(t1+t2,1/n1); if (ABS(r) == 0) { *x = 0; *y = 0; } else { r = 1 / r; *x = r * cos(phi); *y = r * sin(phi); } } --------------------- He also was so free to show how to implement the 3d Version: on the top of the page above, right under the formula. so and this is where i got until now(only vertex shader): --------------------- varying vec4 Color; uniform vec3 LightPosition; uniform vec3 SurfaceColor; const float PI = 3.14159; const float TWO_PI = PI * 2.0; uniform float Radius; uniform float Blend; vec3 pbourke(float m, float n1, float n2, float n3, float phi, vec2 domain) { float r; float t1,t2; float x,y,z; float a=1.0,b=1.0; vec3 range; t1 = cos(m * phi / 4.0) / a; t1 = pow(t1,n2); t2 = sin(m * phi / 4.0) / b; t2 = pow(t2,n3); r = pow(t1+t2,1.0/n1); if (abs(r) == 0.0) { x = 0.0; y = 0.0; z = 0.0; } else { range.x = r * cos(domain.y) * cos(domain.x); range.y = r * sin(domain.y) * cos(domain.x); range.z = r * sin(domain.x); } return range; } void main() { vec2 p0 = gl_Vertex.xy * PI; vec3 normal = pbourke(2.0,0.7,0.3,0.2,1.0,p0); vec3 r0 = Radius * normal; vec3 vertex = r0; normal = normalize(gl_NormalMatrix * normal); vec3 position = vec3(gl_ModelViewMatrix * vec4(vertex, 1.0)); vec3 lightVec = normalize(LightPosition); float diffuse = max(dot(lightVec, normal), 0.65); if (diffuse < 0.125) diffuse = 0.125; Color = vec4(SurfaceColor * diffuse, 1.0); gl_Position = gl_ModelViewProjectionMatrix * vec4(vertex,1.0); } --------------------- It gives me nice effects, but no SuperShades. I'm unfortunately no good programmer and have no idea where to continue. Anybody help me with implementing the SuperShapes into a Vertex Shader?

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!