Followers 0

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

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

0

##### Share on other sites

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

0

##### 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 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 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 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 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 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 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

0

##### Share on other sites

This is the technique I ended up emulating

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

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

0

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

Hmm, interesting - I'm using DX9 though, would I define this in the shader?

0

##### Share on other sites

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

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

## Create an account

Register a new account