Archive for November 8th, 2008

08
Nov
08

Superformula Toroidal Mapping

Some screenshots of an alternative version of the superformula vertex shader. Where the previous version was based on a applying the superformula equation to a parametric sphere, this version applies the formula to a base torus (doughnut shape).

Again, no normal calculation.

Here’s a code-snippet, from the vertex shader:

// Superformula equation applied to a sphere or torus

vec3 sf3D(in float m, in float n1, in float n2, in float n3,
	in float mb, in float n1b, in float n2b, in float n3b,
	in float theta, in float phi)
{
	float rt = superFormula(m, n1, n2, n3, theta);
	float rp = superFormula(mb, n1b, n2b, n3b, phi);
	float st = sin(theta);
	float ct = cos(theta);
	float sp = sin(phi);
	float cp = cos(phi);
	
	vec3 sSphere;
	sSphere.x = rt * ct * rp * cp;
	sSphere.y = rt * st * rp * cp;
	sSphere.z = rp * sp;
	
	vec3 sTorus;
	sTorus.x = cp * (rp + rt * ct);
	sTorus.y = sp * (rp + rt * ct);
	sTorus.z = rt * st;
	sTorus *= 0.55;
	
	return (SphereTorus == 0.0) ? sSphere : sTorus;
}
Advertisements



November 2008
M T W T F S S
« Oct   Dec »
 12
3456789
10111213141516
17181920212223
24252627282930

Links

Blog Stats

  • 490,370 hits
Advertisements