int main(int argc, char** argv) { osg::ArgumentParser arguments(&argc, argv); if (arguments.read("--help")) return usage(argv[0]); // create a viewer: osgViewer::Viewer viewer(arguments); // install our default manipulator (do this before calling load) viewer.setCameraManipulator( new EarthManipulator() ); // Set up the app and read options: App app; std::string filename( "../data/noise3.png" ); arguments.read( "--image", filename ); osg::Image* image = URI(filename).getImage(); if ( !image ) return usage( "Failed to load image" ); app.dt.setImage( image ); unsigned startLOD; if ( arguments.read("--lod", startLOD) ) app.dt.setBaseLOD(startLOD); // Create the UI: ui::Control* demoui = createUI(app); // load an earth file, and support all or our example command-line options // and earth file <external> tags osg::Node* node = MapNodeHelper().load( arguments, &viewer, demoui ); if ( node ) { MapNode* mapNode = MapNode::findMapNode(node); if ( !mapNode ) return -1; // bind a texture image unit for our detail texture. int unit = 1; if ( mapNode->getTerrainEngine()->getTextureCompositor()->reserveTextureImageUnit(unit) ) app.dt.setImageUnit( unit ); // attach the detailer to the terrain. app.dt.setTerrainNode( mapNode->getTerrainEngine() ); viewer.setSceneData( node ); viewer.run(); } else { return usage("no earth file"); } return 0; }
int main(int argc, char** argv) { osg::ArgumentParser arguments(&argc, argv); // create a viewer: osgViewer::Viewer viewer(arguments); // Tell osgEarth to use the "quadtree" terrain driver by default. // Elevation data attribution is only available in this driver! osgEarth::Registry::instance()->setDefaultTerrainEngineDriverName( "quadtree" ); // install our default manipulator (do this before calling load) viewer.setCameraManipulator( new EarthManipulator() ); // load an earth file, and support all or our example command-line options // and earth file <external> tags osg::Node* node = MapNodeHelper().load( arguments, &viewer ); if ( node ) { MapNode* mapNode = MapNode::findMapNode(node); if ( !mapNode ) return -1; if ( mapNode->getMap()->getNumElevationLayers() == 0 ) OE_WARN << "No elevation layers! The contour will be very boring." << std::endl; // Set up a transfer function for the elevation contours. osg::ref_ptr<osg::TransferFunction1D> xfer = new osg::TransferFunction1D(); xfer->setColor( -3000.0f, osg::Vec4f(0,0,0.5,1), false ); xfer->setColor( -10.0f, osg::Vec4f(0,0,0,1), false ); xfer->setColor( 10.0f, osg::Vec4f(0,1,0,1), false ); xfer->setColor( 1500.0f, osg::Vec4f(1,0,0,1), false ); xfer->setColor( 3000.0f, osg::Vec4f(1,1,1,1), false ); xfer->updateImage(); // request an available texture unit: int unit; mapNode->getTerrainEngine()->getTextureCompositor()->reserveTextureImageUnit(unit); // install the contour shaders: osg::Group* root = new osg::Group(); root->setStateSet( createStateSet(xfer.get(), unit) ); root->addChild( node ); viewer.setSceneData( root ); viewer.run(); } else { OE_NOTICE << "\nUsage: " << argv[0] << " file.earth" << std::endl << MapNodeHelper().usage() << std::endl; } return 0; }
int main(int argc, char** argv) { osg::ArgumentParser arguments(&argc, argv); if (arguments.read("--help")) return usage(argv[0]); // create a viewer: osgViewer::Viewer viewer(arguments); // install our default manipulator (do this before calling load) viewer.setCameraManipulator( new EarthManipulator() ); // Set up the app create the UI: App app; ui::Control* demo_ui = createUI(app); // load an earth file, and support all or our example command-line options // and earth file <external> tags osg::Node* node = MapNodeHelper().load( arguments, &viewer, demo_ui ); if ( node ) { MapNode* mapNode = MapNode::get(node); if ( !mapNode ) return -1; app.engine = mapNode->getTerrainEngine(); viewer.setSceneData( node ); viewer.run(); } else { return usage("no earth file"); } return 0; }
bool ShadowUtils::setUpShadows(osgShadow::ShadowedScene* sscene, osg::Group* root) { osg::StateSet* ssStateSet = sscene->getOrCreateStateSet(); MapNode* mapNode = MapNode::findMapNode(root); TerrainEngineNode* engine = mapNode->getTerrainEngine(); if (!engine) return false; TextureCompositor* compositor = engine->getTextureCompositor(); int su = -1; if (!compositor->reserveTextureImageUnit(su)) return false; OE_INFO << LC << "Reserved texture unit " << su << " for shadowing" << std::endl; osgShadow::ViewDependentShadowMap* vdsm = dynamic_cast< osgShadow::ViewDependentShadowMap*>(sscene->getShadowTechnique()); int su1 = -1; if (vdsm && sscene->getShadowSettings()->getNumShadowMapsPerLight() == 2) { if (!compositor->reserveTextureImageUnit(su1) || su1 != su + 1) { OE_FATAL << LC << "couldn't get contiguous shadows for split vdsm\n"; sscene->getShadowSettings()->setNumShadowMapsPerLight(1); if (su1 != -1) compositor->releaseTextureImageUnit(su1); su1 = -1; } else { OE_INFO << LC << "Reserved texture unit " << su1 << " for shadowing" << std::endl; } } // create a virtual program to attach to the shadowed scene. VirtualProgram* vp = new VirtualProgram(); vp->setName( "shadow:terrain" ); //vp->installDefaultColoringAndLightingShaders(); ssStateSet->setAttributeAndModes( vp, 1 ); std::stringstream buf; buf << "#version " << GLSL_VERSION_STR << "\n"; #ifdef OSG_GLES2_AVAILABLE buf << "precision mediump float;\n"; #endif buf << "varying vec4 oe_shadow_ambient;\n"; buf << "varying vec4 oe_shadow_TexCoord0;\n"; if ( su1 >= 0 ) buf << "varying vec4 oe_shadow_TexCoord1;\n"; buf << "void oe_shadow_setupShadowCoords(inout vec4 VertexVIEW)\n"; buf << "{\n"; buf << " vec4 position4 = VertexVIEW;\n"; buf << " oe_shadow_TexCoord0.s = dot( position4, gl_EyePlaneS[" << su <<"]);\n"; buf << " oe_shadow_TexCoord0.t = dot( position4, gl_EyePlaneT[" << su <<"]);\n"; buf << " oe_shadow_TexCoord0.p = dot( position4, gl_EyePlaneR[" << su <<"]);\n"; buf << " oe_shadow_TexCoord0.q = dot( position4, gl_EyePlaneQ[" << su <<"]);\n"; if (su1 >= 0) { buf << " oe_shadow_TexCoord1.s = dot( position4, gl_EyePlaneS[" << su1 <<"]);\n"; buf << " oe_shadow_TexCoord1.t = dot( position4, gl_EyePlaneT[" << su1 <<"]);\n"; buf << " oe_shadow_TexCoord1.p = dot( position4, gl_EyePlaneR[" << su1 <<"]);\n"; buf << " oe_shadow_TexCoord1.q = dot( position4, gl_EyePlaneQ[" << su1 <<"]);\n"; } // the ambient lighting will control the intensity of the shadow. buf << " oe_shadow_ambient = gl_FrontLightProduct[0].ambient; \n" << "}\n"; std::string setupShadowCoords; setupShadowCoords = buf.str(); vp->setFunction( "oe_shadow_setupShadowCoords", setupShadowCoords, ShaderComp::LOCATION_VERTEX_VIEW, -1.0 ); std::stringstream buf2; buf2 << "#version " << GLSL_VERSION_STR << "\n" #ifdef OSG_GLES2_AVAILABLE "precision mediump float;\n" #endif "uniform sampler2DShadow shadowTexture;\n" "varying vec4 oe_shadow_TexCoord0;\n"; if (su1 >= 0) { // bound by vdsm buf2 << "uniform sampler2DShadow shadowTexture1;\n"; buf2 << "varying vec4 oe_shadow_TexCoord1;\n"; } buf2 << "varying vec4 oe_shadow_ambient;\n" "void oe_shadow_applyLighting( inout vec4 color )\n" "{\n" " float alpha = color.a;\n" " float shadowFac = shadow2DProj( shadowTexture, oe_shadow_TexCoord0).r;\n"; if (su1 > 0) { buf2 << " shadowFac *= shadow2DProj( shadowTexture1, oe_shadow_TexCoord1).r;\n"; } // calculate the shadowed color and mix if with the lit color based on the // ambient lighting. The 0.5 is a multiplier that darkens the shadow in // proportion to ambient light. It should probably be a uniform. buf2 << " vec4 colorInFullShadow = color * oe_shadow_ambient; \n" " color = mix(colorInFullShadow, color, shadowFac); \n" " color.a = alpha;\n" "}\n"; std::string fragApplyLighting; fragApplyLighting = buf2.str(); vp->setFunction( "oe_shadow_applyLighting", fragApplyLighting, osgEarth::ShaderComp::LOCATION_FRAGMENT_LIGHTING ); setShadowUnit(sscene, su); // VDSM uses a different sampler name, shadowTexture0. ssStateSet ->getOrCreateUniform("shadowTexture", osg::Uniform::SAMPLER_2D_SHADOW) ->set(su); return true; }
int main(int argc, char** argv) { osg::ArgumentParser arguments(&argc,argv); // help? if ( arguments.read("--help") ) return usage(argv[0]); // create a viewer: osgViewer::Viewer viewer(arguments); // Tell the database pager to not modify the unref settings viewer.getDatabasePager()->setUnrefImageDataAfterApplyPolicy( false, false ); // install our default manipulator (do this before calling load) viewer.setCameraManipulator( new EarthManipulator(arguments) ); // disable the small-feature culling viewer.getCamera()->setSmallFeatureCullingPixelSize(-1.0f); // set a near/far ratio that is smaller than the default. This allows us to get // closer to the ground without near clipping. If you need more, use --logdepth viewer.getCamera()->setNearFarRatio(0.0001); // load an earth file, and support all or our example command-line options // and earth file <external> tags osg::Node* node = MapNodeHelper().load( arguments, &viewer ); if ( node ) { // Get the MapNode MapNode* mapNode = MapNode::findMapNode( node ); // Find the Splat Extension SplatExtension* splatExtension = mapNode->getExtension<SplatExtension>(); if (splatExtension) { OE_NOTICE << "Found Splat Extension" << std::endl; } LandCoverTerrainEffect* landCoverEffect = mapNode->getTerrainEngine()->getEffect<LandCoverTerrainEffect>(); if (landCoverEffect) { OE_NOTICE << "Found landcover terrain effect" << std::endl; for (Zones::const_iterator zoneItr = landCoverEffect->getZones().begin(); zoneItr != landCoverEffect->getZones().end(); ++zoneItr) { // Get the StateSet for each of the LandCoverLayers for (LandCoverLayers::iterator landCoverItr = zoneItr->get()->getLandCover()->getLayers().begin(); landCoverItr != zoneItr->get()->getLandCover()->getLayers().end(); ++landCoverItr) { // Get the stateset for the layer. osg::StateSet* stateset = landCoverItr->get()->getOrCreateStateSet(); // Get the VirtualProgram for this layer. VirtualProgram* vp = VirtualProgram::getOrCreate(stateset); // Make the "tree" layer all red. if (landCoverItr->get()->getName() == "trees") { vp->setFunction( "color_landcover", color_landcover, ShaderComp::LOCATION_FRAGMENT_LIGHTING); } } } } viewer.setSceneData( node ); while(!viewer.done()) { viewer.frame(); } } else { return usage(argv[0]); } }