-
Notifications
You must be signed in to change notification settings - Fork 0
/
DiffuseMaterial.h
54 lines (41 loc) · 1.09 KB
/
DiffuseMaterial.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
#pragma once
#include "Material.h"
class Texture;
class DiffuseMaterial : public Material
{
public:
DiffuseMaterial(Texture *t) : R(t) { this->emission = rgb(); }
virtual void setEmission(float inintensity) override {
this->emission = rgb(inintensity);
}
virtual rgb AmbientResponse(const Vector3 &tex_point, const Vector2 &uv) override {
return R->Value(uv, tex_point);
}
virtual bool ExplicitBRDF(const Vector3 &p, const Vector2 &uv, rgb &brdf) override {
float k = .318309886184f; // 1.0/PI
brdf = k * this->AmbientResponse(p, uv);
return true;
}
virtual bool DiffuseDirection(const ONB &uvw,
const Vector3 &,
const Vector3 &p,
const Vector2 &uv,
Vector2 &seed,
rgb &color,
Vector3 &v_out) override
{
float pi = 3.1415926535f;
float phi = 2 * pi*seed.x;
float r = sqrt(seed.y);
float x = r*cos(phi);
float y = r*sin(phi);
float z = sqrt(1 - x*x - y*y);
color = this->AmbientResponse(p, uv);
v_out = x*uvw.u + y*uvw.v + z*uvw.w;
seed.Scramble();
return true;
}
virtual bool IsDiffuse() override { return true; }
public:
Texture *R;
};