Jump to content
  • Advertisement


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


Generating a lightmap for a landscape

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

Well, the consensus seems to be that I should use lightmaps to light my landscape instead of gouraud shading... 1. Won''t I clearly see the edges of the polygons if I use flat shading combined with lightmaps, or do I not use any shading at all? (I guess the latter). 2. Must my lightmap be at a very high resolution, or will DX8 correctly "interpolate" the dots when I get close to the terrain? My landscape is huge, and I cannot afford the memory for all the lightmaps I will need. As long as the staircase effect isn''t bad, then a "low res" lightmap would be OK for me I guess. 3. How do I go about generating one of these? I could pre-render them with a rendering package, but I''d rather they be dynamic. I guess I could render the landscape 1 time with all 1,000,000 vertices, and take a "snapshot" of that gouraud shading, using that for my lightmap. I don''t want to write my own ray-tracing if I can avoid it. I could easily do that by calculating a line from each terrain vertex to the lightsource, and checking for intersection, BUT, I would have to check if ANY OTHER vertices intersect with that line to do the raytrace, right? UGH SLOW (even for 1-time). SIGH. Thanks for your tips, Greg.

Share this post

Link to post
Share on other sites

1) Don''t use shading; turn lighting off. That is what the lightmap is for.

2) Use two texture stages; stage 0 is your terrain, and is lit to 100% lighting. Stage 1 is your lightmap; set it''s stagestate values so that it is transparent and "subtractive", and it will darken the terrain under it. Turn on linear texture filtering for stage 1, and DX will interpolate. And the lightmap need only be the same size as your map; if you have a 128x128 tile map, you can have a 128x128 pixel lightmap, or higher if you want.

3) I cannot explain how to make it dynamic, because I don''t know exactly what kind of changes you will be making to the terrain or the lighting. But, as for generating the lightmap itself... there''s lots of ways. I''ll give you one...

3a) You can make your own little generator. at each corner/vertex, scan across the terrain in the direction of the light by half-tiles, until you reach the edge of the map. At each point you scan, if the terrain is higher than the point where you started, check; If the angle of the light is not steep enough to get over the terrain, then this corner will be dark. Otherwise, it will be light.
3a, PS) If you use the "subtractive" method of lightmapping, remember that areas you want to be 100% dark must be 100% white in the lightmap! 25% dark = 75% light in lightmap, etc...

3b) If you have buildings and such, then you need to do some ray-casting... but only for the buildings! Project each face of the building onto the ground, using the light''s direction as the projection vector. Scan through the area that the building''s shadow lands on, and darken the corners where the corner collides with the shadow.

S''about all I can say. If you need much more help than that, give me a shout at (zlaj@hotmail.com).

Hope this helps!

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!