For Variance Shadow Mapping
I need a low-res, averaged version of my shadowMap. In DirectX9 I do this by rendering distances to a renderTexture and then generating mipmaps. The mipmap generation should yield results similar to a separable box-filter
, but be faster since there's special hardware for it. However, I'm running into two problems:
- According to PIX, each next mipmap level contains the top-left quadrant of the previous one (at full resolution), instead of the full image at half resolution.
- Framerate is absolutely obliterated when I do this: it's 50x lower than without the mipmap generation.
This is how I initialise the RenderTexture:
D3DXCreateTexture(device, 2048, 2048, 0, D3DUSAGE_RENDERTARGET, D3DFMT_G32R32F, D3DPOOL_DEFAULT, &textureID);
D3DXCreateRenderToSurface(device, 2048, 2048, D3DFMT_G32R32F, TRUE, D3DFMT_D24S8, &renderToSurface);
dxId->GetSurfaceLevel(0, &topSurface);
This is how I generate the mipmaps (this is done every frame after rendering to the shadowMap has finished):
textureID->SetAutoGenFilterType(D3DTEXF_LINEAR);
textureID->GenerateMipSubLevels();
I think setting the filterType shouldn't be done every time, but removing that doesn't make a difference.
Since this is for Variance Shadow Mapping I really need colour format D3DFMT_G32R32F
, but I've also tried D3DFMT_A8R8G8B8
to see whether that made a difference, and it didn't: mipmap is still broken in the same way and framerate is still 1fps.
I've also tried using D3DUSAGE_AUTOGENMIPMAP
instead, but that didn't generate a mipmap at all according to PIX. That looks like this (and then I don't call GenerateMipSubLevels
at all anymore):
D3DXCreateTexture(device, 2048, 2048, 0, D3DUSAGE_RENDERTARGET | D3DUSAGE_AUTOGENMIPMAP, D3DFMT_G32R32F, D3DPOOL_DEFAULT, &textureID);
Note that this is on Windows 10 with a Geforce 550 GPU. I've already tried reinstalling my videocard drivers entirely, just in case, but that didn't make a difference.
How can I get a proper mipmap for a renderTexture in DirectX9, and how can I get proper framerate while doing so?