Ignore:
Timestamp:
06/26/06 09:52:08 (18 years ago)
Author:
szirmay
Message:
 
File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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 
Note: See TracChangeset for help on using the changeset viewer.