Maxime BOUCHER wrote on Friday, July 31, 2009 7:58 AM:
> bthrall wrote:
>> 
>> The shader has a sampler2D uniform that needs to be set to the
texture
>> unit you want to use; as long as you attach a different Texture2D to
>> each geode/drawable on that texture unit, the shader will see that
>> geode/drawable's texture.
> 
> 
> Well, the shader can only access textures belonging to the same
stateset,
> right? 
> 
> For example:
> [Image:
http://img7.hostingpics.net/pics/398942graphe_shader_textures.jpg ]
>
(http://www.hostingpics.net/viewer.php?id=398942graphe_shader_textures.j
pg) 
> 
> Texture0 is the sampler2D given to the shader (well, its unit).
> I would like to load texture0 as texture1 while OSG draws drawable1,
and
> load texture0 as texture2 while OSG draws drawable2. 
> 
>  I guess I could set a shader for each, but first, the scenegraph can
be of
> any complexity, then it could need a great number of shaders, it would
be
> bad. Moreover, I'm not sure on how they will overwrite each other (if
so). 
> 
> Do you still think I can do this without callbacks?

The shader can access the current texture of any texture unit, depending
on what texture unit the sampler2D uniform is set to.

In your example, if texture0 (meaning the osg::Texture2D object
containing texture0) is attached to the root stateset in unit 0, then
the root stateset should have a uniform for the sampler2D with value
'0'. Then, if texture1 and texture2 are attached to their statesets in
unit 0, the shader will use whatever texture is in unit 0 when it
renders geode1 and geode1:

Render geode1: current texture in unit 0 is texture1, sampler2D uniform
has value '0', so shader uses texture1
Render geode2: current texture in unit 0 is texture2, sampler2D uniform
has value '0', so shader uses texture2

If I attach another geode to root, geode3, with no stateset at all, the
shader will use texture0 because that is the texture in unit 0 when
geode3 is rendered.

HTH,
-- 
Bryan Thrall
FlightSafety International
[email protected]
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to