- Timestamp:
- 09/09/08 17:35:18 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ShadowMapping.cpp
r2921 r2922 189 189 //-- We apply the lispsm algorithm in order to calculate an optimal light projection matrix 190 190 191 const float n = 10;//ComputeN(extremalPoints);191 const float n = ComputeN(extremalPoints); 192 192 193 193 cout << "n: " << n << endl; … … 198 198 const Vector3 lsNear = lightProjView * nearPt; 199 199 200 //c start has the x and y coordinate of e, the z coord of B.min() 201 const Vector3 startPt = Vector3::ZERO();//Vector3(lsNear.x, lsNear.y, extremalPoints.Max().z); 200 //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; 202 205 203 206 // the new projection center 204 207 Vector3 projCenter = startPt + Vector3::UNIT_Z() * n; 205 208 209 cout <<"start: " << startPt << " " << projCenter << endl; 210 206 211 //construct a translation that moves to the projection center 207 212 const Matrix4x4 projectionCenter = TranslationMatrix(-projCenter); 208 213 209 214 // light space y size 210 const float d = fabs(extremalPoints.Max()[2] - extremalPoints.Min()[2]); 211 cout << "d: " << d << endl; 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]); 219 220 cout << "d: " << d << " dy: " << dy << " dx: " << dx << endl; 221 212 222 matLispSM = GetFrustum(-1.0, 1.0, -1.0, 1.0, n, n + d); 213 223 214 cout << "lispsm\n" << matLispSM << endl;224 //cout << "lispsm\n" << matLispSM << endl; 215 225 216 226 matLispSM = projectionCenter * matLispSM; 217 227 218 228 cout << "center\n" << projectionCenter << endl; 219 cout << "new\n" << matLispSM << endl;229 //cout << "new\n" << matLispSM << endl; 220 230 221 231 // transform into OpenGL right handed system … … 230 240 Vector3 ShadowMap::GetNearCameraPointE(const VertexArray &pts) const 231 241 { 232 Vector3 nearest ;233 float minDist = 1e2 0f;242 Vector3 nearest = Vector3::ZERO(); 243 float minDist = 1e25f; 234 244 235 245 Vector3 camPos = mCamera->GetPosition(); … … 279 289 280 290 281 static AxisAlignedBox3 GetExtremalPoints(const Matrix4x4 & lightView,291 static AxisAlignedBox3 GetExtremalPoints(const Matrix4x4 &m, 282 292 const VertexArray &pts) 283 293 { … … 290 300 { 291 301 Vector3 pt = *it; 292 pt = lightView* pt;302 pt = m * pt; 293 303 294 304 extremalPoints.Include(pt); … … 301 311 bool ShadowMap::CalcLightProjection(Matrix4x4 &lightProj) 302 312 { 303 DEL_PTR(polyhedron);304 305 306 313 /////////////////// 307 314 //-- First step: calc frustum clipped by scene box 308 315 316 DEL_PTR(polyhedron); 309 317 polyhedron = CalcClippedFrustum(mSceneBox); 310 318 … … 329 337 lightProj = IdentityMatrix(); 330 338 339 // switch coordinate system to that used in the lispsm algorithm for calculations 340 Matrix4x4 transform2LispSM = ZeroMatrix(); 341 342 transform2LispSM.x[0][0] = 1.0f; 343 transform2LispSM.x[1][2] = -1.0f; // y => -z 344 transform2LispSM.x[2][1] = 1.0f; // z => y 345 transform2LispSM.x[3][3] = 1.0f; 346 347 //switch to the lightspace used in the article 348 lightProj = lightProj * transform2LispSM; 349 331 350 const Vector3 projViewDir = GetProjViewDir(lightProj, frustumPoints); 332 351 … … 334 353 335 354 //do Light Space Perspective shadow mapping 336 //rotate the lightspace so that the proj light view always points upwards337 //calculate a frame matrix that uses the projViewDir[light -space] as up vector355 //rotate the lightspace so that the projected light view always points upwards 356 //calculate a frame matrix that uses the projViewDir[lightspace] as up vector 338 357 //look(from position, into the direction of the projected direction, with unchanged up-vector) 339 358 Matrix4x4 frame = LookAt(Vector3::ZERO(), projViewDir, Vector3::UNIT_Y()); 340 359 lightProj = frame * lightProj; 341 360 361 cout << "here9\n" << lightProj << endl; 362 342 363 const Matrix4x4 matLispSM = 343 364 CalcLispSMTransform(lightView * lightProj, extremalPoints, frustumPoints); … … 345 366 lightProj = matLispSM * lightProj; 346 367 368 // change back to GL coordinate system 369 Matrix4x4 transformToGL = ZeroMatrix(); 370 371 transformToGL.x[0][0] = 1.0f; 372 transformToGL.x[1][2] = 1.0f; // z => y 373 transformToGL.x[2][1] = -1.0f; // y => -z 374 transformToGL.x[3][3] = 1.0f; 375 376 lightProj = lightProj * transformToGL; 377 //cout << "here4 \n" << lightProj << endl; 378 347 379 AxisAlignedBox3 lightPts = GetExtremalPoints(lightView * lightProj, frustumPoints); 348 380 349 //cout << "ma x: " << lightPts.Max() << endl;350 //cout << "mi n: " << lightPts.Min() << endl;381 //cout << "ma2: " << lightPts.Max() << endl; 382 //cout << "mi2: " << lightPts.Min() << endl; 351 383 352 384 // focus projection matrix on the extremal points => scale to unit cube 353 lightProj *= GetFittingProjectionMatrix(lightPts);354 //lightProj *= GetFittingProjectionMatrix(extremalPoints);355 356 cout << "max: " << lightProj * lightPts.Max() << endl;357 cout << "min: " << lightProj * lightPts.Min() << endl;385 Matrix4x4 scaleTranslate = GetFittingProjectionMatrix(lightPts); 386 lightProj *= scaleTranslate; 387 388 cout << "max: " << lightProj * extremalPoints.Max() << endl; 389 cout << "min: " << lightProj * extremalPoints.Min() << endl; 358 390 359 391 // we have to flip the signs in order to tranform to opengl right handed system … … 413 445 const float ylen = Magnitude(mSceneBox.Diagonal() * 0.5f); 414 446 415 const Vector3 dir = mLight->GetDirection();416 //const Vector3 dir(0, 0,1);447 //const Vector3 dir = mLight->GetDirection(); 448 const Vector3 dir(0, 0, -1); 417 449 418 450 mShadowCam->SetDirection(dir); … … 426 458 //mCamera->GetModelViewMatrix(camView); 427 459 428 pos -= dir * Magnitude(mSceneBox.Diagonal() * 0. 5f);460 pos -= dir * Magnitude(mSceneBox.Diagonal() * 0.1f); 429 461 mShadowCam->SetPosition(pos); 430 462
Note: See TracChangeset
for help on using the changeset viewer.