Browse Source

`Fog( color, density )` → `Fog( color, near, far )`

Mr.doob 14 years ago
parent
commit
fbf26158fb

+ 13 - 13
build/Three.js

@@ -93,7 +93,7 @@ THREE.Texture=function(a,b,f,d,j,k){this.image=a;this.mapping=b!==undefined?b:ne
 THREE.Texture.prototype={toString:function(){return"THREE.Texture (<br/>image: "+this.image+"<br/>wrap_s: "+this.wrap_s+"<br/>wrap_t: "+this.wrap_t+"<br/>mag_filter: "+this.mag_filter+"<br/>min_filter: "+this.min_filter+"<br/>)"}};THREE.MultiplyOperation=0;THREE.MixOperation=1;THREE.RepeatWrapping=0;THREE.ClampToEdgeWrapping=1;THREE.MirroredRepeatWrapping=2;THREE.NearestFilter=3;THREE.NearestMipMapNearestFilter=4;THREE.NearestMipMapLinearFilter=5;THREE.LinearFilter=6;
 THREE.LinearMipMapNearestFilter=7;THREE.LinearMipMapLinearFilter=8;THREE.CubeReflectionMapping=function(){};THREE.CubeRefractionMapping=function(){};THREE.LatitudeReflectionMapping=function(){};THREE.LatitudeRefractionMapping=function(){};THREE.SphericalReflectionMapping=function(){};THREE.SphericalRefractionMapping=function(){};THREE.UVMapping=function(){};
 THREE.Scene=function(){this.objects=[];this.lights=[];this.fog=null;this.addObject=function(a){this.objects.indexOf(a)===-1&&this.objects.push(a)};this.removeObject=function(a){a=this.objects.indexOf(a);a!==-1&&this.objects.splice(a,1)};this.addLight=function(a){this.lights.indexOf(a)===-1&&this.lights.push(a)};this.removeLight=function(a){a=this.lights.indexOf(a);a!==-1&&this.lights.splice(a,1)};this.toString=function(){return"THREE.Scene ( "+this.objects+" )"}};
-THREE.Fog=function(a,b){this.color=new THREE.Color(a);this.density=b||2.5E-4};
+THREE.Fog=function(a,b,f){this.color=new THREE.Color(a);this.near=b||1;this.far=f||1E3};
 THREE.Projector=function(){function a(e,h){return h.z-e.z}function b(e,h){var m=0,i=1,n=e.z+e.w,g=h.z+h.w,o=-e.z+e.w,r=-h.z+h.w;if(n>=0&&g>=0&&o>=0&&r>=0)return true;else if(n<0&&g<0||o<0&&r<0)return false;else{if(n<0)m=Math.max(m,n/(n-g));else if(g<0)i=Math.min(i,n/(n-g));if(o<0)m=Math.max(m,o/(o-r));else if(r<0)i=Math.min(i,o/(o-r));if(i<m)return false;else{e.lerpSelf(h,m);h.lerpSelf(e,1-i);return true}}}var f,d,j=[],k,q,l,p=[],y,c,C=[],u,t,J=[],R=new THREE.Vector4,N=new THREE.Vector4,s=new THREE.Matrix4,
 T=new THREE.Matrix4,B=[],L=new THREE.Vector4,O=new THREE.Vector4,Q;this.projectObjects=function(e,h,m){var i=[],n,g;d=0;s.multiply(h.projectionMatrix,h.matrix);B[0]=new THREE.Vector4(s.n41-s.n11,s.n42-s.n12,s.n43-s.n13,s.n44-s.n14);B[1]=new THREE.Vector4(s.n41+s.n11,s.n42+s.n12,s.n43+s.n13,s.n44+s.n14);B[2]=new THREE.Vector4(s.n41+s.n21,s.n42+s.n22,s.n43+s.n23,s.n44+s.n24);B[3]=new THREE.Vector4(s.n41-s.n21,s.n42-s.n22,s.n43-s.n23,s.n44-s.n24);B[4]=new THREE.Vector4(s.n41-s.n31,s.n42-s.n32,s.n43-
 s.n33,s.n44-s.n34);B[5]=new THREE.Vector4(s.n41+s.n31,s.n42+s.n32,s.n43+s.n33,s.n44+s.n34);h=0;for(n=B.length;h<n;h++){g=B[h];g.divideScalar(Math.sqrt(g.x*g.x+g.y*g.y+g.z*g.z))}n=e.objects;e=0;for(h=n.length;e<h;e++){g=n[e];var o;if(!(o=!g.visible)){if(o=g instanceof THREE.Mesh){a:{o=void 0;for(var r=g.position,D=-g.geometry.boundingSphere.radius*Math.max(g.scale.x,Math.max(g.scale.y,g.scale.z)),M=0;M<6;M++){o=B[M].x*r.x+B[M].y*r.y+B[M].z*r.z+B[M].w;if(o<=D){o=false;break a}}o=true}o=!o}o=o}if(!o){f=
@@ -151,13 +151,13 @@ THREE.PointLight&&pointLights++}if(pointLights+g<=h){maxDirLights=g;maxPointLigh
 "",e?"uniform vec3 directionalLightDirection[ MAX_DIR_LIGHTS ];":"",h?"uniform vec3 pointLightColor[ MAX_POINT_LIGHTS ];":"",h?"uniform vec3 pointLightPosition[ MAX_POINT_LIGHTS ];":"","varying vec3 vNormal;\nvarying vec2 vUv;\nvarying vec3 vLightWeighting;",h?"varying vec3 vPointLightVector[ MAX_POINT_LIGHTS ];":"","varying vec3 vViewPosition;\nvarying vec3 vReflect;\nuniform float mRefractionRatio;\nvoid main(void) {\nvec4 mPosition = objectMatrix * vec4( position, 1.0 );\nvViewPosition = cameraPosition - mPosition.xyz;\nvec3 nWorld = mat3( objectMatrix[0].xyz, objectMatrix[1].xyz, objectMatrix[2].xyz ) * normal;\nvec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );\nvec3 transformedNormal = normalize( normalMatrix * normal );\nif ( !enableLighting ) {\nvLightWeighting = vec3( 1.0, 1.0, 1.0 );\n} else {\nvLightWeighting = ambientLightColor;",
 e?"for( int i = 0; i < MAX_DIR_LIGHTS; i++ ) {":"",e?"vec4 lDirection = viewMatrix * vec4( directionalLightDirection[ i ], 0.0 );":"",e?"float directionalLightWeighting = max( dot( transformedNormal, normalize( lDirection.xyz ) ), 0.0 );":"",e?"vLightWeighting += directionalLightColor[ i ] * directionalLightWeighting;":"",e?"}":"",h?"for( int i = 0; i < MAX_POINT_LIGHTS; i++ ) {":"",h?"vec4 lPosition = viewMatrix * vec4( pointLightPosition[ i ], 1.0 );":"",h?"vPointLightVector[ i ] = normalize( lPosition.xyz - mvPosition.xyz );":
 "",h?"float pointLightWeighting = max( dot( transformedNormal, vPointLightVector[ i ] ), 0.0 );":"",h?"vLightWeighting += pointLightColor[ i ] * pointLightWeighting;":"",h?"}":"","}\nvNormal = transformedNormal;\nvUv = uv;\nif ( useRefract ) {\nvReflect = refract( normalize(mPosition.xyz - cameraPosition), normalize(nWorld.xyz), mRefractionRatio );\n} else {\nvReflect = reflect( normalize(mPosition.xyz - cameraPosition), normalize(nWorld.xyz) );\n}\ngl_Position = projectionMatrix * mvPosition;\n}"].join("\n"),
-n=[e?"#define MAX_DIR_LIGHTS "+e:"",h?"#define MAX_POINT_LIGHTS "+h:"","uniform int material;\nuniform bool enableMap;\nuniform bool enableCubeMap;\nuniform bool mixEnvMap;\nuniform samplerCube tCube;\nuniform float mReflectivity;\nuniform sampler2D tMap;\nuniform vec4 mColor;\nuniform float mOpacity;\nuniform vec4 mAmbient;\nuniform vec4 mSpecular;\nuniform float mShininess;\n#ifdef USE_FOG\nuniform vec3 fogColor;\nuniform float fogDensity;\n#endif\nuniform int pointLightNumber;\nuniform int directionalLightNumber;",
+n=[e?"#define MAX_DIR_LIGHTS "+e:"",h?"#define MAX_POINT_LIGHTS "+h:"","uniform int material;\nuniform bool enableMap;\nuniform bool enableCubeMap;\nuniform bool mixEnvMap;\nuniform samplerCube tCube;\nuniform float mReflectivity;\nuniform sampler2D tMap;\nuniform vec4 mColor;\nuniform float mOpacity;\nuniform vec4 mAmbient;\nuniform vec4 mSpecular;\nuniform float mShininess;\n#ifdef USE_FOG\nuniform vec3 fogColor;\nuniform float fogNear;\nuniform float fogFar;\n#endif\nuniform int pointLightNumber;\nuniform int directionalLightNumber;",
 e?"uniform vec3 directionalLightDirection[ MAX_DIR_LIGHTS ];":"","varying vec3 vNormal;\nvarying vec2 vUv;\nvarying vec3 vLightWeighting;",h?"varying vec3 vPointLightVector[ MAX_POINT_LIGHTS ];":"","varying vec3 vViewPosition;\nvarying vec3 vReflect;\nvoid main() {\nvec4 mapColor = vec4( 1.0, 1.0, 1.0, 1.0 );\nvec4 cubeColor = vec4( 1.0, 1.0, 1.0, 1.0 );\nif ( enableMap ) {\nmapColor = texture2D( tMap, vUv );\n}\nif ( enableCubeMap ) {\ncubeColor = textureCube( tCube, vec3( -vReflect.x, vReflect.yz ) );\n}\nif ( material == 2 ) { \nvec3 normal = normalize( vNormal );\nvec3 viewPosition = normalize( vViewPosition );",
 h?"vec4 pointDiffuse  = vec4( 0.0, 0.0, 0.0, 0.0 );":"",h?"vec4 pointSpecular = vec4( 0.0, 0.0, 0.0, 0.0 );":"",h?"for( int i = 0; i < MAX_POINT_LIGHTS; i++ ) {":"",h?"vec3 pointVector = normalize( vPointLightVector[ i ] );":"",h?"vec3 pointHalfVector = normalize( vPointLightVector[ i ] + vViewPosition );":"",h?"float pointDotNormalHalf = dot( normal, pointHalfVector );":"",h?"float pointDiffuseWeight = max( dot( normal, pointVector ), 0.0 );":"",h?"float pointSpecularWeight = 0.0;":"",h?"if ( pointDotNormalHalf >= 0.0 )":
 "",h?"pointSpecularWeight = pow( pointDotNormalHalf, mShininess );":"",h?"pointDiffuse  += mColor * pointDiffuseWeight;":"",h?"pointSpecular += mSpecular * pointSpecularWeight;":"",h?"}":"",e?"vec4 dirDiffuse  = vec4( 0.0, 0.0, 0.0, 0.0 );":"",e?"vec4 dirSpecular = vec4( 0.0, 0.0, 0.0, 0.0 );":"",e?"for( int i = 0; i < MAX_DIR_LIGHTS; i++ ) {":"",e?"vec4 lDirection = viewMatrix * vec4( directionalLightDirection[ i ], 0.0 );":"",e?"vec3 dirVector = normalize( lDirection.xyz );":"",e?"vec3 dirHalfVector = normalize( lDirection.xyz + vViewPosition );":
 "",e?"float dirDotNormalHalf = dot( normal, dirHalfVector );":"",e?"float dirDiffuseWeight = max( dot( normal, dirVector ), 0.0 );":"",e?"float dirSpecularWeight = 0.0;":"",e?"if ( dirDotNormalHalf >= 0.0 )":"",e?"dirSpecularWeight = pow( dirDotNormalHalf, mShininess );":"",e?"dirDiffuse  += mColor * dirDiffuseWeight;":"",e?"dirSpecular += mSpecular * dirSpecularWeight;":"",e?"}":"","vec4 totalLight = mAmbient;",e?"totalLight += dirDiffuse + dirSpecular;":"",h?"totalLight += pointDiffuse + pointSpecular;":
-"","if ( mixEnvMap ) {\ngl_FragColor = vec4( mix( mapColor.rgb * totalLight.xyz * vLightWeighting, cubeColor.rgb, mReflectivity ), mapColor.a );\n} else {\ngl_FragColor = vec4( mapColor.rgb * cubeColor.rgb * totalLight.xyz * vLightWeighting, mapColor.a );\n}\n} else if ( material == 1 ) {\nif ( mixEnvMap ) {\ngl_FragColor = vec4( mix( mColor.rgb * mapColor.rgb * vLightWeighting, cubeColor.rgb, mReflectivity ), mColor.a * mapColor.a );\n} else {\ngl_FragColor = vec4( mColor.rgb * mapColor.rgb * cubeColor.rgb * vLightWeighting, mColor.a * mapColor.a );\n}\n} else {\nif ( mixEnvMap ) {\ngl_FragColor = mix( mColor * mapColor, cubeColor, mReflectivity );\n} else {\ngl_FragColor = mColor * mapColor * cubeColor;\n}\n}\n#ifdef USE_FOG\nconst float LOG2 = 1.442695;\nfloat z = gl_FragCoord.z / gl_FragCoord.w;\nfloat fogFactor = exp2( - fogDensity * fogDensity * z * z * LOG2 );\nfogFactor = clamp( fogFactor, 0.0, 1.0 );\ngl_FragColor = mix( vec4( fogColor, 1.0 ), gl_FragColor, fogFactor );\n#endif\n}"].join("\n");
-i=f(n,i,m);c.useProgram(i);k(i,["viewMatrix","modelViewMatrix","projectionMatrix","normalMatrix","objectMatrix","cameraPosition","enableLighting","ambientLightColor","material","mColor","mAmbient","mSpecular","mShininess","mOpacity","enableMap","tMap","enableCubeMap","tCube","mixEnvMap","mReflectivity","mRefractionRatio","useRefract"]);m&&k(i,["fogColor","fogDensity"]);e&&k(i,["directionalLightNumber","directionalLightColor","directionalLightDirection"]);h&&k(i,["pointLightNumber","pointLightColor",
+"","if ( mixEnvMap ) {\ngl_FragColor = vec4( mix( mapColor.rgb * totalLight.xyz * vLightWeighting, cubeColor.rgb, mReflectivity ), mapColor.a );\n} else {\ngl_FragColor = vec4( mapColor.rgb * cubeColor.rgb * totalLight.xyz * vLightWeighting, mapColor.a );\n}\n} else if ( material == 1 ) {\nif ( mixEnvMap ) {\ngl_FragColor = vec4( mix( mColor.rgb * mapColor.rgb * vLightWeighting, cubeColor.rgb, mReflectivity ), mColor.a * mapColor.a );\n} else {\ngl_FragColor = vec4( mColor.rgb * mapColor.rgb * cubeColor.rgb * vLightWeighting, mColor.a * mapColor.a );\n}\n} else {\nif ( mixEnvMap ) {\ngl_FragColor = mix( mColor * mapColor, cubeColor, mReflectivity );\n} else {\ngl_FragColor = mColor * mapColor * cubeColor;\n}\n}\n#ifdef USE_FOG\nfloat depth = gl_FragCoord.z / gl_FragCoord.w;\nfloat fogFactor = smoothstep( fogNear, fogFar, depth );\ngl_FragColor = mix( gl_FragColor, vec4( fogColor, 1.0 ), fogFactor );\n#endif\n}"].join("\n");
+i=f(n,i,m);c.useProgram(i);k(i,["viewMatrix","modelViewMatrix","projectionMatrix","normalMatrix","objectMatrix","cameraPosition","enableLighting","ambientLightColor","material","mColor","mAmbient","mSpecular","mShininess","mOpacity","enableMap","tMap","enableCubeMap","tCube","mixEnvMap","mReflectivity","mRefractionRatio","useRefract"]);m&&k(i,["fogColor","fogNear","fogFar"]);e&&k(i,["directionalLightNumber","directionalLightColor","directionalLightDirection"]);h&&k(i,["pointLightNumber","pointLightColor",
 "pointLightPosition"]);c.uniform1i(i.uniforms.enableMap,0);c.uniform1i(i.uniforms.tMap,0);c.uniform1i(i.uniforms.enableCubeMap,0);c.uniform1i(i.uniforms.tCube,1);c.uniform1i(i.uniforms.mixEnvMap,0);c.uniform1i(i.uniforms.useRefract,0);q(i,["position","normal","uv"]);return i}(L.directional,L.point,fog);this.setSize=function(e,h){y.width=e;y.height=h;c.viewport(0,0,y.width,y.height)};this.clear=function(){c.clear(c.COLOR_BUFFER_BIT|c.DEPTH_BUFFER_BIT)};this.setupLights=function(e,h){var m,i,n,g,o,
 r=[],D=[],M=[];g=[];o=[];c.uniform1i(e.uniforms.enableLighting,h.length);m=0;for(i=h.length;m<i;m++){n=h[m];if(n instanceof THREE.AmbientLight)r.push(n);else if(n instanceof THREE.DirectionalLight)M.push(n);else n instanceof THREE.PointLight&&D.push(n)}m=n=g=o=0;for(i=r.length;m<i;m++){n+=r[m].color.r;g+=r[m].color.g;o+=r[m].color.b}c.uniform3f(e.uniforms.ambientLightColor,n,g,o);g=[];o=[];m=0;for(i=M.length;m<i;m++){n=M[m];g.push(n.color.r*n.intensity);g.push(n.color.g*n.intensity);g.push(n.color.b*
 n.intensity);o.push(n.position.x);o.push(n.position.y);o.push(n.position.z)}if(M.length){c.uniform1i(e.uniforms.directionalLightNumber,M.length);c.uniform3fv(e.uniforms.directionalLightDirection,o);c.uniform3fv(e.uniforms.directionalLightColor,g)}g=[];o=[];m=0;for(i=D.length;m<i;m++){n=D[m];g.push(n.color.r*n.intensity);g.push(n.color.g*n.intensity);g.push(n.color.b*n.intensity);o.push(n.position.x);o.push(n.position.y);o.push(n.position.z)}if(D.length){c.uniform1i(e.uniforms.pointLightNumber,D.length);
@@ -171,15 +171,15 @@ K.__webGLLineBuffer);c.bufferData(c.ELEMENT_ARRAY_BUFFER,new Uint16Array(S),c.ST
 i.near;i.uniforms.mFar.value=i.far}else if(i instanceof THREE.MeshNormalMaterial){z=Q.normal;i.fragment_shader=z.fragment_shader;i.vertex_shader=z.vertex_shader;i.uniforms=z.uniforms}i.program=f(i.fragment_shader,i.vertex_shader,null);z=["viewMatrix","modelViewMatrix","projectionMatrix","normalMatrix","objectMatrix","cameraPosition"];for(E in i.uniforms)z.push(E);k(i.program,z);q(i.program,["position","normal","uv","tangent"])}E=i.program}else E=u;if(E!=C){c.useProgram(E);C=E}E==u&&this.setupLights(E,
 h);this.loadCamera(E,e);this.loadMatrices(E);if(i instanceof THREE.MeshShaderMaterial||i instanceof THREE.MeshDepthMaterial||i instanceof THREE.MeshNormalMaterial){r=i.wireframe;D=i.wireframe_linewidth;e=E;h=i.uniforms;var U;for(g in h){S=h[g].type;z=h[g].value;U=e.uniforms[g];if(S=="i")c.uniform1i(U,z);else if(S=="f")c.uniform1f(U,z);else if(S=="v3")c.uniform3f(U,z.x,z.y,z.z);else if(S=="c")c.uniform3f(U,z.r,z.g,z.b);else if(S=="t"){c.uniform1i(U,z);if(S=h[g].texture)S.image instanceof Array&&S.image.length==
 6?d(S,z):j(S,z)}}}if(i instanceof THREE.MeshPhongMaterial||i instanceof THREE.MeshLambertMaterial||i instanceof THREE.MeshBasicMaterial){g=i.color;o=i.opacity;r=i.wireframe;D=i.wireframe_linewidth;M=i.map;H=i.env_map;h=i.combine==THREE.MixOperation;e=i.reflectivity;S=i.env_map&&i.env_map.mapping instanceof THREE.CubeRefractionMapping;z=i.refraction_ratio;c.uniform4f(E.uniforms.mColor,g.r*o,g.g*o,g.b*o,o);c.uniform1i(E.uniforms.mixEnvMap,h);c.uniform1f(E.uniforms.mReflectivity,e);c.uniform1i(E.uniforms.useRefract,
-S);c.uniform1f(E.uniforms.mRefractionRatio,z);if(m){c.uniform1f(E.uniforms.fogDensity,m.density);c.uniform3f(E.uniforms.fogColor,m.color.r,m.color.g,m.color.b)}}if(i instanceof THREE.MeshPhongMaterial){m=i.ambient;g=i.specular;i=i.shininess;c.uniform4f(E.uniforms.mAmbient,m.r,m.g,m.b,o);c.uniform4f(E.uniforms.mSpecular,g.r,g.g,g.b,o);c.uniform1f(E.uniforms.mShininess,i);c.uniform1i(E.uniforms.material,2)}else if(i instanceof THREE.MeshLambertMaterial)c.uniform1i(E.uniforms.material,1);else i instanceof
-THREE.MeshBasicMaterial&&c.uniform1i(E.uniforms.material,0);if(M){j(M,0);c.uniform1i(E.uniforms.tMap,0);c.uniform1i(E.uniforms.enableMap,1)}else c.uniform1i(E.uniforms.enableMap,0);if(H){d(H,1);c.uniform1i(E.uniforms.tCube,1);c.uniform1i(E.uniforms.enableCubeMap,1)}else c.uniform1i(E.uniforms.enableCubeMap,0);o=E.attributes;c.bindBuffer(c.ARRAY_BUFFER,n.__webGLVertexBuffer);c.vertexAttribPointer(o.position,3,c.FLOAT,false,0,0);c.enableVertexAttribArray(o.position);if(o.normal>=0){c.bindBuffer(c.ARRAY_BUFFER,
-n.__webGLNormalBuffer);c.vertexAttribPointer(o.normal,3,c.FLOAT,false,0,0);c.enableVertexAttribArray(o.normal)}if(o.tangent>=0){c.bindBuffer(c.ARRAY_BUFFER,n.__webGLTangentBuffer);c.vertexAttribPointer(o.tangent,4,c.FLOAT,false,0,0);c.enableVertexAttribArray(o.tangent)}if(o.uv>=0)if(n.__webGLUVBuffer){c.bindBuffer(c.ARRAY_BUFFER,n.__webGLUVBuffer);c.vertexAttribPointer(o.uv,2,c.FLOAT,false,0,0);c.enableVertexAttribArray(o.uv)}else c.disableVertexAttribArray(o.uv);if(r){c.lineWidth(D);c.bindBuffer(c.ELEMENT_ARRAY_BUFFER,
-n.__webGLLineBuffer);c.drawElements(c.LINES,n.__webGLLineCount,c.UNSIGNED_SHORT,0)}else{c.bindBuffer(c.ELEMENT_ARRAY_BUFFER,n.__webGLFaceBuffer);c.drawElements(c.TRIANGLES,n.__webGLFaceCount,c.UNSIGNED_SHORT,0)}};this.renderPass=function(e,h,m,i,n,g,o){var r,D,M,H,z;M=0;for(H=i.materials.length;M<H;M++){r=i.materials[M];if(r instanceof THREE.MeshFaceMaterial){r=0;for(D=n.materials.length;r<D;r++)if((z=n.materials[r])&&z.blending==g&&z.opacity<1==o){this.setBlending(z.blending);this.renderBuffer(e,
-h,m,z,n)}}else if((z=r)&&z.blending==g&&z.opacity<1==o){this.setBlending(z.blending);this.renderBuffer(e,h,m,z,n)}}};this.render=function(e,h){var m,i,n,g,o=e.lights,r=e.fog;this.initWebGLObjects(e);this.autoClear&&this.clear();h.autoUpdateMatrix&&h.updateMatrix();R.set(h.matrix.flatten());s.set(h.projectionMatrix.flatten());m=0;for(i=e.__webGLObjects.length;m<i;m++){n=e.__webGLObjects[m];g=n.object;n=n.buffer;if(g.visible){this.setupMatrices(g,h);this.renderPass(h,o,r,g,n,THREE.NormalBlending,false)}}m=
-0;for(i=e.__webGLObjects.length;m<i;m++){n=e.__webGLObjects[m];g=n.object;n=n.buffer;if(g.visible){this.setupMatrices(g,h);this.renderPass(h,o,r,g,n,THREE.AdditiveBlending,false);this.renderPass(h,o,r,g,n,THREE.SubtractiveBlending,false);this.renderPass(h,o,r,g,n,THREE.AdditiveBlending,true);this.renderPass(h,o,r,g,n,THREE.SubtractiveBlending,true);this.renderPass(h,o,r,g,n,THREE.NormalBlending,true)}}};this.initWebGLObjects=function(e){var h,m,i,n,g,o;if(!e.__webGLObjects){e.__webGLObjects=[];e.__webGLObjectsMap=
-{}}h=0;for(m=e.objects.length;h<m;h++){i=e.objects[h];if(e.__webGLObjectsMap[i.id]==undefined)e.__webGLObjectsMap[i.id]={};o=e.__webGLObjectsMap[i.id];if(i instanceof THREE.Mesh)for(g in i.geometry.geometryChunks){n=i.geometry.geometryChunks[g];n.__webGLVertexBuffer||this.createBuffers(i,g);if(o[g]==undefined){n={buffer:n,object:i};e.__webGLObjects.push(n);o[g]=1}}}};this.removeObject=function(e,h){var m,i;for(m=e.__webGLObjects.length-1;m>=0;m--){i=e.__webGLObjects[m].object;h==i&&e.__webGLObjects.splice(m,
-1)}};this.setupMatrices=function(e,h){e.autoUpdateMatrix&&e.updateMatrix();t.multiply(h.matrix,e.matrix);N.set(t.flatten());J=THREE.Matrix4.makeInvert3x3(t).transpose();T.set(J.m);B.set(e.matrix.flatten())};this.loadMatrices=function(e){c.uniformMatrix4fv(e.uniforms.viewMatrix,false,R);c.uniformMatrix4fv(e.uniforms.modelViewMatrix,false,N);c.uniformMatrix4fv(e.uniforms.projectionMatrix,false,s);c.uniformMatrix3fv(e.uniforms.normalMatrix,false,T);c.uniformMatrix4fv(e.uniforms.objectMatrix,false,B)};
-this.loadCamera=function(e,h){c.uniform3f(e.uniforms.cameraPosition,h.position.x,h.position.y,h.position.z)};this.setBlending=function(e){switch(e){case THREE.AdditiveBlending:c.blendEquation(c.FUNC_ADD);c.blendFunc(c.ONE,c.ONE);break;case THREE.SubtractiveBlending:c.blendFunc(c.DST_COLOR,c.ZERO);break;default:c.blendEquation(c.FUNC_ADD);c.blendFunc(c.ONE,c.ONE_MINUS_SRC_ALPHA)}};this.setFaceCulling=function(e,h){if(e){!h||h=="ccw"?c.frontFace(c.CCW):c.frontFace(c.CW);if(e=="back")c.cullFace(c.BACK);
+S);c.uniform1f(E.uniforms.mRefractionRatio,z);if(m){c.uniform1f(E.uniforms.fogNear,m.near);c.uniform1f(E.uniforms.fogFar,m.far);c.uniform3f(E.uniforms.fogColor,m.color.r,m.color.g,m.color.b)}}if(i instanceof THREE.MeshPhongMaterial){m=i.ambient;g=i.specular;i=i.shininess;c.uniform4f(E.uniforms.mAmbient,m.r,m.g,m.b,o);c.uniform4f(E.uniforms.mSpecular,g.r,g.g,g.b,o);c.uniform1f(E.uniforms.mShininess,i);c.uniform1i(E.uniforms.material,2)}else if(i instanceof THREE.MeshLambertMaterial)c.uniform1i(E.uniforms.material,
+1);else i instanceof THREE.MeshBasicMaterial&&c.uniform1i(E.uniforms.material,0);if(M){j(M,0);c.uniform1i(E.uniforms.tMap,0);c.uniform1i(E.uniforms.enableMap,1)}else c.uniform1i(E.uniforms.enableMap,0);if(H){d(H,1);c.uniform1i(E.uniforms.tCube,1);c.uniform1i(E.uniforms.enableCubeMap,1)}else c.uniform1i(E.uniforms.enableCubeMap,0);o=E.attributes;c.bindBuffer(c.ARRAY_BUFFER,n.__webGLVertexBuffer);c.vertexAttribPointer(o.position,3,c.FLOAT,false,0,0);c.enableVertexAttribArray(o.position);if(o.normal>=
+0){c.bindBuffer(c.ARRAY_BUFFER,n.__webGLNormalBuffer);c.vertexAttribPointer(o.normal,3,c.FLOAT,false,0,0);c.enableVertexAttribArray(o.normal)}if(o.tangent>=0){c.bindBuffer(c.ARRAY_BUFFER,n.__webGLTangentBuffer);c.vertexAttribPointer(o.tangent,4,c.FLOAT,false,0,0);c.enableVertexAttribArray(o.tangent)}if(o.uv>=0)if(n.__webGLUVBuffer){c.bindBuffer(c.ARRAY_BUFFER,n.__webGLUVBuffer);c.vertexAttribPointer(o.uv,2,c.FLOAT,false,0,0);c.enableVertexAttribArray(o.uv)}else c.disableVertexAttribArray(o.uv);if(r){c.lineWidth(D);
+c.bindBuffer(c.ELEMENT_ARRAY_BUFFER,n.__webGLLineBuffer);c.drawElements(c.LINES,n.__webGLLineCount,c.UNSIGNED_SHORT,0)}else{c.bindBuffer(c.ELEMENT_ARRAY_BUFFER,n.__webGLFaceBuffer);c.drawElements(c.TRIANGLES,n.__webGLFaceCount,c.UNSIGNED_SHORT,0)}};this.renderPass=function(e,h,m,i,n,g,o){var r,D,M,H,z;M=0;for(H=i.materials.length;M<H;M++){r=i.materials[M];if(r instanceof THREE.MeshFaceMaterial){r=0;for(D=n.materials.length;r<D;r++)if((z=n.materials[r])&&z.blending==g&&z.opacity<1==o){this.setBlending(z.blending);
+this.renderBuffer(e,h,m,z,n)}}else if((z=r)&&z.blending==g&&z.opacity<1==o){this.setBlending(z.blending);this.renderBuffer(e,h,m,z,n)}}};this.render=function(e,h){var m,i,n,g,o=e.lights,r=e.fog;this.initWebGLObjects(e);this.autoClear&&this.clear();h.autoUpdateMatrix&&h.updateMatrix();R.set(h.matrix.flatten());s.set(h.projectionMatrix.flatten());m=0;for(i=e.__webGLObjects.length;m<i;m++){n=e.__webGLObjects[m];g=n.object;n=n.buffer;if(g.visible){this.setupMatrices(g,h);this.renderPass(h,o,r,g,n,THREE.NormalBlending,
+false)}}m=0;for(i=e.__webGLObjects.length;m<i;m++){n=e.__webGLObjects[m];g=n.object;n=n.buffer;if(g.visible){this.setupMatrices(g,h);this.renderPass(h,o,r,g,n,THREE.AdditiveBlending,false);this.renderPass(h,o,r,g,n,THREE.SubtractiveBlending,false);this.renderPass(h,o,r,g,n,THREE.AdditiveBlending,true);this.renderPass(h,o,r,g,n,THREE.SubtractiveBlending,true);this.renderPass(h,o,r,g,n,THREE.NormalBlending,true)}}};this.initWebGLObjects=function(e){var h,m,i,n,g,o;if(!e.__webGLObjects){e.__webGLObjects=
+[];e.__webGLObjectsMap={}}h=0;for(m=e.objects.length;h<m;h++){i=e.objects[h];if(e.__webGLObjectsMap[i.id]==undefined)e.__webGLObjectsMap[i.id]={};o=e.__webGLObjectsMap[i.id];if(i instanceof THREE.Mesh)for(g in i.geometry.geometryChunks){n=i.geometry.geometryChunks[g];n.__webGLVertexBuffer||this.createBuffers(i,g);if(o[g]==undefined){n={buffer:n,object:i};e.__webGLObjects.push(n);o[g]=1}}}};this.removeObject=function(e,h){var m,i;for(m=e.__webGLObjects.length-1;m>=0;m--){i=e.__webGLObjects[m].object;
+h==i&&e.__webGLObjects.splice(m,1)}};this.setupMatrices=function(e,h){e.autoUpdateMatrix&&e.updateMatrix();t.multiply(h.matrix,e.matrix);N.set(t.flatten());J=THREE.Matrix4.makeInvert3x3(t).transpose();T.set(J.m);B.set(e.matrix.flatten())};this.loadMatrices=function(e){c.uniformMatrix4fv(e.uniforms.viewMatrix,false,R);c.uniformMatrix4fv(e.uniforms.modelViewMatrix,false,N);c.uniformMatrix4fv(e.uniforms.projectionMatrix,false,s);c.uniformMatrix3fv(e.uniforms.normalMatrix,false,T);c.uniformMatrix4fv(e.uniforms.objectMatrix,
+false,B)};this.loadCamera=function(e,h){c.uniform3f(e.uniforms.cameraPosition,h.position.x,h.position.y,h.position.z)};this.setBlending=function(e){switch(e){case THREE.AdditiveBlending:c.blendEquation(c.FUNC_ADD);c.blendFunc(c.ONE,c.ONE);break;case THREE.SubtractiveBlending:c.blendFunc(c.DST_COLOR,c.ZERO);break;default:c.blendEquation(c.FUNC_ADD);c.blendFunc(c.ONE,c.ONE_MINUS_SRC_ALPHA)}};this.setFaceCulling=function(e,h){if(e){!h||h=="ccw"?c.frontFace(c.CCW):c.frontFace(c.CW);if(e=="back")c.cullFace(c.BACK);
 else e=="front"?c.cullFace(c.FRONT):c.cullFace(c.FRONT_AND_BACK);c.enable(c.CULL_FACE)}else c.disable(c.CULL_FACE)};this.supportsVertexTextures=function(){return c.getParameter(c.MAX_VERTEX_TEXTURE_IMAGE_UNITS)>0};var Q={depth:{uniforms:{mNear:{type:"f",value:1},mFar:{type:"f",value:2E3}},fragment_shader:"uniform float mNear;\nuniform float mFar;\nvoid main() {\nfloat depth = gl_FragCoord.z / gl_FragCoord.w;\nfloat color = 1.0 - smoothstep( mNear, mFar, depth );\ngl_FragColor = vec4( vec3( color ), 1.0 );\n}",
 vertex_shader:"void main() {\ngl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n}"},normal:{uniforms:{},fragment_shader:"varying vec3 vNormal;\nvoid main() {\ngl_FragColor = vec4( 0.5 * normalize( vNormal ) + 0.5, 1.0 );\n}",vertex_shader:"varying vec3 vNormal;\nvoid main() {\nvec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );\nvNormal = normalize( normalMatrix * normal );\ngl_Position = projectionMatrix * mvPosition;\n}"}}};
 THREE.RenderableObject=function(){this.z=this.object=null};THREE.RenderableFace3=function(){this.z=null;this.v1=new THREE.Vertex;this.v2=new THREE.Vertex;this.v3=new THREE.Vertex;this.centroidWorld=new THREE.Vector3;this.centroidScreen=new THREE.Vector3;this.normalWorld=new THREE.Vector3;this.vertexNormalsWorld=[];this.faceMaterials=this.meshMaterials=null;this.overdraw=false;this.uvs=[null,null,null]};

+ 13 - 13
build/ThreeDebug.js

@@ -93,7 +93,7 @@ THREE.Texture=function(a,b,f,d,j,k){this.image=a;this.mapping=b!==undefined?b:ne
 THREE.Texture.prototype={toString:function(){return"THREE.Texture (<br/>image: "+this.image+"<br/>wrap_s: "+this.wrap_s+"<br/>wrap_t: "+this.wrap_t+"<br/>mag_filter: "+this.mag_filter+"<br/>min_filter: "+this.min_filter+"<br/>)"}};THREE.MultiplyOperation=0;THREE.MixOperation=1;THREE.RepeatWrapping=0;THREE.ClampToEdgeWrapping=1;THREE.MirroredRepeatWrapping=2;THREE.NearestFilter=3;THREE.NearestMipMapNearestFilter=4;THREE.NearestMipMapLinearFilter=5;THREE.LinearFilter=6;
 THREE.LinearMipMapNearestFilter=7;THREE.LinearMipMapLinearFilter=8;THREE.CubeReflectionMapping=function(){};THREE.CubeRefractionMapping=function(){};THREE.LatitudeReflectionMapping=function(){};THREE.LatitudeRefractionMapping=function(){};THREE.SphericalReflectionMapping=function(){};THREE.SphericalRefractionMapping=function(){};THREE.UVMapping=function(){};
 THREE.Scene=function(){this.objects=[];this.lights=[];this.fog=null;this.addObject=function(a){this.objects.indexOf(a)===-1&&this.objects.push(a)};this.removeObject=function(a){a=this.objects.indexOf(a);a!==-1&&this.objects.splice(a,1)};this.addLight=function(a){this.lights.indexOf(a)===-1&&this.lights.push(a)};this.removeLight=function(a){a=this.lights.indexOf(a);a!==-1&&this.lights.splice(a,1)};this.toString=function(){return"THREE.Scene ( "+this.objects+" )"}};
-THREE.Fog=function(a,b){this.color=new THREE.Color(a);this.density=b||2.5E-4};
+THREE.Fog=function(a,b,f){this.color=new THREE.Color(a);this.near=b||1;this.far=f||1E3};
 THREE.Projector=function(){function a(e,h){return h.z-e.z}function b(e,h){var m=0,i=1,n=e.z+e.w,g=h.z+h.w,o=-e.z+e.w,r=-h.z+h.w;if(n>=0&&g>=0&&o>=0&&r>=0)return true;else if(n<0&&g<0||o<0&&r<0)return false;else{if(n<0)m=Math.max(m,n/(n-g));else if(g<0)i=Math.min(i,n/(n-g));if(o<0)m=Math.max(m,o/(o-r));else if(r<0)i=Math.min(i,o/(o-r));if(i<m)return false;else{e.lerpSelf(h,m);h.lerpSelf(e,1-i);return true}}}var f,d,j=[],k,q,l,p=[],y,c,C=[],v,u,J=[],R=new THREE.Vector4,N=new THREE.Vector4,s=new THREE.Matrix4,
 U=new THREE.Matrix4,B=[],L=new THREE.Vector4,O=new THREE.Vector4,Q;this.projectObjects=function(e,h,m){var i=[],n,g;d=0;s.multiply(h.projectionMatrix,h.matrix);B[0]=new THREE.Vector4(s.n41-s.n11,s.n42-s.n12,s.n43-s.n13,s.n44-s.n14);B[1]=new THREE.Vector4(s.n41+s.n11,s.n42+s.n12,s.n43+s.n13,s.n44+s.n14);B[2]=new THREE.Vector4(s.n41+s.n21,s.n42+s.n22,s.n43+s.n23,s.n44+s.n24);B[3]=new THREE.Vector4(s.n41-s.n21,s.n42-s.n22,s.n43-s.n23,s.n44-s.n24);B[4]=new THREE.Vector4(s.n41-s.n31,s.n42-s.n32,s.n43-
 s.n33,s.n44-s.n34);B[5]=new THREE.Vector4(s.n41+s.n31,s.n42+s.n32,s.n43+s.n33,s.n44+s.n34);h=0;for(n=B.length;h<n;h++){g=B[h];g.divideScalar(Math.sqrt(g.x*g.x+g.y*g.y+g.z*g.z))}n=e.objects;e=0;for(h=n.length;e<h;e++){g=n[e];var o;if(!(o=!g.visible)){if(o=g instanceof THREE.Mesh){a:{o=void 0;for(var r=g.position,E=-g.geometry.boundingSphere.radius*Math.max(g.scale.x,Math.max(g.scale.y,g.scale.z)),M=0;M<6;M++){o=B[M].x*r.x+B[M].y*r.y+B[M].z*r.z+B[M].w;if(o<=E){o=false;break a}}o=true}o=!o}o=o}if(!o){f=
@@ -152,13 +152,13 @@ THREE.PointLight&&pointLights++}if(pointLights+g<=h){maxDirLights=g;maxPointLigh
 "",e?"uniform vec3 directionalLightDirection[ MAX_DIR_LIGHTS ];":"",h?"uniform vec3 pointLightColor[ MAX_POINT_LIGHTS ];":"",h?"uniform vec3 pointLightPosition[ MAX_POINT_LIGHTS ];":"","varying vec3 vNormal;\nvarying vec2 vUv;\nvarying vec3 vLightWeighting;",h?"varying vec3 vPointLightVector[ MAX_POINT_LIGHTS ];":"","varying vec3 vViewPosition;\nvarying vec3 vReflect;\nuniform float mRefractionRatio;\nvoid main(void) {\nvec4 mPosition = objectMatrix * vec4( position, 1.0 );\nvViewPosition = cameraPosition - mPosition.xyz;\nvec3 nWorld = mat3( objectMatrix[0].xyz, objectMatrix[1].xyz, objectMatrix[2].xyz ) * normal;\nvec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );\nvec3 transformedNormal = normalize( normalMatrix * normal );\nif ( !enableLighting ) {\nvLightWeighting = vec3( 1.0, 1.0, 1.0 );\n} else {\nvLightWeighting = ambientLightColor;",
 e?"for( int i = 0; i < MAX_DIR_LIGHTS; i++ ) {":"",e?"vec4 lDirection = viewMatrix * vec4( directionalLightDirection[ i ], 0.0 );":"",e?"float directionalLightWeighting = max( dot( transformedNormal, normalize( lDirection.xyz ) ), 0.0 );":"",e?"vLightWeighting += directionalLightColor[ i ] * directionalLightWeighting;":"",e?"}":"",h?"for( int i = 0; i < MAX_POINT_LIGHTS; i++ ) {":"",h?"vec4 lPosition = viewMatrix * vec4( pointLightPosition[ i ], 1.0 );":"",h?"vPointLightVector[ i ] = normalize( lPosition.xyz - mvPosition.xyz );":
 "",h?"float pointLightWeighting = max( dot( transformedNormal, vPointLightVector[ i ] ), 0.0 );":"",h?"vLightWeighting += pointLightColor[ i ] * pointLightWeighting;":"",h?"}":"","}\nvNormal = transformedNormal;\nvUv = uv;\nif ( useRefract ) {\nvReflect = refract( normalize(mPosition.xyz - cameraPosition), normalize(nWorld.xyz), mRefractionRatio );\n} else {\nvReflect = reflect( normalize(mPosition.xyz - cameraPosition), normalize(nWorld.xyz) );\n}\ngl_Position = projectionMatrix * mvPosition;\n}"].join("\n"),
-n=[e?"#define MAX_DIR_LIGHTS "+e:"",h?"#define MAX_POINT_LIGHTS "+h:"","uniform int material;\nuniform bool enableMap;\nuniform bool enableCubeMap;\nuniform bool mixEnvMap;\nuniform samplerCube tCube;\nuniform float mReflectivity;\nuniform sampler2D tMap;\nuniform vec4 mColor;\nuniform float mOpacity;\nuniform vec4 mAmbient;\nuniform vec4 mSpecular;\nuniform float mShininess;\n#ifdef USE_FOG\nuniform vec3 fogColor;\nuniform float fogDensity;\n#endif\nuniform int pointLightNumber;\nuniform int directionalLightNumber;",
+n=[e?"#define MAX_DIR_LIGHTS "+e:"",h?"#define MAX_POINT_LIGHTS "+h:"","uniform int material;\nuniform bool enableMap;\nuniform bool enableCubeMap;\nuniform bool mixEnvMap;\nuniform samplerCube tCube;\nuniform float mReflectivity;\nuniform sampler2D tMap;\nuniform vec4 mColor;\nuniform float mOpacity;\nuniform vec4 mAmbient;\nuniform vec4 mSpecular;\nuniform float mShininess;\n#ifdef USE_FOG\nuniform vec3 fogColor;\nuniform float fogNear;\nuniform float fogFar;\n#endif\nuniform int pointLightNumber;\nuniform int directionalLightNumber;",
 e?"uniform vec3 directionalLightDirection[ MAX_DIR_LIGHTS ];":"","varying vec3 vNormal;\nvarying vec2 vUv;\nvarying vec3 vLightWeighting;",h?"varying vec3 vPointLightVector[ MAX_POINT_LIGHTS ];":"","varying vec3 vViewPosition;\nvarying vec3 vReflect;\nvoid main() {\nvec4 mapColor = vec4( 1.0, 1.0, 1.0, 1.0 );\nvec4 cubeColor = vec4( 1.0, 1.0, 1.0, 1.0 );\nif ( enableMap ) {\nmapColor = texture2D( tMap, vUv );\n}\nif ( enableCubeMap ) {\ncubeColor = textureCube( tCube, vec3( -vReflect.x, vReflect.yz ) );\n}\nif ( material == 2 ) { \nvec3 normal = normalize( vNormal );\nvec3 viewPosition = normalize( vViewPosition );",
 h?"vec4 pointDiffuse  = vec4( 0.0, 0.0, 0.0, 0.0 );":"",h?"vec4 pointSpecular = vec4( 0.0, 0.0, 0.0, 0.0 );":"",h?"for( int i = 0; i < MAX_POINT_LIGHTS; i++ ) {":"",h?"vec3 pointVector = normalize( vPointLightVector[ i ] );":"",h?"vec3 pointHalfVector = normalize( vPointLightVector[ i ] + vViewPosition );":"",h?"float pointDotNormalHalf = dot( normal, pointHalfVector );":"",h?"float pointDiffuseWeight = max( dot( normal, pointVector ), 0.0 );":"",h?"float pointSpecularWeight = 0.0;":"",h?"if ( pointDotNormalHalf >= 0.0 )":
 "",h?"pointSpecularWeight = pow( pointDotNormalHalf, mShininess );":"",h?"pointDiffuse  += mColor * pointDiffuseWeight;":"",h?"pointSpecular += mSpecular * pointSpecularWeight;":"",h?"}":"",e?"vec4 dirDiffuse  = vec4( 0.0, 0.0, 0.0, 0.0 );":"",e?"vec4 dirSpecular = vec4( 0.0, 0.0, 0.0, 0.0 );":"",e?"for( int i = 0; i < MAX_DIR_LIGHTS; i++ ) {":"",e?"vec4 lDirection = viewMatrix * vec4( directionalLightDirection[ i ], 0.0 );":"",e?"vec3 dirVector = normalize( lDirection.xyz );":"",e?"vec3 dirHalfVector = normalize( lDirection.xyz + vViewPosition );":
 "",e?"float dirDotNormalHalf = dot( normal, dirHalfVector );":"",e?"float dirDiffuseWeight = max( dot( normal, dirVector ), 0.0 );":"",e?"float dirSpecularWeight = 0.0;":"",e?"if ( dirDotNormalHalf >= 0.0 )":"",e?"dirSpecularWeight = pow( dirDotNormalHalf, mShininess );":"",e?"dirDiffuse  += mColor * dirDiffuseWeight;":"",e?"dirSpecular += mSpecular * dirSpecularWeight;":"",e?"}":"","vec4 totalLight = mAmbient;",e?"totalLight += dirDiffuse + dirSpecular;":"",h?"totalLight += pointDiffuse + pointSpecular;":
-"","if ( mixEnvMap ) {\ngl_FragColor = vec4( mix( mapColor.rgb * totalLight.xyz * vLightWeighting, cubeColor.rgb, mReflectivity ), mapColor.a );\n} else {\ngl_FragColor = vec4( mapColor.rgb * cubeColor.rgb * totalLight.xyz * vLightWeighting, mapColor.a );\n}\n} else if ( material == 1 ) {\nif ( mixEnvMap ) {\ngl_FragColor = vec4( mix( mColor.rgb * mapColor.rgb * vLightWeighting, cubeColor.rgb, mReflectivity ), mColor.a * mapColor.a );\n} else {\ngl_FragColor = vec4( mColor.rgb * mapColor.rgb * cubeColor.rgb * vLightWeighting, mColor.a * mapColor.a );\n}\n} else {\nif ( mixEnvMap ) {\ngl_FragColor = mix( mColor * mapColor, cubeColor, mReflectivity );\n} else {\ngl_FragColor = mColor * mapColor * cubeColor;\n}\n}\n#ifdef USE_FOG\nconst float LOG2 = 1.442695;\nfloat z = gl_FragCoord.z / gl_FragCoord.w;\nfloat fogFactor = exp2( - fogDensity * fogDensity * z * z * LOG2 );\nfogFactor = clamp( fogFactor, 0.0, 1.0 );\ngl_FragColor = mix( vec4( fogColor, 1.0 ), gl_FragColor, fogFactor );\n#endif\n}"].join("\n");
-i=f(n,i,m);c.useProgram(i);k(i,["viewMatrix","modelViewMatrix","projectionMatrix","normalMatrix","objectMatrix","cameraPosition","enableLighting","ambientLightColor","material","mColor","mAmbient","mSpecular","mShininess","mOpacity","enableMap","tMap","enableCubeMap","tCube","mixEnvMap","mReflectivity","mRefractionRatio","useRefract"]);m&&k(i,["fogColor","fogDensity"]);e&&k(i,["directionalLightNumber","directionalLightColor","directionalLightDirection"]);h&&k(i,["pointLightNumber","pointLightColor",
+"","if ( mixEnvMap ) {\ngl_FragColor = vec4( mix( mapColor.rgb * totalLight.xyz * vLightWeighting, cubeColor.rgb, mReflectivity ), mapColor.a );\n} else {\ngl_FragColor = vec4( mapColor.rgb * cubeColor.rgb * totalLight.xyz * vLightWeighting, mapColor.a );\n}\n} else if ( material == 1 ) {\nif ( mixEnvMap ) {\ngl_FragColor = vec4( mix( mColor.rgb * mapColor.rgb * vLightWeighting, cubeColor.rgb, mReflectivity ), mColor.a * mapColor.a );\n} else {\ngl_FragColor = vec4( mColor.rgb * mapColor.rgb * cubeColor.rgb * vLightWeighting, mColor.a * mapColor.a );\n}\n} else {\nif ( mixEnvMap ) {\ngl_FragColor = mix( mColor * mapColor, cubeColor, mReflectivity );\n} else {\ngl_FragColor = mColor * mapColor * cubeColor;\n}\n}\n#ifdef USE_FOG\nfloat depth = gl_FragCoord.z / gl_FragCoord.w;\nfloat fogFactor = smoothstep( fogNear, fogFar, depth );\ngl_FragColor = mix( gl_FragColor, vec4( fogColor, 1.0 ), fogFactor );\n#endif\n}"].join("\n");
+i=f(n,i,m);c.useProgram(i);k(i,["viewMatrix","modelViewMatrix","projectionMatrix","normalMatrix","objectMatrix","cameraPosition","enableLighting","ambientLightColor","material","mColor","mAmbient","mSpecular","mShininess","mOpacity","enableMap","tMap","enableCubeMap","tCube","mixEnvMap","mReflectivity","mRefractionRatio","useRefract"]);m&&k(i,["fogColor","fogNear","fogFar"]);e&&k(i,["directionalLightNumber","directionalLightColor","directionalLightDirection"]);h&&k(i,["pointLightNumber","pointLightColor",
 "pointLightPosition"]);c.uniform1i(i.uniforms.enableMap,0);c.uniform1i(i.uniforms.tMap,0);c.uniform1i(i.uniforms.enableCubeMap,0);c.uniform1i(i.uniforms.tCube,1);c.uniform1i(i.uniforms.mixEnvMap,0);c.uniform1i(i.uniforms.useRefract,0);q(i,["position","normal","uv"]);return i}(L.directional,L.point,fog);this.setSize=function(e,h){y.width=e;y.height=h;c.viewport(0,0,y.width,y.height)};this.clear=function(){c.clear(c.COLOR_BUFFER_BIT|c.DEPTH_BUFFER_BIT)};this.setupLights=function(e,h){var m,i,n,g,o,
 r=[],E=[],M=[];g=[];o=[];c.uniform1i(e.uniforms.enableLighting,h.length);m=0;for(i=h.length;m<i;m++){n=h[m];if(n instanceof THREE.AmbientLight)r.push(n);else if(n instanceof THREE.DirectionalLight)M.push(n);else n instanceof THREE.PointLight&&E.push(n)}m=n=g=o=0;for(i=r.length;m<i;m++){n+=r[m].color.r;g+=r[m].color.g;o+=r[m].color.b}c.uniform3f(e.uniforms.ambientLightColor,n,g,o);g=[];o=[];m=0;for(i=M.length;m<i;m++){n=M[m];g.push(n.color.r*n.intensity);g.push(n.color.g*n.intensity);g.push(n.color.b*
 n.intensity);o.push(n.position.x);o.push(n.position.y);o.push(n.position.z)}if(M.length){c.uniform1i(e.uniforms.directionalLightNumber,M.length);c.uniform3fv(e.uniforms.directionalLightDirection,o);c.uniform3fv(e.uniforms.directionalLightColor,g)}g=[];o=[];m=0;for(i=E.length;m<i;m++){n=E[m];g.push(n.color.r*n.intensity);g.push(n.color.g*n.intensity);g.push(n.color.b*n.intensity);o.push(n.position.x);o.push(n.position.y);o.push(n.position.z)}if(E.length){c.uniform1i(e.uniforms.pointLightNumber,E.length);
@@ -172,15 +172,15 @@ K.__webGLLineBuffer);c.bufferData(c.ELEMENT_ARRAY_BUFFER,new Uint16Array(T),c.ST
 i.near;i.uniforms.mFar.value=i.far}else if(i instanceof THREE.MeshNormalMaterial){z=Q.normal;i.fragment_shader=z.fragment_shader;i.vertex_shader=z.vertex_shader;i.uniforms=z.uniforms}i.program=f(i.fragment_shader,i.vertex_shader,null);z=["viewMatrix","modelViewMatrix","projectionMatrix","normalMatrix","objectMatrix","cameraPosition"];for(F in i.uniforms)z.push(F);k(i.program,z);q(i.program,["position","normal","uv","tangent"])}F=i.program}else F=v;if(F!=C){c.useProgram(F);C=F}F==v&&this.setupLights(F,
 h);this.loadCamera(F,e);this.loadMatrices(F);if(i instanceof THREE.MeshShaderMaterial||i instanceof THREE.MeshDepthMaterial||i instanceof THREE.MeshNormalMaterial){r=i.wireframe;E=i.wireframe_linewidth;e=F;h=i.uniforms;var S;for(g in h){T=h[g].type;z=h[g].value;S=e.uniforms[g];if(T=="i")c.uniform1i(S,z);else if(T=="f")c.uniform1f(S,z);else if(T=="v3")c.uniform3f(S,z.x,z.y,z.z);else if(T=="c")c.uniform3f(S,z.r,z.g,z.b);else if(T=="t"){c.uniform1i(S,z);if(T=h[g].texture)T.image instanceof Array&&T.image.length==
 6?d(T,z):j(T,z)}}}if(i instanceof THREE.MeshPhongMaterial||i instanceof THREE.MeshLambertMaterial||i instanceof THREE.MeshBasicMaterial){g=i.color;o=i.opacity;r=i.wireframe;E=i.wireframe_linewidth;M=i.map;H=i.env_map;h=i.combine==THREE.MixOperation;e=i.reflectivity;T=i.env_map&&i.env_map.mapping instanceof THREE.CubeRefractionMapping;z=i.refraction_ratio;c.uniform4f(F.uniforms.mColor,g.r*o,g.g*o,g.b*o,o);c.uniform1i(F.uniforms.mixEnvMap,h);c.uniform1f(F.uniforms.mReflectivity,e);c.uniform1i(F.uniforms.useRefract,
-T);c.uniform1f(F.uniforms.mRefractionRatio,z);if(m){c.uniform1f(F.uniforms.fogDensity,m.density);c.uniform3f(F.uniforms.fogColor,m.color.r,m.color.g,m.color.b)}}if(i instanceof THREE.MeshPhongMaterial){m=i.ambient;g=i.specular;i=i.shininess;c.uniform4f(F.uniforms.mAmbient,m.r,m.g,m.b,o);c.uniform4f(F.uniforms.mSpecular,g.r,g.g,g.b,o);c.uniform1f(F.uniforms.mShininess,i);c.uniform1i(F.uniforms.material,2)}else if(i instanceof THREE.MeshLambertMaterial)c.uniform1i(F.uniforms.material,1);else i instanceof
-THREE.MeshBasicMaterial&&c.uniform1i(F.uniforms.material,0);if(M){j(M,0);c.uniform1i(F.uniforms.tMap,0);c.uniform1i(F.uniforms.enableMap,1)}else c.uniform1i(F.uniforms.enableMap,0);if(H){d(H,1);c.uniform1i(F.uniforms.tCube,1);c.uniform1i(F.uniforms.enableCubeMap,1)}else c.uniform1i(F.uniforms.enableCubeMap,0);o=F.attributes;c.bindBuffer(c.ARRAY_BUFFER,n.__webGLVertexBuffer);c.vertexAttribPointer(o.position,3,c.FLOAT,false,0,0);c.enableVertexAttribArray(o.position);if(o.normal>=0){c.bindBuffer(c.ARRAY_BUFFER,
-n.__webGLNormalBuffer);c.vertexAttribPointer(o.normal,3,c.FLOAT,false,0,0);c.enableVertexAttribArray(o.normal)}if(o.tangent>=0){c.bindBuffer(c.ARRAY_BUFFER,n.__webGLTangentBuffer);c.vertexAttribPointer(o.tangent,4,c.FLOAT,false,0,0);c.enableVertexAttribArray(o.tangent)}if(o.uv>=0)if(n.__webGLUVBuffer){c.bindBuffer(c.ARRAY_BUFFER,n.__webGLUVBuffer);c.vertexAttribPointer(o.uv,2,c.FLOAT,false,0,0);c.enableVertexAttribArray(o.uv)}else c.disableVertexAttribArray(o.uv);if(r){c.lineWidth(E);c.bindBuffer(c.ELEMENT_ARRAY_BUFFER,
-n.__webGLLineBuffer);c.drawElements(c.LINES,n.__webGLLineCount,c.UNSIGNED_SHORT,0)}else{c.bindBuffer(c.ELEMENT_ARRAY_BUFFER,n.__webGLFaceBuffer);c.drawElements(c.TRIANGLES,n.__webGLFaceCount,c.UNSIGNED_SHORT,0)}};this.renderPass=function(e,h,m,i,n,g,o){var r,E,M,H,z;M=0;for(H=i.materials.length;M<H;M++){r=i.materials[M];if(r instanceof THREE.MeshFaceMaterial){r=0;for(E=n.materials.length;r<E;r++)if((z=n.materials[r])&&z.blending==g&&z.opacity<1==o){this.setBlending(z.blending);this.renderBuffer(e,
-h,m,z,n)}}else if((z=r)&&z.blending==g&&z.opacity<1==o){this.setBlending(z.blending);this.renderBuffer(e,h,m,z,n)}}};this.render=function(e,h){var m,i,n,g,o=e.lights,r=e.fog;this.initWebGLObjects(e);this.autoClear&&this.clear();h.autoUpdateMatrix&&h.updateMatrix();R.set(h.matrix.flatten());s.set(h.projectionMatrix.flatten());m=0;for(i=e.__webGLObjects.length;m<i;m++){n=e.__webGLObjects[m];g=n.object;n=n.buffer;if(g.visible){this.setupMatrices(g,h);this.renderPass(h,o,r,g,n,THREE.NormalBlending,false)}}m=
-0;for(i=e.__webGLObjects.length;m<i;m++){n=e.__webGLObjects[m];g=n.object;n=n.buffer;if(g.visible){this.setupMatrices(g,h);this.renderPass(h,o,r,g,n,THREE.AdditiveBlending,false);this.renderPass(h,o,r,g,n,THREE.SubtractiveBlending,false);this.renderPass(h,o,r,g,n,THREE.AdditiveBlending,true);this.renderPass(h,o,r,g,n,THREE.SubtractiveBlending,true);this.renderPass(h,o,r,g,n,THREE.NormalBlending,true)}}};this.initWebGLObjects=function(e){var h,m,i,n,g,o;if(!e.__webGLObjects){e.__webGLObjects=[];e.__webGLObjectsMap=
-{}}h=0;for(m=e.objects.length;h<m;h++){i=e.objects[h];if(e.__webGLObjectsMap[i.id]==undefined)e.__webGLObjectsMap[i.id]={};o=e.__webGLObjectsMap[i.id];if(i instanceof THREE.Mesh)for(g in i.geometry.geometryChunks){n=i.geometry.geometryChunks[g];n.__webGLVertexBuffer||this.createBuffers(i,g);if(o[g]==undefined){n={buffer:n,object:i};e.__webGLObjects.push(n);o[g]=1}}}};this.removeObject=function(e,h){var m,i;for(m=e.__webGLObjects.length-1;m>=0;m--){i=e.__webGLObjects[m].object;h==i&&e.__webGLObjects.splice(m,
-1)}};this.setupMatrices=function(e,h){e.autoUpdateMatrix&&e.updateMatrix();u.multiply(h.matrix,e.matrix);N.set(u.flatten());J=THREE.Matrix4.makeInvert3x3(u).transpose();U.set(J.m);B.set(e.matrix.flatten())};this.loadMatrices=function(e){c.uniformMatrix4fv(e.uniforms.viewMatrix,false,R);c.uniformMatrix4fv(e.uniforms.modelViewMatrix,false,N);c.uniformMatrix4fv(e.uniforms.projectionMatrix,false,s);c.uniformMatrix3fv(e.uniforms.normalMatrix,false,U);c.uniformMatrix4fv(e.uniforms.objectMatrix,false,B)};
-this.loadCamera=function(e,h){c.uniform3f(e.uniforms.cameraPosition,h.position.x,h.position.y,h.position.z)};this.setBlending=function(e){switch(e){case THREE.AdditiveBlending:c.blendEquation(c.FUNC_ADD);c.blendFunc(c.ONE,c.ONE);break;case THREE.SubtractiveBlending:c.blendFunc(c.DST_COLOR,c.ZERO);break;default:c.blendEquation(c.FUNC_ADD);c.blendFunc(c.ONE,c.ONE_MINUS_SRC_ALPHA)}};this.setFaceCulling=function(e,h){if(e){!h||h=="ccw"?c.frontFace(c.CCW):c.frontFace(c.CW);if(e=="back")c.cullFace(c.BACK);
+T);c.uniform1f(F.uniforms.mRefractionRatio,z);if(m){c.uniform1f(F.uniforms.fogNear,m.near);c.uniform1f(F.uniforms.fogFar,m.far);c.uniform3f(F.uniforms.fogColor,m.color.r,m.color.g,m.color.b)}}if(i instanceof THREE.MeshPhongMaterial){m=i.ambient;g=i.specular;i=i.shininess;c.uniform4f(F.uniforms.mAmbient,m.r,m.g,m.b,o);c.uniform4f(F.uniforms.mSpecular,g.r,g.g,g.b,o);c.uniform1f(F.uniforms.mShininess,i);c.uniform1i(F.uniforms.material,2)}else if(i instanceof THREE.MeshLambertMaterial)c.uniform1i(F.uniforms.material,
+1);else i instanceof THREE.MeshBasicMaterial&&c.uniform1i(F.uniforms.material,0);if(M){j(M,0);c.uniform1i(F.uniforms.tMap,0);c.uniform1i(F.uniforms.enableMap,1)}else c.uniform1i(F.uniforms.enableMap,0);if(H){d(H,1);c.uniform1i(F.uniforms.tCube,1);c.uniform1i(F.uniforms.enableCubeMap,1)}else c.uniform1i(F.uniforms.enableCubeMap,0);o=F.attributes;c.bindBuffer(c.ARRAY_BUFFER,n.__webGLVertexBuffer);c.vertexAttribPointer(o.position,3,c.FLOAT,false,0,0);c.enableVertexAttribArray(o.position);if(o.normal>=
+0){c.bindBuffer(c.ARRAY_BUFFER,n.__webGLNormalBuffer);c.vertexAttribPointer(o.normal,3,c.FLOAT,false,0,0);c.enableVertexAttribArray(o.normal)}if(o.tangent>=0){c.bindBuffer(c.ARRAY_BUFFER,n.__webGLTangentBuffer);c.vertexAttribPointer(o.tangent,4,c.FLOAT,false,0,0);c.enableVertexAttribArray(o.tangent)}if(o.uv>=0)if(n.__webGLUVBuffer){c.bindBuffer(c.ARRAY_BUFFER,n.__webGLUVBuffer);c.vertexAttribPointer(o.uv,2,c.FLOAT,false,0,0);c.enableVertexAttribArray(o.uv)}else c.disableVertexAttribArray(o.uv);if(r){c.lineWidth(E);
+c.bindBuffer(c.ELEMENT_ARRAY_BUFFER,n.__webGLLineBuffer);c.drawElements(c.LINES,n.__webGLLineCount,c.UNSIGNED_SHORT,0)}else{c.bindBuffer(c.ELEMENT_ARRAY_BUFFER,n.__webGLFaceBuffer);c.drawElements(c.TRIANGLES,n.__webGLFaceCount,c.UNSIGNED_SHORT,0)}};this.renderPass=function(e,h,m,i,n,g,o){var r,E,M,H,z;M=0;for(H=i.materials.length;M<H;M++){r=i.materials[M];if(r instanceof THREE.MeshFaceMaterial){r=0;for(E=n.materials.length;r<E;r++)if((z=n.materials[r])&&z.blending==g&&z.opacity<1==o){this.setBlending(z.blending);
+this.renderBuffer(e,h,m,z,n)}}else if((z=r)&&z.blending==g&&z.opacity<1==o){this.setBlending(z.blending);this.renderBuffer(e,h,m,z,n)}}};this.render=function(e,h){var m,i,n,g,o=e.lights,r=e.fog;this.initWebGLObjects(e);this.autoClear&&this.clear();h.autoUpdateMatrix&&h.updateMatrix();R.set(h.matrix.flatten());s.set(h.projectionMatrix.flatten());m=0;for(i=e.__webGLObjects.length;m<i;m++){n=e.__webGLObjects[m];g=n.object;n=n.buffer;if(g.visible){this.setupMatrices(g,h);this.renderPass(h,o,r,g,n,THREE.NormalBlending,
+false)}}m=0;for(i=e.__webGLObjects.length;m<i;m++){n=e.__webGLObjects[m];g=n.object;n=n.buffer;if(g.visible){this.setupMatrices(g,h);this.renderPass(h,o,r,g,n,THREE.AdditiveBlending,false);this.renderPass(h,o,r,g,n,THREE.SubtractiveBlending,false);this.renderPass(h,o,r,g,n,THREE.AdditiveBlending,true);this.renderPass(h,o,r,g,n,THREE.SubtractiveBlending,true);this.renderPass(h,o,r,g,n,THREE.NormalBlending,true)}}};this.initWebGLObjects=function(e){var h,m,i,n,g,o;if(!e.__webGLObjects){e.__webGLObjects=
+[];e.__webGLObjectsMap={}}h=0;for(m=e.objects.length;h<m;h++){i=e.objects[h];if(e.__webGLObjectsMap[i.id]==undefined)e.__webGLObjectsMap[i.id]={};o=e.__webGLObjectsMap[i.id];if(i instanceof THREE.Mesh)for(g in i.geometry.geometryChunks){n=i.geometry.geometryChunks[g];n.__webGLVertexBuffer||this.createBuffers(i,g);if(o[g]==undefined){n={buffer:n,object:i};e.__webGLObjects.push(n);o[g]=1}}}};this.removeObject=function(e,h){var m,i;for(m=e.__webGLObjects.length-1;m>=0;m--){i=e.__webGLObjects[m].object;
+h==i&&e.__webGLObjects.splice(m,1)}};this.setupMatrices=function(e,h){e.autoUpdateMatrix&&e.updateMatrix();u.multiply(h.matrix,e.matrix);N.set(u.flatten());J=THREE.Matrix4.makeInvert3x3(u).transpose();U.set(J.m);B.set(e.matrix.flatten())};this.loadMatrices=function(e){c.uniformMatrix4fv(e.uniforms.viewMatrix,false,R);c.uniformMatrix4fv(e.uniforms.modelViewMatrix,false,N);c.uniformMatrix4fv(e.uniforms.projectionMatrix,false,s);c.uniformMatrix3fv(e.uniforms.normalMatrix,false,U);c.uniformMatrix4fv(e.uniforms.objectMatrix,
+false,B)};this.loadCamera=function(e,h){c.uniform3f(e.uniforms.cameraPosition,h.position.x,h.position.y,h.position.z)};this.setBlending=function(e){switch(e){case THREE.AdditiveBlending:c.blendEquation(c.FUNC_ADD);c.blendFunc(c.ONE,c.ONE);break;case THREE.SubtractiveBlending:c.blendFunc(c.DST_COLOR,c.ZERO);break;default:c.blendEquation(c.FUNC_ADD);c.blendFunc(c.ONE,c.ONE_MINUS_SRC_ALPHA)}};this.setFaceCulling=function(e,h){if(e){!h||h=="ccw"?c.frontFace(c.CCW):c.frontFace(c.CW);if(e=="back")c.cullFace(c.BACK);
 else e=="front"?c.cullFace(c.FRONT):c.cullFace(c.FRONT_AND_BACK);c.enable(c.CULL_FACE)}else c.disable(c.CULL_FACE)};this.supportsVertexTextures=function(){return c.getParameter(c.MAX_VERTEX_TEXTURE_IMAGE_UNITS)>0};var Q={depth:{uniforms:{mNear:{type:"f",value:1},mFar:{type:"f",value:2E3}},fragment_shader:"uniform float mNear;\nuniform float mFar;\nvoid main() {\nfloat depth = gl_FragCoord.z / gl_FragCoord.w;\nfloat color = 1.0 - smoothstep( mNear, mFar, depth );\ngl_FragColor = vec4( vec3( color ), 1.0 );\n}",
 vertex_shader:"void main() {\ngl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n}"},normal:{uniforms:{},fragment_shader:"varying vec3 vNormal;\nvoid main() {\ngl_FragColor = vec4( 0.5 * normalize( vNormal ) + 0.5, 1.0 );\n}",vertex_shader:"varying vec3 vNormal;\nvoid main() {\nvec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );\nvNormal = normalize( normalMatrix * normal );\ngl_Position = projectionMatrix * mvPosition;\n}"}}};
 THREE.RenderableObject=function(){this.z=this.object=null};THREE.RenderableFace3=function(){this.z=null;this.v1=new THREE.Vertex;this.v2=new THREE.Vertex;this.v3=new THREE.Vertex;this.centroidWorld=new THREE.Vector3;this.centroidScreen=new THREE.Vector3;this.normalWorld=new THREE.Vector3;this.vertexNormalsWorld=[];this.faceMaterials=this.meshMaterials=null;this.overdraw=false;this.uvs=[null,null,null]};

+ 13 - 13
build/ThreeExtras.js

@@ -93,7 +93,7 @@ THREE.Texture=function(a,b,e,d,g,f){this.image=a;this.mapping=b!==undefined?b:ne
 THREE.Texture.prototype={toString:function(){return"THREE.Texture (<br/>image: "+this.image+"<br/>wrap_s: "+this.wrap_s+"<br/>wrap_t: "+this.wrap_t+"<br/>mag_filter: "+this.mag_filter+"<br/>min_filter: "+this.min_filter+"<br/>)"}};THREE.MultiplyOperation=0;THREE.MixOperation=1;THREE.RepeatWrapping=0;THREE.ClampToEdgeWrapping=1;THREE.MirroredRepeatWrapping=2;THREE.NearestFilter=3;THREE.NearestMipMapNearestFilter=4;THREE.NearestMipMapLinearFilter=5;THREE.LinearFilter=6;
 THREE.LinearMipMapNearestFilter=7;THREE.LinearMipMapLinearFilter=8;THREE.CubeReflectionMapping=function(){};THREE.CubeRefractionMapping=function(){};THREE.LatitudeReflectionMapping=function(){};THREE.LatitudeRefractionMapping=function(){};THREE.SphericalReflectionMapping=function(){};THREE.SphericalRefractionMapping=function(){};THREE.UVMapping=function(){};
 THREE.Scene=function(){this.objects=[];this.lights=[];this.fog=null;this.addObject=function(a){this.objects.indexOf(a)===-1&&this.objects.push(a)};this.removeObject=function(a){a=this.objects.indexOf(a);a!==-1&&this.objects.splice(a,1)};this.addLight=function(a){this.lights.indexOf(a)===-1&&this.lights.push(a)};this.removeLight=function(a){a=this.lights.indexOf(a);a!==-1&&this.lights.splice(a,1)};this.toString=function(){return"THREE.Scene ( "+this.objects+" )"}};
-THREE.Fog=function(a,b){this.color=new THREE.Color(a);this.density=b||2.5E-4};
+THREE.Fog=function(a,b,e){this.color=new THREE.Color(a);this.near=b||1;this.far=e||1E3};
 THREE.Projector=function(){function a(i,o){return o.z-i.z}function b(i,o){var s=0,p=1,u=i.z+i.w,l=o.z+o.w,v=-i.z+i.w,z=-o.z+o.w;if(u>=0&&l>=0&&v>=0&&z>=0)return true;else if(u<0&&l<0||v<0&&z<0)return false;else{if(u<0)s=Math.max(s,u/(u-l));else if(l<0)p=Math.min(p,u/(u-l));if(v<0)s=Math.max(s,v/(v-z));else if(z<0)p=Math.min(p,v/(v-z));if(p<s)return false;else{i.lerpSelf(o,s);o.lerpSelf(i,1-p);return true}}}var e,d,g=[],f,j,h,k=[],x,c,B=[],r,t,y=[],A=new THREE.Vector4,I=new THREE.Vector4,w=new THREE.Matrix4,
 C=new THREE.Matrix4,n=[],O=new THREE.Vector4,L=new THREE.Vector4,T;this.projectObjects=function(i,o,s){var p=[],u,l;d=0;w.multiply(o.projectionMatrix,o.matrix);n[0]=new THREE.Vector4(w.n41-w.n11,w.n42-w.n12,w.n43-w.n13,w.n44-w.n14);n[1]=new THREE.Vector4(w.n41+w.n11,w.n42+w.n12,w.n43+w.n13,w.n44+w.n14);n[2]=new THREE.Vector4(w.n41+w.n21,w.n42+w.n22,w.n43+w.n23,w.n44+w.n24);n[3]=new THREE.Vector4(w.n41-w.n21,w.n42-w.n22,w.n43-w.n23,w.n44-w.n24);n[4]=new THREE.Vector4(w.n41-w.n31,w.n42-w.n32,w.n43-
 w.n33,w.n44-w.n34);n[5]=new THREE.Vector4(w.n41+w.n31,w.n42+w.n32,w.n43+w.n33,w.n44+w.n34);o=0;for(u=n.length;o<u;o++){l=n[o];l.divideScalar(Math.sqrt(l.x*l.x+l.y*l.y+l.z*l.z))}u=i.objects;i=0;for(o=u.length;i<o;i++){l=u[i];var v;if(!(v=!l.visible)){if(v=l instanceof THREE.Mesh){a:{v=void 0;for(var z=l.position,J=-l.geometry.boundingSphere.radius*Math.max(l.scale.x,Math.max(l.scale.y,l.scale.z)),S=0;S<6;S++){v=n[S].x*z.x+n[S].y*z.y+n[S].z*z.z+n[S].w;if(v<=J){v=false;break a}}v=true}v=!v}v=v}if(!v){e=
@@ -151,13 +151,13 @@ THREE.PointLight&&pointLights++}if(pointLights+l<=o){maxDirLights=l;maxPointLigh
 "",i?"uniform vec3 directionalLightDirection[ MAX_DIR_LIGHTS ];":"",o?"uniform vec3 pointLightColor[ MAX_POINT_LIGHTS ];":"",o?"uniform vec3 pointLightPosition[ MAX_POINT_LIGHTS ];":"","varying vec3 vNormal;\nvarying vec2 vUv;\nvarying vec3 vLightWeighting;",o?"varying vec3 vPointLightVector[ MAX_POINT_LIGHTS ];":"","varying vec3 vViewPosition;\nvarying vec3 vReflect;\nuniform float mRefractionRatio;\nvoid main(void) {\nvec4 mPosition = objectMatrix * vec4( position, 1.0 );\nvViewPosition = cameraPosition - mPosition.xyz;\nvec3 nWorld = mat3( objectMatrix[0].xyz, objectMatrix[1].xyz, objectMatrix[2].xyz ) * normal;\nvec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );\nvec3 transformedNormal = normalize( normalMatrix * normal );\nif ( !enableLighting ) {\nvLightWeighting = vec3( 1.0, 1.0, 1.0 );\n} else {\nvLightWeighting = ambientLightColor;",
 i?"for( int i = 0; i < MAX_DIR_LIGHTS; i++ ) {":"",i?"vec4 lDirection = viewMatrix * vec4( directionalLightDirection[ i ], 0.0 );":"",i?"float directionalLightWeighting = max( dot( transformedNormal, normalize( lDirection.xyz ) ), 0.0 );":"",i?"vLightWeighting += directionalLightColor[ i ] * directionalLightWeighting;":"",i?"}":"",o?"for( int i = 0; i < MAX_POINT_LIGHTS; i++ ) {":"",o?"vec4 lPosition = viewMatrix * vec4( pointLightPosition[ i ], 1.0 );":"",o?"vPointLightVector[ i ] = normalize( lPosition.xyz - mvPosition.xyz );":
 "",o?"float pointLightWeighting = max( dot( transformedNormal, vPointLightVector[ i ] ), 0.0 );":"",o?"vLightWeighting += pointLightColor[ i ] * pointLightWeighting;":"",o?"}":"","}\nvNormal = transformedNormal;\nvUv = uv;\nif ( useRefract ) {\nvReflect = refract( normalize(mPosition.xyz - cameraPosition), normalize(nWorld.xyz), mRefractionRatio );\n} else {\nvReflect = reflect( normalize(mPosition.xyz - cameraPosition), normalize(nWorld.xyz) );\n}\ngl_Position = projectionMatrix * mvPosition;\n}"].join("\n"),
-u=[i?"#define MAX_DIR_LIGHTS "+i:"",o?"#define MAX_POINT_LIGHTS "+o:"","uniform int material;\nuniform bool enableMap;\nuniform bool enableCubeMap;\nuniform bool mixEnvMap;\nuniform samplerCube tCube;\nuniform float mReflectivity;\nuniform sampler2D tMap;\nuniform vec4 mColor;\nuniform float mOpacity;\nuniform vec4 mAmbient;\nuniform vec4 mSpecular;\nuniform float mShininess;\n#ifdef USE_FOG\nuniform vec3 fogColor;\nuniform float fogDensity;\n#endif\nuniform int pointLightNumber;\nuniform int directionalLightNumber;",
+u=[i?"#define MAX_DIR_LIGHTS "+i:"",o?"#define MAX_POINT_LIGHTS "+o:"","uniform int material;\nuniform bool enableMap;\nuniform bool enableCubeMap;\nuniform bool mixEnvMap;\nuniform samplerCube tCube;\nuniform float mReflectivity;\nuniform sampler2D tMap;\nuniform vec4 mColor;\nuniform float mOpacity;\nuniform vec4 mAmbient;\nuniform vec4 mSpecular;\nuniform float mShininess;\n#ifdef USE_FOG\nuniform vec3 fogColor;\nuniform float fogNear;\nuniform float fogFar;\n#endif\nuniform int pointLightNumber;\nuniform int directionalLightNumber;",
 i?"uniform vec3 directionalLightDirection[ MAX_DIR_LIGHTS ];":"","varying vec3 vNormal;\nvarying vec2 vUv;\nvarying vec3 vLightWeighting;",o?"varying vec3 vPointLightVector[ MAX_POINT_LIGHTS ];":"","varying vec3 vViewPosition;\nvarying vec3 vReflect;\nvoid main() {\nvec4 mapColor = vec4( 1.0, 1.0, 1.0, 1.0 );\nvec4 cubeColor = vec4( 1.0, 1.0, 1.0, 1.0 );\nif ( enableMap ) {\nmapColor = texture2D( tMap, vUv );\n}\nif ( enableCubeMap ) {\ncubeColor = textureCube( tCube, vec3( -vReflect.x, vReflect.yz ) );\n}\nif ( material == 2 ) { \nvec3 normal = normalize( vNormal );\nvec3 viewPosition = normalize( vViewPosition );",
 o?"vec4 pointDiffuse  = vec4( 0.0, 0.0, 0.0, 0.0 );":"",o?"vec4 pointSpecular = vec4( 0.0, 0.0, 0.0, 0.0 );":"",o?"for( int i = 0; i < MAX_POINT_LIGHTS; i++ ) {":"",o?"vec3 pointVector = normalize( vPointLightVector[ i ] );":"",o?"vec3 pointHalfVector = normalize( vPointLightVector[ i ] + vViewPosition );":"",o?"float pointDotNormalHalf = dot( normal, pointHalfVector );":"",o?"float pointDiffuseWeight = max( dot( normal, pointVector ), 0.0 );":"",o?"float pointSpecularWeight = 0.0;":"",o?"if ( pointDotNormalHalf >= 0.0 )":
 "",o?"pointSpecularWeight = pow( pointDotNormalHalf, mShininess );":"",o?"pointDiffuse  += mColor * pointDiffuseWeight;":"",o?"pointSpecular += mSpecular * pointSpecularWeight;":"",o?"}":"",i?"vec4 dirDiffuse  = vec4( 0.0, 0.0, 0.0, 0.0 );":"",i?"vec4 dirSpecular = vec4( 0.0, 0.0, 0.0, 0.0 );":"",i?"for( int i = 0; i < MAX_DIR_LIGHTS; i++ ) {":"",i?"vec4 lDirection = viewMatrix * vec4( directionalLightDirection[ i ], 0.0 );":"",i?"vec3 dirVector = normalize( lDirection.xyz );":"",i?"vec3 dirHalfVector = normalize( lDirection.xyz + vViewPosition );":
 "",i?"float dirDotNormalHalf = dot( normal, dirHalfVector );":"",i?"float dirDiffuseWeight = max( dot( normal, dirVector ), 0.0 );":"",i?"float dirSpecularWeight = 0.0;":"",i?"if ( dirDotNormalHalf >= 0.0 )":"",i?"dirSpecularWeight = pow( dirDotNormalHalf, mShininess );":"",i?"dirDiffuse  += mColor * dirDiffuseWeight;":"",i?"dirSpecular += mSpecular * dirSpecularWeight;":"",i?"}":"","vec4 totalLight = mAmbient;",i?"totalLight += dirDiffuse + dirSpecular;":"",o?"totalLight += pointDiffuse + pointSpecular;":
-"","if ( mixEnvMap ) {\ngl_FragColor = vec4( mix( mapColor.rgb * totalLight.xyz * vLightWeighting, cubeColor.rgb, mReflectivity ), mapColor.a );\n} else {\ngl_FragColor = vec4( mapColor.rgb * cubeColor.rgb * totalLight.xyz * vLightWeighting, mapColor.a );\n}\n} else if ( material == 1 ) {\nif ( mixEnvMap ) {\ngl_FragColor = vec4( mix( mColor.rgb * mapColor.rgb * vLightWeighting, cubeColor.rgb, mReflectivity ), mColor.a * mapColor.a );\n} else {\ngl_FragColor = vec4( mColor.rgb * mapColor.rgb * cubeColor.rgb * vLightWeighting, mColor.a * mapColor.a );\n}\n} else {\nif ( mixEnvMap ) {\ngl_FragColor = mix( mColor * mapColor, cubeColor, mReflectivity );\n} else {\ngl_FragColor = mColor * mapColor * cubeColor;\n}\n}\n#ifdef USE_FOG\nconst float LOG2 = 1.442695;\nfloat z = gl_FragCoord.z / gl_FragCoord.w;\nfloat fogFactor = exp2( - fogDensity * fogDensity * z * z * LOG2 );\nfogFactor = clamp( fogFactor, 0.0, 1.0 );\ngl_FragColor = mix( vec4( fogColor, 1.0 ), gl_FragColor, fogFactor );\n#endif\n}"].join("\n");
-p=e(u,p,s);c.useProgram(p);f(p,["viewMatrix","modelViewMatrix","projectionMatrix","normalMatrix","objectMatrix","cameraPosition","enableLighting","ambientLightColor","material","mColor","mAmbient","mSpecular","mShininess","mOpacity","enableMap","tMap","enableCubeMap","tCube","mixEnvMap","mReflectivity","mRefractionRatio","useRefract"]);s&&f(p,["fogColor","fogDensity"]);i&&f(p,["directionalLightNumber","directionalLightColor","directionalLightDirection"]);o&&f(p,["pointLightNumber","pointLightColor",
+"","if ( mixEnvMap ) {\ngl_FragColor = vec4( mix( mapColor.rgb * totalLight.xyz * vLightWeighting, cubeColor.rgb, mReflectivity ), mapColor.a );\n} else {\ngl_FragColor = vec4( mapColor.rgb * cubeColor.rgb * totalLight.xyz * vLightWeighting, mapColor.a );\n}\n} else if ( material == 1 ) {\nif ( mixEnvMap ) {\ngl_FragColor = vec4( mix( mColor.rgb * mapColor.rgb * vLightWeighting, cubeColor.rgb, mReflectivity ), mColor.a * mapColor.a );\n} else {\ngl_FragColor = vec4( mColor.rgb * mapColor.rgb * cubeColor.rgb * vLightWeighting, mColor.a * mapColor.a );\n}\n} else {\nif ( mixEnvMap ) {\ngl_FragColor = mix( mColor * mapColor, cubeColor, mReflectivity );\n} else {\ngl_FragColor = mColor * mapColor * cubeColor;\n}\n}\n#ifdef USE_FOG\nfloat depth = gl_FragCoord.z / gl_FragCoord.w;\nfloat fogFactor = smoothstep( fogNear, fogFar, depth );\ngl_FragColor = mix( gl_FragColor, vec4( fogColor, 1.0 ), fogFactor );\n#endif\n}"].join("\n");
+p=e(u,p,s);c.useProgram(p);f(p,["viewMatrix","modelViewMatrix","projectionMatrix","normalMatrix","objectMatrix","cameraPosition","enableLighting","ambientLightColor","material","mColor","mAmbient","mSpecular","mShininess","mOpacity","enableMap","tMap","enableCubeMap","tCube","mixEnvMap","mReflectivity","mRefractionRatio","useRefract"]);s&&f(p,["fogColor","fogNear","fogFar"]);i&&f(p,["directionalLightNumber","directionalLightColor","directionalLightDirection"]);o&&f(p,["pointLightNumber","pointLightColor",
 "pointLightPosition"]);c.uniform1i(p.uniforms.enableMap,0);c.uniform1i(p.uniforms.tMap,0);c.uniform1i(p.uniforms.enableCubeMap,0);c.uniform1i(p.uniforms.tCube,1);c.uniform1i(p.uniforms.mixEnvMap,0);c.uniform1i(p.uniforms.useRefract,0);j(p,["position","normal","uv"]);return p}(O.directional,O.point,fog);this.setSize=function(i,o){x.width=i;x.height=o;c.viewport(0,0,x.width,x.height)};this.clear=function(){c.clear(c.COLOR_BUFFER_BIT|c.DEPTH_BUFFER_BIT)};this.setupLights=function(i,o){var s,p,u,l,v,
 z=[],J=[],S=[];l=[];v=[];c.uniform1i(i.uniforms.enableLighting,o.length);s=0;for(p=o.length;s<p;s++){u=o[s];if(u instanceof THREE.AmbientLight)z.push(u);else if(u instanceof THREE.DirectionalLight)S.push(u);else u instanceof THREE.PointLight&&J.push(u)}s=u=l=v=0;for(p=z.length;s<p;s++){u+=z[s].color.r;l+=z[s].color.g;v+=z[s].color.b}c.uniform3f(i.uniforms.ambientLightColor,u,l,v);l=[];v=[];s=0;for(p=S.length;s<p;s++){u=S[s];l.push(u.color.r*u.intensity);l.push(u.color.g*u.intensity);l.push(u.color.b*
 u.intensity);v.push(u.position.x);v.push(u.position.y);v.push(u.position.z)}if(S.length){c.uniform1i(i.uniforms.directionalLightNumber,S.length);c.uniform3fv(i.uniforms.directionalLightDirection,v);c.uniform3fv(i.uniforms.directionalLightColor,l)}l=[];v=[];s=0;for(p=J.length;s<p;s++){u=J[s];l.push(u.color.r*u.intensity);l.push(u.color.g*u.intensity);l.push(u.color.b*u.intensity);v.push(u.position.x);v.push(u.position.y);v.push(u.position.z)}if(J.length){c.uniform1i(i.uniforms.pointLightNumber,J.length);
@@ -171,15 +171,15 @@ m.__webGLLineBuffer);c.bufferData(c.ELEMENT_ARRAY_BUFFER,new Uint16Array(V),c.ST
 p.near;p.uniforms.mFar.value=p.far}else if(p instanceof THREE.MeshNormalMaterial){H=T.normal;p.fragment_shader=H.fragment_shader;p.vertex_shader=H.vertex_shader;p.uniforms=H.uniforms}p.program=e(p.fragment_shader,p.vertex_shader,null);H=["viewMatrix","modelViewMatrix","projectionMatrix","normalMatrix","objectMatrix","cameraPosition"];for(M in p.uniforms)H.push(M);f(p.program,H);j(p.program,["position","normal","uv","tangent"])}M=p.program}else M=r;if(M!=B){c.useProgram(M);B=M}M==r&&this.setupLights(M,
 o);this.loadCamera(M,i);this.loadMatrices(M);if(p instanceof THREE.MeshShaderMaterial||p instanceof THREE.MeshDepthMaterial||p instanceof THREE.MeshNormalMaterial){z=p.wireframe;J=p.wireframe_linewidth;i=M;o=p.uniforms;var W;for(l in o){V=o[l].type;H=o[l].value;W=i.uniforms[l];if(V=="i")c.uniform1i(W,H);else if(V=="f")c.uniform1f(W,H);else if(V=="v3")c.uniform3f(W,H.x,H.y,H.z);else if(V=="c")c.uniform3f(W,H.r,H.g,H.b);else if(V=="t"){c.uniform1i(W,H);if(V=o[l].texture)V.image instanceof Array&&V.image.length==
 6?d(V,H):g(V,H)}}}if(p instanceof THREE.MeshPhongMaterial||p instanceof THREE.MeshLambertMaterial||p instanceof THREE.MeshBasicMaterial){l=p.color;v=p.opacity;z=p.wireframe;J=p.wireframe_linewidth;S=p.map;Q=p.env_map;o=p.combine==THREE.MixOperation;i=p.reflectivity;V=p.env_map&&p.env_map.mapping instanceof THREE.CubeRefractionMapping;H=p.refraction_ratio;c.uniform4f(M.uniforms.mColor,l.r*v,l.g*v,l.b*v,v);c.uniform1i(M.uniforms.mixEnvMap,o);c.uniform1f(M.uniforms.mReflectivity,i);c.uniform1i(M.uniforms.useRefract,
-V);c.uniform1f(M.uniforms.mRefractionRatio,H);if(s){c.uniform1f(M.uniforms.fogDensity,s.density);c.uniform3f(M.uniforms.fogColor,s.color.r,s.color.g,s.color.b)}}if(p instanceof THREE.MeshPhongMaterial){s=p.ambient;l=p.specular;p=p.shininess;c.uniform4f(M.uniforms.mAmbient,s.r,s.g,s.b,v);c.uniform4f(M.uniforms.mSpecular,l.r,l.g,l.b,v);c.uniform1f(M.uniforms.mShininess,p);c.uniform1i(M.uniforms.material,2)}else if(p instanceof THREE.MeshLambertMaterial)c.uniform1i(M.uniforms.material,1);else p instanceof
-THREE.MeshBasicMaterial&&c.uniform1i(M.uniforms.material,0);if(S){g(S,0);c.uniform1i(M.uniforms.tMap,0);c.uniform1i(M.uniforms.enableMap,1)}else c.uniform1i(M.uniforms.enableMap,0);if(Q){d(Q,1);c.uniform1i(M.uniforms.tCube,1);c.uniform1i(M.uniforms.enableCubeMap,1)}else c.uniform1i(M.uniforms.enableCubeMap,0);v=M.attributes;c.bindBuffer(c.ARRAY_BUFFER,u.__webGLVertexBuffer);c.vertexAttribPointer(v.position,3,c.FLOAT,false,0,0);c.enableVertexAttribArray(v.position);if(v.normal>=0){c.bindBuffer(c.ARRAY_BUFFER,
-u.__webGLNormalBuffer);c.vertexAttribPointer(v.normal,3,c.FLOAT,false,0,0);c.enableVertexAttribArray(v.normal)}if(v.tangent>=0){c.bindBuffer(c.ARRAY_BUFFER,u.__webGLTangentBuffer);c.vertexAttribPointer(v.tangent,4,c.FLOAT,false,0,0);c.enableVertexAttribArray(v.tangent)}if(v.uv>=0)if(u.__webGLUVBuffer){c.bindBuffer(c.ARRAY_BUFFER,u.__webGLUVBuffer);c.vertexAttribPointer(v.uv,2,c.FLOAT,false,0,0);c.enableVertexAttribArray(v.uv)}else c.disableVertexAttribArray(v.uv);if(z){c.lineWidth(J);c.bindBuffer(c.ELEMENT_ARRAY_BUFFER,
-u.__webGLLineBuffer);c.drawElements(c.LINES,u.__webGLLineCount,c.UNSIGNED_SHORT,0)}else{c.bindBuffer(c.ELEMENT_ARRAY_BUFFER,u.__webGLFaceBuffer);c.drawElements(c.TRIANGLES,u.__webGLFaceCount,c.UNSIGNED_SHORT,0)}};this.renderPass=function(i,o,s,p,u,l,v){var z,J,S,Q,H;S=0;for(Q=p.materials.length;S<Q;S++){z=p.materials[S];if(z instanceof THREE.MeshFaceMaterial){z=0;for(J=u.materials.length;z<J;z++)if((H=u.materials[z])&&H.blending==l&&H.opacity<1==v){this.setBlending(H.blending);this.renderBuffer(i,
-o,s,H,u)}}else if((H=z)&&H.blending==l&&H.opacity<1==v){this.setBlending(H.blending);this.renderBuffer(i,o,s,H,u)}}};this.render=function(i,o){var s,p,u,l,v=i.lights,z=i.fog;this.initWebGLObjects(i);this.autoClear&&this.clear();o.autoUpdateMatrix&&o.updateMatrix();A.set(o.matrix.flatten());w.set(o.projectionMatrix.flatten());s=0;for(p=i.__webGLObjects.length;s<p;s++){u=i.__webGLObjects[s];l=u.object;u=u.buffer;if(l.visible){this.setupMatrices(l,o);this.renderPass(o,v,z,l,u,THREE.NormalBlending,false)}}s=
-0;for(p=i.__webGLObjects.length;s<p;s++){u=i.__webGLObjects[s];l=u.object;u=u.buffer;if(l.visible){this.setupMatrices(l,o);this.renderPass(o,v,z,l,u,THREE.AdditiveBlending,false);this.renderPass(o,v,z,l,u,THREE.SubtractiveBlending,false);this.renderPass(o,v,z,l,u,THREE.AdditiveBlending,true);this.renderPass(o,v,z,l,u,THREE.SubtractiveBlending,true);this.renderPass(o,v,z,l,u,THREE.NormalBlending,true)}}};this.initWebGLObjects=function(i){var o,s,p,u,l,v;if(!i.__webGLObjects){i.__webGLObjects=[];i.__webGLObjectsMap=
-{}}o=0;for(s=i.objects.length;o<s;o++){p=i.objects[o];if(i.__webGLObjectsMap[p.id]==undefined)i.__webGLObjectsMap[p.id]={};v=i.__webGLObjectsMap[p.id];if(p instanceof THREE.Mesh)for(l in p.geometry.geometryChunks){u=p.geometry.geometryChunks[l];u.__webGLVertexBuffer||this.createBuffers(p,l);if(v[l]==undefined){u={buffer:u,object:p};i.__webGLObjects.push(u);v[l]=1}}}};this.removeObject=function(i,o){var s,p;for(s=i.__webGLObjects.length-1;s>=0;s--){p=i.__webGLObjects[s].object;o==p&&i.__webGLObjects.splice(s,
-1)}};this.setupMatrices=function(i,o){i.autoUpdateMatrix&&i.updateMatrix();t.multiply(o.matrix,i.matrix);I.set(t.flatten());y=THREE.Matrix4.makeInvert3x3(t).transpose();C.set(y.m);n.set(i.matrix.flatten())};this.loadMatrices=function(i){c.uniformMatrix4fv(i.uniforms.viewMatrix,false,A);c.uniformMatrix4fv(i.uniforms.modelViewMatrix,false,I);c.uniformMatrix4fv(i.uniforms.projectionMatrix,false,w);c.uniformMatrix3fv(i.uniforms.normalMatrix,false,C);c.uniformMatrix4fv(i.uniforms.objectMatrix,false,n)};
-this.loadCamera=function(i,o){c.uniform3f(i.uniforms.cameraPosition,o.position.x,o.position.y,o.position.z)};this.setBlending=function(i){switch(i){case THREE.AdditiveBlending:c.blendEquation(c.FUNC_ADD);c.blendFunc(c.ONE,c.ONE);break;case THREE.SubtractiveBlending:c.blendFunc(c.DST_COLOR,c.ZERO);break;default:c.blendEquation(c.FUNC_ADD);c.blendFunc(c.ONE,c.ONE_MINUS_SRC_ALPHA)}};this.setFaceCulling=function(i,o){if(i){!o||o=="ccw"?c.frontFace(c.CCW):c.frontFace(c.CW);if(i=="back")c.cullFace(c.BACK);
+V);c.uniform1f(M.uniforms.mRefractionRatio,H);if(s){c.uniform1f(M.uniforms.fogNear,s.near);c.uniform1f(M.uniforms.fogFar,s.far);c.uniform3f(M.uniforms.fogColor,s.color.r,s.color.g,s.color.b)}}if(p instanceof THREE.MeshPhongMaterial){s=p.ambient;l=p.specular;p=p.shininess;c.uniform4f(M.uniforms.mAmbient,s.r,s.g,s.b,v);c.uniform4f(M.uniforms.mSpecular,l.r,l.g,l.b,v);c.uniform1f(M.uniforms.mShininess,p);c.uniform1i(M.uniforms.material,2)}else if(p instanceof THREE.MeshLambertMaterial)c.uniform1i(M.uniforms.material,
+1);else p instanceof THREE.MeshBasicMaterial&&c.uniform1i(M.uniforms.material,0);if(S){g(S,0);c.uniform1i(M.uniforms.tMap,0);c.uniform1i(M.uniforms.enableMap,1)}else c.uniform1i(M.uniforms.enableMap,0);if(Q){d(Q,1);c.uniform1i(M.uniforms.tCube,1);c.uniform1i(M.uniforms.enableCubeMap,1)}else c.uniform1i(M.uniforms.enableCubeMap,0);v=M.attributes;c.bindBuffer(c.ARRAY_BUFFER,u.__webGLVertexBuffer);c.vertexAttribPointer(v.position,3,c.FLOAT,false,0,0);c.enableVertexAttribArray(v.position);if(v.normal>=
+0){c.bindBuffer(c.ARRAY_BUFFER,u.__webGLNormalBuffer);c.vertexAttribPointer(v.normal,3,c.FLOAT,false,0,0);c.enableVertexAttribArray(v.normal)}if(v.tangent>=0){c.bindBuffer(c.ARRAY_BUFFER,u.__webGLTangentBuffer);c.vertexAttribPointer(v.tangent,4,c.FLOAT,false,0,0);c.enableVertexAttribArray(v.tangent)}if(v.uv>=0)if(u.__webGLUVBuffer){c.bindBuffer(c.ARRAY_BUFFER,u.__webGLUVBuffer);c.vertexAttribPointer(v.uv,2,c.FLOAT,false,0,0);c.enableVertexAttribArray(v.uv)}else c.disableVertexAttribArray(v.uv);if(z){c.lineWidth(J);
+c.bindBuffer(c.ELEMENT_ARRAY_BUFFER,u.__webGLLineBuffer);c.drawElements(c.LINES,u.__webGLLineCount,c.UNSIGNED_SHORT,0)}else{c.bindBuffer(c.ELEMENT_ARRAY_BUFFER,u.__webGLFaceBuffer);c.drawElements(c.TRIANGLES,u.__webGLFaceCount,c.UNSIGNED_SHORT,0)}};this.renderPass=function(i,o,s,p,u,l,v){var z,J,S,Q,H;S=0;for(Q=p.materials.length;S<Q;S++){z=p.materials[S];if(z instanceof THREE.MeshFaceMaterial){z=0;for(J=u.materials.length;z<J;z++)if((H=u.materials[z])&&H.blending==l&&H.opacity<1==v){this.setBlending(H.blending);
+this.renderBuffer(i,o,s,H,u)}}else if((H=z)&&H.blending==l&&H.opacity<1==v){this.setBlending(H.blending);this.renderBuffer(i,o,s,H,u)}}};this.render=function(i,o){var s,p,u,l,v=i.lights,z=i.fog;this.initWebGLObjects(i);this.autoClear&&this.clear();o.autoUpdateMatrix&&o.updateMatrix();A.set(o.matrix.flatten());w.set(o.projectionMatrix.flatten());s=0;for(p=i.__webGLObjects.length;s<p;s++){u=i.__webGLObjects[s];l=u.object;u=u.buffer;if(l.visible){this.setupMatrices(l,o);this.renderPass(o,v,z,l,u,THREE.NormalBlending,
+false)}}s=0;for(p=i.__webGLObjects.length;s<p;s++){u=i.__webGLObjects[s];l=u.object;u=u.buffer;if(l.visible){this.setupMatrices(l,o);this.renderPass(o,v,z,l,u,THREE.AdditiveBlending,false);this.renderPass(o,v,z,l,u,THREE.SubtractiveBlending,false);this.renderPass(o,v,z,l,u,THREE.AdditiveBlending,true);this.renderPass(o,v,z,l,u,THREE.SubtractiveBlending,true);this.renderPass(o,v,z,l,u,THREE.NormalBlending,true)}}};this.initWebGLObjects=function(i){var o,s,p,u,l,v;if(!i.__webGLObjects){i.__webGLObjects=
+[];i.__webGLObjectsMap={}}o=0;for(s=i.objects.length;o<s;o++){p=i.objects[o];if(i.__webGLObjectsMap[p.id]==undefined)i.__webGLObjectsMap[p.id]={};v=i.__webGLObjectsMap[p.id];if(p instanceof THREE.Mesh)for(l in p.geometry.geometryChunks){u=p.geometry.geometryChunks[l];u.__webGLVertexBuffer||this.createBuffers(p,l);if(v[l]==undefined){u={buffer:u,object:p};i.__webGLObjects.push(u);v[l]=1}}}};this.removeObject=function(i,o){var s,p;for(s=i.__webGLObjects.length-1;s>=0;s--){p=i.__webGLObjects[s].object;
+o==p&&i.__webGLObjects.splice(s,1)}};this.setupMatrices=function(i,o){i.autoUpdateMatrix&&i.updateMatrix();t.multiply(o.matrix,i.matrix);I.set(t.flatten());y=THREE.Matrix4.makeInvert3x3(t).transpose();C.set(y.m);n.set(i.matrix.flatten())};this.loadMatrices=function(i){c.uniformMatrix4fv(i.uniforms.viewMatrix,false,A);c.uniformMatrix4fv(i.uniforms.modelViewMatrix,false,I);c.uniformMatrix4fv(i.uniforms.projectionMatrix,false,w);c.uniformMatrix3fv(i.uniforms.normalMatrix,false,C);c.uniformMatrix4fv(i.uniforms.objectMatrix,
+false,n)};this.loadCamera=function(i,o){c.uniform3f(i.uniforms.cameraPosition,o.position.x,o.position.y,o.position.z)};this.setBlending=function(i){switch(i){case THREE.AdditiveBlending:c.blendEquation(c.FUNC_ADD);c.blendFunc(c.ONE,c.ONE);break;case THREE.SubtractiveBlending:c.blendFunc(c.DST_COLOR,c.ZERO);break;default:c.blendEquation(c.FUNC_ADD);c.blendFunc(c.ONE,c.ONE_MINUS_SRC_ALPHA)}};this.setFaceCulling=function(i,o){if(i){!o||o=="ccw"?c.frontFace(c.CCW):c.frontFace(c.CW);if(i=="back")c.cullFace(c.BACK);
 else i=="front"?c.cullFace(c.FRONT):c.cullFace(c.FRONT_AND_BACK);c.enable(c.CULL_FACE)}else c.disable(c.CULL_FACE)};this.supportsVertexTextures=function(){return c.getParameter(c.MAX_VERTEX_TEXTURE_IMAGE_UNITS)>0};var T={depth:{uniforms:{mNear:{type:"f",value:1},mFar:{type:"f",value:2E3}},fragment_shader:"uniform float mNear;\nuniform float mFar;\nvoid main() {\nfloat depth = gl_FragCoord.z / gl_FragCoord.w;\nfloat color = 1.0 - smoothstep( mNear, mFar, depth );\ngl_FragColor = vec4( vec3( color ), 1.0 );\n}",
 vertex_shader:"void main() {\ngl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n}"},normal:{uniforms:{},fragment_shader:"varying vec3 vNormal;\nvoid main() {\ngl_FragColor = vec4( 0.5 * normalize( vNormal ) + 0.5, 1.0 );\n}",vertex_shader:"varying vec3 vNormal;\nvoid main() {\nvec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );\nvNormal = normalize( normalMatrix * normal );\ngl_Position = projectionMatrix * mvPosition;\n}"}}};
 THREE.RenderableObject=function(){this.z=this.object=null};THREE.RenderableFace3=function(){this.z=null;this.v1=new THREE.Vertex;this.v2=new THREE.Vertex;this.v3=new THREE.Vertex;this.centroidWorld=new THREE.Vector3;this.centroidScreen=new THREE.Vector3;this.normalWorld=new THREE.Vector3;this.vertexNormalsWorld=[];this.faceMaterials=this.meshMaterials=null;this.overdraw=false;this.uvs=[null,null,null]};

+ 3 - 3
examples/geometry_minecraft_ao.html

@@ -110,15 +110,15 @@
 
 				container = document.getElementById( 'container' );
 
-				camera = new THREE.Camera( 60, window.innerWidth / window.innerHeight, 1, 20000 );
+				camera = new THREE.Camera( 60, window.innerWidth / window.innerHeight, 1, 7500 );
 				camera.target.position.z = - 100;
 
 				camera.position.y = getY( worldHalfWidth, worldHalfDepth ) * 100 + 100;
 				camera.target.position.y = camera.position.y;
 
 				scene = new THREE.Scene();
-				scene.fog = new THREE.Fog( 0xffffff, 0.00025 );
-				
+				scene.fog = new THREE.Fog( 0xffffff, 1, 7500 );
+
 				var debug_texture = false,
 					debug_numbers = false,
 					debug_corner_colors = false,

+ 2 - 2
examples/geometry_terrain_fog_gl.html

@@ -69,11 +69,11 @@
 
 				container = document.getElementById( 'container' );
 
-				camera = new THREE.Camera( 60, window.innerWidth / window.innerHeight, 1, 20000 );
+				camera = new THREE.Camera( 60, window.innerWidth / window.innerHeight, 1, 750 );
 				camera.target.position.z = - 100;
 
 				scene = new THREE.Scene();
-				scene.fog = new THREE.Fog( 0xefd1b5, 0.0025 );
+				scene.fog = new THREE.Fog( 0xefd1b5, 1, 750 );
 
 				data = generateHeight( worldWidth, worldDepth );
 

+ 3 - 4
examples/webglrenderer2_sandbox.html

@@ -127,11 +127,11 @@
 				container = document.createElement( 'div' );
 				document.body.appendChild( container );
 
-				camera = new THREE.Camera( 60, window.innerWidth / window.innerHeight, 1, 100000 );
+				camera = new THREE.Camera( 60, window.innerWidth / window.innerHeight, 1, 10000 );
 				camera.position.z = 3200;
 
 				scene = new THREE.Scene();
-				scene.fog = new THREE.Fog( 0xffffff, 0.00025 );
+				scene.fog = new THREE.Fog( 0xffffff, 1, 10000 );
 
 				var geometry = new Sphere( 50, 32, 16 );
 
@@ -151,7 +151,7 @@
 					new THREE.MeshPhongMaterial( { ambient: 0x030303, color: 0xdddddd, specular: 0x009900, shininess: 30, shading: THREE.SmoothShading } ),
 					new THREE.MeshNormalMaterial( { shading: THREE.SmoothShading } ),
 					new THREE.MeshBasicMaterial( { color: 0xffaa00, wireframe: true } ),
-					new THREE.MeshDepthMaterial( { near: 1, far: 2000 } ),
+					new THREE.MeshDepthMaterial( { near: 1, far: 10000 } ),
 					new THREE.MeshBasicMaterial( { map: generatedTexture, fog: false } ),
 					new THREE.MeshLambertMaterial( { map: generatedTexture } ),
 					new THREE.MeshShaderMaterial( { uniforms: uniforms, vertex_shader: vertex_shader, fragment_shader: fragment_shader } )
@@ -167,7 +167,6 @@
 
 				materials.push( new THREE.MeshFaceMaterial() );
 
-
 				for ( var i = 0; i < 5000; i ++ ) {
 
 					var mesh = new THREE.Mesh( geometry, materials[ Math.floor( Math.random() * materials.length ) ] );

+ 59 - 51
src/renderers/WebGLRenderer.js

@@ -38,9 +38,9 @@ THREE.WebGLRenderer = function ( scene, antialias ) {
 
 	maxLightCount = allocateLights( scene, 4 );
 	fog = scene ? scene.fog : null,
-	
+
 	aa = antialias != undefined ? antialias : true;
-	
+
 	this.domElement = _canvas;
 	this.autoClear = true;
 
@@ -363,13 +363,13 @@ THREE.WebGLRenderer = function ( scene, antialias ) {
 	};
 
 	function setMaterialShaders( material, shaders ) {
-		
+
 		material.fragment_shader = shaders.fragment_shader;
 		material.vertex_shader = shaders.vertex_shader;
 		material.uniforms = shaders.uniforms;
-		
+
 	};
-	
+
 	this.renderBuffer = function ( camera, lights, fog, material, geometryChunk ) {
 
 		var mColor, mOpacity, mReflectivity,
@@ -387,18 +387,18 @@ THREE.WebGLRenderer = function ( scene, antialias ) {
 			if ( !material.program ) {
 
 				if ( material instanceof THREE.MeshDepthMaterial ) {
-					
+
 					setMaterialShaders( material, ShaderLib[ 'depth' ] );
-					
+
 					material.uniforms.mNear.value = material.near;
 					material.uniforms.mFar.value = material.far;
-					
+
 				} else if ( material instanceof THREE.MeshNormalMaterial ) {
-					
+
 					setMaterialShaders( material, ShaderLib[ 'normal' ] );
-					
-				}					
-				
+
+				}
+
 				material.program = buildProgram( material.fragment_shader, material.vertex_shader, null );
 
 				identifiers = [ 'viewMatrix', 'modelViewMatrix', 'projectionMatrix', 'normalMatrix', 'objectMatrix', 'cameraPosition' ];
@@ -407,7 +407,7 @@ THREE.WebGLRenderer = function ( scene, antialias ) {
 					identifiers.push(u);
 
 				}
-				
+
 				cacheUniformLocations( material.program, identifiers );
 				cacheAttributeLocations( material.program, [ "position", "normal", "uv", "tangent" ] );
 
@@ -437,7 +437,7 @@ THREE.WebGLRenderer = function ( scene, antialias ) {
 		this.loadCamera( program, camera );
 		this.loadMatrices( program );
 
-		if ( material instanceof THREE.MeshShaderMaterial || 
+		if ( material instanceof THREE.MeshShaderMaterial ||
 		     material instanceof THREE.MeshDepthMaterial ||
 			 material instanceof THREE.MeshNormalMaterial ) {
 
@@ -478,12 +478,13 @@ THREE.WebGLRenderer = function ( scene, antialias ) {
 
 			_gl.uniform1i( program.uniforms.useRefract, useRefract );
 			_gl.uniform1f( program.uniforms.mRefractionRatio, mRefractionRatio );
-			
+
 			if ( fog ) {
-				
-				_gl.uniform1f( program.uniforms.fogDensity, fog.density );
+
+				_gl.uniform1f( program.uniforms.fogNear, fog.near );
+				_gl.uniform1f( program.uniforms.fogFar, fog.far );
 				_gl.uniform3f( program.uniforms.fogColor, fog.color.r, fog.color.g, fog.color.b );
-				
+
 			}
 
 		}
@@ -535,7 +536,7 @@ THREE.WebGLRenderer = function ( scene, antialias ) {
 			_gl.uniform1i( program.uniforms.enableCubeMap, 0 );
 
 		}
-		
+
 		attributes = program.attributes;
 
 		// vertices
@@ -561,7 +562,7 @@ THREE.WebGLRenderer = function ( scene, antialias ) {
 			_gl.bindBuffer( _gl.ARRAY_BUFFER, geometryChunk.__webGLTangentBuffer );
 			_gl.vertexAttribPointer( attributes.tangent, 4, _gl.FLOAT, false, 0, 0 );
 			_gl.enableVertexAttribArray( attributes.tangent );
-			
+
 		}
 
 		// uvs
@@ -569,7 +570,7 @@ THREE.WebGLRenderer = function ( scene, antialias ) {
 		if ( attributes.uv >= 0 ) {
 
 			if ( geometryChunk.__webGLUVBuffer ) {
-				
+
 				_gl.bindBuffer( _gl.ARRAY_BUFFER, geometryChunk.__webGLUVBuffer );
 				_gl.vertexAttribPointer( attributes.uv, 2, _gl.FLOAT, false, 0, 0 );
 
@@ -957,7 +958,8 @@ THREE.WebGLRenderer = function ( scene, antialias ) {
 
 			"#ifdef USE_FOG",
 				"uniform vec3 fogColor;",
-				"uniform float fogDensity;",
+				"uniform float fogNear;",
+				"uniform float fogFar;",
 			"#endif",
 
 			"uniform int pointLightNumber;",
@@ -1113,17 +1115,23 @@ THREE.WebGLRenderer = function ( scene, antialias ) {
 					"}",
 
 				"}",
-				
+
 				"#ifdef USE_FOG",
-		
+
+					"float depth = gl_FragCoord.z / gl_FragCoord.w;",
+					"float fogFactor = smoothstep( fogNear, fogFar, depth );",
+					"gl_FragColor = mix( gl_FragColor, vec4( fogColor, 1.0 ), fogFactor );",
+
+					/*
 					"const float LOG2 = 1.442695;",
 					"float z = gl_FragCoord.z / gl_FragCoord.w;",
 					"float fogFactor = exp2( - fogDensity * fogDensity * z * z * LOG2 );",
 					"fogFactor = clamp( fogFactor, 0.0, 1.0 );",
 					"gl_FragColor = mix( vec4( fogColor, 1.0 ), gl_FragColor, fogFactor );",
-			
+					*/
+
 				"#endif",
-				
+
 			"}" ];
 
 		return chunks.join("\n");
@@ -1237,12 +1245,12 @@ THREE.WebGLRenderer = function ( scene, antialias ) {
 			"#endif",
 
 			fog ? "#define USE_FOG" : "",
-		
+
 			"uniform mat4 viewMatrix;",
 			"uniform vec3 cameraPosition;",
 			""
 		].join("\n"),
-		
+
 		prefix_vertex = [
 			maxVertexTextures() > 0 ? "#define VERTEX_TEXTURES" : "",
 
@@ -1257,7 +1265,7 @@ THREE.WebGLRenderer = function ( scene, antialias ) {
 			"attribute vec2 uv;",
 			""
 		].join("\n");
-		
+
 		_gl.attachShader( program, getShader( "fragment", prefix_fragment + fragment_shader ) );
 		_gl.attachShader( program, getShader( "vertex", prefix_vertex + vertex_shader ) );
 
@@ -1440,9 +1448,9 @@ THREE.WebGLRenderer = function ( scene, antialias ) {
 		] );
 
 		if ( fog ) {
-			
-			cacheUniformLocations( program, [ 'fogColor', 'fogDensity' ] );
-			
+
+			cacheUniformLocations( program, [ 'fogColor', 'fogNear', 'fogFar' ] );
+
 		}
 
 		if ( maxDirLights ) {
@@ -1642,29 +1650,29 @@ THREE.WebGLRenderer = function ( scene, antialias ) {
 		return str;
 	}
 	*/
-	
+
 	var ShaderLib = {
-		
+
 		'depth': {
 
-			uniforms: { "mNear": { type: "f", value: 1.0 }, 
+			uniforms: { "mNear": { type: "f", value: 1.0 },
 						"mFar" : { type: "f", value: 2000.0 } },
 
 			fragment_shader: [
-				
+
 				"uniform float mNear;",
 				"uniform float mFar;",
 
 				"void main() {",
-						
+
 					"float depth = gl_FragCoord.z / gl_FragCoord.w;",
 					"float color = 1.0 - smoothstep( mNear, mFar, depth );",
 					"gl_FragColor = vec4( vec3( color ), 1.0 );",
-					
+
 				"}"
 
 			].join("\n"),
-						
+
 			vertex_shader: [
 
 				"void main() {",
@@ -1676,29 +1684,29 @@ THREE.WebGLRenderer = function ( scene, antialias ) {
 			].join("\n")
 
 		},
-		
+
 		'normal': {
-			
+
 			uniforms: { },
-			
+
 			fragment_shader: [
-				
+
 				"varying vec3 vNormal;",
-			
+
 				"void main() {",
-						
+
 					"gl_FragColor = vec4( 0.5 * normalize( vNormal ) + 0.5, 1.0 );",
-					
+
 				"}"
 
 			].join("\n"),
-			
+
 			vertex_shader: [
-			
+
 				"varying vec3 vNormal;",
 
 				"void main() {",
-			
+
 					"vec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );",
 					"vNormal = normalize( normalMatrix * normal );",
 
@@ -1707,9 +1715,9 @@ THREE.WebGLRenderer = function ( scene, antialias ) {
 				"}"
 
 			].join("\n")
-			
+
 		}
-		
+
 	};
 
 };

+ 16 - 16
src/renderers/WebGLRenderer2.js

@@ -150,7 +150,8 @@ THREE.WebGLRenderer2 = function ( antialias ) {
 						if ( scene.fog ) {
 
 							_gl.uniform1f( uniforms.fog, 1 );
-							_gl.uniform1f( uniforms.fogDensity, scene.fog.density );
+							_gl.uniform1f( uniforms.fogNear, scene.fog.near );
+							_gl.uniform1f( uniforms.fogFar, scene.fog.far );
 							_gl.uniform3f( uniforms.fogColor, scene.fog.color.r, scene.fog.color.g, scene.fog.color.b );
 
 						} else {
@@ -181,9 +182,8 @@ THREE.WebGLRenderer2 = function ( antialias ) {
 
 						} else if ( material instanceof THREE.MeshDepthMaterial ) {
 
-							_gl.uniform1f( uniforms.m2Near, material.__2near );
-							_gl.uniform1f( uniforms.mFarPlusNear, material.__farPlusNear );
-							_gl.uniform1f( uniforms.mFarMinusNear, material.__farMinusNear );
+							_gl.uniform1f( uniforms.mNear, material.near );
+							_gl.uniform1f( uniforms.mFar, material.far );
 							_gl.uniform1f( uniforms.mOpacity, material.opacity );
 
 						}
@@ -492,8 +492,9 @@ THREE.WebGLRenderer2 = function ( antialias ) {
 					material.map ? 'varying vec2 vUv;' : null,
 
 					material.fog ? 'uniform float fog;' : null,
+					material.fog ? 'uniform float fogNear;' : null,
+					material.fog ? 'uniform float fogFar;' : null,
 					material.fog ? 'uniform vec3 fogColor;' : null,
-					material.fog ? 'uniform float fogDensity;' : null,
 
 					'void main() {',
 						'gl_FragColor = vec4( mColor.xyz, mOpacity );',
@@ -505,16 +506,15 @@ THREE.WebGLRenderer2 = function ( antialias ) {
 
 						material.map ? 'gl_FragColor *= texture2D( tMap, vUv );' : null,
 
-						material.fog ? 'const float LOG2 = 1.442695;' : null,
-						material.fog ? 'float z = fog * ( gl_FragCoord.z / gl_FragCoord.w );' : null,
-						material.fog ? 'float fogFactor = exp2( - fogDensity * fogDensity * z * z * LOG2 );' : null,
-						material.fog ? 'gl_FragColor = mix( gl_FragColor, vec4( fogColor, 1.0 ), 1.0 - clamp( fogFactor, 0.0, 1.0 ) );' : null,
+						material.fog ? 'float depth = gl_FragCoord.z / gl_FragCoord.w;' : null,
+						material.fog ? 'float fogFactor = fog * smoothstep( fogNear, fogFar, depth );' : null,
+						material.fog ? 'gl_FragColor = mix( gl_FragColor, vec4( fogColor, 1.0 ), fogFactor );' : null,
 					'}'
 				].filter( removeNull ).join( '\n' );
 
 				identifiers.push( 'mColor', 'mOpacity' );
 				material.map ? identifiers.push( 'tMap' ) : null;
-				material.fog ? identifiers.push( 'fog', 'fogColor', 'fogDensity' ) : null;
+				material.fog ? identifiers.push( 'fog', 'fogColor', 'fogNear', 'fogFar' ) : null;
 
 
 			} else if ( material instanceof THREE.MeshNormalMaterial ) {
@@ -549,18 +549,18 @@ THREE.WebGLRenderer2 = function ( antialias ) {
 				].join( '\n' );
 
 				fs = [
-					'uniform float m2Near;',
-					'uniform float mFarPlusNear;',
-					'uniform float mFarMinusNear;',
+					'uniform float mNear;',
+					'uniform float mFar;',
 					'uniform float mOpacity;',
 
 					'void main() {',
-						'float w = 1.0 - ( m2Near / ( mFarPlusNear - gl_FragCoord.z * mFarMinusNear ) );',
-						'gl_FragColor = vec4( w, w, w, mOpacity );',
+						'float depth = gl_FragCoord.z / gl_FragCoord.w;',
+						'float color = 1.0 - smoothstep( mNear, mFar, depth );',
+						'gl_FragColor = vec4( vec3( color ), 1.0 );',
 					'}'
 				].join( '\n' );
 
-				identifiers.push( 'm2Near', 'mFarPlusNear', 'mFarMinusNear', 'mOpacity' );
+				identifiers.push( 'mNear', 'mFar', 'mOpacity' );
 
 			} else if ( material instanceof THREE.MeshShaderMaterial ) {
 

+ 3 - 2
src/scenes/Fog.js

@@ -3,9 +3,10 @@
  * @author alteredq / http://alteredqualia.com/
  */
 
-THREE.Fog = function ( hex, density ) {
+THREE.Fog = function ( hex, near, far ) {
 
 	this.color = new THREE.Color( hex );
-	this.density = density || 0.00025;
+	this.near = near || 1;
+	this.far = far || 1000;
 
 };