当前位置: 首页>>代码示例>>C++>>正文


C++ VirtualProgram::setFunction方法代码示例

本文整理汇总了C++中VirtualProgram::setFunction方法的典型用法代码示例。如果您正苦于以下问题:C++ VirtualProgram::setFunction方法的具体用法?C++ VirtualProgram::setFunction怎么用?C++ VirtualProgram::setFunction使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在VirtualProgram的用法示例。


在下文中一共展示了VirtualProgram::setFunction方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: VirtualProgram

FadeLOD::FadeLOD() :
_minPixelExtent( 0.0f ),
_maxPixelExtent( FLT_MAX ),
_minFadeExtent ( 0.0f ),
_maxFadeExtent ( 0.0f )
{
    if ( Registry::capabilities().supportsGLSL() )
    {
        VirtualProgram* vp = new VirtualProgram();

        vp->setFunction(
            "oe_fragFadeLOD",
            FadeLODFragmentShader,
            ShaderComp::LOCATION_FRAGMENT_COLORING );

        osg::StateSet* ss = getOrCreateStateSet();

        ss->setAttributeAndModes( vp, osg::StateAttribute::ON );
    }
}
开发者ID:APerennec,项目名称:osgearth,代码行数:20,代码来源:FadeEffect.cpp

示例2: run

    osg::Group* run(osg::Node* node)
    {
        float radius = osgEarth::SpatialReference::get("wgs84")->getEllipsoid()->getRadiusEquator();

        VirtualProgram* vp = VirtualProgram::getOrCreate(node->getOrCreateStateSet());

        // Install the shader function:
        vp->setFunction("make_it_red", fragShader, ShaderComp::LOCATION_FRAGMENT_LIGHTING);

        // Set a maximum LOD range for the above function:
        vp->setFunctionMinRange( "make_it_red", 500000 );
        vp->setFunctionMaxRange( "make_it_red", 1000000 );

        osg::Group* g = new osg::Group();

        // Install a callback that will convey the LOD range to the shader LOD.
        g->addCullCallback( new RangeUniformCullCallback() );

        g->addChild( node );
        return g;
    }
开发者ID:rhabacker,项目名称:osgearth,代码行数:21,代码来源:osgearth_shadercomp.cpp

示例3: LineStipple

void 
FeaturesToNodeFilter::applyLineSymbology(osg::StateSet*    stateset, 
                                         const LineSymbol* line)
{
    if ( line && line->stroke().isSet() )
    {
        if ( line->stroke()->width().isSet() )
        {
            float width = std::max( 1.0f, *line->stroke()->width() );
            if ( width != 1.0f )
            {
                stateset->setAttributeAndModes(new osg::LineWidth(width), 1);
            }
        }

        if ( line->stroke()->stipplePattern().isSet() )
        {
#if 1
            stateset->setAttributeAndModes(
                new osg::LineStipple(
                    line->stroke()->stippleFactor().value(),
                    line->stroke()->stipplePattern().value()),
                osg::StateAttribute::ON );
#else
            // goofing around...
            const char* frag =
                "#version 110\n"
                "void oe_stipple_frag(inout vec4 color) {\n"
                "    float x = mod(gl_FragCoord.x, 5.0);\n"
                "    float y = mod(gl_FragCoord.y, 5.0);\n"
                "    if (x < y)\n"
                "        color.a = 0.0;\n"
                "}\n";

            VirtualProgram* vp = VirtualProgram::getOrCreate(stateset);
            vp->setFunction("oe_stipple_frag", frag, ShaderComp::LOCATION_FRAGMENT_COLORING);
#endif
        }
    }
}
开发者ID:DavidLeehome,项目名称:osgearth,代码行数:40,代码来源:Filter.cpp

示例4: Stringify

