Discussion:
animating textures
Julia Guo
2009-04-06 01:58:41 UTC
Permalink
Hi,

I am trying to animate a transition between textures on a surface.
I had a look in osgAnimation (http://www.openscenegraph.org/documentation/OpenSceneGraphReferenceDocs/a01556.html) but that namespace seems to be just related to geometry. I found osgFX::MultiTextureControl (http://www.openscenegraph.org/documentation/OpenSceneGraphReferenceDocs/a00429.html), which can control which textures are active and how to blend them, but doesnt support animating.

So to animate between textures should I create a callback to update the texture control (like the rotate example in the manual)? Or is there a better approach?

Thank you.
Julia

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=9763#9763
Ümit Uzun
2009-04-06 06:25:17 UTC
Permalink
Hi Julia,

If you mean sliding images in a sequenced order you can look at
osgimagesequence example. Or you mean rotating, translating, retexturing in
new texture coordinate you can achieve these kind of operation by using
fixed openGL functions or you can use GLSL to manipulate texture coordinate
in fragment shader section. You code only couple of line in fragment shader.

I have not ever tried osganimation or osgfx nodekit to get kind of result on
textures.

Best Regards.
Post by Julia Guo
Hi,
I am trying to animate a transition between textures on a surface.
I had a look in osgAnimation (
http://www.openscenegraph.org/documentation/OpenSceneGraphReferenceDocs/a01556.html)
but that namespace seems to be just related to geometry. I found
osgFX::MultiTextureControl (
http://www.openscenegraph.org/documentation/OpenSceneGraphReferenceDocs/a00429.html),
which can control which textures are active and how to blend them, but
doesnt support animating.
So to animate between textures should I create a callback to update the
texture control (like the rotate example in the manual)? Or is there a
better approach?
Thank you.
Julia
------------------
http://forum.openscenegraph.org/viewtopic.php?p=9763#9763
_______________________________________________
osg-users mailing list
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
--
Ümit Uzun
Julia Guo
2009-04-06 06:46:31 UTC
Permalink
ah - I should have been more specific with what I meant by animation.
I want to fade between two textures so that the previous texture slowly gets weaker while the new texture slowly gets stronger.

Can shaders manipulate the texture opacity? (I expect so.)
And do you think this is a better approach than what OSG provides with the MultiTextureControl?

Julia

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=9766#9766
Roland Smeenk
2009-04-06 07:13:04 UTC
Permalink
Post by Julia Guo
I had a look in osgAnimation (http://www.openscenegraph.org/documentation/OpenSceneGraphReferenceDocs/a01556.html) but that namespace seems to be just related to geometry.
That's not entirely true. osgAnimation can be used to generate animated values. These values will have to be linked to some part of your scenegraph, which is done with an AnimationUpdateCallback. The currently available callbacks are indeed only for updating geometry, but a custom AnimationUpdateCallback could be written to update shader uniforms or the textureWeight in a MultiTextureControl.

--
Roland

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=9768#9768
Cedric Pinson
2009-04-06 10:08:13 UTC
Permalink
Hi Roland,

Yes the idea should be to use a UpdateCallback that use easemotion. I
will try to make new example with ease motion and stateset callback.
I guess that to fade in/out texture, the osgFX::MultitextureControl is
ready to use.

Cheers,
Cedric
Post by Roland Smeenk
Post by Julia Guo
I had a look in osgAnimation (http://www.openscenegraph.org/documentation/OpenSceneGraphReferenceDocs/a01556.html) but that namespace seems to be just related to geometry.
That's not entirely true. osgAnimation can be used to generate animated values. These values will have to be linked to some part of your scenegraph, which is done with an AnimationUpdateCallback. The currently available callbacks are indeed only for updating geometry, but a custom AnimationUpdateCallback could be written to update shader uniforms or the textureWeight in a MultiTextureControl.
--
Roland
------------------
http://forum.openscenegraph.org/viewtopic.php?p=9768#9768
_______________________________________________
osg-users mailing list
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
--
+33 (0) 6 63 20 03 56 Cedric Pinson mailto:mornifle-***@public.gmane.org http://www.plopbyte.net
Robert Osfield
2009-04-06 07:34:37 UTC
Permalink
Hi Julia,

osgFX::MultiTextureControl would be able to do what you want. It uses
register combiner extensions to do the blending, but you could use your own
fragment shader to control the blending precisely.

The other way to do it is use a 3D texture and then vary the r coord. See
the osgtexture3D example for an example of this.

Robert.
Post by Julia Guo
ah - I should have been more specific with what I meant by animation.
I want to fade between two textures so that the previous texture slowly
gets weaker while the new texture slowly gets stronger.
Can shaders manipulate the texture opacity? (I expect so.)
And do you think this is a better approach than what OSG provides with the
MultiTextureControl?
Julia
------------------
http://forum.openscenegraph.org/viewtopic.php?p=9766#9766
_______________________________________________
osg-users mailing list
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Julia Guo
2009-04-08 02:57:26 UTC
Permalink
Hi, thanks very much for the advices.

I now have a basic MultitextureControl example working that fades a single texture.
However I cant seem to activate texture unit 1. The following example only shows the texture if I set unit to 0:

Code:
addDrawable(new osg::ShapeDrawable(new osg::Cone()));
texture = new osg::Texture2D;
texture->setImage(osgDB::readImageFile("brick1.TGA"));
int unit = 1; // works fine when unit=0
getOrCreateStateSet()->setTextureAttributeAndModes(unit, texture);


Like lights, is only texture 0 activated by default? Am I missing something to activate the texture?
The other way to do it is use a 3D texture and then vary the r coord. See the osgtexture3D example for an example of this.
hi Robert: is there an advantage to this technique or has it been obsoleted by MultitextureControl?


Julia

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=9874#9874
Robert Osfield
2009-04-08 08:16:45 UTC
Permalink
Hi Julia,
Post by Julia Guo
Hi, thanks very much for the advices.
I now have a basic MultitextureControl example working that fades a single texture.
However I cant seem to activate texture unit 1. The following example only
addDrawable(new osg::ShapeDrawable(new osg::Cone()));
texture = new osg::Texture2D;
texture->setImage(osgDB::readImageFile("brick1.TGA"));
int unit = 1; // works fine when unit=0
getOrCreateStateSet()->setTextureAttributeAndModes(unit, texture);
This doesn't really provide enough info about your overall texture set to
know whether it's appropriate. Most likely the problems you are seeing are
related to not setting up the scene graph appropriately, but as to what you
are doing wrong I can't say.
Post by Julia Guo
Like lights, is only texture 0 activated by default? Am I missing something
to activate the texture?
All textures are off by default, you have to explicitly enable them all.
Post by Julia Guo
Post by Robert Osfield
The other way to do it is use a 3D texture and then vary the r coord.
See the osgtexture3D example for an example of this.
hi Robert: is there an advantage to this technique or has it been obsoleted
by MultitextureControl?
It's just a different way of doing it, there are pros and cons of both
ways. The OSG/OpenGL are just the basic language that you the programmer
use to construct your graphics app, how you use it depends upon what you are
trying to achieve.

Robert.
Julia Guo
2009-04-08 13:35:19 UTC
Permalink
hi Robert,

so if all textures are disabled initially is there any difference between textures 0 and 1? Because the exact same code works for texture 0 but not texture 1.
I saw in the archives a snippet (http://groups.google.com/group/osg-users/browse_thread/thread/616a24590cce9c3) where the texture coordinates were set manually like this:

Code:
geometry->setTexCoordArray(1, geometry->getTexCoordArray(0));


I cant do this because my drawable does not inherit from osg::Geometry, but is something manual like this needed for non-zero textures?
Most likely the problems you are seeing are related to not setting up the scene graph appropriately
What kind of settings can effect whether a texture is displayed?


Julia

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=9911#9911
Robert Osfield
2009-04-08 14:25:44 UTC
Permalink
Hi Julia,
Post by Julia Guo
hi Robert,
so if all textures are disabled initially is there any difference between
textures 0 and 1? Because the exact same code works for texture 0 but not
texture 1.
I saw in the archives a snippet (
http://groups.google.com/group/osg-users/browse_thread/thread/616a24590cce9c3)
geometry->setTexCoordArray(1, geometry->getTexCoordArray(0));
I cant do this because my drawable does not inherit from osg::Geometry, but
is something manual like this needed for non-zero textures?
You will need texture coordinates for all the texture unit you use. You'll
either have to move to using a different technique or using osg::Geometry.
Post by Julia Guo
Most likely the problems you are seeing are related to not setting up the
scene graph appropriately
What kind of settings can effect whether a texture is displayed?
Well not provide texture coordinates correctly is one such example.

Robert.
Jean-Sébastien Guay
2009-04-08 17:59:20 UTC
Permalink
Hello Julia,
Post by Julia Guo
geometry->setTexCoordArray(1, geometry->getTexCoordArray(0));
I cant do this because my drawable does not inherit from osg::Geometry, but is something manual like this needed for non-zero textures?
Well, there you have it, you need texture coordinates for unit 1 if you
want to get any predictable effect from setting a texture on unit 1.

Is your drawable a ShapeDrawable? Then you're pretty much out of luck,
because these only set texture coordinates on unit 0 and don't give you
access to their internals. I suggest you go into a modeling program,
create (say) a sphere of diameter 1 (if what you want is a sphere, if
not do the same for another type of object), export that and load it in
your program instead of using ShapeDrawables. Then they will be
instances of osg::Geometry (which you'll have to find with a visitor)
and you'll be able to use the code above to copy texture coordinate
arrays. If you use diameter of 1 you can then scale it with a
MatrixTransform and get predictable results.

Hope this helps,

J-S
--
______________________________________________________
Jean-Sebastien Guay jean-sebastien.guay-***@public.gmane.org
http://www.cm-labs.com/
http://whitestar02.webhop.org/
Julia Guo
2009-04-09 01:17:05 UTC
Permalink
Post by Jean-Sébastien Guay
Is your drawable a ShapeDrawable? Then you're pretty much out of luck,
because these only set texture coordinates on unit 0 and don't give you
access to their internals.
thanks Skylark! - that would explain the different results Im getting for unit 0 and 1 with a ShapeDrawable.
Ive now changed to a model derived from osg::Geometry and the texture animation is working fine.


Those ShapeDrawable classes seem limiting ... is there a goal to derive them from osg::Geometry rather than the current raw OpenGL calls?

Julia

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=9949#9949
Robert Osfield
2009-04-09 07:58:27 UTC
Permalink
Hi Julia,
Post by Julia Guo
Post by Jean-Sébastien Guay
Is your drawable a ShapeDrawable? Then you're pretty much out of luck,
because these only set texture coordinates on unit 0 and don't give you
access to their internals.
thanks Skylark! - that would explain the different results Im getting for
unit 0 and 1 with a ShapeDrawable.
Ive now changed to a model derived from osg::Geometry and the texture
animation is working fine.
Those ShapeDrawable classes seem limiting ... is there a goal to derive
them from osg::Geometry rather than the current raw OpenGL calls?
ShapeDrawable has turned out to be as much as hinderance as they have been a
help. I added them just as convenience for quickly visualizing the shape
primitives, without any intention of it being widely used. I would like to
see ShapeDrawable deprecated and replaced by a facility that creates
osg::Geometry given a shape primitive. Alas I have many things on my TODO
list and replacing ShapeDrawable is towards the back of this list.

Robert.
Jean-Sébastien Guay
2009-04-09 12:56:54 UTC
Permalink
Hi Julia,
Post by Julia Guo
thanks Skylark! - that would explain the different results Im getting for unit 0 and 1 with a ShapeDrawable.
Ive now changed to a model derived from osg::Geometry and the texture animation is working fine.
Good to hear!
Post by Julia Guo
Those ShapeDrawable classes seem limiting ... is there a goal to derive them from osg::Geometry rather than the current raw OpenGL calls?
Yes they are limiting, as Robert has said often before they were done
for quick prototyping but in hindsight he would have made them based on
osg::Geometry instead (as this kind of question/problem pops up pretty
often on this list). Refactoring them and basing them on osg::Geometry
is one of the little projects I have on my list for a rainy day (but
there don't seem to be much of those these days :-( ).

Glad I could help,

J-S
--
______________________________________________________
Jean-Sebastien Guay jean-sebastien.guay-***@public.gmane.org
http://www.cm-labs.com/
http://whitestar02.webhop.org/
Loading...