Simple shadow map antialiasing?

Started by
23 comments, last by george7378 10 years, 11 months ago

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.

Advertisement

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

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.

^ 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);

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!

This topic is closed to new replies.

Advertisement