Obtaining shadow matrixes

Discussion area about developing or extending OGRE, adding plugins for it or building applications on it. No newbie questions please, use the Help forum for that.
User avatar
sparkprime
Ogre Magi
Posts: 1137
Joined: Mon May 07, 2007 3:43 am
Location: Ossining, New York
x 13

Obtaining shadow matrixes

Post by sparkprime »

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)
bstone
OGRE Expert User
OGRE Expert User
Posts: 1920
Joined: Sun Feb 19, 2012 9:24 pm
Location: Russia
x 201

Re: Obtaining shadow matrixes

Post by bstone »

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().
User avatar
sparkprime
Ogre Magi
Posts: 1137
Joined: Mon May 07, 2007 3:43 am
Location: Ossining, New York
x 13

Re: Obtaining shadow matrixes

Post by sparkprime »

But where do I get the shadow camera from? Do I just take any old (or new) camera and give it to the CameraSetup?
User avatar
lunkhound
Gremlin
Posts: 169
Joined: Sun Apr 29, 2012 1:03 am
Location: Santa Monica, California
x 19

Re: Obtaining shadow matrixes

Post by lunkhound »

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.
User avatar
sparkprime
Ogre Magi
Posts: 1137
Joined: Mon May 07, 2007 3:43 am
Location: Ossining, New York
x 13

Re: Obtaining shadow matrixes

Post by sparkprime »

OK that sounds like a close match for what I want, I'll give it a go. Thanks
User avatar
sparkprime
Ogre Magi
Posts: 1137
Joined: Mon May 07, 2007 3:43 am
Location: Ossining, New York
x 13

Re: Obtaining shadow matrixes

Post by sparkprime »

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...
Last edited by sparkprime on Sat Sep 15, 2012 10:21 pm, edited 1 time in total.
User avatar
sparkprime
Ogre Magi
Posts: 1137
Joined: Mon May 07, 2007 3:43 am
Location: Ossining, New York
x 13

Re: Obtaining shadow matrixes

Post by sparkprime »

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.
User avatar
sparkprime
Ogre Magi
Posts: 1137
Joined: Mon May 07, 2007 3:43 am
Location: Ossining, New York
x 13

Re: Obtaining shadow matrixes

Post by sparkprime »

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?
User avatar
sparkprime
Ogre Magi
Posts: 1137
Joined: Mon May 07, 2007 3:43 am
Location: Ossining, New York
x 13

Re: Obtaining shadow matrixes

Post by sparkprime »

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 :)
User avatar
syedhs
Silver Sponsor
Silver Sponsor
Posts: 2703
Joined: Mon Aug 29, 2005 3:24 pm
Location: Kuala Lumpur, Malaysia
x 51

Re: Obtaining shadow matrixes

Post by syedhs »

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
User avatar
sparkprime
Ogre Magi
Posts: 1137
Joined: Mon May 07, 2007 3:43 am
Location: Ossining, New York
x 13

Re: Obtaining shadow matrixes

Post by sparkprime »

The dialogue with the duck took a couple of hours though :)