Sign in to follow this  
hlee

How to save a scene in higher resolution?

Recommended Posts

hlee    115

I am trying to make posters for secens from my program.  I can grab the screen by using IDirect3DDevice9::

GetBackBuffer.  However it is limited to the screen resolutions of my display, 2560x1600.  The new 4K displays can go up to 3840x2160, but even that is not good enough for large posters.  I would like to have images of 6000x4000 or higher.

 

Is this possible?  Do I need to use a software device to render in a higher resolution than the display?  If so, how?

Share this post


Link to post
Share on other sites
Migi0027    4628

When choosing to capture a frame, you could wait to next frame (and activate some kind of trigger), then resize the display to something bigger, and then capture the frame?

 

If you have dynamic resolution on e.g. ssao... Then you could multiply each single resolution by f each frame, which you can change, to a higher/lower value when needed.

 

PS. Sorry if this is a bit messy, but it's a bit late over here. happy.png

Edited by Migi0027

Share this post


Link to post
Share on other sites
hlee    115

Migi0027, thanks for the suggestion, but how do you resize the display beyond the capability of the harware?  Which resizing function should I call?

Share this post


Link to post
Share on other sites
Ravyne    14300

You can render to a render-target, then you'll only be limited by the max texture size, rather than the display resolution, I believe -- to 8k+. If you want to go even larger, you can render in multiple sections at some high resolution. Bungie used to do this on their servers for premium bungie.net members (you could take a high-res shot from a captured gameplay video). You have to mess with the frustum/projection I think, since it becomes non-uniform. I think they may have done a whitepaper on how they did it.

Share this post


Link to post
Share on other sites
tivolo    1367

If you want to support arbitrary resolutions and not be limited by either the size of the viewport or the render target, there are two possibilities I know of:

 

1) render the scene in tiles, e.g. 2x2, 3x3, 4x4, altering view- and projection-matrices accordingly, stitching together the results of the different renders.

2) use subpixel rendering, more or less. there's a bit of information here, and there's an article in game programming gems 4 as well.

 

note that both methods will likely cause problems with fullscreen effects, which have to be treated separately. your renderer/engine needs to be aware of the fact that it renders high-resolution screenshots, and e.g. treat all fullscreen effects differently.

 

hth,

-tiv

Share this post


Link to post
Share on other sites
hlee    115

@Ravyne,  I've tried your suggestions and created a temporary render target with larger surface, but it does not work.  The rendered scene is clipped to the same size as the backbuffer.

 

@Medo3337, how can I change the backbuffer size?  I use DXUTCreateDevice to create the D3D device, which limits the width/height to the maximums of the display adapter.  SetViewport does not change the backbuffer either.

Share this post


Link to post
Share on other sites
Ravyne    14300

@Ravyne,  I've tried your suggestions and created a temporary render target with larger surface, but it does not work.  The rendered scene is clipped to the same size as the backbuffer.

 

 

Did you adjust your projection to fill the render target?

Share this post


Link to post
Share on other sites
hlee    115


Did you adjust your projection to fill the render target?

 

Yes.  I get the whole scene if the render target is smaller than the adapter limit.  Larger, then the scene is clipped.

Share this post


Link to post
Share on other sites
Adam_42    3629

D3D definitely supports rendering to targets that are bigger than the screen. I suspect your problem is one of:

 

- Your depth buffer is smaller than the render target. You'll need an appropriately sized one of those as well.

- Scissor rectangle is too small.

- Viewport is too small.

Share this post


Link to post
Share on other sites
hlee    115


D3D definitely supports rendering to targets that are bigger than the screen. I suspect your problem is one of:

You are absolutely right about the depth buffer.  After creating a depth stencil surface that matches the render target I can now get the full frame.  Thank you so much!

 

However, MultiSampleType must be set to D3DMULTISAMPLE_NONE for the render target, otherwise the GetRenderTargetData would return D3DERR_INVALIDCALL.  Without multisample I might as well just capture the screen with a lower resolution but with anti-aliasing.  Is there a way to use multisample in this method?

Share this post


Link to post
Share on other sites
DwarvesH    510

