Changeset 2951
- Timestamp:
- 09/16/08 12:38:36 (16 years ago)
- Location:
- GTP/trunk/App/Demos/Vis/FriendlyCulling
- Files:
-
- 2 added
- 13 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/App/Demos/Vis/FriendlyCulling/FriendlyCulling.vcproj
r2946 r2951 268 268 </File> 269 269 <File 270 RelativePath=".\src\MotionPath.cpp" 271 > 272 </File> 273 <File 274 RelativePath=".\src\MotionPath.h" 275 > 276 </File> 277 <File 270 278 RelativePath=".\src\PerformanceGraph.cpp" 271 279 > -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/AxisAlignedBox3.cpp
r2947 r2951 3 3 #include "Polygon3.h" 4 4 #include "Polyhedron.h" 5 #include "Triangle3.h" 5 6 6 7 #include <cassert> … … 1400 1401 } 1401 1402 1402 } 1403 1403 1404 void AxisAlignedBox3::Triangulate(std::vector<Triangle3> &triangles) const 1405 { 1406 Triangle3 tri; 1407 1408 tri.mVertices[0] = Vector3(mMin.x, mMax.y ,mMin.z); 1409 tri.mVertices[1] = Vector3(mMin.x, mMax.y, mMax.z); 1410 tri.mVertices[2] = Vector3(mMin.x, mMin.y, mMax.z); 1411 1412 triangles.push_back(tri); 1413 1414 tri.mVertices[0] = Vector3(mMin.x, mMin.y, mMax.z); 1415 tri.mVertices[1] = Vector3(mMin.x, mMin.y, mMin.z); 1416 tri.mVertices[2] = Vector3(mMin.x, mMax.y ,mMin.z); 1417 1418 triangles.push_back(tri); 1419 1420 ////////////////////////////////////// 1421 1422 tri.mVertices[0] = Vector3(mMax.x, mMax.y, mMax.z); 1423 tri.mVertices[1] = Vector3(mMax.x, mMax.y, mMin.z); 1424 tri.mVertices[2] = Vector3(mMax.x, mMin.y, mMin.z); 1425 1426 triangles.push_back(tri); 1427 1428 tri.mVertices[0] = Vector3(mMax.x, mMin.y, mMin.z); 1429 tri.mVertices[1] = Vector3(mMax.x, mMin.y, mMax.z); 1430 tri.mVertices[2] = Vector3(mMax.x, mMax.y, mMax.z); 1431 1432 triangles.push_back(tri); 1433 1434 1435 ////////////////////////////////////// 1436 1437 tri.mVertices[0] = Vector3(mMin.x, mMin.y, mMax.z); 1438 tri.mVertices[1] = Vector3(mMax.x, mMin.y, mMax.z); 1439 tri.mVertices[2] = Vector3(mMax.x, mMin.y ,mMin.z); 1440 1441 triangles.push_back(tri); 1442 1443 tri.mVertices[0] = Vector3(mMax.x, mMin.y ,mMin.z); 1444 tri.mVertices[1] = Vector3(mMin.x, mMin.y, mMin.z); 1445 tri.mVertices[2] = Vector3(mMin.x, mMin.y, mMax.z); 1446 1447 triangles.push_back(tri); 1448 1449 1450 ////////////////////////////////////// 1451 1452 tri.mVertices[0] = Vector3(mMax.x, mMax.y, mMax.z); 1453 tri.mVertices[1] = Vector3(mMin.x, mMax.y, mMax.z); 1454 tri.mVertices[2] = Vector3(mMin.x, mMax.y, mMin.z); 1455 1456 triangles.push_back(tri); 1457 1458 tri.mVertices[0] = Vector3(mMin.x, mMax.y, mMin.z); 1459 tri.mVertices[1] = Vector3(mMax.x, mMax.y, mMin.z); 1460 tri.mVertices[2] = Vector3(mMax.x, mMax.y, mMax.z); 1461 1462 triangles.push_back(tri); 1463 1464 1465 ////////////////////////////////////// 1466 1467 tri.mVertices[0] = Vector3(mMax.x, mMin.y, mMin.z); 1468 tri.mVertices[1] = Vector3(mMax.x, mMax.y, mMin.z); 1469 tri.mVertices[2] = Vector3(mMin.x, mMax.y, mMin.z); 1470 1471 triangles.push_back(tri); 1472 1473 tri.mVertices[0] = Vector3(mMin.x, mMax.y, mMin.z); 1474 tri.mVertices[1] = Vector3(mMin.x, mMin.y, mMin.z); 1475 tri.mVertices[2] = Vector3(mMax.x, mMin.y, mMin.z); 1476 1477 triangles.push_back(tri); 1478 1479 1480 ////////////////////////////////////// 1481 1482 tri.mVertices[0] = Vector3(mMax.x, mMax.y, mMax.z); 1483 tri.mVertices[1] = Vector3(mMax.x, mMin.y, mMax.z); 1484 tri.mVertices[2] = Vector3(mMin.x, mMin.y, mMax.z); 1485 1486 triangles.push_back(tri); 1487 1488 tri.mVertices[0] = Vector3(mMin.x, mMin.y, mMax.z); 1489 tri.mVertices[1] = Vector3(mMin.x, mMax.y, mMax.z); 1490 tri.mVertices[2] = Vector3(mMax.x, mMax.y, mMax.z); 1491 1492 triangles.push_back(tri); 1493 } 1494 1495 1496 } 1497 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/AxisAlignedBox3.h
r2947 r2951 149 149 150 150 // Six faces are distuinguished by their name. 151 enum EFaces {ID_Back = 0, 152 ID_Left = 1,153 ID_Bottom = 2,154 ID_Front = 3,155 ID_Right = 4,156 ID_Top = 5};151 enum EFaces {ID_Back = 0, 152 ID_Left = 1, 153 ID_Bottom = 2, 154 ID_Front = 3, 155 ID_Right = 4, 156 ID_Top = 5}; 157 157 158 158 // Writes a brief description of the object, indenting by the given … … 217 217 */ 218 218 void ExtractPolygons(PolygonContainer &polys) const; 219 /** Returns triangle representation of this box. 220 */ 221 void Triangulate(std::vector<Triangle3> &triangles) const; 222 219 223 220 224 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Bvh.cpp
r2947 r2951 290 290 } 291 291 else 292 { 292 { 293 293 BvhInterior *interior = static_cast<BvhInterior *>(node); 294 294 … … 300 300 301 301 302 SceneEntity **Bvh::GetGeometry(BvhNode *node, int &geometrySize) 302 SceneEntity **Bvh::GetGeometry(BvhNode *node, int &geometrySize) const 303 303 { 304 304 geometrySize = node->CountPrimitives(); … … 398 398 { 399 399 return node->GetBox().GetMaxDistance(sNearPlane); 400 401 float maxDist = .0f; 402 403 int geometrySize; 404 SceneEntity **entities = GetGeometry(node, geometrySize); 405 406 for (int i = 0; i < geometrySize; ++ i) 407 { 408 SceneEntity *ent = entities[i]; 409 float dist = ent->GetTransformedBoundingBox().GetMaxDistance(sNearPlane); 410 411 if (dist > maxDist) maxDist = dist; 412 } 413 414 return maxDist; 400 415 } 401 416 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Bvh.h
r2947 r2951 492 492 /** Returns geometry by reference (faster). 493 493 */ 494 SceneEntity **GetGeometry(BvhNode *node, int &size) ;494 SceneEntity **GetGeometry(BvhNode *node, int &size) const; 495 495 496 496 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Geometry.h
r2842 r2951 20 20 public: 21 21 /** Constructor taking an array of triangles. 22 If delData is true, the vertex / normal / texture is deleted when 23 after it was transferred into a vbo 22 24 */ 23 25 Geometry(Vector3 *vertices, -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderTraverser.cpp
r2947 r2951 120 120 121 121 // store the visible entities for rendering in the second pass 122 if (mUseDepthPass) 123 mVisibleObjects.push_back(ent); 122 if (mUseDepthPass) mVisibleObjects.push_back(ent); 124 123 } 125 124 … … 148 147 { 149 148 mVisibleObjects.clear(); 149 mMaxVisibleDistance = .0f; 150 150 151 151 glEnableClientState(GL_VERTEX_ARRAY); 152 153 if (!mUseDepthPass) 154 glEnableClientState(GL_NORMAL_ARRAY); 152 if (!mUseDepthPass) glEnableClientState(GL_NORMAL_ARRAY); 155 153 156 154 ++ mFrameId; … … 160 158 mStats.Reset(); 161 159 mQueryHandler.ResetQueries(); 162 160 // add root node to queue 163 161 EnqueueNode(mBvh->GetRoot()); 164 162 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderTraverser.h
r2947 r2951 190 190 /// the objects found visible in current frame 191 191 SceneEntityContainer mVisibleObjects; 192 193 192 /// the maximal visible distance in the scene 194 193 float mMaxVisibleDistance; -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SceneEntityConverter.cpp
r2946 r2951 1 1 #include "SceneEntityConverter.h" 2 #include "SceneEntity.h" 3 #include "Geometry.h" 4 #include "Shape.h" 2 5 3 6 … … 7 10 namespace CHCDemoEngine 8 11 { 12 13 SceneEntity *SceneEntityConverter::ConvertBox(const AxisAlignedBox3 &box, 14 Material *mat, 15 Transform3 *trafo) 16 { 17 SceneEntity *ent = new SceneEntity(trafo); 18 19 vector<Triangle3> triangles; 20 21 box.Triangulate(triangles); 22 23 Vector3 *vertices = new Vector3[12]; 24 Vector3 *normals = new Vector3[12]; 25 26 for (size_t i = 0; i < triangles.size(); ++ i) 27 { 28 Triangle3 tri = triangles[i]; 29 30 vertices[i * 3 + 0] = tri.mVertices[0]; 31 vertices[i * 3 + 1] = tri.mVertices[1]; 32 vertices[i * 3 + 2] = tri.mVertices[2]; 33 34 Vector3 normal = tri.GetNormal(); 35 36 normals[i * 3 + 0] = normal; 37 normals[i * 3 + 1] = normal; 38 normals[i * 3 + 2] = normal; 39 } 40 41 42 Geometry *geom = new Geometry(vertices, normals, NULL, 12, true); 43 44 Shape *shape = new Shape(geom, mat, ent); 45 ent->AddShape(shape); 46 47 return ent; 9 48 } 49 50 51 } -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ShadowMapping.cpp
r2947 r2951 590 590 591 591 glDisable(GL_LIGHTING); 592 //glDisable(GL_TEXTURE_2D);593 592 glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE); 594 593 … … 658 657 { 659 658 const Vector3 dir = mLight->GetDirection(); 660 //const Vector3 dir(0, 0, -1);661 659 662 660 mShadowCam->SetDirection(dir); … … 692 690 glMatrixMode(GL_MODELVIEW); 693 691 glPushMatrix(); 694 glLoadIdentity(); 695 696 //glDisable(GL_CULL_FACE); 692 697 693 mShadowCam->SetupCameraView(); 698 694 … … 704 700 705 701 702 703 glMatrixMode(GL_PROJECTION); 704 glPopMatrix(); 705 706 706 glMatrixMode(GL_MODELVIEW); 707 707 glPopMatrix(); 708 708 709 glMatrixMode(GL_PROJECTION);710 glPopMatrix();711 712 709 713 710 glDisable(GL_POLYGON_OFFSET_FILL); -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Transform3.cpp
r2950 r2951 28 28 cgGLSetMatrixParameterfc(sModelMatrixParam, (const float *)mMatrix->x); 29 29 } 30 else31 {30 // else 31 // { 32 32 glPushMatrix(); 33 33 glMultMatrixf((float *)mMatrix->x); 34 }34 // } 35 35 } 36 36 … … 45 45 cgGLSetMatrixParameterfc(sModelMatrixParam, (const float *)identity.x); 46 46 } 47 else48 {47 // else 48 // { 49 49 glPopMatrix(); 50 }50 // } 51 51 } 52 52 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp
r2950 r2951 228 228 inline float KeyRotationAngle() { return keyRotation * elapsedTime * 1e-3f; } 229 229 inline float KeyShift() { return keyForwardMotion * elapsedTime * 1e-3f; } 230 230 231 void InitFBO(); 231 void RenderShadowMap(); 232 233 232 233 void RenderShadowMap(float newfar); 234 234 235 235 … … 516 516 517 517 cgGLSetParameter1f(sMaxDepthParamTex, MAX_DEPTH_CONST / farDist); 518 //Debug << "maxdepth: " << MAX_DEPTH_CONST / myfar << endl;519 518 } 520 519 else … … 557 556 558 557 // the diffuse color buffer 559 //fbo->AddColorBuffer(ColorBufferObject::BUFFER_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_MIPMAP_LINEAR, true);560 fbo->AddColorBuffer(ColorBufferObject::BUFFER_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_NEAREST, false);558 fbo->AddColorBuffer(ColorBufferObject::BUFFER_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_MIPMAP_LINEAR, true); 559 //fbo->AddColorBuffer(ColorBufferObject::BUFFER_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_NEAREST, false); 561 560 562 561 // the positions buffer 563 562 fbo->AddColorBuffer(ColorBufferObject::BUFFER_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_MIPMAP_LINEAR, true); 564 563 //fbo->AddColorBuffer(ColorBufferObject::BUFFER_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_NEAREST, false); 565 564 566 565 // the normals buffer 567 //fbo->AddColorBuffer(ColorBufferObject::BUFFER_UBYTE, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_NEAREST, false);568 566 fbo->AddColorBuffer(ColorBufferObject::BUFFER_FLOAT_16, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_NEAREST, false); 569 567 … … 592 590 void InitGLstate() 593 591 { 594 glClearColor( 1.0f, 1.0f, 1.0f, 1.0f);592 glClearColor(0.2f, 0.2f, 0.8f, 1.0f); 595 593 596 594 glPixelStorei(GL_UNPACK_ALIGNMENT, 1); … … 608 606 glEnable(GL_NORMALIZE); 609 607 610 //glEnable(GL_ALPHA_TEST);611 608 glDisable(GL_ALPHA_TEST); 612 glAlphaFunc(GL_GEQUAL, 0. 8f);609 glAlphaFunc(GL_GEQUAL, 0.5f); 613 610 614 611 glFrontFace(GL_CCW); … … 616 613 glEnable(GL_CULL_FACE); 617 614 618 //glDisable(GL_CULL_FACE);619 615 glDisable(GL_TEXTURE_2D); 620 616 … … 810 806 811 807 glMatrixMode(GL_MODELVIEW); 812 glLoadIdentity(); 813 808 814 809 // set up the camera view 815 810 camera->SetupCameraView(); … … 877 872 cgGLEnableProfile(RenderState::sCgFragmentProfile); 878 873 cgGLBindProgram(RenderState::sCgMrtFragmentProgram); 874 875 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 879 876 } 880 877 … … 919 916 } 920 917 918 919 // bring eye modelview matrix up-to-date 920 SetupEyeView(); 921 921 922 // hack 922 923 int oldRenderType = renderType; … … 957 958 cgGLDisableProfile(RenderState::sCgVertexProfile); 958 959 959 glClear(GL_DEPTH_BUFFER_BIT); 960 //glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 960 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 961 961 962 962 // the scene is rendered withouth any shading … … 988 988 989 989 if (showShadowMap && !renderLightView) 990 RenderShadowMap( );991 990 RenderShadowMap(camera->GetFar()); 991 992 992 //glPushAttrib(GL_VIEWPORT_BIT); 993 993 glViewport(0, 0, texWidth, texHeight); 994 994 995 995 InitDeferredRendering(); 996 996 997 // draw to 3 color buffers 997 998 glDrawBuffers(3, mrt); 998 999 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);1000 999 1001 1000 break; … … 1011 1010 // reset lod levels for current frame 1012 1011 LODLevel::InitFrame(camera->GetPosition()); 1013 1014 1015 // bring eye modelview matrix up-to-date1016 SetupEyeView();1017 1012 1018 1013 // set up lights … … 1362 1357 1363 1358 renderType = (renderType + 1) % RenderState::NUM_RENDER_TYPES; 1364 traverser->SetUseDepthPass((renderType == RenderState::DEPTH_PASS) || (renderType == RenderState::DEPTH_PASS ) || (renderType == RenderState::DEPTH_PASS_DEFERRED));1359 traverser->SetUseDepthPass((renderType == RenderState::DEPTH_PASS) || (renderType == RenderState::DEPTH_PASS_DEFERRED)); 1365 1360 1366 1361 break; 1367 1362 case GLUT_KEY_F8: 1368 1369 1363 useAdvancedShading = !useAdvancedShading; 1370 //shadingMethod = (DeferredRenderer::SHADING_METHOD)((shadingMethod + 1) % 2);1371 1364 1372 1365 break; … … 1899 1892 { 1900 1893 if (showShadowMap && !renderLightView) 1901 RenderShadowMap(); 1894 { 1895 float minVisibleDist = min(camera->GetFar(), traverser->GetMaxVisibleDistance()); 1896 RenderShadowMap(minVisibleDist); 1897 //cout << "far: " << camera->GetFar() << " min: " << traverser->GetMaxVisibleDistance() << endl; 1898 } 1899 glEnableClientState(GL_VERTEX_ARRAY); 1900 glEnableClientState(GL_NORMAL_ARRAY); 1902 1901 1903 1902 glDisable(GL_LIGHTING); 1904 1903 glViewport(0, 0, texWidth, texHeight); 1904 1905 1905 InitDeferredRendering(); 1906 1906 1907 1907 // draw to 3 color buffers 1908 1908 glDrawBuffers(3, mrt); 1909 glClear(GL_COLOR_BUFFER_BIT); 1909 1910 } 1910 1911 else … … 1912 1913 glShadeModel(GL_SMOOTH); 1913 1914 glEnable(GL_LIGHTING); 1915 1914 1916 state.SetRenderType(RenderState::FIXED); 1915 1917 } … … 1921 1923 state.SetUseAlphaToCoverage(true); 1922 1924 state.Reset(); 1923 1924 1925 1925 1926 //cout << "visible: " << (int)traverser->GetVisibleObjects().size() << endl; 1926 1927 … … 1936 1937 1937 1938 glDepthFunc(GL_LESS); 1938 state.SetUseAlphaToCoverage(true);1939 1939 1940 1940 PrintGLerror("visibleobjects"); … … 1956 1956 1957 1957 1958 void RenderShadowMap( )1958 void RenderShadowMap(float newfar) 1959 1959 { 1960 1960 cgGLDisableProfile(RenderState::sCgFragmentProfile); … … 1969 1969 1970 1970 // hack: temporarily change camera far plane 1971 //camera->SetFar(0.2f * Magnitude(bvh->GetBox().Diagonal()));1971 camera->SetFar(newfar); 1972 1972 1973 1973 // the scene is rendered withouth any shading -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/mrt.cg
r2949 r2951 34 34 35 35 float4 mypos: TEXCOORD3; 36 //float DEPTH;37 36 }; 38 37 … … 45 44 }; 46 45 46 #pragma position_invariant vtx 47 47 48 48 vtxout vtx(vtxin IN, … … 59 59 60 60 // transform the vertex position into eye space 61 OUT.position = mul(ModelViewProj, OUT.worldPos); 61 //OUT.position = mul(ModelViewProj, OUT.worldPos); 62 OUT.position = mul(glstate.matrix.mvp, IN.position); 62 63 63 64 OUT.normal = IN.normal; 64 65 65 66 OUT.mypos = OUT.position; 67 66 68 return OUT; 67 69 } … … 79 81 pix.col = (ambient + diffuse) * tex2D(tex, IN.texCoord.xy); 80 82 81 // save world position in second r t83 // save world position in second render target 82 84 pix.pos = IN.worldPos * maxDepth; 83 85 // save normal in third rt 84 //pix.norm.xyz = IN.normal * 0.5f + 0.5f;85 86 pix.norm.xyz = IN.normal; 86 87
Note: See TracChangeset
for help on using the changeset viewer.