//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
🔒 Locked
I hate lights
Advertisement
Original Post
Whats wrong with my lights? All my polys are just rendered plain black! 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!
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:
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..
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..
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.
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.
Quote:
Original post by Trillian
I don't think thats the problem because it is still lit with RGB 0 0 0 for the light...
PS : TX streamer, i'll look at these. (but I don't think i've ever installed the "basic" sdk o_O)
Too bad :) there are samples that you can't find in any DirectX 9.0a-b-c "Update".
You're welcome [smile]
Quote:
Original post by Trillian
the mesh should have normals (I put D3DFVF_NORMAL in my CloneMeshFVF) but not the other objects
Specifying D3DFVF_NORMAL in an ID3DXMesh::CloneMeshFVF() call will NOT generate normals for your object. It just allocates space (per vertex) for a normal vector. What exactly it'll be filled with is anyones guess [smile]
Try calling D3DXComputeNormals() after the cloning process.
Correct normals are required for fixed-function lighting.
hth
Jack
Now I have made a new file to start from zero implementing lights and my directional light WORKS!!!!
BUT! (I knoe you guys hate "but"s)
I made a D3DXMesh cylinder and when lit, it flashes really annoyingly.
now I have decided to put my ENTIRE script (almost)!
but then that dumb cylinder flashes (mostly on the two circlar sides).
You guys know what causes this?
EDIT -> System:
Intel Pentium 4 CPU 3.00GHz (2CPUs), ~3.00GHz
Microsoft windows XP home edition
512MB RAM
ATI RADEON 9200
DirectX 9.0c (DXSDK august 2005)
BUT! (I knoe you guys hate "but"s)
I made a D3DXMesh cylinder and when lit, it flashes really annoyingly.
now I have decided to put my ENTIRE script (almost)!
LPD3DXMESH Cylinder = 0;D3DMATERIAL9 DefaultMaterial;D3DLIGHT9 Light;bool Setup(){ pD3DDevice->SetRenderState(D3DRS_ZENABLE, true ); pD3DDevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE); pD3DDevice->SetRenderState(D3DRS_LIGHTING, true); pD3DDevice->SetRenderState(D3DRS_AMBIENT,RGB(0,0,0)); pD3DDevice->SetRenderState(D3DRS_SPECULARENABLE,true); return true;}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_DIRECTIONAL; Light.Ambient = D3DYCOLOR_WHITE * 0.6f; Light.Diffuse = D3DYCOLOR_WHITE; Light.Specular = D3DYCOLOR_WHITE * 0.3f; //Light.Position = D3DXVECTOR3(0.0f, 3.0f, -1.0f); Light.Direction = D3DXVECTOR3(1.0f, 0.0f, 0.0f); Light.Range = 0.0f; Light.Falloff = 0.0f; Light.Attenuation0 = 1.0f; Light.Attenuation1 = 0.0f; Light.Attenuation2 = 0.0f; pD3DDevice->SetLight(0, &Light); pD3DDevice->LightEnable(0, true); pD3DDevice->LightEnable(0, TRUE); DefaultMaterial.Ambient = D3DYCOLOR_WHITE; DefaultMaterial.Diffuse = D3DYCOLOR_WHITE; DefaultMaterial.Emissive = D3DYCOLOR_BLACK; DefaultMaterial.Specular = D3DYCOLOR_WHITE; DefaultMaterial.Power=5.0f; pD3DDevice->SetMaterial(&DefaultMaterial); pD3DDevice->SetRenderState(D3DRS_LIGHTING, true); pD3DDevice->SetLight(0, &Light); pD3DDevice->LightEnable(0, true); LPD3DXMESH TempMesh = 0; D3DXCreateCylinder(pD3DDevice, 2.0f, 2.0f, 4.0f, 40, 40 ,&TempMesh, 0); TempMesh->CloneMeshFVF(0,D3DFVF_XYZ | D3DFVF_NORMAL,pD3DDevice,&Cylinder); SAFE_RELEASE(TempMesh); D3DXComputeNormals(Cylinder,NULL); return true;}bool Update(float timeDelta){ pD3DDevice->Clear( 0, 0, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER | D3DCLEAR_STENCIL,D3DCOLOR_COLORVALUE(0.0f,0.0f,0.0f,0.0f), 1.0f, 0 ); /***********************/ pD3DDevice->BeginScene(); /***********************/ Cylinder->DrawSubset(0); /*********************/ pD3DDevice->EndScene(); /*********************/ pD3DDevice->Present( NULL, NULL, NULL, NULL ); return true;}bool Destroy(){ SAFE_RELEASE(Cylinder); return true;}but then that dumb cylinder flashes (mostly on the two circlar sides).
You guys know what causes this?
EDIT -> System:
Intel Pentium 4 CPU 3.00GHz (2CPUs), ~3.00GHz
Microsoft windows XP home edition
512MB RAM
ATI RADEON 9200
DirectX 9.0c (DXSDK august 2005)
Topic Locked
This topic has been locked by a moderator. New replies are not allowed.
Sign in to reply to this topic.
Advertisement