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

Reply via email to