KiCad PCB EDA Suite
material.h
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright (C) 2015-2016 Mario Luzeiro <[email protected]>
5 * Copyright (C) 2015-2021 KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, you may find one here:
19 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20 * or you may search the http://www.gnu.org website for the version 2 license,
21 * or you may write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23 */
24
25#ifndef MATERIAL_H
26#define MATERIAL_H
27
28#include "ray.h"
29#include "hitinfo.h"
30#include "PerlinNoise.h"
31
36{
37public:
39
41 {
42 }
43
51 virtual SFVEC3F Generate( const RAY& aRay, const HITINFO& aHitInfo ) const = 0;
52};
53
54
56{
57public:
59 BOARD_NORMAL( float aScale );
60
61 virtual ~BOARD_NORMAL()
62 {
63 }
64
65 SFVEC3F Generate( const RAY& aRay, const HITINFO& aHitInfo ) const override;
66
67private:
68 float m_scale;
69};
70
71
76{
77public:
79 {
81 m_scale = 1.0f;
82 }
83
84 COPPER_NORMAL( float aScale, const MATERIAL_GENERATOR* aBoardNormalGenerator );
85
87 {
88 }
89
90 SFVEC3F Generate( const RAY& aRay, const HITINFO& aHitInfo ) const override;
91
92private:
94 float m_scale;
95};
96
97
99{
100public:
102 {
103 m_scale = 1.0f;
104 }
105
106 PLATED_COPPER_NORMAL( float aScale )
107 {
108 m_scale = 1.0f / aScale;
109 }
110
112 {
113 }
114
115 SFVEC3F Generate( const RAY& aRay, const HITINFO& aHitInfo ) const override;
116
117private:
118 float m_scale;
119};
120
121
126{
127public:
129 SOLDER_MASK_NORMAL( const MATERIAL_GENERATOR* aCopperNormalGenerator );
130
132 {
133 }
134
135 SFVEC3F Generate( const RAY& aRay, const HITINFO& aHitInfo ) const override;
136
137private:
139};
140
141
146{
147public:
149 {
150 m_scale = 1.0f;
151 }
152
153 PLASTIC_NORMAL( float aScale );
154
156 {
157 }
158
159 SFVEC3F Generate( const RAY& aRay, const HITINFO& aHitInfo ) const override;
160
161private:
162 float m_scale;
163};
164
165
170{
171public:
173 {
174 m_scale = 1.0f;
175 }
176
177 PLASTIC_SHINE_NORMAL( float aScale );
178
180 {
181 }
182
183 // Imported from MATERIAL_GENERATOR
184 SFVEC3F Generate( const RAY& aRay, const HITINFO& aHitInfo ) const override;
185
186private:
187 float m_scale;
188};
189
190
195{
196public:
198 {
199 m_scale = 1.0f;
200 }
201
202 BRUSHED_METAL_NORMAL( float aScale );
203
205 {
206 }
207
208 SFVEC3F Generate( const RAY& aRay, const HITINFO& aHitInfo ) const override;
209
210private:
211 float m_scale;
212};
213
214
216{
217public:
219 {
220 m_scale = 1.0f;
221 }
222
223 SILK_SCREEN_NORMAL( float aScale );
224
226 {
227 }
228
229 SFVEC3F Generate( const RAY& aRay, const HITINFO& aHitInfo ) const override;
230
231private:
232 float m_scale;
233};
234
235
240{
241public:
242 static void SetDefaultRefractionRayCount( unsigned int aCount )
243 {
245 }
246
247 static void SetDefaultReflectionRayCount( unsigned int aCount )
248 {
250 }
251
252 static void SetDefaultRefractionRecursionCount( unsigned int aCount )
253 {
255 }
256
257 static void SetDefaultReflectionRecursionCount( unsigned int aCount )
258 {
260 }
261
262 MATERIAL();
263 MATERIAL( const SFVEC3F& aAmbient, const SFVEC3F& aEmissive, const SFVEC3F& aSpecular,
264 float aShinness, float aTransparency, float aReflection );
265
266 virtual ~MATERIAL() {}
267
268 const SFVEC3F& GetAmbientColor() const { return m_ambientColor; }
269 const SFVEC3F& GetEmissiveColor() const { return m_emissiveColor; }
270 const SFVEC3F& GetSpecularColor() const { return m_specularColor; }
271
272 float GetReflectivity() const { return m_reflectivity; }
273 float GetTransparency() const { return m_transparency; }
274 float GetReflection() const { return m_reflection; }
275 float GetAbsorvance() const { return m_absorbance; }
276 unsigned int GetRefractionRayCount() const { return m_refractionRayCount; }
277 unsigned int GetReflectionRayCount() const { return m_reflectionRayCount; }
280
281 void SetAbsorvance( float aAbsorvanceFactor ) { m_absorbance = aAbsorvanceFactor; }
282 void SetRefractionRayCount( unsigned int aCount )
283 {
284 m_refractionRayCount = aCount;
285 }
286
287 void SetReflectionRayCount( unsigned int aCount )
288 {
289 m_reflectionRayCount = aCount;
290 }
291
292 void SetReflectionRecursionCount( unsigned int aCount )
293 {
295 }
296
297 void SetRefractionRecursionCount( unsigned int aCount )
298 {
300 }
301
307 void SetCastShadows( bool aCastShadows ) { m_castShadows = aCastShadows; }
308
309 bool GetCastShadows() const { return m_castShadows; }
310
323 virtual SFVEC3F Shade( const RAY& aRay, const HITINFO& aHitInfo, float NdotL,
324 const SFVEC3F& aDiffuseObjColor, const SFVEC3F& aDirToLight,
325 const SFVEC3F& aLightColor,
326 float aShadowAttenuationFactor ) const = 0;
327
328 void SetGenerator( const MATERIAL_GENERATOR* aGenerator )
329 {
330 m_generator = aGenerator;
331 }
332
333 const MATERIAL_GENERATOR* GetGenerator() const { return m_generator; }
334
335 void Generate( SFVEC3F& aNormal, const RAY& aRay, const HITINFO& aHitInfo ) const;
336
337protected:
339
340 // NOTE: we will not use diffuse color material here,
341 // because it will be stored in object, since there are objects (i.e: triangles)
342 // that can have per vertex color
343
347
353
356
359
362
365
367
368private:
373};
374
375
379{
380public:
382
383 BLINN_PHONG_MATERIAL( const SFVEC3F& aAmbient, const SFVEC3F& aEmissive,
384 const SFVEC3F& aSpecular, float aShinness, float aTransparency,
385 float aReflection ) :
386 MATERIAL( aAmbient, aEmissive, aSpecular, aShinness, aTransparency, aReflection ) {}
387
388 // Imported from MATERIAL
389 SFVEC3F Shade( const RAY& aRay, const HITINFO& aHitInfo, float NdotL,
390 const SFVEC3F& aDiffuseObjColor, const SFVEC3F& aDirToLight,
391 const SFVEC3F& aLightColor, float aShadowAttenuationFactor ) const override;
392};
393
394#endif // MATERIAL_H
This source code comes from the project: https://github.com/sol-prog/Perlin_Noise.
Blinn Phong based material https://en.wikipedia.org/wiki/Blinn%E2%80%93Phong_shading_model.
Definition: material.h:379
BLINN_PHONG_MATERIAL(const SFVEC3F &aAmbient, const SFVEC3F &aEmissive, const SFVEC3F &aSpecular, float aShinness, float aTransparency, float aReflection)
Definition: material.h:383
SFVEC3F Shade(const RAY &aRay, const HITINFO &aHitInfo, float NdotL, const SFVEC3F &aDiffuseObjColor, const SFVEC3F &aDirToLight, const SFVEC3F &aLightColor, float aShadowAttenuationFactor) const override
Shade an intersection point.
Definition: material.cpp:100
SFVEC3F Generate(const RAY &aRay, const HITINFO &aHitInfo) const override
Generate a 3D vector based on the ray and hit information depending on the implementation.
Definition: material.cpp:145
BOARD_NORMAL()
Definition: material.h:58
float m_scale
Definition: material.h:68
virtual ~BOARD_NORMAL()
Definition: material.h:61
Procedural generation of the shiny brushed metal.
Definition: material.h:195
virtual ~BRUSHED_METAL_NORMAL()
Definition: material.h:204
SFVEC3F Generate(const RAY &aRay, const HITINFO &aHitInfo) const override
Generate a 3D vector based on the ray and hit information depending on the implementation.
Definition: material.cpp:285
Procedural generation of the copper normals.
Definition: material.h:76
float m_scale
Definition: material.h:94
SFVEC3F Generate(const RAY &aRay, const HITINFO &aHitInfo) const override
Generate a 3D vector based on the ray and hit information depending on the implementation.
Definition: material.cpp:171
const MATERIAL_GENERATOR * m_board_normal_generator
Definition: material.h:93
virtual ~COPPER_NORMAL()
Definition: material.h:86
A base class that can be used to derive procedurally generated materials.
Definition: material.h:36
virtual SFVEC3F Generate(const RAY &aRay, const HITINFO &aHitInfo) const =0
Generate a 3D vector based on the ray and hit information depending on the implementation.
virtual ~MATERIAL_GENERATOR()
Definition: material.h:40
Base material class that can be used to derive other material implementations.
Definition: material.h:240
float GetReflectivity() const
Definition: material.h:272
float GetAbsorvance() const
Definition: material.h:275
SFVEC3F m_emissiveColor
Definition: material.h:344
const MATERIAL_GENERATOR * GetGenerator() const
Definition: material.h:333
void SetReflectionRayCount(unsigned int aCount)
Definition: material.h:287
unsigned int m_refractionRayCount
Number of rays that will be interpolated for this material if it is reflective.
Definition: material.h:355
unsigned int m_refractionRecursionCount
Number of levels it allows for reflection recursiveness.
Definition: material.h:361
static void SetDefaultReflectionRayCount(unsigned int aCount)
Definition: material.h:247
void SetRefractionRecursionCount(unsigned int aCount)
Definition: material.h:297
static void SetDefaultRefractionRayCount(unsigned int aCount)
Definition: material.h:242
float m_absorbance
absorbance factor for the transparent material.
Definition: material.h:350
unsigned int m_reflectionRayCount
Number of levels it allows for refraction recursiveness.
Definition: material.h:358
unsigned int m_reflectionRecursionCount
Definition: material.h:364
bool GetCastShadows() const
Definition: material.h:309
static int m_defaultReflectionRayCount
Definition: material.h:370
static int m_defaultRefractionRayCount
Definition: material.h:369
static void SetDefaultRefractionRecursionCount(unsigned int aCount)
Definition: material.h:252
void SetCastShadows(bool aCastShadows)
Set if the material can receive shadows.
Definition: material.h:307
void SetGenerator(const MATERIAL_GENERATOR *aGenerator)
Definition: material.h:328
MATERIAL()
Definition: material.cpp:40
virtual SFVEC3F Shade(const RAY &aRay, const HITINFO &aHitInfo, float NdotL, const SFVEC3F &aDiffuseObjColor, const SFVEC3F &aDirToLight, const SFVEC3F &aLightColor, float aShadowAttenuationFactor) const =0
Shade an intersection point.
const SFVEC3F & GetAmbientColor() const
Definition: material.h:268
unsigned int GetReflectionRecursionCount() const
Definition: material.h:278
static int m_defaultRefractionRecursionCount
Definition: material.h:371
float GetTransparency() const
Definition: material.h:273
unsigned int GetRefractionRayCount() const
Definition: material.h:276
bool m_castShadows
true if this object will block the light.
Definition: material.h:352
unsigned int GetRefractionRecursionCount() const
Definition: material.h:279
virtual ~MATERIAL()
Definition: material.h:266
void Generate(SFVEC3F &aNormal, const RAY &aRay, const HITINFO &aHitInfo) const
Definition: material.cpp:89
SFVEC3F m_ambientColor
Definition: material.h:338
float m_transparency
Definition: material.h:349
float m_reflection
1.0 completely reflective, 0.0 no reflective.
Definition: material.h:351
const MATERIAL_GENERATOR * m_generator
Definition: material.h:366
const SFVEC3F & GetSpecularColor() const
Definition: material.h:270
void SetReflectionRecursionCount(unsigned int aCount)
Definition: material.h:292
static void SetDefaultReflectionRecursionCount(unsigned int aCount)
Definition: material.h:257
float m_reflectivity
1.0 is completely transparent, 0.0 completely opaque.
Definition: material.h:346
static int m_defaultFeflectionRecursionCount
Definition: material.h:372
void SetRefractionRayCount(unsigned int aCount)
Definition: material.h:282
const SFVEC3F & GetEmissiveColor() const
Definition: material.h:269
SFVEC3F m_specularColor
Definition: material.h:345
void SetAbsorvance(float aAbsorvanceFactor)
Definition: material.h:281
float GetReflection() const
Definition: material.h:274
unsigned int GetReflectionRayCount() const
Definition: material.h:277
Procedural generation of the plastic normals.
Definition: material.h:146
SFVEC3F Generate(const RAY &aRay, const HITINFO &aHitInfo) const override
Generate a 3D vector based on the ray and hit information depending on the implementation.
Definition: material.cpp:236
float m_scale
Definition: material.h:162
virtual ~PLASTIC_NORMAL()
Definition: material.h:155
Procedural generation of the shiny plastic normals.
Definition: material.h:170
SFVEC3F Generate(const RAY &aRay, const HITINFO &aHitInfo) const override
Generate a 3D vector based on the ray and hit information depending on the implementation.
Definition: material.cpp:261
virtual ~PLASTIC_SHINE_NORMAL()
Definition: material.h:179
virtual ~PLATED_COPPER_NORMAL()
Definition: material.h:111
PLATED_COPPER_NORMAL(float aScale)
Definition: material.h:106
SFVEC3F Generate(const RAY &aRay, const HITINFO &aHitInfo) const override
Generate a 3D vector based on the ray and hit information depending on the implementation.
Definition: material.cpp:219
virtual ~SILK_SCREEN_NORMAL()
Definition: material.h:225
SFVEC3F Generate(const RAY &aRay, const HITINFO &aHitInfo) const override
Generate a 3D vector based on the ray and hit information depending on the implementation.
Definition: material.cpp:308
Procedural generation of the solder mask.
Definition: material.h:126
const MATERIAL_GENERATOR * m_copper_normal_generator
Definition: material.h:138
virtual ~SOLDER_MASK_NORMAL()
Definition: material.h:131
SFVEC3F Generate(const RAY &aRay, const HITINFO &aHitInfo) const override
Generate a 3D vector based on the ray and hit information depending on the implementation.
Definition: material.cpp:204
Stores the hit information of a ray with a point on the surface of a object.
Definition: hitinfo.h:36
Definition: ray.h:63
glm::vec3 SFVEC3F
Definition: xv3d_types.h:44