-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSampler.h
More file actions
90 lines (75 loc) · 2.14 KB
/
Sampler.h
File metadata and controls
90 lines (75 loc) · 2.14 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#pragma once
#include "stdafx.h"
#include "Screen.h"
#include "Object.h"
#include "Scene.h"
enum RayType { CAMERA, DIFFUSE, SPECULAR_REFLECT, SPECULAR_REFRACT_IN, SPECULAR_REFRACT_OUT, SCATTER};
struct RaySample{
EIGEN_MAKE_ALIGNED_OPERATOR_NEW
Vector3R v;
Color radiance;
Real weight;
RayType type = DIFFUSE;
};
struct Sample2D {
Sample2D() {}
Real u, v;
Sample2D(Real _u, Real _v) : u(_u), v(_v) {}
Color value;
};
struct PreSample3D {
PreSample3D() {}
Real x, y, z;
Real weight;
PreSample3D(Real _x, Real _y, Real _z, Real _w) :
x(_x), y(_y), z(_z), weight(_w) {}
};
struct PreSamplePool3D {
PreSamplePool3D() {}
std::vector<PreSample3D> presamples;
int elementCount;
int cursor;
};
class Sampler2D {
public:
Sampler2D() {}
~Sampler2D() {}
virtual std::vector<Sample2D> sample_UnitSquare_Uniform(int) = 0;
std::vector<Sample2D> sampleTriangle(int n);
protected:
std::default_random_engine gen;
std::uniform_real_distribution<Real> uniform_01 = std::uniform_real_distribution<Real>(0.0, 1.0);
};
class Sampler3D {
public:
Sampler3D();
~Sampler3D(){};
// return a random real in [0,1);
Real getUniform_01();
// the only abstract function
void generatePreSamples_Diffuse(int numSamples);
void generatePreSamples_Specular(int numSamples, int N);
// get a single sample
Vector3R sample_Diffuse_P(const Vector3R&);
Vector3R sample_Specular_P(const Vector3R&, const Vector3R&, int N);
// get a single sample
RaySample sample(const Vector3R &in, const Vector3R &normal, const MaterialPtr &mPtr);
private:
std::default_random_engine gen;
std::uniform_real_distribution<Real> uniform_01 = std::uniform_real_distribution<Real>(0.0, 1.0);
PreSamplePool3D presamples_Diffuse;
std::map<int, PreSamplePool3D> presamples_Specular;
PreSamplePool3D presamples_Diffuse_Single;
std::map<int, PreSamplePool3D> presamples_Specular_Single;
Sample2D sampleUnitSquare_Uniform();
};
class StratifiedSampler : public Sampler2D {
public:
StratifiedSampler() {}
std::vector<Sample2D> sample_UnitSquare_Uniform(int);
};
class LatinCubeSampler : public Sampler2D {
public:
LatinCubeSampler() {}
std::vector<Sample2D> sample_UnitSquare_Uniform(int);
};