DirectX 10 Render targets

Started by
4 comments, last by OliverSharpe 14 years, 3 months ago
I'll admit it, I haven't had much experience with render targets, but trying to go through the DX10 SDK samples and NVIDIA samples to learn how to use them is driving me nuts. I've used them only a couple times in XNA before, so I am not entirely familiar with the steps needed to use them. What I'm trying to do is create a simple post process effect that takes a rendered screen and modulates or adds to the red channel. I'm only doing this as practice, as I would very much like to create a gaussian blur and depth of field effect all on my own. Is there a simple way to get render targets working? Theory/steps would work just as well as code examples, as I would like to make a reusable class that I could use to make my other post process effects from. Currently I'm trying to draw a full screen quad using a sprite, which worked in XNA, but would it be better to use a basic textured quad in DirectX 10?
Advertisement
Here's the d3d basic tutorial, which includes creating a render target:

http://msdn.microsoft.com/en-us/library/ee416436(VS.85).aspx

The meat of it is:

hr = g_pd3dDevice->CreateRenderTargetView( pBackBuffer, NULL, &g_pRenderTargetView );


And setting the current render target:

g_pd3dDevice->OMSetRenderTargets( 1, &g_pRenderTargetView, NULL );

Doing a full-screen pass is as simple as setting up some verts for the quad, setting the shaders and binding shader paramters (+textures), and drawing the quad
Okay, thanks!

I'm also having trouble acquiring the texture, right now I'm doing some crazy thing trying to get the resource from the render target and convert it to a Texture2D that I can pass to the shader. Obviously this is not a good method and it certainly isn't working.

In XNA it was really simple to just acquire the render target texture, there has to be a way to do this in DirectX 10, but I just can't find it!
CreateRenderTargetView takes the texture as its first argument, so you should already have the texture there..

You'll need to make a shader resource view for the texture so you can bind it to a shader

create a D3D10_SHADER_RESOURCE_VIEW_DESC and call CreateShaderResourceView() on the device to create a ID3D10ShaderResourceView, which you can bind to an effect like:

effect->GetVariableByName("tex")->AsShaderResource()->SetResource( texShaderResource );

Oh, jeez. Is that really it?

I was thinking there was some specific method to call to retrieve the texture or the shader resource. Thank you so much for your help!

This topic is closed to new replies.

Advertisement