Browse Source

Added automatic deallocation of previous shader program on material update.

As per discussion in #1803.

It's really hard to tell if this has any affect at all as shader creation by itself is so costly it dwarfs everything else.
alteredq 13 years ago
parent
commit
2fd0b1b14d
3 changed files with 30 additions and 28 deletions
  1. 8 8
      build/Three.js
  2. 20 20
      build/custom/ThreeWebGL.js
  3. 2 0
      src/renderers/WebGLRenderer.js

+ 8 - 8
build/Three.js

@@ -290,14 +290,14 @@ g=h.value[g];h.array[f]=g.x;h.array[f+1]=g.y;h.array[f+2]=g.z;h.array[f+3]=g.w;f
 m,b)}if(q){k=0;for(j=q.length;k<j;k++){h=q[k];if(h.needsUpdate||c.sortParticles){i.bindBuffer(i.ARRAY_BUFFER,h.buffer);i.bufferData(i.ARRAY_BUFFER,h.array,b)}}}}function g(a,b){return b.z-a.z}function h(a,b){return b[1]-a[1]}function k(a,b,c){if(a.length)for(var d=0,e=a.length;d<e;d++){ha=ba=null;fa=Z=T=Y=oa=Oa=$=-1;la=true;a[d].render(b,c,ab,Ba);ha=ba=null;fa=Z=T=Y=oa=Oa=$=-1;la=true}}function j(a,b,c,d,e,f,g,h){var i,k,j,l;if(b){k=a.length-1;l=b=-1}else{k=0;b=a.length;l=1}for(var m=k;m!==b;m=m+
 l){i=a[m];if(i.render){k=i.object;j=i.buffer;if(h)i=h;else{i=i[c];if(!i)continue;g&&H.setBlending(i.blending,i.blendEquation,i.blendSrc,i.blendDst);H.setDepthTest(i.depthTest);H.setDepthWrite(i.depthWrite);t(i.polygonOffset,i.polygonOffsetFactor,i.polygonOffsetUnits)}H.setObjectFaces(k);j instanceof THREE.BufferGeometry?H.renderBufferDirect(d,e,f,i,j,k):H.renderBuffer(d,e,f,i,j,k)}}}function l(a,b,c,d,e,f,g){for(var h,i,k=0,j=a.length;k<j;k++){h=a[k];i=h.object;if(i.visible){if(g)h=g;else{h=h[b];
 if(!h)continue;f&&H.setBlending(h.blending,h.blendEquation,h.blendSrc,h.blendDst);H.setDepthTest(h.depthTest);H.setDepthWrite(h.depthWrite);t(h.polygonOffset,h.polygonOffsetFactor,h.polygonOffsetUnits)}H.renderImmediateObject(c,d,e,h,i)}}}function o(a,b,c){a.push({buffer:b,object:c,opaque:null,transparent:null})}function m(a){for(var b in a.attributes)if(a.attributes[b].needsUpdate)return true;return false}function p(a){for(var b in a.attributes)a.attributes[b].needsUpdate=false}function q(a,b){for(var c=
-a.length-1;c>=0;c--)a[c].object===b&&a.splice(c,1)}function n(a,b){for(var c=a.length-1;c>=0;c--)a[c]===b&&a.splice(c,1)}function r(a,b,c,d,e){if(!d.program||d.needsUpdate){H.initMaterial(d,b,c,e);d.needsUpdate=false}if(d.morphTargets&&!e.__webglMorphTargetInfluences){e.__webglMorphTargetInfluences=new Float32Array(H.maxMorphTargets);for(var f=0,g=H.maxMorphTargets;f<g;f++)e.__webglMorphTargetInfluences[f]=0}var h=false,f=d.program,g=f.uniforms,k=d.uniforms;if(f!==ba){i.useProgram(f);ba=f;h=true}if(d.id!==
-fa){fa=d.id;h=true}if(h||a!==ha){i.uniformMatrix4fv(g.projectionMatrix,false,a._projectionMatrixArray);a!==ha&&(ha=a)}if(h){if(c&&d.fog){k.fogColor.value=c.color;if(c instanceof THREE.Fog){k.fogNear.value=c.near;k.fogFar.value=c.far}else if(c instanceof THREE.FogExp2)k.fogDensity.value=c.density}if(d instanceof THREE.MeshPhongMaterial||d instanceof THREE.MeshLambertMaterial||d.lights){if(la){for(var j,l=0,m=0,n=0,o,p,q,r=bb,u=r.directional.colors,t=r.directional.positions,v=r.point.colors,x=r.point.positions,
-y=r.point.distances,B=r.spot.colors,J=r.spot.positions,E=r.spot.distances,G=r.spot.directions,Y=r.spot.angles,D=r.spot.exponents,L=0,M=0,N=0,I=q=0,c=I=0,h=b.length;c<h;c++){j=b[c];if(!j.onlyShadow){o=j.color;p=j.intensity;q=j.distance;if(j instanceof THREE.AmbientLight)if(H.gammaInput){l=l+o.r*o.r;m=m+o.g*o.g;n=n+o.b*o.b}else{l=l+o.r;m=m+o.g;n=n+o.b}else if(j instanceof THREE.DirectionalLight){q=L*3;if(H.gammaInput){u[q]=o.r*o.r*p*p;u[q+1]=o.g*o.g*p*p;u[q+2]=o.b*o.b*p*p}else{u[q]=o.r*p;u[q+1]=o.g*
-p;u[q+2]=o.b*p}Da.copy(j.matrixWorld.getPosition());Da.subSelf(j.target.matrixWorld.getPosition());Da.normalize();t[q]=Da.x;t[q+1]=Da.y;t[q+2]=Da.z;L=L+1}else if(j instanceof THREE.PointLight){I=M*3;if(H.gammaInput){v[I]=o.r*o.r*p*p;v[I+1]=o.g*o.g*p*p;v[I+2]=o.b*o.b*p*p}else{v[I]=o.r*p;v[I+1]=o.g*p;v[I+2]=o.b*p}o=j.matrixWorld.getPosition();x[I]=o.x;x[I+1]=o.y;x[I+2]=o.z;y[M]=q;M=M+1}else if(j instanceof THREE.SpotLight){I=N*3;if(H.gammaInput){B[I]=o.r*o.r*p*p;B[I+1]=o.g*o.g*p*p;B[I+2]=o.b*o.b*p*
-p}else{B[I]=o.r*p;B[I+1]=o.g*p;B[I+2]=o.b*p}o=j.matrixWorld.getPosition();J[I]=o.x;J[I+1]=o.y;J[I+2]=o.z;E[N]=q;Da.copy(o);Da.subSelf(j.target.matrixWorld.getPosition());Da.normalize();G[I]=Da.x;G[I+1]=Da.y;G[I+2]=Da.z;Y[N]=Math.cos(j.angle);D[N]=j.exponent;N=N+1}}}c=L*3;for(h=u.length;c<h;c++)u[c]=0;c=M*3;for(h=v.length;c<h;c++)v[c]=0;c=N*3;for(h=B.length;c<h;c++)B[c]=0;r.directional.length=L;r.point.length=M;r.spot.length=N;r.ambient[0]=l;r.ambient[1]=m;r.ambient[2]=n;la=false}c=bb;k.ambientLightColor.value=
-c.ambient;k.directionalLightColor.value=c.directional.colors;k.directionalLightDirection.value=c.directional.positions;k.pointLightColor.value=c.point.colors;k.pointLightPosition.value=c.point.positions;k.pointLightDistance.value=c.point.distances;k.spotLightColor.value=c.spot.colors;k.spotLightPosition.value=c.spot.positions;k.spotLightDistance.value=c.spot.distances;k.spotLightDirection.value=c.spot.directions;k.spotLightAngle.value=c.spot.angles;k.spotLightExponent.value=c.spot.exponents}if(d instanceof
-THREE.MeshBasicMaterial||d instanceof THREE.MeshLambertMaterial||d instanceof THREE.MeshPhongMaterial){k.opacity.value=d.opacity;H.gammaInput?k.diffuse.value.copyGammaToLinear(d.color):k.diffuse.value=d.color;(k.map.texture=d.map)&&k.offsetRepeat.value.set(d.map.offset.x,d.map.offset.y,d.map.repeat.x,d.map.repeat.y);k.lightMap.texture=d.lightMap;k.envMap.texture=d.envMap;k.flipEnvMap.value=d.envMap instanceof THREE.WebGLRenderTargetCube?1:-1;k.reflectivity.value=d.reflectivity;k.refractionRatio.value=
-d.refractionRatio;k.combine.value=d.combine;k.useRefract.value=d.envMap&&d.envMap.mapping instanceof THREE.CubeRefractionMapping}if(d instanceof THREE.LineBasicMaterial){k.diffuse.value=d.color;k.opacity.value=d.opacity}else if(d instanceof THREE.ParticleBasicMaterial){k.psColor.value=d.color;k.opacity.value=d.opacity;k.size.value=d.size;k.scale.value=z.height/2;k.map.texture=d.map}else if(d instanceof THREE.MeshPhongMaterial){k.shininess.value=d.shininess;if(H.gammaInput){k.ambient.value.copyGammaToLinear(d.ambient);
+a.length-1;c>=0;c--)a[c].object===b&&a.splice(c,1)}function n(a,b){for(var c=a.length-1;c>=0;c--)a[c]===b&&a.splice(c,1)}function r(a,b,c,d,e){if(!d.program||d.needsUpdate){d.program&&H.deallocateMaterial(d);H.initMaterial(d,b,c,e);d.needsUpdate=false}if(d.morphTargets&&!e.__webglMorphTargetInfluences){e.__webglMorphTargetInfluences=new Float32Array(H.maxMorphTargets);for(var f=0,g=H.maxMorphTargets;f<g;f++)e.__webglMorphTargetInfluences[f]=0}var h=false,f=d.program,g=f.uniforms,k=d.uniforms;if(f!==
+ba){i.useProgram(f);ba=f;h=true}if(d.id!==fa){fa=d.id;h=true}if(h||a!==ha){i.uniformMatrix4fv(g.projectionMatrix,false,a._projectionMatrixArray);a!==ha&&(ha=a)}if(h){if(c&&d.fog){k.fogColor.value=c.color;if(c instanceof THREE.Fog){k.fogNear.value=c.near;k.fogFar.value=c.far}else if(c instanceof THREE.FogExp2)k.fogDensity.value=c.density}if(d instanceof THREE.MeshPhongMaterial||d instanceof THREE.MeshLambertMaterial||d.lights){if(la){for(var j,l=0,m=0,n=0,o,p,q,r=bb,u=r.directional.colors,t=r.directional.positions,
+v=r.point.colors,x=r.point.positions,y=r.point.distances,B=r.spot.colors,J=r.spot.positions,E=r.spot.distances,G=r.spot.directions,Y=r.spot.angles,D=r.spot.exponents,L=0,M=0,N=0,I=q=0,c=I=0,h=b.length;c<h;c++){j=b[c];if(!j.onlyShadow){o=j.color;p=j.intensity;q=j.distance;if(j instanceof THREE.AmbientLight)if(H.gammaInput){l=l+o.r*o.r;m=m+o.g*o.g;n=n+o.b*o.b}else{l=l+o.r;m=m+o.g;n=n+o.b}else if(j instanceof THREE.DirectionalLight){q=L*3;if(H.gammaInput){u[q]=o.r*o.r*p*p;u[q+1]=o.g*o.g*p*p;u[q+2]=o.b*
+o.b*p*p}else{u[q]=o.r*p;u[q+1]=o.g*p;u[q+2]=o.b*p}Da.copy(j.matrixWorld.getPosition());Da.subSelf(j.target.matrixWorld.getPosition());Da.normalize();t[q]=Da.x;t[q+1]=Da.y;t[q+2]=Da.z;L=L+1}else if(j instanceof THREE.PointLight){I=M*3;if(H.gammaInput){v[I]=o.r*o.r*p*p;v[I+1]=o.g*o.g*p*p;v[I+2]=o.b*o.b*p*p}else{v[I]=o.r*p;v[I+1]=o.g*p;v[I+2]=o.b*p}o=j.matrixWorld.getPosition();x[I]=o.x;x[I+1]=o.y;x[I+2]=o.z;y[M]=q;M=M+1}else if(j instanceof THREE.SpotLight){I=N*3;if(H.gammaInput){B[I]=o.r*o.r*p*p;B[I+
+1]=o.g*o.g*p*p;B[I+2]=o.b*o.b*p*p}else{B[I]=o.r*p;B[I+1]=o.g*p;B[I+2]=o.b*p}o=j.matrixWorld.getPosition();J[I]=o.x;J[I+1]=o.y;J[I+2]=o.z;E[N]=q;Da.copy(o);Da.subSelf(j.target.matrixWorld.getPosition());Da.normalize();G[I]=Da.x;G[I+1]=Da.y;G[I+2]=Da.z;Y[N]=Math.cos(j.angle);D[N]=j.exponent;N=N+1}}}c=L*3;for(h=u.length;c<h;c++)u[c]=0;c=M*3;for(h=v.length;c<h;c++)v[c]=0;c=N*3;for(h=B.length;c<h;c++)B[c]=0;r.directional.length=L;r.point.length=M;r.spot.length=N;r.ambient[0]=l;r.ambient[1]=m;r.ambient[2]=
+n;la=false}c=bb;k.ambientLightColor.value=c.ambient;k.directionalLightColor.value=c.directional.colors;k.directionalLightDirection.value=c.directional.positions;k.pointLightColor.value=c.point.colors;k.pointLightPosition.value=c.point.positions;k.pointLightDistance.value=c.point.distances;k.spotLightColor.value=c.spot.colors;k.spotLightPosition.value=c.spot.positions;k.spotLightDistance.value=c.spot.distances;k.spotLightDirection.value=c.spot.directions;k.spotLightAngle.value=c.spot.angles;k.spotLightExponent.value=
+c.spot.exponents}if(d instanceof THREE.MeshBasicMaterial||d instanceof THREE.MeshLambertMaterial||d instanceof THREE.MeshPhongMaterial){k.opacity.value=d.opacity;H.gammaInput?k.diffuse.value.copyGammaToLinear(d.color):k.diffuse.value=d.color;(k.map.texture=d.map)&&k.offsetRepeat.value.set(d.map.offset.x,d.map.offset.y,d.map.repeat.x,d.map.repeat.y);k.lightMap.texture=d.lightMap;k.envMap.texture=d.envMap;k.flipEnvMap.value=d.envMap instanceof THREE.WebGLRenderTargetCube?1:-1;k.reflectivity.value=d.reflectivity;
+k.refractionRatio.value=d.refractionRatio;k.combine.value=d.combine;k.useRefract.value=d.envMap&&d.envMap.mapping instanceof THREE.CubeRefractionMapping}if(d instanceof THREE.LineBasicMaterial){k.diffuse.value=d.color;k.opacity.value=d.opacity}else if(d instanceof THREE.ParticleBasicMaterial){k.psColor.value=d.color;k.opacity.value=d.opacity;k.size.value=d.size;k.scale.value=z.height/2;k.map.texture=d.map}else if(d instanceof THREE.MeshPhongMaterial){k.shininess.value=d.shininess;if(H.gammaInput){k.ambient.value.copyGammaToLinear(d.ambient);
 k.emissive.value.copyGammaToLinear(d.emissive);k.specular.value.copyGammaToLinear(d.specular)}else{k.ambient.value=d.ambient;k.emissive.value=d.emissive;k.specular.value=d.specular}d.wrapAround&&k.wrapRGB.value.copy(d.wrapRGB)}else if(d instanceof THREE.MeshLambertMaterial){if(H.gammaInput){k.ambient.value.copyGammaToLinear(d.ambient);k.emissive.value.copyGammaToLinear(d.emissive)}else{k.ambient.value=d.ambient;k.emissive.value=d.emissive}d.wrapAround&&k.wrapRGB.value.copy(d.wrapRGB)}else if(d instanceof
 THREE.MeshDepthMaterial){k.mNear.value=a.near;k.mFar.value=a.far;k.opacity.value=d.opacity}else if(d instanceof THREE.MeshNormalMaterial)k.opacity.value=d.opacity;if(e.receiveShadow&&!d._shadowPass&&k.shadowMatrix){h=c=0;for(j=b.length;h<j;h++){l=b[h];if(l.castShadow&&(l instanceof THREE.SpotLight||l instanceof THREE.DirectionalLight&&!l.shadowCascade)){k.shadowMap.texture[c]=l.shadowMap;k.shadowMapSize.value[c]=l.shadowMapSize;k.shadowMatrix.value[c]=l.shadowMatrix;k.shadowDarkness.value[c]=l.shadowDarkness;
 k.shadowBias.value[c]=l.shadowBias;c++}}}b=d.uniformsList;k=0;for(c=b.length;k<c;k++)if(l=f.uniforms[b[k][1]]){h=b[k][0];m=h.type;j=h.value;switch(m){case "i":i.uniform1i(l,j);break;case "f":i.uniform1f(l,j);break;case "v2":i.uniform2f(l,j.x,j.y);break;case "v3":i.uniform3f(l,j.x,j.y,j.z);break;case "v4":i.uniform4f(l,j.x,j.y,j.z,j.w);break;case "c":i.uniform3f(l,j.r,j.g,j.b);break;case "fv1":i.uniform1fv(l,j);break;case "fv":i.uniform3fv(l,j);break;case "v2v":if(!h._array)h._array=new Float32Array(2*

+ 20 - 20
build/custom/ThreeWebGL.js

@@ -254,26 +254,26 @@ h=i.value[h];i.array[g]=h.x;i.array[g+1]=h.y;i.array[g+2]=h.z;i.array[g+3]=h.w;g
 m,b)}if(r){j=0;for(l=r.length;j<l;j++){i=r[j];if(i.needsUpdate||c.sortParticles){f.bindBuffer(f.ARRAY_BUFFER,i.buffer);f.bufferData(f.ARRAY_BUFFER,i.array,b)}}}}function h(a,b){return b.z-a.z}function k(a,b){return b[1]-a[1]}function m(a,b,c){if(a.length)for(var d=0,f=a.length;d<f;d++){ga=za=null;na=ca=Ha=Ba=nb=Xa=Ia=-1;ob=true;a[d].render(b,c,$b,ac);ga=za=null;na=ca=Ha=Ba=nb=Xa=Ia=-1;ob=true}}function j(a,b,c,d,f,e,g,h){var i,j,l,k;if(b){j=a.length-1;k=b=-1}else{j=0;b=a.length;k=1}for(var m=j;m!==
 b;m=m+k){i=a[m];if(i.render){j=i.object;l=i.buffer;if(h)i=h;else{i=i[c];if(!i)continue;g&&E.setBlending(i.blending,i.blendEquation,i.blendSrc,i.blendDst);E.setDepthTest(i.depthTest);E.setDepthWrite(i.depthWrite);q(i.polygonOffset,i.polygonOffsetFactor,i.polygonOffsetUnits)}E.setObjectFaces(j);l instanceof THREE.BufferGeometry?E.renderBufferDirect(d,f,e,i,l,j):E.renderBuffer(d,f,e,i,l,j)}}}function i(a,b,c,d,f,e,g){for(var i,h,j=0,l=a.length;j<l;j++){i=a[j];h=i.object;if(h.visible){if(g)i=g;else{i=
 i[b];if(!i)continue;e&&E.setBlending(i.blending,i.blendEquation,i.blendSrc,i.blendDst);E.setDepthTest(i.depthTest);E.setDepthWrite(i.depthWrite);q(i.polygonOffset,i.polygonOffsetFactor,i.polygonOffsetUnits)}E.renderImmediateObject(c,d,f,i,h)}}}function p(a,b,c){a.push({buffer:b,object:c,opaque:null,transparent:null})}function l(a){for(var b in a.attributes)if(a.attributes[b].needsUpdate)return true;return false}function v(a){for(var b in a.attributes)a.attributes[b].needsUpdate=false}function o(a,
-b){for(var c=a.length-1;c>=0;c--)a[c].object===b&&a.splice(c,1)}function n(a,b){for(var c=a.length-1;c>=0;c--)a[c]===b&&a.splice(c,1)}function r(a,b,c,d,e){if(!d.program||d.needsUpdate){E.initMaterial(d,b,c,e);d.needsUpdate=false}if(d.morphTargets&&!e.__webglMorphTargetInfluences){e.__webglMorphTargetInfluences=new Float32Array(E.maxMorphTargets);for(var g=0,i=E.maxMorphTargets;g<i;g++)e.__webglMorphTargetInfluences[g]=0}var h=false,g=d.program,i=g.uniforms,j=d.uniforms;if(g!==za){f.useProgram(g);
-za=g;h=true}if(d.id!==na){na=d.id;h=true}if(h||a!==ga){f.uniformMatrix4fv(i.projectionMatrix,false,a._projectionMatrixArray);a!==ga&&(ga=a)}if(h){if(c&&d.fog){j.fogColor.value=c.color;if(c instanceof THREE.Fog){j.fogNear.value=c.near;j.fogFar.value=c.far}else if(c instanceof THREE.FogExp2)j.fogDensity.value=c.density}if(d instanceof THREE.MeshPhongMaterial||d instanceof THREE.MeshLambertMaterial||d.lights){if(ob){for(var l,k=0,m=0,n=0,p,o,r,q=bc,v=q.directional.colors,s=q.directional.positions,w=
-q.point.colors,z=q.point.positions,H=q.point.distances,D=q.spot.colors,F=q.spot.positions,L=q.spot.distances,K=q.spot.directions,M=q.spot.angles,Q=q.spot.exponents,R=0,T=0,S=0,I=r=0,c=I=0,h=b.length;c<h;c++){l=b[c];if(!l.onlyShadow){p=l.color;o=l.intensity;r=l.distance;if(l instanceof THREE.AmbientLight)if(E.gammaInput){k=k+p.r*p.r;m=m+p.g*p.g;n=n+p.b*p.b}else{k=k+p.r;m=m+p.g;n=n+p.b}else if(l instanceof THREE.DirectionalLight){r=R*3;if(E.gammaInput){v[r]=p.r*p.r*o*o;v[r+1]=p.g*p.g*o*o;v[r+2]=p.b*
-p.b*o*o}else{v[r]=p.r*o;v[r+1]=p.g*o;v[r+2]=p.b*o}Ca.copy(l.matrixWorld.getPosition());Ca.subSelf(l.target.matrixWorld.getPosition());Ca.normalize();s[r]=Ca.x;s[r+1]=Ca.y;s[r+2]=Ca.z;R=R+1}else if(l instanceof THREE.PointLight){I=T*3;if(E.gammaInput){w[I]=p.r*p.r*o*o;w[I+1]=p.g*p.g*o*o;w[I+2]=p.b*p.b*o*o}else{w[I]=p.r*o;w[I+1]=p.g*o;w[I+2]=p.b*o}p=l.matrixWorld.getPosition();z[I]=p.x;z[I+1]=p.y;z[I+2]=p.z;H[T]=r;T=T+1}else if(l instanceof THREE.SpotLight){I=S*3;if(E.gammaInput){D[I]=p.r*p.r*o*o;D[I+
-1]=p.g*p.g*o*o;D[I+2]=p.b*p.b*o*o}else{D[I]=p.r*o;D[I+1]=p.g*o;D[I+2]=p.b*o}p=l.matrixWorld.getPosition();F[I]=p.x;F[I+1]=p.y;F[I+2]=p.z;L[S]=r;Ca.copy(p);Ca.subSelf(l.target.matrixWorld.getPosition());Ca.normalize();K[I]=Ca.x;K[I+1]=Ca.y;K[I+2]=Ca.z;M[S]=Math.cos(l.angle);Q[S]=l.exponent;S=S+1}}}c=R*3;for(h=v.length;c<h;c++)v[c]=0;c=T*3;for(h=w.length;c<h;c++)w[c]=0;c=S*3;for(h=D.length;c<h;c++)D[c]=0;q.directional.length=R;q.point.length=T;q.spot.length=S;q.ambient[0]=k;q.ambient[1]=m;q.ambient[2]=
-n;ob=false}c=bc;j.ambientLightColor.value=c.ambient;j.directionalLightColor.value=c.directional.colors;j.directionalLightDirection.value=c.directional.positions;j.pointLightColor.value=c.point.colors;j.pointLightPosition.value=c.point.positions;j.pointLightDistance.value=c.point.distances;j.spotLightColor.value=c.spot.colors;j.spotLightPosition.value=c.spot.positions;j.spotLightDistance.value=c.spot.distances;j.spotLightDirection.value=c.spot.directions;j.spotLightAngle.value=c.spot.angles;j.spotLightExponent.value=
-c.spot.exponents}if(d instanceof THREE.MeshBasicMaterial||d instanceof THREE.MeshLambertMaterial||d instanceof THREE.MeshPhongMaterial){j.opacity.value=d.opacity;E.gammaInput?j.diffuse.value.copyGammaToLinear(d.color):j.diffuse.value=d.color;(j.map.texture=d.map)&&j.offsetRepeat.value.set(d.map.offset.x,d.map.offset.y,d.map.repeat.x,d.map.repeat.y);j.lightMap.texture=d.lightMap;j.envMap.texture=d.envMap;j.flipEnvMap.value=d.envMap instanceof THREE.WebGLRenderTargetCube?1:-1;j.reflectivity.value=d.reflectivity;
-j.refractionRatio.value=d.refractionRatio;j.combine.value=d.combine;j.useRefract.value=d.envMap&&d.envMap.mapping instanceof THREE.CubeRefractionMapping}if(d instanceof THREE.LineBasicMaterial){j.diffuse.value=d.color;j.opacity.value=d.opacity}else if(d instanceof THREE.ParticleBasicMaterial){j.psColor.value=d.color;j.opacity.value=d.opacity;j.size.value=d.size;j.scale.value=G.height/2;j.map.texture=d.map}else if(d instanceof THREE.MeshPhongMaterial){j.shininess.value=d.shininess;if(E.gammaInput){j.ambient.value.copyGammaToLinear(d.ambient);
-j.emissive.value.copyGammaToLinear(d.emissive);j.specular.value.copyGammaToLinear(d.specular)}else{j.ambient.value=d.ambient;j.emissive.value=d.emissive;j.specular.value=d.specular}d.wrapAround&&j.wrapRGB.value.copy(d.wrapRGB)}else if(d instanceof THREE.MeshLambertMaterial){if(E.gammaInput){j.ambient.value.copyGammaToLinear(d.ambient);j.emissive.value.copyGammaToLinear(d.emissive)}else{j.ambient.value=d.ambient;j.emissive.value=d.emissive}d.wrapAround&&j.wrapRGB.value.copy(d.wrapRGB)}else if(d instanceof
-THREE.MeshDepthMaterial){j.mNear.value=a.near;j.mFar.value=a.far;j.opacity.value=d.opacity}else if(d instanceof THREE.MeshNormalMaterial)j.opacity.value=d.opacity;if(e.receiveShadow&&!d._shadowPass&&j.shadowMatrix){h=c=0;for(l=b.length;h<l;h++){k=b[h];if(k.castShadow&&(k instanceof THREE.SpotLight||k instanceof THREE.DirectionalLight&&!k.shadowCascade)){j.shadowMap.texture[c]=k.shadowMap;j.shadowMapSize.value[c]=k.shadowMapSize;j.shadowMatrix.value[c]=k.shadowMatrix;j.shadowDarkness.value[c]=k.shadowDarkness;
-j.shadowBias.value[c]=k.shadowBias;c++}}}b=d.uniformsList;j=0;for(c=b.length;j<c;j++)if(k=g.uniforms[b[j][1]]){h=b[j][0];m=h.type;l=h.value;switch(m){case "i":f.uniform1i(k,l);break;case "f":f.uniform1f(k,l);break;case "v2":f.uniform2f(k,l.x,l.y);break;case "v3":f.uniform3f(k,l.x,l.y,l.z);break;case "v4":f.uniform4f(k,l.x,l.y,l.z,l.w);break;case "c":f.uniform3f(k,l.r,l.g,l.b);break;case "fv1":f.uniform1fv(k,l);break;case "fv":f.uniform3fv(k,l);break;case "v2v":if(!h._array)h._array=new Float32Array(2*
-l.length);m=0;for(n=l.length;m<n;m++){q=m*2;h._array[q]=l[m].x;h._array[q+1]=l[m].y}f.uniform2fv(k,h._array);break;case "v3v":if(!h._array)h._array=new Float32Array(3*l.length);m=0;for(n=l.length;m<n;m++){q=m*3;h._array[q]=l[m].x;h._array[q+1]=l[m].y;h._array[q+2]=l[m].z}f.uniform3fv(k,h._array);break;case "v4v":if(!h._array)h._array=new Float32Array(4*l.length);m=0;for(n=l.length;m<n;m++){q=m*4;h._array[q]=l[m].x;h._array[q+1]=l[m].y;h._array[q+2]=l[m].z;h._array[q+3]=l[m].w}f.uniform4fv(k,h._array);
-break;case "m4":if(!h._array)h._array=new Float32Array(16);l.flattenToArray(h._array);f.uniformMatrix4fv(k,false,h._array);break;case "m4v":if(!h._array)h._array=new Float32Array(16*l.length);m=0;for(n=l.length;m<n;m++)l[m].flattenToArrayOffset(h._array,m*16);f.uniformMatrix4fv(k,false,h._array);break;case "t":f.uniform1i(k,l);k=h.texture;if(!k)continue;if(k.image instanceof Array&&k.image.length===6){h=k;if(h.image.length===6)if(h.needsUpdate){if(!h.image.__webglTextureCube)h.image.__webglTextureCube=
-f.createTexture();f.activeTexture(f.TEXTURE0+l);f.bindTexture(f.TEXTURE_CUBE_MAP,h.image.__webglTextureCube);l=[];for(k=0;k<6;k++){m=l;n=k;if(E.autoScaleCubemaps){q=h.image[k];s=Kc;if(!(q.width<=s&&q.height<=s)){w=Math.max(q.width,q.height);v=Math.floor(q.width*s/w);s=Math.floor(q.height*s/w);w=document.createElement("canvas");w.width=v;w.height=s;w.getContext("2d").drawImage(q,0,0,q.width,q.height,0,0,v,s);q=w}}else q=h.image[k];m[n]=q}k=l[0];m=(k.width&k.width-1)===0&&(k.height&k.height-1)===0;
-n=A(h.format);q=A(h.type);C(f.TEXTURE_CUBE_MAP,h,m);for(k=0;k<6;k++)f.texImage2D(f.TEXTURE_CUBE_MAP_POSITIVE_X+k,0,n,n,q,l[k]);h.generateMipmaps&&m&&f.generateMipmap(f.TEXTURE_CUBE_MAP);h.needsUpdate=false;if(h.onUpdate)h.onUpdate()}else{f.activeTexture(f.TEXTURE0+l);f.bindTexture(f.TEXTURE_CUBE_MAP,h.image.__webglTextureCube)}}else if(k instanceof THREE.WebGLRenderTargetCube){h=k;f.activeTexture(f.TEXTURE0+l);f.bindTexture(f.TEXTURE_CUBE_MAP,h.__webglTexture)}else E.setTexture(k,l);break;case "tv":if(!h._array){h._array=
-[];m=0;for(n=h.texture.length;m<n;m++)h._array[m]=l+m}f.uniform1iv(k,h._array);m=0;for(n=h.texture.length;m<n;m++)(k=h.texture[m])&&E.setTexture(k,h._array[m])}}if((d instanceof THREE.ShaderMaterial||d instanceof THREE.MeshPhongMaterial||d.envMap)&&i.cameraPosition!==null){b=a.matrixWorld.getPosition();f.uniform3f(i.cameraPosition,b.x,b.y,b.z)}(d instanceof THREE.MeshPhongMaterial||d instanceof THREE.MeshLambertMaterial||d instanceof THREE.ShaderMaterial||d.skinning)&&i.viewMatrix!==null&&f.uniformMatrix4fv(i.viewMatrix,
-false,a._viewMatrixArray);d.skinning&&f.uniformMatrix4fv(i.boneGlobalMatrices,false,e.boneMatrices)}f.uniformMatrix4fv(i.modelViewMatrix,false,e._modelViewMatrix.elements);i.normalMatrix&&f.uniformMatrix3fv(i.normalMatrix,false,e._normalMatrix.elements);i.objectMatrix!==null&&f.uniformMatrix4fv(i.objectMatrix,false,e.matrixWorld.elements);return g}function w(a,b){a._modelViewMatrix.multiply(b.matrixWorldInverse,a.matrixWorld);a._normalMatrix.getInverse(a._modelViewMatrix);a._normalMatrix.transpose()}
-function q(a,b,c){if(sc!==a){a?f.enable(f.POLYGON_OFFSET_FILL):f.disable(f.POLYGON_OFFSET_FILL);sc=a}if(a&&(tc!==b||uc!==c)){f.polygonOffset(b,c);tc=b;uc=c}}function F(a,b){var c;a==="fragment"?c=f.createShader(f.FRAGMENT_SHADER):a==="vertex"&&(c=f.createShader(f.VERTEX_SHADER));f.shaderSource(c,b);f.compileShader(c);if(!f.getShaderParameter(c,f.COMPILE_STATUS)){console.error(f.getShaderInfoLog(c));console.error(b);return null}return c}function C(a,b,c){if(c){f.texParameteri(a,f.TEXTURE_WRAP_S,A(b.wrapS));
-f.texParameteri(a,f.TEXTURE_WRAP_T,A(b.wrapT));f.texParameteri(a,f.TEXTURE_MAG_FILTER,A(b.magFilter));f.texParameteri(a,f.TEXTURE_MIN_FILTER,A(b.minFilter))}else{f.texParameteri(a,f.TEXTURE_WRAP_S,f.CLAMP_TO_EDGE);f.texParameteri(a,f.TEXTURE_WRAP_T,f.CLAMP_TO_EDGE);f.texParameteri(a,f.TEXTURE_MAG_FILTER,K(b.magFilter));f.texParameteri(a,f.TEXTURE_MIN_FILTER,K(b.minFilter))}}function s(a,b){f.bindRenderbuffer(f.RENDERBUFFER,a);if(b.depthBuffer&&!b.stencilBuffer){f.renderbufferStorage(f.RENDERBUFFER,
-f.DEPTH_COMPONENT16,b.width,b.height);f.framebufferRenderbuffer(f.FRAMEBUFFER,f.DEPTH_ATTACHMENT,f.RENDERBUFFER,a)}else if(b.depthBuffer&&b.stencilBuffer){f.renderbufferStorage(f.RENDERBUFFER,f.DEPTH_STENCIL,b.width,b.height);f.framebufferRenderbuffer(f.FRAMEBUFFER,f.DEPTH_STENCIL_ATTACHMENT,f.RENDERBUFFER,a)}else f.renderbufferStorage(f.RENDERBUFFER,f.RGBA4,b.width,b.height)}function K(a){switch(a){case THREE.NearestFilter:case THREE.NearestMipMapNearestFilter:case THREE.NearestMipMapLinearFilter:return f.NEAREST;
+b){for(var c=a.length-1;c>=0;c--)a[c].object===b&&a.splice(c,1)}function n(a,b){for(var c=a.length-1;c>=0;c--)a[c]===b&&a.splice(c,1)}function r(a,b,c,d,e){if(!d.program||d.needsUpdate){d.program&&E.deallocateMaterial(d);E.initMaterial(d,b,c,e);d.needsUpdate=false}if(d.morphTargets&&!e.__webglMorphTargetInfluences){e.__webglMorphTargetInfluences=new Float32Array(E.maxMorphTargets);for(var g=0,i=E.maxMorphTargets;g<i;g++)e.__webglMorphTargetInfluences[g]=0}var h=false,g=d.program,i=g.uniforms,j=d.uniforms;
+if(g!==za){f.useProgram(g);za=g;h=true}if(d.id!==na){na=d.id;h=true}if(h||a!==ga){f.uniformMatrix4fv(i.projectionMatrix,false,a._projectionMatrixArray);a!==ga&&(ga=a)}if(h){if(c&&d.fog){j.fogColor.value=c.color;if(c instanceof THREE.Fog){j.fogNear.value=c.near;j.fogFar.value=c.far}else if(c instanceof THREE.FogExp2)j.fogDensity.value=c.density}if(d instanceof THREE.MeshPhongMaterial||d instanceof THREE.MeshLambertMaterial||d.lights){if(ob){for(var l,k=0,m=0,n=0,p,o,r,q=bc,v=q.directional.colors,s=
+q.directional.positions,w=q.point.colors,z=q.point.positions,H=q.point.distances,D=q.spot.colors,F=q.spot.positions,L=q.spot.distances,K=q.spot.directions,M=q.spot.angles,Q=q.spot.exponents,R=0,T=0,S=0,I=r=0,c=I=0,h=b.length;c<h;c++){l=b[c];if(!l.onlyShadow){p=l.color;o=l.intensity;r=l.distance;if(l instanceof THREE.AmbientLight)if(E.gammaInput){k=k+p.r*p.r;m=m+p.g*p.g;n=n+p.b*p.b}else{k=k+p.r;m=m+p.g;n=n+p.b}else if(l instanceof THREE.DirectionalLight){r=R*3;if(E.gammaInput){v[r]=p.r*p.r*o*o;v[r+
+1]=p.g*p.g*o*o;v[r+2]=p.b*p.b*o*o}else{v[r]=p.r*o;v[r+1]=p.g*o;v[r+2]=p.b*o}Ca.copy(l.matrixWorld.getPosition());Ca.subSelf(l.target.matrixWorld.getPosition());Ca.normalize();s[r]=Ca.x;s[r+1]=Ca.y;s[r+2]=Ca.z;R=R+1}else if(l instanceof THREE.PointLight){I=T*3;if(E.gammaInput){w[I]=p.r*p.r*o*o;w[I+1]=p.g*p.g*o*o;w[I+2]=p.b*p.b*o*o}else{w[I]=p.r*o;w[I+1]=p.g*o;w[I+2]=p.b*o}p=l.matrixWorld.getPosition();z[I]=p.x;z[I+1]=p.y;z[I+2]=p.z;H[T]=r;T=T+1}else if(l instanceof THREE.SpotLight){I=S*3;if(E.gammaInput){D[I]=
+p.r*p.r*o*o;D[I+1]=p.g*p.g*o*o;D[I+2]=p.b*p.b*o*o}else{D[I]=p.r*o;D[I+1]=p.g*o;D[I+2]=p.b*o}p=l.matrixWorld.getPosition();F[I]=p.x;F[I+1]=p.y;F[I+2]=p.z;L[S]=r;Ca.copy(p);Ca.subSelf(l.target.matrixWorld.getPosition());Ca.normalize();K[I]=Ca.x;K[I+1]=Ca.y;K[I+2]=Ca.z;M[S]=Math.cos(l.angle);Q[S]=l.exponent;S=S+1}}}c=R*3;for(h=v.length;c<h;c++)v[c]=0;c=T*3;for(h=w.length;c<h;c++)w[c]=0;c=S*3;for(h=D.length;c<h;c++)D[c]=0;q.directional.length=R;q.point.length=T;q.spot.length=S;q.ambient[0]=k;q.ambient[1]=
+m;q.ambient[2]=n;ob=false}c=bc;j.ambientLightColor.value=c.ambient;j.directionalLightColor.value=c.directional.colors;j.directionalLightDirection.value=c.directional.positions;j.pointLightColor.value=c.point.colors;j.pointLightPosition.value=c.point.positions;j.pointLightDistance.value=c.point.distances;j.spotLightColor.value=c.spot.colors;j.spotLightPosition.value=c.spot.positions;j.spotLightDistance.value=c.spot.distances;j.spotLightDirection.value=c.spot.directions;j.spotLightAngle.value=c.spot.angles;
+j.spotLightExponent.value=c.spot.exponents}if(d instanceof THREE.MeshBasicMaterial||d instanceof THREE.MeshLambertMaterial||d instanceof THREE.MeshPhongMaterial){j.opacity.value=d.opacity;E.gammaInput?j.diffuse.value.copyGammaToLinear(d.color):j.diffuse.value=d.color;(j.map.texture=d.map)&&j.offsetRepeat.value.set(d.map.offset.x,d.map.offset.y,d.map.repeat.x,d.map.repeat.y);j.lightMap.texture=d.lightMap;j.envMap.texture=d.envMap;j.flipEnvMap.value=d.envMap instanceof THREE.WebGLRenderTargetCube?1:
+-1;j.reflectivity.value=d.reflectivity;j.refractionRatio.value=d.refractionRatio;j.combine.value=d.combine;j.useRefract.value=d.envMap&&d.envMap.mapping instanceof THREE.CubeRefractionMapping}if(d instanceof THREE.LineBasicMaterial){j.diffuse.value=d.color;j.opacity.value=d.opacity}else if(d instanceof THREE.ParticleBasicMaterial){j.psColor.value=d.color;j.opacity.value=d.opacity;j.size.value=d.size;j.scale.value=G.height/2;j.map.texture=d.map}else if(d instanceof THREE.MeshPhongMaterial){j.shininess.value=
+d.shininess;if(E.gammaInput){j.ambient.value.copyGammaToLinear(d.ambient);j.emissive.value.copyGammaToLinear(d.emissive);j.specular.value.copyGammaToLinear(d.specular)}else{j.ambient.value=d.ambient;j.emissive.value=d.emissive;j.specular.value=d.specular}d.wrapAround&&j.wrapRGB.value.copy(d.wrapRGB)}else if(d instanceof THREE.MeshLambertMaterial){if(E.gammaInput){j.ambient.value.copyGammaToLinear(d.ambient);j.emissive.value.copyGammaToLinear(d.emissive)}else{j.ambient.value=d.ambient;j.emissive.value=
+d.emissive}d.wrapAround&&j.wrapRGB.value.copy(d.wrapRGB)}else if(d instanceof THREE.MeshDepthMaterial){j.mNear.value=a.near;j.mFar.value=a.far;j.opacity.value=d.opacity}else if(d instanceof THREE.MeshNormalMaterial)j.opacity.value=d.opacity;if(e.receiveShadow&&!d._shadowPass&&j.shadowMatrix){h=c=0;for(l=b.length;h<l;h++){k=b[h];if(k.castShadow&&(k instanceof THREE.SpotLight||k instanceof THREE.DirectionalLight&&!k.shadowCascade)){j.shadowMap.texture[c]=k.shadowMap;j.shadowMapSize.value[c]=k.shadowMapSize;
+j.shadowMatrix.value[c]=k.shadowMatrix;j.shadowDarkness.value[c]=k.shadowDarkness;j.shadowBias.value[c]=k.shadowBias;c++}}}b=d.uniformsList;j=0;for(c=b.length;j<c;j++)if(k=g.uniforms[b[j][1]]){h=b[j][0];m=h.type;l=h.value;switch(m){case "i":f.uniform1i(k,l);break;case "f":f.uniform1f(k,l);break;case "v2":f.uniform2f(k,l.x,l.y);break;case "v3":f.uniform3f(k,l.x,l.y,l.z);break;case "v4":f.uniform4f(k,l.x,l.y,l.z,l.w);break;case "c":f.uniform3f(k,l.r,l.g,l.b);break;case "fv1":f.uniform1fv(k,l);break;
+case "fv":f.uniform3fv(k,l);break;case "v2v":if(!h._array)h._array=new Float32Array(2*l.length);m=0;for(n=l.length;m<n;m++){q=m*2;h._array[q]=l[m].x;h._array[q+1]=l[m].y}f.uniform2fv(k,h._array);break;case "v3v":if(!h._array)h._array=new Float32Array(3*l.length);m=0;for(n=l.length;m<n;m++){q=m*3;h._array[q]=l[m].x;h._array[q+1]=l[m].y;h._array[q+2]=l[m].z}f.uniform3fv(k,h._array);break;case "v4v":if(!h._array)h._array=new Float32Array(4*l.length);m=0;for(n=l.length;m<n;m++){q=m*4;h._array[q]=l[m].x;
+h._array[q+1]=l[m].y;h._array[q+2]=l[m].z;h._array[q+3]=l[m].w}f.uniform4fv(k,h._array);break;case "m4":if(!h._array)h._array=new Float32Array(16);l.flattenToArray(h._array);f.uniformMatrix4fv(k,false,h._array);break;case "m4v":if(!h._array)h._array=new Float32Array(16*l.length);m=0;for(n=l.length;m<n;m++)l[m].flattenToArrayOffset(h._array,m*16);f.uniformMatrix4fv(k,false,h._array);break;case "t":f.uniform1i(k,l);k=h.texture;if(!k)continue;if(k.image instanceof Array&&k.image.length===6){h=k;if(h.image.length===
+6)if(h.needsUpdate){if(!h.image.__webglTextureCube)h.image.__webglTextureCube=f.createTexture();f.activeTexture(f.TEXTURE0+l);f.bindTexture(f.TEXTURE_CUBE_MAP,h.image.__webglTextureCube);l=[];for(k=0;k<6;k++){m=l;n=k;if(E.autoScaleCubemaps){q=h.image[k];s=Kc;if(!(q.width<=s&&q.height<=s)){w=Math.max(q.width,q.height);v=Math.floor(q.width*s/w);s=Math.floor(q.height*s/w);w=document.createElement("canvas");w.width=v;w.height=s;w.getContext("2d").drawImage(q,0,0,q.width,q.height,0,0,v,s);q=w}}else q=
+h.image[k];m[n]=q}k=l[0];m=(k.width&k.width-1)===0&&(k.height&k.height-1)===0;n=A(h.format);q=A(h.type);C(f.TEXTURE_CUBE_MAP,h,m);for(k=0;k<6;k++)f.texImage2D(f.TEXTURE_CUBE_MAP_POSITIVE_X+k,0,n,n,q,l[k]);h.generateMipmaps&&m&&f.generateMipmap(f.TEXTURE_CUBE_MAP);h.needsUpdate=false;if(h.onUpdate)h.onUpdate()}else{f.activeTexture(f.TEXTURE0+l);f.bindTexture(f.TEXTURE_CUBE_MAP,h.image.__webglTextureCube)}}else if(k instanceof THREE.WebGLRenderTargetCube){h=k;f.activeTexture(f.TEXTURE0+l);f.bindTexture(f.TEXTURE_CUBE_MAP,
+h.__webglTexture)}else E.setTexture(k,l);break;case "tv":if(!h._array){h._array=[];m=0;for(n=h.texture.length;m<n;m++)h._array[m]=l+m}f.uniform1iv(k,h._array);m=0;for(n=h.texture.length;m<n;m++)(k=h.texture[m])&&E.setTexture(k,h._array[m])}}if((d instanceof THREE.ShaderMaterial||d instanceof THREE.MeshPhongMaterial||d.envMap)&&i.cameraPosition!==null){b=a.matrixWorld.getPosition();f.uniform3f(i.cameraPosition,b.x,b.y,b.z)}(d instanceof THREE.MeshPhongMaterial||d instanceof THREE.MeshLambertMaterial||
+d instanceof THREE.ShaderMaterial||d.skinning)&&i.viewMatrix!==null&&f.uniformMatrix4fv(i.viewMatrix,false,a._viewMatrixArray);d.skinning&&f.uniformMatrix4fv(i.boneGlobalMatrices,false,e.boneMatrices)}f.uniformMatrix4fv(i.modelViewMatrix,false,e._modelViewMatrix.elements);i.normalMatrix&&f.uniformMatrix3fv(i.normalMatrix,false,e._normalMatrix.elements);i.objectMatrix!==null&&f.uniformMatrix4fv(i.objectMatrix,false,e.matrixWorld.elements);return g}function w(a,b){a._modelViewMatrix.multiply(b.matrixWorldInverse,
+a.matrixWorld);a._normalMatrix.getInverse(a._modelViewMatrix);a._normalMatrix.transpose()}function q(a,b,c){if(sc!==a){a?f.enable(f.POLYGON_OFFSET_FILL):f.disable(f.POLYGON_OFFSET_FILL);sc=a}if(a&&(tc!==b||uc!==c)){f.polygonOffset(b,c);tc=b;uc=c}}function F(a,b){var c;a==="fragment"?c=f.createShader(f.FRAGMENT_SHADER):a==="vertex"&&(c=f.createShader(f.VERTEX_SHADER));f.shaderSource(c,b);f.compileShader(c);if(!f.getShaderParameter(c,f.COMPILE_STATUS)){console.error(f.getShaderInfoLog(c));console.error(b);
+return null}return c}function C(a,b,c){if(c){f.texParameteri(a,f.TEXTURE_WRAP_S,A(b.wrapS));f.texParameteri(a,f.TEXTURE_WRAP_T,A(b.wrapT));f.texParameteri(a,f.TEXTURE_MAG_FILTER,A(b.magFilter));f.texParameteri(a,f.TEXTURE_MIN_FILTER,A(b.minFilter))}else{f.texParameteri(a,f.TEXTURE_WRAP_S,f.CLAMP_TO_EDGE);f.texParameteri(a,f.TEXTURE_WRAP_T,f.CLAMP_TO_EDGE);f.texParameteri(a,f.TEXTURE_MAG_FILTER,K(b.magFilter));f.texParameteri(a,f.TEXTURE_MIN_FILTER,K(b.minFilter))}}function s(a,b){f.bindRenderbuffer(f.RENDERBUFFER,
+a);if(b.depthBuffer&&!b.stencilBuffer){f.renderbufferStorage(f.RENDERBUFFER,f.DEPTH_COMPONENT16,b.width,b.height);f.framebufferRenderbuffer(f.FRAMEBUFFER,f.DEPTH_ATTACHMENT,f.RENDERBUFFER,a)}else if(b.depthBuffer&&b.stencilBuffer){f.renderbufferStorage(f.RENDERBUFFER,f.DEPTH_STENCIL,b.width,b.height);f.framebufferRenderbuffer(f.FRAMEBUFFER,f.DEPTH_STENCIL_ATTACHMENT,f.RENDERBUFFER,a)}else f.renderbufferStorage(f.RENDERBUFFER,f.RGBA4,b.width,b.height)}function K(a){switch(a){case THREE.NearestFilter:case THREE.NearestMipMapNearestFilter:case THREE.NearestMipMapLinearFilter:return f.NEAREST;
 default:return f.LINEAR}}function A(a){switch(a){case THREE.RepeatWrapping:return f.REPEAT;case THREE.ClampToEdgeWrapping:return f.CLAMP_TO_EDGE;case THREE.MirroredRepeatWrapping:return f.MIRRORED_REPEAT;case THREE.NearestFilter:return f.NEAREST;case THREE.NearestMipMapNearestFilter:return f.NEAREST_MIPMAP_NEAREST;case THREE.NearestMipMapLinearFilter:return f.NEAREST_MIPMAP_LINEAR;case THREE.LinearFilter:return f.LINEAR;case THREE.LinearMipMapNearestFilter:return f.LINEAR_MIPMAP_NEAREST;case THREE.LinearMipMapLinearFilter:return f.LINEAR_MIPMAP_LINEAR;
 case THREE.ByteType:return f.BYTE;case THREE.UnsignedByteType:return f.UNSIGNED_BYTE;case THREE.ShortType:return f.SHORT;case THREE.UnsignedShortType:return f.UNSIGNED_SHORT;case THREE.IntType:return f.INT;case THREE.UnsignedIntType:return f.UNSIGNED_INT;case THREE.FloatType:return f.FLOAT;case THREE.AlphaFormat:return f.ALPHA;case THREE.RGBFormat:return f.RGB;case THREE.RGBAFormat:return f.RGBA;case THREE.LuminanceFormat:return f.LUMINANCE;case THREE.LuminanceAlphaFormat:return f.LUMINANCE_ALPHA;
 case THREE.AddEquation:return f.FUNC_ADD;case THREE.SubtractEquation:return f.FUNC_SUBTRACT;case THREE.ReverseSubtractEquation:return f.FUNC_REVERSE_SUBTRACT;case THREE.ZeroFactor:return f.ZERO;case THREE.OneFactor:return f.ONE;case THREE.SrcColorFactor:return f.SRC_COLOR;case THREE.OneMinusSrcColorFactor:return f.ONE_MINUS_SRC_COLOR;case THREE.SrcAlphaFactor:return f.SRC_ALPHA;case THREE.OneMinusSrcAlphaFactor:return f.ONE_MINUS_SRC_ALPHA;case THREE.DstAlphaFactor:return f.DST_ALPHA;case THREE.OneMinusDstAlphaFactor:return f.ONE_MINUS_DST_ALPHA;

+ 2 - 0
src/renderers/WebGLRenderer.js

@@ -4491,6 +4491,8 @@ THREE.WebGLRenderer = function ( parameters ) {
 
 		if ( ! material.program || material.needsUpdate ) {
 
+			if ( material.program ) _this.deallocateMaterial( material );
+
 			_this.initMaterial( material, lights, fog, object );
 			material.needsUpdate = false;