- Timestamp:
- 01/16/06 19:33:48 (19 years ago)
- Location:
- trunk/VUT/GtpVisibilityPreprocessor
- Files:
-
- 2 added
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/VUT/GtpVisibilityPreprocessor/scripts/Preprocessor.vcproj
r527 r544 348 348 </File> 349 349 <File 350 RelativePath="..\src\Tetrahedron3.cpp"> 351 </File> 352 <File 353 RelativePath="..\src\Tetrahedron3.h"> 354 </File> 355 <File 350 356 RelativePath="..\src\Triangle3.cpp"> 351 357 </File> -
trunk/VUT/GtpVisibilityPreprocessor/scripts/default.env
r543 r544 303 303 #maxAccRayLength 100 304 304 305 maxViewCells 5001305 maxViewCells 6001 306 306 307 307 # used for pvs criterium … … 323 323 PostProcess { 324 324 maxCostRatio 0.001 325 minViewCells 1000325 minViewCells 2000 326 326 useRaysForMerge true 327 327 } -
trunk/VUT/GtpVisibilityPreprocessor/src/GlRenderer.cpp
r542 r544 582 582 BeamSampleStatistics &stat) 583 583 { 584 // create beam mesh if not already doen 585 //TODO: should this be done here? 586 587 beam.CreateMesh(2.0f * Magnitude(mSceneGraph->GetBox().Diagonal())); 588 589 // TODO: should not be done every time here 584 // TODO: should be moved out of here (not to be done every time) 590 585 // only back faces are interesting for the depth pass 591 586 glShadeModel(GL_FLAT); 592 587 glDisable(GL_LIGHTING); 588 593 589 // needed to kill the fragments for the front buffer 594 590 glEnable(GL_ALPHA_TEST); … … 605 601 // The viewpoints could actually be generated outside of the bounding box which 606 602 // would distribute the 'efective viewpoints' of the object surface and thus 607 // with a few viewpoints better sample the vipoint space.... 608 //TODO: remove 603 // with a few viewpoints better sample the viewpoint space.... 604 605 //TODO: comment in 609 606 //int viewPointSamples = sqrt((float)desiredSamples); 610 607 int viewPointSamples = max(desiredSamples / (GetWidth() * GetHeight()), 1); … … 640 637 // in order that thios scheme is working well the gpu render buffer should run in a separate 641 638 // thread than the cpu sampler, which would not be such a big problem.... 639 640 // disable alpha test again 641 glDisable(GL_ALPHA_TEST); 642 642 } 643 643 … … 650 650 { 651 651 // 1. setup the view port to match the desired samples 652 glViewport(0, 0, GetWidth(), GetHeight());652 glViewport(0, 0, samples, samples); 653 653 654 654 // 2. setup the projection matrix and view matrix to match the viewpoint + beam.mDirBox 655 655 SetupProjectionForViewPoint(viewPoint, beam, sourceObject); 656 656 657 657 658 // 3. reset z-buffer to 0 and render the source object for the beam 658 659 // with glCullFace(Enabled) and glFrontFace(GL_CW) 659 // save result to depth map 660 661 // front depth buffer must bé initialised to 0 660 // save result to the front depth map 661 // the front depth map holds ray origins 662 663 664 // front depth buffer must be initialised to 0 662 665 float clearDepth; 666 663 667 glGetFloatv(GL_DEPTH_CLEAR_VALUE, &clearDepth); 664 668 glClearDepth(0.0f); 665 666 667 669 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); 670 671 668 672 //glFrontFace(GL_CW); 669 673 glEnable(GL_CULL_FACE); … … 676 680 glStencilFunc(GL_ALWAYS, 0x1, 0x1); 677 681 glStencilOp(GL_REPLACE, GL_REPLACE, GL_REPLACE); 682 678 683 679 684 #if 0 … … 694 699 695 700 #endif 701 702 // copy contents of the front depth buffer into depth texture 703 glBindTexture(GL_TEXTURE_2D, frontDepthMap); 704 glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, depthMapSize, depthMapSize); 705 706 696 707 // reset clear function 697 708 glClearDepth(clearDepth); 698 709 699 // copy contents of depth buffer into depth texture 700 // depth buffer holds ray origins 701 glBindTexture(GL_TEXTURE_2D, frontDepthMap); 702 glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, depthMapSize, depthMapSize); 703 704 705 #if 0 706 // only the samples which are inside the beam AND on the source object 707 // should be considered => only where stencil == 2 710 711 712 // 4. set up the termination depth buffer (= standard depth buffer) 713 // only rays which have non-zero entry in the origin buffer are valid since 714 // they realy start on the object surface (this is tagged by setting a 715 // stencil buffer bit at step 3). 716 717 glStencilFunc(GL_EQUAL, 0x1, 0x1); 718 glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP); 719 708 720 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 709 glStencilFunc(GL_ALWAYS, 0x2, 0x2);710 glStencilOp(GL_INCR, GL_INCR, GL_INCR);711 712 // render back face of frustum beam713 RenderMesh(beam.mMesh);714 #endif715 716 717 // 4. set back to normal rendering and clear the ray termination depth buffer718 // only rays which have non-zero entry in the origin buffer are valid since719 // they realy start on the object surface (this can also be tagged by setting a720 // stencil buffer bit at step 3)721 722 //glDisable(GL_STENCIL_TEST);723 glEnable(GL_STENCIL_TEST);724 glStencilFunc(GL_EQUAL, 0x1, 0x1);725 //glStencilFunc(GL_EQUAL, 0x2, 0x2);726 glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);727 728 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);729 glColorMask(1, 1, 1, 1);730 721 glDepthMask(1); 722 731 723 glEnable(GL_DEPTH_TEST); 732 //glDisable(GL_STENCIL_TEST);724 733 725 glEnable(GL_CULL_FACE); 734 726 glCullFace(GL_BACK); 735 727 736 737 // 5. render all objects inside the beam using id based false color 738 // (objects can be compiled to a gl list now so that subsequent rendering for 739 // this beam is fast - the same hold for step 3) 740 728 // setup front depth buffer 729 glEnable(GL_TEXTURE_2D); 730 731 // bind pixel shader implementing the front depth buffer functionality 732 cgGLBindProgram(sCgFragmentProgram); 733 cgGLEnableProfile(sCgFragmentProfile); 734 735 736 // 5. render all objects inside the beam 737 // we can use id based false color to read them back for gaining the pvs 738 739 glColorMask(1, 1, 1, 1); 740 741 742 // if objects not stored in beam => extract objects 741 743 if (beam.mFlags & !Beam::STORE_OBJECTS) 742 744 { … … 750 752 } 751 753 752 // list of objects intersected by the frustum 754 755 // (objects can be compiled to a gl list now so that subsequent rendering for 756 // this beam is fast - the same hold for step 3) 757 // Afterwards we have two depth buffers defining the ray origin and termination 758 759 753 760 #if 0 754 761 static int glObjList = -1; … … 761 768 for (it = beam.mObjects.begin(); it != it_end; ++ it) 762 769 { 770 // render all objects except the source object 763 771 if (*it != sourceObject) 764 772 RenderIntersectable(*it); … … 767 775 glEndList(); 768 776 } 777 769 778 glCallList(glObjList); 770 779 #else … … 772 781 for (it = beam.mObjects.begin(); it != it_end; ++ it) 773 782 { 783 // render all objects except the source object 774 784 if (*it != sourceObject) 775 785 RenderIntersectable(*it); 776 786 } 777 787 #endif 778 779 780 // 6. Now we have a two depth buffers defining the ray origin and termination 781 782 783 // bind depth texture 784 glEnable(GL_TEXTURE_2D); 785 786 // bind depth cull pixel shader 787 cgGLBindProgram(sCgFragmentProgram); 788 cgGLEnableProfile(sCgFragmentProfile); 789 790 // 7. Use occlusion queries for all viewcell meshes associated with the beam -> 791 // a fragment passes if the corresponding stencil fragment is set and its depth is 792 // between origin and termination buffer 788 789 790 791 // 6. Use occlusion queries for all viewcell meshes associated with the beam -> 792 // a fragment passes if the corresponding stencil fragment is set and its depth is 793 // between origin and termination buffer 793 794 794 795 // create new queries if necessary 795 796 GenQueries((int)beam.mViewCells.size()); 796 797 797 // now check whether any backfacing polygon would pass the depth test? 798 //matt: should check both back /front facing because of dual depth buffer 799 //and danger of cutting the near plane with front facing polys. 798 // check whether any backfacing polygon would pass the depth test? 799 // matt: should check both back /front facing because of dual depth buffer 800 // and danger of cutting the near plane with front facing polys. 801 800 802 glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE); 801 803 glDepthMask(GL_FALSE); 802 804 glDisable(GL_CULL_FACE); 805 803 806 804 807 ViewCellContainer::const_iterator vit, vit_end = beam.mViewCells.end(); … … 815 818 } 816 819 820 821 817 822 // at this point, if possible, go and do some other computation 823 824 825 826 // 7. The number of visible pixels is the number of sample rays which see the source 827 // object from the corresponding viewcell -> remember these values for later update 828 // of the viewcell pvs - or update immediately? 818 829 819 830 queryIdx = 0; 820 831 unsigned int pixelCount; 821 822 // 8. The number of visible pixels is the number of sample rays which see the source823 // object from the corresponding viewcell -> remember these values for later update824 // of the viewcell pvs - or update immediately?825 832 826 833 for (vit = beam.mViewCells.begin(); vit != vit_end; ++ vit) … … 835 842 836 843 837 // In general it is not neccessary to remember to extract all the rays cast. I hope it 844 // 8. Copmpute rendering statistics 845 // In general it is not neccessary to remember to extract all the rays cast. I hope it 838 846 // would be sufficient to gain only the intergral statistics about the new contributions 839 847 // and so the rss tree would actually store no new rays (only the initial ones) … … 846 854 stat.pvsSize = ComputePvs(beam.mObjects, pvsObj); 847 855 848 856 // to gain ray source and termination 857 // copy contents of ray termination buffer into depth texture 858 // and compare with ray source buffer 849 859 #if 0 850 // copy contents of back depth buffer into depth texture851 // depth buffer holds ray origins 860 VssRayContainer rays; 861 852 862 glBindTexture(GL_TEXTURE_2D, backDepthMap); 853 863 glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, depthMapSize, depthMapSize); 864 865 ComputeRays(Intersectable *sourceObj, rays); 866 854 867 #endif 855 // reset state 868 869 870 871 //-- cleanup 872 873 874 // reset gl state 856 875 glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); 857 876 glDepthMask(GL_TRUE); … … 861 880 glDisable(GL_TEXTURE_2D); 862 881 863 // remove objects again882 // remove objects from beam 864 883 if (beam.mFlags & !Beam::STORE_OBJECTS) 865 884 beam.mObjects.clear(); -
trunk/VUT/GtpVisibilityPreprocessor/src/Polygon3.cpp
r538 r544 120 120 v += CrossProd(mVertices[i], mVertices[i+1]); 121 121 122 //Debug << "area2: " << 0.5f * fabs(DotProd(GetNormal(), v)) << endl; 123 return 0.5f * fabs(DotProd(GetNormal(), v)); 122 return 0.5f * fabs(DotProd(GetNormal(), v)); 124 123 } 125 124 -
trunk/VUT/GtpVisibilityPreprocessor/src/Triangle3.h
r191 r544 37 37 38 38 float GetSpatialAngle(const Vector3 &point) const; 39 40 float GetArea() const { 41 Vector3 v1=mVertices[0]-mVertices[1], v2=mVertices[2]-mVertices[1]; 42 return 0.5f * Magnitude(CrossProd(v2, v1)); 43 } 39 44 }; 40 45 -
trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.cpp
r535 r544 9 9 #include "AxisAlignedBox3.h" 10 10 #include "Triangle3.h" 11 #include "Tetrahedron3.h" 11 12 12 13 #include <stack> … … 2549 2550 2550 2551 2552 float BspNodeGeometry::GetVolume() const 2553 { 2554 //-- compute volume using tetrahedralization of the geometry 2555 // and adding the volume of the single tetrahedrons 2556 float volume = 0; 2557 const float f = 1.0f / 6.0f; 2558 2559 PolygonContainer::const_iterator pit, pit_end = mPolys.end(); 2560 2561 for (pit = mPolys.begin(); pit != pit_end; ++ pit) 2562 { 2563 Polygon3 *poly = *pit; 2564 const Vector3 v = poly->mVertices[0]; 2565 2566 for (int i = 1; i < (int)poly->mVertices.size() - 1; ++ i) 2567 { 2568 volume += f * (DotProd(v, 2569 CrossProd(poly->mVertices[i], poly->mVertices[i + 1]))); 2570 } 2571 } 2572 2573 Debug << "volume: " << volume << endl; 2574 return volume; 2575 } 2576 2577 2578 Vector3 BspNodeGeometry::ComputeMassCenter() const 2579 { 2580 int n = 0; 2581 2582 Vector3 center(0,0,0); 2583 2584 PolygonContainer::const_iterator pit, pit_end = mPolys.end(); 2585 2586 for (pit = mPolys.begin(); pit != pit_end; ++ pit) 2587 { 2588 Polygon3 *poly = *pit; 2589 2590 VertexContainer::const_iterator vit, vit_end = poly->mVertices.end(); 2591 2592 for(vit = poly->mVertices.begin(); vit != vit_end; ++ vit) 2593 { 2594 center += *vit; 2595 ++ n; 2596 } 2597 } 2598 2599 return center / (float)n; 2600 } 2601 2602 2551 2603 void BspNodeGeometry::AddToMesh(Mesh &mesh) 2552 2604 { -
trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.h
r535 r544 35 35 float GetArea() const; 36 36 37 float GetVolume() const; 38 37 39 /** Computes new front and back geometry based on the old cell 38 40 geometry and a new split plane … … 57 59 void AddToMesh(Mesh &mesh); 58 60 61 /** Computes mass center of bsp node geometry. 62 */ 63 Vector3 ComputeMassCenter() const; 59 64 /** The polygons the geometry consists of. 60 65 */ -
trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellsManager.cpp
r542 r544 2017 2017 2018 2018 // check if new view cells turned invalid 2019 mVspBspTree-> CheckValidy();2019 mVspBspTree->ValidateTree(); 2020 2020 ResetViewCells(); 2021 2021 -
trunk/VUT/GtpVisibilityPreprocessor/src/VspBspTree.cpp
r543 r544 1606 1606 1607 1607 1608 1609 void VspBspTree::CheckValidy() 1608 void VspBspTree::ValidateTree() 1610 1609 { 1611 1610 stack<BspNode *> nodeStack; … … 1635 1634 BspLeaf *l = viewCell->mLeaves.back(); 1636 1635 l->SetTreeValid(false); 1636 ++ mStat.invalidLeaves; 1637 1637 PropagateUpValidity(l); 1638 1638 … … 2697 2697 startTime = GetTime(); 2698 2698 2699 int nViewCells = /*mergeStats.nodes*/mStat.Leaves() - mStat.invalidLeaves;2699 int nViewCells = mStat.Leaves() - mStat.invalidLeaves; 2700 2700 2701 2701 //-- use priority queue to merge leaf pairs -
trunk/VUT/GtpVisibilityPreprocessor/src/VspBspTree.h
r542 r544 308 308 if not valid, sets regions invalid and deletes view cell. 309 309 */ 310 void CheckValidy();310 void ValidateTree(); 311 311 312 312 protected:
Note: See TracChangeset
for help on using the changeset viewer.