Yes, this is absolutely the way skyboxes should "usually" be done, as  
rendering front to back typically increases fill performance. I've  
done this many times with custom OpenGL code, but not with OSG (this  
is my first OSG project).

However, in my case I would need the frustum to be much smaller than  
the skydome geometry. I'm having Z-fighting issues because my frustum  
is too big.... but that is not the only issue.  Actually, the changing  
of the depth test is actually quite clever, I wish I had thought of  
that!  However, I also have some transparent items, so the sky still  
needs to be drawn first (and I did neglect to mention this to be  
fair). As a side issue I am also thinking about high quality sky  
rendering, in which case the sky can consist of several transparent  
layers rendered back to front too.

For my immediate needs, I have solved the problem (as in I have coded  
and tested this), but I'm still curious about the depth partitioning  
node (another thread) that would also solved this problem (and a few  
others I can foresee down the road).

Richard


On Dec 17, 2007, at 9:17 PM, Jean-Sébastien Guay wrote:

> Hello Richard,
>
>> Being able to render something last... that could be useful. But I'm
>> thinking I want to render the skydome _first_, using a "painters
>> algorithm" and drawing everything else in front of it. It seems this
>> would also be the best approach for a rendering a night time sky  
>> using
>> point sprites for the stars, etc.
>
> Why do you want to render it first, and then have it be overwritten by
> your objects, which might (worst case) result in having drawn the
> whole screen twice for nothing?
>
> Render it last, but only setting pixels at the far plane. That way,
> pixels that contain other objects will not be overwritten by your
> skydome.
>
> For example, this is from the skybox code in my current project, but I
> can't take credit as most of it was lifted from a post to this very
> mailing list. Unfortunately, it's from the old list server and I can't
> seem to find the message in the current archives. The old link was:
> http://openscenegraph.org/archiver/osg-users/2005-June/0581.html
>
>
>     osg::StateSet* stateset = new osg::StateSet;
>
>     // Set texture mode to REPLACE
>     osg::TexEnv* te = new osg::TexEnv;
>     te->setMode(osg::TexEnv::REPLACE);
>     stateset->setTextureAttributeAndModes(0, te,  
> osg::StateAttribute::ON);
>
>     // Turn off lighting and cull face
>     stateset->setMode(GL_LIGHTING,  osg::StateAttribute::OFF);
>     stateset->setMode(GL_CULL_FACE, osg::StateAttribute::OFF);
>
>     // Basic principle of skyboxes: render it last, and with a depth  
> func
>     // that only sets pixels at the far plane. That way, if the sky  
> is not
>     // visible at all for example, the sky won't be drawn (and  
> possibly
>     // fragment shaders will not be called) whereas rendering it  
> first will
>     // cause all pixels to be written, then overwritten by objects,  
> and
>     // possibly fragment shaders will have been called for nothing.
>
>     // Clear the depth to the far plane.
>     osg::Depth* depth = new osg::Depth(osg::Depth::LEQUAL, 1.0, 1.0);
>     stateset->setAttributeAndModes(depth, osg::StateAttribute::ON);
>
>     // Make pretty darn sure it is drawn last.
>     stateset->setRenderBinDetails(1000, "RenderBin");
>
>     // Create a drawable for the skybox.
>     osg::Geometry* drawable = new osg::Geometry;
>
>     // Create vertices for box
>     // [...]
>
>     // Create texture coordinates for cubemaps
>     // [...]
>
>     // Create an index array for the box
>     // [...]
>
>     // Create a geode for the skybox
>     osg::Geode* geode = new osg::Geode;
>     geode->setName("Skybox");
>
>     // Disable culling
>     geode->setCullingActive(false);
>
>     // Set the stateset
>     geode->setStateSet(stateset);
>
>     // Add the skybox
>     geode->addDrawable(drawable);
>
>     // Next is setting the texture and the transform node...
>     // [...]
>
> -- 
> ______________________________________________________
> Jean-Sebastien Guay     [EMAIL PROTECTED]
>                         http://whitestar02.webhop.org/
>
> ----------------------------------------------------------------
> This message was sent using IMP, the Internet Messaging Program.
>
>
> _______________________________________________
> osg-users mailing list
> [email protected]
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to