• FEATURED

View more

View more

View more

### Image of the Day Submit

IOTD | Top Screenshots

### The latest, straight to your Inbox.

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

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

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.

### #1bjornp  Members

Posted 10 March 2013 - 12:19 PM

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:

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

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))



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)
Manager.Render()

'Second stage, does not work fine :(
'context.OutputMerger.SetTargets(renderview)
context.OutputMerger.SetTargets(depthView, renderview)
context.InputAssembler.InputLayout = layout2d                    'Set layout to Pos(float3), TEX
context.ClearRenderTargetView(renderview, Color.Black)
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;

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

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

{
output.Position = input.Position;
output.TexCoord = input.TexCoord;
return output;
}

{
return colorMap.Sample(colorSampler, input.TexCoord);
}


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

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

### #2Gavin Williams  Members

Posted 12 March 2013 - 04:13 AM

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.

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);
rtvLightMap = new RenderTargetView(device, resLightMap);