• Stars
    star
    234
  • Rank 171,630 (Top 4 %)
  • Language
    C
  • Created almost 8 years ago
  • Updated almost 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A C/C++ single-file library that minimizes the hard transition errors of disjoint edges in lightmaps.

seamoptimizer

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:

#define SEAMOPTIMIZER_IMPLEMENTATION
#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,
	cosNormalThreshold,
	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");
}

printf("Done!\n");
so_seams_free(seams);

Thanks

  • 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

More Repositories

1

lightmapper

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

spherical_harmonics_playground

Simple application that loads an OBJ file and an environment map and calculates & displays the corresponding 3rd order spherical harmonics coefficients
C++
119
star
3

borderless-window-opengl

Demonstration of alpha blended compositing of OpenGL contexts via borderless windows using the Win32 API
C++
92
star
4

sproutline

A small single-file library for sprite outline extraction and simplification for C/C++
C
82
star
5

trianglepacker

A C/C++ single-file library that packs triangles of a 3D mesh into a rectangle/texture.
C
60
star
6

PonyBehaviourTrees

A set of C# libraries for runtime behaviour tree editing, scripting and inspection
C#
53
star
7

am_fft

am_fft.h - A single-header library for power-of-two sized 1D and 2D FFTs
C
22
star
8

GLGUI

A WinForms-like C# OpenGL User Interface library
C#
18
star
9

vga2scope

A Video/Camera image (over VGA) to oscilloscope X/Y mode streaming tool
C
18
star
10

libr3d

A small realtime software rendering library
C
14
star
11

OculusMeetsAR

A library that allows to use the Oculus Rift DK2, two Logitech C310 Webcams (with fisheye lenses) and the OptiTrack Flex 3 tracking system in AR applications.
C++
10
star
12

this_is_fine_tray

A small tray icon application with global hotkeys to speed up simple everyday tasks
C
8
star
13

EsaBusModule

C++
6
star
14

TiGRE

TiGRE (Tiny Game Rendering Engine) This is some old stuff for a university project
C++
4
star