Skip to content

Blur skybox#695

Merged
elalish merged 53 commits intomasterfrom
blurSkyboxInterp
Aug 13, 2019
Merged

Blur skybox#695
elalish merged 53 commits intomasterfrom
blurSkyboxInterp

Conversation

@elalish
Copy link
Contributor

@elalish elalish commented Aug 6, 2019

Fixes #181
Fixes #528

This applies our cubemap Gaussian blur function to the skybox. In the process, it also converts an RGBE skybox to RGB so that it can be mipmapped and interpolated like an LDR skybox. I'm not 100% happy with the Gaussian blur function yet, as there is still a bit of aliasing, but I have an idea to improve it that we can look into as a follow-on.

Emmett Lalish and others added 30 commits May 31, 2019 14:18
* generated environment map now RGBM16

* switched RGBM16 to RGBE

* started gaussianBlur

* gaussianBlur compiles

* gaussian blur functional

* gaussianBlur properly parameterized

* target caching works

* removed extraneous cache, cleaned up generation

* Reuse renderer in tests

* switched cubeGenerators

* reuse renderer in TextureUtils-spec

* addressing feedback

* generated environment map now RGBM16

* switched RGBM16 to RGBE

* started gaussianBlur

* gaussianBlur compiles

* gaussian blur functional

* gaussianBlur properly parameterized

* switched cubeGenerators

* reuse renderer in TextureUtils-spec

* addressing feedback

* fixed IE11 shader bug
@elalish elalish requested a review from cdata August 6, 2019 18:29
@elalish elalish self-assigned this Aug 6, 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.

Looks good 👍 but some minor cleanup requested

licensed under <a href="https://hdrihaven.com/p/license.php">CC0</a>
(<a href="https://hdrihaven.com/hdri/?h=aircraft_workshop_01">source</a>)

## music_hall_01_4k.hdr
Copy link
Contributor

Choose a reason for hiding this comment

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

💯

Symbol('loadEnvironmentMapFromSkyboxUrl');
const $loadGeneratedEnvironmentMap = Symbol('loadGeneratedEnvironmentMap');

