Getting the matView and matProj of a view

Posted By: Excessus

Getting the matView and matProj of a view - 10/21/06 21:45

I'd like to see a function for getting the matView and matProj of a view.

I need this for a shadow mapping shader I'm writing. To project the depth map onto the scene, it uses a matrix that is the product of the models world matrix, the lights matView and matProj matrices (a camera is placed at the light position) and a TexAdjust matrix. The problem is that there is no way to get the matView and matProj of the light in the ENABLE_RENDER (where the models matWorld is available).

I tried saving matView and matProj in the ENABLE_VIEW of the DepthRender material but it doesn't work because I also use another material event (ENABLE_TREE, for switching the material depending on the view) and there is no way to determine what triggered the event (unknown parameter EVENT_TREE).
Posted By: jcl

Re: Getting the matView and matProj of a view - 10/23/06 08:47

I think I don't understand your request. Can you explain which problem you have with the current implementation of matView and matProj?
Posted By: Excessus

Re: Getting the matView and matProj of a view - 10/23/06 09:04

I'm writing a shadow mapping shader, it works like this:

1) Render the depth of the scene, as seen from the light's position to a 32-bit floating point red texture. (Done, works)
2) Render the scene from the camera's point of view and project the depthmap onto the scene (like normal projective texturing). Then I compare the depth stored in the depth texture to the distance from the pixel to the light. If the distance to the light is greater than the value stored in the depthmap, the pixel is shadowed (since this point isn't visible from the light's point of view).

To project the depthmap, a matrix is used to calculate UV coordinates on the depthmap for every vertex. This matrix is the product of the matWorld of the mesh, the matView and matProj of the lightsource and a scale and bias matrix(I can calculate the last one).

What I need is the matView and matProj of viewA (the view placed at the light) while rendering the scene from viewB (the normal camera).

As stated in my first post, I couldn't find a way to somehow store the matrix when the light/depth view is rendered.
Posted By: jcl

Re: Getting the matView and matProj of a view - 10/23/06 09:16

Yes, I understand that so far, but matView and matProj are both among the predefined matrices (manual -> Engine functions -> matrix calculations). So you can just copy them to your material matrix (matMtl), or to matEffect, and use it in subsequent shaders.

For deciding whether an event is triggered by ENABLE_TREE or ENABLE_VIEW you could use the my pointer, which should be zero in an ENABLE_VIEW event. Or even easier, use a dummy material that only has a view event that copies the matrices.
Posted By: Alexander Esslinger

Re: Getting the matView and matProj of a view - 10/24/06 20:54

When using a material event for storing the view- and project-matrix, they may lag one frame behind.

Example:
material mat1 {..} // uses stored matrices
material mat2 {..} // stores matrices of view2
view view1 {..} // shows an entity with mat1
view view2 {..} // shows an entity with mat2
view view3 {..} // rendered last, for not allowing you to say "use matView/matProj in mat1"

If view2 is rendered after view1, the matrices used are from the previous frame.

None the less, functions like get_viewMatrix(view*), get_projMatrix(view*) or get_worldMatrix(entity*) would make sense. I guess the matrices are "precalculated" and stored inside the objects anyway.
© 2024 lite-C Forums