Results 1 to 5 of 5

Thread: Fetching vertex attributes at different rate

  1. #1
    Member Contributor
    Join Date
    Oct 2011
    Posts
    60

    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
    Join Date
    Oct 2004
    Posts
    4,654
    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
    Member Contributor
    Join Date
    Oct 2011
    Posts
    60
    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
    Join Date
    Oct 2004
    Posts
    4,654
    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
    Member Contributor
    Join Date
    Oct 2011
    Posts
    60
    Thanks! I will try the geom shader approach then.

Similar Threads

  1. Vertex Attributes
    By thatguy in forum OpenGL: Basic Coding
    Replies: 0
    Last Post: 08-22-2011, 05:54 AM
  2. Vertex shader texture fetching problem
    By somboon in forum OpenGL: Basic Coding
    Replies: 5
    Last Post: 08-23-2009, 06:39 PM
  3. Vertex Attributes
    By SeanAustin in forum OpenGL: GLSL
    Replies: 14
    Last Post: 06-24-2009, 06:55 AM
  4. Vertex Attributes
    By Jan in forum OpenGL: Advanced Coding
    Replies: 13
    Last Post: 05-02-2007, 04:59 AM
  5. Replies: 1
    Last Post: 06-11-2004, 02:52 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean