Changeset 1125 for GTP/trunk/Lib/Illum
- Timestamp:
- 07/12/06 15:44:01 (18 years ago)
- Location:
- GTP/trunk/Lib/Illum/IllumModule
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/Lib/Illum/IllumModule/IllumModule/include/RenderingRun.h
r949 r1125 52 52 @param frameNum current frame number 53 53 */ 54 bool needUpdate(unsigned long frameNum )54 virtual bool needUpdate(unsigned long frameNum ) 55 55 { 56 56 if(frameNum == lastupdated ) -
GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/include/RenderingRuns/OgreFocusingMapRenderingRun.h
r1103 r1125 22 22 @brief Constructor. 23 23 24 @param sharedRuns a pointer to the OgreSharedRuns this run belongs to 25 @param name the name of the scene depth texture to be created 26 @param playerView pointer to the player's viewport 24 27 25 */ 28 26 OgreFocusingMapRenderingRun(String name, 29 Viewport* playerView,30 27 Matrix4 lightMatrix, 31 28 unsigned int focusingMapSize); … … 36 33 void getMinMax(Vector3& min, Vector3& max); 37 34 void setLightMatrix(Matrix4 &m){this->lightMatrix = m;} 35 void setCameraMatrices(const Matrix4 &view, const Matrix4 &projection); 38 36 39 37 protected: … … 41 39 @brief pointer to the player's viewport 42 40 */ 43 Viewport* playerView;44 41 Matrix4 lightMatrix; 45 42 /** 46 43 @brief pointer to the player's camera 47 44 */ 48 Camera* playerCamera;45 Camera* camera; 49 46 50 47 /** … … 63 60 inline void createFocusingMap(); 64 61 62 bool needUpdate(unsigned long frameNum ) 63 { 64 return true; 65 } 66 65 67 }; -
GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/scripts/OgreIllumModule.vcproj
r1103 r1125 342 342 </File> 343 343 <File 344 RelativePath="..\..\..\..\..\App\Demos\Illum\Ogre\Media\materials\programs\GameTools_Focusing.hlsl"> 345 </File> 346 <File 344 347 RelativePath="..\..\..\..\..\App\Demos\Illum\Ogre\Media\materials\programs\GameTools_Localized_EnvMap.hlsl"> 345 348 </File> -
GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/src/OgreIlluminationManager.cpp
r1103 r1125 512 512 globalSharedRuns.addRun(ILLUMRUN_SCENE_CAMERA_DEPTH, run); 513 513 } 514 case ILLUMRUN_FOCUSING_MAP: 515 if(globalSharedRuns.getRun(ILLUMRUN_FOCUSING_MAP) == 0) 516 { 517 OgreFocusingMapRenderingRun* run = new OgreFocusingMapRenderingRun( 518 "LIGHT_FOCUSING_MAP", 519 Matrix4::IDENTITY, 520 focusingMapSize 521 ); 522 globalSharedRuns.addRun(ILLUMRUN_FOCUSING_MAP, run); 523 524 } 514 525 break; 515 526 } … … 520 531 RenderingRun* OgreIlluminationManager::getGlobalRun(RenderingRunType runType) 521 532 { 533 if(globalSharedRuns.getRun(runType) == 0) 534 createGlobalRun(runType); 522 535 return globalSharedRuns.getRun(runType); 523 536 } … … 565 578 lightName + "DEPTH_SHADOW_MAP", 566 579 sm->getLight(lightName), 567 512, //TODO568 512, //TODO580 128, //TODO 581 128, //TODO 569 582 "GameTools/ShadowMapDepth" //TODO 570 583 ); 571 584 runs->addRun(ILLUMRUN_DEPTH_SHADOWMAP, run); 572 585 573 } 574 case ILLUMRUN_FOCUSING_MAP: 575 if(runs->getRun(ILLUMRUN_FOCUSING_MAP) == 0) 576 { 577 SceneManager* sm = Root::getSingleton()._getCurrentSceneManager(); 578 Light* light = sm->getLight(lightName); 579 Vector3 position = light->getPosition(); 580 Vector3 direction = light->getDirection(); 581 Matrix4 transMatrix; 582 Camera cam("tempCamera", sm); 583 cam.setPosition(position); 584 cam.setDirection(direction); 585 transMatrix = cam.getViewMatrix(); 586 587 if(light->getType() == Light::LT_SPOTLIGHT) 588 { 589 Radian fov = light->getSpotlightOuterAngle(); 590 float far = light->getAttenuationRange(); 591 cam.setNearClipDistance(0.1); 592 cam.setFarClipDistance(far); 593 cam.setFOVy(fov); 594 Matrix4 proj = cam.getProjectionMatrix(); 595 transMatrix = transMatrix * proj; 596 } 597 sm->destroyCamera("tempCamera"); 598 599 OgreFocusingMapRenderingRun* run = new OgreFocusingMapRenderingRun( 600 lightName + "FOCUSING_MAP", 601 mainViewport, 602 transMatrix, 603 focusingMapSize 604 ); 605 runs->addRun(ILLUMRUN_FOCUSING_MAP, run); 606 607 } 586 } 608 587 break; 609 588 } -
GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/src/RenderingRuns/OgreDepthShadowMapRenderingRun.cpp
r1120 r1125 73 73 rt->update(); 74 74 restoreMaterials(); 75 //rt->writeContentsToFile("shadowmap1.dds");75 rt->writeContentsToFile("shadowmap1.dds"); 76 76 } 77 77 … … 88 88 if(light->getType() == Light::LT_DIRECTIONAL) 89 89 { 90 Camera* viewcam = OgreIlluminationManager::getSingleton().getMainCamera(); 91 92 OgreIlluminationManager::getSingleton().updatePerLightRun(light->getName(), 93 ILLUMRUN_FOCUSING_MAP, 94 frameNum); 95 90 Camera* viewcam = OgreIlluminationManager::getSingleton().getMainCamera(); 91 96 92 OgreFocusingMapRenderingRun* frun = (OgreFocusingMapRenderingRun*) 97 OgreIlluminationManager::getSingleton().getPerLightRun(light->getName(), ILLUMRUN_FOCUSING_MAP)->asOgreRenderingRun(); 98 99 Vector3 min; 100 Vector3 max; 101 frun->getMinMax(min, max); 93 OgreIlluminationManager::getSingleton().getGlobalRun(ILLUMRUN_FOCUSING_MAP)->asOgreRenderingRun(); 94 frun->setCameraMatrices(viewcam->getViewMatrix(), viewcam->getProjectionMatrix()); 102 95 103 96 Vector3 lightpos = light->getPosition(); 104 97 Vector3 lightdir = light->getDirection(); 105 lightdir.normalise(); 106 107 depthMapCamera->setProjectionType(PT_ORTHOGRAPHIC); 108 /*depthMapCameras[0]->setAspectRatio(1.0); 109 depthMapCameras[0]->setFOVy(Radian(Degree(20))); 110 depthMapCameras[0]->setNearClipDistance(0.1); 111 depthMapCameras[0]->setFarClipDistance(200);*/ 112 113 98 lightdir.normalise(); 99 100 Vector3 min; 101 Vector3 max; 102 103 bool uselispsm = true; 104 if(uselispsm) 105 { 106 Camera* maincam = OgreIlluminationManager::getSingleton().getMainCamera(); 107 Vector3 viewdir = maincam->getDirection(); 108 viewdir.normalise(); 109 Vector3 campos = maincam->getPosition(); 110 float nearclip = maincam->getNearClipDistance(); 111 112 float dotprod = viewdir.dotProduct(lightdir); 113 float sinGamma = sqrt(1.0 - dotprod * dotprod); 114 115 Vector3 left = lightdir.crossProduct(viewdir); 116 Vector3 up = left.crossProduct(lightdir); 117 up.normalise(); 118 //left = lightdir.crossProduct(up); 119 left.normalise(); 120 121 Matrix4 viewMatrix( left.x, left.y, left.z, 0, 122 up.x, up.y, up.z, 0, 123 lightdir.x, lightdir.y, lightdir.z, 0, 124 0, 0, 0, 1); 125 126 frun->setLightMatrix(viewMatrix); 127 OgreIlluminationManager::getSingleton().updateGlobalRun( ILLUMRUN_FOCUSING_MAP, 128 frameNum); 129 frun->getMinMax(min, max); 130 131 float n; 132 float f; 133 float d = abs(max.y - min.y); 134 135 float z_n = nearclip / sinGamma; 136 float one_min_singamma = (1 - sinGamma); 137 float fact = d * pow(one_min_singamma, 2); 138 float z_f = z_n + d * sinGamma * fact; 139 n = (z_n + sqrt(z_f * z_n)) / sinGamma; 140 ///n = 100000; 141 f = n + d; 142 143 Vector3 pos = campos - up * (n - nearclip); 144 145 Matrix4 newViewMatrix( left.x, left.y, left.z, -left.dotProduct(pos), 146 up.x, up.y, up.z, -up.dotProduct(pos), 147 lightdir.x, lightdir.y, lightdir.z, -lightdir.dotProduct(pos), 148 0, 0, 0, 1); 149 150 151 Matrix4 newProjection = Matrix4::IDENTITY; 152 153 newProjection[1][1] = (f + n) / (f - n); 154 newProjection[1][3] = - 2* f * n / (f - n); 155 newProjection[3][1] = 1; 156 newProjection[3][3] = 0; 157 //newProjection = newProjection.transpose(); 158 Matrix4 standardProjMatrix = Matrix4::IDENTITY; 159 standardProjMatrix.setScale(Vector3(1,1,-1)); 160 newProjection = newProjection * standardProjMatrix; 161 depthMapCamera->setCustomProjectionMatrix(true, newProjection); 162 depthMapCamera->setCustomViewMatrix(true, viewMatrix); 163 } 164 else 165 { 166 Matrix4 standardProjMatrix = Matrix4::IDENTITY; 167 standardProjMatrix.setScale(Vector3(0,0,-1)); 168 depthMapCamera->setCustomProjectionMatrix(true, standardProjMatrix); 169 depthMapCamera->setCustomViewMatrix(false); 170 depthMapCamera->setProjectionType(PT_ORTHOGRAPHIC); 171 depthMapCamera->setPosition(lightpos); 172 depthMapCamera->setDirection(lightdir); 173 } 174 175 176 Matrix4 lightMatrix = depthMapCamera->getProjectionMatrix() * depthMapCamera->getViewMatrix(); 177 frun->setLightMatrix(lightMatrix); 178 179 OgreIlluminationManager::getSingleton().updateGlobalRun( ILLUMRUN_FOCUSING_MAP, 180 frameNum); 181 182 frun->getMinMax(min, max); 183 184 114 185 Vector3 scale = (max - min); 115 scale *= 1.5; 116 //scale = Vector3(150,150,150); 117 Matrix4 projection = depthMapCamera->getProjectionMatrix(); 118 projection = Matrix4::IDENTITY; 186 scale *= 1.5; // just for safety 187 scale.z = 200; //TODO: get scene bounding box to set z scale 188 Matrix4 projection = Matrix4::IDENTITY; 119 189 projection.setScale(Vector3(2.0 / scale.x, 2.0 / scale.y, -2.0 / scale.z)); 120 190 projection.setTrans(Vector3(-(max.x + min.x) / scale.x, 121 191 -(max.y + min.y) / scale.y, 122 192 -(max.z + min.z) / scale.z)); 193 projection = projection * depthMapCamera->getProjectionMatrix(); 123 194 depthMapCamera->setCustomProjectionMatrix(true, projection); 124 195 125 depthMapCamera->setPosition(lightpos); 126 depthMapCamera->setDirection(lightdir); 127 128 /* 129 projection = Matrix4::IDENTITY; 130 projection.setScale(Vector3(1.0 / 100.0, 1.0 / 100.0, -1.0 / 100.0)); 131 depthMapCameras[0]->setCustomProjectionMatrix(true, projection); 132 depthMapCameras[0]->setPosition( Vector3(50,50,50) );*/ 133 196 197 134 198 } 135 199 else if(light->getType() == Light::LT_SPOTLIGHT) -
GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/src/RenderingRuns/OgreFocusingMapRenderingRun.cpp
r1103 r1125 58 58 59 59 OgreFocusingMapRenderingRun::OgreFocusingMapRenderingRun( String name, 60 Viewport* playerView,61 60 Matrix4 lightMatrix, 62 61 unsigned int focusingMapSize … … 66 65 { 67 66 this->name = name; 68 this->playerView = playerView;69 67 this->lightMatrix = lightMatrix; 70 this->focusingMapSize = focusingMapSize; 68 this->focusingMapSize = focusingMapSize; 71 69 72 createFocusingMap(); 73 74 70 createFocusingMap(); 75 71 } 76 72 77 73 void OgreFocusingMapRenderingRun::setCameraMatrices(const Matrix4 &view, const Matrix4 &projection) 74 { 75 camera->setCustomViewMatrix(true, view); 76 camera->setCustomProjectionMatrix(true, projection); 77 } 78 78 79 79 void OgreFocusingMapRenderingRun::createFocusingMap() … … 91 91 TU_RENDERTARGET); 92 92 focusingTexture = texPtr.getPointer(); 93 playerCamera = playerView->getCamera();94 93 //add viewport to rendertarget 95 94 HardwarePixelBuffer* hpb = (focusingTexture->getBuffer()).getPointer(); 96 95 RenderTarget* rt = hpb->getRenderTarget(); 97 Viewport* v = rt->addViewport(playerCamera); 96 this->camera = Root::getSingleton()._getCurrentSceneManager()->createCamera(name + "_CAMERA"); 97 Viewport* v = rt->addViewport(camera); 98 98 v->setOverlaysEnabled(false); 99 99 rt->setAutoUpdated(false); … … 110 110 Vparams->setNamedConstant("lightTransform", lightMatrix); 111 111 112 setMaterialForVisibles(String("GameTools/FocusingShader"), playerCamera);112 setMaterialForVisibles(String("GameTools/FocusingShader"), camera); 113 113 114 114 RenderTarget* rt = focusingTexture->getBuffer().getPointer()->getRenderTarget();
Note: See TracChangeset
for help on using the changeset viewer.