• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0

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

2 posts in this topic

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.

Edited by bjornp

Share this post

Link to post
Share on other sites

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

Share this post

Link to post
Share on other sites
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.

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  
Followers 0