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 5 of 5

Thread: Fragment position

  1. #1
    Newbie Newbie
    Join Date
    Nov 2012
    Posts
    3

    Fragment position

    Hey guys. I started openGL ES a month ago, because it was a project requirement and I must say I really love it, so far.

    I had a multi-texturing issue regarding finding a fragment position inside a primitive (rectangle). I needed a fragment position as x = [0.0 - 1.0], y = [0.0 - 1.0]. I found out about gl_FragCoord and gl_PointCoord.

    The first one would give me a fragment coordinate in the window coordinate system which didn't do much for me. At first glance it worked fine, but it was just because the primitive was taking the whole screen, in other words I had no projection.

    gl_PointCoord was somehow always 0. The thing that was confusing about it was what the reference said about "gl_PointCoord is a fragment language input variable that contains the two-dimensional coordinates indicating where within a point primitive the current fragment is located. If the current primitive is not a point, then values read from gl_PointCoord are undefined.", as I'm not exactly sure what a point primitive is. I ended up passing 0.0 - 1.0 coordinates for each vertex and getting a varying value inside the fragment shader, which worked just fine, but I'm sure there's another (better) way to do it.

    Thanks in advance

  2. #2
    Senior Member OpenGL Guru
    Join Date
    May 2009
    Posts
    4,948
    I'm not exactly sure what a point primitive is
    It's a point. That enumerator you use when you draw stuff? GL_TRIANGLES, GL_TRIANGLE_STRIP? That's your primitive. You can also draw GL_LINES and GL_POINTS. Points are basically screen-aligned squares. gl_PointCoord is the location within the point of that fragment.

    I'm sure there's another (better) way to do it
    There isn't. You need gl_PointCoord because points are generated from a single vertex and a size. Since there is only one vertex, the rasterizer has to provide some location within the expanded point primitive.

    When you're dealing with lines and triangles, this isn't necessary (and would be a lot more difficult to define in the general case). It's better to leave it to the user, so that they can pass whatever info they want. After all, OpenGL doesn't know you're rendering quads; all it sees is a single triangle at a time. The best it can give you is barycentric coordinates, which doesn't really help.

  3. #3
    Newbie Newbie
    Join Date
    Nov 2012
    Posts
    3
    Quote Originally Posted by Alfonse Reinheart View Post
    Points are basically screen-aligned squares. gl_PointCoord is the location within the point of that fragment.
    I'm sorry but I don't seem to understand this.

  4. #4
    Senior Member OpenGL Guru Dark Photon's Avatar
    Join Date
    Oct 2004
    Location
    Druidia
    Posts
    3,220
    Quote Originally Posted by Mercurial View Post
    I'm sorry but I don't seem to understand this.
    From the GLSL 4.3 spec:
    The values in gl_PointCoord are two-dimensional coordinates indicating where within a point primitive
    the current fragment is located, when point sprites are enabled. They range from 0.0 to 1.0 across the
    point. If the current primitive is not a point, or if point sprites are not enabled, then the values read from
    gl_PointCoord are undefined.
    Think of point primitives as quads where you only have to pass down a single vertex for the center of the quad. And think of gl_PointCoord like a (0,0)..(1,1) texcoord you can use to lookup the texture value for the current fragment (candidate pixel) in that quad).
    Last edited by Dark Photon; 11-10-2012 at 06:00 PM.

  5. #5
    Newbie Newbie
    Join Date
    Nov 2012
    Posts
    3
    Right, got it now. Definitely have to improve my English, not to ask question twice.

    Thanks a lot

Posting Permissions

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