Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Passing values for each vertex to shader

in Shaders Posts: 82

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?

Tagged:

Comments

  • IgnatzIgnatz Mod
    Posts: 5,396

    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.

  • Posts: 82
    @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 :)

    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!
  • edited January 2016 Posts: 2,020

    @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.

  • IgnatzIgnatz Mod
    Posts: 5,396

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

  • edited January 2016 Posts: 2,020

    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

Sign In or Register to comment.