00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039 #include <stdlib.h>
00040 #include <stdio.h>
00041
00042 #include "OSGPCFShadowMapHandler.h"
00043 #include "OSGShadowStageData.h"
00044 #include "OSGRenderAction.h"
00045 #include "OSGShadowStage.h"
00046 #include "OSGSpotLight.h"
00047
00048 OSG_BEGIN_NAMESPACE
00049
00050 #include "ShaderCode/OSGPCFShadowMapShaderCode.cinl"
00051
00052 PCFShadowMapHandler::PCFShadowMapHandler(ShadowStage *pSource,
00053 ShadowStageData *pData ) :
00054 Inherited (pSource,
00055 pData ),
00056 _pPoly (NULL ),
00057 _matrixDeco (NULL ),
00058
00059 _shadowSHL (NULL ),
00060 _shadowSHL2 (NULL ),
00061 _shadowSHL3 (NULL ),
00062 _shadowSHL4 (NULL ),
00063 _shadowCubeSHL(NULL ),
00064
00065 _firstRun (1 ),
00066 _oldRange (0 )
00067 {
00068 _uiMode = ShadowStage::PCF_SHADOW_MAP;
00069
00070 _shadowFactorMap2O = TextureObjChunk::createLocal();
00071 _shadowFactorMapImage2 = Image ::createLocal();
00072
00073 _shadowFactorMap2O->setImage (_shadowFactorMapImage2);
00074 _shadowFactorMap2O->setInternalFormat(GL_RGB);
00075 _shadowFactorMap2O->setExternalFormat(GL_RGB);
00076 _shadowFactorMap2O->setMinFilter (GL_LINEAR);
00077 _shadowFactorMap2O->setMagFilter (GL_LINEAR);
00078 _shadowFactorMap2O->setWrapS (GL_REPEAT);
00079 _shadowFactorMap2O->setWrapT (GL_REPEAT);
00080 _shadowFactorMap2O->setTarget (GL_TEXTURE_2D);
00081
00082
00083 _shadowSHL = SimpleSHLChunk::createLocal();
00084 _shadowSHL2 = SimpleSHLChunk::createLocal();
00085 _shadowSHL3 = SimpleSHLChunk::createLocal();
00086 _shadowSHL4 = SimpleSHLChunk::createLocal();
00087
00088
00089
00090 _shadowCubeSHL = SimpleSHLChunk::createLocal();
00091
00092
00093 _oldRange = _pStage->getShadowSmoothness();
00094
00095 if(_oldRange <= 0.1999)
00096 {
00097 _shadowSHL->setVertexProgram (_pcf_shadow_vp);
00098 _shadowSHL->setFragmentProgram(_pcf2_shadow_fp);
00099
00100 _shadowSHL2->setVertexProgram (_pcf_shadow2_vp);
00101 _shadowSHL2->setFragmentProgram(_pcf2_shadow2_fp);
00102
00103 _shadowSHL3->setVertexProgram (_pcf_shadow3_vp);
00104 _shadowSHL3->setFragmentProgram(_pcf2_shadow3_fp);
00105
00106 _shadowSHL4->setVertexProgram (_pcf_shadow4_vp);
00107 _shadowSHL4->setFragmentProgram(_pcf2_shadow4_fp);
00108
00109 _shadowCubeSHL->setVertexProgram (_pcf_shadowCube_vp);
00110 _shadowCubeSHL->setFragmentProgram(_pcf2_shadowCube_fp);
00111 }
00112 else if(_oldRange <= 0.3999)
00113 {
00114 _shadowSHL->setVertexProgram (_pcf_shadow_vp);
00115 _shadowSHL->setFragmentProgram(_pcf3_shadow_fp);
00116
00117 _shadowSHL2->setVertexProgram (_pcf_shadow2_vp);
00118 _shadowSHL2->setFragmentProgram(_pcf3_shadow2_fp);
00119
00120 _shadowSHL3->setVertexProgram (_pcf_shadow3_vp);
00121 _shadowSHL3->setFragmentProgram(_pcf3_shadow3_fp);
00122
00123 _shadowSHL4->setVertexProgram (_pcf_shadow4_vp);
00124 _shadowSHL4->setFragmentProgram(_pcf3_shadow4_fp);
00125
00126 _shadowCubeSHL->setVertexProgram (_pcf_shadowCube_vp);
00127 _shadowCubeSHL->setFragmentProgram(_pcf3_shadowCube_fp);
00128 }
00129 else if(_oldRange <= 0.5999)
00130 {
00131 _shadowSHL->setVertexProgram (_pcf_shadow_vp);
00132 _shadowSHL->setFragmentProgram(_pcf4_shadow_fp);
00133
00134 _shadowSHL2->setVertexProgram (_pcf_shadow2_vp);
00135 _shadowSHL2->setFragmentProgram(_pcf4_shadow2_fp);
00136
00137 _shadowSHL3->setVertexProgram (_pcf_shadow3_vp);
00138 _shadowSHL3->setFragmentProgram(_pcf4_shadow3_fp);
00139
00140 _shadowSHL4->setVertexProgram (_pcf_shadow4_vp);
00141 _shadowSHL4->setFragmentProgram(_pcf4_shadow4_fp);
00142
00143 _shadowCubeSHL->setVertexProgram (_pcf_shadowCube_vp);
00144 _shadowCubeSHL->setFragmentProgram(_pcf4_shadowCube_fp);
00145 }
00146 else if(_oldRange <= 0.7999)
00147 {
00148 _shadowSHL->setVertexProgram (_pcf_shadow_vp);
00149 _shadowSHL->setFragmentProgram(_pcf5_shadow_fp);
00150
00151 _shadowSHL2->setVertexProgram (_pcf_shadow2_vp);
00152 _shadowSHL2->setFragmentProgram(_pcf5_shadow2_fp);
00153
00154 _shadowSHL3->setVertexProgram (_pcf_shadow3_vp);
00155 _shadowSHL3->setFragmentProgram(_pcf5_shadow3_fp);
00156
00157 _shadowSHL4->setVertexProgram (_pcf_shadow4_vp);
00158 _shadowSHL4->setFragmentProgram(_pcf5_shadow4_fp);
00159
00160 _shadowCubeSHL->setVertexProgram (_pcf_shadowCube_vp);
00161 _shadowCubeSHL->setFragmentProgram(_pcf5_shadowCube_fp);
00162 }
00163 else
00164 {
00165 _shadowSHL->setVertexProgram (_pcf_shadow_vp);
00166 _shadowSHL->setFragmentProgram(_pcf6_shadow_fp);
00167
00168 _shadowSHL2->setVertexProgram (_pcf_shadow2_vp);
00169 _shadowSHL2->setFragmentProgram(_pcf6_shadow2_fp);
00170
00171 _shadowSHL3->setVertexProgram (_pcf_shadow3_vp);
00172 _shadowSHL3->setFragmentProgram(_pcf6_shadow3_fp);
00173
00174 _shadowSHL4->setVertexProgram (_pcf_shadow4_vp);
00175 _shadowSHL4->setFragmentProgram(_pcf6_shadow4_fp);
00176
00177 _shadowCubeSHL->setVertexProgram (_pcf_shadowCube_vp);
00178 _shadowCubeSHL->setFragmentProgram(_pcf6_shadowCube_fp);
00179 }
00180
00181
00182 _pPoly = PolygonChunk::createLocal();
00183
00184 _unlitMat->addChunk(_pPoly);
00185
00186 _matrixDeco = MatrixCameraDecorator::createLocal();
00187 }
00188
00189 PCFShadowMapHandler::~PCFShadowMapHandler(void)
00190 {
00191 _pPoly = NULL;
00192 _matrixDeco = NULL;
00193
00194 _shadowSHL = NULL;
00195 _shadowSHL2 = NULL;
00196 _shadowSHL3 = NULL;
00197 _shadowSHL4 = NULL;
00198 _shadowCubeSHL = NULL;
00199
00200 _vShadowCmat .clear();
00201 _vShadowSHLVar .clear();
00202 _vShadowSHLVar2 .clear();
00203 _vShadowSHLVar3 .clear();
00204 _vShadowSHLVar4 .clear();
00205 _vShadowCubeSHLVar.clear();
00206 }
00207
00208
00209
00210 void PCFShadowMapHandler::createShadowMapsFBO(RenderAction *a,
00211 DrawEnv *pEnv)
00212 {
00213
00214
00215
00216
00217 std::vector<bool> vLocalLightStates;
00218
00219 const ShadowStageData::LightStore &vLights =
00220 _pStageData->getLights();
00221
00222 const ShadowStageData::LStateStore &vLightStates =
00223 _pStageData->getLightStates();
00224
00225 const ShadowStageData::StatusStore &vRealPLight =
00226 _pStageData->getRealPointLight();
00227
00228 const ShadowStageData::CamStore &vLCams =
00229 _pStageData->getLightCameras();
00230
00231 const ShadowStageData::StatusStore &vExclActive =
00232 _pStageData->getExcludeNodeActive();
00233
00234
00235 for(UInt32 i = 0;i < vLights.size();++i)
00236 {
00237
00238 vLocalLightStates.push_back(vLights[i].second->getOn());
00239 vLights[i].second->setOn(false);
00240 }
00241
00242
00243 for(UInt32 i = 0;i < _pStage->getMFExcludeNodes()->size();++i)
00244 {
00245 Node *exnode = _pStage->getExcludeNodes(i);
00246
00247 if(exnode != NULL)
00248 exnode->setTravMask(0);
00249 }
00250
00251 ShadowStageData::ShadowMapStore &vShadowMaps = _pStageData->getShadowMaps();
00252
00253 for(UInt32 i = 0;i < vLights.size();++i)
00254 {
00255 if(vLightStates[i])
00256 {
00257 if(_pStage->getGlobalShadowIntensity() != 0.0 ||
00258 vLights[i].second->getShadowIntensity() != 0.0)
00259 {
00260
00261
00262 if(vLights[i].second->getType() != PointLight::getClassType() ||
00263 vRealPLight[i] == false )
00264 {
00265 a->pushPartition();
00266 {
00267 RenderPartition *pPart = a->getActivePartition();
00268
00269 pPart->addPreRenderCallback(
00270 &ShadowTreeHandler::setupAmbientModelAndMasks);
00271 pPart->addPostRenderCallback(
00272 &ShadowTreeHandler::endAmbientModelAndMasks);
00273
00274 pPart->setRenderTarget(vShadowMaps[i].pFBO);
00275
00276 pPart->setWindow (a->getWindow());
00277
00278 pPart->calcViewportDimension(0.f,
00279 0.f,
00280 _pStage->getMapSize()-1,
00281 _pStage->getMapSize()-1,
00282
00283 _pStage->getMapSize(),
00284 _pStage->getMapSize() );
00285
00286
00287 Matrix m, t;
00288
00289
00290 vLCams[i]->getProjection(
00291 m,
00292 pPart->getViewportWidth (),
00293 pPart->getViewportHeight());
00294
00295 vLCams[i]->getProjectionTranslation(
00296 t,
00297 pPart->getViewportWidth (),
00298 pPart->getViewportHeight());
00299
00300 pPart->setupProjection(m, t);
00301
00302 vLCams[i]->getViewing(
00303 m,
00304 pPart->getViewportWidth (),
00305 pPart->getViewportHeight());
00306
00307
00308 pPart->setupViewing(m);
00309
00310 pPart->setNear (vLCams[i]->getNear());
00311 pPart->setFar (vLCams[i]->getFar ());
00312
00313 pPart->calcFrustum();
00314
00315 pPart->setBackground(_pClearBackground);
00316
00317 Node *light = vLights[i].first;
00318 Node *parent = light->getParent();
00319
00320 if(parent != NULL)
00321 {
00322 a->pushMatrix(parent->getToWorld());
00323 }
00324
00325
00326 a->overrideMaterial(_unlitMat, a->getActNode());
00327 _pStage->recurse(a, light);
00328 a->overrideMaterial( NULL, a->getActNode());
00329
00330 if(parent != NULL)
00331 {
00332 a->popMatrix();
00333 }
00334 }
00335 a->popPartition();
00336
00337 }
00338 else
00339 {
00340 for(UInt32 j = 0;j < 6;j++)
00341 {
00342
00343 UInt32 xOffset, yOffset;
00344 if(j == 0)
00345 {
00346 xOffset = 0;
00347 yOffset = 0;
00348 }
00349 else if(j == 1)
00350 {
00351 xOffset = _PLMapSize;
00352 yOffset = 0;
00353 }
00354 else if(j == 2)
00355 {
00356 xOffset = 2 * _PLMapSize;
00357 yOffset = 0;
00358 }
00359 else if(j == 3)
00360 {
00361 xOffset = 3 * _PLMapSize;
00362 yOffset = 0;
00363 }
00364 else if(j == 4)
00365 {
00366 xOffset = 0;
00367 yOffset = _PLMapSize;
00368 }
00369 else
00370 {
00371 xOffset = _PLMapSize;
00372 yOffset = _PLMapSize;
00373 }
00374
00375 _matrixDeco->setDecoratee (vLCams [i]);
00376 _matrixDeco->setPreProjection(_aCubeTrans[j]);
00377
00378 a->pushPartition();
00379 {
00380 RenderPartition *pPart = a->getActivePartition();
00381
00382 pPart->addPreRenderCallback(
00383 &ShadowTreeHandler::setupAmbientModelAndMasks);
00384 pPart->addPostRenderCallback(
00385 &ShadowTreeHandler::endAmbientModelAndMasks);
00386
00387 pPart->setRenderTarget(
00388 vShadowMaps[i].pFBO);
00389
00390 pPart->setWindow (a->getWindow());
00391
00392 pPart->calcViewportDimension(
00393 xOffset,
00394 yOffset,
00395 xOffset + _PLMapSize,
00396 yOffset + _PLMapSize,
00397
00398 _pStage->getMapSize(),
00399 _pStage->getMapSize() );
00400
00401
00402 Matrix m, t;
00403
00404
00405 _matrixDeco->getProjection (
00406 m,
00407 pPart->getViewportWidth (),
00408 pPart->getViewportHeight());
00409
00410 _matrixDeco->getProjectionTranslation(
00411 t,
00412 pPart->getViewportWidth (),
00413 pPart->getViewportHeight());
00414
00415 pPart->setupProjection(m, t);
00416
00417 _matrixDeco->getViewing(
00418 m,
00419 pPart->getViewportWidth (),
00420 pPart->getViewportHeight());
00421
00422 pPart->setupViewing(m);
00423
00424 pPart->setNear (
00425 _matrixDeco->getNear());
00426 pPart->setFar (
00427 _matrixDeco->getFar ());
00428
00429 pPart->calcFrustum();
00430
00431 pPart->setBackground(_pClearBackground);
00432
00433 Node *light = vLights[i].first;
00434 Node *parent = light->getParent();
00435
00436 if(parent != NULL)
00437 {
00438 a->pushMatrix(parent->getToWorld());
00439 }
00440
00441
00442 a->overrideMaterial(_unlitMat, a->getActNode());
00443 _pStage->recurse(a, light);
00444 a->overrideMaterial( NULL, a->getActNode());
00445
00446 if(parent != NULL)
00447 {
00448 a->popMatrix();
00449 }
00450 }
00451 a->popPartition();
00452
00453 }
00454 }
00455 }
00456 }
00457 }
00458
00459
00460
00461
00462 for(UInt32 i = 0;i < _pStage->getMFExcludeNodes()->size();++i)
00463 {
00464 Node *exnode = _pStage->getExcludeNodes(i);
00465
00466 if(exnode != NULL)
00467 {
00468 if(vExclActive[i] == true)
00469 {
00470 exnode->setTravMask(TypeTraits<UInt32>::BitsSet);
00471 }
00472 }
00473 }
00474
00475
00476 for(UInt32 i = 0;i < vLights.size();++i)
00477 {
00478
00479 vLights[i].second->setOn(vLocalLightStates[i]);
00480 }
00481 }
00482
00483 void PCFShadowMapHandler::createColorMapFBO(RenderAction *a,
00484 DrawEnv *pEnv)
00485 {
00486 a->pushPartition((RenderPartition::CopyWindow |
00487 RenderPartition::CopyViewing |
00488 RenderPartition::CopyProjection |
00489 RenderPartition::CopyFrustum |
00490 RenderPartition::CopyNearFar |
00491 RenderPartition::CopyViewportSize),
00492 RenderPartition::StateSorting);
00493 {
00494 RenderPartition *pPart = a->getActivePartition();
00495
00496 pPart->addPreRenderCallback (&ShadowTreeHandler::setupAmbientModel);
00497 pPart->addPostRenderCallback(&ShadowTreeHandler::endAmbientModel );
00498
00499 pPart->setRenderTarget(_pSceneFBO);
00500 pPart->setDrawBuffer (GL_COLOR_ATTACHMENT0_EXT);
00501
00502 Node *parent = a->getActNode()->getParent();
00503
00504 if(parent != NULL)
00505 {
00506 a->pushMatrix(parent->getToWorld());
00507 }
00508
00509 pPart->setBackground(a->getBackground());
00510
00511 _pStage->recurseFromThis(a);
00512
00513 if(parent != NULL)
00514 {
00515 a->popMatrix();
00516 }
00517 }
00518 a->popPartition();
00519 }
00520
00521 void PCFShadowMapHandler::createShadowFactorMapFBO(RenderAction *a,
00522 DrawEnv *pEnv)
00523 {
00524 _activeFactorMap = 0;
00525
00526 const ShadowStageData::LightStore &vLights =
00527 _pStageData->getLights();
00528
00529 const ShadowStageData::LStateStore &vLightStates =
00530 _pStageData->getLightStates();
00531
00532 const ShadowStageData::StatusStore &vRealPLight =
00533 _pStageData->getRealPointLight();
00534
00535 const ShadowStageData::CamStore &vLCams =
00536 _pStageData->getLightCameras();
00537
00538
00539
00540
00541 Real32 activeLights = 0;
00542
00543 if(_pStage->getGlobalShadowIntensity() != 0.0)
00544 {
00545 for(UInt32 i = 0;i < vLights.size();i++)
00546 {
00547 if(vLightStates[i] != 0)
00548 activeLights++;
00549 }
00550 }
00551 else
00552 {
00553 for(UInt32 i = 0;i < vLights.size();i++)
00554 {
00555 if(vLightStates[i] != 0 &&
00556 vLights[i].second->getShadowIntensity() != 0.0)
00557 {
00558 activeLights++;
00559 }
00560 }
00561 }
00562
00563 bool bCA1Cleared = false;
00564 bool bCA2Cleared = false;
00565
00566 UInt32 uiPLightCount = 0;
00567
00568 ShadowStageData::ShadowMapStore &vShadowMaps = _pStageData->getShadowMaps();
00569
00570
00571 for(UInt32 i = 0;i < vLights.size();i++)
00572 {
00573 if(vLightStates[i] != 0)
00574 {
00575 if((_pStage->getGlobalShadowIntensity () != 0.0 ||
00576 vLights[i].second->getShadowIntensity() != 0.0 ) &&
00577 vRealPLight[i] == true )
00578 {
00579 Real32 shadowIntensity;
00580 if(_pStage->getGlobalShadowIntensity() != 0.0)
00581 {
00582 shadowIntensity = (_pStage->getGlobalShadowIntensity() /
00583 activeLights);
00584 }
00585 else
00586 {
00587 shadowIntensity =
00588 (vLights[i].second->getShadowIntensity() /
00589 activeLights);
00590 }
00591 Matrix LVM, LPM, CVM;
00592
00593 vLCams[i]->getViewing(
00594 LVM,
00595 pEnv->getPixelWidth(),
00596 pEnv->getPixelHeight());
00597
00598 vLCams[i]->getProjection(
00599 LPM,
00600 pEnv->getPixelWidth(),
00601 pEnv->getPixelHeight());
00602
00603 CVM = pEnv->getCameraViewing();
00604
00605 Matrix iCVM = CVM;
00606 iCVM.invert();
00607
00608 Real32 texFactor;
00609 if(vLights[i].second->getType() == PointLight::getClassType() ||
00610 vLights[i].second->getType() == SpotLight ::getClassType() )
00611 {
00612 texFactor = Real32(_width) / Real32(_height);
00613 }
00614 else
00615 {
00616 texFactor = 1.0;
00617 }
00618
00619 Matrix shadowMatrix = LPM;
00620 shadowMatrix.mult(LVM);
00621 shadowMatrix.mult(iCVM);
00622
00623 Real32 xFactor = 1.0;
00624 Real32 yFactor = 1.0;
00625
00626 Matrix m = pEnv->getCameraToWorld();
00627
00628 Matrix shadowMatrixOP = LVM;
00629 shadowMatrix.mult(iCVM);
00630
00631 Matrix shadowMatrixA = LPM;
00632 shadowMatrixA.mult(_aCubeTrans[0]);
00633 shadowMatrixA.mult(LVM);
00634 shadowMatrixA.mult(iCVM);
00635
00636 Matrix shadowMatrixB = LPM;
00637 shadowMatrixB.mult(_aCubeTrans[1]);
00638 shadowMatrixB.mult(LVM);
00639 shadowMatrixB.mult(iCVM);
00640
00641 Matrix shadowMatrixC = LPM;
00642 shadowMatrixC.mult(_aCubeTrans[2]);
00643 shadowMatrixC.mult(LVM);
00644 shadowMatrixC.mult(iCVM);
00645
00646 Matrix shadowMatrixD = LPM;
00647 shadowMatrixD.mult(_aCubeTrans[3]);
00648 shadowMatrixD.mult(LVM);
00649 shadowMatrixD.mult(iCVM);
00650
00651 Matrix shadowMatrixE = LPM;
00652 shadowMatrixE.mult(_aCubeTrans[4]);
00653 shadowMatrixE.mult(LVM);
00654 shadowMatrixE.mult(iCVM);
00655
00656 Matrix shadowMatrixF = LPM;
00657 shadowMatrixF.mult(_aCubeTrans[5]);
00658 shadowMatrixF.mult(LVM);
00659 shadowMatrixF.mult(iCVM);
00660
00661 if(_vShadowCubeSHLVar.size() == uiPLightCount)
00662 {
00663 _vShadowCubeSHLVar.push_back(
00664 SimpleSHLVariableChunk::createLocal());
00665 }
00666
00667 OSG_ASSERT(uiPLightCount < _vShadowCubeSHLVar.size());
00668
00669
00670 _shadowCubeSHL->addUniformVariable("shadowMap", 0);
00671 _shadowCubeSHL->addUniformVariable("oldFactorMap", 1);
00672 _shadowCubeSHL->addUniformVariable("firstRun", _firstRun);
00673 _shadowCubeSHL->addUniformVariable("intensity",
00674 shadowIntensity);
00675 _shadowCubeSHL->addUniformVariable("texFactor", texFactor);
00676 _shadowCubeSHL->addUniformVariable("lightPMA", shadowMatrixA);
00677 _shadowCubeSHL->addUniformVariable("lightPMB", shadowMatrixB);
00678 _shadowCubeSHL->addUniformVariable("lightPMC", shadowMatrixC);
00679 _shadowCubeSHL->addUniformVariable("lightPMD", shadowMatrixD);
00680 _shadowCubeSHL->addUniformVariable("lightPME", shadowMatrixE);
00681 _shadowCubeSHL->addUniformVariable("lightPMF", shadowMatrixF);
00682 _shadowCubeSHL->addUniformVariable("lightPMOP",
00683 shadowMatrixOP);
00684 _shadowCubeSHL->addUniformVariable("KKtoWK", m);
00685 _shadowCubeSHL->addUniformVariable("mapSize",
00686 Real32(_PLMapSize));
00687 _shadowCubeSHL->addUniformVariable("xFactor",
00688 Real32(xFactor));
00689 _shadowCubeSHL->addUniformVariable("yFactor",
00690 Real32(yFactor));
00691
00692 if(_vShadowCmat.size() == uiPLightCount)
00693 {
00694 _vShadowCmat.push_back(ChunkMaterial::createLocal());
00695 }
00696
00697 OSG_ASSERT( uiPLightCount < _vShadowCmat.size());
00698
00699 _vShadowCmat[uiPLightCount]->clearChunks();
00700 _vShadowCmat[uiPLightCount]->addChunk(_shadowCubeSHL);
00701
00702 _vShadowCmat[uiPLightCount]->addChunk(
00703 vShadowMaps[i].pTexO);
00704
00705 _vShadowCmat[uiPLightCount]->addChunk(
00706 vShadowMaps[i].pTexE);
00707
00708 if(_activeFactorMap == 0)
00709 {
00710 _vShadowCmat[uiPLightCount]->addChunk(_shadowFactorMap2O);
00711 }
00712 else
00713 {
00714 _vShadowCmat[uiPLightCount]->addChunk(_shadowFactorMapO);
00715 }
00716
00717 GLenum dBuffers = GL_COLOR_ATTACHMENT1_EXT;
00718
00719 if(_activeFactorMap == 0)
00720 dBuffers = GL_COLOR_ATTACHMENT1_EXT;
00721 else
00722 dBuffers = GL_COLOR_ATTACHMENT2_EXT;
00723
00724 a->pushPartition((RenderPartition::CopyWindow |
00725 RenderPartition::CopyViewing |
00726 RenderPartition::CopyProjection |
00727 RenderPartition::CopyFrustum |
00728 RenderPartition::CopyNearFar |
00729 RenderPartition::CopyViewportSize),
00730 RenderPartition::StateSorting);
00731 {
00732 RenderPartition *pPart = a->getActivePartition();
00733
00734 pPart->addPreRenderCallback (
00735 &ShadowTreeHandler::setupAmbientModel);
00736 pPart->addPostRenderCallback(
00737 &ShadowTreeHandler::endAmbientModel );
00738
00739 pPart->setRenderTarget(_pSceneFBO);
00740 pPart->setDrawBuffer ( dBuffers );
00741
00742 Node *light = vLights[i].first;
00743 Node *parent = light->getParent();
00744
00745 if(parent != NULL)
00746 {
00747 a->pushMatrix(parent->getToWorld());
00748 }
00749
00750 if(_activeFactorMap == 0 && bCA1Cleared == false)
00751 {
00752 pPart->setBackground(_pClearBackground);
00753 bCA1Cleared = true;
00754 }
00755 else if(bCA2Cleared == false)
00756 {
00757 pPart->setBackground(_pClearBackground);
00758 bCA2Cleared = true;
00759 }
00760
00761 commitChanges();
00762
00763 a->overrideMaterial(_vShadowCmat[uiPLightCount],
00764 a->getActNode());
00765 _pStage->recurse(a, light);
00766 a->overrideMaterial( NULL,
00767 a->getActNode());
00768
00769 if(parent != NULL)
00770 {
00771 a->popMatrix();
00772 }
00773 }
00774 a->popPartition();
00775
00776 _firstRun = 0;
00777
00778 if(_activeFactorMap == 0)
00779 _activeFactorMap = 1;
00780 else
00781 _activeFactorMap = 0;
00782
00783 ++uiPLightCount;
00784 }
00785 }
00786 }
00787
00788 std::vector<Real32> shadowIntensityF;
00789 std::vector<Real32> texFactorF;
00790 std::vector<Real32> mapFactorF;
00791 std::vector<Matrix> shadowMatrixF;
00792
00793 UInt32 lightCounter = 0;
00794
00795 Real32 xFactor = 1.0;
00796 Real32 yFactor = 1.0;
00797
00798
00799 for(UInt32 i = 0;i < vLights.size();i++)
00800 {
00801 if(vLightStates[i] != 0 &&
00802 ((_pStage->getGlobalShadowIntensity() != 0.0 ||
00803 vLights[i].second->getShadowIntensity() != 0.0) &&
00804 vRealPLight[i]) == false)
00805 {
00806
00807 Real32 shadowIntensity;
00808 if(_pStage->getGlobalShadowIntensity() != 0.0)
00809 {
00810 shadowIntensity = (_pStage->getGlobalShadowIntensity() /
00811 activeLights);
00812 }
00813 else
00814 {
00815 shadowIntensity = (vLights[i].second->getShadowIntensity() /
00816 activeLights);
00817 }
00818
00819 shadowIntensityF.push_back(shadowIntensity);
00820
00821 Matrix LVM, LPM, CVM;
00822
00823 vLCams[i]->getViewing(LVM,
00824 pEnv->getPixelWidth(),
00825 pEnv->getPixelHeight());
00826
00827 vLCams[i]->getProjection(LPM,
00828 pEnv->getPixelWidth(),
00829 pEnv->getPixelHeight());
00830
00831 CVM = pEnv->getCameraViewing();
00832
00833 Matrix iCVM = CVM;
00834 iCVM.invert();
00835
00836 Real32 texFactor;
00837
00838 if(vLights[i].second->getType() == PointLight::getClassType() ||
00839 vLights[i].second->getType() == SpotLight ::getClassType() )
00840 {
00841 texFactor = Real32(_width) / Real32(_height);
00842 }
00843 else
00844 {
00845 texFactor = 1.0;
00846 }
00847
00848 texFactorF.push_back(texFactor);
00849
00850 Matrix shadowMatrix = LPM;
00851 shadowMatrix.mult(LVM);
00852 shadowMatrix.mult(iCVM);
00853
00854 shadowMatrixF.push_back(shadowMatrix);
00855
00856 Real32 mapFactor;
00857
00858 mapFactor = Real32(_pStage->getMapSize()) /
00859 Real32(vShadowMaps[i].pImage->getWidth());
00860
00861 mapFactorF.push_back(mapFactor);
00862 lightCounter++;
00863 }
00864 }
00865
00866 if(lightCounter != 0)
00867 {
00868 UInt32 renderTimes = 1;
00869 UInt32 uiMatCount = uiPLightCount;
00870
00871 UInt32 uiVarCount = 0;
00872 UInt32 uiVarCount2 = 0;
00873 UInt32 uiVarCount3 = 0;
00874 UInt32 uiVarCount4 = 0;
00875
00876 if(lightCounter > 4)
00877 renderTimes = UInt32(ceil(Real32(lightCounter) / 4.0f));
00878
00879 for(UInt32 i = 0;i < renderTimes;i++)
00880 {
00881
00882 GLenum dBuffers = GL_COLOR_ATTACHMENT1_EXT;
00883
00884 if(_activeFactorMap == 0)
00885 dBuffers = GL_COLOR_ATTACHMENT1_EXT;
00886 else
00887 dBuffers = GL_COLOR_ATTACHMENT2_EXT;
00888
00889 UInt32 lightOffset = lightCounter - (i * 4);
00890
00891 if(_vShadowCmat.size() == uiMatCount)
00892 {
00893 _vShadowCmat.push_back(ChunkMaterial::createLocal());
00894 }
00895
00896 OSG_ASSERT( uiMatCount < _vShadowCmat.size());
00897
00898
00899 _vShadowCmat[uiMatCount]->clearChunks();
00900
00901 UInt32 lightNum = 0;
00902 for(UInt32 j = 0;j < vLights.size();j++)
00903 {
00904 if(vLightStates[j] != 0)
00905 {
00906 if((_pStage->getGlobalShadowIntensity () != 0.0 ||
00907 vLights[j].second->getShadowIntensity() != 0.0) &&
00908 vRealPLight[j] == false)
00909 {
00910 if(lightNum >= (i * 4) && lightNum < ((i + 1) * 4))
00911 {
00912 _vShadowCmat[uiMatCount]->addChunk(
00913 vShadowMaps[j].pTexO);
00914 _vShadowCmat[uiMatCount]->addChunk(
00915 vShadowMaps[j].pTexE);
00916 }
00917 lightNum++;
00918 }
00919 }
00920 }
00921
00922 if(lightOffset == 1)
00923 {
00924 _vShadowCmat[uiMatCount]->addChunk(_shadowSHL);
00925
00926 if(_activeFactorMap == 0)
00927 {
00928 _vShadowCmat[uiMatCount]->addChunk(_shadowFactorMap2O);
00929 }
00930 else
00931 {
00932 _vShadowCmat[uiMatCount]->addChunk(_shadowFactorMapO);
00933 }
00934
00935 if(_vShadowSHLVar.size() == uiVarCount)
00936 {
00937 _vShadowSHLVar.push_back(
00938 SimpleSHLVariableChunk::createLocal());
00939 }
00940
00941 OSG_ASSERT(uiVarCount < _vShadowSHLVar.size());
00942
00943 _shadowSHL->addUniformVariable("oldFactorMap", 1);
00944 _shadowSHL->addUniformVariable("shadowMap", 0);
00945 _shadowSHL->addUniformVariable("firstRun", _firstRun);
00946 _shadowSHL->addUniformVariable("intensity",
00947 shadowIntensityF[0 + (i * 4)]);
00948 _shadowSHL->addUniformVariable("texFactor", texFactorF[0 +
00949 (i * 4)]);
00950 _shadowSHL->addUniformVariable("lightPM", shadowMatrixF[0 +
00951 (i * 4)]);
00952 _shadowSHL->addUniformVariable("xFactor", Real32(xFactor));
00953 _shadowSHL->addUniformVariable("yFactor", Real32(yFactor));
00954 _shadowSHL->addUniformVariable("mapSize",
00955 Real32(_pStage->getMapSize
00956 ()));
00957 _shadowSHL->addUniformVariable("mapFactor",
00958 Real32(mapFactorF[0 +
00959 (i * 4)]));
00960 ++uiVarCount;
00961 }
00962
00963 else if(lightOffset == 2)
00964 {
00965 _vShadowCmat[uiMatCount]->addChunk(_shadowSHL2);
00966
00967 if(_activeFactorMap == 0)
00968 {
00969 _vShadowCmat[uiMatCount]->addChunk(_shadowFactorMap2O);
00970 }
00971 else
00972 {
00973 _vShadowCmat[uiMatCount]->addChunk(_shadowFactorMapO);
00974 }
00975
00976 if(_vShadowSHLVar2.size() == uiVarCount2)
00977 {
00978 _vShadowSHLVar2.push_back(
00979 SimpleSHLVariableChunk::createLocal());
00980 }
00981
00982 OSG_ASSERT(uiVarCount2 < _vShadowSHLVar2.size());
00983
00984 _shadowSHL2->addUniformVariable("oldFactorMap", 2);
00985 _shadowSHL2->addUniformVariable("shadowMap1", 0);
00986 _shadowSHL2->addUniformVariable("shadowMap2", 1);
00987 _shadowSHL2->addUniformVariable("firstRun", _firstRun);
00988 _shadowSHL2->addUniformVariable("intensity1",
00989 shadowIntensityF[0 +
00990 (i * 4)]);
00991 _shadowSHL2->addUniformVariable("intensity2",
00992 shadowIntensityF[1 +
00993 (i * 4)]);
00994 _shadowSHL2->addUniformVariable("texFactor1", texFactorF[0 +
00995 (i * 4)]);
00996 _shadowSHL2->addUniformVariable("texFactor2", texFactorF[1 +
00997 (i * 4)]);
00998 _shadowSHL2->addUniformVariable("lightPM1", shadowMatrixF[0 +
00999 (i * 4)]);
01000 _shadowSHL2->addUniformVariable("lightPM2", shadowMatrixF[1 +
01001 (i * 4)]);
01002 _shadowSHL2->addUniformVariable("xFactor", Real32(xFactor));
01003 _shadowSHL2->addUniformVariable("yFactor", Real32(yFactor));
01004 _shadowSHL2->addUniformVariable("mapSize",
01005 Real32(
01006 _pStage->getMapSize()));
01007 _shadowSHL2->addUniformVariable("mapFactor1",
01008 Real32(mapFactorF[0 + (i *
01009 4)]));
01010 _shadowSHL2->addUniformVariable("mapFactor2",
01011 Real32(mapFactorF[1 + (i *
01012 4)]));
01013
01014 ++uiVarCount2;
01015 }
01016
01017 else if(lightOffset == 3)
01018 {
01019 _vShadowCmat[uiMatCount]->addChunk(_shadowSHL3);
01020
01021 if(_activeFactorMap == 0)
01022 {
01023 _vShadowCmat[uiMatCount]->addChunk(_shadowFactorMap2O);
01024 }
01025 else
01026 {
01027 _vShadowCmat[uiMatCount]->addChunk(_shadowFactorMapO);
01028 }
01029
01030 if(_vShadowSHLVar3.size() == uiVarCount3)
01031 {
01032 _vShadowSHLVar3.push_back(
01033 SimpleSHLVariableChunk::createLocal());
01034 }
01035
01036 OSG_ASSERT(uiVarCount3 < _vShadowSHLVar3.size());
01037
01038 _shadowSHL3->addUniformVariable("oldFactorMap", 3);
01039 _shadowSHL3->addUniformVariable("shadowMap1", 0);
01040 _shadowSHL3->addUniformVariable("shadowMap2", 1);
01041 _shadowSHL3->addUniformVariable("shadowMap3", 2);
01042 _shadowSHL3->addUniformVariable("firstRun", _firstRun);
01043 _shadowSHL3->addUniformVariable("intensity1",
01044 shadowIntensityF[0 +
01045 (i * 4)]);
01046 _shadowSHL3->addUniformVariable("intensity2",
01047 shadowIntensityF[1 +
01048 (i * 4)]);
01049 _shadowSHL3->addUniformVariable("intensity3",
01050 shadowIntensityF[2 +
01051 (i * 4)]);
01052 _shadowSHL3->addUniformVariable("texFactor1", texFactorF[0 +
01053 (i * 4)]);
01054 _shadowSHL3->addUniformVariable("texFactor2", texFactorF[1 +
01055 (i * 4)]);
01056 _shadowSHL3->addUniformVariable("texFactor3", texFactorF[2 +
01057 (i * 4)]);
01058 _shadowSHL3->addUniformVariable("lightPM1", shadowMatrixF[0 +
01059 (i * 4)]);
01060 _shadowSHL3->addUniformVariable("lightPM2", shadowMatrixF[1 +
01061 (i * 4)]);
01062 _shadowSHL3->addUniformVariable("lightPM3", shadowMatrixF[2 +
01063 (i * 4)]);
01064 _shadowSHL3->addUniformVariable("xFactor", Real32(xFactor));
01065 _shadowSHL3->addUniformVariable("yFactor", Real32(yFactor));
01066 _shadowSHL3->addUniformVariable("mapSize",
01067 Real32(
01068 _pStage->getMapSize()));
01069 _shadowSHL3->addUniformVariable("mapFactor1",
01070 Real32(mapFactorF[0 + (i *
01071 4)]));
01072 _shadowSHL3->addUniformVariable("mapFactor2",
01073 Real32(mapFactorF[1 + (i *
01074 4)]));
01075 _shadowSHL3->addUniformVariable("mapFactor3",
01076 Real32(mapFactorF[2 + (i *
01077 4)]));
01078
01079 ++uiVarCount3;
01080 }
01081
01082 else
01083
01084 {
01085 _vShadowCmat[uiMatCount]->addChunk(_shadowSHL4);
01086
01087 if(_activeFactorMap == 0)
01088 {
01089 _vShadowCmat[uiMatCount]->addChunk(_shadowFactorMap2O);
01090 }
01091 else
01092 {
01093 _vShadowCmat[uiMatCount]->addChunk(_shadowFactorMapO);
01094 }
01095
01096 if(_vShadowSHLVar4.size() == uiVarCount4)
01097 {
01098 _vShadowSHLVar4.push_back(
01099 SimpleSHLVariableChunk::createLocal());
01100 }
01101
01102 OSG_ASSERT(uiVarCount4 < _vShadowSHLVar4.size());
01103
01104 _shadowSHL4->addUniformVariable("oldFactorMap", 4);
01105 _shadowSHL4->addUniformVariable("shadowMap1", 0);
01106 _shadowSHL4->addUniformVariable("shadowMap2", 1);
01107 _shadowSHL4->addUniformVariable("shadowMap3", 2);
01108 _shadowSHL4->addUniformVariable("shadowMap4", 3);
01109 _shadowSHL4->addUniformVariable("firstRun", _firstRun);
01110 _shadowSHL4->addUniformVariable("intensity1",
01111 shadowIntensityF[0 +
01112 (i * 4)]);
01113 _shadowSHL4->addUniformVariable("intensity2",
01114 shadowIntensityF[1 +
01115 (i * 4)]);
01116 _shadowSHL4->addUniformVariable("intensity3",
01117 shadowIntensityF[2 +
01118 (i * 4)]);
01119 _shadowSHL4->addUniformVariable("intensity4",
01120 shadowIntensityF[3 +
01121 (i * 4)]);
01122 _shadowSHL4->addUniformVariable("texFactor1", texFactorF[0 +
01123 (i * 4)]);
01124 _shadowSHL4->addUniformVariable("texFactor2", texFactorF[1 +
01125 (i * 4)]);
01126 _shadowSHL4->addUniformVariable("texFactor3", texFactorF[2 +
01127 (i * 4)]);
01128 _shadowSHL4->addUniformVariable("texFactor4", texFactorF[3 +
01129 (i * 4)]);
01130 _shadowSHL4->addUniformVariable("lightPM1", shadowMatrixF[0 +
01131 (i * 4)]);
01132 _shadowSHL4->addUniformVariable("lightPM2", shadowMatrixF[1 +
01133 (i * 4)]);
01134 _shadowSHL4->addUniformVariable("lightPM3", shadowMatrixF[2 +
01135 (i * 4)]);
01136 _shadowSHL4->addUniformVariable("lightPM4", shadowMatrixF[3 +
01137 (i * 4)]);
01138 _shadowSHL4->addUniformVariable("xFactor", Real32(xFactor));
01139 _shadowSHL4->addUniformVariable("yFactor", Real32(yFactor));
01140 _shadowSHL4->addUniformVariable("mapSize",
01141 Real32(
01142 _pStage->getMapSize()));
01143 _shadowSHL4->addUniformVariable("mapFactor1",
01144 Real32(mapFactorF[0 + (i *
01145 4)]));
01146 _shadowSHL4->addUniformVariable("mapFactor2",
01147 Real32(mapFactorF[1 + (i *
01148 4)]));
01149 _shadowSHL4->addUniformVariable("mapFactor3",
01150 Real32(mapFactorF[2 + (i *
01151 4)]));
01152 _shadowSHL4->addUniformVariable("mapFactor4",
01153 Real32(mapFactorF[3 + (i *
01154 4)]));
01155
01156 ++uiVarCount4;
01157 }
01158
01159
01160 a->pushPartition((RenderPartition::CopyWindow |
01161 RenderPartition::CopyViewing |
01162 RenderPartition::CopyProjection |
01163 RenderPartition::CopyFrustum |
01164 RenderPartition::CopyNearFar |
01165 RenderPartition::CopyViewportSize),
01166 RenderPartition::StateSorting);
01167 {
01168 RenderPartition *pPart = a->getActivePartition();
01169
01170 pPart->addPreRenderCallback (
01171 &ShadowTreeHandler::setupAmbientModel);
01172 pPart->addPostRenderCallback(
01173 &ShadowTreeHandler::endAmbientModel );
01174
01175 pPart->setRenderTarget(_pSceneFBO);
01176 pPart->setDrawBuffer ( dBuffers);
01177
01178 Node *light = vLights[i].first;
01179 Node *parent = light->getParent();
01180
01181 if(parent != NULL)
01182 {
01183 a->pushMatrix(parent->getToWorld());
01184 }
01185
01186 if(_activeFactorMap == 0 && bCA1Cleared == false)
01187 {
01188 pPart->setBackground(_pClearBackground);
01189 bCA1Cleared = true;
01190 }
01191 else if(bCA2Cleared == false)
01192 {
01193 pPart->setBackground(_pClearBackground);
01194 bCA2Cleared = true;
01195 }
01196
01197 commitChanges();
01198
01199 a->overrideMaterial(_vShadowCmat[uiMatCount], a->getActNode());
01200 _pStage->recurse(a, light);
01201 a->overrideMaterial( NULL, a->getActNode());
01202
01203 if(parent != NULL)
01204 {
01205 a->popMatrix();
01206 }
01207 }
01208 a->popPartition();
01209
01210 _firstRun = 0;
01211 if(_activeFactorMap == 0)
01212 _activeFactorMap = 1;
01213 else
01214 _activeFactorMap = 0;
01215
01216 ++uiMatCount;
01217 }
01218 }
01219 _firstRun = 0;
01220 shadowIntensityF.clear();
01221 texFactorF.clear();
01222 mapFactorF.clear();
01223 shadowMatrixF.clear();
01224 }
01225
01226
01227 void PCFShadowMapHandler::render(RenderAction *a,
01228 DrawEnv *pEnv)
01229 {
01230 const ShadowStageData::LightStore &vLights =
01231 _pStageData->getLights();
01232
01233 const ShadowStageData::NodeStore &vTransparents =
01234 _pStageData->getTransparents();
01235
01236
01237 if(_pStageData->getShadowMaps().size() != vLights.size())
01238 {
01239 initShadowMaps();
01240 }
01241
01242 if(_bShadowMapsConfigured == false)
01243 {
01244 configureShadowMaps();
01245 }
01246
01247 if(_uiMapSize != _pStage->getMapSize())
01248 {
01249 updateShadowMapSize();
01250 }
01251
01252 if(_pSceneFBO == NULL)
01253 initSceneFBO(pEnv, true);
01254
01255 if(_width != pEnv->getPixelWidth () ||
01256 _height != pEnv->getPixelHeight() )
01257 {
01258 updateSceneFBOSize(pEnv, true);
01259 }
01260
01261 commitChanges();
01262
01263
01264 if(_pStage->getMapSize() / 4 > _maxPLMapSize)
01265 _PLMapSize = _maxPLMapSize;
01266 else
01267 _PLMapSize = _pStage->getMapSize() / 4;
01268
01269 #ifdef SHADOWCHECK
01270 GLfloat globalAmbient[4];
01271 glGetFloatv(GL_LIGHT_MODEL_AMBIENT, globalAmbient);
01272 GLfloat newGlobalAmbient[] =
01273 {
01274 0.0, 0.0, 0.0, 1.0
01275 };
01276 glLightModelfv(GL_LIGHT_MODEL_AMBIENT, newGlobalAmbient);
01277 #endif
01278
01279
01280 _firstRun = 1;
01281
01282
01283 if(_oldRange != _pStage->getShadowSmoothness())
01284 {
01285 _oldRange = _pStage->getShadowSmoothness();
01286
01287 if(_oldRange <= 0.1999)
01288 {
01289 _shadowSHL->setVertexProgram(_pcf_shadow_vp);
01290 _shadowSHL->setFragmentProgram(_pcf2_shadow_fp);
01291
01292 _shadowSHL2->setVertexProgram(_pcf_shadow2_vp);
01293 _shadowSHL2->setFragmentProgram(_pcf2_shadow2_fp);
01294
01295 _shadowSHL3->setVertexProgram(_pcf_shadow3_vp);
01296 _shadowSHL3->setFragmentProgram(_pcf2_shadow3_fp);
01297
01298 _shadowSHL4->setVertexProgram(_pcf_shadow4_vp);
01299 _shadowSHL4->setFragmentProgram(_pcf2_shadow4_fp);
01300
01301 _shadowCubeSHL->setVertexProgram(_pcf_shadowCube_vp);
01302 _shadowCubeSHL->setFragmentProgram(_pcf2_shadowCube_fp);
01303 }
01304 else if(_oldRange <= 0.3999)
01305 {
01306 _shadowSHL->setVertexProgram(_pcf_shadow_vp);
01307 _shadowSHL->setFragmentProgram(_pcf3_shadow_fp);
01308
01309 _shadowSHL2->setVertexProgram(_pcf_shadow2_vp);
01310 _shadowSHL2->setFragmentProgram(_pcf3_shadow2_fp);
01311
01312 _shadowSHL3->setVertexProgram(_pcf_shadow3_vp);
01313 _shadowSHL3->setFragmentProgram(_pcf3_shadow3_fp);
01314
01315 _shadowSHL4->setVertexProgram(_pcf_shadow4_vp);
01316 _shadowSHL4->setFragmentProgram(_pcf3_shadow4_fp);
01317
01318 _shadowCubeSHL->setVertexProgram(_pcf_shadowCube_vp);
01319 _shadowCubeSHL->setFragmentProgram(_pcf3_shadowCube_fp);
01320 }
01321 else if(_oldRange <= 0.5999)
01322 {
01323 _shadowSHL->setVertexProgram(_pcf_shadow_vp);
01324 _shadowSHL->setFragmentProgram(_pcf4_shadow_fp);
01325
01326 _shadowSHL2->setVertexProgram(_pcf_shadow2_vp);
01327 _shadowSHL2->setFragmentProgram(_pcf4_shadow2_fp);
01328
01329 _shadowSHL3->setVertexProgram(_pcf_shadow3_vp);
01330 _shadowSHL3->setFragmentProgram(_pcf4_shadow3_fp);
01331
01332 _shadowSHL4->setVertexProgram(_pcf_shadow4_vp);
01333 _shadowSHL4->setFragmentProgram(_pcf4_shadow4_fp);
01334
01335 _shadowCubeSHL->setVertexProgram(_pcf_shadowCube_vp);
01336 _shadowCubeSHL->setFragmentProgram(_pcf4_shadowCube_fp);
01337 }
01338 else if(_oldRange <= 0.7999)
01339 {
01340 _shadowSHL->setVertexProgram(_pcf_shadow_vp);
01341 _shadowSHL->setFragmentProgram(_pcf5_shadow_fp);
01342
01343 _shadowSHL2->setVertexProgram(_pcf_shadow2_vp);
01344 _shadowSHL2->setFragmentProgram(_pcf5_shadow2_fp);
01345
01346 _shadowSHL3->setVertexProgram(_pcf_shadow3_vp);
01347 _shadowSHL3->setFragmentProgram(_pcf5_shadow3_fp);
01348
01349 _shadowSHL4->setVertexProgram(_pcf_shadow4_vp);
01350 _shadowSHL4->setFragmentProgram(_pcf5_shadow4_fp);
01351
01352 _shadowCubeSHL->setVertexProgram(_pcf_shadowCube_vp);
01353 _shadowCubeSHL->setFragmentProgram(_pcf5_shadowCube_fp);
01354 }
01355 else
01356 {
01357 _shadowSHL->setVertexProgram(_pcf_shadow_vp);
01358 _shadowSHL->setFragmentProgram(_pcf6_shadow_fp);
01359
01360 _shadowSHL2->setVertexProgram(_pcf_shadow2_vp);
01361 _shadowSHL2->setFragmentProgram(_pcf6_shadow2_fp);
01362
01363 _shadowSHL3->setVertexProgram(_pcf_shadow3_vp);
01364 _shadowSHL3->setFragmentProgram(_pcf6_shadow3_fp);
01365
01366 _shadowSHL4->setVertexProgram(_pcf_shadow4_vp);
01367 _shadowSHL4->setFragmentProgram(_pcf6_shadow4_fp);
01368
01369 _shadowCubeSHL->setVertexProgram(_pcf_shadowCube_vp);
01370 _shadowCubeSHL->setFragmentProgram(_pcf6_shadowCube_fp);
01371 }
01372 }
01373
01374 if(_pStage->getMapAutoUpdate() == true ||
01375 _pStage->_trigger_update == true )
01376 {
01377 _pPoly->setOffsetFill (true );
01378 _pPoly->setOffsetFactor(_pStage->getOffFactor());
01379 _pPoly->setOffsetBias (_pStage->getOffBias ());
01380
01381 createColorMapFBO(a, pEnv);
01382
01383
01384
01385 for(UInt32 t = 0;t < vTransparents.size();++t)
01386 {
01387 vTransparents[t]->setTravMask(0);
01388 }
01389
01390
01391 createShadowMapsFBO(a, pEnv);
01392
01393
01394
01395 for(UInt32 t = 0;t < vTransparents.size();++t)
01396 {
01397 vTransparents[t]->setTravMask(TypeTraits<UInt32>::BitsSet);
01398 }
01399
01400
01401 createShadowFactorMapFBO(a, pEnv);
01402
01403 _pStage->_trigger_update = false;
01404 }
01405
01406 setupDrawCombineMap2(a);
01407 }
01408
01409 OSG_END_NAMESPACE