Changeset 2943 for GTP/trunk/App/Demos/Vis/FriendlyCulling
- Timestamp:
- 09/13/08 15:00:11 (16 years ago)
- Location:
- GTP/trunk/App/Demos/Vis/FriendlyCulling/src
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Polyhedron.cpp
r2936 r2943 268 268 planePoly = SplitPolygon(planePoly); 269 269 270 // something is wrong, probably some numerical error 271 if (!planePoly) 272 { 273 cerr << "should not happen" << endl; 270 if (planePoly) 271 { 272 // we can now savely add the new polygon 273 clippedPolyhedron->Add(planePoly); 274 } 275 else if (0) 276 { 277 // something is wrong, probably some numerical error 278 cerr << "no polygon: should not happen" << endl; 274 279 return new Polyhedron(*this); 275 280 } 276 281 277 282 278 283 ///////////// … … 317 322 } 318 323 319 // we can now savely add the new polygon320 clippedPolyhedron->Add(planePoly);321 322 324 return clippedPolyhedron; 323 325 } … … 357 359 break; 358 360 case Polygon3::FRONT_SIDE: 359 cerr << "SplitPolygon: should not come here" << endl;361 //cerr << "SplitPolygon: should not come here" << endl; 360 362 DEL_PTR(polygon); 361 363 break; -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderState.cpp
r2934 r2943 22 22 mTexturesEnabled(false), 23 23 mMode(RENDER), 24 mRenderType(FIXED) 24 mRenderType(FIXED), 25 mUseAlphaToCoverage(true) 25 26 { 26 27 Reset(); … … 96 97 mAlphaTestEnabled = false; 97 98 98 // not needed with GL_SAMPLE_ALPHA_TO_COVERAGE_ARB 99 //glDisable(GL_ALPHA_TEST); 100 glDisable(GL_SAMPLE_ALPHA_TO_COVERAGE_ARB); 99 if (mUseAlphaToCoverage) 100 glDisable(GL_SAMPLE_ALPHA_TO_COVERAGE_ARB); 101 else 102 glDisable(GL_ALPHA_TEST); 101 103 } 102 104 else if (!mAlphaTestEnabled && alphaTest) … … 104 106 mAlphaTestEnabled = true; 105 107 106 // not needed with GL_SAMPLE_ALPHA_TO_COVERAGE_ARB 107 //glEnable(GL_ALPHA_TEST); 108 glEnable(GL_SAMPLE_ALPHA_TO_COVERAGE_ARB); 108 if (mUseAlphaToCoverage) 109 glEnable(GL_SAMPLE_ALPHA_TO_COVERAGE_ARB); 110 else 111 glEnable(GL_ALPHA_TEST); 109 112 } 110 113 … … 146 149 147 150 151 void RenderState::SetUseAlphaToCoverage(bool useAlphaToCoverage) 152 { 153 mUseAlphaToCoverage = useAlphaToCoverage; 148 154 } 155 156 157 } -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderState.h
r2854 r2943 57 57 */ 58 58 inline int GetCurrentVboId() const { return mCurrentVboId; } 59 /** If alpha to coverage is instead of alpha testing 60 */ 61 void SetUseAlphaToCoverage(bool useAlphaToCoverage); 59 62 60 63 void SetRenderType(RenderType type) { mRenderType = type; } … … 86 89 87 90 RenderType mRenderType; 91 92 bool mUseAlphaToCoverage; 88 93 }; 89 94 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ShadowMapping.cpp
r2942 r2943 23 23 static Polyhedron *polyhedron = NULL; 24 24 static Polyhedron *lightPoly = NULL; 25 static Vector3 dummyPt;26 static Matrix4x4 dummyMat;27 25 28 26 … … 159 157 160 158 161 void ShadowMap::DrawPoly(Polyhedron *poly, const Vector3 &color, const Vector3 &color2)159 static void DrawPoly(Polyhedron *poly, const Vector3 &color) 162 160 { 163 161 if (!poly) return; … … 167 165 glColor3f(color.x, color.y, color.z); 168 166 169 if (i == poly->NumPolygons() - 1) // hack: different color for near170 {171 //glLineWidth(2);172 glColor3f(color2.x, color2.y, color2.z);173 174 }175 167 glBegin(GL_LINE_LOOP); 176 168 … … 184 176 185 177 glEnd(); 186 187 //if (i == poly->NumPolygons() - 1) glLineWidth(1);188 178 } 189 179 } … … 192 182 void ShadowMap::DrawPolys() 193 183 { 194 DrawPoly(lightPoly, Vector3(1, 0, 1), Vector3(1, 1, 1)); 195 DrawPoly(polyhedron, Vector3(0, 1, 0), Vector3(0, 1, 1)); 196 197 glPointSize(10.0f); 198 199 Vector3 pt = Vector3::ZERO(); 200 //Vector3 pt = dummyPt; 201 202 Matrix4x4 myMat = Invert(dummyMat); 203 pt = myMat * pt; 204 205 glBegin(GL_POINTS); 206 glVertex3f(pt.x, pt.y, pt.z); 207 glEnd(); 184 DrawPoly(lightPoly, Vector3(1, 0, 1)); 185 DrawPoly(polyhedron, Vector3(0, 1, 0)); 208 186 } 209 187 … … 235 213 //-- first find the free parameter values n, and P (the projection center), and the projection depth 236 214 237 //const float n = 1e2f;238 //const float n = 1e6f;239 215 const float n = ComputeN(bounds_ls); 240 216 241 cout << "n: " << n << endl;217 //cout << "n: " << n << endl; 242 218 243 219 const Vector3 nearPt = GetNearCameraPointE(body); … … 248 224 // the start point has the x and y coordinate of e, the z coord of the near plane of the light volume 249 225 const Vector3 startPt = Vector3(lsNear.x, lsNear.y, bounds_ls.Max().z); 250 //const Vector3 schas = lightSpace * mCamera->GetPosition(); 251 //const Vector3 startPt = Vector3(schas.x, schas.y, bounds_ls.Max().z); 252 253 cout << "mx: " << bounds_ls.Max() << endl; 254 cout << "mn: " << bounds_ls.Min() << endl; 255 226 256 227 // the new projection center 257 228 const Vector3 projCenter = startPt + Vector3::UNIT_Z() * n; 258 229 259 cout <<"start: " << startPt << " " << projCenter << " " << Distance(lightSpace * mCamera->GetPosition(), startPt) << endl;260 261 dummyPt = startPt;262 263 230 //construct a translation that moves to the projection center 264 231 const Matrix4x4 projectionCenter = TranslationMatrix(-projCenter); … … 270 237 const float dx = fabs(bounds_ls.Max()[0] - bounds_ls.Min()[0]); 271 238 272 cout << "d: " << d << " dy: " << dy << " dx: " << dx << endl;273 274 239 275 240 … … 281 246 matLispSM = GetFrustum(-1.0, 1.0, -1.0, 1.0, n, n + d); 282 247 283 //cout << "lispsm\n" << matLispSM << endl;284 285 248 // translate to the projection center 286 249 matLispSM = projectionCenter * matLispSM; 287 288 //cout << "new\n" << matLispSM << endl;289 250 290 251 // transform into OpenGL right handed system … … 314 275 Vector3 pt = *it; 315 276 Vector3 ptE = eyeView * pt; 316 //cout<<"i"<< pt.z; 277 317 278 if (ptE.z > 0) cerr <<"should not happen " << ptE.z << endl; 318 279 else … … 376 337 Vector3 projDir(b_lp - e_lp); 377 338 378 Matrix4x4 dummy = Invert(lightSpace);379 Invert(dummy);380 Vector3 dummyVec = dummy * e_lp;381 Vector3 dummyVec2 = dummy * b_lp;382 383 //projDir.z = -projDir.z;384 385 cout << "dummy: " << Normalize(dummyVec2 - dummyVec) << endl;386 339 //project the view direction into the shadow map plane 387 340 projDir.y = .0f; 388 341 389 342 return Normalize(projDir); 390 //return projDir;391 343 } 392 344 … … 435 387 const Vector3 projViewDir = GetProjViewDir(lightView * lightProj, frustumPoints); 436 388 437 cout << "projViewDir: " << projViewDir << " orig " << mCamera->GetDirection() << endl;438 439 389 //do Light Space Perspective shadow mapping 440 390 //rotate the lightspace so that the projected light view always points upwards … … 444 394 const Matrix4x4 frame = MyLookAt(Vector3::ZERO(), projViewDir, Vector3::UNIT_Y()); 445 395 446 cout << "frame\n " << frame << endl;447 396 lightProj *= frame; 448 397 … … 464 413 AxisAlignedBox3 lightPts = GetExtremalPoints(lightView * lightProj, frustumPoints); 465 414 466 cout << "max: " << lightPts.Max() << " min: " << lightPts.Min() << endl;467 415 // focus projection matrix on the extremal points => scale to unit cube 468 416 Matrix4x4 scaleTranslate = GetFittingProjectionMatrix(lightPts); 469 417 470 cout << "scaleTranslate:\n" << scaleTranslate << endl;471 472 418 lightProj = lightProj * scaleTranslate; 473 419 … … 475 421 476 422 AxisAlignedBox3 lightPtsNew = GetExtremalPoints(mymat, frustumPoints); 477 478 cout << "newmax: " << lightPtsNew.Max() << endl;479 cout << "newmin: " << lightPtsNew.Min() << endl;480 423 481 424 // we have to flip the signs in order to tranform to opengl right handed system … … 578 521 579 522 glDisable(GL_LIGHTING); 580 glDisable(GL_TEXTURE_2D);523 //glDisable(GL_TEXTURE_2D); 581 524 glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE); 582 525 … … 602 545 glPopAttrib(); 603 546 547 glShadeModel(GL_SMOOTH); 604 548 glEnable(GL_LIGHTING); 605 549 glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); … … 623 567 { 624 568 glEnable(GL_LIGHTING); 625 glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); 626 569 627 570 _Render(renderer); 628 571 572 /*glDisable(GL_LIGHTING); 573 glDisable(GL_DEPTH_TEST); 574 575 //glLineWidth(2); 576 Polyhedron *hpoly = CreatePolyhedron(projView, mSceneBox); 577 DrawPoly(hpoly, Vector3(1, 1, 1)); 578 579 DEL_PTR(hpoly); 580 581 glEnable(GL_LIGHTING); 582 glEnable(GL_DEPTH_TEST);*/ 583 629 584 glDisable(GL_POLYGON_OFFSET_FILL); 630 glDisable(GL_LIGHTING);631 585 } 632 586 … … 637 591 //const Vector3 dir(0, 0, -1); 638 592 639 cout << "dir: " << dir << endl;640 593 mShadowCam->SetDirection(dir); 641 594 … … 664 617 665 618 mLightProjView = lightView * lightProj; 666 dummyMat = mLightProjView;667 619 668 620 DEL_PTR(lightPoly); … … 682 634 renderer->RenderScene(); 683 635 636 684 637 glMatrixMode(GL_MODELVIEW); 685 638 glPopMatrix(); -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ShadowMapping.h
r2942 r2943 87 87 Vector3 GetProjViewDir(const Matrix4x4 &lightSpace, const VertexArray &pts) const; 88 88 89 static void DrawPoly(Polyhedron *poly, const Vector3 &color, const Vector3 &color2);90 89 91 90 /** Internal shador render method. -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp
r2942 r2943 100 100 static int winHeight = 768; 101 101 102 const float shadowSize = 4096; 102 //const float shadowSize = 4096; 103 const float shadowSize = 2048; 103 104 104 105 static float winAspectRatio = 1.0f; … … 922 923 923 924 // the scene is rendered withouth any shading 925 glShadeModel(GL_FLAT); 926 924 927 glDisable(GL_LIGHTING); 925 928 … … 934 937 { 935 938 shadowChanged = false; 939 940 //glEnable(GL_MULTISAMPLE_ARB); 936 941 937 942 cgGLDisableProfile(RenderState::sCgFragmentProfile); … … 944 949 BvhNode::SetCurrentState(1); 945 950 951 state.SetUseAlphaToCoverage(false); 952 946 953 // the scene is rendered withouth any shading 947 954 shadowMap->ComputeShadowMap(shadowTraverser, matProjectionView); 955 956 state.SetUseAlphaToCoverage(true); 948 957 949 958 // change back state … … 1025 1034 { 1026 1035 glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); 1036 glShadeModel(GL_SMOOTH); 1037 1027 1038 RenderVisibleObjects(); 1028 1039 } -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg
r2942 r2943 137 137 if (amb < 0.9f) // hack: prevent shadowing the sky 138 138 { 139 const float x = 0.1f; 139 // base lighting 140 const float x = 0.4f; 140 141 OUT.color *= x + (1.0f - x) * (1.0f - d); 141 142 }
Note: See TracChangeset
for help on using the changeset viewer.