Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


Simple shadow map antialiasing?


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
24 replies to this topic

#1 george7378   Members   -  Reputation: 1252

Like
1Likes
Like

Posted 04 May 2013 - 01:19 PM

Hi everyone,

 

At the moment I've got basic shadow maps, but I'd like to try and remove the blocky pixel edges by adding some antialiasing. I'm not looking for soft shadows - I want to keep them hard, but I'd like to try and make the edges smoother.

 

Thanks!



Sponsor:

#2 Migi0027 =A=   Crossbones+   -  Reputation: 1987

Like
0Likes
Like

Posted 04 May 2013 - 01:25 PM

You are basing your tutorials from RasterTek aren't you?

 

Just asking...


Hi! Cuboid Zone
The Rule: Be polite, be professional, but have a plan to steal all their shaders!


#3 george7378   Members   -  Reputation: 1252

Like
0Likes
Like

Posted 04 May 2013 - 01:51 PM

I sometimes use Rastertek but I got my shadow mapping stuff from Riemers (XNA) and changed it to DirectX.



#4 MJP   Moderators   -  Reputation: 11590

Like
3Likes
Like

Posted 04 May 2013 - 05:25 PM

The standard technique is called Percentage Closer Filtering, or PCF for short. It basically amounts to sampling the shadow map multiple times in a small radius, performing the shadow comparison for each sample, and averaging the result. Which version of D3D are you using?



#5 george7378   Members   -  Reputation: 1252

Like
0Likes
Like

Posted 04 May 2013 - 05:33 PM

OK - I'm using D3D9 and pixel/vertex shader 2.0 - I did hear about PCF but I thought that was primarily for making shadows softer. If it reduces the visibility of texels at the edge of the shadow, then I guess I'll use that!



#6 MJP   Moderators   -  Reputation: 11590

Like
3Likes
Like

Posted 04 May 2013 - 11:48 PM

Well, it's actually a form of filtering but it will have the result of "softening" your shadows by giving them a penumbra. Filtering is definitely a good way to reduce aliasing (the jagged, stair-step artifacts that you're talking about), but it will also reduce the sharp details. If you want really sharp details without aliasing, then the only good solution is to increase the effective resolution of your shadow map (either by increasing the size of the shadow map, or reducing the amount of screen space that it covers). High shadow map resolution + filtering will give you sharp, unaliased shadows.



#7 george7378   Members   -  Reputation: 1252

Like
0Likes
Like

Posted 05 May 2013 - 03:47 AM

That's useful, thanks! Since my game takes place on the Moon, I need to try and maintain reasonably hard shadows. I'm willing to trade off a little bit of hardness for antialiasing though, so I guess PCF it is! Thanks for your help!



#8 VladR   Members   -  Reputation: 722

Like
0Likes
Like

Posted 05 May 2013 - 11:33 AM

I'm not sure what the effective screen resolution of your shadow map is, but I found that bumping the render target of the shadow map to 4096x4096 did the trick for me - I have both the hard shadows and enough detail. And I did not have to implement PCF.


VladR    My 3rd person action RPG on GreenLight:    http://steamcommunity.com/sharedfiles/filedetails/?id=92951596

 


#9 phil_t   Crossbones+   -  Reputation: 3949

Like
0Likes
Like

Posted 05 May 2013 - 06:18 PM

Shadow volumes aren't a very popular technique these days, but if you want perfect sharp-edged shadows they might be worth considering.



#10 MJP   Moderators   -  Reputation: 11590

Like
0Likes
Like

Posted 06 May 2013 - 04:56 PM

I'm not sure what the effective screen resolution of your shadow map is, but I found that bumping the render target of the shadow map to 4096x4096 did the trick for me - I have both the hard shadows and enough detail. And I did not have to implement PCF.

 

If your shadow map resolution is actually higher than your rendering resolution and you don't apply filtering, than you'll actually undersample the shadow map which can result in aliasing.



#11 VladR   Members   -  Reputation: 722

Like
0Likes
Like

Posted 08 May 2013 - 08:33 AM

I'm not sure what the effective screen resolution of your shadow map is, but I found that bumping the render target of the shadow map to 4096x4096 did the trick for me - I have both the hard shadows and enough detail. And I did not have to implement PCF.

 

If your shadow map resolution is actually higher than your rendering resolution and you don't apply filtering, than you'll actually undersample the shadow map which can result in aliasing.

Sure, but since it is impossible to miss such an artifact (when it happens), you spend about 5 more minutes tweaking the SM's projection matrix until it is just right. And you didn't have to pay the price of PCF (or other method). Time well spent :-)

 

SM is just another type of effect where you can easily spend more time tweaking it than it took you to implement it. Though, that's probably true of most effects...

 

 

