• Vertex shader generating UV coordinates?

    From Edward Brekelbaum@21:1/5 to All on Wed Sep 23 18:11:51 2015
    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!

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Nobody@21:1/5 to Edward Brekelbaum on Mon Sep 28 00:55:38 2015
    On Wed, 23 Sep 2015 18:11:51 -0700, Edward Brekelbaum wrote:

    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.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Edward Brekelbaum@21:1/5 to Nobody on Thu Oct 1 19:03:46 2015
    On Sunday, September 27, 2015 at 6:55:03 PM UTC-5, Nobody wrote:
    On Wed, 23 Sep 2015 18:11:51 -0700, Edward Brekelbaum wrote:

    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.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)