Passing values for each vertex to shader

I’m storing my mesh vertices in vec4 instead of vec3, so that a fourth value vec.w is attributed to each vertex. But this fourth value isn’t passed on to the shader, although the vertex shader works with vec4 for its position values. The fourth values seems to be 1.0 by standard in the shader. Is there any way to pass this fourth value to the vertex shader for each value individually?

probably only through a separate array, or by using one of the other standard shader attributes, eg if you aren’t using normals, you could use them to store extra info.

@Ignatz Thanks for your quick response. Right now I’m using the texCoord attribute, since I’m not applying any textures anyway. I was hoping I maybe could define custom vertex attributes, but too bad :slight_smile:

I want to thank you by the way for your excellent ebooks on shaders and 3D lighting. It once again taught me a whole lot of interesting stuff!

@Kjell you can define custom vertex attributes. See the documentation for the buffer command. I wouldn’t try to use vertex.w as a custom attribute, as you’d have to suppress it when you do the modelViewProjection multiplication, something like gl_Position = modelViewProjection * vec4(position.x, position.y, position.z, 1.);, and as you say, it seems the API is suppressing it anyway, automatically. Best to set up a custom buffer.

Why not just use the built in normals? They are vec3, trivially easy to use, and available in the shader

Sure, but it depends whether you’re already using them, how many custom attributes you need etc. I was responding to

I was hoping I maybe could define custom vertex attributes, but too bad

, letting @Kjell know that you can