Skip to content
A C/C++ single-file library that minimizes the hard transition errors of disjoint edges in lightmaps.
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.
example_images a different set of images Feb 27, 2017 added comma Feb 27, 2017
seamoptimizer.h Fixed edge case from issue #1 Apr 30, 2019


A C/C++ single-file library that minimizes the hard transition errors of disjoint edges in lightmaps. It is based on a idea presented by Michał Iwanicki in the talk Lighting Technology of "The Last Of Us". A least squares solver is used to find a minimal error solution to the problem of sampling along the edges between triangles that are mapped with disjoint lightmap regions. This can improve the visual appearance at these discontinuities or "seams".

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

#include "seamoptimizer.h"

Before optimizing a very bad UV mapping (each triangle edge is a seam): Sean Optimizer Before After optimizing the seams of the bad UV mapping: Sean Optimizer After The seams are not all completely gone, but, especially on the walls, there is a very noticeable improvement.

Example Usage

The following example finds and optimizes all the seams for some mesh geometry on a lightmap.

// only optimize seams between triangles that are on the same plane
// (where dot(A.normal, B.normal) > cosNormalThreshold):
const float cosNormalThreshold = 0.99f;

// how "important" the original color values are:
const float lambda = 0.1f;

printf("Searching for separate seams...\n");
so_seam_t *seams = so_seams_find(
	(float*)mesh->positions, (float*)mesh->texcoords, mesh->vertexCount,
	lightmap->data, lightmap->width, lightmap->height, lightmap->channelCount);

printf("Optimizing seams...\n");
for (so_seam_t *seam = seams; seam; seam = so_seam_next(seam))
	// NOTE: seams can also be optimized in parallel on separate threads!
	if (!so_seam_optimize(seam, lightmap->data, lightmap->width, lightmap->height, lightmap->channelCount, lambda))
		printf("Could not optimize a seam (Cholesky decomposition failed).\n");



  • To Michał Iwanicki for helping me with the transformation of the problem into a problem that can be solved by a least-squares solver
  • To Dominik Lazarek for pointing me to Michał's presentation
You can’t perform that action at this time.