- Timestamp:
- 07/07/06 17:01:43 (18 years ago)
- Location:
- GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/src/RenderingRuns
- Files:
-
- 1 added
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/src/RenderingRuns/OgreDepthShadowMapRenderingRun.cpp
r1055 r1103 25 25 void OgreDepthShadowMapRenderingRun::createDepthMap() 26 26 { 27 for(int i = 0; i < 2; i++)27 for(int i = 0; i < 1; i++) 28 28 { 29 29 TexturePtr texPtr = Ogre::TextureManager::getSingleton().createManual(names[i], … … 49 49 void OgreDepthShadowMapRenderingRun::updateFrame(unsigned long frameNum) 50 50 { 51 refreshLight( );51 refreshLight(frameNum); 52 52 53 53 if(light->getType() == Light::LT_POINT) … … 69 69 void OgreDepthShadowMapRenderingRun::updateDepthMap() 70 70 { 71 setMaterialForVisibles(materialName, depthMapCameras[0], true);71 setMaterialForVisibles(materialName, depthMapCameras[0], false); 72 72 RenderTarget* rt = depthMapTextures[0]->getBuffer().getPointer()->getRenderTarget(); 73 73 rt->update(); 74 //restoreMaterials();74 restoreMaterials(); 75 75 //rt->writeContentsToFile("shadowmap1.dds"); 76 77 //setMaterialForVisibles(materialName, depthMapCameras[1], true);78 RenderTarget* rt2 = depthMapTextures[1]->getBuffer().getPointer()->getRenderTarget();79 rt2->update();80 restoreMaterials();81 //rt2->writeContentsToFile("shadowmap2.dds");82 83 84 76 } 85 77 … … 89 81 } 90 82 91 void OgreDepthShadowMapRenderingRun::refreshLight( )83 void OgreDepthShadowMapRenderingRun::refreshLight(unsigned long frameNum) 92 84 { 93 85 … … 96 88 if(light->getType() == Light::LT_DIRECTIONAL) 97 89 { 98 //Vector3 dir = light->getDirection();99 Vector3 dir = Vector3(0,-1,-1);100 Vector3 pos;101 float size;102 103 90 Camera* viewcam = OgreIlluminationManager::getSingleton().getMainCamera(); 104 91 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(); 92 OgreIlluminationManager::getSingleton().updatePerLightRun(light->getName(), 93 ILLUMRUN_FOCUSING_MAP, 94 frameNum); 95 96 OgreFocusingMapRenderingRun* frun = (OgreFocusingMapRenderingRun*) 97 OgreIlluminationManager::getSingleton().getPerLightRun(light->getName(), ILLUMRUN_FOCUSING_MAP)->asOgreRenderingRun(); 116 98 117 //TODO: where to put light 118 size = 30; 119 pos = Vector3(0,0,0); 99 Vector3 min; 100 Vector3 max; 101 frun->getMinMax(min, max); 102 103 Vector3 lightpos = light->getPosition(); 104 Vector3 lightdir = light->getDirection(); 120 105 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); 106 Vector3 center = (min + max) / 2.0; 107 Vector3 scale = max - min; 108 scale.x = 2.0 / scale.x; 109 scale.y = 2.0 / scale.y; 110 scale.z = 2.0 / scale.z; 111 center.x *= scale.x; 112 center.y *= scale.y; 113 center.z *= scale.z; 131 114 132 115 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; 116 depthMapCameras[0]->setDirection( lightdir ); 117 depthMapCameras[0]->setPosition( lightpos ); 167 118 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;*/ 119 Matrix4 projection = Matrix4::IDENTITY; 120 projection.setTrans(center); 121 projection.setScale(scale); 122 depthMapCameras[0]->setCustomProjectionMatrix(true, projection); 123 /* 124 projection = Matrix4::IDENTITY; 125 projection.setScale(Vector3(1.0 / 100.0, 1.0 / 100.0, -1.0 / 100.0)); 126 depthMapCameras[0]->setCustomProjectionMatrix(true, projection); 127 depthMapCameras[0]->setPosition( Vector3(50,50,50) );*/ 175 128 176 129 }
Note: See TracChangeset
for help on using the changeset viewer.