I’m using D3D11 on a Windows 7 desktop platform to render to a texture that I want to apply to a quad in my scene. I have everything connected and I can debug the native C++ plugin and step through all of the lines with no errors.
Right now, all I’m doing is clearing the texture, I’m not rendering to it. But no matter what colour I clear it to, it always ends up being black. Here are the steps I’m using:
D3D11RenderTargetViewPtr pCurrentRenderTarget;
D3D11DepthStencilViewPtr pCurrentDepthStencil;
// Get the current render targets
pD3D11DC->OMGetRenderTargets(1, &pCurrentRenderTarget, &pCurrentDepthStencil);
pD3D11DC->OMSetRenderTargets(1, &g_pD3D11RenderTargetView, nullptr);
const float CLEAR_CLR[4] = { 1, 1, 0, 1 };
pD3D11DC->ClearRenderTargetView(g_pD3D11RenderTargetView, CLEAR_CLR);
// Restore the original rendertarget
pD3D11DC->OMSetRenderTargets(1, &(pCurrentRenderTarget.p), pCurrentDepthStencil);
I have my Unity material on the quad setup as Unlit/Texture. I have also tried Unlit/Transparent, but if I do that, I don’t get anything. I’m assuming that the texture is fully transparent which is why I can’t see it in that case.
The texture is created in Unity like this:
m_Texture = new RenderTexture(1600, 900, 0, RenderTextureFormat.ARGB32);
m_Texture.filterMode = FilterMode.Point;
m_Texture.Create();
I then pass the texture to my plugin:
U_EXPORT void SetTexturePtr(void* pTexture)
{
Log(L"Setting texture pointer\n");
switch (g_iGfxDeviceType)
{
case GFXRENDERER_D3D11:
g_pD3D11RenderTexture = reinterpret_cast<D3D11TexPtr>(pTexture);
if (nullptr != g_pD3D11Device && nullptr != g_pD3D11RenderTexture )
{
D3D11_TEXTURE2D_DESC texDesc = { 0 };
// Get the format of the texture
g_pD3D11RenderTexture ->GetDesc(&texDesc);
D3D11_RENDER_TARGET_VIEW_DESC rtvDesc = { texDesc.Format };
rtvDesc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2D;
// Create the render target view for the texture
g_pD3D11Device->CreateRenderTargetView
(
g_pD3D11RenderTexture ,
&rtvDesc,
&g_pD3D11RenderTargetView
);
}
break;
}
}
I’m sure I’m missing something, but I can’t seem to find it. If you have any suggestions, I would love to hear them.
Thanks

