Skip to content

Commit

Permalink
WebGPUBackend: Fix Occlusion Query Logic (#30288)
Browse files Browse the repository at this point in the history
* fix

* Update WebGLBackend.js

* Update webgpu_occlusion.html

---------

Co-authored-by: sunag <[email protected]>
  • Loading branch information
ycw and sunag authored Jan 9, 2025
1 parent 055364a commit 95a994c
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 8 deletions.
7 changes: 1 addition & 6 deletions examples/webgpu_occlusion.html
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@
const plane = new THREE.Mesh( planeGeometry, new THREE.MeshPhongNodeMaterial( { color: 0x00ff00, side: THREE.DoubleSide } ) );
const sphere = new THREE.Mesh( sphereGeometry, new THREE.MeshPhongNodeMaterial( { color: 0xffff00 } ) );

const instanceUniform = nodeObject( new OcclusionNode( sphere, new THREE.Color( 0x00ff00 ), new THREE.Color( 0x0000ff ) ) );
const instanceUniform = nodeObject( new OcclusionNode( sphere, new THREE.Color( 0x0000ff ), new THREE.Color( 0x00ff00 ) ) );

plane.material.colorNode = instanceUniform;

Expand All @@ -107,11 +107,6 @@
renderer = new THREE.WebGPURenderer( { antialias: true } );
renderer.setPixelRatio( window.devicePixelRatio );
renderer.setSize( window.innerWidth, window.innerHeight );

// ensure shaders/pipelines are all complete before rendering

await renderer.compileAsync( scene, camera );

renderer.setAnimationLoop( render );
document.body.appendChild( renderer.domElement );

Expand Down
2 changes: 1 addition & 1 deletion src/renderers/webgl-fallback/WebGLBackend.js
Original file line number Diff line number Diff line change
Expand Up @@ -611,7 +611,7 @@ class WebGLBackend extends Backend {

if ( gl.getQueryParameter( query, gl.QUERY_RESULT_AVAILABLE ) ) {

if ( gl.getQueryParameter( query, gl.QUERY_RESULT ) > 0 ) occluded.add( currentOcclusionQueryObjects[ i ] );
if ( gl.getQueryParameter( query, gl.QUERY_RESULT ) === 0 ) occluded.add( currentOcclusionQueryObjects[ i ] );

currentOcclusionQueries[ i ] = null;
gl.deleteQuery( query );
Expand Down
2 changes: 1 addition & 1 deletion src/renderers/webgpu/WebGPUBackend.js
Original file line number Diff line number Diff line change
Expand Up @@ -787,7 +787,7 @@ class WebGPUBackend extends Backend {

for ( let i = 0; i < currentOcclusionQueryObjects.length; i ++ ) {

if ( results[ i ] !== BigInt( 0 ) ) {
if ( results[ i ] === BigInt( 0 ) ) {

occluded.add( currentOcclusionQueryObjects[ i ] );

Expand Down

0 comments on commit 95a994c

Please sign in to comment.