export interface TextureUtilsConfig {
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

const HDR_FILE_RE = /\.hdr$/;
const ldrLoader = new TextureLoader();
const hdrLoader = new RGBELoader();
const cubemapSize = 256;
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 capitalize this e.g, CUBEMAP_SIZE (and yeah, ldrLoader / hdrLoader break our convention here a little; they should probably be static class members or something but we can fix that later).

await Promise.all([environmentMapLoads, skyboxLoads]);

if (skybox != null) {
skybox = this.gaussianBlur(skybox, 0.004, GammaEncoding);
Copy link
Contributor

Choose a reason for hiding this comment

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

Doesn't this return a reference to a new, distinct render target? If so, who manages the lifecycle of this instance? When does it get disposed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sometimes it is the same renderTarget (if the input is jpg); if it is hdr then gaussianBlur disposes of the one you gave it and returns this new one in its place.

Copy link
Contributor

Choose a reason for hiding this comment

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

Doesn't that mean we're possibly disposing of the cached render target?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Let's fix this in a following PR to extend our usage of your cachingPolicy.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

To be clear, we're no longer disposing of the cached render target, but we are leaking backgrounds.

cubeTarget: WebGLRenderTargetCube,
standardDeviationRadians: number = 0.04) {
standardDeviationRadians: number = 0.04,
outputEncoding: TextureEncoding|null = null): WebGLRenderTargetCube {
Copy link
Contributor

Choose a reason for hiding this comment

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

If you just want this to be an optional third argument, you can express it as outputEncoding?: TextureEncoding. The "loose" equality conditionals are useful for this particular scenario only: checking if a value is undefined or null. So, the check further down the page will work as written.

this.renderer.toneMapping = toneMapping;
this.renderer.toneMappingExposure = toneMappingExposure;
this.renderer.gammaOutput = gammaOutput;
if (outputEncoding != null && outputEncoding === GammaEncoding &&
Copy link
Contributor

Choose a reason for hiding this comment

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

Strictly speaking, you probably don't need the first clause of this condition because outputEncoding === GammaEncoding will always be false for every non-number value.

vec4 inputTexelToLinear(vec4 value, int encoding){
if(encoding == 0){
uniform int inputEncoding;
uniform int outputEncoding;
Copy link
Contributor

Choose a reason for hiding this comment

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

💯

if (outputEncoding != null && outputEncoding === GammaEncoding &&
cubeTexture.encoding !== GammaEncoding) {
cubeTarget.dispose();
const outParams = {
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 call this blurTargetOptions or something like that

@elalish elalish requested a review from cdata August 13, 2019 16:42
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.

Looks great, let's ship it and fix the leaking backgrounds in a future change 👍

Also, we can do configurable blur as a follow-on feature e.g., #704

@elalish elalish merged commit 6eb788f into master Aug 13, 2019
@elalish elalish deleted the blurSkyboxInterp branch August 13, 2019 18:17
cdata pushed a commit that referenced this pull request Aug 13, 2019
* removed pmrem attribute

* removed pmrem attribute from non-code files

* default environment map now uses PMREM

* fixed tests

* using PMREM for all cases, fixing #565

* increasing sauce timeout to 3min

* target caching works

* removed extraneous cache, cleaned up generation

* added LDR and HDR environment tests

* updated goldens

* Reuse renderer in tests (#668)

* Refactor envmap / skybox generation

* default stage light to zero, removed hemisphere light (#674)

* added new PMREMGenerator

* modified MeshStandardShader to show it can work

* Switch environment generation from HalfFloat to RGBE (#670)

* generated environment map now RGBM16

* switched RGBM16 to RGBE

* started gaussianBlur

* gaussianBlur compiles

* gaussian blur functional

* gaussianBlur properly parameterized

* target caching works

* removed extraneous cache, cleaned up generation

* Reuse renderer in tests

* switched cubeGenerators

* reuse renderer in TextureUtils-spec

* addressing feedback

* generated environment map now RGBM16

* switched RGBM16 to RGBE

* started gaussianBlur

* gaussianBlur compiles

* gaussian blur functional

* gaussianBlur properly parameterized

* switched cubeGenerators

* reuse renderer in TextureUtils-spec

* addressing feedback

* fixed IE11 shader bug

* added envmap chunk

* updated three's shaders

* fixed shaders

* shaders compile

* fixed all WebGL errors

* PMREMGenerator now takes any encoding of input texture

* fixed several shader bugs

* fixed mipmap generation

* fixed maxLod

* PMREM mostly working

* recreate intermediate targets

* fixed mipmap level selection

* minor cleanup

* addressing feedback

* refactored PMREM

* cleanup

* dispose of temp materials

* removed envMap hack

* blurring skybox

* HDR skyboxes are now interpolated

* reduced skybox resolution to match input

* minor cleanup

* fixed skybox metadata

* reduced cubemapSize, cleanup

* updated all environments to 1k

* re-enable Android tests

* Revert "re-enable Android tests"

This reverts commit f743b26.

* addressing feedback

* Gaussian blur returns a new target
@cdata cdata added this to the v0.6.0 milestone Aug 13, 2019
@elalish elalish mentioned this pull request Aug 13, 2019
@mrdoob
Copy link
Collaborator

mrdoob commented Aug 13, 2019

Love the blurred skyboxes! 👌

I tried the feature in http://model-viewer-tester.glitch.me/ and I'm not sure the exposure works correctly for the background now.

Screen Shot 2019-08-13 at 4 35 40 PM

Is there something I should change in my test?

@cdata
Copy link
Contributor

cdata commented Aug 13, 2019 via email

@mrdoob
Copy link
Collaborator

mrdoob commented Aug 14, 2019

Yes, sorry, I did not know how to use a previous version of the element, just figured it out.

This is how it's supposed to look like:

Screen Shot 2019-08-13 at 5 03 16 PM

Basically, it looks like the blurred background loses the HDR information.

@cdata
Copy link
Contributor

cdata commented Aug 14, 2019

👍 great catch @mrdoob I filed #707 to investigate

@elalish
Copy link
Contributor Author

elalish commented Aug 14, 2019 via email

elalish added a commit to elalish/model-viewer that referenced this pull request Feb 4, 2020
 
Blur skybox (google#695)

* removed pmrem attribute

* removed pmrem attribute from non-code files

* default environment map now uses PMREM

* fixed tests

* using PMREM for all cases, fixing google#565

* increasing sauce timeout to 3min

* target caching works

* removed extraneous cache, cleaned up generation

* added LDR and HDR environment tests

* updated goldens

* Reuse renderer in tests (google#668)

* Refactor envmap / skybox generation

* default stage light to zero, removed hemisphere light (google#674)

* added new PMREMGenerator

* modified MeshStandardShader to show it can work

* Switch environment generation from HalfFloat to RGBE (google#670)

* generated environment map now RGBM16

* switched RGBM16 to RGBE

* started gaussianBlur

* gaussianBlur compiles

* gaussian blur functional

* gaussianBlur properly parameterized

* target caching works

* removed extraneous cache, cleaned up generation

* Reuse renderer in tests

* switched cubeGenerators

* reuse renderer in TextureUtils-spec

* addressing feedback

* generated environment map now RGBM16

* switched RGBM16 to RGBE

* started gaussianBlur

* gaussianBlur compiles

* gaussian blur functional

* gaussianBlur properly parameterized

* switched cubeGenerators

* reuse renderer in TextureUtils-spec

* addressing feedback

* fixed IE11 shader bug

* added envmap chunk

* updated three's shaders

* fixed shaders

* shaders compile

* fixed all WebGL errors

* PMREMGenerator now takes any encoding of input texture

* fixed several shader bugs

* fixed mipmap generation

* fixed maxLod

* PMREM mostly working

* recreate intermediate targets

* fixed mipmap level selection

* minor cleanup

* addressing feedback

* refactored PMREM

* cleanup

* dispose of temp materials

* removed envMap hack

* blurring skybox

* HDR skyboxes are now interpolated

* reduced skybox resolution to match input

* minor cleanup

* fixed skybox metadata

* reduced cubemapSize, cleanup

* updated all environments to 1k

* re-enable Android tests

* Revert "re-enable Android tests"

This reverts commit f743b26.

* addressing feedback

* Gaussian blur returns a new target
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.

HDR environment maps are not interpolated Ability to Blur out environment

3 participants