提交 f5809c2f 编写于 作者: F Fernando Serrano

Clean up WebGLMultiview allocations and simplify update matrices code

上级 5c29bf2c
......@@ -18,6 +18,7 @@ function WebGLMultiview( renderer, requested, options ) {
var properties = renderer.properties;
var renderTarget, currentRenderTarget;
var mat3, mat4, cameraArray;
this.getMaxViews = function () {
......@@ -31,14 +32,14 @@ function WebGLMultiview( renderer, requested, options ) {
};
// Auxiliary matrices to be used when updating arrays of uniforms
var mat4 = [];
var mat3 = [];
for ( var i = 0; i < this.getMaxViews(); i ++ ) {
function getCameraArray( camera ) {
mat4[ i ] = new Matrix4();
mat3[ i ] = new Matrix3();
if ( camera.isArrayCamera ) return camera.cameras;
cameraArray[ 0 ] = camera;
return cameraArray;
}
......@@ -70,25 +71,14 @@ function WebGLMultiview( renderer, requested, options ) {
}
this.updateCameraProjectionMatrices = function ( camera, uniforms ) {
var numViews = this.getNumViews();
if ( camera.isArrayCamera ) {
for ( var i = 0; i < numViews; i ++ ) {
mat4[ i ].copy( camera.cameras[ i ].projectionMatrix );
}
} else {
this.updateCameraProjectionMatrices = function ( camera, uniforms ) {
for ( var i = 0; i < numViews; i ++ ) {
var cameras = getCameraArray( camera );
mat4[ i ].copy( camera.projectionMatrix );
for ( var i = 0; i < cameras.length; i ++ ) {
}
mat4[ i ].copy( cameras[ i ].projectionMatrix );
}
......@@ -98,23 +88,11 @@ function WebGLMultiview( renderer, requested, options ) {
this.updateCameraViewMatrices = function ( camera, uniforms ) {
var numViews = this.getNumViews();
if ( camera.isArrayCamera ) {
for ( var i = 0; i < numViews; i ++ ) {
mat4[ i ].copy( camera.cameras[ i ].matrixWorldInverse );
var cameras = getCameraArray( camera );
}
} else {
for ( var i = 0; i < cameras.length; i ++ ) {
for ( var i = 0; i < numViews; i ++ ) {
mat4[ i ].copy( camera.matrixWorldInverse );
}
mat4[ i ].copy( cameras[ i ].matrixWorldInverse );
}
......@@ -124,29 +102,12 @@ function WebGLMultiview( renderer, requested, options ) {
this.updateObjectMatrices = function ( object, camera, uniforms ) {
var numViews = this.getNumViews();
if ( camera.isArrayCamera ) {
for ( var i = 0; i < numViews; i ++ ) {
mat4[ i ].multiplyMatrices( camera.cameras[ i ].matrixWorldInverse, object.matrixWorld );
mat3[ i ].getNormalMatrix( mat4[ i ] );
var cameras = getCameraArray( camera );
}
} else {
for ( var i = 0; i < cameras.length; i ++ ) {
// In this case we still need to provide an array of matrices but just the first one will be used
mat4[ 0 ].multiplyMatrices( camera.matrixWorldInverse, object.matrixWorld );
mat3[ 0 ].getNormalMatrix( mat4[ 0 ] );
for ( var i = 1; i < numViews; i ++ ) {
mat4[ i ].copy( mat4[ 0 ] );
mat3[ i ].copy( mat3[ 0 ] );
}
mat4[ i ].multiplyMatrices( cameras[ i ].matrixWorldInverse, object.matrixWorld );
mat3[ i ].getNormalMatrix( mat4[ i ] );
}
......@@ -225,6 +186,18 @@ function WebGLMultiview( renderer, requested, options ) {
renderTarget = new WebGLMultiviewRenderTarget( canvas.width, canvas.height, this.numViews );
// Auxiliary matrices to be used when updating arrays of uniforms
mat4 = [];
mat3 = [];
cameraArray = [];
for ( var i = 0; i < this.getMaxViews(); i ++ ) {
mat4[ i ] = new Matrix4();
mat3[ i ] = new Matrix3();
}
}
}
......
......@@ -1039,11 +1039,11 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
_gl.bindFramebuffer( _gl.FRAMEBUFFER, null );
_gl.bindTexture( _gl.TEXTURE_2D_ARRAY, null );
}
} else {
} else {
console.warn( 'THREE.WebGLRenderer: WebGLMultiviewRenderTarget can only be used with WebGL2 and Multiview extension support.' );
console.warn( 'THREE.WebGLRenderer: WebGLMultiviewRenderTarget can only be used with WebGL2 and Multiview extension support.' );
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册