Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pass custom attributes to a custom fragment shader

Is it possible to pass custom attributes to a fragment shader, i know i can pass attributes via GLES20.glVertexAttribPointer to the vertex shader, but how can i pass a float[] to the fragment shader?

like image 956
teamalpha5441 Avatar asked Jul 19 '12 18:07

teamalpha5441


2 Answers

No.

If you want to pass uniforms to a fragment shader, you can easily do that (see any tutorial). But if you want something similar to the per-vertex attributes, then it makes no sense to do that. What you can also do is pass attributes to the vertex shader, and then in the vertex shader pass them through to the fragment shader as varyings. They will be interpolated across the primitive and provided as inputs to the fragment shader.

like image 142
Tim Avatar answered Nov 06 '22 13:11

Tim


Tim's answer is of course correct.

A possible workaround would be to store your float values in a 2D texture and pass the texture coordinates (and the number of values) to the shader. However, this can become really slow if you have large numbers of float values per vertex (because of all the texture lookups per fragment). Another problem is that this results in very large textures if you have a lot of vertices. Anyway, in some cases this approach can be useful.

like image 1
kroneml Avatar answered Nov 06 '22 13:11

kroneml