diff --git a/build/Three.js b/build/Three.js index bdc9599f..48c7eae7 100755 --- a/build/Three.js +++ b/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 (
image: "+this.image+"
wrap_s: "+this.wrap_s+"
wrap_t: "+this.wrap_t+"
mag_filter: "+this.mag_filter+"
min_filter: "+this.min_filter+"
)"}};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= 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=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=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=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]}; diff --git a/build/ThreeDebug.js b/build/ThreeDebug.js index a4d23808..ba454395 100644 --- a/build/ThreeDebug.js +++ b/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 (
image: "+this.image+"
wrap_s: "+this.wrap_s+"
wrap_t: "+this.wrap_t+"
mag_filter: "+this.mag_filter+"
min_filter: "+this.min_filter+"
)"}};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= 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=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=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=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]}; diff --git a/build/ThreeExtras.js b/build/ThreeExtras.js index dee1831e..43cc3e0b 100644 --- a/build/ThreeExtras.js +++ b/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 (
image: "+this.image+"
wrap_s: "+this.wrap_s+"
wrap_t: "+this.wrap_t+"
mag_filter: "+this.mag_filter+"
min_filter: "+this.min_filter+"
)"}};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= 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=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=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=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]}; diff --git a/examples/geometry_minecraft_ao.html b/examples/geometry_minecraft_ao.html index 60f2f054..837fc045 100644 --- a/examples/geometry_minecraft_ao.html +++ b/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, diff --git a/examples/geometry_terrain_fog_gl.html b/examples/geometry_terrain_fog_gl.html index 50fac96b..7f2bfa8b 100644 --- a/examples/geometry_terrain_fog_gl.html +++ b/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 ); diff --git a/examples/webglrenderer2_sandbox.html b/examples/webglrenderer2_sandbox.html index aaa2d407..2e0051cf 100644 --- a/examples/webglrenderer2_sandbox.html +++ b/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 ) ] ); diff --git a/src/renderers/WebGLRenderer.js b/src/renderers/WebGLRenderer.js index e455552b..1bb1ede8 100644 --- a/src/renderers/WebGLRenderer.js +++ b/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") - + } - + }; }; diff --git a/src/renderers/WebGLRenderer2.js b/src/renderers/WebGLRenderer2.js index 6282b6b5..24c3b48f 100644 --- a/src/renderers/WebGLRenderer2.js +++ b/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 ) { diff --git a/src/scenes/Fog.js b/src/scenes/Fog.js index ee4bf306..82c9d67b 100644 --- a/src/scenes/Fog.js +++ b/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; };