• 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

Shadow map size-based artifact

15 posts in this topic

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:

 

[attachment=14836:artifact1.jpg]

 

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

 

Thanks.

0

Share this post


Link to post
Share on other sites

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?

0

Share this post


Link to post
Share on other sites

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:

 

[attachment=14838:arti2.jpg]

 

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.

0

Share this post


Link to post
Share on other sites

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

0

Share this post


Link to post
Share on other sites

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:

 

[attachment=14839:512sm.jpg]

 

1024:

 

[attachment=14840:1024sm.jpg]

 

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

0

Share this post


Link to post
Share on other sites

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?

 

[attachment=14841:test.png]

0

Share this post


Link to post
Share on other sites

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

1

Share this post


Link to post
Share on other sites

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.

0

Share this post


Link to post
Share on other sites

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
0

Share this post


Link to post
Share on other sites
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?
0

Share this post


Link to post
Share on other sites

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);
 
    // set shadow buffers
    D3DVIEWPORT9 shadowViewport;
    shadowViewport.X      = 0;
    shadowViewport.Y      = 0;
    shadowViewport.Width  = SHADOW_RT_WIDTH;
    shadowViewport.Height = SHADOW_RT_HEIGHT;
    shadowViewport.MinZ   = 0;
    shadowViewport.MaxZ   = 1;
    d3d9device->SetViewport(&shadowViewport);
    d3d9device->SetRenderTarget(0, shadowSurface);
    d3d9device->SetDepthStencilSurface(shadowDS);
 
   DrawFromShadowView();
 
  // 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();
1

Share this post


Link to post
Share on other sites

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!

 

[url=http://s302.photobucket.com/user/george7378/media/shadowmapsurface_zpsbe691522.png.html]shadowmapsurface_zpsbe691522.png[/URL]

 

0

Share this post


Link to post
Share on other sites

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.

0

Share this post


Link to post
Share on other sites

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.

1

Share this post


Link to post
Share on other sites

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
1

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