• Advertisement
Sign in to follow this  

Full screen quad without vertex buffer?

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

How do people generally render full screen quads (such as for deferred shading)? Do you actually upload a quad in your vertex buffer along with all of your other geometry? Do you have a separate vertex buffer just for the quad, since it doesn't need all of the vertex attributes that the rest of your geometry uses? Do you use old-school immediate mode commands to render the quad without a vertex buffer? Or is there a way to simulate quad vertices within a vertex shader without uploading anything?

I'm curious how other people typically handle this.

Share this post


Link to post
Share on other sites
Advertisement
With DX10 or DX11 you can render a quad or fullscreen triangle without a vertex buffer. Basically you bind NULL for your vertex buffer, index buffer, and input layout and draw 3 or 6 vertices. Then in your vertex shader, you take SV_VertexID as an input and use that to position the vertex. I still have code lying around that draws fullscreen quads with a vertex and index buffer since was made for DX9, but lately when I write new code I'll use the above method since it's way easier than setting up the necessary resources.

Share this post


Link to post
Share on other sites
I guess I should have mentioned I'm using OpenGL 3.2, I didn't realize there were platform-specific ways to accomplish this. I'll have to look and see if OpenGL has something similar to what you describe.

Share this post


Link to post
Share on other sites
This is the DX code implementing what MJP said. You should be able to convert it to opengl. Remember, opengl has their texcoord (0, 0) at the bottom left, where directx is top left.


struct VSQuadOut{
float4 position : SV_Position;
float2 texcoord: TexCoord;
};
VSQuadOut VSQuad(uint VertexID: SV_VertexID){// ouputs a full screen quad with tex coords
VSQuadOut Out;
Out.texcoord = float2( (VertexID << 1) & 2, VertexID & 2 );
Out.position = float4( Out.texcoord * float2( 2.0f, -2.0f ) + float2( -1.0f, 1.0f), 0.0f, 1.0f );
return Out;
}

Share this post


Link to post
Share on other sites
Huh. I'd always thought there should be a better way, but I hadn't bought of doing it in the shader. Thanks for the tip, MJP.

Share this post


Link to post
Share on other sites

take a look at the FSAA code(http://timothylottes.blogspot.com), in the vertex shader he uses only 3 vertex IDs to generate the fullscreen texture coordinates

That is because he renders a full screen triangle instead of a quad.

Share this post


Link to post
Share on other sites
A fullscreen triangle is slightly more efficient since you get maximum quad occupancy in your fragment shader (fragments are always shaded in 2x2 quads, and with a fullscreen quad you will end up with partially-occupied quads along the triangle edge).

Share this post


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

  • Advertisement