Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add utility class for generating AO Map #33

Open
gkjohnson opened this issue Mar 18, 2022 · 3 comments
Open

Add utility class for generating AO Map #33

gkjohnson opened this issue Mar 18, 2022 · 3 comments
Labels
help wanted Extra attention is needed
Milestone

Comments

@gkjohnson
Copy link
Owner

gkjohnson commented Mar 18, 2022

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:

Hubs-Foundation/Spoke@9701d64

TODO

  • Write uv generator and ao map generator utilities
  • AO map must be flooded between triangles to avoid seams
  • Update example to show mesh with unwrapped UVs and live generating ao map
  • Update example to show 2d projection of ao map
  • Update example to take target map resolution
@gkjohnson gkjohnson added the help wanted Extra attention is needed label Mar 18, 2022
@gkjohnson gkjohnson added this to the phase-x milestone Mar 18, 2022
@donmccurdy
Copy link

/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:

  • (A) 1 mesh - unwrap and pack

    • load 1 mesh, providing position and normal attributes
    • generate a new UV atlas
    • use xref vertex IDs to rewrite the original mesh since some vertices have been duplicated. Original mesh may have arbitrary other attributes not used in the atlasing process.
  • (B) N meshes - repack only

    • load N meshes that already have UVs, providing position, normal, and uv attributes
    • generate a shared atlas, packing all UVs into the same [0,1] coordinate space
    • use xref vertex IDs to rewrite all original meshes, as above

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: donmccurdy/glTF-Transform#534

@hybridherbst
Copy link
Contributor

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

  • C)
    • load N meshes that may or may not have UVs
    • generate UV2 if UV1 is overlapping or doesn't exist
    • atlas all UV2s into 1-M AO maps (depends on target texel count)
    • generate AO map(s) in UV2
    • write out meshes with new UV2 + AO, no need to repack existing textures

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

@gkjohnson
Copy link
Owner Author

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

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

3 participants