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
[QUOTE=hgwells;1291650]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.[/QUOTE]
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.
[ul]
[li]One is using glDraw*Instanced() calls and in the shader doing a lookup based on gl_InstanceID. [/li][li]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()). [/li][/ul]
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:
[ul]
[li]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. [/li][li]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. [/li][/ul]