-
Notifications
You must be signed in to change notification settings - Fork 0
/
SceneVPMObject.h
104 lines (101 loc) · 2.46 KB
/
SceneVPMObject.h
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
91
92
93
94
95
96
97
98
99
100
101
102
103
#pragma once
#include "SceneObject.h"
#include "HomoMediaDistSampler.h"
#include "HGPhaseSampler.h"
#include "IsotropicPhaseSampler.h"
#include "HGPhaseFunc.h"
#include "IsotropicPhaseFunc.h"
#include "volumeData.h"
class SceneVPMObject : public SceneObject
{
public:
BSDF* bsdf;
vec3f ds, da, dt;
float g;
float stepSize;
float IOR;
Ray scatter(const Ray& inRay, const bool russian = true) const;
bool isVolumetric() { return true; }
bool hasCosineTerm() { return false; }
bool isHomogeneous() { return true; }
protected:
float y(vec3f c) const {
const float YWeight[3] = { 0.212671f, 0.715160f, 0.072169f };
return YWeight[0] * c[0] + YWeight[1] * c[1] + YWeight[2] * c[2];
}
vec3f transmittance(float dist) const{
vec3f tr;
for(int i = 0; i < 3; i++){
tr[i] = exp(-dt[i] * dist);
}
return tr;
}
float p_medium(float s) const{
vec3f pm;
for(int i = 0; i < 3; i++){
pm[i] = dt[i] * exp(-dt[i] * s);
}
return y(pm);
}
float P_surface(float d) const{
vec3f Pd;
for(int i = 0; i < 3; i++){
Pd[i] = exp(-dt[i] * d);
}
return y(Pd);
}
public:
virtual vec3f getRadianceDecay(const Ray &inRay, const float &dist) const ;
vec3f getBSDF(const Ray& inRay, const Ray& outRay) const;
float getDirectionSampleProbDensity(const Ray& inRay, const Ray& outRay) const;
float getOriginSampleProbDensity(const Ray& inRay, const Ray& outRay) const;
float getContinueProbability(const Ray &inRay, const Ray &outRay) const;
float getRefrCoeff() const {
return IOR;
}
float getG() const {
return g;
}
SceneVPMObject(Scene* scene) : SceneObject(scene)
{
canMerge = true;
stepSize = 0.0005;
}
~SceneVPMObject()
{
delete bsdf;
}
float getAlbedo() const{
return y(ds) / y(dt);
}
void setSSS(std::string name){
std::cout << "in VPM setSSS" << " " << name << std::endl;
bool success = search_sss_color(name, da, ds);
std::cout << "ds: " << ds.x << ' ' << ds.y << ' ' << ds.z << std::endl;
std::cout << "da: " << da.x << ' ' << da.y << ' ' << da.z << std::endl;
if(!success){
std::cerr << "sss not found " << std::endl;
}
}
void setSigma(vec3f sigma_s, vec3f sigma_a){
ds = sigma_s;
da = sigma_a;
dt = ds + da;
}
void setInRate(float ior){
IOR = ior;
}
void setG(float g){
this->g = g;
bsdf = new HGPhaseFunc(g);
//std::cout << "new hg phase function g= " << g<<std::endl;
}
void setStepSize(float step){
stepSize = step;
}
void setScale(float scale){
ds *= scale;
da *= scale;
dt *= scale;
}
};