• Create Account

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.

15 replies to this topic

### #1george7378  Members

Posted 13 April 2013 - 06:12 AM

Hi everyone,

I've noticed that when I raise the size of my shadow map above 512x512, the following artifact creeps in at the bottom:

I'm not sure why - it only appears when I raise the shadow map size! Is it a simple issue?

Thanks.

### #2Jason Z  Members

Posted 13 April 2013 - 09:53 AM

Can you show the same screen shot with a smaller resolution shadow map?  Also, what is the artifact that you are describing - the shape of the shadow itself?

Jason Zink :: DirectX MVP

Direct3D 11 engine on CodePlex: Hieroglyph 3

Games: Lunar Rift

### #3george7378  Members

Posted 13 April 2013 - 10:03 AM

Hi, sorry if it wasn't visible.

The only thing casting a shadow should be the pyramid, but in the first pic there's a long rectangle added onto the shadow for some reason. Here's how it looks with a 512 shadow map:

There's no rectangle at the bottom. Also, in the first picture, the artefact is shadowing the object itself too, so for some reason it seems to think there's an object blocking the light there.

### #4phil_t  Members

Posted 13 April 2013 - 11:41 AM

Is your object hitting the edge of the shadow map? That's why we need to see what the actual shadow map looks like.

### #5george7378  Members

Posted 13 April 2013 - 12:02 PM

I thought it might have been, but this is what I get when I render the shadow map straight to the screen - they both look the same:

512:

1024:

Is there a way to save the shadow texture itself to a file? I guess that would be a better diagnostic!

### #6belfegor  Members

Posted 13 April 2013 - 12:05 PM

D3DXSaveSurfaceToFile

### #7george7378  Members

Posted 13 April 2013 - 12:42 PM

Ah, well I dumped my render surface to a png file and it came out with this at a size of 1024x1024. I guess that's the problem. I should also say that the cutoff starts at 768 pixels down - the size of my back buffer. So does that mean I can only use maps smaller than my back buffer?

### #8phil_t  Members

Posted 13 April 2013 - 12:55 PM

No, the backbuffer size shouldn't matter. Maybe check to make sure your viewport is correct when you're rendering your shadow map?

### #9Juliean  GDNet+

Posted 13 April 2013 - 12:59 PM

Its been a while, but don't you need to set a z/depth-buffer thats at least the size of your current render target? Experienced some issues like this a while ago, I swear it was something with depth buffer, but I can't really tell anymore.

### #10belfegor  Members

Posted 13 April 2013 - 01:07 PM

As said above, did you created separate depth/stencil buffer beside your RT on which you render shadow depth? And set it before render to shadow RT?

Did you set new viewport based on shadow map size/camera properties?

Edited by belfegor, 13 April 2013 - 01:08 PM.

### #11george7378  Members

Posted 14 April 2013 - 04:11 AM

Ah, that'll be the problem then! So I suppose I need to use this:

http://msdn.microsoft.com/en-gb/library/windows/desktop/bb174356(v=vs.85).aspx

Followed by this:

http://msdn.microsoft.com/en-gb/library/windows/desktop/bb174431(v=vs.85).aspx

At the moment I'm already using a surface which I acquired by using GetSurfaceLevel() on my shadow map texture - is this not the same thing? I'm using this surface as my render target, do I need to create another separate surface as my depth buffer?

### #12belfegor  Members

Posted 14 April 2013 - 04:44 AM

When you create your device, and you specify this:

presentParams.EnableAutoDepthStencil     = TRUE;


there is one depth/stencil (DS) buffer created for you behind the scene and its size is as backbuffer. Then when you set render target (RT) for shadow depth, DS size must be larger then your RT. If you had 1024x768 window with shadow 512x512 its ok, but with 1024x1024 you see its larger? Its best to create yet another DS buffer with size of your RT.

And then you render something like this:

// backup old buffers
LPDIRECT3DSURFACE9 oldBackBuffer;
LPDIRECT3DSURFACE9 oldDepthStencil;
D3DVIEWPORT9 oldViewport;
d3d9device->GetRenderTarget(0, &oldBackBuffer);
d3d9device->GetDepthStencilSurface(&oldDepthStencil);
d3d9device->GetViewport(&oldViewport);

// restore old buffers
d3d9device->SetViewport(&oldViewport);
d3d9device->SetRenderTarget(0, oldBackBuffer);
d3d9device->SetDepthStencilSurface(oldDepthStencil);
// you must call Release to avoid memry leaks as Get...Surface increment ref count
oldBackBuffer->Release();
oldDepthStencil->Release();

DrawFromPlayerCamera();


### #13george7378  Members

Posted 14 April 2013 - 05:59 AM

OK, I tried that, and yes, setting the viewport and the new depth stencil surface did work! I can now do any-size shadow maps! Thanks a lot for your help.

I also decided to look at the sample shadow map program in the SDK and the same routines are done in there too, including backing up the old buffers on the fly.

I do have one small question though, regarding D3DXSaveSurfaceToFile. I tried using it to save my ShadowDepthStencilSurface to a screenshot, but it didn't save anyhting. It works fine for the shadow surface itself, but not for the depth surface. I guess there's a good reason! Also, when I render my shadow surface to the screen, I get the usual gradient of black to white denoting depth values. However, when I save the surface to a file, I get a strange looking blue outline without any depth gradient info - why is this? I ask more out of curiosity, because it seems to be the correct thing since the shadow map works!

### #14belfegor  Members

Posted 14 April 2013 - 06:20 AM

What is the format of your RT surface? What is the file format that you use to save? With which image editor you visualise that image?

I don't think that D3DXSaveSurfaceToFile can save DS surface.

### #15george7378  Members

Posted 14 April 2013 - 07:47 AM

The format of my SM texture is D3DFMT_R32F and then I use GetSurfaceLevel(0, &shadowMapSurface) to get the surface. I saved it as a PNG using D3DXSaveSurfaceToFile, and then just uploaded the PNG file as it was. I guess because it's not an RGB format that it only has a red channel.

### #16belfegor  Members

Posted 14 April 2013 - 08:34 AM

Exactly. Also there is a 32 bits in RT red channel and on conversion to RGB png ( where is each channel 8 bits) some values are clamped (probably), and then you loose proper image representation so you can't rely on that output.

You could save as DDS witch supports that format, but then again it depends how would image editor/browser display 32 bits floating point image.

Edited by belfegor, 14 April 2013 - 08:44 AM.

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.