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

UltraHDR lighting support #4578

Merged
merged 5 commits into from
Dec 8, 2023
Merged

UltraHDR lighting support #4578

merged 5 commits into from
Dec 8, 2023

Conversation

elalish
Copy link
Collaborator

@elalish elalish commented Nov 27, 2023

This is an exciting one! Custom lighting environments with 10-30x less file size, using UltraHDR (a backward-compatible, HDR version of JPEG) rather than .hdr. This is pulling in a dependency on https://github.com/MONOGRID/gainmap-js (thanks @daniele-pelagatti!), which is a very fast and lightweight decoder that leverages the browser's in-built JPEG decoding that ends up faster than the JS .hdr decoder we use now.

Monogrid has also helpfully made available a simple webpage that will do local conversion of .hdr to UltraHDR .jpg files. This brought Spruit Sunrise down from 1.5MB to 122KB - and the compression is even more impressive with grayscale studio lighting. We're only going to support the single-file .jpg approach for now - separate WebP files gives a bit of additional compression, but it seems too inconvenient to our users.

We put an upstream fix into three.js to make this work better, so I'll wait to merge this until we've updated to the next release.

(resolve, reject) => this.imageLoader.load(url, (result) => {
const {texture} = result.renderTarget;
result.dispose(false);
resolve(texture)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the fixes @daniele-pelagatti! All seems to be working now. One thing I was curious about: if I change this to result.dispose(true), my textures go black. However as it is, I believe I lose my handle to the renderTarget and can therefore never dispose of it. Not sure that's a huge deal, but I'd like to know what your recommended pattern is here?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

result.dispose(true) calls renderTarget.dispose() too and can be used when , for example, you do

const result = await loader.loadAsync('something.jpeg')

// once pmremgenerator has generated its own texture, result.renderTargetis not used anymore
pmremgenerator.fromEquirectangular(result.renderTarget.texture)
// or
texture.map = result.toDataTexture()
// or
myfile.serialize(result.toDataTexture())
result.dispose(true) // <-----

in other words, if you are going to use result.renderTarget.texture in any significant way in the future, don't call result.dispose(true), just call it with false or no params

@elalish elalish merged commit 99fa9a8 into master Dec 8, 2023
6 checks passed
@elalish elalish deleted the ultraHDR branch December 8, 2023 02:05
@elalish elalish mentioned this pull request Jan 11, 2024
JL-Vidinoti pushed a commit to vidinoti/model-viewer that referenced this pull request Apr 22, 2024
* UltraHDR working

* update an HDR environment

* add dispose

* fixed texture name bug
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.

2 participants