// Set light data
ZeroMemory(&Light, sizeof(Light));
Light.Type = D3DLIGHT_SPOT;
Light.Diffuse.r = 1.0f;
Light.Diffuse.g = 1.0f;
Light.Diffuse.b = 0.0f;
Light.Ambient.r = 1.0f;
Light.Ambient.g = 1.0f;
Light.Ambient.b = 0.0f;
Light.Range = 1000.0f;
Light.Falloff = 1.0;
Light.Phi = 0.3488;
Light.Theta = 0.1744;
Light.Direction = D3DXVECTOR3(0.0f, 0.0f, 1.0f);
Light.Attenuation0 = 0.0f;
Light.Attenuation1 = 0.0f;
Light.Attenuation2 = 0.0f;
Light.Position.x = 0.0f;
Light.Position.y = 0.0f;
Light.Position.z = -100.0f;
// Set and enable the light
g_pD3DDevice->SetLight(0, &Light);
g_pD3DDevice->LightEnable(0, TRUE);
// Set material properties
ZeroMemory(&Material, sizeof(Material));
Material.Diffuse.r = 1.0f;
Material.Diffuse.g = 1.0f;
Material.Diffuse.b = 1.0f;
g_pD3DDevice->SetMaterial(&Material);
Problems with spotlight
Howdy all,
I can't figure out how to get my spotlight to work correctly. I have a small cube spinning around the y-axis at the origin. I'm trying to setup a yellow spotlight to light up the front of my cube, which has a white material. However, I just can't get it to light correctly. The cube still looks white and it lights up the same way if I were using a point light instead. Here's part of my code:
I tried to fiddle around with all the properties, but can't seem to get anywere. Any suggestions would be great.
Thanks.
Eric
[edited by - codegod on April 19, 2002 2:19:51 PM]
yo whats up,
i recently had the same problem, and instead of using color values b/t 0.0 and 1.0, i used values b/t 0 - 255. although this goes against the sdk documentation, it worked. so you might want to try that, i really do not see any problems with your code by glancing at it. good luck.
i recently had the same problem, and instead of using color values b/t 0.0 and 1.0, i used values b/t 0 - 255. although this goes against the sdk documentation, it worked. so you might want to try that, i really do not see any problems with your code by glancing at it. good luck.
First, you should be aware that because lighting is done per-vertex (unless you''re using pixel shaders), a cube with a spotlight on it won''t look very good unless it has several (ie more than 4) vertices per face.
Second, you''ve got full red and green ambient light on - which means that the red and green colour values will effectively be taken directly from your material.
Third, since you say you''re getting a white cube, even though your light is yellow (red + green, but no blue), it seems like lighting isn''t being performed at all - make sure you''re turning lighting on with
SetRenderState(D3DRS_LIGHTING, TRUE);
So the things to do are:
+ Check you''re render and texture state settings (you may also want to check the DirectX docs to find out the default values for some things).
+ Reduce the ambient lighting values (mainly to see if they''re interfering).
+ Work out (probably on paper) which parts of the cube should be illuminated given the settings you''re actually using (not just the settings you think you''re using, or the effect you want to produce).
Anyway, I''ll post when I''ve thought about it some more.
John B
Second, you''ve got full red and green ambient light on - which means that the red and green colour values will effectively be taken directly from your material.
Third, since you say you''re getting a white cube, even though your light is yellow (red + green, but no blue), it seems like lighting isn''t being performed at all - make sure you''re turning lighting on with
SetRenderState(D3DRS_LIGHTING, TRUE);
So the things to do are:
+ Check you''re render and texture state settings (you may also want to check the DirectX docs to find out the default values for some things).
+ Reduce the ambient lighting values (mainly to see if they''re interfering).
+ Work out (probably on paper) which parts of the cube should be illuminated given the settings you''re actually using (not just the settings you think you''re using, or the effect you want to produce).
Anyway, I''ll post when I''ve thought about it some more.
John B
Hmm... well I know my rendering states are correct, since it works just fine when I use a point light or directional light.
I''ve tried not using any ambient light, but that didn''t make any difference.
I think I''m beginning to remember back in the days when I was using OpenGL, that I had to split a four vertex poly into 8 polys in order for it to have enough vertices and normals for the spot light to look right.
I will give that a try and see what happens.
Thanks.
Eric
I''ve tried not using any ambient light, but that didn''t make any difference.
I think I''m beginning to remember back in the days when I was using OpenGL, that I had to split a four vertex poly into 8 polys in order for it to have enough vertices and normals for the spot light to look right.
I will give that a try and see what happens.
Thanks.
Eric
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement