• 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
Bj

[SharpDX][VB.net] Problems drawing a fullscreenquad.

1 post in this topic

Hello gamedev, 
I'm trying to implement and learn how to do deferred rendering, but having some problems along the way. 

In my first pass I render the scene and save the color, normal, and depth to 3 different rendertargets. This seems to work fine according to GPU PerfStudio 2, as it shows me these 3 images:

post-209015-0-75355900-1362936990_thumb.post-209015-0-74717500-1362936991_thumb.post-209015-0-79513800-1362936992_thumb.

 

However the second stage is causing me problems. From what I understand I'm supposed to draw a fullscreen quad so that every pixel of my rendertargets are used in the lighting calculations. What do i need to change between drawing the scene above to drawing the fullscreen quad in terms of settings?

At the moment I set up my vertices as this:

Imports SharpDX
Public Structure Vertex2DTextured
    Public Position As Vector3
    Public TextureCoords As Vector2

    Public Sub New(Position As Vector3, texcoord As Vector2)
        Me.Position = Position
        Me.TextureCoords = texcoord
    End Sub
End Structure

Dim quad2d(5) As Vertex2DTextured
quad2d(0) = New Vertex2DTextured(New Vector3(-1, 1, 0), New Vector2(0, 0))
quad2d(1) = New Vertex2DTextured(New Vector3(1, 1, 0), New Vector2(1, 0))
quad2d(2) = New Vertex2DTextured(New Vector3(-1, -1, 0), New Vector2(0, 1))
quad2d(3) = New Vertex2DTextured(New Vector3(1, 1, 0), New Vector2(1, 0))
quad2d(4) = New Vertex2DTextured(New Vector3(1, -1, 0), New Vector2(1, 1))
quad2d(5) = New Vertex2DTextured(New Vector3(-1, -1, 0), New Vector2(0, 1))
Dim quad2dvb As Buffer = Buffer.Create(device, BindFlags.VertexBuffer, quad2d)

 

And my renderloop looks like this:

context.ClearDepthStencilView(depthView, DepthStencilClearFlags.Depth, 1.0F, 0)

'First stage, works fine
context.InputAssembler.InputLayout = layout3d                   'Set layout to POS (float4), NOR, COL, TEX
context.OutputMerger.SetTargets(rtvs)                           'Set the rendertargets
context.ClearRenderTargetView(rtvs(0), Color4.Black)
context.ClearRenderTargetView(rtvs(1), Color.Gray)
context.ClearRenderTargetView(rtvs(2), Color4.White)
context.VertexShader.Set(vertexShader)
context.PixelShader.Set(pixelShader)
Manager.Render()

'Second stage, does not work fine :(
'context.OutputMerger.SetTargets(renderview)
context.OutputMerger.SetTargets(depthView, renderview)
context.VertexShader.Set(vertexShader2)
context.PixelShader.Set(pixelShader2) 
context.InputAssembler.InputLayout = layout2d                    'Set layout to Pos(float3), TEX  
context.ClearRenderTargetView(renderview, Color.Black)
context.PixelShader.SetSampler(0, SampleState)
context.PixelShader.SetShaderResources(0, rendertv)              'My 3 ShaderRescourceViews from stage 1
context.InputAssembler.SetVertexBuffers(0, New VertexBufferBinding(quad2dvb, Utilities.SizeOf(Of Quad2DTextured)(), 0))
context.Draw(6, 0)

swapchain.Present(0, PresentFlags.None)

 

I just wanted to see if the fullscreen quad was drawn in the second stage to vertex- and pixelshader2 corresponds to this:

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

struct VertexShaderInput
{
    float3 Position : POSITION;
    float2 TexCoord : TEXCOORD;
};

struct VertexShaderOutput
{
    float3 Position : POSITION;
    float2 TexCoord : TEXCOORD;
};

VertexShaderOutput VS(VertexShaderInput input)
{
    VertexShaderOutput output;
    output.Position = input.Position;
    output.TexCoord = input.TexCoord;
    return output;
}

float4 PS(VertexShaderOutput input) : SV_TARGET
{
    return colorMap.Sample(colorSampler, input.TexCoord);
}

 

However, nothing is drawn. When i look in PerfStudio I only see 1 incoming texture:

post-209015-0-74868500-1362938436_thumb.

which is none of my rendertargets... :(. I was hoping my first rendertarget would be drawn. 
My 2D and 3D layouts:

Dim layout2d As InputLayout = New InputLayout(device, signature2, {New InputElement("POSITION", 0, Format.R32G32B32_Float, 0, 0), New InputElement("TEXCOORD", 0, Format.R32G32_Float, 12, 0)})

Dim layout3d As InputLayout = New InputLayout(device, signature, {New InputElement("POSITION", 0, Format.R32G32B32A32_Float, 0, 0), New InputElement("COLOR", 0, Format.R32G32B32A32_Float, 16, 0), New InputElement("NORMAL", 0, Format.R32G32B32_Float, 32, 0), New InputElement("TEXCOORD", 0, Format.R32G32_Float, 44, 0)})

 

 

If anyone could help me get this quad rendered it would be greatly appreciated.

 

/ Björn
 

0

Share this post


Link to post
Share on other sites

Hi Bjorn,

 

Just to follow the steps through, here's how i do it ...

 

* render to gbuffer - Color, Normal, Position / Depth

* render shaped lights to light textures (require Normal & Position maps) - skip this for now, but I include it for completeness

* render fullscreen light to fullscreen texture (requires normal texture) - start with this, it's much easier

* render final light map // composes all light maps into one - skip this when you just have a fullscreen lightmap

* render final composition to the default or output depth stencil view - additive blend the final light map with your color (albedo) map

 

So my first comment is that i find it strange that your input looks different as though it were a different frame, or the camera has been moved. So you might have to check that everything is happening in proper sequence.

 

I'm not sure about this line

context.PixelShader.SetShaderResources(0, rendertv)

 

That should be a Shader Resource View, not a Render Target View. The way i do it is by having both SRV & RTV over the same resource, and you use whichever is appropriate for usage. Like this ...

 

            // create light map texture
            resLightMap = new Texture2D(device, resDescription);
            srvLightMap = new ShaderResourceView(device, resLightMap);
            rtvLightMap = new RenderTargetView(device, resLightMap);

 

Let me know how it's going, if you've made progress or if you need more info.

0

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