The Cube is not Lighted

Started by
7 comments, last by silvia_steven_2000 18 years, 11 months ago
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
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.
Take back the internet with the most awsome browser around, FireFox
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.
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. :)
Sincerely,Arto RuotsalainenDawn Bringer 3D - Tips & Tricks
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
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?
Chris ByersMicrosoft DirectX MVP - 2005
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.

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.

thanks guys , I fixed it. ur comments helped allot.

This topic is closed to new replies.

Advertisement