本文整理汇总了C++中VirtualProgram类的典型用法代码示例。如果您正苦于以下问题:C++ VirtualProgram类的具体用法?C++ VirtualProgram怎么用?C++ VirtualProgram使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了VirtualProgram类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: _batchUpdateInProgress
RexTerrainEngineNode::RexTerrainEngineNode() :
TerrainEngineNode ( ),
_terrain ( 0L ),
_tileCount ( 0 ),
_tileCreationTime ( 0.0 ),
_batchUpdateInProgress( false ),
_refreshRequired ( false ),
_stateUpdateRequired ( false )
{
// Necessary for pager object data
this->setName("osgEarth.RexTerrainEngineNode");
// unique ID for this engine:
_uid = Registry::instance()->createUID();
// always require elevation.
_requireElevationTextures = true;
// install an elevation callback so we can update elevation data
_elevationCallback = new ElevationChangedCallback( this );
// static shaders.
if ( Registry::capabilities().supportsGLSL() )
{
osg::StateSet* stateset = getOrCreateStateSet();
VirtualProgram* vp = VirtualProgram::getOrCreate(stateset);
vp->setName("RexTerrainEngineNode");
vp->setIsAbstract(true); // cannot run by itself, requires additional children
Shaders package;
package.load(vp, package.SDK);
}
// TODO: replace with a "renderer" object that can return statesets
// for different layer types, or something.
_imageLayerStateSet = new osg::StateSet();
}
开发者ID:,项目名称:,代码行数:36,代码来源:
示例2: Stringify
void
DrawInstanced::install(osg::StateSet* stateset)
{
if ( !stateset )
return;
// simple vertex program to position a vertex based on its instance
// matrix, which is stored in a texture.
std::string src_vert = Stringify()
<< "#version 120 \n"
<< "#extension GL_EXT_gpu_shader4 : enable \n"
<< "#extension GL_ARB_draw_instanced: enable \n"
<< "uniform sampler2D oe_di_postex; \n"
<< "uniform vec2 oe_di_postex_size; \n"
<< "void oe_di_setInstancePosition(inout vec4 VertexMODEL) \n"
<< "{ \n"
<< " float index = float(4 * gl_InstanceID) / oe_di_postex_size.x; \n"
<< " float s = fract(index); \n"
<< " float t = floor(index)/oe_di_postex_size.y; \n"
<< " float step = 1.0 / oe_di_postex_size.x; \n" // step from one vec4 to the next
<< " vec4 m0 = texture2D(oe_di_postex, vec2(s, t)); \n"
<< " vec4 m1 = texture2D(oe_di_postex, vec2(s+step, t)); \n"
<< " vec4 m2 = texture2D(oe_di_postex, vec2(s+step+step, t)); \n"
<< " vec4 m3 = texture2D(oe_di_postex, vec2(s+step+step+step, t)); \n"
<< " VertexMODEL = VertexMODEL * mat4(m0, m1, m2, m3); \n" // why???
<< "} \n";
VirtualProgram* vp = VirtualProgram::getOrCreate(stateset);
vp->setFunction(
"oe_di_setInstancePosition",
src_vert,
ShaderComp::LOCATION_VERTEX_MODEL );
stateset->getOrCreateUniform("oe_di_postex", osg::Uniform::SAMPLER_2D)->set(POSTEX_TEXTURE_UNIT);
}
开发者ID:Geo12,项目名称:osgearth,代码行数:36,代码来源:DrawInstanced.cpp
示例3: createMRTPass
osg::Node*
createMRTPass(App& app, osg::Node* sceneGraph)
{
osg::Camera* rtt = new osg::Camera();
rtt->setRenderOrder(osg::Camera::PRE_RENDER);
rtt->setRenderTargetImplementation(osg::Camera::FRAME_BUFFER_OBJECT);
rtt->setViewport(0, 0, app.gcolor->getTextureWidth(), app.gcolor->getTextureHeight());
rtt->setClearMask(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
rtt->attach(osg::Camera::BufferComponent(osg::Camera::COLOR_BUFFER0), app.gcolor);
rtt->attach(osg::Camera::BufferComponent(osg::Camera::COLOR_BUFFER1), app.gnormal);
rtt->attach(osg::Camera::BufferComponent(osg::Camera::COLOR_BUFFER2), app.gdepth);
static const char* vertSource =
"varying float mrt_depth;\n"
"void oe_mrt_vertex(inout vec4 vertexClip)\n"
"{\n"
" mrt_depth = (vertexClip.z/vertexClip.w)*0.5+1.0;\n"
"}\n";
static const char* fragSource =
"varying float mrt_depth;\n"
"vec3 oe_global_Normal; \n"
"void oe_mrt_fragment(inout vec4 color)\n"
"{\n"
" gl_FragData[0] = color; \n"
" gl_FragData[1] = vec4((oe_global_Normal+1.0)/2.0,1.0);\n"
" gl_FragData[2] = vec4(mrt_depth,mrt_depth,mrt_depth,1.0); \n"
"}\n";
VirtualProgram* vp = VirtualProgram::getOrCreate( rtt->getOrCreateStateSet() );
vp->setFunction( "oe_mrt_vertex", vertSource, ShaderComp::LOCATION_VERTEX_CLIP );
vp->setFunction( "oe_mrt_fragment", fragSource, ShaderComp::LOCATION_FRAGMENT_OUTPUT );
rtt->addChild( sceneGraph );
return rtt;
}
开发者ID:3dcl,项目名称:osgearth,代码行数:36,代码来源:osgearth_mrt.cpp
示例4:
void
DepthOffsetAdapter::setGraph(osg::Node* graph)
{
if ( !_supported ) return;
bool graphChanging =
_graph.get() != graph;
bool uninstall =
(_graph.valid() && _graph->getStateSet()) &&
(graphChanging || (_options.enabled() == false));
bool install =
(graph && graphChanging ) ||
(graph && (_options.enabled() == true));
if ( uninstall )
{
OE_TEST << LC << "Removing depth offset shaders" << std::endl;
// uninstall uniforms and shaders.
osg::StateSet* s = _graph->getStateSet();
s->removeUniform( _biasUniform.get() );
s->removeUniform( _rangeUniform.get() );
VirtualProgram* vp = VirtualProgram::get( s );
if ( vp )
{
vp->removeShader( "oe_doff_vertex" );
vp->removeShader( "oe_doff_fragment" );
}
}
if ( install )
{
OE_TEST << LC << "Installing depth offset shaders" << std::endl;
// install uniforms and shaders.
osg::StateSet* s = graph->getOrCreateStateSet();
s->addUniform( _biasUniform.get() );
s->addUniform( _rangeUniform.get() );
VirtualProgram* vp = VirtualProgram::getOrCreate( s );
vp->setFunction( "oe_doff_vertex", s_vertex, ShaderComp::LOCATION_VERTEX_VIEW );
vp->setFunction( "oe_doff_fragment", s_fragment, ShaderComp::LOCATION_FRAGMENT_COLORING );
s->setAttributeAndModes( vp, osg::StateAttribute::ON );
}
if ( graphChanging )
{
_graph = graph;
}
// always set Dirty when setGraph is called sine it may be called anytime
// the subgraph changes (as can be detected by a computeBound)
_dirty = (_options.automatic() == true);
}
开发者ID:APerennec,项目名称:osgearth,代码行数:56,代码来源:DepthOffset.cpp
示例5: Map
void
SimpleOceanNode::rebuild()
{
this->removeChildren( 0, this->getNumChildren() );
osg::ref_ptr<MapNode> mapNode;
if (_parentMapNode.lock(mapNode))
{
const MapOptions& parentMapOptions = mapNode->getMap()->getMapOptions();
const MapNodeOptions& parentMapNodeOptions = mapNode->getMapNodeOptions();
// set up the map to "match" the parent map:
MapOptions mo;
mo.coordSysType() = parentMapOptions.coordSysType();
mo.profile() = mapNode->getMap()->getProfile()->toProfileOptions();
// new data model for the ocean:
Map* oceanMap = new Map( mo );
// ditto with the map node options:
MapNodeOptions mno;
if ( mno.enableLighting().isSet() )
mno.enableLighting() = *mno.enableLighting();
RexTerrainEngineOptions terrainoptions;
terrainoptions.enableBlending() = true; // gotsta blend with the main node
terrainoptions.color() = baseColor().get();
terrainoptions.tileSize() = 5;
mno.setTerrainOptions( terrainoptions );
// make the ocean's map node:
MapNode* oceanMapNode = new MapNode( oceanMap, mno );
// set up the shaders.
osg::StateSet* ss = this->getOrCreateStateSet();
// if the caller requested a mask layer, install that now.
if ( maskLayer().isSet() )
{
if ( !maskLayer()->maxLevel().isSet() )
{
// set the max subdivision level if it's not already specified in the
// mask layer options:
maskLayer()->maxLevel() = maxLOD().get();
}
// make sure the mask is shared (so we can access it from our shader)
// and invisible (so we can't see it)
maskLayer()->shared() = true;
maskLayer()->visible() = false;
ImageLayer* layer = new ImageLayer("ocean-mask", maskLayer().get());
oceanMap->addLayer( layer );
ss->setDefine("OE_SIMPLE_OCEAN_USE_MASK");
OE_INFO << LC << "Using mask layer \"" << layer->getName() << "\"\n";
}
// otherwise, install a "proxy layer" that will use the elevation data in the map
// to determine where the ocean is. This approach is limited in that it cannot
// detect the difference between ocean and inland areas that are below sea level.
else
{
// install an "elevation proxy" layer that reads elevation tiles from the
// parent map and turns them into encoded images for our shader to use.
ImageLayerOptions epo( "ocean-proxy" );
epo.cachePolicy() = CachePolicy::NO_CACHE;
epo.shared() = true;
epo.visible() = false;
epo.shareTexUniformName() = "oe_ocean_proxyTex";
epo.shareTexMatUniformName() = "oe_ocean_proxyMat";
oceanMap->addLayer( new ElevationProxyImageLayer(mapNode->getMap(), epo) );
OE_INFO << LC << "Using elevation proxy layer\n";
}
this->addChild( oceanMapNode );
// install the shaders on the ocean map node.
VirtualProgram* vp = VirtualProgram::getOrCreate( ss );
vp->setName( "osgEarth SimpleOcean" );
Shaders shaders;
shaders.loadAll(vp, 0L);
// set up the options uniforms.
_seaLevel = new osg::Uniform(osg::Uniform::FLOAT, "ocean_seaLevel");
ss->addUniform( _seaLevel.get() );
_lowFeather = new osg::Uniform(osg::Uniform::FLOAT, "ocean_lowFeather");
ss->addUniform( _lowFeather.get() );
_highFeather = new osg::Uniform(osg::Uniform::FLOAT, "ocean_highFeather");
ss->addUniform( _highFeather.get() );
_baseColor = new osg::Uniform(osg::Uniform::FLOAT_VEC4, "ocean_baseColor");
ss->addUniform( _baseColor.get() );
//.........这里部分代码省略.........
开发者ID:JD31,项目名称:osgearth,代码行数:101,代码来源:SimpleOceanNode.cpp
示例6: run
osg::Node* run(osg::Node* earthfile)
{
// 32-bit vertex shader, for reference only. This shader will exceed
// the single-precision capacity and cause "jumping verts" at the
// camera make small movements.
const char* vs32 =
"#version 330 \n"
"uniform mat4 osg_ViewMatrixInverse; \n"
"flat out float isRed; \n"
"void vertex(inout vec4 v32) \n"
"{ \n"
" vec4 world = osg_ViewMatrixInverse * v32; \n"
" world /= world.w; \n"
" float len = length(world); \n"
" const float R = 6371234.5678; \n"
" isRed = 0.0; \n"
" if (len > R) \n"
" isRed = 1.0;"
"}\n";
// 64-bit vertex shader. This shader uses a double-precision inverse
// view matrix and calculates the altitude all in double precision;
// therefore the "jumping verts" problem in the 32-bit version is
// resolved. (Mostly-- you will still see the jumping if you view the
// earth from orbit, because the 32-bit vertex itself is very far from
// the camera in view coordinates. If that is an issue, you need to pass
// in 64-bit vertex attributes.)
const char* vs64 =
"#version 330 \n"
"#extension GL_ARB_gpu_shader_fp64 : enable \n"
"uniform dmat4 u_ViewMatrixInverse64; \n" // must use a 64-bit VMI.
"flat out float isRed; \n"
"flat out double vary64; \n" // just to test shadercomp framework
"void vertex(inout vec4 v32) \n"
"{ \n"
" dvec4 v64 = dvec4(v32); \n" // upcast to 64-bit, no precision loss
// unless camera is very far away
" dvec4 world = u_ViewMatrixInverse64 * v64; \n" // xform into world coords
" world /= world.w; \n" // divide by w
" double len = length(world.xyz); \n" // get double-precision vector length.
" const double R = 6371234.5678; \n" // arbitrary earth radius threshold
" isRed = (len > R) ? 1.0 : 0.0; \n"
"}\n";
// frag shader: color the terrain red if the incoming varying is non-zero.
const char* fs =
"#version 330 \n"
"#extension GL_ARB_gpu_shader_fp64 : enable \n"
"flat in float isRed; \n"
"flat in double vary64; \n"
"void fragment(inout vec4 color) \n"
"{ \n"
" if (isRed > 0.0f) { \n"
" color.r = 1.0; \n"
" color.gb *= 0.5; \n"
" } \n"
"} \n";
// installs a double-precision inverse view matrix for our shader to use.
struct VMI64Callback : public osg::NodeCallback
{
void operator()(osg::Node* node, osg::NodeVisitor* nv)
{
osgUtil::CullVisitor* cv = dynamic_cast<osgUtil::CullVisitor*>(nv);
osg::Uniform* u = new osg::Uniform(osg::Uniform::DOUBLE_MAT4, "u_ViewMatrixInverse64");
u->set(cv->getCurrentCamera()->getInverseViewMatrix());
osg::ref_ptr<osg::StateSet> ss = new osg::StateSet();
ss->addUniform(u);
cv->pushStateSet(ss.get());
traverse(node, nv);
cv->popStateSet();
}
};
earthfile->setCullCallback(new VMI64Callback());
osg::StateSet* ss = earthfile->getOrCreateStateSet();
VirtualProgram* vp = VirtualProgram::getOrCreate(ss);
vp->setFunction("vertex", vs64, ShaderComp::LOCATION_VERTEX_VIEW);
vp->setFunction("fragment", fs, ShaderComp::LOCATION_FRAGMENT_COLORING);
return earthfile;
}
开发者ID:rhabacker,项目名称:osgearth,代码行数:95,代码来源:osgearth_shadercomp.cpp
示例7: getSurfaceStateSet
// Generates the main shader code for rendering the terrain.
void
RexTerrainEngineNode::updateState()
{
if ( _batchUpdateInProgress )
{
_stateUpdateRequired = true;
}
else
{
osg::StateSet* terrainStateSet = _terrain->getOrCreateStateSet(); // everything
osg::StateSet* surfaceStateSet = getSurfaceStateSet(); // just the surface
// required for multipass tile rendering to work
surfaceStateSet->setAttributeAndModes(
new osg::Depth(osg::Depth::LEQUAL, 0, 1, true) );
// activate standard mix blending.
terrainStateSet->setAttributeAndModes(
new osg::BlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA),
osg::StateAttribute::ON );
// install patch param if we are tessellation on the GPU.
if ( _terrainOptions.gpuTessellation() == true )
{
#ifdef HAVE_PATCH_PARAMETER
terrainStateSet->setAttributeAndModes( new osg::PatchParameter(3) );
#endif
}
// install shaders, if we're using them.
if ( Registry::capabilities().supportsGLSL() )
{
Shaders package;
VirtualProgram* terrainVP = VirtualProgram::getOrCreate(terrainStateSet);
terrainVP->setName( "Rex Terrain" );
package.load(terrainVP, package.ENGINE_VERT_MODEL);
//moved to CTOR so it's always available
//package.load(terrainVP, package.SDK);
bool useTerrainColor = _terrainOptions.color().isSet();
package.define("OE_REX_USE_TERRAIN_COLOR", useTerrainColor);
if ( useTerrainColor )
{
surfaceStateSet->addUniform(new osg::Uniform("oe_terrain_color", _terrainOptions.color().get()));
}
bool useBlending = _terrainOptions.enableBlending().get();
package.define("OE_REX_GL_BLENDING", useBlending);
bool morphImagery = _terrainOptions.morphImagery().get();
package.define("OE_REX_MORPH_IMAGERY", morphImagery);
// Funtions that affect only the terrain surface:
VirtualProgram* surfaceVP = VirtualProgram::getOrCreate(surfaceStateSet);
surfaceVP->setName("Rex Surface");
// Functions that affect the terrain surface only:
package.load(surfaceVP, package.ENGINE_VERT_VIEW);
package.load(surfaceVP, package.ENGINE_FRAG);
// Normal mapping shaders:
if ( this->normalTexturesRequired() )
{
package.load(surfaceVP, package.NORMAL_MAP_VERT);
package.load(surfaceVP, package.NORMAL_MAP_FRAG);
}
// Morphing?
if (_terrainOptions.morphTerrain() == true ||
_terrainOptions.morphImagery() == true)
{
package.define("OE_REX_VERTEX_MORPHING", (_terrainOptions.morphTerrain() == true));
package.load(surfaceVP, package.MORPHING_VERT);
}
for(LandCoverZones::iterator zone = _landCoverData._zones.begin(); zone != _landCoverData._zones.end(); ++zone)
{
for(LandCoverBins::iterator bin = zone->_bins.begin(); bin != zone->_bins.end(); ++bin)
{
osg::StateSet* landCoverStateSet = bin->_binProto->getStateSet();
// enable alpha-to-coverage multisampling for vegetation.
landCoverStateSet->setMode(GL_SAMPLE_ALPHA_TO_COVERAGE_ARB, 1);
// uniform that communicates the availability of multisampling.
landCoverStateSet->addUniform( new osg::Uniform(
"oe_terrain_hasMultiSamples",
osg::DisplaySettings::instance()->getMultiSamples()) );
landCoverStateSet->setAttributeAndModes(
new osg::BlendFunc(GL_ONE, GL_ZERO, GL_ONE, GL_ZERO),
osg::StateAttribute::OVERRIDE );
#ifdef HAVE_OSG_PATCH_PARAMETER
landCoverStateSet->setAttributeAndModes( new osg::PatchParameter(3) );
#endif
}
//.........这里部分代码省略.........
开发者ID:rmk177,项目名称:osgearth,代码行数:101,代码来源:RexTerrainEngineNode.cpp
示例8: LocalPerViewData
//.........这里部分代码省略.........
params._rttCamera->setReferenceFrame( osg::Camera::ABSOLUTE_RF_INHERIT_VIEWPOINT );
params._rttCamera->setClearDepth( 1.0 );
params._rttCamera->setClearMask( GL_DEPTH_BUFFER_BIT );
params._rttCamera->setComputeNearFarMode( osg::CullSettings::DO_NOT_COMPUTE_NEAR_FAR );
params._rttCamera->setViewport( 0, 0, *_textureSize, *_textureSize );
params._rttCamera->setRenderOrder( osg::Camera::PRE_RENDER );
params._rttCamera->setRenderTargetImplementation( osg::Camera::FRAME_BUFFER_OBJECT );
params._rttCamera->setImplicitBufferAttachmentMask(0, 0);
params._rttCamera->attach( osg::Camera::DEPTH_BUFFER, local->_rttTexture.get() );
#ifdef DUMP_RTT_IMAGE
local->_rttDebugImage = new osg::Image();
local->_rttDebugImage->allocateImage(4096, 4096, 1, GL_RGB, GL_UNSIGNED_BYTE);
memset( (void*)local->_rttDebugImage->getDataPointer(), 0xff, local->_rttDebugImage->getTotalSizeInBytes() );
params._rttCamera->attach( osg::Camera::COLOR_BUFFER, local->_rttDebugImage.get() );
params._rttCamera->setFinalDrawCallback( new DumpTex(local->_rttDebugImage.get()) );
#endif
#ifdef TIME_RTT_CAMERA
params._rttCamera->setInitialDrawCallback( new RttIn() );
params._rttCamera->setFinalDrawCallback( new RttOut() );
#endif
// set up a StateSet for the RTT camera.
osg::StateSet* rttStateSet = params._rttCamera->getOrCreateStateSet();
rttStateSet->setMode(
GL_BLEND,
osg::StateAttribute::OFF | osg::StateAttribute::OVERRIDE);
// prevents wireframe mode in the depth camera.
rttStateSet->setAttributeAndModes(
new osg::PolygonMode( osg::PolygonMode::FRONT_AND_BACK, osg::PolygonMode::FILL ),
osg::StateAttribute::ON | osg::StateAttribute::PROTECTED );
// attach the terrain to the camera.
// todo: should probably protect this with a mutex.....
params._rttCamera->addChild( _engine ); // the terrain itself.
// assemble the overlay graph stateset.
local->_groupStateSet = new osg::StateSet();
// Required for now, otherwise GPU-clamped geometry will jitter sometimes.
// TODO: figure out why and fix it. This is a workaround for now.
local->_groupStateSet->setDataVariance( osg::Object::DYNAMIC );
local->_groupStateSet->setTextureAttributeAndModes(
_textureUnit,
local->_rttTexture.get(),
osg::StateAttribute::ON | osg::StateAttribute::OVERRIDE );
// set up depth test/write parameters for the overlay geometry:
local->_groupStateSet->setAttributeAndModes(
new osg::Depth( osg::Depth::LEQUAL, 0.0, 1.0, true ),
osg::StateAttribute::ON );
local->_groupStateSet->setRenderingHint( osg::StateSet::TRANSPARENT_BIN );
// uniform for the horizon distance (== max clamping distance)
local->_horizonDistanceUniform = local->_groupStateSet->getOrCreateUniform(
"oe_clamp_horizonDistance",
osg::Uniform::FLOAT );
// sampler for depth map texture:
local->_groupStateSet->getOrCreateUniform(
"oe_clamp_depthTex",
osg::Uniform::SAMPLER_2D )->set( _textureUnit );
// matrix that transforms a vert from EYE coords to the depth camera's CLIP coord.
local->_camViewToDepthClipUniform = local->_groupStateSet->getOrCreateUniform(
"oe_clamp_cameraView2depthClip",
osg::Uniform::FLOAT_MAT4 );
#ifdef SUPPORT_Z
// matrix that transforms a vert from depth clip coords to depth view coords.
local->_depthClipToDepthViewUniform = local->_groupStateSet->getOrCreateUniform(
"oe_clamp_depthClip2depthView",
osg::Uniform::FLOAT_MAT4 );
// matrix that transforms a vert from depth view coords to camera view coords.
local->_depthViewToCamViewUniform = local->_groupStateSet->getOrCreateUniform(
"oe_clamp_depthView2cameraView",
osg::Uniform::FLOAT_MAT4 );
#else
// matrix that transforms a vert from depth-cam CLIP coords to EYE coords.
local->_depthClipToCamViewUniform = local->_groupStateSet->getOrCreateUniform(
"oe_clamp_depthClip2cameraView",
osg::Uniform::FLOAT_MAT4 );
#endif
// make the shader that will do clamping and depth offsetting.
VirtualProgram* vp = VirtualProgram::getOrCreate(local->_groupStateSet.get());
vp->setName( "ClampingTechnique" );
vp->setFunction( "oe_clamp_vertex", clampingVertexShader, ShaderComp::LOCATION_VERTEX_VIEW );
vp->setFunction( "oe_clamp_fragment", clampingFragmentShader, ShaderComp::LOCATION_FRAGMENT_COLORING );
}
开发者ID:DavidLeehome,项目名称:osgearth,代码行数:101,代码来源:ClampingTechnique.cpp
示例9: VirtualProgram
// Generates the main shader code for rendering the terrain.
void
MPTerrainEngineNode::updateState()
{
if ( _batchUpdateInProgress )
{
_stateUpdateRequired = true;
}
else
{
osg::StateSet* terrainStateSet = _terrain->getOrCreateStateSet();
// required for multipass tile rendering to work
terrainStateSet->setAttributeAndModes(
new osg::Depth(osg::Depth::LEQUAL, 0, 1, true) );
// activate standard mix blending.
terrainStateSet->setAttributeAndModes(
new osg::BlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA),
osg::StateAttribute::ON );
// install shaders, if we're using them.
if ( Registry::capabilities().supportsGLSL() )
{
VirtualProgram* vp = new VirtualProgram();
vp->setName( "osgEarth.engine_mp.TerrainNode" );
terrainStateSet->setAttributeAndModes( vp, osg::StateAttribute::ON );
// bind the vertex attributes generated by the tile compiler.
vp->addBindAttribLocation( "oe_terrain_attr", osg::Drawable::ATTRIBUTE_6 );
vp->addBindAttribLocation( "oe_terrain_attr2", osg::Drawable::ATTRIBUTE_7 );
// Vertex shader:
std::string vs = Stringify() <<
"#version " GLSL_VERSION_STR "\n"
GLSL_DEFAULT_PRECISION_FLOAT "\n"
"varying vec4 oe_layer_texc;\n"
"varying vec4 oe_layer_tilec;\n"
"void oe_mp_setup_coloring(inout vec4 VertexModel) \n"
"{ \n"
" oe_layer_texc = gl_MultiTexCoord" << _primaryUnit << ";\n"
" oe_layer_tilec = gl_MultiTexCoord" << _secondaryUnit << ";\n"
"}\n";
bool useTerrainColor = _terrainOptions.color().isSet();
bool useBlending = _terrainOptions.enableBlending() == true;
// Fragment Shader for normal blending:
std::string fs = Stringify() <<
"#version " GLSL_VERSION_STR "\n"
GLSL_DEFAULT_PRECISION_FLOAT "\n"
"varying vec4 oe_layer_texc; \n"
"uniform sampler2D oe_layer_tex; \n"
"uniform int oe_layer_uid; \n"
"uniform int oe_layer_order; \n"
"uniform float oe_layer_opacity; \n"
<< (useTerrainColor ?
"uniform vec4 oe_terrain_color; \n" : ""
) <<
"void oe_mp_apply_coloring(inout vec4 color) \n"
"{ \n"
<< (useTerrainColor ?
" color = oe_terrain_color; \n" : ""
) <<
//" color = vec4(1,1,1,1); \n"
" vec4 texel; \n"
" if ( oe_layer_uid >= 0 ) { \n"
" texel = texture2D(oe_layer_tex, oe_layer_texc.st); \n"
" texel.a *= oe_layer_opacity; \n"
" } \n"
" else \n"
" texel = color; \n"
" "
<< (useBlending ?
" if ( oe_layer_order == 0 ) \n"
" color = texel*texel.a + color*(1.0-texel.a); \n" // simulate src_alpha, 1-src_alpha blens
" else \n" : ""
) <<
" color = texel; \n"
"} \n";
// Color filter frag function:
std::string fs_colorfilters =
"#version " GLSL_VERSION_STR "\n"
GLSL_DEFAULT_PRECISION_FLOAT "\n"
"uniform int oe_layer_uid; \n"
"__COLOR_FILTER_HEAD__"
"void oe_mp_apply_filters(inout vec4 color) \n"
"{ \n"
"__COLOR_FILTER_BODY__"
"} \n";
vp->setFunction( "oe_mp_setup_coloring", vs, ShaderComp::LOCATION_VERTEX_MODEL, 0.0 );
vp->setFunction( "oe_mp_apply_coloring", fs, ShaderComp::LOCATION_FRAGMENT_COLORING, 0.0 );
// assemble color filter code snippets.
bool haveColorFilters = false;
{
std::stringstream cf_head;
//.........这里部分代码省略.........
开发者ID:aurelien35,项目名称:osgearth,代码行数:101,代码来源:MPTerrainEngineNode.cpp
示例10: while
//.........这里部分代码省略.........
eq.getElevations(verts->asVector(), mapNode->getMapSRS(), true, 0.005);
OE_NOTICE << "Building geometry...\n";
osg::Vec3Array* normals = new osg::Vec3Array(verts->size());
osg::Vec4Array* colors = new osg::Vec4Array(verts->size());
Random rng;
for (int i=0; i < verts->size(); i++)
{
GeoPoint vert(mapNode->getMapSRS(), (*verts)[i], osgEarth::ALTMODE_ABSOLUTE);
osg::Vec3d world;
vert.toWorld(world);
(*verts)[i] = world * w2l;
osg::Vec3 normal = world;
normal.normalize();
(*normals)[i] = osg::Matrix::transform3x3(normal, w2l);
double n = rng.next();
(*colors)[i].set( n, n, n, 1 );
}
//create geom and primitive sets
osg::Geometry* geometry = new osg::Geometry();
geometry->setVertexArray( verts );
geometry->setNormalArray( normals );
geometry->setNormalBinding( osg::Geometry::BIND_PER_VERTEX );
geometry->setColorArray(colors);
geometry->setColorBinding( osg::Geometry::BIND_PER_VERTEX );
geometry->addPrimitiveSet( new osg::DrawArrays( GL_POINTS, 0, verts->size() ) );
//create image and texture to render to
osg::Texture2D* tex = new osg::Texture2D(_options.imageURI()->getImage(_dbOptions));
tex->setResizeNonPowerOfTwoHint(false);
tex->setFilter( osg::Texture::MIN_FILTER, osg::Texture::LINEAR_MIPMAP_LINEAR );
tex->setFilter( osg::Texture::MAG_FILTER, osg::Texture::LINEAR );
tex->setWrap(osg::Texture::WRAP_S, osg::Texture::CLAMP_TO_EDGE);
tex->setWrap(osg::Texture::WRAP_T, osg::Texture::CLAMP_TO_EDGE);
geometry->setName("BillboardPoints");
osg::Geode* geode = new osg::Geode;
geode->addDrawable(geometry);
//osg::ref_ptr<StateSetCache> cache = new StateSetCache();
//Registry::shaderGenerator().run(geode, cache.get());
//set the texture related uniforms
osg::StateSet* geode_ss = geode->getOrCreateStateSet();
geode_ss->setTextureAttributeAndModes( 2, tex, 1 );
geode_ss->getOrCreateUniform("billboard_tex", osg::Uniform::SAMPLER_2D)->set( 2 );
float bbWidth = (float)tex->getImage()->s() / 2.0f;
float bbHeight = (float)tex->getImage()->t();
float aspect = (float)tex->getImage()->s() / (float)tex->getImage()->t();
if (_options.height().isSet())
{
bbHeight = _options.height().get();
if (!_options.width().isSet())
{
bbWidth = bbHeight * aspect / 2.0f;
}
}
if (_options.width().isSet())
{
bbWidth = _options.width().get() / 2.0f;
if (!_options.height().isSet())
{
bbHeight = _options.width().get() / aspect;
}
}
geode_ss->getOrCreateUniform("billboard_width", osg::Uniform::FLOAT)->set( bbWidth );
geode_ss->getOrCreateUniform("billboard_height", osg::Uniform::FLOAT)->set( bbHeight );
geode_ss->setMode(GL_BLEND, osg::StateAttribute::ON);
//for now just using an osg::Program
//TODO: need to add GeometryShader support to the shader comp setup
VirtualProgram* vp = VirtualProgram::getOrCreate(geode_ss);
vp->setName( "osgEarth Billboard Extension" );
ShaderPackage shaders;
shaders.add( "Billboard geometry shader", billboardGeomShader );
shaders.add( "Billboard fragment shader", billboardFragShader );
shaders.loadAll( vp );
geode_ss->setMode( GL_CULL_FACE, osg::StateAttribute::OFF );
geode->setCullingActive(false);
mt->addChild(geode);
mapNode->getModelLayerGroup()->addChild(mt);
return true;
}
return false;
}
开发者ID:omega-hub,项目名称:osgearth,代码行数:101,代码来源:BillboardExtension.cpp
示例11: Map
void
SimpleOceanNode::rebuild()
{
this->removeChildren( 0, this->getNumChildren() );
if ( _parentMapNode.valid() )
{
const MapOptions& parentMapOptions = _parentMapNode->getMap()->getMapOptions();
const MapNodeOptions& parentMapNodeOptions = _parentMapNode->getMapNodeOptions();
// set up the map to "match" the parent map:
MapOptions mo;
mo.coordSysType() = parentMapOptions.coordSysType();
mo.profile() = _parentMapNode->getMap()->getProfile()->toProfileOptions();
// new data model for the ocean:
Map* oceanMap = new Map( mo );
// ditto with the map node options:
MapNodeOptions mno;
if ( mno.enableLighting().isSet() )
mno.enableLighting() = *mno.enableLighting();
MPTerrainEngineOptions mpoptions;
mpoptions.heightFieldSkirtRatio() = 0.0; // don't want to see skirts
mpoptions.minLOD() = _options.maxLOD().get(); // weird, I know
// so we can the surface from underwater:
mpoptions.clusterCulling() = false; // want to see underwater
mpoptions.enableBlending() = true; // gotsta blend with the main node
mpoptions.color() = _options.baseColor().get();
mno.setTerrainOptions( mpoptions );
// make the ocean's map node:
MapNode* oceanMapNode = new MapNode( oceanMap, mno );
// if the caller requested a mask layer, install that now.
if ( _options.maskLayer().isSet() )
{
if ( !_options.maskLayer()->maxLevel().isSet() )
{
// set the max subdivision level if it's not already specified in the
// mask layer options:
_options.maskLayer()->maxLevel() = *_options.maxLOD();
}
// make sure the mask is shared (so we can access it from our shader)
// and invisible (so we can't see it)
_options.maskLayer()->shared() = true;
_options.maskLayer()->visible() = false;
ImageLayer* maskLayer = new ImageLayer( "ocean-mask", *_options.maskLayer() );
oceanMap->addImageLayer( maskLayer );
}
// otherwise, install a "proxy layer" that will use the elevation data in the map
// to determine where the ocean is. This approach is limited in that it cannot
// detect the difference between ocean and inland areas that are below sea level.
else
{
// install an "elevation proxy" layer that reads elevation tiles from the
// parent map and turns them into encoded images for our shader to use.
ImageLayerOptions epo( "ocean-proxy" );
epo.cachePolicy() = CachePolicy::NO_CACHE;
//epo.maxLevel() = *_options.maxLOD();
oceanMap->addImageLayer( new ElevationProxyImageLayer(_parentMapNode->getMap(), epo) );
}
this->addChild( oceanMapNode );
// set up the shaders.
osg::StateSet* ss = this->getOrCreateStateSet();
// install the shaders on the ocean map node.
VirtualProgram* vp = VirtualProgram::getOrCreate( ss );
vp->setName( "osgEarth SimpleOcean" );
// use the appropriate shader for the active technique:
std::string vertSource = _options.maskLayer().isSet() ? source_vertMask : source_vertProxy;
std::string fragSource = _options.maskLayer().isSet() ? source_fragMask : source_fragProxy;
vp->setFunction( "oe_ocean_vertex", vertSource, ShaderComp::LOCATION_VERTEX_VIEW );
vp->setFunction( "oe_ocean_fragment", fragSource, ShaderComp::LOCATION_FRAGMENT_COLORING, 0.6f );
// install the slot attribute(s)
ss->getOrCreateUniform( "ocean_data", osg::Uniform::SAMPLER_2D )->set( 0 );
// set up the options uniforms.
_seaLevel = new osg::Uniform(osg::Uniform::FLOAT, "ocean_seaLevel");
ss->addUniform( _seaLevel.get() );
_lowFeather = new osg::Uniform(osg::Uniform::FLOAT, "ocean_lowFeather");
ss->addUniform( _lowFeather.get() );
_highFeather = new osg::Uniform(osg::Uniform::FLOAT, "ocean_highFeather");
ss->addUniform( _highFeather.get() );
//.........这里部分代码省略.........
开发者ID:2php,项目名称:osgearth,代码行数:101,代码来源:SimpleOceanNode.cpp
示例12: getOrCreateStateSet
void
GroundCoverLayer::buildStateSets()
{
// assert we have the necessary TIUs:
if (_groundCoverTexBinding.valid() == false) {
OE_DEBUG << LC << "buildStateSets deferred.. bindings not reserved\n";
return;
}
if (!_zonesConfigured) {
OE_DEBUG << LC << "buildStateSets deferred.. zones not yet configured\n";
return;
}
osg::ref_ptr<LandCoverDictionary> landCoverDict;
if (_landCoverDict.lock(landCoverDict) == false) {
OE_DEBUG << LC << "buildStateSets deferred.. land cover dictionary not available\n";
return;
}
osg::ref_ptr<LandCoverLayer> landCoverLayer;
if (_landCoverLayer.lock(landCoverLayer) == false) {
OE_DEBUG << LC << "buildStateSets deferred.. land cover layer not available\n";
return;
}
NoiseTextureFactory noise;
osg::ref_ptr<osg::Texture> noiseTexture = noise.create(256u, 4u);
GroundCoverShaders shaders;
// Layer-wide stateset:
osg::StateSet* stateset = getOrCreateStateSet();
// bind the noise sampler.
stateset->setTextureAttribute(_noiseBinding.unit(), noiseTexture.get());
stateset->addUniform(new osg::Uniform(NOISE_SAMPLER, _noiseBinding.unit()));
if (_maskLayer.valid())
{
stateset->setDefine("OE_GROUNDCOVER_MASK_SAMPLER", _maskLayer->shareTexUniformName().get());
stateset->setDefine("OE_GROUNDCOVER_MASK_MATRIX", _maskLayer->shareTexMatUniformName().get());
}
// disable backface culling to support shadow/depth cameras,
// for which the geometry shader renders cross hatches instead of billboards.
stateset->setMode(GL_CULL_FACE, osg::StateAttribute::PROTECTED);
// enable alpha-to-coverage multisampling for vegetation.
stateset->setMode(GL_SAMPLE_ALPHA_TO_COVERAGE_ARB, 1);
// uniform that communicates the availability of multisampling.
if (osg::DisplaySettings::instance()->getMultiSamples())
{
stateset->setDefine("OE_GROUNDCOVER_HAS_MULTISAMPLES");
}
stateset->setAttributeAndModes(
new osg::BlendFunc(GL_ONE, GL_ZERO, GL_ONE, GL_ZERO),
osg::StateAttribute::OVERRIDE);
for (Zones::iterator z = _zones.begin(); z != _zones.end(); ++z)
{
Zone* zone = z->get();
GroundCover* groundCover = zone->getGroundCover();
if (groundCover)
{
if (!groundCover->getBiomes().empty() || groundCover->getTotalNumBillboards() > 0)
{
osg::StateSet* zoneStateSet = groundCover->getOrCreateStateSet();
// Install the land cover shaders on the state set
VirtualProgram* vp = VirtualProgram::getOrCreate(zoneStateSet);
vp->setName("Ground cover (" + groundCover->getName() + ")");
shaders.loadAll(vp, getReadOptions());
// Generate the coverage acceptor shader
osg::Shader* covTest = groundCover->createPredicateShader(_landCoverDict.get(), _landCoverLayer.get());
covTest->setName(covTest->getName() + "_GEOMETRY");
covTest->setType(osg::Shader::GEOMETRY);
vp->setShader(covTest);
osg::Shader* covTest2 = groundCover->createPredicateShader(_landCoverDict.get(), _landCoverLayer.get());
covTest->setName(covTest->getName() + "_TESSCONTROL");
covTest2->setType(osg::Shader::TESSCONTROL);
vp->setShader(covTest2);
osg::ref_ptr<osg::Shader> layerShader = groundCover->createShader();
layerShader->setType(osg::Shader::GEOMETRY);
vp->setShader(layerShader.get());
OE_INFO << LC << "Established zone \"" << zone->getName() << "\" at LOD " << getLOD() << "\n";
osg::Texture* tex = groundCover->createTexture();
zoneStateSet->setTextureAttribute(_groundCoverTexBinding.unit(), tex);
zoneStateSet->addUniform(new osg::Uniform(GCTEX_SAMPLER, _groundCoverTexBinding.unit()));
OE_DEBUG << LC << "buildStateSets completed!\n";
//.........这里部分代码省略.........
开发者ID:XenonofArcticus,项目名称:osgearth,代码行数:101,代码来源:GroundCoverLayer.cpp
示例13: reset
osg::Node*
ExtrudeGeometryFilter::push( FeatureList& input, FilterContext& context )
{
reset( context );
// minimally, we require an extrusion symbol.
if ( !_extrusionSymbol.valid() )
{
OE_WARN << LC << "Missing required extrusion symbolology; geometry will be empty" << std::endl;
return new osg::Group();
}
// establish the active resource library, if applicable.
_wallResLib = 0L;
_roofResLib = 0L;
const StyleSheet* sheet = context.getSession() ? context.getSession()->styles() : 0L;
if ( sheet != 0L )
{
if ( _wallSkinSymbol.valid() && _wallSkinSymbol->libraryName().isSet() )
{
_wallResLib = sheet->getResourceLibrary( *_wallSkinSymbol->libraryName() );
if ( !_wallResLib.valid() )
{
OE_WARN << LC << "Unable to load resource library '" << *_wallSkinSymbol->libraryName() << "'"
<< "; wall geometry will not be textured." << std::endl;
_wallSkinSymbol = 0L;
}
}
if ( _roofSkinSymbol.valid() && _roofSkinSymbol->libraryName().isSet() )
{
_roofResLib = sheet->getResourceLibrary( *_roofSkinSymbol->libraryName() );
if ( !_roofResLib.valid() )
{
OE_WARN << LC << "Unable to load resource library '" << *_roofSkinSymbol->libraryName() << "'"
<< "; roof geometry will not be textured." << std::endl;
_roofSkinSymbol = 0L;
}
}
}
// calculate the localization matrices (_local2world and _world2local)
computeLocalizers( context );
// push all the features through the extruder.
bool ok = process( input, context );
// convert everything to triangles and combine drawables.
if ( _mergeGeometry == true && _featureNameExpr.empty() )
{
for( SortedGeodeMap::iterator i = _geodes.begin(); i != _geodes.end(); ++i )
{
MeshConsolidator::run( *i->second.get() );
}
}
// parent geometry with a delocalizer (if necessary)
osg::Group* group = createDelocalizeGroup();
// combines geometries where the statesets are the same.
for( SortedGeodeMap::iterator i = _geodes.begin(); i != _geodes.end(); ++i )
{
group->addChild( i->second.get() );
}
_geodes.clear();
// if we drew outlines, apply a poly offset too.
if ( _outlineSymbol.valid() )
{
osg::StateSet* groupStateSet = group->getOrCreateStateSet();
groupStateSet->setAttributeAndModes( new osg::PolygonOffset(1,1), 1 );
if ( _outlineSymbol->stroke()->width().isSet() )
groupStateSet->setAttributeAndModes( new osg::LineWidth(*_outlineSymbol->stroke()->width()), 1 );
}
// if we have textures, install a shader to draw them
if ( _wallSkinSymbol.valid() || _roofSkinSymbol.valid() )
{
osg::StateSet* stateSet = group->getOrCreateStateSet();
VirtualProgram* vp
|
请发表评论