Re: [osg-users] Layer Opacity using TexEnvCombine

2009-06-09 Thread Jason Beverage
Hi Jason,

You're exactly right, if texture 1 has transparency, then I want texture 0
to show through no matter what.  Doing something like the following on unit
0 works great in that case, but I also want to add in another scaling factor
that will scale the alpha value of the texture from 0 to 1 to essentially
act as a slider for the opacity.  I'll keep hacking along, but I might need
to just stick with shaders.

osg::TexEnvCombine* tec = new osg::TexEnvCombine;
tec-setSource0_RGB(osg::TexEnvCombine::TEXTURE1);
tec-setOperand0_RGB(osg::TexEnvCombine::SRC_COLOR);

tec-setSource1_RGB(osg::TexEnvCombine::TEXTURE0);
tec-setOperand1_RGB(osg::TexEnvCombine::SRC_COLOR);

tec-setSource2_RGB(osg::TexEnvCombine::TEXTURE1);
tec-setOperand2_RGB(osg::TexEnvCombine::SRC_ALPHA);

tec-setCombine_RGB(osg::TexEnvCombine::INTERPOLATE);

csn-getOrCreateStateSet()-setTextureAttribute(0, tec);

Thanks!

Jason

On Mon, Jun 8, 2009 at 8:23 PM, Jason Daly jd...@ist.ucf.edu wrote:

 Jason Beverage wrote:

 Hi all,

 I'm trying to figure out a way to modify layer opacity using TexEnvCombine
 that takes into account the underlying alpha channel of a texture.


 Do you mean if unit 1's texture has transparency, you want that to show
 through to unit 0's texture?



 The osgFX::MultiTextureControl does very close to what I'm looking to do,
 but doesn't take into account the fact that the underlying texture may
 contain transparency (like a road overlay).

 From my understanding of texenvcombine, I can either use a constant color
 or SRC_ALPHA as an operand, but not a combination of both.


 It sounds like you need three parameters combined (2 texture colors and a
 user-defined parameter), so your only hope is the INTERPOLATE mode for the
 alpha values (INTERPOLATE is the only combiner operation that takes three
 parameters).  Try this:

 tec-setSource0_RGB(osg::TexEnvCombine::TEXTURE0);
 tec-setSource1_RGB(osg::TexEnvCombine::TEXTURE1);
 tec-setCombine_RGB(osg::TexEnvCombine::MODULATE);

 tec-setConstantColor(osg::Vec4(1.0, 1.0, 1.0, userDefinedAlpha));
 tec-setSource0_Alpha(osg::TexEnvCombine::TEXTURE0);
 tec-setSource1_Alpha(osg::TexEnvCombine::TEXTURE1);
 tec-setSource2_Alpha(osg::TexEnvCombine::CONSTANT);
 tec-setCombine_Alpha(osg::TexEnvCombine::INTERPOLATE);

 I just made this up, so I have no idea if it will work or not.  It might
 not be the only possibility, either, but it's all I can think of right now.

 --J

 ___
 osg-users mailing list
 osg-users@lists.openscenegraph.org
 http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] Layer Opacity using TexEnvCombine

2009-06-09 Thread Jason Daly

Jason Beverage wrote:

Hi Jason,

You're exactly right, if texture 1 has transparency, then I want 
texture 0 to show through no matter what.  Doing something like the 
following on unit 0 works great in that case, but I also want to add 
in another scaling factor that will scale the alpha value of the 
texture from 0 to 1 to essentially act as a slider for the opacity.  
I'll keep hacking along, but I might need to just stick with shaders.


Yeah, at first I thought i had an easy answer to your question, but as I 
looked into it I realized just how many combinations you can come up 
with for TexEnvCombine settings.  I just sent you my best guess, which 
is probably way off.


Let me know if you figure it out...

--J

___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


[osg-users] Layer Opacity using TexEnvCombine

2009-06-08 Thread Jason Beverage
Hi all,

I'm trying to figure out a way to modify layer opacity using TexEnvCombine
that takes into account the underlying alpha channel of a texture.

The osgFX::MultiTextureControl does very close to what I'm looking to do,
but doesn't take into account the fact that the underlying texture may
contain transparency (like a road overlay).

From my understanding of texenvcombine, I can either use a constant color or
SRC_ALPHA as an operand, but not a combination of both.  I really want a way
to use SRC_ALPHA scaled by some user defined opacity value (0 to 1).

Does anyone know of a way to accomplish this?  I know how to accomplish this
using a glsl shader, but can't quite figure out how to do it with
texenvcombine.

Thanks!

Jason
___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] Layer Opacity using TexEnvCombine

2009-06-08 Thread Jason Daly

Jason Beverage wrote:

Hi all,

I'm trying to figure out a way to modify layer opacity using 
TexEnvCombine that takes into account the underlying alpha channel of 
a texture.


Do you mean if unit 1's texture has transparency, you want that to show 
through to unit 0's texture?





The osgFX::MultiTextureControl does very close to what I'm looking to 
do, but doesn't take into account the fact that the underlying texture 
may contain transparency (like a road overlay).


From my understanding of texenvcombine, I can either use a constant 
color or SRC_ALPHA as an operand, but not a combination of both.


It sounds like you need three parameters combined (2 texture colors and 
a user-defined parameter), so your only hope is the INTERPOLATE mode for 
the alpha values (INTERPOLATE is the only combiner operation that takes 
three parameters).  Try this:


tec-setSource0_RGB(osg::TexEnvCombine::TEXTURE0);
tec-setSource1_RGB(osg::TexEnvCombine::TEXTURE1);
tec-setCombine_RGB(osg::TexEnvCombine::MODULATE);

tec-setConstantColor(osg::Vec4(1.0, 1.0, 1.0, userDefinedAlpha));
tec-setSource0_Alpha(osg::TexEnvCombine::TEXTURE0);
tec-setSource1_Alpha(osg::TexEnvCombine::TEXTURE1);
tec-setSource2_Alpha(osg::TexEnvCombine::CONSTANT);
tec-setCombine_Alpha(osg::TexEnvCombine::INTERPOLATE);

I just made this up, so I have no idea if it will work or not.  It might 
not be the only possibility, either, but it's all I can think of right now.


--J

___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org