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: Fetching vertex attributes at different rate

  1. #1
    Intern Newbie
    Join Date
    Oct 2011
    Posts
    47

    Fetching vertex attributes at different rate

    Is there a way to fetch different vertex attributes at different rate. Like to use new vertex coordinates per every execution of the vertex shader but use the same color for 3 vertices. This would result in the vertex-pos VBO having 3x as many elements as the vertex-color VBO. Can that be done? Thanks!

  2. #2
    Senior Member OpenGL Guru Dark Photon's Avatar
    Join Date
    Oct 2004
    Location
    Druidia
    Posts
    3,125
    ARB_instanced_arrays allows you to fetch different vertex attributes at different rates. This has been in core since OpenGL 3.3.

    However, this is used for instancing (when you want one or more vertex attribute values to be applied to "all" verts in other vtx attribs, not just to one primitive's worth of verts in the other vtx attribs).

    Couple ideas for you. One is you could repeat the color for multiple verts. Another is you could use flat shading so that only the color for only one of the verts is applied to the entire triangle. Or you could lookup the color in the vert shader based on gl_VertexID or similar.

  3. #3
    Intern Newbie
    Join Date
    Oct 2011
    Posts
    47
    Thanks! Actually, I wanted to do text rendering and particles, where I want to provide the center of a quad while its 4 points are calculated in the vertex shader(as the width of the quads is fixed). ....so I would need to store 1 position, 1 color, 4 texture-coords per quad(2 triangles).

    Geometry shader: can I use that while I cant calculate the texture coords in the shader?
    Instanced rendering: how much slower would it be compared to providing all the (unnecessary) data for all vertex attribs and use a normal draw call? and compared to the geometry shader?

    As I understand, instanced rendering works well when the instanced objects are complex, not like in this case with 4 vertices.

  4. #4
    Senior Member OpenGL Guru Dark Photon's Avatar
    Join Date
    Oct 2004
    Location
    Druidia
    Posts
    3,125
    Quote Originally Posted by Aliii View Post
    Thanks! Actually, I wanted to do text rendering and particles, where I want to provide the center of a quad while its 4 points are calculated in the vertex shader(as the width of the quads is fixed). ....so I would need to store 1 position, 1 color, 4 texture-coords per quad(2 triangles).

    Geometry shader: can I use that while I cant calculate the texture coords in the shader?
    Yes. A geometry shader is actually good for the simple point-to-quad spread operation you're describing. You can easily calculate your texture coordinates in the shader, as well as compute your quad positions based on some dimension you pass in or compute in the shader.

    Instanced rendering: how much slower would it be compared to providing all the (unnecessary) data for all vertex attribs and use a normal draw call? and compared to the geometry shader?
    As I said, it doesn't sound like instancing is the problem you have. Do the geom shader pt-to-quad spread, and it sounds like you want to just rip a standard draw call. Now if instead your input data for each resulting primitive wasn't a single vertex but a number of vertices, and you had a number of them, that's when you'd want to use instancing. And yes, instanced rendering can be very efficient because it reduces CPU overhead dispatching batches.

  5. #5
    Intern Newbie
    Join Date
    Oct 2011
    Posts
    47
    Thanks! I will try the geom shader approach then.

Posting Permissions

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