three.js icon indicating copy to clipboard operation
three.js copied to clipboard

first pass at occlusion in gpurenderer

Open cabanier opened this issue 7 months ago • 8 comments

This implements per pixel occlusion by updating the shader of each renderer object.

@sunag , even though I apply the masknode to each element in the scene, it seems to apply only to some of the elements in the scene. If I recreate the material with masknode (instead of just assigning the node), it seems to work.

Am I doing something wrong?

cabanier avatar May 30 '25 21:05 cabanier

@mrdoob instead of copying the depth like we did previously, we now depth text for each render pixel. I'm hoping to use the view/projection matrices in effect of the capture of the depth texture for better occlusion alignment. I have not figured out how to do that yet :-)

cabanier avatar May 30 '25 21:05 cabanier

📦 Bundle size

Full ESM build, minified and gzipped.

Before After Diff
WebGL 337.4
78.67
337.4
78.67
+0 B
+0 B
WebGPU 553.64
153.44
555.1
153.85
+1.46 kB
+411 B
WebGPU Nodes 552.99
153.28
554.45
153.69
+1.46 kB
+411 B

🌳 Bundle size after tree-shaking

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

Before After Diff
WebGL 468.59
113.32
468.59
113.32
+0 B
+0 B
WebGPU 628.59
170.16
630.03
170.55
+1.44 kB
+396 B
WebGPU Nodes 583.45
159.5
584.88
159.9
+1.44 kB
+397 B

github-actions[bot] avatar May 30 '25 21:05 github-actions[bot]

@sunag @Mugen87 Any idea why applying the masknode to each material only works for some objects?

cabanier avatar Jun 02 '25 15:06 cabanier

I'm working on a NodeHandler to handle this with this kind of replacement, I think renderer.applyOcclusion() should be replaced with something more targeted at replacement at render time.

sunag avatar Jun 02 '25 15:06 sunag

I'm working on a NodeHandler to handle this with this kind of replacement, I think renderer.applyOcclusion() should be replaced with something more targeted at replacement at render time.

How can I do that?

cabanier avatar Jun 02 '25 18:06 cabanier

How can I do that?

I'm developing this new feature.

Have you tried replacing for testes your code renderer.xr.applyOcclusion() with?

scene.traverse( ( object ) => {

	if ( object.material ) {

		object.material.maskNode = false;

	}

} );

It seems to disappear(apply) all objects.

sunag avatar Jun 04 '25 05:06 sunag

Have you tried replacing for testes your code renderer.xr.applyOcclusion() with?

scene.traverse( ( object ) => {

	if ( object.material ) {

		object.material.maskNode = false;

	}

} );

It seems to disappear(apply) all objects.

Isn't that expected? Or are you saying that the current code disappears all objects?

cabanier avatar Jun 04 '25 05:06 cabanier

Isn't that expected? Or are you saying that the current code disappears all objects?

Yes, works as expected, just answering the previous question about: masknode only works for some objects. The problem is probably related to something else.

sunag avatar Jun 04 '25 06:06 sunag

Isn't that expected? Or are you saying that the current code disappears all objects?

Yes, works as expected, just answering the previous question about: masknode only works for some objects. The problem is probably related to something else.

was this problem fixed or do I need to open an issue?

cabanier avatar Jun 25 '25 19:06 cabanier

this doesn't seem to be a problem with the maskNode input as tests have shown, but if it is we can fix it.

sunag avatar Jun 25 '25 23:06 sunag