void
DiscardAlphaFragments::install(osg::StateSet* ss, float minAlpha) const
{
    if ( ss && minAlpha < 1.0f && Registry::capabilities().supportsGLSL() )
    {
        VirtualProgram* vp = VirtualProgram::getOrCreate(ss);
        if ( vp )
        {
            std::string code = Stringify()
                << "#version " GLSL_VERSION_STR "\n"
                << "void oe_discardalpha_frag(inout vec4 color) { \n"
                << "    if ( color.a < " << std::setprecision(1) << minAlpha << ") discard;\n"
                << "} \n";

            vp->setFunction(
                "oe_discardalpha_frag",
                code,
                ShaderComp::LOCATION_FRAGMENT_COLORING,
                0L, 0.95f);
        }
    }
}
开发者ID:podsvirov,项目名称:osgearth,代码行数:22,代码来源:ShaderUtils.cpp

示例5: 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:energonQuest,项目名称:dtEarth,代码行数:36,代码来源:DrawInstanced.cpp

示例6: apply

void
ShaderGenerator::apply(osg::ClipNode& node)
{
    static const char* s_clip_source =
        "#version " GLSL_VERSION_STR "\n"
        "void oe_sg_set_clipvertex(inout vec4 vertexVIEW)\n"
        "{\n"
        "    gl_ClipVertex = vertexVIEW; \n"
        "}\n";

    if ( !_active )
        return;

    if ( ignore(&node) )
        return;

    VirtualProgram* vp = VirtualProgram::getOrCreate(node.getOrCreateStateSet());
    if ( vp->referenceCount() == 1 ) vp->setName( _name );
    vp->setFunction( "oe_sg_set_clipvertex", s_clip_source, ShaderComp::LOCATION_VERTEX_VIEW );

    apply( static_cast<osg::Group&>(node) );
}
开发者ID:curious-boy,项目名称:osgearth,代码行数:22,代码来源:ShaderGenerator.cpp

示例7: traverse

        void traverse(osg::NodeVisitor& nv)
        {
            if (nv.getVisitorType() == nv.UPDATE_VISITOR)
            {
                if ( (nv.getFrameStamp()->getFrameNumber() % 2) == 0 )
                {
                    _toggle = !_toggle;

                    VirtualProgram* vp = VirtualProgram::getOrCreate(this->getOrCreateStateSet());
                    if ( _toggle )
                    {
                        vp->setFunction(
                            "make_it_red", fragShader,
                            osgEarth::ShaderComp::LOCATION_FRAGMENT_COLORING,
                            new Acceptor() );
                    }
                    else
                    {
                        vp->removeShader("make_it_red");
                    }
                }
            }
            osg::Group::traverse(nv);
        }
开发者ID:rhabacker,项目名称:osgearth,代码行数:24,代码来源:osgearth_shadercomp.cpp

示例8:

bool
HighlightDecoration::apply(AnnotationNode& node, bool enable)
{
    if ( _supported )
    {
        osg::StateSet* ss = node.getOrCreateStateSet();
        if ( enable )
        {
            VirtualProgram* vp = VirtualProgram::getOrCreate( ss );
            if ( vp->getShader(FRAG_FUNCTION) == 0L )
            {
                vp->setFunction(FRAG_FUNCTION, fragSource, ShaderComp::LOCATION_FRAGMENT_COLORING);
                ss->addUniform( _colorUniform.get() );
            }
            _colorUniform->set(_color);
        }
        else
        {
            // sets alpha=0 to disable highlighting
            _colorUniform->set(osg::Vec4f(1,1,1,0));
        }
    }
    return _supported;
}
开发者ID:Geo12,项目名称:osgearth,代码行数:24,代码来源:HighlightDecoration.cpp

示例9: Depth

// 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: VirtualProgram

