|
@@ -69,6 +69,8 @@ const _axisDirections = [
|
|
|
/*@__PURE__*/ new Vector3( 1, 1, 1 )
|
|
/*@__PURE__*/ new Vector3( 1, 1, 1 )
|
|
|
];
|
|
];
|
|
|
|
|
|
|
|
|
|
+const _origin = /*@__PURE__*/ new Vector3();
|
|
|
|
|
+
|
|
|
// maps blur materials to their uniforms dictionary
|
|
// maps blur materials to their uniforms dictionary
|
|
|
|
|
|
|
|
const _uniformsMap = new WeakMap();
|
|
const _uniformsMap = new WeakMap();
|
|
@@ -93,8 +95,8 @@ const _outputDirection = /*@__PURE__*/ vec3( _direction.x, _direction.y, _direct
|
|
|
* higher roughness levels. In this way we maintain resolution to smoothly
|
|
* higher roughness levels. In this way we maintain resolution to smoothly
|
|
|
* interpolate diffuse lighting while limiting sampling computation.
|
|
* interpolate diffuse lighting while limiting sampling computation.
|
|
|
*
|
|
*
|
|
|
- * Paper: Fast, Accurate Image-Based Lighting
|
|
|
|
|
- * https://drive.google.com/file/d/15y8r_UpKlU9SvV4ILb0C3qCPecS8pvLz/view
|
|
|
|
|
|
|
+ * Paper: Fast, Accurate Image-Based Lighting:
|
|
|
|
|
+ * {@link https://drive.google.com/file/d/15y8r_UpKlU9SvV4ILb0C3qCPecS8pvLz/view}
|
|
|
*/
|
|
*/
|
|
|
|
|
|
|
|
class PMREMGenerator {
|
|
class PMREMGenerator {
|
|
@@ -128,20 +130,28 @@ class PMREMGenerator {
|
|
|
* Generates a PMREM from a supplied Scene, which can be faster than using an
|
|
* 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
|
|
* 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
|
|
* 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.
|
|
|
*
|
|
*
|
|
|
* @param {Scene} scene - The scene to be captured.
|
|
* @param {Scene} scene - The scene to be captured.
|
|
|
* @param {number} [sigma=0] - The blur radius in radians.
|
|
* @param {number} [sigma=0] - The blur radius in radians.
|
|
|
* @param {number} [near=0.1] - The near plane distance.
|
|
* @param {number} [near=0.1] - The near plane distance.
|
|
|
* @param {number} [far=100] - The far plane distance.
|
|
* @param {number} [far=100] - The far plane distance.
|
|
|
- * @param {?RenderTarget} [renderTarget=null] - The render target to use.
|
|
|
|
|
|
|
+ * @param {Object} [options={}] - The configuration options.
|
|
|
|
|
+ * @param {number} [options.size=256] - The texture size of the PMREM.
|
|
|
|
|
+ * @param {Vector3} [options.renderTarget=origin] - The position of the internal cube camera that renders the scene.
|
|
|
|
|
+ * @param {?RenderTarget} [options.renderTarget=null] - The render target to use.
|
|
|
* @return {RenderTarget} The resulting PMREM.
|
|
* @return {RenderTarget} The resulting PMREM.
|
|
|
* @see fromSceneAsync
|
|
* @see fromSceneAsync
|
|
|
*/
|
|
*/
|
|
|
- fromScene( scene, sigma = 0, near = 0.1, far = 100, renderTarget = null ) {
|
|
|
|
|
|
|
+ fromScene( scene, sigma = 0, near = 0.1, far = 100, options = {} ) {
|
|
|
|
|
+
|
|
|
|
|
+ const {
|
|
|
|
|
+ size = 256,
|
|
|
|
|
+ position = _origin,
|
|
|
|
|
+ renderTarget = null,
|
|
|
|
|
+ } = options;
|
|
|
|
|
|
|
|
- this._setSize( 256 );
|
|
|
|
|
|
|
+ this._setSize( size );
|
|
|
|
|
|
|
|
if ( this._hasInitialized === false ) {
|
|
if ( this._hasInitialized === false ) {
|
|
|
|
|
|
|
@@ -149,7 +159,9 @@ class PMREMGenerator {
|
|
|
|
|
|
|
|
const cubeUVRenderTarget = renderTarget || this._allocateTargets();
|
|
const cubeUVRenderTarget = renderTarget || this._allocateTargets();
|
|
|
|
|
|
|
|
- this.fromSceneAsync( scene, sigma, near, far, cubeUVRenderTarget );
|
|
|
|
|
|
|
+ options.renderTarget = cubeUVRenderTarget;
|
|
|
|
|
+
|
|
|
|
|
+ this.fromSceneAsync( scene, sigma, near, far, options );
|
|
|
|
|
|
|
|
return cubeUVRenderTarget;
|
|
return cubeUVRenderTarget;
|
|
|
|
|
|
|
@@ -162,7 +174,7 @@ class PMREMGenerator {
|
|
|
const cubeUVRenderTarget = renderTarget || this._allocateTargets();
|
|
const cubeUVRenderTarget = renderTarget || this._allocateTargets();
|
|
|
cubeUVRenderTarget.depthBuffer = true;
|
|
cubeUVRenderTarget.depthBuffer = true;
|
|
|
|
|
|
|
|
- this._sceneToCubeUV( scene, near, far, cubeUVRenderTarget );
|
|
|
|
|
|
|
+ this._sceneToCubeUV( scene, near, far, cubeUVRenderTarget, position );
|
|
|
|
|
|
|
|
if ( sigma > 0 ) {
|
|
if ( sigma > 0 ) {
|
|
|
|
|
|
|
@@ -189,15 +201,18 @@ class PMREMGenerator {
|
|
|
* @param {number} [sigma=0] - The blur radius in radians.
|
|
* @param {number} [sigma=0] - The blur radius in radians.
|
|
|
* @param {number} [near=0.1] - The near plane distance.
|
|
* @param {number} [near=0.1] - The near plane distance.
|
|
|
* @param {number} [far=100] - The far plane distance.
|
|
* @param {number} [far=100] - The far plane distance.
|
|
|
- * @param {?RenderTarget} [renderTarget=null] - The render target to use.
|
|
|
|
|
- * @return {Promise<RenderTarget>} The resulting PMREM.
|
|
|
|
|
|
|
+ * @param {Object} [options={}] - The configuration options.
|
|
|
|
|
+ * @param {number} [options.size=256] - The texture size of the PMREM.
|
|
|
|
|
+ * @param {Vector3} [options.renderTarget=origin] - The position of the internal cube camera that renders the scene.
|
|
|
|
|
+ * @param {?RenderTarget} [options.renderTarget=null] - The render target to use.
|
|
|
|
|
+ * @return {Promise<RenderTarget>} A Promise that resolve with the PMREM when the generation has been finished.
|
|
|
* @see fromScene
|
|
* @see fromScene
|
|
|
*/
|
|
*/
|
|
|
- async fromSceneAsync( scene, sigma = 0, near = 0.1, far = 100, renderTarget = null ) {
|
|
|
|
|
|
|
+ async fromSceneAsync( scene, sigma = 0, near = 0.1, far = 100, options = {} ) {
|
|
|
|
|
|
|
|
if ( this._hasInitialized === false ) await this._renderer.init();
|
|
if ( this._hasInitialized === false ) await this._renderer.init();
|
|
|
|
|
|
|
|
- return this.fromScene( scene, sigma, near, far, renderTarget );
|
|
|
|
|
|
|
+ return this.fromScene( scene, sigma, near, far, options );
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -458,7 +473,7 @@ class PMREMGenerator {
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- _sceneToCubeUV( scene, near, far, cubeUVRenderTarget ) {
|
|
|
|
|
|
|
+ _sceneToCubeUV( scene, near, far, cubeUVRenderTarget, position ) {
|
|
|
|
|
|
|
|
const cubeCamera = _cubeCamera;
|
|
const cubeCamera = _cubeCamera;
|
|
|
cubeCamera.near = near;
|
|
cubeCamera.near = near;
|
|
@@ -528,17 +543,22 @@ class PMREMGenerator {
|
|
|
if ( col === 0 ) {
|
|
if ( col === 0 ) {
|
|
|
|
|
|
|
|
cubeCamera.up.set( 0, upSign[ i ], 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 ) {
|
|
} else if ( col === 1 ) {
|
|
|
|
|
|
|
|
cubeCamera.up.set( 0, 0, upSign[ i ] );
|
|
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 {
|
|
} else {
|
|
|
|
|
|
|
|
cubeCamera.up.set( 0, upSign[ i ], 0 );
|
|
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 ] );
|
|
|
|
|
+
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|