-
Notifications
You must be signed in to change notification settings - Fork 0
/
material.h
80 lines (63 loc) · 2.04 KB
/
material.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
#ifndef _MATERIAL_H_
#define _MATERIAL_H_
#include "glCanvas.h"
#include <cassert>
#include <string>
#include "vectors.h"
#include "image.h"
class ArgParser;
class Ray;
class Hit;
// ====================================================================
// ====================================================================
// A simple Phong-like material
class Material {
public:
Material(const std::string &texture_file, const Vec3f &d_color,
const Vec3f &r_color, const Vec3f &e_color, double roughness_) {
textureFile = texture_file;
if (textureFile != "") {
image = new Image(textureFile);
ComputeAverageTextureColor();
} else {
diffuseColor = d_color;
image = NULL;
}
reflectiveColor = r_color;
emittedColor = e_color;
roughness = roughness_;
// need to initialize texture_id after glut has started
texture_id = 0;
}
~Material();
// ACCESSORS
const Vec3f& getDiffuseColor() const { return diffuseColor; }
const Vec3f getDiffuseColor(double s, double t) const;
const Vec3f& getReflectiveColor() const { return reflectiveColor; }
const Vec3f& getEmittedColor() const { return emittedColor; }
double getRoughness() const { return roughness; }
bool hasTextureMap() const { return (textureFile != std::string("")); }
GLuint getTextureID();
// SHADE
// compute the contribution to local illumination at this point for
// a particular light source
Vec3f Shade
(const Ray &ray, const Hit &hit, const Vec3f &dirToLight,
const Vec3f &lightColor, ArgParser *args) const;
protected:
Material() { exit(0); }
Material(const Material&) { exit(0); }
const Material& operator=(const Material&) { exit(0); }
void ComputeAverageTextureColor();
// REPRESENTATION
Vec3f diffuseColor;
Vec3f reflectiveColor;
Vec3f emittedColor;
double roughness;
std::string textureFile;
GLuint texture_id;
Image *image;
};
// ====================================================================
// ====================================================================
#endif