Reduce shadow swimming for rotating camera

Started by
11 comments, last by B_old 14 years, 10 months ago
Hello, in this forum I found a good method to reduce shadow swimming in situations where the camera gets translated. You adjust the translation of the shadow transformation so that it "snaps" to the texels and could be implemented like this:

	//Reduce shadow swimming caused by camera translation
	const float halfShadowRes = float(m_shadowRes) * 0.5f;

	Vector2 texCoords(viewProj.m30 * halfShadowRes, viewProj.m31 * halfShadowRes);
	Vector2 d = (rounded(texCoords) - texCoords) / halfShadowRes;

	viewProj.m30 += d.x;
	viewProj.m31 += d.y;

This however will fail if I rotate the camera and I can't find a good solution for that. I'm not even sure that I understand why its still swimming during rotation. It would be cool to reduce the swimming for camera rotation as well.
Advertisement
"Shadow swimming", what the heck is shadow swimming ? Do you mean lag, that when you move or rotate the camera your next rendered frames is rendered with an "old" shadowmap ?

If this is the case, you got a render order problem, that is
1. render scene (with use of shadowmap)
2. render shadowmap
which will result in choppy or maybe "swimming" shadowmaps.
In this case you have to get the rendering in the right order:
1. render shadowmap
2. render scene

--
Ashaman
Nope, that is not my problem.
By "shadow swimming" I mean, that the edges of the shadow seem to moving when the camera is moving. I thought I had seen that term used before for the behavior I mean. Do you know what the common term for this is?
I think I know what you mean. Perhaps this is from low sampling of your shadowmap? What technique are you using to get your map?
Otherwise, look at this:
http://www.cg.tuwien.ac.at/research/publications/2007/Scherzer-2007-PCS/Scherzer-2007-PCS-Preprint.pdf
ROFLMAO-GG-HF-GL-LOL-TTYL-BRB-GTG
This presentation from Guerrilla has a few details on how they stop swimming in Killzone (page 37). I think I saw a more detailed description somewhere but I can't find it right now...
Shader x6 4.Shadows
4.1 Stable rendering of cascaded shadow maps by Michal Valient


Shader x7 4.1: Practical Cascaded Shadow Maps

These 2 both provide details on the stabilization methods used with shadow maps and how to achieve them. Its pretty straightforward really.
Quote:
This however will fail if I rotate the camera and I can't find a good solution for that.

Who said you have to rotate the shadow map so that it's aligned with the camera all of the time?

Quote:I'm not even sure that I understand why its still swimming during rotation.

It's because how you're hitting the samples changes. Let's say your shadow map is oriented so that some triangle edge is almost horizontal from its point of view, (so the render target stores a straight line with a few jags in it), and then another orientation has that same edge oriented so that it is at a 45d from the shadow's POV (so the render target stores a line with a stairstep with a slope of 1). Obviously, you have two entirely different patterns for hte line there, so sampling those two will look different.
clamp the shadows position/direction eg to the nearest meter

eg shadowcenter = camerapos + camera_forward*100
round_to_nearest( shadowcenter.x, 1.0 );
round_to_nearest( shadowcenter.z, 1.0 );
Thanks for the replies!

@lefthandman: This seems like more than I'm looking for...

@OrangyTang: Hm, I don't think I understand. If I made a sphere around the camera position than the shadowmap wouldn't change when I rotate the camera, but I would waste a lot of resolution for stuff I'll never see. But if I make a sphere around the current split only, it will still change when I move camera, right? I don't get it.

Quote:Original post by AndyFirth
Shader x6 4.Shadows
4.1 Stable rendering of cascaded shadow maps by Michal Valient


Shader x7 4.1: Practical Cascaded Shadow Maps

These 2 both provide details on the stabilization methods used with shadow maps and how to achieve them. Its pretty straightforward really.

I don't suppose those techniques can be viewed online? I think the stuff I am doing for camera translation is from a forums users thread to get some help with the implementation of one technique presented in one of those books.

Quote:Original post by Cypher19
Who said you have to rotate the shadow map so that it's aligned with the camera all of the time?

Thanks for the explanation. Its not really that I am rotating the shadowmaps, but when I rotate the camera the "look at" point for shadow rendering will also move. Isn't that normal?

Quote:Original post by zedz
clamp the shadows position/direction eg to the nearest meter

eg shadowcenter = camerapos + camera_forward*100
round_to_nearest( shadowcenter.x, 1.0 );
round_to_nearest( shadowcenter.z, 1.0 );

Hm, maybe something like that would work. Does anyone else do this?

[Edited by - B_old on June 20, 2009 2:59:27 AM]
Its called aliasing, if its shadowmaps.

You can reduce it a little bit with filters, try a blur filter.

This topic is closed to new replies.

Advertisement