On 03/12/2012 03:40 PM, Jason Daly wrote:
On 03/12/2012 02:21 PM, Ethan Fahy wrote:
Thanks Jason,

So, since I can't combine programs (I didn't necessarily mean multiple shaders, 
I just meant multiple programs), I decided to take this line of code:

program->addBindAttribLocation("indices", 6);

and move it to where I assemble my shader program and attach it to the node's 
stateset.  This way my nodeVisitor can still set my generic vertex array in 
position 6 and my osg::Program's shader can access those index values by 
including the following line in the frag shader:

in float indices;

I looked at the osg file that I wrote to disk and verified that my stateset's 
program contained this line:

AttribBindingLocation indices 6

However, when I use indices in my shader, the resulting value is always equal 
to 0.0, even though my VertexAttributeArray values range from 0.0 to 124.0.  I 
don't want to impose on you too much since you've already helped me out a great 
deal, but I'm going to go ahead and attach an osg file that demonstrates this 
behavior.  The file is a simple human shape with 125 primitives.  I created a 
generic vertex array with index values sequential from 0-124.  I also attached 
a simple shader that paints everything green if the indices = 0 and red 
otherwise.  As you can see by opening this file in osgviewer, all values are 
green.  If you have time to look at it that would be fantastic but I completely 
understand if you don't.  Thanks again,

It seems that generic vertex attributes don't work in PER_PRIMITIVE mode (at least not with shaders). Changing the binding to PER_VERTEX (and adding enough values to cover all the vertices) makes it work. Have a look:

