6

i am trying to render my Scene to a texture to use it in shaders for some post processing effect. I am not very experienced with this kind of stuff so i have some questions here.. First off all:

I am having this code in my OnCreateDevice() method:

    D3D11_TEXTURE2D_DESC textureDesc;
    D3D11_RENDER_TARGET_VIEW_DESC renderTargetViewDesc;
    D3D11_SHADER_RESOURCE_VIEW_DESC shaderResourceViewDesc;

    ZeroMemory(&textureDesc, sizeof(textureDesc));

    textureDesc.Width = 800/2;
    textureDesc.Height = 600/2;
    textureDesc.MipLevels = 1;
    textureDesc.ArraySize = 1;
    textureDesc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
    textureDesc.SampleDesc.Count = 1;
    textureDesc.Usage = D3D11_USAGE_DEFAULT;
    textureDesc.BindFlags = D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE;
    textureDesc.CPUAccessFlags = 0;
    textureDesc.MiscFlags = 0;


    pd3dDevice->CreateTexture2D(&textureDesc, NULL, &renderTargetTextureMap);


    renderTargetViewDesc.Format = textureDesc.Format;
    renderTargetViewDesc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2D;
    renderTargetViewDesc.Texture2D.MipSlice = 0;


    pd3dDevice->CreateRenderTargetView(renderTargetTextureMap, &renderTargetViewDesc, &renderTargetViewMap);

    shaderResourceViewDesc.Format = textureDesc.Format;
    shaderResourceViewDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
    shaderResourceViewDesc.Texture2D.MostDetailedMip = 0;
    shaderResourceViewDesc.Texture2D.MipLevels = 1;


    pd3dDevice->CreateShaderResourceView(renderTargetTextureMap, &shaderResourceViewDesc, &shaderResourceViewMap);

I am creating a texture, a renderView and a resourceView. But where do i go from here? Do i have to define another buffer or does this work after all?

Specifically,

So i think i know i have to set the OMRenderTargets with: renderTargetViewMap and depthStencilView. But where do i have to set this? In every frame render call? Before or after i rendered the other objects in my scene? and my guess would be that i have to make a new shader to which i give this texture created to work with it.

Thanks for any insight :/

7
  • What have you tried? I'm sure there are MANY render to texture tutorials out there (google.com/…). What part, specifically are you looking for help with? Commented Jun 29, 2012 at 20:16
  • So i think i know i have to set the OMRenderTargets with: renderTargetViewMap and depthStencilView. But where do i have to set this? In every frame render call? Before or after i rendered the other objects in my scene? and my guess would be that i have to make a new shader to which i give this texture created to work with it. Commented Jun 29, 2012 at 20:30
  • You will have to set it each time you want to render to the texture, yes (and as long as you haven't switched to another render target or the back buffer). Once you've rendered the data to the texture, set up the shader that processes this data and draw a screen aligned quad with this texture. Commented Jun 29, 2012 at 20:57
  • Thanks. I will try around a little bit and see how this works. Thanks so far. I guess the screen aligned quad could be accomplished with a geometryshader? Or would this be a bad use of it? Commented Jun 29, 2012 at 21:06
  • That'd work, although I wouldn't use a geometry shader for simply rendering a quad :) Commented Jun 29, 2012 at 21:07

1 Answer 1

1

You will have to set it each time you want to render to the texture, yes (and as long as you haven't switched to another render target or the back buffer). Once you've rendered the data to the texture, set up the shader that processes this data and draw a screen aligned quad with this texture.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.