halcyon81 122 Report post Posted November 27, 2006 I just built bumpmapping into my engine, I am using a GLSL implementation. My vertex shader needs the normal, and a vertex tangent at every vertex point to compute the tangent space matrix for calculations. I am curious if there is an easy way or method to get this vertex tangent into the shader when using something like glusphere that is generating all the geometry for me? Or am I going to need to roll my own sphere/sphere texture generation code? How does everyone else deal with this? Thanks! 0 Share this post Link to post Share on other sites
KreK 204 Report post Posted November 27, 2006 GLU primitives don't come with tangent vectors (they do have normals, though). You have to calculate them yourself but in the case of spheres you don't need a general triangle tangent vector calculator.If you decide to let all tangents lie parallel to the XZ plane, you can easily calculate tangents as derivates of vertex circular (projected to XZ plane) position.From calculus, we know the derivative of the sine is the cosine, and the derivative of the cosine is minus the sine, therefore:if: vtx_pos_x = cos( angle ) vtx_pos_y = irrelevant vtx_pos_z = -sin( angle )then: vtx_tangent_x = -sin( angle ) vtx_tangent_y = 0 vtx_tangent_z = -cos( angle )The bitangent is calculated as the cross-product of vertex tangent and normal vector.<edit spelling> 0 Share this post Link to post Share on other sites
halcyon81 122 Report post Posted November 27, 2006 Right I follow that, is there any easy way to hook into the GLU code to add these vertex attributes, IE do they have any kind of callback or anything? If not I'm not sure how I can even specify a vertex attribute short of taking SGI's source and adding my own stuff to it? 0 Share this post Link to post Share on other sites
Digitalfragment 1504 Report post Posted November 27, 2006 Nope, but because you are using GLSL, you can do the tangent/binormal calculation in the vertex shader, but only in this case of it being a sphere. 0 Share this post Link to post Share on other sites
halcyon81 122 Report post Posted December 5, 2006 I wanted to thank Krek for his help, I've got it semi working, I wanted to post my code for determining the vertex tangent and see if I'm way off base or what:float angle = acos(gl_Vertex.x);if (gl_Vertex.z > 0.0) { angle = (2.0 * PI) - angle;}// derivative in the x z plane creates our texture tangentvertexTangentTemp = normalize(vec3(-sin(angle), 0, -cos(angle)));The ball looks mostly good but there seem to be some kind of boundry problems going on. For example there are visible 'lines' running around the sphere that the specular highlights seem to get trapped in. Also when I roll the ball towards the light down the z axis the specular seems to slightly wobble side to side when it should stay dead center. Here is an example image of the specular getting trapped in the line (on the left), versus it looking (as best i can tell) proper, on the right. http://www.malevolenceguild.org/spheres.jpgWould the lines be caused by the texturing somehow? I seem to remember seeing on another of my spheres a visible line where the left and right edges of the texture were meeting up, rather than there being a nice smooth transition from one side of the texture to the other.Thanks for all help in advance! 0 Share this post Link to post Share on other sites