void
OverlayDecorator::initSubgraphShaders( osg::StateSet* set )
{
    VirtualProgram* vp = new VirtualProgram();
    vp->setName( "OverlayDecorator subgraph shader" );
    set->setAttributeAndModes( vp, osg::StateAttribute::ON );

    // sampler for projected texture:
    set->getOrCreateUniform( "osgearth_overlay_ProjTex", osg::Uniform::SAMPLER_2D )->set( *_textureUnit );

    // the texture projection matrix uniform.
    _texGenUniform = set->getOrCreateUniform( "osgearth_overlay_TexGenMatrix", osg::Uniform::FLOAT_MAT4 );

    std::stringstream buf;

    // vertex shader - subgraph
    buf << "#version 110 \n"
        << "uniform mat4 osgearth_overlay_TexGenMatrix; \n"
        << "uniform mat4 osg_ViewMatrixInverse; \n"

        << "void osgearth_overlay_vertex(void) \n"
        << "{ \n"
        << "    gl_TexCoord["<< *_textureUnit << "] = osgearth_overlay_TexGenMatrix * osg_ViewMatrixInverse * gl_ModelViewMatrix * gl_Vertex; \n"
        << "} \n";

    std::string vertexSource = buf.str();
    vp->setFunction( "osgearth_overlay_vertex", vertexSource, ShaderComp::LOCATION_VERTEX_POST_LIGHTING );

    // fragment shader - subgraph
    buf.str("");
    buf << "#version 110 \n"
        << "uniform sampler2D osgearth_overlay_ProjTex; \n";

    if ( _useWarping )
    {
        buf << "uniform float warp; \n"

            // because the built-in pow() is busted
            << "float mypow( in float x, in float y ) \n"
            << "{ \n"
            << "    return x/(x+y-y*x); \n"
            << "} \n"

            << "vec2 warpTexCoord( in vec2 src ) \n"
            << "{ \n"
            //      incoming tex coord is [0..1], so we scale to [-1..1]
            << "    vec2 srcn = vec2( src.x*2.0 - 1.0, src.y*2.0 - 1.0 ); \n" 

            //      we want to work in the [0..1] space on each side of 0, so can the abs
            //      and store the signs for later:
            << "    vec2 srct = vec2( abs(srcn.x), abs(srcn.y) ); \n"
            << "    vec2 sign = vec2( srcn.x > 0.0 ? 1.0 : -1.0, srcn.y > 0.0 ? 1.0 : -1.0 ); \n"

            //      apply the deformation using a deceleration curve:
            << "    vec2 srcp = vec2( 1.0-mypow(1.0-srct.x,warp), 1.0-mypow(1.0-srct.y,warp) ); \n"

            //      reapply the sign, and scale back to [0..1]:
            << "    vec2 srcr = vec2( sign.x*srcp.x, sign.y*srcp.y ); \n"
            << "    return vec2( 0.5*(srcr.x + 1.0), 0.5*(srcr.y + 1.0) ); \n"
            << "} \n";
    }

    buf << "void osgearth_overlay_fragment( inout vec4 color ) \n"
        << "{ \n"
        << "    vec2 texCoord = gl_TexCoord["<< *_textureUnit << "].xy / gl_TexCoord["<< *_textureUnit << "].q; \n";

    if ( _useWarping && !_visualizeWarp )
        buf  << "    texCoord = warpTexCoord( texCoord ); \n";

    buf << "    vec4 texel = texture2D(osgearth_overlay_ProjTex, texCoord); \n"  
        << "    color = vec4( mix( color.rgb, texel.rgb, texel.a ), color.a); \n"
        << "} \n";

    std::string fragmentSource = buf.str();
    vp->setFunction( "osgearth_overlay_fragment", fragmentSource, ShaderComp::LOCATION_FRAGMENT_PRE_LIGHTING );
}
开发者ID:spencerg,项目名称:osgearth,代码行数:76,代码来源:OverlayDecorator.cpp

示例11: VirtualProgram

