• Advertisement
Sign in to follow this  

s-tangent

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

i just need a little help workig out the s-tangent in the following case: trying to some some simple bump mapping with GLSL i am drawing a cube and sending the s-tangent through glColor3f to the vert shader
	glBegin(GL_QUADS);
		// Front Face
		glColor3f(?,?,?); //send s-tangent through color
		glNormal3f( 0.0f, 0.0f, 1.0f);		
		glMultiTexCoord2fARB( GL_TEXTURE0_ARB,0.0f, 0.0f); glVertex3f(-1.0f, -1.0f,  1.0f);	
		glMultiTexCoord2fARB( GL_TEXTURE0_ARB,1.0f, 0.0f); glVertex3f( 1.0f, -1.0f,  1.0f);	
		glMultiTexCoord2fARB( GL_TEXTURE0_ARB,1.0f, 1.0f); glVertex3f( 1.0f,  1.0f,  1.0f);	
		glMultiTexCoord2fARB( GL_TEXTURE0_ARB,0.0f, 1.0f); glVertex3f(-1.0f,  1.0f,  1.0f);	
		// Back Face
		glColor3f(?,?,?); 
		glNormal3f( 0.0f, 0.0f,-1.0f);
		glMultiTexCoord2fARB( GL_TEXTURE0_ARB,1.0f, 0.0f); glVertex3f(-1.0f, -1.0f, -1.0f);	
		glMultiTexCoord2fARB( GL_TEXTURE0_ARB,1.0f, 1.0f); glVertex3f(-1.0f,  1.0f, -1.0f);	
		glMultiTexCoord2fARB( GL_TEXTURE0_ARB,0.0f, 1.0f); glVertex3f( 1.0f,  1.0f, -1.0f);	
		glMultiTexCoord2fARB( GL_TEXTURE0_ARB,0.0f, 0.0f); glVertex3f( 1.0f, -1.0f, -1.0f);	
		// Top Face
		glColor3f(?,?,?);
		glNormal3f( 0.0f, 1.0f, 0.0f);
		glMultiTexCoord2fARB( GL_TEXTURE0_ARB,0.0f, 1.0f); glVertex3f(-1.0f,  1.0f, -1.0f);	
		glMultiTexCoord2fARB( GL_TEXTURE0_ARB,0.0f, 0.0f); glVertex3f(-1.0f,  1.0f,  1.0f);	
		glMultiTexCoord2fARB( GL_TEXTURE0_ARB,1.0f, 0.0f); glVertex3f( 1.0f,  1.0f,  1.0f);	
		glMultiTexCoord2fARB( GL_TEXTURE0_ARB,1.0f, 1.0f); glVertex3f( 1.0f,  1.0f, -1.0f);	
		// Bottom Face
		glColor3f(?,?,?);
		glNormal3f( 0.0f,-1.0f, 0.0f);
		glMultiTexCoord2fARB( GL_TEXTURE0_ARB,1.0f, 1.0f); glVertex3f(-1.0f, -1.0f, -1.0f);	
		glMultiTexCoord2fARB( GL_TEXTURE0_ARB,0.0f, 1.0f); glVertex3f( 1.0f, -1.0f, -1.0f);	
		glMultiTexCoord2fARB( GL_TEXTURE0_ARB,0.0f, 0.0f); glVertex3f( 1.0f, -1.0f,  1.0f);	
		glMultiTexCoord2fARB( GL_TEXTURE0_ARB,1.0f, 0.0f); glVertex3f(-1.0f, -1.0f,  1.0f);	
		// Right face
		glColor3f(?,?,?);
		glNormal3f( 1.0f, 0.0f, 0.0f);
		glMultiTexCoord2fARB( GL_TEXTURE0_ARB,1.0f, 0.0f); glVertex3f( 1.0f, -1.0f, -1.0f);	
		glMultiTexCoord2fARB( GL_TEXTURE0_ARB,1.0f, 1.0f); glVertex3f( 1.0f,  1.0f, -1.0f);	
		glMultiTexCoord2fARB( GL_TEXTURE0_ARB,0.0f, 1.0f); glVertex3f( 1.0f,  1.0f,  1.0f);	
		glMultiTexCoord2fARB( GL_TEXTURE0_ARB,0.0f, 0.0f); glVertex3f( 1.0f, -1.0f,  1.0f);
		// Left Face
		glColor3f(?,?,?);
		glNormal3f(-1.0f, 0.0f, 0.0f);
		glMultiTexCoord2fARB( GL_TEXTURE0_ARB,0.0f, 0.0f); glVertex3f(-1.0f, -1.0f, -1.0f);	
		glMultiTexCoord2fARB( GL_TEXTURE0_ARB,1.0f, 0.0f); glVertex3f(-1.0f, -1.0f,  1.0f);	
		glMultiTexCoord2fARB( GL_TEXTURE0_ARB,1.0f, 1.0f); glVertex3f(-1.0f,  1.0f,  1.0f);	
		glMultiTexCoord2fARB( GL_TEXTURE0_ARB,0.0f, 1.0f); glVertex3f(-1.0f,  1.0f, -1.0f);	
	glEnd();

in the vert shader:
vec3 s-tangent = gl_Color.xyz;
vec3 normal = gl_Normal.xyz;
vec3 t-tangent = cross(s-tangent, normal); //binormal

so in the above example how do i calculate the s-tangent for each face of the cube? also is that the correct way to work out the t-tangent in the vert shader too?

Share this post


Link to post
Share on other sites
Advertisement
Before you do anything else, I felt I must warn you that s-tangent and t-tangent aren't valid variable names for the shader! [smile]

Try s_tangent.

Share this post


Link to post
Share on other sites
yeah i have just renamed them here for clarifaction

Share this post


Link to post
Share on other sites
The s-tangent is the direction, in which the s-coordinates of the texture increase.
So in your case it's no problem to calculate the tangents, but you could guess them even more easy:
(Remember s-Axis in textures is the usual y-Axis)
For your first quad the tangent is (1.0f,0.0f,0.0f), see why?
the s-value increases when you go to your second vertex of the quad, and there you only increase the x-value.
And as you already did, the t-tangent is the same for the whole face,

If you understood that, you can also guess the others...

If you want to calculate more difficult s-tangents, you'll have to construct a vector pointing into the direction of the increasing s-coordinate.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement