Hi everyone,
I am using the soft shadow shader code from nullsquared http://www.ogre3d.org/forums/viewtopic.php?f=11&t=39809 and I am currently working to make them work with directional lights. The problem I have is that I do not know where the shadow camera was positioned when rendering the shadow map, and I need this information to compare to the data contained in the shadow map (the depth). Anyone know how I could get this information ?
- Matt
Get directional light's shadow camera's position in shader
-
MattStevens
- Goblin
- Posts: 239
- Joined: Mon Apr 07, 2008 10:27 pm
- x 4
-
Gucman
- Orc
- Posts: 467
- Joined: Fri Dec 15, 2006 2:09 pm
- Location: Poland, Lodz
- x 1
Re: Get directional light's shadow camera's position in shader
You can get texture_viewproj_matrix in your shader. It's view and projection matrices combination of the camera used to render shadow. You can use it to calculate distance of point (in world space) form the near/far clipping plane easily. There is also an array version for this "semantic".
See: http://www.ogre3d.org/docs/manual/manual_23.html#SEC121 for possible value_codes.
See: http://www.ogre3d.org/docs/manual/manual_23.html#SEC121 for possible value_codes.
-
MattStevens
- Goblin
- Posts: 239
- Joined: Mon Apr 07, 2008 10:27 pm
- x 4
Re: Get directional light's shadow camera's position in shader
Thank you for your help.
I am using texture_viewproj_matrix already to get the shadow texture coordinate. I multiply the fragment's world position by the texture_viewproj_matrix and with the new position I do
float2 shadowUV = shadowMapPostion.xy / shadowMapPostion.w;
This gives me the UV coordinate to pick the good pixel on the shadow texture (which contains depth informations)
What I tried now, is instead of calculating the light distance from the fragment, I use shadowMapPostion.z . I expected it to work, and it did work for spotlights (same result as using the light distance). For directionnal light, I still get nothing.
I keep reading about a kind of "debug mode" for shadow textures. Anyone knows how to activate it ?
EDIT: Is it possible to have ONLY the view matrix instead of the view/projection one ? texture_viewproj_matrix gives both.
I'm wondering if the length of a position in world_view space is equal to the z value in world_view_projection space ?
- Matt
I am using texture_viewproj_matrix already to get the shadow texture coordinate. I multiply the fragment's world position by the texture_viewproj_matrix and with the new position I do
float2 shadowUV = shadowMapPostion.xy / shadowMapPostion.w;
This gives me the UV coordinate to pick the good pixel on the shadow texture (which contains depth informations)
What I tried now, is instead of calculating the light distance from the fragment, I use shadowMapPostion.z . I expected it to work, and it did work for spotlights (same result as using the light distance). For directionnal light, I still get nothing.
I keep reading about a kind of "debug mode" for shadow textures. Anyone knows how to activate it ?
EDIT: Is it possible to have ONLY the view matrix instead of the view/projection one ? texture_viewproj_matrix gives both.
I'm wondering if the length of a position in world_view space is equal to the z value in world_view_projection space ?
- Matt
-
Gucman
- Orc
- Posts: 467
- Joined: Fri Dec 15, 2006 2:09 pm
- Location: Poland, Lodz
- x 1
Re: Get directional light's shadow camera's position in shader
Hmmm. I remember I have had similar problem (with z always set to 1 for directional lights) but now I forget how it was resolved. I get my hands on code on mondey so I will be able to check if that is it and tell you something more.
-
ndoxx
- Kobold
- Posts: 31
- Joined: Tue Mar 11, 2008 4:54 pm
Re: Get directional light's shadow camera's position in shader
Hi all,
Sorry for bumping this thread again, but do you know how to get directional light's shadow camera position in viewspace at the receiver shader for depth comparison?
Thanks,
Ndoxx
Sorry for bumping this thread again, but do you know how to get directional light's shadow camera position in viewspace at the receiver shader for depth comparison?
Thanks,
Ndoxx