Light Normals ---

Started by
16 comments, last by pcbrainbuster 15 years, 11 months ago
If you have the vertices you want, use the D3DXVec3Cross function described above to determine the normals.

Also, be careful with your vertex format. With your FVF, your vertex structure should be { x,y,z,normal,u,v }. Put the texcoords after the normal vector. The FVF definition does not determine the order of the variables. It only tells the device to expect position, normal and texcoord info.

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.

Advertisement
Hmm, thanks again guys! I think I now understand normals also the blue square problem is gone because of what buckeye said and my texture shows.

But the problem hasn't died sadly, the light still doesn't work... The following is my light function --->

VOID InitLights(){ D3DVECTOR LightDir = {0.0f, 0.0f, 0.0f}; ZeroMemory(&Light, sizeof(Light)); ZeroMemory(&LightM, sizeof(LightM)); Light.Type = D3DLIGHT_DIRECTIONAL; Light.Diffuse.r = 0.5f; Light.Diffuse.g = 0.5f; Light.Diffuse.b = 0.5f; Light.Diffuse.a = 1.0f; Light.Direction = LightDir; LightM.Diffuse.r = LightM.Ambient.r = 1.0f; LightM.Diffuse.g = LightM.Ambient.g = 1.0f; LightM.Diffuse.b = LightM.Ambient.b = 1.0f; LightM.Diffuse.a = LightM.Ambient.a = 1.0f; D3DDev->SetLight(0, &Light); D3DDev->LightEnable(0, true); D3DDev->SetMaterial(&LightM);}


Any issues that you guys can see with it?

Thanks.
Quote:Original post by pcbrainbuster

 D3DVECTOR LightDir = {0.0f, 0.0f, 0.0f};




That's not a valid direction vector. The pipeline may convert it into something usable (I'm not sure, I never use the fixed-function lighting stuff), but it's probably better if you set it to something usable from the start. In particular, if you want your triangles to be lit you should set the light direction to be approximately opposite of your vertex normals (such as <0, 0, -1>).
Your direction needs attention - I don't believe the FF pipe will subst in a meaningful value for you.

Also, I suspect your setting the material's ambient to <1,1,1,1> will effectively disable your lighting. Leave it as just setting the diffuse to <1,1,1,1>.

hth
Jack

<hr align="left" width="25%" />
Jack Hoxley <small>[</small><small> Forum FAQ | Revised FAQ | MVP Profile | Developer Journal ]</small>

MJP: Yay it worked :) the problem was that well what you said :)

JollyJefers: Attenuation would be the problem if I wasn't using a directionallight ;) Directional lights go on forever...

Every other Humanoid: When you're setting the light well your setting the light right? But when you're setting the material you're setting how the light will reflect. But what I don't understand is why the ambient member is in both the light and material struct. I mean shouldn't it only be in the material one?

Thanks.
Quote:Original post by pcbrainbuster

JollyJefers: Attenuation would be the problem if I wasn't using a directionallight ;) Directional lights go on forever...



He didn't say "attenuation", he was saying "attention". Basically he was pointing out the same thing that I was. [wink]
Thanks MJP... For making me feel stupid lol. But seriously sorry JolyJefers for doin' that.

(questions still apply)

Thanks.
I've just constructed a cube and am not sure if I completed the normals properly can you guys check please?

CustomV Primitive[] ={ //Front Side {-3.0f, 3.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0, 0, }, {3.0f, 3.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1, 0, }, {-3.0f, -3.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0, 1, }, {3.0f, -3.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1, 1, }, //Right Side {3.0f, 3.0f, 1.0f, 1.0f, 0.0f, 0.0f, 0, 0, }, {3.0f, 3.0f, 6.0f, 1.0f, 0.0f, 0.0f, 1, 0, }, {3.0f, -3.0f, 1.0f, 1.0f, 0.0f, 0.0f, 0, 1, }, {3.0f, -3.0f, 6.0f, 1.0f, 0.0f, 0.0f, 1, 1, }, //Left Side {-3.0f, 3.0f, 6.0f, -1.0f, 0.0f, 0.0f, 0, 0, }, {-3.0f, 3.0f, 1.0f, -1.0f, 0.0f, 0.0f, 1, 0, }, {-3.0f, -3.0f, 6.0f, -1.0f, 0.0f, 0.0f, 0, 1, }, {-3.0f, -3.0f, 1.0f, -1.0f, 0.0f, 0.0f, 1, 1, }, //Back Side {3.0f, 3.0f, 6.0f, 0.0f, 0.0f, -1.0f, 0, 0, }, {-3.0f, 3.0f, 6.0f, 0.0f, 0.0f, -1.0f, 1, 0, }, {3.0f, -3.0f, 6.0f, 0.0f, 0.0f, -1.0f, 0, 1, }, {-3.0f, -3.0f, 6.0f, 0.0f, 0.0f, -1.0f, 1, 1, }, //Top Side {3.0f, 3.0f, 1.0f, 0.0f, 1.0f, 0.0f, 0, 0, }, {-3.0f, 3.0f, 1.0f, 0.0f, 1.0f, 0.0f, 1, 0, }, {3.0f, 3.0f, 6.0f, 0.0f, 1.0f, 0.0f, 0, 1, }, {-3.0f, 3.0f, 6.0f, 0.0f, 1.0f, 0.0f, 1, 1, }, //Bottom Side {-3.0f, -3.0f, 1.0f, 0.0f, -1.0f, 0.0f, 0, 0, }, {3.0f, -3.0f, 1.0f, 0.0f, -1.0f, 0.0f, 1, 0, }, {-3.0f, -3.0f, 6.0f, 0.0f, -1.0f, 0.0f, 0, 1, }, {3.0f, -3.0f, 6.0f, 0.0f, -1.0f, 0.0f, 1, 1, },}


(questions still apply)

Thanks.

This topic is closed to new replies.

Advertisement