Advertisement Jump to content
Sign in to follow this  

How to generate lightmap by using Ray Tracing technique

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

when i read the book "An Introduction To Ray Tracing", i learn something about how to create a realistic image of my scene. But how to generate a lightmap (or 3 lightmaps) for each object in my scene? Current 3D game engine(e.g. UnrealEngine) used ray tracing to generate 3 lightmaps each object, and used these lightmap in shader to modulate diffuse color/texture. Is there any paper to read? thanks.

Share this post

Link to post
Share on other sites
I don't know of any paper about that (though I'm sure there are plenty of them out there). As far as I know, you must first build a basic raytracer. Then from every surface you shot n rays (where n is the resolution you want the lightmaps to be, and considering only point lights), and shot them towards each light source. If a ray hits another surface closer than the light, its contribute to the final lightmap pixel is zero. Otherwise it is a value that depends upon the number (and intensity ) of the light sources, the distance of the current light (if you want to take it into account here instead than during runtime light calculations) and so on. If no light source is visible from that pixel, the pixel is black. If all the lighs are visible, the pixel is white (or of the sum of the colors of the light sources).
-If you want to use area lights, you will need to shot more than one ray from each texel to achieve penumbras.
-Color lights and light distances could be computed at runtime, but then you will need to store one lightmap for each light that affect a given surface. You can reduce this by just using lightmaps for the sun, and using other methods for dynamic lights.
-If you want to take into account Global illumination effect (in particular, indirect illumination from near surfaces), you need more sofisticate algorithms, i.e. radiosity. This is what was done for quake 2 and half life 1 and 2 (with HL2 being my favourite use of this technique).
-Today the games tend to move toward fully dynamic lighting and shadowing. Consider this before starting with a non trivial task as writing a light mapper.

Anyway, I've seen many threads about this topic here on gamedev. Try using the search tool, you should get many of them.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!