I hate lights

Started by
13 comments, last by Trillian 18 years, 6 months ago
Whats wrong with my lights? All my polys are just rendered plain black!

//Globals
D3DLIGHT9 Light;

//[...]

//Init
ZeroMemory( &Light, sizeof(Light) );
pD3DDevice->SetRenderState(D3DRS_LIGHTING,true);
pD3DDevice->SetRenderState(D3DRS_AMBIENT,RGB(1.0f,1.0f,1.0f));
Light.Type      = D3DLIGHT_POINT;
Light.Ambient   = D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f);
Light.Diffuse   = D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f);
Light.Specular  = D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f);

//I also tried like this:
//Light.Diffuse.r = 1.0f;
//Light.Diffuse.g = 1.0f;
//Light.Diffuse.b = 1.0f;

Light.Position  = D3DXVECTOR3(0.0f, 3.0f, -1.0f);
Light.Range     = 1000.0f;
Light.Falloff   = 1.0f;
Light.Attenuation0 = 1.0f;
Light.Attenuation1 = 0.0f;
Light.Attenuation2 = 0.0f;
pD3DDevice->SetLight(0, &Light);
pD3DDevice->LightEnable(0, true);

//[...]

//Render all thingZ


I have made all possible tutorials but found no answers! the only thing I see when doing this is my vertex-shaded teapot, and even if I comment all the shaders things, the lights wont work!
Advertisement
Light.Position = D3DXVECTOR3(0.0f, 3.0f, -1.0f);

Where is your direction?

Also, if you are using the sampleFramework and HLSL (.fx) then the fixed-function (D3DLight) is disabled automatically.
He's using a point light so he shouldn't need one.

What are the material settings for your polys?
Ok so I need a material for EACH of my polygons?
And do I also need to set normals in my FVFs?
Yes, you do need normals and materials. One material should be enough, it just means all your polygons will have the same color and such.

Make sure you calculate the normals correctly too, you can't just add them to the FVF. I think if you use a d3dxmesh it can do this for you.
Ok now i've made a material and it works!
I'm now getting all my polys in color.

But stiiillllll... The light wont work!

I'll put back my code because I might have updated it:
//GlobalsD3DLIGHT9 Light;//in bool init() :	ZeroMemory( &Light, sizeof(Light) );	pD3DDevice->SetRenderState(D3DRS_LIGHTING, true);	//pD3DDevice->SetRenderState(D3DRS_AMBIENT,RGB(0.0f,1.0f,1.0f));	Light.Type      = D3DLIGHT_POINT;	D3DCOLORVALUE LightColor;	LightColor.a=LightColor.r=LightColor.b=1.0f;	Light.Ambient   = LightColor; //D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f);	Light.Diffuse   = LightColor; //D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f);	Light.Specular  = LightColor; //D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f);	Light.Position  = D3DXVECTOR3(0.0f, 3.0f, -1.0f);	Light.Range     = 5.0f;	Light.Falloff   = 1.0f;	Light.Attenuation0 = 1.0f;	Light.Attenuation1 = 0.0f;	Light.Attenuation2 = 0.0f;	pD3DDevice->SetLight(0, &Light);	pD3DDevice->LightEnable(0, true);    D3DCOLORVALUE MaterialColor;	MaterialColor.a=MaterialColor.r=MaterialColor.g=1.0f;    D3DMATERIAL9 DefaultMaterial;    DefaultMaterial.Ambient=        DefaultMaterial.Diffuse=        DefaultMaterial.Emissive=        DefaultMaterial.Specular=MaterialColor;    DefaultMaterial.Power=1.0f;    pD3DDevice->SetMaterial(&DefaultMaterial);


Ok now you can forget about the vertex shader thing, I have removed it completely to be sure it doesn't influence the fixed function pipeline.

Still I dont see my mistakes, I've made all steps:
1-Enable lights
2-Create light structure
3-Set as light 0
4-Enable light 0

Any ideas?

Note that I am using a ID3DXMesh, a plane and a heightmap to test my light, the mesh should have normals (I put D3DFVF_NORMAL in my CloneMeshFVF) but not the other objects, but anyway I should not be able to see anything from a certain distance even without normals I guess..
In directx SDK 9.0 you can find a 'Lighting' sample. In sample there are point, directional, and spot lights, all moving and working 100%. Look at it... if you don't have it send me a message I'll send it to you via mail.

Hum... I can't seem to find your lighting sample... I have only HLSL things.

Was I in the good directory?
C:\Program Files\Microsoft DirectX 9.0 SDK (August 2005)\Samples\C++\Direct3D

BTW my email should be in my profile
nop it is in original dirctx 9.0 sdk, the first one without updates. anyway I'll send it to you...
If you see the colors specified in the material, and lighting is enabled, that should mean the light is working.

Maybe it's not working at all, but I'd guess it's just not working the way you expect. I would try messing with the settings: increase the range, set the "ambient" value to zero, and decrease the attenuation for starters, just to see if it has any effect.

This topic is closed to new replies.

Advertisement