void DepthPeelingStage::setupRenderScene(RenderAction* a, Int32 iVPWidth, Int32 iVPHeight, bool isInitial, bool isPing ) { this->pushPartition(a); { RenderPartition *pPart = a->getActivePartition(); FrameBufferObject *pTarget = NULL; Viewarea *pArea = a->getViewarea (); Camera *pCam = a->getCamera (); Background *pBack = NULL; DepthPeelingStageDataUnrecPtr pData = a->getData<DepthPeelingStageData *>(_iDataSlotId); if(!pData) { this->initData(a, iVPWidth, iVPHeight); } else { this->updateData(a, iVPWidth, iVPHeight); } pData = a->getData<DepthPeelingStageData *>(_iDataSlotId); if (isInitial) { pTarget = pData->getBlendFBO(); pBack = a->getBackground (); } else { if (isPing) pTarget = pData->getPeelPingFBO(); else pTarget = pData->getPeelPongFBO(); pBack = pData->getBackground(); } pPart->setRenderTarget(pTarget); if(pArea != NULL) { pPart->setWindow (a->getWindow()); if(pTarget != NULL) { pPart->calcViewportDimension(pArea->getLeft (), pArea->getBottom(), pArea->getRight (), pArea->getTop (), pTarget->getWidth (), pTarget->getHeight ()); } else { pPart->calcViewportDimension(pArea->getLeft (), pArea->getBottom(), pArea->getRight (), pArea->getTop (), a->getWindow()->getWidth (), a->getWindow()->getHeight()); } if(pCam != NULL) { Matrix m, t; // set the projection pCam->getProjection (m, pPart->getViewportWidth (), pPart->getViewportHeight()); pCam->getProjectionTranslation(t, pPart->getViewportWidth (), pPart->getViewportHeight()); pPart->setupProjection(m, t); pCam->getViewing(m, pPart->getViewportWidth (), pPart->getViewportHeight()); pPart->setupViewing(m); pPart->setNear (pCam->getNear()); pPart->setFar (pCam->getFar ()); pPart->calcFrustum(); } pPart->setBackground(pBack); } pPart->addSetupModeBit(RenderPartition::BackgroundSetup); pPart->pushState(); if (!isInitial) { FrameBufferObject* fbo = isPing ? pData->getPeelPongFBO() : pData->getPeelPingFBO(); TextureBuffer* texbuf = static_cast<TextureBuffer *>(fbo->getDepthAttachment()); TextureObjChunk* depthTexChunk = texbuf->getTexture(); pPart->addOverride(depthTexChunk->getClassId() + getDepthTexUnit(), depthTexChunk ); pPart->addOverride(pData->getSpvIsPeelChunk()->getClassId(), pData->getSpvIsPeelChunk() ); } else { pPart->addOverride(pData->getSpvIsInitialChunk()->getClassId(), pData->getSpvIsInitialChunk() ); } pPart->addOverride(pData->getDepthChunk()->getClassId(), pData->getDepthChunk() ); this->recurseFromThis(a); a->useNodeList(false); pPart->popState(); } this->popPartition(a); }
void DeferredShadingStage::scheduleGBufferPass(RenderAction *ract) { #if 0 RenderPartition *parentPart = ract->getActivePartition(); #endif DSStageData *data = ract->getData<DSStageData *>(_iDataSlotId); ShaderProgramChunk *shader = this->getGBufferProgram(); #if 0 UInt32 bufferCount = osgMin(getMFPixelFormats()->size(), getMFPixelTypes ()->size() ); #endif // create shadow maps MFLightsType::const_iterator lIt = _mfLights.begin(); MFLightsType::const_iterator lEnd = _mfLights.end (); for(UInt32 i = 0; lIt != lEnd; ++lIt, ++i) { (*lIt)->callLightEngineEnter(ract); ShaderProgramChunk *spc = data->getShadingProgramChunks(1+i); State *state = data->getShadingStates (1+i); ShaderShadowMapEngine *sme = dynamic_cast<ShaderShadowMapEngine *>( (*lIt)->getLightEngine()); if(sme != NULL) { // ShaderProgram *shadowVP = sme->getShadowVertexProgram (); ShaderProgram *shadowFP = sme->getShadowFragmentProgram(); // if(shadowVP != NULL && // spc->getMFVertexShader()->findIndex(shadowVP) == -1 ) // { // spc->addShader(shadowVP); // } if(shadowFP != NULL && spc->getMFFragmentShader()->findIndex(shadowFP) == -1 ) { spc->addShader(shadowFP); } Int32 shadowTexUnit = sme->getForceTextureUnit() > 0 ? sme->getForceTextureUnit() : 7; if(sme->getEnabled() == true) { state->addChunk(sme->getShadowTexChunk(), shadowTexUnit ); } else { state->subChunk(TextureObjChunk::getStaticClassId(), shadowTexUnit ); } } } this->pushPartition(ract); { RenderPartition *part = ract->getActivePartition(); #ifdef OSG_DEBUG part->setDebugString("DeferredShadingStage::GBufferPartition"); #endif setupGBufferPartition(part, ract, data); if(shader != NULL) { part->pushState ( ); part->addOverride(shader->getClassId(), shader); } this->recurseFromThis(ract); if(shader != NULL) part->popState(); } this->popPartition(ract); // create shadow maps lIt = _mfLights.begin(); lEnd = _mfLights.end (); for(; lIt != lEnd; ++lIt) { (*lIt)->callLightEngineLeave(ract); } }