Changeset 2924 for GTP/trunk/App/Demos
- Timestamp:
- 09/09/08 21:01:13 (16 years ago)
- Location:
- GTP/trunk/App/Demos/Vis/FriendlyCulling/src
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Matrix4x4.cpp
r2920 r2924 717 717 { 718 718 const Vector3 nDir = Normalize(dir); 719 720 719 Vector3 nUp = Normalize(up); 721 720 … … 723 722 nUp = Normalize(CrossProd(nRight, nDir)); 724 723 725 Matrix4x4 m; 726 Matrix4x4(nRight, nUp, -nDir); 724 Matrix4x4 m(nRight, nUp, -nDir); 727 725 728 726 m.x[3][0] = -DotProd(nRight, pos); -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ShadowMapping.cpp
r2923 r2924 85 85 86 86 87 static AxisAlignedBox3 GetExtremalPoints(const Matrix4x4 &m, 88 const VertexArray &pts) 89 { 90 AxisAlignedBox3 extremalPoints; 91 extremalPoints.Initialize(); 92 93 VertexArray::const_iterator it, it_end = pts.end(); 94 95 for (it = pts.begin(); it != it_end; ++ it) 96 { 97 Vector3 pt = *it; 98 pt = m * pt; 99 100 extremalPoints.Include(pt); 101 } 102 103 return extremalPoints; 104 } 105 106 87 107 ShadowMap::ShadowMap(Light *light, int size, const AxisAlignedBox3 &sceneBox, Camera *cam): 88 108 mSceneBox(sceneBox), mSize(size), mCamera(cam), mLight(light) … … 179 199 180 200 181 Matrix4x4 ShadowMap::CalcLispSMTransform(const Matrix4x4 &light ProjView,201 Matrix4x4 ShadowMap::CalcLispSMTransform(const Matrix4x4 &lightSpace, 182 202 const AxisAlignedBox3 &extremalPoints, 183 const VertexArray & pts203 const VertexArray &body 184 204 ) 185 205 { 186 Matrix4x4 matLispSM; 206 AxisAlignedBox3 bounds_ls = GetExtremalPoints(lightSpace, body); 207 //return IdentityMatrix(); 187 208 188 209 /////////////// 189 210 //-- We apply the lispsm algorithm in order to calculate an optimal light projection matrix 190 211 191 const float n = ComputeN(extremalPoints); 212 213 //////// 214 //-- first find the free parameter values n, and P (the projection center), and the projection depth 215 216 const float n = 1e6;//ComputeN(bounds_ls); 192 217 193 218 cout << "n: " << n << endl; 194 219 195 const Vector3 nearPt = GetNearCameraPointE( pts);196 220 const Vector3 nearPt = GetNearCameraPointE(body); 221 const float dummy = 0; 197 222 //get the coordinates of the near camera point in light space 198 const Vector3 lsNear = light ProjView* nearPt;223 const Vector3 lsNear = lightSpace * nearPt; 199 224 200 225 //c start has the x and y coordinate of e, the z coord of the near plane of the light volume 201 const Vector3 startPt = Vector3(lsNear.x, lsNear.y, extremalPoints.Max().z);202 203 cout << "mx: " << extremalPoints.Max() << endl;204 cout << "mn: " << extremalPoints.Min() << endl;226 const Vector3 startPt = Vector3(lsNear.x, lsNear.y, bounds_ls.Max().z); 227 228 cout << "mx: " << bounds_ls.Max() << endl; 229 cout << "mn: " << bounds_ls.Min() << endl; 205 230 206 231 // the new projection center 207 232 Vector3 projCenter = startPt + Vector3::UNIT_Z() * n; 208 233 209 cout <<"start: " << startPt << " " << projCenter << endl;234 cout <<"start: " << startPt << " " << projCenter << " " << Distance(lightSpace * mCamera->GetPosition(), startPt) << endl; 210 235 211 236 //construct a translation that moves to the projection center … … 213 238 214 239 // light space y size 215 const float d = fabs( extremalPoints.Max()[2] - extremalPoints.Min()[2]);216 217 const float dy = fabs( extremalPoints.Max()[1] - extremalPoints.Min()[1]);218 const float dx = fabs( extremalPoints.Max()[0] - extremalPoints.Min()[0]);240 const float d = fabs(bounds_ls.Max()[2] - bounds_ls.Min()[2])+dummy; 241 242 const float dy = fabs(bounds_ls.Max()[1] - bounds_ls.Min()[1]); 243 const float dx = fabs(bounds_ls.Max()[0] - bounds_ls.Min()[0]); 219 244 220 245 cout << "d: " << d << " dy: " << dy << " dx: " << dx << endl; 221 246 222 matLispSM = GetFrustum(-1.0, 1.0, -1.0, 1.0, n, n + d); 247 248 249 //////// 250 //-- now apply these values to construct the perspective lispsm matrix 251 252 Matrix4x4 matLispSM; 253 254 matLispSM = GetFrustum(-1.0, 1.0, -1.0, 1.0, n+dummy, n + d); 223 255 224 256 //cout << "lispsm\n" << matLispSM << endl; 225 257 258 // translate to the projection center 226 259 matLispSM = projectionCenter * matLispSM; 227 260 228 cout << "center\n" << projectionCenter << endl;229 261 //cout << "new\n" << matLispSM << endl; 230 262 … … 232 264 Matrix4x4 refl = ScaleMatrix(1.0f, 1.0f, -1.0f); 233 265 matLispSM *= refl; 234 matLispSM = IdentityMatrix(); 235 266 236 267 return matLispSM; 237 268 } … … 243 274 float minDist = 1e25f; 244 275 245 Vector3 camPos = mCamera->GetPosition();276 const Vector3 camPos = mCamera->GetPosition(); 246 277 247 278 /*Matrix4x4 inverseCamView; … … 281 312 Vector3 projDir(b_lp - e_lp); 282 313 314 Matrix4x4 dummy = lightSpace; 315 Invert(dummy); 316 Vector3 dummyVec = dummy * e_lp; 317 Vector3 dummyVec2 = dummy * b_lp; 318 319 //projDir.z = -projDir.z; 320 321 cout << "dummy: " << Normalize(dummyVec2 - dummyVec) << endl; 283 322 //project the view direction into the shadow map plane 284 323 projDir.y = 0.0; 285 //projDir.z = 0.0;286 324 287 325 return Normalize(projDir); 288 } 289 290 291 static AxisAlignedBox3 GetExtremalPoints(const Matrix4x4 &m, 292 const VertexArray &pts) 293 { 294 AxisAlignedBox3 extremalPoints; 295 extremalPoints.Initialize(); 296 297 VertexArray::const_iterator it, it_end = pts.end(); 298 299 for (it = pts.begin(); it != it_end; ++ it) 300 { 301 Vector3 pt = *it; 302 pt = m * pt; 303 304 extremalPoints.Include(pt); 305 } 306 307 return extremalPoints; 326 //return projDir; 308 327 } 309 328 … … 342 361 transform2LispSM.x[0][0] = 1.0f; 343 362 transform2LispSM.x[1][2] = -1.0f; // y => -z 344 transform2LispSM.x[2][1] = 1.0f; 363 transform2LispSM.x[2][1] = 1.0f; // z => y 345 364 transform2LispSM.x[3][3] = 1.0f; 346 365 … … 348 367 lightProj = lightProj * transform2LispSM; 349 368 350 const Vector3 projViewDir = GetProjViewDir(lightProj, frustumPoints); 351 352 cout << "projViewDir: " << projViewDir << endl; 369 const Vector3 projViewDir = GetProjViewDir(lightView * lightProj, frustumPoints); 370 371 372 cout << "projViewDir: " << projViewDir << " orig " << mCamera->GetDirection() << endl; 353 373 354 374 //do Light Space Perspective shadow mapping … … 357 377 //look(from position, into the direction of the projected direction, with unchanged up-vector) 358 378 Matrix4x4 frame = LookAt(Vector3::ZERO(), projViewDir, Vector3::UNIT_Y()); 359 //lightProj = lightProj * frame; 379 380 cout << "frame\n " << frame << endl; 381 lightProj = lightProj * frame; 360 382 361 383 cout << "here9\n" << lightProj << endl; … … 364 386 CalcLispSMTransform(lightView * lightProj, extremalPoints, frustumPoints); 365 387 388 Vector3 mydummy = Vector3::UNIT_Z(); 389 390 cout << "yoyo: " << Normalize(lightView * lightProj * mydummy) << endl; 366 391 lightProj = lightProj * matLispSM; 367 392
Note: See TracChangeset
for help on using the changeset viewer.