Light Normals ---

Started by
16 comments, last by pcbrainbuster 15 years, 11 months ago
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).
Advertisement
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
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.
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?
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 );
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!
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.
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();

Please don't PM me with questions. Post them in the forums for everyone's benefit, and I can embarrass myself publicly.

You don't forget how to play when you grow old; you grow old when you forget how to play.

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.
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].

This topic is closed to new replies.

Advertisement