Prechádzať zdrojové kódy

InstancedMesh: Compute instanceNormalMatrix in vertex shader.

Mr.doob 5 rokov pred
rodič
commit
114eb01ad3

+ 0 - 6
src/objects/InstancedMesh.js

@@ -3,17 +3,13 @@
  */
 
 import { BufferAttribute } from '../core/BufferAttribute.js';
-import { Matrix3 } from '../math/Matrix3.js';
 import { Mesh } from './Mesh.js';
 
-var _matrix3 = new Matrix3();
-
 function InstancedMesh( geometry, material, count ) {
 
 	Mesh.call( this, geometry, material );
 
 	this.instanceMatrix = new BufferAttribute( new Float32Array( count * 16 ), 16 );
-	this.instanceNormalMatrix = new BufferAttribute( new Float32Array( count * 9 ), 9 );
 
 }
 
@@ -29,8 +25,6 @@ InstancedMesh.prototype = Object.assign( Object.create( Mesh.prototype ), {
 
 		matrix.toArray( this.instanceMatrix.array, index * 16 );
 
-		_matrix3.getNormalMatrix( matrix ).toArray( this.instanceNormalMatrix.array, index * 9 );
-
 	},
 
 	updateMorphTargets: function () {}

+ 0 - 21
src/renderers/WebGLRenderer.js

@@ -1015,27 +1015,6 @@ function WebGLRenderer( parameters ) {
 					_gl.vertexAttribPointer( programAttribute + 2, 4, type, false, 64, 32 );
 					_gl.vertexAttribPointer( programAttribute + 3, 4, type, false, 64, 48 );
 
-				} else if ( name === 'instanceNormalMatrix' ) {
-
-					var attribute = attributes.get( object.instanceNormalMatrix );
-
-					// TODO Attribute may not be available on context restore
-
-					if ( attribute === undefined ) continue;
-
-					var buffer = attribute.buffer;
-					var type = attribute.type;
-
-					state.enableAttributeAndDivisor( programAttribute + 0, 1 );
-					state.enableAttributeAndDivisor( programAttribute + 1, 1 );
-					state.enableAttributeAndDivisor( programAttribute + 2, 1 );
-
-					_gl.bindBuffer( _gl.ARRAY_BUFFER, buffer );
-
-					_gl.vertexAttribPointer( programAttribute + 0, 3, type, false, 36, 0 );
-					_gl.vertexAttribPointer( programAttribute + 1, 3, type, false, 36, 12 );
-					_gl.vertexAttribPointer( programAttribute + 2, 3, type, false, 36, 24 );
-
 				} else if ( materialDefaultAttributeValues !== undefined ) {
 
 					var value = materialDefaultAttributeValues[ name ];

+ 1 - 1
src/renderers/shaders/ShaderChunk/defaultnormal_vertex.glsl.js

@@ -3,7 +3,7 @@ vec3 transformedNormal = objectNormal;
 
 #ifdef USE_INSTANCING
 
-	transformedNormal = instanceNormalMatrix * transformedNormal;
+	transformedNormal = mat3( instanceMatrix ) * transformedNormal;
 
 #endif
 

+ 0 - 1
src/renderers/webgl/WebGLObjects.js

@@ -32,7 +32,6 @@ function WebGLObjects( gl, geometries, attributes, info ) {
 		if ( object.isInstancedMesh ) {
 
 			attributes.update( object.instanceMatrix, gl.ARRAY_BUFFER );
-			attributes.update( object.instanceNormalMatrix, gl.ARRAY_BUFFER );
 
 		}
 

+ 0 - 1
src/renderers/webgl/WebGLProgram.js

@@ -509,7 +509,6 @@ function WebGLProgram( renderer, extensions, code, material, shader, parameters,
 			'#ifdef USE_INSTANCING',
 
 			' attribute mat4 instanceMatrix;',
-			' attribute mat3 instanceNormalMatrix;',
 
 			'#endif',