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-2020 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 
29 #ifndef _MATERIAL_H_
30 #define _MATERIAL_H_
31 
32 #include "ray.h"
33 #include "hitinfo.h"
34 #include "PerlinNoise.h"
35 
40 {
41 public:
43 
45  {
46  }
47 
55  virtual SFVEC3F Generate( const RAY& aRay, const HITINFO& aHitInfo ) const = 0;
56 };
57 
58 
60 {
61 public:
63  BOARD_NORMAL( float aScale );
64 
65  virtual ~BOARD_NORMAL()
66  {
67  }
68 
69  SFVEC3F Generate( const RAY& aRay, const HITINFO& aHitInfo ) const override;
70 
71 private:
72  float m_scale;
73 };
74 
75 
80 {
81 public:
83  {
84  m_board_normal_generator = nullptr;
85  m_scale = 1.0f;
86  }
87 
88  COPPER_NORMAL( float aScale, const MATERIAL_GENERATOR* aBoardNormalGenerator );
89 
90  virtual ~COPPER_NORMAL()
91  {
92  }
93 
94  SFVEC3F Generate( const RAY& aRay, const HITINFO& aHitInfo ) const override;
95 
96 private:
98  float m_scale;
99 };
100 
101 
103 {
104 public:
106  {
107  m_scale = 1.0f;
108  }
109 
110  PLATED_COPPER_NORMAL( float aScale )
111  {
112  m_scale = 1.0f / aScale;
113  }
114 
116  {
117  }
118 
119  SFVEC3F Generate( const RAY& aRay, const HITINFO& aHitInfo ) const override;
120 
121 private:
122  float m_scale;
123 };
124 
125 
130 {
131 public:
133  SOLDER_MASK_NORMAL( const MATERIAL_GENERATOR* aCopperNormalGenerator );
134 
136  {
137  }
138 
139  SFVEC3F Generate( const RAY& aRay, const HITINFO& aHitInfo ) const override;
140 
141 private:
143 };
144 
145 
150 {
151 public:
153  {
154  m_scale = 1.0f;
155  }
156 
157  PLASTIC_NORMAL( float aScale );
158 
159  virtual ~PLASTIC_NORMAL()
160  {
161  }
162 
163  SFVEC3F Generate( const RAY& aRay, const HITINFO& aHitInfo ) const override;
164 
165 private:
166  float m_scale;
167 };
168 
169 
174 {
175 public:
177  {
178  m_scale = 1.0f;
179  }
180 
181  PLASTIC_SHINE_NORMAL( float aScale );
182 
184  {
185  }
186 
187  // Imported from MATERIAL_GENERATOR
188  SFVEC3F Generate( const RAY& aRay, const HITINFO& aHitInfo ) const override;
189 
190 private:
191  float m_scale;
192 };
193 
194 
199 {
200 public:
202  {
203  m_scale = 1.0f;
204  }
205 
206  BRUSHED_METAL_NORMAL( float aScale );
207 
209  {
210  }
211 
212  SFVEC3F Generate( const RAY& aRay, const HITINFO& aHitInfo ) const override;
213 
214 private:
215  float m_scale;
216 };
217 
218 
220 {
221 public:
223  {
224  m_scale = 1.0f;
225  }
226 
227  SILK_SCREEN_NORMAL( float aScale );
228 
230  {
231  }
232 
233  SFVEC3F Generate( const RAY& aRay, const HITINFO& aHitInfo ) const override;
234 
235 private:
236  float m_scale;
237 };
238 
239 
243 class MATERIAL
244 {
245 public:
246  static void SetDefaultRefractionRayCount( unsigned int aCount )
247  {
249  }
250 
251  static void SetDefaultReflectionRayCount( unsigned int aCount )
252  {
254  }
255 
256  static void SetDefaultRefractionRecursionCount( unsigned int aCount )
257  {
259  }
260 
261  static void SetDefaultReflectionRecursionCount( unsigned int aCount )
262  {
264  }
265 
266  MATERIAL();
267  MATERIAL( const SFVEC3F& aAmbient, const SFVEC3F& aEmissive, const SFVEC3F& aSpecular,
268  float aShinness, float aTransparency, float aReflection );
269 
270  virtual ~MATERIAL() {}
271 
272  const SFVEC3F& GetAmbientColor() const { return m_ambientColor; }
273  const SFVEC3F& GetEmissiveColor() const { return m_emissiveColor; }
274  const SFVEC3F& GetSpecularColor() const { return m_specularColor; }
275 
276  float GetReflectivity() const { return m_reflectivity; }
277  float GetTransparency() const { return m_transparency; }
278  float GetReflection() const { return m_reflection; }
279  float GetAbsorvance() const { return m_absorbance; }
280  unsigned int GetRefractionRayCount() const { return m_refractionRayCount; }
281  unsigned int GetReflectionRayCount() const { return m_reflectionRayCount; }
284 
285  void SetAbsorvance( float aAbsorvanceFactor ) { m_absorbance = aAbsorvanceFactor; }
286  void SetRefractionRayCount( unsigned int aCount )
287  {
288  m_refractionRayCount = aCount;
289  }
290 
291  void SetReflectionRayCount( unsigned int aCount )
292  {
293  m_reflectionRayCount = aCount;
294  }
295 
296  void SetReflectionRecursionCount( unsigned int aCount )
297  {
299  }
300 
301  void SetRefractionRecursionCount( unsigned int aCount )
302  {
304  }
305 
311  void SetCastShadows( bool aCastShadows ) { m_castShadows = aCastShadows; }
312 
313  bool GetCastShadows() const { return m_castShadows; }
314 
327  virtual SFVEC3F Shade( const RAY& aRay, const HITINFO& aHitInfo, float NdotL,
328  const SFVEC3F& aDiffuseObjColor, const SFVEC3F& aDirToLight,
329  const SFVEC3F& aLightColor,
330  float aShadowAttenuationFactor ) const = 0;
331 
332  void SetGenerator( const MATERIAL_GENERATOR* aGenerator )
333  {
334  m_generator = aGenerator;
335  }
336 
337  const MATERIAL_GENERATOR* GetGenerator() const { return m_generator; }
338 
339  void Generate( SFVEC3F& aNormal, const RAY& aRay, const HITINFO& aHitInfo ) const;
340 
341 protected:
343 
344  // NOTE: we will not use diffuse color material here,
345  // because it will be stored in object, since there are objects (i.e: triangles)
346  // that can have per vertex color
347 
351 
354  float m_absorbance;
355  float m_reflection;
357 
359  unsigned int m_refractionRayCount;
360 
362  unsigned int m_reflectionRayCount;
363 
366 
369 
371 
372 private:
377 };
378 
379 
383 {
384 public:
386 
387  BLINN_PHONG_MATERIAL( const SFVEC3F& aAmbient, const SFVEC3F& aEmissive,
388  const SFVEC3F& aSpecular, float aShinness, float aTransparency,
389  float aReflection ) :
390  MATERIAL( aAmbient, aEmissive, aSpecular, aShinness, aTransparency, aReflection ) {}
391 
392  // Imported from MATERIAL
393  SFVEC3F Shade( const RAY& aRay, const HITINFO& aHitInfo, float NdotL,
394  const SFVEC3F& aDiffuseObjColor, const SFVEC3F& aDirToLight,
395  const SFVEC3F& aLightColor, float aShadowAttenuationFactor ) const override;
396 };
397 
398 #endif // _MATERIAL_H_
float GetTransparency() const
Definition: material.h:277
float GetReflectivity() const
Definition: material.h:276
virtual ~PLASTIC_SHINE_NORMAL()
Definition: material.h:183
Procedural generation of the copper normals.
Definition: material.h:79
float m_reflection
1.0 completely reflective, 0.0 no reflective.
Definition: material.h:355
This source code comes from the project: https://github.com/sol-prog/Perlin_Noise.
const SFVEC3F & GetEmissiveColor() const
Definition: material.h:273
static void SetDefaultReflectionRecursionCount(unsigned int aCount)
Definition: material.h:261
bool m_castShadows
true if this object will block the light.
Definition: material.h:356
static void SetDefaultRefractionRecursionCount(unsigned int aCount)
Definition: material.h:256
void Generate(SFVEC3F &aNormal, const RAY &aRay, const HITINFO &aHitInfo) const
Definition: material.cpp:93
static int m_defaultReflectionRayCount
Definition: material.h:374
void SetReflectionRayCount(unsigned int aCount)
Definition: material.h:291
void SetAbsorvance(float aAbsorvanceFactor)
Definition: material.h:285
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:149
SFVEC3F m_emissiveColor
Definition: material.h:348
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:265
void SetGenerator(const MATERIAL_GENERATOR *aGenerator)
Definition: material.h:332
SFVEC3F m_ambientColor
Definition: material.h:342
Procedural generation of the plastic normals.
Definition: material.h:149
void SetReflectionRecursionCount(unsigned int aCount)
Definition: material.h:296
float m_scale
Definition: material.h:166
float m_scale
Definition: material.h:98
Definition: ray.h:67
Blinn Phong based material https://en.wikipedia.org/wiki/Blinn%E2%80%93Phong_shading_model.
Definition: material.h:382
const SFVEC3F & GetSpecularColor() const
Definition: material.h:274
void SetCastShadows(bool aCastShadows)
Set if the material can receive shadows.
Definition: material.h:311
float m_transparency
Definition: material.h:353
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:208
static int m_defaultFeflectionRecursionCount
Definition: material.h:376
virtual ~SOLDER_MASK_NORMAL()
Definition: material.h:135
Base material class that can be used to derive other material implementations.
Definition: material.h:243
virtual ~PLATED_COPPER_NORMAL()
Definition: material.h:115
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:289
float GetReflection() const
Definition: material.h:278
static void SetDefaultReflectionRayCount(unsigned int aCount)
Definition: material.h:251
void SetRefractionRecursionCount(unsigned int aCount)
Definition: material.h:301
PLATED_COPPER_NORMAL(float aScale)
Definition: material.h:110
unsigned int m_reflectionRecursionCount
Definition: material.h:368
unsigned int m_refractionRayCount
Number of rays that will be interpolated for this material if it is reflective.
Definition: material.h:359
unsigned int GetRefractionRayCount() const
Definition: material.h:280
virtual ~MATERIAL()
Definition: material.h:270
A base class that can be used to derive procedurally generated materials.
Definition: material.h:39
unsigned int m_reflectionRayCount
Number of levels it allows for refraction recursiveness.
Definition: material.h:362
unsigned int m_refractionRecursionCount
Number of levels it allows for reflection recursiveness.
Definition: material.h:365
const MATERIAL_GENERATOR * GetGenerator() const
Definition: material.h:337
BLINN_PHONG_MATERIAL(const SFVEC3F &aAmbient, const SFVEC3F &aEmissive, const SFVEC3F &aSpecular, float aShinness, float aTransparency, float aReflection)
Definition: material.h:387
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:312
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:240
const MATERIAL_GENERATOR * m_generator
Definition: material.h:370
static int m_defaultRefractionRecursionCount
Definition: material.h:375
SFVEC3F m_specularColor
Definition: material.h:349
Procedural generation of the shiny brushed metal.
Definition: material.h:198
const MATERIAL_GENERATOR * m_copper_normal_generator
Definition: material.h:142
const SFVEC3F & GetAmbientColor() const
Definition: material.h:272
static int m_defaultRefractionRayCount
Definition: material.h:373
Stores the hit information of a ray with a point on the surface of a object.
Definition: hitinfo.h:40
unsigned int GetReflectionRayCount() const
Definition: material.h:281
virtual ~PLASTIC_NORMAL()
Definition: material.h:159
glm::vec3 SFVEC3F
Definition: xv3d_types.h:44
virtual ~SILK_SCREEN_NORMAL()
Definition: material.h:229
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:104
virtual ~COPPER_NORMAL()
Definition: material.h:90
Procedural generation of the shiny plastic normals.
Definition: material.h:173
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:208
const MATERIAL_GENERATOR * m_board_normal_generator
Definition: material.h:97
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:175
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:223
float m_absorbance
absorbance factor for the transparent material.
Definition: material.h:354
void SetRefractionRayCount(unsigned int aCount)
Definition: material.h:286
MATERIAL()
Definition: material.cpp:44
BOARD_NORMAL()
Definition: material.h:62
static void SetDefaultRefractionRayCount(unsigned int aCount)
Definition: material.h:246
float m_reflectivity
1.0 is completely transparent, 0.0 completely opaque.
Definition: material.h:350
virtual ~MATERIAL_GENERATOR()
Definition: material.h:44
Procedural generation of the solder mask.
Definition: material.h:129
float GetAbsorvance() const
Definition: material.h:279
unsigned int GetReflectionRecursionCount() const
Definition: material.h:282
float m_scale
Definition: material.h:72
unsigned int GetRefractionRecursionCount() const
Definition: material.h:283
virtual ~BOARD_NORMAL()
Definition: material.h:65
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:313