-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSampler.h
More file actions
52 lines (46 loc) · 1.59 KB
/
Copy pathSampler.h
File metadata and controls
52 lines (46 loc) · 1.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#pragma once
class Ray;
class Scene;
class HitPoint;
class RGBColor;
class GeoPrimitive;
class Sampler
{
private:
Scene* scene;
Ray ray;
public:
// Comstruct from a scene ptr
Sampler(Scene* sceneInput);
~Sampler();
// Set Ray
void set_ray(Ray& rayInput);
// Start sampling the scene with defult depth 0
RGBColor sample();
// The method to recursively sample the scene
RGBColor sample(Ray& ray_process, const int depth);
// The method to shade current HitPoint, called in sample
void shade(Ray& ray_process, HitPoint& hitPoint, RGBColor& color, const int depth);
// Visibility query, use the cache or directly use the BVH, starting from certain depth
bool isVisible(Ray& shadowRay, Normal& norml, const int depth);
// Visibility query, use the cache or directly use the BVH
bool isVisible(Ray& shadowRay, Normal& norml);
friend class Material;
};
// Non-member function
// A Many Light Rendering Algorithm
// The function to randomly select a light index with uniform distribution. Probablity of being chosen equals their importance
int random_light_index(std::vector<float>& list);
// The function to build a importance list for lights
void build_importance_list(const std::vector<GeoPrimitive*>&, const HitPoint&, std::vector<float>&);
// Inline non-member functions
// Balanced heuristic and power heuristic, based on Veach's MIS, from PBRT
inline float BalanceHeuristic(int nf, float fPdf, int ng, float gPdf)
{
return (nf * fPdf) / (nf * fPdf + ng * gPdf);
}
inline float PowerHeuristic(int nf, float fPdf, int ng, float gPdf)
{
float f = nf * fPdf, g = ng * gPdf;
return (f * f) / (f * f + g * g);
}