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 <mrluzeiro@ua.pt>
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 {
37 public:
39 
41  {
42  }
43 
51  virtual SFVEC3F Generate( const RAY& aRay, const HITINFO& aHitInfo ) const = 0;
52 };
53 
54 
56 {
57 public:
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 
67 private:
68  float m_scale;
69 };
70 
71 
76 {
77 public:
79  {
80  m_board_normal_generator = nullptr;
81  m_scale = 1.0f;
82  }
83 
84  COPPER_NORMAL( float aScale, const MATERIAL_GENERATOR* aBoardNormalGenerator );
85 
86  virtual ~COPPER_NORMAL()
87  {
88  }
89 
90  SFVEC3F Generate( const RAY& aRay, const HITINFO& aHitInfo ) const override;
91 
92 private:
94  float m_scale;
95 };
96 
97 
99 {
100 public:
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 
117 private:
118  float m_scale;
119 };
120 
121 
126 {
127 public:
129  SOLDER_MASK_NORMAL( const MATERIAL_GENERATOR* aCopperNormalGenerator );
130 
132  {
133  }
134 
135  SFVEC3F Generate( const RAY& aRay, const HITINFO& aHitInfo ) const override;
136 
137 private:
139 };
140 
141 
146 {
147 public:
149  {
150  m_scale = 1.0f;
151  }
152 
153  PLASTIC_NORMAL( float aScale );
154 
155  virtual ~PLASTIC_NORMAL()
156  {
157  }
158 
159  SFVEC3F Generate( const RAY& aRay, const HITINFO& aHitInfo ) const override;
160 
161 private:
162  float m_scale;
163 };
164 
165 
170 {
171 public:
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 
186 private:
187  float m_scale;
188 };
189 
190 
195 {
196 public:
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 
210 private:
211  float m_scale;
212 };
213 
214 
216 {
217 public:
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 
231 private:
232  float m_scale;
233 };
234 
235 
239 class MATERIAL
240 {
241 public:
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 
337 protected:
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 
350  float m_absorbance;
351  float m_reflection;
353 
355  unsigned int m_refractionRayCount;
356 
358  unsigned int m_reflectionRayCount;
359 
362 
365 
367 
368 private:
373 };
374 
375 
379 {
380 public:
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
float GetTransparency() const
Definition: material.h:273
float GetReflectivity() const
Definition: material.h:272
virtual ~PLASTIC_SHINE_NORMAL()
Definition: material.h:179
Procedural generation of the copper normals.
Definition: material.h:75
float m_reflection
1.0 completely reflective, 0.0 no reflective.
Definition: material.h:351
This source code comes from the project: https://github.com/sol-prog/Perlin_Noise.
const SFVEC3F & GetEmissiveColor() const
Definition: material.h:269
static void SetDefaultReflectionRecursionCount(unsigned int aCount)
Definition: material.h:257
bool m_castShadows
true if this object will block the light.
Definition: material.h:352
static void SetDefaultRefractionRecursionCount(unsigned int aCount)
Definition: material.h:252
void Generate(SFVEC3F &aNormal, const RAY &aRay, const HITINFO &aHitInfo) const
Definition: material.cpp:89
static int m_defaultReflectionRayCount
Definition: material.h:370
void SetReflectionRayCount(unsigned int aCount)
Definition: material.h:287
void SetAbsorvance(float aAbsorvanceFactor)
Definition: material.h:281
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
SFVEC3F m_emissiveColor
Definition: material.h:344
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
void SetGenerator(const MATERIAL_GENERATOR *aGenerator)
Definition: material.h:328
SFVEC3F m_ambientColor
Definition: material.h:338
Procedural generation of the plastic normals.
Definition: material.h:145
void SetReflectionRecursionCount(unsigned int aCount)
Definition: material.h:292
float m_scale
Definition: material.h:162
float m_scale
Definition: material.h:94
Definition: ray.h:62
Blinn Phong based material https://en.wikipedia.org/wiki/Blinn%E2%80%93Phong_shading_model.
Definition: material.h:378
const SFVEC3F & GetSpecularColor() const
Definition: material.h:270
void SetCastShadows(bool aCastShadows)
Set if the material can receive shadows.
Definition: material.h:307
float m_transparency
Definition: material.h:349
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.
virtual ~BRUSHED_METAL_NORMAL()
Definition: material.h:204
static int m_defaultFeflectionRecursionCount
Definition: material.h:372
virtual ~SOLDER_MASK_NORMAL()
Definition: material.h:131
Base material class that can be used to derive other material implementations.
Definition: material.h:239
virtual ~PLATED_COPPER_NORMAL()
Definition: material.h:111
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
float GetReflection() const
Definition: material.h:274
static void SetDefaultReflectionRayCount(unsigned int aCount)
Definition: material.h:247
void SetRefractionRecursionCount(unsigned int aCount)
Definition: material.h:297
PLATED_COPPER_NORMAL(float aScale)
Definition: material.h:106
unsigned int m_reflectionRecursionCount
Definition: material.h:364
unsigned int m_refractionRayCount
Number of rays that will be interpolated for this material if it is reflective.
Definition: material.h:355
unsigned int GetRefractionRayCount() const
Definition: material.h:276
virtual ~MATERIAL()
Definition: material.h:266
A base class that can be used to derive procedurally generated materials.
Definition: material.h:35
unsigned int m_reflectionRayCount
Number of levels it allows for refraction recursiveness.
Definition: material.h:358
unsigned int m_refractionRecursionCount
Number of levels it allows for reflection recursiveness.
Definition: material.h:361
const MATERIAL_GENERATOR * GetGenerator() const
Definition: material.h:333
BLINN_PHONG_MATERIAL(const SFVEC3F &aAmbient, const SFVEC3F &aEmissive, const SFVEC3F &aSpecular, float aShinness, float aTransparency, float aReflection)
Definition: material.h:383
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
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
const MATERIAL_GENERATOR * m_generator
Definition: material.h:366
static int m_defaultRefractionRecursionCount
Definition: material.h:371
SFVEC3F m_specularColor
Definition: material.h:345
Procedural generation of the shiny brushed metal.
Definition: material.h:194
const MATERIAL_GENERATOR * m_copper_normal_generator
Definition: material.h:138
const SFVEC3F & GetAmbientColor() const
Definition: material.h:268
static int m_defaultRefractionRayCount
Definition: material.h:369
Stores the hit information of a ray with a point on the surface of a object.
Definition: hitinfo.h:35
unsigned int GetReflectionRayCount() const
Definition: material.h:277
virtual ~PLASTIC_NORMAL()
Definition: material.h:155
glm::vec3 SFVEC3F
Definition: xv3d_types.h:44
virtual ~SILK_SCREEN_NORMAL()
Definition: material.h:225
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
virtual ~COPPER_NORMAL()
Definition: material.h:86
Procedural generation of the shiny plastic normals.
Definition: material.h:169
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
const MATERIAL_GENERATOR * m_board_normal_generator
Definition: material.h:93
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
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
float m_absorbance
absorbance factor for the transparent material.
Definition: material.h:350
void SetRefractionRayCount(unsigned int aCount)
Definition: material.h:282
MATERIAL()
Definition: material.cpp:40
BOARD_NORMAL()
Definition: material.h:58
static void SetDefaultRefractionRayCount(unsigned int aCount)
Definition: material.h:242
float m_reflectivity
1.0 is completely transparent, 0.0 completely opaque.
Definition: material.h:346
virtual ~MATERIAL_GENERATOR()
Definition: material.h:40
Procedural generation of the solder mask.
Definition: material.h:125
float GetAbsorvance() const
Definition: material.h:275
unsigned int GetReflectionRecursionCount() const
Definition: material.h:278
float m_scale
Definition: material.h:68
unsigned int GetRefractionRecursionCount() const
Definition: material.h:279
virtual ~BOARD_NORMAL()
Definition: material.h:61
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.
bool GetCastShadows() const
Definition: material.h:309