Hi J-S, thanks for your helpful insights.  I'm brand new to this shader
stuff (osg::Programs, etc.), but I'm doing ok on the scenegraphs, nodes and
callbacks.  I've also got a lot more to learn about multiple cameras,
render-to-texture, etc.

I think my data items are going to be per Geode (e.g., thickness of a
"part"), but I thought I still needed shader attributes instead of uniforms,
because uniforms are per frame.  Unless you're thinking I'd make an array of
them where the indexing is the Geodes?

Bob

-----Original Message-----
From: Jean-Sébastien Guay [mailto:[email protected]] 
Sent: Wednesday, July 08, 2009 9:14 PM
To: OpenSceneGraph Users
Subject: Re: [osg-users] how to set per vertext attributes using osg

Hi Bob,

> Hi all, I’m trying to figure out the best method to pass per vertex 
> “attributes” to shaders using osg and I can’t seem to find many examples 
> of attribute use.  My guess is there’s a reason for that and I should 
> probably code up a uniform array of some kind instead.

There's no reason other than no example has been made yet.

Mike Weiblen's osgtoy-data repository has a compactdisc.osg file that 
shows that attributes work. It's a single .osg file that contains the 
model and the shaders to show a compact disc with the color diffraction 
effect (different colors visible depending on the viewing angle).

There's also a compactdisc-texcoord.osg file that does the same thing 
using one of the texcoord arrays. That's always an option, btw, you can 
just co-opt one of the unused arrays from the fixed pipeline (like 
texcoord for texture unit 1 if your model uses a single texture on unit 0).

Of course having a data file that has attributes won't show you how to 
use them in your program, and how to update them when you need to, but 
at least it proves that they're usable.

> I need to pass 
> “thickness” as an “attribute” and that varies with the geometry / 
> osg::Geode.

Does it vary based on the geode, or on the geometry's vertices? The 
sentence above is very ambiguous. If you need just one value per geode, 
you can perfectly well use a single uniform. Attributes are for when 
things vary per vertex.

> I’ve studied the osg::Drawable and its attribute types, and 
> the osg::Program and its addBindAttribLocation, but I can’t find any 
> examples of the callback or other mechanism to actually get the data set 
> into the attributes from the scenegraph.

Well, that's because it's kind of up to you. Once you've set your 
attribute array in the geometry object, and called addBindAttribLocation 
to tell the program that a given attribute location potentially has data 
in it, you can fill in the data however you like. If your attributes 
don't change you can set them once at startup. If they vary per frame 
then you'll want to either put an update callback somewhere or break up 
your frame loop and then do your calculations there. (I personally 
prefer update callbacks, that way a given node can do all the work it 
has to do without needing to modify any other parts of the program, but 
that's just a preference)

Hope this helps,

J-S
-- 
______________________________________________________
Jean-Sebastien Guay    [email protected]
                                http://www.cm-labs.com/
                         http://whitestar02.webhop.org/



_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to