- Timestamp:
- 09/13/08 14:03:47 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ShadowMapping.cpp
r2941 r2942 570 570 void ShadowMap::ComputeShadowMap(RenderTraverser *renderer, const Matrix4x4 &projView) 571 571 { 572 const float xlen = Magnitude(mSceneBox.Diagonal() * 0.5f);573 const float ylen = Magnitude(mSceneBox.Diagonal() * 0.5f);574 575 const Vector3 dir = mLight->GetDirection();576 //const Vector3 dir(0, 0, -1);577 578 // set position so that we can see the whole scene579 //Vector3 pos = mSceneBox.Center();580 //pos -= dir * Magnitude(mSceneBox.Diagonal() * 0.5f);581 //mShadowCam->SetPosition(pos);582 mShadowCam->SetPosition(mCamera->GetPosition());583 584 Vector3 upVec = CalcUpVec(mCamera->GetDirection(), dir);585 Matrix4x4 lightView = MyLookAt(mShadowCam->GetPosition(), dir, upVec);586 //Matrix4x4 lightView = MyLookAt(mShadowCam->GetPosition(), -dir, mCamera->GetDirection());587 588 Matrix4x4 refl = ScaleMatrix(-1, 1, 1);589 lightView = lightView * refl;590 591 mShadowCam->mViewOrientation = lightView;592 593 594 572 mFbo->Bind(); 595 573 … … 598 576 glPushAttrib(GL_VIEWPORT_BIT); 599 577 glViewport(0, 0, mSize, mSize); 600 601 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);602 578 603 579 glDisable(GL_LIGHTING); … … 605 581 glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE); 606 582 607 //glDisable(GL_CULL_FACE);608 609 glPolygonOffset(1.0f, 2000.0f);610 glEnable(GL_POLYGON_OFFSET_FILL);611 //glDisable(GL_POLYGON_OFFSET_FILL);612 613 583 glShadeModel(GL_FLAT); 614 glEnable(GL_DEPTH_TEST); 615 616 Matrix4x4 lightProj; 617 618 CalcLightProjection(lightProj); 619 620 glMatrixMode(GL_PROJECTION); 621 glPushMatrix(); 622 glLoadMatrixf((float *)lightProj.x); 623 624 mLightProjView = lightView * lightProj; 625 626 cout << "here3" << endl; 627 DEL_PTR(lightPoly); 628 lightPoly = CreatePolyhedron(mLightProjView, mSceneBox); 629 cout << "here4\n" << lightView << endl; 630 631 glMatrixMode(GL_MODELVIEW); 632 glPushMatrix(); 633 glLoadIdentity(); 634 635 mShadowCam->SetupCameraView(); 636 637 dummyMat = mLightProjView; 584 585 586 ///////////// 587 //-- render scene into shadow map 588 589 _Render(renderer); 638 590 639 591 … … 648 600 mTextureMatrix = mLightProjView * biasMatrix; 649 601 650 651 652 653 /////////////654 //-- render scene into shadow map655 656 renderer->RenderScene();657 658 659 glDisable(GL_POLYGON_OFFSET_FILL);660 glMatrixMode(GL_MODELVIEW);661 glPopMatrix();662 663 glMatrixMode(GL_PROJECTION);664 glPopMatrix();665 666 602 glPopAttrib(); 667 668 603 669 604 glEnable(GL_LIGHTING); … … 680 615 PrintGLerror("shadow map"); 681 616 #endif 617 682 618 FrameBufferObject::Release(); 683 619 } … … 685 621 686 622 void ShadowMap::RenderShadowView(RenderTraverser *renderer, const Matrix4x4 &projView) 623 { 624 glEnable(GL_LIGHTING); 625 glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); 626 627 _Render(renderer); 628 629 glDisable(GL_POLYGON_OFFSET_FILL); 630 glDisable(GL_LIGHTING); 631 } 632 633 634 void ShadowMap::_Render(RenderTraverser *renderer) 687 635 { 688 636 const Vector3 dir = mLight->GetDirection(); … … 700 648 Vector3 upVec = CalcUpVec(mCamera->GetDirection(), dir); 701 649 Matrix4x4 lightView = MyLookAt(mShadowCam->GetPosition(), dir, upVec); 702 //Matrix4x4 lightView = MyLookAt(mShadowCam->GetPosition(), -dir, mCamera->GetDirection());703 704 //Matrix4x4 refl = ScaleMatrix(-1, 1, 1);705 //lightView = lightView * refl;706 650 707 651 mShadowCam->mViewOrientation = lightView; 708 652 709 653 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 710 711 glEnable(GL_LIGHTING);712 glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);713 654 714 655 glPolygonOffset(1.0f, 2000.0f); 715 656 glEnable(GL_POLYGON_OFFSET_FILL); 716 657 717 glEnable(GL_DEPTH_TEST);718 719 658 Matrix4x4 lightProj; 720 659 CalcLightProjection(lightProj); … … 730 669 lightPoly = CreatePolyhedron(mLightProjView, mSceneBox); 731 670 732 Frustum frustum(mLightProjView);733 cout << "near: " << Normalize(frustum.mClipPlanes[4].mNormal) << endl;734 cout << "far: " << Normalize(frustum.mClipPlanes[5].mNormal) << endl;735 736 671 glMatrixMode(GL_MODELVIEW); 737 672 glPushMatrix(); … … 739 674 740 675 //glDisable(GL_CULL_FACE); 741 742 676 mShadowCam->SetupCameraView(); 743 744 677 678 745 679 ///////////// 746 680 //-- render scene into shadow map … … 748 682 renderer->RenderScene(); 749 683 750 751 glDisable(GL_POLYGON_OFFSET_FILL);752 753 glDisable(GL_LIGHTING);754 glDisable(GL_DEPTH_TEST);755 756 glLineWidth(2);757 Polyhedron *hpoly = CreatePolyhedron(projView, mSceneBox);758 DrawPoly(hpoly, Vector3(1, 1, 1), Vector3(0, 1, 1));759 760 DEL_PTR(hpoly);761 762 763 glEnable(GL_LIGHTING);764 glEnable(GL_DEPTH_TEST);765 766 684 glMatrixMode(GL_MODELVIEW); 767 685 glPopMatrix(); … … 770 688 glPopMatrix(); 771 689 772 773 #if 0 774 float *data = new float[mSize * mSize]; 775 776 GrabDepthBuffer(data, mFbo->GetDepthTex()); 777 ExportDepthBuffer(data, mSize); 778 779 delete [] data; 780 781 PrintGLerror("shadow map"); 782 #endif 783 FrameBufferObject::Release(); 784 } 785 786 787 788 690 691 glDisable(GL_POLYGON_OFFSET_FILL); 692 } 789 693 } // namespace
Note: See TracChangeset
for help on using the changeset viewer.