ソースを参照

Added safeguards to morph buffers setting in WebGLRenderer.

Now morph buffers behave the same like other buffers and do not attempt to get set when materials do not use corresponding attributes. Not having this was crashing deferred rendering when shuffling around materials in G-buffer passes.
alteredq 12 年 前
コミット
b6331a8560
3 ファイル変更44 行追加22 行削除
  1. 20 9
      build/three.js
  2. 4 4
      build/three.min.js
  3. 20 9
      src/renderers/WebGLRenderer.js

+ 20 - 9
build/three.js

@@ -19353,7 +19353,7 @@ THREE.WebGLRenderer = function ( parameters ) {
 
 		var attributes = material.program.attributes;
 
-		if ( object.morphTargetBase !== -1 ) {
+		if ( object.morphTargetBase !== -1 && attributes.position >= 0 ) {
 
 			_gl.bindBuffer( _gl.ARRAY_BUFFER, geometryGroup.__webglMorphTargetsBuffers[ object.morphTargetBase ] );
 			enableAttribute( attributes.position );
@@ -19377,11 +19377,15 @@ THREE.WebGLRenderer = function ( parameters ) {
 
 			while ( m < material.numSupportedMorphTargets && m < order.length ) {
 
-				_gl.bindBuffer( _gl.ARRAY_BUFFER, geometryGroup.__webglMorphTargetsBuffers[ order[ m ] ] );
-				enableAttribute( attributes[ "morphTarget" + m ] );
-				_gl.vertexAttribPointer( attributes[ "morphTarget" + m ], 3, _gl.FLOAT, false, 0, 0 );
+				if ( attributes[ "morphTarget" + m ] >= 0 ) {
 
-				if ( material.morphNormals ) {
+					_gl.bindBuffer( _gl.ARRAY_BUFFER, geometryGroup.__webglMorphTargetsBuffers[ order[ m ] ] );
+					enableAttribute( attributes[ "morphTarget" + m ] );
+					_gl.vertexAttribPointer( attributes[ "morphTarget" + m ], 3, _gl.FLOAT, false, 0, 0 );
+
+				}
+
+				if ( attributes[ "morphNormal" + m ] >= 0 && material.morphNormals ) {
 
 					_gl.bindBuffer( _gl.ARRAY_BUFFER, geometryGroup.__webglMorphNormalsBuffers[ order[ m ] ] );
 					enableAttribute( attributes[ "morphNormal" + m ] );
@@ -19437,22 +19441,28 @@ THREE.WebGLRenderer = function ( parameters ) {
 
 					influenceIndex = activeInfluenceIndices[ m ][ 0 ];
 
-					_gl.bindBuffer( _gl.ARRAY_BUFFER, geometryGroup.__webglMorphTargetsBuffers[ influenceIndex ] );
-					enableAttribute( attributes[ "morphTarget" + m ] );
-					_gl.vertexAttribPointer( attributes[ "morphTarget" + m ], 3, _gl.FLOAT, false, 0, 0 );
+					if ( attributes[ "morphTarget" + m ] >= 0 ) {
 
-					if ( material.morphNormals ) {
+						_gl.bindBuffer( _gl.ARRAY_BUFFER, geometryGroup.__webglMorphTargetsBuffers[ influenceIndex ] );
+						enableAttribute( attributes[ "morphTarget" + m ] );
+						_gl.vertexAttribPointer( attributes[ "morphTarget" + m ], 3, _gl.FLOAT, false, 0, 0 );
+
+					}
+
+					if ( attributes[ "morphNormal" + m ] >= 0 && material.morphNormals ) {
 
 						_gl.bindBuffer( _gl.ARRAY_BUFFER, geometryGroup.__webglMorphNormalsBuffers[ influenceIndex ] );
 						enableAttribute( attributes[ "morphNormal" + m ] );
 						_gl.vertexAttribPointer( attributes[ "morphNormal" + m ], 3, _gl.FLOAT, false, 0, 0 );
 
+
 					}
 
 					object.__webglMorphTargetInfluences[ m ] = influences[ influenceIndex ];
 
 				} else {
 
+					/*
 					_gl.vertexAttribPointer( attributes[ "morphTarget" + m ], 3, _gl.FLOAT, false, 0, 0 );
 
 					if ( material.morphNormals ) {
@@ -19460,6 +19470,7 @@ THREE.WebGLRenderer = function ( parameters ) {
 						_gl.vertexAttribPointer( attributes[ "morphNormal" + m ], 3, _gl.FLOAT, false, 0, 0 );
 
 					}
+					*/
 
 					object.__webglMorphTargetInfluences[ m ] = 0;
 

+ 4 - 4
build/three.min.js

@@ -358,10 +358,10 @@ j&&(n=j.itemSize,k.bindBuffer(k.ARRAY_BUFFER,j.buffer),l(a.uv),k.vertexAttribPoi
 k.UNSIGNED_SHORT,2*d[c].start);H.info.render.calls++;H.info.render.vertices+=d[c].count;H.info.render.faces+=d[c].count/3}}else b&&(i=e.attributes.position,j=i.itemSize,k.bindBuffer(k.ARRAY_BUFFER,i.buffer),l(a.position),k.vertexAttribPointer(a.position,j,k.FLOAT,!1,0,0),j=e.attributes.normal,0<=a.normal&&j&&(n=j.itemSize,k.bindBuffer(k.ARRAY_BUFFER,j.buffer),l(a.normal),k.vertexAttribPointer(a.normal,n,k.FLOAT,!1,0,0)),j=e.attributes.uv,0<=a.uv&&j&&(n=j.itemSize,k.bindBuffer(k.ARRAY_BUFFER,j.buffer),
 l(a.uv),k.vertexAttribPointer(a.uv,n,k.FLOAT,!1,0,0)),j=e.attributes.color,0<=a.color&&j&&(n=j.itemSize,k.bindBuffer(k.ARRAY_BUFFER,j.buffer),l(a.color),k.vertexAttribPointer(a.color,n,k.FLOAT,!1,0,0)),j=e.attributes.tangent,0<=a.tangent&&j&&(n=j.itemSize,k.bindBuffer(k.ARRAY_BUFFER,j.buffer),l(a.tangent),k.vertexAttribPointer(a.tangent,n,k.FLOAT,!1,0,0))),k.drawArrays(k.TRIANGLES,0,i.numItems/3),H.info.render.calls++,H.info.render.vertices+=i.numItems/3,H.info.render.faces+=i.numItems/3/3;else f instanceof
 THREE.ParticleSystem&&b&&(i=e.attributes.position,j=i.itemSize,k.bindBuffer(k.ARRAY_BUFFER,i.buffer),l(a.position),k.vertexAttribPointer(a.position,j,k.FLOAT,!1,0,0),j=e.attributes.color,0<=a.color&&j&&(n=j.itemSize,k.bindBuffer(k.ARRAY_BUFFER,j.buffer),l(a.color),k.vertexAttribPointer(a.color,n,k.FLOAT,!1,0,0)),k.drawArrays(k.POINTS,0,i.numItems/3),H.info.render.calls++,H.info.render.points+=i.numItems/3)};this.renderBuffer=function(a,b,c,d,e,f){if(!1!==d.visible){var g,h,c=A(a,b,c,d,f),b=c.attributes,
-a=!1,c=16777215*e.id+2*c.id+(d.wireframe?1:0);c!==ba&&(ba=c,a=!0);a&&m();if(!d.morphTargets&&0<=b.position)a&&(k.bindBuffer(k.ARRAY_BUFFER,e.__webglVertexBuffer),l(b.position),k.vertexAttribPointer(b.position,3,k.FLOAT,!1,0,0));else if(f.morphTargetBase){c=d.program.attributes;-1!==f.morphTargetBase?(k.bindBuffer(k.ARRAY_BUFFER,e.__webglMorphTargetsBuffers[f.morphTargetBase]),l(c.position),k.vertexAttribPointer(c.position,3,k.FLOAT,!1,0,0)):0<=c.position&&(k.bindBuffer(k.ARRAY_BUFFER,e.__webglVertexBuffer),
-l(c.position),k.vertexAttribPointer(c.position,3,k.FLOAT,!1,0,0));if(f.morphTargetForcedOrder.length){var i=0;h=f.morphTargetForcedOrder;for(g=f.morphTargetInfluences;i<d.numSupportedMorphTargets&&i<h.length;)k.bindBuffer(k.ARRAY_BUFFER,e.__webglMorphTargetsBuffers[h[i]]),l(c["morphTarget"+i]),k.vertexAttribPointer(c["morphTarget"+i],3,k.FLOAT,!1,0,0),d.morphNormals&&(k.bindBuffer(k.ARRAY_BUFFER,e.__webglMorphNormalsBuffers[h[i]]),l(c["morphNormal"+i]),k.vertexAttribPointer(c["morphNormal"+i],3,k.FLOAT,
-!1,0,0)),f.__webglMorphTargetInfluences[i]=g[h[i]],i++}else{h=[];g=f.morphTargetInfluences;var j,n=g.length;for(j=0;j<n;j++)i=g[j],0<i&&h.push([j,i]);h.length>d.numSupportedMorphTargets?(h.sort(p),h.length=d.numSupportedMorphTargets):h.length>d.numSupportedMorphNormals?h.sort(p):0===h.length&&h.push([0,0]);for(i=0;i<d.numSupportedMorphTargets;)h[i]?(j=h[i][0],k.bindBuffer(k.ARRAY_BUFFER,e.__webglMorphTargetsBuffers[j]),l(c["morphTarget"+i]),k.vertexAttribPointer(c["morphTarget"+i],3,k.FLOAT,!1,0,
-0),d.morphNormals&&(k.bindBuffer(k.ARRAY_BUFFER,e.__webglMorphNormalsBuffers[j]),l(c["morphNormal"+i]),k.vertexAttribPointer(c["morphNormal"+i],3,k.FLOAT,!1,0,0)),f.__webglMorphTargetInfluences[i]=g[j]):(k.vertexAttribPointer(c["morphTarget"+i],3,k.FLOAT,!1,0,0),d.morphNormals&&k.vertexAttribPointer(c["morphNormal"+i],3,k.FLOAT,!1,0,0),f.__webglMorphTargetInfluences[i]=0),i++}null!==d.program.uniforms.morphTargetInfluences&&k.uniform1fv(d.program.uniforms.morphTargetInfluences,f.__webglMorphTargetInfluences)}if(a){if(e.__webglCustomAttributesList){g=
+a=!1,c=16777215*e.id+2*c.id+(d.wireframe?1:0);c!==ba&&(ba=c,a=!0);a&&m();if(!d.morphTargets&&0<=b.position)a&&(k.bindBuffer(k.ARRAY_BUFFER,e.__webglVertexBuffer),l(b.position),k.vertexAttribPointer(b.position,3,k.FLOAT,!1,0,0));else if(f.morphTargetBase){c=d.program.attributes;-1!==f.morphTargetBase&&0<=c.position?(k.bindBuffer(k.ARRAY_BUFFER,e.__webglMorphTargetsBuffers[f.morphTargetBase]),l(c.position),k.vertexAttribPointer(c.position,3,k.FLOAT,!1,0,0)):0<=c.position&&(k.bindBuffer(k.ARRAY_BUFFER,
+e.__webglVertexBuffer),l(c.position),k.vertexAttribPointer(c.position,3,k.FLOAT,!1,0,0));if(f.morphTargetForcedOrder.length){var i=0;h=f.morphTargetForcedOrder;for(g=f.morphTargetInfluences;i<d.numSupportedMorphTargets&&i<h.length;)0<=c["morphTarget"+i]&&(k.bindBuffer(k.ARRAY_BUFFER,e.__webglMorphTargetsBuffers[h[i]]),l(c["morphTarget"+i]),k.vertexAttribPointer(c["morphTarget"+i],3,k.FLOAT,!1,0,0)),0<=c["morphNormal"+i]&&d.morphNormals&&(k.bindBuffer(k.ARRAY_BUFFER,e.__webglMorphNormalsBuffers[h[i]]),
+l(c["morphNormal"+i]),k.vertexAttribPointer(c["morphNormal"+i],3,k.FLOAT,!1,0,0)),f.__webglMorphTargetInfluences[i]=g[h[i]],i++}else{h=[];g=f.morphTargetInfluences;var j,n=g.length;for(j=0;j<n;j++)i=g[j],0<i&&h.push([j,i]);h.length>d.numSupportedMorphTargets?(h.sort(p),h.length=d.numSupportedMorphTargets):h.length>d.numSupportedMorphNormals?h.sort(p):0===h.length&&h.push([0,0]);for(i=0;i<d.numSupportedMorphTargets;)h[i]?(j=h[i][0],0<=c["morphTarget"+i]&&(k.bindBuffer(k.ARRAY_BUFFER,e.__webglMorphTargetsBuffers[j]),
+l(c["morphTarget"+i]),k.vertexAttribPointer(c["morphTarget"+i],3,k.FLOAT,!1,0,0)),0<=c["morphNormal"+i]&&d.morphNormals&&(k.bindBuffer(k.ARRAY_BUFFER,e.__webglMorphNormalsBuffers[j]),l(c["morphNormal"+i]),k.vertexAttribPointer(c["morphNormal"+i],3,k.FLOAT,!1,0,0)),f.__webglMorphTargetInfluences[i]=g[j]):f.__webglMorphTargetInfluences[i]=0,i++}null!==d.program.uniforms.morphTargetInfluences&&k.uniform1fv(d.program.uniforms.morphTargetInfluences,f.__webglMorphTargetInfluences)}if(a){if(e.__webglCustomAttributesList){g=
 0;for(h=e.__webglCustomAttributesList.length;g<h;g++)c=e.__webglCustomAttributesList[g],0<=b[c.buffer.belongsToAttribute]&&(k.bindBuffer(k.ARRAY_BUFFER,c.buffer),l(b[c.buffer.belongsToAttribute]),k.vertexAttribPointer(b[c.buffer.belongsToAttribute],c.size,k.FLOAT,!1,0,0))}0<=b.color&&(k.bindBuffer(k.ARRAY_BUFFER,e.__webglColorBuffer),l(b.color),k.vertexAttribPointer(b.color,3,k.FLOAT,!1,0,0));0<=b.normal&&(k.bindBuffer(k.ARRAY_BUFFER,e.__webglNormalBuffer),l(b.normal),k.vertexAttribPointer(b.normal,
 3,k.FLOAT,!1,0,0));0<=b.tangent&&(k.bindBuffer(k.ARRAY_BUFFER,e.__webglTangentBuffer),l(b.tangent),k.vertexAttribPointer(b.tangent,4,k.FLOAT,!1,0,0));0<=b.uv&&(k.bindBuffer(k.ARRAY_BUFFER,e.__webglUVBuffer),l(b.uv),k.vertexAttribPointer(b.uv,2,k.FLOAT,!1,0,0));0<=b.uv2&&(k.bindBuffer(k.ARRAY_BUFFER,e.__webglUV2Buffer),l(b.uv2),k.vertexAttribPointer(b.uv2,2,k.FLOAT,!1,0,0));d.skinning&&(0<=b.skinIndex&&0<=b.skinWeight)&&(k.bindBuffer(k.ARRAY_BUFFER,e.__webglSkinIndicesBuffer),l(b.skinIndex),k.vertexAttribPointer(b.skinIndex,
 4,k.FLOAT,!1,0,0),k.bindBuffer(k.ARRAY_BUFFER,e.__webglSkinWeightsBuffer),l(b.skinWeight),k.vertexAttribPointer(b.skinWeight,4,k.FLOAT,!1,0,0));0<=b.lineDistance&&(k.bindBuffer(k.ARRAY_BUFFER,e.__webglLineDistanceBuffer),l(b.lineDistance),k.vertexAttribPointer(b.lineDistance,1,k.FLOAT,!1,0,0))}f instanceof THREE.Mesh?(d.wireframe?(d=d.wireframeLinewidth,d!==ra&&(k.lineWidth(d),ra=d),a&&k.bindBuffer(k.ELEMENT_ARRAY_BUFFER,e.__webglLineBuffer),k.drawElements(k.LINES,e.__webglLineCount,k.UNSIGNED_SHORT,

+ 20 - 9
src/renderers/WebGLRenderer.js

@@ -3727,7 +3727,7 @@ THREE.WebGLRenderer = function ( parameters ) {
 
 		var attributes = material.program.attributes;
 
-		if ( object.morphTargetBase !== -1 ) {
+		if ( object.morphTargetBase !== -1 && attributes.position >= 0 ) {
 
 			_gl.bindBuffer( _gl.ARRAY_BUFFER, geometryGroup.__webglMorphTargetsBuffers[ object.morphTargetBase ] );
 			enableAttribute( attributes.position );
@@ -3751,11 +3751,15 @@ THREE.WebGLRenderer = function ( parameters ) {
 
 			while ( m < material.numSupportedMorphTargets && m < order.length ) {
 
-				_gl.bindBuffer( _gl.ARRAY_BUFFER, geometryGroup.__webglMorphTargetsBuffers[ order[ m ] ] );
-				enableAttribute( attributes[ "morphTarget" + m ] );
-				_gl.vertexAttribPointer( attributes[ "morphTarget" + m ], 3, _gl.FLOAT, false, 0, 0 );
+				if ( attributes[ "morphTarget" + m ] >= 0 ) {
 
-				if ( material.morphNormals ) {
+					_gl.bindBuffer( _gl.ARRAY_BUFFER, geometryGroup.__webglMorphTargetsBuffers[ order[ m ] ] );
+					enableAttribute( attributes[ "morphTarget" + m ] );
+					_gl.vertexAttribPointer( attributes[ "morphTarget" + m ], 3, _gl.FLOAT, false, 0, 0 );
+
+				}
+
+				if ( attributes[ "morphNormal" + m ] >= 0 && material.morphNormals ) {
 
 					_gl.bindBuffer( _gl.ARRAY_BUFFER, geometryGroup.__webglMorphNormalsBuffers[ order[ m ] ] );
 					enableAttribute( attributes[ "morphNormal" + m ] );
@@ -3811,22 +3815,28 @@ THREE.WebGLRenderer = function ( parameters ) {
 
 					influenceIndex = activeInfluenceIndices[ m ][ 0 ];
 
-					_gl.bindBuffer( _gl.ARRAY_BUFFER, geometryGroup.__webglMorphTargetsBuffers[ influenceIndex ] );
-					enableAttribute( attributes[ "morphTarget" + m ] );
-					_gl.vertexAttribPointer( attributes[ "morphTarget" + m ], 3, _gl.FLOAT, false, 0, 0 );
+					if ( attributes[ "morphTarget" + m ] >= 0 ) {
 
-					if ( material.morphNormals ) {
+						_gl.bindBuffer( _gl.ARRAY_BUFFER, geometryGroup.__webglMorphTargetsBuffers[ influenceIndex ] );
+						enableAttribute( attributes[ "morphTarget" + m ] );
+						_gl.vertexAttribPointer( attributes[ "morphTarget" + m ], 3, _gl.FLOAT, false, 0, 0 );
+
+					}
+
+					if ( attributes[ "morphNormal" + m ] >= 0 && material.morphNormals ) {
 
 						_gl.bindBuffer( _gl.ARRAY_BUFFER, geometryGroup.__webglMorphNormalsBuffers[ influenceIndex ] );
 						enableAttribute( attributes[ "morphNormal" + m ] );
 						_gl.vertexAttribPointer( attributes[ "morphNormal" + m ], 3, _gl.FLOAT, false, 0, 0 );
 
+
 					}
 
 					object.__webglMorphTargetInfluences[ m ] = influences[ influenceIndex ];
 
 				} else {
 
+					/*
 					_gl.vertexAttribPointer( attributes[ "morphTarget" + m ], 3, _gl.FLOAT, false, 0, 0 );
 
 					if ( material.morphNormals ) {
@@ -3834,6 +3844,7 @@ THREE.WebGLRenderer = function ( parameters ) {
 						_gl.vertexAttribPointer( attributes[ "morphNormal" + m ], 3, _gl.FLOAT, false, 0, 0 );
 
 					}
+					*/
 
 					object.__webglMorphTargetInfluences[ m ] = 0;