[osg-users] ClipNode Opposite Behavior

Christian Buchner christian.buchner at gmail.com
Mon Aug 17 04:02:23 PDT 2015

whatever float your boat... ;)

Here's a shader routine that evaluates if a fragment coordinate in object
space is within a polygon described by up to 16 vertices in the x/y plane.
We use it to cut a hole into a city scenario, so we can see into the
basement of a house. The shader does a simple point in polygon test.

The weird osgShadow_.... naming for my uniforms comes from the fact that
we've extended the one of OSG's shadow implementations of OSG with support
for cutting holes into the shadowed scene.

const char MyShadowMap::fragmentShaderSource_HoleCutter[] =
    "#version 120\n"
    "uniform vec2 osgShadow_polygon[16]; \n"
    "uniform float osgShadow_nvert; \n"
    "bool pnpoly(vec2 test)\n"
    "    bool c = false;"
    "    if (osgShadow_nvert >= 3)\n"
    "    {\n"
    "        int i, j;\n"
    "        for (i = 0, j = int(osgShadow_nvert) - 1; i <
int(osgShadow_nvert); j = i++) {\n"
    "            if (((osgShadow_polygon[i].y>test.y) !=
(osgShadow_polygon[j].y>test.y)) &&\n"
    "                (test.x < (osgShadow_polygon[j].x -
osgShadow_polygon[i].x) * (test.y - osgShadow_polygon[i].y) /
(osgShadow_polygon[j].y - osgShadow_polygon[i].y) +
    "                c = !c;\n"
    "        }\n"
    "    }\n"
    "    return c;\n"
    "bool is_hole(vec3 pos)\n"
    "    return pnpoly(pos.xy);\n"

static const char fragmentShaderSource[] =
    "#version 120\n"
    "bool is_hole(vec3 pos);\n"
    "void main(void) \n"
    "{ \n"
    "    \n"
    //   early discard
    //   NOTE: we've previously set up gl_TexCoord[4].xyz to contain vertex
    //   so we don't require a vertex shader here that passes us a varying
of vertex coords.
    "    if (is_hole(gl_TexCoord[4].xyz)) discard;\n"
    "    \n"
         // remainder of shader is here

2015-08-17 3:03 GMT+02:00 Erik Hensens <ehensens at hunter.com>:

> I just wanted to mention that I never got the fragment shader approach to
> work for what I wanted. I ended up using polygon tessellation to build the
> geometry out of triangles.
> Thanks anyway to everyone who attempted to help!
> ------------------
> Read this topic online here:
> http://forum.openscenegraph.org/viewtopic.php?p=64791#64791
> _______________________________________________
> 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/20150817/b06539aa/attachment-0003.htm>

More information about the osg-users mailing list