1 | #ifndef _SamplingPreprocessor_H__ |
---|
2 | #define _SamplingPreprocessor_H__ |
---|
3 | |
---|
4 | #include <fstream> |
---|
5 | using namespace std; |
---|
6 | |
---|
7 | #include "Preprocessor.h" |
---|
8 | |
---|
9 | |
---|
10 | /** Sampling based visibility preprocessing. The implementation is based on heuristical |
---|
11 | sampling of view space */ |
---|
12 | class SamplingPreprocessor : public Preprocessor { |
---|
13 | public: |
---|
14 | |
---|
15 | SamplingPreprocessor(); |
---|
16 | |
---|
17 | ~SamplingPreprocessor(); |
---|
18 | |
---|
19 | virtual bool ComputeVisibility(); |
---|
20 | |
---|
21 | protected: |
---|
22 | int mPass; |
---|
23 | |
---|
24 | int mSamplesPerPass; |
---|
25 | int mTotalSamples; |
---|
26 | int mKdPvsDepth; |
---|
27 | ofstream mStats; |
---|
28 | ObjectContainer mObjects; |
---|
29 | RayContainer mSampleRays; |
---|
30 | int mBspConstructionSamples; |
---|
31 | int mPostProcessSamples; |
---|
32 | |
---|
33 | |
---|
34 | void |
---|
35 | SetupRay(Ray &ray, |
---|
36 | const Vector3 &point, |
---|
37 | const Vector3 &direction, |
---|
38 | const int type); |
---|
39 | |
---|
40 | KdNode * |
---|
41 | GetNodeForPvs(KdLeaf *leaf); |
---|
42 | |
---|
43 | int |
---|
44 | AddNodeSamples(const Ray &ray, |
---|
45 | Intersectable *sObject, |
---|
46 | Intersectable *tObject |
---|
47 | ); |
---|
48 | |
---|
49 | void |
---|
50 | HoleSamplingPass(); |
---|
51 | |
---|
52 | int |
---|
53 | CastRay(Intersectable *object, |
---|
54 | Ray &ray); |
---|
55 | |
---|
56 | KdNode * |
---|
57 | GetNodeToSample(Intersectable *object); |
---|
58 | void |
---|
59 | VerifyVisibility(Intersectable *object); |
---|
60 | |
---|
61 | int |
---|
62 | CastEdgeSamples( |
---|
63 | Intersectable *object, |
---|
64 | const Vector3 &point, |
---|
65 | MeshInstance *mi, |
---|
66 | const int samples |
---|
67 | ); |
---|
68 | |
---|
69 | /** Processes the BSP based view cells during a pass. |
---|
70 | |
---|
71 | @param ray the current ray |
---|
72 | @param object the currently processed object |
---|
73 | @param faceIndex the sampled face of the object |
---|
74 | @param contributingSamples samples contributing to pvs |
---|
75 | @param sampleContributions contribution of the samples |
---|
76 | */ |
---|
77 | void ProcessBspViewCells(Ray &ray, |
---|
78 | Intersectable *object, |
---|
79 | int faceIndex, |
---|
80 | int &contributingSamples, |
---|
81 | int &sampleContributions); |
---|
82 | |
---|
83 | /** Adds objects samples to bsp view cells. |
---|
84 | */ |
---|
85 | int AddObjectSamples(Intersectable *obj, const Ray &ray); |
---|
86 | |
---|
87 | bool BuildBspTree(); |
---|
88 | |
---|
89 | void ExportSplits(const ObjectContainer &objects); |
---|
90 | |
---|
91 | void ExportBspPvs(const ObjectContainer &objects); |
---|
92 | |
---|
93 | /** Post processes view cells (i.e., merges or subdivides view cells based |
---|
94 | on the PVS and the ray sets. |
---|
95 | @param rays a set of rays which carries the visibility information |
---|
96 | the merging / subdivision is based on. |
---|
97 | @returns number of merged view cells. |
---|
98 | */ |
---|
99 | int PostprocessViewCells(const RayContainer &rays); |
---|
100 | |
---|
101 | /** Simulated rendering using a simple render heuristics. Used to evaluate the |
---|
102 | quality of the view cell partition. |
---|
103 | */ |
---|
104 | Real SimulateRendering(); |
---|
105 | /** Simulates rendering of the pvs of one view cell, with given rendering time for an object. |
---|
106 | @param viewCell the view cell holding the Pvs |
---|
107 | @param objRenderTime estimated render time for one object of the Pvs |
---|
108 | */ |
---|
109 | Real RenderPvs(ViewCell &viewCell, const float objRenderTime) const; |
---|
110 | |
---|
111 | }; |
---|
112 | |
---|
113 | |
---|
114 | |
---|
115 | #endif |
---|