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

Thread: Set attribute values

  1. #1
    Junior Member Newbie
    Join Date
    Jan 2018
    Posts
    4

    Set attribute values

    hello. I need help to do the next stuff:

    im in processing, and i have an array of objects. what i want, is that every object send a different value to a one shader. For example, imagine a value for "velocity", what i want is that each object `ve different value of velocity. I try sending via an uniform variable, but is not working becouse uniform is a constant. I think that attribute is working better, but i dont know how write a new attribute in processing and send it to a vertex, and next to a fragment. Is this right? is there any other way to use one shader, but in different stages for each object?
    THANKS A LOT

  2. #2
    Senior Member OpenGL Guru Dark Photon's Avatar
    Join Date
    Oct 2004
    Location
    Druidia
    Posts
    4,478
    Quote Originally Posted by hgwells View Post
    i have an array of objects.
    what i want, is that every object send a different value to a one shader.
    For example, imagine a value for "velocity", what i want is that each object `ve different value of velocity.
    What you seem to be describing here is "per-instance" data. That is data which is constant across all of the shader executions for a single object instance but varies between instances.

    There are two common ways to do this.

    • One is using glDraw*Instanced() calls and in the shader doing a lookup based on gl_InstanceID.
    • The second is using "instanced arrays" and basically designating vertex attributes which store one value per instance rather than one value per vertex (this technique makes use of the glVertexAttribDivisor()).

    For more on these, see:

    I try sending via an uniform variable, but is not working becouse uniform is a constant.
    I think that attribute is working better, but i dont know how write a new attribute in processing and send it to a vertex, and next to a fragment.
    Is this right?
    is there any other way to use one shader, but in different stages for each object?
    Ok, so it's sounds like you don't just want 1 value per instance, but rather 1 value per instance per shader. Is that right?

    Just treat this like the 1 value per instance case, but use N values instead. That is:

    • For the glDraw*Instanced() approach, you can do separate lookups in your vertex and fragment shaders based on gl_InstanceID to retrieve values specific to that shader stage.
    • For the instanced array approach, you can plumb in multiple per-instance attributes and then just feed the one destinated for the fragment shader through the vertex shader, relaying to to the fragment shader via an interpolant.

Posting Permissions

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