Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

hVoid

D3D Light Problems

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

I''m new to DirectX, so it''s probably just something stupid I forgot to do. Diffuse and specular lighting doesn''t work, and I can''t figure out why. I''ve even tried coping source from other programes. Any help would be appriciated.

Share this post


Link to post
Share on other sites
Advertisement
It could be because you aren''t setting the diffuse and specular components for your materials. What type of lighting are you using? Or post your code for setting up the light and materials.

*** Triality ***

Share this post


Link to post
Share on other sites
In what way don''t they work?

Here are some steps that are needed to get lighting to work:

pD3DDev->SetRenderState(D3DRENDERSTATE_LIGHTING, TRUE); // Default
pD3DDev->LightEnable(0, TRUE); // Enable light 0
D3DLIGHT7 Light; // Initialize the lightsource
...
pD3DDev->SetLight(0, &Light);

In addition to this you also need to specify the material:

pD3DDev->SetRenderState(D3DRENDERSTATE_DIFFUSEMATERIALSOURCE, D3DMCS_MATERIAL); // Default == D3DMCS_COLOR1
pD3DDev->SetRenderState(D3DRENDERSTATE_SPECULARMATERIALSOURCE, D3DMCS_MATERIAL); // Default == D3DMCS_COLOR2
pD3DDev->SetRenderState(D3DRENDERSTATE_AMBIENTMATERIALSOURCE, D3DMCS_MATERIAL); // Default == D3DMCS_COLOR2
pD3DDev->SetRenderState(D3DRENDERSTATE_EMISSIVEMATERIALSOURCE, D3DMCS_MATERIAL); // Default == D3DMCS_MATERIAL

D3DMATERIAL7 Material; // Initialize Material
...
pD3DDev->SetMaterial(&Material);

This is assuming you didn''t want vertex coloring. If you want vertex coloring then you can skip the material setup and instead change your Flexible Vertex Format to include diffuse and specular color.

WitchLord

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
To answer a few questions, yes I set the diffuse and specular components for the matterial an light, no it doesn''t matter what type of light I use, and when i say the diffuse and specular components don''t work, I mean they arn''t rendered.

Here is my source (I''m proramming in Visual Basic):
---------------------------------------------------

Dim mtrl As D3DMATERIAL7
Dim Light1 as D3DLIGHT7

g_d3dDevice.SetRenderState(D3DRENDERSTATE_LIGHTING, True)
g_d3dDevice.SetRenderState(D3DRENDERSTATE_SPECULARENABLE, True)

With Light1
.dltType = D3DLIGHT_POINT
.position.x = 0
.position.y = -170
.position.z = 0
.range = 600
.attenuation1 = 0.01
.diffuse = DXColor(1, 1, 1, 1)
.Ambient = DXColor(1, 1, 1, 1)
.specular = DXColor(1, 1, 1, 1)
End With
g_d3dDevice.SetLight(0, Light1)
g_d3dDevice.LightEnable(0, True)

mtrl.Ambient = DXColor(0.5, 0.5, 0.5, 0.5)
mtrl.diffuse = DXColor(1, 1, 1, 1)
mtrl.specular = DXColor(1, 1, 1, 1)

g_d3dDevice.SetMaterial(mtrl)

---------------------------------------------
I''ll atempt to translate it into C++...
---------------------------------------------

D3DMATERIAL7 mtrl;
D3DLIGHT7 Light1;

g_d3dDevice->SetRenderState(D3DRENDERSTATE_LIGHTING, True);
g_d3dDevice->SetRenderState(D3DRENDERSTATE_SPECULARENABLE, True);

Light1->dltType == D3DLIGHT_POINT;
Light1->position.x == 0;
Light1->position.y == -170;
Light1->position.z == 0;
Light1->range == 600;
Light1->attenuation1 == 0.01;

Light1->diffuse->r == 1;
Light1->diffuse->g == 1;
Light1->diffuse->b == 1;
Light1->diffuse->a == 1;

