Changeset 544 for trunk/VUT/GtpVisibilityPreprocessor/src/GlRenderer.cpp
- Timestamp:
- 01/16/06 19:33:48 (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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();
Note: See TracChangeset
for help on using the changeset viewer.