Welcome to mirror list, hosted at ThFree Co, Russian Federation.

FrsMaterial.h « scene_graph « intern « freestyle « blender « source - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 43a61e772f9d5f99c9dad007f3bbf583d3ad22b9 (plain)
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
/*
 * ***** BEGIN GPL LICENSE BLOCK *****
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 *
 * ***** END GPL LICENSE BLOCK *****
 */

#ifndef __FREESTYLE_MATERIAL_H__
#define __FREESTYLE_MATERIAL_H__

/** \file blender/freestyle/intern/scene_graph/FrsMaterial.h
 *  \ingroup freestyle
 *  \brief Class used to handle materials.
 *  \author Stephane Grabli
 *  \date 10/10/2002
 */

#include "../system/FreestyleConfig.h"

namespace Freestyle {

/*! Class defining a material */
class FrsMaterial
{
public:
	/*! Default constructor */
	inline FrsMaterial();

	/*! Builds a Material from its diffuse, ambiant, specular, emissive colors and a shininess coefficient.
	 *    \param iDiffuse
	 *      A 4 element float-array containing the diffuse color.
	 *    \param iAmbiant
	 *      A 4 element float-array containing the ambiant color.
	 *    \param iSpecular
	 *      A 4 element float-array containing the specular color.
	 *    \param iEmission
	 *      A 4 element float-array containing the emissive color.
	 *    \param iShininess
	 *      The shininess coefficient.
	 */
	inline FrsMaterial(const float *iDiffuse, const float *iAmbiant, const float *iSpecular, const float *iEmission,
	                   const float iShininess);

	/*! Copy constructor */
	inline FrsMaterial(const FrsMaterial& m);

	/*! Destructor */
	virtual ~FrsMaterial() {}


	/*! Returns the diffuse color as a 4 float array */
	inline const float *diffuse() const
	{
		return Diffuse;
	}

	/*! Returns the red component of the diffuse color */
	inline const float diffuseR() const
	{
		return Diffuse[0];
	}

	/*! Returns the green component of the diffuse color */
	inline const float diffuseG() const
	{
		return Diffuse[1];
	}

	/*! Returns the blue component of the diffuse color */
	inline const float diffuseB() const
	{
		return Diffuse[2];
	}

	/*! Returns the alpha component of the diffuse color */
	inline const float diffuseA() const
	{
		return Diffuse[3];
	}

	/*! Returns the specular color as a 4 float array */
	inline const float *specular() const
	{
		return Specular;
	}

	/*! Returns the red component of the specular color */
	inline const float specularR() const
	{
		return Specular[0];
	}

	/*! Returns the green component of the specular color */
	inline const float specularG() const
	{
		return Specular[1];
	}

	/*! Returns the blue component of the specular color */
	inline const float specularB() const
	{
		return Specular[2];
	}

	/*! Returns the alpha component of the specular color */
	inline const float specularA() const
	{
		return Specular[3];
	}

	/*! Returns the ambiant color as a 4 float array */
	inline const float *ambient() const
	{
		return Ambient;
	}

	/*! Returns the red component of the ambiant color */
	inline const float ambientR() const
	{
		return Ambient[0];
	}

	/*! Returns the green component of the ambiant color */
	inline const float ambientG() const
	{
		return Ambient[1];
	}

	/*! Returns the blue component of the ambiant color */
	inline const float ambientB() const
	{
		return Ambient[2];
	}

	/*! Returns the alpha component of the ambiant color */
	inline const float ambientA() const
	{
		return Ambient[3];
	}

	/*! Returns the emissive color as a 4 float array */
	inline const float *emission() const
	{
		return Emission;
	}

	/*! Returns the red component of the emissive color */
	inline const float emissionR() const
	{
		return Emission[0];
	}

	/*! Returns the green component of the emissive color */
	inline const float emissionG() const
	{
		return Emission[1];
	}

	/*! Returns the blue component of the emissive color */
	inline const float emissionB() const
	{
		return Emission[2];
	}

	/*! Returns the alpha component of the emissive color */
	inline const float emissionA() const
	{
		return Emission[3];
	}

	/*! Returns the shininess coefficient */
	inline const float shininess() const
	{
		return Shininess;
	}

	/*! Sets the diffuse color.
	 *    \param r
	 *      Red component
	 *    \param g
	 *      Green component
	 *    \param b
	 *     Blue component
	 *    \param a
	 *      Alpha component
	 */
	inline void setDiffuse(const float r, const float g, const float b, const float a);

