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: Billboard that covers always one pixel

  1. #1
    Advanced Member Frequent Contributor _NK47's Avatar
    Join Date
    Mar 2008
    Posts
    574

    Billboard that covers always one pixel

    Happy New Year everyone.

    New year, new problem i can't get my brains on. I have the following need: From any camera position find a scale for the billboard transformation matrix so that the rendered billboard will cover only one pixel in the color buffer. Right now i use a fixed small scale (0.01f) and it sometimes gets draw and sometimes not causing flickering since i test this way the visibility (visible = occlusion_query_passed_samples != 0). Any help and ideas are totally welcome since i have no more ideas from where to start.
    p.s. Points aren't working at all (passed samples always 0).

  2. #2
    Senior Member OpenGL Guru Dark Photon's Avatar
    Join Date
    Oct 2004
    Location
    Druidia
    Posts
    4,398

    Re: Billboard that covers always one pixel

    Do you need to do this with a transformation matrix? You just want to take some point, and spread the quad to cover a pixel. Sounds like a simple vertex shader tweak (delta) on the clip-space XY position.

  3. #3
    Advanced Member Frequent Contributor _NK47's Avatar
    Join Date
    Mar 2008
    Posts
    574

    Re: Billboard that covers always one pixel

    No really with a matrix, whatever works with occlusion query. Transform into clip-space and go from there, i would have thought NDC-space would be better here, no?

  4. #4
    Senior Member OpenGL Guru Dark Photon's Avatar
    Join Date
    Oct 2004
    Location
    Druidia
    Posts
    4,398

    Re: Billboard that covers always one pixel

    Quote Originally Posted by _NK47
    Transform into clip-space and go from there, i would have thought NDC-space would be better here, no?
    Yeah, NDC is what you want, but ideally you'd like this to be a vertex shader thing, and the perspective divide to take you to NDC doesn't happen until after the vertex shader.

    However, you can easily back your NDC adjustment up to clip space by pre-multiplying your NDC XY offsets by gl_Position.w -- as it'll be divided out later in the perspective divide. Then you can do this at the end of the vertex shader in clip space. For instance:

    gl_Position.xy += vec2(ndc_deltax,ndc_deltay) * gl_Position.w;

    Quote Originally Posted by _NK47
    No really with a matrix, whatever works with occlusion query.
    There's no reason that the above should be incompatible with occlusion query if done at the end of the vertex shader. If you've got some vert_offsetx = -1/+1, vert_offsety = -1/+1 for each of your quad verts, then your deltax and deltay are just:

    ndc_delta = vert_offset * scale

    where scale just scales NDC (-1..1) units to pixel resolution units.

    If you have to have this gl_Position.xy adjustment in matrix form, I think this can be smashed onto the end of the gl_Projection fairly nicely:

    Code :
    1 0 0 deltax
    0 1 0 deltay
    0 0 1 0
    0 0 0 1

  5. #5
    Advanced Member Frequent Contributor _NK47's Avatar
    Join Date
    Mar 2008
    Posts
    574

    Re: Billboard that covers always one pixel

    That puts some new thoughts on the design. I will mess with it a bit and might post the source if when done. Thanks for the hints Dark Photon.

Posting Permissions

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