提交 75e66cdf 编写于 作者: F Fernando Serrano

Add setNumViews() to WebGLMultiview

上级 ffc4b96b
...@@ -30,6 +30,19 @@ WebGLMultiviewRenderTarget.prototype = Object.assign( Object.create( WebGLRender ...@@ -30,6 +30,19 @@ WebGLMultiviewRenderTarget.prototype = Object.assign( Object.create( WebGLRender
return this; return this;
},
setNumViews: function ( numViews ) {
if ( this.numViews !== numViews ) {
this.numViews = numViews;
this.dispose();
}
return this;
} }
} ); } );
......
...@@ -1242,9 +1242,9 @@ function WebGLRenderer( parameters ) { ...@@ -1242,9 +1242,9 @@ function WebGLRenderer( parameters ) {
state.setPolygonOffset( false ); state.setPolygonOffset( false );
if ( this.multiview.isEnabled() ) { if ( multiview.isEnabled() ) {
this.multiview.detachRenderTarget( camera ); multiview.detachRenderTarget( camera );
} }
......
...@@ -11,44 +11,42 @@ function WebGLMultiview( renderer, requested, options ) { ...@@ -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 this.getMaxViews = function () {
var aux = {
mat4: [],
mat3: []
};
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 ) { ...@@ -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 ) { ...@@ -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 ) { ...@@ -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 ); mat4[ i ].multiplyMatrices( camera.cameras[ i ].matrixWorldInverse, object.matrixWorld );
aux.mat3[ i ].getNormalMatrix( aux.mat4[ i ] ); 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 ); mat4[ 0 ].multiplyMatrices( camera.matrixWorldInverse, object.matrixWorld );
aux.mat3[ 0 ].getNormalMatrix( aux.mat4[ 0 ] ); 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 ] ); mat4[ i ].copy( mat4[ 0 ] );
aux.mat3[ i ].copy( aux.mat3[ 0 ] ); mat3[ i ].copy( mat3[ 0 ] );
} }
} }
p_uniforms.setValue( gl, 'modelViewMatrices', aux.mat4 ); uniforms.setValue( gl, 'modelViewMatrices', mat4 );
p_uniforms.setValue( gl, 'normalMatrices', aux.mat3 ); uniforms.setValue( gl, 'normalMatrices', mat3 );
}; };
...@@ -167,6 +171,12 @@ function WebGLMultiview( renderer, requested, options ) { ...@@ -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 ) { ...@@ -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 );
} }
......
...@@ -1024,11 +1024,11 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils, ...@@ -1024,11 +1024,11 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
ext.framebufferTextureMultiviewOVR( _gl.FRAMEBUFFER, _gl.DEPTH_STENCIL_ATTACHMENT, depthStencilTexture, 0, 0, numViews ); ext.framebufferTextureMultiviewOVR( _gl.FRAMEBUFFER, _gl.DEPTH_STENCIL_ATTACHMENT, depthStencilTexture, 0, 0, numViews );
var viewFramebuffers = new Array( numViews ); var viewFramebuffers = new Array( numViews );
for ( var viewIndex = 0; viewIndex < numViews; ++ viewIndex ) { for ( var i = 0; i < numViews; ++ i ) {
viewFramebuffers[ viewIndex ] = _gl.createFramebuffer(); viewFramebuffers[ i ] = _gl.createFramebuffer();
_gl.bindFramebuffer( _gl.FRAMEBUFFER, viewFramebuffers[ viewIndex ] ); _gl.bindFramebuffer( _gl.FRAMEBUFFER, viewFramebuffers[ i ] );
_gl.framebufferTextureLayer( _gl.FRAMEBUFFER, _gl.COLOR_ATTACHMENT0, colorTexture, 0, viewIndex ); _gl.framebufferTextureLayer( _gl.FRAMEBUFFER, _gl.COLOR_ATTACHMENT0, colorTexture, 0, i );
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册