If you want the hole to be specified in object local coordinates, use gl_Vertex. Getting world coordinates is a bit more tricky, you would need to have the transformation matrix between object coordinates and world coordinates accessible in the vertex (or fragment) shader.
Definitely do not use gl_FragCoord - because this one is in 2D screen space. Christian 2015-07-26 15:46 GMT+02:00 Glenn Waldron <gwald...@gmail.com>: > 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 <ehens...@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@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 > >
_______________________________________________ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org