bool
ShadowUtils::setUpShadows(osgShadow::ShadowedScene* sscene, osg::Group* root)
{
    osg::StateSet* ssStateSet = sscene->getOrCreateStateSet();

    MapNode* mapNode = MapNode::findMapNode(root);
    TerrainEngineNode* engine = mapNode->getTerrainEngine();
    if (!engine)
        return false;

    TextureCompositor* compositor = engine->getTextureCompositor();
    int su = -1;
    if (!compositor->reserveTextureImageUnit(su))
        return false;

    OE_INFO << LC << "Reserved texture unit " << su << " for shadowing" << std::endl;

    osgShadow::ViewDependentShadowMap* vdsm =  dynamic_cast< osgShadow::ViewDependentShadowMap*>(sscene->getShadowTechnique());
    int su1 = -1;
    if (vdsm && sscene->getShadowSettings()->getNumShadowMapsPerLight() == 2)
    {
        if (!compositor->reserveTextureImageUnit(su1) || su1 != su + 1)
        {
            OE_FATAL << LC << "couldn't get contiguous shadows for split vdsm\n";
            sscene->getShadowSettings()->setNumShadowMapsPerLight(1);
            if (su1 != -1)
                compositor->releaseTextureImageUnit(su1);
            su1 = -1;
        }
        else
        {
            OE_INFO << LC << "Reserved texture unit " << su1 << " for shadowing" << std::endl;
        }
    }

    // create a virtual program to attach to the shadowed scene.
    VirtualProgram* vp = new VirtualProgram();
    vp->setName( "shadow:terrain" );
    //vp->installDefaultColoringAndLightingShaders();

    ssStateSet->setAttributeAndModes( vp, 1 );


    std::stringstream buf;
    buf << "#version " << GLSL_VERSION_STR << "\n";
#ifdef OSG_GLES2_AVAILABLE
    buf << "precision mediump float;\n";
#endif
    buf << "varying vec4 oe_shadow_ambient;\n";
    buf << "varying vec4 oe_shadow_TexCoord0;\n";
    if ( su1 >= 0 )
        buf << "varying vec4 oe_shadow_TexCoord1;\n";


    buf << "void oe_shadow_setupShadowCoords(inout vec4 VertexVIEW)\n";
    buf << "{\n";
    buf << "    vec4 position4 = VertexVIEW;\n";
    buf << "    oe_shadow_TexCoord0.s = dot( position4, gl_EyePlaneS[" << su <<"]);\n";
    buf << "    oe_shadow_TexCoord0.t = dot( position4, gl_EyePlaneT[" << su <<"]);\n";
    buf << "    oe_shadow_TexCoord0.p = dot( position4, gl_EyePlaneR[" << su <<"]);\n";
    buf << "    oe_shadow_TexCoord0.q = dot( position4, gl_EyePlaneQ[" << su <<"]);\n";
    if (su1 >= 0)
    {
        buf << "    oe_shadow_TexCoord1.s = dot( position4, gl_EyePlaneS[" << su1 <<"]);\n";
        buf << "    oe_shadow_TexCoord1.t = dot( position4, gl_EyePlaneT[" << su1 <<"]);\n";
        buf << "    oe_shadow_TexCoord1.p = dot( position4, gl_EyePlaneR[" << su1 <<"]);\n";
        buf << "    oe_shadow_TexCoord1.q = dot( position4, gl_EyePlaneQ[" << su1 <<"]);\n";
    }

    // the ambient lighting will control the intensity of the shadow.
    buf << "    oe_shadow_ambient = gl_FrontLightProduct[0].ambient; \n"
        << "}\n";

    std::string setupShadowCoords;
    setupShadowCoords = buf.str();

    vp->setFunction(
        "oe_shadow_setupShadowCoords", 
        setupShadowCoords, 
        ShaderComp::LOCATION_VERTEX_VIEW,
        -1.0 );

    std::stringstream buf2;
    buf2 <<
        "#version " << GLSL_VERSION_STR << "\n"
#ifdef OSG_GLES2_AVAILABLE
        "precision mediump float;\n"
#endif
        "uniform sampler2DShadow shadowTexture;\n"
        "varying vec4 oe_shadow_TexCoord0;\n";

    if (su1 >= 0)
    {
        // bound by vdsm
        buf2 << "uniform sampler2DShadow shadowTexture1;\n";
        buf2 << "varying vec4 oe_shadow_TexCoord1;\n";
    }
    buf2 <<
        "varying vec4 oe_shadow_ambient;\n"

//.........这里部分代码省略.........
开发者ID:APerennec,项目名称:osgearth,代码行数:101,代码来源:ShadowUtils.cpp

示例12: PolygonMode


//.........这里部分代码省略.........

    // matrix that transforms a vert from depth-cam CLIP coords to EYE coords.
    local->_depthClipToCamViewUniform = local->_groupStateSet->getOrCreateUniform( 
        "oe_clamp_depthclip2eyemat", 
        osg::Uniform::FLOAT_MAT4 );

    // make the shader that will do clamping and depth offsetting.
    VirtualProgram* vp = new VirtualProgram();
    vp->setName( "ClampingBinTechnique program" );
    local->_groupStateSet->setAttributeAndModes( vp, osg::StateAttribute::ON );

    // vertex shader - subgraph
    std::string vertexSource = Stringify()
        << "#version " << GLSL_VERSION_STR << "\n"
#ifdef OSG_GLES2_AVAILABLE
        << "precision mediump float;\n"
#endif
        // uniforms from this ClampingBinTechnique:
        << "uniform sampler2D oe_clamp_depthtex; \n"
        << "uniform mat4 oe_clamp_eye2depthclipmat; \n"
        << "uniform mat4 oe_clamp_depthclip2eyemat; \n"

        // uniforms from ClampableNode:
        << "uniform vec2 oe_clamp_bias; \n"
        << "uniform vec2 oe_clamp_range; \n"

        << "varying vec4 oe_clamp_simvert; \n"
        << "varying float oe_clamp_simvertrange; \n"

        << "void oe_clamp_vertex(void) \n"
        << "{ \n"
        // transform the vertex into the depth texture's clip coordinates.
        << "    vec4 v_eye_orig = gl_ModelViewMatrix * gl_Vertex; \n"
        << "    vec4 tc = oe_clamp_eye2depthclipmat * v_eye_orig; \n"

        // sample the depth map.
        << "    float d = texture2DProj( oe_clamp_depthtex, tc ).r; \n"

        // make a fake point in depth clip space and transform it back into eye coords.
        << "    vec4 p = vec4(tc.x, tc.y, d, 1.0); \n"
        << "    vec4 v_eye_clamped = oe_clamp_depthclip2eyemat * p; \n"

        // if the clamping distance is too big, bag it.
        << "    vec3 v_eye_orig3    = v_eye_orig.xyz/v_eye_orig.w;\n"
        << "    vec3 v_eye_clamped3 = v_eye_clamped.xyz/v_eye_clamped.w; \n"
        << "    float clamp_distance = length(v_eye_orig3 - v_eye_clamped3); \n"

        << "    const float maxClampDistance = 10000.0; \n"
        
        << "    if ( clamp_distance > maxClampDistance ) \n"
        << "    { \n"
        << "        gl_Position = gl_ProjectionMatrix * v_eye_orig; \n"
        // still have to populate these to nullify the depth offset code.
        << "        oe_clamp_simvert = gl_Position; \n"
        << "        oe_clamp_simvertrange = 1.0; \n"
        << "    } \n"
        << "    else \n"
        << "    { \n"

        // now simulate a "closer" vertex for depth offsetting.

        // remap depth offset based on camera distance to vertex. The farther you are away,
        // the more of an offset you need.

        << "        float range = length(v_eye_clamped3); \n"

        << "        float ratio = (clamp(range, oe_clamp_range[0], oe_clamp_range[1])-oe_clamp_range[0])/(oe_clamp_range[1]-oe_clamp_range[0]);\n"
        << "        float bias = oe_clamp_bias[0] + ratio * (oe_clamp_bias[1]-oe_clamp_bias[0]);\n"

        << "        vec3 adj_vec = normalize(v_eye_clamped3); \n"
        << "        vec3 v_eye_offset3 = v_eye_clamped3 - (adj_vec * bias); \n"

        << "        vec4 v_sim_eye = vec4( v_eye_offset3 * v_eye_clamped.w, v_eye_clamped.w ); \n"
        << "        oe_clamp_simvert = gl_ProjectionMatrix * v_sim_eye;\n"
        << "        oe_clamp_simvertrange = range - bias; \n"
        << "        gl_Position = gl_ProjectionMatrix * v_eye_clamped; \n"
        << "    } \n"
        << "} \n";

    vp->setFunction( "oe_clamp_vertex", vertexSource, ShaderComp::LOCATION_VERTEX_POST_LIGHTING );


    // fragment shader - depth offset apply
    std::string frag =
        "varying vec4 oe_clamp_simvert; \n"
        "varying float oe_clamp_simvertrange; \n"
        "void oe_clamp_fragment(inout vec4 color)\n"
        "{ \n"
        "    float sim_depth = 0.5 * (1.0+(oe_clamp_simvert.z/oe_clamp_simvert.w));\n"

        // if the offset pushed the Z behind the eye, the projection mapping will
        // result in a z>1. We need to bring these values back down to the 
        // near clip plan (z=0). We need to check simRange too before doing this
        // so we don't draw fragments that are legitimently beyond the far clip plane.
        "    if ( sim_depth > 1.0 && oe_clamp_simvertrange < 0.0 ) { sim_depth = 0.0; } \n"
        "    gl_FragDepth = max(0.0, sim_depth); \n"
        "}\n";

    vp->setFunction( "oe_clamp_fragment", frag, ShaderComp::LOCATION_FRAGMENT_PRE_LIGHTING );
}
开发者ID:2php,项目名称:osgearth,代码行数:101,代码来源:ClampingBinTechnique.cpp

