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

Examples: Add GPU Progressive Lightmapping Example #21435

Merged
merged 37 commits into from
Mar 12, 2021

Conversation

zalo
Copy link
Contributor

@zalo zalo commented Mar 9, 2021

Related issue: Fixed #14048

Description

This PR adds a light-weight example for generating silky smooth, physically-correct lightmaps over time by jittering directional lights + shadows (1st bounce only).

The lightmapping accumulation step for this scene takes between 0.2ms and 0.4ms per frame on my machine (GTX 1080).

While the setup currently generates physically accurate soft shadows and ambient occlusion, the technique could generalize to multibounce global illumination/radiosity with the right kind of depth-peeling "light sources".

Check out the live deployment here:
https://zalo.github.io/three.js/examples/?q=shadowmap#webgl_shadowmap_progressive

image

The potpack module is a (very) small utility for packing multiple mesh's UVs into a unified texture atlas for the lightmap.

@Mugen87
Copy link
Collaborator

Mugen87 commented Mar 9, 2021

examples/models/obj/ShadowmappableMesh.obj

Do you mind using a glb file instead?

@Mugen87
Copy link
Collaborator

Mugen87 commented Mar 9, 2021

The E2E test for webgl_shadowmap_progressive is still failing. Maybe you have to regenerate the screenshot.

For testing: https://raw.githack.com/zalo/three.js/progressive-lightmapping/examples/webgl_shadowmap_progressive.html

@mrdoob mrdoob added this to the r127 milestone Mar 9, 2021
@zalo
Copy link
Contributor Author

zalo commented Mar 10, 2021

Happy to add additional stylization, tests, API changes, or aspects to the scene (if desired).

Also happy to see the retweet 😁
https://twitter.com/threejs_org/status/1369421471643271172

Mugen87
Mugen87 previously approved these changes Mar 10, 2021
@supereggbert
Copy link
Contributor

Just an FYI I'm not seeing anything on Samsung S10. I'm getting the following in the console "RENDER WARNING: texture bound to texture unit 0 is not renderable. It might be non-power-of-2 or have incompatible texture filtering (maybe)?"

@marcofugaro
Copy link
Contributor

@zalo does the ShadowmappableMesh.glb has to be created in any particular way from blender or it can be just a regular model?

@Mugen87
Copy link
Collaborator

Mugen87 commented Mar 10, 2021

I've realized there are two warnings in the console that should be removed before merging:

ProgressiveLightMap.js:232 Call this after adding the objects!

three.module.js:17076 THREE.WebGLProgram: gl.getProgramInfoLog() WARNING: Output of vertex shader 'vUv' not read by fragment shader

BTW: Can you please test whether the demo works with WebGL 1, too? You can create an instance of WebGL1Renderer to test this.

@zalo
Copy link
Contributor Author

zalo commented Mar 10, 2021

@supereggbert I think this was due to a WebGL1 compatibility breaking issue I just fixed in my latest commit. But just to be safe, I added Android to the list of userAgents that trigger Half precision floating point textures. The difference in quality is almost negligible, but there is more support for it on older phones.

@marcofugaro Technically the only requirement is that the object is UV mapped. However, you'll get oddly colored lines at the texture seams if two faces share an edge in the map (bilinear interpolation edge bleed), so adding some padding is ideal. I created this model with automatic UVs from my own program, so I'm not sure if Blender has any special needs...

@Mugen87 Thank you for the suggestion to force a WebGL1 Renderer! I'd been using texture instead of texture2D 🙃
Correcting this fixes support on iOS (though, I don't have any Android phones to test with). I also fixed the warnings you reported.

@supereggbert
Copy link
Contributor

(though, I don't have any Android phones to test with)

Working here now

@zalo
Copy link
Contributor Author

zalo commented Mar 12, 2021

Slightly off-topic: I'm testing out radiosity using Approximate Radiosity by Stochastic Depth Buffering (which is technically the multi-bounce extension of this PR's technique (that also doesn't require depth peeling)).

Early results are here:
https://raw.githack.com/zalo/three.js/progressive-radiosity/examples/?q=progress#webgl_shadowmap_progressive

It's not really appropriate for this PR or class. It's like triple the complexity+compute, converges way more slowly, and it works best with emissive meshes rather than directional lights... all for dubious additional visual quality. That said, I thought you guys might enjoy it. :-)

@mrdoob
Copy link
Owner

mrdoob commented Mar 12, 2021

That said, I thought you guys might enjoy it. :-)

Yes! 😍

@mrdoob mrdoob merged commit 71332b0 into mrdoob:dev Mar 12, 2021
@mrdoob
Copy link
Owner

mrdoob commented Mar 12, 2021

Thanks!

@zalo zalo deleted the progressive-lightmapping branch March 13, 2021 00:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Soft Shadows via Light Source Sampling
5 participants