Changeset 513


Ignore:
Timestamp:
01/11/06 01:35:44 (18 years ago)
Author:
mattausch
Message:
 
Location:
trunk/VUT/GtpVisibilityPreprocessor
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/VUT/GtpVisibilityPreprocessor/scripts/default.env

    r508 r513  
    180180        height 5.0 
    181181        maxViewCells 500 
    182         maxPvs 500 
     182        #percentage of total visible objects where pvs is considered invalid 
     183        maxPvsRatio 0.1 
    183184                 
    184185        PostProcess { 
  • trunk/VUT/GtpVisibilityPreprocessor/src/Beam.cpp

    r512 r513  
    55 
    66void 
    7 Beam::Construct(const  AxisAlignedBox3 &box, 
    8                                 const  AxisAlignedBox3 &dBox) 
     7Beam::Construct(const  AxisAlignedBox3 &box, const  AxisAlignedBox3 &dBox) 
    98{ 
    109  // the frustum is defined by set of negative halfspace described by mPlanes 
  • trunk/VUT/GtpVisibilityPreprocessor/src/Beam.h

    r512 r513  
    1818  // list of nodes intersected by the frustum 
    1919  vector<KdNode *> mKdNodes; 
    20   // lits of objects intersected by the frustum 
    21   vector<Intersectable *> mObjects; 
     20  // list of objects intersected by the frustum 
     21  ObjectContainer mObjects; 
     22  // view cells intersected by frustum 
     23  ViewCellContainer mViewCells; 
    2224 
    2325  // spatial box 
  • trunk/VUT/GtpVisibilityPreprocessor/src/GlRenderer.cpp

    r512 r513  
    66#include "Viewcell.h" 
    77#include "Beam.h" 
     8 
    89#include <GL/glext.h> 
    910#include <Cg/cg.h> 
     
    2122GLuint depthMap; 
    2223const int depthMapSize = 512; 
     24static vector<int> sQueries; 
    2325 
    2426GlRendererWidget *rendererWidget = NULL; 
     27 
    2528 
    2629#ifdef _WIN32 
     
    570573                                                                                           BeamSampleStatistics &stat) 
    571574{ 
    572         // TODO: should be out of here 
    573         cgGLBindProgram(sCgFragmentProgram); 
    574         cgGLEnableProfile(sCgFragmentProfile); 
     575        // TODO: should not be done every time here 
     576        // only back faces are interesting for the depth pass 
     577        glShadeModel(GL_FLAT); 
     578        glDisable(GL_LIGHTING); 
    575579 
    576580        // assumes that the beam is constructed and contains kd-tree nodes 
    577581        // and viewcells which it intersects 
    578          
    579  
    580582   
    581583   
     
    618620        // in order that thios scheme is working well the gpu render buffer should run in a separate 
    619621        // thread than the cpu sampler, which would not be such a big problem.... 
    620  
    621         cgGLDisableProfile(sCgFragmentProfile); 
    622622} 
    623623 
     
    631631        // 2. setup the projection matrix and view matrix to match the viewpoint + beam.mDirBox 
    632632   
    633         // 3. reset z-buffer to 0 and render the source object for the beam using 
    634         //    glDepthFunc(GL_GREATER) 
    635         //    and glCullFace(Enabled) and glFrontFace(GL_CW) 
    636         //    save result to depth buffer? 
    637          
    638         // bind ray origin depth buffer 
    639         glClear(GL_DEPTH); 
    640         glBindTexture(GL_TEXTURE_2D, depthMap); 
    641     glEnable(GL_TEXTURE_2D); 
    642  
    643         // compare with second depth buffer: should be done in pixel shader 
    644         /*glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE_ARB, GL_COMPARE_R_TO_TEXTURE); 
    645         glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC_ARB, GL_GREATER); 
    646         glTexParameteri(GL_TEXTURE_2D, GL_DEPTH_TEXTURE_MODE_ARB, GL_INTENSITY); 
    647         */ 
    648  
     633        // 3. reset z-buffer to 0 and render the source object for the beam 
     634        //    with glCullFace(Enabled) and glFrontFace(GL_CW) 
     635        //    save result to depth map 
     636        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); 
     637        glEnable(GL_CULL_FACE); 
     638        glEnable(GL_STENCIL_TEST); 
     639        glCullFace(GL_FRONT); 
     640        glColorMask(0, 0, 0, 0); 
     641         
     642        // stencil is increased where the source object is located 
     643        glStencilFunc(GL_ALWAYS, 0x1, 0x1); 
     644        glStencilOp(GL_INCR, GL_INCR, GL_INCR); 
     645 
     646#if 0 
     647        static int glSourceObjList = -1;          
     648        if (glSourceObjList != -1)  
     649        { 
     650                glSourceObjList = glGenLists(1); 
     651                glNewList(glSourceObjList, GL_COMPILE); 
     652 
     653                RenderIntersectable(sourceObject); 
     654         
     655                glEndList(); 
     656        } 
     657        glCallList(glSourceObjList); 
     658 
     659#else 
     660        RenderIntersectable(sourceObject); 
     661 
     662#endif   
    649663 
    650664        // 4. set back to normal rendering and clear the ray termination depth buffer 
     665        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 
     666        glColorMask(1, 1, 1, 1); 
     667         
    651668        // 5. render all objects inside the beam using id based false color 
    652669        //    (objects can be compiled to a gl list now so that subsequent rendering for 
    653670        //     this beam is fast - the same hold for step 3) 
    654671 
    655  
     672        // list of objects intersected by the frustum 
     673#if 0 
     674        static int glObjList = -1;  
     675        if (glObjList != -1)  
     676        { 
     677                glObjList = glGenLists(1); 
     678                glNewList(glObjList, GL_COMPILE); 
     679         
     680                ObjectContainer::const_iterator it, it_end = beam.mObjects.end(); 
     681                for (it = beam.mObjects.begin(); it != it_end; ++ it) 
     682                        RenderIntersectable(*it); 
     683                 
     684                glEndList(); 
     685        } 
     686        glCallList(glObjList); 
     687#else 
     688        ObjectContainer::const_iterator it, it_end = beam.mObjects.end(); 
     689                for (it = beam.mObjects.begin(); it != it_end; ++ it) 
     690                        RenderIntersectable(*it); 
     691#endif 
     692 
     693        // bind ray origin depth buffer 
     694        glBindTexture(GL_TEXTURE_2D, depthMap); 
     695    glEnable(GL_TEXTURE_2D); 
     696         
     697 
     698        //Read the depth buffer into the shadow map texture 
     699        glBindTexture(GL_TEXTURE_2D, depthMap); 
     700        glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, depthMapSize, depthMapSize); 
     701 
     702         
    656703        // 6. Now we have a two depth buffers defining the ray origin and termination 
    657704        //    only rays which have non-zero entry in the origin buffer are valid since 
    658705        //    they realy start on the object surface (this can also be tagged by setting a 
    659706        //    stencil buffer bit at step 3) 
     707        glStencilFunc(GL_EQUAL, 0x1, 0x1); 
     708 
     709        // compare with second depth buffer: done in pixel shader 
     710        cgGLBindProgram(sCgFragmentProgram); 
     711        cgGLEnableProfile(sCgFragmentProfile); 
    660712 
    661713        // 7. Use occlusion queries for all viewcell meshes associated with the beam -> 
    662714        // a fragment passes if the corresponding stencil fragment is set and its depth is 
    663715        // between origin and termination buffer 
     716 
     717        // create new queries if necessary 
     718        GenQueries((int)beam.mViewCells.size()); 
     719 
     720        // now check whether any backfacing polygon would pass the depth test 
     721        glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE); 
     722        glDepthMask(GL_FALSE); 
     723        glDisable(GL_CULL_FACE); 
     724   
     725        ViewCellContainer::const_iterator vit, vit_end = beam.mViewCells.end(); 
     726 
     727        int queryIdx = 0; 
     728 
     729        for (vit = beam.mViewCells.begin(); vit != vit_end; ++ vit) 
     730        { 
     731                glBeginOcclusionQueryNV(sQueries[queryIdx ++]); 
     732   
     733                RenderIntersectable(*vit); 
     734   
     735                glEndOcclusionQueryNV(); 
     736        } 
     737 
     738        // at this point, if possible, go and do some other computation 
     739        glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); 
     740        glDepthMask(GL_TRUE); 
     741        glEnable(GL_CULL_FACE); 
    664742 
    665743        // 8. The number of visible pixels is the number of sample rays which see the source 
     
    675753        // (new viewcell has been discovered) or relative contribution greater than a threashold ...  
    676754 
    677 } 
     755        cgGLDisableProfile(sCgFragmentProfile); 
     756        glDisable(GL_TEXTURE_2D); 
     757} 
     758 
     759 
     760void GlRendererBuffer::GenQueries(const int numQueries) 
     761{ 
     762        if ((int)sQueries.size() < numQueries) 
     763        { 
     764                const int n = numQueries - (int)sQueries.size(); 
     765                int *newQueries = new int[n]; 
     766 
     767                glGenOcclusionQueriesNV(n, (unsigned int *)&newQueries); 
     768 
     769                for (int i = 0; i < n; ++ i) 
     770                { 
     771                        sQueries.push_back(newQueries[i]); 
     772                } 
     773 
     774                delete newQueries; 
     775        } 
     776} 
  • trunk/VUT/GtpVisibilityPreprocessor/src/GlRenderer.h

    r512 r513  
    172172                                                           ); 
    173173 
     174private: 
     175        static void GenQueries(const int numQueries); 
     176 
    174177}; 
    175178 
Note: See TracChangeset for help on using the changeset viewer.