#### Archived

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

# Problems with lighting

This topic is 5806 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I''m getting unwanted results with DX8 lighting. Here is what I get. There''s a point light in the left. Maybe this is an expected result (which I doubt), but frankly, it looks ugly. Is there a way to make the lighting smoother than that so the sphere would actually look like a sphere? rk

##### Share on other sites
since the silouette of the sphere seems perfectly round you are probably already using enough polys.

are the normals all correct and normalized? (->yes, otherwise lighting will fuck up)
do you use any "scaling" matrices? (->no, not good with d3d!)

bye,

--- foobar
We push more polygons before breakfast than most people do in a day

##### Share on other sites
quote:
Original post by foobar
are the normals all correct and normalized?
do you use any "scaling" matrices?

Yes.
No.
No.
No.

rk

##### Share on other sites
Are your attenuation settings like these: atten0=some number, atten1=0, atten2=0? If yes, you are getting NO attenuation with distance. This is not what you want. Set atten0 to 0 and atten1 to 0.1 and see if it helps.

##### Share on other sites
Now as I fiddled with the attenuation values, I found out a very strange thing. If I set all attenuations to zero, I get the result in the screenshot. If I change the values to anything else, the scene acts like lighting was disabled.

And things get even stranger: I noticed that when I compile the Retail version of my program instead of Debug that I've been doing so far, everything turns blue! Like all the other hues were simply stripped off the picture.

I have no slightest idea what might be causing this, I've fiddled around with about everything in my code and haven't gotten rid of these two problems.

rk

Edited by - rk on February 25, 2002 6:33:32 AM

##### Share on other sites
Today when I was once again fiddling around with the code, I found out that by stopping using materials made my app work in the desired way.

I thought you need to use materials to make lighting work correctly; what I''m experiencing is that if you DO use materials, everything will get screwed up. Funny.

rk

##### Share on other sites
> If I set all attenuations to zero

The docs say not to do that :-)

Try a material like this:

  D3DMATERIAL8 Mat; Mat.Diffuse.r = 1.0F; Mat.Diffuse.g = 1.0F; Mat.Diffuse.b = 1.0F; Mat.Diffuse.a = 1.0F; Mat.Ambient.r = 1.0F; Mat.Ambient.g = 1.0F; Mat.Ambient.b = 1.0F; Mat.Ambient.a = 1.0F; Mat.Specular.r = 0.0F; Mat.Specular.g = 0.0F; Mat.Specular.b = 0.0F; Mat.Specular.a = 0.0F; Mat.Emissive.r = 0.0F; Mat.Emissive.g = 0.0F; Mat.Emissive.b = 0.0F; Mat.Emissive.a = 0.0F; Mat.Power = 0;

And a light like this:

  D3DLIGHT8 Light; Light.Type = D3DLIGHT_POINT; Light.Diffuse.r = 1.0F; Light.Diffuse.g = 1.0F; Light.Diffuse.b = 1.0F; Light.Diffuse.a = 1.0F; Light.Ambient.r = 0.0F; Light.Ambient.g = 0.0F; Light.Ambient.b = 0.0F; Light.Ambient.a = 0.0F; Light.Specular.r = 0.0F; Light.Specular.g = 0.0F; Light.Specular.b = 0.0F; Light.Specular.a = 0.0F; Light.Position = theApp.LightPosition; Light.Direction.y = -1.0F; Light.Direction.x = 1.0F; Light.Direction.z = 1.0F; D3DXVec3Normalize((D3DXVECTOR3 *) &Light.Direction, (D3DXVECTOR3 *) &Light.Direction); Light.Attenuation0 = 1; Light.Attenuation1 = 0; Light.Attenuation2 = 0; Light.Theta = Light.Phi = 0; Light.Range = 999;

and see what it does.

Hope this helps (-:

##### Share on other sites
I''ve done so many changes to the program recently that I''ve really lost track. Now as I tried the materials with your values, NightShade, it worked absolutely fine. I can even change the diffuse colour values (!)

Direct3D seems to be a very delicate and complex thing and even the slightest fault in the input data will lead into terrible results. Urgh, learning this stuff is gonna take a looooong time if even making this simple program to work properly took me so long.

rk