gkjohnson / three-gpu-pathtracer

Path tracing renderer and utilities for three.js built on top of three-mesh-bvh.
https://gkjohnson.github.io/three-gpu-pathtracer/example/bundle/index.html
MIT License
1.37k stars 133 forks source link

Add utility class for generating AO Map #33

Open gkjohnson opened 2 years ago

gkjohnson commented 2 years ago

Related to #32. Something like the following:

const uvGenerator = new UVGenerator();
uvGenerator.attributeName = 'uv2';
uvGenerator.generate( targetMeshes );

const aoGenerator = new AOMapGenerator();
aoGenerator.samples = 1000;
aoGenerator.attributeName = 'uv2';

const targetMeshes = [ ... ];
const texture = await aoGenerator.generate( renderer, targetMeshes, aoBvh );

Untested UV unwrapping logic using xatlas is here:

https://github.com/gkjohnson/three-gpu-pathtracer/blob/main/src/utils/UVUnwrapper.js

Originally from this Mozilla Spoke commit:

https://github.com/mozilla/Spoke/commit/9701d647020e09d584885bd457eb225e9995c12f

TODO

donmccurdy commented 2 years ago

/cc @robertlong – Hi! Hope it's OK to ask a couple questions here. I'm wondering about using xatlas-web for this. I think we'd ideally need two workflows supported:

At a glance I'm having trouble seeing if these workflows are supported by xatlas itself, the xatlas-web bindings, or neither... is that something you happen to know?

Related: https://github.com/donmccurdy/glTF-Transform/issues/534

hybridherbst commented 2 years ago

A nice workflow would also be (kind of an extension of B):

This is generally what game engines (Unity/Unreal at least) do for lightmaps.

gkjohnson commented 2 years ago

@donmccurdy Looks like there's a new xatlas wrapper being developed -- maybe it alleviates some of your concerns?

https://twitter.com/repalash/status/1521165176086487040