本文整理汇总了C++中Shaders::define方法的典型用法代码示例。如果您正苦于以下问题:C++ Shaders::define方法的具体用法?C++ Shaders::define怎么用?C++ Shaders::define使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Shaders
的用法示例。
在下文中一共展示了Shaders::define方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
void
BumpMapTerrainEffect::onInstall(TerrainEngineNode* engine)
{
if ( engine && _bumpMapTex.valid() )
{
osg::StateSet* stateset = engine->getTerrainStateSet();
// install the NormalMap texture array:
if ( engine->getResources()->reserveTextureImageUnit(_bumpMapUnit, "BumpMap") )
{
// NormalMap sampler
_bumpMapTexUniform = stateset->getOrCreateUniform(BUMP_SAMPLER, osg::Uniform::SAMPLER_2D);
_bumpMapTexUniform->set( _bumpMapUnit );
stateset->setTextureAttribute( _bumpMapUnit, _bumpMapTex.get(), osg::StateAttribute::ON );
// configure shaders
VirtualProgram* vp = VirtualProgram::getOrCreate(stateset);
Shaders package;
package.define( "OE_USE_NORMAL_MAP", engine->normalTexturesRequired() );
package.loadFunction( vp, package.VertexModel );
package.loadFunction( vp, package.VertexView );
package.loadFunction( vp, _octaves <= 1? package.FragmentSimple : package.FragmentProgressive );
if ( _octaves > 1 )
stateset->addUniform(new osg::Uniform("oe_bumpmap_octaves", _octaves));
stateset->addUniform(new osg::Uniform("oe_bumpmap_maxRange", _maxRange));
stateset->addUniform( _scaleUniform.get() );
stateset->addUniform( _intensityUniform.get() );
}
}
}
示例2:
void
BumpMapTerrainEffect::onInstall(TerrainEngineNode* engine)
{
if ( engine && _bumpMapTex.valid() )
{
osg::StateSet* stateset = engine->getSurfaceStateSet();
// install the NormalMap texture array:
if ( engine->getResources()->reserveTextureImageUnit(_bumpMapUnit, "BumpMap") )
{
// NormalMap sampler
_bumpMapTexUniform = stateset->getOrCreateUniform(BUMP_SAMPLER, osg::Uniform::SAMPLER_2D);
_bumpMapTexUniform->set( _bumpMapUnit );
stateset->setTextureAttribute( _bumpMapUnit, _bumpMapTex.get() );
// configure shaders
VirtualProgram* vp = VirtualProgram::getOrCreate(stateset);
Shaders package;
package.define( "OE_USE_NORMAL_MAP", false ); //engine->normalTexturesRequired() );
//package.load( vp, package.VertexModel );
package.load( vp, package.VertexView );
package.load( vp, _octaves <= 1? package.FragmentSimple : package.FragmentProgressive );
if ( _octaves > 1 )
stateset->addUniform(new osg::Uniform("oe_bumpmap_octaves", _octaves));
stateset->addUniform(new osg::Uniform("oe_bumpmap_maxRange", _maxRange));
stateset->addUniform(new osg::Uniform("oe_bumpmap_slopeFactor", 1.0f));
stateset->addUniform(new osg::Uniform("oe_bumpmap_baseLOD", (float)_baseLOD));
stateset->addUniform( _scaleUniform.get() );
stateset->addUniform( _intensityUniform.get() );
}
else
{
OE_WARN << LC << "Failed to allocation a texture image unit!\n";
}
}
}
示例3: Depth
// Generates the main shader code for rendering the terrain.
void
MPTerrainEngineNode::updateState()
{
if ( _batchUpdateInProgress )
{
_stateUpdateRequired = true;
}
else
{
if ( _elevationTextureUnit < 0 && elevationTexturesRequired() )
{
getResources()->reserveTextureImageUnit( _elevationTextureUnit, "MP Engine Elevation" );
}
osg::StateSet* terrainStateSet = getTerrainStateSet();
// 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 );
Shaders package;
package.replace( "$MP_PRIMARY_UNIT", Stringify() << _primaryUnit );
package.replace( "$MP_SECONDARY_UNIT", Stringify() << (_secondaryUnit>=0?_secondaryUnit:0) );
package.define( "MP_USE_BLENDING", (_terrainOptions.enableBlending() == true) );
package.loadFunction( vp, package.VertexModel );
package.loadFunction( vp, package.VertexView );
package.loadFunction( vp, package.Fragment );
// terrain background color; negative means use the vertex color.
Color terrainColor = _terrainOptions.color().getOrUse( Color(1,1,1,-1) );
terrainStateSet->addUniform(new osg::Uniform("oe_terrain_color", terrainColor));
// assemble color filter code snippets.
bool haveColorFilters = false;
{
// 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";
std::stringstream cf_head;
std::stringstream cf_body;
const char* I = " ";
// second, install the per-layer color filter functions AND shared layer bindings.
bool ifStarted = false;
int numImageLayers = _update_mapf->imageLayers().size();
for( int i=0; i<numImageLayers; ++i )
{
ImageLayer* layer = _update_mapf->getImageLayerAt(i);
if ( layer->getEnabled() )
{
// install Color Filter function calls:
const ColorFilterChain& chain = layer->getColorFilters();
if ( chain.size() > 0 )
{
haveColorFilters = true;
if ( ifStarted ) cf_body << I << "else if ";
else cf_body << I << "if ";
cf_body << "(oe_layer_uid == " << layer->getUID() << ") {\n";
for( ColorFilterChain::const_iterator j = chain.begin(); j != chain.end(); ++j )
{
const ColorFilter* filter = j->get();
cf_head << "void " << filter->getEntryPointFunctionName() << "(inout vec4 color);\n";
cf_body << I << I << filter->getEntryPointFunctionName() << "(color);\n";
filter->install( terrainStateSet );
}
cf_body << I << "}\n";
ifStarted = true;
}
}
}
//.........这里部分代码省略.........
示例4: Depth
// 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
}
//.........这里部分代码省略.........