	/*! Sets the specular color.
	 *    \param r
	 *      Red component
	 *    \param g
	 *      Green component
	 *    \param b
	 *     Blue component
	 *    \param a
	 *      Alpha component
	 */
	inline void setSpecular(const float r, const float g, const float b, const float a);

	/*! Sets the ambiant color.
	 *    \param r
	 *      Red component
	 *    \param g
	 *      Green component
	 *    \param b
	 *     Blue component
	 *    \param a
	 *      Alpha component
	 */
	inline void setAmbient(const float r, const float g, const float b, const float a);

	/*! Sets the emissive color.
	 *    \param r
	 *      Red component
	 *    \param g
	 *      Green component
	 *    \param b
	 *     Blue component
	 *    \param a
	 *      Alpha component
	 */
	inline void setEmission(const float r, const float g, const float b, const float a);

	/*! Sets the shininess.
	 *    \param s
	 *      Shininess
	 */
	inline void setShininess(const float s);

	/* operators */
	inline FrsMaterial& operator=(const FrsMaterial& m);
	inline bool operator!=(const FrsMaterial& m) const;
	inline bool operator==(const FrsMaterial& m) const;

private:
	/*! Material properties */
	float Diffuse[4];
	float Specular[4];
	float Ambient[4];
	float Emission[4];
	float Shininess;
};

FrsMaterial::FrsMaterial()
{
	Ambient[0] = Ambient[1] = Ambient[2] = 0.2f;
	Ambient[3] = 1.0f;

	Diffuse[0] = Diffuse[1] = Diffuse[2] = 0.8f;
	Diffuse[3] = 1.0f;

	Emission[0] = Emission[1] = Emission[2] = 0.0f;
	Emission[3] = 1.0f;

	Specular[0] = Specular[1] = Specular[2] = 0.0f;
	Specular[3] = 1.0f;

	Shininess = 0.0f;
}

FrsMaterial::FrsMaterial(const float *iDiffuse, const float *iAmbiant, const float *iSpecular, const float *iEmission,
                         const float iShininess)
{
	for (int i = 0; i < 4; i++) {
		Diffuse[i]  = iDiffuse[i];
		Specular[i] = iSpecular[i];
		Ambient[i]  = iAmbiant[i];
		Emission[i] = iEmission[i];
	}

	Shininess = iShininess;
}

FrsMaterial::FrsMaterial(const FrsMaterial& m)
{
	for (int i = 0; i < 4; i++) {
		Diffuse[i]  = m.diffuse()[i];
		Specular[i] = m.specular()[i];
		Ambient[i]  = m.ambient()[i];
		Emission[i] = m.emission()[i];
	}

	Shininess = m.shininess();
}

void FrsMaterial::setDiffuse(const float r, const float g, const float b, const float a)
{
	Diffuse[0] = r;
	Diffuse[1] = g;
	Diffuse[2] = b;
	Diffuse[3] = a;
}

void FrsMaterial::setSpecular(const float r, const float g, const float b, const float a)
{
	Specular[0] = r;
	Specular[1] = g;
	Specular[2] = b;
	Specular[3] = a;
}

void FrsMaterial::setAmbient(const float r, const float g, const float b, const float a)
{
	Ambient[0] = r;
	Ambient[1] = g;
	Ambient[2] = b;
	Ambient[3] = a;
}

void FrsMaterial::setEmission(const float r, const float g, const float b, const float a)
{
	Emission[0] = r;
	Emission[1] = g;
	Emission[2] = b;
	Emission[3] = a;
}

void FrsMaterial::setShininess(const float s)
{
	Shininess = s;
}

FrsMaterial& FrsMaterial::operator=(const FrsMaterial& m)
{
	for (int i = 0; i < 4; i++) {
		Diffuse[i]  = m.diffuse()[i];
		Specular[i] = m.specular()[i];
		Ambient[i]  = m.ambient()[i];
		Emission[i] = m.emission()[i];
	}

	Shininess = m.shininess();
	return *this;
}

bool FrsMaterial::operator!=(const FrsMaterial& m) const
{
	if (Shininess != m.shininess())
		return true;

	for (int i = 0; i < 4; i++) {
		if (Diffuse[i]  != m.diffuse()[i])
			return true;
		if (Specular[i] != m.specular()[i])
			return true;
		if (Ambient[i]  != m.ambient()[i])
			return true;
		if (Emission[i] != m.emission()[i])
			return true;
	}

	return false;
}

bool FrsMaterial::operator==(const FrsMaterial& m) const
{
	return (!((*this) != m));
}

} /* namespace Freestyle */

#endif // __FREESTYLE_MATERIAL_H__