Questions about ShaderGenerator

classic Classic list List threaded Threaded
2 messages Options
David David
Reply | Threaded
Open this post in threaded view
|

Questions about ShaderGenerator

I ran across a question in the FAQ about models not being rendered with textures and needing to call osgEarth::Registry::shaderGenerator().run( myNode ); on your node to generate shader snippets for it.  This certainly fixed my problem, but I couldn't really find anything else about the shader generator beyond this, so I have some questions.

1) My geometry nodes can be updated at run time by specifying different geometry/models to use (not very likely) or different styles/textures (more likely).  Do I need to run the shader generator on the node every time it changes, or only once?
2) Does the shader generator create a new shader for each node I pass to run(), or will it reuse existing shaders for similar nodes (i.e., if it only needs to render a single texture)?  Do I need to be worried about the overhead and resource utilization of this in scenes with lots and lots of nodes?
3) I'm using the GeoPositionNode and attaching my geometry/model to the PositionAttitudeTransform child.  Does it matter which node I pass to the shader generator?  Right now I'm just using the GeoPositionNode and that seems to be working.
4) Anything else I should know about using the shader generator?
gwaldron gwaldron
Reply | Threaded
Open this post in threaded view
|

Re: Questions about ShaderGenerator

David,

The shader generator is a useful tool when you're loading a 3D model from disk and using it as-is. If you are creating your own geometry and manipulating it, I recommend creating your own shaders instead.

Whether you need to modify shaders depends on the change. Geometry or texture changes, no. Adding or removing a texture, yes.

The SG will create new shader snippets each time you run it. Optionally you can supply a StateSetCache that will cause it to reuse existing snippets. This is critical for run-time performance.

The SG is a visitor so it doesn't matter which node you start at - it will descend the tree and do its business.
Glenn Waldron / Pelican Mapping