Ignore:
Timestamp:
01/16/06 19:33:48 (18 years ago)
Author:
mattausch
Message:
 
File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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(); 
Note: See TracChangeset for help on using the changeset viewer.