Well, I don't know what extra advice to give you that hasn't been said before, but you have inspired me to add a super screenshot mode to my engine. A special hotkey that when pressed will save a superb quality screenshot with normal or super-high quality/resolution. I'm estimating that at the highest quality setting the engine will consume about 2 GiB or RAM and spend 5-10 second creating one screenshot smile.png.

 

I'll let you know how it turns out.

Edited by DwarvesH

Share this post


Link to post
Share on other sites
Adam_42    3629

If you look at the documentation for GetRenderTargetData() you'll see:

 

 

This method will fail if:

  • The render target is multisampled.

 

The standard solution to that is to use StretchRect() to copy it to a non-multisampled render target.

 

However in your case I'd just increase the resolution and downsize the result in some image editing software - you'll get better quality that way.

Share this post


Link to post
Share on other sites
hlee    115


The standard solution to that is to use StretchRect() to copy it to a non-multisampled render target.

That's it!  This is what works:

1. Create a large multisampled RT, called it RT1, along with a depth buffer

2. Render the scene to RT1

3. Create a non-multisampled RT, called it RT2, the same size as RT1

4. StretchRect RT1 to RT2

5. Use GetRenderTargetData to copy RT2 to an OffscreenPlainSurce

6. Use D3DXSaveSurfaceToFile to save the OffscreenPlainSurce

 

Now I get a high resolution, multiampled scene.  Thanks so much, Adam!

 

But why does it have to be so cumbersome?  Why can't D3DXSaveSurfaceToFile save a mutisampled RT directly?

Share this post


Link to post
Share on other sites
Adam_42    3629

The way multisampling works is that D3D internally creates an extra large render target and depth buffer (e.g. for 4X it's double the width and height).

 

However, when rendering to it the pixel shader isn't re-run for each extra pixel, but the depth test is. That gives significantly better performance than rendering to a double sized render target, at the cost of a bit of quality - it won't solve aliasing that's caused by the shader, which manually rendering at double the size then downsizing will do.

 

There's usually also some hardware trickery in there to accelerate the common case where all of the antialiased samples for one output pixel are identical by storing the data a bit differently.

 

The shader aliasing is why I said you want to just render to a bigger texture and downsize it yourself. Doing that also means you need less GPU memory.

 

The reason you need the StretchRect() step is that the GPU needs to decode and downsize the extra large render target to an antialiased one of the right size before you can read it back with either a shader or the CPU.

Share this post


Link to post
Share on other sites
DwarvesH    510

StrechRect will work, but will probably perform poorly. You are effectively using SSAA at this point and there is a good reason most games don't offer this option.

 

But since you want to capture screenshots, I would recommend rendering your high resolution texture as a full screen quad and using high quality down-sampling filter implemented in the pixel shader. Or do it in an external program once the screenshot is saved.

Share this post


Link to post
Share on other sites
hlee    115

5. Use D3DXSaveTextureToFile to save RT2 directly to a file

D3DXSaveTextureToFile complains that RT2 is not a texture.  If I'd created RT2 as a texture then StrectRec would complain that RT2 is not a IDirect3DSurface9.  How can I make it to work?

Share this post


Link to post
Share on other sites
hlee    115

How about using D3DXSaveSurfaceToFile wink.png

That works!  I thought D3DXSaveSurfaceToFile requires the source being OffscreenPlainSurface.

 

That's one step saved.  I still think it is unnecessarily cumbersome.  Maybe D3D11 provide a more efficient method?

Share this post


Link to post
Share on other sites
hlee    115

 

How about using D3DXSaveSurfaceToFile wink.png

That works!  I thought D3DXSaveSurfaceToFile requires the source being OffscreenPlainSurface.

 

That's one step saved.  I still think it is unnecessarily cumbersome.  Maybe D3D11 provide a more efficient method?

 

Just noticed a side effect of skipping the step: the maximum resolution is reduced !

 

Somehow, by copying RT2 to an OffscreenPlainSurface before D3DXSaveSurfaceToFile, I can save a frame with higher resolution.  Does anyone have an explanation?

 

Since efficiency is not a concern for my purpose, I will add the step back.

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