Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/cameras/ArrayCamera.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,15 @@ class ArrayCamera extends PerspectiveCamera {
*/
this.isMultiViewCamera = false;

/**
* Whether to perform view-frustum culling during rendering
* on a per-camera basis, or to use the `ArrayCamera`'s own projection matrix.
*
* @type {boolean}
* @default true
*/
this.perCameraCulling = true;

/**
* An array of perspective sub cameras.
*
Expand Down
18 changes: 14 additions & 4 deletions src/renderers/WebGLRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
} from '../constants.js';
import { Color } from '../math/Color.js';
import { Frustum } from '../math/Frustum.js';
import { FrustumArray } from '../math/FrustumArray.js';
import { Matrix4 } from '../math/Matrix4.js';
import { Vector3 } from '../math/Vector3.js';
import { Vector4 } from '../math/Vector4.js';
Expand Down Expand Up @@ -305,6 +306,7 @@ class WebGLRenderer {
// frustum

const _frustum = new Frustum();
const _frustumArray = new FrustumArray();

// clipping

Expand Down Expand Up @@ -1555,8 +1557,12 @@ class WebGLRenderer {

renderStateStack.push( currentRenderState );

_projScreenMatrix.multiplyMatrices( camera.projectionMatrix, camera.matrixWorldInverse );
_frustum.setFromProjectionMatrix( _projScreenMatrix, WebGLCoordinateSystem, camera.reversedDepth );
if ( ! camera.perCameraCulling ) {

_projScreenMatrix.multiplyMatrices( camera.projectionMatrix, camera.matrixWorldInverse );
_frustum.setFromProjectionMatrix( _projScreenMatrix, WebGLCoordinateSystem, camera.reversedDepth );

}

_localClippingEnabled = this.localClippingEnabled;
_clippingEnabled = clipping.init( this.clippingPlanes, _localClippingEnabled );
Expand Down Expand Up @@ -1734,7 +1740,9 @@ class WebGLRenderer {

} else if ( object.isSprite ) {

if ( ! object.frustumCulled || _frustum.intersectsSprite( object ) ) {
const frustum = camera.perCameraCulling ? _frustumArray : _frustum;

if ( ! object.frustumCulled || frustum.intersectsSprite( object, camera ) ) {

if ( sortObjects ) {

Expand All @@ -1756,7 +1764,9 @@ class WebGLRenderer {

} else if ( object.isMesh || object.isLine || object.isPoints ) {

if ( ! object.frustumCulled || _frustum.intersectsObject( object ) ) {
const frustum = camera.perCameraCulling ? _frustumArray : _frustum;

if ( ! object.frustumCulled || frustum.intersectsObject( object, camera ) ) {

const geometry = objects.update( object );
const material = object.material;
Expand Down
10 changes: 4 additions & 6 deletions src/renderers/common/Renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -1408,12 +1408,10 @@ class Renderer {

//

const frustum = camera.isArrayCamera ? _frustumArray : _frustum;

if ( ! camera.isArrayCamera ) {
if ( ! camera.perCameraCulling ) {

_projScreenMatrix.multiplyMatrices( camera.projectionMatrix, camera.matrixWorldInverse );
frustum.setFromProjectionMatrix( _projScreenMatrix, camera.coordinateSystem, camera.reversedDepth );
_frustum.setFromProjectionMatrix( _projScreenMatrix, camera.coordinateSystem, camera.reversedDepth );

}

Expand Down Expand Up @@ -2645,7 +2643,7 @@ class Renderer {

} else if ( object.isSprite ) {

const frustum = camera.isArrayCamera ? _frustumArray : _frustum;
const frustum = camera.perCameraCulling ? _frustumArray : _frustum;

if ( ! object.frustumCulled || frustum.intersectsSprite( object, camera ) ) {

Expand All @@ -2671,7 +2669,7 @@ class Renderer {

} else if ( object.isMesh || object.isLine || object.isPoints ) {

const frustum = camera.isArrayCamera ? _frustumArray : _frustum;
const frustum = camera.perCameraCulling ? _frustumArray : _frustum;

if ( ! object.frustumCulled || frustum.intersectsObject( object, camera ) ) {

Expand Down
3 changes: 2 additions & 1 deletion src/renderers/common/XRManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -1152,7 +1152,7 @@ class XRManager extends EventDispatcher {

} else {

// assume single camera setup (AR)
// view frustum culling will be performed per camera, but assign this anyway

cameraXR.projectionMatrix.copy( cameraL.projectionMatrix );

Expand Down Expand Up @@ -1575,6 +1575,7 @@ function onAnimationFrame( time, frame ) {

cameraXR.cameras.length = 0;
cameraXRNeedsUpdate = true;
cameraXR.perCameraCulling = views.length !== 2;

}

Expand Down
3 changes: 2 additions & 1 deletion src/renderers/webxr/WebXRManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -770,7 +770,7 @@ class WebXRManager extends EventDispatcher {

} else {

// assume single camera setup (AR)
// view frustum culling will be performed per camera, but assign this anyway

cameraXR.projectionMatrix.copy( cameraL.projectionMatrix );

Expand Down Expand Up @@ -936,6 +936,7 @@ class WebXRManager extends EventDispatcher {

cameraXR.cameras.length = 0;
cameraXRNeedsUpdate = true;
cameraXR.perCameraCulling = views.length !== 2;

}

Expand Down
Loading