Jump to content
  • Advertisement
Sign in to follow this  
silvia_steven_2000

The Cube is not Lighted

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

Hi All I have a cube with some material properties. the vertices have their own colors and normals. when I turn off lighting and render the cube I get it rendered well with these colors which is ok. when I turn on lighting without specifying any light source, it becomes black which is also ok. now I added one light source and enable lighting. the cube is rendered with the original colors. I guess d3d should assign new colors based on lighting conditions. why does not it do that ? by the way , I am specifying a vertex format of pos|norm|color. any hints ? thanks

Share this post


Link to post
Share on other sites
Advertisement
Uh...yeah, your cube shouldn't change colors just because of lighting. Unless you are using different martical colors for diffuse, ambient, specual and what not. And still, those properties determine how much of WHAT color is drawn.

I think you are a little confused on how 3D lighting works. Using the normals, Direct3D computes the color for the pixel using the vertex color you specified (or texture if you are using textures, but you're not so...) and a lighting formula that compute how dark the pixel is(in general terms). Just look it up on the net or search the API docs for lighting and materials.

Share this post


Link to post
Share on other sites
I removed colors by specifying the format POS|NORM. my material is white in all color components. the light is also white in all its color components. if lighting is ok then I should see a white cube , right ?
but right now I can not see anything, I gues my light source is not working.

Share this post


Link to post
Share on other sites
Check out these renderstates:

D3DRS_DIFFUSEMATERIALSOURCE (default is vertex color 1)
D3DRS_AMBIENTMATERIALSOURCE (default is material)
D3DRS_SPECULARMATERIALSOURCE (default is vertex color 2)

With vertex colors you can control the lighting (basicly), so use materials for that, and you might want to change the sources to material. :)

Share this post


Link to post
Share on other sites
I have not used these states before but I think this is similar to color tracking in OpenGL however, I would like to point to the fact that I am not using colors right now. I am only using positions and normals by specifying the FVF_XYZ|FVF_NORMAL. do I still need to specify the sources u just mentioned ?
thanks

Share this post


Link to post
Share on other sites
Yes, try changing the D3DRS_DIFFUSEMATERIALSOURCE state to D3DMCS_MATERIAL. I'm not sure where the value comes from if it expects to get it from the vertex diffuse color and that doesn't exist. Anyone?

Share this post


Link to post
Share on other sites
Hi Silvia,
How are you doing?
Ok firstly your light doesn't seem to work right?
I would specify those colors again if I were you. Then I would like to know how you are creating your light. Secondly when debugging light it's nice to set the cube to a color or set a texture to the cube so that you can make the light white and get the a somewhat clear view of what is going on.

A few problems that might or can occur
1) You are not setting the normals correctly
2) The cube is lit and not rotating which might result in what you see with the cube being the original color since the light is directly shining on one face of the cube. the faces facing you.
3) Your material is set wrong? (check Arex post)

I hope some of this helps.

Share this post


Link to post
Share on other sites
If the DIFFUSEMATERIALSOURCE is specified to use a color from the vertex and there is no color in the vertex, the material diffuse color is used.

The default material for a device has all of its members set to 0.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!