示例13: arguments

int
main(int argc, char** argv)
{
    osg::ArgumentParser arguments(&argc,argv);

    // help?
    if ( arguments.read("--help") )
        return usage(argv[0]);

    // 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(arguments) );

    // disable the small-feature culling
    viewer.getCamera()->setSmallFeatureCullingPixelSize(-1.0f);

    // set a near/far ratio that is smaller than the default. This allows us to get
    // closer to the ground without near clipping. If you need more, use --logdepth
    viewer.getCamera()->setNearFarRatio(0.0001);

    // 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 )
    {

        // Get the MapNode
        MapNode* mapNode = MapNode::findMapNode( node );

        // Find the Splat Extension
        SplatExtension* splatExtension = mapNode->getExtension<SplatExtension>();
        if (splatExtension)
        {
            OE_NOTICE << "Found Splat Extension" << std::endl;
        }

        LandCoverTerrainEffect* landCoverEffect = mapNode->getTerrainEngine()->getEffect<LandCoverTerrainEffect>();
        if (landCoverEffect)
        {
            OE_NOTICE << "Found landcover terrain effect" << std::endl;

            for (Zones::const_iterator zoneItr = landCoverEffect->getZones().begin();
                zoneItr != landCoverEffect->getZones().end();
                ++zoneItr)
            {
                // Get the StateSet for each of the LandCoverLayers
                for (LandCoverLayers::iterator landCoverItr = zoneItr->get()->getLandCover()->getLayers().begin();
                    landCoverItr != zoneItr->get()->getLandCover()->getLayers().end();
                    ++landCoverItr)
                {
                    // Get the stateset for the layer.
                    osg::StateSet* stateset = landCoverItr->get()->getOrCreateStateSet();

                    // Get the VirtualProgram for this layer.
                    VirtualProgram* vp = VirtualProgram::getOrCreate(stateset);

                    // Make the "tree" layer all red.
                    if (landCoverItr->get()->getName() == "trees")
                    {                                         
                        vp->setFunction( "color_landcover", color_landcover, ShaderComp::LOCATION_FRAGMENT_LIGHTING);
                    }
                }
            }
        }

        viewer.setSceneData( node );
        while(!viewer.done())
        {
            viewer.frame();
        }
    }
    else
    {
        return usage(argv[0]);
    }
}
开发者ID:rhabacker,项目名称:osgearth,代码行数:81,代码来源:osgearth_splat.cpp

