Is there a way to get on the CPU the shadow view/projection matrixes for a particular light in the current frame? I looked but I couldn't find...
(Obviously one can get it in the shader by binding an auto param, I'm talking about getting it on the CPU)
Obtaining shadow matrixes
-
- Ogre Magi
- Posts: 1137
- Joined: Mon May 07, 2007 3:43 am
- Location: Ossining, New York
- x 13
-
- OGRE Expert User
- Posts: 1920
- Joined: Sun Feb 19, 2012 9:24 pm
- Location: Russia
- x 201
Re: Obtaining shadow matrixes
You can get the default scene-wide shadow camera setup information with Ogre::SceneManager::getShadowCameraSetup() or if your lights use custom shadow projection - Ogre::Light::getCustomShadowCameraSetup(). Once you have those you can go for Ogre::Camera::getView/ProjectionMatrix().
-
- Ogre Magi
- Posts: 1137
- Joined: Mon May 07, 2007 3:43 am
- Location: Ossining, New York
- x 13
Re: Obtaining shadow matrixes
But where do I get the shadow camera from? Do I just take any old (or new) camera and give it to the CameraSetup?
-
- Gremlin
- Posts: 169
- Joined: Sun Apr 29, 2012 1:03 am
- Location: Santa Monica, California
- x 19
Re: Obtaining shadow matrixes
If you register a listener with the SceneManager and then provide a function for shadowTextureCasterPreViewProj(...), it will pass to you the light and the shadow camera (and an iteration index for when there are multiple shadow cameras per light). From the camera you can query (or even change if you like) the view and projection matrices.
-
- Ogre Magi
- Posts: 1137
- Joined: Mon May 07, 2007 3:43 am
- Location: Ossining, New York
- x 13
Re: Obtaining shadow matrixes
OK that sounds like a close match for what I want, I'll give it a go. Thanks
-
- Ogre Magi
- Posts: 1137
- Joined: Mon May 07, 2007 3:43 am
- Location: Ossining, New York
- x 13
Re: Obtaining shadow matrixes
I can't get this working, the shadow matrixes appear to be wrong. Is it possible they are not actually initialised at this point?
edit: checked the code, they should definitely be initialised...
edit: checked the code, they should definitely be initialised...
Last edited by sparkprime on Sat Sep 15, 2012 10:21 pm, edited 1 time in total.
-
- Ogre Magi
- Posts: 1137
- Joined: Mon May 07, 2007 3:43 am
- Location: Ossining, New York
- x 13
Re: Obtaining shadow matrixes
They are moving as the light moves and as the camera moves, but when I use them to compute shadows, the shadows are all in the wrong places. So maybe it's some col/row major mismatch, or maybe something is going wrong, or maybe it's the matrixes that are wrong. I am not actually sure yet.
-
- Ogre Magi
- Posts: 1137
- Joined: Mon May 07, 2007 3:43 am
- Location: Ossining, New York
- x 13
Re: Obtaining shadow matrixes
I'm not sure on what the difference is between
virtual void shadowTextureCasterPreViewProj (Light *light, Camera *camera, size_t iteration)
This event occurs just before the view & projection matrices are set for rendering into a shadow texture.
virtual void shadowTextureReceiverPreViewProj (Light *light, Frustum *frustum)
This event occurs just before the view & projection matrices are set for re-rendering a shadow receiver.
The latter is never called for me, and surely the matrixes are the same in both cases?
virtual void shadowTextureCasterPreViewProj (Light *light, Camera *camera, size_t iteration)
This event occurs just before the view & projection matrices are set for rendering into a shadow texture.
virtual void shadowTextureReceiverPreViewProj (Light *light, Frustum *frustum)
This event occurs just before the view & projection matrices are set for re-rendering a shadow receiver.
The latter is never called for me, and surely the matrixes are the same in both cases?
-
- Ogre Magi
- Posts: 1137
- Joined: Mon May 07, 2007 3:43 am
- Location: Ossining, New York
- x 13
Re: Obtaining shadow matrixes
Ah of course, these matrix don't include a mapping to uv space, there has to be an extra transform to map (-1,1) to (0,1) for x and y values before you can index the shadowmap with them. Works now 

-
- Silver Sponsor
- Posts: 2703
- Joined: Mon Aug 29, 2005 3:24 pm
- Location: Kuala Lumpur, Malaysia
- x 51
Re: Obtaining shadow matrixes
A willow deeply scarred, somebody's broken heart
And a washed-out dream
They follow the pattern of the wind, ya' see
Cause they got no place to be
That's why I'm starting with me
And a washed-out dream
They follow the pattern of the wind, ya' see
Cause they got no place to be
That's why I'm starting with me
-
- Ogre Magi
- Posts: 1137
- Joined: Mon May 07, 2007 3:43 am
- Location: Ossining, New York
- x 13
Re: Obtaining shadow matrixes
The dialogue with the duck took a couple of hours though 
