Lightmapping geomipmapped terrain

Hi all,

I succesfully implemented geomipmapping for my terrain engine. I am using a 1025 x 1025 heighmap with 17 x 17 patch size. The next step is to apply a lightmap over the entire terrain, this I found a bit hard to implement. I am probably missing something on texturing in general or something.

I would like to precalculate a lightmap from the heightmap and then create a texture from this data to wrap over the entire terrain. But this one big texture would have to span over multiple Shape3D objects. Another approach would be to generate a smaller lightmap for every patch. What would be the best approach? How do I have to generate texture coordinates in the case of one big lightmap? Any hints on generating a lightmap would be appriciated too ;) Thanks in advance.

[796 byte] By [Bananiel] at [2007-9-30 21:27:00]
# 1

If you are trying to implement shadows on your terrain, I can think of two different approaches. Which option you use depends on your approach to geomipmapping. There are geometry simplification algorithms for terrains (such as RTIN and ROAM) that vary the number of triangles based on the user's position (more triangles close in, bigger and fewer far away). If you are using patches that have a fixed geometry, consider using vertex coloring. If you are varying the geometry of the patches, consider using texture mapping.

I have used vertex coloring to create shadows when the geometry has a high level of detail and the geometry is fixed. I would assume you are already coloring your terrain with a color ramp of some sort. To create the light map, I have done light ray tracing. This is essentially for each light source, start at a vertex. Visit each vertex on the line between that vertex and the edge of the terrain in the direction of the light source. If the light ray is interrupted by a vertex with a higher elevation, then it is in a shadow. I take the color of the vertex, convert it to HLS, decrease the L and convert back to RGB. An example of this approach is described in more detail here: http://www.gamedev.net/reference/articles/article1817.asp. I have found it necessary to emulate a penumbra with a transisition color at the edge of the shadow.

If the patch geometry varies, I think it might be difficult to do vertex coloring since the number of vertices change in real-time. You might be able to calculate a light map as I described above and then interpolate new vertex colors as the geometry changes. For this reason, I believe texture mapping would work best for variable geometries.

Because of the power of 2 contraint on texture sizes, I would tend to side with the single texture approach to reduce the amount of memory swapping in the video card. Theoretically, it could be faster to have a texture per patch which would make texture coordinates easier. You would have to experiment to see if there is a performance advantage with one approach versus the other. In either case, I think the challenge is to create the light map at each pixel given the texture resolution will be different from your terrain vertex resolution. The J3D tutorial has a pretty good overview of how to create texture coordinates. It is essentially the percentage approach (values ranging from 0.0 to 1.0 or 0% to 100% of the texture). I did include texture mapping over a fixed geometry terrain in my June 2004 JDJ article if you want to crawl through a code example: http://sys-con.com/story/?storyid=45087&DE=1. That example does not include light map support though.

Hope this helps,

Mike

mnjacobs at 2007-7-7 2:58:56 > top of Java-index,Security,Cryptography...
# 2

Thank you for your reply. I have changing geometry so I have to go with a lightmap aproach, I followed the geomipmapping algorithm from de Boer found at flipcode. I had found that article on gamedev earlier and I tried it but I am not so happy with the result. I guess I made some mistakes in the implementation but I still have to dig into that. What do you mean by emulate a penumbra at the edges? Once again thanks for your reply.

Bananiel at 2007-7-7 2:58:56 > top of Java-index,Security,Cryptography...
# 3

> What do you mean by

> emulate a penumbra at the edges?

A shadow has two areas: umbra and penumbra. Have a look at the picture here: http://www.schorsch.com/kbase/glossary/penumbra.html. When you look at the edges of a shadow, you should see a lighter version of the shadow (penumbra) around the edge of the dark area (umbra).

I'll have to read that article. I am in the middle of implementing a ROAM geomipmap approach (see http://www.llnl.gov/graphics/ROAM/).

Good luck,

Mike

mnjacobs at 2007-7-7 2:58:56 > top of Java-index,Security,Cryptography...