Advertisement

Normals for a simple quad?

Started by March 29, 2002 01:41 PM
1 comment, last by Sammy70 22 years, 11 months ago
I'm currently learning D3D, and have a question about normals. I have a slowly rotating quad defined with this vertices :
  
#define D3DFVF_UNLIT_TEX_VERTEX D3DFVF_XYZ | D3DFVF_NORMAL 

typedef struct
{
	float x, y, z;
	float nx, ny, nz;
} UNLIT_TEX_VERTEX;


UNLIT_TEX_VERTEX m_QuadVertices[] =
{
    {  1.0f, 1.0f, 0.0f,  1.0f, 1.0f, 0.0f, },
    {  1.0f,-1.0f, 0.0f,  1.0f,-1.0f, 0.0f, },
    { -1.0f,-1.0f, 0.0f, -1.0f,-1.0f, 0.0f, },  
    { -1.0f,-1.0f, 0.0f, -1.0f,-1.0f, 0.0f, },
    { -1.0f, 1.0f, 0.0f, -1.0f, 1.0f, 0.0f, },
    {  1.0f, 1.0f, 0.0f,  1.0f, 1.0f, 0.0f, },
};
  
I have Backface ulling turned off. The normals seems to be ok, as long as the face isn't directly looking at the camera (the light is slightly behind, above and right of the camera). I understand why, but if I set the Z of the normals to anything than 0.0f only one face is lit, and the other stays black. The only solution I can see is to build the quad ~2 sided~ out of 4 triangles instead of 2, and to have 2 triangles have their normals pointing along the positive Z axis, and the 2 others with negative Zs. (I hope you understand what I mean Is that the only way? It's not really crucial for me to have this worked out, as I'm just fooling around with vertices currently, but I'm just wondering ... Thanks, Sammy EDIT: had forgotten to write how the structure definition looked like. Edited by - Sammy70 on March 29, 2002 2:43:10 PM
Hmm. Your face normals aren''t normal. In order for lighting to work properly, the magnitude of all your face normals should be 1.

Do something like n[x,y, or z] / (sqrt(nx*nx+ny*ny+nz*nz))

on each of the components of your normal vector. See if that helps.
Advertisement
Thanks, but that doesn''t solve the problem. Even with a normalized normal (if I didn''t do anything wrong, the (absolute)value needed along the x and y axis is 1/SQR(2) = 0,7071067812), only one side is lighted, the other is just plain black :\

Oh well .. no matter. I''ll now try to put some textures on it. The chances I will ever need a single two sided polygon is relatively slim anyway

Thanks again anyway. At least I polished my knowledge of normals up through this.

This topic is closed to new replies.

Advertisement