예제 #1
0
void PCSSShadowMap::drawCombineMap(RenderActionBase *action)
{
    Real32  xFactor = 1.0;
    Real32  yFactor = 1.0;
    if(!_useNPOTTextures)
    {
        xFactor = Real32(_width) / Real32(_widthHeightPOT);
        yFactor = Real32(_height) / Real32(_widthHeightPOT);
    }

    beginEditCP(_combineSHL, ShaderChunk::ParametersFieldMask);
    _combineSHL->setUniformParameter("colorMap", 0);
    _combineSHL->setUniformParameter("shadowFactorMap", 1);
    _combineSHL->setUniformParameter("xFactor", Real32(xFactor));
    _combineSHL->setUniformParameter("yFactor", Real32(yFactor));
    _combineSHL->setUniformParameter("hasFactorMap", hasFactorMap());
    endEditCP(_combineSHL, ShaderChunk::ParametersFieldMask);

    //draw the Scene
    // glViewport is called in the render action but we don't use the renderaction here!
    GLint   pl = _shadowVP->getPixelLeft(), pr = _shadowVP->getPixelRight(),
            pb = _shadowVP->getPixelBottom(),
            pt = _shadowVP->getPixelTop();
    GLint   pw = pr - pl + 1, ph = pt - pb + 1;
    glViewport(pl, pb, pw, ph);
    glScissor(pl, pb, pw, ph);
    glEnable(GL_SCISSOR_TEST);

    // we can't use the shadowVP camera here could be a TileCameraDecorator!
    action->setCamera(getCPtr(_combine_camera));
    _pf->draw(action, _shadowVP);
    action->setCamera(getCPtr(_shadowVP->getCamera()));

    glDisable(GL_SCISSOR_TEST);
}
// redraw the window
void display(void)
{
    mgr->getNavigator()->updateCameraTransformation();

    mgr->getWindow()->activate();
    mgr->getWindow()->frameInit();

    raction->setWindow(getCPtr(mgr->getWindow()));

    ViewportPtr viewport = mgr->getWindow()->getPort(0);

    glClear(GL_ACCUM_BUFFER_BIT);

    for (int i=0; i < JITTERSIZE[activeJitter]; i++) {
        beginEditCP(cameraDecorator);
            cameraDecorator->setOffset(
                (JITTER[activeJitter][i].x() - 0.5) * jitterRadius,
                (JITTER[activeJitter][i].y() - 0.5) * jitterRadius);
        endEditCP(cameraDecorator);

        viewport->render(raction);
    
        glAccum(GL_ACCUM, 1.0f / float(JITTERSIZE[activeJitter]));
        glAccum(GL_RETURN, float(JITTERSIZE[activeJitter]) / float(i + 1));
    }

    glAccum(GL_RETURN, 1.0f);

    mgr->getWindow()->swap();
    mgr->getWindow()->frameExit();
}
예제 #3
0
    static void drop(DrawActionBase *action, const BoxVolume     &volume, Color3f col)
#endif
    {
        VolumeDrawWrapper * vdw = new VolumeDrawWrapper(volume, col);

        Material::DrawFunctor func;
        func = osgTypedMethodFunctor1ObjPtr(vdw, &VolumeDrawWrapper::draw);
    
        RenderAction *ra = dynamic_cast<RenderAction*>(action);
        
        ra->dropFunctor(func, getCPtr(getDefaultUnlitMaterial()));
    }
