[162] | 1 | #ifndef _SamplingPreprocessor_H__ |
---|
| 2 | #define _SamplingPreprocessor_H__ |
---|
| 3 | |
---|
[245] | 4 | #include <fstream> |
---|
| 5 | using namespace std; |
---|
| 6 | |
---|
[162] | 7 | #include "Preprocessor.h" |
---|
| 8 | |
---|
[245] | 9 | struct SimpleRay { |
---|
| 10 | Vector3 mOrigin; |
---|
| 11 | Vector3 mDirection; |
---|
| 12 | }; |
---|
[162] | 13 | |
---|
| 14 | /** Sampling based visibility preprocessing. The implementation is based on heuristical |
---|
| 15 | sampling of view space */ |
---|
| 16 | class SamplingPreprocessor : public Preprocessor { |
---|
| 17 | public: |
---|
[256] | 18 | int mPass; |
---|
| 19 | |
---|
[176] | 20 | int mSamplesPerPass; |
---|
| 21 | int mTotalSamples; |
---|
| 22 | int mKdPvsDepth; |
---|
[245] | 23 | ofstream mStats; |
---|
| 24 | ObjectContainer mObjects; |
---|
[331] | 25 | RayContainer mSampleRays; |
---|
[329] | 26 | int mBspConstructionSamples; |
---|
[245] | 27 | |
---|
[333] | 28 | |
---|
[176] | 29 | SamplingPreprocessor(); |
---|
| 30 | |
---|
[329] | 31 | ~SamplingPreprocessor(); |
---|
| 32 | |
---|
[162] | 33 | virtual bool ComputeVisibility(); |
---|
[176] | 34 | |
---|
| 35 | void |
---|
[335] | 36 | SetupRay(Ray &ray, |
---|
| 37 | const Vector3 &point, |
---|
| 38 | const Vector3 &direction, |
---|
| 39 | const int type); |
---|
[176] | 40 | |
---|
| 41 | KdNode * |
---|
| 42 | GetNodeForPvs(KdLeaf *leaf); |
---|
| 43 | |
---|
| 44 | int |
---|
[256] | 45 | AddNodeSamples(Intersectable *object, const Ray &ray); |
---|
[176] | 46 | |
---|
[191] | 47 | void |
---|
| 48 | HoleSamplingPass(); |
---|
| 49 | |
---|
[256] | 50 | int |
---|
[354] | 51 | CastRay(Intersectable *object, Ray &ray, const bool reverseSample); |
---|
[256] | 52 | |
---|
[354] | 53 | KdNode * |
---|
| 54 | GetNodeToSample(Intersectable *object); |
---|
| 55 | void |
---|
| 56 | VerifyVisibility(Intersectable *object); |
---|
| 57 | |
---|
[333] | 58 | int |
---|
[256] | 59 | CastEdgeSamples( |
---|
| 60 | Intersectable *object, |
---|
| 61 | const Vector3 &point, |
---|
[333] | 62 | MeshInstance *mi, |
---|
[256] | 63 | const int samples |
---|
| 64 | ); |
---|
| 65 | |
---|
[362] | 66 | /** Processes the BSP based view cells during a pass. |
---|
| 67 | @param collectSamplesForBps if still in sample collection phase |
---|
| 68 | @param ray the current ray |
---|
| 69 | @param object the currently processed object |
---|
| 70 | @param faceIndex the sampled face of the object |
---|
| 71 | @param contributingSamples samples contributing to pvs |
---|
| 72 | @param sampleContributions contribution of the samples |
---|
| 73 | |
---|
| 74 | @returns true if BSP tree has been constructed, false if not yet |
---|
| 75 | |
---|
[308] | 76 | */ |
---|
[362] | 77 | bool ProcessBspViewCells(bool collectSamplesForBsp, |
---|
| 78 | Ray &ray, |
---|
| 79 | Intersectable *object, |
---|
| 80 | int faceIndex, |
---|
| 81 | int &contributingSamples, |
---|
| 82 | int &sampleContributions); |
---|
| 83 | |
---|
| 84 | /** Adds objects samples to bsp view cells. |
---|
| 85 | */ |
---|
[308] | 86 | int AddObjectSamples(Intersectable *obj, const Ray &ray); |
---|
[329] | 87 | |
---|
| 88 | bool BuildBspTree(); |
---|
[349] | 89 | |
---|
| 90 | void ExportSplits(const ObjectContainer &objects); |
---|
[362] | 91 | |
---|
| 92 | void ExportBspPvs(const ObjectContainer &objects); |
---|
| 93 | |
---|
| 94 | /** Post processes view cells (i.e., merges or subdivides view cells based |
---|
| 95 | on the PVS and the ray sets. |
---|
| 96 | @returns number of merged view cells. |
---|
| 97 | */ |
---|
| 98 | int PostprocessViewCells(const RayContainer &rays); |
---|
| 99 | |
---|
[162] | 100 | }; |
---|
| 101 | |
---|
| 102 | |
---|
| 103 | |
---|
| 104 | #endif |
---|