Changeset 513 for trunk/VUT/GtpVisibilityPreprocessor/src
- Timestamp:
- 01/11/06 01:35:44 (19 years ago)
- Location:
- trunk/VUT/GtpVisibilityPreprocessor/src
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/VUT/GtpVisibilityPreprocessor/src/Beam.cpp
r512 r513 5 5 6 6 void 7 Beam::Construct(const AxisAlignedBox3 &box, 8 const AxisAlignedBox3 &dBox) 7 Beam::Construct(const AxisAlignedBox3 &box, const AxisAlignedBox3 &dBox) 9 8 { 10 9 // the frustum is defined by set of negative halfspace described by mPlanes -
trunk/VUT/GtpVisibilityPreprocessor/src/Beam.h
r512 r513 18 18 // list of nodes intersected by the frustum 19 19 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; 22 24 23 25 // spatial box -
trunk/VUT/GtpVisibilityPreprocessor/src/GlRenderer.cpp
r512 r513 6 6 #include "Viewcell.h" 7 7 #include "Beam.h" 8 8 9 #include <GL/glext.h> 9 10 #include <Cg/cg.h> … … 21 22 GLuint depthMap; 22 23 const int depthMapSize = 512; 24 static vector<int> sQueries; 23 25 24 26 GlRendererWidget *rendererWidget = NULL; 27 25 28 26 29 #ifdef _WIN32 … … 570 573 BeamSampleStatistics &stat) 571 574 { 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); 575 579 576 580 // assumes that the beam is constructed and contains kd-tree nodes 577 581 // and viewcells which it intersects 578 579 580 582 581 583 … … 618 620 // in order that thios scheme is working well the gpu render buffer should run in a separate 619 621 // thread than the cpu sampler, which would not be such a big problem.... 620 621 cgGLDisableProfile(sCgFragmentProfile);622 622 } 623 623 … … 631 631 // 2. setup the projection matrix and view matrix to match the viewpoint + beam.mDirBox 632 632 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 649 663 650 664 // 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 651 668 // 5. render all objects inside the beam using id based false color 652 669 // (objects can be compiled to a gl list now so that subsequent rendering for 653 670 // this beam is fast - the same hold for step 3) 654 671 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 656 703 // 6. Now we have a two depth buffers defining the ray origin and termination 657 704 // only rays which have non-zero entry in the origin buffer are valid since 658 705 // they realy start on the object surface (this can also be tagged by setting a 659 706 // 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); 660 712 661 713 // 7. Use occlusion queries for all viewcell meshes associated with the beam -> 662 714 // a fragment passes if the corresponding stencil fragment is set and its depth is 663 715 // 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); 664 742 665 743 // 8. The number of visible pixels is the number of sample rays which see the source … … 675 753 // (new viewcell has been discovered) or relative contribution greater than a threashold ... 676 754 677 } 755 cgGLDisableProfile(sCgFragmentProfile); 756 glDisable(GL_TEXTURE_2D); 757 } 758 759 760 void 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 172 172 ); 173 173 174 private: 175 static void GenQueries(const int numQueries); 176 174 177 }; 175 178
Note: See TracChangeset
for help on using the changeset viewer.