void testNode(void)
{
#if 0
    OSG::SFNodePtr sfNode;
    OSG::MFNodePtr mfNode;

    OSG::NodePtr pNode = OSG::Node::create();

    sfNode.setValue(pNode);
    mfNode.push_back(pNode);

/*
    fprintf(stderr, "%p %p %p | %d %d\n", 
            pNode, 
            sfNode.getValue(), 
            mfNode[0],
            OSG::Node::VolumeFieldId,
            OSG::Node::TravMaskFieldId);
 */

    OSG::NodePtr pNode1 = OSG::Node::create();

    sfNode.setValue(pNode1);
    mfNode.resize(2);
    mfNode.replace(1, pNode1);

    const OSG::Field *pF1 = pNode->getSFVolume();
          OSG::Field *pF2 = pNode->editSFVolume();

    OSG::GetFieldHandlePtr  pRF1 = pNode->getField("volume");
    OSG::EditFieldHandlePtr pRF2 = pNode->editField("volume");

    fprintf(stderr, "#### Field %p %p | %p %p\n", 
            pF1, 
            pF2, 
            pRF1.get(), 
            pRF2.get());

//    fprintf(stderr, "%p %p %p\n", pNode1, sfNode.getValue(), mfNode[1]);

    const OSG::SFNodePtr constSFNode;

//    fprintf(stderr, "%p %p\n", pNode1, constSFNode.getValue());

    OSG::FieldContainerPtr pNodeClone = deepClone(pNode);

    OSG::FieldContainerPtr pFC = 
        OSG::FieldContainerFactory::the()->createContainer("Billboard");

    fprintf(stderr, "### FOO %p\n", getCPtr(pFC));

#endif
}
예제 #5
0
void State::changeFrom(DrawActionBase *action, State *old)
{
    MFStateChunkPtr::iterator it;
    const MFStateChunkPtr::iterator itEnd = _mfChunks.end();
    Int32 ind = 0;
    UInt32 i;
    UInt32 cind;

    for(it = _mfChunks.begin(), cind = 0; it != itEnd;
            ++it, ++cind)
    {
        StateChunkPtr o = old->getChunk(cind);
        StateChunkPtr n = *it;

        if(n != NullFC && !n->getIgnore())
        {
            if(o != NullFC && !o->getIgnore())
                n->changeFrom(action, getCPtr(o), UInt32(ind));
            else
                n->activate(action, UInt32(ind));
        }
        else if(o != NullFC && !o->getIgnore())
        {
            o->deactivate(action, UInt32(ind));
        }

        if(++ind >= StateChunkClass::getNumSlots(cind))
            ind = 0;
    }

    if(ind >= StateChunkClass::getNumSlots(cind))
        ind = 0;

    for(i = cind; i < old->getMFChunks()->size(); ++i)
    {
        StateChunkPtr o = old->getChunk(i);

        if(o != NullFC && !o->getIgnore())
        {
            o->deactivate(action, UInt32(ind));
        }

        if(++ind >= StateChunkClass::getNumSlots(i))
        {
            ind = 0;
        }
    }
}
static void dumpAspect(OSG::TestFC *pFC, OSG::UInt32 uiAspect)
{
    OSG::UInt32 uiCurrAspect= OSG::Thread::getCurrentAspect();

    OSG::Thread::setAspectTo(uiAspect);

#ifdef OSG_MT_CPTR_ASPECT
    OSG::TestFC *pAFC = OSG::convertToCurrentAspect(pFC);
#else
    OSG::TestFC *pAFC = getCPtr(pFC);
#endif

    if(pAFC != NULL)
    {
        pAFC->dump();
    }
    else
    {
        fprintf(stderr, "No Aspect Ptr\n");
    }

    OSG::Thread::setAspectTo(uiCurrAspect);
}
예제 #7
0
Action::ResultE ProxyGroup::render(Action *action)
{
    DrawActionBase *da        = dynamic_cast<DrawActionBase *>(action);

    if(getEnabled() == false)
        return Action::Continue;

    if(getState() == NOT_LOADED)
        startLoading();

    if(getState() == LOAD_THREAD_FINISHED)
    {
        if(_loadedRoot != NULL)
        {
            _loadThread = NULL;

            setRoot(_loadedRoot);

            getRoot()->invalidateVolume();
            getRoot()->updateVolume();


            setState(LOADED);

            da->getActNode()->invalidateVolume();
            da->getActNode()->updateVolume    ();
        }
        else
        {
            SWARNING << "failed to load " << getAbsoluteUrl() << std::endl;

            setState(LOAD_ERROR);
        }
    }

    if(getState() == LOADED)
    {
        da->useNodeList();

        if(da->isVisible(getCPtr(getRoot())))
            da->addNode(getRoot());
    }
    else
    {
        if(da->getActNode()->getNChildren() == 0)
        {
            Color3f col;
            col.setValuesRGB(.5,.3,0);            

            dropVolume(da, da->getActNode(), col);
        }
    }

    // thread cleanup
    if(_loadThread && _loadQueue.empty())
    {
        printf("join\n");
        BaseThread::join(_loadThread);
        _loadThread = NULL;
    }

    return Action::Continue;
}
예제 #8
0
Action::ResultE DistanceLOD::draw(Action *action)
{
	DrawActionBase *da = dynamic_cast<DrawActionBase *>(action);
	RenderAction   *ra = dynamic_cast<RenderAction *>  (action);
	
    action->useNodeList();

    UInt32 numLevels = action->getNNodes();
    Int32 index = -1;
    
    if (numLevels == 0)
    {
    	// update index field for being externally accessible
    	if (index != getIndex() && (!ra || !ra->getEffectsPass()))
    	{
			beginEditCP(getPtr(), IndexFieldMask);
				setIndex(index);
			endEditCP  (getPtr(), IndexFieldMask);
		}
		
        return Action::Continue;
    }

    const MFReal32 &range = (*getMFRange());
    UInt32 numRanges = range.size();
	
    if (numRanges == 0)
    {
        index = 0;
    }
    else
    {
        Real32 dist = 0;
		
        if (ra != NULL)
		{
			if (!ra->getEffectsPass())
				dist = calcDistance(da, ra->top_matrix());
			else
				dist = _lastDist;
		}
        else
            dist = calcDistance(da, da->getActNode()->getToWorld());

        if (numRanges >= numLevels)
            numRanges = numLevels - 1;

        if(numRanges == 0)
        {
            index = 0;
        }
        else if (dist >= range[numRanges - 1])
        {
            index = numRanges;
        }
        else
        {
            for (index = 0; index < numRanges; ++index)
            {
                if (dist < range[index])
                    break;
            }
        }
    }
    
    // update index field for being externally accessible
	if (index != getIndex() && (!ra || !ra->getEffectsPass()))
	{
		beginEditCP(getPtr(), IndexFieldMask);
			setIndex(index);
		endEditCP  (getPtr(), IndexFieldMask);
	}

    const NodePtr nodePtr = action->getNode(index);
    
    if(da->isVisible(getCPtr(nodePtr)))
    {
        da->addNode(nodePtr);
    }

    return Action::Continue;
}
예제 #9
0
void PCSSShadowMap::createShadowFactorMapFBO(RenderActionBase *action,
                                             UInt32 num)
{
    glClearColor(0.0, 0.0, 0.0, 1.0);

    //Finde alle aktiven Lichtquellen
    Real32  activeLights = 0;
    if(_shadowVP->getGlobalShadowIntensity() != 0.0)
    {
        for(UInt32 i = 0;i < _shadowVP->_lights.size();i++)
        {
            if(_shadowVP->_lightStates[i] != 0)
                activeLights++;
        }
    }
    else
    {
        for(UInt32 i = 0;i < _shadowVP->_lights.size();i++)
        {
            if(_shadowVP->_lightStates[i] != 0 &&
               _shadowVP->_lights[i].second->getShadowIntensity() != 0.0)
                activeLights++;
        }
    }

    Real32  shadowIntensity;
    if(_shadowVP->getGlobalShadowIntensity() != 0.0)
        shadowIntensity = (_shadowVP->getGlobalShadowIntensity() /
                           activeLights);
    else
        shadowIntensity = (_shadowVP->_lights[num].second->getShadowIntensity() /
                           activeLights);
    if(_shadowVP->_lights[num].second->getShadowIntensity() != 0.0 ||
       _shadowVP->getGlobalShadowIntensity() != 0.0)
    {

        Matrix  LVM, LPM, CVM;
        _shadowVP->_lightCameras[num]->getViewing(LVM,
                                                  _shadowVP->getPixelWidth(),
                                                  _shadowVP->getPixelHeight());
        _shadowVP->_lightCameras[num]->getProjection(LPM,
                                                     _shadowVP->getPixelWidth
                                                     (),
                                                     _shadowVP->getPixelHeight
                                                     ());
        _shadowVP->getCamera()->getViewing(CVM, _shadowVP->getPixelWidth(),
                                           _shadowVP->getPixelHeight());
        Matrix  iCVM = CVM;
        iCVM.invert();

        Real32  texFactor;
        if(_shadowVP->_lights[num].second->getType() == SpotLight::getClassType() ||
           _shadowVP->_lights[num].second->getType() == PointLight::getClassType())
            texFactor = Real32(_width) / Real32(_height);
        else
            texFactor = 1.0;

        Matrix  shadowMatrix = LPM;
        shadowMatrix.mult(LVM);
        shadowMatrix.mult(iCVM);

        Real32  xFactor = 1.0;
        Real32  yFactor = 1.0;
        if(!_useNPOTTextures)
        {
            xFactor = Real32(_width) / Real32(_widthHeightPOT);
            yFactor = Real32(_height) / Real32(_widthHeightPOT);
        }

        Real32  lightSize;
        if(_shadowVP->_lights[num].second->getType() != DirectionalLight::getClassType
           ())
            lightSize = _shadowVP->getShadowSmoothness() * 10.0;
        else
            lightSize = _shadowVP->getShadowSmoothness() / 25.0;

        beginEditCP(_shadowSHL, ShaderChunk::ParametersFieldMask);
        _shadowSHL->setUniformParameter("shadowMap", 0);
        _shadowSHL->setUniformParameter("oldFactorMap", 1);
        _shadowSHL->setUniformParameter("firstRun", _firstRun);
        _shadowSHL->setUniformParameter("intensity", shadowIntensity);
        _shadowSHL->setUniformParameter("texFactor", texFactor);
        _shadowSHL->setUniformParameter("lightPM", shadowMatrix);
        _shadowSHL->setUniformParameter("mapSize",
                                        Real32(_shadowVP->getMapSize()));
        _shadowSHL->setUniformParameter("lightSize", Real32(lightSize));
        _shadowSHL->setUniformParameter("xFactor", Real32(xFactor));
        _shadowSHL->setUniformParameter("yFactor", Real32(yFactor));
        endEditCP(_shadowSHL, ShaderChunk::ParametersFieldMask);

        beginEditCP(_shadowCmat);
        _shadowCmat->clearChunks();
        _shadowCmat->addChunk(_shadowSHL);
        _shadowCmat->addChunk(_shadowVP->_texChunks[num]);
        _shadowCmat->addChunk(_shadowFactorMap);
        endEditCP(_shadowCmat);

        GLenum  *buffers = NULL;
        buffers = new GLenum[1];
        buffers[0] = GL_COLOR_ATTACHMENT1_EXT;

        //Setup FBO
        glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, _fb);

        glDrawBuffer(*buffers);

        //draw the Scene
        if(_firstRun)
            glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

        _shadowVP->renderLight(action, getCPtr(_shadowCmat), num);

        glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);

        delete[] buffers;
        _firstRun = 0;
    }
}
예제 #10
0
void PCSSShadowMap::createShadowMapsFBO(RenderActionBase *action)
{
    UInt32  oldWidth, oldHeight;
    oldWidth = _shadowVP->getPixelWidth();
    oldHeight = _shadowVP->getPixelHeight();

    //------Setting up Window to fit size of ShadowMap----------------

    _shadowVP->setVPSize(0, 0, _shadowVP->getMapSize() - 1,
                         _shadowVP->getMapSize() - 1);

    glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
    glShadeModel(GL_FLAT);
    glDisable(GL_LIGHTING);
    glDepthMask(GL_TRUE);

    // disable all lights more speed
    std::vector<bool> lightStates;
    for(UInt32 i = 0;i < _shadowVP->_lights.size();++i)
    {
        // store old states.
        lightStates.push_back(_shadowVP->_lights[i].second->getOn());
        _shadowVP->_lights[i].second->setOn(false);
    }

    // deactivate exclude nodes:
    for(UInt32 i = 0;i < _shadowVP->getMFExcludeNodes()->getSize();++i)
    {
        NodePtr exnode = _shadowVP->getExcludeNodes(i);
        if(exnode != NullFC)
            exnode->setTravMask(0);
    }

    for(UInt32 i = 0;i < _shadowVP->_lights.size();++i)
    {
        if(_shadowVP->_lightStates[i] != 0)
        {
            if(_shadowVP->getGlobalShadowIntensity() != 0.0 ||
               _shadowVP->_lights[i].second->getShadowIntensity() != 0.0)
            {

                action->getWindow()->validateGLObject(
                    _shadowVP->_texChunks[i]->getGLId());

                glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, _fb2);

                glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT
                                          , GL_TEXTURE_2D,
                                          action->getWindow()->getGLObjectId(
                                          _shadowVP->_texChunks[i]->getGLId()),
                                          0);

                glDrawBuffer(GL_NONE);
                glReadBuffer(GL_NONE);

                glPolygonOffset(_shadowVP->getOffFactor(),
                                _shadowVP->getOffBias());
                glEnable(GL_POLYGON_OFFSET_FILL);

                glClearColor(1.0, 1.0, 1.0, 1.0);
                glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

                action->setCamera(getCPtr(_shadowVP->_lightCameras[i]));

                _shadowVP->renderLight(action, getCPtr(_unlitMat), i);

                glDisable(GL_POLYGON_OFFSET_FILL);

                glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);

                glClearColor(0.0, 0.0, 0.0, 1.0);

                action->setCamera(getCPtr(_shadowVP->getCamera()));
            }
        }
    }

    //-------Restoring old states of Window and Viewport----------
    // enable all lights.
    for(UInt32 i = 0;i < _shadowVP->_lights.size();++i)
    {
        // restore old states.
        _shadowVP->_lights[i].second->setOn(lightStates[i]);
    }

    // activate exclude nodes:
    for(UInt32 i = 0;i < _shadowVP->getMFExcludeNodes()->getSize();++i)
    {
        NodePtr exnode = _shadowVP->getExcludeNodes(i);
        if(exnode != NullFC)
            exnode->setTravMask(_shadowVP->_excludeNodeTravMask[i]);
    }

    _shadowVP->setVPSize(0, 0, oldWidth - 1, oldHeight - 1);
    _shadowVP->setVPSize(0, 0, 1, 1);

    glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
    glShadeModel(GL_SMOOTH);
    glEnable(GL_LIGHTING);
}
예제 #11
0
void PCSSShadowMap::createShadowMaps(RenderActionBase *action)
{
    if(_tiledeco == NullFC)
    {
        _tiledeco = TileCameraDecorator::create();
        addRefCP(_tiledeco);
    }

    //Checking for the smallest Window-Dimension
    UInt32  minSize = _shadowVP->getPixelWidth();

    if(_shadowVP->getPixelHeight() < minSize)
        minSize = _shadowVP->getPixelHeight();

    //Checking for biggest PowerOf2 that fits in smallest Window-Dimension
    UInt32  _mapRenderSize = osgnextpower2(minSize + 1) / 2;
    if(_mapRenderSize == 0)
        _mapRenderSize = 128;

    Real32  vpTop, vpBottom, vpLeft, vpRight;

    //------Setting up Window to fit size of ShadowMap----------------

    // Saving original Viewport-Dimensions
    vpTop = _shadowVP->getTop();
    vpBottom = _shadowVP->getBottom();
    vpLeft = _shadowVP->getLeft();
    vpRight = _shadowVP->getRight();

    glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
    glShadeModel(GL_FLAT);
    glDisable(GL_LIGHTING);
    glDepthMask(GL_TRUE);

    // disable all lights more speed
    std::vector<bool> lightStates;
    for(UInt32 i = 0;i < _shadowVP->_lights.size();++i)
    {
        // store old states.
        lightStates.push_back(_shadowVP->_lights[i].second->getOn());
        _shadowVP->_lights[i].second->setOn(false);
    }

    // deactivate exclude nodes:
    for(UInt32 i = 0;i < _shadowVP->getMFExcludeNodes()->getSize();++i)
    {
        NodePtr exnode = _shadowVP->getExcludeNodes(i);
        if(exnode != NullFC)
            exnode->setTravMask(0);
    }

    for(UInt32 i = 0;i < _shadowVP->_lights.size();++i)
    {
        if(_shadowVP->_lightStates[i] != 0)
        {
            if(_shadowVP->getGlobalShadowIntensity() != 0.0 ||
               _shadowVP->_lights[i].second->getShadowIntensity() != 0.0)
            {
                if(_mapRenderSize > _shadowVP->getMapSize())
                    _mapRenderSize = _shadowVP->getMapSize();
                _shadowVP->setVPSize(0, 0, _mapRenderSize - 1, _mapRenderSize -
                                     1);
                // we use a tiledecorator to create shadow maps with
                // a higher resolutions than the viewport or the screen.
                beginEditCP(_tiledeco);
                _tiledeco->setDecoratee(_shadowVP->_lightCameras[i]);
                _tiledeco->setFullSize(_shadowVP->getMapSize(),
                                       _shadowVP->getMapSize());
                endEditCP(_tiledeco);

                action->setCamera(getCPtr(_tiledeco));

                Real32  step = (1.0 / Real32(_shadowVP->getMapSize())) *
                    Real32(_mapRenderSize);

                UInt32  ypos = 0;
                for(Real32 y = 0;y < 1.0;y += step)
                {
                    UInt32  xpos = 0;
                    for(Real32 x = 0;x < 1.0;x += step)
                    {
                        beginEditCP(_tiledeco);
                        _tiledeco->setSize(x, y, x + step, y + step);
                        endEditCP(_tiledeco);

                        glClear(GL_DEPTH_BUFFER_BIT);
                        glPolygonOffset(_shadowVP->getOffFactor(),
                                        _shadowVP->getOffBias());
                        glEnable(GL_POLYGON_OFFSET_FILL);

                        _shadowVP->renderLight(action, getCPtr(_unlitMat), i);

                        action->getWindow()->validateGLObject(
                            _shadowVP->_texChunks[i]->getGLId());

                        glDisable(GL_POLYGON_OFFSET_FILL);

                        //----------Shadow-Texture-Parameters and Indices-------------

                        glBindTexture(GL_TEXTURE_2D,
                                      action->getWindow()->getGLObjectId(
                                      _shadowVP->_texChunks[i]->getGLId()));
                        if(glGetError() != GL_NO_ERROR)
                            SWARNING << "Error on binding Texture!" << endLog;

                        glCopyTexSubImage2D(GL_TEXTURE_2D, 0, xpos, ypos, 0, 0,
                                            _mapRenderSize, _mapRenderSize);

                        if(glGetError() != GL_NO_ERROR)
                            SWARNING << "Error on copying Texture!" << endLog;

                        glBindTexture(GL_TEXTURE_2D, 0);
                        if(glGetError() != GL_NO_ERROR)
                            SWARNING << "Error on releasing Texture!" <<
                                endLog;

                        if(glGetError() != GL_NO_ERROR)
                            SWARNING << "Error while Texture-Creation!" <<
                                endLog;

                        xpos += _mapRenderSize;
                    }
                    ypos += _mapRenderSize;
                }
            }
        }
    }


    // enable all lights.
    for(UInt32 i = 0;i < _shadowVP->_lights.size();++i)
    {
        // restore old states.
        _shadowVP->_lights[i].second->setOn(lightStates[i]);
    }

    // activate exclude nodes:
    for(UInt32 i = 0;i < _shadowVP->getMFExcludeNodes()->getSize();++i)
    {
        NodePtr exnode = _shadowVP->getExcludeNodes(i);
        if(exnode != NullFC)
            exnode->setTravMask(_shadowVP->_excludeNodeTravMask[i]);
    }
    //-------Restoring old states of Window and Viewport----------

    beginEditCP(_shadowVP->getCamera(),
                _shadowVP->LeftFieldMask | _shadowVP->RightFieldMask |
                _shadowVP->BottomFieldMask | _shadowVP->TopFieldMask);
    {
        _shadowVP->setSize(vpLeft, vpBottom, vpRight, vpTop);
    }
    endEditCP(_shadowVP->getCamera(),
              _shadowVP->LeftFieldMask | _shadowVP->RightFieldMask |
              _shadowVP->BottomFieldMask | _shadowVP->TopFieldMask);

    action->setCamera(getCPtr(_shadowVP->getCamera()));

    glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
    glShadeModel(GL_SMOOTH);
    glEnable(GL_LIGHTING);
}
예제 #12
0
void PCSSShadowMap::createShadowFactorMap(RenderActionBase *action, UInt32 num)
{
    glClearColor(0.0, 0.0, 0.0, 1.0);
    if(_firstRun)
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    //Finde alle aktiven Lichtquellen
    Real32  activeLights = 0;
    if(_shadowVP->getGlobalShadowIntensity() != 0.0)
    {
        for(UInt32 i = 0;i < _shadowVP->_lights.size();i++)
        {
            if(_shadowVP->_lightStates[i] != 0)
                activeLights++;
        }
    }
    else
    {
        for(UInt32 i = 0;i < _shadowVP->_lights.size();i++)
        {
            if(_shadowVP->_lightStates[i] != 0 &&
               _shadowVP->_lights[i].second->getShadowIntensity() != 0.0)
                activeLights++;
        }
    }

    Real32  shadowIntensity;
    if(_shadowVP->getGlobalShadowIntensity() != 0.0)
        shadowIntensity = (_shadowVP->getGlobalShadowIntensity() /
                           activeLights);
    else
        shadowIntensity = (_shadowVP->_lights[num].second->getShadowIntensity() /
                           activeLights);
    if(_shadowVP->_lights[num].second->getShadowIntensity() != 0.0 ||
       _shadowVP->getGlobalShadowIntensity() != 0.0)
    {

        Matrix  LVM, LPM, CVM;
        _shadowVP->_lightCameras[num]->getViewing(LVM,
                                                  _shadowVP->getPixelWidth(),
                                                  _shadowVP->getPixelHeight());
        _shadowVP->_lightCameras[num]->getProjection(LPM,
                                                     _shadowVP->getPixelWidth
                                                     (),
                                                     _shadowVP->getPixelHeight
                                                     ());
        _shadowVP->getCamera()->getViewing(CVM, _shadowVP->getPixelWidth(),
                                           _shadowVP->getPixelHeight());
        Matrix  iCVM = CVM;
        iCVM.invert();
        Matrix  iLVM = LVM;
        iLVM.invert();

        Real32  texFactor;
        if(_shadowVP->_lights[num].second->getType() == SpotLight::getClassType() ||
           _shadowVP->_lights[num].second->getType() == PointLight::getClassType())
            texFactor = Real32(_width) / Real32(_height);
        else
            texFactor = 1.0;

        Matrix  shadowMatrix = LPM;
        shadowMatrix.mult(LVM);
        shadowMatrix.mult(iCVM);

        Real32  xFactor = 1.0;
        Real32  yFactor = 1.0;
        if(!_useNPOTTextures)
        {
            xFactor = Real32(_width) / Real32(_widthHeightPOT);
            yFactor = Real32(_height) / Real32(_widthHeightPOT);
        }

        Real32  lightSize;
        if(_shadowVP->_lights[num].second->getType() != DirectionalLight::getClassType
           ())
            lightSize = _shadowVP->getShadowSmoothness() * 10.0;
        else
            lightSize = _shadowVP->getShadowSmoothness() / 25.0;

        beginEditCP(_shadowSHL, ShaderChunk::ParametersFieldMask);
        _shadowSHL->setUniformParameter("shadowMap", 0);
        _shadowSHL->setUniformParameter("oldFactorMap", 1);
        _shadowSHL->setUniformParameter("firstRun", _firstRun);
        _shadowSHL->setUniformParameter("intensity", shadowIntensity);
        _shadowSHL->setUniformParameter("texFactor", texFactor);
        _shadowSHL->setUniformParameter("lightPM", shadowMatrix);
        _shadowSHL->setUniformParameter("mapSize",
                                        Real32(_shadowVP->getMapSize()));
        _shadowSHL->setUniformParameter("lightSize", Real32(lightSize));
        _shadowSHL->setUniformParameter("xFactor", Real32(xFactor));
        _shadowSHL->setUniformParameter("yFactor", Real32(yFactor));
        endEditCP(_shadowSHL, ShaderChunk::ParametersFieldMask);

        beginEditCP(_shadowCmat);
        _shadowCmat->clearChunks();
        _shadowCmat->addChunk(_shadowSHL);
        _shadowCmat->addChunk(_shadowVP->_texChunks[num]);
        _shadowCmat->addChunk(_shadowFactorMap);
        endEditCP(_shadowCmat);

        _shadowVP->renderLight(action, getCPtr(_shadowCmat), num);

        action->getWindow()->validateGLObject(_shadowFactorMap->getGLId());

        glBindTexture(GL_TEXTURE_2D,
                      action->getWindow()->getGLObjectId(
                      _shadowFactorMap->getGLId()));
        glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0,
                            _shadowVP->getPixelWidth(),
                            _shadowVP->getPixelHeight());
        glBindTexture(GL_TEXTURE_2D, 0);

        _firstRun = 0;
    }
}