Skip to content

Switch environment generation from HalfFloat to RGBE#670

Merged
elalish merged 26 commits intoremove_pmrem_flagfrom
gen_env
Jul 17, 2019
Merged

Switch environment generation from HalfFloat to RGBE#670
elalish merged 26 commits intoremove_pmrem_flagfrom
gen_env

Conversation

@elalish
Copy link
Contributor

@elalish elalish commented Jul 1, 2019

Fixes #574

Several major Samsung devices don't support halfFloat textures, causing our environment generation to fail. Switching to RGBE fixes this, but kills our current shader for blurring that environment, so I've created a new gaussianBlur filter for cubeMaps to replace it.

@elalish elalish requested a review from cdata July 1, 2019 18:17
@elalish elalish self-assigned this Jul 1, 2019
@elalish
Copy link
Contributor Author

elalish commented Jul 10, 2019

IE 11 says it can't compile a shader, but I can't get it to run on an interactive Sauce Labs session at all (seems to just hang).

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.

🤩 Love the Gaussian blur util

suite('TextureUtils', () => {
let textureUtils: TextureUtils;
let renderer: WebGLRenderer;
const renderer = new WebGLRenderer({canvas});
Copy link
Contributor

Choose a reason for hiding this comment

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

We should leave a note here, because WebGLRenderer is stateful and can lead to unexpected results in tests depending on the order they are run in down the road.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added.

const n = Math.ceil(
standardDeviations * standardDeviationRadians * cubeResolution * 2 /
Math.PI);
const norm = standardDeviations / ((n - 1) * Math.sqrt(2 * Math.PI));
Copy link
Contributor

Choose a reason for hiding this comment

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

`,
fragmentShader: [
'const float n = ' + n + '.0;',
'uniform float weights[' + n + '];',
Copy link
Contributor

Choose a reason for hiding this comment

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

A couple of comments...

JavaScript numbers have a toFixed method that would probably be appropriate here.

You can also interpolate values with the template string (the one that uses the ` character as its boundary) that follows. For example:

const myProgram = `
const float n = ${n.toFixed(1)};
uniform float weights[${n}];

// rest of the program follows ...
`;

Template strings are also multi-line friendly, so this will save you from the cumbersome and less legible .join('\n') on an array of strings.

}
}

gaussianBlur(
Copy link
Contributor

Choose a reason for hiding this comment

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

💎

this.environmentMapGenerator =
new EnvironmentMapGenerator(this.renderer);
environmentMap = this.environmentMapGenerator.generate();
this.gaussianBlur(environmentMap);
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

weights.push(norm * Math.exp(-x * x / 2));
}

const blurMaterial = new ShaderMaterial({
Copy link
Contributor

Choose a reason for hiding this comment

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

If we make the blurMaterial and blurCamera class members, we could probably re-use them and then dispose them when TextureUtils dispose is called.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually we can't reuse blurMaterial because if you call the function with a different standard deviation, you'll create a different shader. Likewise if you invoke it on a different size texture, you'll have to create a differently sized camera.

Copy link
Contributor

Choose a reason for hiding this comment

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

👍

@elalish elalish changed the base branch from reuse_renderer to cache_env July 11, 2019 16:51
@elalish elalish changed the base branch from cache_env to reuse_renderer July 11, 2019 16:54
@cdata cdata changed the base branch from reuse_renderer to remove_pmrem_flag July 12, 2019 15:32
@elalish
Copy link
Contributor Author

elalish commented Jul 17, 2019

merging this down to the big, combined PR.

@elalish elalish merged commit ae16f17 into remove_pmrem_flag Jul 17, 2019
@elalish elalish deleted the gen_env branch July 17, 2019 16:06
elalish added a commit that referenced this pull request Jul 22, 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)

* 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

* addressing feedback

* Remove accidental render target disposal
@mrdoob
Copy link
Collaborator

mrdoob commented Jul 24, 2019

Nice!! 👌👌

elalish added a commit that referenced this pull request Aug 6, 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

* removed android sauce test
elalish added 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 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 added a commit to elalish/model-viewer that referenced this pull request Feb 4, 2020
 
Remove experimental-pmrem flag (google#591)

* 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)

* 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

* addressing feedback

* Remove accidental render target disposal
elalish added a commit to elalish/model-viewer that referenced this pull request Feb 4, 2020
 
New PMREM (google#684)

* 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

* removed android sauce test
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.

3 participants