- Timestamp:
- 10/17/06 09:21:50 (18 years ago)
- Location:
- GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/include/OgreIlluminationManager.h
r1425 r1628 70 70 unsigned int focusingMapSize; 71 71 unsigned int shadowMapSize; 72 bool useLISPSM; 73 bool useVSM; 74 bool blurSM; 72 75 unsigned int phaseTextureSize; 73 76 std::map<RenderingRunType,float> maxRads; … … 302 305 return FrameListener::frameStarted(evt); 303 306 } 307 308 bool getUseLISPSM(){return useLISPSM;} 309 bool getUseVSM(){return useVSM;} 310 bool getBlurShadowMap(){return blurSM;} 311 void setUseLISPSM(bool use){useLISPSM = use;} 312 void setUseVSM(bool use){useVSM = use;} 313 void setBlurShadowMap(bool use){blurSM = use;} 304 314 }; 305 315 -
GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/include/RenderingRuns/OgreDepthShadowMapRenderingRun.h
r1130 r1628 42 42 @brief returns the depth shadow map texture created by this run 43 43 */ 44 String getDepthMapTextureName(){return blurredname;} 44 String getDepthMapTextureName(); 45 45 46 /** 46 47 @brief Refreshes light camera matrices, called in each update. -
GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/src/OgreIlluminationManager.cpp
r1425 r1628 82 82 shadowMapSize = 512; 83 83 phaseTextureSize = 256; 84 useLISPSM = false; 85 useVSM = false; 86 blurSM = false; 84 87 85 88 for(int i = 0; i < RUN_TYPE_COUNT; i++) -
GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/src/RenderTechniques/OgreDepthShadowRecieverRenderTechnique.cpp
r1130 r1628 51 51 52 52 TextureUnitState* st = newpass->createTextureUnitState(); 53 st->setTextureFiltering(TFO_ANISOTROPIC); 53 st->setTextureFiltering(TFO_ANISOTROPIC); 54 st->setTextureAddressingMode(TextureUnitState::TAM_BORDER); 55 st->setTextureBorderColour(ColourValue::White); 54 56 55 57 newpass->setSceneBlending(SBT_MODULATE); … … 73 75 100000.0, 74 76 lights); 75 77 76 78 //fill passes 79 unsigned int l = 0; 77 80 for(unsigned int i = 0; i < passes.size(); i++) 78 81 { 79 if(lights.size() > i) 82 while(lights.size() != l && !lights.at(l)->getCastShadows()) 83 l++; 84 85 if(lights.size() > l) 80 86 { 81 //create run if not exists82 OgreIlluminationManager::getSingleton().createPerLightRun(lights.at(i)->getName(),83 ILLUMRUN_DEPTH_SHADOWMAP);84 //update light depth map85 OgreIlluminationManager::getSingleton().updatePerLightRun(lights.at(i)->getName(),86 ILLUMRUN_DEPTH_SHADOWMAP,87 frameNum);88 87 89 //set texture to pass 90 OgreDepthShadowMapRenderingRun* depthRun = 91 (OgreDepthShadowMapRenderingRun*) OgreIlluminationManager::getSingleton() 92 .getPerLightRun(lights.at(i)->getName(), 93 ILLUMRUN_DEPTH_SHADOWMAP)->asOgreRenderingRun(); 94 95 passes.at(i)->getTextureUnitState(0)->setTextureName( 96 depthRun->getDepthMapTextureName()); 97 98 //TODO: set matrices 99 GpuProgramParametersSharedPtr fpParams = passes.at(i)->getFragmentProgramParameters(); 100 GpuProgramParametersSharedPtr vpParams = passes.at(i)->getVertexProgramParameters(); 101 102 //fpParams->setNamedConstant("lightViewProj", depthRun->getLightViewProjMatrix()); 103 vpParams->setNamedConstant("lightViewProj", depthRun->getLightViewProjMatrix()); 88 //create run if not exists 89 OgreIlluminationManager::getSingleton().createPerLightRun(lights.at(l)->getName(), 90 ILLUMRUN_DEPTH_SHADOWMAP); 91 //update light depth map 92 OgreIlluminationManager::getSingleton().updatePerLightRun(lights.at(l)->getName(), 93 ILLUMRUN_DEPTH_SHADOWMAP, 94 frameNum); 95 96 //set texture to pass 97 OgreDepthShadowMapRenderingRun* depthRun = 98 (OgreDepthShadowMapRenderingRun*) OgreIlluminationManager::getSingleton() 99 .getPerLightRun(lights.at(l)->getName(), 100 ILLUMRUN_DEPTH_SHADOWMAP)->asOgreRenderingRun(); 101 102 passes.at(i)->getTextureUnitState(0)->setTextureName( 103 depthRun->getDepthMapTextureName()); 104 104 105 passes.at(i)->setActive(true); 105 //TODO: set matrices 106 GpuProgramParametersSharedPtr fpParams = passes.at(i)->getFragmentProgramParameters(); 107 GpuProgramParametersSharedPtr vpParams = passes.at(i)->getVertexProgramParameters(); 108 109 //fpParams->setNamedConstant("lightViewProj", depthRun->getLightViewProjMatrix()); 110 vpParams->setNamedConstant("lightViewProj", depthRun->getLightViewProjMatrix()); 111 112 passes.at(i)->setActive(true); 113 106 114 } 107 115 else -
GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/src/RenderingRuns/OgreDepthShadowMapRenderingRun.cpp
r1130 r1628 42 42 RenderTarget* rt = hpb->getRenderTarget(); 43 43 Viewport* v = rt->addViewport(depthMapCamera); 44 v->setBackgroundColour(ColourValue::White); 44 45 v->setOverlaysEnabled(false); 45 46 rt->setAutoUpdated(false); 46 47 texPtr = Ogre::TextureManager::getSingleton().createManual(blurredname, 48 "default", 49 TEX_TYPE_2D, 50 resolutionX, 51 resolutionY, 52 6, 53 0, 54 PF_FLOAT16_RGBA, 55 TU_RENDERTARGET); 56 blurredDepthMapTexture = texPtr.getPointer(); 57 hpb = (blurredDepthMapTexture->getBuffer()).getPointer(); 58 rt = hpb->getRenderTarget(); 59 v = rt->addViewport(depthMapCamera); 60 v->setOverlaysEnabled(false); 61 rt->setAutoUpdated(false); 47 48 if(OgreIlluminationManager::getSingleton().getBlurShadowMap()) 49 { 50 texPtr = Ogre::TextureManager::getSingleton().createManual(blurredname, 51 "default", 52 TEX_TYPE_2D, 53 resolutionX, 54 resolutionY, 55 6, 56 0, 57 PF_FLOAT16_RGBA, 58 TU_RENDERTARGET); 59 blurredDepthMapTexture = texPtr.getPointer(); 60 hpb = (blurredDepthMapTexture->getBuffer()).getPointer(); 61 rt = hpb->getRenderTarget(); 62 v = rt->addViewport(depthMapCamera); 63 v->setOverlaysEnabled(false); 64 rt->setAutoUpdated(false); 65 } 62 66 } 63 67 … … 88 92 rt->update(); 89 93 restoreMaterials(); 90 91 rt = blurredDepthMapTexture->getBuffer().getPointer()->getRenderTarget(); 92 Material* mat = (Material*) MaterialManager::getSingleton().getByName("GameTools/Blur").getPointer(); 93 mat->getTechnique(0)->getPass(0)->getTextureUnitState(0)->setTextureName(depthMapTexture->getName()); 94 renderFullscreenQuad("GameTools/Blur", rt); 95 94 95 if(OgreIlluminationManager::getSingleton().getBlurShadowMap()) 96 { 97 rt = blurredDepthMapTexture->getBuffer().getPointer()->getRenderTarget(); 98 Material* mat = (Material*) MaterialManager::getSingleton().getByName("GameTools/Blur").getPointer(); 99 mat->getTechnique(0)->getPass(0)->getTextureUnitState(0)->setTextureName(depthMapTexture->getName()); 100 renderFullscreenQuad("GameTools/Blur", rt); 101 } 96 102 97 103 //rt->writeContentsToFile("shadowmap1.dds"); … … 99 105 //depthMapTexture->(); 100 106 } 101 102 void setnear() 103 { 104 107 String OgreDepthShadowMapRenderingRun::getDepthMapTextureName() 108 { 109 if(OgreIlluminationManager::getSingleton().getBlurShadowMap()) 110 return blurredname; 111 112 return name; 105 113 } 106 114 … … 110 118 if(light!= 0) 111 119 { 120 bool uselispsm = OgreIlluminationManager::getSingleton().getUseLISPSM(); 112 121 if(light->getType() == Light::LT_DIRECTIONAL) 113 122 { … … 118 127 frun->setCameraMatrices(viewcam->getViewMatrix(), viewcam->getProjectionMatrix()); 119 128 120 Vector3 lightpos = light->getP osition();129 Vector3 lightpos = light->getParentSceneNode()->getWorldPosition(); 121 130 Vector3 lightdir = light->getDirection(); 122 131 lightdir.normalise(); … … 125 134 Vector3 max; 126 135 127 bool uselispsm = true;136 128 137 if(uselispsm) 129 138 { … … 138 147 139 148 Vector3 left = lightdir.crossProduct(viewdir); 149 left.normalise(); 140 150 Vector3 up = left.crossProduct(lightdir); 141 151 up.normalise(); … … 167 177 Matrix4 newViewMatrix( left.x, left.y, left.z, -left.dotProduct(pos), 168 178 up.x, up.y, up.z, -up.dotProduct(pos), 169 lightdir.x, lightdir.y, lightdir.z, -lightdir.dotProduct(pos),179 -lightdir.x, -lightdir.y, -lightdir.z, lightdir.dotProduct(pos), 170 180 0, 0, 0, 1); 171 181 … … 200 210 Vector3 scale = (max - min); 201 211 scale *= 1.5; // just for safety 202 scale.z = 200; //TODO: get scene bounding box to set z scale 212 if(uselispsm) 213 scale.z += 1; 214 else 215 scale.z += 1000; //TODO: get scene bounding box to set z scale 203 216 Matrix4 projection = Matrix4::IDENTITY; 204 projection.setScale(Vector3(2.0 / scale.x, 2.0 / scale.y, -2.0 / scale.z)); 205 projection.setTrans(Vector3(-(max.x + min.x) / scale.x, 206 -(max.y + min.y) / scale.y, 207 -(max.z + min.z) / scale.z)); 217 Matrix4 trans = Matrix4::IDENTITY; 218 trans.setTrans(Vector3(-(max.x + min.x) / 2.0, 219 -(max.y + min.y) / 2.0, 220 -(max.z + min.z) / 2.0)); 221 Matrix4 scaleM = Matrix4::IDENTITY; 222 scaleM.setScale(Vector3(2.0 / scale.x, 2.0 / scale.y, -2.0 / scale.z)); 223 projection = scaleM * trans; 208 224 depthMapCamera->setCustomProjectionMatrix(true, projection); 209 225 } 210 226 else if(light->getType() == Light::LT_SPOTLIGHT) 211 227 { 212 /* Vector3 dir = light->getDirection(); 213 depthMapCamera->setDirection( dir ); 214 Vector3 pos = light->getParentNode()->getWorldPosition(); 215 depthMapCamera->setPosition(pos); 216 depthMapCamera->setProjectionType(PT_PERSPECTIVE); 217 depthMapCamera->setFOVy(light->getSpotlightOuterAngle());*/ 228 Camera* viewcam = OgreIlluminationManager::getSingleton().getMainCamera(); 229 230 OgreFocusingMapRenderingRun* frun = (OgreFocusingMapRenderingRun*) 231 OgreIlluminationManager::getSingleton().getGlobalRun(ILLUMRUN_FOCUSING_MAP)->asOgreRenderingRun(); 232 frun->setCameraMatrices(viewcam->getViewMatrix(), viewcam->getProjectionMatrix()); 233 234 Vector3 lightpos = light->getParentSceneNode()->getWorldPosition (); 235 Vector3 lightdir = light->getDirection(); 236 lightdir.normalise(); 237 Radian lightangle = light->getSpotlightOuterAngle(); 238 239 Vector3 min; 240 Vector3 max; 241 242 if(uselispsm) 243 { 244 Camera* maincam = OgreIlluminationManager::getSingleton().getMainCamera(); 245 Vector3 viewdir = maincam->getDirection(); 246 viewdir.normalise(); 247 Vector3 campos = maincam->getPosition(); 248 float nearclip = maincam->getNearClipDistance(); 249 250 float dotprod = viewdir.dotProduct(lightdir); 251 float sinGamma = sqrt(1.0 - dotprod * dotprod); 252 253 Vector3 left = lightdir.crossProduct(viewdir); 254 Vector3 up = left.crossProduct(lightdir); 255 up.normalise(); 256 //left = lightdir.crossProduct(up); 257 left.normalise(); 258 259 depthMapCamera->setCustomProjectionMatrix(false); 260 depthMapCamera->setProjectionType(PT_PERSPECTIVE); 261 depthMapCamera->setFOVy(lightangle); 262 depthMapCamera->setAspectRatio(1); 263 depthMapCamera->setNearClipDistance(0.1); 264 depthMapCamera->setFarClipDistance(1.0); 265 266 Matrix4 projMatrix = depthMapCamera->getProjectionMatrixWithRSDepth(); 267 268 Matrix4 viewMatrix( left.x, left.y, left.z, 0, 269 up.x, up.y, up.z, 0, 270 -lightdir.x, -lightdir.y, -lightdir.z, 0, 271 0, 0, 0, 1); 272 273 frun->setLightMatrix(projMatrix * viewMatrix); 274 OgreIlluminationManager::getSingleton().updateGlobalRun( ILLUMRUN_FOCUSING_MAP, 275 frameNum); 276 frun->getMinMax(min, max); 277 278 float n; 279 float f; 280 float d = abs(max.y - min.y); 281 282 float z_n = nearclip / sinGamma; 283 float one_min_singamma = (1 - sinGamma); 284 float fact = d * pow(one_min_singamma, 2); 285 float z_f = z_n + d * sinGamma * fact; 286 n = (z_n + sqrt(z_f * z_n)) / sinGamma; 287 ///n = 100000; 288 f = n + d; 289 290 Vector3 pos = campos - up * (n - nearclip); 291 Matrix4 newViewMatrix( left.x, left.y, left.z, -left.dotProduct(pos), 292 up.x, up.y, up.z, -up.dotProduct(pos), 293 -lightdir.x, -lightdir.y, -lightdir.z, lightdir.dotProduct(pos), 294 0, 0, 0, 1); 295 296 Matrix4 lispMat = Matrix4::IDENTITY; 297 298 lispMat[1][1] = f / (f - n); 299 lispMat[1][3] = f * n / (f - n); 300 lispMat[3][1] = 1; 301 lispMat[3][3] = 0; 302 303 depthMapCamera->setCustomProjectionMatrix(true, Matrix4::IDENTITY); 304 depthMapCamera->setCustomViewMatrix(true, lispMat * projMatrix * newViewMatrix); 305 } 306 else 307 { 308 depthMapCamera->setCustomProjectionMatrix(false); 309 depthMapCamera->setCustomViewMatrix(false); 310 depthMapCamera->setPosition(lightpos); 311 depthMapCamera->setDirection(lightdir); 312 depthMapCamera->setProjectionType(PT_PERSPECTIVE); 313 depthMapCamera->setFOVy(lightangle); 314 depthMapCamera->setAspectRatio(1); 315 depthMapCamera->setNearClipDistance(0.1); 316 depthMapCamera->setFarClipDistance(1.0); 317 } 318 319 320 Matrix4 lightMatrix = depthMapCamera->getViewMatrix(); 321 frun->setLightMatrix(lightMatrix); 322 323 OgreIlluminationManager::getSingleton().updateGlobalRun( ILLUMRUN_FOCUSING_MAP, 324 frameNum); 325 326 frun->getMinMax(min, max); 327 328 if(min.z < 0) 329 { 330 float farP= -1.5 * min.z; 331 if(farP < 0.2) farP = 0.2; 332 depthMapCamera->setFarClipDistance(farP); 333 334 Vector3 scale = (max - min); 335 scale *= 1.5; // just for safety 336 337 Matrix4 projection = Matrix4::IDENTITY; 338 Matrix4 trans = Matrix4::IDENTITY; 339 trans.setTrans(Vector3(-(max.x + min.x) / 2.0, 340 -(max.y + min.y) / 2.0, 341 0)); 342 Matrix4 scaleM = Matrix4::IDENTITY; 343 scaleM.setScale(Vector3(2.0 / scale.x, 2.0 / scale.y, 1)); 344 projection = scaleM * trans; 345 depthMapCamera->setCustomProjectionMatrix(true, projection * depthMapCamera->getProjectionMatrix()); 346 } 218 347 } 219 348 else//point light -
GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/src/RenderingRuns/OgrePhotonMapRenderingRun.cpp
r1055 r1628 108 108 Matrix4 proj; 109 109 proj = Matrix4::IDENTITY; 110 proj.setScale(Vector3(1.0/r, 1.0/r, -1. 0/r));111 proj.setTrans(Vector3(0,0,-1));110 proj.setScale(Vector3(1.0/r, 1.0/r, -1.5/r)); 111 //proj.setTrans(Vector3(0,0,-1)); 112 112 photonMapCamera->setCustomProjectionMatrix(true,proj); 113 113 }
Note: See TracChangeset
for help on using the changeset viewer.