Ignore:
Timestamp:
06/26/06 09:52:08 (18 years ago)
Author:
szirmay
Message:
 
Location:
GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/src
Files:
4 added
12 edited

Legend:

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

    r949 r1055  
    7979        visitor = new VisibleFinderVisitor(&visibleObjects); 
    8080        maxRad = 400; 
     81         
     82        for(int i = 0; i < RUN_TYPE_COUNT; i++) 
     83        { 
     84                maxRads[(RenderingRunType)i] = (float) maxRad; 
     85        } 
    8186 
    8287        //register rendertechnique factories 
     
    95100        OgreSBBRenderTechniqueFactory* sbb = new OgreSBBRenderTechniqueFactory(); 
    96101                addRenderTechniqueFactory(sbb); 
     102        OgreFireRenderTechniqueFactory* fire = new OgreFireRenderTechniqueFactory(); 
     103                addRenderTechniqueFactory(fire); 
    97104} 
    98105 
     
    160167void OgreIlluminationManager::initTechniques(Entity* e) 
    161168{ 
     169        if( e->getParentSceneNode() == 0 )//Entity not attached 
     170                return; 
     171 
    162172        OgreSharedRuns* sharedruns = 0; 
    163173         
     
    215225} 
    216226 
     227 
     228void OgreIlluminationManager::initTechniques(BillboardSet* bbs, ParticleSystem* sys) 
     229{ 
     230        if( bbs->getParentSceneNode() == 0 )//billboardset not attached 
     231                return; 
     232 
     233        OgreSharedRuns* sharedruns = 0;  
     234 
     235        Material* mat = bbs->getMaterial().getPointer(); 
     236         
     237        OgreRenderable* rend = 0;        
     238        OgreTechniqueGroup* group = 0; 
     239 
     240        for(unsigned int t = 0 ; t < mat->getNumTechniques() ; t++) 
     241        { 
     242                Technique* tech = mat->getTechnique(t); 
     243 
     244                for(unsigned int p = 0; p< tech->getNumPasses(); p++) 
     245                { 
     246                        Pass* pass = tech->getPass(p); 
     247 
     248                        std::vector<IllumTechniqueParams*>& techniques = pass->getIllumTechniques(); 
     249                        std::vector<IllumTechniqueParams*>::iterator i = techniques.begin();  
     250                        std::vector<IllumTechniqueParams*>::iterator iend = techniques.end(); 
     251                         
     252                        while( i != iend) 
     253                        { 
     254                                IllumTechniqueParams* params = *i; 
     255                                 
     256                                if(rend == 0) 
     257                                { 
     258                                        rend = new OgreRenderable(bbs, sys); 
     259                                        group = new OgreTechniqueGroup(); 
     260                                        bbs->setRenderTechniqueGroup(group);                                                     
     261                                         
     262                                        if( sharedruns == 0) 
     263                                        {                                                                        
     264                                                sharedruns  = new OgreSharedRuns(); 
     265                                                addSharedRuns(sharedruns); 
     266                                        } 
     267 
     268                                        group->addSharedRun(sharedruns); 
     269                                        sharedruns->addRenderable(rend); 
     270                                        sharedruns->updateBounds(); 
     271                                } 
     272                                 
     273                                createTechnique(params, pass, rend, sharedruns);  
     274 
     275                                i++; 
     276                        } 
     277                } 
     278        } 
     279                         
     280} 
     281 
    217282void OgreIlluminationManager::initTechniques() 
    218283{ 
     
    225290                        MovableObject* o = it.getNext(); 
    226291                        Entity* e = (Entity*) o; 
    227  
    228                 /*      OgreSharedRuns* sharedruns = 0; 
    229                          
    230                         for(unsigned int s = 0; s < e->getNumSubEntities(); s++) 
    231                         { 
    232                                 SubEntity* sube = e->getSubEntity(s); 
    233  
    234                                 Material* mat = sube->getMaterial().getPointer(); 
    235                                  
    236                                 OgreRenderable* rend = 0;        
    237                                 OgreTechniqueGroup* group = 0; 
    238                          
    239                                 for(unsigned int t = 0 ; t < mat->getNumTechniques() ; t++) 
    240                                 { 
    241                                         Technique* tech = mat->getTechnique(t); 
    242  
    243                                         for(unsigned int p = 0; p< tech->getNumPasses(); p++) 
    244                                         { 
    245                                                 Pass* pass = tech->getPass(p); 
    246  
    247                                                 std::vector<IllumTechniqueParams*>& techniques = pass->getIllumTechniques(); 
    248                                                 std::vector<IllumTechniqueParams*>::iterator i = techniques.begin();  
    249                                                 std::vector<IllumTechniqueParams*>::iterator iend = techniques.end(); 
    250                                                  
    251                                                 while( i != iend) 
    252                                                 { 
    253                                                         IllumTechniqueParams* params = *i; 
    254                                                          
    255                                                         if(rend == 0) 
    256                                                         { 
    257                                                                 rend = new OgreRenderable(e, s); 
    258                                                                 group = new OgreTechniqueGroup(); 
    259                                                                 sube->setRenderTechniqueGroup(group);                                                    
    260                                                                  
    261                                                                 if( sharedruns == 0) 
    262                                                                 {                                                                        
    263                                                                         sharedruns  = new OgreSharedRuns(); 
    264                                                                         addSharedRuns(sharedruns); 
    265                                                                 } 
    266  
    267                                                                 group->addSharedRun(sharedruns); 
    268                                                                 sharedruns->addRenderable(rend); 
    269                                                                 sharedruns->updateBounds(); 
    270                                                         } 
    271                                                          
    272                                                         createTechnique(params, pass, rend, sharedruns);  
    273  
    274                                                         i++; 
    275                                                 } 
    276                                         } 
    277                                 } 
    278                         } 
    279  
    280                 */ 
     292                 
    281293                        initTechniques(e); 
    282294                } 
     
    290302                        MovableObject* o = it.getNext(); 
    291303                        ParticleSystem* psys = (ParticleSystem*) o; 
    292  
    293                         BillboardSet* bbset = findRenderableInParticleSystem(psys); 
    294                          
    295                         OgreTechniqueGroup* group = 0;                   
    296                         OgreSharedRuns* sharedruns = 0; 
    297                         OgreRenderable* rend = 0;        
    298                                                  
    299                         String matName = psys->getMaterialName(); 
    300                         Material* mat = (Material*) MaterialManager::getSingleton().getByName(matName).getPointer(); 
    301  
    302                         for(unsigned int t = 0 ; t < mat->getNumTechniques() ; t++) 
     304                         
     305                        try 
    303306                        { 
    304                                 Technique* tech = mat->getTechnique(t); 
    305  
    306                                 for(unsigned int p = 0; p< tech->getNumPasses(); p++) 
    307                                 { 
    308                                         Pass* pass = tech->getPass(p); 
    309  
    310                                         std::vector<IllumTechniqueParams*>& techniques = pass->getIllumTechniques(); 
    311                                         std::vector<IllumTechniqueParams*>::iterator i = techniques.begin();  
    312                                         std::vector<IllumTechniqueParams*>::iterator iend = techniques.end(); 
    313  
    314                                          
    315                                         while( i != iend) 
    316                                         { 
    317                                                 IllumTechniqueParams* params = *i; 
    318                                                  
    319                                                 if(rend == 0) 
    320                                                 { 
    321                                                         rend = new OgreRenderable(bbset); 
    322                                                         group = new OgreTechniqueGroup(); 
    323                                                         bbset->setRenderTechniqueGroup(group);                                                   
    324                                                          
    325                                                         if( sharedruns == 0) 
    326                                                         {                                                                        
    327                                                                 sharedruns  = new OgreSharedRuns(); 
    328                                                                 addSharedRuns(sharedruns); 
    329                                                         } 
    330  
    331                                                         group->addSharedRun(sharedruns); 
    332                                                         sharedruns->addRenderable(rend); 
    333                                                         sharedruns->updateBounds(); 
    334                                                 } 
    335  
    336                                                 createTechnique(params, pass, rend, sharedruns);  
    337  
    338                                                 i++; 
    339                                         } 
    340                                 } 
     307                         BillboardSet* bbset = findRenderableInParticleSystem(psys); 
     308                         bbset->setMaterialName(psys->getMaterialName()); 
     309                         initTechniques(bbset, psys); 
    341310                        } 
    342                          
    343  
     311                        catch( ... ) 
     312                        { 
     313                                //unsupported particle renderer, skip init 
     314                        } 
    344315                } 
    345316        } 
     
    371342                } 
    372343 
     344                it++; 
     345        } 
     346} 
     347void OgreIlluminationManager::preAllUpdates() 
     348{ 
     349        std::vector<UpdateListener*>::iterator it = updateListeners.begin(); 
     350        std::vector<UpdateListener*>::iterator itend = updateListeners.end(); 
     351 
     352        while(it != itend) 
     353        { 
     354                UpdateListener* l = *it; 
     355                l->preAllUpdates(); 
     356                it++; 
     357        } 
     358} 
     359 
     360void OgreIlluminationManager::postAllUpdates() 
     361{ 
     362        std::vector<UpdateListener*>::iterator it = updateListeners.begin(); 
     363        std::vector<UpdateListener*>::iterator itend = updateListeners.end(); 
     364 
     365        while(it != itend) 
     366        { 
     367                UpdateListener* l = *it; 
     368                l->postAllUpdates(); 
    373369                it++; 
    374370        } 
     
    406402                std::vector<const Renderable*>::iterator iter = visibleObjects.begin(); 
    407403                const std::vector<const Renderable*>::iterator iend = visibleObjects.end(); 
     404 
     405                preAllUpdates(); 
    408406 
    409407                while(iter != iend) 
     
    418416                } 
    419417 
     418                postAllUpdates(); 
     419 
    420420        } 
    421421} 
     
    448448                while(it2 != itend) 
    449449                { 
    450                         if( *it1 != *it2 && OgreSharedRuns::canJoin(*it1, *it2)) 
     450                        if( it1 != it2 && OgreSharedRuns::canJoin(*it1, *it2)) 
    451451                        { 
    452452                                SharedRuns* newruns = (*it1)->joinRuns(*it2); 
     
    513513} 
    514514 
     515 
     516 
    515517RenderingRun* OgreIlluminationManager::getGlobalRun(RenderingRunType runType) 
    516518{ 
    517519        return globalSharedRuns.getRun(runType); 
     520} 
     521 
     522GlobalUseRenderTarget* OgreIlluminationManager::getGlobalTarget(GlobalTargetType type) 
     523{ 
     524        std::map<GlobalTargetType, GlobalUseRenderTarget*>::iterator it = globalTargets.find(type); 
     525         
     526        if( it != globalTargets.end()) 
     527                return (*it).second; 
     528 
     529        return 0; 
     530} 
     531 
     532void OgreIlluminationManager::addGlobalTarget(GlobalTargetType type, GlobalUseRenderTarget* target) 
     533{ 
     534        globalTargets[type] = target;   
    518535} 
    519536 
     
    545562                                lightName + "DEPTH_SHADOW_MAP", 
    546563                                sm->getLight(lightName), 
    547                                 2048, //TODO 
    548                                 2048, //TODO 
     564                                512, //TODO 
     565                                512, //TODO 
    549566                                "GameTools/ShadowMapDepth" //TODO 
    550567                                ); 
  • GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/src/OgreRenderable.cpp

    r790 r1055  
    2929} 
    3030 
    31 OgreRenderable::OgreRenderable(BillboardSet* billboardset) 
     31OgreRenderable::OgreRenderable(BillboardSet* billboardset, ParticleSystem* sys) 
    3232{ 
    3333        renderableType = OGRE_RENDERABLETYPE_BILLBOARDSET; 
    3434        billboardSetRenderable = billboardset; 
     35        parentParticleSystem = sys; 
    3536        updateBounds(); 
    3637        name = billboardset->getName(); 
     
    4748        { 
    4849         case OGRE_RENDERABLETYPE_SUBENTITY:  
    49                  subEntityRenderable->setVisible(visible); 
     50//               subEntityRenderable->setVisible(visible); 
     51                 parentEntity->setVisible(visible); 
    5052                 break; 
    5153         case OGRE_RENDERABLETYPE_BILLBOARDSET: 
    52                  billboardSetRenderable->setVisible(visible); 
     54                 if(parentParticleSystem != 0) 
     55                         parentParticleSystem->setVisible(visible); 
     56                 else 
     57                         billboardSetRenderable->setVisible(visible); 
    5358                 break; 
    5459          default: 
  • GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/src/OgreRenderingRun.cpp

    r808 r1055  
    214214                int resolutionX = width; 
    215215                int resolutionY = height; 
    216                 pixelSprites = new SpriteSet(spriteSetName, resolutionX * resolutionY, true); 
     216                pixelSprites = new BillboardSet(spriteSetName, resolutionX * resolutionY, true); 
    217217                pixelSprites->setBillboardsInWorldSpace(true); 
    218                 pixelSprites->setCullIndividually(false);                
    219                 pixelSprites->setDefaultDimensions(1.0 / (float) resolutionX, 1.0 / resolutionY); 
     218                pixelSprites->setCullIndividually(false); 
     219                pixelSprites->setPointRenderingEnabled(true); 
     220                //pixelSprites->setDefaultDimensions(1.0 / (float) resolutionX, 1.0 / resolutionY); 
    220221                pixelSprites->beginBillboards(); 
    221222                for(int i = 0; i < resolutionX; i++) 
     
    223224                        for(int j = 0; j < resolutionY; j++) 
    224225                        {                                
    225                                 Billboard bb; 
    226  
    227                                 bb.setPosition( 
    228                                                                 ( (float)i + 0.5 )/ (float) resolutionX, //position x 
    229                                                                 ( (float)j + 0.5 )/ (float) resolutionY, //position y 
    230                                                                 0);                                                                                                     //position z                                     
     226                                Billboard bb( Vector3( 
     227                                                                                ( (float)i + 0.5 )/ (float) resolutionX, //position x 
     228                                                                                ( (float)j + 0.5 )/ (float) resolutionY, //position y 
     229                                                                                0), 
     230                                                          pixelSprites); 
     231                                bb.setDimensions(1.0 / (float) resolutionX, 1.0 / resolutionY);                          
    231232                                pixelSprites->injectBillboard(bb);                               
    232233                        } 
  • GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/src/OgreSharedRuns.cpp

    r949 r1055  
    11#include "..\include\OgreSharedRuns.h" 
    22#include "OgreIlluminationManager.h" 
     3 
     4void OgreSharedRuns::runChanged(RenderingRunType runType, RenderingRun* run) 
     5{ 
     6        if(child1 != 0) child1->runChanged(runType, run); 
     7        if(child2 != 0) child2->runChanged(runType, run); 
     8         
     9        std::vector<TechniqueGroup*>::iterator it = childTechniqueGroups.begin(); 
     10        std::vector<TechniqueGroup*>::iterator itend = childTechniqueGroups.end(); 
     11 
     12        while(it != itend) 
     13        { 
     14                (*it)->runChanged(runType, run); 
     15                it++; 
     16        } 
     17} 
     18 
     19void OgreSharedRuns::runUpdated(RenderingRunType runType, RenderingRun* run) 
     20{ 
     21        if(child1 != 0) child1->runUpdated(runType, run); 
     22        if(child2 != 0) child2->runUpdated(runType, run); 
     23         
     24 
     25        std::vector<TechniqueGroup*>::iterator it = childTechniqueGroups.begin(); 
     26        std::vector<TechniqueGroup*>::iterator itend = childTechniqueGroups.end(); 
     27 
     28        while(it != itend) 
     29        { 
     30                (*it)->runUpdated(runType, run); 
     31                it++; 
     32        } 
     33} 
    334 
    435RenderingRun* OgreSharedRuns::getRun(RenderingRunType runType) 
     
    108139        { 
    109140                runChanged( (*it).first, (*it).second ); 
    110                 runChanged( (*it).first, (*it).second ); 
    111141                it++; 
    112142        } 
     
    135165} 
    136166 
    137 bool OgreSharedRuns::haveCommonRuns(SharedRuns* r1, SharedRuns* r2) 
     167bool OgreSharedRuns::haveCommonRuns(SharedRuns* r1, SharedRuns* r2, std::vector<RenderingRunType>& commonruns) 
    138168{ 
    139169        OgreSharedRuns* run1 = (OgreSharedRuns*) r1; 
     
    143173        std::map<RenderingRunType, RenderingRun*>::iterator itend = run1->sharedRuns.end(); 
    144174 
     175        bool returnvalue = false; 
    145176        while(it != itend) 
    146177        { 
    147178                if( run2->hasOwnRun((*it).first)) 
    148                         return true; 
    149                 it++; 
    150         } 
    151  
    152         return false; 
     179                { 
     180                        if(                      run1->getRun((*it).first)->asOgreRenderingRun()-> 
     181                                canJoin( run2->getRun((*it).first)->asOgreRenderingRun() ) 
     182                           ) 
     183                        { 
     184                                returnvalue = true; 
     185                                commonruns.push_back((*it).first); 
     186                        } 
     187                } 
     188                it++; 
     189        } 
     190 
     191        return returnvalue; 
    153192} 
    154193 
    155194bool OgreSharedRuns::canJoin(SharedRuns* r1, SharedRuns* r2) 
    156195{ 
     196        std::vector<RenderingRunType> commonruns; 
    157197        //check if they have common resources 
    158         if(!haveCommonRuns(r1, r2)) 
     198        if(!haveCommonRuns(r1, r2, commonruns)) 
    159199                return false; 
    160  
     200         
     201        float MAXRAD = 0xffffffff; 
    161202        //check bounds 
    162         float MAXRAD = OgreIlluminationManager::getSingleton().getMaxJoinRadius(); 
     203        for(int i = 0; i < commonruns.size(); i++) 
     204        { 
     205          
     206         RenderingRunType type = commonruns.at(i); 
     207         float marad = OgreIlluminationManager::getSingleton().getMaxJoinRadius(type); 
     208          
     209         MAXRAD = std::min(MAXRAD, marad); 
     210        } 
    163211 
    164212        Sphere bSphere1 = ((OgreSharedRuns*) r1)->getBoundingSphere(); 
  • GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/src/RenderTechniques/OgreCausticCasterRenderTechnique.cpp

    r949 r1055  
    1515                                                                                                                                bool updateAllFace, 
    1616                                                                                                                                bool useDistance, 
     17                                                                                                                                float attenuation, 
    1718                                                                                                                                Pass* pass, 
    1819                                                                                                                                OgreRenderable* parentRenderable, 
     
    2223                                                        RenderTechnique( parentRenderable, parentTechniqueGroup) 
    2324{        
     25        this->attenuation = attenuation; 
    2426        this->photonMapMaterialName = photonMapMaterialName; 
    2527         
     
    103105                                                                                                causticMapMaterialName, 
    104106                                                                                                photonMapTexID, 
    105                                                                                                 updateAllFace 
     107                                                                                                updateAllFace, 
     108                                                                                                attenuation 
    106109                                                                                                ); 
    107110 
     
    185188                OgreCausticCasterRenderTechniqueFactory* f = (OgreCausticCasterRenderTechniqueFactory*) factory; 
    186189                f->causticMapMaterialName =  params; 
     190        } 
     191 
     192        void parseAttenuation(String& params, RenderTechniqueFactory* factory) 
     193        { 
     194                OgreCausticCasterRenderTechniqueFactory* f = (OgreCausticCasterRenderTechniqueFactory*) factory; 
     195                f->attenuation =  StringConverter::parseReal(params); 
    187196        } 
    188197} 
     
    206215        this->attributeParsers.insert(AttribParserList::value_type("distance_impostor", (ILLUM_ATTRIBUTE_PARSER) parseUseDistance)); 
    207216        this->attributeParsers.insert(AttribParserList::value_type("update_all_face", (ILLUM_ATTRIBUTE_PARSER) parseUpdateAllFace)); 
    208  
     217        this->attributeParsers.insert(AttribParserList::value_type("attenuation", (ILLUM_ATTRIBUTE_PARSER) parseAttenuation)); 
     218         
    209219} 
    210220 
     
    216226{        
    217227        //reset parameters 
     228        attenuation = 1.0; 
    218229        startFrame = 1; 
    219230        photonMapUpdateInterval = 1; 
     
    237248                                                                                                photonMapTexID, 
    238249                                                                                                updateAllFace, 
    239                                                                                                 useDistance,                                             
     250                                                                                                useDistance, 
     251                                                                                                attenuation, 
    240252                                                                                                pass, 
    241253                                                                                                parentRenderable, 
  • GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/src/RenderTechniques/OgreCausticRecieverRenderTechnique.cpp

    r949 r1055  
    106106                        Fparams->setNamedConstant("cubeMapCameraPosition", 
    107107                                causticCasters.at(i)->getRootPosition(ILLUMRUN_CAUSTIC_CUBEMAP)); 
     108                        Fparams->setNamedConstant("attenuation", cauCubeRun->getAttenuation()); 
    108109                        passes.at(i)->setActive(true); 
    109110                }        
     
    135136                f->causticFragmentProgram =  params; 
    136137        } 
     138         
    137139} 
    138140OgreCausticRecieverRenderTechniqueFactory::OgreCausticRecieverRenderTechniqueFactory() 
     
    145147        this->attributeParsers.insert(AttribParserList::value_type("vertex_program_name", (ILLUM_ATTRIBUTE_PARSER) parseVertexProgram)); 
    146148        this->attributeParsers.insert(AttribParserList::value_type("fragment_program_name", (ILLUM_ATTRIBUTE_PARSER) parseFragmentProgram)); 
     149         
    147150} 
    148151 
  • GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/src/RenderTechniques/OgreDepthShadowRecieverRenderTechnique.cpp

    r949 r1055  
    5252                TextureUnitState* st = newpass->createTextureUnitState();                
    5353                st->setTextureFiltering(TFO_BILINEAR);           
     54                st = newpass->createTextureUnitState();          
     55                st->setTextureFiltering(TFO_BILINEAR);           
    5456 
    5557                newpass->setSceneBlending(SBT_MODULATE); 
    56                 newpass->setDepthBias(5); 
     58                newpass->setDepthBias(7); 
    5759                techn->movePass(lastpass, index);                        
    5860        } 
     
    9395                                         
    9496                        passes.at(i)->getTextureUnitState(0)->setTextureName( 
    95                                 depthRun->getDepthMapTextureName()); 
     97                                depthRun->getDepthMapTextureName(0)); 
     98                        passes.at(i)->getTextureUnitState(1)->setTextureName( 
     99                                depthRun->getDepthMapTextureName(1)); 
    96100 
    97101                        //TODO: set matrices 
    98102                        GpuProgramParametersSharedPtr fpParams = passes.at(i)->getFragmentProgramParameters(); 
    99                         fpParams->setNamedConstant("lightView", depthRun->getLightViewMatrix());  
    100                         fpParams->setNamedConstant("lightViewProj", depthRun->getLightViewProjMatrix());  
     103                        fpParams->setNamedConstant("lightView", depthRun->getLightViewMatrix(0));  
     104                        fpParams->setNamedConstant("lightViewProj", depthRun->getLightViewProjMatrix(0));  
     105                        fpParams->setNamedConstant("lightView2", depthRun->getLightViewMatrix(1));  
     106                        fpParams->setNamedConstant("lightViewProj2", depthRun->getLightViewProjMatrix(1));  
    101107                         
    102108                        passes.at(i)->setActive(true); 
  • GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/src/RenderTechniques/OgreSBBRenderTechnique.cpp

    r874 r1055  
    1313{ 
    1414        this->depthTexID = depthTexID; 
    15         OgreIlluminationManager::getSingleton().createGlobalRun(ILLUMRUN_SCENE_CAMERA_DEPTH); 
    1615         
     16        OgreIlluminationManager::getSingleton().createGlobalRun(ILLUMRUN_SCENE_CAMERA_DEPTH);    
    1717         
    1818        OgreSceneCameraDepthRenderingRun* run = (OgreSceneCameraDepthRenderingRun*) 
    1919                OgreIlluminationManager::getSingleton().getGlobalRun(ILLUMRUN_SCENE_CAMERA_DEPTH)->asOgreRenderingRun(); 
     20 
     21        Root::getSingleton().addFrameListener(this); 
     22        OgreIlluminationManager::getSingleton().getMainViewport() 
     23                                                                ->getTarget()->addListener(this); 
     24        OgreIlluminationManager::getSingleton().addUpdateListener(this); 
    2025         
    2126        pass->getTextureUnitState(depthTexID)->setTextureName(run->getDepthTextureName()); 
    2227         
     28} 
     29 
     30void OgreSBBRenderTechnique::preAllUpdates() 
     31{ 
     32        lastVisibility = parentOgreRenderable->isVisible(); 
     33        parentOgreRenderable->setVisible(false); 
     34} 
     35void  OgreSBBRenderTechnique::preRenderTargetUpdate (const RenderTargetEvent &evt) 
     36{ 
     37        //parentOgreRenderable->setVisible(lastVisibility);      
     38} 
     39void  OgreSBBRenderTechnique::postRenderTargetUpdate (const RenderTargetEvent &evt) 
     40{ 
     41        //parentOgreRenderable->setVisible(false); 
     42} 
     43bool  OgreSBBRenderTechnique::frameEnded (const FrameEvent &evt) 
     44{ 
     45         
     46        return true; 
     47} 
     48void  OgreSBBRenderTechnique::postAllUpdates() 
     49{ 
     50        parentOgreRenderable->setVisible(lastVisibility);        
    2351} 
    2452 
  • GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/src/RenderingRuns/OgreCausticCubeMapRenderingRun.cpp

    r949 r1055  
    1212                                                                                                                   String materialName, 
    1313                                                                                                                   unsigned char photonMapTexId, 
    14                                                                                                                    bool updateAllFace) 
     14                                                                                                                   bool updateAllFace, 
     15                                                                                                                   float attenuation) 
    1516                :CausticCubeMapRenderingRun(startFrame, updateInterval, resolution, updateAllFace) 
    1617                , OgreRenderingRun(startFrame, updateInterval) 
    1718                , RenderingRun(startFrame, updateInterval) 
    1819{ 
     20        this->attenuation = attenuation; 
    1921        this->sharedRuns = sharedRuns; 
    2022        this->name = name; 
  • GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/src/RenderingRuns/OgreDepthShadowMapRenderingRun.cpp

    r874 r1055  
    11#include "OgreDepthShadowMapRenderingRun.h" 
     2#include "OgreIlluminationManager.h" 
    23 
    34 
     
    1516        this->light = light; 
    1617        this->sharedRuns = sharedRuns; 
    17         this->name = name;       
     18        names[0] = name + "1";   
     19        names[1] = name + "2";   
    1820        this->materialName = materialName; 
    1921 
     
    2325void OgreDepthShadowMapRenderingRun::createDepthMap() 
    2426{ 
    25         TexturePtr texPtr = Ogre::TextureManager::getSingleton().createManual(name,  
    26                                                                                                                                                 "default", 
    27                                                                                                                                                 TEX_TYPE_2D, 
    28                                                                                                                                                 resolutionX, 
    29                                                                                                                                                 resolutionY, 
    30                                                                                                                                                 0, 
    31                                                                                                                                                 0, 
    32                                                                                                                                                 PF_FLOAT16_RGBA, 
    33                                                                                                                                                 TU_RENDERTARGET); 
    34          depthMapTexture = texPtr.getPointer(); 
    35          depthMapCamera = Root::getSingleton()._getCurrentSceneManager()->createCamera(name + "_CAMERA"); 
    36          //add viewport to rendertarget 
    37          HardwarePixelBuffer* hpb = (depthMapTexture->getBuffer()).getPointer(); 
    38          RenderTarget* rt = hpb->getRenderTarget(); 
    39          Viewport* v = rt->addViewport(depthMapCamera); 
    40          v->setOverlaysEnabled(false); 
    41          rt->setAutoUpdated(false); 
     27        for(int i = 0; i < 2; i++) 
     28        { 
     29                TexturePtr texPtr = Ogre::TextureManager::getSingleton().createManual(names[i],  
     30                                                                                                                                                        "default", 
     31                                                                                                                                                        TEX_TYPE_2D, 
     32                                                                                                                                                        resolutionX, 
     33                                                                                                                                                        resolutionY, 
     34                                                                                                                                                        0, 
     35                                                                                                                                                        0, 
     36                                                                                                                                                        PF_FLOAT16_RGBA, 
     37                                                                                                                                                        TU_RENDERTARGET); 
     38                depthMapTextures[i] = texPtr.getPointer(); 
     39                depthMapCameras[i] = Root::getSingleton()._getCurrentSceneManager()->createCamera(names[i] + "_CAMERA"); 
     40                //add viewport to rendertarget 
     41                HardwarePixelBuffer* hpb = (depthMapTextures[i]->getBuffer()).getPointer(); 
     42                RenderTarget* rt = hpb->getRenderTarget(); 
     43                Viewport* v = rt->addViewport(depthMapCameras[i]); 
     44                v->setOverlaysEnabled(false); 
     45                rt->setAutoUpdated(false); 
     46        } 
    4247} 
    4348 
     
    6469void OgreDepthShadowMapRenderingRun::updateDepthMap() 
    6570{ 
    66         setMaterialForVisibles(materialName, depthMapCamera, true); 
    67          
    68         RenderTarget* rt = depthMapTexture->getBuffer().getPointer()->getRenderTarget(); 
    69          
    70         SceneManager* sm = Root::getSingleton()._getCurrentSceneManager(); 
    71          
    72         rt->update();    
    73  
    74         //rt->writeContentsToFile("shadowmap.dds"); 
    75  
     71        setMaterialForVisibles(materialName, depthMapCameras[0], true);  
     72        RenderTarget* rt = depthMapTextures[0]->getBuffer().getPointer()->getRenderTarget();     
     73        rt->update(); 
     74        //restoreMaterials(); 
     75        //rt->writeContentsToFile("shadowmap1.dds"); 
     76         
     77        //setMaterialForVisibles(materialName, depthMapCameras[1], true);        
     78        RenderTarget* rt2 = depthMapTextures[1]->getBuffer().getPointer()->getRenderTarget(); 
     79        rt2->update(); 
    7680        restoreMaterials(); 
     81        //rt2->writeContentsToFile("shadowmap2.dds"); 
     82 
     83         
     84} 
     85 
     86void setnear() 
     87{ 
     88 
    7789} 
    7890 
     
    8496                if(light->getType() == Light::LT_DIRECTIONAL) 
    8597                { 
    86                         Vector3 dir = light->getDirection(); 
    87                         depthMapCamera->setDirection( dir ); 
     98                        //Vector3 dir = light->getDirection(); 
     99                        Vector3 dir = Vector3(0,-1,-1); 
     100                        Vector3 pos; 
     101                        float size; 
     102                         
     103                        Camera* viewcam = OgreIlluminationManager::getSingleton().getMainCamera(); 
     104                         
     105                        //Matrix4 camView = viewcam->getViewMatrix(); 
     106                        //Matrix4 camViewI = camView.inverse(); 
     107                        //const AxisAlignedBox bt = viewcam->getWorldBoundingBox(true); 
     108                        //AxisAlignedBox b = bt; 
     109                        //b.transform(camView); 
     110                        //SceneManager* sm = Root::getSingleton()._getCurrentSceneManager(); 
     111                        //SceneNode* node = sm->getRootSceneNode(); 
     112                        //const AxisAlignedBox bs(-35,-5 ,-75, 35, 15, 75);// = node->_getWorldAABB(); 
     113                        //AxisAlignedBox intersection = b.intersection(bs); 
     114                        //pos = intersection.getCenter();                        
     115                        //size = (intersection.getMaximum() - pos).length(); 
     116                         
    88117                        //TODO: where to put light 
    89                         depthMapCamera->setPosition( - dir * 100000 ); 
    90                         depthMapCamera->setProjectionType(PT_ORTHOGRAPHIC);              
     118                        size = 30; 
     119                        pos = Vector3(0,0,0); 
     120                         
     121                        depthMapCameras[0]->setDirection( dir ); 
     122                        pos = pos - size * dir;                  
     123                        depthMapCameras[0]->setPosition( pos ); 
     124                        depthMapCameras[0]->setProjectionType(PT_ORTHOGRAPHIC);          
     125                        Matrix4 fproj; 
     126                        fproj = depthMapCameras[0]->getProjectionMatrix(); 
     127                        fproj = Matrix4::IDENTITY; 
     128                        fproj.setScale(Vector3(1.0/20, 1.0/25, -1.0/100)); 
     129                        //fproj.setTrans(Vector3(0,0,-50)); 
     130                        depthMapCameras[0]->setCustomProjectionMatrix(true,fproj); 
     131 
     132 
     133                        //camera2 
     134                        dir.normalise(); 
     135                        size = abs(dir.crossProduct(Vector3(0,0,1)).length() * 2); 
     136                        Vector3 viewDir = viewcam->getDirection(); 
     137                        float y = viewDir.y; 
     138                        viewDir.y = std::min(0.0f, y); 
     139                        viewDir.normalise(); 
     140                        Vector3 down(0,-1,0); 
     141                        float cosA = viewDir.dotProduct(down); 
     142                        Vector3 newDir = viewDir + down * 0.4;  
     143                        newDir.normalise(); 
     144                        pos = viewcam->getPosition(); 
     145                        size *= pos.y * 0.5 + 1; 
     146                        pos += newDir * viewcam->getPosition().y  
     147                                                                                        / newDir.dotProduct(down); 
     148                        //pos.y = 0; 
     149                         
     150                         
     151                         
     152                        depthMapCameras[1]->setDirection( dir ); 
     153                        pos = pos - 30 * dir;                    
     154                        depthMapCameras[1]->setPosition( pos ); 
     155                        depthMapCameras[1]->setProjectionType(PT_ORTHOGRAPHIC);          
     156                        Matrix4 fproj2; 
     157                        fproj2 = depthMapCameras[1]->getProjectionMatrix(); 
     158                        fproj2 = Matrix4::IDENTITY; 
     159                        fproj2.setScale(Vector3(1.0/size, 1.0/size, -1.0/100)); 
     160                        //fproj.setTrans(Vector3(0,0,-50)); 
     161                        depthMapCameras[1]->setCustomProjectionMatrix(true,fproj2); 
     162                         
     163                         
     164/*LISPSM 
     165                        Vector3 viewdir = viewcam->getDirection(); 
     166                        Vector3 lightdir = dir; 
     167 
     168                        float dotProd = viewdir.dotProduct(lightdir); 
     169                        float sinGamma; 
     170                        sinGamma = sqrt(1.0-dotProd*dotProd); 
     171                        g_fsinGamma = sinGamma; 
     172 
     173                        Vector3 newVdir = viewdir; 
     174                        Matrix4 proj;*/ 
     175 
    91176                } 
    92177                else if(light->getType() == Light::LT_SPOTLIGHT) 
    93178                { 
    94                         Vector3 dir = light->getDirection(); 
     179        /*              Vector3 dir = light->getDirection(); 
    95180                        depthMapCamera->setDirection( dir ); 
    96181                        Vector3 pos = light->getParentNode()->getWorldPosition(); 
    97182                        depthMapCamera->setPosition(pos); 
    98183                        depthMapCamera->setProjectionType(PT_PERSPECTIVE);               
    99                         depthMapCamera->setFOVy(light->getSpotlightOuterAngle()); 
     184                        depthMapCamera->setFOVy(light->getSpotlightOuterAngle());*/ 
    100185                } 
    101186                else//point light 
    102187                { 
    103                         Vector3 pos = light->getParentNode()->getWorldPosition(); 
     188        /*              Vector3 pos = light->getParentNode()->getWorldPosition(); 
    104189                        Vector3 dir = -pos; 
    105190                        depthMapCamera->setDirection( dir ); 
     
    111196         
    112197                        //OGRE_EXCEPT(0, "NOT implemented for Pointlight", "OgreDepthShadowMapRenderingRun::refreshLight"); 
    113                          
     198                */       
    114199                        /*Vector3 pos = light->getParentNode()->getWorldPosition(); 
    115200                        Vector3 dir = -pos; 
     
    123208} 
    124209 
    125 Matrix4 OgreDepthShadowMapRenderingRun::getLightViewMatrix() 
    126 { 
    127         return depthMapCamera->getViewMatrix(); 
    128 } 
    129  
    130 Matrix4 OgreDepthShadowMapRenderingRun::getLightViewProjMatrix() 
    131 { 
    132         return depthMapCamera->getProjectionMatrix() * depthMapCamera->getViewMatrix(); 
    133 } 
    134  
     210Matrix4 OgreDepthShadowMapRenderingRun::getLightViewMatrix(int i) 
     211{ 
     212        return depthMapCameras[i]->getViewMatrix(); 
     213} 
     214 
     215Matrix4 OgreDepthShadowMapRenderingRun::getLightViewProjMatrix(int i) 
     216{ 
     217        return depthMapCameras[i]->getProjectionMatrix() * depthMapCameras[i]->getViewMatrix(); 
     218} 
     219 
  • GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/src/RenderingRuns/OgrePhotonMapRenderingRun.cpp

    r949 r1055  
    103103                        Vector3 dir = light->getDirection(); 
    104104                        photonMapCamera->setDirection( dir ); 
    105                         photonMapCamera->setPosition( sharedRuns->getRootPosition(ILLUMRUN_PHOTONMAP) - dir ); 
    106                         photonMapCamera->setProjectionType(PT_ORTHOGRAPHIC);             
     105                        Real r = sharedRuns->getRootBoundingSphere(ILLUMRUN_PHOTONMAP).getRadius(); 
     106                        photonMapCamera->setPosition( sharedRuns->getRootPosition(ILLUMRUN_PHOTONMAP) - dir * r); 
     107                        photonMapCamera->setProjectionType(PT_ORTHOGRAPHIC); 
     108                        Matrix4 proj; 
     109                        proj = Matrix4::IDENTITY; 
     110                        proj.setScale(Vector3(1.0/r, 1.0/r, -1.0/r)); 
     111                        proj.setTrans(Vector3(0,0,-1)); 
     112                        photonMapCamera->setCustomProjectionMatrix(true,proj); 
    107113                } 
    108114                else 
    109                 { 
    110                         photonMapCamera->setFarClipDistance(100000); 
    111                         photonMapCamera->setNearClipDistance(0.1); 
     115                {                        
    112116                        Vector3 pos = light->getParentSceneNode()->getPosition(); 
    113117                        Vector3 dir = sharedRuns->getRootPosition(ILLUMRUN_PHOTONMAP) - pos; 
     
    125129                        photonMapCamera->setFOVy(2*alfa); 
    126130                        photonMapCamera->setDirection( dir ); 
     131 
     132                        photonMapCamera->setNearClipDistance(std::max(0.01f, d - r)); 
     133                        photonMapCamera->setFarClipDistance(r + d);      
    127134                } 
    128135        } 
  • GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/src/RenderingRuns/OgreReducedCubeMapRenderingRun.cpp

    r790 r1055  
    2727{ 
    2828        reducedCubemapTexture = createCubeRenderTexture(name,  
    29                                                                                                 sharedRuns->getRootPosition(ILLUMRUN_REDUCED_CUBEMAP), 
     29                                                                                                sharedRuns->getRootPosition(), 
    3030                                                                                                resolution, 
    3131                                                                                                PF_FLOAT16_RGBA); 
     
    4242//      mat->getTechnique(0)->getPass(0)->setFragmentProgramParameters(fpParams);  
    4343         
     44        renderFullscreenQuad("GameTools/CubeMap/Reduce", rt); 
     45         
    4446        //rt->writeContentsToFile("cubbereduce" + StringConverter::toString(facenum) + ".dds"); 
    45  
    46         renderFullscreenQuad("GameTools/CubeMap/Reduce", rt); 
    4747} 
    4848 
Note: See TracChangeset for help on using the changeset viewer.