Changeset 2942 for GTP/trunk/App/Demos/Vis/FriendlyCulling/src
- Timestamp:
- 09/13/08 14:03:47 (16 years ago)
- Location:
- GTP/trunk/App/Demos/Vis/FriendlyCulling/src
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
TabularUnified GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Camera.cpp ¶
r2941 r2942 41 41 mIsOrtho = false; 42 42 43 SetPosition(Vector3 (0, 0, 0));43 SetPosition(Vector3::ZERO()); 44 44 45 45 mPitch = mYaw = 0; -
TabularUnified GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Matrix4x4.cpp ¶
r2940 r2942 777 777 0, 0, 0, 1); 778 778 779 Vector3 position = m * -pos;780 781 779 // note: left handed system => we go into positive z 782 780 m.x[3][0] = -DotProd(nRight, pos); 783 781 m.x[3][1] = -DotProd(nUp, pos); 784 m.x[3][2] = 782 m.x[3][2] = DotProd(nDir, pos); 785 783 786 784 return m; … … 788 786 789 787 790 Matrix4x4 MyLookAt2(const Vector3 &pos, const Vector3 &dir, const Vector3& up) 791 { 792 const Vector3 nDir = Normalize(dir); 793 Vector3 nUp = Normalize(up); 794 795 Vector3 nRight = Normalize(CrossProd(nDir, nUp)); 796 nUp = Normalize(CrossProd(nRight, nDir)); 797 798 Matrix4x4 m(nRight, nUp, nDir); 799 800 Vector3 position = m * -pos; 801 802 // note: left handed system => we go into positive z 803 m.x[3][0] = position.x; 804 m.x[3][1] = position.y; 805 m.x[3][2] = position.z; 806 807 return m; 808 } 809 810 811 } 788 } -
TabularUnified GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Matrix4x4.h ¶
r2934 r2942 161 161 Matrix4x4 LookAt(const Vector3 &pos, const Vector3 &dir, const Vector3& up); 162 162 Matrix4x4 MyLookAt(const Vector3 &pos, const Vector3 &dir, const Vector3& up); 163 Matrix4x4 MyLookAt2(const Vector3 &pos, const Vector3 &dir, const Vector3& up);164 163 165 164 -
TabularUnified 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 -
TabularUnified GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ShadowMapping.h ¶
r2936 r2942 89 89 static void DrawPoly(Polyhedron *poly, const Vector3 &color, const Vector3 &color2); 90 90 91 91 /** Internal shador render method. 92 */ 93 void _Render(RenderTraverser *renderer); 92 94 93 95 ////////////// -
TabularUnified GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp ¶
r2939 r2942 1035 1035 // this would conveniently solves some issues (e.g, skys without shadows) 1036 1036 1037 //RenderSky();1037 RenderSky(); 1038 1038 1039 1039 -
TabularUnified GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg ¶
r2941 r2942 104 104 lightSpacePos /= lightSpacePos.w; 105 105 106 /*float shadowDepth[9]; 106 OUT.color = col; 107 108 float shadowDepth[9]; 107 109 108 110 float w = sampleWidth; … … 132 134 133 135 d /= 9.0f; 134 */ 135 136 OUT.color = col; 136 137 if (amb < 0.9f) // hack: prevent shadowing the sky 138 { 139 const float x = 0.1f; 140 OUT.color *= x + (1.0f - x) * (1.0f - d); 141 } 142 143 /* 137 144 138 145 float shadowDepth = tex2D(shadowMap, lightSpacePos.xy).x; … … 142 149 { 143 150 OUT.color *= 0.1f; 144 } 145 /* 146 if (amb < 0.9f) // hack: prevent shadowing the sky 147 { 148 const float x = 0.1f; 149 OUT.color *= x + (1.0f - x) * (1.0f - d); 150 } 151 */ 152 //OUT.color = lightSpacePos;//float4(lightSpacePos.z / lightSpacePos.w); 153 //OUT.color = float4(shadowDepth); 151 }*/ 152 154 153 OUT.color.w = color.w; 155 154
Note: See TracChangeset
for help on using the changeset viewer.