|
@@ -11,44 +11,42 @@ function WebGLMultiview( renderer, requested, options ) {
|
|
|
|
|
|
options = Object.assign( {}, { debug: false }, options );
|
|
options = Object.assign( {}, { debug: false }, options );
|
|
|
|
|
|
|
|
+ var DEFAULT_NUMVIEWS = 2;
|
|
var gl = renderer.context;
|
|
var gl = renderer.context;
|
|
var canvas = renderer.domElement;
|
|
var canvas = renderer.domElement;
|
|
var capabilities = renderer.capabilities;
|
|
var capabilities = renderer.capabilities;
|
|
var properties = renderer.properties;
|
|
var properties = renderer.properties;
|
|
|
|
|
|
- var numViews = 2;
|
|
|
|
var renderTarget, currentRenderTarget;
|
|
var renderTarget, currentRenderTarget;
|
|
|
|
|
|
- // Auxiliary matrices to be used when updating arrays of uniforms
|
|
|
|
- var aux = {
|
|
|
|
- mat4: [],
|
|
|
|
- mat3: []
|
|
|
|
- };
|
|
|
|
|
|
+ this.getMaxViews = function () {
|
|
|
|
|
|
- for ( var i = 0; i < numViews; i ++ ) {
|
|
|
|
|
|
+ return capabilities.maxMultiviewViews;
|
|
|
|
|
|
- aux.mat4[ i ] = new Matrix4();
|
|
|
|
- aux.mat3[ i ] = new Matrix3();
|
|
|
|
|
|
+ };
|
|
|
|
|
|
- }
|
|
|
|
|
|
+ this.getNumViews = function () {
|
|
|
|
|
|
- //
|
|
|
|
|
|
+ return renderTarget ? renderTarget.numViews : 1;
|
|
|
|
|
|
- this.isAvailable = function () {
|
|
|
|
|
|
+ };
|
|
|
|
|
|
- return capabilities.multiview;
|
|
|
|
|
|
+ // Auxiliary matrices to be used when updating arrays of uniforms
|
|
|
|
+ var mat4 = [];
|
|
|
|
+ var mat3 = [];
|
|
|
|
|
|
- };
|
|
|
|
|
|
+ for ( var i = 0; i < this.getMaxViews(); i ++ ) {
|
|
|
|
|
|
- this.getNumViews = function () {
|
|
|
|
|
|
+ mat4[ i ] = new Matrix4();
|
|
|
|
+ mat3[ i ] = new Matrix3();
|
|
|
|
|
|
- return numViews;
|
|
|
|
|
|
+ }
|
|
|
|
|
|
- };
|
|
|
|
|
|
+ //
|
|
|
|
|
|
- this.getMaxViews = function () {
|
|
|
|
|
|
+ this.isAvailable = function () {
|
|
|
|
|
|
- return capabilities.maxMultiviewViews;
|
|
|
|
|
|
+ return capabilities.multiview;
|
|
|
|
|
|
};
|
|
};
|
|
|
|
|
|
@@ -72,13 +70,15 @@ function WebGLMultiview( renderer, requested, options ) {
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
- this.updateCameraProjectionMatrices = function ( camera, p_uniforms ) {
|
|
|
|
|
|
+ this.updateCameraProjectionMatrices = function ( camera, uniforms ) {
|
|
|
|
+
|
|
|
|
+ var numViews = this.getNumViews();
|
|
|
|
|
|
if ( camera.isArrayCamera ) {
|
|
if ( camera.isArrayCamera ) {
|
|
|
|
|
|
for ( var i = 0; i < numViews; i ++ ) {
|
|
for ( var i = 0; i < numViews; i ++ ) {
|
|
|
|
|
|
- aux.mat4[ i ].copy( camera.cameras[ i ].projectionMatrix );
|
|
|
|
|
|
+ mat4[ i ].copy( camera.cameras[ i ].projectionMatrix );
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
@@ -86,23 +86,25 @@ function WebGLMultiview( renderer, requested, options ) {
|
|
|
|
|
|
for ( var i = 0; i < numViews; i ++ ) {
|
|
for ( var i = 0; i < numViews; i ++ ) {
|
|
|
|
|
|
- aux.mat4[ i ].copy( camera.projectionMatrix );
|
|
|
|
|
|
+ mat4[ i ].copy( camera.projectionMatrix );
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
- p_uniforms.setValue( gl, 'projectionMatrices', aux.mat4 );
|
|
|
|
|
|
+ uniforms.setValue( gl, 'projectionMatrices', mat4 );
|
|
|
|
|
|
};
|
|
};
|
|
|
|
|
|
- this.updateCameraViewMatrices = function ( camera, p_uniforms ) {
|
|
|
|
|
|
+ this.updateCameraViewMatrices = function ( camera, uniforms ) {
|
|
|
|
+
|
|
|
|
+ var numViews = this.getNumViews();
|
|
|
|
|
|
if ( camera.isArrayCamera ) {
|
|
if ( camera.isArrayCamera ) {
|
|
|
|
|
|
for ( var i = 0; i < numViews; i ++ ) {
|
|
for ( var i = 0; i < numViews; i ++ ) {
|
|
|
|
|
|
- aux.mat4[ i ].copy( camera.cameras[ i ].matrixWorldInverse );
|
|
|
|
|
|
+ mat4[ i ].copy( camera.cameras[ i ].matrixWorldInverse );
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
@@ -110,44 +112,46 @@ function WebGLMultiview( renderer, requested, options ) {
|
|
|
|
|
|
for ( var i = 0; i < numViews; i ++ ) {
|
|
for ( var i = 0; i < numViews; i ++ ) {
|
|
|
|
|
|
- aux.mat4[ i ].copy( camera.matrixWorldInverse );
|
|
|
|
|
|
+ mat4[ i ].copy( camera.matrixWorldInverse );
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
- p_uniforms.setValue( gl, 'viewMatrices', aux.mat4 );
|
|
|
|
|
|
+ uniforms.setValue( gl, 'viewMatrices', mat4 );
|
|
|
|
|
|
};
|
|
};
|
|
|
|
|
|
- this.updateObjectMatrices = function ( object, camera, p_uniforms ) {
|
|
|
|
|
|
+ this.updateObjectMatrices = function ( object, camera, uniforms ) {
|
|
|
|
+
|
|
|
|
+ var numViews = this.getNumViews();
|
|
|
|
|
|
if ( camera.isArrayCamera ) {
|
|
if ( camera.isArrayCamera ) {
|
|
|
|
|
|
for ( var i = 0; i < numViews; i ++ ) {
|
|
for ( var i = 0; i < numViews; i ++ ) {
|
|
|
|
|
|
- aux.mat4[ i ].multiplyMatrices( camera.cameras[ i ].matrixWorldInverse, object.matrixWorld );
|
|
|
|
- aux.mat3[ i ].getNormalMatrix( aux.mat4[ i ] );
|
|
|
|
|
|
+ mat4[ i ].multiplyMatrices( camera.cameras[ i ].matrixWorldInverse, object.matrixWorld );
|
|
|
|
+ mat3[ i ].getNormalMatrix( mat4[ i ] );
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
} else {
|
|
} else {
|
|
|
|
|
|
// In this case we still need to provide an array of matrices but just the first one will be used
|
|
// In this case we still need to provide an array of matrices but just the first one will be used
|
|
- aux.mat4[ 0 ].multiplyMatrices( camera.matrixWorldInverse, object.matrixWorld );
|
|
|
|
- aux.mat3[ 0 ].getNormalMatrix( aux.mat4[ 0 ] );
|
|
|
|
|
|
+ mat4[ 0 ].multiplyMatrices( camera.matrixWorldInverse, object.matrixWorld );
|
|
|
|
+ mat3[ 0 ].getNormalMatrix( mat4[ 0 ] );
|
|
|
|
|
|
for ( var i = 1; i < numViews; i ++ ) {
|
|
for ( var i = 1; i < numViews; i ++ ) {
|
|
|
|
|
|
- aux.mat4[ i ].copy( aux.mat4[ 0 ] );
|
|
|
|
- aux.mat3[ i ].copy( aux.mat3[ 0 ] );
|
|
|
|
|
|
+ mat4[ i ].copy( mat4[ 0 ] );
|
|
|
|
+ mat3[ i ].copy( mat3[ 0 ] );
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
- p_uniforms.setValue( gl, 'modelViewMatrices', aux.mat4 );
|
|
|
|
- p_uniforms.setValue( gl, 'normalMatrices', aux.mat3 );
|
|
|
|
|
|
+ uniforms.setValue( gl, 'modelViewMatrices', mat4 );
|
|
|
|
+ uniforms.setValue( gl, 'normalMatrices', mat3 );
|
|
|
|
|
|
};
|
|
};
|
|
|
|
|
|
@@ -167,6 +171,12 @@ function WebGLMultiview( renderer, requested, options ) {
|
|
width *= bounds.z;
|
|
width *= bounds.z;
|
|
height *= bounds.w;
|
|
height *= bounds.w;
|
|
|
|
|
|
|
|
+ renderTarget.setNumViews( camera.cameras.length );
|
|
|
|
+
|
|
|
|
+ } else {
|
|
|
|
+
|
|
|
|
+ renderTarget.setNumViews( DEFAULT_NUMVIEWS );
|
|
|
|
+
|
|
}
|
|
}
|
|
|
|
|
|
renderTarget.setSize( width, height );
|
|
renderTarget.setSize( width, height );
|
|
@@ -213,7 +223,7 @@ function WebGLMultiview( renderer, requested, options ) {
|
|
|
|
|
|
if ( this.isEnabled() ) {
|
|
if ( this.isEnabled() ) {
|
|
|
|
|
|
- renderTarget = new WebGLMultiviewRenderTarget( canvas.width, canvas.height, numViews );
|
|
|
|
|
|
+ renderTarget = new WebGLMultiviewRenderTarget( canvas.width, canvas.height, this.numViews );
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|