Changeset 1628


Ignore:
Timestamp:
10/17/06 09:21:50 (18 years ago)
Author:
szirmay
Message:
 
Location:
GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/include/OgreIlluminationManager.h

    r1425 r1628  
    7070        unsigned int focusingMapSize; 
    7171        unsigned int shadowMapSize; 
     72        bool useLISPSM; 
     73        bool useVSM; 
     74        bool blurSM; 
    7275        unsigned int phaseTextureSize; 
    7376        std::map<RenderingRunType,float> maxRads; 
     
    302305                return FrameListener::frameStarted(evt); 
    303306        } 
     307 
     308        bool getUseLISPSM(){return useLISPSM;} 
     309        bool getUseVSM(){return useVSM;} 
     310        bool getBlurShadowMap(){return blurSM;} 
     311        void setUseLISPSM(bool use){useLISPSM = use;} 
     312        void setUseVSM(bool use){useVSM = use;} 
     313        void setBlurShadowMap(bool use){blurSM = use;} 
    304314}; 
    305315 
  • GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/include/RenderingRuns/OgreDepthShadowMapRenderingRun.h

    r1130 r1628  
    4242                @brief returns the depth shadow map texture created by this run 
    4343        */ 
    44         String getDepthMapTextureName(){return blurredname;} 
     44        String getDepthMapTextureName(); 
     45         
    4546        /** 
    4647                @brief Refreshes light camera matrices, called in each update. 
  • GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/src/OgreIlluminationManager.cpp

    r1425 r1628  
    8282        shadowMapSize = 512; 
    8383        phaseTextureSize = 256; 
     84        useLISPSM = false; 
     85        useVSM = false; 
     86        blurSM = false; 
    8487         
    8588        for(int i = 0; i < RUN_TYPE_COUNT; i++) 
  • GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/src/RenderTechniques/OgreDepthShadowRecieverRenderTechnique.cpp

    r1130 r1628  
    5151                 
    5252                TextureUnitState* st = newpass->createTextureUnitState();                
    53                 st->setTextureFiltering(TFO_ANISOTROPIC);                                                
     53                st->setTextureFiltering(TFO_ANISOTROPIC); 
     54                st->setTextureAddressingMode(TextureUnitState::TAM_BORDER); 
     55                st->setTextureBorderColour(ColourValue::White); 
    5456 
    5557                newpass->setSceneBlending(SBT_MODULATE); 
     
    7375                                                        100000.0, 
    7476                                                        lights); 
    75          
     77 
    7678        //fill passes 
     79        unsigned int l = 0; 
    7780        for(unsigned int i = 0; i < passes.size(); i++) 
    7881        { 
    79                 if(lights.size() > i) 
     82                while(lights.size() != l && !lights.at(l)->getCastShadows()) 
     83                 l++; 
     84 
     85                if(lights.size() > l) 
    8086                { 
    81                         //create run if not exists 
    82                         OgreIlluminationManager::getSingleton().createPerLightRun(lights.at(i)->getName(), 
    83                                                                                                                                                 ILLUMRUN_DEPTH_SHADOWMAP); 
    84                         //update light depth map 
    85                         OgreIlluminationManager::getSingleton().updatePerLightRun(lights.at(i)->getName(), 
    86                                                                                                                                                 ILLUMRUN_DEPTH_SHADOWMAP, 
    87                                                                                                                                                 frameNum); 
    8887                         
    89                         //set texture to pass 
    90                         OgreDepthShadowMapRenderingRun* depthRun =  
    91                                 (OgreDepthShadowMapRenderingRun*) OgreIlluminationManager::getSingleton() 
    92                                                                                                         .getPerLightRun(lights.at(i)->getName(),  
    93                                                                                                         ILLUMRUN_DEPTH_SHADOWMAP)->asOgreRenderingRun(); 
    94                                          
    95                         passes.at(i)->getTextureUnitState(0)->setTextureName( 
    96                                 depthRun->getDepthMapTextureName()); 
    97                  
    98                         //TODO: set matrices 
    99                         GpuProgramParametersSharedPtr fpParams = passes.at(i)->getFragmentProgramParameters(); 
    100                         GpuProgramParametersSharedPtr vpParams = passes.at(i)->getVertexProgramParameters(); 
    101                  
    102                         //fpParams->setNamedConstant("lightViewProj", depthRun->getLightViewProjMatrix());  
    103                         vpParams->setNamedConstant("lightViewProj", depthRun->getLightViewProjMatrix()); 
     88                                //create run if not exists 
     89                                OgreIlluminationManager::getSingleton().createPerLightRun(lights.at(l)->getName(), 
     90                                                                                                                                                        ILLUMRUN_DEPTH_SHADOWMAP); 
     91                                //update light depth map 
     92                                OgreIlluminationManager::getSingleton().updatePerLightRun(lights.at(l)->getName(), 
     93                                                                                                                                                        ILLUMRUN_DEPTH_SHADOWMAP, 
     94                                                                                                                                                        frameNum); 
     95                                 
     96                                //set texture to pass 
     97                                OgreDepthShadowMapRenderingRun* depthRun =  
     98                                        (OgreDepthShadowMapRenderingRun*) OgreIlluminationManager::getSingleton() 
     99                                                                                                                .getPerLightRun(lights.at(l)->getName(),  
     100                                                                                                                ILLUMRUN_DEPTH_SHADOWMAP)->asOgreRenderingRun(); 
     101                                                 
     102                                passes.at(i)->getTextureUnitState(0)->setTextureName( 
     103                                        depthRun->getDepthMapTextureName()); 
    104104                         
    105                         passes.at(i)->setActive(true); 
     105                                //TODO: set matrices 
     106                                GpuProgramParametersSharedPtr fpParams = passes.at(i)->getFragmentProgramParameters(); 
     107                                GpuProgramParametersSharedPtr vpParams = passes.at(i)->getVertexProgramParameters(); 
     108                         
     109                                //fpParams->setNamedConstant("lightViewProj", depthRun->getLightViewProjMatrix());  
     110                                vpParams->setNamedConstant("lightViewProj", depthRun->getLightViewProjMatrix()); 
     111                                 
     112                                passes.at(i)->setActive(true); 
     113                         
    106114                }        
    107115                else 
  • GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/src/RenderingRuns/OgreDepthShadowMapRenderingRun.cpp

    r1130 r1628  
    4242                RenderTarget* rt = hpb->getRenderTarget(); 
    4343                Viewport* v = rt->addViewport(depthMapCamera); 
     44                v->setBackgroundColour(ColourValue::White); 
    4445                v->setOverlaysEnabled(false); 
    4546                rt->setAutoUpdated(false); 
    46  
    47                 texPtr = Ogre::TextureManager::getSingleton().createManual(blurredname,  
    48                                                                                                                                                         "default", 
    49                                                                                                                                                         TEX_TYPE_2D, 
    50                                                                                                                                                         resolutionX, 
    51                                                                                                                                                         resolutionY, 
    52                                                                                                                                                         6, 
    53                                                                                                                                                         0, 
    54                                                                                                                                                         PF_FLOAT16_RGBA, 
    55                                                                                                                                                         TU_RENDERTARGET); 
    56                 blurredDepthMapTexture = texPtr.getPointer(); 
    57                 hpb = (blurredDepthMapTexture->getBuffer()).getPointer(); 
    58                 rt = hpb->getRenderTarget(); 
    59                 v = rt->addViewport(depthMapCamera); 
    60                 v->setOverlaysEnabled(false); 
    61                 rt->setAutoUpdated(false); 
     47                 
     48                if(OgreIlluminationManager::getSingleton().getBlurShadowMap()) 
     49                { 
     50                        texPtr = Ogre::TextureManager::getSingleton().createManual(blurredname,  
     51                                                                                                                                                                "default", 
     52                                                                                                                                                                TEX_TYPE_2D, 
     53                                                                                                                                                                resolutionX, 
     54                                                                                                                                                                resolutionY, 
     55                                                                                                                                                                6, 
     56                                                                                                                                                                0, 
     57                                                                                                                                                                PF_FLOAT16_RGBA, 
     58                                                                                                                                                                TU_RENDERTARGET); 
     59                        blurredDepthMapTexture = texPtr.getPointer(); 
     60                        hpb = (blurredDepthMapTexture->getBuffer()).getPointer(); 
     61                        rt = hpb->getRenderTarget(); 
     62                        v = rt->addViewport(depthMapCamera); 
     63                        v->setOverlaysEnabled(false); 
     64                        rt->setAutoUpdated(false); 
     65                } 
    6266} 
    6367 
     
    8892        rt->update(); 
    8993        restoreMaterials(); 
    90  
    91         rt = blurredDepthMapTexture->getBuffer().getPointer()->getRenderTarget(); 
    92         Material*  mat = (Material*) MaterialManager::getSingleton().getByName("GameTools/Blur").getPointer(); 
    93         mat->getTechnique(0)->getPass(0)->getTextureUnitState(0)->setTextureName(depthMapTexture->getName()); 
    94         renderFullscreenQuad("GameTools/Blur", rt); 
    95          
     94         
     95        if(OgreIlluminationManager::getSingleton().getBlurShadowMap()) 
     96        { 
     97                rt = blurredDepthMapTexture->getBuffer().getPointer()->getRenderTarget(); 
     98                Material*  mat = (Material*) MaterialManager::getSingleton().getByName("GameTools/Blur").getPointer(); 
     99                mat->getTechnique(0)->getPass(0)->getTextureUnitState(0)->setTextureName(depthMapTexture->getName()); 
     100                renderFullscreenQuad("GameTools/Blur", rt); 
     101        }        
    96102         
    97103        //rt->writeContentsToFile("shadowmap1.dds"); 
     
    99105        //depthMapTexture->(); 
    100106} 
    101  
    102 void setnear() 
    103 { 
    104  
     107String OgreDepthShadowMapRenderingRun::getDepthMapTextureName() 
     108{ 
     109                if(OgreIlluminationManager::getSingleton().getBlurShadowMap()) 
     110                        return blurredname; 
     111 
     112                return name; 
    105113} 
    106114 
     
    110118        if(light!= 0) 
    111119        { 
     120                bool uselispsm = OgreIlluminationManager::getSingleton().getUseLISPSM(); 
    112121                if(light->getType() == Light::LT_DIRECTIONAL) 
    113122                { 
     
    118127                        frun->setCameraMatrices(viewcam->getViewMatrix(), viewcam->getProjectionMatrix()); 
    119128 
    120                         Vector3 lightpos = light->getPosition(); 
     129                        Vector3 lightpos = light->getParentSceneNode()->getWorldPosition(); 
    121130                        Vector3 lightdir = light->getDirection(); 
    122131                        lightdir.normalise();            
     
    125134                        Vector3 max;                     
    126135 
    127                         bool uselispsm = true; 
     136                         
    128137                        if(uselispsm) 
    129138                        { 
     
    138147                                 
    139148                                Vector3 left = lightdir.crossProduct(viewdir); 
     149                                left.normalise(); 
    140150                                Vector3 up = left.crossProduct(lightdir); 
    141151                                up.normalise(); 
     
    167177                                Matrix4 newViewMatrix(  left.x,      left.y,      left.z,                -left.dotProduct(pos), 
    168178                                                                                up.x,            up.y,            up.z,                  -up.dotProduct(pos), 
    169                                                                                 lightdir.x,  lightdir.y,  lightdir.z,    -lightdir.dotProduct(pos), 
     179                                                                                -lightdir.x,  -lightdir.y,  -lightdir.z,    lightdir.dotProduct(pos), 
    170180                                                                                0,           0,           0,             1); 
    171181 
     
    200210                        Vector3 scale = (max - min); 
    201211                        scale *= 1.5; // just for safety 
    202                         scale.z = 200; //TODO: get scene bounding box to set z scale     
     212                        if(uselispsm) 
     213                                scale.z += 1; 
     214                        else 
     215                                scale.z += 1000; //TODO: get scene bounding box to set z scale   
    203216                        Matrix4 projection = Matrix4::IDENTITY; 
    204                         projection.setScale(Vector3(2.0 / scale.x, 2.0 / scale.y, -2.0 / scale.z));                      
    205                         projection.setTrans(Vector3(-(max.x + min.x) / scale.x, 
    206                                                                                 -(max.y + min.y) / scale.y, 
    207                                                                                 -(max.z + min.z) / scale.z)); 
     217                        Matrix4 trans = Matrix4::IDENTITY; 
     218                        trans.setTrans(Vector3(-(max.x + min.x) / 2.0, 
     219                                                                   -(max.y + min.y) / 2.0, 
     220                                                                   -(max.z + min.z) / 2.0)); 
     221                        Matrix4 scaleM = Matrix4::IDENTITY; 
     222                        scaleM.setScale(Vector3(2.0 / scale.x, 2.0 / scale.y, -2.0 / scale.z)); 
     223                        projection = scaleM * trans;                     
    208224                        depthMapCamera->setCustomProjectionMatrix(true, projection);                     
    209225                } 
    210226                else if(light->getType() == Light::LT_SPOTLIGHT) 
    211227                { 
    212         /*              Vector3 dir = light->getDirection(); 
    213                         depthMapCamera->setDirection( dir ); 
    214                         Vector3 pos = light->getParentNode()->getWorldPosition(); 
    215                         depthMapCamera->setPosition(pos); 
    216                         depthMapCamera->setProjectionType(PT_PERSPECTIVE);               
    217                         depthMapCamera->setFOVy(light->getSpotlightOuterAngle());*/ 
     228                        Camera* viewcam = OgreIlluminationManager::getSingleton().getMainCamera();                       
     229                         
     230                        OgreFocusingMapRenderingRun* frun = (OgreFocusingMapRenderingRun*) 
     231                                OgreIlluminationManager::getSingleton().getGlobalRun(ILLUMRUN_FOCUSING_MAP)->asOgreRenderingRun(); 
     232                        frun->setCameraMatrices(viewcam->getViewMatrix(), viewcam->getProjectionMatrix()); 
     233 
     234                        Vector3 lightpos = light->getParentSceneNode()->getWorldPosition (); 
     235                        Vector3 lightdir = light->getDirection(); 
     236                        lightdir.normalise();            
     237                        Radian lightangle = light->getSpotlightOuterAngle(); 
     238                                 
     239                        Vector3 min; 
     240                        Vector3 max; 
     241                         
     242                        if(uselispsm) 
     243                        { 
     244                                Camera* maincam = OgreIlluminationManager::getSingleton().getMainCamera(); 
     245                                Vector3 viewdir = maincam->getDirection(); 
     246                                viewdir.normalise(); 
     247                                Vector3 campos = maincam->getPosition(); 
     248                                float nearclip = maincam->getNearClipDistance(); 
     249 
     250                                float dotprod = viewdir.dotProduct(lightdir); 
     251                                float sinGamma = sqrt(1.0 - dotprod * dotprod); 
     252                                 
     253                                Vector3 left = lightdir.crossProduct(viewdir); 
     254                                Vector3 up = left.crossProduct(lightdir); 
     255                                up.normalise(); 
     256                                //left = lightdir.crossProduct(up); 
     257                                left.normalise(); 
     258                                 
     259                                depthMapCamera->setCustomProjectionMatrix(false); 
     260                                depthMapCamera->setProjectionType(PT_PERSPECTIVE); 
     261                                depthMapCamera->setFOVy(lightangle); 
     262                                depthMapCamera->setAspectRatio(1); 
     263                                depthMapCamera->setNearClipDistance(0.1); 
     264                                depthMapCamera->setFarClipDistance(1.0); 
     265 
     266                                Matrix4 projMatrix = depthMapCamera->getProjectionMatrixWithRSDepth(); 
     267 
     268                                Matrix4 viewMatrix( left.x,      left.y,      left.z,            0, 
     269                                                                        up.x,            up.y,            up.z,                  0, 
     270                                                                        -lightdir.x,  -lightdir.y,  -lightdir.z,    0, 
     271                                                                        0,           0,           0,             1);                             
     272                                 
     273                                frun->setLightMatrix(projMatrix * viewMatrix);                           
     274                                OgreIlluminationManager::getSingleton().updateGlobalRun( ILLUMRUN_FOCUSING_MAP, 
     275                                                                                                                                                        frameNum);                       
     276                                frun->getMinMax(min, max); 
     277 
     278                                float n; 
     279                                float f; 
     280                                float d = abs(max.y - min.y); 
     281                                         
     282                                float z_n = nearclip / sinGamma; 
     283                                float one_min_singamma = (1 - sinGamma); 
     284                                float fact = d * pow(one_min_singamma, 2); 
     285                                float z_f = z_n + d * sinGamma * fact; 
     286                                n = (z_n + sqrt(z_f * z_n)) / sinGamma; 
     287                                ///n = 100000; 
     288                                f = n + d; 
     289 
     290                                Vector3 pos = campos - up * (n - nearclip); 
     291                                Matrix4 newViewMatrix(  left.x,      left.y,      left.z,                -left.dotProduct(pos), 
     292                                                                                up.x,            up.y,            up.z,                  -up.dotProduct(pos), 
     293                                                                                -lightdir.x,  -lightdir.y,  -lightdir.z,    lightdir.dotProduct(pos), 
     294                                                                                0,           0,           0,             1); 
     295 
     296                                Matrix4 lispMat = Matrix4::IDENTITY; 
     297                                 
     298                                lispMat[1][1] = f / (f - n); 
     299                                lispMat[1][3] = f * n / (f - n); 
     300                                lispMat[3][1] = 1; 
     301                                lispMat[3][3] = 0; 
     302                                 
     303                                depthMapCamera->setCustomProjectionMatrix(true, Matrix4::IDENTITY); 
     304                                depthMapCamera->setCustomViewMatrix(true, lispMat * projMatrix * newViewMatrix); 
     305                        } 
     306                        else 
     307                        { 
     308                                depthMapCamera->setCustomProjectionMatrix(false); 
     309                                depthMapCamera->setCustomViewMatrix(false); 
     310                                depthMapCamera->setPosition(lightpos); 
     311                                depthMapCamera->setDirection(lightdir); 
     312                                depthMapCamera->setProjectionType(PT_PERSPECTIVE); 
     313                                depthMapCamera->setFOVy(lightangle); 
     314                                depthMapCamera->setAspectRatio(1); 
     315                                depthMapCamera->setNearClipDistance(0.1); 
     316                                depthMapCamera->setFarClipDistance(1.0); 
     317                        } 
     318                         
     319 
     320                        Matrix4 lightMatrix = depthMapCamera->getViewMatrix(); 
     321                        frun->setLightMatrix(lightMatrix); 
     322                         
     323                        OgreIlluminationManager::getSingleton().updateGlobalRun( ILLUMRUN_FOCUSING_MAP, 
     324                                                                                                                                                frameNum); 
     325 
     326                        frun->getMinMax(min, max);                       
     327                         
     328                        if(min.z < 0) 
     329                        { 
     330                                float farP= -1.5 * min.z; 
     331                                if(farP < 0.2) farP = 0.2; 
     332                                depthMapCamera->setFarClipDistance(farP); 
     333 
     334                                Vector3 scale = (max - min); 
     335                                scale *= 1.5; // just for safety 
     336                                 
     337                                Matrix4 projection = Matrix4::IDENTITY; 
     338                                Matrix4 trans = Matrix4::IDENTITY; 
     339                                trans.setTrans(Vector3(-(max.x + min.x) / 2.0, 
     340                                                                   -(max.y + min.y) / 2.0, 
     341                                                                     0)); 
     342                                Matrix4 scaleM = Matrix4::IDENTITY; 
     343                                scaleM.setScale(Vector3(2.0 / scale.x, 2.0 / scale.y, 1)); 
     344                                projection = scaleM * trans;                     
     345                                depthMapCamera->setCustomProjectionMatrix(true, projection * depthMapCamera->getProjectionMatrix());                                            
     346                        } 
    218347                } 
    219348                else//point light 
  • GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/src/RenderingRuns/OgrePhotonMapRenderingRun.cpp

    r1055 r1628  
    108108                        Matrix4 proj; 
    109109                        proj = Matrix4::IDENTITY; 
    110                         proj.setScale(Vector3(1.0/r, 1.0/r, -1.0/r)); 
    111                         proj.setTrans(Vector3(0,0,-1)); 
     110                        proj.setScale(Vector3(1.0/r, 1.0/r, -1.5/r)); 
     111                        //proj.setTrans(Vector3(0,0,-1)); 
    112112                        photonMapCamera->setCustomProjectionMatrix(true,proj); 
    113113                } 
Note: See TracChangeset for help on using the changeset viewer.