渲染到纹理反转

时间:2014-09-30 20:17:59

标签: c++ rendering directx-11 render-to-texture

我试图渲染到纹理,但纹理与我想要的相反。即,清除并渲染清晰的颜色,而我要渲染的实际对象是alpha输出。

//Set the render target
RenderToTexture(RENDERTEXTURE_PARTICLESTAGE);
//Draw the scene (using the new render target)
m_Renderer.Draw();
//Save the file out so we can see the result
m_pRenderTextures[RENDERTEXTURE_PARTICLESTAGE]->SaveToFile(L"data/particle.tga");
This is the code I use to render to texture

在渲染到纹理功能中,我这样做

m_pDeviceContext->OMSetRenderTargets(1, &m_pRenderTargetView, _pDepthStencilView);

m_pRenderTargetView 独立于m_pRenderTexture对象, _pDepthStencilView 从我的主应用程序传入。

我也清除了渲染目标并预先清除了深度模板,我只是将代码留下来以使问题膨胀到最小。

我确定这不是保存纹理的问题 - 我尝试将资源直接渲染回应用程序并获得相同的结果。

我很确定这是因为我的深度模板描述,但我不确定究竟会出现什么问题。

//Depth Stencil
    D3D11_TEXTURE2D_DESC DepthStencilDescription;
    {
        DepthStencilDescription.Width               = m_uiClientWidth;
        DepthStencilDescription.Height              = m_uiClientHeight;
        DepthStencilDescription.MipLevels           = 1;
        DepthStencilDescription.ArraySize           = 1;
        DepthStencilDescription.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
        DepthStencilDescription.SampleDesc.Count    = 1;
        DepthStencilDescription.SampleDesc.Quality  = 0;
        DepthStencilDescription.Usage               = D3D11_USAGE_DEFAULT;
        DepthStencilDescription.BindFlags           = D3D11_BIND_DEPTH_STENCIL;
        DepthStencilDescription.CPUAccessFlags      = 0; 
        DepthStencilDescription.MiscFlags           = 0;
    }
    Utility::Assert(m_pDevice->CreateTexture2D(&DepthStencilDescription, 0, &m_pDepthStencilBuffer));
    Utility::Assert(m_pDevice->CreateDepthStencilView(m_pDepthStencilBuffer, 0, &m_pDepthStencilView));

与我的RenderTextureClass中的纹理描述相对,

TextureDescription.Format = DXGI_FORMAT_R8G8B8A8_UNORM;

但是试图让它们相互匹配会引发错误。

以下是PIX的结果:

This is me rendering to texture 这是我渲染到纹理的时候。到目前为止它看起来很好...... enter image description here 但我保存纹理,这就是它的样子 enter image description here 直接通过着色器资源视图将纹理渲染回屏幕...(不是纹理保存功能的问题) 白色实际上是BackBuffer的清晰颜色,红色是RenderTexture的清晰颜色。所以它拯救了与我想要的相反的东西。

我期待白色背景上的蓝色球体

如果有人能指出我正确的方向,那就太好了。干杯:)

0 个答案:

没有答案