I am writing a planet renderer and have stumbled into a problem that I cannot solve. I am generating heightmaps in a glsl pixel shader. These heightmaps are generated for every quad in the quadtree that the planetary sphere is built on. The sphere is a cube transformed by the equations found here. The way I am generating a point to be inputted into the noise function in the shader is shown here:
vec2 coords = vec2((gl_FragCoord.x - 0.5) * m_Scale , (gl_FragCoord.y - 0.5) * m_Scale)+m_Offset; vec2 position = vec2(coords.x,coords.y); vec3 noiseInput; if(m_t == 1){ noiseInput = vec3(spherize(vec3(position.x, 0.0, position.y) + m_faceOffset))/m_worldSize; }else if(m_t == 2){ noiseInput = vec3(spherize(vec3(position.x, position.y, 0.0) + m_faceOffset))/m_worldSize; }else if(m_t == 3){ noiseInput = vec3(spherize(vec3(0.0, position.x, position.y) + m_faceOffset))/m_worldSize; } Here "m_Scale" is the length of the quad's edges divided by the lengths of one of the root node's sides. m_Offset is a variable which offsets the quad from the origin. m_worldSize represents the planet's radius. m_faceOffset is the variable which translates the quad to it's correct face of the cube (faceIndex = faceOffset):
if(c.face.equals(faces.TOP)){ c.faceIndex = new Vector3f(nhsize, hsize, nhsize); }else if(c.face.equals(faces.BOTTOM)){ c.faceIndex = new Vector3f(nhsize, nhsize, nhsize); }else if(c.face.equals(faces.FRONT)){ c.faceIndex = new Vector3f(nhsize, nhsize, hsize); }else if(c.face.equals(faces.BACK)){ c.faceIndex = new Vector3f(nhsize, nhsize, nhsize); }else if(c.face.equals(faces.RIGHT)){ c.faceIndex = new Vector3f(hsize, nhsize, nhsize); }else{ c.faceIndex = new Vector3f(nhsize, nhsize, nhsize); } where hsize is the radius of the planet and nhsize is the radius negated. Finally, m_t describes which face of the cube the quad is supposed to be on:
if(q.face.equals(QuadMesh.faces.TOP.toString()) || q.face.equals(QuadMesh.faces.BOTTOM.toString())){ t = 1; } if(q.face.equals(QuadMesh.faces.FRONT.toString()) || q.face.equals(QuadMesh.faces.BACK.toString())){ t = 2; } if(q.face.equals(QuadMesh.faces.RIGHT.toString()) || q.face.equals(QuadMesh.faces.LEFT.toString())){ t = 3; } "spherize" is the function which transforms a point on the cube to a point on the sphere:
denom1 = hWorldSize * hWorldSize * 2f; denom2 = hWorldSize * hWorldSize * hWorldSize *hWorldSize * 3f; vec3 spherize(vec3 v){ float x = (v.x * (sqrt(1.0-((v.y*v.y)/m_denom1)-((v.z*v.z)/m_denom1)+(((v.y*v.y)*(v.z*v.z))/m_denom2)))); float y = (v.y * (sqrt(1.0-((v.x*v.x)/m_denom1)-((v.z*v.z)/m_denom1)+(((v.x*v.x)*(v.z*v.z))/m_denom2)))); float z = (v.z * (sqrt(1.0-((v.y*v.y)/m_denom1)-((v.x*v.x)/m_denom1)+(((v.y*v.y)*(v.x*v.x))/m_denom2)))); return vec3(x,y,z); } This all leads to the following problem:

As one can see the faces of the "cube" do not match up. I am at a loss here; I use the exact same methods described above to transform the vertices of the cube to those of a sphere.
Any and all help is highly appreciated. If one needs more code to form an accurate opinion please let me know.