• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
george7378

Simple shadow map antialiasing?

24 posts in this topic

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!

1

Share this post


Link to post
Share on other sites

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!

0

Share this post


Link to post
Share on other sites

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!

0

Share this post


Link to post
Share on other sites

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.

0

Share this post


Link to post
Share on other sites

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

0

Share this post


Link to post
Share on other sites

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.

0

Share this post


Link to post
Share on other sites

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.

0

Share this post


Link to post
Share on other sites

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

0

Share this post


Link to post
Share on other sites

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.

0

Share this post


Link to post
Share on other sites

^ 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.

0

Share this post


Link to post
Share on other sites

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!

0

Share this post


Link to post
Share on other sites

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

0

Share this post


Link to post
Share on other sites

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.

0

Share this post


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

0

Share this post


Link to post
Share on other sites

If you use a sampler state with D3D11_FILTER_COMPARISON_MIN_MAG_MIP_LINEAR, the hardware will automatically perform 2x2 PCF when you call SampleCmp.

0

Share this post


Link to post
Share on other sites

In D3D9 the procedure is a bit, hacky...

http://aras-p.info/texts/D3D9GPUHacks.html#shadowmap

http://developer.amd.com/wordpress/media/2012/10/Advanced-DX9-Capabilities-for-ATI-Radeon-Cards_v2.pdf

 

You use CreateTexture to make a depth-stencil usage texture with a regular depth format like D24S8, and then you retrieve the surface from that texture to bind it as your depth-stencil target. After drawing to it, you can then bind the texture that you created to your pixel shader, and sample from it as usual (ensuring that linear filtering is enabled on the sampler), except that you put your depth value in the z coordinate of the tex-coords and the hardware will do the PCF for you.

0

Share this post


Link to post
Share on other sites

^ In addition to what Hodgman said. That DS surface must be followed by a proper RT, and since we don't use it in this case you might want to save memory by checking if NULL RT is supported (code chopped from my old projects):

#define D3DFMT_NULL      ((D3DFORMAT)(MAKEFOURCC('N','U','L','L')))
 
hr = d3d9->CheckDeviceFormat(adapter, deviceType, displayMode.Format, D3DUSAGE_RENDERTARGET, D3DRTYPE_SURFACE, D3DFMT_NULL);
    if(SUCCEDDED(hr))
    {
        hr = d3d9device->CreateTexture(SMAP_DIM.cx, SMAP_DIM.cy, 1, D3DUSAGE_RENDERTARGET, D3DFMT_NULL, D3DPOOL_DEFAULT, &nullTex, NULL);
        if(FAILED(hr))
...

 

First check if it is supported and then create DS texture:

// D3DFMT_D24X8 we don't need stencil for this
hr = d3d9device->CreateTexture(SMAP_DIM.cx, SMAP_DIM.cy, 1, D3DUSAGE_DEPTHSTENCIL, D3DFMT_D24X8, D3DPOOL_DEFAULT, &smapTex, NULL);
    if(FAILED(hr))
    {
        ...// handle error
    }
    hr = smapTex->GetSurfaceLevel(0, &smapSurface);
0

Share this post


Link to post
Share on other sites

Interesting, but it looks like it would probably take as much effort, if not more, to implement than the current PCF that I use. Also, I understand how the PCF works, and I can't say I get this other method!

0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0