Strange artifact with lighting (picture included)

Started by
4 comments, last by atreyu 21 years, 10 months ago
I'm generating all the normals for each sphere using the following:
    
for(int index = 0; index < pModel->numOfObjects; index++)
{
   OBJECT3DS *pObject = &(pModel->pObject[index]);

   D3DXVECTOR3 *pNormals = new D3DXVECTOR3 [pObject->numOfFaces];
   D3DXVECTOR3 *pTempNormals = new D3DXVECTOR3 [pObject->numOfFaces];
   pObject->pNormals = new D3DXVECTOR3 [pObject->numOfVerts];

   for(int i=0; i < pObject->numOfFaces; i++)
   {									
      vPoly[0] = pObject->pVerts[pObject->pFaces[i].vertIndex[0]];
      vPoly[1] = pObject->pVerts[pObject->pFaces[i].vertIndex[1]];
      vPoly[2] = pObject->pVerts[pObject->pFaces[i].vertIndex[2]];

      vVector1 = vPoly[0] - vPoly[2];			
      vVector2 = vPoly[2] - vPoly[1];			

      D3DXVec3Cross(&vNormal, &vVector1, &vVector2);			
      pTempNormals[i] = vNormal;	
	
      D3DXVec3Normalize(&vNormal, &vNormal);

      pNormals[i] = vNormal;						
   }

   D3DXVECTOR3 vSum(0, 0, 0);
   D3DXVECTOR3 vZero = vSum;
   int shared=0;

   for (i = 0; i < pObject->numOfVerts; i++)			
   {
      for (int j = 0; j < pObject->numOfFaces; j++)	
      {												
         if (pObject->pFaces[j].vertIndex[0] == i || 
             pObject->pFaces[j].vertIndex[1] == i || 	 
             pObject->pFaces[j].vertIndex[2] == i)
		{
               vSum += pTempNormals[j];			
               shared++;						
            }
      }      
		
      pObject->pNormals[i] = vSum / (float)(-shared);

      D3DXVec3Normalize(&(pObject->pNormals[i]), &(pObject->pNormals[i]));

      vSum = vZero;								
      shared = 0;									
   }
	
   delete [] pTempNormals;
   delete [] pNormals;
}

  
This is the most common way I know for generating vertex normals anyway. Add up all the face normals that share a vertice and divide by the number. Every sphere in the entire game has the line on it when lighting is enabled. If I turn lighting off it's no longer there. I'm currently just using a single point light at the center of the sun which is approx. 10,000 directx units away from each planet. The spheres were all created in 3ds max and the textures do match up correctly so I don't think they're causing it. Also, as each planet rotates the line fades and then completely dissapears. It's only visible through approximately 90 degrees of the rotation. Thanks for any help. -Ben | particlefield.com | [edited by - atreyu on June 4, 2002 6:55:18 AM]
Advertisement
Not the solution to your problem, but something to look into...

3D Studio Max generates the normals for its meshes and you can extract them right from the .3ds file. In the case of your normal calculations, your method should work provided the vertex information saved in the .3ds file is uniform, meaning all triangle vertices are saved out in a clockwise/counter-clockwise order. Otherwise, some of your normals will be pointing up while others are pointing down (relatively speaking) due to the cross-product calc.
Chris Z. GPU FX
Are you using specular lighting for the planets? If so, turn off specular and see if the line goes away. It could be caused by the cut off point for the specular if you have a substantial specular contribution and most importantly a low shininess value set - try increasing that.

Cameron
ZeroEffect:
That might fix it if I load the normals from the 3ds file, but I''d rather leave the line there than mess with that god-awful file format again :/ I''ll have to take a look at some of my settings in max. Maybe I messed something up.

Kamrann:
Specular is off so that unfortunately isn''t it. Thanks though.

This isn''t that big a deal. If I have to leave the line there I don''t think anyone will really care :/

Cheers,
-Ben

| particlefield.com |
It could be that the planet is outside the range of the light-source...

Have you tried setting light range to infinite ?

Allan
------------------------------ BOOMZAPTry our latest game, Jewels of Cleopatra
try computing normals based on the location on the sphere, since the normals will just be the sin()/cos() combos used to create the sphere, without the radius multiplied in.

have you tried moving the light source around the sphere (not a fix, just a text) instead of rotation the sphere? does the same thing happen?

it may be the alpha blended shell creating the wonky effect. try turning that off and seeing if it fixes things. quite possible the shell has bad normals and is being lit wrong.

This topic is closed to new replies.

Advertisement