<div dir="ltr"><div><div><br></div>whatever float your boat... ;)<br><br></div><div>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.<br><br></div><div>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.<br></div><div><br>const char MyShadowMap::fragmentShaderSource_HoleCutter[] =<br>{<br> "#version 120\n"<br> "uniform vec2 osgShadow_polygon[16]; \n"<br> "uniform float osgShadow_nvert; \n"<br> "\n"<br> "bool pnpoly(vec2 test)\n"<br> "{\n"<br> " bool c = false;"<br> " if (osgShadow_nvert >= 3)\n"<br> " {\n"<br> " int i, j;\n"<br> " for (i = 0, j = int(osgShadow_nvert) - 1; i < int(osgShadow_nvert); j = i++) {\n"<br> " if (((osgShadow_polygon[i].y>test.y) != (osgShadow_polygon[j].y>test.y)) &&\n"<br> " (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"<br> " c = !c;\n"<br> " }\n"<br> " }\n"<br> " return c;\n"<br> "}\n"<br> "\n"<br> "bool is_hole(vec3 pos)\n"<br> "{\n"<br> " return pnpoly(pos.xy);\n"<br> "}\n"<br>};<br><br>static const char fragmentShaderSource[] =<br> "#version 120\n"<br> "\n"<br> "bool is_hole(vec3 pos);\n"<br> "\n"<br> "void main(void) \n"<br> "{ \n"<br> " \n"<br> // early discard<br></div><div> // NOTE: we've previously set up gl_TexCoord[4].xyz to contain vertex coordinates<br></div><div> // so we don't require a vertex shader here that passes us a varying of vertex coords.<br></div> " if (is_hole(gl_TexCoord[4].xyz)) discard;\n"<br><div> " \n"<br></div><div> // remainder of shader is here<br></div><div> "}\n";<br><br><br></div><div class="gmail_extra"><br><div class="gmail_quote">2015-08-17 3:03 GMT+02:00 Erik Hensens <span dir="ltr"><<a href="mailto:ehensens@hunter.com" target="_blank">ehensens@hunter.com</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">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.<br>
<br>
Thanks anyway to everyone who attempted to help!<br>
<br>
------------------<br>
Read this topic online here:<br>
<a href="http://forum.openscenegraph.org/viewtopic.php?p=64791#64791" rel="noreferrer" target="_blank">http://forum.openscenegraph.org/viewtopic.php?p=64791#64791</a><br>
<br>
<br>
<br>
<br>
<br>
_______________________________________________<br>
osg-users mailing list<br>
<a href="mailto:osg-users@lists.openscenegraph.org" target="_blank">osg-users@lists.openscenegraph.org</a><br>
<a href="http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org" rel="noreferrer" target="_blank">http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org</a><br>
</blockquote></div><br></div></div>