Full screen quad without vertex buffer?

Started by
8 comments, last by MJP 12 years, 7 months ago
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.
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.
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.
I'm not an OpenGL guy myself, but I think gl_VertexID should let you accomplish the same thing.
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;
}
Wisdom is knowing when to shut up, so try it.
--Game Development http://nolimitsdesigns.com: Reliable UDP library, Threading library, Math Library, UI Library. Take a look, its all free.
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.
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

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.
where is the difference between a fullscreen quad and triangle^^
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).

This topic is closed to new replies.

Advertisement