Hello.
The code below is supposed to create a surface looking something like this from a plane grid:
Unfortunately, what I get is just a big disk. Can anyone see any obvious errors in my code?
/////////////////////
//// CONSTANTS ////
/////////////////////
#define TWOPI 6.28318531
#define PI 3.14159265
////////////////////
//// CONTROLS ////
////////////////////
// Pre-transform matrix
// Since QC won't display mat4 variables as inputs, I'm using 4 separate
// vec4s (one for each column of the transformation matrix).
uniform vec4 TT_0;
uniform vec4 TT_1;
uniform vec4 TT_2;
uniform vec4 TT_3;
// Select algorithm
uniform int Select;
// Tweakables not always active (depends on algorithm)
uniform float A;
uniform float B;
uniform float C;
uniform float D;
// Light position
uniform vec3 LightPosition;
// Final scale adjust
uniform float ScaleAdj;
// Passes shading to Fragment Shader
varying float colpos;
/////////////////////////
//// FUNCTIONS ////
/////////////////////////
//// COSH Function (Hyperbolic Cosine)
float cosh(float val)
{
float tmp = exp(val);
float cosH = (tmp + 1.0 / tmp) / 2.0;
return cosH;
}
// TANH Function (Hyperbolic Tangent)
float tanh(float val)
{
float tmp = exp(val);
float tanH = (tmp - 1.0 / tmp) / (tmp + 1.0 / tmp);
return tanH;
}
// SINH Function (Hyperbolic Sine)
float sinh(float val)
{
float tmp = exp(val);
float sinH = (tmp - 1.0 / tmp) / 2.0;
return sinH;
}
/////////////////////////
//// MAIN LOOP ////
/////////////////////////
void main()
{
// Assemble pre-transform matrix
mat4 TT = mat4(TT_0,TT_1,TT_2,TT_3);
// Placeholder variables
float a = A;
float b = B;
float c = C;
float d = D;
// XYZ vertex coordinates (multiplied by pre-transform matrix)
vec3 vertex = (gl_Vertex * TT).xyz;
////////////////////////////////////
//////// 43 Henneburg ////////
////////////////////////////////////
float u = vertex.x * 2.0;
float v = vertex.y * 2.0;
vertex.x = 2.0 * sinh(u) * cos(v) - 2.0 * sinh(3.0*u) * cos(3.0*v)/3.0;
vertex.y = 2.0 * sinh(u) * sin(v) + 2.0 * sinh(3.0*u) * sin(3.0*v)/3.0;
vertex.z = 2.0 * cosh(2.0*u) * cos(2.0*v);
// Final scale adjustment
mat4 finalScale = mat4(ScaleAdj,0.0,0.0,0.0,
0.0,ScaleAdj,0.0,0.0,
0.0,0.0,ScaleAdj,0.0,
0.0,0.0,0.0,1.0);
vertex = vec3(vec4(vertex,1.0) * finalScale);
// Shading calculations
colpos = length(vertex.xyz + LightPosition);
// Outputs
gl_Position = gl_ModelViewProjectionMatrix * vec4(vertex,1.0);
gl_TexCoord[0] = gl_TextureMatrix[0] * gl_MultiTexCoord0;
}