Horde3D

Next-Generation Graphics Engine
It is currently 29.03.2024, 10:53

All times are UTC + 1 hour




Post new topic Reply to topic  [ 10 posts ] 
Author Message
PostPosted: 11.06.2008, 14:40 
Offline

Joined: 02.01.2008, 18:34
Posts: 14
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?


Top
 Profile  
Reply with quote  
PostPosted: 11.06.2008, 15:35 
Offline

Joined: 22.11.2007, 17:05
Posts: 707
Location: Boston, MA
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.

_________________
Tristam MacDonald - [swiftcoding]


Top
 Profile  
Reply with quote  
PostPosted: 11.06.2008, 20:12 
Offline

Joined: 02.01.2008, 18:34
Posts: 14
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.


Top
 Profile  
Reply with quote  
PostPosted: 14.06.2008, 14:19 
Offline
Engine Developer

Joined: 10.09.2006, 15:52
Posts: 1217
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.


Top
 Profile  
Reply with quote  
PostPosted: 02.11.2010, 14:59 
Offline

Joined: 29.10.2010, 14:28
Posts: 46
Location: Hungary
marciano: The directional lighting will be implemented in the next SDK?
I still fighting with this basic function. :? :cry:


Top
 Profile  
Reply with quote  
PostPosted: 02.11.2010, 22:08 
Offline
Engine Developer

Joined: 10.09.2006, 15:52
Posts: 1217
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.


Top
 Profile  
Reply with quote  
PostPosted: 03.11.2010, 21:36 
Offline

Joined: 29.10.2010, 14:28
Posts: 46
Location: Hungary
I will investigate your suggestion :)


Top
 Profile  
Reply with quote  
PostPosted: 01.10.2011, 11:44 
Offline

Joined: 29.10.2010, 14:28
Posts: 46
Location: Hungary
The final answer is: I really need the directional light feature...
Will You implement it in the near future?


Top
 Profile  
Reply with quote  
PostPosted: 03.10.2011, 20:53 
Offline
Engine Developer

Joined: 10.09.2006, 15:52
Posts: 1217
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.


Top
 Profile  
Reply with quote  
PostPosted: 04.10.2011, 19:05 
Offline

Joined: 29.10.2010, 14:28
Posts: 46
Location: Hungary
Thank You very much the reply. I will try it soon :)


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 10 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 58 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group