void DepthPeelingStage::setupPostProcess(RenderAction* a, bool isFinal, bool isPing) { this->pushPartition(a, (RenderPartition::CopyWindow | RenderPartition::CopyViewportSize), RenderPartition::SimpleCallback ); { RenderPartition *pPart = a->getActivePartition(); Matrix m, t; m.setIdentity(); t.setIdentity(); MatrixOrthogonal( m, 0.f, 1.f, 0.f, 1.f, -1.f, 1.f); pPart->setupProjection(m, t); RenderPartition::SimpleDrawCallback f; if (!isFinal) f = boost::bind(&DepthPeelingStage::postProcess, this, _1, isPing); else f = boost::bind(&DepthPeelingStage::postProcessFinal, this, _1); pPart->dropFunctor(f); } this->popPartition(a); }
void DeferredShadingStage::scheduleShadingPass(RenderAction *ract) { #if 0 RenderPartition *parentPart = ract->getActivePartition ( ); #endif DSStageData *data = ract->getData<DSStageData *>(_iDataSlotId); this->pushPartition(ract, (RenderPartition::CopyWindow | RenderPartition::CopyViewportSize) ); { RenderPartition *part = ract->getActivePartition(); #ifdef OSG_DEBUG part->setDebugString("DeferredShadingStage::ShadingPartition"); #endif setupShadingPartition(part, ract, data); RenderPartition::DrawFunctor f = boost::bind(&DeferredShadingStage::executeShadingPass, this, _1); DSStageData::MFShadingStatesType::const_iterator sIt = data->getMFShadingStates()->begin(); DSStageData::MFShadingStatesType::const_iterator sEnd = data->getMFShadingStates()->end(); for(UInt32 i = 0; sIt != sEnd; ++sIt, ++i) { if((i > 0) && (getLights(i-1)->getOn() == false)) continue; part->dropFunctor(f, *sIt, (*sIt)->getSortKey()); } } this->popPartition(ract); }
Action::ResultE PostShaderStage::renderEnter(Action *action) { RenderAction *a = dynamic_cast<RenderAction *>(action); a->disableDefaultPartition(); this->beginPartitionGroup(a); { this->pushPartition(a); { RenderPartition *pPart = a->getActivePartition(); FrameBufferObject *pTarget = this->getRenderTarget(); Viewarea *pArea = a->getViewarea(); Camera *pCam = a->getCamera (); Background *pBack = a->getBackground(); if(pTarget == NULL) { this->initData(a); pTarget = this->getRenderTarget(); } pPart->setRenderTarget(pTarget); #ifdef OSG_DEBUGX std::string szMessage("RenderPartition\n"); pPart->setDebugString(szMessage ); #endif if(pArea != NULL) { // pPart->setViewport(pPort ); pPart->setWindow (a->getWindow()); if(pTarget != NULL) { #if 0 pPart->calcViewportDimension(pArea->getLeft (), pArea->getBottom(), pArea->getRight (), pArea->getTop (), pTarget->getWidth (), pTarget->getHeight ()); #endif pPart->calcViewportDimension(0.f, 0.f, 1.f, 1.f, 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); } this->recurseFromThis(a); } this->popPartition(a); this->pushPartition(a, (RenderPartition::CopyWindow | RenderPartition::CopyViewportSize), RenderPartition::SimpleCallback ); { RenderPartition *pPart = a->getActivePartition(); #ifdef OSG_DEBUGX std::string szMessage("PostProcessPartition\n"); pPart->setDebugString(szMessage ); #endif Matrix m, t; m.setIdentity(); t.setIdentity(); MatrixOrthogonal( m, 0.f, 1.f, 0.f, 1.f, -1.f, 1.f); pPart->setupProjection(m, t); RenderPartition::SimpleDrawCallback f; f = boost::bind(&PostShaderStage::postProcess, this, _1); pPart->dropFunctor(f); } this->popPartition(a); } this->endPartitionGroup(a); RenderPassVector::iterator passIt = _vPostProcessPasses.begin(); //Update the uniform parameters to the shader for(; passIt != _vPostProcessPasses.end(); ++passIt) { (*passIt)->updateUniformVariables(a); } return Action::Skip; }
Action::ResultE HDRStage::renderEnter(Action *action) { RenderAction *a = dynamic_cast<RenderAction *>(action); a->disableDefaultPartition(); Int32 iVPWidth = a->getActivePartition()->getViewportWidth (); Int32 iVPHeight = a->getActivePartition()->getViewportHeight(); this->beginPartitionGroup(a); { this->pushPartition(a); { RenderPartition *pPart = a ->getActivePartition(); FrameBufferObject *pTarget = this->getRenderTarget (); Viewarea *pArea = a ->getViewarea (); Camera *pCam = a ->getCamera (); Background *pBack = a ->getBackground (); if(pTarget == NULL) { this->initData(a, iVPWidth, iVPHeight); pTarget = this->getRenderTarget(); } else { this->updateData(a, iVPWidth, iVPHeight); } pPart->setRenderTarget(pTarget); pPart->getDrawEnv().setTargetBufferFormat(this->getBufferFormat()); #ifdef OSG_DEBUGX std::string szMessage("HDR: RenderPartition\n"); pPart->setDebugString(szMessage ); #endif if(pArea != NULL) { pPart->setWindow (a->getWindow()); if(pTarget != NULL) { #if 0 pPart->calcViewportDimension(pArea->getLeft (), pArea->getBottom(), pArea->getRight (), pArea->getTop (), pTarget->getWidth (), pTarget->getHeight ()); #endif pPart->calcViewportDimension(0.f, 0.f, 1.f, 1.f, 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); } this->recurseFromThis(a); } this->popPartition(a); a->getActivePartition()->disable(); this->pushPartition(a, (RenderPartition::CopyWindow | RenderPartition::CopyViewportSize | RenderPartition::CopyTarget ), RenderPartition::SimpleCallback ); { RenderPartition *pPart = a->getActivePartition(); #ifdef OSG_DEBUGX std::string szMessage("HDR: PostProcessPartition\n"); pPart->setDebugString(szMessage ); #endif Matrix m, t; m.setIdentity(); t.setIdentity(); MatrixOrthogonal( m, 0.f, 1.f, 0.f, 1.f, -1.f, 1.f); pPart->setupProjection(m, t); RenderPartition::SimpleDrawCallback f; f = boost::bind(&HDRStage::postProcess, this, _1); pPart->dropFunctor(f); } this->popPartition(a); } this->endPartitionGroup(a); return Action::Skip; }
void TrapezoidalShadowMapEngine::handlePointLightEnter( PointLight *pointL, RenderAction *ract, TSMEngineData *data) { RenderPartition *parentPart = ract->getActivePartition(); Matrixr matEyeToWorld(parentPart->getCameraToWorld()); Matrixr matLightProj; Real shadowNear = (getShadowNear() != 0.f ? getShadowNear() : parentPart->getNear() ); Real shadowFar = (getShadowFar () != 0.f ? getShadowFar () : parentPart->getFar() ); Inherited::calcPointLightRange( pointL, 0.01f, shadowNear, shadowFar, shadowNear, shadowFar); MatrixPerspective(matLightProj, Pi / 4.f, 1.f, shadowNear, shadowFar ); Matrixr matWorldToLight; Matrixr matEyeToLight; MFMatrixr mfMatNT; mfMatNT.resize(6); Inherited::calcPointLightMatrices(matWorldToLight, matEyeToLight, pointL, matEyeToWorld ); Inherited::updatePointLightShadowTexImage (data); Inherited::updatePointLightShadowTexBuffers(data); Inherited::updatePointLightRenderTargets (data); Int32 shadowTexUnit = (this->getForceTextureUnit() >= 0) ? this->getForceTextureUnit() : 7; ShaderProgram *shadowFP = this->getShadowFragmentProgram(); if(shadowFP == NULL) { ShaderProgramUnrecPtr newShadowFP = ShaderProgram::createLocal(); newShadowFP->setShaderType(GL_FRAGMENT_SHADER); newShadowFP->setProgram (_pointFPCode ); newShadowFP->addUniformVariable("TSME_matEyeToLight", matEyeToLight); newShadowFP->addUniformVariable("TSME_matLightProj", matLightProj ); newShadowFP->addUniformVariable("TSME_matNT", mfMatNT ); newShadowFP->addUniformVariable("TSME_texShadow", shadowTexUnit); newShadowFP->addUniformVariable("TSME_texShadowSizeInv", Vec2f(1.f / getWidth (), 1.f / getHeight() ) ); this->setShadowFragmentProgram(newShadowFP); shadowFP = newShadowFP; } else { shadowFP->updateUniformVariable("TSME_matEyeToLight", matEyeToLight); shadowFP->updateUniformVariable("TSME_matLightProj", matLightProj ); } const FrustumVolume &eyeFrust = parentPart->getFrustum(); for(UInt16 faceIdx = 0; faceIdx < 6; ++faceIdx) { Matrixr matWorldToLightFace (matWorldToLight ); matWorldToLightFace.multLeft(_matCubeFaceInv[faceIdx]); Matrixr matLightFull(matWorldToLightFace); matLightFull.multLeft(matLightProj); FrustumVolume lightFrust; Matrixr matNT; lightFrust.setPlanes(matLightFull); bool matNTValid = calcTrapezoidalTransform(mfMatNT[faceIdx], matEyeToWorld, matLightFull, eyeFrust, lightFrust ); if(matNTValid == false) { // setup a minimal partition to clear the cube face commitChanges(); this->pushPartition(ract, RenderPartition::CopyNothing, RenderPartition::SimpleCallback); { RenderPartition *part = ract->getActivePartition( ); Window *win = ract->getWindow ( ); FrameBufferObject *target = data->getRenderTargets (faceIdx); Background *back = data->getBackground ( ); part->setSetupMode(RenderPartition::ViewportSetup | RenderPartition::BackgroundSetup ); part->setRenderTarget(target); part->setWindow (win ); part->calcViewportDimension(0.f, 0.f, 1.f, 1.f, target->getWidth (), target->getHeight() ); part->setBackground(back); RenderPartition::SimpleDrawCallback emptyCubeFaceDraw = boost::bind( &TrapezoidalShadowMapEngine::emptyCubeFaceDrawFunc, this, _1); part->dropFunctor(emptyCubeFaceDraw); } this->popPartition(ract); } else { updateLightPassMaterial(data, faceIdx, mfMatNT[faceIdx]); commitChanges(); this->pushPartition(ract); { RenderPartition *part = ract->getActivePartition( ); Window *win = ract->getWindow ( ); FrameBufferObject *target = data->getRenderTargets (faceIdx); Background *back = data->getBackground ( ); part->setRenderTarget(target); part->setWindow (win ); part->calcViewportDimension(0.f, 0.f, 1.f, 1.f, target->getWidth (), target->getHeight() ); part->setupProjection(matLightProj, Matrixr::identity()); part->setupViewing (matWorldToLightFace ); part->setNear (parentPart->getNear()); part->setFar (parentPart->getFar ()); part->setFrustum (lightFrust ); part->setBackground (back ); part->overrideMaterial(data->getLightPassMaterials(faceIdx), ract->getActNode ( ) ); this->recurseFrom(ract, pointL); ract->useNodeList(false ); part->overrideMaterial(NULL, ract->getActNode ( ) ); } this->popPartition(ract); } } shadowFP->updateUniformVariable("TSME_matNT", mfMatNT); }
Action::ResultE DisplayFilterStage::renderEnter(Action *action) { RenderAction *ract = dynamic_cast<RenderAction *>(action); if(ract == NULL) return Action::Continue; DisplayFilterStageDataUnrecPtr pData = ract->getData<DisplayFilterStageData *>(_iDataSlotId); DrawEnv &oEnv = ract->getActivePartition()->getDrawEnv(); bool bFilterActive = false; RenderPartition::Mode partMode = RenderPartition::StateSorting; CalibrationPatternFilter *pCalibFilter = NULL; ResolutionDisplayFilter *pResFilter = NULL; DistortionDisplayFilter *pDistFilter = NULL; ColorDisplayFilter *pColFilter = NULL; bool bDoDraw = true; if(_mfFilterGroups.size() == 0) { pCalibFilter = this->getCalibrationPatternFilter(); pResFilter = this->getResolutionFilter(); pColFilter = this->getColorFilter(); pDistFilter = this->getDistortionFilter(); } else { // Linear search, optimize of needed MFFilterGroupsType::const_iterator gIt = _mfFilterGroups.begin(); MFFilterGroupsType::const_iterator gEnd = _mfFilterGroups.end (); for(; gIt != gEnd; ++gIt) { if((*gIt)->matches(oEnv.getDrawerId(), oEnv.getDrawableId()) == true) { pCalibFilter = (*gIt)->getCalibrationPatternFilter(); pResFilter = (*gIt)->getResolutionFilter(); pColFilter = (*gIt)->getColorFilter(); pDistFilter = (*gIt)->getDistortionFilter(); bDoDraw = ((*gIt)->matches(this->getActiveGroup(), oEnv. getDrawableId ()) == true) || (this->getActiveGroup() == -1 ) ; break; } } } if(pCalibFilter != NULL && pCalibFilter->getEnabled() == true) { if(pData != NULL) pData->setCalibFilter(pCalibFilter); bFilterActive = true; partMode = RenderPartition::SimpleCallback; } else { if(pData != NULL) pData->setCalibFilter(NULL); } if(pColFilter != NULL && pColFilter->getEnabled() == true ) { if(pData != NULL) pData->setColFilter(pColFilter); bFilterActive = true; } else { if(pData != NULL) { pData->setColFilter(NULL); ColorDisplayFilter::deactivate(pData); } } if(pDistFilter != NULL && pDistFilter->getEnabled() == true ) { if(pData != NULL) pData->setDistFilter(pDistFilter); bFilterActive = true; } else { if(pData != NULL) pData->setDistFilter(NULL); } UInt32 uiTargetWidth = oEnv.getPixelWidth (); UInt32 uiTargetHeight = oEnv.getPixelHeight(); Int32 iLeft = oEnv.getPixelLeft (); Int32 iRight = oEnv.getPixelRight (); Int32 iBottom = oEnv.getPixelBottom(); Int32 iTop = oEnv.getPixelTop (); if(pResFilter != NULL && pResFilter->getEnabled() == true ) { bFilterActive = true; uiTargetWidth = UInt32(uiTargetWidth * pResFilter->getDownScale()); uiTargetHeight = UInt32(uiTargetHeight * pResFilter->getDownScale()); iLeft = Int32(iLeft * pResFilter->getDownScale()); iRight = Int32(iRight * pResFilter->getDownScale()); iBottom = Int32(iBottom * pResFilter->getDownScale()); iTop = Int32(iTop * pResFilter->getDownScale()); } if(pData == NULL) { pData = setupStageData(uiTargetWidth, uiTargetHeight); if(pData == NULL) return Action::Continue; this->setData(pData, _iDataSlotId, ract); pData->setColFilter (pColFilter ); pData->setDistFilter (pDistFilter ); pData->setCalibFilter(pCalibFilter); } if((pData->getWidth () != uiTargetWidth ) || (pData->getHeight() != uiTargetHeight) ) { resizeStageData(pData, uiTargetWidth, uiTargetHeight); } if(bFilterActive == false) return Action::Continue; ract->disableDefaultPartition(); this->beginPartitionGroup(ract); { this->pushPartition(ract, 0x0000, partMode); { RenderPartition *pPart = ract ->getActivePartition(); FrameBufferObject *pTarget = pData->getTarget(); Viewarea *pArea = ract ->getViewarea(); Camera *pCam = ract ->getCamera (); Background *pBack = ract ->getBackground(); pPart->setRenderTarget(pTarget); if(pArea != NULL) { pPart->setWindow(ract->getWindow()); if(pTarget != NULL) { pPart->calcViewportDimension(iLeft , iBottom, iRight , iTop , pTarget->getWidth (), pTarget->getHeight ()); } else { pPart->calcViewportDimension( pArea->getLeft (), pArea->getBottom(), pArea->getRight (), pArea->getTop (), ract->getWindow()->getWidth (), ract->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); } if(pCalibFilter != NULL && pCalibFilter->getEnabled() == true) { RenderPartition::SimpleDrawCallback f; if(bDoDraw == true) { f = boost::bind(&DisplayFilterStage::processCalibActive, this, _1); } else { f = boost::bind(&DisplayFilterStage::processCalibInactive, this, _1); } pPart->dropFunctor(f); } else { MFForegroundsType::const_iterator fIt = this->getMFForegrounds()->begin(); MFForegroundsType::const_iterator fEnd = this->getMFForegrounds()->end (); for(; fIt != fEnd; ++fIt) { pPart->pushToForegrounds(*fIt); } this->recurseFromThis(ract); } } this->popPartition(ract); this->pushPartition(ract, (RenderPartition::CopyWindow | RenderPartition::CopyViewportSize), RenderPartition::SimpleCallback); { RenderPartition *pPart = ract->getActivePartition(); Matrix m, t; m.setIdentity(); t.setIdentity(); MatrixOrthogonal( m, 0.f, 1.f, 0.f, 1.f, -1.f, 1.f); pPart->setupProjection(m, t); RenderPartition::SimpleDrawCallback f; f = boost::bind(&DisplayFilterStage::postProcess, this, _1); pPart->dropFunctor(f); } this->popPartition(ract); } this->endPartitionGroup(ract); return Action::Skip; }