コード例 #1
0
void ShaderShadowMapEngine::updateLightPassMaterial(SSMEngineData *data)
{
    if(data->getMFLightPassMaterials()->empty() == true)
    {
        MaterialChunkUnrecPtr newMatChunk = MaterialChunk::createLocal();
        newMatChunk->setLit          (false  );
        newMatChunk->setColorMaterial(GL_NONE);

        ColorMaskChunkUnrecPtr newCMaskChunk = ColorMaskChunk::create();
        newCMaskChunk->setMaskR(false);
        newCMaskChunk->setMaskG(false);
        newCMaskChunk->setMaskB(false);
        newCMaskChunk->setMaskA(false);

        PolygonChunkUnrecPtr newPolyChunk = PolygonChunk::createLocal();
        newPolyChunk->setOffsetFill  (true                   );
        newPolyChunk->setOffsetFactor(this->getOffsetFactor());
        newPolyChunk->setOffsetBias  (this->getOffsetBias  ());

        ChunkMaterialUnrecPtr newLightPassMat = ChunkMaterial::createLocal();
        newLightPassMat->addChunk(newMatChunk  );
        newLightPassMat->addChunk(newCMaskChunk);
        newLightPassMat->addChunk(newPolyChunk );

        data->editMFLightPassMaterials()->push_back(newLightPassMat);
    }
}
コード例 #2
0
void OcclusionCullingTreeBuilder::draw(DrawEnv             &denv,
                                       RenderPartitionBase *part)
{
#if 1 //CHECK_ENV_ACTION
    //std::cout << "Frame Start" << std::endl;
    Window* win = denv.getWindow();

    if(_sortMode == ModeAdaptiveBucket)
    {
        // Merge all the buckets to a tree
        for(UInt32 i = 0; i < _numBuckets; ++i)
        {
            if(_buckets[i] != NULL)
            {
                _pRoot->addChild(_buckets[i]);
            }
        }
    }

    if(!win->hasExtension(_extOcclusionQuery))
    {
        // Don't have it, just draw the whole tree.
        SLOG << "Missing OCC GL extensions!!" << endLog;

        _uiActiveMatrix = 0;
        Inherited::drawNode(_pRoot, denv, part);

        return;
    }

//SETUP
// done in add, action should never change
//    _ract = dynamic_cast<RenderAction*>(denv.getAction());

    if(!_ract)
    {
        FFATAL(("OcclusionCullingTreeBuilder::draw: Action in denv is not a "
                "RenderAction!\n"));
        return;
    }

    _uiActiveMatrix = 0;
    Real32 screenCoveredPercentage = 0.f;
    if(_ract->getOcclusionCullingQueryBufferSize() != _numTestSamples || !_occInitialized)
    {
        _numTestSamples = _ract->getOcclusionCullingQueryBufferSize();
        //std::cout << "Buf size: " << _numTestSamples << std::endl;
        _testSamples.resize(_numTestSamples);
        //std::cout << "Performing OCC on " << _numNodes << " nodes." << std::endl;

        GenQueryT genquer = reinterpret_cast<GenQueryT>(
            win->getFunction(_funcGenQueriesARB));
        genquer(_numTestSamples, &(_testSamples.front()));
        _occInitialized = true;
    }

    if(!_isOccStateCreated)
    {
        _isOccStateCreated = true;

        // register an exit function to clean up the State object
        addPreFactoryExitFunction(&releaseTestingState);

        // Create an empty state to render test nodes.
        _testingStatePtr = State::create();

        DepthChunkUnrecPtr dc = DepthChunk::create();
        dc->setReadOnly(true);
        _testingStatePtr->addChunk(dc);

        ColorMaskChunkUnrecPtr cc = ColorMaskChunk::create();
        cc->setMaskR(false);
        cc->setMaskG(false);
        cc->setMaskB(false);
        cc->setMaskA(false);
        _testingStatePtr->addChunk(cc);

        PolygonChunkUnrecPtr pc = PolygonChunk::create();
        pc->setCullFace(GL_BACK);
        _testingStatePtr->addChunk(pc);

        commitChanges();
    }

    //glGenQueriesARB(_numNodes, queries);
    //std::cout << "Calculated Pixels" << std::endl;

    _vpWidth  = denv.getPixelWidth();
    _vpHeight = denv.getPixelHeight();

    _worldToScreen = denv.getVPWorldToScreen();

    _testingState = &*_testingStatePtr;


    _minFeatureSize = _ract->getOcclusionCullingMinimumFeatureSize();
    _visPixelThreshold = _ract->getOcclusionCullingVisibilityThreshold();
    _coveredProbThreshold = _ract->getOcclusionCullingCoveredThreshold();
    _minTriangleCount = _ract->getOcclusionCullingMinimumTriangleCount();
    _inTesting = false;

    _currSample = 0;
//DRAW / TEST / RE-DRAW ON BUFFER FULL
    testNode(_pRoot, denv, part, screenCoveredPercentage);

    StatCollector *sc = _ract->getStatCollector();
    if(sc != NULL)
        sc->getElem(statNOccNodes)->add(_numNodes);
    _numNodes=0;
    _uiActiveMatrix = 0;

    leaveTesting(denv, part);

//RESULTS / RE-DRAW
    while( !_testPendingNodes.empty() )
    {
        drawTestResults(denv, part);
    }

    //std::cout << "Calc Pixels" << std::endl;


    if(sc != NULL)
    {
        Real32 percentage =
            Real32(sc->getElem(statNOccInvisible)->get()) /
            Real32(sc->getElem(statNOccTests)->get());
        sc->getElem(statNOccSuccessTestPer)->set(percentage);
    }

    //std::cout << "Real pixels " << std::endl;
    //std::cout << std::endl;

   // screen_covered_percentage = 1.0;
   // drawNode(_pRoot, denv, part, screen_covered_percentage);
    _numNodes=0;
    _currSample = 0;
    //std::cout << "Frame End" << std::endl;
#endif
}
void TrapezoidalShadowMapEngine::updateLightPassMaterial(
    TSMEngineData *data, UInt16 faceIdx, const Matrixr &matNT)
{
    if(data->getMFLightPassMaterials()->size() < 6)
        data->editMFLightPassMaterials()->resize(6, NULL);

    ChunkMaterial *lightPassMat = data->getLightPassMaterials(faceIdx);

    if(lightPassMat == NULL)
    {
        ColorMaskChunkUnrecPtr newCMaskChunk = ColorMaskChunk::create();
        newCMaskChunk->setMaskR(false);
        newCMaskChunk->setMaskG(false);
        newCMaskChunk->setMaskB(false);
        newCMaskChunk->setMaskA(false);

#ifdef OSG_TSME_LIGHTPASS_EXACT

        ShaderProgramUnrecPtr newLightPassVP = ShaderProgram::createLocal();
        newLightPassVP->setShaderType(GL_VERTEX_SHADER);
        newLightPassVP->setProgram   (_lightPassVPCode);
        newLightPassVP->addUniformVariable("TSME_matNT", matNT);

        ShaderProgramUnrecPtr newLightPassFP = ShaderProgram::createLocal();
        newLightPassFP->setShaderType(GL_FRAGMENT_SHADER);
        newLightPassFP->setProgram   (_lightPassFPCode  );
        newLightPassFP->addUniformVariable("TSME_offsetFactor", getOffsetFactor());
        newLightPassFP->addUniformVariable("TSME_offsetBias",   getOffsetBias  ());

        ShaderProgramChunkUnrecPtr newLightPassSHChunk =
            ShaderProgramChunk::createLocal();
        newLightPassSHChunk->addVertexShader  (newLightPassVP);
        newLightPassSHChunk->addFragmentShader(newLightPassFP);

        ChunkMaterialUnrecPtr  newLightPassMat = ChunkMaterial::createLocal();
        newLightPassMat->addChunk(newCMaskChunk      );
        newLightPassMat->addChunk(newLightPassSHChunk);

        lightPassMat = newLightPassMat;
        data->editMFLightPassMaterials()->replace(faceIdx, newLightPassMat);

#else
        
        PolygonChunkUnrecPtr newPolyChunk = PolygonChunk::createLocal();
        newPolyChunk->setOffsetFill  (true             );
        newPolyChunk->setOffsetFactor(getOffsetFactor());
        newPolyChunk->setOffsetBias  (getOffsetBias  ());

        ShaderProgramUnrecPtr newLightPassVP = ShaderProgram::createLocal();
        newLightPassVP->setShaderType     (GL_VERTEX_SHADER   );
        newLightPassVP->setProgram        (_lightPassVPCode   );
        newLightPassVP->addUniformVariable("TSME_matNT", matNT);

        ShaderProgramChunkUnrecPtr newLightPassSHChunk =
            ShaderProgramChunk::createLocal();
        newLightPassSHChunk->addVertexShader(newLightPassVP);

        ChunkMaterialUnrecPtr  newLightPassMat = ChunkMaterial::createLocal();
        newLightPassMat->addChunk(newCMaskChunk      );
        newLightPassMat->addChunk(newPolyChunk       );
        newLightPassMat->addChunk(newLightPassSHChunk);

        lightPassMat = newLightPassMat;
        (*data->editMFLightPassMaterials())[faceIdx] = newLightPassMat;

#endif

        
    }
    else
    {
        ShaderProgramChunk *lightPassSHChunk =
            dynamic_cast<ShaderProgramChunk *>(
                lightPassMat->find(ShaderProgramChunk::getClassType()));
    
        if(lightPassSHChunk != NULL)
        {
            ShaderProgram *lightPassVP = lightPassSHChunk->getVertexShader(0);
            lightPassVP->updateUniformVariable("TSME_matNT", matNT);
        }
    }
}