# SuperShapes in GLSL

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

## 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?

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 10
• 11
• 13
• 9
• 11
• ### Forum Statistics

• Total Topics
634090
• Total Posts
3015434
×