Skip to content

Blur mip#750

Merged
cdata merged 23 commits intomasterfrom
blurMip
Oct 8, 2019
Merged

Blur mip#750
cdata merged 23 commits intomasterfrom
blurMip

Conversation

@elalish
Copy link
Contributor

@elalish elalish commented Sep 12, 2019

Fixes #724

Well, I doubt this will completely fix #724, but we'll see. Mostly this is a refactor to improve and speed up PMREM. I condensed five shaders into one, which reduces our compile time significantly (a major contributor to first-environment startup time). I also reduced the number of draw calls by a factor of 3, which significantly reduced the time to run environment generation (a major contributor to next-environment startup time). This has the added benefit of anti-aliasing our skyboxes a bit, since I replaced three's EquirectangularToCubemap function.

@elalish elalish requested a review from cdata September 12, 2019 23:24
@elalish elalish self-assigned this Sep 12, 2019
@elalish
Copy link
Contributor Author

elalish commented Sep 12, 2019

@cdata I have a very strange problem I don't understand here. When I run check-fidelity, the environments are 90 degrees off (I'm looking at the ceiling). When I run them in the viewer directly, they're fine. Can you reproduce this behavior? I can't imagine what could cause it.

@cdata cdata added this to the v0.7.0 milestone Sep 17, 2019
@elalish
Copy link
Contributor Author

elalish commented Sep 18, 2019

@cdata @mrdoob I'm totally baffled here. Outside of puppeteer, all of the fidelity tests work great. Inside of puppeteer, my PMREM environments end up quite wrong, and it seems that the position attribute I'm passing into my RawShaderMaterial is getting stretched by a factor of 2. If I switch one line in my vertex shader to gl_Position = vec4( 0.5 * position - 0.5, 1.0 );, it ends up nearly correct (but only in puppeteer). Looking in the debugger everything appears to be as expected; the attributes all have the right values, the shaders are as expected. Does anyone have any ideas?

@elalish elalish mentioned this pull request Sep 19, 2019
@elalish
Copy link
Contributor Author

elalish commented Sep 20, 2019

@cdata @mrdoob I finally figured it out! It was a DPR issue. When running offscreen renders I had neglected to set the pixel ratio back to one, hence why it only affected macbooks and puppeteer. It didn't occur to me that there was a scaling factor that applied to render target dimensions but not viewport dimensions.

@mrdoob
Copy link
Collaborator

mrdoob commented Sep 23, 2019

@cdata @mrdoob I finally figured it out! It was a DPR issue. When running offscreen renders I had neglected to set the pixel ratio back to one, hence why it only affected macbooks and puppeteer.

That makes A LOT of sense. Nice detective work!

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.

Let's keep the changes simple for now. We'll want to bang on it a little before the release, but let's try to get it landed.

return material;
};

export const environmentScene = (): Scene => {
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 slightly re-write this as a class that inherits from Scene. The body of the function would instead become the body of the constructor.

new WebGLRenderTarget(3 * sizeMax, offsetY, params);
cubeUVRenderTarget.texture.name = 'PMREMCubeUVPacker.cubeUv';
cubeUVRenderTarget.texture.mapping = CubeUVReflectionMapping;
fromDefault(): WebGLRenderTarget {
Copy link
Contributor

Choose a reason for hiding this comment

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

Please document this method

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

uniforms.inputEncoding.value = encodings[cubeLods[i].texture.encoding];
}
};
fromScene(
Copy link
Contributor

Choose a reason for hiding this comment

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

Please document this method

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

class MipmapShader extends RawShaderMaterial {
constructor() {
super({
fromEquirectangular(equirectangular: Texture): WebGLRenderTarget {
Copy link
Contributor

Choose a reason for hiding this comment

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

I know this method already existed, but please add some docs!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

const samples = 1 + Math.floor(STANDARD_DEVIATIONS * sigmaPixels);

if (samples > MAX_SAMPLES) {
console.log(
Copy link
Contributor

Choose a reason for hiding this comment

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

console.warn seems more appropriate here. Also, it would probably be easier to read with string interpolation:

console.warn(`sigmaRadians, ${sigmaRadians}, is too large and will clip, as it requested ${samples} samples when the maximum is set to ${MAX_SAMPLES}`);

const $blur = Symbol('blur');
const $halfBlur = Symbol('halfBlur');

export class PMREMGenerator {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you move the docs related to this class so that they appear right above the class declaration?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

import ModelViewerElementBase from './model-viewer-base.js';
import {FocusVisiblePolyfillMixin} from './utilities/focus-visible.js';

// Uncomment these lines to export PMREM textures in Glitch:
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 requested a review from cdata September 30, 2019 19:18
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.

This is some crazy magic ✨🎩🐇✨

@cdata cdata merged commit 4f6bae8 into master Oct 8, 2019
@cdata cdata deleted the blurMip branch October 8, 2019 06:20
@mrdoob
Copy link
Collaborator

mrdoob commented Oct 8, 2019

Wow! Looking incredible!

Before:
http://model-viewer-tester.glitch.me/0.6.0.html
Screen Shot 2019-10-08 at 9 00 52 AM

After:
http://model-viewer-tester.glitch.me/
Screen Shot 2019-10-08 at 9 01 08 AM

@mrdoob
Copy link
Collaborator

mrdoob commented Oct 8, 2019

It's amazing how the handle of the boombox looks now 🤯

Before:
Screen Shot 2019-10-08 at 9 19 25 AM

After:
Screen Shot 2019-10-08 at 9 19 10 AM

@pushmatrix
Copy link
Contributor

The mip checker boarding seems to still be happening: Screen Shot 2019-10-08 at 8 31 25 AM

Screen Shot 2019-10-08 at 8 36 04 AM

See here:
https://shelled-turret.glitch.me/

@elalish
Copy link
Contributor Author

elalish commented Oct 8, 2019

@pushmatrix Indeed, this is only the first part of the fix. What I fixed here was the roughness mapping (wetness) and PMREM performance. Aliasing is next, stay tuned.

@pushmatrix
Copy link
Contributor

@elalish I can confirm things do look significantly less wet! :D

elalish added a commit to elalish/model-viewer that referenced this pull request Feb 4, 2020
* simplified PMREM layout

* refactored PMREMGenerator

* using new PMREM for input environments

* NewPMREM starting to work

* newPMREM working

* minMip 3->4

* fixed skybox aliasing

* don't blur over the poles

* environment generation working

* cleanup

* fixed tests

* more cleanup

* reverting exports

* fixed some blur math

* fixed IE bug

* removed forked three files

* fixed DPR issue

* addressing feedback

* updated goldens
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.

Textures are blurring when in the distance in 0.6.0

4 participants