Browse Source

Another update of render-to-texture example and related bugfix.

Rendering proper 3d object into the texture uncovered another issue - framebuffer had to be cleared after switching.

Texture is still flipped :( (original scene has small red torus on the top)

This is proving to be rather tricky. Yet again I tried to handle image coordinate mess in a proper way (UNPACK_FLIP_Y_WEBGL as texture parameter and non-inverted UVs), fixing hacks across the codebase.

This did indeed help with render-to-texture flipping, but instead it created really ugly problems with both normal map and minecraft AO demos. So back to square one :(
alteredq 14 years ago
parent
commit
7c9fe8ff82
5 changed files with 72 additions and 28 deletions
  1. 8 8
      build/Three.js
  2. 8 8
      build/ThreeDebug.js
  3. 8 8
      build/ThreeExtras.js
  4. 47 4
      examples/render_to_texture.html
  5. 1 0
      src/renderers/WebGLRenderer.js

+ 8 - 8
build/Three.js

@@ -177,14 +177,14 @@ j.wireframe_linewidth!==undefined?j.wireframe_linewidth:j.linewidth!==undefined?
 j.materials.length;r<l;r++){s=j.materials[r];if(s instanceof THREE.MeshFaceMaterial){s=0;for(t=p.materials.length;s<t;s++)if((H=p.materials[s])&&H.blending==B&&H.opacity<1==k){this.setBlending(H.blending);this.renderBuffer(e,h,n,H,p,j)}}else if((H=s)&&H.blending==B&&H.opacity<1==k){this.setBlending(H.blending);this.renderBuffer(e,h,n,H,p,j)}}};this.render=function(e,h,n){var j,p,B,k,s=e.lights,t=e.fog;this.initWebGLObjects(e);if(n&&!n.__webGLFramebuffer){n.__webGLFramebuffer=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){j=n.__webGLFramebuffer;p=n.width;k=n.height}else{j=null;
-p=q.width;k=q.height}if(j!=o){b.bindFramebuffer(b.FRAMEBUFFER,j);b.viewport(0,0,p,k);o=j}this.autoClear&&this.clear();h.autoUpdateMatrix&&h.updateMatrix();y.set(h.matrix.flatten());S.set(h.projectionMatrix.flatten());j=0;for(p=e.__webGLObjects.length;j<p;j++){B=e.__webGLObjects[j];k=B.object;B=B.buffer;if(k.visible){this.setupMatrices(k,h);this.renderPass(h,s,t,k,B,THREE.NormalBlending,false)}}j=0;for(p=e.__webGLObjects.length;j<p;j++){B=e.__webGLObjects[j];k=B.object;B=B.buffer;if(k.visible){this.setupMatrices(k,
-h);this.renderPass(h,s,t,k,B,THREE.AdditiveBlending,false);this.renderPass(h,s,t,k,B,THREE.SubtractiveBlending,false);this.renderPass(h,s,t,k,B,THREE.AdditiveBlending,true);this.renderPass(h,s,t,k,B,THREE.SubtractiveBlending,true);this.renderPass(h,s,t,k,B,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,w){if(r[l]==undefined){e.__webGLObjects.push({buffer:H,object:w});r[l]=1}}var n,j,p,B,k,s,t;if(!e.__webGLObjects){e.__webGLObjects=[];e.__webGLObjectsMap={}}n=0;for(j=e.objects.length;n<j;n++){p=e.objects[n];k=p.geometry;if(e.__webGLObjectsMap[p.id]==undefined)e.__webGLObjectsMap[p.id]={};t=e.__webGLObjectsMap[p.id];if(p instanceof THREE.Mesh){for(B in k.geometryChunks){s=k.geometryChunks[B];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,B,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 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);U.set(e.matrix.flatten())};this.loadMatrices=function(e){b.uniformMatrix4fv(e.uniforms.viewMatrix,false,y);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,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}};
+p=q.width;k=q.height}if(j!=o){b.bindFramebuffer(b.FRAMEBUFFER,j);b.viewport(0,0,p,k);b.clear(b.COLOR_BUFFER_BIT|b.DEPTH_BUFFER_BIT);o=j}this.autoClear&&this.clear();h.autoUpdateMatrix&&h.updateMatrix();y.set(h.matrix.flatten());S.set(h.projectionMatrix.flatten());j=0;for(p=e.__webGLObjects.length;j<p;j++){B=e.__webGLObjects[j];k=B.object;B=B.buffer;if(k.visible){this.setupMatrices(k,h);this.renderPass(h,s,t,k,B,THREE.NormalBlending,false)}}j=0;for(p=e.__webGLObjects.length;j<p;j++){B=e.__webGLObjects[j];
+k=B.object;B=B.buffer;if(k.visible){this.setupMatrices(k,h);this.renderPass(h,s,t,k,B,THREE.AdditiveBlending,false);this.renderPass(h,s,t,k,B,THREE.SubtractiveBlending,false);this.renderPass(h,s,t,k,B,THREE.AdditiveBlending,true);this.renderPass(h,s,t,k,B,THREE.SubtractiveBlending,true);this.renderPass(h,s,t,k,B,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,w){if(r[l]==undefined){e.__webGLObjects.push({buffer:H,object:w});r[l]=1}}var n,j,p,B,k,s,t;if(!e.__webGLObjects){e.__webGLObjects=[];e.__webGLObjectsMap={}}n=0;for(j=e.objects.length;n<j;n++){p=e.objects[n];k=p.geometry;if(e.__webGLObjectsMap[p.id]==undefined)e.__webGLObjectsMap[p.id]={};t=e.__webGLObjectsMap[p.id];if(p instanceof THREE.Mesh){for(B in k.geometryChunks){s=k.geometryChunks[B];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,B,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 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);U.set(e.matrix.flatten())};this.loadMatrices=function(e){b.uniformMatrix4fv(e.uniforms.viewMatrix,false,y);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,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",

+ 8 - 8
build/ThreeDebug.js

@@ -178,14 +178,14 @@ j.wireframe_linewidth!==undefined?j.wireframe_linewidth:j.linewidth!==undefined?
 j.materials.length;r<l;r++){s=j.materials[r];if(s instanceof THREE.MeshFaceMaterial){s=0;for(t=p.materials.length;s<t;s++)if((H=p.materials[s])&&H.blending==B&&H.opacity<1==k){this.setBlending(H.blending);this.renderBuffer(e,h,o,H,p,j)}}else if((H=s)&&H.blending==B&&H.opacity<1==k){this.setBlending(H.blending);this.renderBuffer(e,h,o,H,p,j)}}};this.render=function(e,h,o){var j,p,B,k,s=e.lights,t=e.fog;this.initWebGLObjects(e);if(o&&!o.__webGLFramebuffer){o.__webGLFramebuffer=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){j=o.__webGLFramebuffer;p=o.width;k=o.height}else{j=null;
-p=q.width;k=q.height}if(j!=n){b.bindFramebuffer(b.FRAMEBUFFER,j);b.viewport(0,0,p,k);n=j}this.autoClear&&this.clear();h.autoUpdateMatrix&&h.updateMatrix();y.set(h.matrix.flatten());T.set(h.projectionMatrix.flatten());j=0;for(p=e.__webGLObjects.length;j<p;j++){B=e.__webGLObjects[j];k=B.object;B=B.buffer;if(k.visible){this.setupMatrices(k,h);this.renderPass(h,s,t,k,B,THREE.NormalBlending,false)}}j=0;for(p=e.__webGLObjects.length;j<p;j++){B=e.__webGLObjects[j];k=B.object;B=B.buffer;if(k.visible){this.setupMatrices(k,
-h);this.renderPass(h,s,t,k,B,THREE.AdditiveBlending,false);this.renderPass(h,s,t,k,B,THREE.SubtractiveBlending,false);this.renderPass(h,s,t,k,B,THREE.AdditiveBlending,true);this.renderPass(h,s,t,k,B,THREE.SubtractiveBlending,true);this.renderPass(h,s,t,k,B,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,x){if(r[l]==undefined){e.__webGLObjects.push({buffer:H,object:x});r[l]=1}}var o,j,p,B,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(B in k.geometryChunks){s=k.geometryChunks[B];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,B,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,y);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}};
+p=q.width;k=q.height}if(j!=n){b.bindFramebuffer(b.FRAMEBUFFER,j);b.viewport(0,0,p,k);b.clear(b.COLOR_BUFFER_BIT|b.DEPTH_BUFFER_BIT);n=j}this.autoClear&&this.clear();h.autoUpdateMatrix&&h.updateMatrix();y.set(h.matrix.flatten());T.set(h.projectionMatrix.flatten());j=0;for(p=e.__webGLObjects.length;j<p;j++){B=e.__webGLObjects[j];k=B.object;B=B.buffer;if(k.visible){this.setupMatrices(k,h);this.renderPass(h,s,t,k,B,THREE.NormalBlending,false)}}j=0;for(p=e.__webGLObjects.length;j<p;j++){B=e.__webGLObjects[j];
+k=B.object;B=B.buffer;if(k.visible){this.setupMatrices(k,h);this.renderPass(h,s,t,k,B,THREE.AdditiveBlending,false);this.renderPass(h,s,t,k,B,THREE.SubtractiveBlending,false);this.renderPass(h,s,t,k,B,THREE.AdditiveBlending,true);this.renderPass(h,s,t,k,B,THREE.SubtractiveBlending,true);this.renderPass(h,s,t,k,B,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,x){if(r[l]==undefined){e.__webGLObjects.push({buffer:H,object:x});r[l]=1}}var o,j,p,B,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(B in k.geometryChunks){s=k.geometryChunks[B];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,B,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,y);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",

+ 8 - 8
build/ThreeExtras.js

@@ -177,14 +177,14 @@ n.wireframe_linewidth!==undefined?n.wireframe_linewidth:n.linewidth!==undefined?
 n.materials.length;x<q;x++){w=n.materials[x];if(w instanceof THREE.MeshFaceMaterial){w=0;for(z=s.materials.length;w<z;w++)if((N=s.materials[w])&&N.blending==J&&N.opacity<1==p){this.setBlending(N.blending);this.renderBuffer(f,l,u,N,s,n)}}else if((N=w)&&N.blending==J&&N.opacity<1==p){this.setBlending(N.blending);this.renderBuffer(f,l,u,N,s,n)}}};this.render=function(f,l,u){var n,s,J,p,w=f.lights,z=f.fog;this.initWebGLObjects(f);if(u&&!u.__webGLFramebuffer){u.__webGLFramebuffer=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){n=u.__webGLFramebuffer;s=u.width;p=u.height}else{n=null;
-s=j.width;p=j.height}if(n!=m){c.bindFramebuffer(c.FRAMEBUFFER,n);c.viewport(0,0,s,p);m=n}this.autoClear&&this.clear();l.autoUpdateMatrix&&l.updateMatrix();r.set(l.matrix.flatten());B.set(l.projectionMatrix.flatten());n=0;for(s=f.__webGLObjects.length;n<s;n++){J=f.__webGLObjects[n];p=J.object;J=J.buffer;if(p.visible){this.setupMatrices(p,l);this.renderPass(l,w,z,p,J,THREE.NormalBlending,false)}}n=0;for(s=f.__webGLObjects.length;n<s;n++){J=f.__webGLObjects[n];p=J.object;J=J.buffer;if(p.visible){this.setupMatrices(p,
-l);this.renderPass(l,w,z,p,J,THREE.AdditiveBlending,false);this.renderPass(l,w,z,p,J,THREE.SubtractiveBlending,false);this.renderPass(l,w,z,p,J,THREE.AdditiveBlending,true);this.renderPass(l,w,z,p,J,THREE.SubtractiveBlending,true);this.renderPass(l,w,z,p,J,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,J,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(J in p.geometryChunks){w=p.geometryChunks[J];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,J,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);M.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,B);c.uniformMatrix3fv(f.uniforms.normalMatrix,false,C);c.uniformMatrix4fv(f.uniforms.objectMatrix,false,M)};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}};
+s=j.width;p=j.height}if(n!=m){c.bindFramebuffer(c.FRAMEBUFFER,n);c.viewport(0,0,s,p);c.clear(c.COLOR_BUFFER_BIT|c.DEPTH_BUFFER_BIT);m=n}this.autoClear&&this.clear();l.autoUpdateMatrix&&l.updateMatrix();r.set(l.matrix.flatten());B.set(l.projectionMatrix.flatten());n=0;for(s=f.__webGLObjects.length;n<s;n++){J=f.__webGLObjects[n];p=J.object;J=J.buffer;if(p.visible){this.setupMatrices(p,l);this.renderPass(l,w,z,p,J,THREE.NormalBlending,false)}}n=0;for(s=f.__webGLObjects.length;n<s;n++){J=f.__webGLObjects[n];
+p=J.object;J=J.buffer;if(p.visible){this.setupMatrices(p,l);this.renderPass(l,w,z,p,J,THREE.AdditiveBlending,false);this.renderPass(l,w,z,p,J,THREE.SubtractiveBlending,false);this.renderPass(l,w,z,p,J,THREE.AdditiveBlending,true);this.renderPass(l,w,z,p,J,THREE.SubtractiveBlending,true);this.renderPass(l,w,z,p,J,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,J,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(J in p.geometryChunks){w=p.geometryChunks[J];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,J,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);M.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,B);c.uniformMatrix3fv(f.uniforms.normalMatrix,false,C);c.uniformMatrix4fv(f.uniforms.objectMatrix,false,M)};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",

+ 47 - 4
examples/render_to_texture.html

@@ -43,6 +43,7 @@
 			
             void main(void)
             {
+				//gl_FragColor = texture2D( tDiffuse, vec2( vUv.x, 1.0 - vUv.y ) );
 				gl_FragColor = texture2D( tDiffuse, vUv );
             }
         </script>
@@ -79,7 +80,7 @@
 
             var container, stats;
 
-            var cameraRTT, camera, sceneRTT, sceneScreen, scene, renderer;
+            var cameraRTT, camera, sceneRTT, sceneScreen, scene, renderer, zmesh1, zmesh2;
 
 			var mouseX = 0, mouseY = 0;
 			
@@ -113,6 +114,8 @@
 				light.position.z = 1;
 				light.position.normalize();
 				scene.addLight( light );
+				sceneRTT.addLight( light );
+				sceneScreen.addLight( light );
 
 				light = new THREE.DirectionalLight( 0xffaaaa, 0.5 );
 				light.position.x = -1;
@@ -139,14 +142,17 @@
 
                 } );
 
-				var mt = new THREE.MeshBasicMaterial( { color:0xffffff, map: ImageUtils.loadTexture( "textures/land_ocean_ice_cloud_2048.jpg" ) } );
+				//var mt = new THREE.MeshBasicMaterial( { color:0xffffff, map: ImageUtils.loadTexture( "textures/land_ocean_ice_cloud_2048.jpg" ) } );
 				
-				var plane = new Plane( 2000, 1000 );
+				var plane = new Plane( window.innerWidth, window.innerHeight );
 				
                 quad = new THREE.Mesh( plane, material );
 				quad.position.z = -100;
                 sceneRTT.addObject( quad );
 
+				var loader = new THREE.Loader();
+				loader.loadBinary( { model: "obj/torus/Torus_bin.js", callback: function( geometry ) { createMesh( geometry, sceneRTT ) } } );
+
                 quad = new THREE.Mesh( plane, materialScreen );
 				quad.position.z = -100;
                 sceneScreen.addObject( quad );
@@ -183,6 +189,31 @@
 
             }
 
+			function createMesh( geometry, xscene ) {
+
+				var mat1 = new THREE.MeshPhongMaterial( { color: 0x555555, specular:0xffaa00, shininess:5 } ),
+					mat2 = new THREE.MeshPhongMaterial( { color: 0x550000, specular:0xff2200, shininess:5 } );
+				
+				zmesh1 = new THREE.Mesh( geometry, mat1 );
+				zmesh1.position.x = 0;
+				zmesh1.position.y = 0;
+				zmesh1.position.z = 100;
+				zmesh1.scale.x = zmesh1.scale.y = zmesh1.scale.z = 150;
+				zmesh1.overdraw = true;
+				zmesh1.updateMatrix();
+				xscene.addObject( zmesh1 );
+
+				zmesh2 = new THREE.Mesh( geometry, mat2 );
+				zmesh2.position.x = 0;
+				zmesh2.position.y = 150;
+				zmesh2.position.z = 100;
+				zmesh2.scale.x = zmesh2.scale.y = zmesh2.scale.z = 75;
+				zmesh2.overdraw = true;
+				zmesh2.updateMatrix();
+				xscene.addObject( zmesh2 );
+
+			}
+
 			function onDocumentMouseMove( event ) {
 
 				mouseX = ( event.clientX - windowHalfX );
@@ -194,10 +225,20 @@
 			
             function loop() {
 
+				var time = new Date().getTime() * 0.0015;
+				
 				camera.position.x += ( mouseX - camera.position.x ) * .05;
 				camera.position.y += ( - mouseY - camera.position.y ) * .05;
 
-                
+				if ( zmesh1 && zmesh2 ) {
+				
+					zmesh1.rotation.x = 1.57;
+					zmesh1.rotation.z = time;
+
+					zmesh2.rotation.z = 1.57;
+					zmesh2.rotation.y = -time;
+
+				}
 				
 				if ( material.uniforms.time.value > 1 || material.uniforms.time.value < 0 ) {
 				
@@ -213,11 +254,13 @@
 				
                 renderer.render( sceneRTT, cameraRTT, rtTexture );
 				
+				
 				// Render full screen quad with generated texture
 				// (disable depth writing so that it stays in the background)
 				
 				renderer.context.depthMask( 0 );
 				renderer.render( sceneScreen, cameraRTT );
+				//renderer.render( sceneRTT, cameraRTT );
 				renderer.context.depthMask( 1 );
 				
                 // Render second scene to screen

+ 1 - 0
src/renderers/WebGLRenderer.js

@@ -1505,6 +1505,7 @@ THREE.WebGLRenderer = function ( parameters ) {
 			
 			_gl.bindFramebuffer( _gl.FRAMEBUFFER, framebuffer );
 			_gl.viewport( 0, 0, width, height );
+			_gl.clear( _gl.COLOR_BUFFER_BIT | _gl.DEPTH_BUFFER_BIT );
 			
 			_oldFramebuffer = framebuffer;