osgEarth 2.1.1
|
#include <osg/Notify>
#include <osgGA/StateSetManipulator>
#include <osgViewer/Viewer>
#include <osgViewer/ViewerEventHandlers>
#include <osgEarthUtil/EarthManipulator>
#include <osgEarth/ShaderComposition>
#include <osgEarth/Registry>
Go to the source code of this file.
Functions | |
osg::StateAttribute * | createHaze () |
int | usage (const std::string &msg) |
int | main (int argc, char **argv) |
Variables | |
static char | s_hazeVertShader [] = "} \n" |
static char | s_hazeFragShader [] = "} \n" |
osg::StateAttribute * createHaze | ( | ) |
This sample demonstrates a simple use of osgEarth's shader composition framework.
By default, osgEarth uses GL shaders to render the terrain. Shader composition is a mechanism by which you can inject custom shader code into osgEarth's shader program pipeline. This gets around the problem of having to duplicate shader code in order to add functionality.
Definition at line 95 of file osgearth_shadercomp.cpp.
{ osgEarth::VirtualProgram* vp = new osgEarth::VirtualProgram(); vp->setFunction( "setup_haze", s_hazeVertShader, osgEarth::ShaderComp::LOCATION_VERTEX_POST_LIGHTING ); vp->setFunction( "apply_haze", s_hazeFragShader, osgEarth::ShaderComp::LOCATION_FRAGMENT_POST_LIGHTING ); return vp; }
int main | ( | int | argc, |
char ** | argv | ||
) |
Definition at line 47 of file osgearth_shadercomp.cpp.
{ osg::ArgumentParser arguments(&argc,argv); osg::Node* earthNode = osgDB::readNodeFiles( arguments ); if (!earthNode) { return usage( "Unable to load earth model." ); } osg::Group* root = new osg::Group(); root->addChild( earthNode ); osgViewer::Viewer viewer(arguments); viewer.setCameraManipulator( new osgEarth::Util::EarthManipulator() ); viewer.setSceneData( root ); // inject the haze shader components: root->getOrCreateStateSet()->setAttributeAndModes( createHaze(), osg::StateAttribute::ON ); // add some stock OSG handlers: viewer.addEventHandler(new osgViewer::StatsHandler()); viewer.addEventHandler(new osgViewer::WindowSizeHandler()); viewer.addEventHandler(new osgViewer::ThreadingHandler()); viewer.addEventHandler(new osgGA::StateSetManipulator(viewer.getCamera()->getOrCreateStateSet())); return viewer.run(); }
int usage | ( | const std::string & | msg | ) |
Definition at line 38 of file osgearth_shadercomp.cpp.
{ OE_NOTICE << msg << std::endl << "USAGE: osgearth_shadercomp <earthfile>" << std::endl; return -1; }
char s_hazeFragShader[] = "} \n" [static] |
Definition at line 85 of file osgearth_shadercomp.cpp.
char s_hazeVertShader[] = "} \n" [static] |
Definition at line 78 of file osgearth_shadercomp.cpp.