# Reduce shadow swimming for rotating camera

This topic is 3318 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

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

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.

##### Share on other sites
"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)
which will result in choppy or maybe "swimming" shadowmaps.
In this case you have to get the rendering in the right order:
2. render scene

--
Ashaman

##### Share on other sites
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?

##### Share on other sites
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

##### Share on other sites
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...

##### Share on other sites

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

##### Share on other sites
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.

##### Share on other sites
clamp the shadows position/direction eg to the nearest meter

eg shadowcenter = camerapos + camera_forward*100

##### Share on other sites
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:

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 Cypher19Who 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 zedzclamp the shadows position/direction eg to the nearest metereg shadowcenter = camerapos + camera_forward*100round_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]

##### Share on other sites
Its called aliasing, if its shadowmaps.

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

1. 1
2. 2
Rutin
24
3. 3
4. 4
JoeJ
16
5. 5

• 14
• 29
• 11
• 11
• 9
• ### Forum Statistics

• Total Topics
631773
• Total Posts
3002271
×