本文整理汇总了C++中VirtualProgram::setUseLightingShaders方法的典型用法代码示例。如果您正苦于以下问题:C++ VirtualProgram::setUseLightingShaders方法的具体用法?C++ VirtualProgram::setUseLightingShaders怎么用?C++ VirtualProgram::setUseLightingShaders使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类VirtualProgram
的用法示例。
在下文中一共展示了VirtualProgram::setUseLightingShaders方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
bool
ShaderGenerator::processText( osg::StateSet* ss, osg::ref_ptr<osg::StateSet>& replacement )
{
// do nothing if there's no GLSL support
if ( !Registry::capabilities().supportsGLSL() )
return false;
// State object with extra accessors:
StateEx* state = static_cast<StateEx*>(_state.get());
// check for a real osg::Program. If it exists, bail out so that OSG
// can use the program already in the graph
osg::StateAttribute* program = state->getAttribute(osg::StateAttribute::PROGRAM);
if ( dynamic_cast<osg::Program*>(program) != 0L )
return false;
// see if the current state set contains a VirtualProgram already. If so,
// we will add to it if necessary.
VirtualProgram* vp = dynamic_cast<VirtualProgram*>( ss->getAttribute(VirtualProgram::SA_TYPE) );
replacement = osg::clone(ss, osg::CopyOp::DEEP_COPY_ALL);
std::string vertSrc =
"#version " GLSL_VERSION_STR "\n" GLSL_PRECISION "\n"
"varying " MEDIUMP "vec4 " TEX_COORD_TEXT ";\n"
"void " VERTEX_FUNCTION "()\n"
"{ \n"
INDENT TEX_COORD_TEXT " = gl_MultiTexCoord0;\n"
"} \n";
std::string fragSrc =
"#version " GLSL_VERSION_STR "\n" GLSL_PRECISION "\n"
"uniform sampler2D " SAMPLER_TEXT ";\n"
"varying " MEDIUMP "vec4 " TEX_COORD_TEXT ";\n"
"void " FRAGMENT_FUNCTION "(inout vec4 color)\n"
"{ \n"
INDENT MEDIUMP "vec4 texel = texture2D(" SAMPLER_TEXT ", " TEX_COORD_TEXT ".xy);\n"
INDENT "color.a *= texel.a; \n"
"}\n";
if ( !vp )
vp = osg::clone( _defaultVP.get() );
replacement->setAttributeAndModes( vp, osg::StateAttribute::ON );
vp->setUseLightingShaders( false );
vp->setFunction( VERTEX_FUNCTION, vertSrc, ShaderComp::LOCATION_VERTEX_PRE_LIGHTING );
vp->setFunction( FRAGMENT_FUNCTION, fragSrc, ShaderComp::LOCATION_FRAGMENT_PRE_LIGHTING );
replacement->getOrCreateUniform( SAMPLER_TEXT, osg::Uniform::SAMPLER_2D )->set( 0 );
return replacement.valid();
}