提交 c83f5e5d 编写于 作者: A alteredq

Fixed shadowmaps not getting proper GL state if there were flipsided objects in the scene.

上级 69449576
......@@ -34057,6 +34057,7 @@ THREE.ShadowMapPlugin = function ( ) {
_gl.disable( _gl.BLEND );
_gl.enable( _gl.CULL_FACE );
_gl.frontFace( _gl.CCW );
if ( _renderer.shadowMapCullFrontFaces ) {
......
......@@ -742,17 +742,17 @@ I.y<s){b.activeTexture(b.TEXTURE1);b.bindTexture(b.TEXTURE_2D,h);b.copyTexImage2
b.bindTexture(b.TEXTURE_2D,h);b.drawElements(b.TRIANGLES,6,b.UNSIGNED_SHORT,0);D.positionScreen.copy(y);D.customUpdateCallback?D.customUpdateCallback(D):D.updateLensFlares();b.uniform1i(F.renderType,2);b.enable(b.BLEND);G=0;for(M=D.lensFlares.length;G<M;G++){K=D.lensFlares[G];if(K.opacity>0.001&&K.scale>0.001){y.x=K.x;y.y=K.y;y.z=K.z;B=K.size*K.scale/s;J.x=B*u;J.y=B;b.uniform3f(F.screenPosition,y.x,y.y,y.z);b.uniform2f(F.scale,J.x,J.y);b.uniform1f(F.rotation,K.rotation);b.uniform1f(F.opacity,K.opacity);
b.uniform3f(F.color,K.color.r,K.color.g,K.color.b);c.setBlending(K.blending,K.blendEquation,K.blendSrc,K.blendDst);c.setTexture(K.texture,1);b.drawElements(b.TRIANGLES,6,b.UNSIGNED_SHORT,0)}}}}b.enable(b.CULL_FACE);b.enable(b.DEPTH_TEST);b.depthMask(true)}}};
THREE.ShadowMapPlugin=function(){var a,b,c,d,f,e,g=new THREE.Frustum,h=new THREE.Matrix4,i=new THREE.Vector3,j=new THREE.Vector3;this.init=function(g){a=g.context;b=g;var g=THREE.ShaderLib.depthRGBA,h=THREE.UniformsUtils.clone(g.uniforms);c=new THREE.ShaderMaterial({fragmentShader:g.fragmentShader,vertexShader:g.vertexShader,uniforms:h});d=new THREE.ShaderMaterial({fragmentShader:g.fragmentShader,vertexShader:g.vertexShader,uniforms:h,morphTargets:true});f=new THREE.ShaderMaterial({fragmentShader:g.fragmentShader,
vertexShader:g.vertexShader,uniforms:h,skinning:true});e=new THREE.ShaderMaterial({fragmentShader:g.fragmentShader,vertexShader:g.vertexShader,uniforms:h,morphTargets:true,skinning:true});c._shadowPass=true;d._shadowPass=true;f._shadowPass=true;e._shadowPass=true};this.render=function(a,c){b.shadowMapEnabled&&b.shadowMapAutoUpdate&&this.update(a,c)};this.update=function(l,n){var m,q,p,o,r,s,t,v,u,A=[];o=0;a.clearColor(1,1,1,1);a.disable(a.BLEND);a.enable(a.CULL_FACE);b.shadowMapCullFrontFaces?a.cullFace(a.FRONT):
a.cullFace(a.BACK);b.setDepthTest(true);m=0;for(q=l.__lights.length;m<q;m++){p=l.__lights[m];if(p.castShadow)if(p instanceof THREE.DirectionalLight&&p.shadowCascade)for(r=0;r<p.shadowCascadeCount;r++){var x;if(p.shadowCascadeArray[r])x=p.shadowCascadeArray[r];else{u=p;t=r;x=new THREE.DirectionalLight;x.isVirtual=true;x.onlyShadow=true;x.castShadow=true;x.shadowCameraNear=u.shadowCameraNear;x.shadowCameraFar=u.shadowCameraFar;x.shadowCameraLeft=u.shadowCameraLeft;x.shadowCameraRight=u.shadowCameraRight;
x.shadowCameraBottom=u.shadowCameraBottom;x.shadowCameraTop=u.shadowCameraTop;x.shadowCameraVisible=u.shadowCameraVisible;x.shadowDarkness=u.shadowDarkness;x.shadowBias=u.shadowCascadeBias[t];x.shadowMapWidth=u.shadowCascadeWidth[t];x.shadowMapHeight=u.shadowCascadeHeight[t];x.pointsWorld=[];x.pointsFrustum=[];v=x.pointsWorld;s=x.pointsFrustum;for(var B=0;B<8;B++){v[B]=new THREE.Vector3;s[B]=new THREE.Vector3}v=u.shadowCascadeNearZ[t];u=u.shadowCascadeFarZ[t];s[0].set(-1,-1,v);s[1].set(1,-1,v);s[2].set(-1,
1,v);s[3].set(1,1,v);s[4].set(-1,-1,u);s[5].set(1,-1,u);s[6].set(-1,1,u);s[7].set(1,1,u);x.originalCamera=n;s=new THREE.Gyroscope;s.position=p.shadowCascadeOffset;s.add(x);s.add(x.target);n.add(s);p.shadowCascadeArray[r]=x;console.log("Created virtualLight",x)}t=p;v=r;u=t.shadowCascadeArray[v];u.position.copy(t.position);u.target.position.copy(t.target.position);u.lookAt(u.target);u.shadowCameraVisible=t.shadowCameraVisible;u.shadowDarkness=t.shadowDarkness;u.shadowBias=t.shadowCascadeBias[v];s=t.shadowCascadeNearZ[v];
t=t.shadowCascadeFarZ[v];u=u.pointsFrustum;u[0].z=s;u[1].z=s;u[2].z=s;u[3].z=s;u[4].z=t;u[5].z=t;u[6].z=t;u[7].z=t;A[o]=x;o++}else{A[o]=p;o++}}m=0;for(q=A.length;m<q;m++){p=A[m];if(!p.shadowMap){p.shadowMap=new THREE.WebGLRenderTarget(p.shadowMapWidth,p.shadowMapHeight,{minFilter:THREE.LinearFilter,magFilter:THREE.LinearFilter,format:THREE.RGBAFormat});p.shadowMapSize=new THREE.Vector2(p.shadowMapWidth,p.shadowMapHeight);p.shadowMatrix=new THREE.Matrix4}if(!p.shadowCamera){if(p instanceof THREE.SpotLight)p.shadowCamera=
new THREE.PerspectiveCamera(p.shadowCameraFov,p.shadowMapWidth/p.shadowMapHeight,p.shadowCameraNear,p.shadowCameraFar);else if(p instanceof THREE.DirectionalLight)p.shadowCamera=new THREE.OrthographicCamera(p.shadowCameraLeft,p.shadowCameraRight,p.shadowCameraTop,p.shadowCameraBottom,p.shadowCameraNear,p.shadowCameraFar);else{console.error("Unsupported light type for shadow");continue}l.add(p.shadowCamera);b.autoUpdateScene&&l.updateMatrixWorld()}if(p.shadowCameraVisible&&!p.cameraHelper){p.cameraHelper=
new THREE.CameraHelper(p.shadowCamera);p.shadowCamera.add(p.cameraHelper)}if(p.isVirtual&&x.originalCamera==n){r=n;o=p.shadowCamera;s=p.pointsFrustum;u=p.pointsWorld;i.set(Infinity,Infinity,Infinity);j.set(-Infinity,-Infinity,-Infinity);for(t=0;t<8;t++){v=u[t];v.copy(s[t]);THREE.ShadowMapPlugin.__projector.unprojectVector(v,r);o.matrixWorldInverse.multiplyVector3(v);if(v.x<i.x)i.x=v.x;if(v.x>j.x)j.x=v.x;if(v.y<i.y)i.y=v.y;if(v.y>j.y)j.y=v.y;if(v.z<i.z)i.z=v.z;if(v.z>j.z)j.z=v.z}o.left=i.x;o.right=
j.x;o.top=j.y;o.bottom=i.y;o.updateProjectionMatrix()}o=p.shadowMap;s=p.shadowMatrix;r=p.shadowCamera;r.position.copy(p.matrixWorld.getPosition());r.lookAt(p.target.matrixWorld.getPosition());r.updateMatrixWorld();r.matrixWorldInverse.getInverse(r.matrixWorld);if(p.cameraHelper)p.cameraHelper.visible=p.shadowCameraVisible;p.shadowCameraVisible&&p.cameraHelper.update();s.set(0.5,0,0,0.5,0,0.5,0,0.5,0,0,0.5,0.5,0,0,0,1);s.multiplySelf(r.projectionMatrix);s.multiplySelf(r.matrixWorldInverse);if(!r._viewMatrixArray)r._viewMatrixArray=
new Float32Array(16);if(!r._projectionMatrixArray)r._projectionMatrixArray=new Float32Array(16);r.matrixWorldInverse.flattenToArray(r._viewMatrixArray);r.projectionMatrix.flattenToArray(r._projectionMatrixArray);h.multiply(r.projectionMatrix,r.matrixWorldInverse);g.setFromMatrix(h);b.setRenderTarget(o);b.clear();u=l.__webglObjects;p=0;for(o=u.length;p<o;p++){t=u[p];s=t.object;t.render=false;if(s.visible&&s.castShadow&&(!(s instanceof THREE.Mesh)||!s.frustumCulled||g.contains(s))){s._modelViewMatrix.multiply(r.matrixWorldInverse,
s.matrixWorld);t.render=true}}p=0;for(o=u.length;p<o;p++){t=u[p];if(t.render){s=t.object;t=t.buffer;v=s.customDepthMaterial?s.customDepthMaterial:s instanceof THREE.SkinnedMesh?s.geometry.morphTargets.length?e:f:s.geometry.morphTargets.length?d:c;t instanceof THREE.BufferGeometry?b.renderBufferDirect(r,l.__lights,null,v,t,s):b.renderBuffer(r,l.__lights,null,v,t,s)}}u=l.__webglObjectsImmediate;p=0;for(o=u.length;p<o;p++){t=u[p];s=t.object;if(s.visible&&s.castShadow){s._modelViewMatrix.multiply(r.matrixWorldInverse,
s.matrixWorld);b.renderImmediateObject(r,l.__lights,null,c,s)}}}m=b.getClearColor();q=b.getClearAlpha();a.clearColor(m.r,m.g,m.b,q);a.enable(a.BLEND);b.shadowMapCullFrontFaces&&a.cullFace(a.BACK)}};THREE.ShadowMapPlugin.__projector=new THREE.Projector;
vertexShader:g.vertexShader,uniforms:h,skinning:true});e=new THREE.ShaderMaterial({fragmentShader:g.fragmentShader,vertexShader:g.vertexShader,uniforms:h,morphTargets:true,skinning:true});c._shadowPass=true;d._shadowPass=true;f._shadowPass=true;e._shadowPass=true};this.render=function(a,c){b.shadowMapEnabled&&b.shadowMapAutoUpdate&&this.update(a,c)};this.update=function(l,n){var m,q,p,o,r,s,t,v,u,A=[];o=0;a.clearColor(1,1,1,1);a.disable(a.BLEND);a.enable(a.CULL_FACE);a.frontFace(a.CCW);b.shadowMapCullFrontFaces?
a.cullFace(a.FRONT):a.cullFace(a.BACK);b.setDepthTest(true);m=0;for(q=l.__lights.length;m<q;m++){p=l.__lights[m];if(p.castShadow)if(p instanceof THREE.DirectionalLight&&p.shadowCascade)for(r=0;r<p.shadowCascadeCount;r++){var x;if(p.shadowCascadeArray[r])x=p.shadowCascadeArray[r];else{u=p;t=r;x=new THREE.DirectionalLight;x.isVirtual=true;x.onlyShadow=true;x.castShadow=true;x.shadowCameraNear=u.shadowCameraNear;x.shadowCameraFar=u.shadowCameraFar;x.shadowCameraLeft=u.shadowCameraLeft;x.shadowCameraRight=
u.shadowCameraRight;x.shadowCameraBottom=u.shadowCameraBottom;x.shadowCameraTop=u.shadowCameraTop;x.shadowCameraVisible=u.shadowCameraVisible;x.shadowDarkness=u.shadowDarkness;x.shadowBias=u.shadowCascadeBias[t];x.shadowMapWidth=u.shadowCascadeWidth[t];x.shadowMapHeight=u.shadowCascadeHeight[t];x.pointsWorld=[];x.pointsFrustum=[];v=x.pointsWorld;s=x.pointsFrustum;for(var B=0;B<8;B++){v[B]=new THREE.Vector3;s[B]=new THREE.Vector3}v=u.shadowCascadeNearZ[t];u=u.shadowCascadeFarZ[t];s[0].set(-1,-1,v);
s[1].set(1,-1,v);s[2].set(-1,1,v);s[3].set(1,1,v);s[4].set(-1,-1,u);s[5].set(1,-1,u);s[6].set(-1,1,u);s[7].set(1,1,u);x.originalCamera=n;s=new THREE.Gyroscope;s.position=p.shadowCascadeOffset;s.add(x);s.add(x.target);n.add(s);p.shadowCascadeArray[r]=x;console.log("Created virtualLight",x)}t=p;v=r;u=t.shadowCascadeArray[v];u.position.copy(t.position);u.target.position.copy(t.target.position);u.lookAt(u.target);u.shadowCameraVisible=t.shadowCameraVisible;u.shadowDarkness=t.shadowDarkness;u.shadowBias=
t.shadowCascadeBias[v];s=t.shadowCascadeNearZ[v];t=t.shadowCascadeFarZ[v];u=u.pointsFrustum;u[0].z=s;u[1].z=s;u[2].z=s;u[3].z=s;u[4].z=t;u[5].z=t;u[6].z=t;u[7].z=t;A[o]=x;o++}else{A[o]=p;o++}}m=0;for(q=A.length;m<q;m++){p=A[m];if(!p.shadowMap){p.shadowMap=new THREE.WebGLRenderTarget(p.shadowMapWidth,p.shadowMapHeight,{minFilter:THREE.LinearFilter,magFilter:THREE.LinearFilter,format:THREE.RGBAFormat});p.shadowMapSize=new THREE.Vector2(p.shadowMapWidth,p.shadowMapHeight);p.shadowMatrix=new THREE.Matrix4}if(!p.shadowCamera){if(p instanceof
THREE.SpotLight)p.shadowCamera=new THREE.PerspectiveCamera(p.shadowCameraFov,p.shadowMapWidth/p.shadowMapHeight,p.shadowCameraNear,p.shadowCameraFar);else if(p instanceof THREE.DirectionalLight)p.shadowCamera=new THREE.OrthographicCamera(p.shadowCameraLeft,p.shadowCameraRight,p.shadowCameraTop,p.shadowCameraBottom,p.shadowCameraNear,p.shadowCameraFar);else{console.error("Unsupported light type for shadow");continue}l.add(p.shadowCamera);b.autoUpdateScene&&l.updateMatrixWorld()}if(p.shadowCameraVisible&&
!p.cameraHelper){p.cameraHelper=new THREE.CameraHelper(p.shadowCamera);p.shadowCamera.add(p.cameraHelper)}if(p.isVirtual&&x.originalCamera==n){r=n;o=p.shadowCamera;s=p.pointsFrustum;u=p.pointsWorld;i.set(Infinity,Infinity,Infinity);j.set(-Infinity,-Infinity,-Infinity);for(t=0;t<8;t++){v=u[t];v.copy(s[t]);THREE.ShadowMapPlugin.__projector.unprojectVector(v,r);o.matrixWorldInverse.multiplyVector3(v);if(v.x<i.x)i.x=v.x;if(v.x>j.x)j.x=v.x;if(v.y<i.y)i.y=v.y;if(v.y>j.y)j.y=v.y;if(v.z<i.z)i.z=v.z;if(v.z>
j.z)j.z=v.z}o.left=i.x;o.right=j.x;o.top=j.y;o.bottom=i.y;o.updateProjectionMatrix()}o=p.shadowMap;s=p.shadowMatrix;r=p.shadowCamera;r.position.copy(p.matrixWorld.getPosition());r.lookAt(p.target.matrixWorld.getPosition());r.updateMatrixWorld();r.matrixWorldInverse.getInverse(r.matrixWorld);if(p.cameraHelper)p.cameraHelper.visible=p.shadowCameraVisible;p.shadowCameraVisible&&p.cameraHelper.update();s.set(0.5,0,0,0.5,0,0.5,0,0.5,0,0,0.5,0.5,0,0,0,1);s.multiplySelf(r.projectionMatrix);s.multiplySelf(r.matrixWorldInverse);
if(!r._viewMatrixArray)r._viewMatrixArray=new Float32Array(16);if(!r._projectionMatrixArray)r._projectionMatrixArray=new Float32Array(16);r.matrixWorldInverse.flattenToArray(r._viewMatrixArray);r.projectionMatrix.flattenToArray(r._projectionMatrixArray);h.multiply(r.projectionMatrix,r.matrixWorldInverse);g.setFromMatrix(h);b.setRenderTarget(o);b.clear();u=l.__webglObjects;p=0;for(o=u.length;p<o;p++){t=u[p];s=t.object;t.render=false;if(s.visible&&s.castShadow&&(!(s instanceof THREE.Mesh)||!s.frustumCulled||
g.contains(s))){s._modelViewMatrix.multiply(r.matrixWorldInverse,s.matrixWorld);t.render=true}}p=0;for(o=u.length;p<o;p++){t=u[p];if(t.render){s=t.object;t=t.buffer;v=s.customDepthMaterial?s.customDepthMaterial:s instanceof THREE.SkinnedMesh?s.geometry.morphTargets.length?e:f:s.geometry.morphTargets.length?d:c;t instanceof THREE.BufferGeometry?b.renderBufferDirect(r,l.__lights,null,v,t,s):b.renderBuffer(r,l.__lights,null,v,t,s)}}u=l.__webglObjectsImmediate;p=0;for(o=u.length;p<o;p++){t=u[p];s=t.object;
if(s.visible&&s.castShadow){s._modelViewMatrix.multiply(r.matrixWorldInverse,s.matrixWorld);b.renderImmediateObject(r,l.__lights,null,c,s)}}}m=b.getClearColor();q=b.getClearAlpha();a.clearColor(m.r,m.g,m.b,q);a.enable(a.BLEND);b.shadowMapCullFrontFaces&&a.cullFace(a.BACK)}};THREE.ShadowMapPlugin.__projector=new THREE.Projector;
THREE.SpritePlugin=function(){function a(a,b){return b.z-a.z}var b,c,d,f,e,g,h,i,j,l;this.init=function(a){b=a.context;c=a;d=new Float32Array(16);f=new Uint16Array(6);a=0;d[a++]=-1;d[a++]=-1;d[a++]=0;d[a++]=0;d[a++]=1;d[a++]=-1;d[a++]=1;d[a++]=0;d[a++]=1;d[a++]=1;d[a++]=1;d[a++]=1;d[a++]=-1;d[a++]=1;d[a++]=0;d[a++]=1;a=0;f[a++]=0;f[a++]=1;f[a++]=2;f[a++]=0;f[a++]=2;f[a++]=3;e=b.createBuffer();g=b.createBuffer();b.bindBuffer(b.ARRAY_BUFFER,e);b.bufferData(b.ARRAY_BUFFER,d,b.STATIC_DRAW);b.bindBuffer(b.ELEMENT_ARRAY_BUFFER,
g);b.bufferData(b.ELEMENT_ARRAY_BUFFER,f,b.STATIC_DRAW);var a=THREE.ShaderSprite.sprite,m=b.createProgram(),q=b.createShader(b.FRAGMENT_SHADER),p=b.createShader(b.VERTEX_SHADER);b.shaderSource(q,a.fragmentShader);b.shaderSource(p,a.vertexShader);b.compileShader(q);b.compileShader(p);b.attachShader(m,q);b.attachShader(m,p);b.linkProgram(m);h=m;i={};j={};i.position=b.getAttribLocation(h,"position");i.uv=b.getAttribLocation(h,"uv");j.uvOffset=b.getUniformLocation(h,"uvOffset");j.uvScale=b.getUniformLocation(h,
"uvScale");j.rotation=b.getUniformLocation(h,"rotation");j.scale=b.getUniformLocation(h,"scale");j.alignment=b.getUniformLocation(h,"alignment");j.color=b.getUniformLocation(h,"color");j.map=b.getUniformLocation(h,"map");j.opacity=b.getUniformLocation(h,"opacity");j.useScreenCoordinates=b.getUniformLocation(h,"useScreenCoordinates");j.affectedByDistance=b.getUniformLocation(h,"affectedByDistance");j.screenPosition=b.getUniformLocation(h,"screenPosition");j.modelViewMatrix=b.getUniformLocation(h,"modelViewMatrix");
......
......@@ -62,6 +62,7 @@ THREE.ShadowMapPlugin = function ( ) {
_gl.disable( _gl.BLEND );
_gl.enable( _gl.CULL_FACE );
_gl.frontFace( _gl.CCW );
if ( _renderer.shadowMapCullFrontFaces ) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册