INFO804 Introduction à l'informatique graphique
Loading...
Searching...
No Matches
Material.h
Go to the documentation of this file.
1/**
2@file Material.h
3@author JOL
4*/
5#pragma once
6#ifndef _MATERIAL_H_
7#define _MATERIAL_H_
8
9#include "Color.h"
10
11// @see http://devernay.free.fr/cours/opengl/materials.html
12
13/// Namespace RayTracer
14namespace rt {
15
16 /// This structure stores the material associated to a graphical object.
17 /// object should have.
18 struct Material {
19 /// ambient color
21 /// diffuse color
23 /// specular color
25 /// shinyness (50: very high, 1: low )
27
28 // --------- The following data is used in later questions. --------------
29
30 /// The material is perfectly diffuse if coef_diffusion == 1.0,
31 /// otherwise it may have reflexion / transparency properties.
33 /// The material has some specularity if coef_reflexion > 0.0
35 /// The material is transparent if coef_refraction > 0.0
37 /// Refractive index (1.0f in vacuum, 1.31 in ice, 1.52 window glass, 1.33 water
38 /// Inside refractive index (for transparent medium) (>= 1.0f)
40 /// Outside refractive index (1.0f if object is in the air otherwise >= 1.0f)
42
43 /// Mixes two material (t=0 gives m1, t=1 gives m2, t=0.5 gives their average)
44 static Material mix( Real t, const Material& m1, const Material& m2 )
45 {
46 Material m;
47 Real s = 1.0f - t;
48 m.ambient = s * m1.ambient + t * m2.ambient;
49 m.diffuse = s * m1.diffuse + t * m2.diffuse;
50 m.specular = s * m1.specular + t * m2.specular;
51 m.shinyness = s * m1.shinyness + t * m2.shinyness;
57 return m;
58 }
59
60 /// Default constructor
62
63 /// Constructor from colors and shinyness.
64 Material( Color amb, Color diff, Color spec, Real shiny = 0.0f,
65 Real cdiff = 1.0f, Real crefl = 0.0f, Real crefr = 0.0f,
66 Real in_ridx = 1.0f, Real out_ridx = 1.0f )
67 : ambient( amb ), diffuse( diff ), specular( spec ), shinyness( shiny ),
68 coef_diffusion( cdiff ), coef_reflexion( crefl ), coef_refraction( crefr ),
69 in_refractive_index( in_ridx ), out_refractive_index( out_ridx )
70 {}
71
72 static Material whitePlastic()
73 {
74 Material m;
75 m.ambient = Color( 0.1, 0.1, 0.1 );
76 m.diffuse = Color( 0.7, 0.7, 0.7 );
77 m.specular = Color( 1.0, 1.0, 0.98 );
78 m.shinyness = 5.0;
79 m.coef_diffusion = 0.9f;
80 m.coef_reflexion = 0.1f;
81 m.coef_refraction = 0.0f;
82 m.in_refractive_index = 1.0f;
83 m.out_refractive_index = 1.0f;
84 return m;
85 }
86 static Material redPlastic()
87 {
88 Material m;
89 m.ambient = Color( 0.1, 0.0, 0.0 );
90 m.diffuse = Color( 0.85, 0.05, 0.05 );
91 m.specular = Color( 1.0, 0.8, 0.8 );
92 m.shinyness = 5.0;
93 m.coef_diffusion = 1.0f;
94 m.coef_reflexion = 0.05f;
95 m.coef_refraction = 0.0f;
96 m.in_refractive_index = 1.0f;
97 m.out_refractive_index = 1.0f;
98 return m;
99 }
100 static Material bronze()
101 {
102 Material m;
103 m.ambient = Color( 0.1125, 0.0675, 0.054 );
104 m.diffuse = Color( 0.714, 0.4284, 0.18144 );
105 m.specular = Color( 0.9, 0.8, 0.7 );
106 // m.specular = Color( 0.393548, 0.271906, 0.166721 );
107 m.shinyness = 56; // 25.6;
108 m.coef_diffusion = 0.5f;
109 m.coef_reflexion = 0.75f;
110 m.coef_refraction = 0.0f;
111 m.in_refractive_index = 1.0f;
112 m.out_refractive_index = 1.0f;
113 return m;
114 }
115 static Material emerald()
116 {
117 Material m;
118 m.ambient = Color( 0.0f, 0.01f, 0.0f ); //Color( 0.0215, 0.1745, 0.0215 );
119 m.diffuse = Color( 0.09568, 0.77424, 0.10 );
120 m.specular = Color( 0.9, 1.0, 0.9 ); // Color( 0.633, 0.727811, 0.633 );
121 m.shinyness = 0.6*128.0;
122 m.coef_diffusion = 0.15f;
123 m.coef_reflexion = 0.5f;
124 m.coef_refraction = 0.65f;
125 m.in_refractive_index = 1.5f;
126 m.out_refractive_index = 1.0f;
127 return m;
128 }
129 static Material glass()
130 {
131 Material m;
132 m.ambient = Color( 0.0, 0.0, 0.0 );
133 m.diffuse = Color( 0.95, 0.95, 1.0 );
134 m.specular = Color( 1.0, 1.0, 1.0 );
135 m.shinyness = 80.0f;
136 m.coef_diffusion = 0.01f;
137 m.coef_reflexion = 0.05f;
138 m.coef_refraction = 0.98f;
139 m.in_refractive_index = 1.5f;
140 m.out_refractive_index = 1.0f;
141 return m;
142 }
143 };
144
145
146
147} // namespace rt
148
149#endif // #define _MATERIAL_H_
Namespace RayTracer.
Definition Color.h:11
float Real
the type for representing a real number.
Real coef_refraction
The material is transparent if coef_refraction > 0.0.
Definition Material.h:36
Real shinyness
shinyness (50: very high, 1: low )
Definition Material.h:26
Real in_refractive_index
Definition Material.h:39
Material(Color amb, Color diff, Color spec, Real shiny=0.0f, Real cdiff=1.0f, Real crefl=0.0f, Real crefr=0.0f, Real in_ridx=1.0f, Real out_ridx=1.0f)
Constructor from colors and shinyness.
Definition Material.h:64
Color diffuse
diffuse color
Definition Material.h:22
static Material mix(Real t, const Material &m1, const Material &m2)
Mixes two material (t=0 gives m1, t=1 gives m2, t=0.5 gives their average)
Definition Material.h:44
Real out_refractive_index
Outside refractive index (1.0f if object is in the air otherwise >= 1.0f)
Definition Material.h:41
Real coef_diffusion
Definition Material.h:32
Real coef_reflexion
The material has some specularity if coef_reflexion > 0.0.
Definition Material.h:34
Color ambient
ambient color
Definition Material.h:20
Material()
Default constructor.
Definition Material.h:61
Color specular
specular color
Definition Material.h:24