2.1 Shadows

Discussion area about developing with Ogre-Next (2.1, 2.2 and beyond)


Post Reply
Jay721
Halfling
Posts: 62
Joined: Mon Jan 29, 2018 8:19 am

2.1 Shadows

Post by Jay721 »

Hi. Ogre newbie here..

I'm looking at the samples, specifically ShadowMapDebugging. I noticed that when you add more spot lights, only two render at a time. How would I get it so I can have alot of shadow casting lights.

I need a lot of lights that can cast shadows, between 5 and 20 - I kinda have the feeling that so many lights would be too intensive for shadow maps? If so, would static shadow maps work smoothly?
al2950
OGRE Expert User
OGRE Expert User
Posts: 1227
Joined: Thu Dec 11, 2008 7:56 pm
Location: Bristol, UK
x 157

Re: 2.1 Shadows

Post by al2950 »

Shadow mapping is a slightly complicated subject, but I think ogre 2.1 does a great job at simplifying it whilst keeping flexible.

First off, you can certainly do what you want. However please note that shadow mapping is an expensive operation. There are effectively 2 sides to shadowing mapping
- Rendering Caster into shadow map
- Sampling shadow maps in pixel shader

Both of this will be heavily impacted by increasing the number of lights. However Ogre 2.1 is extremely fast now at rendering shadow casters (in certain circumstances it can even render a single light shadow map in 1 draw call :D). Further more if your casters are going to be static you can use static shadow maps, which will remove the need to render the shadow casters every frame.

You will however always need to sample the shadow maps for n number of lights. setting the PBS shadow quality can effect performance here, as better looking sampling techniques (softer shadows), will require more GPU grunt.

To get you started have a look at ShadowMapDebugging.compositor in Samples\Media\2.0\scripts\Compositors. Have a look a the 'compositor_node_shadow' definition. It only defines shadows for 3 lights.
1 Directional light using the PSSM technique
2 spot/point lights using the 'focused' technique.

To increase the possible number of shadow casting spot lights you need to add more entries like this

Code: Select all

shadow_map 5 atlas uv 0.0 0.714285714285714 1.0 0.285714285714286 light 3
The atlas is extremely important for what you want to do. You could use separate textures for each light shadow map, but that decreases performance, but also means you will run out of texture units on the pixel shaders, and ogre will spit out an error and probably crash! If you had 26 lights that would be 26 extra texture units, however if you use an atlas it will always just use 1 texture unit.

However this does mean you need to work out the UV space each light should use on the atlas, hence the list of slightly complicated looking numbers. Suggest you take a look at the manaul https://ogrecave.github.io/ogre/api/2.1 ... hadowNodes

and make sure you update the shadow map target eg

Code: Select all

	shadow_map_target_type directional spot
	{
	       // NOTICE THE EXTRA NUMBER 5 !
		shadow_map 3 4 5
		{
			pass render_scene
			{
			}
		}
	}
Let us know how you get on!
Jay721
Halfling
Posts: 62
Joined: Mon Jan 29, 2018 8:19 am

Re: 2.1 Shadows

Post by Jay721 »

Okay so, in theory, would having 50 statically shadow mapped lights affect performance? I’m sorry for being quite unknowledgeable.
al2950
OGRE Expert User
OGRE Expert User
Posts: 1227
Joined: Thu Dec 11, 2008 7:56 pm
Location: Bristol, UK
x 157

Re: 2.1 Shadows

Post by al2950 »

Jay721 wrote: Wed Apr 11, 2018 12:24 pm Okay so, in theory, would having 50 statically shadow mapped lights affect performance? I’m sorry for being quite unknowledgeable.
Short anser Yes

Long answer maybe, probably yes! Even though the shadow maps wont be updated you will have to sample them in the pixel shader. For each light, using low quality shadow sampling, its something like an extra 4 texture reads per pixel per light. Unfortunately sampling/reading from textures on a GPU is one of the more expensive GPU operations.

So it will have an impact, how much of an impact will depend on many other factors.... including how good your GPU is!
Post Reply