Jump to content
  • Advertisement
Sign in to follow this  
mind in a box

Flickering rendertarget

This topic is 2902 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

Hello!

I have a strange problem with one of my rendertargets.
The rendertarget holds the Depth of a special place in the scene and it flickers between the right result and some junk. Here are both:

(First is wrong, second is right)

It gets written by a shader as the first MRT of three. Then, I draw a fullscreen quad with it on top. The other 2 MRTs are fine.
The format is DXGI_FORMAT_R32_FLOAT if that helps.

Share this post


Link to post
Share on other sites
Advertisement
Are all your render targets 32-bit? When using MRTs all render targets must have the same bit-depth.

Other then that I can only imagine it's some sort of issue with depth testing.

Share this post


Link to post
Share on other sites
Quote:
Are all your render targets 32-bit? When using MRTs all render targets must have the same bit-depth.


Really? I have a deferred renderer for lighting and it works well, even with variable bit depths. I guess you mean the AA-Level?

Quote:

Other then that I can only imagine it's some sort of issue with depth testing.


I'll check that, later. [smile]

Share this post


Link to post
Share on other sites
Quote:
Original post by mind in a box
Quote:
Are all your render targets 32-bit? When using MRTs all render targets must have the same bit-depth.


Really? I have a deferred renderer for lighting and it works well, even with variable bit depths. I guess you mean the AA-Level?


This is a limitation on some DX9 level hardware. If you use DX10 and up you should be fine.


Share this post


Link to post
Share on other sites
Another thing I found out: When I put the depth into a component of one of the other MRTs, it works fine. But not with it's own texture...

Edit: Here's some code:

Thats where the shader writes to the MRTs

struct TER_PS_OUT
{
float Depth : SV_Target0;
float4 Normals : SV_Target1;
float4 Layers : SV_Target2;
};

TER_PS_OUT wtPixelShader(PixelShaderInput Input)
{
TER_PS_OUT Out;

Out.Depth=Input.Pos.z;
Out.Normals.rgb=Input.Norm;

//Decode layer information
Out.Normals.a=Input.TexCoord.r;
Out.Layers=float4(Input.TexCoord.g,Input.Tangent.rgb);

return Out;
}




Here is the creation:

void PP_DeferedRenderer::CreateTerrainMRTs()
{
if(bTerrainMode==true)
{
DeleteTexture(TerrainDepth);
DeleteTexture(TerrainNormals);
DeleteTexture(TerrainLayers);

CreateTexture(&TerrainDepth,WindowSize.right,WindowSize.bottom,DXGI_FORMAT_R32_FLOAT);
CreateTexture(&TerrainNormals,WindowSize.right,WindowSize.bottom,DXGI_FORMAT_R16G16B16A16_FLOAT);
CreateTexture(&TerrainLayers,WindowSize.right,WindowSize.bottom,DXGI_FORMAT_R8G8B8A8_UNORM );
}
}


//...

void PP_BaseEffect::CreateTexture(PPTexture** Tex, UINT SizeX,UINT SizeY,DXGI_FORMAT Format)
{
if(SizeX == 0 && SizeY == 0)
{
RECT r;
GetClientRect(Params->ActiveViewportWindow,&r);
SizeX=r.right;
SizeY=r.bottom;
}

if(Format==0)
{
//Get the main rendertarget to see which format we have to use
ID3D11RenderTargetView* MainView=StartRenderTarget;
D3D11_RENDER_TARGET_VIEW_DESC MainViewDesc;
MainView->GetDesc(&MainViewDesc);
Format=MainViewDesc.Format;
}

PPTexture* NewTex = new PPTexture;
//Create a new render target texture
D3D11_TEXTURE2D_DESC Desc;
ZeroMemory( &Desc, sizeof( D3D10_TEXTURE2D_DESC ) );
Desc.ArraySize = 1;
Desc.BindFlags = D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE;
Desc.Usage = D3D11_USAGE_DEFAULT;
Desc.Format = Format;
Desc.Width = SizeX;
Desc.Height = SizeY;
Desc.MipLevels = 1;
Desc.SampleDesc.Count = 1;

DXUTGetD3D11Device()->CreateTexture2D(&Desc,NULL,&NewTex->Texture);

//Create a render target view
D3D11_RENDER_TARGET_VIEW_DESC DescRT;
DescRT.Format = Desc.Format;
DescRT.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2D;
DescRT.Texture2D.MipSlice = 0;
DXUTGetD3D11Device()->CreateRenderTargetView((ID3D11Resource *)NewTex->Texture,&DescRT,&NewTex->RenderTargetView);


// Create the resource view
D3D11_SHADER_RESOURCE_VIEW_DESC DescRV;
DescRV.Format = Desc.Format;
DescRV.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
DescRV.Texture2D.MipLevels = 1;
DescRV.Texture2D.MostDetailedMip = 0;
DXUTGetD3D11Device()->CreateShaderResourceView( (ID3D11Resource *)NewTex->Texture, &DescRV, &NewTex->ShaderResView );

*Tex=NewTex;

}




It also looks like that this noise is "mapped" to the mesh like with a UV-Map (It doesn't have one, TexCoords are used for other information here)

Edit2: It is NOT an issue with that texture! I swapped them, so the second MRT became the first one, now the depth is working fine, but the one which is at the first MRT slot is the bad one now...

More code:

ID3D11RenderTargetView* RTViews[ 3 ] = { TerrainNormals->RenderTargetView, TerrainDepth->RenderTargetView, TerrainLayers->RenderTargetView};
DXUTGetD3D11DeviceContext()->OMSetRenderTargets(3,&RTViews[0],OldDepthView);



[Edited by - mind in a box on July 14, 2010 1:22:03 PM]

Share this post


Link to post
Share on other sites
Try this:

float Depth : SV_Target0;

to

float4 Depth : SV_Target0;

Then output depth as the .r component

Out.Depth.r=Input.Pos.z;

It mightn't make a bit of difference but maybe the SV_Target has to be a float4.

I know in DX9 hlsl when using a 32bit float you just output it as the red component of a float4 and it works that way.

Share this post


Link to post
Share on other sites
As a temporary solution (I'm not very pleased with it) I shifted the MRTs one slot to the right. So this:

ID3D11RenderTargetView* RTViews[ 3 ] = { TerrainNormals->RenderTargetView, TerrainDepth->RenderTargetView, TerrainLayers->RenderTargetView};



became this:


ID3D11RenderTargetView* RTViews[ 4 ] = { NULL, TerrainNormals->RenderTargetView, TerrainDepth->RenderTargetView, TerrainLayers->RenderTargetView};



And I have no flickering at all with this.
I only did this to make my engine usable again, a real solution would be better.
But that also says that the "float" to "float4" thing isn't the issue...

Share this post


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

  • Advertisement
×

Important Information

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

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!