From ad0ff80ce559e87a2921d1b1b6761f2954c0fe59 Mon Sep 17 00:00:00 2001 From: Honigstein Samuel Date: Wed, 4 Dec 2024 07:07:50 +0100 Subject: [PATCH 1/2] LineSegments2: Fix `raycast()` . (#30016) * updated linesegments2 webgpu * Update LineSegments2.js FIx codescan issue. * use of vec4 to transfer viewport to this.resolution --------- Co-authored-by: Michael Herzog Co-authored-by: Renaud Rohlinger --- examples/jsm/lines/webgpu/LineSegments2.js | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/examples/jsm/lines/webgpu/LineSegments2.js b/examples/jsm/lines/webgpu/LineSegments2.js index 73eab628ddf422..da9fe4dd4acc08 100644 --- a/examples/jsm/lines/webgpu/LineSegments2.js +++ b/examples/jsm/lines/webgpu/LineSegments2.js @@ -9,9 +9,9 @@ import { Sphere, Vector3, Vector4, - Line2NodeMaterial + Line2NodeMaterial, + Vector2 } from 'three/webgpu'; - import { LineSegmentsGeometry } from '../../lines/LineSegmentsGeometry.js'; const _start = new Vector3(); @@ -29,6 +29,7 @@ const _closestPoint = new Vector3(); const _box = new Box3(); const _sphere = new Sphere(); const _clipToWorldVector = new Vector4(); +const _viewport = new Vector4(); let _ray, _lineWidth; @@ -93,8 +94,7 @@ function raycastWorldUnits( lineSegments, intersects ) { function raycastScreenSpace( lineSegments, camera, intersects ) { const projectionMatrix = camera.projectionMatrix; - const material = lineSegments.material; - const resolution = material.resolution; + const resolution = lineSegments.resolution; const matrixWorld = lineSegments.matrixWorld; const geometry = lineSegments.geometry; @@ -233,6 +233,8 @@ class LineSegments2 extends Mesh { this.type = 'LineSegments2'; + this.resolution = new Vector2(); + } // for backwards-compatibility, but could be a method of LineSegmentsGeometry... @@ -264,6 +266,13 @@ class LineSegments2 extends Mesh { } + onBeforeRender( renderer ) { + + renderer.getViewport( _viewport ); + this.resolution.set( _viewport.z, _viewport.w ); + + } + raycast( raycaster, intersects ) { const worldUnits = this.material.worldUnits; @@ -303,7 +312,7 @@ class LineSegments2 extends Mesh { } else { const distanceToSphere = Math.max( camera.near, _sphere.distanceToPoint( _ray.origin ) ); - sphereMargin = getWorldSpaceHalfWidth( camera, distanceToSphere, material.resolution ); + sphereMargin = getWorldSpaceHalfWidth( camera, distanceToSphere, this.resolution ); } @@ -333,7 +342,7 @@ class LineSegments2 extends Mesh { } else { const distanceToBox = Math.max( camera.near, _box.distanceToPoint( _ray.origin ) ); - boxMargin = getWorldSpaceHalfWidth( camera, distanceToBox, material.resolution ); + boxMargin = getWorldSpaceHalfWidth( camera, distanceToBox, this.resolution ); } From 3df50b769f0a8a9874dbc3b9d1176a9156a82fac Mon Sep 17 00:00:00 2001 From: Renaud Rohlinger Date: Wed, 4 Dec 2024 15:55:39 +0900 Subject: [PATCH 2/2] WebGPUBackend: Revert onSubmittedWorkDone usage in timestamp queries (#30031) --- src/renderers/webgpu/WebGPUBackend.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/renderers/webgpu/WebGPUBackend.js b/src/renderers/webgpu/WebGPUBackend.js index b35cbd7eefd315..211ade93c36aea 100644 --- a/src/renderers/webgpu/WebGPUBackend.js +++ b/src/renderers/webgpu/WebGPUBackend.js @@ -1243,8 +1243,6 @@ class WebGPUBackend extends Backend { const { resultBuffer } = renderContextData.currentTimestampQueryBuffers; - await this.device.queue.onSubmittedWorkDone(); - if ( resultBuffer.mapState === 'unmapped' ) { resultBuffer.mapAsync( GPUMapMode.READ ).then( () => {