Changeset 512 for trunk/VUT/GtpVisibilityPreprocessor/src/GlRenderer.cpp
- Timestamp:
- 01/10/06 18:27:20 (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/VUT/GtpVisibilityPreprocessor/src/GlRenderer.cpp
r511 r512 6 6 #include "Viewcell.h" 7 7 #include "Beam.h" 8 9 8 #include <GL/glext.h> 9 #include <Cg/cg.h> 10 #include <Cg/cgGL.h> 11 12 static CGcontext sCgContext = NULL; 13 static CGprogram sCgFragmentProgram = NULL; 14 15 static CGparameter sCgKdParam = NULL; 16 static CGparameter sCgModelViewProjParam = NULL; 17 18 19 static CGprofile sCgFragmentProfile = CG_PROFILE_FP30; 20 21 GLuint depthMap; 22 const int depthMapSize = 512; 10 23 11 24 GlRendererWidget *rendererWidget = NULL; … … 119 132 wglGetProcAddress("glGetOcclusionQueryuivNV"); 120 133 121 // second depth buffer texture 122 GLuint shadowMap; 123 const int shadowMapSize=512; 124 125 126 glGenTextures(1, &shadowMap); 127 glBindTexture(GL_TEXTURE_2D, shadowMap); 128 129 glTexImage2D( GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, shadowMapSize, 130 shadowMapSize, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_BYTE, NULL); 134 // initialise second depth buffer texture 135 glGenTextures(1, &depthMap); 136 glBindTexture(GL_TEXTURE_2D, depthMap); 137 138 glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, depthMapSize, 139 depthMapSize, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_BYTE, NULL); 131 140 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); 132 141 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); 133 142 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); 134 143 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); 144 145 // cg initialization 146 sCgContext = cgCreateContext(); 147 148 sCgFragmentProgram = cgCreateProgramFromFile(sCgContext, 149 CG_SOURCE, "dual_depth.cg", 150 sCgFragmentProfile, 151 NULL, 152 NULL); 135 153 } 136 154 … … 547 565 548 566 549 void 550 GlRendererBuffer::SampleBeamContributions( 551 Intersectable *sourceObject, 552 MyBeam &beam, 553 const int desiredSamples, 554 BeamSampleStatistics &stat 555 ) 556 { 557 // assumes that the beam is constructed and contains kd-tree nodes 558 // and viewcells which it intersects 559 560 561 562 563 // Get the number of viewpoints to be sampled 564 // Now it is a sqrt but in general a wiser decision could be made. 565 // The less viewpoints the better for rendering performance, since less passes 566 // over the beam is needed. 567 // The viewpoints could actually be generated outside of the bounding box which 568 // would distribute the 'efective viewpoints' of the object surface and thus 569 // with a few viewpoints better sample the vipoint space.... 570 571 int viewPointSamples = sqrt((float)desiredSamples); 572 573 // the number of direction samples per pass is given by the number of viewpoints 574 int directionalSamples = desiredSamples/viewPointSamples; 575 int i; 576 for (i=0; i < viewPointSamples; i++) { 577 Vector3 viewPoint = beam.mBox.GetRandomPoint(); 578 // perhaps the viewpoint should be shifted back a little bit so that it always lies 579 // inside the source object 580 // 'ideally' the viewpoints would be distributed on the soureObject surface, but this 581 // would require more complicated sampling (perhaps hierarchical rejection sampling of 582 // the object surface is an option here - only the mesh faces which are inside the box 583 // are considered as candidates) 584 SampleViewpointContributions( 585 sourceObject, 586 beam, 587 directionalSamples, 588 stat 589 ); 590 } 591 592 593 // note: 594 // this routine would be called only if the number of desired samples is sufficiently 595 // large - for other rss tree cells the cpu based sampling is perhaps more efficient 596 // distributing the work between cpu and gpu would also allow us to place more sophisticated 597 // sample distributions (silhouette ones) using the cpu and the jittered once on the GPU 598 // in order that thios scheme is working well the gpu render buffer should run in a separate 599 // thread than the cpu sampler, which would not be such a big problem.... 600 } 601 602 603 void 604 GlRendererBuffer::SampleViewpointContributions( 605 Intersectable *sourceObject, 606 MyBeam &beam, 567 void GlRendererBuffer::SampleBeamContributions(Intersectable *sourceObject, 568 Beam &beam, 607 569 const int desiredSamples, 608 BeamSampleStatistics &stat 609 ) 610 { 611 // 1. setup the view port to match the desired samples 612 // 2. setup the projection matrix and view matrix to match the viewpoint + beam.mDirBox 613 614 // 3. reset z-buffer to 0 and render the source object for the beam using 615 // glDepthFunc(GL_GREATER) 616 // and glCullFace(Enabled) and glFrontFace(GL_CW) 617 // remember the ray origin depth buffer somewhere? 618 619 // 4. set back to normal rendering and clear the ray termination depth buffer 620 // 5. render all objects inside the beam using id based false color 621 // (objects can be compiled to a gl list now so that subsequent rendering for 622 // this beam is fast - the same hold for step 3) 623 624 625 // 6. Now we have a two depth buffers defining the ray origin and termination 626 // only rays which have non-zero entry in the origin buffer are valid since 627 // they realy start on the object surface (this can also be tagged by setting a 628 // stencil buffer bit at step 3) 629 630 // 7. Use occlusion queries for all viewcell meshes associated with the beam -> 631 // a fragment passes if the corresponding stencil fragment is set and its depth is 632 // between origin and termination buffer 633 634 // 8. The number of visible pixels is the number of sample rays which see the source 635 // object from the corresponding viewcell -> rember these values for later update 636 // of the viewcell pvs - or update immediatelly? 637 638 // In general it is not neccessary to rember to extract all the rays cast. I hope it 639 // would be sufficient to gain only the intergral statistics about the new contributions 640 // and so the rss tree would actually store no new rays (only the initial ones) 641 // the subdivision of the tree would only be driven by the statistics (the glrender could 642 // evaluate the contribution entropy for example) 643 // However might be an option to extract/store only those the rays which made a contribution 644 // (new viewcell has been discovered) or relative contribution greater than a threashold... 645 646 647 } 570 BeamSampleStatistics &stat) 571 { 572 // TODO: should be out of here 573 cgGLBindProgram(sCgFragmentProgram); 574 cgGLEnableProfile(sCgFragmentProfile); 575 576 // assumes that the beam is constructed and contains kd-tree nodes 577 // and viewcells which it intersects 578 579 580 581 582 // Get the number of viewpoints to be sampled 583 // Now it is a sqrt but in general a wiser decision could be made. 584 // The less viewpoints the better for rendering performance, since less passes 585 // over the beam is needed. 586 // The viewpoints could actually be generated outside of the bounding box which 587 // would distribute the 'efective viewpoints' of the object surface and thus 588 // with a few viewpoints better sample the vipoint space.... 589 590 int viewPointSamples = sqrt((float)desiredSamples); 591 592 // the number of direction samples per pass is given by the number of viewpoints 593 int directionalSamples = desiredSamples/viewPointSamples; 594 595 for (int i = 0; i < viewPointSamples; ++ i) 596 { 597 Vector3 viewPoint = beam.mBox.GetRandomPoint(); 598 599 // perhaps the viewpoint should be shifted back a little bit so that it always lies 600 // inside the source object 601 // 'ideally' the viewpoints would be distributed on the soureObject surface, but this 602 // would require more complicated sampling (perhaps hierarchical rejection sampling of 603 // the object surface is an option here - only the mesh faces which are inside the box 604 // are considered as candidates) 605 606 SampleViewpointContributions(sourceObject, 607 beam, 608 directionalSamples, 609 stat); 610 } 611 612 613 // note: 614 // this routine would be called only if the number of desired samples is sufficiently 615 // large - for other rss tree cells the cpu based sampling is perhaps more efficient 616 // distributing the work between cpu and gpu would also allow us to place more sophisticated 617 // sample distributions (silhouette ones) using the cpu and the jittered once on the GPU 618 // in order that thios scheme is working well the gpu render buffer should run in a separate 619 // thread than the cpu sampler, which would not be such a big problem.... 620 621 cgGLDisableProfile(sCgFragmentProfile); 622 } 623 624 625 void GlRendererBuffer::SampleViewpointContributions(Intersectable *sourceObject, 626 Beam &beam, 627 const int desiredSamples, 628 BeamSampleStatistics &stat) 629 { 630 // 1. setup the view port to match the desired samples 631 // 2. setup the projection matrix and view matrix to match the viewpoint + beam.mDirBox 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 649 650 // 4. set back to normal rendering and clear the ray termination depth buffer 651 // 5. render all objects inside the beam using id based false color 652 // (objects can be compiled to a gl list now so that subsequent rendering for 653 // this beam is fast - the same hold for step 3) 654 655 656 // 6. Now we have a two depth buffers defining the ray origin and termination 657 // only rays which have non-zero entry in the origin buffer are valid since 658 // they realy start on the object surface (this can also be tagged by setting a 659 // stencil buffer bit at step 3) 660 661 // 7. Use occlusion queries for all viewcell meshes associated with the beam -> 662 // a fragment passes if the corresponding stencil fragment is set and its depth is 663 // between origin and termination buffer 664 665 // 8. The number of visible pixels is the number of sample rays which see the source 666 // object from the corresponding viewcell -> rember these values for later update 667 // of the viewcell pvs - or update immediatelly? 668 669 // In general it is not neccessary to rember to extract all the rays cast. I hope it 670 // would be sufficient to gain only the intergral statistics about the new contributions 671 // and so the rss tree would actually store no new rays (only the initial ones) 672 // the subdivision of the tree would only be driven by the statistics (the glrender could 673 // evaluate the contribution entropy for example) 674 // However might be an option to extract/store only those the rays which made a contribution 675 // (new viewcell has been discovered) or relative contribution greater than a threashold ... 676 677 }
Note: See TracChangeset
for help on using the changeset viewer.