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
RenderTargetView to shader
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.
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
D3D10_TEXTURE2D_DESC texDesc;
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.BindFlags = D3D10_BIND_RENDER_TARGET | D3D10_BIND_SHADER_RESOURCE;
texDesc.CPUAccessFlags = 0;
texDesc.MiscFlags = D3D10_RESOURCE_MISC_GENERATE_MIPS;
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
testLevel->Draw();
//Draw the fps/ms per frame
RECT R = {5, 5, 0, 0};
md3dDevice->RSSetState(0);
mFont->DrawText(0, mFrameStats.c_str(), -1, &R, DT_NOCLIP, WHITE);
//Reset device render target
resetOMTargetsAndViewport();
//Draw the SRV to the screen, sprite used for simplicity
srSprite.pTexture = SRV;
spriteBatch->SetProjectionTransform(&matProjection);
spriteBatch->Begin(D3DX10_SPRITE_SORT_DEPTH_BACK_TO_FRONT);
spriteBatch->DrawSpritesBuffered(&srSprite, 1);
spriteBatch->Flush();
spriteBatch->End();
//Cleanup
RTV->Release();
SRV->Release();
RTVTex->Release();
//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.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement