- Timestamp:
- 09/12/08 03:09:20 (16 years ago)
- Location:
- GTP/trunk/App/Demos/Vis/FriendlyCulling/src
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Camera.cpp
r2931 r2932 11 11 using namespace std; 12 12 13 // our coordinate system has the positive z axis pointing up 13 // our coordinate system is left-handed 14 // we look into positive y and have the positive z axis pointing up 14 15 static const Vector3 baseDir = -Vector3::UNIT_Y(); 15 16 … … 88 89 mat = mViewOrientation; 89 90 90 Vector3 pos = mViewOrientation * -mPosition; 91 92 mat.x[3][0] = pos.x; 93 mat.x[3][1] = pos.y; 94 mat.x[3][2] = pos.z; 95 96 //glGetFloatv(GL_MODELVIEW_MATRIX, (float *)mat.x); 91 // note: left handed system => we go into positive z 92 mat.x[3][0] = -DotProd(GetRightVector(), mPosition); 93 mat.x[3][1] = -DotProd(GetUpVector(), mPosition); 94 mat.x[3][2] = DotProd(GetDirection(), mPosition); 97 95 } 98 96 … … 127 125 void Camera::SetupCameraView() 128 126 { 129 Matrix4x4 viewOrientation = mViewOrientation; 130 131 Vector3 pos = mViewOrientation * -mPosition; 132 133 viewOrientation.x[3][0] = pos.x; 134 viewOrientation.x[3][1] = pos.y; 135 viewOrientation.x[3][2] = pos.z; 136 137 glLoadMatrixf((float *)viewOrientation.x); 127 Matrix4x4 m; 128 GetModelViewMatrix(m); 129 130 glLoadMatrixf((float *)m.x); 138 131 } 139 132 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Camera.h
r2931 r2932 40 40 class Camera 41 41 { 42 friend class ShadowMap; 42 43 public: 43 44 … … 46 47 Camera(int width, int height, float fieldOfView = 90.f); 47 48 48 49 /** Sets the current camera position. 50 */ 49 51 void SetPosition(const Vector3 &pos); 50 52 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.cpp
r2930 r2932 293 293 CG_SOURCE, 294 294 #ifdef USE_3D_SSAO 295 "src/shaders/ssao3d.cg", 296 295 "src/shaders/ssao3d.cg", 297 296 #else 298 297 "src/shaders/ssao.cg", -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Matrix4x4.cpp
r2924 r2932 731 731 } 732 732 733 } 733 734 Matrix4x4 MyLookAt(const Vector3 &pos, const Vector3 &dir, const Vector3& up) 735 { 736 const Vector3 nDir = Normalize(dir); 737 Vector3 nUp = Normalize(up); 738 739 Vector3 nRight = Normalize(CrossProd(nDir, nUp)); 740 nUp = Normalize(CrossProd(nRight, nDir)); 741 742 Matrix4x4 m(nRight, nUp, -nDir); 743 744 /*m.x[3][0] = -DotProd(nRight, position); 745 m.x[3][1] = -DotProd(nUp, position); 746 m.x[3][2] = -DotProd(nDir, position);*/ 747 748 Vector3 position = m * -pos; 749 750 // note: left handet system => we go into positive z 751 m.x[3][0] = position.x; 752 m.x[3][1] = position.y; 753 m.x[3][2] = position.z; 754 755 return m; 756 } 757 758 } -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Matrix4x4.h
r2919 r2932 160 160 Matrix4x4 GetFrustum(float left, float right, float bottom, float top, float near, float far); 161 161 Matrix4x4 LookAt(const Vector3 &pos, const Vector3 &dir, const Vector3& up); 162 Matrix4x4 MyLookAt(const Vector3 &pos, const Vector3 &dir, const Vector3& up); 162 163 163 164 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ShadowMapping.cpp
r2931 r2932 23 23 static Polyhedron *polyhedron = NULL; 24 24 static Polyhedron *lightPoly = NULL; 25 static Matrix4x4 dummy = IdentityMatrix(); 25 26 26 27 … … 183 184 DrawPoly(lightPoly, Vector3(1, 0, 1)); 184 185 DrawPoly(polyhedron, Vector3(0, 1, 0)); 186 187 Vector3 pt = Vector3::ZERO(); 188 189 pt = dummy * pt; 190 191 glPointSize(10.0f); 192 193 glBegin(GL_POINTS); 194 glVertex3f(pt.x, pt.y, pt.z); 195 glEnd(); 185 196 } 186 197 … … 212 223 //-- first find the free parameter values n, and P (the projection center), and the projection depth 213 224 214 //const float n = 1e2f;215 const float n = 1e6f;225 const float n = 1e2f; 226 //const float n = 1e6f; 216 227 //const float n = ComputeN(bounds_ls) * 100; 217 228 … … 357 368 cout << "dummy: " << Normalize(dummyVec2 - dummyVec) << endl; 358 369 //project the view direction into the shadow map plane 359 projDir.y = 0.0;370 projDir.y = .0f; 360 371 361 372 return Normalize(projDir); … … 401 412 402 413 //switch to the lightspace used in the article 403 lightProj = lightProj * transform2LispSM;414 //lightProj = lightProj * transform2LispSM; 404 415 405 416 const Vector3 projViewDir = GetProjViewDir(lightView * lightProj, frustumPoints); … … 412 423 //calculate a frame matrix that uses the projViewDir[lightspace] as up vector 413 424 //look(from position, into the direction of the projected direction, with unchanged up-vector) 414 const Matrix4x4 frame = LookAt(Vector3::ZERO(), projViewDir, Vector3::UNIT_Y());425 const Matrix4x4 frame = MyLookAt(Vector3::ZERO(), projViewDir, Vector3::UNIT_Y()); 415 426 416 427 cout << "frame\n " << frame << endl; 417 lightProj = lightProj * frame;428 //lightProj = lightProj * frame; 418 429 419 430 cout << "here9\n" << lightProj << endl; … … 421 432 const Matrix4x4 matLispSM = 422 433 CalcLispSMTransform(lightView * lightProj, extremalPoints, frustumPoints); 423 424 Vector3 mydummy = projViewDir;//Vector3::UNIT_Z();425 //cout << "transformed unit z vector: " << Normalize(lightView * lightProj * mydummy) << endl;426 cout << "transformed unit z vector: " << Normalize(frame * mydummy) << endl;427 434 428 435 lightProj = lightProj * matLispSM; … … 436 443 transformToGL.x[3][3] = 1.0f; 437 444 438 lightProj = lightProj * transformToGL;445 //lightProj = lightProj * transformToGL; 439 446 //cout << "here4 \n" << lightProj << endl; 440 447 … … 485 492 return Normalize(up); 486 493 } 487 488 489 void ShadowMap::ComputeShadowMap(RenderTraverser *renderer, const Matrix4x4 &projView)490 {491 const float xlen = Magnitude(mSceneBox.Diagonal() * 0.5f);492 const float ylen = Magnitude(mSceneBox.Diagonal() * 0.5f);493 494 //const Vector3 dir = mLight->GetDirection();495 const Vector3 dir(0, 0, -1);496 497 Vector3 upVec = CalcUpVec(mCamera->GetDirection(), dir);498 mLightMatrix = LookAt(mCamera->GetPosition(), dir, upVec);499 500 mShadowCam->SetDirection(dir);501 502 //cout << "lightdir: " << mShadowCam->GetDirection() << endl;503 504 // set position so that we can see the whole scene505 Vector3 pos = mSceneBox.Center();506 507 //Matrix4x4 camView;508 //mCamera->GetModelViewMatrix(camView);509 510 pos -= dir * Magnitude(mSceneBox.Diagonal() * 0.5f);511 mShadowCam->SetPosition(pos);512 513 mFbo->Bind();514 515 glDrawBuffers(1, mrt);516 517 glPushAttrib(GL_VIEWPORT_BIT);518 glViewport(0, 0, mSize, mSize);519 520 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);521 522 //glEnable(GL_LIGHTING);523 //glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);524 glDisable(GL_LIGHTING);525 glDisable(GL_TEXTURE_2D);526 glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);527 528 glPolygonOffset(1.0f, 2000.0f);529 glEnable(GL_POLYGON_OFFSET_FILL);530 531 glShadeModel(GL_FLAT);532 glEnable(GL_DEPTH_TEST);533 534 // setup projection535 /*glMatrixMode(GL_PROJECTION);536 glLoadIdentity();537 glOrtho(+xlen, -xlen, +ylen, -ylen, 0.0f, Magnitude(mSceneBox.Diagonal()));538 539 Matrix4x4 dummyMat;540 glGetFloatv(GL_PROJECTION_MATRIX, (float *)dummyMat.x);541 cout << "old:\n" << dummyMat << endl;542 */543 544 Matrix4x4 lightView, lightProj;545 546 //mShadowCam->GetModelViewMatrix(lightView);547 lightView = mLightMatrix;548 549 CalcLightProjection(lightProj);550 551 glMatrixMode(GL_PROJECTION);552 glPushMatrix();553 glLoadMatrixf((float *)lightProj.x);554 555 mLightProjView = lightView * lightProj;556 557 DEL_PTR(lightPoly);558 lightPoly = CreatePolyhedron(mLightProjView, mSceneBox);559 560 //cout << "new:\n" << lightProj << endl;561 562 glMatrixMode(GL_MODELVIEW);563 glPushMatrix();564 glLoadIdentity();565 566 //mShadowCam->SetupCameraView();567 glLoadMatrixf((float *)mLightMatrix.x);568 569 //////////////570 //-- compute texture matrix571 572 static Matrix4x4 biasMatrix(0.5f, 0.0f, 0.0f, 0.5f,573 0.0f, 0.5f, 0.0f, 0.5f,574 0.0f, 0.0f, 0.5f, 0.5f,575 0.0f, 0.0f, 0.0f, 1.0f);576 577 mTextureMatrix = mLightProjView * biasMatrix;578 579 580 581 582 /////////////583 //-- render scene into shadow map584 585 renderer->RenderScene();586 587 588 glDisable(GL_POLYGON_OFFSET_FILL);589 glMatrixMode(GL_MODELVIEW);590 glPopMatrix();591 592 glMatrixMode(GL_PROJECTION);593 glPopMatrix();594 595 glPopAttrib();596 597 598 glEnable(GL_LIGHTING);599 glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);600 601 #if 0602 float *data = new float[mSize * mSize];603 604 GrabDepthBuffer(data, mFbo->GetDepthTex());605 ExportDepthBuffer(data, mSize);606 607 delete [] data;608 609 PrintGLerror("shadow map");610 #endif611 FrameBufferObject::Release();612 }613 614 494 615 495 … … 667 547 668 548 669 void ShadowMap::RenderShadowView(RenderTraverser *renderer, const Matrix4x4 &projView) 670 { 549 void ShadowMap::ComputeShadowMap(RenderTraverser *renderer, const Matrix4x4 &projView) 550 { 551 const float xlen = Magnitude(mSceneBox.Diagonal() * 0.5f); 552 const float ylen = Magnitude(mSceneBox.Diagonal() * 0.5f); 553 671 554 //const Vector3 dir = mLight->GetDirection(); 672 555 const Vector3 dir(0, 0, -1); 673 556 674 mShadowCam->SetDirection(dir); 557 // set position so that we can see the whole scene 558 //Vector3 pos = mSceneBox.Center(); 559 //pos -= dir * Magnitude(mSceneBox.Diagonal() * 0.5f); 560 //mShadowCam->SetPosition(pos); 561 mShadowCam->SetPosition(mCamera->GetPosition()); 675 562 676 563 Vector3 upVec = CalcUpVec(mCamera->GetDirection(), dir); 677 mLightMatrix = LookAt(mCamera->GetPosition(), dir, upVec); 678 679 // set position so that we can see the whole scene 680 Vector3 pos = mSceneBox.Center(); 681 682 pos -= dir * Magnitude(mSceneBox.Diagonal() * 0.5f); 683 mShadowCam->SetPosition(pos); 564 Matrix4x4 lightView = 565 MyLookAt(mShadowCam->GetPosition(), dir, upVec); 566 567 mShadowCam->mViewOrientation = lightView; 568 569 //cout << "here45:\n" << lightView << endl; 570 571 //mShadowCam->SetDirection(dir); 572 //mShadowCam->GetModelViewMatrix(lightView); 573 //cout << "here46:\n" << lightView << endl; 574 575 mFbo->Bind(); 576 577 glDrawBuffers(1, mrt); 578 579 glPushAttrib(GL_VIEWPORT_BIT); 580 glViewport(0, 0, mSize, mSize); 684 581 685 582 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 686 583 687 glEnable(GL_LIGHTING); 688 glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); 584 glDisable(GL_LIGHTING); 585 glDisable(GL_TEXTURE_2D); 586 glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE); 689 587 690 588 glPolygonOffset(1.0f, 2000.0f); 691 589 glEnable(GL_POLYGON_OFFSET_FILL); 692 glDisable(GL_CULL_FACE); 590 591 glShadeModel(GL_FLAT); 693 592 glEnable(GL_DEPTH_TEST); 694 593 695 Matrix4x4 lightView, lightProj; 696 697 //mShadowCam->GetModelViewMatrix(lightView); 698 lightView = mLightMatrix; 594 Matrix4x4 lightProj; 595 699 596 CalcLightProjection(lightProj); 700 597 … … 705 602 mLightProjView = lightView * lightProj; 706 603 604 cout << "here3" << endl; 707 605 DEL_PTR(lightPoly); 708 606 lightPoly = CreatePolyhedron(mLightProjView, mSceneBox); 709 710 //cout << "new:\n" << lightProj << endl; 607 cout << "here4\n" << lightView << endl; 711 608 712 609 glMatrixMode(GL_MODELVIEW); … … 714 611 glLoadIdentity(); 715 612 716 //mShadowCam->SetupCameraView(); 717 glLoadMatrixf((float *)mLightMatrix.x); 718 613 mShadowCam->SetupCameraView(); 614 615 616 ////////////// 617 //-- compute texture matrix 618 619 static Matrix4x4 biasMatrix(0.5f, 0.0f, 0.0f, 0.5f, 620 0.0f, 0.5f, 0.0f, 0.5f, 621 0.0f, 0.0f, 0.5f, 0.5f, 622 0.0f, 0.0f, 0.0f, 1.0f); 623 624 mTextureMatrix = mLightProjView * biasMatrix; 625 626 627 628 629 ///////////// 630 //-- render scene into shadow map 631 632 renderer->RenderScene(); 633 634 635 glDisable(GL_POLYGON_OFFSET_FILL); 636 glMatrixMode(GL_MODELVIEW); 637 glPopMatrix(); 638 639 glMatrixMode(GL_PROJECTION); 640 glPopMatrix(); 641 642 glPopAttrib(); 643 644 645 glEnable(GL_LIGHTING); 646 glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); 647 648 #if 0 649 float *data = new float[mSize * mSize]; 650 651 GrabDepthBuffer(data, mFbo->GetDepthTex()); 652 ExportDepthBuffer(data, mSize); 653 654 delete [] data; 655 656 PrintGLerror("shadow map"); 657 #endif 658 FrameBufferObject::Release(); 659 } 660 661 662 void ShadowMap::RenderShadowView(RenderTraverser *renderer, const Matrix4x4 &projView) 663 { 664 //const Vector3 dir = mLight->GetDirection(); 665 const Vector3 dir(0, 0, -1); 666 667 mShadowCam->SetDirection(dir); 668 669 // set position so that we can see the whole scene 670 Vector3 pos = mSceneBox.Center(); 671 pos -= dir * Magnitude(mSceneBox.Diagonal() * 0.5f); 672 673 mShadowCam->SetPosition(mCamera->GetPosition()); 674 675 Vector3 upVec = CalcUpVec(mCamera->GetDirection(), dir); 676 Matrix4x4 lightView = MyLookAt(mShadowCam->GetPosition(), dir, upVec); 677 678 mShadowCam->mViewOrientation = lightView; 679 680 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 681 682 glEnable(GL_LIGHTING); 683 glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); 684 685 glPolygonOffset(1.0f, 2000.0f); 686 glEnable(GL_POLYGON_OFFSET_FILL); 687 688 glEnable(GL_DEPTH_TEST); 689 690 Matrix4x4 lightProj; 691 692 CalcLightProjection(lightProj); 693 694 glMatrixMode(GL_PROJECTION); 695 glPushMatrix(); 696 glLoadMatrixf((float *)lightProj.x); 697 698 mLightProjView = lightView * lightProj; 699 700 dummy = mLightProjView; 701 702 DEL_PTR(lightPoly); 703 lightPoly = CreatePolyhedron(mLightProjView, mSceneBox); 704 705 glMatrixMode(GL_MODELVIEW); 706 glPushMatrix(); 707 glLoadIdentity(); 708 709 mShadowCam->SetupCameraView(); 710 719 711 720 712 ///////////// … … 736 728 737 729 DrawPoly(hpoly, Vector3(1, 1, 1)); 730 738 731 DEL_PTR(hpoly); 739 732 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ShadowMapping.h
r2931 r2932 109 109 110 110 Matrix4x4 mLightProjView; 111 112 Matrix4x4 mLightMatrix;113 111 }; 114 112 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp
r2931 r2932 1569 1569 1570 1570 //const float offs = box.Size().x * 0.3f; 1571 const float offs = box.Size().x * 0. 4f;1571 const float offs = box.Size().x * 0.6f; 1572 1572 1573 1573 Vector3 vizpos = Vector3(box.Min().x, box.Min().y - box.Size().y * 0.35f, box.Min().z + box.Size().z * 50);
Note: See TracChangeset
for help on using the changeset viewer.