|
@@ -7,13 +7,33 @@ import { WebGLMultiviewRenderTarget } from '../WebGLMultiviewRenderTarget.js';
|
|
|
import { Matrix3 } from '../../math/Matrix3.js';
|
|
|
import { Matrix4 } from '../../math/Matrix4.js';
|
|
|
|
|
|
-function WebGLMultiview( renderer, requested ) {
|
|
|
+function WebGLMultiview( renderer, requested, options ) {
|
|
|
+
|
|
|
+ options = Object.assign( {}, { debug: false }, options );
|
|
|
|
|
|
var gl = renderer.context;
|
|
|
var canvas = renderer.domElement;
|
|
|
var capabilities = renderer.capabilities;
|
|
|
var properties = renderer.properties;
|
|
|
|
|
|
+ var numViews = 2;
|
|
|
+ var renderTarget, currentRenderTarget;
|
|
|
+
|
|
|
+ // Auxiliary matrices to be used when updating arrays of uniforms
|
|
|
+ var aux = {
|
|
|
+ mat4: [],
|
|
|
+ mat3: []
|
|
|
+ };
|
|
|
+
|
|
|
+ for ( var i = 0; i < numViews; i ++ ) {
|
|
|
+
|
|
|
+ aux.mat4[ i ] = new Matrix4();
|
|
|
+ aux.mat3[ i ] = new Matrix3();
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ //
|
|
|
+
|
|
|
this.isAvailable = function () {
|
|
|
|
|
|
return capabilities.multiview;
|
|
@@ -38,41 +58,27 @@ function WebGLMultiview( renderer, requested ) {
|
|
|
|
|
|
};
|
|
|
|
|
|
- if ( requested && ! this.isAvailable() ) {
|
|
|
-
|
|
|
- console.warn( 'WebGLRenderer: Multiview requested but not supported by the browser' );
|
|
|
+ if ( options.debug ) {
|
|
|
|
|
|
- } else if ( requested !== false && this.isAvailable() ) {
|
|
|
+ if ( requested && ! this.isAvailable() ) {
|
|
|
|
|
|
- console.info( 'WebGLRenderer: Multiview enabled' );
|
|
|
+ console.warn( 'WebGLRenderer: Multiview requested but not supported by the browser' );
|
|
|
|
|
|
- }
|
|
|
+ } else if ( requested !== false && this.isAvailable() ) {
|
|
|
|
|
|
- var numViews = 2;
|
|
|
- var renderTarget, currentRenderTarget;
|
|
|
+ console.info( 'WebGLRenderer: Multiview enabled' );
|
|
|
|
|
|
- this.computeCameraMatrices = function ( camera ) {
|
|
|
-
|
|
|
- if ( ! camera.projectionMatrices ) {
|
|
|
-
|
|
|
- camera.projectionMatrices = new Array( numViews );
|
|
|
- camera.viewMatrices = new Array( numViews );
|
|
|
-
|
|
|
- for ( var i = 0; i < numViews; i ++ ) {
|
|
|
-
|
|
|
- camera.projectionMatrices[ i ] = new Matrix4();
|
|
|
- camera.viewMatrices[ i ] = new Matrix4();
|
|
|
+ }
|
|
|
|
|
|
- }
|
|
|
+ }
|
|
|
|
|
|
- }
|
|
|
+ this.updateCameraProjectionMatrices = function ( camera, p_uniforms ) {
|
|
|
|
|
|
if ( camera.isArrayCamera ) {
|
|
|
|
|
|
for ( var i = 0; i < numViews; i ++ ) {
|
|
|
|
|
|
- camera.projectionMatrices[ i ].copy( camera.cameras[ i ].projectionMatrix );
|
|
|
- camera.viewMatrices[ i ].copy( camera.cameras[ i ].matrixWorldInverse );
|
|
|
+ aux.mat4[ i ].copy( camera.cameras[ i ].projectionMatrix );
|
|
|
|
|
|
}
|
|
|
|
|
@@ -80,55 +86,69 @@ function WebGLMultiview( renderer, requested ) {
|
|
|
|
|
|
for ( var i = 0; i < numViews; i ++ ) {
|
|
|
|
|
|
- camera.projectionMatrices[ i ].copy( camera.projectionMatrix );
|
|
|
- camera.viewMatrices[ i ].copy( camera.matrixWorldInverse );
|
|
|
+ aux.mat4[ i ].copy( camera.projectionMatrix );
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
+ p_uniforms.setValue( gl, 'projectionMatrices', aux.mat4 );
|
|
|
+
|
|
|
};
|
|
|
|
|
|
- this.computeObjectMatrices = function ( object, camera ) {
|
|
|
+ this.updateCameraViewMatrices = function ( camera, p_uniforms ) {
|
|
|
+
|
|
|
+ if ( camera.isArrayCamera ) {
|
|
|
+
|
|
|
+ for ( var i = 0; i < numViews; i ++ ) {
|
|
|
|
|
|
- if ( ! object.modelViewMatrices ) {
|
|
|
+ aux.mat4[ i ].copy( camera.cameras[ i ].matrixWorldInverse );
|
|
|
|
|
|
- object.modelViewMatrices = new Array( numViews );
|
|
|
- object.normalMatrices = new Array( numViews );
|
|
|
+ }
|
|
|
+
|
|
|
+ } else {
|
|
|
|
|
|
for ( var i = 0; i < numViews; i ++ ) {
|
|
|
|
|
|
- object.modelViewMatrices[ i ] = new Matrix4();
|
|
|
- object.normalMatrices[ i ] = new Matrix3();
|
|
|
+ aux.mat4[ i ].copy( camera.matrixWorldInverse );
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
+ p_uniforms.setValue( gl, 'viewMatrices', aux.mat4 );
|
|
|
+
|
|
|
+ };
|
|
|
+
|
|
|
+ this.updateObjectMatrices = function ( object, camera, p_uniforms ) {
|
|
|
+
|
|
|
if ( camera.isArrayCamera ) {
|
|
|
|
|
|
for ( var i = 0; i < numViews; i ++ ) {
|
|
|
|
|
|
- object.modelViewMatrices[ i ].multiplyMatrices( camera.cameras[ i ].matrixWorldInverse, object.matrixWorld );
|
|
|
- object.normalMatrices[ i ].getNormalMatrix( object.modelViewMatrices[ i ] );
|
|
|
+ aux.mat4[ i ].multiplyMatrices( camera.cameras[ i ].matrixWorldInverse, object.matrixWorld );
|
|
|
+ aux.mat3[ i ].getNormalMatrix( aux.mat4[ i ] );
|
|
|
|
|
|
}
|
|
|
|
|
|
} else {
|
|
|
|
|
|
// In this case we still need to provide an array of matrices but just the first one will be used
|
|
|
- object.modelViewMatrices[ 0 ].multiplyMatrices( camera.matrixWorldInverse, object.matrixWorld );
|
|
|
- object.normalMatrices[ 0 ].getNormalMatrix( object.modelViewMatrices[ 0 ] );
|
|
|
+ aux.mat4[ 0 ].multiplyMatrices( camera.matrixWorldInverse, object.matrixWorld );
|
|
|
+ aux.mat3[ 0 ].getNormalMatrix( aux.mat4[ 0 ] );
|
|
|
|
|
|
for ( var i = 1; i < numViews; i ++ ) {
|
|
|
|
|
|
- object.modelViewMatrices[ i ].copy( object.modelViewMatrices[ 0 ] );
|
|
|
- object.normalMatrices[ i ].copy( object.normalMatrices[ 0 ] );
|
|
|
+ aux.mat4[ i ].copy( aux.mat4[ 0 ] );
|
|
|
+ aux.mat3[ i ].copy( aux.mat3[ 0 ] );
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
+ p_uniforms.setValue( gl, 'modelViewMatrices', aux.mat4 );
|
|
|
+ p_uniforms.setValue( gl, 'normalMatrices', aux.mat3 );
|
|
|
+
|
|
|
};
|
|
|
|
|
|
this.attachRenderTarget = function ( camera ) {
|