Jump to content
  • Advertisement
Sign in to follow this  
Gaenor

Incorrect bump mapping problem (solved)

This topic is 4883 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

Hi, (hey, first post :D) I'm trying to add bump mapping to my engine, and it basically works, but it looks like light position is displaced from its place. This gets worse when I add the attenuation, as you can see that the brightest spot is not in the middle. Here's a screenshot without attenuation: Clicky The white sphere is the light and, as you can see, the light is displaced. I once saw a thread regarding this same topic, but after some hours searching i couldn't find it. The code I'm using to calculate the light vector is this:
	Light& light = lighting->GetLight(i);
	Vector3D pos = *light.GetPosition();
	float radius = light.Get_Radius();

		for(unsigned int j = 0; j<numTriangles; j++)
			if(auxMask->Get(j))
			{
				EXENGINE_TRIANGLE& tri = triangles[j];
				for(int k = 0; k<3; k++)
				{
					Vector3D lightVector = Vector3D(tri.v[k]->x, tri.v[k]->y, tri.v[k]->z) - pos;
					lightVector.Normalize();

					// S = sTangent.DotProduct(lightVector);
					tri.v[k]->s = lightVector.Dot_P(Vector3D(tri.v[k]->sTangent[0], tri.v[k]->sTangent[1], tri.v[k]->sTangent[2]));

					// T = tTangent.DotProduct(lightVector);
					tri.v[k]->t = lightVector.Dot_P(Vector3D(tri.v[k]->tTangent[0], tri.v[k]->tTangent[1], tri.v[k]->tTangent[2]));

					// R = normal.DotProduct(lightVector);
					tri.v[k]->r = lightVector.Dot_P(Vector3D(tri.v[k]->normal[0], tri.v[k]->normal[1], tri.v[k]->normal[2]));
				}
			}



And this is the code that generates the tangents:
		Vector3D normal = GetNormal(*tri->v[0], *tri->v[1], *tri->v[2]);

		Vector3D side0(tri->v[0]->x - tri->v[1]->x, tri->v[0]->y - tri->v[1]->y, tri->v[0]->z - tri->v[1]->z);
		Vector3D side1(tri->v[2]->x - tri->v[1]->x, tri->v[2]->y - tri->v[1]->y, tri->v[2]->z - tri->v[1]->z);

		// Calculate S tangent
		float deltaS0 = tri->v[0]->tv - tri->v[1]->tv;
		float deltaS1 = tri->v[2]->tv - tri->v[1]->tv;
		Vector3D sTan = side0*deltaS1 - side1*deltaS0;
		sTan.Normalize();

		// Calculate T tangent
		float deltaT0 = tri->v[0]->tu - tri->v[1]->tu;
		float deltaT1 = tri->v[2]->tu - tri->v[1]->tu;
		Vector3D tTan = side0*deltaT1 - side1*deltaT0;
		tTan.Normalize();

		// Make sure their cross product faces the same direction as the normal
		Vector3D tangentCross = sTan.Cross_P(tTan);
		if(tangentCross.Dot_P(normal) < 0.0f)
		{
			sTan = -sTan;
			tTan = -tTan;
		}

// ... add them to the vertex's tangents and normal
// ... later all the vectors are normalized


I'm sorry to ask for help in such a way, but I've ran out of ideas. [Edited by - Gaenor on August 1, 2005 12:10:22 PM]

Share this post


Link to post
Share on other sites
Advertisement
Any ideas anyone?

I've also made a small program where you can see its behaviour in motion.
You can download it here: Bumps.zip.jpg
Remember to remove the .jpg

Press the buttons 1-7 to change the movement. What am I doing wrong? :(

Share this post


Link to post
Share on other sites
Removing

 lightVector.Normalize();
happened to fix it.

Thanks to anyone who thought about it.

Share this post


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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!