Render to texture problem

Started by
5 comments, last by chowarth 13 years ago
I'm having a bit of a problem trying to setup a render target in order to be able to create a refraction map. I'm getting this error, and I cant narrow it down to any particular piece of code myself:

D3D10: ERROR: ID3D10Device::DrawIndexed: The view dimension declared in the shader code does not match the view type bound to slot 0 of the Pixel Shader unit. This is invalid if the shader actually uses the view (e.g. it is not skipped due to shader code branching). [ EXECUTION ERROR #354: DEVICE_DRAW_VIEW_DIMENSION_MISMATCH ]

Here is the resource creation:
//** Depth stencil
D3D10_TEXTURE2D_DESC TEXdesc;
TEXdesc.Width = REFRACMAP_SIZE;
TEXdesc.Height = REFRACMAP_SIZE;
TEXdesc.MipLevels = 1;
TEXdesc.ArraySize = 1;
TEXdesc.SampleDesc.Count = 1;
TEXdesc.SampleDesc.Quality = 0;
TEXdesc.Format = DXGI_FORMAT_D32_FLOAT;
TEXdesc.Usage = D3D10_USAGE_DEFAULT;
TEXdesc.BindFlags = D3D10_BIND_DEPTH_STENCIL;
TEXdesc.CPUAccessFlags = 0;
TEXdesc.MiscFlags = 0;
if( FAILED( g_pd3dDevice->CreateTexture2D( &TEXdesc, NULL, &m_RefracMapDepth ) ) )
{
return false;
}

//** Depth stencil view
D3D10_DEPTH_STENCIL_VIEW_DESC DSVdesc;
DSVdesc.Format = TEXdesc.Format;
DSVdesc.ViewDimension = D3D10_DSV_DIMENSION_TEXTURE2D;
DSVdesc.Texture2D.MipSlice = 0;
if( FAILED( g_pd3dDevice->CreateDepthStencilView( m_RefracMapDepth, &DSVdesc, &m_RefracMapDSV ) ) )
{
return false;
}

//** Render target view
TEXdesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
TEXdesc.BindFlags = D3D10_BIND_RENDER_TARGET | D3D10_BIND_SHADER_RESOURCE;
if( FAILED( g_pd3dDevice->CreateTexture2D( &TEXdesc, NULL, &m_RefracMapTexture ) ) )
{
return false;
}

D3D10_RENDER_TARGET_VIEW_DESC RTVdesc;
RTVdesc.Format = TEXdesc.Format;
RTVdesc.ViewDimension = D3D10_RTV_DIMENSION_TEXTURE2D;
RTVdesc.Texture2D.MipSlice = 0;
if( FAILED( g_pd3dDevice->CreateRenderTargetView( m_RefracMapTexture, &RTVdesc, &m_RefracMapRTV ) ) )
{
return false;
}

//** Shader resource view
D3D10_SHADER_RESOURCE_VIEW_DESC SRVdesc;
SRVdesc.Format = TEXdesc.Format;
SRVdesc.ViewDimension = D3D10_SRV_DIMENSION_TEXTURE2D;
SRVdesc.Texture2D.MipLevels = 1;
SRVdesc.Texture2D.MostDetailedMip = 0;
if( FAILED( g_pd3dDevice->CreateShaderResourceView( m_RefracMapTexture, &SRVdesc, &m_RefracMapSRV ) ) )
{
return false;
}


And setting the render target:
D3D10_VIEWPORT newVP;
newVP.Width = REFRACMAP_SIZE;
newVP.Height = REFRACMAP_SIZE;
newVP.MinDepth = 0;
newVP.MaxDepth = 1;
newVP.TopLeftX = 0;
newVP.TopLeftY = 0;
g_pd3dDevice->RSSetViewports( 1, &newVP );

float clearColour[4] = { 0.0f, 0.0f, 0.0f, 0.0f };
g_pd3dDevice->ClearRenderTargetView( m_RefracMapRTV, clearColour );
g_pd3dDevice->ClearDepthStencilView( m_RefracMapDSV, D3D10_CLEAR_DEPTH, 1.0f, 0 );

g_pd3dDevice->OMSetRenderTargets( 1, &m_RefracMapRTV, m_RefracMapDSV );
Ramblings: www.chowarth.co.uk
Advertisement
The resource creation code looks correct.

However looks like the problem is occurs when you use the shader resource view... How do you bound the shader resource view with the shader?
Essentially Im trying to just render a heightmapped terrain, clipping everything above WorldPos.y, for the refraction map.
This appears to be fine for the first frame, then on the second it dies.

Setting the textures:
SetTexture( 0, m_CubeMapSRV );
SetTexture( 1, m_DepthMapSRV );
SetTexture( 2, m_RefracMapSRV );


Corresponding shader textures:
TextureCube CubeMap;
Texture2D ShadowMap;
Texture2D RefractionMap;
Ramblings: www.chowarth.co.uk
Make sure you set the ID3D10EffectShaderResourceVariable* of the refraction map to null before rendering a to it render target.
Yup, I set the texture in slot 2 to NULL right before I change the viewport and render target.
Ramblings: www.chowarth.co.uk

Yup, I set the texture in slot 2 to NULL right before I change the viewport and render target.


Can you tell in which exact line is the error thrown? Set a breakpoint in every draw call and see after each one is the error thrown... Because I guess that the view bound to slot 0 is the TextureCube. So it has nothing to do with the resource creation code you posted...
The break occurs on the DrawIndexed line when rendering the terrain grid mesh:


void CGridMesh::Draw()
{
g_pd3dDevice->IASetInputLayout( m_VertexLayout );
g_pd3dDevice->IASetPrimitiveTopology( D3D10_PRIMITIVE_TOPOLOGY_TRIANGLELIST );

UINT stride = sizeof( SGridVertex );
UINT offset = 0;
g_pd3dDevice->IASetVertexBuffers( 0, 1, &m_VertexBuffer, &stride, &offset );
g_pd3dDevice->IASetIndexBuffer( m_IndexBuffer, DXGI_FORMAT_R32_UINT, 0 );
g_pd3dDevice->DrawIndexed( m_nFaces*3, 0, 0 );
}
Ramblings: www.chowarth.co.uk

This topic is closed to new replies.

Advertisement