PDA

View Full Version : FXAA and Fullscreen Triangles



dpoon
08-27-2011, 12:23 AM
Hi,

I was reading Timothy Lottes' FXAA whitepaper (http://developer.download.nvidia.com/assets/gamedev/files/sdk/11/FXAA_WhitePaper.pdf) and it mentions that it uses fullscreen triangles.

My current post-processing framework uses fullscreen quads.

The application setup:


float quad[] =
{
-1.0f, 1.0f, // top left corner
-1.0f, -1.0f, // bottom left corner
1.0f, 1.0f, // top right corner
1.0f, -1.0f // bottom right corner
};

glGenVertexArrays(1, &m_vertexArrayObject);
glBindVertexArray(m_vertexArrayObject);

glGenBuffers(1, &m_vertexBufferObject);
glBindBuffer(GL_ARRAY_BUFFER, m_vertexBufferObject);
glBufferData(GL_ARRAY_BUFFER, sizeof(quad), quad, GL_STATIC_DRAW);

glVertexAttribPointer(glGetAttribLocation(m_progra m, "PositionNDC", 2, GL_FLOAT, GL_FALSE, 0, BUFFER_OFFSET(0));
glEnableVertexAttribArray(glGetAttribLocation(m_pr ogram, "PositionNDC");


The vertex shader


in vec2 PositionNDC;
out vec2 Texcoord;

void main()
{
gl_Position = vec4(PositionNDC, 0.0, 1.0);
Texcoord = PositionNDC * 0.5 + 0.5;
}


How does one setup a fullscreen triangle for use in post-processing effects?

Most modern GPUs work on groups of pixels so for a fullscreen quad rendered as 2 triangles the main diagonal will have overlapping groups of pixels for the GPU to process. So I can see the benefits of a fullscreen triangle. But is there much difference in real world performance over fullscreen quads?

aqnuep
08-27-2011, 03:49 AM
There isn't much difference between using a fullscreen quad or a fullscreen triangle, however you can save a few % of performance by using a triangle, as as you said, because of the overlapping groups, some parts of the screen get processed twice.

V-man
08-28-2011, 07:04 AM
There shouldn't be any overlapping pixels if the vertices are shared between the 2 triangle edges.
If there is, then the GL implementation isn't compliant with the gl specification.

As for rendering only 1 triangle vs 2 triangles, you think there will be a difference in performance?

Alfonse Reinheart
08-28-2011, 01:01 PM
There shouldn't be any overlapping pixels if the vertices are shared between the 2 triangle edges.

No, there won't be any overlapping rendered pixels. But there will be overlapping fragment shaders along the main diagonal. Fragment shaders run in blocks of neighboring samples, and along the main diagonal, shaders will be run twice. The results may ultimately be discarded, but the shader will be executed multiple times for those samples.