On 03/12/2012 10:04 AM, Ethan Fahy wrote:
Thanks Jason,

I understand about the interpolation.  I have been operating under the 
assumption that if I use a node visitor to loop over each primitive in my 
object, create a floatArray of index numbers of size=size(primitive array), and 
then bind_per_primitive, then I shouldn't have to worry about interpolation of 
those index numbers within the shader.  Is that correct?

If you're trying to get the same value for all fragments on a primitive, then yes, this will work. Be aware, though, that rendering geometry with per-primitive binding is going to be quite slow compared to overall or per-vertex binding.

As an alternative, you could specify your floatArray at size=size(primitive array) * 3 (assuming you're rendering triangles) and just specify the same index for all three vertices of each triangle. Then, you could use per-vertex binding and not fall off the fast path.


I noticed that in Christian's code snippet that the osg::Program that he 
created was not attached to the geometry's stateset.  Without attaching it, you 
will still have a floatArray stored in the 6 position, but it will not have a 
name and therefore I don't think you can access it from the shader.

In either case, when i try to add my floatArray to the 6th vertex attribute, my 
shaders stop working.  I don't get any glsl errors printed to screen, but even 
if I try to do something simple like assign all color values to black, the 
shader just spits out the underlying object colors and ignores my shader 
commands.  If I don't attach the osg::Program to my object's stateset, the 
shader commands do work again but I can't access my 6th vertex attribute 
because it wasn't named.

Here is the stateset that was added to my object.obj's geometry:

StateSet {
       rendering_hint DEFAULT_BIN
       renderBinMode INHERIT
       Program {
         name "targetIndices"
         GeometryVerticesOut 1
         GeometryInputType TRIANGLES
         GeometryOutputType TRIANGLE_STRIP
         AttribBindingLocation indices 6
         num_shaders 0
       }
     }

I'm assuming most of these things are default values since I never specified 
GeometryVerticesOut, GeometryInputType, GeometryOutputType, or num_shaders when 
I created my osg::Program.  Are these defaults the cause of my problems?

The defaults are probably fine (they apply to geometry shaders, which I don't think you're using). The attribute binding for "indices" at attribute 6 looks good as well. However, it looks as if there are not any shaders attached to your Program ("num_shaders 0"), which isn't going to work at all. You need to create an osg::Shader (specifying the type of shader, vertex, geometry, or fragment), add the shader's source to it, and then add the shader to the Program. Then, you can attach the program to the StateSet and everything should work:

shader = new osg::Shader(osg::Shader::FRAGMENT);
shader->setShaderSource(source);
program->addShader(shader);

--"J"
_______________________________________________
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to