Git Product home page Git Product logo

seamoptimizer's Introduction

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

seamoptimizer's People

Contributors

ands avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.