Archived

This topic is now archived and is closed to further replies.

Normals problem

This topic is 5128 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, i''m having some problems with my normals for lighting. The quad directly under the lightsource is always black, and theres a drk band going diagonally from the top left to the bottom right. Heres a screenie: Buggered I left bump mapping on, because it makes it easier to see the problem (its just a darker shade without). The problem goes away if i set all my normals to (0,0,-1), but that knackers the bumpmap effect. Heres the code i''m using (edited slightly):
#define XNORMAL_LEN	0.30822070014844882251250961907271f
#define YNORMAL_LEN	0.30822070014844882251250961907271f
#define ZNORMAL_LEN	0.81f

pVerts->nx = -XNORMAL_LEN;
pVerts->ny = -YNORMAL_LEN;
pVerts->nz = -ZNORMAL_LEN;
pVerts++;
pVerts->nx = XNORMAL_LEN;
pVerts->ny = -YNORMAL_LEN;
pVerts->nz = -ZNORMAL_LEN;
pVerts++;
pVerts->nx = -XNORMAL_LEN;
pVerts->ny = YNORMAL_LEN;
pVerts->nz = -ZNORMAL_LEN;
pVerts++;
pVerts->nx = XNORMAL_LEN;
pVerts->ny = -YNORMAL_LEN;
pVerts->nz = -ZNORMAL_LEN;
pVerts++;
pVerts->nx = XNORMAL_LEN;
pVerts->ny = YNORMAL_LEN;
pVerts->nz = -ZNORMAL_LEN;
pVerts++;
pVerts->nx = -XNORMAL_LEN;
pVerts->ny = YNORMAL_LEN;
pVerts->nz = -ZNORMAL_LEN;
pVerts++;
Obviously theres more vertex setup betweeen the normals Anyone got any ideas? Ooh, also - has anyone else had any problems installing the debug runtimes for DX9.0b? I downloaded the SDK about half an hour ago because i had the DX9.0a version, and the runtimes wouldn''t install. But when i try to switch to the debug version, the progress bar zooms to the end and then it says that its installed after less than a second - although theres no debug output in MSVC, and theres no DirectX icon in the control pannel... Cheers, Steve

Share this post


Link to post
Share on other sites
Your normals aren''t normalized. What does it look like if you set D3DRS_NORMALIZENORMALS to TRUE?

It would help to diagnose the problem if you noted which corner of the quad each of the 6 normals you''re setting with the code you''ve posted is associated with (i.e. upper left, lower right, etc.).


Share this post


Link to post
Share on other sites
Oops, the z coord should be sqrt(0.81). Anyway, i've tried all sorts of other combinations, and none work apart from (0,0,-1). Setting the D3DRS_NORMALIZENORMALS render state doesn't affect it at all.

Yeah, sorry - i forgot to include the vertex order. Here we go:

0--1
| /|
|/ |
2--3


pVerts[0].nx = -XNORMAL_LEN;
pVerts[0].ny = -YNORMAL_LEN;
pVerts[0].nz = -ZNORMAL_LEN;
pVerts[1].nx = XNORMAL_LEN;
pVerts[1].ny = -YNORMAL_LEN;
pVerts[1].nz = -ZNORMAL_LEN;
pVerts[2].nx = -XNORMAL_LEN;
pVerts[2].ny = YNORMAL_LEN;
pVerts[2].nz = -ZNORMAL_LEN;
pVerts[3].nx = XNORMAL_LEN;
pVerts[3].ny = -YNORMAL_LEN;
pVerts[3].nz = -ZNORMAL_LEN;

The vertices are duplicated for the triangles like so:

+--+ Triangle 1: 0--1 Triangle 2: 1
|1/| | / /|
|/2| |/ / |
+--+ 2 3--2

In triangle 1, the vertex order is (0,1,2), and in triangle 2 its (1,2,3).

Hmm... This might not be a normals problem - If i draw every second triangle, the problem disappears (i think - its hard to see)

Edit: nope - the effects still thre only drawing the top left triangle of each quad

Cheers,
Steve

[edited by - Evil Steve on December 1, 2003 9:43:39 AM]

[edited by - Evil Steve on December 1, 2003 4:54:46 PM]

Share this post


Link to post
Share on other sites
Thanks for the additional info. Your normals seem to be pointing in an odd direction for a quad. For instance, the upper left vertex has the normal pointing to the left and down. Did you get the Y direction reversed by accident in each of these normals? I don''t know what sort of effect you''re trying to achieve, but I would think you''d want the normal of the upper left vertex to point to the left and up.

Also, the winding order is reversed for the two triangles of the quad. Depending on how you''ve set the back-face culling mode, this could be a problem.

Share this post


Link to post
Share on other sites
I''ve turned off backface culling, and the bit i posted there is wrong - the second traingle is backwards as you said. I''ve corrected it now.

If i flip the Y normals, the black shadow you can see to the top left moves to the bottom left. Which is odd...

Share this post


Link to post
Share on other sites
The darkened blocks directly beneath the light are black because you''ve got the point light source so close to the face of the quad that the angle between the vector from the vertex to the light position and the vertex normal is greater than 90 degrees. This will result in no contribution from this light at the vertices. The surrounding quads will have at least one vertex normal that will point roughly in the light direction so they will be lit.

The black band that you see from the top left, to the lower right is a side effect of per-vertex lighting. The direction of this band is due to the diagonal across your quads made up of two triangles. In the triangles in the upper left of your mesh, three of the vertices (top left, top right, and bottom left) all have vertex normals that are pointing away from the light direction. Since these three vertices are all from the *same* triangle making up your quad, the entire triangle is shaded with black.

You''ll see something similar on the lower right side of the mesh. The upper left vertex of the quads point toward the light and the other three vertices (that make up a the same triangle) are facing away and will get little to no light at each vertex. Hence another black triangle.

In the other corners of the mesh, the vertex of the quad that is pointing in the direction of the light is shared by both triangles making up the quad. This results in the lit vertex being shaded evenly across the face of the two triangles towards the dark color of the other three vertices.



Share this post


Link to post
Share on other sites
Thanks
If anyone wants to see it in motion, you can Download it (233Kb).It'll require a card capable of bump mapping to do bump mapping (strangely enough). I get 533FPS on my GeForce 4 Ti 4400, AMD 1700XP+.

Edit: Oops, broke the tables >_<

Cheers,
Steve

[edited by - Evil Steve on December 2, 2003 1:25:13 PM]

Share this post


Link to post
Share on other sites