--"J"
Geode {
  nodeMask 0xffffffff
  cullingActive TRUE
  StateSet {
    rendering_hint DEFAULT_BIN
    renderBinMode USE
    binNumber 6
    binName RenderBin
    GL_LIGHTING OFF
    Program {
      name "Environment"
      GeometryVerticesOut 1
      GeometryInputType TRIANGLES
      GeometryOutputType TRIANGLE_STRIP
      AttribBindingLocation indices 6
      num_shaders 2
      Shader {
        type FRAGMENT
        code {
          "varying float fIndices;
"
          "void main(void)
"
          "{
"
          "     vec4 color = gl_Color;
"
          "     
"
          "     if( fIndices == 0.0 ){
"
          "             color.r = 0.0;
"
          "             color.g = 1.0;
"
          "             color.b = 0.0;
"
          "     }else{
"
          "             color.r = 1.0;
"
          "             color.g = 0.0;
"
          "             color.b = 0.0;
"
          "     }
"
          "     
"
          "     gl_FragColor = color;
"
          "     
"
          "}"
        }
      }
      Shader {
        type VERTEX
        code {
          "attribute float indices;
"
          "varying float fIndices;
"
          "void main(void)
"
          "{  
"
          "    gl_FrontColor = gl_Color;
"
          "     gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;"
          "     fIndices = indices; 
"
          "}"
        }
      }
    }
    textureUnit 0 {
    }
    textureUnit 1 {
      GL_TEXTURE_2D ON
      Texture2D {
        UniqueID Texture2D_0
        wrap_s CLAMP_TO_EDGE
        wrap_t CLAMP_TO_EDGE
        wrap_r CLAMP_TO_EDGE
        min_filter NEAREST
        mag_filter NEAREST
        maxAnisotropy 1
        borderColor 0 0 0 0
        borderWidth 0
        useHardwareMipMapGeneration TRUE
        unRefImageDataAfterApply FALSE
        internalFormatMode USE_IMAGE_DATA_FORMAT
        resizeNonPowerOfTwo FALSE
        shadowComparison FALSE
        shadowCompareFunc GL_LEQUAL
        shadowTextureMode GL_LUMINANCE
      }
    }
  }
  num_drawables 1
  Geometry {
    useDisplayList TRUE
    useVertexBufferObjects FALSE
    PrimitiveSets 125
    {
      DrawElementsUInt QUADS 4
      {
        0 1 2 3 
      }
      DrawElementsUInt QUADS 4
      {
        3 4 5 0 
      }
      DrawElementsUInt QUADS 4
      {
        1 6 7 2 
      }
      DrawElementsUInt QUADS 4
      {
        5 4 7 6 
      }
      DrawElementsUInt QUADS 4
      {
        8 9 10 11 
      }
      DrawElementsUInt QUADS 4
      {
        9 12 13 10 
      }
      DrawElementsUInt QUADS 4
      {
        10 16 17 11 
      }
      DrawElementsUInt QUADS 4
      {
        10 13 18 16 
      }
      DrawElementsUInt QUADS 4
      {
        13 14 19 18 
      }
      DrawElementsUInt QUADS 4
      {
        17 20 22 11 
      }
      DrawElementsUInt QUADS 4
      {
        22 20 21 23 
      }
      DrawElementsUInt QUADS 4
      {
        23 21 19 14 
      }
      DrawElementsUInt QUADS 4
      {
        17 16 24 25 
      }
      DrawElementsUInt QUADS 4
      {
        16 18 26 24 
      }
      DrawElementsUInt QUADS 4
      {
        18 19 27 26 
      }
      DrawElementsUInt QUADS 4
      {
        25 28 20 17 
      }
      DrawElementsUInt QUADS 4
      {
        20 28 29 21 
      }
      DrawElementsUInt QUADS 4
      {
        29 27 19 21 
      }
      DrawElementsUInt QUADS 4
      {
        29 28 26 27 
      }
      DrawElementsUInt QUADS 4
      {
        26 28 25 24 
      }
      DrawElementsUInt TRIANGLES 3
      {
        9 30 12 
      }
      DrawElementsUInt QUADS 4
      {
        30 3 2 12 
      }
      DrawElementsUInt QUADS 4
      {
        30 15 4 3 
      }
      DrawElementsUInt QUADS 4
      {
        7 15 12 2 
      }
      DrawElementsUInt TRIANGLES 3
      {
        15 7 4 
      }
      DrawElementsUInt QUADS 4
      {
        12 15 14 13 
      }
      DrawElementsUInt QUADS 4
      {
        33 36 37 32 
      }
      DrawElementsUInt QUADS 4
      {
        31 32 37 35 
      }
      DrawElementsUInt QUADS 4
      {
        38 41 40 39 
      }
      DrawElementsUInt QUADS 4
      {
        39 40 43 42 
      }
      DrawElementsUInt QUADS 4
      {
        40 41 47 46 
      }
      DrawElementsUInt QUADS 4
      {
        40 46 48 43 
      }
      DrawElementsUInt QUADS 4
      {
        43 48 49 44 
      }
      DrawElementsUInt QUADS 4
      {
        47 41 52 50 
      }
      DrawElementsUInt QUADS 4
      {
        52 53 51 50 
      }
      DrawElementsUInt QUADS 4
      {
        53 44 49 51 
      }
      DrawElementsUInt QUADS 4
      {
        47 55 54 46 
      }
      DrawElementsUInt QUADS 4
      {
        46 54 56 48 
      }
      DrawElementsUInt QUADS 4
      {
        48 56 57 49 
      }
      DrawElementsUInt QUADS 4
      {
        55 47 50 58 
      }
      DrawElementsUInt QUADS 4
      {
        50 51 59 58 
      }
      DrawElementsUInt QUADS 4
      {
        59 51 49 57 
      }
      DrawElementsUInt QUADS 4
      {
        59 57 56 58 
      }
      DrawElementsUInt QUADS 4
      {
        56 54 55 58 
      }
      DrawElementsUInt TRIANGLES 3
      {
        39 42 60 
      }
      DrawElementsUInt QUADS 4
      {
        60 42 36 34 
      }
      DrawElementsUInt QUADS 4
      {
        60 34 35 45 
      }
      DrawElementsUInt QUADS 4
      {
        37 36 42 45 
      }
      DrawElementsUInt TRIANGLES 3
      {
        45 35 37 
      }
      DrawElementsUInt QUADS 4
      {
        42 43 44 45 
      }
      DrawElementsUInt QUADS 4
      {
        38 8 11 41 
      }
      DrawElementsUInt QUADS 4
      {
        11 22 52 41 
      }
      DrawElementsUInt QUADS 4
      {
        22 23 53 52 
      }
      DrawElementsUInt QUADS 4
      {
        23 14 44 53 
      }
      DrawElementsUInt QUADS 4
      {
        14 15 45 44 
      }
      DrawElementsUInt QUADS 4
      {
        61 31 35 34 
      }
      DrawElementsUInt QUADS 4
      {
        34 36 33 61 
      }
      DrawElementsUInt QUADS 4
      {
        70 71 72 73 
      }
      DrawElementsUInt QUADS 4
      {
        68 71 70 69 
      }
      DrawElementsUInt TRIANGLES 3
      {
        69 70 67 
      }
      DrawElementsUInt TRIANGLES 3
      {
        67 70 66 
      }
      DrawElementsUInt QUADS 4
      {
        66 70 73 62 
      }
      DrawElementsUInt TRIANGLES 3
      {
        62 73 63 
      }
      DrawElementsUInt TRIANGLES 3
      {
        63 73 65 
      }
      DrawElementsUInt QUADS 4
      {
        65 73 72 64 
      }
      DrawElementsUInt QUADS 4
      {
        71 68 64 72 
      }
      DrawElementsUInt QUADS 4
      {
        74 75 76 77 
      }
      DrawElementsUInt QUADS 4
      {
        78 79 75 74 
      }
      DrawElementsUInt QUADS 4
      {
        74 77 80 78 
      }
      DrawElementsUInt QUADS 4
      {
        77 76 81 80 
      }
      DrawElementsUInt QUADS 4
      {
        75 79 81 76 
      }
      DrawElementsUInt QUADS 4
      {
        82 83 84 85 
      }
      DrawElementsUInt QUADS 4
      {
        83 86 87 84 
      }
      DrawElementsUInt QUADS 4
      {
        84 90 91 85 
      }
      DrawElementsUInt QUADS 4
      {
        84 87 92 90 
      }
      DrawElementsUInt QUADS 4
      {
        87 88 93 92 
      }
      DrawElementsUInt QUADS 4
      {
        91 94 96 85 
      }
      DrawElementsUInt QUADS 4
      {
        96 94 95 97 
      }
      DrawElementsUInt QUADS 4
      {
        97 95 93 88 
      }
      DrawElementsUInt QUADS 4
      {
        91 90 98 99 
      }
      DrawElementsUInt QUADS 4
      {
        90 92 100 98 
      }
      DrawElementsUInt QUADS 4
      {
        92 93 101 100 
      }
      DrawElementsUInt QUADS 4
      {
        99 102 94 91 
      }
      DrawElementsUInt QUADS 4
      {
        94 102 103 95 
      }
      DrawElementsUInt QUADS 4
      {
        103 101 93 95 
      }
      DrawElementsUInt QUADS 4
      {
        103 102 100 101 
      }
      DrawElementsUInt QUADS 4
      {
        100 102 99 98 
      }
      DrawElementsUInt TRIANGLES 3
      {
        83 104 86 
      }
      DrawElementsUInt QUADS 4
      {
        104 78 80 86 
      }
      DrawElementsUInt QUADS 4
      {
        104 89 79 78 
      }
      DrawElementsUInt QUADS 4
      {
        81 89 86 80 
      }
      DrawElementsUInt TRIANGLES 3
      {
        89 81 79 
      }
      DrawElementsUInt QUADS 4
      {
        86 89 88 87 
      }
      DrawElementsUInt QUADS 4
      {
        105 108 107 106 
      }
      DrawElementsUInt QUADS 4
      {
        109 105 106 110 
      }
      DrawElementsUInt QUADS 4
      {
        105 109 111 108 
      }
      DrawElementsUInt QUADS 4
      {
        108 111 112 107 
      }
      DrawElementsUInt QUADS 4
      {
        106 107 112 110 
      }
      DrawElementsUInt QUADS 4
      {
        113 116 115 114 
      }
      DrawElementsUInt QUADS 4
      {
        114 115 118 117 
      }
      DrawElementsUInt QUADS 4
      {
        115 116 122 121 
      }
      DrawElementsUInt QUADS 4
      {
        115 121 123 118 
      }
      DrawElementsUInt QUADS 4
      {
        118 123 124 119 
      }
      DrawElementsUInt QUADS 4
      {
        122 116 127 125 
      }
      DrawElementsUInt QUADS 4
      {
        127 128 126 125 
      }
      DrawElementsUInt QUADS 4
      {
        128 119 124 126 
      }
      DrawElementsUInt QUADS 4
      {
        122 130 129 121 
      }
      DrawElementsUInt QUADS 4
      {
        121 129 131 123 
      }
      DrawElementsUInt QUADS 4
      {
        123 131 132 124 
      }
      DrawElementsUInt QUADS 4
      {
        130 122 125 133 
      }
      DrawElementsUInt QUADS 4
      {
        125 126 134 133 
      }
      DrawElementsUInt QUADS 4
      {
        134 126 124 132 
      }
      DrawElementsUInt QUADS 4
      {
        134 132 131 133 
      }
      DrawElementsUInt QUADS 4
      {
        131 129 130 133 
      }
      DrawElementsUInt TRIANGLES 3
      {
        114 117 135 
      }
      DrawElementsUInt QUADS 4
      {
        135 117 111 109 
      }
      DrawElementsUInt QUADS 4
      {
        135 109 110 120 
      }
      DrawElementsUInt QUADS 4
      {
        112 111 117 120 
      }
      DrawElementsUInt TRIANGLES 3
      {
        120 110 112 
      }
      DrawElementsUInt QUADS 4
      {
        117 118 119 120 
      }
      DrawElementsUInt QUADS 4
      {
        113 82 85 116 
      }
      DrawElementsUInt QUADS 4
      {
        85 96 127 116 
      }
      DrawElementsUInt QUADS 4
      {
        96 97 128 127 
      }
      DrawElementsUInt QUADS 4
      {
        97 88 119 128 
      }
      DrawElementsUInt QUADS 4
      {
        88 89 120 119 
      }
    }
    VertexArray Vec3Array 136
    {
      -0.0599923 -0.241477 0.807598
      -0.0599923 -0.174467 0.807598
      -0.0599923 -0.174467 1.39265
      -0.0599923 -0.241477 1.39265
      -0.130444 -0.241477 1.39265
      -0.130444 -0.241477 0.807598
      -0.130444 -0.174467 0.807598
      -0.130444 -0.174467 1.39265
      4.76361e-007 -0.0414642 1.47751
      8.15046e-006 -0.138539 1.47751
      8.15046e-006 -0.137861 0.825657
      4.76361e-007 -0.0407867 0.825657
      -0.0599923 -0.154934 1.41695
      -0.0619919 -0.154316 0.825657
      -0.196896 -0.125441 0.825657
      -0.196896 -0.126118 1.47751
      8.15046e-006 -0.137131 0.128711
      4.7636e-007 -0.0400641 0.128711
      -0.0619919 -0.153586 0.128711
      -0.196896 -0.124711 0.128711
      -0.0619919 -0.0235864 0.128711
      -0.167769 -0.0235864 0.128711
      -0.0619919 -0.0242789 0.78884
      -0.167769 -0.0242789 0.78884
      0.0546315 -0.136454 -6.01868e-008
      0.0546315 -0.0421793 -6.01868e-008
      -0.00736859 -0.152909 -6.01867e-008
      -0.196896 -0.125441 -6.01867e-008
      -0.00536129 -0.0257091 -6.01867e-008
      -0.167769 -0.0243166 -6.01867e-008
      -0.0599923 -0.154994 1.47751
      -0.130444 0.251837 0.807598
      -0.130444 0.184827 0.807598
      -0.0599923 0.184827 0.807598
      -0.0599923 0.251837 1.39265
      -0.130444 0.251837 1.39265
      -0.0599923 0.184827 1.39265
      -0.130444 0.184827 1.39265
      4.76361e-007 0.051824 1.47751
      8.15046e-006 0.148899 1.47751
      8.15046e-006 0.148221 0.825657
      4.76361e-007 0.0511465 0.825657
      -0.0599923 0.165293 1.41695
      -0.0619919 0.164676 0.825657
      -0.196896 0.140942 0.825657
      -0.196896 0.141619 1.47751
      8.15046e-006 0.147491 0.128711
      4.7636e-007 0.0504239 0.128711
      -0.0619919 0.163946 0.128711
      -0.196896 0.140212 0.128711
      -0.0619919 0.0339462 0.128711
      -0.167769 0.0339462 0.128711
      -0.0619919 0.0346388 0.78884
      -0.167769 0.0346388 0.78884
      0.0546315 0.146813 -6.01868e-008
      0.0546315 0.0525391 -6.01868e-008
      -0.00736859 0.163269 -6.01867e-008
      -0.196896 0.140942 -6.01867e-008
      -0.00536129 0.036069 -6.01867e-008
      -0.167769 0.0346764 -6.01867e-008
      -0.0619919 0.165354 1.47751
      -0.0599923 0.251837 0.807598
      -0.00199944 -0.0434678 1.4775
      -0.00199188 -0.136537 1.4775
      -0.194896 -0.126114 1.4775
      -0.0619937 -0.152993 1.4775
      -0.00199944 0.0538276 1.4775
      -0.00199188 0.146897 1.4775
      -0.194896 0.141618 1.4775
      -0.0619937 0.163353 1.4775
      -0.0346896 0.0616674 1.73477
      -0.181714 0.0616674 1.73477
      -0.181714 -0.0513075 1.73477
      -0.0346896 -0.0513075 1.73477
      -0.0619937 -0.239477 0.742593
      -0.128443 -0.239477 0.742593
      -0.128443 -0.176468 0.742593
      -0.0619937 -0.176468 0.742593
      -0.0619937 -0.239477 1.39263
      -0.128443 -0.239477 1.39263
      -0.0619937 -0.176468 1.39263
      -0.128443 -0.176468 1.39263
      -0.00199944 -0.0434678 1.4775
      -0.00199188 -0.136537 1.4775
      -0.00199188 -0.135858 0.825642
      -0.00199944 -0.0427883 0.825642
      -0.0619937 -0.152933 1.42095
      -0.0619937 -0.152314 0.825642
      -0.194896 -0.125442 0.825642
      -0.194896 -0.126114 1.4775
      -0.00199188 -0.135133 0.128728
      -0.00199944 -0.0420641 0.128728
      -0.0619937 -0.151589 0.128728
      -0.194896 -0.12471 0.128728
      -0.0619937 -0.0255931 0.128728
      -0.165768 -0.0255931 0.128728
      -0.0619937 -0.02628 0.790847
      -0.165768 -0.02628 0.790847
      0.0526315 -0.134454 0.00199997
      0.0526315 -0.0441771 0.00199997
      -0.00737037 -0.15091 0.00199997
      -0.194896 -0.125442 0.00199997
      -0.00735904 -0.0277061 0.00199997
      -0.165768 -0.0263173 0.00199997
      -0.0619937 -0.152993 1.4775
      -0.0619937 0.249837 0.742593
      -0.128443 0.249837 0.742593
      -0.128443 0.186828 0.742593
      -0.0619937 0.186828 0.742593
      -0.0619937 0.249837 1.39263
      -0.128443 0.249837 1.39263
      -0.0619937 0.186828 1.39263
      -0.128443 0.186828 1.39263
      -0.00199944 0.0538276 1.4775
      -0.00199188 0.146897 1.4775
      -0.00199188 0.146218 0.825642
      -0.00199944 0.0531482 0.825642
      -0.0619937 0.163293 1.42095
      -0.0619937 0.162674 0.825642
      -0.194896 0.140939 0.825642
      -0.194896 0.141618 1.4775
      -0.00199188 0.145493 0.128728
      -0.00199944 0.0524239 0.128728
      -0.0619937 0.161949 0.128728
      -0.194896 0.140215 0.128728
      -0.0619937 0.0359529 0.128728
      -0.165768 0.0359529 0.128728
      -0.0619937 0.0366398 0.790847
      -0.165768 0.0366398 0.790847
      0.0526315 0.144814 0.00199997
      0.0526315 0.0545369 0.00199997
      -0.00737037 0.16127 0.00199997
      -0.194896 0.140939 0.00199997
      -0.00735904 0.0380659 0.00199997
      -0.165768 0.0366772 0.00199997
      -0.0619937 0.163353 1.4775
    }
    ColorBinding PER_PRIMITIVE
    ColorArray Vec4Array 125
    {
      1 1 1 1
      1 1 1 1
      1 1 1 1
      1 1 1 1
      1 1 1 1
      1 1 1 1
      1 1 1 1
      1 1 1 1
      1 1 1 1
      1 1 1 1
      1 1 1 1
      1 1 1 1
      1 1 1 1
      1 1 1 1
      1 1 1 1
      1 1 1 1
      1 1 1 1
      1 1 1 1
      1 1 1 1
      1 1 1 1
      1 1 1 1
      1 1 1 1
      1 1 1 1
      1 1 1 1
      1 1 1 1
      1 1 1 1
      1 1 1 1
      1 1 1 1
      1 1 1 1
      1 1 1 1
      1 1 1 1
      1 1 1 1
      1 1 1 1
      1 1 1 1
      1 1 1 1
      1 1 1 1
      1 1 1 1
      1 1 1 1
      1 1 1 1
      1 1 1 1
      1 1 1 1
      1 1 1 1
      1 1 1 1
      1 1 1 1
      1 1 1 1
      1 1 1 1
      1 1 1 1
      1 1 1 1
      1 1 1 1
      1 1 1 1
      1 1 1 1
      1 1 1 1
      1 1 1 1
      1 1 1 1
      1 1 1 1
      1 1 1 1
      1 1 1 1
      1 1 1 1
      1 1 1 1
      1 1 1 1
      1 1 1 1
      1 1 1 1
      1 1 1 1
      1 1 1 1
      1 1 1 1
      1 1 1 1
      1 1 1 1
      1 1 1 1
      1 1 1 1
      1 1 1 1
      1 1 1 1
      1 1 1 1
      1 1 1 1
      1 1 1 1
      1 1 1 1
      1 1 1 1
      1 1 1 1
      1 1 1 1
      1 1 1 1
      1 1 1 1
      1 1 1 1
      1 1 1 1
      1 1 1 1
      1 1 1 1
      1 1 1 1
      1 1 1 1
      1 1 1 1
      1 1 1 1
      1 1 1 1
      1 1 1 1
      1 1 1 1
      1 1 1 1
      1 1 1 1
      1 1 1 1
      1 1 1 1
      1 1 1 1
      1 1 1 1
      1 1 1 1
      1 1 1 1
      1 1 1 1
      1 1 1 1
      1 1 1 1
      1 1 1 1
      1 1 1 1
      1 1 1 1
      1 1 1 1
      1 1 1 1
      1 1 1 1
      1 1 1 1
      1 1 1 1
      1 1 1 1
      1 1 1 1
      1 1 1 1
      1 1 1 1
      1 1 1 1
      1 1 1 1
      1 1 1 1
      1 1 1 1
      1 1 1 1
      1 1 1 1
      1 1 1 1
      1 1 1 1
      1 1 1 1
      1 1 1 1
      1 1 1 1
    }
    VertexAttribBinding 6 PER_VERTEX
    VertexAttribNormalize 6 FALSE
    VertexAttribArray 6 FloatArray 136
    {
      0 1 2 3 4 5 6 7 8 9
      10 11 12 13 14 15 16 17 18 19
      20 21 22 23 24 25 26 27 28 29
      30 31 32 33 34 35 36 37 38 39
      40 41 42 43 44 45 46 47 48 49
      50 51 52 53 54 55 56 57 58 59
      60 61 62 63 64 65 66 67 68 69
      70 71 72 73 74 75 76 77 78 79
      80 81 82 83 84 85 86 87 88 89
      90 91 92 93 94 95 96 97 98 99
      100 101 102 103 104 105 106 107 108 109
      110 111 112 113 114 115 116 117 118 119
      120 121 122 123 124 125 126 127 128 129
      130 131 132 133 134 135
    }
  }
}
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to