示例14: CullFace


//.........这里部分代码省略.........
        "    vec2 sincos = vec2(sin(a), cos(a)); \n"
        "    return vec2(dot(p, vec2(sincos.y, -sincos.x)), dot(p, sincos.xy)); \n"
        "}\n"

        // slow PCF sampling.
        "float oe_shadow_multisample(in vec3 c, in float refvalue, in float blur) \n"
        "{ \n"
        "    float shadowed = 0.0; \n"
        "    float a = 6.283185 * oe_shadow_rand(c.xy); \n"
        "    vec4 b = vec4(oe_shadow_rot(vec2(1,0),a), oe_shadow_rot(vec2(0,1),a)); \n"
        "    for(int i=0; i<OE_SHADOW_NUM_SAMPLES; ++i) { \n"
        "        vec2 off = oe_shadow_samples[i];\n"
        "        off = vec2(dot(off,b.xz), dot(off,b.yw)); \n"
        "        vec3 pc = vec3(c.xy + off*blur, c.z); \n"
        "        float depth = texture2DArray(oe_shadow_map, pc).r; \n"
        "        if ( depth < 1.0 && depth < refvalue ) { \n"
        "           shadowed += 1.0; \n"
        "        } \n"
        "    } \n"
        "    return 1.0-(shadowed/OE_SHADOW_NUM_SAMPLES); \n"
        "} \n"

        "void oe_shadow_fragment( inout vec4 color )\n"
        "{\n"
        "    float alpha = color.a; \n"
        "    float factor = 1.0; \n"

        // pre-pixel biasing to reduce moire/acne
        "    const float b0 = 0.001; \n"
        "    const float b1 = 0.01; \n"
        "    vec3 L = normalize(gl_LightSource[0].position.xyz); \n"
        "    vec3 N = normalize(vp_Normal); \n"
        "    float costheta = clamp(dot(L,N), 0.0, 1.0); \n"
        "    float bias = b0*tan(acos(costheta)); \n"

        // loop over the slices:
        "    for(int i=0; i<" << numSlices << " && factor > 0.0; ++i) \n"
        "    { \n"
        "        vec4 c = oe_shadow_coord[i]; \n"
        "        vec3 coord = vec3(c.x, c.y, float(i)); \n"

        "        if ( oe_shadow_blur > 0.0 ) \n"
        "        { \n"
        "            factor = min(factor, oe_shadow_multisample(coord, c.z-bias, oe_shadow_blur)); \n"
        "        } \n"
        "        else \n"
        "        { \n"
        "            float depth = texture2DArray(oe_shadow_map, coord).r; \n"
        "            if ( depth < 1.0 && depth < c.z-bias ) \n"
        "                factor = 0.0; \n"
        "        } \n"
        "    } \n"

        "    vec4 colorInFullShadow = color * oe_shadow_color; \n"
        "    color = mix(colorInFullShadow, color, factor); \n"
        "    color.a = alpha;\n"
        "}\n";

    VirtualProgram* vp = VirtualProgram::getOrCreate(_renderStateSet.get());

    vp->setFunction(
        "oe_shadow_vertex", 
        vertex, 
        ShaderComp::LOCATION_VERTEX_VIEW,
        0.9f );

    vp->setFunction(
        "oe_shadow_fragment",
        fragment,
        ShaderComp::LOCATION_FRAGMENT_LIGHTING,
        0.9f );

    // the texture coord generator matrix array (from the caster):
    _shadowMapTexGenUniform = _renderStateSet->getOrCreateUniform(
        "oe_shadow_matrix",
        osg::Uniform::FLOAT_MAT4,
        numSlices );

    // bind the shadow map texture itself:
    _renderStateSet->setTextureAttribute(
        _texImageUnit,
        _shadowmap.get(),
        osg::StateAttribute::ON );

    _renderStateSet->addUniform( new osg::Uniform("oe_shadow_map", _texImageUnit) );

    // blur factor:
    _shadowBlurUniform = _renderStateSet->getOrCreateUniform(
        "oe_shadow_blur",
        osg::Uniform::FLOAT);

    _shadowBlurUniform->set(_blurFactor);

    // shadow color:
    _shadowColorUniform = _renderStateSet->getOrCreateUniform(
        "oe_shadow_color",
        osg::Uniform::FLOAT_VEC4);

    _shadowColorUniform->set(_color);
}
开发者ID:fei-GitHub,项目名称:osgearth,代码行数:101,代码来源:Shadowing.cpp

