|
@@ -824,13 +824,8 @@ THREE.WebGLRenderer = function ( parameters ) {
|
|
|
|
|
|
}
|
|
|
|
|
|
- var uniforms = program.getUniforms();
|
|
|
-
|
|
|
- if ( uniforms.morphTargetInfluences !== null ) {
|
|
|
-
|
|
|
- _gl.uniform1fv( uniforms.morphTargetInfluences, morphInfluences );
|
|
|
-
|
|
|
- }
|
|
|
+ program.getUniforms().setValue(
|
|
|
+ _gl, 'morphTargetInfluences', morphInfluences );
|
|
|
|
|
|
updateBuffers = true;
|
|
|
|
|
@@ -1631,22 +1626,6 @@ THREE.WebGLRenderer = function ( parameters ) {
|
|
|
|
|
|
}
|
|
|
|
|
|
- var uniformLocations = materialProperties.program.getUniforms();
|
|
|
-
|
|
|
- materialProperties.uniformsList = [];
|
|
|
-
|
|
|
- for ( var u in uniforms ) {
|
|
|
-
|
|
|
- var location = uniformLocations[ u ];
|
|
|
-
|
|
|
- if ( location ) {
|
|
|
-
|
|
|
- materialProperties.uniformsList.push( [ materialProperties.__webglShader.uniforms[ u ], location ] );
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
if ( material instanceof THREE.MeshPhongMaterial ||
|
|
|
material instanceof THREE.MeshLambertMaterial ||
|
|
|
material instanceof THREE.MeshStandardMaterial ||
|
|
@@ -1673,22 +1652,13 @@ THREE.WebGLRenderer = function ( parameters ) {
|
|
|
|
|
|
}
|
|
|
|
|
|
- // detect dynamic uniforms
|
|
|
-
|
|
|
- materialProperties.hasDynamicUniforms = false;
|
|
|
+ var progUniforms = materialProperties.program.getUniforms(),
|
|
|
+ uniformsList =
|
|
|
+ THREE.WebGLUniforms.seqWithValue( progUniforms.seq, uniforms );
|
|
|
|
|
|
- for ( var j = 0, jl = materialProperties.uniformsList.length; j < jl; j ++ ) {
|
|
|
-
|
|
|
- var uniform = materialProperties.uniformsList[ j ][ 0 ];
|
|
|
-
|
|
|
- if ( uniform.dynamic === true ) {
|
|
|
-
|
|
|
- materialProperties.hasDynamicUniforms = true;
|
|
|
- break;
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
+ materialProperties.uniformsList = uniformsList;
|
|
|
+ materialProperties.dynamicUniforms =
|
|
|
+ THREE.WebGLUniforms.splitDynamic( uniformsList, uniforms );
|
|
|
|
|
|
}
|
|
|
|
|
@@ -1802,11 +1772,12 @@ THREE.WebGLRenderer = function ( parameters ) {
|
|
|
|
|
|
if ( refreshProgram || camera !== _currentCamera ) {
|
|
|
|
|
|
- _gl.uniformMatrix4fv( p_uniforms.projectionMatrix, false, camera.projectionMatrix.elements );
|
|
|
+ p_uniforms.set( _gl, camera, 'projectionMatrix' );
|
|
|
|
|
|
if ( capabilities.logarithmicDepthBuffer ) {
|
|
|
|
|
|
- _gl.uniform1f( p_uniforms.logDepthBufFC, 2.0 / ( Math.log( camera.far + 1.0 ) / Math.LN2 ) );
|
|
|
+ p_uniforms.setValue( _gl, 'logDepthBufFC',
|
|
|
+ 2.0 / ( Math.log( camera.far + 1.0 ) / Math.LN2 ) );
|
|
|
|
|
|
}
|
|
|
|
|
@@ -1832,10 +1803,12 @@ THREE.WebGLRenderer = function ( parameters ) {
|
|
|
material instanceof THREE.MeshStandardMaterial ||
|
|
|
material.envMap ) {
|
|
|
|
|
|
- if ( p_uniforms.cameraPosition !== undefined ) {
|
|
|
+ var uCamPos = p_uniforms.map.cameraPosition;
|
|
|
+
|
|
|
+ if ( uCamPos !== undefined ) {
|
|
|
|
|
|
- _vector3.setFromMatrixPosition( camera.matrixWorld );
|
|
|
- _gl.uniform3f( p_uniforms.cameraPosition, _vector3.x, _vector3.y, _vector3.z );
|
|
|
+ uCamPos.setValue( _gl,
|
|
|
+ _vector3.setFromMatrixPosition( camera.matrixWorld ) );
|
|
|
|
|
|
}
|
|
|
|
|
@@ -1848,26 +1821,12 @@ THREE.WebGLRenderer = function ( parameters ) {
|
|
|
material instanceof THREE.ShaderMaterial ||
|
|
|
material.skinning ) {
|
|
|
|
|
|
- if ( p_uniforms.viewMatrix !== undefined ) {
|
|
|
-
|
|
|
- _gl.uniformMatrix4fv( p_uniforms.viewMatrix, false, camera.matrixWorldInverse.elements );
|
|
|
-
|
|
|
- }
|
|
|
+ p_uniforms.setValue( _gl, 'viewMatrix', camera.matrixWorldInverse );
|
|
|
|
|
|
}
|
|
|
|
|
|
-
|
|
|
- if ( p_uniforms.toneMappingExposure !== undefined ) {
|
|
|
-
|
|
|
- _gl.uniform1f( p_uniforms.toneMappingExposure, _this.toneMappingExposure );
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- if ( p_uniforms.toneMappingWhitePoint !== undefined ) {
|
|
|
-
|
|
|
- _gl.uniform1f( p_uniforms.toneMappingWhitePoint, _this.toneMappingWhitePoint );
|
|
|
-
|
|
|
- }
|
|
|
+ p_uniforms.set( _gl, _this, 'toneMappingExposure' );
|
|
|
+ p_uniforms.set( _gl, _this, 'toneMappingWhitePoint' );
|
|
|
|
|
|
}
|
|
|
|
|
@@ -1877,46 +1836,22 @@ THREE.WebGLRenderer = function ( parameters ) {
|
|
|
|
|
|
if ( material.skinning ) {
|
|
|
|
|
|
- if ( object.bindMatrix && p_uniforms.bindMatrix !== undefined ) {
|
|
|
+ p_uniforms.setOptional( _gl, object, 'bindMatrix' );
|
|
|
+ p_uniforms.setOptional( _gl, object, 'bindMatrixInverse' );
|
|
|
|
|
|
- _gl.uniformMatrix4fv( p_uniforms.bindMatrix, false, object.bindMatrix.elements );
|
|
|
+ var skeleton = object.skeleton;
|
|
|
|
|
|
- }
|
|
|
-
|
|
|
- if ( object.bindMatrixInverse && p_uniforms.bindMatrixInverse !== undefined ) {
|
|
|
-
|
|
|
- _gl.uniformMatrix4fv( p_uniforms.bindMatrixInverse, false, object.bindMatrixInverse.elements );
|
|
|
-
|
|
|
- }
|
|
|
+ if ( skeleton ) {
|
|
|
|
|
|
- if ( capabilities.floatVertexTextures && object.skeleton && object.skeleton.useVertexTexture ) {
|
|
|
+ if ( capabilities.floatVertexTextures && skeleton.useVertexTexture ) {
|
|
|
|
|
|
- if ( p_uniforms.boneTexture !== undefined ) {
|
|
|
+ p_uniforms.set( _gl, skeleton, 'boneTexture' );
|
|
|
+ p_uniforms.set( _gl, skeleton, 'boneTextureWidth' );
|
|
|
+ p_uniforms.set( _gl, skeleton, 'boneTextureHeight' );
|
|
|
|
|
|
- var textureUnit = getTextureUnit();
|
|
|
-
|
|
|
- _gl.uniform1i( p_uniforms.boneTexture, textureUnit );
|
|
|
- _this.setTexture( object.skeleton.boneTexture, textureUnit );
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- if ( p_uniforms.boneTextureWidth !== undefined ) {
|
|
|
-
|
|
|
- _gl.uniform1i( p_uniforms.boneTextureWidth, object.skeleton.boneTextureWidth );
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- if ( p_uniforms.boneTextureHeight !== undefined ) {
|
|
|
-
|
|
|
- _gl.uniform1i( p_uniforms.boneTextureHeight, object.skeleton.boneTextureHeight );
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- } else if ( object.skeleton && object.skeleton.boneMatrices ) {
|
|
|
-
|
|
|
- if ( p_uniforms.boneGlobalMatrices !== undefined ) {
|
|
|
+ } else {
|
|
|
|
|
|
- _gl.uniformMatrix4fv( p_uniforms.boneGlobalMatrices, false, object.skeleton.boneMatrices );
|
|
|
+ p_uniforms.setOptional( _gl, skeleton, 'boneMatrices' );
|
|
|
|
|
|
}
|
|
|
|
|
@@ -2010,49 +1945,33 @@ THREE.WebGLRenderer = function ( parameters ) {
|
|
|
|
|
|
}
|
|
|
|
|
|
- // load common uniforms
|
|
|
-
|
|
|
- loadUniformsGeneric( materialProperties.uniformsList );
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- loadUniformsMatrices( p_uniforms, object );
|
|
|
-
|
|
|
- if ( p_uniforms.modelMatrix !== undefined ) {
|
|
|
-
|
|
|
- _gl.uniformMatrix4fv( p_uniforms.modelMatrix, false, object.matrixWorld.elements );
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- if ( materialProperties.hasDynamicUniforms === true ) {
|
|
|
-
|
|
|
- updateDynamicUniforms( materialProperties.uniformsList, object, camera );
|
|
|
+ THREE.WebGLUniforms.upload(
|
|
|
+ _gl, materialProperties.uniformsList, m_uniforms, _this );
|
|
|
|
|
|
}
|
|
|
|
|
|
- return program;
|
|
|
|
|
|
- }
|
|
|
+ // common matrices
|
|
|
|
|
|
- function updateDynamicUniforms ( uniforms, object, camera ) {
|
|
|
+ p_uniforms.set( _gl, object, 'modelViewMatrix' );
|
|
|
+ p_uniforms.set( _gl, object, 'normalMatrix' );
|
|
|
+ p_uniforms.setValue( _gl, 'modelMatrix', object.matrixWorld );
|
|
|
|
|
|
- var dynamicUniforms = [];
|
|
|
|
|
|
- for ( var j = 0, jl = uniforms.length; j < jl; j ++ ) {
|
|
|
+ // dynamic uniforms
|
|
|
|
|
|
- var uniform = uniforms[ j ][ 0 ];
|
|
|
- var onUpdateCallback = uniform.onUpdateCallback;
|
|
|
+ var dynUniforms = materialProperties.dynamicUniforms;
|
|
|
|
|
|
- if ( onUpdateCallback !== undefined ) {
|
|
|
+ if ( dynUniforms !== null ) {
|
|
|
|
|
|
- onUpdateCallback.bind( uniform )( object, camera );
|
|
|
- dynamicUniforms.push( uniforms[ j ] );
|
|
|
+ THREE.WebGLUniforms.evalDynamic(
|
|
|
+ dynUniforms, m_uniforms, object, camera );
|
|
|
|
|
|
- }
|
|
|
+ THREE.WebGLUniforms.upload( _gl, dynUniforms, m_uniforms, _this );
|
|
|
|
|
|
}
|
|
|
|
|
|
- loadUniformsGeneric( dynamicUniforms );
|
|
|
+ return program;
|
|
|
|
|
|
}
|
|
|
|
|
@@ -2343,384 +2262,7 @@ THREE.WebGLRenderer = function ( parameters ) {
|
|
|
|
|
|
}
|
|
|
|
|
|
- // Uniforms (load to GPU)
|
|
|
-
|
|
|
- function loadUniformsMatrices ( uniforms, object ) {
|
|
|
-
|
|
|
- _gl.uniformMatrix4fv( uniforms.modelViewMatrix, false, object.modelViewMatrix.elements );
|
|
|
-
|
|
|
- if ( uniforms.normalMatrix ) {
|
|
|
-
|
|
|
- _gl.uniformMatrix3fv( uniforms.normalMatrix, false, object.normalMatrix.elements );
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- function getTextureUnit() {
|
|
|
-
|
|
|
- var textureUnit = _usedTextureUnits;
|
|
|
-
|
|
|
- if ( textureUnit >= capabilities.maxTextures ) {
|
|
|
-
|
|
|
- console.warn( 'WebGLRenderer: trying to use ' + textureUnit + ' texture units while this GPU supports only ' + capabilities.maxTextures );
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- _usedTextureUnits += 1;
|
|
|
-
|
|
|
- return textureUnit;
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- function loadUniform( uniform, type, location, value ) {
|
|
|
-
|
|
|
- var texture, textureUnit;
|
|
|
-
|
|
|
- if ( type === '1i' ) {
|
|
|
-
|
|
|
- _gl.uniform1i( location, value );
|
|
|
-
|
|
|
- } else if ( type === '1f' ) {
|
|
|
-
|
|
|
- _gl.uniform1f( location, value );
|
|
|
-
|
|
|
- } else if ( type === '2f' ) {
|
|
|
-
|
|
|
- _gl.uniform2f( location, value[ 0 ], value[ 1 ] );
|
|
|
-
|
|
|
- } else if ( type === '3f' ) {
|
|
|
-
|
|
|
- _gl.uniform3f( location, value[ 0 ], value[ 1 ], value[ 2 ] );
|
|
|
-
|
|
|
- } else if ( type === '4f' ) {
|
|
|
-
|
|
|
- _gl.uniform4f( location, value[ 0 ], value[ 1 ], value[ 2 ], value[ 3 ] );
|
|
|
-
|
|
|
- } else if ( type === '1iv' ) {
|
|
|
-
|
|
|
- _gl.uniform1iv( location, value );
|
|
|
-
|
|
|
- } else if ( type === '3iv' ) {
|
|
|
-
|
|
|
- _gl.uniform3iv( location, value );
|
|
|
-
|
|
|
- } else if ( type === '1fv' ) {
|
|
|
-
|
|
|
- _gl.uniform1fv( location, value );
|
|
|
-
|
|
|
- } else if ( type === '2fv' ) {
|
|
|
-
|
|
|
- _gl.uniform2fv( location, value );
|
|
|
-
|
|
|
- } else if ( type === '3fv' ) {
|
|
|
-
|
|
|
- _gl.uniform3fv( location, value );
|
|
|
-
|
|
|
- } else if ( type === '4fv' ) {
|
|
|
-
|
|
|
- _gl.uniform4fv( location, value );
|
|
|
-
|
|
|
- } else if ( type === 'Matrix2fv' ) {
|
|
|
-
|
|
|
- _gl.uniformMatrix2fv( location, false, value );
|
|
|
-
|
|
|
- } else if ( type === 'Matrix3fv' ) {
|
|
|
-
|
|
|
- _gl.uniformMatrix3fv( location, false, value );
|
|
|
-
|
|
|
- } else if ( type === 'Matrix4fv' ) {
|
|
|
-
|
|
|
- _gl.uniformMatrix4fv( location, false, value );
|
|
|
-
|
|
|
- //
|
|
|
-
|
|
|
- } else if ( type === 'i' ) {
|
|
|
-
|
|
|
- // console.warn( 'THREE.WebGLRenderer: Uniform "i" is now "1i".' );
|
|
|
- _gl.uniform1i( location, value );
|
|
|
-
|
|
|
- } else if ( type === 'f' ) {
|
|
|
-
|
|
|
- // console.warn( 'THREE.WebGLRenderer: Uniform "f" is now "1f".' );
|
|
|
- _gl.uniform1f( location, value );
|
|
|
-
|
|
|
- } else if ( type === 'iv1' ) {
|
|
|
-
|
|
|
- // console.warn( 'THREE.WebGLRenderer: Uniform "iv1" is now "1iv".' );
|
|
|
- _gl.uniform1iv( location, value );
|
|
|
-
|
|
|
- } else if ( type === 'iv' ) {
|
|
|
-
|
|
|
- // console.warn( 'THREE.WebGLRenderer: Uniform "iv" is now "3iv".' );
|
|
|
- _gl.uniform3iv( location, value );
|
|
|
-
|
|
|
- } else if ( type === 'fv1' ) {
|
|
|
-
|
|
|
- // console.warn( 'THREE.WebGLRenderer: Uniform "fv1" is now "1fv".' );
|
|
|
- _gl.uniform1fv( location, value );
|
|
|
-
|
|
|
- } else if ( type === 'fv' ) {
|
|
|
-
|
|
|
- // console.warn( 'THREE.WebGLRenderer: Uniform "fv" is now "3fv".' );
|
|
|
- _gl.uniform3fv( location, value );
|
|
|
-
|
|
|
- } else if ( type === 'v2' ) {
|
|
|
-
|
|
|
- // single THREE.Vector2
|
|
|
- _gl.uniform2f( location, value.x, value.y );
|
|
|
-
|
|
|
- } else if ( type === 'v3' ) {
|
|
|
-
|
|
|
- // single THREE.Vector3
|
|
|
- _gl.uniform3f( location, value.x, value.y, value.z );
|
|
|
-
|
|
|
- } else if ( type === 'v4' ) {
|
|
|
-
|
|
|
- // single THREE.Vector4
|
|
|
- _gl.uniform4f( location, value.x, value.y, value.z, value.w );
|
|
|
-
|
|
|
- } else if ( type === 'c' ) {
|
|
|
-
|
|
|
- // single THREE.Color
|
|
|
- _gl.uniform3f( location, value.r, value.g, value.b );
|
|
|
-
|
|
|
- } else if ( type === 's' || type === 'sa' ) {
|
|
|
-
|
|
|
- var properties = uniform.properties,
|
|
|
- identifiers = location.ids,
|
|
|
- nestedInfos = location.infos;
|
|
|
-
|
|
|
- for ( var i = 0, n = identifiers.length; i !== n; ++ i ) {
|
|
|
-
|
|
|
- var id = identifiers[ i ],
|
|
|
- isArray = typeof id === 'number',
|
|
|
- nestedUniform = isArray ? uniform : properties[ id ],
|
|
|
- nestedInfo = nestedInfos[ i ],
|
|
|
- nestedType = nestedInfo.infos !== undefined ? 's' : nestedUniform.type,
|
|
|
- nestedValue = value[ id ];
|
|
|
-
|
|
|
- loadUniform( nestedUniform, nestedType, nestedInfo, nestedValue );
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- } else if ( type === 'v2v' ) {
|
|
|
-
|
|
|
- // array of THREE.Vector2
|
|
|
-
|
|
|
- if ( uniform._array === undefined ) {
|
|
|
-
|
|
|
- uniform._array = new Float32Array( 2 * value.length );
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- for ( var i = 0, i2 = 0, il = value.length; i < il; i ++, i2 += 2 ) {
|
|
|
-
|
|
|
- uniform._array[ i2 + 0 ] = value[ i ].x;
|
|
|
- uniform._array[ i2 + 1 ] = value[ i ].y;
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- _gl.uniform2fv( location, uniform._array );
|
|
|
-
|
|
|
- } else if ( type === 'v3v' ) {
|
|
|
-
|
|
|
- // array of THREE.Vector3
|
|
|
-
|
|
|
- if ( uniform._array === undefined ) {
|
|
|
-
|
|
|
- uniform._array = new Float32Array( 3 * value.length );
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- for ( var i = 0, i3 = 0, il = value.length; i < il; i ++, i3 += 3 ) {
|
|
|
-
|
|
|
- uniform._array[ i3 + 0 ] = value[ i ].x;
|
|
|
- uniform._array[ i3 + 1 ] = value[ i ].y;
|
|
|
- uniform._array[ i3 + 2 ] = value[ i ].z;
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- _gl.uniform3fv( location, uniform._array );
|
|
|
-
|
|
|
- } else if ( type === 'v4v' ) {
|
|
|
-
|
|
|
- // array of THREE.Vector4
|
|
|
-
|
|
|
- if ( uniform._array === undefined ) {
|
|
|
-
|
|
|
- uniform._array = new Float32Array( 4 * value.length );
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- for ( var i = 0, i4 = 0, il = value.length; i < il; i ++, i4 += 4 ) {
|
|
|
-
|
|
|
- uniform._array[ i4 + 0 ] = value[ i ].x;
|
|
|
- uniform._array[ i4 + 1 ] = value[ i ].y;
|
|
|
- uniform._array[ i4 + 2 ] = value[ i ].z;
|
|
|
- uniform._array[ i4 + 3 ] = value[ i ].w;
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- _gl.uniform4fv( location, uniform._array );
|
|
|
-
|
|
|
- } else if ( type === 'm2' ) {
|
|
|
-
|
|
|
- // single THREE.Matrix2
|
|
|
- _gl.uniformMatrix2fv( location, false, value.elements );
|
|
|
-
|
|
|
- } else if ( type === 'm3' ) {
|
|
|
-
|
|
|
- // single THREE.Matrix3
|
|
|
- _gl.uniformMatrix3fv( location, false, value.elements );
|
|
|
-
|
|
|
- } else if ( type === 'm3v' ) {
|
|
|
-
|
|
|
- // array of THREE.Matrix3
|
|
|
-
|
|
|
- if ( uniform._array === undefined ) {
|
|
|
-
|
|
|
- uniform._array = new Float32Array( 9 * value.length );
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- for ( var i = 0, il = value.length; i < il; i ++ ) {
|
|
|
-
|
|
|
- value[ i ].flattenToArrayOffset( uniform._array, i * 9 );
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- _gl.uniformMatrix3fv( location, false, uniform._array );
|
|
|
-
|
|
|
- } else if ( type === 'm4' ) {
|
|
|
-
|
|
|
- // single THREE.Matrix4
|
|
|
- _gl.uniformMatrix4fv( location, false, value.elements );
|
|
|
-
|
|
|
- } else if ( type === 'm4v' ) {
|
|
|
-
|
|
|
- // array of THREE.Matrix4
|
|
|
-
|
|
|
- if ( uniform._array === undefined ) {
|
|
|
-
|
|
|
- uniform._array = new Float32Array( 16 * value.length );
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- for ( var i = 0, il = value.length; i < il; i ++ ) {
|
|
|
-
|
|
|
- value[ i ].flattenToArrayOffset( uniform._array, i * 16 );
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- _gl.uniformMatrix4fv( location, false, uniform._array );
|
|
|
-
|
|
|
- } else if ( type === 't' ) {
|
|
|
-
|
|
|
- // single THREE.Texture (2d or cube)
|
|
|
-
|
|
|
- texture = value;
|
|
|
- textureUnit = getTextureUnit();
|
|
|
-
|
|
|
- _gl.uniform1i( location, textureUnit );
|
|
|
-
|
|
|
- if ( ! texture ) return;
|
|
|
-
|
|
|
- if ( texture instanceof THREE.CubeTexture ||
|
|
|
- ( Array.isArray( texture.image ) && texture.image.length === 6 ) ) {
|
|
|
-
|
|
|
- // CompressedTexture can have Array in image :/
|
|
|
-
|
|
|
- setCubeTexture( texture, textureUnit );
|
|
|
-
|
|
|
- } else if ( texture instanceof THREE.WebGLRenderTargetCube ) {
|
|
|
-
|
|
|
- setCubeTextureDynamic( texture.texture, textureUnit );
|
|
|
-
|
|
|
- } else if ( texture instanceof THREE.WebGLRenderTarget ) {
|
|
|
-
|
|
|
- _this.setTexture( texture.texture, textureUnit );
|
|
|
-
|
|
|
- } else {
|
|
|
-
|
|
|
- _this.setTexture( texture, textureUnit );
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- } else if ( type === 'tv' ) {
|
|
|
-
|
|
|
- // array of THREE.Texture (2d or cube)
|
|
|
-
|
|
|
- if ( uniform._array === undefined ) {
|
|
|
-
|
|
|
- uniform._array = [];
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- for ( var i = 0, il = uniform.value.length; i < il; i ++ ) {
|
|
|
-
|
|
|
- uniform._array[ i ] = getTextureUnit();
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- _gl.uniform1iv( location, uniform._array );
|
|
|
-
|
|
|
- for ( var i = 0, il = uniform.value.length; i < il; i ++ ) {
|
|
|
-
|
|
|
- texture = uniform.value[ i ];
|
|
|
- textureUnit = uniform._array[ i ];
|
|
|
-
|
|
|
- if ( ! texture ) continue;
|
|
|
-
|
|
|
- if ( texture instanceof THREE.CubeTexture ||
|
|
|
- ( texture.image instanceof Array && texture.image.length === 6 ) ) {
|
|
|
-
|
|
|
- // CompressedTexture can have Array in image :/
|
|
|
-
|
|
|
- setCubeTexture( texture, textureUnit );
|
|
|
-
|
|
|
- } else if ( texture instanceof THREE.WebGLRenderTarget ) {
|
|
|
-
|
|
|
- _this.setTexture( texture.texture, textureUnit );
|
|
|
-
|
|
|
- } else if ( texture instanceof THREE.WebGLRenderTargetCube ) {
|
|
|
-
|
|
|
- setCubeTextureDynamic( texture.texture, textureUnit );
|
|
|
-
|
|
|
- } else {
|
|
|
-
|
|
|
- _this.setTexture( texture, textureUnit );
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- } else {
|
|
|
-
|
|
|
- console.warn( 'THREE.WebGLRenderer: Unknown uniform type: ' + type );
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- function loadUniformsGeneric( uniforms ) {
|
|
|
-
|
|
|
- for ( var i = 0, l = uniforms.length; i < l; i ++ ) {
|
|
|
-
|
|
|
- var uniform = uniforms[ i ][ 0 ];
|
|
|
-
|
|
|
- // needsUpdate property is not added to all uniforms.
|
|
|
- if ( uniform.needsUpdate === false ) continue;
|
|
|
-
|
|
|
- var type = uniform.type;
|
|
|
- var location = uniforms[ i ][ 1 ];
|
|
|
- var value = uniform.value;
|
|
|
-
|
|
|
- loadUniform( uniform, type, location, value );
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
+ // Lighting
|
|
|
|
|
|
function setupShadows ( lights ) {
|
|
|
|
|
@@ -2894,6 +2436,7 @@ THREE.WebGLRenderer = function ( parameters ) {
|
|
|
|
|
|
}
|
|
|
|
|
|
+ // Clipping
|
|
|
|
|
|
function setupGlobalClippingPlanes( planes, camera ) {
|
|
|
|
|
@@ -3053,6 +2596,22 @@ THREE.WebGLRenderer = function ( parameters ) {
|
|
|
|
|
|
// Textures
|
|
|
|
|
|
+ function allocTextureUnit() {
|
|
|
+
|
|
|
+ var textureUnit = _usedTextureUnits;
|
|
|
+
|
|
|
+ if ( textureUnit >= capabilities.maxTextures ) {
|
|
|
+
|
|
|
+ console.warn( 'WebGLRenderer: trying to use ' + textureUnit + ' texture units while this GPU supports only ' + capabilities.maxTextures );
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ _usedTextureUnits += 1;
|
|
|
+
|
|
|
+ return textureUnit;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
function setTextureParameters ( textureType, texture, isPowerOfTwoImage ) {
|
|
|
|
|
|
var extension;
|
|
@@ -3246,7 +2805,9 @@ THREE.WebGLRenderer = function ( parameters ) {
|
|
|
|
|
|
}
|
|
|
|
|
|
- this.setTexture = function ( texture, slot ) {
|
|
|
+ function setTexture2D( texture, slot ) {
|
|
|
+
|
|
|
+ if ( texture instanceof THREE.WebGLRenderTarget ) texture = texture.texture;
|
|
|
|
|
|
var textureProperties = properties.get( texture );
|
|
|
|
|
@@ -3464,6 +3025,41 @@ THREE.WebGLRenderer = function ( parameters ) {
|
|
|
|
|
|
}
|
|
|
|
|
|
+ var setTextureWarned = false;
|
|
|
+ this.setTexture = function( texture, slot ) {
|
|
|
+
|
|
|
+ if ( ! setTextureWarned ) {
|
|
|
+
|
|
|
+ console.warn( "THREE.WebGLRenderer: .setTexture is deprecated, " +
|
|
|
+ "use setTexture2D instead." );
|
|
|
+ setTextureWarned = true;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ setTexture2D( texture, slot );
|
|
|
+
|
|
|
+ };
|
|
|
+
|
|
|
+ this.allocTextureUnit = allocTextureUnit;
|
|
|
+ this.setTexture2D = setTexture2D;
|
|
|
+ this.setTextureCube = function( texture, slot ) {
|
|
|
+
|
|
|
+ if ( texture instanceof THREE.CubeTexture ||
|
|
|
+ ( Array.isArray( texture.image ) && texture.image.length === 6 ) ) {
|
|
|
+
|
|
|
+ // CompressedTexture can have Array in image :/
|
|
|
+
|
|
|
+ setCubeTexture( texture, slot );
|
|
|
+
|
|
|
+ } else {
|
|
|
+ // assumed: texture instanceof THREE.WebGLRenderTargetCube
|
|
|
+
|
|
|
+ setCubeTextureDynamic( texture.texture, slot );
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ };
|
|
|
+
|
|
|
// Render targets
|
|
|
|
|
|
// Setup storage for target texture and bind it to correct framebuffer
|