# Light Normals ---

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

## Recommended Posts

Sup guys, I'm having some trouble with light normals and just don't 'get' how to set them in my custom vertex struct... I know their purpose and even the way you have to set them(perpendicular to the surface) but like I said I don't know how! Can anyone explain in detail how it's done and give some examples? Thanks(a load).

##### Share on other sites
right now i only remember managed directx, its been a couple years since i did unmanaged dx. but in managed you create a group of vertices for example:

CustomeVertex.PositionNormalTexture[] m_vertes = new Customvertex.PositionNormalTexture[size];

inside the vertex stucture there is a vector3 for position and a vector 3 for the normal and also uv coords....

im not completely sure about unmanaged...if i can rmemeber you have to define your vertex structure and inside there you can define a normal vector.

im not sure if that helps....specify which version of directX and maybe you can get more answers

##### Share on other sites
Thanks for trying to help me dude, but unmanaged and managed seem to be a bit too different for me to understand or work by... Also Im using DX9.

##### Share on other sites
Is it that you don't get how to actually set the normal values in your vertex buffer, or that you don't get how to compute the normal values for a given mesh?

##### Share on other sites
from what i can remmeber its something like this....search online...i found this on msdn site...just added normals to the vertex structure.

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

CUSTOMVERTEX Vertices[] =
{
{ 0.0, 0.0, 0.0, 0.0, 1.0, 0.0},
{-5.0, 5.0, 0.0, 0.0, 1.0, 0.0},
{-3.0, 7.0, 0.0, 0.0, 1.0, 0.0},
{ 0.0, 10.0, 0.0, 0.0, 1.0, 0.0},
{ 3.0, 7.0, 0.0, 0.0, 1.0, 0.0},
{ 5.0, 5.0, 0.0, 0.0, 1.0, 0.0},
};

d3dDevice->DrawPrimitive( D3DPT_TRIANGLEFAN, 0, 4 );

##### Share on other sites
Thanks again for all your help guys, the problem is that I don't know how to set them.

StoneDevil: That can't be a right example :) thanks though!

##### Share on other sites
why dont you just post the section of your code where you are trying to "set" the normals...and also where you are rendering your mesh.

##### Share on other sites
If you just want a normal that's perpendicular to a face (3 vertices, a triangle):

D3DXVECTOR3 v0, v1, v2; // three vertices forming a face
D3DXVECTOR3 normal;

D3DXVECTOR3 vn0 = v1-v0;
D3DXVECTOR3 vn1 = v2-v0;

D3DXVec3Cross( &normal, &vn1, &vn0 );

If the normal is pointing in rather than out, then:

D3DXVec3Cross( &normal, &vn0, &vn1 );

If you form a mesh and want all the normals to be smoothed, look at:

D3DXComputeNormals();

##### Share on other sites
Thanks again! The thing is guys that I'm NOT owrking with a mesh here I'm still doing the basics because I keep getting confused with this normal thing.

Well the following is my custom vertex, flexible vertex format and the primitive respectively --->

[icode]
//The FVF --->
#define CustomFVF (D3DFVF_XYZ | D3DFVF_TEX1 | D3DFVF_NORMAL)

//Custom Vertex --->
struct CustomV
{

FLOAT x, y, z;
FLOAT u, v;
D3DVECTOR vnormal;

};

//Primitive --->
CustomV Primitive[] =
{

{-3.0f, 3.0f, 1.0f, 0, 0, 0.0f, 1.0f, 0.0f, },
{3.0f, 3.0f, 1.0f, 1, 0, 0.0f, 1.0f, 0.0f, },
{-3.0f, -3.0f, 1.0f, 0, 1, 0.0f, 1.0f, 0.0f, },
{3.0f, -3.0f, 1.0f, 1, 1, 0.0f, 1.0f, 0.0f, },

};
[/icode]

This though was just a guess(the normals).

Thanks.

##### Share on other sites
Since you are drawing a standard quad, you are going to want the normal to be (0, 0, 1) meaning the normal would come towards you.

{-3.0f,  3.0f, 1.0f, 	0, 0, 	0.0f, 0.0f, 1.0f, },{ 3.0f,  3.0f, 1.0f, 	1, 0, 	0.0f, 0.0f, 1.0f, },{-3.0f, -3.0f, 1.0f, 	0, 1, 	0.0f, 0.0f, 1.0f, },{ 3.0f, -3.0f, 1.0f, 	1, 1, 	0.0f, 0.0f, 1.0f, },

Also, the takes to do code is [ \ code].

1. 1
2. 2
Rutin
19
3. 3
JoeJ
16
4. 4
5. 5

• 36
• 23
• 13
• 13
• 17
• ### Forum Statistics

• Total Topics
631703
• Total Posts
3001814
×