Jump to content
  • Advertisement
Sign in to follow this  
eason

Directx 10/11 Render to Volume Texture Problem

This topic is 3167 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm trying to implement render to volume texture. I create ShaderResourceView and RenderTargetView for texture3d,then set the texture3d as render target. When i check the result,i encounter problems. In shader,only if SV_RenderTargetArrayIndex output's value set 0,i can find things in texture3d's slice 0. But if i set SV_RenderTargetArrayIndex output's value isn't 0,then i can't find anything in every slice. How can i correctly render things in texture3d's slices? plz help me my program code is below:
/////////////create Texture3D,ShaderResourceView,RenderTargetView//////////////



	const int Depth=8;
	ID3D11Texture3D* colorMap;
	ID3D11ShaderResourceView* mColorMapSRV;
	ID3D11RenderTargetView* mColorMapRTV;

//create Texture3D

	D3D11_TEXTURE3D_DESC texDesc;
	
	texDesc.Width     = mWidth;
	texDesc.Height    = mHeight;
	texDesc.Depth=Depth;
	texDesc.MipLevels = 1;
	texDesc.Format    =  DXGI_FORMAT_R16G16B16A16_FLOAT; 
	texDesc.Usage          = D3D11_USAGE_DEFAULT;
	texDesc.BindFlags      = D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE;
	texDesc.CPUAccessFlags = 0; 
	texDesc.MiscFlags      = 0;

	HR(md3dDevice->CreateTexture3D(&texDesc, 0, &colorMap));

//create ShaderResourceView

	D3D11_SHADER_RESOURCE_VIEW_DESC SRVDesc;
    	ZeroMemory( &SRVDesc, sizeof(SRVDesc) );
   	SRVDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE3D;
   	SRVDesc.Texture3D.MipLevels = 1;
    	SRVDesc.Texture3D.MostDetailedMip = 0;
	SRVDesc.Format=texDesc.Format;

	HR(md3dDevice->CreateShaderResourceView(colorMap, &SRVDesc, &mColorMapSRV));

//create RenderTargetView

	D3D11_RENDER_TARGET_VIEW_DESC DescRT;
	DescRT.Format = texDesc.Format;  
	DescRT.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE3D;  
	DescRT.Texture3D.WSize= Depth; 
	DescRT.Texture3D.FirstWSlice= 0;  
	DescRT.Texture3D.MipSlice = 0;  

    	HR( md3dDevice->CreateRenderTargetView( colorMap, &DescRT, &mColorMapRTV ) );
/////////////////////////////Set Render Target////////////////////////////////



mDeviceContext->RSSetViewports(1, &mViewport);
	

mDeviceContext->ClearRenderTargetView(mColorMapRTV, BLACK);
	
mDeviceContext->OMSetRenderTargets(1, &mColorMapRTV, NULL);


/////////////////////Render Volume Texture shader code////////////////////////




struct VS_TEX_IN
{
	float3 posL    : POSITION;

};

struct VS_TEX_OUT
{
	float4 posH    : POSITION;
};
struct GS_OUT
{
    uint   RTIndex      : SV_RENDERTARGETARRAYINDEX;
    float4 Pos          : SV_Position;
};

 
VS_TEX_OUT VS_TEX(VS_TEX_IN vIn)
{
	VS_TEX_OUT vOut;
	
	// Transform to world space space.

	vOut.posH = mul(float4(vIn.posL, 1.0f), gViewProj);
	
	return vOut;
}

[maxvertexcount (3)]
void gs_main(triangle VS_TEX_OUT input[3], inout TriangleStream<GS_OUT> triStream)
{
   GS_OUT output;
    output.RTIndex = 0; //if i set non-zero,i can't find anything in every slice
for(int v=0; v<3; v++)
{
      output.Pos = input[v].posH;
       triStream.Append( output );
}

}


float4 PS_TEX(GS_OUT pIn) : SV_Target
{
	
    
    return float4(1.0f,0.0f,0.0f,1.0f);
}

technique11 SliceTech
{
    pass P0
    {
        SetVertexShader( CompileShader( vs_4_1, VS_TEX() ) );
       SetGeometryShader( CompileShader( gs_4_1, gs_main() ));
        SetPixelShader( CompileShader( ps_4_1, PS_TEX() ) );
    }
}

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!