Created
February 26, 2015 22:19
-
-
Save gwaldron/187b95865d82dc74fdd3 to your computer and use it in GitHub Desktop.
final.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* -*-c++-*- */ | |
/* osgEarth - Dynamic map generation toolkit for OpenSceneGraph | |
* Copyright 2008-2014 Pelican Mapping | |
* http://osgearth.org | |
* | |
* osgEarth is free software; you can redistribute it and/or modify | |
* it under the terms of the GNU Lesser General Public License as published by | |
* the Free Software Foundation; either version 2 of the License, or | |
* (at your option) any later version. | |
* | |
* This program is distributed in the hope that it will be useful, | |
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
* GNU Lesser General Public License for more details. | |
* | |
* You should have received a copy of the GNU Lesser General Public License | |
* along with this program. If not, see <http://www.gnu.org/licenses/> | |
*/ | |
#include <osgViewer/Viewer> | |
#include <osgEarth/Notify> | |
#include <osgEarthUtil/EarthManipulator> | |
#include <osgEarthUtil/ExampleResources> | |
#include <osgEarth/ShaderLoader> | |
#include <osgEarth/VirtualProgram> | |
#include <osg/Uniform> | |
const char* vs = OE_MULTILINE( | |
#pragma vp_entryPoint "oe_grid_vertex"\n | |
#pragma vp_location "vertex_view"\n | |
uniform vec4 oe_tile_key; | |
varying vec4 oe_layer_tilec; | |
varying vec2 oe_grid_coord; | |
void oe_grid_vertex(inout vec4 vertex) | |
{ | |
// calculate long and lat from [0..1] across the profile: | |
vec2 r = (oe_tile_key.xy + oe_layer_tilec.xy)/exp2(oe_tile_key.z); | |
oe_grid_coord = vec2(0.5*r.x, r.y); | |
} | |
); | |
const char* fs = OE_MULTILINE( | |
#pragma vp_entryPoint "oe_grid_fragment"\n | |
#pragma vp_location "fragment_coloring"\n | |
uniform float gridLineWidth; | |
uniform float gridResolution; | |
uniform float gridAlpha; | |
varying vec2 oe_grid_coord; | |
void oe_grid_fragment(inout vec4 color) | |
{ | |
// double the effective res for longitude since it has twice the span | |
vec2 gr = vec2(0.5*gridResolution, gridResolution); | |
vec2 distanceToLine = mod(oe_grid_coord, gr); | |
vec2 dx = abs(dFdx(oe_grid_coord)); | |
vec2 dy = abs(dFdy(oe_grid_coord)); | |
vec2 dF = vec2(max(dx.s, dy.s), max(dx.t, dy.t)) * gridLineWidth; | |
if ( any(lessThan(distanceToLine, dF)) ) | |
{ | |
color.rgb = mix(color.rgb, vec3(1,1,0), gridAlpha); | |
} | |
} | |
); | |
#define LC "[viewer] " | |
using namespace osgEarth; | |
using namespace osgEarth::Util; | |
int | |
usage(const char* name) | |
{ | |
OE_NOTICE | |
<< "\nUsage: " << name << " file.earth" << std::endl | |
<< MapNodeHelper().usage() << std::endl; | |
return 0; | |
} | |
int | |
main(int argc, char** argv) | |
{ | |
osg::ArgumentParser arguments(&argc,argv); | |
// help? | |
if ( arguments.read("--help") ) | |
return usage(argv[0]); | |
if ( arguments.read("--stencil") ) | |
osg::DisplaySettings::instance()->setMinimumNumStencilBits( 8 ); | |
// 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() ); | |
// 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 ) | |
{ | |
viewer.setSceneData( node ); | |
osg::StateSet* ss = MapNode::get(node)->getTerrainEngine()->getOrCreateStateSet(); | |
VirtualProgram* vp = VirtualProgram::getOrCreate(ss); | |
ShaderPackage sp; | |
sp.add( "Vertex", vs ); | |
sp.add( "Fragment", fs ); | |
sp.loadFunction( vp, "Vertex" ); | |
sp.loadFunction( vp, "Fragment" ); | |
const SpatialReference* srs = SpatialReference::get("wgs84"); | |
osg::Vec3f escale( | |
1.0/srs->getEllipsoid()->getRadiusEquator(), | |
1.0/srs->getEllipsoid()->getRadiusEquator(), | |
1.0/srs->getEllipsoid()->getRadiusPolar()); | |
ss->addUniform(new osg::Uniform("oe_grid_ellipsoidScale", escale)); | |
ss->addUniform(new osg::Uniform("gridLineWidth", 3.0f)); | |
ss->addUniform(new osg::Uniform("gridResolution", 0.125f)); | |
ss->addUniform(new osg::Uniform("gridAlpha", 0.5f)); | |
//viewer.getCamera()->setNearFarRatio(0.00002); | |
viewer.getCamera()->setSmallFeatureCullingPixelSize(-1.0f); | |
return viewer.run(); | |
} | |
else | |
{ | |
return usage(argv[0]); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment