Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
L

lightmapper

> 编程语言
Open source

A C/C++ single-file library for drop-in lightmap baking. Just use your existing OpenGL renderer to bounce light!

1.5K stars0 likes0 views
WebsiteGitHub

About

A C/C++ single-file library for drop-in lightmap baking. Just use your existing OpenGL renderer to bounce light!

Lightmapper

lightmapper.h is a C/C++ single-file library for lightmap baking by using your existing OpenGL renderer.

To paste the implementation into your project, insert the following lines:

#define LIGHTMAPPER_IMPLEMENTATION
#include "lightmapper.h"

While the simple example application demonstrates the baking of ambient occlusion only, the library can also be used to precompute global illumination for static scene geometry by doing multiple bounces.

Any light shapes and emissive surfaces are supported as long as you draw them with their corresponding emissive light colors.

You may want to use thekla_atlas / xatlas or uvatlas to prepare your geometry for lightmapping.

Example application

The provided example application should build on Windows/Linux/MacOSX.

Linux dependencies for glfw: xorg-dev libgl1-mesa-dev

bash
git clone --recursive https://github.com/ands/lightmapper.git
cd lightmapper/example
cmake .
make
./example

Example usage

…

Quality improvement

To improve the lightmapping quality on closed meshes it is recommended to disable backface culling and to write (gl_FrontFacing ? 1.0 : 0.0) into the alpha channel during scene rendering to mark valid and invalid geometry (look at example.c for more details). The lightmapper will use this information to discard lightmap texel results with too many invalid samples. These texels can then be filled in by calls to lmImageDilate during postprocessing.

Selective hierarchical interpolation for speedup

The lightmapper can do several passes traversing the geometry to render to the lightmap. If interpolation passes are turned on, only every (1 << interpolationPasses) texel gets rendered in the first pass. Consecutive passes either render or interpolate the values in between based on the interpolationThreshold value. If the neighbours deviate too much or don't exist yet, the texel gets also rendered, otherwise it is simply interpolated between the neighbours. If interpolationPasses or interpolationThreshold are set too high, lighting variations can be missed. If they are very low, very many lightmap texels get rendered, which is very expensive compared to interpolating them. On the example above this technique gives about a ~3.3x speedup without degrading the quality. Larger lightmaps can even get a ~10x speedup depending on the scene. This image shows which texels get rendered (red) and which get interpolated (green) in the above example:

This technique is also described by Hugo Elias over here.

Example media

The following video shows several lighting effects. The static/stationary and indirect lighting were precomputed with lightmapper.h:

Thanks

  • To Ignacio Castaño and Jonathan Blow for blogging about their lightmapping system for The Witness.
  • To Hugo Elias who documented his radiosity light mapper and acceleration technique a long time ago.
  • To Sean Barrett for his library design philosophy.
  • To Nyamyam Ltd. for letting me use their engine and assets during my master's thesis for which I started my work on this library.
  • To Apoorva Joshi for trying to find a graphics driver performance anomaly.
  • To Teh_Bucket for this public domain gazebo model on OpenGameArt.org.
  • To everybody else that I forgot :)

Issues· 7 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

C

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category编程语言
PricingOpen source

> Related tools

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言