-
-
Notifications
You must be signed in to change notification settings - Fork 35.2k
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
I have changed the new PMREMGenerator and the associated PMREMNode #28334
Changes from all commits
9c6f24e
bc6b3ce
751bac8
86ccd08
7aa7b91
994b3e7
a51382e
dba7265
b008922
abd9aa4
f0ee877
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 ) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've tested this code locally and it changes the result of Making the size and origin of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, I have to take a closer look at that. The PMREMGenerator in the src differs in some parts from the one in the node system. |
||
|
||
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 ] ); | ||
|
||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Side note: Please avoid addressing multiple issues with a single PR.
We can leave it for now but in the future try to fix different issues in different PRs please. That makes them easier to review and merge.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I assumed that it had to be one PR because the changes in both files (PMREMGenerator and PMREMNode) belong together for it to work properly. Was the idea wrong?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Um, I don't understand. It seems the issue in the fiddle can be fixed without enhancing the API of
PMREMGenerator
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fiddle seems to offers more options than CodePen, so I'll look into that too. But I'm happy that it worked and that it can now be experienced live with the fiddle.
Thanks for doing that, Mugen
The one with the two issues: Of course thats already possible. If you just change the pmremNode without the sign correction in the x axis in the PMREMGenerator, then the x axis reflection is not correct and that is independent of the camera translation.
The camera translation has no influence at all and is therefore actually a different topic. The bottom line for me is that it's just important to get it done properly and if those are two issues I can live with that very well.
I'm happy that the PMREMGenerator has come and the pmremNode, as the WebGLCubeRenderTarget previously seemed simply out of place in WebGPU, even though it worked well.