Jump to content

View more

Image of the Day

The beast has a mighty searchlight of evil! #screenshotsaturday https://t.co/bzKepOojDL
IOTD | Top Screenshots

The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.

Sign up now

[SharpDX][.Net] Rendertargets dont display correctly when used as textures

4: Adsense

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
2 replies to this topic

#1 bjornp   Members   


Posted 19 March 2013 - 03:44 PM

Hello gamedev.
I'm having some troubles getting my rendertargets to display correctly when used as textures. I generate all the rendertargets in an earlier stage and pass them on to the drawing stage, according to GPU PerfStudio they look like this when passed to the drawing stage:


This is what i expect them to look like, so they seem correct. However when trying to draw them as fullscreen textures all I see is this: 



This is how i create my rendertargets and shaderresourceviews:

Dim rtdesc As RenderTargetViewDescription
'rtdesc.Format = Format.R32G32B32A32_Float
rtdesc.Format = Format.R8G8B8A8_UNorm
rtdesc.Dimension = RenderTargetViewDimension.Texture2D
rtdesc.Texture2D.MipSlice = 0

Dim srvdesc As ShaderResourceViewDescription
srvdesc.Dimension = ShaderResourceViewDimension.Texture2D
'srvdesc.Format = Format.R32G32B32A32_Float
srvdesc.Format = Format.R8G8B8A8_UNorm
srvdesc.Texture2D.MostDetailedMip = 0
srvdesc.Texture2D.MipLevels = 1

Dim renderTargetColor As Texture2D = New Texture2D(device, rendertargetdesc)
Dim renderTargetNormal As Texture2D = New Texture2D(device, rendertargetdesc)
Dim renderTargetDepth As Texture2D = New Texture2D(device, rendertargetdesc)

Dim rttColorRTV = New RenderTargetView(device, renderTargetColor, rtdesc)
Dim rttColorSRV = New ShaderResourceView(device, renderTargetColor, srvdesc)
Dim rttNormalRTV = New RenderTargetView(device, renderTargetNormal, rtdesc)
Dim rttNormalSRV = New ShaderResourceView(device, renderTargetNormal, srvdesc)
Dim rttDepthRTV = New RenderTargetView(device, renderTargetDepth, rtdesc)
Dim rttDepthSRV = New ShaderResourceView(device, renderTargetDepth, srvdesc)


My drawing stage:

context.InputAssembler.InputLayout = layout2d
context.PixelShader.SetShaderResource(0, rttColorSRV)
context.PixelShader.SetShaderResource(1, rttNormalSRV)
context.PixelShader.SetShaderResource(2, rttDepthSRV)
context.InputAssembler.SetVertexBuffers(0, New VertexBufferBinding(quad2dvb, Utilities.SizeOf(Of Vertex2DTextured)(), 0))
context.Draw(6, 0)
swapchain.Present(0, PresentFlags.None)


My shader:

SamplerState colorSampler;
Texture2D colorMap;
Texture2D NormalMap;
Texture2D DepthMap;

struct VertexShaderInput
    float3 Position : POSITION;
    float2 TexCoord : TEXCOORD0;

struct VertexShaderOutput
    float4 Position : SV_POSITION;
    float2 TexCoord : TEXCOORD0;

VertexShaderOutput VS(VertexShaderInput input)
    VertexShaderOutput output;
    output.Position.w = 1.0f;
    output.Position.xyz = input.Position;
    output.TexCoord = input.TexCoord;
    return output;

float4 PS(VertexShaderOutput input) : SV_TARGET
    return colorMap.Sample(colorSampler, input.TexCoord);
    //return NormalMap.Sample(colorSampler, input.TexCoord);
    //return DepthMap.Sample(colorSampler, input.TexCoord);


At first i thought the fullscreen quad i use was wrong, but I loaded a texture from a bmp file, and it renders correctly as a textured fullscreen quad. Is there something special I have to do with my ShaderResourceViews before using them? I release the RenderTargetViews before using the ShaderResourceViews, Switching which texture to use in the shader gives the exact same result except it's a different color.

Attached Thumbnails

  • DC8_OM_RenderTarget_0.png
  • DC9_PS_Texture_1.png
  • DC9_PS_Texture_2.png
  • window2.png

Edited by bjornp, 19 March 2013 - 03:46 PM.

#2 MJP   Moderators   


Posted 19 March 2013 - 05:35 PM

It looks like you still have the render target textures bound as outputs when you bind those textures as inputs, which means that the runtime will set them to NULL in order to avoid a read/write conflict. The runtime will warn you about these kinds of things if you pass the DEBUG flag when creating your device. However the messages will go to the native debugging output, so you need to either enable managed debugging for your project (which you can only do with paid versions of Visual Studio) or you can use a separate program like DebugView.

Edited by MJP, 19 March 2013 - 05:35 PM.

#3 bjornp   Members   


Posted 19 March 2013 - 11:38 PM

Hi, MJP and thank you for your answer. The first thing i do in my drawing code is
So I don't think that is the case, if i don't do this the shaderresourceviews don't show up at all in perfstudio.

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.