Skip to content

Conversation

@jsantell
Copy link
Contributor

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.background with 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.

screenshot from 2019-01-30 12-57-03

@jsantell
Copy link
Contributor Author

TIL IE doesn't have Array.prototype.find; repush test

@jsantell
Copy link
Contributor Author

Object doesn't support property or method 'findIndex' oh come on

Copy link
Contributor

@cdata cdata left a 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:

  1. 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?
  2. 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?

this[$scene].skysphere.material.needsUpdate = true;
this[$currentCubemap] = cubemap;
this[$scene].model.applyEnvironmentMap(cubemap);
// TODO #196
Copy link
Contributor

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

this[$setShadowLightColor](skysphereColor);
const parsedColor = new Color(color);

// TODO #196
Copy link
Contributor

Choose a reason for hiding this comment

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

Ditto

this[$scene].skysphere.material.needsUpdate = true;
this[$setShadowLightColor](parsedColor);

// TODO can cache this per renderer and color
Copy link
Contributor

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?

this[$currentCubemap] = cubemap;
this[$scene].model.applyEnvironmentMap(this[$currentCubemap]);
const envmap = textureUtils.generateDefaultEnvMap();
this[$currentEnvMap] = envmap;
Copy link
Contributor

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.

/**
* Work around for #196, can remove this function
* and set backgrounds on `scene.background` directly
* once upgraded to r100. Most of the logic from
Copy link
Contributor

Choose a reason for hiding this comment

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

I thought we upgraded to r100?

#312

Did you mean r101?

model,
'envmap-change',
e => textureMatchesMeta(e.value, {...meta, type: 'EnvironmentMap'}));
const waitForEnvmap = (model, meta) =>
Copy link
Contributor

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) {
Copy link
Contributor

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?

Copy link
Contributor Author

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

Copy link
Contributor

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$/.test(url);
Copy link
Contributor

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.

equirect.dispose();

return {envmap, skybox};
} catch (e) {
Copy link
Contributor

Choose a reason for hiding this comment

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

e => error

envmap.dispose();
}

console.error(e);
Copy link
Contributor

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

@cdata
Copy link
Contributor

cdata commented Jan 31, 2019

HDR looks so good 🤩thanks for all your work to make this happen @jsantell

@jsantell jsantell force-pushed the scene-skybox branch 2 times, most recently from 6143437 to deb62b1 Compare February 1, 2019 23:27
@jsantell
Copy link
Contributor Author

jsantell commented Feb 1, 2019

Addressed all comments, I think -- let me know if I missed any!

  • Removed the hack now that r101 has landed
  • Updated TODO comments
  • Added tests that use HDR textures
  • consistently use camel case environmentMap throughout

cdata
cdata previously approved these changes Feb 1, 2019
Copy link
Contributor

@cdata cdata left a 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"
Copy link
Contributor

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
Copy link
Contributor

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
Copy link
Contributor

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'
Copy link
Contributor

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);
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

dispose() {
this.envMapGenerator.camera.renderTarget.dispose();
this.envMapGenerator = null;
this.environmentMapGenerator.camera.renderTarget.dispose();
Copy link
Contributor

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?

Copy link
Contributor Author

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

@cdata
Copy link
Contributor

cdata commented Feb 4, 2019

Excellent work 👍 LGTM

cdata
cdata previously approved these changes Feb 4, 2019
mrdoob
mrdoob previously approved these changes Feb 4, 2019
@jsantell jsantell dismissed stale reviews from mrdoob and cdata via a8d9ad0 February 5, 2019 01:05
@jsantell jsantell requested a review from cdata February 5, 2019 01:06
@jsantell jsantell merged commit 01e0de9 into master Feb 5, 2019
@jsantell jsantell deleted the scene-skybox branch February 5, 2019 01:28
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.

4 participants