提交 d110c49c 编写于 作者: A alteredq

Added support for `flipSided` mesh property to WebGLRenderer.

Also doesn't seem to decrease performance so far (though most of demos have small number of objects).
上级 271ba6c5
......@@ -178,16 +178,17 @@ h,n,j,o,z,k){var s,t,r,l,H;r=0;for(l=j.materials.length;r<l;r++){s=j.materials[r
b.createFramebuffer();n.__webGLRenderbuffer=b.createRenderbuffer();n.__webGLTexture=b.createTexture();b.bindRenderbuffer(b.RENDERBUFFER,n.__webGLRenderbuffer);b.renderbufferStorage(b.RENDERBUFFER,b.DEPTH_COMPONENT16,n.width,n.height);b.bindTexture(b.TEXTURE_2D,n.__webGLTexture);b.texParameteri(b.TEXTURE_2D,b.TEXTURE_WRAP_S,i(n.wrap_s));b.texParameteri(b.TEXTURE_2D,b.TEXTURE_WRAP_T,i(n.wrap_t));b.texParameteri(b.TEXTURE_2D,b.TEXTURE_MAG_FILTER,i(n.mag_filter));b.texParameteri(b.TEXTURE_2D,b.TEXTURE_MIN_FILTER,
i(n.min_filter));b.texImage2D(b.TEXTURE_2D,0,i(n.format),n.width,n.height,0,i(n.format),i(n.type),null);b.bindFramebuffer(b.FRAMEBUFFER,n.__webGLFramebuffer);b.framebufferTexture2D(b.FRAMEBUFFER,b.COLOR_ATTACHMENT0,b.TEXTURE_2D,n.__webGLTexture,0);b.framebufferRenderbuffer(b.FRAMEBUFFER,b.DEPTH_ATTACHMENT,b.RENDERBUFFER,n.__webGLRenderbuffer);b.bindTexture(b.TEXTURE_2D,null);b.bindRenderbuffer(b.RENDERBUFFER,null);b.bindFramebuffer(b.FRAMEBUFFER,null)}if(n){o=n.__webGLFramebuffer;k=n.width;z=n.height}else{o=
null;k=q.width;z=q.height}if(o!=p){b.bindFramebuffer(b.FRAMEBUFFER,o);b.viewport(0,0,k,z);j&&b.clear(b.COLOR_BUFFER_BIT|b.DEPTH_BUFFER_BIT);p=o}this.autoClear&&this.clear();h.autoUpdateMatrix&&h.updateMatrix();w.set(h.matrix.flatten());S.set(h.projectionMatrix.flatten());j=0;for(o=e.__webGLObjects.length;j<o;j++){z=e.__webGLObjects[j];k=z.object;z=z.buffer;if(k.visible){this.setupMatrices(k,h);this.renderPass(h,s,t,k,z,THREE.NormalBlending,false)}}j=0;for(o=e.__webGLObjects.length;j<o;j++){z=e.__webGLObjects[j];
k=z.object;z=z.buffer;if(k.visible){this.setupMatrices(k,h);k.doubleSided?b.disable(b.CULL_FACE):b.enable(b.CULL_FACE);this.renderPass(h,s,t,k,z,THREE.AdditiveBlending,false);this.renderPass(h,s,t,k,z,THREE.SubtractiveBlending,false);this.renderPass(h,s,t,k,z,THREE.AdditiveBlending,true);this.renderPass(h,s,t,k,z,THREE.SubtractiveBlending,true);this.renderPass(h,s,t,k,z,THREE.NormalBlending,true)}}if(n&&n.min_filter!==THREE.NearestFilter&&n.min_filter!==THREE.LinearFilter){b.bindTexture(b.TEXTURE_2D,
n.__webGLTexture);b.generateMipmap(b.TEXTURE_2D);b.bindTexture(b.TEXTURE_2D,null)}};this.initWebGLObjects=function(e){function h(r,l,H,x){if(r[l]==undefined){e.__webGLObjects.push({buffer:H,object:x});r[l]=1}}var n,j,o,z,k,s,t;if(!e.__webGLObjects){e.__webGLObjects=[];e.__webGLObjectsMap={}}n=0;for(j=e.objects.length;n<j;n++){o=e.objects[n];k=o.geometry;if(e.__webGLObjectsMap[o.id]==undefined)e.__webGLObjectsMap[o.id]={};t=e.__webGLObjectsMap[o.id];if(o instanceof THREE.Mesh){for(z in k.geometryChunks){s=
k.geometryChunks[z];if(!s.__webGLVertexBuffer){this.createMeshBuffers(s);this.initMeshBuffers(s,o);k.__dirtyVertices=true;k.__dirtyElements=true;k.__dirtyUvs=true;k.__dirtyNormals=true;k.__dirtyTangents=true}if(k.__dirtyVertices||k.__dirtyElements||k.__dirtyUvs)this.setMeshBuffers(s,o,b.DYNAMIC_DRAW,k.__dirtyVertices,k.__dirtyElements,k.__dirtyUvs,k.__dirtyNormals,k.__dirtyTangents);h(t,z,s,o)}k.__dirtyVertices=false;k.__dirtyElements=false;k.__dirtyUvs=false;k.__dirtyNormals=false;k.__dirtyTangents=
false}else if(o instanceof THREE.Line){if(!k.__webGLVertexBuffer){this.createLineBuffers(k);this.initLineBuffers(k);k.__dirtyVertices=true;k.__dirtyElements=true}k.__dirtyVertices&&this.setLineBuffers(k,b.DYNAMIC_DRAW,k.__dirtyVertices,k.__dirtyElements);h(t,0,k,o);k.__dirtyVertices=false;k.__dirtyElements=false}else if(o instanceof THREE.ParticleSystem){k.__webGLVertexBuffer||this.createParticleBuffers(k);h(t,0,k,o)}}};this.removeObject=function(e,h){var n,j;for(n=e.__webGLObjects.length-1;n>=0;n--){j=
e.__webGLObjects[n].object;h==j&&e.__webGLObjects.splice(n,1)}};this.setupMatrices=function(e,h){e.autoUpdateMatrix&&e.updateMatrix();D.multiply(h.matrix,e.matrix);A.set(D.flatten());F=THREE.Matrix4.makeInvert3x3(D).transpose();V.set(F.m);T.set(e.matrix.flatten())};this.loadMatrices=function(e){b.uniformMatrix4fv(e.uniforms.viewMatrix,false,w);b.uniformMatrix4fv(e.uniforms.modelViewMatrix,false,A);b.uniformMatrix4fv(e.uniforms.projectionMatrix,false,S);b.uniformMatrix3fv(e.uniforms.normalMatrix,false,
V);b.uniformMatrix4fv(e.uniforms.objectMatrix,false,T)};this.loadCamera=function(e,h){b.uniform3f(e.uniforms.cameraPosition,h.position.x,h.position.y,h.position.z)};this.setBlending=function(e){switch(e){case THREE.AdditiveBlending:b.blendEquation(b.FUNC_ADD);b.blendFunc(b.ONE,b.ONE);break;case THREE.SubtractiveBlending:b.blendFunc(b.DST_COLOR,b.ZERO);break;default:b.blendEquation(b.FUNC_ADD);b.blendFunc(b.ONE,b.ONE_MINUS_SRC_ALPHA)}};this.setFaceCulling=function(e,h){if(e){!h||h=="ccw"?b.frontFace(b.CCW):
b.frontFace(b.CW);if(e=="back")b.cullFace(b.BACK);else e=="front"?b.cullFace(b.FRONT):b.cullFace(b.FRONT_AND_BACK);b.enable(b.CULL_FACE)}else b.disable(b.CULL_FACE)};this.supportsVertexTextures=function(){return b.getParameter(b.MAX_VERTEX_TEXTURE_IMAGE_UNITS)>0}};
THREE.Snippets={fog_pars_fragment:"#ifdef USE_FOG\nuniform vec3 fogColor;\n#ifdef FOG_EXP2\nuniform float fogDensity;\n#else\nuniform float fogNear;\nuniform float fogFar;\n#endif\n#endif",fog_fragment:"#ifdef USE_FOG\nfloat depth = gl_FragCoord.z / gl_FragCoord.w;\n#ifdef FOG_EXP2\nconst float LOG2 = 1.442695;\nfloat fogFactor = exp2( - fogDensity * fogDensity * depth * depth * LOG2 );\nfogFactor = 1.0 - clamp( fogFactor, 0.0, 1.0 );\n#else\nfloat fogFactor = smoothstep( fogNear, fogFar, depth );\n#endif\ngl_FragColor = mix( gl_FragColor, vec4( fogColor, 1.0 ), fogFactor );\n#endif",envmap_pars_fragment:"#ifdef USE_ENVMAP\nvarying vec3 vReflect;\nuniform float reflectivity;\nuniform samplerCube env_map;\nuniform int combine;\n#endif",
envmap_fragment:"#ifdef USE_ENVMAP\ncubeColor = textureCube( env_map, vec3( -vReflect.x, vReflect.yz ) );\nif ( combine == 1 ) {\ngl_FragColor = mix( gl_FragColor, cubeColor, reflectivity );\n} else {\ngl_FragColor = gl_FragColor * cubeColor;\n}\n#endif",envmap_pars_vertex:"#ifdef USE_ENVMAP\nvarying vec3 vReflect;\nuniform float refraction_ratio;\nuniform bool useRefract;\n#endif",envmap_vertex:"#ifdef USE_ENVMAP\nvec4 mPosition = objectMatrix * vec4( position, 1.0 );\nvec3 nWorld = mat3( objectMatrix[0].xyz, objectMatrix[1].xyz, objectMatrix[2].xyz ) * normal;\nif ( useRefract ) {\nvReflect = refract( normalize( mPosition.xyz - cameraPosition ), normalize( nWorld.xyz ), refraction_ratio );\n} else {\nvReflect = reflect( normalize( mPosition.xyz - cameraPosition ), normalize( nWorld.xyz ) );\n}\n#endif",
map_pars_fragment:"#ifdef USE_MAP\nvarying vec2 vUv;\nuniform sampler2D map;\n#endif",map_pars_vertex:"#ifdef USE_MAP\nvarying vec2 vUv;\n#endif",map_fragment:"#ifdef USE_MAP\nmapColor = texture2D( map, vUv );\n#endif",map_vertex:"#ifdef USE_MAP\nvUv = uv;\n#endif",lights_pars_vertex:"uniform bool enableLighting;\nuniform vec3 ambientLightColor;\n#if MAX_DIR_LIGHTS > 0\nuniform vec3 directionalLightColor[ MAX_DIR_LIGHTS ];\nuniform vec3 directionalLightDirection[ MAX_DIR_LIGHTS ];\n#endif\n#if MAX_POINT_LIGHTS > 0\nuniform vec3 pointLightColor[ MAX_POINT_LIGHTS ];\nuniform vec3 pointLightPosition[ MAX_POINT_LIGHTS ];\n#ifdef PHONG\nvarying vec3 vPointLightVector[ MAX_POINT_LIGHTS ];\n#endif\n#endif",
k=z.object;z=z.buffer;if(k.visible){this.setupMatrices(k,h);if(k.doubleSided)b.disable(b.CULL_FACE);else{b.enable(b.CULL_FACE);k.flipSided?b.frontFace(b.CW):b.frontFace(b.CCW)}this.renderPass(h,s,t,k,z,THREE.AdditiveBlending,false);this.renderPass(h,s,t,k,z,THREE.SubtractiveBlending,false);this.renderPass(h,s,t,k,z,THREE.AdditiveBlending,true);this.renderPass(h,s,t,k,z,THREE.SubtractiveBlending,true);this.renderPass(h,s,t,k,z,THREE.NormalBlending,true)}}if(n&&n.min_filter!==THREE.NearestFilter&&n.min_filter!==
THREE.LinearFilter){b.bindTexture(b.TEXTURE_2D,n.__webGLTexture);b.generateMipmap(b.TEXTURE_2D);b.bindTexture(b.TEXTURE_2D,null)}};this.initWebGLObjects=function(e){function h(r,l,H,x){if(r[l]==undefined){e.__webGLObjects.push({buffer:H,object:x});r[l]=1}}var n,j,o,z,k,s,t;if(!e.__webGLObjects){e.__webGLObjects=[];e.__webGLObjectsMap={}}n=0;for(j=e.objects.length;n<j;n++){o=e.objects[n];k=o.geometry;if(e.__webGLObjectsMap[o.id]==undefined)e.__webGLObjectsMap[o.id]={};t=e.__webGLObjectsMap[o.id];if(o instanceof
THREE.Mesh){for(z in k.geometryChunks){s=k.geometryChunks[z];if(!s.__webGLVertexBuffer){this.createMeshBuffers(s);this.initMeshBuffers(s,o);k.__dirtyVertices=true;k.__dirtyElements=true;k.__dirtyUvs=true;k.__dirtyNormals=true;k.__dirtyTangents=true}if(k.__dirtyVertices||k.__dirtyElements||k.__dirtyUvs)this.setMeshBuffers(s,o,b.DYNAMIC_DRAW,k.__dirtyVertices,k.__dirtyElements,k.__dirtyUvs,k.__dirtyNormals,k.__dirtyTangents);h(t,z,s,o)}k.__dirtyVertices=false;k.__dirtyElements=false;k.__dirtyUvs=false;
k.__dirtyNormals=false;k.__dirtyTangents=false}else if(o instanceof THREE.Line){if(!k.__webGLVertexBuffer){this.createLineBuffers(k);this.initLineBuffers(k);k.__dirtyVertices=true;k.__dirtyElements=true}k.__dirtyVertices&&this.setLineBuffers(k,b.DYNAMIC_DRAW,k.__dirtyVertices,k.__dirtyElements);h(t,0,k,o);k.__dirtyVertices=false;k.__dirtyElements=false}else if(o instanceof THREE.ParticleSystem){k.__webGLVertexBuffer||this.createParticleBuffers(k);h(t,0,k,o)}}};this.removeObject=function(e,h){var n,
j;for(n=e.__webGLObjects.length-1;n>=0;n--){j=e.__webGLObjects[n].object;h==j&&e.__webGLObjects.splice(n,1)}};this.setupMatrices=function(e,h){e.autoUpdateMatrix&&e.updateMatrix();D.multiply(h.matrix,e.matrix);A.set(D.flatten());F=THREE.Matrix4.makeInvert3x3(D).transpose();V.set(F.m);T.set(e.matrix.flatten())};this.loadMatrices=function(e){b.uniformMatrix4fv(e.uniforms.viewMatrix,false,w);b.uniformMatrix4fv(e.uniforms.modelViewMatrix,false,A);b.uniformMatrix4fv(e.uniforms.projectionMatrix,false,S);
b.uniformMatrix3fv(e.uniforms.normalMatrix,false,V);b.uniformMatrix4fv(e.uniforms.objectMatrix,false,T)};this.loadCamera=function(e,h){b.uniform3f(e.uniforms.cameraPosition,h.position.x,h.position.y,h.position.z)};this.setBlending=function(e){switch(e){case THREE.AdditiveBlending:b.blendEquation(b.FUNC_ADD);b.blendFunc(b.ONE,b.ONE);break;case THREE.SubtractiveBlending:b.blendFunc(b.DST_COLOR,b.ZERO);break;default:b.blendEquation(b.FUNC_ADD);b.blendFunc(b.ONE,b.ONE_MINUS_SRC_ALPHA)}};this.setFaceCulling=
function(e,h){if(e){!h||h=="ccw"?b.frontFace(b.CCW):b.frontFace(b.CW);if(e=="back")b.cullFace(b.BACK);else e=="front"?b.cullFace(b.FRONT):b.cullFace(b.FRONT_AND_BACK);b.enable(b.CULL_FACE)}else b.disable(b.CULL_FACE)};this.supportsVertexTextures=function(){return b.getParameter(b.MAX_VERTEX_TEXTURE_IMAGE_UNITS)>0}};
THREE.Snippets={fog_pars_fragment:"#ifdef USE_FOG\nuniform vec3 fogColor;\n#ifdef FOG_EXP2\nuniform float fogDensity;\n#else\nuniform float fogNear;\nuniform float fogFar;\n#endif\n#endif",fog_fragment:"#ifdef USE_FOG\nfloat depth = gl_FragCoord.z / gl_FragCoord.w;\n#ifdef FOG_EXP2\nconst float LOG2 = 1.442695;\nfloat fogFactor = exp2( - fogDensity * fogDensity * depth * depth * LOG2 );\nfogFactor = 1.0 - clamp( fogFactor, 0.0, 1.0 );\n#else\nfloat fogFactor = smoothstep( fogNear, fogFar, depth );\n#endif\ngl_FragColor = mix( gl_FragColor, vec4( fogColor, 1.0 ), fogFactor );\n#endif",
envmap_pars_fragment:"#ifdef USE_ENVMAP\nvarying vec3 vReflect;\nuniform float reflectivity;\nuniform samplerCube env_map;\nuniform int combine;\n#endif",envmap_fragment:"#ifdef USE_ENVMAP\ncubeColor = textureCube( env_map, vec3( -vReflect.x, vReflect.yz ) );\nif ( combine == 1 ) {\ngl_FragColor = mix( gl_FragColor, cubeColor, reflectivity );\n} else {\ngl_FragColor = gl_FragColor * cubeColor;\n}\n#endif",envmap_pars_vertex:"#ifdef USE_ENVMAP\nvarying vec3 vReflect;\nuniform float refraction_ratio;\nuniform bool useRefract;\n#endif",
envmap_vertex:"#ifdef USE_ENVMAP\nvec4 mPosition = objectMatrix * vec4( position, 1.0 );\nvec3 nWorld = mat3( objectMatrix[0].xyz, objectMatrix[1].xyz, objectMatrix[2].xyz ) * normal;\nif ( useRefract ) {\nvReflect = refract( normalize( mPosition.xyz - cameraPosition ), normalize( nWorld.xyz ), refraction_ratio );\n} else {\nvReflect = reflect( normalize( mPosition.xyz - cameraPosition ), normalize( nWorld.xyz ) );\n}\n#endif",map_pars_fragment:"#ifdef USE_MAP\nvarying vec2 vUv;\nuniform sampler2D map;\n#endif",
map_pars_vertex:"#ifdef USE_MAP\nvarying vec2 vUv;\n#endif",map_fragment:"#ifdef USE_MAP\nmapColor = texture2D( map, vUv );\n#endif",map_vertex:"#ifdef USE_MAP\nvUv = uv;\n#endif",lights_pars_vertex:"uniform bool enableLighting;\nuniform vec3 ambientLightColor;\n#if MAX_DIR_LIGHTS > 0\nuniform vec3 directionalLightColor[ MAX_DIR_LIGHTS ];\nuniform vec3 directionalLightDirection[ MAX_DIR_LIGHTS ];\n#endif\n#if MAX_POINT_LIGHTS > 0\nuniform vec3 pointLightColor[ MAX_POINT_LIGHTS ];\nuniform vec3 pointLightPosition[ MAX_POINT_LIGHTS ];\n#ifdef PHONG\nvarying vec3 vPointLightVector[ MAX_POINT_LIGHTS ];\n#endif\n#endif",
lights_vertex:"if ( !enableLighting ) {\nvLightWeighting = vec3( 1.0 );\n} else {\nvLightWeighting = ambientLightColor;\n#if MAX_DIR_LIGHTS > 0\nfor( int i = 0; i < MAX_DIR_LIGHTS; i++ ) {\nvec4 lDirection = viewMatrix * vec4( directionalLightDirection[ i ], 0.0 );\nfloat directionalLightWeighting = max( dot( transformedNormal, normalize( lDirection.xyz ) ), 0.0 );\nvLightWeighting += directionalLightColor[ i ] * directionalLightWeighting;\n}\n#endif\n#if MAX_POINT_LIGHTS > 0\nfor( int i = 0; i < MAX_POINT_LIGHTS; i++ ) {\nvec4 lPosition = viewMatrix * vec4( pointLightPosition[ i ], 1.0 );\nvec3 pointLightVector = normalize( lPosition.xyz - mvPosition.xyz );\nfloat pointLightWeighting = max( dot( transformedNormal, pointLightVector ), 0.0 );\nvLightWeighting += pointLightColor[ i ] * pointLightWeighting;\n#ifdef PHONG\nvPointLightVector[ i ] = pointLightVector;\n#endif\n}\n#endif\n}",
lights_pars_fragment:"#if MAX_DIR_LIGHTS > 0\nuniform vec3 directionalLightDirection[ MAX_DIR_LIGHTS ];\n#endif\n#if MAX_POINT_LIGHTS > 0\nvarying vec3 vPointLightVector[ MAX_POINT_LIGHTS ];\n#endif\nvarying vec3 vViewPosition;\nvarying vec3 vNormal;",lights_fragment:"vec3 normal = normalize( vNormal );\nvec3 viewPosition = normalize( vViewPosition );\nvec4 mSpecular = vec4( specular, opacity );\n#if MAX_POINT_LIGHTS > 0\nvec4 pointDiffuse = vec4( 0.0 );\nvec4 pointSpecular = vec4( 0.0 );\nfor( int i = 0; i < MAX_POINT_LIGHTS; i++ ) {\nvec3 pointVector = normalize( vPointLightVector[ i ] );\nvec3 pointHalfVector = normalize( vPointLightVector[ i ] + vViewPosition );\nfloat pointDotNormalHalf = dot( normal, pointHalfVector );\nfloat pointDiffuseWeight = max( dot( normal, pointVector ), 0.0 );\nfloat pointSpecularWeight = 0.0;\nif ( pointDotNormalHalf >= 0.0 )\npointSpecularWeight = pow( pointDotNormalHalf, shininess );\npointDiffuse += mColor * pointDiffuseWeight;\npointSpecular += mSpecular * pointSpecularWeight;\n}\n#endif\n#if MAX_DIR_LIGHTS > 0\nvec4 dirDiffuse = vec4( 0.0 );\nvec4 dirSpecular = vec4( 0.0 );\nfor( int i = 0; i < MAX_DIR_LIGHTS; i++ ) {\nvec4 lDirection = viewMatrix * vec4( directionalLightDirection[ i ], 0.0 );\nvec3 dirVector = normalize( lDirection.xyz );\nvec3 dirHalfVector = normalize( lDirection.xyz + vViewPosition );\nfloat dirDotNormalHalf = dot( normal, dirHalfVector );\nfloat dirDiffuseWeight = max( dot( normal, dirVector ), 0.0 );\nfloat dirSpecularWeight = 0.0;\nif ( dirDotNormalHalf >= 0.0 )\ndirSpecularWeight = pow( dirDotNormalHalf, shininess );\ndirDiffuse += mColor * dirDiffuseWeight;\ndirSpecular += mSpecular * dirSpecularWeight;\n}\n#endif\nvec4 totalLight = vec4( ambient, opacity );\n#if MAX_DIR_LIGHTS > 0\ntotalLight += dirDiffuse + dirSpecular;\n#endif\n#if MAX_POINT_LIGHTS > 0\ntotalLight += pointDiffuse + pointSpecular;\n#endif"};
THREE.UniformsLib={common:{color:{type:"c",value:new THREE.Color(15658734)},opacity:{type:"f",value:1},map:{type:"t",value:0,texture:null},env_map:{type:"t",value:1,texture:null},useRefract:{type:"i",value:0},reflectivity:{type:"f",value:1},refraction_ratio:{type:"f",value:0.98},combine:{type:"i",value:0},fogDensity:{type:"f",value:2.5E-4},fogNear:{type:"f",value:1},fogFar:{type:"f",value:2E3},fogColor:{type:"c",value:new THREE.Color(16777215)}},lights:{enableLighting:{type:"i",value:1},ambientLightColor:{type:"fv",
......
......@@ -179,16 +179,17 @@ h,o,j,p,z,k){var s,t,r,l,H;r=0;for(l=j.materials.length;r<l;r++){s=j.materials[r
b.createFramebuffer();o.__webGLRenderbuffer=b.createRenderbuffer();o.__webGLTexture=b.createTexture();b.bindRenderbuffer(b.RENDERBUFFER,o.__webGLRenderbuffer);b.renderbufferStorage(b.RENDERBUFFER,b.DEPTH_COMPONENT16,o.width,o.height);b.bindTexture(b.TEXTURE_2D,o.__webGLTexture);b.texParameteri(b.TEXTURE_2D,b.TEXTURE_WRAP_S,i(o.wrap_s));b.texParameteri(b.TEXTURE_2D,b.TEXTURE_WRAP_T,i(o.wrap_t));b.texParameteri(b.TEXTURE_2D,b.TEXTURE_MAG_FILTER,i(o.mag_filter));b.texParameteri(b.TEXTURE_2D,b.TEXTURE_MIN_FILTER,
i(o.min_filter));b.texImage2D(b.TEXTURE_2D,0,i(o.format),o.width,o.height,0,i(o.format),i(o.type),null);b.bindFramebuffer(b.FRAMEBUFFER,o.__webGLFramebuffer);b.framebufferTexture2D(b.FRAMEBUFFER,b.COLOR_ATTACHMENT0,b.TEXTURE_2D,o.__webGLTexture,0);b.framebufferRenderbuffer(b.FRAMEBUFFER,b.DEPTH_ATTACHMENT,b.RENDERBUFFER,o.__webGLRenderbuffer);b.bindTexture(b.TEXTURE_2D,null);b.bindRenderbuffer(b.RENDERBUFFER,null);b.bindFramebuffer(b.FRAMEBUFFER,null)}if(o){p=o.__webGLFramebuffer;k=o.width;z=o.height}else{p=
null;k=q.width;z=q.height}if(p!=n){b.bindFramebuffer(b.FRAMEBUFFER,p);b.viewport(0,0,k,z);j&&b.clear(b.COLOR_BUFFER_BIT|b.DEPTH_BUFFER_BIT);n=p}this.autoClear&&this.clear();h.autoUpdateMatrix&&h.updateMatrix();x.set(h.matrix.flatten());T.set(h.projectionMatrix.flatten());j=0;for(p=e.__webGLObjects.length;j<p;j++){z=e.__webGLObjects[j];k=z.object;z=z.buffer;if(k.visible){this.setupMatrices(k,h);this.renderPass(h,s,t,k,z,THREE.NormalBlending,false)}}j=0;for(p=e.__webGLObjects.length;j<p;j++){z=e.__webGLObjects[j];
k=z.object;z=z.buffer;if(k.visible){this.setupMatrices(k,h);k.doubleSided?b.disable(b.CULL_FACE):b.enable(b.CULL_FACE);this.renderPass(h,s,t,k,z,THREE.AdditiveBlending,false);this.renderPass(h,s,t,k,z,THREE.SubtractiveBlending,false);this.renderPass(h,s,t,k,z,THREE.AdditiveBlending,true);this.renderPass(h,s,t,k,z,THREE.SubtractiveBlending,true);this.renderPass(h,s,t,k,z,THREE.NormalBlending,true)}}if(o&&o.min_filter!==THREE.NearestFilter&&o.min_filter!==THREE.LinearFilter){b.bindTexture(b.TEXTURE_2D,
o.__webGLTexture);b.generateMipmap(b.TEXTURE_2D);b.bindTexture(b.TEXTURE_2D,null)}};this.initWebGLObjects=function(e){function h(r,l,H,y){if(r[l]==undefined){e.__webGLObjects.push({buffer:H,object:y});r[l]=1}}var o,j,p,z,k,s,t;if(!e.__webGLObjects){e.__webGLObjects=[];e.__webGLObjectsMap={}}o=0;for(j=e.objects.length;o<j;o++){p=e.objects[o];k=p.geometry;if(e.__webGLObjectsMap[p.id]==undefined)e.__webGLObjectsMap[p.id]={};t=e.__webGLObjectsMap[p.id];if(p instanceof THREE.Mesh){for(z in k.geometryChunks){s=
k.geometryChunks[z];if(!s.__webGLVertexBuffer){this.createMeshBuffers(s);this.initMeshBuffers(s,p);k.__dirtyVertices=true;k.__dirtyElements=true;k.__dirtyUvs=true;k.__dirtyNormals=true;k.__dirtyTangents=true}if(k.__dirtyVertices||k.__dirtyElements||k.__dirtyUvs)this.setMeshBuffers(s,p,b.DYNAMIC_DRAW,k.__dirtyVertices,k.__dirtyElements,k.__dirtyUvs,k.__dirtyNormals,k.__dirtyTangents);h(t,z,s,p)}k.__dirtyVertices=false;k.__dirtyElements=false;k.__dirtyUvs=false;k.__dirtyNormals=false;k.__dirtyTangents=
false}else if(p instanceof THREE.Line){if(!k.__webGLVertexBuffer){this.createLineBuffers(k);this.initLineBuffers(k);k.__dirtyVertices=true;k.__dirtyElements=true}k.__dirtyVertices&&this.setLineBuffers(k,b.DYNAMIC_DRAW,k.__dirtyVertices,k.__dirtyElements);h(t,0,k,p);k.__dirtyVertices=false;k.__dirtyElements=false}else if(p instanceof THREE.ParticleSystem){k.__webGLVertexBuffer||this.createParticleBuffers(k);h(t,0,k,p)}}};this.removeObject=function(e,h){var o,j;for(o=e.__webGLObjects.length-1;o>=0;o--){j=
e.__webGLObjects[o].object;h==j&&e.__webGLObjects.splice(o,1)}};this.setupMatrices=function(e,h){e.autoUpdateMatrix&&e.updateMatrix();D.multiply(h.matrix,e.matrix);A.set(D.flatten());F=THREE.Matrix4.makeInvert3x3(D).transpose();V.set(F.m);U.set(e.matrix.flatten())};this.loadMatrices=function(e){b.uniformMatrix4fv(e.uniforms.viewMatrix,false,x);b.uniformMatrix4fv(e.uniforms.modelViewMatrix,false,A);b.uniformMatrix4fv(e.uniforms.projectionMatrix,false,T);b.uniformMatrix3fv(e.uniforms.normalMatrix,false,
V);b.uniformMatrix4fv(e.uniforms.objectMatrix,false,U)};this.loadCamera=function(e,h){b.uniform3f(e.uniforms.cameraPosition,h.position.x,h.position.y,h.position.z)};this.setBlending=function(e){switch(e){case THREE.AdditiveBlending:b.blendEquation(b.FUNC_ADD);b.blendFunc(b.ONE,b.ONE);break;case THREE.SubtractiveBlending:b.blendFunc(b.DST_COLOR,b.ZERO);break;default:b.blendEquation(b.FUNC_ADD);b.blendFunc(b.ONE,b.ONE_MINUS_SRC_ALPHA)}};this.setFaceCulling=function(e,h){if(e){!h||h=="ccw"?b.frontFace(b.CCW):
b.frontFace(b.CW);if(e=="back")b.cullFace(b.BACK);else e=="front"?b.cullFace(b.FRONT):b.cullFace(b.FRONT_AND_BACK);b.enable(b.CULL_FACE)}else b.disable(b.CULL_FACE)};this.supportsVertexTextures=function(){return b.getParameter(b.MAX_VERTEX_TEXTURE_IMAGE_UNITS)>0}};
THREE.Snippets={fog_pars_fragment:"#ifdef USE_FOG\nuniform vec3 fogColor;\n#ifdef FOG_EXP2\nuniform float fogDensity;\n#else\nuniform float fogNear;\nuniform float fogFar;\n#endif\n#endif",fog_fragment:"#ifdef USE_FOG\nfloat depth = gl_FragCoord.z / gl_FragCoord.w;\n#ifdef FOG_EXP2\nconst float LOG2 = 1.442695;\nfloat fogFactor = exp2( - fogDensity * fogDensity * depth * depth * LOG2 );\nfogFactor = 1.0 - clamp( fogFactor, 0.0, 1.0 );\n#else\nfloat fogFactor = smoothstep( fogNear, fogFar, depth );\n#endif\ngl_FragColor = mix( gl_FragColor, vec4( fogColor, 1.0 ), fogFactor );\n#endif",envmap_pars_fragment:"#ifdef USE_ENVMAP\nvarying vec3 vReflect;\nuniform float reflectivity;\nuniform samplerCube env_map;\nuniform int combine;\n#endif",
envmap_fragment:"#ifdef USE_ENVMAP\ncubeColor = textureCube( env_map, vec3( -vReflect.x, vReflect.yz ) );\nif ( combine == 1 ) {\ngl_FragColor = mix( gl_FragColor, cubeColor, reflectivity );\n} else {\ngl_FragColor = gl_FragColor * cubeColor;\n}\n#endif",envmap_pars_vertex:"#ifdef USE_ENVMAP\nvarying vec3 vReflect;\nuniform float refraction_ratio;\nuniform bool useRefract;\n#endif",envmap_vertex:"#ifdef USE_ENVMAP\nvec4 mPosition = objectMatrix * vec4( position, 1.0 );\nvec3 nWorld = mat3( objectMatrix[0].xyz, objectMatrix[1].xyz, objectMatrix[2].xyz ) * normal;\nif ( useRefract ) {\nvReflect = refract( normalize( mPosition.xyz - cameraPosition ), normalize( nWorld.xyz ), refraction_ratio );\n} else {\nvReflect = reflect( normalize( mPosition.xyz - cameraPosition ), normalize( nWorld.xyz ) );\n}\n#endif",
map_pars_fragment:"#ifdef USE_MAP\nvarying vec2 vUv;\nuniform sampler2D map;\n#endif",map_pars_vertex:"#ifdef USE_MAP\nvarying vec2 vUv;\n#endif",map_fragment:"#ifdef USE_MAP\nmapColor = texture2D( map, vUv );\n#endif",map_vertex:"#ifdef USE_MAP\nvUv = uv;\n#endif",lights_pars_vertex:"uniform bool enableLighting;\nuniform vec3 ambientLightColor;\n#if MAX_DIR_LIGHTS > 0\nuniform vec3 directionalLightColor[ MAX_DIR_LIGHTS ];\nuniform vec3 directionalLightDirection[ MAX_DIR_LIGHTS ];\n#endif\n#if MAX_POINT_LIGHTS > 0\nuniform vec3 pointLightColor[ MAX_POINT_LIGHTS ];\nuniform vec3 pointLightPosition[ MAX_POINT_LIGHTS ];\n#ifdef PHONG\nvarying vec3 vPointLightVector[ MAX_POINT_LIGHTS ];\n#endif\n#endif",
k=z.object;z=z.buffer;if(k.visible){this.setupMatrices(k,h);if(k.doubleSided)b.disable(b.CULL_FACE);else{b.enable(b.CULL_FACE);k.flipSided?b.frontFace(b.CW):b.frontFace(b.CCW)}this.renderPass(h,s,t,k,z,THREE.AdditiveBlending,false);this.renderPass(h,s,t,k,z,THREE.SubtractiveBlending,false);this.renderPass(h,s,t,k,z,THREE.AdditiveBlending,true);this.renderPass(h,s,t,k,z,THREE.SubtractiveBlending,true);this.renderPass(h,s,t,k,z,THREE.NormalBlending,true)}}if(o&&o.min_filter!==THREE.NearestFilter&&o.min_filter!==
THREE.LinearFilter){b.bindTexture(b.TEXTURE_2D,o.__webGLTexture);b.generateMipmap(b.TEXTURE_2D);b.bindTexture(b.TEXTURE_2D,null)}};this.initWebGLObjects=function(e){function h(r,l,H,y){if(r[l]==undefined){e.__webGLObjects.push({buffer:H,object:y});r[l]=1}}var o,j,p,z,k,s,t;if(!e.__webGLObjects){e.__webGLObjects=[];e.__webGLObjectsMap={}}o=0;for(j=e.objects.length;o<j;o++){p=e.objects[o];k=p.geometry;if(e.__webGLObjectsMap[p.id]==undefined)e.__webGLObjectsMap[p.id]={};t=e.__webGLObjectsMap[p.id];if(p instanceof
THREE.Mesh){for(z in k.geometryChunks){s=k.geometryChunks[z];if(!s.__webGLVertexBuffer){this.createMeshBuffers(s);this.initMeshBuffers(s,p);k.__dirtyVertices=true;k.__dirtyElements=true;k.__dirtyUvs=true;k.__dirtyNormals=true;k.__dirtyTangents=true}if(k.__dirtyVertices||k.__dirtyElements||k.__dirtyUvs)this.setMeshBuffers(s,p,b.DYNAMIC_DRAW,k.__dirtyVertices,k.__dirtyElements,k.__dirtyUvs,k.__dirtyNormals,k.__dirtyTangents);h(t,z,s,p)}k.__dirtyVertices=false;k.__dirtyElements=false;k.__dirtyUvs=false;
k.__dirtyNormals=false;k.__dirtyTangents=false}else if(p instanceof THREE.Line){if(!k.__webGLVertexBuffer){this.createLineBuffers(k);this.initLineBuffers(k);k.__dirtyVertices=true;k.__dirtyElements=true}k.__dirtyVertices&&this.setLineBuffers(k,b.DYNAMIC_DRAW,k.__dirtyVertices,k.__dirtyElements);h(t,0,k,p);k.__dirtyVertices=false;k.__dirtyElements=false}else if(p instanceof THREE.ParticleSystem){k.__webGLVertexBuffer||this.createParticleBuffers(k);h(t,0,k,p)}}};this.removeObject=function(e,h){var o,
j;for(o=e.__webGLObjects.length-1;o>=0;o--){j=e.__webGLObjects[o].object;h==j&&e.__webGLObjects.splice(o,1)}};this.setupMatrices=function(e,h){e.autoUpdateMatrix&&e.updateMatrix();D.multiply(h.matrix,e.matrix);A.set(D.flatten());F=THREE.Matrix4.makeInvert3x3(D).transpose();V.set(F.m);U.set(e.matrix.flatten())};this.loadMatrices=function(e){b.uniformMatrix4fv(e.uniforms.viewMatrix,false,x);b.uniformMatrix4fv(e.uniforms.modelViewMatrix,false,A);b.uniformMatrix4fv(e.uniforms.projectionMatrix,false,T);
b.uniformMatrix3fv(e.uniforms.normalMatrix,false,V);b.uniformMatrix4fv(e.uniforms.objectMatrix,false,U)};this.loadCamera=function(e,h){b.uniform3f(e.uniforms.cameraPosition,h.position.x,h.position.y,h.position.z)};this.setBlending=function(e){switch(e){case THREE.AdditiveBlending:b.blendEquation(b.FUNC_ADD);b.blendFunc(b.ONE,b.ONE);break;case THREE.SubtractiveBlending:b.blendFunc(b.DST_COLOR,b.ZERO);break;default:b.blendEquation(b.FUNC_ADD);b.blendFunc(b.ONE,b.ONE_MINUS_SRC_ALPHA)}};this.setFaceCulling=
function(e,h){if(e){!h||h=="ccw"?b.frontFace(b.CCW):b.frontFace(b.CW);if(e=="back")b.cullFace(b.BACK);else e=="front"?b.cullFace(b.FRONT):b.cullFace(b.FRONT_AND_BACK);b.enable(b.CULL_FACE)}else b.disable(b.CULL_FACE)};this.supportsVertexTextures=function(){return b.getParameter(b.MAX_VERTEX_TEXTURE_IMAGE_UNITS)>0}};
THREE.Snippets={fog_pars_fragment:"#ifdef USE_FOG\nuniform vec3 fogColor;\n#ifdef FOG_EXP2\nuniform float fogDensity;\n#else\nuniform float fogNear;\nuniform float fogFar;\n#endif\n#endif",fog_fragment:"#ifdef USE_FOG\nfloat depth = gl_FragCoord.z / gl_FragCoord.w;\n#ifdef FOG_EXP2\nconst float LOG2 = 1.442695;\nfloat fogFactor = exp2( - fogDensity * fogDensity * depth * depth * LOG2 );\nfogFactor = 1.0 - clamp( fogFactor, 0.0, 1.0 );\n#else\nfloat fogFactor = smoothstep( fogNear, fogFar, depth );\n#endif\ngl_FragColor = mix( gl_FragColor, vec4( fogColor, 1.0 ), fogFactor );\n#endif",
envmap_pars_fragment:"#ifdef USE_ENVMAP\nvarying vec3 vReflect;\nuniform float reflectivity;\nuniform samplerCube env_map;\nuniform int combine;\n#endif",envmap_fragment:"#ifdef USE_ENVMAP\ncubeColor = textureCube( env_map, vec3( -vReflect.x, vReflect.yz ) );\nif ( combine == 1 ) {\ngl_FragColor = mix( gl_FragColor, cubeColor, reflectivity );\n} else {\ngl_FragColor = gl_FragColor * cubeColor;\n}\n#endif",envmap_pars_vertex:"#ifdef USE_ENVMAP\nvarying vec3 vReflect;\nuniform float refraction_ratio;\nuniform bool useRefract;\n#endif",
envmap_vertex:"#ifdef USE_ENVMAP\nvec4 mPosition = objectMatrix * vec4( position, 1.0 );\nvec3 nWorld = mat3( objectMatrix[0].xyz, objectMatrix[1].xyz, objectMatrix[2].xyz ) * normal;\nif ( useRefract ) {\nvReflect = refract( normalize( mPosition.xyz - cameraPosition ), normalize( nWorld.xyz ), refraction_ratio );\n} else {\nvReflect = reflect( normalize( mPosition.xyz - cameraPosition ), normalize( nWorld.xyz ) );\n}\n#endif",map_pars_fragment:"#ifdef USE_MAP\nvarying vec2 vUv;\nuniform sampler2D map;\n#endif",
map_pars_vertex:"#ifdef USE_MAP\nvarying vec2 vUv;\n#endif",map_fragment:"#ifdef USE_MAP\nmapColor = texture2D( map, vUv );\n#endif",map_vertex:"#ifdef USE_MAP\nvUv = uv;\n#endif",lights_pars_vertex:"uniform bool enableLighting;\nuniform vec3 ambientLightColor;\n#if MAX_DIR_LIGHTS > 0\nuniform vec3 directionalLightColor[ MAX_DIR_LIGHTS ];\nuniform vec3 directionalLightDirection[ MAX_DIR_LIGHTS ];\n#endif\n#if MAX_POINT_LIGHTS > 0\nuniform vec3 pointLightColor[ MAX_POINT_LIGHTS ];\nuniform vec3 pointLightPosition[ MAX_POINT_LIGHTS ];\n#ifdef PHONG\nvarying vec3 vPointLightVector[ MAX_POINT_LIGHTS ];\n#endif\n#endif",
lights_vertex:"if ( !enableLighting ) {\nvLightWeighting = vec3( 1.0 );\n} else {\nvLightWeighting = ambientLightColor;\n#if MAX_DIR_LIGHTS > 0\nfor( int i = 0; i < MAX_DIR_LIGHTS; i++ ) {\nvec4 lDirection = viewMatrix * vec4( directionalLightDirection[ i ], 0.0 );\nfloat directionalLightWeighting = max( dot( transformedNormal, normalize( lDirection.xyz ) ), 0.0 );\nvLightWeighting += directionalLightColor[ i ] * directionalLightWeighting;\n}\n#endif\n#if MAX_POINT_LIGHTS > 0\nfor( int i = 0; i < MAX_POINT_LIGHTS; i++ ) {\nvec4 lPosition = viewMatrix * vec4( pointLightPosition[ i ], 1.0 );\nvec3 pointLightVector = normalize( lPosition.xyz - mvPosition.xyz );\nfloat pointLightWeighting = max( dot( transformedNormal, pointLightVector ), 0.0 );\nvLightWeighting += pointLightColor[ i ] * pointLightWeighting;\n#ifdef PHONG\nvPointLightVector[ i ] = pointLightVector;\n#endif\n}\n#endif\n}",
lights_pars_fragment:"#if MAX_DIR_LIGHTS > 0\nuniform vec3 directionalLightDirection[ MAX_DIR_LIGHTS ];\n#endif\n#if MAX_POINT_LIGHTS > 0\nvarying vec3 vPointLightVector[ MAX_POINT_LIGHTS ];\n#endif\nvarying vec3 vViewPosition;\nvarying vec3 vNormal;",lights_fragment:"vec3 normal = normalize( vNormal );\nvec3 viewPosition = normalize( vViewPosition );\nvec4 mSpecular = vec4( specular, opacity );\n#if MAX_POINT_LIGHTS > 0\nvec4 pointDiffuse = vec4( 0.0 );\nvec4 pointSpecular = vec4( 0.0 );\nfor( int i = 0; i < MAX_POINT_LIGHTS; i++ ) {\nvec3 pointVector = normalize( vPointLightVector[ i ] );\nvec3 pointHalfVector = normalize( vPointLightVector[ i ] + vViewPosition );\nfloat pointDotNormalHalf = dot( normal, pointHalfVector );\nfloat pointDiffuseWeight = max( dot( normal, pointVector ), 0.0 );\nfloat pointSpecularWeight = 0.0;\nif ( pointDotNormalHalf >= 0.0 )\npointSpecularWeight = pow( pointDotNormalHalf, shininess );\npointDiffuse += mColor * pointDiffuseWeight;\npointSpecular += mSpecular * pointSpecularWeight;\n}\n#endif\n#if MAX_DIR_LIGHTS > 0\nvec4 dirDiffuse = vec4( 0.0 );\nvec4 dirSpecular = vec4( 0.0 );\nfor( int i = 0; i < MAX_DIR_LIGHTS; i++ ) {\nvec4 lDirection = viewMatrix * vec4( directionalLightDirection[ i ], 0.0 );\nvec3 dirVector = normalize( lDirection.xyz );\nvec3 dirHalfVector = normalize( lDirection.xyz + vViewPosition );\nfloat dirDotNormalHalf = dot( normal, dirHalfVector );\nfloat dirDiffuseWeight = max( dot( normal, dirVector ), 0.0 );\nfloat dirSpecularWeight = 0.0;\nif ( dirDotNormalHalf >= 0.0 )\ndirSpecularWeight = pow( dirDotNormalHalf, shininess );\ndirDiffuse += mColor * dirDiffuseWeight;\ndirSpecular += mSpecular * dirSpecularWeight;\n}\n#endif\nvec4 totalLight = vec4( ambient, opacity );\n#if MAX_DIR_LIGHTS > 0\ntotalLight += dirDiffuse + dirSpecular;\n#endif\n#if MAX_POINT_LIGHTS > 0\ntotalLight += pointDiffuse + pointSpecular;\n#endif"};
THREE.UniformsLib={common:{color:{type:"c",value:new THREE.Color(15658734)},opacity:{type:"f",value:1},map:{type:"t",value:0,texture:null},env_map:{type:"t",value:1,texture:null},useRefract:{type:"i",value:0},reflectivity:{type:"f",value:1},refraction_ratio:{type:"f",value:0.98},combine:{type:"i",value:0},fogDensity:{type:"f",value:2.5E-4},fogNear:{type:"f",value:1},fogFar:{type:"f",value:2E3},fogColor:{type:"c",value:new THREE.Color(16777215)}},lights:{enableLighting:{type:"i",value:1},ambientLightColor:{type:"fv",
......
......@@ -178,16 +178,17 @@ l,u,n,s,I,p){var w,z,x,q,N;x=0;for(q=n.materials.length;x<q;x++){w=n.materials[x
c.createFramebuffer();u.__webGLRenderbuffer=c.createRenderbuffer();u.__webGLTexture=c.createTexture();c.bindRenderbuffer(c.RENDERBUFFER,u.__webGLRenderbuffer);c.renderbufferStorage(c.RENDERBUFFER,c.DEPTH_COMPONENT16,u.width,u.height);c.bindTexture(c.TEXTURE_2D,u.__webGLTexture);c.texParameteri(c.TEXTURE_2D,c.TEXTURE_WRAP_S,h(u.wrap_s));c.texParameteri(c.TEXTURE_2D,c.TEXTURE_WRAP_T,h(u.wrap_t));c.texParameteri(c.TEXTURE_2D,c.TEXTURE_MAG_FILTER,h(u.mag_filter));c.texParameteri(c.TEXTURE_2D,c.TEXTURE_MIN_FILTER,
h(u.min_filter));c.texImage2D(c.TEXTURE_2D,0,h(u.format),u.width,u.height,0,h(u.format),h(u.type),null);c.bindFramebuffer(c.FRAMEBUFFER,u.__webGLFramebuffer);c.framebufferTexture2D(c.FRAMEBUFFER,c.COLOR_ATTACHMENT0,c.TEXTURE_2D,u.__webGLTexture,0);c.framebufferRenderbuffer(c.FRAMEBUFFER,c.DEPTH_ATTACHMENT,c.RENDERBUFFER,u.__webGLRenderbuffer);c.bindTexture(c.TEXTURE_2D,null);c.bindRenderbuffer(c.RENDERBUFFER,null);c.bindFramebuffer(c.FRAMEBUFFER,null)}if(u){s=u.__webGLFramebuffer;p=u.width;I=u.height}else{s=
null;p=j.width;I=j.height}if(s!=m){c.bindFramebuffer(c.FRAMEBUFFER,s);c.viewport(0,0,p,I);n&&c.clear(c.COLOR_BUFFER_BIT|c.DEPTH_BUFFER_BIT);m=s}this.autoClear&&this.clear();l.autoUpdateMatrix&&l.updateMatrix();r.set(l.matrix.flatten());A.set(l.projectionMatrix.flatten());n=0;for(s=f.__webGLObjects.length;n<s;n++){I=f.__webGLObjects[n];p=I.object;I=I.buffer;if(p.visible){this.setupMatrices(p,l);this.renderPass(l,w,z,p,I,THREE.NormalBlending,false)}}n=0;for(s=f.__webGLObjects.length;n<s;n++){I=f.__webGLObjects[n];
p=I.object;I=I.buffer;if(p.visible){this.setupMatrices(p,l);p.doubleSided?c.disable(c.CULL_FACE):c.enable(c.CULL_FACE);this.renderPass(l,w,z,p,I,THREE.AdditiveBlending,false);this.renderPass(l,w,z,p,I,THREE.SubtractiveBlending,false);this.renderPass(l,w,z,p,I,THREE.AdditiveBlending,true);this.renderPass(l,w,z,p,I,THREE.SubtractiveBlending,true);this.renderPass(l,w,z,p,I,THREE.NormalBlending,true)}}if(u&&u.min_filter!==THREE.NearestFilter&&u.min_filter!==THREE.LinearFilter){c.bindTexture(c.TEXTURE_2D,
u.__webGLTexture);c.generateMipmap(c.TEXTURE_2D);c.bindTexture(c.TEXTURE_2D,null)}};this.initWebGLObjects=function(f){function l(x,q,N,G){if(x[q]==undefined){f.__webGLObjects.push({buffer:N,object:G});x[q]=1}}var u,n,s,I,p,w,z;if(!f.__webGLObjects){f.__webGLObjects=[];f.__webGLObjectsMap={}}u=0;for(n=f.objects.length;u<n;u++){s=f.objects[u];p=s.geometry;if(f.__webGLObjectsMap[s.id]==undefined)f.__webGLObjectsMap[s.id]={};z=f.__webGLObjectsMap[s.id];if(s instanceof THREE.Mesh){for(I in p.geometryChunks){w=
p.geometryChunks[I];if(!w.__webGLVertexBuffer){this.createMeshBuffers(w);this.initMeshBuffers(w,s);p.__dirtyVertices=true;p.__dirtyElements=true;p.__dirtyUvs=true;p.__dirtyNormals=true;p.__dirtyTangents=true}if(p.__dirtyVertices||p.__dirtyElements||p.__dirtyUvs)this.setMeshBuffers(w,s,c.DYNAMIC_DRAW,p.__dirtyVertices,p.__dirtyElements,p.__dirtyUvs,p.__dirtyNormals,p.__dirtyTangents);l(z,I,w,s)}p.__dirtyVertices=false;p.__dirtyElements=false;p.__dirtyUvs=false;p.__dirtyNormals=false;p.__dirtyTangents=
false}else if(s instanceof THREE.Line){if(!p.__webGLVertexBuffer){this.createLineBuffers(p);this.initLineBuffers(p);p.__dirtyVertices=true;p.__dirtyElements=true}p.__dirtyVertices&&this.setLineBuffers(p,c.DYNAMIC_DRAW,p.__dirtyVertices,p.__dirtyElements);l(z,0,p,s);p.__dirtyVertices=false;p.__dirtyElements=false}else if(s instanceof THREE.ParticleSystem){p.__webGLVertexBuffer||this.createParticleBuffers(p);l(z,0,p,s)}}};this.removeObject=function(f,l){var u,n;for(u=f.__webGLObjects.length-1;u>=0;u--){n=
f.__webGLObjects[u].object;l==n&&f.__webGLObjects.splice(u,1)}};this.setupMatrices=function(f,l){f.autoUpdateMatrix&&f.updateMatrix();v.multiply(l.matrix,f.matrix);y.set(v.flatten());D=THREE.Matrix4.makeInvert3x3(v).transpose();C.set(D.m);L.set(f.matrix.flatten())};this.loadMatrices=function(f){c.uniformMatrix4fv(f.uniforms.viewMatrix,false,r);c.uniformMatrix4fv(f.uniforms.modelViewMatrix,false,y);c.uniformMatrix4fv(f.uniforms.projectionMatrix,false,A);c.uniformMatrix3fv(f.uniforms.normalMatrix,false,
C);c.uniformMatrix4fv(f.uniforms.objectMatrix,false,L)};this.loadCamera=function(f,l){c.uniform3f(f.uniforms.cameraPosition,l.position.x,l.position.y,l.position.z)};this.setBlending=function(f){switch(f){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(f,l){if(f){!l||l=="ccw"?c.frontFace(c.CCW):
c.frontFace(c.CW);if(f=="back")c.cullFace(c.BACK);else f=="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}};
THREE.Snippets={fog_pars_fragment:"#ifdef USE_FOG\nuniform vec3 fogColor;\n#ifdef FOG_EXP2\nuniform float fogDensity;\n#else\nuniform float fogNear;\nuniform float fogFar;\n#endif\n#endif",fog_fragment:"#ifdef USE_FOG\nfloat depth = gl_FragCoord.z / gl_FragCoord.w;\n#ifdef FOG_EXP2\nconst float LOG2 = 1.442695;\nfloat fogFactor = exp2( - fogDensity * fogDensity * depth * depth * LOG2 );\nfogFactor = 1.0 - clamp( fogFactor, 0.0, 1.0 );\n#else\nfloat fogFactor = smoothstep( fogNear, fogFar, depth );\n#endif\ngl_FragColor = mix( gl_FragColor, vec4( fogColor, 1.0 ), fogFactor );\n#endif",envmap_pars_fragment:"#ifdef USE_ENVMAP\nvarying vec3 vReflect;\nuniform float reflectivity;\nuniform samplerCube env_map;\nuniform int combine;\n#endif",
envmap_fragment:"#ifdef USE_ENVMAP\ncubeColor = textureCube( env_map, vec3( -vReflect.x, vReflect.yz ) );\nif ( combine == 1 ) {\ngl_FragColor = mix( gl_FragColor, cubeColor, reflectivity );\n} else {\ngl_FragColor = gl_FragColor * cubeColor;\n}\n#endif",envmap_pars_vertex:"#ifdef USE_ENVMAP\nvarying vec3 vReflect;\nuniform float refraction_ratio;\nuniform bool useRefract;\n#endif",envmap_vertex:"#ifdef USE_ENVMAP\nvec4 mPosition = objectMatrix * vec4( position, 1.0 );\nvec3 nWorld = mat3( objectMatrix[0].xyz, objectMatrix[1].xyz, objectMatrix[2].xyz ) * normal;\nif ( useRefract ) {\nvReflect = refract( normalize( mPosition.xyz - cameraPosition ), normalize( nWorld.xyz ), refraction_ratio );\n} else {\nvReflect = reflect( normalize( mPosition.xyz - cameraPosition ), normalize( nWorld.xyz ) );\n}\n#endif",
map_pars_fragment:"#ifdef USE_MAP\nvarying vec2 vUv;\nuniform sampler2D map;\n#endif",map_pars_vertex:"#ifdef USE_MAP\nvarying vec2 vUv;\n#endif",map_fragment:"#ifdef USE_MAP\nmapColor = texture2D( map, vUv );\n#endif",map_vertex:"#ifdef USE_MAP\nvUv = uv;\n#endif",lights_pars_vertex:"uniform bool enableLighting;\nuniform vec3 ambientLightColor;\n#if MAX_DIR_LIGHTS > 0\nuniform vec3 directionalLightColor[ MAX_DIR_LIGHTS ];\nuniform vec3 directionalLightDirection[ MAX_DIR_LIGHTS ];\n#endif\n#if MAX_POINT_LIGHTS > 0\nuniform vec3 pointLightColor[ MAX_POINT_LIGHTS ];\nuniform vec3 pointLightPosition[ MAX_POINT_LIGHTS ];\n#ifdef PHONG\nvarying vec3 vPointLightVector[ MAX_POINT_LIGHTS ];\n#endif\n#endif",
p=I.object;I=I.buffer;if(p.visible){this.setupMatrices(p,l);if(p.doubleSided)c.disable(c.CULL_FACE);else{c.enable(c.CULL_FACE);p.flipSided?c.frontFace(c.CW):c.frontFace(c.CCW)}this.renderPass(l,w,z,p,I,THREE.AdditiveBlending,false);this.renderPass(l,w,z,p,I,THREE.SubtractiveBlending,false);this.renderPass(l,w,z,p,I,THREE.AdditiveBlending,true);this.renderPass(l,w,z,p,I,THREE.SubtractiveBlending,true);this.renderPass(l,w,z,p,I,THREE.NormalBlending,true)}}if(u&&u.min_filter!==THREE.NearestFilter&&u.min_filter!==
THREE.LinearFilter){c.bindTexture(c.TEXTURE_2D,u.__webGLTexture);c.generateMipmap(c.TEXTURE_2D);c.bindTexture(c.TEXTURE_2D,null)}};this.initWebGLObjects=function(f){function l(x,q,N,G){if(x[q]==undefined){f.__webGLObjects.push({buffer:N,object:G});x[q]=1}}var u,n,s,I,p,w,z;if(!f.__webGLObjects){f.__webGLObjects=[];f.__webGLObjectsMap={}}u=0;for(n=f.objects.length;u<n;u++){s=f.objects[u];p=s.geometry;if(f.__webGLObjectsMap[s.id]==undefined)f.__webGLObjectsMap[s.id]={};z=f.__webGLObjectsMap[s.id];if(s instanceof
THREE.Mesh){for(I in p.geometryChunks){w=p.geometryChunks[I];if(!w.__webGLVertexBuffer){this.createMeshBuffers(w);this.initMeshBuffers(w,s);p.__dirtyVertices=true;p.__dirtyElements=true;p.__dirtyUvs=true;p.__dirtyNormals=true;p.__dirtyTangents=true}if(p.__dirtyVertices||p.__dirtyElements||p.__dirtyUvs)this.setMeshBuffers(w,s,c.DYNAMIC_DRAW,p.__dirtyVertices,p.__dirtyElements,p.__dirtyUvs,p.__dirtyNormals,p.__dirtyTangents);l(z,I,w,s)}p.__dirtyVertices=false;p.__dirtyElements=false;p.__dirtyUvs=false;
p.__dirtyNormals=false;p.__dirtyTangents=false}else if(s instanceof THREE.Line){if(!p.__webGLVertexBuffer){this.createLineBuffers(p);this.initLineBuffers(p);p.__dirtyVertices=true;p.__dirtyElements=true}p.__dirtyVertices&&this.setLineBuffers(p,c.DYNAMIC_DRAW,p.__dirtyVertices,p.__dirtyElements);l(z,0,p,s);p.__dirtyVertices=false;p.__dirtyElements=false}else if(s instanceof THREE.ParticleSystem){p.__webGLVertexBuffer||this.createParticleBuffers(p);l(z,0,p,s)}}};this.removeObject=function(f,l){var u,
n;for(u=f.__webGLObjects.length-1;u>=0;u--){n=f.__webGLObjects[u].object;l==n&&f.__webGLObjects.splice(u,1)}};this.setupMatrices=function(f,l){f.autoUpdateMatrix&&f.updateMatrix();v.multiply(l.matrix,f.matrix);y.set(v.flatten());D=THREE.Matrix4.makeInvert3x3(v).transpose();C.set(D.m);L.set(f.matrix.flatten())};this.loadMatrices=function(f){c.uniformMatrix4fv(f.uniforms.viewMatrix,false,r);c.uniformMatrix4fv(f.uniforms.modelViewMatrix,false,y);c.uniformMatrix4fv(f.uniforms.projectionMatrix,false,A);
c.uniformMatrix3fv(f.uniforms.normalMatrix,false,C);c.uniformMatrix4fv(f.uniforms.objectMatrix,false,L)};this.loadCamera=function(f,l){c.uniform3f(f.uniforms.cameraPosition,l.position.x,l.position.y,l.position.z)};this.setBlending=function(f){switch(f){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(f,l){if(f){!l||l=="ccw"?c.frontFace(c.CCW):c.frontFace(c.CW);if(f=="back")c.cullFace(c.BACK);else f=="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}};
THREE.Snippets={fog_pars_fragment:"#ifdef USE_FOG\nuniform vec3 fogColor;\n#ifdef FOG_EXP2\nuniform float fogDensity;\n#else\nuniform float fogNear;\nuniform float fogFar;\n#endif\n#endif",fog_fragment:"#ifdef USE_FOG\nfloat depth = gl_FragCoord.z / gl_FragCoord.w;\n#ifdef FOG_EXP2\nconst float LOG2 = 1.442695;\nfloat fogFactor = exp2( - fogDensity * fogDensity * depth * depth * LOG2 );\nfogFactor = 1.0 - clamp( fogFactor, 0.0, 1.0 );\n#else\nfloat fogFactor = smoothstep( fogNear, fogFar, depth );\n#endif\ngl_FragColor = mix( gl_FragColor, vec4( fogColor, 1.0 ), fogFactor );\n#endif",
envmap_pars_fragment:"#ifdef USE_ENVMAP\nvarying vec3 vReflect;\nuniform float reflectivity;\nuniform samplerCube env_map;\nuniform int combine;\n#endif",envmap_fragment:"#ifdef USE_ENVMAP\ncubeColor = textureCube( env_map, vec3( -vReflect.x, vReflect.yz ) );\nif ( combine == 1 ) {\ngl_FragColor = mix( gl_FragColor, cubeColor, reflectivity );\n} else {\ngl_FragColor = gl_FragColor * cubeColor;\n}\n#endif",envmap_pars_vertex:"#ifdef USE_ENVMAP\nvarying vec3 vReflect;\nuniform float refraction_ratio;\nuniform bool useRefract;\n#endif",
envmap_vertex:"#ifdef USE_ENVMAP\nvec4 mPosition = objectMatrix * vec4( position, 1.0 );\nvec3 nWorld = mat3( objectMatrix[0].xyz, objectMatrix[1].xyz, objectMatrix[2].xyz ) * normal;\nif ( useRefract ) {\nvReflect = refract( normalize( mPosition.xyz - cameraPosition ), normalize( nWorld.xyz ), refraction_ratio );\n} else {\nvReflect = reflect( normalize( mPosition.xyz - cameraPosition ), normalize( nWorld.xyz ) );\n}\n#endif",map_pars_fragment:"#ifdef USE_MAP\nvarying vec2 vUv;\nuniform sampler2D map;\n#endif",
map_pars_vertex:"#ifdef USE_MAP\nvarying vec2 vUv;\n#endif",map_fragment:"#ifdef USE_MAP\nmapColor = texture2D( map, vUv );\n#endif",map_vertex:"#ifdef USE_MAP\nvUv = uv;\n#endif",lights_pars_vertex:"uniform bool enableLighting;\nuniform vec3 ambientLightColor;\n#if MAX_DIR_LIGHTS > 0\nuniform vec3 directionalLightColor[ MAX_DIR_LIGHTS ];\nuniform vec3 directionalLightDirection[ MAX_DIR_LIGHTS ];\n#endif\n#if MAX_POINT_LIGHTS > 0\nuniform vec3 pointLightColor[ MAX_POINT_LIGHTS ];\nuniform vec3 pointLightPosition[ MAX_POINT_LIGHTS ];\n#ifdef PHONG\nvarying vec3 vPointLightVector[ MAX_POINT_LIGHTS ];\n#endif\n#endif",
lights_vertex:"if ( !enableLighting ) {\nvLightWeighting = vec3( 1.0 );\n} else {\nvLightWeighting = ambientLightColor;\n#if MAX_DIR_LIGHTS > 0\nfor( int i = 0; i < MAX_DIR_LIGHTS; i++ ) {\nvec4 lDirection = viewMatrix * vec4( directionalLightDirection[ i ], 0.0 );\nfloat directionalLightWeighting = max( dot( transformedNormal, normalize( lDirection.xyz ) ), 0.0 );\nvLightWeighting += directionalLightColor[ i ] * directionalLightWeighting;\n}\n#endif\n#if MAX_POINT_LIGHTS > 0\nfor( int i = 0; i < MAX_POINT_LIGHTS; i++ ) {\nvec4 lPosition = viewMatrix * vec4( pointLightPosition[ i ], 1.0 );\nvec3 pointLightVector = normalize( lPosition.xyz - mvPosition.xyz );\nfloat pointLightWeighting = max( dot( transformedNormal, pointLightVector ), 0.0 );\nvLightWeighting += pointLightColor[ i ] * pointLightWeighting;\n#ifdef PHONG\nvPointLightVector[ i ] = pointLightVector;\n#endif\n}\n#endif\n}",
lights_pars_fragment:"#if MAX_DIR_LIGHTS > 0\nuniform vec3 directionalLightDirection[ MAX_DIR_LIGHTS ];\n#endif\n#if MAX_POINT_LIGHTS > 0\nvarying vec3 vPointLightVector[ MAX_POINT_LIGHTS ];\n#endif\nvarying vec3 vViewPosition;\nvarying vec3 vNormal;",lights_fragment:"vec3 normal = normalize( vNormal );\nvec3 viewPosition = normalize( vViewPosition );\nvec4 mSpecular = vec4( specular, opacity );\n#if MAX_POINT_LIGHTS > 0\nvec4 pointDiffuse = vec4( 0.0 );\nvec4 pointSpecular = vec4( 0.0 );\nfor( int i = 0; i < MAX_POINT_LIGHTS; i++ ) {\nvec3 pointVector = normalize( vPointLightVector[ i ] );\nvec3 pointHalfVector = normalize( vPointLightVector[ i ] + vViewPosition );\nfloat pointDotNormalHalf = dot( normal, pointHalfVector );\nfloat pointDiffuseWeight = max( dot( normal, pointVector ), 0.0 );\nfloat pointSpecularWeight = 0.0;\nif ( pointDotNormalHalf >= 0.0 )\npointSpecularWeight = pow( pointDotNormalHalf, shininess );\npointDiffuse += mColor * pointDiffuseWeight;\npointSpecular += mSpecular * pointSpecularWeight;\n}\n#endif\n#if MAX_DIR_LIGHTS > 0\nvec4 dirDiffuse = vec4( 0.0 );\nvec4 dirSpecular = vec4( 0.0 );\nfor( int i = 0; i < MAX_DIR_LIGHTS; i++ ) {\nvec4 lDirection = viewMatrix * vec4( directionalLightDirection[ i ], 0.0 );\nvec3 dirVector = normalize( lDirection.xyz );\nvec3 dirHalfVector = normalize( lDirection.xyz + vViewPosition );\nfloat dirDotNormalHalf = dot( normal, dirHalfVector );\nfloat dirDiffuseWeight = max( dot( normal, dirVector ), 0.0 );\nfloat dirSpecularWeight = 0.0;\nif ( dirDotNormalHalf >= 0.0 )\ndirSpecularWeight = pow( dirDotNormalHalf, shininess );\ndirDiffuse += mColor * dirDiffuseWeight;\ndirSpecular += mSpecular * dirSpecularWeight;\n}\n#endif\nvec4 totalLight = vec4( ambient, opacity );\n#if MAX_DIR_LIGHTS > 0\ntotalLight += dirDiffuse + dirSpecular;\n#endif\n#if MAX_POINT_LIGHTS > 0\ntotalLight += pointDiffuse + pointSpecular;\n#endif"};
THREE.UniformsLib={common:{color:{type:"c",value:new THREE.Color(15658734)},opacity:{type:"f",value:1},map:{type:"t",value:0,texture:null},env_map:{type:"t",value:1,texture:null},useRefract:{type:"i",value:0},reflectivity:{type:"f",value:1},refraction_ratio:{type:"f",value:0.98},combine:{type:"i",value:0},fogDensity:{type:"f",value:2.5E-4},fogNear:{type:"f",value:1},fogFar:{type:"f",value:2E3},fogColor:{type:"c",value:new THREE.Color(16777215)}},lights:{enableLighting:{type:"i",value:1},ambientLightColor:{type:"fv",
......
......@@ -961,6 +961,17 @@ THREE.WebGLRenderer = function ( parameters ) {
_gl.enable( _gl.CULL_FACE );
if( object.flipSided ) {
_gl.frontFace( _gl.CW );
}
else {
_gl.frontFace( _gl.CCW );
}
}
// opaque blended materials
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册