Changeset 507


Ignore:
Timestamp:
01/07/06 10:50:29 (18 years ago)
Author:
bittner
Message:

Preparation for hw based sampling

Location:
trunk/VUT/GtpVisibilityPreprocessor/src
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/VUT/GtpVisibilityPreprocessor/src/Beam.cpp

    r506 r507  
    4040        } 
    4141  } 
     42 
     43  mBox = box; 
     44  mDirBox = dBox; 
     45   
     46  SetValid(); 
    4247} 
    4348 
  • trunk/VUT/GtpVisibilityPreprocessor/src/Beam.h

    r506 r507  
    1212   
    1313public:                  
    14   enum {STORE_KD_NODES=1, STORE_OBJECTS=2}; 
     14  enum {STORE_KD_NODES=1, STORE_OBJECTS=2, VALID=4}; 
    1515  int mFlags; 
    1616   
    1717  // list of nodes intersected by the frustum 
    1818  vector<KdNode *> mKdNodes; 
    19   // lits of objects intersected by the frum 
     19  // lits of objects intersected by the frustum 
    2020  vector<Intersectable *> mObjects; 
    21  
    2221 
    2322  // spatial box 
     
    2827 
    2928  vector<Plane3> mPlanes; 
    30    
    31   Beam():mFlags(STORE_KD_NODES+STORE_OBJECTS) 
     29 
     30  bool IsValid() { return mFlags & VALID; } 
     31  bool SetValid() { return mFlags |= VALID; } 
     32 
     33  Beam():mFlags(STORE_KD_NODES+STORE_OBJECTS),mKdNodes(0), mObjects(0) 
    3234  { 
    3335  } 
     
    3638                                 const  AxisAlignedBox3 &dBox); 
    3739   
    38  
     40   
    3941  int 
    4042  ComputeIntersection(const  AxisAlignedBox3 &box); 
  • trunk/VUT/GtpVisibilityPreprocessor/src/GlRenderer.cpp

    r504 r507  
    55#include "Pvs.h" 
    66#include "Viewcell.h" 
     7#include "Beam.cpp" 
    78 
    89#include <GL/glext.h> 
     
    529530   
    530531} 
     532 
     533 
     534void 
     535GlRendererBuffer::SampleBeamContributions( 
     536                                                                                  Intersectable *sourceObject, 
     537                                                                                  Beam &beam, 
     538                                                                                  const int desiredSamples, 
     539                                                                                  BeamSampleStatistics &stat 
     540                                                                                  ) 
     541{ 
     542  // assumes that the beam is constructed and contains kd-tree nodes 
     543  // and viewcells which it intersects 
     544 
     545 
     546   
     547   
     548  // Get the number of viewpoints to be sampled 
     549  // Now it is a sqrt but in general a wiser decision could be made. 
     550  // The less viewpoints the better for rendering performance, since less passes 
     551  // over the beam is needed. 
     552  // The viewpoints could actually be generated outside of the bounding box which 
     553  // would distribute the 'efective viewpoints' of the object surface and thus 
     554  // with a few viewpoints better sample the vipoint space.... 
     555   
     556  int viewPointSamples = sqrt((float)desiredSamples); 
     557 
     558  // the number of direction samples per pass is given by the number of viewpoints 
     559  int directionalSamples = desiredSamples/viewPointSamples; 
     560  int i; 
     561  for (i=0; i < viewPointSamples; i++) { 
     562        Vector3 viewPoint = beam.mBox.GetRandomPoint(); 
     563        // perhaps the viewpoint should be shifted back a little bit so that it always lies 
     564        // inside the source object 
     565        // 'ideally' the viewpoints would be distributed on the soureObject surface, but this 
     566        // would require more complicated sampling (perhaps hierarchical rejection sampling of 
     567        // the object surface is an option here - only the mesh faces which are inside the box 
     568        // are considered as candidates)  
     569        SampleViewpointContributions( 
     570                                                                  sourceObject, 
     571                                                                  beam, 
     572                                                                  directionalSamples, 
     573                                                                  stat 
     574                                                                  ); 
     575  } 
     576 
     577 
     578  // note: 
     579  // this routine would be called only if the number of desired samples is sufficiently 
     580  // large - for other rss tree cells the cpu based sampling is perhaps more efficient 
     581  // distributing the work between cpu and gpu would also allow us to place more sophisticated 
     582  // sample distributions (silhouette ones) using the cpu and the jittered once on the GPU 
     583  // in order that thios scheme is working well the gpu render buffer should run in a separate 
     584  // thread than the cpu sampler, which would not be such a big problem.... 
     585} 
     586 
     587 
     588void 
     589GlRendererBuffer::SampleViewpointContributions( 
     590                                                                                           Intersectable *sourceObject, 
     591                                                                                           Beam &beam, 
     592                                                                                           const int desiredSamples, 
     593                                                                                           BeamSampleStatistics &stat 
     594                                                                                           ) 
     595{ 
     596  // 1. setup the view port to match the desired samples 
     597  // 2. setup the projection matrix and view matrix to match the viewpoint + beam.mDirBox 
     598   
     599  // 3. reset z-buffer to 0 and render the source object for the beam using 
     600  //    glDepthFunc(GL_GREATER) 
     601  //    and glCullFace(Enabled) and glFrontFace(GL_CW) 
     602  //    remember the ray origin depth buffer somewhere? 
     603 
     604  // 4. set back to normal rendering and clear the ray termination depth buffer 
     605  // 5. render all objects inside the beam using id based false color 
     606  //    (objects can be compiled to a gl list now so that subsequent rendering for 
     607  //     this beam is fast - the same hold for step 3) 
     608 
     609 
     610  // 6. Now we have a two depth buffers defining the ray origin and termination 
     611  //    only rays which have non-zero entry in the origin buffer are valid since 
     612  //    they realy start on the object surface (this can also be tagged by setting a 
     613  //    stencil buffer bit at step 3) 
     614 
     615  // 7. Use occlusion queries for all viewcell meshes associated with the beam -> 
     616  // a fragment passes if the corresponding stencil fragment is set and its depth is 
     617  // between origin and termination buffer 
     618 
     619  // 8. The number of visible pixels is the number of sample rays which see the source 
     620  //    object from the corresponding viewcell -> rember these values for later update 
     621  //   of the viewcell pvs - or update immediatelly? 
     622 
     623  //  In general it is not neccessary to rember to extract all the rays cast. I hope it 
     624  // would be sufficient to gain only the intergral statistics about the new contributions 
     625  // and so the rss tree would actually store no new rays (only the initial ones) 
     626  // the subdivision of the tree would only be driven by the statistics (the glrender could 
     627  // evaluate the contribution entropy for example) 
     628  // However might be an option to extract/store only those the rays which made a contribution 
     629  // (new viewcell has been discovered) or relative contribution greater than a threashold... 
     630        
     631   
     632} 
  • trunk/VUT/GtpVisibilityPreprocessor/src/GlRenderer.h

    r504 r507  
    1717class Intersectable; 
    1818class Material; 
     19class Beam; 
    1920 
    2021struct PvsRenderStatistics { 
     
    129130  void 
    130131  ClearErrorBuffer(); 
    131  
    132132   
    133133 
    134134  virtual int GetWidth() const { return width(); } 
    135135  virtual int GetHeight() const { return height(); } 
     136 
     137 
     138 
     139  // the values need for rss tree update computed already inside the glrendererbuffer 
     140  // not all of them need to be computed 
     141  struct BeamSampleStatistics { 
     142 
     143        enum {COMPUTE_PVS_SIZE, COMPUTE_RAY_CONTRIBUTIONS, COMPUTE_PVS_ENTROPY}; 
     144        int flags; 
     145 
     146        BeamSampleStatistics():flags(COMPUTE_RAY_CONTRIBUTIONS) {} 
     147         
     148        float pvsSize; 
     149        float rays; 
     150        float rayContributions; 
     151        float pvsEntropy; 
     152        float rayLengthEntropy; 
     153        float importance; 
     154         
     155        float weightedRayContribution; 
     156  }; 
     157   
     158 
     159  void SampleBeamContributions( 
     160                                                           Intersectable *sourceObject, 
     161                                                           Beam &beam, 
     162                                                           const int samples, 
     163                                                           BeamSampleStatistics &stat 
     164                                                           ); 
     165 
     166  void 
     167  SampleViewpointContributions( 
     168                                                           Intersectable *sourceObject, 
     169                                                           Beam &beam, 
     170                                                           const int desiredSamples, 
     171                                                           BeamSampleStatistics &stat 
     172                                                           ); 
    136173 
    137174}; 
  • trunk/VUT/GtpVisibilityPreprocessor/src/KdTree.cpp

    r505 r507  
    941941KdTree::GetRandomLeaf(const bool onlyUnmailed) 
    942942{ 
    943         stack<KdNode *> nodeStack; 
     943  stack<KdNode *> nodeStack; 
    944944  nodeStack.push(mRoot); 
    945  
    946         int mask = rand(); 
     945   
     946  int mask = rand(); 
    947947         
    948948  while (!nodeStack.empty()) { 
     
    967967 
    968968int 
    969 CastBeam( 
    970                  Beam &beam 
    971                  ) 
    972 { 
    973    
    974  
    975   return 0; 
    976 } 
     969KdTree::CastBeam( 
     970                                 Beam &beam 
     971                                 ) 
     972{ 
     973  stack<KdNode *> nodeStack; 
     974  nodeStack.push(mRoot); 
     975   
     976  while (!nodeStack.empty()) { 
     977    KdNode *node = nodeStack.top(); 
     978    nodeStack.pop(); 
     979         
     980        int side = beam.ComputeIntersection(GetBox(node)); 
     981        switch (side) { 
     982        case -1: 
     983          beam.mKdNodes.push_back(node); 
     984          break; 
     985        case 0: 
     986          if (node->IsLeaf()) 
     987                beam.mKdNodes.push_back(node); 
     988          else { 
     989                KdInterior *interior = (KdInterior *)node; 
     990                KdNode *first = interior->mBack; 
     991                KdNode *second = interior->mFront; 
     992                 
     993                if (interior->mAxis < 3) { 
     994                  // spatial split -> decide on the order of the nodes 
     995                  if (beam.mPlanes[0].mNormal[interior->mAxis] > 0) 
     996                        swap(first, second); 
     997                } 
     998 
     999                nodeStack.push(first); 
     1000                nodeStack.push(second); 
     1001          } 
     1002          break; 
     1003          // default: cull 
     1004        } 
     1005  } 
     1006 
     1007  return beam.mKdNodes.size(); 
     1008} 
  • trunk/VUT/GtpVisibilityPreprocessor/src/Makefile

    r505 r507  
    11############################################################################# 
    22# Makefile for building: preprocessor 
    3 # Generated by qmake (2.00a) (Qt 4.1.0) on: pá 6. I 14:52:19 2006 
     3# Generated by qmake (2.00a) (Qt 4.1.0) on: so 7. I 10:49:27 2006 
    44# Project:  preprocessor.pro 
    55# Template: app 
  • trunk/VUT/GtpVisibilityPreprocessor/src/RssTree.cpp

    r500 r507  
    20032003        return; 
    20042004   
     2005   
    20052006  int nrays = leaf->rays.size(); 
    20062007 
     
    20082009  AxisAlignedBox3 box = GetBBox(leaf); 
    20092010  AxisAlignedBox3 dirBox = GetDirBBox(leaf); 
     2011 
    20102012 
    20112013  AxisAlignedBox3 sBox(box); 
  • trunk/VUT/GtpVisibilityPreprocessor/src/RssTree.h

    r492 r507  
    2222#include "AxisAlignedBox3.h" 
    2323#include "Halton.h" 
    24  
     24#include "beam.h" 
    2525 
    2626#define USE_KDNODE_VECTORS 1 
     
    419419   
    420420  HaltonSequence halton; 
     421 
     422  Beam mBeam; 
    421423   
    422424  RssTreeLeaf(RssTreeInterior *p, 
  • trunk/VUT/GtpVisibilityPreprocessor/src/default.env

    r504 r507  
    1515filename ../data/atlanta/atlanta2.x3d 
    1616# filename ../data/soda/soda.dat 
    17 # filename ../data/soda/soda5.dat 
     17filename ../data/soda/soda5.dat 
    1818} 
    1919 
Note: See TracChangeset for help on using the changeset viewer.