I’m wondering what’s the best way to send custom vertex data to a shader within the mesh geometry.
Let me explain my question.
I want to draw a mesh using extra per-vertex data at the shader.
At this post by @edapx, you can find a way to add custom data into the VBO of a ofVboMesh…
But this method requires the attrib location of an attribute inside an specific shader. So those data will not work in a different shader.
- I do have different 2 shaders (program_01 and program_02) and a ofVboMesh. with a simple triangle.
- I do want to add some custom color data to the triangle VBO so I can use it at the shaders.
// Locate ‘custom_color’ attribute
GLint attLoc1 = program_01.getAttributeLocation(“custom_color”); // located at 2
GLint attLoc2 = program_02.getAttributeLocation(“custom_color”); // located at 1
// set custom Vertex Color Data
mesh.getVbo().setAttributeData(attLoc1, glm::value_ptr(colorData), 3, 3*3, GL_STATIC_DRAW, sizeof(glm::vec3));
This is the result:
Only one of the shaders uses correctly the data, because the custom_color data was located at the VBO using the reference to the program_01 and the same attribute has a different location at program_02.
Does it mean I do have to duplicate the custom data and set a different Vertex Attribute for each shader/location?
I’ve tried using ofShader::bindAttribute() but did not work.
What’s the best way to add custom vertex data to a mesh and use it on multiple shaders?
Better if the solution does not involve manual handling the data binding/unbinding each time the shader begins.
Thanks for your help and greetings