diff --git a/examples/jsm/nodes/pmrem/PMREMNode.js b/examples/jsm/nodes/pmrem/PMREMNode.js index 1a189991423f6..ebc8de11a3542 100644 --- a/examples/jsm/nodes/pmrem/PMREMNode.js +++ b/examples/jsm/nodes/pmrem/PMREMNode.js @@ -5,7 +5,6 @@ import { textureCubeUV } from './PMREMUtils.js'; import { uniform } from '../core/UniformNode.js'; import { NodeUpdateType } from '../core/constants.js'; import { nodeProxy, vec3 } from '../shadernode/ShaderNode.js'; -import { WebGLCoordinateSystem } from 'three'; let _generator = null; @@ -162,7 +161,7 @@ class PMREMNode extends TempNode { const texture = this.value; - if ( builder.renderer.coordinateSystem === WebGLCoordinateSystem && texture.isPMREMTexture !== true && texture.isRenderTargetTexture === true ) { + if ( texture.isRenderTargetTexture === true ) { uvNode = vec3( uvNode.x.negate(), uvNode.yz ); diff --git a/examples/jsm/renderers/common/WebGPURenderTarget.js b/examples/jsm/renderers/common/WebGPURenderTarget.js new file mode 100644 index 0000000000000..786fd236ae695 --- /dev/null +++ b/examples/jsm/renderers/common/WebGPURenderTarget.js @@ -0,0 +1,74 @@ +import { RenderTarget } from 'three'; + + +class WebGPURenderTarget { + + constructor( width = 1, height = 1, options = {} ) { + + this.readBuffer = new RenderTarget( width, height, options ); + this.writeBuffer = new RenderTarget( width, height, options ); + + } + + swap() { + + [this.readBuffer, this.writeBuffer ] = [ this.writeBuffer, this.readBuffer ]; + + } + + get read() { + + return this.readBuffer; + } + + get write() { + + return this.writeBuffer; + } + + get texture() { + + return this.readBuffer.texture; + } + + setSize( width, height ) { + + this.readBuffer.setSize( width, height ); + this.writeBuffer.setSize( width, height ); + + } + + dispose() { + + this.readBuffer.dispose(); + this.writeBuffer.dispose(); + + } + + render( renderer, scene, camera ) { + + renderer.setRenderTarget( this.writeBuffer ); + renderer.render( scene, camera ); + renderer.setRenderTarget( null ); + + this.swap(); + + return this; + + } + + async renderAsync( renderer, scene, camera ) { + + renderer.setRenderTarget( this.writeBuffer ); + await renderer.renderAsync( scene, camera ); + renderer.setRenderTarget( null ); + + this.swap(); + + return this; + + } + +} + +export default WebGPURenderTarget; \ No newline at end of file diff --git a/examples/jsm/renderers/common/extras/PMREMGenerator.js b/examples/jsm/renderers/common/extras/PMREMGenerator.js index 38fecad21d1c4..e7e69a4461c37 100644 --- a/examples/jsm/renderers/common/extras/PMREMGenerator.js +++ b/examples/jsm/renderers/common/extras/PMREMGenerator.js @@ -119,21 +119,22 @@ class PMREMGenerator { * Generates a PMREM from a supplied Scene, which can be faster than using an * image if networking bandwidth is low. Optional sigma specifies a blur radius * in radians to be applied to the scene before PMREM generation. Optional near - * and far planes ensure the scene is rendered in its entirety (the cubeCamera - * is placed at the origin). + * and far planes ensure the scene is rendered in its entirety + * Optional size, the renderTarget default size is 256 + * Optional cubeCamera position, the cubeCamera default position is the origin */ - fromScene( scene, sigma = 0, near = 0.1, far = 100 ) { + fromScene( scene, sigma = 0, near = 0.1, far = 100, size = 256, position = new Vector3( 0, 0, 0 ) ) { _oldTarget = this._renderer.getRenderTarget(); _oldActiveCubeFace = this._renderer.getActiveCubeFace(); _oldActiveMipmapLevel = this._renderer.getActiveMipmapLevel(); - this._setSize( 256 ); + this._setSize( size ); const cubeUVRenderTarget = this._allocateTargets(); cubeUVRenderTarget.depthBuffer = true; - this._sceneToCubeUV( scene, near, far, cubeUVRenderTarget ); + this._sceneToCubeUV( scene, near, far, cubeUVRenderTarget, position ); if ( sigma > 0 ) { @@ -324,7 +325,7 @@ class PMREMGenerator { } - _sceneToCubeUV( scene, near, far, cubeUVRenderTarget ) { + _sceneToCubeUV( scene, near, far, cubeUVRenderTarget, position ) { const cubeCamera = _cubeCamera; cubeCamera.near = near; @@ -394,17 +395,20 @@ class PMREMGenerator { if ( col === 0 ) { cubeCamera.up.set( 0, upSign[ i ], 0 ); - cubeCamera.lookAt( forwardSign[ i ], 0, 0 ); + cubeCamera.position.set( position.x, position.y, position.z ); + cubeCamera.lookAt( position.x - forwardSign[ i ], position.y, position.z ); } else if ( col === 1 ) { cubeCamera.up.set( 0, 0, upSign[ i ] ); - cubeCamera.lookAt( 0, forwardSign[ i ], 0 ); + cubeCamera.position.set( position.x, position.y, position.z ); + cubeCamera.lookAt( position.x, position.y + forwardSign[ i ], position.z ); } else { cubeCamera.up.set( 0, upSign[ i ], 0 ); - cubeCamera.lookAt( 0, 0, forwardSign[ i ] ); + cubeCamera.position.set( position.x, position.y, position.z ); + cubeCamera.lookAt( position.x, position.y, position.z + forwardSign[ i ] ); } diff --git a/src/extras/PMREMGenerator.js b/src/extras/PMREMGenerator.js index c0429ed7ee581..167f7a092183e 100644 --- a/src/extras/PMREMGenerator.js +++ b/src/extras/PMREMGenerator.js @@ -100,10 +100,12 @@ class PMREMGenerator { * Generates a PMREM from a supplied Scene, which can be faster than using an * image if networking bandwidth is low. Optional sigma specifies a blur radius * in radians to be applied to the scene before PMREM generation. Optional near - * and far planes ensure the scene is rendered in its entirety (the cubeCamera + * and far planes ensure the scene is rendered in its entirety + * Optional size, the renderTarget default size is 256 + * Optional cubeCamera position, the cubeCamera default position is the origin * is placed at the origin). */ - fromScene( scene, sigma = 0, near = 0.1, far = 100 ) { + fromScene( scene, sigma = 0, near = 0.1, far = 100, size = 256, position = new Vector3( 0, 0, 0 ) ) { _oldTarget = this._renderer.getRenderTarget(); _oldActiveCubeFace = this._renderer.getActiveCubeFace(); @@ -112,12 +114,12 @@ class PMREMGenerator { this._renderer.xr.enabled = false; - this._setSize( 256 ); + this._setSize( size ); const cubeUVRenderTarget = this._allocateTargets(); cubeUVRenderTarget.depthBuffer = true; - this._sceneToCubeUV( scene, near, far, cubeUVRenderTarget ); + this._sceneToCubeUV( scene, near, far, cubeUVRenderTarget, position ); if ( sigma > 0 ) { @@ -306,7 +308,7 @@ class PMREMGenerator { } - _sceneToCubeUV( scene, near, far, cubeUVRenderTarget ) { + _sceneToCubeUV( scene, near, far, cubeUVRenderTarget, position ) { const fov = 90; const aspect = 1; @@ -358,17 +360,20 @@ class PMREMGenerator { if ( col === 0 ) { cubeCamera.up.set( 0, upSign[ i ], 0 ); - cubeCamera.lookAt( forwardSign[ i ], 0, 0 ); + cubeCamera.position.set( position.x, position.y, position.z ); + cubeCamera.lookAt( position.x - forwardSign[ i ], position.y, position.z ); } else if ( col === 1 ) { cubeCamera.up.set( 0, 0, upSign[ i ] ); - cubeCamera.lookAt( 0, forwardSign[ i ], 0 ); + cubeCamera.position.set( position.x, position.y, position.z ); + cubeCamera.lookAt( position.x, position.y + forwardSign[ i ], position.z ); } else { cubeCamera.up.set( 0, upSign[ i ], 0 ); - cubeCamera.lookAt( 0, 0, forwardSign[ i ] ); + cubeCamera.position.set( position.x, position.y, position.z ); + cubeCamera.lookAt( position.x, position.y, position.z + forwardSign[ i ] ); }