Jump to content
  • Advertisement
Sign in to follow this  

RenderTargetView to shader

This topic is 2810 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm trying to pass the render target to the shader for things like blur effects (as described in the book I'm reading, Shaders for Game Programmers and Artists), but I'm completely lost as to how to:

1) Get the current view into the shader.
2) Draw the output from the shader onto the screen instead of having the initial view rendered.

I feel like this is something that should be really obvious, but I've spent most of the day trying to figure it out and I'm just stumped. Any help would be greatly appreciated :)

Share this post

Link to post
Share on other sites
Not quite sure I understand your problem, but if you have a texture you can create several views on it. So create one render target view and one shader resource view, both to the same texture, and use the RTV when rendering to and the SRV when reading from the texture. Just be sure not to bind both at the same time, that is not allowed, as that would give a read/write conflict.

Share this post

Link to post
Share on other sites

Just be sure not to bind both at the same time, that is not allowed, as that would give a read/write conflict.

For some reason, I didn't think of that part. Now, I'm creating a temporary RTV that the scene gets drawn to, then switching the device back to the original RTV and drawing the temporary SRV onto it through a sprite. However, only the frame statistics and a very small piece of the terrain get rendered, and that's only if the camera is close enough to it.

The relevant code:

//Create Texture2D desc for RTV and SRV
texDesc.Width = screenWidth;
texDesc.Height = screenHeight;
texDesc.MipLevels = 0;
texDesc.ArraySize = 1;
texDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
texDesc.SampleDesc.Count = 1;
texDesc.SampleDesc.Quality = 0;
texDesc.Usage = D3D10_USAGE_DEFAULT;
texDesc.CPUAccessFlags = 0;

ID3D10Texture2D* RTVTex = 0;
HR(md3dDevice->CreateTexture2D(&texDesc, 0, &RTVTex));

ID3D10RenderTargetView* RTV;
ID3D10ShaderResourceView* SRV;

HR(md3dDevice->CreateRenderTargetView(RTVTex, 0, &RTV));
HR(md3dDevice->CreateShaderResourceView(RTVTex, 0, &SRV));

ID3D10RenderTargetView* renderTarget[1] = {RTV};
//Set device render target
md3dDevice->OMSetRenderTargets(1, renderTarget, D3DApp::getDepthStencilView());

//Draw the level

//Draw the fps/ms per frame
RECT R = {5, 5, 0, 0};
mFont->DrawText(0, mFrameStats.c_str(), -1, &R, DT_NOCLIP, WHITE);

//Reset device render target

//Draw the SRV to the screen, sprite used for simplicity
srSprite.pTexture = SRV;
spriteBatch->DrawSpritesBuffered(&srSprite, 1);


//present the scene
mSwapChain->Present(0, 0);

Again, any help would be wonderful. I just don't see what the issue is, as the scene draws fine if there's no second RTV.

Share this post

Link to post
Share on other sites
Turns out the problem was my changing the blendstate when drawing a crosshair in game to alpha blending, resetting the blendstate afterwards solved it.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!