Getting directional lights to work with soft shadows

A place for users of OGRE to discuss ideas and experiences of utilitising OGRE in their games / demos / applications.
Post Reply
OGREHEAD
Goblin
Posts: 260
Joined: Tue Feb 02, 2010 6:25 pm
x 2

Getting directional lights to work with soft shadows

Post by OGREHEAD »

I have gotten soft shadows implemented, but only spot lights give shadows.

Can this easily be changed to work for directional lights as well?
OGREHEAD
Goblin
Posts: 260
Joined: Tue Feb 02, 2010 6:25 pm
x 2

Re: Getting directional lights to work with soft shadows

Post by OGREHEAD »

I have instead switched to depth shadow map and will try to blur the shadows I get here with parts of the soft shadow demo.

But I have a transparent material with this:

alpha_to_coverage off
colour_write on
cull_hardware clockwise
depth_check on
depth_func less_equal
depth_write on
illumination_stage
light_clip_planes off
light_scissor off
lighting on
normalise_normals off
polygon_mode solid
scene_blend alpha_blend
scene_blend_op add
shading gouraud
transparent_sorting on

And it works with simple textures / materials, so I can see other objects fine through.
But when I have depth shadowmap texture / material behind I cannot see object.
It is just dark.
I expect that I have to set something for either the transparent or depth shadowmap object.
But I can not figure out what.
Any suggestions?
OGREHEAD
Goblin
Posts: 260
Joined: Tue Feb 02, 2010 6:25 pm
x 2

Re: Getting directional lights to work with soft shadows

Post by OGREHEAD »

OK Ifixed it somewhat.

But now the problem is when I have two transparent planes overlapping / mixed in each other like this:
/
----/----
/

But I guess there is no easy way to put the correct part of each plane behind the other.
And I guess one would seldomly have two transparent planes mixed like this.

So now only problem left is blurring shadows, I will try to do that with compositor and to get more stable shadows when light is close or far away from object where shadows then disappear or get cut.

I have depth shadow map now and focused shadow camera.

Will shadows become more stable by changing to PSSM or LISPSM?
And can I still have depth shadowmap with these camera types?
bstone
OGRE Expert User
OGRE Expert User
Posts: 1920
Joined: Sun Feb 19, 2012 9:24 pm
Location: Russia
x 201

Re: Getting directional lights to work with soft shadows

Post by bstone »

PSSM and LiSPSM will only change shadow projection methods, i.e. none of them prevents you from having the depth maps.

The way the softer shadows are typically implemented is by using percentage closer filtering or PCF. Blurring shadows by depth is not something you will be able implement within the bounds of the standard Ogre's shadow processing unless you go for screen space shadows (also known as deferred shadows). In that case you could use a compositor to blur them using the depths as you intended. But then again, it's not something available out of the box and is more suited for the deferred rendering pipeline. So my recommendation would be sticking to the integrated shadows with PCF.

PSSM is relatively good for direct light shadows. You will get the most stable shadows by employing cascaded shadow maps or CSM though.
OGREHEAD
Goblin
Posts: 260
Joined: Tue Feb 02, 2010 6:25 pm
x 2

Re: Getting directional lights to work with soft shadows

Post by OGREHEAD »

Right now I get shadows from both directional, spot and point lights.
Directional light do not distort.
Point and spot lights look OK at certain positions and disappear at other positions.
Mostly when camera gets too near or to far.
The depth shadowmap code I have running have some pcf in it I think.
I will try to tweak that, I just do not think it can become as good as with a compositor, mayve I am wrong.
From what you write about the shadow camera types, I understand it as the shadow map and camera projection can be changed independently of each other.
But do shadows become more stable with a certain shadowcamera type. I would expect pssm to be the best.
I was not aiming at blurring depending on the depth.
My main goal is ideally to get stable shadows for all light types at all positions, but I have come to the conclusion that point lights are to complex and heavy to get.
So if just point lights appear like they do now at some positions I find that acceptable.
But I would like the spot lights to work better and not disappear at some positions.
I will try to experiment with pcf and compositor and then look into CSM.
My problem is mostly integrating different techniques, since I am not expert in shaders and cg programs.
Thans for the CSM tip.
bstone
OGRE Expert User
OGRE Expert User
Posts: 1920
Joined: Sun Feb 19, 2012 9:24 pm
Location: Russia
x 201

Re: Getting directional lights to work with soft shadows

Post by bstone »

