Browse Source

WebGLRenderer: Tweaked index0AttributeName handling. Fixes #4469.

Mr.doob 11 years ago
parent
commit
390ab5b422

+ 1 - 3
src/materials/ShaderMaterial.js

@@ -65,9 +65,7 @@ THREE.ShaderMaterial = function ( parameters ) {
 		"uv2" : [ 0, 0 ]
 		"uv2" : [ 0, 0 ]
 	};
 	};
 
 
-	// By default, bind position to attribute index 0. In WebGL, attribute 0
-	// should always be used to avoid potentially expensive emulation.
-	this.index0AttributeName = "position";
+	this.index0AttributeName = undefined;
 
 
 	this.setValues( parameters );
 	this.setValues( parameters );
 
 

+ 12 - 3
src/renderers/webgl/WebGLProgram.js

@@ -62,6 +62,14 @@ THREE.WebGLProgram = ( function () {
 		var defines = material.defines;
 		var defines = material.defines;
 		var index0AttributeName = material.index0AttributeName;
 		var index0AttributeName = material.index0AttributeName;
 
 
+		if ( index0AttributeName === undefined && parameters.morphTargets === true ) {
+
+			// programs with morphTargets displace position out of attribute 0
+
+			index0AttributeName = 'position';
+
+		}
+
 		var shadowMapTypeDefine = "SHADOWMAP_TYPE_BASIC";
 		var shadowMapTypeDefine = "SHADOWMAP_TYPE_BASIC";
 
 
 		if ( parameters.shadowMapType === THREE.PCFShadowMap ) {
 		if ( parameters.shadowMapType === THREE.PCFShadowMap ) {
@@ -237,11 +245,12 @@ THREE.WebGLProgram = ( function () {
 		_gl.attachShader( program, glVertexShader );
 		_gl.attachShader( program, glVertexShader );
 		_gl.attachShader( program, glFragmentShader );
 		_gl.attachShader( program, glFragmentShader );
 
 
-		// Force a particular attribute to index 0.
-		// because potentially expensive emulation is done by browser if attribute 0 is disabled.
-		// And, color, for example is often automatically bound to index 0 so disabling it
 		if ( index0AttributeName !== undefined ) {
 		if ( index0AttributeName !== undefined ) {
 
 
+			// Force a particular attribute to index 0.
+			// because potentially expensive emulation is done by browser if attribute 0 is disabled.
+			// And, color, for example is often automatically bound to index 0 so disabling it
+
 			_gl.bindAttribLocation( program, 0, index0AttributeName );
 			_gl.bindAttribLocation( program, 0, index0AttributeName );
 
 
 		}
 		}

+ 5 - 1
src/renderers/webgl/WebGLShader.js

@@ -21,7 +21,11 @@ THREE.WebGLShader = ( function () {
 		gl.shaderSource( shader, string );
 		gl.shaderSource( shader, string );
 		gl.compileShader( shader );
 		gl.compileShader( shader );
 
 
-		// if ( gl.getShaderParameter( shader, gl.COMPILE_STATUS ) === false ) {}
+		if ( gl.getShaderParameter( shader, gl.COMPILE_STATUS ) === false ) {
+
+			console.error( 'THREE.WebGLShader: Shader couldn\'t compile.' );
+
+		}
 
 
 		if ( gl.getShaderInfoLog( shader ) !== '' ) {
 		if ( gl.getShaderInfoLog( shader ) !== '' ) {