Changeset 544 for trunk/VUT


Ignore:
Timestamp:
01/16/06 19:33:48 (19 years ago)
Author:
mattausch
Message:
 
Location:
trunk/VUT/GtpVisibilityPreprocessor
Files:
2 added
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/VUT/GtpVisibilityPreprocessor/scripts/Preprocessor.vcproj

    r527 r544  
    348348                        </File> 
    349349                        <File 
     350                                RelativePath="..\src\Tetrahedron3.cpp"> 
     351                        </File> 
     352                        <File 
     353                                RelativePath="..\src\Tetrahedron3.h"> 
     354                        </File> 
     355                        <File 
    350356                                RelativePath="..\src\Triangle3.cpp"> 
    351357                        </File> 
  • trunk/VUT/GtpVisibilityPreprocessor/scripts/default.env

    r543 r544  
    303303                #maxAccRayLength        100 
    304304                 
    305                 maxViewCells            5001 
     305                maxViewCells            6001 
    306306                 
    307307                # used for pvs criterium 
     
    323323        PostProcess { 
    324324                maxCostRatio 0.001 
    325                 minViewCells 1000 
     325                minViewCells 2000 
    326326                useRaysForMerge true 
    327327        } 
  • trunk/VUT/GtpVisibilityPreprocessor/src/GlRenderer.cpp

    r542 r544  
    582582                                                                                           BeamSampleStatistics &stat) 
    583583{ 
    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) 
    590585        // only back faces are interesting for the depth pass 
    591586        glShadeModel(GL_FLAT); 
    592587        glDisable(GL_LIGHTING); 
     588 
    593589        // needed to kill the fragments for the front buffer 
    594590        glEnable(GL_ALPHA_TEST); 
     
    605601        // The viewpoints could actually be generated outside of the bounding box which 
    606602        // 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 
    609606        //int viewPointSamples = sqrt((float)desiredSamples); 
    610607        int viewPointSamples = max(desiredSamples / (GetWidth() * GetHeight()), 1); 
     
    640637        // in order that thios scheme is working well the gpu render buffer should run in a separate 
    641638        // thread than the cpu sampler, which would not be such a big problem.... 
     639 
     640        // disable alpha test again 
     641        glDisable(GL_ALPHA_TEST); 
    642642} 
    643643 
     
    650650{ 
    651651    // 1. setup the view port to match the desired samples 
    652         glViewport(0, 0, GetWidth(), GetHeight()); 
     652        glViewport(0, 0, samples, samples); 
    653653 
    654654        // 2. setup the projection matrix and view matrix to match the viewpoint + beam.mDirBox 
    655655        SetupProjectionForViewPoint(viewPoint, beam, sourceObject); 
    656656 
     657 
    657658        // 3. reset z-buffer to 0 and render the source object for the beam 
    658659        //    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 
    662665        float clearDepth; 
     666         
    663667        glGetFloatv(GL_DEPTH_CLEAR_VALUE, &clearDepth); 
    664668        glClearDepth(0.0f); 
    665          
    666  
    667669        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); 
     670 
     671 
    668672        //glFrontFace(GL_CW); 
    669673        glEnable(GL_CULL_FACE); 
     
    676680        glStencilFunc(GL_ALWAYS, 0x1, 0x1); 
    677681        glStencilOp(GL_REPLACE, GL_REPLACE, GL_REPLACE); 
     682 
    678683 
    679684#if 0 
     
    694699 
    695700#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 
    696707        // reset clear function 
    697708        glClearDepth(clearDepth); 
    698709 
    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 
    708720        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 beam 
    713         RenderMesh(beam.mMesh); 
    714 #endif 
    715  
    716  
    717         // 4. set back to normal rendering and clear the ray termination depth buffer 
    718         //    only rays which have non-zero entry in the origin buffer are valid since 
    719         //    they realy start on the object surface (this can also be tagged by setting a 
    720         //    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); 
    730721        glDepthMask(1); 
     722 
    731723        glEnable(GL_DEPTH_TEST); 
    732         //glDisable(GL_STENCIL_TEST);    
     724                 
    733725        glEnable(GL_CULL_FACE); 
    734726        glCullFace(GL_BACK); 
    735727 
    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 
    741743        if (beam.mFlags & !Beam::STORE_OBJECTS) 
    742744        { 
     
    750752        } 
    751753 
    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 
    753760#if 0 
    754761        static int glObjList = -1;  
     
    761768                for (it = beam.mObjects.begin(); it != it_end; ++ it) 
    762769                { 
     770                        // render all objects except the source object 
    763771                        if (*it != sourceObject) 
    764772                                RenderIntersectable(*it); 
     
    767775                glEndList(); 
    768776        } 
     777 
    769778        glCallList(glObjList); 
    770779#else 
     
    772781        for (it = beam.mObjects.begin(); it != it_end; ++ it) 
    773782        {        
     783                // render all objects except the source object 
    774784                if (*it != sourceObject) 
    775785                        RenderIntersectable(*it); 
    776786        } 
    777787#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 
    793794 
    794795        // create new queries if necessary 
    795796        GenQueries((int)beam.mViewCells.size()); 
    796797 
    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         
    800802        glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE); 
    801803        glDepthMask(GL_FALSE); 
    802804        glDisable(GL_CULL_FACE); 
     805 
    803806   
    804807        ViewCellContainer::const_iterator vit, vit_end = beam.mViewCells.end(); 
     
    815818        } 
    816819 
     820 
     821 
    817822        // 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? 
    818829 
    819830        queryIdx = 0; 
    820831        unsigned int pixelCount; 
    821  
    822         // 8. The number of visible pixels is the number of sample rays which see the source 
    823         //    object from the corresponding viewcell -> remember these values for later update 
    824         //   of the viewcell pvs - or update immediately? 
    825832 
    826833        for (vit = beam.mViewCells.begin(); vit != vit_end; ++ vit) 
     
    835842         
    836843 
    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 
    838846        // would be sufficient to gain only the intergral statistics about the new contributions 
    839847        // and so the rss tree would actually store no new rays (only the initial ones) 
     
    846854        stat.pvsSize = ComputePvs(beam.mObjects, pvsObj); 
    847855         
    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 
    849859#if 0 
    850         // copy contents of back depth buffer into depth texture 
    851         // depth buffer holds ray origins 
     860        VssRayContainer rays; 
     861 
    852862        glBindTexture(GL_TEXTURE_2D, backDepthMap);      
    853863        glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, depthMapSize, depthMapSize); 
     864 
     865        ComputeRays(Intersectable *sourceObj, rays); 
     866 
    854867#endif 
    855         // reset state 
     868 
     869 
     870 
     871        //-- cleanup 
     872 
     873 
     874        // reset gl state 
    856875        glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); 
    857876        glDepthMask(GL_TRUE); 
     
    861880        glDisable(GL_TEXTURE_2D); 
    862881 
    863         // remove objects again 
     882        // remove objects from beam 
    864883        if (beam.mFlags & !Beam::STORE_OBJECTS) 
    865884                beam.mObjects.clear(); 
  • trunk/VUT/GtpVisibilityPreprocessor/src/Polygon3.cpp

    r538 r544  
    120120                v += CrossProd(mVertices[i], mVertices[i+1]); 
    121121     
    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)); 
    124123} 
    125124 
  • trunk/VUT/GtpVisibilityPreprocessor/src/Triangle3.h

    r191 r544  
    3737 
    3838  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  } 
    3944}; 
    4045 
  • trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.cpp

    r535 r544  
    99#include "AxisAlignedBox3.h" 
    1010#include "Triangle3.h" 
     11#include "Tetrahedron3.h" 
    1112 
    1213#include <stack> 
     
    25492550 
    25502551 
     2552float 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 
     2578Vector3 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 
    25512603void BspNodeGeometry::AddToMesh(Mesh &mesh) 
    25522604{ 
  • trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.h

    r535 r544  
    3535        float GetArea() const; 
    3636         
     37        float GetVolume() const; 
     38 
    3739        /** Computes new front and back geometry based on the old cell  
    3840                geometry and a new split plane 
     
    5759        void AddToMesh(Mesh &mesh); 
    5860 
     61        /** Computes mass center of bsp node geometry. 
     62        */ 
     63        Vector3 ComputeMassCenter() const; 
    5964        /** The polygons the geometry consists of. 
    6065        */ 
  • trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellsManager.cpp

    r542 r544  
    20172017 
    20182018        // check if new view cells turned invalid 
    2019         mVspBspTree->CheckValidy(); 
     2019        mVspBspTree->ValidateTree(); 
    20202020        ResetViewCells(); 
    20212021 
  • trunk/VUT/GtpVisibilityPreprocessor/src/VspBspTree.cpp

    r543 r544  
    16061606 
    16071607 
    1608  
    1609 void VspBspTree::CheckValidy() 
     1608void VspBspTree::ValidateTree() 
    16101609{ 
    16111610        stack<BspNode *> nodeStack; 
     
    16351634                                                BspLeaf *l = viewCell->mLeaves.back(); 
    16361635                                                l->SetTreeValid(false); 
     1636                                                ++ mStat.invalidLeaves; 
    16371637                                                PropagateUpValidity(l); 
    16381638 
     
    26972697        startTime = GetTime(); 
    26982698 
    2699         int nViewCells = /*mergeStats.nodes*/ mStat.Leaves() - mStat.invalidLeaves; 
     2699        int nViewCells = mStat.Leaves() - mStat.invalidLeaves; 
    27002700 
    27012701        //-- use priority queue to merge leaf pairs 
  • trunk/VUT/GtpVisibilityPreprocessor/src/VspBspTree.h

    r542 r544  
    308308                if not valid, sets regions invalid and deletes view cell. 
    309309        */ 
    310         void CheckValidy(); 
     310        void ValidateTree(); 
    311311 
    312312protected: 
Note: See TracChangeset for help on using the changeset viewer.