本文整理汇总了C++中Shaders::replace方法的典型用法代码示例。如果您正苦于以下问题:C++ Shaders::replace方法的具体用法?C++ Shaders::replace怎么用?C++ Shaders::replace使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Shaders
的用法示例。
在下文中一共展示了Shaders::replace方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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;
}
}
}
//.........这里部分代码省略.........