I haven't looked how Ogre deals with point light shadows in detail. I would assume that they are approximated with a wide cone spot light shadow and hence they disappear once the light origin is within the camera frustrum. Otherwise the illusion of a point light would have been broken I guess. The most stable way to deal with point light shadows would be projecting shadow maps on the sides of a cube and then using a cubemap to carry out the depth tests in your shaders. But that's also the most expensive way.

When talking about stability I thought you were going after spatially stable shadows. That's where CSM could be the best pick. Otherwise PSSM is certainly not a bad option.
OGREHEAD
Goblin
Posts: 260
Joined: Tue Feb 02, 2010 6:25 pm
x 2

Re: Getting directional lights to work with soft shadows

Post by OGREHEAD »

I am not sure what you mean by spatially stable shadows.
I just want the shadows to be visible and not distort at all angle and positions.
I am not focusing on point lights right now.
You are probably correct that is it when the light is in the camera frustum.
I will try to get pssm to work with the depth shadowmap code I have then, since you say CSM is not for getting stable shadows.
bstone
OGRE Expert User
OGRE Expert User
Posts: 1920
Joined: Sun Feb 19, 2012 9:24 pm
Location: Russia
x 201

Re: Getting directional lights to work with soft shadows

Post by bstone »

By spatially stable shadows I meant shadows that don't jitter on their edges when the camera moves around, hence stable. But that seems to be different from your stability requirements as I've already guessed. Anyway, try PSSM first. Spot light shadows should be working relatively good with any setup because they are the simplest. If you have issues with them then make sure your near/far shadow clipping distance is appropriately set. Directional lights are a bit more tricky but PSSM does a good job here.
OGREHEAD
Goblin
Posts: 260
Joined: Tue Feb 02, 2010 6:25 pm
x 2

Re: Getting directional lights to work with soft shadows

Post by OGREHEAD »

OK then spatially stable shadows is what I want, I thought it was blurring shadows depending on depth or something like that.
I will try to check out csm then.
Thanks for elaboration.
bstone
OGRE Expert User
OGRE Expert User
Posts: 1920
Joined: Sun Feb 19, 2012 9:24 pm
Location: Russia
x 201

Re: Getting directional lights to work with soft shadows

Post by bstone »

OGREHEAD
Goblin
Posts: 260
Joined: Tue Feb 02, 2010 6:25 pm
x 2

Re: Getting directional lights to work with soft shadows

Post by OGREHEAD »

I just thought I were on to a solution, but then I read on the page you linked to...

Implementation limitations:
- Only works with directional lights

So csm does not work with spots or directional.

I think I will stick to the depth shadowmap shadows I have for now and try to improve, since I get directional, spot and point light shadows with this.
Only problem is point and spot distorts at certain angles and positions and that is what I want to improve if it is possible.
OGREHEAD
Goblin
Posts: 260
Joined: Tue Feb 02, 2010 6:25 pm
x 2

Re: Getting directional lights to work with soft shadows

Post by OGREHEAD »

I have tested a bit more.
And the spot light shadow disappear when inside the camera frustum. Like bstone wrote.

Now my question is, can I make the spot shadow appear when the light is in the frustum, because the shadows is elsewise OK.
Can I enable spot light shadows in frustum???
bstone
OGRE Expert User
OGRE Expert User
Posts: 1920
Joined: Sun Feb 19, 2012 9:24 pm
Location: Russia
x 201

Re: Getting directional lights to work with soft shadows

Post by bstone »

You mean the point lights. No, there's no easy way to make them cast shadows when inside the frustrum because that makes the spot light approximation impossible (think about the direction from the point light source to the frustrum - it becomes undefined, that's a simplification but close enough for understanding the problem).

Have you considered using static light maps for point light shadows?
OGREHEAD
Goblin
Posts: 260
Joined: Tue Feb 02, 2010 6:25 pm
x 2

Re: Getting directional lights to work with soft shadows

Post by OGREHEAD »

No, I mean spot light shadows disappear when spot light is in the frustum.

Point lights corrupt as well but I am now focusing on getting spots and directional shadows to work both.
Directional shadows work ok, spot works outside frustum and point I does almost not work at all, which is ok.
I want spot shadows in frustum if possible.
vincegdm
Gnoblar
Posts: 24
Joined: Tue Dec 06, 2016 12:59 pm

Re: Getting directional lights to work with soft shadows

Post by vincegdm »

Hi,

I'm sorry to wake this old topic up but I am really in need of help with exactly the same problem mentioned in this last post.
Did you find an answer to the spotlight-inside-view-frustum problem?
I opened my own thread but nobody has answered yet: http://www.ogre3d.org/forums/viewtopic. ... 2&p=535278
Post Reply