Hi Mike,

I have a simple repro of this problem.  See the attached .osg file.

It's a super simple shader that colors an object blue or red depending
on a bool uniform.  The default state on the parent group sets this
uniform to 0, then one of the children overrides it with 1.  You'd
expect to see a blue sphere and a red sphere.  But in OSG 1.2 you see
two blue spheres.  OSG 2.4 works as I'd expect.

The problem seems to come in when the render bins are set up in just the
right way -- in this case, with the overriding child rendering first.

Obviously we can fix the problem by going to OSG 2.4, and we're trying
:)  But unfortunately we have to put out a working version of our
software pretty soon with 1.2 as the base (I'm working on the same
project as Chris).  Do you know of a reliable workaround?

Thanks,
Nathan



-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of
Dorosky, Christopher G
Sent: Monday, May 19, 2008 1:41 PM
To: OpenSceneGraph Users
Subject: Re: [osg-users] Uniform value getting overwritten in shader.

Mike,

Run with osgviewer, the glsl example works.

The problem with that example is that it creates new geometry and
doesn't reuse it.

My model has two parents (MatrixTransforms), A & B. These parents share
the same shader, but have different statesets.

"A" has a stateset setting a new uniform MYCOLOR to (1.0, 0.0, 0.0,
1.0);
"B" has a stateset setting a new uniform MYCOLOR to (0.0, 0.0, 1.0,
1.0);

The scene graph adds A first, then B. They are translated from each
other.
The shader simply sets the gl_FragColor to MYCOLOR.

If "A" and "B" are in the scene, both are RED.
If only "B" is in the scene, it is BLUE.

It appears that the uniform gets trampled. I was careful to make
explicitly new uniforms each time.
Running a different set of geometry under the shader, and setting a new
MYCOLOR to GREEN works.

The problem seems to be with reusing geometry, but applying different
statesets to the parents. The uniform value of the object during its
draw under the second parent retains its first parent value.

For what it's worth, this worked fine under whatever pre-1.2 version we
were using.

Chris





-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Mike
Weiblen
Sent: Thursday, May 15, 2008 2:13 PM
To: OpenSceneGraph Users
Subject: Re: [osg-users] Uniform value getting overwritten in shader.

Does the glsl_simple.osg example datafile work for you?  It demonstrates
one shader w/ different values for the "Color1" uniform.
-- mew



On Thu, May 15, 2008 at 2:01 PM, Dorosky, Christopher G
<[EMAIL PROTECTED]> wrote:
> Hello,
>
> I am having problems with a uniform value getting trumped in a shader.
>
> Here is most of the shader fragment:
>
> ___________________________________________________________________
>
>  os << "\nuniform bool PreMultipliedAlpha;\n";  os << "uniform vec4 
> FogUniform;\n";
>  os << "   vec3 FogColor;\n";
>        os << "   vec3 FogUniformColor;\n";
>
>        os << "void main()\n";
>        os << "{\n";
>
>        os << "   if (PreMultipliedAlpha) {\n";
>        os << "      FogColor = gl_Fog.color.rgb * gl_FragColor.a;\n";
>        if (aFogType == EXP2_FOG)
>            os << "      FogUniformColor = FogUniform.rgb *
> gl_FragColor.a;\n";
>        os << "   } else {\n";
>        os << "      FogColor = gl_Fog.color.rgb;\n";
>        if (aFogType == EXP2_FOG)
>            os << "      FogUniformColor = FogUniform.rgb;\n";
>        os << "   }\n";
> ______________________________________________________________________
>
> Now, to use it, I have this code...
>
> osg::Group *Topgroup = new osg::Group; // real code this has more 
> stuff attached.
> osg::Group *group = new osg::Group;
>
> Topgroup->addChild(group);
>
> // modelA and modelB groups already exist.
>
> modelA->getOrCreateStateSet()->getOrCreateUniform("PreMultipliedAlpha"
> modelA->,
> osg::Uniform::BOOL)->set(true);
> modelB->getOrCreateStateSet()->getOrCreateUniform("PreMultipliedAlpha"
> modelB->,
> osg::Uniform::BOOL)->set(false);
>
>
> group->addChild(modelA);
> group->addChild(modelB);
>
> // Then the Fragment shader is added to the Topgroup node.
> // Didn't include code here because it is long, and it works as shown 
> below.
>
> Here is what happens.
> When modelA and modelB are added to the group as shown above, the 
> uniform is always false.
>
> If I comment out the line:
> //group->addChild(modelB);
>
> Then I have the uniform set correctly to true.
>
> Reinserting that line, and commenting out
> group->addChild(modelA);
> Has the uniform set correctly to false.
>
> It seems that I can't have both models added with different uniform 
> values without one trumping the other.
>
> Am I doing something wrong or is this a bug?
>
> I've tried more obvious things conditional on the uniform value, like 
> making the model red or blue with same results.
>
> OSG 1.2, Windows XP
>
> Thanks,
>
> Chris
> _______________________________________________
> osg-users mailing list
> osg-users@lists.openscenegraph.org
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.
> org
>



--
Mike Weiblen -- Austin Texas USA -- http://mew.cx/
_______________________________________________
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.or
g
_______________________________________________
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.or
g

Attachment: uniform_sort_problem.osg
Description: uniform_sort_problem.osg

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

Reply via email to