Ignore:
Timestamp:
04/24/07 14:04:48 (17 years ago)
Author:
szirmay
Message:
 
Location:
GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/src/RenderingRuns
Files:
4 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 
  • GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/src/RenderingRuns/OgreLightVolumeRenderingRun.cpp

    r2321 r2333  
    238238                else 
    239239                {                        
    240                         Vector3 pos = light->getParentSceneNode()->getPosition(); 
     240                        Vector3 pos = light->getDerivedPosition(); 
    241241                        Vector3 dir = sharedRuns->getRootPosition(ILLUMRUN_LIGHTVOLUME_MAP) - pos; 
    242242                        dir.normalise(); 
  • GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/src/RenderingRuns/OgrePMWeightComputeRenderingRun.cpp

    r2321 r2333  
    44#include "OgreDepthShadowMapRenderingRun.h" 
    55 
     6Texture* OgrePMWeightComputeRenderingRun::weightTexture = 0; 
     7Texture* OgrePMWeightComputeRenderingRun::allWeightsTexture = 0; 
     8 
    69OgrePMWeightComputeRenderingRun::OgrePMWeightComputeRenderingRun(String name, String LightName) 
    710                                                                                                                   : OgreRenderingRun(1, 1) 
     
    1922void OgrePMWeightComputeRenderingRun::createWeightMap() 
    2023{ 
    21          
    22         unsigned int entryPointCnt = OgreIlluminationManager::getSingleton().getPathMapEntryPoints().size(); 
    23         int width = entryPointCnt / 4096; 
    24         int height = 4096; 
    25         TexturePtr texPtr = Ogre::TextureManager::getSingleton().createManual(name + "_ALL",  
    26                                                                                                                                                 "default", 
    27                                                                                                                                                 TEX_TYPE_2D, 
    28                                                                                                                                                 width, 
    29                                                                                                                                                 height, 
    30                                                                                                                                                 0, 
    31                                                                                                                                                 0, 
    32                                                                                                                                                 PF_FLOAT32_R, 
    33                                                                                                                                                 TU_RENDERTARGET); 
    34          allWeightsTexture = texPtr.getPointer(); 
    35          //add viewport to rendertarget 
    36          HardwarePixelBuffer* hpb = (allWeightsTexture->getBuffer()).getPointer(); 
    37          RenderTarget* rt = hpb->getRenderTarget(); 
    38          Camera* wc = Root::getSingleton()._getCurrentSceneManager()->createCamera(name + "_ALL_CAMERA");  
    39          Viewport* v = rt->addViewport(wc); 
    40          v->setOverlaysEnabled(false); 
    41          rt->setAutoUpdated(false); 
    42  
    43         unsigned int clustercount = OgreIlluminationManager::getSingleton().getPathMapClusterLengthsSize(); 
    44         width = clustercount; 
    45         height = 1; 
    46         texPtr = Ogre::TextureManager::getSingleton().createManual(name,  
    47                                                                                                                                 "default", 
    48                                                                                                                                 TEX_TYPE_2D, 
    49                                                                                                                                 width, 
    50                                                                                                                                 height, 
    51                                                                                                                                 0, 
    52                                                                                                                                 0, 
    53                                                                                                                                 PF_FLOAT32_R, 
    54                                                                                                                                 TU_RENDERTARGET); 
    55          weightTexture = texPtr.getPointer(); 
    56          //add viewport to rendertarget 
    57          hpb = (weightTexture->getBuffer()).getPointer(); 
    58          rt = hpb->getRenderTarget(); 
    59          wc = Root::getSingleton()._getCurrentSceneManager()->createCamera(name + "_CAMERA");  
    60          v = rt->addViewport(wc); 
    61          v->setOverlaysEnabled(false); 
    62          rt->setAutoUpdated(false); 
     24        if(allWeightsTexture == 0) 
     25        { 
     26                unsigned int entryPointCnt = OgreIlluminationManager::getSingleton().getPathMapEntryPoints().size(); 
     27                int width = entryPointCnt / 4096; 
     28                int height = 4096; 
     29                TexturePtr texPtr = Ogre::TextureManager::getSingleton().createManual(name + "_ALL",  
     30                                                                                                                                                        "default", 
     31                                                                                                                                                        TEX_TYPE_2D, 
     32                                                                                                                                                        width, 
     33                                                                                                                                                        height, 
     34                                                                                                                                                        0, 
     35                                                                                                                                                        0, 
     36                                                                                                                                                        PF_FLOAT16_RGBA, 
     37                                                                                                                                                        TU_RENDERTARGET); 
     38                allWeightsTexture = texPtr.getPointer(); 
     39                //add viewport to rendertarget 
     40                HardwarePixelBuffer* hpb = (allWeightsTexture->getBuffer()).getPointer(); 
     41                RenderTarget* rt = hpb->getRenderTarget(); 
     42                Camera* wc = Root::getSingleton()._getCurrentSceneManager()->createCamera(name + "_ALL_CAMERA");  
     43                Viewport* v = rt->addViewport(wc); 
     44                v->setBackgroundColour(ColourValue::Black); 
     45                v->setClearEveryFrame(false); 
     46                v->setOverlaysEnabled(false); 
     47                rt->setAutoUpdated(false); 
     48 
     49                unsigned int clustercount = OgreIlluminationManager::getSingleton().getPathMapClusterLengthsSize(); 
     50                width = clustercount; 
     51                height = 1; 
     52                texPtr = Ogre::TextureManager::getSingleton().createManual(name,  
     53                                                                                                                                        "default", 
     54                                                                                                                                        TEX_TYPE_2D, 
     55                                                                                                                                        width, 
     56                                                                                                                                        height, 
     57                                                                                                                                        0, 
     58                                                                                                                                        0, 
     59                                                                                                                                        PF_FLOAT16_RGBA, 
     60                                                                                                                                        TU_RENDERTARGET); 
     61                weightTexture = texPtr.getPointer(); 
     62                //add viewport to rendertarget 
     63                hpb = (weightTexture->getBuffer()).getPointer(); 
     64                rt = hpb->getRenderTarget(); 
     65                wc = Root::getSingleton()._getCurrentSceneManager()->createCamera(name + "_CAMERA");  
     66                v = rt->addViewport(wc); 
     67                v->setOverlaysEnabled(false); 
     68                rt->setAutoUpdated(false);               
     69        } 
    6370} 
    6471 
     
    8390                GpuProgramParameters* Fparams = mat->getTechnique(0)->getPass(0)->getFragmentProgramParameters().getPointer(); 
    8491                         
    85                         Vector3 lightPos = light->getPosition(); 
    86                         Vector3 lightDir = light->getDirection(); 
    87                 //      Radian lightAngle = light->getSpotlightOuterAngle(); 
     92                        Vector3 lightPos = light->getDerivedPosition(); 
     93                        Vector3 lightDir = light->getDerivedDirection(); 
     94                        Radian lightAngle = light->getSpotlightOuterAngle(); 
    8895                         
    8996                        Fparams->setNamedConstant("nRadionColumns", col); 
     
    9198                        Fparams->setNamedConstant("lightDir", lightDir); 
    9299                        Fparams->setNamedConstant("lightPower", light->getPowerScale()); 
     100                        Fparams->setNamedConstant("lightColor", light->getDiffuseColour()); 
    93101                        Fparams->setNamedConstant("lightViewProj", SMrun->getLightViewProjMatrix()); 
    94102                        Fparams->setNamedConstant("lightFarPlane", SMrun->getLightFarPlane()); 
     103                        Fparams->setNamedConstant("lightAttenuation", Vector4(light->getAttenuationRange(), 
     104                                                                                                                                        light->getAttenuationConstant(), 
     105                                                                                                                                        light->getAttenuationLinear(), 
     106                                                                                                                                        light->getAttenuationQuadric())); 
     107                        Fparams->setNamedConstant("lightAngleCos", Math::Cos(lightAngle.valueRadians()/2.0));                    
     108                        Fparams->setNamedConstant("spotLightFalloff", light->getSpotlightFalloff());                     
    95109                         
    96110                        mat->getTechnique(0)->getPass(0)->getTextureUnitState(0)->setTextureName( 
     
    100114                                 
    101115                        RenderTarget* rt = allWeightsTexture->getBuffer().getPointer()->getRenderTarget(); 
    102                         renderFullscreenQuad(mat->getName(), rt); 
     116                        if(frameNum != rt->getLastFrameNumber()) 
     117                                rt->getViewport(0)->setClearEveryFrame(true); 
     118                        else 
     119                                rt->getViewport(0)->setClearEveryFrame(false); 
     120                         
     121                                renderFullscreenQuad(mat->getName(), rt); 
     122                         
    103123 
    104124                //      rt->writeContentsToFile("allweights.bmp"); 
    105125                //      rt->writeContentsToFile("allweights.dds"); 
    106                          
    107                 /*      float* allweights = new float[entryPointCnt / 4096 * 4096]; 
    108                         PixelBox lockBox(entryPointCnt / 4096, 4096, 1, PF_FLOAT32_R, allweights); 
    109                         allWeightsTexture->getBuffer()->blitToMemory(lockBox); 
    110  
    111                         ///////////////////DEBUG 
    112                         static BillboardSet* entryPointBBSet = 0; 
    113                         if(entryPointBBSet == 0) 
    114                         { 
    115                                 SceneManager* sm = Root::getSingleton()._getCurrentSceneManager(); 
    116                                 entryPointBBSet = sm->createBillboardSet("PATHMAP_ENTRYPOINTS", entryPointCnt); 
    117                                 entryPointBBSet->setBillboardType(BBT_POINT); 
    118                                 entryPointBBSet->setBillboardsInWorldSpace(true); 
    119                                 entryPointBBSet->setPointRenderingEnabled(true); 
    120                                 for(unsigned int i = 0; i < entryPointCnt; i++) 
    121                                 { 
    122                                         PathMapEntryPoint EP = OgreIlluminationManager::getSingleton().getPathMapEntryPoints().at(i); 
    123                                         Vector3 billboardPosition = EP.position; 
    124                                          
    125                                         float uCoord = allweights[i]; 
    126                                         float  vCoord = 0; 
    127                                         //float uCoord = ((float) (i % col) + 0.5f) / (float) col; 
    128                                         //float vCoord = ((float)(i / col) + 0.5f) / 4096.0f; 
    129                                         entryPointBBSet->createBillboard(billboardPosition, ColourValue(uCoord, vCoord, 0, 0)); 
    130                                 } 
    131                                 entryPointBBSet->setMaterialName("GTP/PM/EPBillboards"); 
    132                                 MaterialPtr mater = MaterialManager::getSingleton().getByName("GTP/PM/EPBillboards"); 
    133                                 mater->getTechnique(0)->getPass(0)->getTextureUnitState(0)->setTextureName(allWeightsTexture->getName()); 
    134                                 sm->getRootSceneNode()->createChildSceneNode()->attachObject(entryPointBBSet); 
    135                         } 
    136  
    137                         delete[] allweights;*/ 
    138  
    139 ///////////////// 
     126 
    140127        } 
    141         else 
     128        else if(light->getType() == Light::LT_POINT) 
    142129        { 
    143                 ///not implemented 
     130                OgreIlluminationManager::getSingleton().createPerLightRun(light->getName(), ILLUMRUN_DEPTH_SHADOWMAP); 
     131                OgreIlluminationManager::getSingleton().updatePerLightRun(light->getName(), ILLUMRUN_DEPTH_SHADOWMAP, frameNum); 
     132                OgreDepthShadowMapRenderingRun* SMrun = (OgreDepthShadowMapRenderingRun*) OgreIlluminationManager::getSingleton() 
     133                        .getPerLightRun(light->getName(), ILLUMRUN_DEPTH_SHADOWMAP)->asOgreRenderingRun();  
     134                 
     135                MaterialPtr mat = MaterialManager::getSingleton().getByName("GTP/PathMap_ComputeWeights_Point"); 
     136                GpuProgramParameters* Fparams = mat->getTechnique(0)->getPass(0)->getFragmentProgramParameters().getPointer(); 
     137                         
     138                        Vector3 lightPos = light->getDerivedPosition(); 
     139                         
     140                        Fparams->setNamedConstant("nRadionColumns", col); 
     141                        Fparams->setNamedConstant("lightPos", lightPos); 
     142                        Fparams->setNamedConstant("lightPower", light->getPowerScale()); 
     143                        Fparams->setNamedConstant("lightColor", light->getDiffuseColour()); 
     144                        Fparams->setNamedConstant("lightFarPlane", SMrun->getLightFarPlane()); 
     145                        Fparams->setNamedConstant("lightAttenuation", Vector4(light->getAttenuationRange(), 
     146                                                                                                                                        light->getAttenuationConstant(), 
     147                                                                                                                                        light->getAttenuationLinear(), 
     148                                                                                                                                        light->getAttenuationQuadric())); 
     149 
     150                        mat->getTechnique(0)->getPass(0)->getTextureUnitState(0)->setTextureName( 
     151                                                PMEPrun->getEntryPointTextureName()); 
     152                        mat->getTechnique(0)->getPass(0)->getTextureUnitState(1)->setTextureName( 
     153                                                SMrun->getDepthMapTextureName()); 
     154                                 
     155                        RenderTarget* rt = allWeightsTexture->getBuffer().getPointer()->getRenderTarget(); 
     156                        if(frameNum != rt->getLastFrameNumber()) 
     157                                rt->getViewport(0)->setClearEveryFrame(true); 
     158                        else 
     159                                rt->getViewport(0)->setClearEveryFrame(false); 
     160                         
     161                                renderFullscreenQuad(mat->getName(), rt); 
     162                         
    144163        } 
    145164 
     165} 
     166 
     167void OgrePMWeightComputeRenderingRun::sumWeights(unsigned long frameNum) 
     168{ 
     169        RenderTarget* rt = weightTexture->getBuffer().getPointer()->getRenderTarget(); 
     170        if(frameNum == rt->getLastFrameNumber())return; 
     171         
     172        unsigned int entryPointCnt = OgreIlluminationManager::getSingleton().getPathMapEntryPoints().size(); 
     173        int col = entryPointCnt / 4096;  
    146174        unsigned int clustercount = OgreIlluminationManager::getSingleton().getPathMapClusterLengthsSize(); 
    147  
     175        OgrePMEntryPointMapRenderingRun* PMEPrun = (OgrePMEntryPointMapRenderingRun*) 
     176        OgreIlluminationManager::getSingleton().getGlobalRun(ILLUMRUN_PM_ENTRYPOINTMAP)->asOgreRenderingRun(); 
     177         
    148178        MaterialPtr mat = MaterialManager::getSingleton().getByName("GTP/PathMap_SumWeights"); 
    149179        GpuProgramParameters* Fparams = mat->getTechnique(0)->getPass(0)->getFragmentProgramParameters().getPointer(); 
     
    157187                                                allWeightsTexture->getName()); 
    158188         
    159         RenderTarget* rt = weightTexture->getBuffer().getPointer()->getRenderTarget(); 
    160189        renderFullscreenQuad(mat->getName(), rt); 
    161  
    162         //rt->writeContentsToFile("weights.bmp");        
    163         //rt->writeContentsToFile("weights.dds"); 
    164 /* 
    165         float* weights = new float[clustercount]; 
    166         PixelBox lockBox(clustercount, 1, 1, PF_FLOAT32_R, weights); 
    167         weightTexture->getBuffer()->blitToMemory(lockBox); 
    168  
    169         delete[] weights;*/ 
    170190} 
    171191 
  • GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/src/RenderingRuns/OgrePhotonMapRenderingRun.cpp

    r2321 r2333  
    100100                if(light->getType() == Light::LT_DIRECTIONAL) 
    101101                { 
    102                         Vector3 dir = light->getDirection(); 
     102                        Vector3 dir = light->getDerivedDirection(); 
    103103                        photonMapCamera->setDirection( dir ); 
    104104                        Real r = sharedRuns->getRootBoundingSphere(ILLUMRUN_PHOTONMAP).getRadius(); 
     
    113113                else 
    114114                {                        
    115                         Vector3 pos = light->getParentSceneNode()->getPosition(); 
     115                        Vector3 pos = light->getDerivedPosition(); 
    116116                        Vector3 dir = sharedRuns->getRootPosition(ILLUMRUN_PHOTONMAP) - pos; 
    117117                        Real r = sharedRuns->getRootBoundingSphere(ILLUMRUN_PHOTONMAP).getRadius(); 
Note: See TracChangeset for help on using the changeset viewer.