Ignore:
Timestamp:
04/24/07 14:04:48 (17 years ago)
Author:
szirmay
Message:
 
File:
1 edited

Legend:

Unmodified
Added
Removed
  • GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/src/RenderingRuns/OgreDepthShadowMapRenderingRun.cpp

    r2321 r2333  
    2626void OgreDepthShadowMapRenderingRun::createDepthMap() 
    2727{ 
     28        if(light->getType() == Light::LT_POINT) 
     29        { 
     30                depthMapTexture = createCubeRenderTexture(name, light->getPosition(), resolutionX,PF_FLOAT16_RGBA,0,ColourValue::White); 
     31                if(OgreIlluminationManager::getSingleton().getBlurShadowMap(light->getType())) 
     32                blurredDepthMapTexture = createCubeRenderTexture(blurredname, light->getPosition(), resolutionX,PF_FLOAT16_RGBA,0,ColourValue::White); 
     33        } 
     34        else 
     35        { 
    2836         
    2937                TexturePtr texPtr = Ogre::TextureManager::getSingleton().createManual(name,  
     
    4654                rt->setAutoUpdated(false); 
    4755                 
    48                 if(OgreIlluminationManager::getSingleton().getBlurShadowMap()) 
     56                if(OgreIlluminationManager::getSingleton().getBlurShadowMap(light->getType())) 
    4957                { 
    5058                        texPtr = Ogre::TextureManager::getSingleton().createManual(blurredname,  
     
    6472                        rt->setAutoUpdated(false); 
    6573                } 
     74        } 
    6675} 
    6776 
     
    7281        if(light->getType() == Light::LT_POINT) 
    7382        { 
    74                 updateDepthMap(); 
     83                //static int currentFace = 0; 
     84                //updateDepthCubeFace(currentFace); 
     85                //currentFace = (currentFace+1)%6; 
     86 
     87                for(int i = 0; i < 6 ; i++) 
     88                        updateDepthCubeFace(i); 
    7589        } 
    7690        else 
     
    8296void OgreDepthShadowMapRenderingRun::updateDepthCubeFace(int facenum) 
    8397{ 
     98        Vector3 lightpos = light->getDerivedPosition();                  
     99         
     100        RenderTarget* rt = depthMapTexture->getBuffer(facenum, 0).getPointer()->getRenderTarget();       
     101        Camera*  cam =  rt->getViewport(0)->getCamera(); 
     102        cam->setPosition(lightpos);      
     103        cam->setFarClipDistance(lightFarPlane); 
     104 
     105        setMaterialForVisibles(materialName, cam, false); 
     106        rt->update(); 
     107        restoreMaterials(); 
     108 
     109        //rt->writeContentsToFile("shadowmap_" + StringConverter::toString(facenum) + ".dds"); 
     110 
     111        if(OgreIlluminationManager::getSingleton().getBlurShadowMap(light->getType())) 
     112        { 
     113                rt = blurredDepthMapTexture->getBuffer(facenum, 0).getPointer()->getRenderTarget(); 
     114                Material*  mat = (Material*) MaterialManager::getSingleton().getByName("GameTools/BlurCubeFace").getPointer(); 
     115                mat->getTechnique(0)->getPass(0)->getTextureUnitState(0)->setTextureName(depthMapTexture->getName()); 
     116                mat->getTechnique(0)->getPass(0)->getFragmentProgramParameters()->setNamedConstant("face", facenum); 
     117                renderFullscreenQuad("GameTools/BlurCubeFace", rt);              
     118                 
     119                //rt->writeContentsToFile("shadowmap_blurred_" + StringConverter::toString(facenum) + ".dds"); 
     120        } 
     121         
    84122} 
    85123 
     
    93131        restoreMaterials(); 
    94132         
    95         if(OgreIlluminationManager::getSingleton().getBlurShadowMap()) 
     133        if(OgreIlluminationManager::getSingleton().getBlurShadowMap(light->getType())) 
    96134        { 
    97135                rt = blurredDepthMapTexture->getBuffer().getPointer()->getRenderTarget(); 
     
    108146const String& OgreDepthShadowMapRenderingRun::getDepthMapTextureName() 
    109147{ 
    110                 if(OgreIlluminationManager::getSingleton().getBlurShadowMap()) 
     148                if(OgreIlluminationManager::getSingleton().getBlurShadowMap(light->getType())) 
    111149                        return blurredname; 
    112150 
     
    119157        if(light!= 0) 
    120158        { 
    121                 bool uselispsm = OgreIlluminationManager::getSingleton().getUseLISPSM(); 
    122                 bool usefocusing = OgreIlluminationManager::getSingleton().getFocusingShadowMap(); 
     159                bool uselispsm = OgreIlluminationManager::getSingleton().getUseLISPSM(light->getType()); 
     160                bool usefocusing = OgreIlluminationManager::getSingleton().getFocusingShadowMap(light->getType()); 
    123161                if(light->getType() == Light::LT_DIRECTIONAL) 
    124162                { 
     
    129167                        frun->setCameraMatrices(viewcam->getViewMatrix(), viewcam->getProjectionMatrix()); 
    130168 
    131                         Vector3 lightpos = light->getParentSceneNode()->getWorldPosition(); 
    132                         Vector3 lightdir = light->getDirection(); 
     169                        Vector3 lightpos = light->getDerivedPosition(); 
     170                        Vector3 lightdir = light->getDerivedDirection(); 
    133171                        lightdir.normalise();            
    134172                         
     
    234272                        frun->setCameraMatrices(viewcam->getViewMatrix(), viewcam->getProjectionMatrix()); 
    235273 
    236                         Vector3 lightpos = light->getParentSceneNode()->getWorldPosition (); 
    237                         Vector3 lightdir = light->getDirection(); 
     274                        Vector3 lightpos = light->getDerivedPosition(); 
     275                        Vector3 lightdir = light->getDerivedDirection(); 
    238276                        lightdir.normalise();            
    239277                        Radian lightangle = light->getSpotlightOuterAngle(); 
     
    359397                else//point light 
    360398                { 
    361         /*              Vector3 pos = light->getParentNode()->getWorldPosition(); 
    362                         Vector3 dir = -pos; 
    363                         depthMapCamera->setDirection( dir ); 
    364                         depthMapCamera->setPosition(pos); 
    365                         depthMapCamera->setProjectionType(PT_PERSPECTIVE); 
    366                         depthMapCamera->setFOVy(Radian(Degree(140))); 
    367                         depthMapCamera->setNearClipDistance(1); 
    368                         // depthMapCamera->setFarClipDistance(200); 
    369          
    370                         //OGRE_EXCEPT(0, "NOT implemented for Pointlight", "OgreDepthShadowMapRenderingRun::refreshLight"); 
    371                 */       
    372                         /*Vector3 pos = light->getParentNode()->getWorldPosition(); 
    373                         Vector3 dir = -pos; 
    374                         depthMapCamera->setDirection( dir ); 
    375                         depthMapCamera->setPosition(pos); 
    376                         depthMapCamera->setProjectionType(PT_ORTHOGRAPHIC); 
    377                         depthMapCamera->*/ 
    378                          
     399                        lightFarPlane = light->getAttenuationRange(); 
     400                        //no other adjustment needed                     
    379401                } 
    380402        } 
     
    383405Matrix4 OgreDepthShadowMapRenderingRun::getLightViewMatrix() 
    384406{ 
    385         return depthMapCamera->getViewMatrix(); 
     407        Camera* cam = depthMapCamera; 
     408        if(light->getType() == Light::LT_POINT) 
     409         cam = depthMapTexture->getBuffer(4, 0).getPointer()->getRenderTarget()->getViewport(0)->getCamera();    
     410         
     411        return cam->getViewMatrix(); 
    386412} 
    387413 
    388414Matrix4 OgreDepthShadowMapRenderingRun::getLightViewProjMatrix() 
    389415{ 
    390         return depthMapCamera->getProjectionMatrixWithRSDepth() * depthMapCamera->getViewMatrix(); 
     416        Camera* cam = depthMapCamera; 
     417        if(light->getType() == Light::LT_POINT) 
     418         cam = depthMapTexture->getBuffer(4, 0).getPointer()->getRenderTarget()->getViewport(0)->getCamera();    
     419         
     420        return cam->getProjectionMatrixWithRSDepth() * cam->getViewMatrix(); 
    391421} 
    392422 
Note: See TracChangeset for help on using the changeset viewer.