Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 4 of 4

Thread: FXAA and Fullscreen Triangles

  1. #1
    Intern Newbie
    Join Date
    Jun 2003
    Location
    Australia
    Posts
    49

    FXAA and Fullscreen Triangles

    Hi,

    I was reading Timothy Lottes' FXAA whitepaper and it mentions that it uses fullscreen triangles.

    My current post-processing framework uses fullscreen quads.

    The application setup:
    Code :
    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_program, "PositionNDC", 2, GL_FLOAT, GL_FALSE, 0, BUFFER_OFFSET(0));
    glEnableVertexAttribArray(glGetAttribLocation(m_program, "PositionNDC");

    The vertex shader
    Code :
    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?

  2. #2
    Advanced Member Frequent Contributor
    Join Date
    Dec 2007
    Location
    Hungary
    Posts
    941

    Re: FXAA and Fullscreen Triangles

    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.
    Disclaimer: This is my personal profile. Whatever I write here is my personal opinion and none of my statements or speculations are anyhow related to my employer and as such should not be treated as accurate or valid and in no case should those be considered to represent the opinions of my employer.
    Technical Blog: http://www.rastergrid.com/blog/

  3. #3
    Super Moderator OpenGL Guru
    Join Date
    Feb 2000
    Location
    Montreal, Canada
    Posts
    4,421

    Re: FXAA and Fullscreen Triangles

    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?
    ------------------------------
    Sig: http://glhlib.sourceforge.net
    an open source GLU replacement library. Much more modern than GLU.
    float matrix[16], inverse_matrix[16];
    glhLoadIdentityf2(matrix);
    glhTranslatef2(matrix, 0.0, 0.0, 5.0);
    glhRotateAboutXf2(matrix, angleInRadians);
    glhScalef2(matrix, 1.0, 1.0, -1.0);
    glhQuickInvertMatrixf2(matrix, inverse_matrix);
    glUniformMatrix4fv(uniformLocation1, 1, FALSE, matrix);
    glUniformMatrix4fv(uniformLocation2, 1, FALSE, inverse_matrix);

  4. #4
    Senior Member OpenGL Guru
    Join Date
    May 2009
    Posts
    4,723

    Re: FXAA and Fullscreen Triangles

    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •