[osg-users] ClipNode Opposite Behavior

Glenn Waldron gwaldron at gmail.com
Sun Jul 26 06:46:22 PDT 2015


Erick,
gl_FragCoord is almost certainly not what you want (Google it). Try
something like this:

Vertex shader:

uniform vec3 center;
varying float dist;
void main()
{
    vec4 vertex = gl_ModelViewMatrix * gl_Vertex;
    dist = length(center - vertex.xyz);
}

Fragment shader:

uniform float rad;
varying float dist;
void main()
{
    if ( rad < dist )
        discard;
    else
        gl_FragColor = ...;
}



Glenn Waldron / @glennwaldron

On Fri, Jul 24, 2015 at 9:22 AM, Erik Hensens <ehensens at hunter.com> wrote:

> Thanks Christian. It's funny you mention that because since I'm not
> setting the color, the quad looks like an old television tuned to a
> frequency not in service, i.e. "static" or "snow". I think every time the
> quad is rendered each fragment's color is set to whatever value is in some
> uninitialized portion of memory, and each fragment changes color each time
> it is rendered. Quite a funny effect!
>
> I added the following line to set the color, and now it is always blue,
> but it's still not putting a hole in my quad, it's all there or all gone
> depending on whether I say if (fDist < rad) or if (fDist > rad):
>
>
> Code:
>
> // The fragment shader program source code
> std::string szFragSource(
> "uniform vec3 center;\n"
> "uniform float rad;\n"
> "void main()\n"
> "{\n"
> "float fDistX = gl_FragCoord.x - center.x;\n"
> "float fDistY = gl_FragCoord.y - center.y;\n"
> "float fDistZ = gl_FragCoord.z - center.z;\n"
> "float fDist = sqrt(fDistX * fDistX + fDistY * fDistY + fDistZ *
> fDistZ);\n"
> "gl_FragColor = vec4(0.0,0.0,1.0,1.0);\n"
> "if (fDist < rad) discard;\n"
> "}\n"
> );
>
>
>
>
> Any other ideas about why my code doesn't achieve what I want? For
> example, am I using gl_FragCoord correctly? Are there other errors in my
> frag source?
>
> Thanks again!
>
>
> cbuchner1 wrote:
> > I believe your fragment shader is not setting the output fragment color
> at all, which is a minimum requirement for a fragment shader to work.
> >
> >
> > Christian
> >
> >
> >
> > 2015-07-23 23:59 GMT+02:00 Erik Hensens < ()>:
> >
> > > Sorry for the triplicate post, I received an error message on trying
> to post until I removed the quotes...
> > >
> > > ------------------
> > > Read this topic online here:
> > > http://forum.openscenegraph.org/viewtopic.php?p=64458#64458 (
> http://forum.openscenegraph.org/viewtopic.php?p=64458#64458)
> > >
> > >
> > >
> > >
> > >
> > > _______________________________________________
> > > osg-users mailing list
> > >  ()
> > >
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
> (http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
> )
> > >
> > >
> > >
> >
> >
> >  ------------------
> > Post generated by Mail2Forum
>
>
> ------------------
> Read this topic online here:
> http://forum.openscenegraph.org/viewtopic.php?p=64467#64467
>
>
>
>
>
> _______________________________________________
> osg-users mailing list
> osg-users at lists.openscenegraph.org
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openscenegraph.org/pipermail/osg-users-openscenegraph.org/attachments/20150726/f81ec093/attachment-0002.htm>


More information about the osg-users mailing list