- Timestamp:
- 09/08/08 15:00:23 (16 years ago)
- Location:
- GTP/trunk/App/Demos/Vis/FriendlyCulling/src
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Matrix4x4.cpp
r2915 r2916 655 655 Matrix4x4 m; 656 656 657 /* m.x[0][0] = 2.0f / (box.Max()[0] - box.Min()[0]);658 m.x[1][0] = .0f;659 m.x[2][0] = .0f;660 m.x[3][0] = -(box.Max()[0] + box.Min()[0]) / (box.Max()[0] - box.Min()[0]);661 662 m.x[0][1] = .0f;663 m.x[1][1] = 2.0f / (box.Max()[1] - box.Min()[1]);664 m.x[2][1] = .0f;665 m.x[3][1] = -(box.Max()[1] + box.Min()[1]) / (box.Max()[1] - box.Min()[1]);666 667 m.x[0][2] = .0f;668 m.x[1][2] = .0f;669 m.x[2][2] = 2.0f / (box.Max()[2] - box.Min()[2]);670 m.x[3][2] = -(box.Max()[2] + box.Min()[2]) / (box.Max()[2] - box.Min()[2]);671 672 m.x[0][3] = .0f;673 m.x[1][3] = .0f;674 m.x[2][3] = .0f;675 m.x[3][3] = 1.0f;*/676 677 657 m.x[0][0] = -2.0f / (box.Max()[0] - box.Min()[0]); 678 658 m.x[0][1] = .0f; … … 698 678 } 699 679 680 /* 681 Matrix4x4 GetFittingProjectionMatrix(const AxisAlignedBox3 &box) 682 { 683 Matrix4x4 m; 684 685 m.x[0][0] = 2.0f / (box.Max()[0] - box.Min()[0]); 686 m.x[0][1] = .0f; 687 m.x[0][2] = .0f; 688 m.x[0][3] = .0f; 689 690 m.x[1][0] = .0f; 691 m.x[1][1] = 2.0f / (box.Max()[1] - box.Min()[1]); 692 m.x[1][2] = .0f; 693 m.x[1][3] = .0f; 694 695 m.x[2][0] = .0f; 696 m.x[2][1] = .0f; 697 m.x[2][2] = 2.0f / (box.Max()[2] - box.Min()[2]); 698 m.x[2][3] = .0f; 699 700 m.x[3][0] = -(box.Max()[0] + box.Min()[0]) / (box.Max()[0] - box.Min()[0]); 701 m.x[3][1] = -(box.Max()[1] + box.Min()[1]) / (box.Max()[1] - box.Min()[1]); 702 m.x[3][2] = -(box.Max()[2] + box.Min()[2]) / (box.Max()[2] - box.Min()[2]); 703 m.x[3][3] = 1.0f; 704 705 return m; 706 }*/ 700 707 701 708 //output is initialized with the same result as glFrustum -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Matrix4x4.h
r2915 r2916 155 155 Vector3 GetTranslation(const Matrix4x4 &M); 156 156 Matrix4x4 GetFittingProjectionMatrix(const AxisAlignedBox3 &box); 157 157 Matrix4x4 GetFrustum(float left, float right, float bottom, float top, float near, float far); 158 158 159 159 } -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ShadowMapping.cpp
r2915 r2916 166 166 167 167 168 bool ShadowMap::CalcLightProjectionLispSM(Matrix4x4 &lightProj) 169 { 168 float ShadowMap::ComputeN() const 169 { 170 const float n = mShadowCam->GetNear(); 171 const float f = mShadowCam->GetFar(); 172 173 const float d = fabs(f - n); 174 175 const float dotProd = DotProd(mCamera->GetDirection(), mShadowCam->GetDirection()); 176 const float sinGamma = sin(fabs(acos(dotProd))); 177 178 return (n + sqrt(n * (n + d * sinGamma))) / sinGamma; 179 } 180 181 182 Matrix4x4 ShadowMap::CalcLispSMTransform(const Matrix4x4 &lightProjView) 183 {/* 170 184 Matrix4x4 lispMtx = IdentityMatrix(); 171 185 … … 212 226 //-- We apply the lispsm algorithm in order to calculate an optimal light projection matrix 213 227 214 // use lispsm formulas 215 const float fac = 1.0f / sinGamma; 216 217 const float z_n = fac * mCamera->GetNear(); 218 219 // light space y size 220 const float d = fabs(extremalPoints.Max()[1] - extremalPoints.Min()[1]); 221 222 const float z_f = z_n + d * sinGamma; 223 224 // this is the famous n parameter 225 const float n = (z_n + sqrt(z_f * z_n)) /sinGamma; 226 const float f = n + d; 228 const float n = 1e20f;//ComputeN(); 229 230 cout << "n: " << n << endl; 227 231 228 232 const Vector3 nearPt = mShadowCam->GetNear() * mShadowCam->GetDirection() + mShadowCam->GetPosition(); … … 232 236 233 237 //c start has the x and y coordinate of e, the z coord of B.min() 234 const Vector3 startPt = Vector3(lsNear.x, lsNear.y, extremalPoints.M ax().z);238 const Vector3 startPt = Vector3(lsNear.x, lsNear.y, extremalPoints.Min().y); 235 239 236 240 // the new projection center 237 Vector3 projCenter = startPt - Vector3(0, 0, 1) * n; 241 const Vector3 unit_y = Vector3(0, 1, 0); 242 Vector3 projCenter = startPt - unit_y * n; 238 243 239 244 //construct a translation that moves to the projection center 240 245 const Matrix4x4 projectionCenter = TranslationMatrix(-projCenter); 241 246 242 lightProj = IdentityMatrix(); 243 244 //one possibility for a simple perspective transformation matrix 245 //with the two parameters n(near) and f(far) in y direction 246 247 // a = (f+n)/(f-n); b = -2*f*n/(f-n); 248 // [ 1 0 0 0] 249 // [ 0 a 0 b] 250 // [ 0 0 1 0] 251 // [ 0 1 0 0] 252 253 lightProj.x[1][1] = (f + n) / (f - n); 254 lightProj.x[1][3] = 1.0f; 255 256 lightProj.x[3][1] = -2.0f * f * n / (f - n); 257 lightProj.x[3][3] = 0.0f; 247 // light space y size 248 const float d = fabs(extremalPoints.Max()[2] - extremalPoints.Min()[2]); 249 250 lightProj = GetFrustum(-1.0, 1.0, -1.0, 1.0, n, n + d); 258 251 259 252 cout << "here4\n" << lightProj << endl; … … 270 263 cout << "max: " << lightProj * pmax << endl; 271 264 272 273 return true;265 */ 266 return IdentityMatrix(); 274 267 } 275 268 … … 313 306 } 314 307 308 //Matrix4x4 m = CalcLispSMTransform(lightProj); 309 315 310 // focus projection matrix on the extremal points 316 311 lightProj = GetFittingProjectionMatrix(extremalPoints); 317 312 313 //Matrix4x4 scale = ScaleMatrix(1, 1, -1); lightProj *= scale; 314 318 315 return true; 319 316 } … … 408 405 glEnable(GL_DEPTH_TEST); 409 406 410 411 407 // setup projection 412 408 /*glMatrixMode(GL_PROJECTION); … … 418 414 cout << "old:\n" << dummyMat << endl; 419 415 */ 416 420 417 Matrix4x4 lightView, lightProj; 421 418 422 419 mShadowCam->GetModelViewMatrix(lightView); 423 424 //CalcLightProjection(lightProj); 425 CalcLightProjectionLispSM(lightProj); 420 CalcLightProjection(lightProj); 426 421 427 422 glMatrixMode(GL_PROJECTION); -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ShadowMapping.h
r2915 r2916 64 64 Polyhedron *CalcClippedFrustum(const AxisAlignedBox3 &box) const; 65 65 66 bool CalcLightProjectionLispSM(Matrix4x4 &lightProj);67 66 bool CalcLightProjection(Matrix4x4 &lightProj); 67 Matrix4x4 ShadowMap::CalcLispSMTransform(const Matrix4x4 &lightProjView); 68 68 69 69 void IncludeLightVolume(const Polyhedron &polyhedron, … … 71 71 const Vector3 lightDir, 72 72 const AxisAlignedBox3 &sceneBox); 73 74 float ComputeN() const; 73 75 74 76 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Vector3.h
r2911 r2916 47 47 {} 48 48 49 Vector3(float v): x(v), y(v), z(v){}49 explicit Vector3(float v): x(v), y(v), z(v){} 50 50 /** Copy constructor. 51 51 */
Note: See TracChangeset
for help on using the changeset viewer.