Giter Club home page Giter Club logo

threejs-lightmap-baker's Introduction

THIS REPO HAS MOVED

All development has moved to https://github.com/pmndrs/react-three-lightmap. Please see that package (published as @react-three/lightmap) for newer code and documentation.

Experimental Lightmap Baker for ThreeJS + react-three-fiber

test screenshot of lightmap generator

Quick and cheap global illumination lightmap baking in ThreeJS + react-three-fiber.

Live editable sandbox.

See screenshots and a brief description here: https://unframework.com/portfolio/simple-global-illumination-lightmap-baker-for-threejs/.

To try the experimental lightmap display locally, do this:

git clone [email protected]:unframework/threejs-lightmap-baker.git
cd threejs-lightmap-baker
yarn
yarn storybook

Internal Pipeline Overview

The developer defines a scene the same way they normally would, but adds IrradianceSurface and IrradianceLight markers under the meshes and lights that should be participating in the lighting process. The lightmap that is produced by the baker can then simply be attached to scene materials via the lightMap prop, as usual.

The following is a brief overview of the renderer architecture.

The data flows as follows:

mesh/light definition in scene (with surface marker)
  -> surface manager
      -> atlas mapper
          -> lightmap renderer
              -> lightmap compositor (dummy passthrough for now)
                  -> final lightmap
                      -> mesh material in scene

The surface manager has awareness of all the meshes/lights that affect the lightmap. Before baking can begin, there is an extra step: the atlas mapper has to produce a lookup texture that links every future lightmap texel with the 3D position on a mesh triangle that it corresponds to (based on uv2 information from meshes).

Once that lookup texture is built, baking (lightmap rendering) works in passes. It exposes the result texture at all times, so it is possible to see the lightmap being filled in, texel by texel.

Because there might be more than one lightmap factors (e.g. dynamic light intensity arrangements), there is a final compositor step that combines the output of multiple bakers (one per factor) into the final lightmap. The lightmap is passed down to the scene via React context so that it can be easily accessed inside sub-components, etc.

Baking is an intensive process and there could be multiple lightmaps being baked at once, which may overload the GPU. There is a top-level "work manager" that queues up and schedules work snippets from one or more lightmap bakers - a little bit of work is done per each frame, so that the overall app remains responsive and can render intermediate results.

threejs-lightmap-baker's People

Contributors

dependabot[bot] avatar unframework avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

threejs-lightmap-baker's Issues

Failed to compile

Just trying to see what you've built here, it looks really neat!

Not sure if I'm doing something wrong... I cloned and ran yarn install then yarn start:

image

I was able to get around above error by moving the asset to the public dir, but then there are further errors regarding useIrradianceRenderer not being found.

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.