On the other hand, just as phil_t mentioned, this game might be a perfect candidate for Shadow Volumes (though, it's a mess compared to SM) with its razor sharp shadows.


VladR    My 3rd person action RPG on GreenLight:    http://steamcommunity.com/sharedfiles/filedetails/?id=92951596

 


#12 Hodgman   Moderators   -  Reputation: 31143

Like
4Likes
Like

Posted 08 May 2013 - 09:50 PM

Nowadays most shadow research is directed at soft shadows, but there used to be a popular category of "edge warping" (not sure what to call them) algorithms like this one below, which give you hard shadows with a much higher effective resolution:
http://www.cs.berkeley.edu/~ravir/6160/papers/p521-sen.pdf

There was a similar one with a cute name like "fixies", or something, but I can't recall.

#13 mightypigeon   Members   -  Reputation: 512

Like
1Likes
Like

Posted 11 May 2013 - 05:34 PM

There was a similar one with a cute name like "fixies", or something, but I can't recall.

 

Smoothies?  More of a soft shadow technique though.  http://people.csail.mit.edu/ericchan/papers/smoothie/




#14 Hodgman   Moderators   -  Reputation: 31143

Like
0Likes
Like

Posted 11 May 2013 - 08:18 PM

There was a similar one with a cute name like "fixies", or something, but I can't recall.

 
Smoothies?  More of a soft shadow technique though.  http://people.csail.mit.edu/ericchan/papers/smoothie/

Yeah that's the one I was thinking of! Except I misremembered it being more about hiding aliasing artefacts rather than being about penumbra softening unsure.png



#15 LancerSolurus   Members   -  Reputation: 612

Like
0Likes
Like

Posted 12 May 2013 - 02:37 AM

This is the technique I ended up emulating

 

http://www.gamedev.net/page/resources/_/technical/graphics-programming-and-theory/soft-edged-shadows-r2193

 

Works out very well for large shadow maps and you can complement it with cascaded shadow maps. It give a nice soft penumbra for all maps and all jaggies are pretty much removed. It is a bit expensive on the sampling though, I ended up doing a 27 point tap filter which can thrash the texture cache if your not careful. In my case I limited it to a 0 to 1 sample offset which helped quite a bit.


******************************************************************************************
Youtube Channel


#16 belfegor   Crossbones+   -  Reputation: 2691

Like
0Likes
Like

Posted 12 May 2013 - 02:56 AM

^ You then need to isolate shadowmap projection in separate render pipe? I have combine it with lightning, so i cannot do it this way because it would blur things that i don't want blured.

How do you avoid same "penumbra spread" for close and far shadows? If i have not missed something from that article.



#17 george7378   Members   -  Reputation: 1252

Like
0Likes
Like

Posted 20 May 2013 - 09:08 AM

By the way, I added a PCF into my shader, and it actuall works pretty well - the edges are now soft, but not soft enough to make the boundaries look too blurred. I might tune it later on, but it looks fine for now!



#18 VladR   Members   -  Reputation: 722

Like
0Likes
Like

Posted 20 May 2013 - 10:59 AM

Great news. What filter are you using - 3x3 ?  What kind of a performance impact did you notice ?


VladR    My 3rd person action RPG on GreenLight:    http://steamcommunity.com/sharedfiles/filedetails/?id=92951596

 


#19 george7378   Members   -  Reputation: 1252

Like
0Likes
Like

Posted 20 May 2013 - 12:18 PM

It's just a 2x2 at the moment, which works fine for my needs - I haven't benchmarked it, but I couldn't see a visible drop in performance.



#20 menohack   Members   -  Reputation: 216

Like
0Likes
Like

Posted 20 May 2013 - 01:57 PM

	#define width 4
	#define height 4

		float sum = 0.0f;
		for (int x=-width/2; x < width/2; x++)
			for (int y=-height/2; y < height/2; y++)
				sum += shadow[i].SampleCmpLevelZero(shadowSampler, input.ShadowPosH[i].xy, input.ShadowPosH[i].z - depthEpsilon, int2(x,y));

		sum /= 9.0f;
		sum = saturate(sum);

 

 

This is how I am doing shadow mapping. I noticed that since I am using a fixed width the shadows get smaller as the frustum of the shadow map increases in size. Before my width and height were 7, giving 49 samples. This means that if the shadow map were so large that only one pixel indicates a shadow I would still sample 48 lit pixels in both directions, causing the shadow to shrink significantly. This led me to conclude that the sampling rate should depend on the width of the camera that generates the shadow map.

 

The i represents each of many shadow maps for multiple lights.

 

Someone referenced Sen's paper on Shadow Silhouette Maps. I have tried to implement them as well and let me tell you they are a bit difficult. I still haven't got the silhouette map building correctly. I have also implemented shadow volumes which, aside from generating the volumes in a geometry shader, is pretty straight-forward. Shadow volumes give you incredibly sharp shadow boundaries but the complexity is fundamentally higher than shadow mapping because it is geometry-bound instead of resolution-bound.

 

Since most people like fake soft shadows from shadow mapping, and since they are fast and relatively easy, I would go with them.






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS