view.stage + NOPARTICLE and matrices

Posted By: BoH_Havoc

view.stage + NOPARTICLE and matrices - 08/31/09 12:43

Here's the situation:
I have a view which renders the scene depth into a bmap, which is then used in a deferred shader to reconstruct the world position and do shadowmapping. That view is attached to the camera via
camera.stage = depthView;
set(depthView,CHILD);

So far, this is working just fine.

Now when i switch on the NOPARTICLES flag for depthView, my reconsturcted world position is wrong.

This is how it should look:


And this is how it looks with NOPARTICLES set:


I then figured out, that when NOPARTICLES is set, my matrix is rolled by 90° and tilted by 90°. So after applying a rotation matrix to my shader, it worked again. However this is just a workaround, as i cannot toggle NOPARTICLES without changing my shader again.

here's my matrix (doesn't matter if i calculate it in a material event or in a function, it's always messed up once i set NOPARTICLES for depthView):
Code:
mat_set(mtl.matrix,matWorld);
mat_multiply(mtl.matrix,matView);
mat_multiply(mtl.matrix,matProj);
mat_inverse(mtl.matrix,mtl.matrix);



And here's how i reconstruct the world position:
Code:
//compute world position
float4 vp = float4(inTex.xy * float2(2, -2) - float2(1, -1), depth, 1);
float4 v = mul(vp, matMtl);
float3 position = v.xyz/v.w;





But wait, there's more grin

If i don't attach the depth view to the camera via view.stage and CHILD, but by manually setting it's position,pan and arc to the camera, it works fine, no matter if i set NOPARTICLES or not. I would do it that way, but then my depthmap lags behind the current scene a little if i move the screen too fast and shadows get messed up.



So to sum it up:
- using stage, CHILD and NOPARTICLES = this messes up my matrix, it gets rolled and tilted by 90°
- manually attaching my depthview to the camera works just fine, but my depthmap then lags behind


Any ideas why NOPARTICLES could mess up my matrix?
Posted By: Tobias

Re: view.stage + NOPARTICLE and matrices - 09/01/09 02:31

I am pretty sure that particles are rendered after everything else, so the world matrix setup of the particles is the last one in the scene.

When you get a different matrix dependent on NOPARTICLES then your app seems to depend on the last world matrix setup, this could be a hint where to look for, like a missing initialization of the world matrix.
Posted By: BoH_Havoc

Re: view.stage + NOPARTICLE and matrices - 09/01/09 12:02

Hmmm...if this is true, then all my other shaders which depend on the worldmatrix would also not work. But they do. Everything works fine, even the depthmap is created correctly, no matter if NOPARTICLES is set or not. It's just the recreation of the worldposition by using the depthmap which won't work.

Anyway, I'll try to manually create a matWorldViewProjInverse matrix, pass that to the deferred shader and see if it works, just to be sure wink

Thanks for the tip!
© 2024 lite-C Forums