Skip to content
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

WebGPURenderer: PMREMGenerator - calculate blur weights and parameters once #29900

Open
wants to merge 7 commits into
base: dev
Choose a base branch
from

Conversation

aardgoose
Copy link
Contributor

Address TODO and uses userData() instead of material uniforms for per pass constants.

Copy link

github-actions bot commented Nov 15, 2024

📦 Bundle size

Full ESM build, minified and gzipped.

Before After Diff
WebGL 339.4
79.05
339.4
79.05
+0 B
+0 B
WebGPU 486.51
134.96
486.95
135.05
+434 B
+87 B
WebGPU Nodes 485.98
134.87
486.42
134.95
+434 B
+83 B

🌳 Bundle size after tree-shaking

Minimal build including a renderer, camera, empty scene, and dependencies.

Before After Diff
WebGL 465.3
112.11
465.3
112.11
+0 B
+0 B
WebGPU 555.65
150.41
556.34
150.58
+685 B
+174 B
WebGPU Nodes 511.54
140.14
512.23
140.31
+685 B
+176 B

@sunag sunag added this to the r171 milestone Nov 16, 2024
@mrdoob
Copy link
Owner

mrdoob commented Nov 20, 2024

/ping @elalish

@elalish
Copy link
Contributor

elalish commented Nov 20, 2024

I guess it's fine if it creates the same pixels. I didn't write that TODO, so I'm not sure what this refactor is for. I generally hope for a refactor to result in less code rather than more. If other folks think this is more clear, then go for it.

@aardgoose
Copy link
Contributor Author

One advantage is with dynamic PMREM generation, the weights array is created and weights recalculated every frame, this removes these repeated operations and some others.

Eg webgpu_cubemap_dynamic example.

@mrdoob mrdoob modified the milestones: r171, r172 Nov 29, 2024
@elalish
Copy link
Contributor

elalish commented Dec 18, 2024

@sunag @Mugen87 are either of you going to review / merge this PR? I don't know enough about the coding style you're moving towards to give any useful feedback here (is userData a normal place for state to live now?). However, this seems useful and I'd also like to do some refactoring of PMREM, so it would be great if this was either merged or rejected so I can avoid a bunch of conflicts.

const blurUniforms = blurMaterial.uniforms;
const { _lodMax } = this;

const sigmaRadians = Math.sqrt( this._sigmas[ lodOut ] * this._sigmas[ lodOut ] - this._sigmas[ lodOut - 1 ] * this._sigmas[ lodOut - 1 ] );
Copy link
Contributor

@elalish elalish Dec 18, 2024

Choose a reason for hiding this comment

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

Hmm - is this right? The cache is based on lodIn, but the sigmas we're saving are based on lodOut. Sometimes they are the same and sometimes they are not, based on how halfblur is called. And does this all continue to work when a PMREM is generated with a different size?

Mugen87
Mugen87 previously approved these changes Dec 19, 2024
@Mugen87 Mugen87 modified the milestones: r172, r173 Dec 19, 2024
@elalish
Copy link
Contributor

elalish commented Dec 19, 2024

Okay, I understand this PR now, as well as a couple of minor issues - if you don't mind I'm going to incorporate this with some modifications into my own refactor: #30165.

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.

5 participants