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"
    "\n"
    "bool pnpoly(vec2 test)\n"
    "{\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) +
osgShadow_polygon[i].x))\n"
    "                c = !c;\n"
    "        }\n"
    "    }\n"
    "    return c;\n"
    "}\n"
    "\n"
    "bool is_hole(vec3 pos)\n"
    "{\n"
    "    return pnpoly(pos.xy);\n"
    "}\n"
};

static const char fragmentShaderSource[] =
    "#version 120\n"
    "\n"
    "bool is_hole(vec3 pos);\n"
    "\n"
    "void main(void) \n"
    "{ \n"
    "    \n"
    //   early discard
    //   NOTE: we've previously set up gl_TexCoord[4].xyz to contain vertex
coordinates
    //   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
    "}\n";



2015-08-17 3:03 GMT+02:00 Erik Hensens <ehens...@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@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

Reply via email to