Jump to content

  • Log In with Google      Sign In   
  • Create Account

Full screen quad without vertex buffer?


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.

  • You cannot reply to this topic
9 replies to this topic

#1 Nairou   Members   -  Reputation: 418

Like
0Likes
Like

Posted 03 September 2011 - 12:02 PM

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.

Sponsor:

#2 MJP   Moderators   -  Reputation: 11367

Like
3Likes
Like

Posted 03 September 2011 - 12:36 PM

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.

#3 Nairou   Members   -  Reputation: 418

Like
0Likes
Like

Posted 03 September 2011 - 12:55 PM

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.

#4 MJP   Moderators   -  Reputation: 11367

Like
1Likes
Like

Posted 03 September 2011 - 02:10 PM

I'm not an OpenGL guy myself, but I think gl_VertexID should let you accomplish the same thing.

#5 smasherprog   Members   -  Reputation: 432

Like
2Likes
Like

Posted 03 September 2011 - 08:11 PM

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.

#6 yckx   Prime Members   -  Reputation: 1210

Like
0Likes
Like

Posted 04 September 2011 - 08:34 PM

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.

#7 Danny02   Members   -  Reputation: 275

Like
0Likes
Like

Posted 05 September 2011 - 12:18 PM

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

#8 B_old   Members   -  Reputation: 664

Like
0Likes
Like

Posted 05 September 2011 - 12:32 PM

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.

#9 Danny02   Members   -  Reputation: 275

Like
0Likes
Like

Posted 05 September 2011 - 03:35 PM

where is the difference between a fullscreen quad and triangle^^

#10 MJP   Moderators   -  Reputation: 11367

Like
1Likes
Like

Posted 05 September 2011 - 03:59 PM

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




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.



PARTNERS