-
Notifications
You must be signed in to change notification settings - Fork 883
Implement HDR image support (fixes #65) and transitions to using scene.background
#323
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
Conversation
5c8aac7 to
52ecd4e
Compare
|
TIL IE doesn't have Array.prototype.find; repush test |
52ecd4e to
42160e0
Compare
|
|
42160e0 to
bbab0d8
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some general feedback/questions:
- Almost all of the first party code changes would not be required if Three.js r101 was available to us. Would it be better for us to wait for that release?
- No tests seem to hit the code path for a newly introduced 350 line third party library. Can we add at least one test that hits that code path?
src/features/environment.js
Outdated
| this[$scene].skysphere.material.needsUpdate = true; | ||
| this[$currentCubemap] = cubemap; | ||
| this[$scene].model.applyEnvironmentMap(cubemap); | ||
| // TODO #196 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's follow Google convention for TODO formatting: // TODO(#xxx): elevator summary of thing not done
src/features/environment.js
Outdated
| this[$setShadowLightColor](skysphereColor); | ||
| const parsedColor = new Color(color); | ||
|
|
||
| // TODO #196 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto
src/features/environment.js
Outdated
| this[$scene].skysphere.material.needsUpdate = true; | ||
| this[$setShadowLightColor](parsedColor); | ||
|
|
||
| // TODO can cache this per renderer and color |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this one have an issue?
src/features/environment.js
Outdated
| this[$currentCubemap] = cubemap; | ||
| this[$scene].model.applyEnvironmentMap(this[$currentCubemap]); | ||
| const envmap = textureUtils.generateDefaultEnvMap(); | ||
| this[$currentEnvMap] = envmap; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Formatting convention is a bit scattered here. Env and Environment are used interchangeably, and map is lowercased or capitalized depending on where you look. I would prefer Environment and capitalized Map.
src/features/environment.js
Outdated
| /** | ||
| * Work around for #196, can remove this function | ||
| * and set backgrounds on `scene.background` directly | ||
| * once upgraded to r100. Most of the logic from |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| model, | ||
| 'envmap-change', | ||
| e => textureMatchesMeta(e.value, {...meta, type: 'EnvironmentMap'})); | ||
| const waitForEnvmap = (model, meta) => |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Envmap => EnvironmentMap throughout
| } | ||
|
|
||
| // Checks that the skysphere is within the camera's far plane | ||
| function ensureSkysphereVisible(scene) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Testing and assertions reduced here. What changed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The positioning of the skysphere is in the hands of three now, and the environment feature tests cover whether or not it's visible, these tests here ensured the skybox was positioned and sized correctly
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
src/three-components/TextureUtils.js
Outdated
| * @return {Promise<THREE.Texture>} | ||
| */ | ||
| async load(url) { | ||
| const isHDR = /\.hdr$/.test(url); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's name this RegExp e.g., const HDR_FILE_RE = /\.hdr$/; and hoist it to the module scope.
src/three-components/TextureUtils.js
Outdated
| equirect.dispose(); | ||
|
|
||
| return {envmap, skybox}; | ||
| } catch (e) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
e => error
src/three-components/TextureUtils.js
Outdated
| envmap.dispose(); | ||
| } | ||
|
|
||
| console.error(e); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove and/or re-throw
|
HDR looks so good 🤩thanks for all your work to make this happen @jsantell |
6143437 to
deb62b1
Compare
|
Addressed all comments, I think -- let me know if I missed any!
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One minor question, but otherwise this looks awesome. Very exciting! 💖
| <template> | ||
| <model-viewer | ||
| id="toggle-image" | ||
| backgroud-color="#ff0077" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice catch 👍
| const cubemap = textureUtils.generateDefaultEnvMap(); | ||
| this[$currentCubemap] = cubemap; | ||
| this[$scene].model.applyEnvironmentMap(this[$currentCubemap]); | ||
| // TODO(#336): can cache this per renderer and color |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🍻 thanks for filing!
| textures.skybox.texture, {mapping: 'Cube', url: EQUI_URL})) | ||
| .to.be.ok; | ||
|
|
||
| // TODO (#215): Re-enable once PMREM is added |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
| url: null, | ||
| // 'Equirectangular', 'EnvironmentMap' | ||
| type: null, | ||
| // 'Equirectangular', 'Cube' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💯
| * @return {Promise<THREE.Texture>} | ||
| */ | ||
| async load(url) { | ||
| const isHDR = HDR_FILE_RE.test(url); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
src/three-components/TextureUtils.js
Outdated
| dispose() { | ||
| this.envMapGenerator.camera.renderTarget.dispose(); | ||
| this.envMapGenerator = null; | ||
| this.environmentMapGenerator.camera.renderTarget.dispose(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should EnvironmentMapGenerator have its own dispose method so that we don't have to dig this deeply into its implementation details here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, probably, this is a bit much
deb62b1 to
bbc0929
Compare
|
Excellent work 👍 LGTM |
scene.background for skybox (fixes #196).
bbc0929 to
a8d9ad0
Compare
Broken up form of #237 with only HDR support and initial work for using
scene.background, which greatly simplifies our skybox logic. The PR is big enough with enough test changes (and scene.background is necessary since we can't use two different mappings with the same texture), so PMREM can be in a follow up.There was an issue with using
scene.backgroundwith cube targets (mrdoob/three.js#15662) so the work around here is until we update to r101 with the change -- tracking the removal of this hack via #196.The HDR environments aren't terribly exciting without PMREM unfortunately, so this is pre-work for that, and to scope PMREM issues in its own branch.
Of note, below is an LDR env (top) and an HDR env; it appears the HDR map does not handle any roughness values at all without the PMREM, at least for the specular (the other lights appear to be more diffused as roughness increases). Not sure what's going on there, not what I'd expect three to do (and exactly the same area I was looking at for mrdoob/three.js#15644, so a problem for another day if this is unintended. Either way, this should be thought of as part 1 of 2, i.e. not ready to promote/highlight.