Archived

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

apanjocko

wierd light bug (picture)

Recommended Posts

i have a generated terrain and two lights, one directional and one point. the directional is from (0.8, 0, 1) which seems to do what it''s supposed. the point light however, situated just above the blue tank, is really wierd. different attenuation values yields a bit different results but with the same wierdness. what i don''t like here is how it doesn''t really fade of in the end of the light. i don''t have a word for it... you get what i mean? check this out: http://www.student.bth.se/~daak03/tankland_lightbug.jpg one more thing that maybe someone could answer. the tanks is not affected correctly by the tanks. they act real wierd. i think you can see it on the picture. some areas get black and if i drive around with the tank different areas get all black. thanks for any help about this

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Many things can cause lighting problems, but here are some common things to look for. Do the tanks have normals? Are the normals normalized? Do you ever scale the tanks, and if so do you renormalize the normals?

Share this post


Link to post
Share on other sites
thanks for your answer!

the problem is not with the tanks,
it''s the light coming from the point-light above the blue tank that looks freaky on the terrain.

here is a screenshot showing again what i mean. now the tanks are rendered nicely, but focus on the light around the blue tank.
http://www.student.bth.se/~daak03/ss_tankland_11.jpg

here is a screenshot showing that there is no problem (as far as i can see) with the normals on the terrain.
http://www.student.bth.se/~daak03/ss_tankland_12.jpg

the problem seems to be that the point light won''t light only a part of a triangle obviously... it clearly stops after a whole triangle.

so, i don''t think there is a problem with the tank lightning, even though I don''t normalize the normals on the tank after scaling... it''s a loaded .x file; do you really have to open up the vertex buffer and re-calculate the normals? my .x file is not the correct scaling according to the world, so i scale it every frame.

i have no clue, anyone?

Share this post


Link to post
Share on other sites
Hey,
I''m not an expert in this area, but I believe that lights operate per vertex. Looking at your picture, it appears that the light fades across the ring of polygons at it''s edge. I don''t really know how to fix it, but I think that''s how it''s supposed to be.

tj963

Share this post


Link to post
Share on other sites
quote:
Original post by apanjocko
the problem seems to be that the point light won''t light only a part of a triangle obviously... it clearly stops after a whole triangle.


This is because of what tj963 already said. Light values are computed at each vertex and then interpolated accross the whole triangle. To see a very drastic example of this, run the LightingVS sample that comes with the SDK. Hit "w" to change into wireframe mode. Now use the up and down arrows to change the level of tessellation of the mesh. Notice how the lighting doesn''t fall off as nicely with lower levels of tessellation.

For your terrain, there are a couple of solutions to this. The easiest is probably to generate more triangles for your terrain. Keep the terrain the same size but increase the number of triangles it uses. This will let light fall off a little better. Two other solutions for this are:
1. Use a pixel shader to calculate lighting at each pixel instead of at each vertex.
2. Use dot3 bumpmapping to simulate per-pixel lighting.

These two techniques work very nicely but I think they''re overkill to just light up your terrain. Your best bet is to increase the triangle count of your terrain.

quote:

so, i don''t think there is a problem with the tank lightning, even though I don''t normalize the normals on the tank after scaling... it''s a loaded .x file; do you really have to open up the vertex buffer and re-calculate the normals? my .x file is not the correct scaling according to the world, so i scale it every frame.


The thing is that when you scale your geometry, the normals in the mesh also get scaled. So the normals are no longer of unit length. This messes up D3D''s lighting calculations. For a more detailed explanation as to why this is, take a look at a generic 3D graphics book or do a search with google or here at gamedev.

That being said, you don''t have to go into the vertex buffer and re-normalize the normals of your geometry. You can have D3D normalize everything for you by setting a renderstate: m_pd3dDevice->SetRenderState( D3DRS_NORMALIZENORMALS, TRUE );

This causes D3D to normalize all normals for lighting calculations. This will cause a small performance hit. Professional applications have the artist do all their scaling and such in the model app (like 3D Studio Max) so that the engine doesn''t have to recalculate normals at runtime.

Hope this helps,
neneboricua

Share this post


Link to post
Share on other sites