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

Remove matrices from camera and object and move them to aux variables to reuse them

上级 ea60c3b7
...@@ -1463,16 +1463,8 @@ function WebGLRenderer( parameters ) { ...@@ -1463,16 +1463,8 @@ function WebGLRenderer( parameters ) {
object.onBeforeRender( _this, scene, camera, geometry, material, group ); object.onBeforeRender( _this, scene, camera, geometry, material, group );
currentRenderState = renderStates.get( scene, _currentArrayCamera || camera ); currentRenderState = renderStates.get( scene, _currentArrayCamera || camera );
if ( multiview.isEnabled() ) { object.modelViewMatrix.multiplyMatrices( camera.matrixWorldInverse, object.matrixWorld );
object.normalMatrix.getNormalMatrix( object.modelViewMatrix );
multiview.computeObjectMatrices( object, camera );
} else {
object.modelViewMatrix.multiplyMatrices( camera.matrixWorldInverse, object.matrixWorld );
object.normalMatrix.getNormalMatrix( object.modelViewMatrix );
}
if ( object.isImmediateRenderObject ) { if ( object.isImmediateRenderObject ) {
...@@ -1745,8 +1737,7 @@ function WebGLRenderer( parameters ) { ...@@ -1745,8 +1737,7 @@ function WebGLRenderer( parameters ) {
if ( material.supportsMultiview && multiview.isEnabled() ) { if ( material.supportsMultiview && multiview.isEnabled() ) {
multiview.computeCameraMatrices( camera ); multiview.updateCameraProjectionMatrices( camera, p_uniforms );
p_uniforms.setValue( _gl, 'projectionMatrices', camera.projectionMatrices );
} else { } else {
...@@ -1802,7 +1793,7 @@ function WebGLRenderer( parameters ) { ...@@ -1802,7 +1793,7 @@ function WebGLRenderer( parameters ) {
if ( material.supportsMultiview && multiview.isEnabled() ) { if ( material.supportsMultiview && multiview.isEnabled() ) {
p_uniforms.setValue( _gl, 'viewMatrices', camera.viewMatrices ); multiview.updateCameraViewMatrices( camera, p_uniforms );
} else { } else {
...@@ -2008,8 +1999,7 @@ function WebGLRenderer( parameters ) { ...@@ -2008,8 +1999,7 @@ function WebGLRenderer( parameters ) {
if ( material.supportsMultiview && multiview.isEnabled() ) { if ( material.supportsMultiview && multiview.isEnabled() ) {
p_uniforms.setValue( _gl, 'modelViewMatrices', object.modelViewMatrices ); multiview.updateObjectMatrices( object, camera, p_uniforms );
p_uniforms.setValue( _gl, 'normalMatrices', object.normalMatrices );
} else { } else {
......
...@@ -7,13 +7,33 @@ import { WebGLMultiviewRenderTarget } from '../WebGLMultiviewRenderTarget.js'; ...@@ -7,13 +7,33 @@ import { WebGLMultiviewRenderTarget } from '../WebGLMultiviewRenderTarget.js';
import { Matrix3 } from '../../math/Matrix3.js'; import { Matrix3 } from '../../math/Matrix3.js';
import { Matrix4 } from '../../math/Matrix4.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 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;
// 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 () { this.isAvailable = function () {
return capabilities.multiview; return capabilities.multiview;
...@@ -38,41 +58,27 @@ function WebGLMultiview( renderer, requested ) { ...@@ -38,41 +58,27 @@ function WebGLMultiview( renderer, requested ) {
}; };
if ( requested && ! this.isAvailable() ) { if ( options.debug ) {
console.warn( 'WebGLRenderer: Multiview requested but not supported by the browser' );
} 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; console.info( 'WebGLRenderer: Multiview enabled' );
var renderTarget, currentRenderTarget;
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 ) { if ( camera.isArrayCamera ) {
for ( var i = 0; i < numViews; i ++ ) { for ( var i = 0; i < numViews; i ++ ) {
camera.projectionMatrices[ i ].copy( camera.cameras[ i ].projectionMatrix ); aux.mat4[ i ].copy( camera.cameras[ i ].projectionMatrix );
camera.viewMatrices[ i ].copy( camera.cameras[ i ].matrixWorldInverse );
} }
...@@ -80,55 +86,69 @@ function WebGLMultiview( renderer, requested ) { ...@@ -80,55 +86,69 @@ function WebGLMultiview( renderer, requested ) {
for ( var i = 0; i < numViews; i ++ ) { for ( var i = 0; i < numViews; i ++ ) {
camera.projectionMatrices[ i ].copy( camera.projectionMatrix ); aux.mat4[ i ].copy( camera.projectionMatrix );
camera.viewMatrices[ i ].copy( camera.matrixWorldInverse );
} }
} }
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 ++ ) { for ( var i = 0; i < numViews; i ++ ) {
object.modelViewMatrices[ i ] = new Matrix4(); aux.mat4[ i ].copy( camera.matrixWorldInverse );
object.normalMatrices[ i ] = new Matrix3();
} }
} }
p_uniforms.setValue( gl, 'viewMatrices', aux.mat4 );
};
this.updateObjectMatrices = function ( object, camera, p_uniforms ) {
if ( camera.isArrayCamera ) { if ( camera.isArrayCamera ) {
for ( var i = 0; i < numViews; i ++ ) { for ( var i = 0; i < numViews; i ++ ) {
object.modelViewMatrices[ i ].multiplyMatrices( camera.cameras[ i ].matrixWorldInverse, object.matrixWorld ); aux.mat4[ i ].multiplyMatrices( camera.cameras[ i ].matrixWorldInverse, object.matrixWorld );
object.normalMatrices[ i ].getNormalMatrix( object.modelViewMatrices[ i ] ); aux.mat3[ i ].getNormalMatrix( aux.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
object.modelViewMatrices[ 0 ].multiplyMatrices( camera.matrixWorldInverse, object.matrixWorld ); aux.mat4[ 0 ].multiplyMatrices( camera.matrixWorldInverse, object.matrixWorld );
object.normalMatrices[ 0 ].getNormalMatrix( object.modelViewMatrices[ 0 ] ); aux.mat3[ 0 ].getNormalMatrix( aux.mat4[ 0 ] );
for ( var i = 1; i < numViews; i ++ ) { for ( var i = 1; i < numViews; i ++ ) {
object.modelViewMatrices[ i ].copy( object.modelViewMatrices[ 0 ] ); aux.mat4[ i ].copy( aux.mat4[ 0 ] );
object.normalMatrices[ i ].copy( object.normalMatrices[ 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 ) { this.attachRenderTarget = function ( camera ) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册