#### Archived

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

# Serious Lighting Issues!

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

## Recommended Posts

*sigh* It just won''t work! I''ve got a .x mesh (exported from MilkShape 3D 1.5.7 if that''s relevant) that I''m loading into a Direct3D 8 application (which works fine). The mesh even displays itself using its ambient colour (specified in the material and a call to SetMaterial), but with initializing, setting and enabling a light a few things confuse me. The Range member of the D3DLIGHT8 for one - point lights seem to be unaffected by the Range member whatsoever, which is a serious pain. I have to position a point light right next to the mesh for it to have any effect at all. I haven''t been able to get directional or spot lights to work thus far, so I''m not sure if the range thing is an issue for them or not yet The Direction member when working with spotlights and directional lights ... Providing a normalized vector that points directly along the Z-axis (0.0f, 0.0f, 1.0f) should point it "straight ahead" or "straight backwards" theoretically, depending on which coord system (LH or RH) you''re using - correct? Woe be my poor little unlit mesh, as the spot light fails to illuminate it at all. You''ll have to forgive me, these seem like such silly little problems and almost certainly stem from my poor knowledge of 3D concepts - but the model loads goddammit ... lol Thanks for any help, Tom Relevant Source:
  // // when working with directional lights. Spotlight stuff // looks much similar. // g_lpDevice3D->SetRenderState( D3DRS_AMBIENT, D3DCOLOR_XRGB( 128, 128, 128 ) ); D3DLIGHT8 light; memset( &light, 0, sizeof( light ) ); light.Type = D3DLIGHT_DIRECTIONAL; light.Diffuse.r = 1.0f; light.Diffuse.g = 1.0f; light.Diffuse.b = 1.0f; light.Position.x = 0.0f; light.Position.y = 0.0f; light.Position.z = -8.0f; light.Direction.z = 1.0f; light.Attenuation0 = 1.0f; light.Range = 1000.0f; g_lpDevice3D->SetLight( 0, &light ); g_lpDevice3D->LightEnable( 0, TRUE ); g_lpDevice3D->SetRenderState( D3DRS_LIGHTING, TRUE ); g_lpDevice3D->SetRenderState( D3DRS_CULLMODE, D3DCULL_NONE ); 
and the following uses the same code as above, albeit the light structure is initialized differently:
  light.Type = D3DLIGHT_POINT; light.Diffuse.r = 1.0f; light.Diffuse.g = 1.0f; light.Diffuse.b = 1.0f; light.Position.x = 0.0f; light.Position.y = 0.0f; light.Position.z = 3.0f; light.Attenuation1 = 1.0f; light.Range = 1000.0f; // this doesn''t change anything. Has the same effect as specifying 1.0f, 2.0f or 10000.0f 

##### Share on other sites
mmmm - that''s something that annoys the hell outta me too..

try increasing the values of the rgb diffuse components to something like 3.0 or 4.0, then play around with them until you get the right lighting...

as far as i can tell, the range value only affects the point at which things will no longer be affected by the light..have a look at the Attenuation0 value for this... i think..

##### Share on other sites
Some issues to consider:
(1) If your spotlight cone doesn''t actually enclose any vertices (for example, they are very spread out), you won''t see any light from it.
Also make sure phi > theta, that they are in radians, and that they are large enough to make a good sized cone. Just from problems I''ve had before :-)

(2) As for attenuation, having 1,0,0 for the attenuation0,1,2 parameters *should* make a light that doesn''t "fade" out until the range is exceeded (which will make kind of an ugly border area). Actually attenuating the light is tricky, and for me is usually a trial and error thing, but 1,0,0 should work.

(3) Material affects lighting. Make sure your diffuse component for the material is set properly.

(4) Setting a world or view matrix that contains non uniform scaling can seriously mess up your scene''s lighting (especially if the scalar is a zero). Probably not your problem, but something to remember.

(5) Try it without any ambient or directional lighting. Perhaps your model is actually being lit, but the point lighting is being hidden by the directional and/or ambient lighting. Multiple D3D lights don''t really "add" past a certain point (where the vertex color component becomes rgb=255,255,255).

Hope something here helps.

One other thing I just thought of, is that if your projection matrix is set to right hand, and if the model is set up for left-hand (or vice-versa), and if the normals are generated at run time, you could end up with reversed normals. Of course this should cause the reverse side to light up, so maybe that''s not it either.

Good luck!

##### Share on other sites
Thanks guys, will try out your suggestions and post results and any solution I may come across myself

Tom

##### Share on other sites
Okay, it''s sorted. The problem was with the model itself, NOT the lighting. I''m not sure exactly what''s wrong with the model (a simple Phantom aircraft), but creating other models and placing them in along with a mesh from D3DXCreateSphere displays directional lighting perfectly. Yet to test others, but I''m guessing I''ll have similar successes.

Tom

• 16
• 9
• 13
• 41
• 15
×

## Important Information

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!