Archived

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

Lighting problem in Dx8

This topic is 5675 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

I''m having some problems with lighting my polygons using DirectX Graphics. The scenario is this: I have a scene with one spinning polygon, consisting of just 4 vertices. Each of these vertices has a position, a normal and a diffuse color value. My scene is using a single material with its diffuse colors set to 1. No lights have been created, except the ambient light which is set to white. Now here is my problem: The scene works just fine, if I have the lighting renderstate (D3DRS_LIGHTING) disabled. The gauraud shaded polygon is shown and shaded properly. However if I enable the lighting renderstate, the polygon turns one solid color, which is the same color as the ambient lighting (White). Any suggestions to what Im doing wrong ? - Mort

Share this post


Link to post
Share on other sites
? - but that''s what ambient is meant to do - !

Ambient is just a colour added on at the end of the local lighting equation to mimic a certain amount of global illumination/atmospheric effects.

If there are no lights enabled, then the ambient colour (after modulation with the ambient component of the material) will be set as the vertex colour for all vertices.

Ambient lighting doesn''t have a position or direction, just a colour and intensity so a vertex can only get the same amount of ambient as any any other vertex with the same material.

--
Simon O''Connor
Creative Asylum Ltd
www.creative-asylum.com

Share this post


Link to post
Share on other sites
I know that ambient light affects all vertices equally, thats not the problem Im having. My problem is that once lighting is enabled the color of each vertex is completely ignored, resulting in a flat single colored polygon instead of a gauraud shaded polygon (Each of the vertices in the polygon has a diffrent color).

Share this post


Link to post
Share on other sites
Ah, so you want D3D lighting *AND* per-vertex colour at the same time...

Use the D3DRS_EMISSIVEMATERIALSOURCE state to change the source of the D3D emissive colour from the material to the vertex colour. I posted a more complete description last week (a search for EMISSIVEMATERIALSOURCE should find it).

...Beware though some hardware won''t let you do this.


--
Simon O''Connor
Creative Asylum Ltd
www.creative-asylum.com

Share this post


Link to post
Share on other sites
I think I found out why my lighting doesn't work. I have been declaring and using vertex shaders for my vertex buffer, since I figured this was the new way of doing things in Dx8.

I seem to remember having read somewhere that any lighting performed on vertices will not be applied to vertices rendered using vertex shaders, unless you create your own vertex shader (Which I don't know how to do yet). Can anyone confirm or deny this ? If this is indeed the case, I'll probably have to go back to using FVFs again, like I did in my previous Dx7 engine.

[edited by - Mort on June 4, 2002 8:03:04 AM]

Share this post


Link to post
Share on other sites
Ah...

Yep, if you''re using a vertex shader, you must do *ALL* of the transformation and lighting for the vertex yourself.

The D3D lighting (as enabled with D3DRS_LIGHTING) is *only* for the fixed function pipeline (i.e. not shaders, like the DX7 way of doing things).

This only applies if you have a programmable vertex shader - i.e. one you have created with CreateVertexShader(). It doesn''t apply if you''ve passed an FVF code to SetVertexShader() instead of a shader handle.


If you aren''t using full vertex shaders (i.e. created with CreateVertexShader), then you should look up the post I mentioned where the original poster was trying to do exactly the same thing as you are.




--
Simon O''Connor
Creative Asylum Ltd
www.creative-asylum.com

Share this post


Link to post
Share on other sites
Great, S1ca. Even though the D3DRS_EMISSIVEMATERIALSOURCE state didn''t make the change, searching for the word "D3DRS_EMISSIVEMATERIALSOURCE" gave me the article you had submitted a reply for, and inthere I found the solution I was looking for.

Calling SetRenderState(D3DRS_AMBIENTMATERIALSOURCE, D3DMCS_COLOR1) gave me the vertex color I was expecting to see .

For anyone interested, the answer was found at www.gamedev.net/community/forums/topic.asp?topic_id=96771

- Mort

Share this post


Link to post
Share on other sites