示例15: LocalPerViewData


//.........这里部分代码省略.........
    
    // active blending within the RTT camera's FBO
    if ( _rttBlending )
    {
        //Setup a separate blend function for the alpha components and the RGB components.  
        //Because the destination alpha is initialized to 0 instead of 1
        osg::BlendFunc* blendFunc = 0;        
        if (Registry::capabilities().supportsGLSL(1.4f))
        {
            //Blend Func Separate is only available on OpenGL 1.4 and above
            blendFunc = new osg::BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
        }
        else
        {
            blendFunc = new osg::BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
        }

        rttStateSet->setAttributeAndModes(blendFunc, osg::StateAttribute::ON | osg::StateAttribute::OVERRIDE);
    }
    else
    {
        rttStateSet->setMode(GL_BLEND, osg::StateAttribute::OFF | osg::StateAttribute::OVERRIDE);
    }

    // attach the overlay group to the camera. 
    // TODO: we should probably lock this since other cull traversals might be accessing the group
    //       while we are changing its children.
    params._rttCamera->addChild( params._group );

    // overlay geometry is rendered with no depth testing, and in the order it's found in the
    // scene graph... until further notice.
    rttStateSet->setMode(GL_DEPTH_TEST, 0);
    rttStateSet->setBinName( "TraversalOrderBin" );

    // add to the terrain stateset, i.e. the stateset that the OverlayDecorator will
    // apply to the terrain before cull-traversing it. This will activate the projective
    // texturing on the terrain.
    params._terrainStateSet->setTextureAttributeAndModes( *_textureUnit, projTexture, osg::StateAttribute::ON );

    // fire up the local per-view data:
    LocalPerViewData* local = new LocalPerViewData();
    params._techniqueData = local;
    
    if ( _useShaders )
    {            
        // GPU path

        VirtualProgram* vp = VirtualProgram::getOrCreate(params._terrainStateSet);
        vp->setName( "DrapingTechnique terrain shaders");
        //params._terrainStateSet->setAttributeAndModes( vp, osg::StateAttribute::ON );

        // sampler for projected texture:
        params._terrainStateSet->getOrCreateUniform(
            "oe_overlay_tex", osg::Uniform::SAMPLER_2D )->set( *_textureUnit );

        // the texture projection matrix uniform.
        local->_texGenUniform = params._terrainStateSet->getOrCreateUniform(
            "oe_overlay_texmatrix", osg::Uniform::FLOAT_MAT4 );

        // vertex shader - subgraph
        std::string vs =
            "#version " GLSL_VERSION_STR "\n"
            GLSL_DEFAULT_PRECISION_FLOAT "\n"
            "uniform mat4 oe_overlay_texmatrix; \n"
            "varying vec4 oe_overlay_texcoord; \n"

            "void oe_overlay_vertex(inout vec4 VertexVIEW) \n"
            "{ \n"
            "    oe_overlay_texcoord = oe_overlay_texmatrix * VertexVIEW; \n"
            "} \n";

        vp->setFunction( "oe_overlay_vertex", vs, ShaderComp::LOCATION_VERTEX_VIEW );

        // fragment shader - subgraph
        std::string fs =
            "#version " GLSL_VERSION_STR "\n"
            GLSL_DEFAULT_PRECISION_FLOAT "\n"
            "uniform sampler2D oe_overlay_tex; \n"
            "varying vec4      oe_overlay_texcoord; \n"

            "void oe_overlay_fragment( inout vec4 color ) \n"
            "{ \n"
            "    vec4 texel = texture2DProj(oe_overlay_tex, oe_overlay_texcoord); \n"
            "    color = vec4( mix( color.rgb, texel.rgb, texel.a ), color.a); \n"
            "} \n";

        vp->setFunction( "oe_overlay_fragment", fs, ShaderComp::LOCATION_FRAGMENT_COLORING );
    }
    else
    {
        // FFP path
        local->_texGen = new osg::TexGen();
        local->_texGen->setMode( osg::TexGen::EYE_LINEAR );
        params._terrainStateSet->setTextureAttributeAndModes( *_textureUnit, local->_texGen.get(), 1 );

        osg::TexEnv* env = new osg::TexEnv();
        env->setMode( osg::TexEnv::DECAL );
        params._terrainStateSet->setTextureAttributeAndModes( *_textureUnit, env, 1 );
    }
}
开发者ID:InterAtlas-ML,项目名称:osgearth,代码行数:101,代码来源:DrapingTechnique.cpp


注:本文中的VirtualProgram::setFunction方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。