Skip to content
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

WebGPURenderer: Enable dynamic resizing of the cameras array in ArrayCamera #30353

Merged
merged 1 commit into from
Jan 18, 2025
Merged
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
4 changes: 2 additions & 2 deletions src/nodes/accessors/Camera.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export const cameraProjectionMatrix = /*@__PURE__*/ ( Fn( ( { camera } ) => {

let cameraProjectionMatrix;

if ( camera.isArrayCamera ) {
if ( camera.isArrayCamera && camera.cameras.length > 0 ) {

const matrices = [];

Expand Down Expand Up @@ -76,7 +76,7 @@ export const cameraViewMatrix = /*@__PURE__*/ ( Fn( ( { camera } ) => {

let cameraViewMatrix;

if ( camera.isArrayCamera ) {
if ( camera.isArrayCamera && camera.cameras.length > 0 ) {

const matrices = [];

Expand Down
10 changes: 8 additions & 2 deletions src/renderers/common/RenderObject.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { hashString } from '../../nodes/core/NodeUtils.js';
import { hash, hashString } from '../../nodes/core/NodeUtils.js';

let _id = 0;

Expand Down Expand Up @@ -770,9 +770,15 @@ class RenderObject {

}

if ( this.camera.isArrayCamera ) {

cacheKey = hash( cacheKey, this.camera.cameras.length );

}

if ( this.object.receiveShadow ) {

cacheKey += 1;
cacheKey = hash( cacheKey, 1 );

}

Expand Down
6 changes: 3 additions & 3 deletions src/renderers/webgl-fallback/WebGLBackend.js
Original file line number Diff line number Diff line change
Expand Up @@ -1103,12 +1103,13 @@ class WebGLBackend extends Backend {

};

if ( renderObject.camera.isArrayCamera ) {
if ( renderObject.camera.isArrayCamera && renderObject.camera.cameras.length > 0 ) {

const cameraData = this.get( renderObject.camera );
const cameras = renderObject.camera.cameras;
const cameraIndex = renderObject.getBindingGroup( 'cameraIndex' ).bindings[ 0 ];

if ( cameraData.indexesGPU === undefined ) {
if ( cameraData.indexesGPU === undefined || cameraData.indexesGPU.length !== cameras.length ) {

const data = new Uint32Array( [ 0, 0, 0, 0 ] );
const indexesGPU = [];
Expand All @@ -1130,7 +1131,6 @@ class WebGLBackend extends Backend {

}

const cameraIndex = renderObject.getBindingGroup( 'cameraIndex' ).bindings[ 0 ];
const cameraIndexData = this.get( cameraIndex );
const pixelRatio = this.renderer.getPixelRatio();

Expand Down
9 changes: 4 additions & 5 deletions src/renderers/webgpu/WebGPUBackend.js
Original file line number Diff line number Diff line change
Expand Up @@ -1264,14 +1264,14 @@ class WebGPUBackend extends Backend {

};

if ( renderObject.camera.isArrayCamera ) {
if ( renderObject.camera.isArrayCamera && renderObject.camera.cameras.length > 0 ) {

const cameraData = this.get( renderObject.camera );
const cameras = renderObject.camera.cameras;
const cameraIndex = renderObject.getBindingGroup( 'cameraIndex' );

if ( cameraData.indexesGPU === undefined ) {
if ( cameraData.indexesGPU === undefined || cameraData.indexesGPU.length !== cameras.length ) {

const cameraIndex = renderObject.getBindingGroup( 'cameraIndex' );
const bindingsData = this.get( cameraIndex );
const indexesGPU = [];

Expand All @@ -1288,7 +1288,6 @@ class WebGPUBackend extends Backend {
}

cameraData.indexesGPU = indexesGPU; // TODO: Create a global library for this
cameraData.cameraIndex = cameraIndex;

}

Expand All @@ -1311,7 +1310,7 @@ class WebGPUBackend extends Backend {
context.viewportValue.maxDepth
);

passEncoderGPU.setBindGroup( cameraData.cameraIndex.index, cameraData.indexesGPU[ i ] );
passEncoderGPU.setBindGroup( cameraIndex.index, cameraData.indexesGPU[ i ] );

draw();

Expand Down
Loading