提交 4df44908 编写于 作者: A alteredq

Fixed particles sorting issues.

Issue 1: when having multiple ParticleSystems, starting since second one particles got sorted according to wrong matrix (it was cumulating all transforms).
Issue 2: particle sorting was using camera transform from the previous frame.

This commit is scary, lot of potential for something getting messed up in a subtle way.
上级 c1ce0dbb
因为 它太大了无法显示 source diff 。你可以改为 查看blob
......@@ -407,7 +407,7 @@ s.target.position.copy(o.target.position);s.lookAt(s.target);s.shadowCameraVisib
format:THREE.RGBAFormat}),k.shadowMapSize=new THREE.Vector2(k.shadowMapWidth,k.shadowMapHeight),k.shadowMatrix=new THREE.Matrix4;if(!k.shadowCamera){if(k instanceof THREE.SpotLight)k.shadowCamera=new THREE.PerspectiveCamera(k.shadowCameraFov,k.shadowMapWidth/k.shadowMapHeight,k.shadowCameraNear,k.shadowCameraFar);else if(k instanceof THREE.DirectionalLight)k.shadowCamera=new THREE.OrthographicCamera(k.shadowCameraLeft,k.shadowCameraRight,k.shadowCameraTop,k.shadowCameraBottom,k.shadowCameraNear,k.shadowCameraFar);
else{console.error("Unsupported light type for shadow");continue}i.add(k.shadowCamera);b.autoUpdateScene&&i.updateMatrixWorld()}if(k.shadowCameraVisible&&!k.cameraHelper)k.cameraHelper=new THREE.CameraHelper(k.shadowCamera),k.shadowCamera.add(k.cameraHelper);if(k.isVirtual&&v.originalCamera==l){r=l;n=k.shadowCamera;m=k.pointsFrustum;s=k.pointsWorld;e.set(Infinity,Infinity,Infinity);h.set(-Infinity,-Infinity,-Infinity);for(o=0;8>o;o++){p=s[o];p.copy(m[o]);THREE.ShadowMapPlugin.__projector.unprojectVector(p,
r);n.matrixWorldInverse.multiplyVector3(p);if(p.x<e.x)e.x=p.x;if(p.x>h.x)h.x=p.x;if(p.y<e.y)e.y=p.y;if(p.y>h.y)h.y=p.y;if(p.z<e.z)e.z=p.z;if(p.z>h.z)h.z=p.z}n.left=e.x;n.right=h.x;n.top=h.y;n.bottom=e.y;n.updateProjectionMatrix()}n=k.shadowMap;m=k.shadowMatrix;r=k.shadowCamera;r.position.copy(k.matrixWorld.getPosition());r.lookAt(k.target.matrixWorld.getPosition());r.updateMatrixWorld();r.matrixWorldInverse.getInverse(r.matrixWorld);if(k.cameraHelper)k.cameraHelper.lines.visible=k.shadowCameraVisible;
k.shadowCameraVisible&&k.cameraHelper.update(k.shadowCamera);m.set(0.5,0,0,0.5,0,0.5,0,0.5,0,0,0.5,0.5,0,0,0,1);m.multiplySelf(r.projectionMatrix);m.multiplySelf(r.matrixWorldInverse);if(!r._viewMatrixArray)r._viewMatrixArray=new Float32Array(16);r.matrixWorldInverse.flattenToArray(r._viewMatrixArray);if(!r._projectionMatrixArray)r._projectionMatrixArray=new Float32Array(16);r.projectionMatrix.flattenToArray(r._projectionMatrixArray);g.multiply(r.projectionMatrix,r.matrixWorldInverse);f.setFromMatrix(g);
k.shadowCameraVisible&&k.cameraHelper.update(k.shadowCamera);m.set(0.5,0,0,0.5,0,0.5,0,0.5,0,0,0.5,0.5,0,0,0,1);m.multiplySelf(r.projectionMatrix);m.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);g.multiply(r.projectionMatrix,r.matrixWorldInverse);f.setFromMatrix(g);
b.setRenderTarget(n);b.clear();s=i.__webglObjects;for(k=0,n=s.length;k<n;k++)if(o=s[k],m=o.object,o.render=!1,m.visible&&m.castShadow&&(!(m instanceof THREE.Mesh)||!m.frustumCulled||f.contains(m)))m.matrixWorld.flattenToArray(m._objectMatrixArray),m._modelViewMatrix.multiplyToArray(r.matrixWorldInverse,m.matrixWorld,m._modelViewMatrixArray),o.render=!0;for(k=0,n=s.length;k<n;k++)if(o=s[k],o.render)m=o.object,o=o.buffer,b.setObjectFaces(m),p=m.customDepthMaterial?m.customDepthMaterial:m.geometry.morphTargets.length?
d:c,o instanceof THREE.BufferGeometry?b.renderBufferDirect(r,i.__lights,null,p,o,m):b.renderBuffer(r,i.__lights,null,p,o,m);s=i.__webglObjectsImmediate;for(k=0,n=s.length;k<n;k++)o=s[k],m=o.object,m.visible&&m.castShadow&&(m.matrixAutoUpdate&&m.matrixWorld.flattenToArray(m._objectMatrixArray),m._modelViewMatrix.multiplyToArray(r.matrixWorldInverse,m.matrixWorld,m._modelViewMatrixArray),b.renderImmediateObject(r,i.__lights,null,c,m))}j=b.getClearColor();q=b.getClearAlpha();a.clearColor(j.r,j.g,j.b,
q);a.enable(a.BLEND);b.shadowMapCullFrontFaces&&a.cullFace(a.BACK)}};THREE.ShadowMapPlugin.__projector=new THREE.Projector;
......@@ -419,7 +419,7 @@ l.projectionMatrix=b.getUniformLocation(h,"projectionMatrix");j=!1};this.render=
n)/n,(t-u.position.y)/t,Math.max(0,Math.min(1,u.position.z)))):(b.uniform1i(p.useScreenCoordinates,0),b.uniform1i(p.affectedByDistance,u.affectedByDistance?1:0),b.uniformMatrix4fv(p.modelViewMatrix,!1,u._modelViewMatrixArray)),f=u.map.image.width/(u.scaleByViewport?r:1),w[0]=f*s*u.scale.x,w[1]=f*u.scale.y,b.uniform2f(p.uvScale,u.uvScale.x,u.uvScale.y),b.uniform2f(p.uvOffset,u.uvOffset.x,u.uvOffset.y),b.uniform2f(p.alignment,u.alignment.x,u.alignment.y),b.uniform1f(p.opacity,u.opacity),b.uniform3f(p.color,
u.color.r,u.color.g,u.color.b),b.uniform1f(p.rotation,u.rotation),b.uniform2fv(p.scale,w),u.mergeWith3D&&!v?(b.enable(b.DEPTH_TEST),v=!0):!u.mergeWith3D&&v&&(b.disable(b.DEPTH_TEST),v=!1),c.setBlending(u.blending),c.setTexture(u.map,0),b.drawElements(b.TRIANGLES,6,b.UNSIGNED_SHORT,0));b.enable(b.CULL_FACE);b.enable(b.DEPTH_TEST);b.depthMask(!0)}}};
THREE.DepthPassPlugin=function(){this.enabled=!1;this.renderTarget=null;var a,b,c,d,f=new THREE.Frustum,g=new THREE.Matrix4;this.init=function(e){a=e.context;b=e;var e=THREE.ShaderLib.depthRGBA,f=THREE.UniformsUtils.clone(e.uniforms);c=new THREE.ShaderMaterial({fragmentShader:e.fragmentShader,vertexShader:e.vertexShader,uniforms:f});d=new THREE.ShaderMaterial({fragmentShader:e.fragmentShader,vertexShader:e.vertexShader,uniforms:f,morphTargets:!0});c._shadowPass=!0;d._shadowPass=!0};this.render=function(a,
b){this.enabled&&this.update(a,b)};this.update=function(e,h){var i,l,j,q,k,n;a.clearColor(1,1,1,1);a.disable(a.BLEND);b.setDepthTest(!0);b.autoUpdateScene&&e.updateMatrixWorld();h.matrixWorldInverse.getInverse(h.matrixWorld);if(!h._viewMatrixArray)h._viewMatrixArray=new Float32Array(16);h.matrixWorldInverse.flattenToArray(h._viewMatrixArray);if(!h._projectionMatrixArray)h._projectionMatrixArray=new Float32Array(16);h.projectionMatrix.flattenToArray(h._projectionMatrixArray);g.multiply(h.projectionMatrix,
b){this.enabled&&this.update(a,b)};this.update=function(e,h){var i,l,j,q,k,n;a.clearColor(1,1,1,1);a.disable(a.BLEND);b.setDepthTest(!0);b.autoUpdateScene&&e.updateMatrixWorld();if(!h._viewMatrixArray)h._viewMatrixArray=new Float32Array(16);if(!h._projectionMatrixArray)h._projectionMatrixArray=new Float32Array(16);h.matrixWorldInverse.getInverse(h.matrixWorld);h.matrixWorldInverse.flattenToArray(h._viewMatrixArray);h.projectionMatrix.flattenToArray(h._projectionMatrixArray);g.multiply(h.projectionMatrix,
h.matrixWorldInverse);f.setFromMatrix(g);b.setRenderTarget(this.renderTarget);b.clear();n=e.__webglObjects;for(i=0,l=n.length;i<l;i++)if(j=n[i],k=j.object,j.render=!1,k.visible&&(!(k instanceof THREE.Mesh)||!k.frustumCulled||f.contains(k)))k.matrixWorld.flattenToArray(k._objectMatrixArray),k._modelViewMatrix.multiplyToArray(h.matrixWorldInverse,k.matrixWorld,k._modelViewMatrixArray),j.render=!0;for(i=0,l=n.length;i<l;i++)if(j=n[i],j.render)k=j.object,j=j.buffer,b.setObjectFaces(k),q=k.customDepthMaterial?
k.customDepthMaterial:k.geometry.morphTargets.length?d:c,j instanceof THREE.BufferGeometry?b.renderBufferDirect(h,e.__lights,null,q,j,k):b.renderBuffer(h,e.__lights,null,q,j,k);n=e.__webglObjectsImmediate;for(i=0,l=n.length;i<l;i++)j=n[i],k=j.object,k.visible&&k.castShadow&&(k.matrixAutoUpdate&&k.matrixWorld.flattenToArray(k._objectMatrixArray),k._modelViewMatrix.multiplyToArray(h.matrixWorldInverse,k.matrixWorld,k._modelViewMatrixArray),b.renderImmediateObject(h,e.__lights,null,c,k));i=b.getClearColor();
l=b.getClearAlpha();a.clearColor(i.r,i.g,i.b,l);a.enable(a.BLEND)}};
......
此差异已折叠。
......@@ -55,25 +55,29 @@ THREE.DepthPassPlugin = function ( ) {
_renderer.setDepthTest( true );
// render depth map
// update scene
if ( _renderer.autoUpdateScene ) scene.updateMatrixWorld();
camera.matrixWorldInverse.getInverse( camera.matrixWorld );
// update camera matrices and frustum
if ( ! camera._viewMatrixArray ) camera._viewMatrixArray = new Float32Array( 16 );
camera.matrixWorldInverse.flattenToArray( camera._viewMatrixArray );
if ( ! camera._projectionMatrixArray ) camera._projectionMatrixArray = new Float32Array( 16 );
camera.matrixWorldInverse.getInverse( camera.matrixWorld );
camera.matrixWorldInverse.flattenToArray( camera._viewMatrixArray );
camera.projectionMatrix.flattenToArray( camera._projectionMatrixArray );
_projScreenMatrix.multiply( camera.projectionMatrix, camera.matrixWorldInverse );
_frustum.setFromMatrix( _projScreenMatrix );
// render depth map
_renderer.setRenderTarget( this.renderTarget );
_renderer.clear();
// set matrices & frustum culling
// set object matrices & frustum culling
renderList = scene.__webglObjects;
......
......@@ -191,21 +191,23 @@ THREE.ShadowMapPlugin = function ( ) {
shadowMatrix.multiplySelf( shadowCamera.projectionMatrix );
shadowMatrix.multiplySelf( shadowCamera.matrixWorldInverse );
// render shadow map
// update camera matrices and frustum
if ( ! shadowCamera._viewMatrixArray ) shadowCamera._viewMatrixArray = new Float32Array( 16 );
shadowCamera.matrixWorldInverse.flattenToArray( shadowCamera._viewMatrixArray );
if ( ! shadowCamera._projectionMatrixArray ) shadowCamera._projectionMatrixArray = new Float32Array( 16 );
shadowCamera.matrixWorldInverse.flattenToArray( shadowCamera._viewMatrixArray );
shadowCamera.projectionMatrix.flattenToArray( shadowCamera._projectionMatrixArray );
_projScreenMatrix.multiply( shadowCamera.projectionMatrix, shadowCamera.matrixWorldInverse );
_frustum.setFromMatrix( _projScreenMatrix );
// render shadow map
_renderer.setRenderTarget( shadowMap );
_renderer.clear();
// set matrices & frustum culling
// set object matrices & frustum culling
renderList = scene.__webglObjects;
......
......@@ -140,6 +140,7 @@ THREE.WebGLRenderer = function ( parameters ) {
// camera matrices cache
_projScreenMatrix = new THREE.Matrix4(),
_projScreenMatrixPS = new THREE.Matrix4(),
_vector3 = new THREE.Vector4(),
......@@ -847,14 +848,15 @@ THREE.WebGLRenderer = function ( parameters ) {
if ( object.sortParticles ) {
_projScreenMatrix.multiplySelf( object.matrixWorld );
_projScreenMatrixPS.copy( _projScreenMatrix );
_projScreenMatrixPS.multiplySelf( object.matrixWorld );
for ( v = 0; v < vl; v ++ ) {
vertex = vertices[ v ].position;
_vector3.copy( vertex );
_projScreenMatrix.multiplyVector3( _vector3 );
_projScreenMatrixPS.multiplyVector3( _vector3 );
sortArray[ v ] = [ _vector3.z, v ];
......@@ -3274,7 +3276,7 @@ THREE.WebGLRenderer = function ( parameters ) {
_currentMaterialId = -1;
if ( this.autoUpdateObjects ) this.initWebGLObjects( scene );
// update scene graph
if ( camera.parent === undefined ) {
......@@ -3285,26 +3287,34 @@ THREE.WebGLRenderer = function ( parameters ) {
if ( this.autoUpdateScene ) scene.updateMatrixWorld();
// custom render plugins (pre pass)
renderPlugins( this.renderPluginsPre, scene, camera );
// update camera matrices and frustum
_this.info.render.calls = 0;
_this.info.render.vertices = 0;
_this.info.render.faces = 0;
_this.info.render.points = 0;
if ( ! camera._viewMatrixArray ) camera._viewMatrixArray = new Float32Array( 16 );
if ( ! camera._projectionMatrixArray ) camera._projectionMatrixArray = new Float32Array( 16 );
camera.matrixWorldInverse.getInverse( camera.matrixWorld );
if ( ! camera._viewMatrixArray ) camera._viewMatrixArray = new Float32Array( 16 );
camera.matrixWorldInverse.flattenToArray( camera._viewMatrixArray );
if ( ! camera._projectionMatrixArray ) camera._projectionMatrixArray = new Float32Array( 16 );
camera.projectionMatrix.flattenToArray( camera._projectionMatrixArray );
_projScreenMatrix.multiply( camera.projectionMatrix, camera.matrixWorldInverse );
_frustum.setFromMatrix( _projScreenMatrix );
// update WebGL objects
if ( this.autoUpdateObjects ) this.initWebGLObjects( scene );
// custom render plugins (pre pass)
renderPlugins( this.renderPluginsPre, scene, camera );
//
_this.info.render.calls = 0;
_this.info.render.vertices = 0;
_this.info.render.faces = 0;
_this.info.render.points = 0;
this.setRenderTarget( renderTarget );
if ( this.autoClear || forceClear ) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册