Discussion:
Vertex shader generating UV coordinates?
(too old to reply)
Edward Brekelbaum
2015-09-24 01:11:51 UTC
Permalink
Raw Message
Hello all,

I have a simple model with a lot of triangles. To reduce bandwidth, I'd like to use a VBO with the unique vertex coordinates, and have the vertex shader generate the UV values (they're always {0, 1} {0, 0}, {1, 0} for each triangle) for the fragment shader.

Is this possible? I don't think my current setup allows for any other shader stages...

Thanks!
Nobody
2015-09-27 23:55:38 UTC
Permalink
Raw Message
Post by Edward Brekelbaum
I have a simple model with a lot of triangles. To reduce bandwidth, I'd
like to use a VBO with the unique vertex coordinates, and have the vertex
shader generate the UV values (they're always {0, 1} {0, 0}, {1, 0} for
each triangle) for the fragment shader.
Is this possible? I don't think my current setup allows for any other shader stages...
How does the vertex shader know which vertex should have which UV coordinates?

If you're rendering distinct triangles (rather than strips or fans), you
could use gl_VertexID % 3. Otherwise, you need some other way for the
vertex shader to know which of a triangle's vertices it's dealing with.

In the worst case, you can compress the UV coordinates down to one byte
per vertex, i.e. have a an extra attribute whose value is 0, 1 or 2 (or
-1, 0 or 1) which is then expanded to a (u,v) pair.
Edward Brekelbaum
2015-10-02 02:03:46 UTC
Permalink
Raw Message
Post by Nobody
Post by Edward Brekelbaum
I have a simple model with a lot of triangles. To reduce bandwidth, I'd
like to use a VBO with the unique vertex coordinates, and have the vertex
shader generate the UV values (they're always {0, 1} {0, 0}, {1, 0} for
each triangle) for the fragment shader.
Is this possible? I don't think my current setup allows for any other shader stages...
How does the vertex shader know which vertex should have which UV coordinates?
If you're rendering distinct triangles (rather than strips or fans), you
could use gl_VertexID % 3. Otherwise, you need some other way for the
vertex shader to know which of a triangle's vertices it's dealing with.
In the worst case, you can compress the UV coordinates down to one byte
per vertex, i.e. have a an extra attribute whose value is 0, 1 or 2 (or
-1, 0 or 1) which is then expanded to a (u,v) pair.
Thanks. I think I will go with sending an extra byte per vertex.
Loading...