- Timestamp:
- 07/12/06 15:44:01 (18 years ago)
- Location:
- GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/src/RenderingRuns
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
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.