Changeset 540
- Timestamp:
- 01/15/06 04:23:51 (19 years ago)
- Location:
- trunk/VUT/GtpVisibilityPreprocessor
- Files:
-
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/VUT/GtpVisibilityPreprocessor/scripts/default.env
r538 r540 29 29 VssPreprocessor { 30 30 samplesPerPass 100000 31 initialSamples 30000032 vssSamples 30000031 initialSamples 200000 32 vssSamples 200000 33 33 vssSamplesPerPass 100000 34 34 useImportanceSampling true … … 52 52 maxDepth 40 53 53 minPvs 30 54 minRays 10054 minRays 500 55 55 minSize 0.001 56 56 maxCostRatio 1.5 … … 66 66 67 67 interleaveDirSplits true 68 dirSplitDepth 068 dirSplitDepth 10 69 69 70 70 numberOfEndPointDomains 10000 … … 171 171 ViewCells { 172 172 loadFromFile false 173 exportToFile false173 exportToFile true 174 174 #type kdTree 175 175 #type vspKdTree … … 182 182 maxViewCells 100000 183 183 #percentage of total visible objects where pvs is considered invalid 184 maxPvsRatio 0. 1184 maxPvsRatio 0.5 185 185 186 186 delayedConstruction false … … 207 207 # filename ../data/vienna/viewcells-25.x3d 208 208 # filename ../data/vienna/viewcells-large-sel.x3d 209 filename ../scripts/viewcells_vienna.xml 209 # filename ../scripts/viewcells_vienna.xml 210 filename ../scripts/viewcells_atlanta.xml 210 211 } 211 212 … … 270 271 # pvs = 1024 271 272 272 splitPlaneStrategy 102 4273 splitPlaneStrategy 1026 273 274 274 275 # maximal candidates for split planes … … 288 289 Termination { 289 290 # parameters used for autopartition 290 minRays 400291 minRays 1000 291 292 minPolygons -1 292 293 maxDepth 30 … … 299 300 #maxAccRayLength 100 300 301 301 maxViewCells 200 000302 maxViewCells 200 302 303 303 304 # used for pvs criterium … … 305 306 306 307 AxisAligned { 307 minRays 200000308 minRays 5000 308 309 maxRayContribution 0.5 309 310 } … … 314 315 Visualization { 315 316 # x3d visualization of the split planes 316 exportSplits true317 exportSplits false 317 318 } 318 319 319 320 PostProcess { 320 321 maxCostRatio 0.1 321 minViewCells 6000322 minViewCells 1000 322 323 maxPvsSize 10000 323 324 useRaysForMerge true -
trunk/VUT/GtpVisibilityPreprocessor/src/AxisAlignedBox3.cpp
r538 r540 1715 1715 } 1716 1716 1717 // order intersectio ins1717 // order intersections 1718 1718 if (planePoly->mVertices.size() > 3) 1719 1719 { -
trunk/VUT/GtpVisibilityPreprocessor/src/Beam.cpp
r535 r540 1 1 #include "VssRay.h" 2 2 #include "Beam.h" 3 3 #include "Mesh.h" 4 #include "Polygon3.h" 4 5 5 6 6 7 void 7 Beam::Construct(const AxisAlignedBox3 &box, constAxisAlignedBox3 &dBox)8 Beam::Construct(const AxisAlignedBox3 &box, const AxisAlignedBox3 &dBox) 8 9 { 9 10 // the frustum is defined by set of negative halfspace described by mPlanes … … 73 74 74 75 75 void Beam::Compute Frustum(float &left, float &right,76 77 78 76 void Beam::ComputePerspectiveFrustum(float &left, float &right, 77 float &bottom, float &top, 78 float &near, float &far, 79 const AxisAlignedBox3 &sceneBBox) const 79 80 { 80 81 const float xDirRange = mDirBox.Max().x - mDirBox.Min().x; 81 82 const float yDirRange = mDirBox.Max().y - mDirBox.Min().y; 83 //Debug << "xdir range: " << xDirRange << endl; 84 //Debug << "ydir range: " << yDirRange << endl; 82 85 83 86 near = 0.1f; // NOTE: what is the best value for near and far plane? 84 87 far = 2.0f * Magnitude(sceneBBox.Diagonal()); 85 86 left = near / tan(xDirRange * 0.5f); 87 right = near / tan(xDirRange * 0.5f); 88 89 bottom = near / tan(yDirRange * 0.5f); 90 top = near / tan(yDirRange * 0.5f); 88 89 right = fabs(near * tan(xDirRange * 0.5f)); 90 left = -right; 91 92 top = fabs(near * tan(yDirRange * 0.5f)); 93 bottom = -top; 94 } 95 96 97 void Beam::ComputeOrthoFrustum(float &left, float &right, 98 float &bottom, float &top, 99 float &near, float &far, 100 const AxisAlignedBox3 &sceneBBox) const 101 { 102 const int vAxis = GetMainDirection().DrivingAxis(); 103 const int axis2 = (vAxis + 1) % 3; 104 const int axis3 = (vAxis + 2) % 3; 105 106 const float xDirRange = mBox.Max()[axis2] - mDirBox.Min()[axis2]; 107 const float yDirRange = mDirBox.Max()[axis3] - mDirBox.Min()[axis3]; 108 109 near = 0.1f; // NOTE: what is the best value for near and far plane? 110 far = 2.0f * Magnitude(sceneBBox.Diagonal()); 111 112 right = xDirRange * 0.5f; 113 left = -right; 114 115 top = yDirRange * 0.5; 116 bottom = -top; 91 117 } 92 118 … … 94 120 Vector3 Beam::GetMainDirection() const 95 121 { 96 const Vector3 dCenter = mDirBox.Center(); 97 return VssRay::GetDirection(dCenter.x, dCenter.y); 122 return - mPlanes[0].mNormal; 98 123 } 99 124 … … 123 148 } 124 149 150 151 void Beam::CreateMesh(const float zfar) 152 { 153 if (mMesh) 154 return; 155 156 mMesh = new Mesh(); 157 158 // -- compute far plane 159 160 // box should not never remove part of beam polygons 161 Vector3 bmin = mBox.Min() - Vector3(zfar * 2.0); 162 Vector3 bmax = mBox.Max() + Vector3(zfar * 2.0); 163 164 AxisAlignedBox3 bbox(bmin, bmax); 165 Plane3 fplane; 166 fplane.mNormal = -mPlanes[0].mNormal; 167 168 // NOTE: beam far plane must not not be culled by gl far plane 169 fplane.mD = mPlanes[0].mD - zfar - 1.0f; 170 mPlanes.push_back(fplane); 171 172 for (int i = 0; i < mPlanes.size(); ++ i) 173 { 174 Polygon3 *poly = bbox.CrossSection(mPlanes[i]); 175 176 if (!poly->Valid(Limits::Small)) 177 DEL_PTR(poly); 178 179 for (int j = 0; (j < mPlanes.size()) && poly; ++ j) 180 { 181 if (j != i) 182 { 183 Polygon3 *front = new Polygon3(); 184 Polygon3 *back = new Polygon3(); 185 186 poly->Split(mPlanes[j], *front, *back, Limits::Small); 187 DEL_PTR(poly); 188 DEL_PTR(front); 189 190 if (!back->Valid(Limits::Small)) 191 DEL_PTR(back); 192 poly = back; 193 } 194 } 195 196 if (poly) 197 { 198 poly->AddToMesh(*mMesh); 199 } 200 } 201 202 // remove far plane 203 mPlanes.pop_back(); 204 } -
trunk/VUT/GtpVisibilityPreprocessor/src/Beam.h
r532 r540 10 10 class KdNode; 11 11 class Intersectable; 12 class Mesh; 12 13 13 14 // the values need for rss tree update computed already inside the glrendererbuffer … … 74 75 vector<Plane3> mPlanes; 75 76 77 Mesh *mMesh; 76 78 79 /** Constructs a beam from a spatial and a directional box. 80 */ 77 81 void Construct(const AxisAlignedBox3 &box, 78 const AxisAlignedBox3 &dBox);82 const AxisAlignedBox3 &dBox); 79 83 80 void ComputeFrustum(float &left, float &right, 81 float &bottom, float &top, 82 float &near, float &far, 83 const AxisAlignedBox3 &sceneBBox) const; 84 /** Computes parameters for glFrustum. 85 */ 86 void ComputePerspectiveFrustum(float &left, float &right, 87 float &bottom, float &top, 88 float &near, float &far, 89 const AxisAlignedBox3 &sceneBBox) const; 90 91 /* Computes parameters for glOrtho. 92 */ 93 void ComputeOrthoFrustum(float &left, float &right, 94 float &bottom, float &top, 95 float &near, float &far, 96 const AxisAlignedBox3 &sceneBBox) const; 84 97 85 98 int ComputeIntersection(const AxisAlignedBox3 &box); … … 90 103 bool SetValid() { return mFlags |= VALID; } 91 104 92 Beam():mFlags(STORE_KD_NODES+STORE_OBJECTS), mKdNodes(0), mObjects(0), mViewCells(0) 105 Beam():mFlags(STORE_KD_NODES+STORE_OBJECTS), mKdNodes(0), mObjects(0), mViewCells(0), mMesh(NULL) 93 106 { 94 107 } 108 109 void CreateMesh(const float zfar); 95 110 }; 96 111 -
trunk/VUT/GtpVisibilityPreprocessor/src/GlRenderer.cpp
r538 r540 16 16 static CGprofile sCgFragmentProfile; 17 17 18 GLuint depthMap; 18 GLuint frontDepthMap; 19 GLuint backDepthMap; 20 19 21 const int depthMapSize = 512; 20 22 static vector<int> sQueries; … … 99 101 } 100 102 103 104 int GlRenderer::GetId(int r, int g, int b) const 105 { 106 return r + (g << 8) + (b << 16); 107 } 108 101 109 void 102 110 GlRenderer::SetupMaterial(Material *m) … … 152 160 glGetOcclusionQueryuivNV = (PFNGLGETOCCLUSIONQUERYUIVNVPROC) 153 161 wglGetProcAddress("glGetOcclusionQueryuivNV"); 154 155 // initialise second depth buffer texture156 glGenTextures(1, &depthMap);157 glBindTexture(GL_TEXTURE_2D, depthMap);158 159 glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, depthMapSize,160 depthMapSize, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_BYTE, NULL);161 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);162 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);163 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);164 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);165 166 // cg initialization167 cgSetErrorCallback(handleCgError);168 sCgContext = cgCreateContext();169 170 if (cgGLIsProfileSupported(CG_PROFILE_ARBFP1))171 sCgFragmentProfile = CG_PROFILE_ARBFP1;172 else {173 // try FP30174 if (cgGLIsProfileSupported(CG_PROFILE_FP30))175 sCgFragmentProfile = CG_PROFILE_FP30;176 else {177 fprintf(stderr, "Neither arbfp1 or fp30 fragment profiles supported on this system.\n");178 exit(1);179 }180 }181 182 sCgFragmentProgram = cgCreateProgramFromFile(sCgContext,183 CG_SOURCE, "../src/dual_depth.cg",184 sCgFragmentProfile,185 NULL,186 NULL);187 188 if (!cgIsProgramCompiled(sCgFragmentProgram))189 cgCompileProgram(sCgFragmentProgram);190 191 cgGLLoadProgram(sCgFragmentProgram);192 cgGLBindProgram(sCgFragmentProgram);193 // Debug << "LAST LISTING----" << cgGetLastListing(sCgContext) << "----\n";194 195 Debug << "---- PROGRAM BEGIN ----\n" <<196 cgGetProgramString(sCgFragmentProgram, CG_COMPILED_PROGRAM) << "---- PROGRAM END ----\n";197 162 } 198 163 … … 617 582 BeamSampleStatistics &stat) 618 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 619 589 // TODO: should not be done every time here 620 590 // only back faces are interesting for the depth pass … … 636 606 // would distribute the 'efective viewpoints' of the object surface and thus 637 607 // with a few viewpoints better sample the vipoint space.... 638 639 int viewPointSamples = sqrt((float)desiredSamples); 640 608 //TODO: remove 609 //int viewPointSamples = sqrt((float)desiredSamples); 610 int viewPointSamples = max(desiredSamples / (GetWidth() * GetHeight()), 1); 611 641 612 // the number of direction samples per pass is given by the number of viewpoints 642 int directionalSamples = desiredSamples/viewPointSamples; 643 613 int directionalSamples = desiredSamples / viewPointSamples; 614 615 Debug << "directional samples: " << directionalSamples << endl; 644 616 for (int i = 0; i < viewPointSamples; ++ i) 645 617 { … … 674 646 const Vector3 viewPoint, 675 647 Beam &beam, 676 const int desiredSamples,648 const int samples, 677 649 BeamSampleStatistics &stat) 678 650 { 679 680 glViewport(0, 0, desiredSamples, desiredSamples);651 // 1. setup the view port to match the desired samples 652 glViewport(0, 0, GetWidth(), GetHeight()); 681 653 682 654 // 2. setup the projection matrix and view matrix to match the viewpoint + beam.mDirBox 683 655 SetupProjectionForViewPoint(viewPoint, beam, sourceObject); 684 656 685 657 // 3. reset z-buffer to 0 and render the source object for the beam 686 658 // with glCullFace(Enabled) and glFrontFace(GL_CW) 687 659 // save result to depth map 660 661 // front depth buffer must bé initialised to 0 662 float clearDepth; 663 glGetFloatv(GL_DEPTH_CLEAR_VALUE, &clearDepth); 664 glClearDepth(0.0f); 665 666 688 667 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); 668 //glFrontFace(GL_CW); 689 669 glEnable(GL_CULL_FACE); 690 glEnable(GL_STENCIL_TEST);691 670 glCullFace(GL_FRONT); 692 671 glColorMask(0, 0, 0, 0); 693 672 673 694 674 // stencil is increased where the source object is located 675 glEnable(GL_STENCIL_TEST); 695 676 glStencilFunc(GL_ALWAYS, 0x1, 0x1); 696 glStencilOp(GL_ INCR, GL_INCR, GL_INCR);677 glStencilOp(GL_REPLACE, GL_REPLACE, GL_REPLACE); 697 678 698 679 #if 0 … … 713 694 714 695 #endif 696 // reset clear function 697 glClearDepth(clearDepth); 698 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 708 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 715 716 716 717 // 4. set back to normal rendering and clear the ray termination depth buffer 717 718 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 718 719 glColorMask(1, 1, 1, 1); 719 720 glDepthMask(1); 721 glEnable(GL_DEPTH_TEST); 722 glDisable(GL_STENCIL_TEST); 723 glEnable(GL_CULL_FACE); 724 glCullFace(GL_BACK); 725 720 726 // 5. render all objects inside the beam using id based false color 721 727 // (objects can be compiled to a gl list now so that subsequent rendering for … … 743 749 ObjectContainer::const_iterator it, it_end = beam.mObjects.end(); 744 750 for (it = beam.mObjects.begin(); it != it_end; ++ it) 745 RenderIntersectable(*it); 751 { 752 if (*it != sourceObject) 753 RenderIntersectable(*it); 754 } 746 755 747 756 glEndList(); … … 750 759 #else 751 760 ObjectContainer::const_iterator it, it_end = beam.mObjects.end(); 752 for (it = beam.mObjects.begin(); it != it_end; ++ it) 761 for (it = beam.mObjects.begin(); it != it_end; ++ it) 762 { 763 if (*it != sourceObject) 753 764 RenderIntersectable(*it); 765 } 754 766 #endif 755 767 756 // remove objects again 757 if (beam.mFlags & !Beam::STORE_OBJECTS) 758 beam.mObjects.clear(); 759 760 // bind ray origin depth buffer 761 glBindTexture(GL_TEXTURE_2D, depthMap); 762 glEnable(GL_TEXTURE_2D); 763 764 765 //Read the depth buffer into the shadow map texture 766 glBindTexture(GL_TEXTURE_2D, depthMap); 767 glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, depthMapSize, depthMapSize); 768 769 770 // 6. Now we have a two depth buffers defining the ray origin and termination 768 769 // 6. Now we have a two depth buffers defining the ray origin and termination 771 770 // only rays which have non-zero entry in the origin buffer are valid since 772 771 // they realy start on the object surface (this can also be tagged by setting a 773 772 // stencil buffer bit at step 3) 773 774 glDisable(GL_STENCIL_TEST); 775 //glEnable(GL_STENCIL_TEST); 774 776 glStencilFunc(GL_EQUAL, 0x1, 0x1); 775 776 //cgGLBindProgram(sCgFragmentProgram); 777 //glStencilFunc(GL_EQUAL, 0x2, 0x2); 778 glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP); 779 780 // bind depth texture 781 glEnable(GL_TEXTURE_2D); 782 783 // bind depth cull pixel shader 784 cgGLBindProgram(sCgFragmentProgram); 777 785 cgGLEnableProfile(sCgFragmentProfile); 778 786 … … 785 793 786 794 // now check whether any backfacing polygon would pass the depth test? 795 //matt: should check both back /front facing because of dual depth buffer 796 //and danger of cutting the near plane with front facing polys. 787 797 glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE); 788 798 glDepthMask(GL_FALSE); … … 817 827 GL_PIXEL_COUNT_NV, 818 828 &pixelCount); 819 820 Debug << "visble pixels: " << pixelCount << endl;829 if (pixelCount) 830 Debug << "view cell " << (*vit)->GetId() << " visible pixels: " << pixelCount << endl; 821 831 } 822 832 … … 828 838 // evaluate the contribution entropy for example) 829 839 // However might be an option to extract/store only those the rays which made a contribution 830 // (new viewcell has been discovered) or relative contribution greater than a threashold ... 831 840 // (new viewcell has been discovered) or relative contribution greater than a threshold ... 841 842 ObjectContainer pvsObj; 843 stat.pvsSize = ComputePvs(beam.mObjects, pvsObj); 844 845 846 #if 0 847 // copy contents of back depth buffer into depth texture 848 // depth buffer holds ray origins 849 glBindTexture(GL_TEXTURE_2D, backDepthMap); 850 glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, depthMapSize, depthMapSize); 851 #endif 852 // reset state 832 853 glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); 833 854 glDepthMask(GL_TRUE); 834 855 glEnable(GL_CULL_FACE); 835 836 856 glDisable(GL_STENCIL_TEST); 837 857 cgGLDisableProfile(sCgFragmentProfile); 838 858 glDisable(GL_TEXTURE_2D); 859 860 // remove objects again 861 if (beam.mFlags & !Beam::STORE_OBJECTS) 862 beam.mObjects.clear(); 839 863 } 840 864 … … 845 869 { 846 870 const int n = numQueries - (int)sQueries.size(); 847 int *newQueries = newint[n];848 849 glGenOcclusionQueriesNV(n, (unsigned int *) &newQueries);871 unsigned int *newQueries = new unsigned int[n]; 872 873 glGenOcclusionQueriesNV(n, (unsigned int *)newQueries); 850 874 851 875 for (int i = 0; i < n; ++ i) … … 854 878 } 855 879 856 delete newQueries;880 delete [] newQueries; 857 881 } 858 882 } … … 860 884 861 885 void GlRendererBuffer::SetupProjectionForViewPoint(const Vector3 &viewPoint, 862 const Beam &beam,863 Intersectable *sourceObject)886 const Beam &beam, 887 Intersectable *sourceObject) 864 888 { 865 889 float left, right, bottom, top, znear, zfar; 866 890 867 beam.ComputeFrustum(left, right, bottom, top, znear, zfar, 868 mSceneGraph->GetBox()); 869 891 beam.ComputePerspectiveFrustum(left, right, bottom, top, znear, zfar, 892 mSceneGraph->GetBox()); 893 894 //Debug << left << " " << right << " " << bottom << " " << top << " " << znear << " " << zfar << endl; 895 glMatrixMode(GL_PROJECTION); 896 glLoadIdentity(); 870 897 glFrustum(left, right, bottom, top, znear, zfar); 871 872 const Vector3 eye = viewPoint + beam.GetMainDirection(); 873 const Vector3 up;//AbitraryNormal(eye); 874 875 gluLookAt(eye.x, eye.y, eye.z, 876 viewPoint.x, viewPoint.y, viewPoint.z, 898 //glFrustum(-1, 1, -1, 1, 1, 20000); 899 900 const Vector3 center = viewPoint + beam.GetMainDirection() * (zfar - znear) * 0.3; 901 const Vector3 up = 902 Normalize(CrossProd(beam.mPlanes[0].mNormal, beam.mPlanes[4].mNormal)); 903 904 #ifdef _DEBUG 905 Debug << "view point: " << viewPoint << endl; 906 Debug << "eye: " << center << endl; 907 Debug << "up: " << up << endl; 908 #endif 909 910 glMatrixMode(GL_MODELVIEW); 911 glLoadIdentity(); 912 gluLookAt(viewPoint.x, viewPoint.y, viewPoint.z, 913 center.x, center.y, center.z, 877 914 up.x, up.y, up.z); 878 915 } 879 916 880 917 918 void GlRendererBuffer::InitGL() 919 { 920 GlRenderer::InitGL(); 921 // initialise dual depth buffer textures 922 glGenTextures(1, &frontDepthMap); 923 glBindTexture(GL_TEXTURE_2D, frontDepthMap); 924 925 glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, depthMapSize, 926 depthMapSize, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_BYTE, NULL); 927 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); 928 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); 929 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); 930 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); 931 932 glGenTextures(1, &backDepthMap); 933 glBindTexture(GL_TEXTURE_2D, backDepthMap); 934 935 glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, depthMapSize, 936 depthMapSize, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_BYTE, NULL); 937 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); 938 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); 939 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); 940 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); 941 942 // cg initialization 943 cgSetErrorCallback(handleCgError); 944 sCgContext = cgCreateContext(); 945 946 if (cgGLIsProfileSupported(CG_PROFILE_ARBFP1)) 947 sCgFragmentProfile = CG_PROFILE_ARBFP1; 948 else 949 { 950 // try FP30 951 if (cgGLIsProfileSupported(CG_PROFILE_FP30)) 952 sCgFragmentProfile = CG_PROFILE_FP30; 953 else 954 { 955 Debug << "Neither arbfp1 or fp30 fragment profiles supported on this system" << endl; 956 exit(1); 957 } 958 } 959 960 sCgFragmentProgram = cgCreateProgramFromFile(sCgContext, 961 CG_SOURCE, "../src/dual_depth.cg", 962 sCgFragmentProfile, 963 NULL, 964 NULL); 965 966 if (!cgIsProgramCompiled(sCgFragmentProgram)) 967 cgCompileProgram(sCgFragmentProgram); 968 969 cgGLLoadProgram(sCgFragmentProgram); 970 cgGLBindProgram(sCgFragmentProgram); 881 971 882 883 /***************************************************************/ 884 /* GlDebuggerWidget implementation */ 885 /***************************************************************/ 886 887 888 GlDebuggerWidget::GlDebuggerWidget(QWidget *parent, GlRendererBuffer *buf) 972 Debug << "---- PROGRAM BEGIN ----\n" << 973 cgGetProgramString(sCgFragmentProgram, CG_COMPILED_PROGRAM) << "---- PROGRAM END ----\n"; 974 } 975 976 void GlRendererBuffer::ComputeRays(Intersectable *sourceObj, VssRayContainer &rays) 977 { 978 for (int i = 0; i < depthMapSize * depthMapSize; ++ i) 979 { 980 //todo glGetTexImage() 981 } 982 } 983 984 985 986 inline bool ilt(Intersectable *obj1, Intersectable *obj2) 987 { 988 return obj1->mId < obj2->mId; 989 } 990 991 992 int GlRendererBuffer::ComputePvs(ObjectContainer &objects, 993 ObjectContainer &pvs) const 994 { 995 int pvsSize = 0; 996 QImage image = toImage(); 997 Intersectable::NewMail(); 998 999 std::stable_sort(objects.begin(), objects.end(), ilt); 1000 1001 MeshInstance dummy(NULL); 1002 1003 Intersectable *obj = NULL; 1004 1005 for (int x = 0; x < image.width(); ++ x) 1006 { 1007 for (int y = 0; y < image.height(); ++ y) 1008 { 1009 QRgb pix = image.pixel(x, y); 1010 const int id = GetId(qRed(pix), qGreen(pix), qBlue(pix)); 1011 1012 dummy.SetId(id); 1013 1014 ObjectContainer::iterator oit = 1015 lower_bound(objects.begin(), objects.end(), &dummy, ilt); 1016 obj = *oit; 1017 if (!obj->Mailed()) 1018 { 1019 obj->Mail(); 1020 ++ pvsSize; 1021 pvs.push_back(obj); 1022 } 1023 } 1024 } 1025 1026 return pvsSize; 1027 } 1028 1029 /***********************************************************************/ 1030 /* GlDebuggerWidget implementation */ 1031 /***********************************************************************/ 1032 1033 1034 GlDebuggerWidget::GlDebuggerWidget(GlRendererBuffer *buf, QWidget *parent) 889 1035 : QGLWidget(QGLFormat(QGL::SampleBuffers), parent), mRenderBuffer(buf) 890 1036 { … … 932 1078 // draw a spinning cube into the pbuffer.. 933 1079 mRenderBuffer->makeCurrent(); 934 //mRenderBuffer->SampleBeamContributions(); 1080 1081 BeamSampleStatistics stats; 1082 mRenderBuffer->SampleBeamContributions(mSourceObject, mBeam, mSamples, stats); 1083 935 1084 glFlush(); 936 1085 937 1086 // rendering directly to a texture is not supported on X11, unfortunately 938 1087 mRenderBuffer->updateDynamicTexture(dynamicTexture); 939 1088 940 // ..and use the pbuffer contents as a texture when rendering the1089 // and use the pbuffer contents as a texture when rendering the 941 1090 // background and the bouncing cubes 942 1091 makeCurrent(); … … 962 1111 // set up the pbuffer context 963 1112 mRenderBuffer->makeCurrent(); 964 initCommon();1113 /*mRenderBuffer->InitGL(); 965 1114 966 1115 glViewport(0, 0, mRenderBuffer->size().width(), mRenderBuffer->size().height()); … … 972 1121 glLoadIdentity(); 973 1122 974 glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT); 975 1123 glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);*/ 1124 976 1125 // generate a texture that has the same size/format as the pbuffer 977 1126 dynamicTexture = mRenderBuffer->generateDynamicTexture(); -
trunk/VUT/GtpVisibilityPreprocessor/src/GlRenderer.h
r538 r540 10 10 #include "Halton.h" 11 11 #include "Renderer.h" 12 #include "Beam.h" 12 13 13 14 class SceneGraph; … … 23 24 class BeamSampleStatistics; 24 25 26 struct VssRayContainer; 27 25 28 struct PvsRenderStatistics { 26 29 … … 104 107 virtual int GetWidth() const = 0; 105 108 virtual int GetHeight() const = 0; 109 110 int GetId(int r, int g, int b) const; 106 111 }; 107 112 … … 154 159 ); 155 160 156 PvsRenderStatistics mPvsStat; 161 void InitGL(); 162 163 /** Computes rays from information gained with hw sampling- 164 */ 165 void ComputeRays(Intersectable *sourceObj, VssRayContainer &rays); 166 167 int ComputePvs() const; 168 169 170 int ComputePvs(ObjectContainer &objects, ObjectContainer &pvs) const; 171 172 PvsRenderStatistics mPvsStat; 157 173 158 159 174 int mPvsStatFrames; 175 vector<float> mPvsErrorBuffer; 160 176 161 177 private: 178 162 179 static void GenQueries(const int numQueries); 180 163 181 void SetupProjectionForViewPoint(const Vector3 &viewPoint, 164 182 const Beam &beam, … … 217 235 class GlDebuggerWidget : public QGLWidget 218 236 { 219 public: 220 GlDebuggerWidget(QWidget *parent, GlRendererBuffer *buf); 237 Q_OBJECT 238 public: 239 GlDebuggerWidget(GlRendererBuffer *buf, QWidget *parent = NULL); 221 240 ~GlDebuggerWidget(); 222 241 void initializeGL(); … … 232 251 GlRendererBuffer *mRenderBuffer; 233 252 253 Beam mBeam; 254 int mSamples; 255 Intersectable *mSourceObject; 234 256 private: 235 257 GLuint dynamicTexture; -
trunk/VUT/GtpVisibilityPreprocessor/src/Preprocessor.cpp
r538 r540 259 259 } 260 260 if (mUseGlRenderer || mUseGlDebugger) 261 renderer = new GlRendererBuffer(1024, 768, mSceneGraph, mViewCellsManager, mKdTree); 261 { 262 // NOTE: render texture should be power of 2 and square 263 // renderer must be initialised 264 renderer = new GlRendererBuffer(1024, 768, mSceneGraph, mViewCellsManager, mKdTree); 265 renderer->makeCurrent(); 266 } 262 267 263 268 -
trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellsManager.cpp
r535 r540 13 13 #include "ViewCellsParser.h" 14 14 #include "Beam.h" 15 15 #include "VssPreprocessor.h" 16 #include "RssPreprocessor.h" 16 17 17 18 … … 76 77 int ViewCellsManager::Construct(VssRayContainer &rays) 77 78 { 79 VssPreprocessor preprocessor; 80 81 82 78 83 return 0; 79 84 } -
trunk/VUT/GtpVisibilityPreprocessor/src/VssPreprocessor.cpp
r538 r540 360 360 const ObjectContainer &objects) 361 361 { 362 //debuggerWidget = new GlDebuggerWidget(renderer); 363 // renderer->resize(640, 480); 364 //debuggerWidget->resize(640, 480); 365 362 366 vector<VssTreeLeaf *> leaves; 363 367 tree->CollectLeaves(leaves); … … 366 370 367 371 exporter->SetWireframe(); 368 //exporter->ExportGeometry(objects);372 exporter->ExportGeometry(objects); 369 373 exporter->SetFilled(); 370 374 //Randomize(); 371 for (int i = 0; i < 1; ++ i) 375 debuggerWidget = new GlDebuggerWidget(renderer); 376 377 /*debuggerWidget->mBeam = beam; 378 debuggerWidget->mSourceObject = sourceObj; 379 debuggerWidget->mSamples = 10000; 380 381 Debug << "showing window" << endl; 382 debuggerWidget->show();*/ 383 384 renderer->makeCurrent(); 385 386 for (int i = 0; i < 10; ++ i) 372 387 { 388 Beam beam; 389 Intersectable *sourceObj = mObjects[5]; 390 373 391 const int index = (int)RandomValue(0, (Real)((int)leaves.size() - 1)); 374 392 VssTreeLeaf *leaf = leaves[index]; 375 393 376 Beam beam;377 394 AxisAlignedBox3 dirBox = tree->GetDirBBox(leaf); 378 395 AxisAlignedBox3 box = tree->GetBBox(leaf); … … 387 404 << beam.mKdNodes.size() << " kd nodes" << endl; 388 405 389 Intersectable *sourceObj = mObjects[5];390 406 BeamSampleStatistics stats; 391 407 392 408 renderer->SampleBeamContributions(sourceObj, 393 409 beam, 394 10000,410 200000, 395 411 stats); 396 412 413 char s[64]; sprintf(s, "shaft%04d.png", i); 414 415 QImage image = renderer->toImage(); 416 image.save(s, "PNG"); 397 417 Debug << "beam statistics: " << stats << endl << endl; 418 419 if (1) 420 { 421 AxisAlignedBox3 sbox = mSceneGraph->GetBox(); 422 Vector3 bmin = sbox.Min() - 150.0f; 423 Vector3 bmax = sbox.Max() + 150.0f; 424 AxisAlignedBox3 vbox(bmin, bmax); 398 425 399 AxisAlignedBox3 sbox = mSceneGraph->GetBox(); 400 Vector3 bmin = sbox.Min() - 150.0f; 401 Vector3 bmax = sbox.Max() + 150.0f; 402 AxisAlignedBox3 vbox(bmin, bmax); 403 404 exporter->ExportBeam(beam, vbox); 405 406 bool exportViewCells = true; 426 exporter->ExportBeam(beam, vbox); 427 } 428 429 bool exportViewCells = false; 407 430 408 431 if (exportViewCells) … … 431 454 } 432 455 } 456 /*while (1) 457 { debuggerWidget->repaint(); 458 };*/ 433 459 delete exporter; 434 460 } 461 435 462 436 463 float … … 591 618 592 619 593 int numExportRays = 5000;594 //int numExportRays = 0;620 //int numExportRays = 5000; 621 int numExportRays = 0; 595 622 596 623 if (numExportRays) { … … 723 750 mViewCellsManager->PostProcess(mObjects, viewCellRays); 724 751 725 if (mTestBeamSampling) 752 if (mTestBeamSampling && mUseGlRenderer) 753 { 726 754 TestBeamCasting(vssTree, mViewCellsManager, mObjects); 755 } 727 756 728 757 //-- several visualizations and statistics -
trunk/VUT/GtpVisibilityPreprocessor/src/X3dExporter.cpp
r535 r540 1242 1242 void X3dExporter::ExportBeam(const Beam &beam, const AxisAlignedBox3 &box) 1243 1243 { 1244 if (beam.mMesh) 1245 { 1246 ExportMesh(beam.mMesh); 1247 return; 1248 } 1249 1244 1250 PolygonContainer polys; 1245 1251 //ExportBox(beam.mBox); 1246 1252 1247 for (int i = 0; i < beam.mPlanes.size(); ++ i) 1248 { 1249 Polygon3 *poly = box.CrossSection(beam.mPlanes[i]); 1253 const float zfar = 2.0f * Magnitude(box.Diagonal()); 1254 1255 // box should not never remove part of beam polygons 1256 Vector3 bmin = beam.mBox.Min() - Vector3(zfar * 2.0); 1257 Vector3 bmax = beam.mBox.Max() + Vector3(zfar * 2.0); 1258 1259 AxisAlignedBox3 bbox(bmin, bmax); 1260 Plane3 fplane; 1261 fplane.mNormal = -beam.mPlanes[0].mNormal; 1262 1263 fplane.mD = beam.mPlanes[0].mD - zfar - 1.0f; 1264 1265 vector<Plane3> planes = beam.mPlanes; 1266 planes.push_back(fplane); 1267 1268 for (int i = 0; i < planes.size(); ++ i) 1269 { 1270 Polygon3 *poly = bbox.CrossSection(planes[i]); 1271 if (!poly->Valid(Limits::Small)) 1272 DEL_PTR(poly); 1250 1273 1251 for (int j = 0; (j < beam.mPlanes.size()) && poly; ++ j)1274 for (int j = 0; (j < planes.size()) && poly; ++ j) 1252 1275 { 1253 1276 if (j != i) … … 1256 1279 Polygon3 *back = new Polygon3(); 1257 1280 1258 poly->Split( beam.mPlanes[j], *front, *back, Limits::Small);1281 poly->Split(planes[j], *front, *back, Limits::Small); 1259 1282 DEL_PTR(poly); 1260 1283 DEL_PTR(front); … … 1269 1292 } 1270 1293 1271 1272 1294 ExportPolygons(polys); 1273 1295 CLEAR_CONTAINER(polys); -
trunk/VUT/GtpVisibilityPreprocessor/src/dual_depth.cg
r532 r540 15 15 { 16 16 pixel OUT; 17 17 OUT.color = IN.color0; 18 18 19 // the depth buffer has to be compared to the current depth 19 20 float4 depth = tex2D(depthMap, IN.depthTexCoord.xy); … … 22 23 // reject by alpha test 23 24 if (test < depth.x) 25 { 24 26 OUT.color.w = 0; 25 27 // OUT.color.y += 0.5; 28 } 29 26 30 return OUT; 27 31 } -
trunk/VUT/GtpVisibilityPreprocessor/src/main.cpp
r538 r540 100 100 101 101 pt->start(QThread::LowPriority); 102 103 } else if (0 /*p->UseGlDebugger*/) {104 //debuggerWidget = new GlDebuggerWidget(*, (p->mSceneGraph, p->mViewCellsManager, p->mKdTree);105 // renderer->resize(640, 480);106 // debuggerWidget->resize(640, 480);107 // debuggerWidget->show();108 109 pt->start(QThread::LowPriority);110 102 } else 111 103 {
Note: See TracChangeset
for help on using the changeset viewer.