Light1->Ambient->r == 1;
Light1->Ambient->g == 1;
Light1->Ambient->b == 1;
Light1->Ambient->a == 1;

Light1->specular->r == 1;
Light1->specular->g == 1;
Light1->specular->b == 1;
Light1->specular->a == 1;

g_d3dDevice->SetLight(0, Light1);
g_d3dDevice->LightEnable(0, True);

mtrl->diffuse->r == 1;
mtrl->diffuse->g == 1;
mtrl->diffuse->b == 1;
mtrl->diffuse->a == 1;

mtrl->Ambient->r == 0.5;
mtrl->Ambient->g == 0.5;
mtrl->Ambient->b == 0.5;
mtrl->Ambient->a == 0.5;

mtrl->specular->r == 1;
mtrl->specular->g == 1;
mtrl->specular->b == 1;
mtrl->specular->a == 1;

g_d3dDevice->SetMaterial(mtrl);

Share this post


Link to post
Share on other sites
To answer a few questions, yes I set the diffuse and specular components for the matterial an light, no it doesn''t matter what type of light I use, and when i say the diffuse and specular components don''t work, I mean they arn''t rendered.

Here is my source (I''m proramming in Visual Basic):
---------------------------------------------------

Dim mtrl As D3DMATERIAL7
Dim Light1 as D3DLIGHT7

g_d3dDevice.SetRenderState(D3DRENDERSTATE_LIGHTING, True)
g_d3dDevice.SetRenderState(D3DRENDERSTATE_SPECULARENABLE, True)

With Light1
.dltType = D3DLIGHT_POINT
.position.x = 0
.position.y = -170
.position.z = 0
.range = 600
.attenuation1 = 0.01
.diffuse = DXColor(1, 1, 1, 1)
.Ambient = DXColor(1, 1, 1, 1)
.specular = DXColor(1, 1, 1, 1)
End With
g_d3dDevice.SetLight(0, Light1)
g_d3dDevice.LightEnable(0, True)

mtrl.Ambient = DXColor(0.5, 0.5, 0.5, 0.5)
mtrl.diffuse = DXColor(1, 1, 1, 1)
mtrl.specular = DXColor(1, 1, 1, 1)

g_d3dDevice.SetMaterial(mtrl)

---------------------------------------------
I''ll atempt to translate it into C++...
---------------------------------------------

D3DMATERIAL7 mtrl;
D3DLIGHT7 Light1;

g_d3dDevice->SetRenderState(D3DRENDERSTATE_LIGHTING, True);
g_d3dDevice->SetRenderState(D3DRENDERSTATE_SPECULARENABLE, True);

Light1->dltType == D3DLIGHT_POINT;
Light1->position.x == 0;
Light1->position.y == -170;
Light1->position.z == 0;
Light1->range == 600;
Light1->attenuation1 == 0.01;

Light1->diffuse->r == 1;
Light1->diffuse->g == 1;
Light1->diffuse->b == 1;
Light1->diffuse->a == 1;

Light1->Ambient->r == 1;
Light1->Ambient->g == 1;
Light1->Ambient->b == 1;
Light1->Ambient->a == 1;

Light1->specular->r == 1;
Light1->specular->g == 1;
Light1->specular->b == 1;
Light1->specular->a == 1;

g_d3dDevice->SetLight(0, Light1);
g_d3dDevice->LightEnable(0, True);

mtrl->diffuse->r == 1;
mtrl->diffuse->g == 1;
mtrl->diffuse->b == 1;
mtrl->diffuse->a == 1;

mtrl->Ambient->r == 0.5;
mtrl->Ambient->g == 0.5;
mtrl->Ambient->b == 0.5;
mtrl->Ambient->a == 0.5;

mtrl->specular->r == 1;
mtrl->specular->g == 1;
mtrl->specular->b == 1;
mtrl->specular->a == 1;

g_d3dDevice->SetMaterial(mtrl);

Share this post


Link to post
Share on other sites

  • 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!