From 45f47b89b70d3ffafc092ee54246bc7d9e8ffb6e Mon Sep 17 00:00:00 2001 From: alteredq Date: Tue, 14 Dec 2010 00:17:53 +0100 Subject: [PATCH] Added minecraft fake ambient occlusion demo. For some reason it doesn't work with the current Chrome canary (10.0.607.0) when using ANGLE :(. Also OBJ converter demo is having problems with generated tiled texture in latest canary, so it looks like some bug was introduced in ANGLE's handling of UVs (baked AO relies on "zoomed" UVs). Need to investigate more, maybe file a bug report. --- build/Three.js | 10 +- build/ThreeDebug.js | 10 +- build/ThreeExtras.js | 10 +- examples/geometry_minecraft_ao.html | 908 ++++++++++++++++++++++++++++ src/renderers/WebGLRenderer.js | 5 +- 5 files changed, 926 insertions(+), 17 deletions(-) create mode 100644 examples/geometry_minecraft_ao.html diff --git a/build/Three.js b/build/Three.js index 8f7635bf..a2dd83ad 100755 --- a/build/Three.js +++ b/build/Three.js @@ -169,10 +169,10 @@ THREE.MeshPhongMaterial){j=f.ambient;g=f.specular;f=f.shininess;c.uniform4f(z.un 0);c.uniform1i(z.uniforms.enableMap,1)}else c.uniform1i(z.uniforms.enableMap,0);if(y){d(y,1);c.uniform1i(z.uniforms.tCube,1);c.uniform1i(z.uniforms.enableCubeMap,1)}else c.uniform1i(z.uniforms.enableCubeMap,0);i=z.attributes;c.bindBuffer(c.ARRAY_BUFFER,p.__webGLVertexBuffer);c.vertexAttribPointer(i.position,3,c.FLOAT,false,0,0);if(i.normal>=0){c.bindBuffer(c.ARRAY_BUFFER,p.__webGLNormalBuffer);c.vertexAttribPointer(i.normal,3,c.FLOAT,false,0,0)}if(i.tangent>=0){c.bindBuffer(c.ARRAY_BUFFER,p.__webGLTangentBuffer); c.vertexAttribPointer(i.tangent,4,c.FLOAT,false,0,0)}if(i.uv>=0)if(p.__webGLUVBuffer){c.bindBuffer(c.ARRAY_BUFFER,p.__webGLUVBuffer);c.enableVertexAttribArray(i.uv);c.vertexAttribPointer(i.uv,2,c.FLOAT,false,0,0)}else c.disableVertexAttribArray(i.uv);if(u){c.lineWidth(s);c.bindBuffer(c.ELEMENT_ARRAY_BUFFER,p.__webGLLineBuffer);c.drawElements(c.LINES,p.__webGLLineCount,c.UNSIGNED_SHORT,0)}else{c.bindBuffer(c.ELEMENT_ARRAY_BUFFER,p.__webGLFaceBuffer);c.drawElements(c.TRIANGLES,p.__webGLFaceCount,c.UNSIGNED_SHORT, 0)}};this.renderPass=function(g,k,f,p,j,i){var u,s,G,y,H;G=0;for(y=f.material.length;G=0;f--){p=g.__webGLObjects[f].object;k==p&&g.__webGLObjects.splice(f,1)}};this.setupMatrices=function(g,k){g.autoUpdateMatrix&&g.updateMatrix();r.multiply(k.matrix,g.matrix);E.set(k.matrix.flatten());M.set(r.flatten());O.set(k.projectionMatrix.flatten());q=THREE.Matrix4.makeInvert3x3(r).transpose();J.set(q.m);K.set(g.matrix.flatten())};this.loadMatrices= -function(g){c.uniformMatrix4fv(g.uniforms.viewMatrix,false,E);c.uniformMatrix4fv(g.uniforms.modelViewMatrix,false,M);c.uniformMatrix4fv(g.uniforms.projectionMatrix,false,O);c.uniformMatrix3fv(g.uniforms.normalMatrix,false,J);c.uniformMatrix4fv(g.uniforms.objectMatrix,false,K)};this.loadCamera=function(g,k){c.uniform3f(g.uniforms.cameraPosition,k.position.x,k.position.y,k.position.z)};this.setBlending=function(g){switch(g){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(g,k){if(g){!k||k=="ccw"?c.frontFace(c.CCW):c.frontFace(c.CW);if(g=="back")c.cullFace(c.BACK);else g=="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}}; +k.autoUpdateMatrix&&k.updateMatrix();E.set(k.matrix.flatten());O.set(k.projectionMatrix.flatten());f=0;for(p=g.__webGLObjects.length;f=0;f--){p=g.__webGLObjects[f].object;k==p&&g.__webGLObjects.splice(f,1)}};this.setupMatrices=function(g,k){g.autoUpdateMatrix&&g.updateMatrix();r.multiply(k.matrix,g.matrix);M.set(r.flatten());q=THREE.Matrix4.makeInvert3x3(r).transpose();J.set(q.m);K.set(g.matrix.flatten())};this.loadMatrices=function(g){c.uniformMatrix4fv(g.uniforms.viewMatrix, +false,E);c.uniformMatrix4fv(g.uniforms.modelViewMatrix,false,M);c.uniformMatrix4fv(g.uniforms.projectionMatrix,false,O);c.uniformMatrix3fv(g.uniforms.normalMatrix,false,J);c.uniformMatrix4fv(g.uniforms.objectMatrix,false,K)};this.loadCamera=function(g,k){c.uniform3f(g.uniforms.cameraPosition,k.position.x,k.position.y,k.position.z)};this.setBlending=function(g){switch(g){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(g,k){if(g){!k||k=="ccw"?c.frontFace(c.CCW):c.frontFace(c.CW);if(g=="back")c.cullFace(c.BACK);else g=="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.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.faceMaterial=this.meshMaterial=null;this.overdraw=false;this.uvs=[null,null,null]};THREE.RenderableParticle=function(){this.rotation=this.z=this.y=this.x=null;this.scale=new THREE.Vector2;this.material=null}; THREE.RenderableLine=function(){this.z=null;this.v1=new THREE.Vertex;this.v2=new THREE.Vertex;this.material=null}; diff --git a/build/ThreeDebug.js b/build/ThreeDebug.js index c969a07c..7de5317d 100644 --- a/build/ThreeDebug.js +++ b/build/ThreeDebug.js @@ -170,10 +170,10 @@ THREE.MeshPhongMaterial){j=f.ambient;g=f.specular;f=f.shininess;c.uniform4f(A.un 0);c.uniform1i(A.uniforms.enableMap,1)}else c.uniform1i(A.uniforms.enableMap,0);if(z){d(z,1);c.uniform1i(A.uniforms.tCube,1);c.uniform1i(A.uniforms.enableCubeMap,1)}else c.uniform1i(A.uniforms.enableCubeMap,0);i=A.attributes;c.bindBuffer(c.ARRAY_BUFFER,p.__webGLVertexBuffer);c.vertexAttribPointer(i.position,3,c.FLOAT,false,0,0);if(i.normal>=0){c.bindBuffer(c.ARRAY_BUFFER,p.__webGLNormalBuffer);c.vertexAttribPointer(i.normal,3,c.FLOAT,false,0,0)}if(i.tangent>=0){c.bindBuffer(c.ARRAY_BUFFER,p.__webGLTangentBuffer); c.vertexAttribPointer(i.tangent,4,c.FLOAT,false,0,0)}if(i.uv>=0)if(p.__webGLUVBuffer){c.bindBuffer(c.ARRAY_BUFFER,p.__webGLUVBuffer);c.enableVertexAttribArray(i.uv);c.vertexAttribPointer(i.uv,2,c.FLOAT,false,0,0)}else c.disableVertexAttribArray(i.uv);if(u){c.lineWidth(t);c.bindBuffer(c.ELEMENT_ARRAY_BUFFER,p.__webGLLineBuffer);c.drawElements(c.LINES,p.__webGLLineCount,c.UNSIGNED_SHORT,0)}else{c.bindBuffer(c.ELEMENT_ARRAY_BUFFER,p.__webGLFaceBuffer);c.drawElements(c.TRIANGLES,p.__webGLFaceCount,c.UNSIGNED_SHORT, 0)}};this.renderPass=function(g,l,f,p,j,i){var u,t,G,z,H;G=0;for(z=f.material.length;G=0;f--){p=g.__webGLObjects[f].object;l==p&&g.__webGLObjects.splice(f,1)}};this.setupMatrices=function(g,l){g.autoUpdateMatrix&&g.updateMatrix();s.multiply(l.matrix,g.matrix);E.set(l.matrix.flatten());M.set(s.flatten());O.set(l.projectionMatrix.flatten());r=THREE.Matrix4.makeInvert3x3(s).transpose();J.set(r.m);K.set(g.matrix.flatten())};this.loadMatrices= -function(g){c.uniformMatrix4fv(g.uniforms.viewMatrix,false,E);c.uniformMatrix4fv(g.uniforms.modelViewMatrix,false,M);c.uniformMatrix4fv(g.uniforms.projectionMatrix,false,O);c.uniformMatrix3fv(g.uniforms.normalMatrix,false,J);c.uniformMatrix4fv(g.uniforms.objectMatrix,false,K)};this.loadCamera=function(g,l){c.uniform3f(g.uniforms.cameraPosition,l.position.x,l.position.y,l.position.z)};this.setBlending=function(g){switch(g){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(g,l){if(g){!l||l=="ccw"?c.frontFace(c.CCW):c.frontFace(c.CW);if(g=="back")c.cullFace(c.BACK);else g=="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}}; +l.autoUpdateMatrix&&l.updateMatrix();E.set(l.matrix.flatten());O.set(l.projectionMatrix.flatten());f=0;for(p=g.__webGLObjects.length;f=0;f--){p=g.__webGLObjects[f].object;l==p&&g.__webGLObjects.splice(f,1)}};this.setupMatrices=function(g,l){g.autoUpdateMatrix&&g.updateMatrix();s.multiply(l.matrix,g.matrix);M.set(s.flatten());r=THREE.Matrix4.makeInvert3x3(s).transpose();J.set(r.m);K.set(g.matrix.flatten())};this.loadMatrices=function(g){c.uniformMatrix4fv(g.uniforms.viewMatrix, +false,E);c.uniformMatrix4fv(g.uniforms.modelViewMatrix,false,M);c.uniformMatrix4fv(g.uniforms.projectionMatrix,false,O);c.uniformMatrix3fv(g.uniforms.normalMatrix,false,J);c.uniformMatrix4fv(g.uniforms.objectMatrix,false,K)};this.loadCamera=function(g,l){c.uniform3f(g.uniforms.cameraPosition,l.position.x,l.position.y,l.position.z)};this.setBlending=function(g){switch(g){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(g,l){if(g){!l||l=="ccw"?c.frontFace(c.CCW):c.frontFace(c.CW);if(g=="back")c.cullFace(c.BACK);else g=="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.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.faceMaterial=this.meshMaterial=null;this.overdraw=false;this.uvs=[null,null,null]};THREE.RenderableParticle=function(){this.rotation=this.z=this.y=this.x=null;this.scale=new THREE.Vector2;this.material=null}; THREE.RenderableLine=function(){this.z=null;this.v1=new THREE.Vertex;this.v2=new THREE.Vertex;this.material=null}; diff --git a/build/ThreeExtras.js b/build/ThreeExtras.js index f311d658..fd676384 100644 --- a/build/ThreeExtras.js +++ b/build/ThreeExtras.js @@ -169,11 +169,11 @@ THREE.MeshPhongMaterial){n=h.ambient;i=h.specular;h=h.shininess;c.uniform4f(G.un 0);c.uniform1i(G.uniforms.enableMap,1)}else c.uniform1i(G.uniforms.enableMap,0);if(E){d(E,1);c.uniform1i(G.uniforms.tCube,1);c.uniform1i(G.uniforms.enableCubeMap,1)}else c.uniform1i(G.uniforms.enableCubeMap,0);m=G.attributes;c.bindBuffer(c.ARRAY_BUFFER,w.__webGLVertexBuffer);c.vertexAttribPointer(m.position,3,c.FLOAT,false,0,0);if(m.normal>=0){c.bindBuffer(c.ARRAY_BUFFER,w.__webGLNormalBuffer);c.vertexAttribPointer(m.normal,3,c.FLOAT,false,0,0)}if(m.tangent>=0){c.bindBuffer(c.ARRAY_BUFFER,w.__webGLTangentBuffer); c.vertexAttribPointer(m.tangent,4,c.FLOAT,false,0,0)}if(m.uv>=0)if(w.__webGLUVBuffer){c.bindBuffer(c.ARRAY_BUFFER,w.__webGLUVBuffer);c.enableVertexAttribArray(m.uv);c.vertexAttribPointer(m.uv,2,c.FLOAT,false,0,0)}else c.disableVertexAttribArray(m.uv);if(D){c.lineWidth(A);c.bindBuffer(c.ELEMENT_ARRAY_BUFFER,w.__webGLLineBuffer);c.drawElements(c.LINES,w.__webGLLineCount,c.UNSIGNED_SHORT,0)}else{c.bindBuffer(c.ELEMENT_ARRAY_BUFFER,w.__webGLFaceBuffer);c.drawElements(c.TRIANGLES,w.__webGLFaceCount,c.UNSIGNED_SHORT, 0)}};this.renderPass=function(i,p,h,w,n,m){var D,A,L,E,O;L=0;for(E=h.material.length;L=0;h--){w=i.__webGLObjects[h].object;p==w&&i.__webGLObjects.splice(h,1)}};this.setupMatrices=function(i,p){i.autoUpdateMatrix&&i.updateMatrix();q.multiply(p.matrix,i.matrix);v.set(p.matrix.flatten());z.set(q.flatten());K.set(p.projectionMatrix.flatten());s=THREE.Matrix4.makeInvert3x3(q).transpose();F.set(s.m);y.set(i.matrix.flatten())};this.loadMatrices= -function(i){c.uniformMatrix4fv(i.uniforms.viewMatrix,false,v);c.uniformMatrix4fv(i.uniforms.modelViewMatrix,false,z);c.uniformMatrix4fv(i.uniforms.projectionMatrix,false,K);c.uniformMatrix3fv(i.uniforms.normalMatrix,false,F);c.uniformMatrix4fv(i.uniforms.objectMatrix,false,y)};this.loadCamera=function(i,p){c.uniform3f(i.uniforms.cameraPosition,p.position.x,p.position.y,p.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,p){if(i){!p||p=="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}}; +p.autoUpdateMatrix&&p.updateMatrix();v.set(p.matrix.flatten());K.set(p.projectionMatrix.flatten());h=0;for(w=i.__webGLObjects.length;h=0;h--){w=i.__webGLObjects[h].object;p==w&&i.__webGLObjects.splice(h,1)}};this.setupMatrices=function(i,p){i.autoUpdateMatrix&&i.updateMatrix();q.multiply(p.matrix,i.matrix);z.set(q.flatten());s=THREE.Matrix4.makeInvert3x3(q).transpose();F.set(s.m);y.set(i.matrix.flatten())};this.loadMatrices=function(i){c.uniformMatrix4fv(i.uniforms.viewMatrix, +false,v);c.uniformMatrix4fv(i.uniforms.modelViewMatrix,false,z);c.uniformMatrix4fv(i.uniforms.projectionMatrix,false,K);c.uniformMatrix3fv(i.uniforms.normalMatrix,false,F);c.uniformMatrix4fv(i.uniforms.objectMatrix,false,y)};this.loadCamera=function(i,p){c.uniform3f(i.uniforms.cameraPosition,p.position.x,p.position.y,p.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,p){if(i){!p||p=="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}}; 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.faceMaterial=this.meshMaterial=null;this.overdraw=false;this.uvs=[null,null,null]};THREE.RenderableParticle=function(){this.rotation=this.z=this.y=this.x=null;this.scale=new THREE.Vector2;this.material=null}; THREE.RenderableLine=function(){this.z=null;this.v1=new THREE.Vertex;this.v2=new THREE.Vertex;this.material=null}; var GeometryUtils={merge:function(a,b){var d=b instanceof THREE.Mesh,e=a.vertices.length,f=d?b.geometry:b,k=a.vertices,l=f.vertices,g=a.faces,j=f.faces,c=a.uvs;f=f.uvs;d&&b.updateMatrix();for(var t=0,x=l.length;t + + + three.js - geometry - minecraft - ao + + + + + +





Generating world...
+
+ three.js - minecraft demo [ambient occlusion]. featuring painterly pack
(left click: forward, right click: backward) +

+ + + +
+ +
+
+ Sorry, your browser doesn't support WebGL
+
+ Please try in + Chrome 9+ / + Firefox 4+ / + Safari OSX 10.6+ +
+
+ + + + + + + + + + + + diff --git a/src/renderers/WebGLRenderer.js b/src/renderers/WebGLRenderer.js index 8fcacfe6..ddadadff 100644 --- a/src/renderers/WebGLRenderer.js +++ b/src/renderers/WebGLRenderer.js @@ -645,6 +645,9 @@ THREE.WebGLRenderer = function ( scene ) { } camera.autoUpdateMatrix && camera.updateMatrix(); + + _viewMatrixArray.set( camera.matrix.flatten() ); + _projectionMatrixArray.set( camera.projectionMatrix.flatten() ); // opaque pass @@ -783,9 +786,7 @@ THREE.WebGLRenderer = function ( scene ) { _modelViewMatrix.multiply( camera.matrix, object.matrix ); - _viewMatrixArray.set( camera.matrix.flatten() ); _modelViewMatrixArray.set( _modelViewMatrix.flatten() ); - _projectionMatrixArray.set( camera.projectionMatrix.flatten() ); _normalMatrix = THREE.Matrix4.makeInvert3x3( _modelViewMatrix ).transpose(); _normalMatrixArray.set( _normalMatrix.m );