Horde3D http://horde3d.org/forums/ |
|
Directional Shadow Casting http://horde3d.org/forums/viewtopic.php?f=2&t=368 |
Page 1 of 1 |
Author: | blue [ 11.06.2008, 14:40 ] |
Post subject: | Directional Shadow Casting |
I’d like to add support for directional shadow casting to Horde. By this I mean that shadows would be cast as if from an infinite source such as the sun, so all shadows cast would be parallel. Does anyone know how best to do this? In another post Marciano says: Quote: Shadow maps for directional lights should be relatively easy to realize. Actually you just need to replace the perspective light frustum by an orthographic one. I’m new to the Horde shadow map code and only have a very basic understanding of what’s going on. As a quick test I have a scene with a single light, casting a single shadow map (no PSSM). As a quick/naive attempt I have tried replacing the myPerspective call in calcLightMat with my own function myOrtho, which builds an Orthographic projection Matrix. I believe the orthographic Matrix created is correct, however all my shadows disappear. I’m assuming that my approach is incorrect. Anyone have any hints on what I should be doing? |
Author: | swiftcoder [ 11.06.2008, 15:35 ] |
Post subject: | Re: Directional Shadow Casting |
blue wrote: In another post Marciano says: Quote: Shadow maps for directional lights should be relatively easy to realize. Actually you just need to replace the perspective light frustum by an orthographic one. Further down that same thread (I think), Marciano also suggested that you can use a spot light instead of a directional light, if you put it a long way from the scene, with falloff disabled. This is certainly easier than setting up directional lights, so I was never quite motivated to implement them. |
Author: | blue [ 11.06.2008, 20:12 ] |
Post subject: | Re: Directional Shadow Casting |
Thanks for the help, have you successfully managed to use this effect in your own scenes? He doesn't suggest it in that thread, or in any that I've seen, but it’s a good idea none the less. I believe there are a couple of problems with this approach however: Moving the shadow casting source very far away from the scene results in many shadowing artefacts, the shadows appear to become less crisp and more jittery between frames. There currently isn’t a way I am aware of, to disable falloff for a light source. I believe I would need to change the existing shaders to support this, if I still want to use the current attenuated lighting sometimes I would need to add another context for this (is this correct?). In my current project, I would like to have a spotlight close to the scene which casts shadows as if from a directional lightsource. This is unconventional, but will enable me to use a single light source to give lighting with attenuation, but also cast parallel shadows. It is roughly how light would enter a room from the sun through a porthole. To achieve your suggested method and get the effect I want, without extra cost, you would have to do something like this I think: Code: mNodeVeryFarAway = Horde3D::addLightNode( RootNode, "Infinite Shadow", 0, "", "SHADOWMAP" ); mNodeCloseToScene = Horde3D::addLightNode( RootNode, "Close Spotlight", 0, "LIGHTING", "" ); However, this isn't supported, you can’t currently render the shadows from one light and use those shadows in a separate lighting pass. I think it would be worthwhile to add directional shadow casting and lighting support to Horde, and should be straightforward, however I haven't yet been able to get my head around the UpdateShadowMap code. |
Author: | marciano [ 14.06.2008, 14:19 ] |
Post subject: | Re: Directional Shadow Casting |
Just a quick note for the suggested solution of using a spot light that is far away. If you comment out Code: // Don't adjust near plane; this means less precision if scene is far away from viewer // but that shouldn't be too noticeable and brings better performance since the nearer // split volumes are empty minDist = _curCamera->_frustNear; in Renderer::updateShadowMap the empty space between the light and the scene should be ignored and the full shadow map resolution and depth should be used for the renderable scene. |
Author: | anchor [ 02.11.2010, 14:59 ] |
Post subject: | Re: Directional Shadow Casting |
marciano: The directional lighting will be implemented in the next SDK? I still fighting with this basic function. |
Author: | marciano [ 02.11.2010, 22:08 ] |
Post subject: | Re: Directional Shadow Casting |
Are you sure that you really need parallel shadows? In many cases perspective shadows should work as well, especially since we optimize them for the camera view frustum. You can implement a directional light source (in the lighting shader) and still use perspective shadows if the light has some distance from the world. |
Author: | anchor [ 03.11.2010, 21:36 ] |
Post subject: | Re: Directional Shadow Casting |
I will investigate your suggestion |
Author: | anchor [ 01.10.2011, 11:44 ] |
Post subject: | Re: Directional Shadow Casting |
The final answer is: I really need the directional light feature... Will You implement it in the near future? |
Author: | marciano [ 03.10.2011, 20:53 ] |
Post subject: | Re: Directional Shadow Casting |
Hi anchor, as a quick hack you can try the following: In Renderer::updateShadowMap, replace Code: Matrix4f lightProjMat = Matrix4f::PerspectiveMat( -xmax, xmax, -ymax, ymax, _curCamera->_frustNear, _curLight->_radius ); by Code: Matrix4f lightProjMat = Matrix4f::OrthoMat( -100000, 100000, -100000, 100000, _curCamera->_frustNear, _curLight->_radius ); This definitely needs more testing though before it can be added to the SDK. |
Author: | anchor [ 04.10.2011, 19:05 ] |
Post subject: | Re: Directional Shadow Casting |
Thank You very much the reply. I will try it soon |
Page 1 of 1 | All times are UTC + 1 hour |
Powered by phpBB® Forum Software © phpBB Group https://www.phpbb.com/ |