I’m pretty new to (mesh based) instance rendering, so I hope you’ll bare with me on four rookie questions:
Q 1
Do OpenGL state calls impact instanced rendering? For example, will gl::scale()
change the scale of any mesh rendered via the drawInstanced()
call?
My testing so far suggests ‘No’. Which leads to these follow up questions:
Q 2
Do any OpenGL state calls impact instance rendering? Enabling/Disabling the depth buffer definitely impacts the instance rendering as intended. So my assumption is that states that aren’t ‘mesh rendering’ related, work as normal, but anything that might touch the instance mesh won’t work?
Q 3
This being the case, if I wanted to scale my instances, it would seem that there are two ideal approaches to this:
If I want to scale all instances the same: Create a shader uniform value and have that alter the model matrix in the vertex shader.
If I want to scale all instances differently: Attach a custom value (float or full on transform matrix) to the Vbo and apply this in the shader.
Does this sound reasonable?
Q 4
Is it possible to pass per-vertex coloring to geometry rendered via instanced rendering?
Thanks to awesome libcinder, it’s pretty easy to get some default color variety when instancing meshes. All it takes (apparently) is this type of call: ci::gl::VboMesh::create( ci::geom::Cube().colors() );
, where colors()
is used, and then ensuring that the shaders also support the incoming color values.
But what if I wanted to replace the colors of a cube instance with per-vertex colors?
If I want to have a single color per-instance (not per vertex), I believe the call to setup the Vbo layout looks as follows:
ci::geom::BufferLayout instanceDataLayout;
instanceDataLayout.append( ci::geom::Attrib::COLOR, 4, sizeof( ci::ColorA ), 0, 1 );
The last parameter being set to 1
I believe is the ‘per instance’ count.
Is this the value I need to tweak to be equal to ‘vertex count per mesh’ to have it work like a per-vertex per-instance effect…?
~Gazyou