KiCad PCB EDA Suite
cmaterial.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) 1992-2016 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 
30 #ifndef _CMATERIAL_H_
31 #define _CMATERIAL_H_
32 
33 #include "ray.h"
34 #include "hitinfo.h"
35 #include "PerlinNoise.h"
36 
39 {
40 public:
42 
44  {
45  }
46 
54  virtual SFVEC3F Generate( const RAY &aRay,
55  const HITINFO &aHitInfo ) const = 0;
56 
57 protected:
58 
59 };
60 
61 
62 // Procedural generation of the board normals
64 {
65 public:
67  CBOARDNORMAL( float aScale );
68 
69  virtual ~CBOARDNORMAL()
70  {
71  }
72 
73  // Imported from CPROCEDURALGENERATOR
74  SFVEC3F Generate( const RAY &aRay,
75  const HITINFO &aHitInfo ) const override;
76 private:
77  float m_scale;
78 };
79 
80 // Procedural generation of the copper normals
82 {
83 public:
85  {
87  m_scale = 1.0f;
88  }
89 
90  CCOPPERNORMAL( float aScale, const CPROCEDURALGENERATOR *aBoardNormalGenerator );
91 
92  virtual ~CCOPPERNORMAL()
93  {
94  }
95 
96  // Imported from CPROCEDURALGENERATOR
97  SFVEC3F Generate( const RAY &aRay,
98  const HITINFO &aHitInfo ) const override;
99 private:
102  float m_scale;
103 };
104 
105 // Procedural generation of the solder mask
107 {
108 public:
110  CSOLDERMASKNORMAL( const CPROCEDURALGENERATOR *aCopperNormalGenerator );
111 
113  {
114  }
115 
116  // Imported from CPROCEDURALGENERATOR
117  SFVEC3F Generate( const RAY &aRay,
118  const HITINFO &aHitInfo ) const override;
119 private:
121 };
122 
123 
124 // Procedural generation of the plastic normals
126 {
127 public:
129  {
130  m_scale = 1.0f;
131  }
132 
133  CPLASTICNORMAL( float aScale );
134 
135  virtual ~CPLASTICNORMAL()
136  {
137  }
138 
139  // Imported from CPROCEDURALGENERATOR
140  SFVEC3F Generate( const RAY &aRay,
141  const HITINFO &aHitInfo ) const override;
142 private:
144  float m_scale;
145 };
146 
147 
148 // Procedural generation of the shiny plastic normals
150 {
151 public:
153  {
154  m_scale = 1.0f;
155  }
156 
157  CPLASTICSHINENORMAL( float aScale );
158 
160  {
161  }
162 
163  // Imported from CPROCEDURALGENERATOR
164  SFVEC3F Generate( const RAY &aRay,
165  const HITINFO &aHitInfo ) const override;
166 private:
168  float m_scale;
169 };
170 
171 // Procedural generation of the shiny brushed metal
173 {
174 public:
176  {
177  m_scale = 1.0f;
178  }
179 
180  CMETALBRUSHEDNORMAL( float aScale );
181 
183  {
184  }
185 
186  // Imported from CPROCEDURALGENERATOR
187  SFVEC3F Generate( const RAY &aRay,
188  const HITINFO &aHitInfo ) const override;
189 private:
191  float m_scale;
192 };
193 
196 {
197 public:
198  CMATERIAL();
199  CMATERIAL( const SFVEC3F &aAmbient,
200  const SFVEC3F &aEmissive,
201  const SFVEC3F &aSpecular,
202  float aShinness,
203  float aTransparency,
204  float aReflection );
205 
206  virtual ~CMATERIAL() {}
207 
208  const SFVEC3F &GetAmbientColor() const { return m_ambientColor; }
209  const SFVEC3F &GetEmissiveColor() const { return m_emissiveColor; }
210  const SFVEC3F &GetSpecularColor() const { return m_specularColor; }
211 
212  float GetShinness() const { return m_shinness; }
213  float GetTransparency() const { return m_transparency; }
214  float GetReflection() const { return m_reflection; }
215  float GetAbsorvance() const { return m_absorbance; }
216  unsigned int GetNrRefractionsSamples() const { return m_refraction_nr_samples; }
217  unsigned int GetNrReflectionsSamples() const { return m_reflections_nr_samples; }
218 
219  void SetAbsorvance( float aAbsorvanceFactor ) { m_absorbance = aAbsorvanceFactor; }
220  void SetNrRefractionsSamples( unsigned int aNrRefractions ) { m_refraction_nr_samples = aNrRefractions; }
221  void SetNrReflectionsSamples( unsigned int aNrReflections ) { m_reflections_nr_samples = aNrReflections; }
222 
227  void SetCastShadows( bool aCastShadows ) { m_cast_shadows = aCastShadows; }
228 
229  bool GetCastShadows() const { return m_cast_shadows; }
230 
242  virtual SFVEC3F Shade( const RAY &aRay,
243  const HITINFO &aHitInfo,
244  float NdotL,
245  const SFVEC3F &aDiffuseObjColor,
246  const SFVEC3F &aDirToLight,
247  const SFVEC3F &aLightColor,
248  float aShadowAttenuationFactor ) const = 0;
249 
250  void SetNormalPerturbator( const CPROCEDURALGENERATOR *aPerturbator ) { m_normal_perturbator = aPerturbator; }
252 
253  void PerturbeNormal( SFVEC3F &aNormal, const RAY &aRay, const HITINFO &aHitInfo ) const;
254 
255 protected:
257 
258  // NOTE: we will not use diffuse color material here,
259  // because it will be stored in object, since there are objects (i.e: triangles)
260  // that can have per vertex color
261 
264  float m_shinness;
266  float m_absorbance;
267  float m_reflection;
269  unsigned int m_refraction_nr_samples;
271 
273 };
274 
275 
279 {
280 public:
282 
283  CBLINN_PHONG_MATERIAL( const SFVEC3F &aAmbient,
284  const SFVEC3F &aEmissive,
285  const SFVEC3F &aSpecular,
286  float aShinness,
287  float aTransparency,
288  float aReflection ) : CMATERIAL( aAmbient,
289  aEmissive,
290  aSpecular,
291  aShinness,
292  aTransparency,
293  aReflection ) {}
294 
295  // Imported from CMATERIAL
296  SFVEC3F Shade( const RAY &aRay,
297  const HITINFO &aHitInfo,
298  float NdotL,
299  const SFVEC3F &aDiffuseObjColor,
300  const SFVEC3F &aDirToLight,
301  const SFVEC3F &aLightColor,
302  float aShadowAttenuationFactor ) const override;
303 };
304 
305 #endif // _CMATERIAL_H_
const SFVEC3F & GetEmissiveColor() const
Definition: cmaterial.h:209
SFVEC3F Generate(const RAY &aRay, const HITINFO &aHitInfo) const override
Generate - Generates a 3D vector based on the ray and hit information depending on the implementation...
Definition: cmaterial.cpp:178
SFVEC3F Generate(const RAY &aRay, const HITINFO &aHitInfo) const override
Generate - Generates a 3D vector based on the ray and hit information depending on the implementation...
Definition: cmaterial.cpp:282
const CPROCEDURALGENERATOR * m_copper_normal_generator
Definition: cmaterial.h:120
virtual ~CSOLDERMASKNORMAL()
Definition: cmaterial.h:112
This source code comes from the project: https://github.com/sol-prog/Perlin_Noise.
virtual ~CMETALBRUSHEDNORMAL()
Definition: cmaterial.h:182
A base material class that can be used to derive a material implementation.
Definition: cmaterial.h:195
virtual ~CCOPPERNORMAL()
Definition: cmaterial.h:92
const SFVEC3F & GetSpecularColor() const
Definition: cmaterial.h:210
PerlinNoise m_copper_perlin
Definition: cmaterial.h:101
SFVEC3F Generate(const RAY &aRay, const HITINFO &aHitInfo) const override
Generate - Generates a 3D vector based on the ray and hit information depending on the implementation...
Definition: cmaterial.cpp:209
virtual ~CPROCEDURALGENERATOR()
Definition: cmaterial.h:43
virtual ~CMATERIAL()
Definition: cmaterial.h:206
Definition: ray.h:67
void SetNormalPerturbator(const CPROCEDURALGENERATOR *aPerturbator)
Definition: cmaterial.h:250
float m_reflection
1.0 completely reflective, 0.0 no reflective
Definition: cmaterial.h:267
float m_transparency
1.0 is completely transparent, 0.0 completely opaque
Definition: cmaterial.h:265
const SFVEC3F & GetAmbientColor() const
Definition: cmaterial.h:208
unsigned int GetNrRefractionsSamples() const
Definition: cmaterial.h:216
SFVEC3F Generate(const RAY &aRay, const HITINFO &aHitInfo) const override
Generate - Generates a 3D vector based on the ray and hit information depending on the implementation...
Definition: cmaterial.cpp:154
float m_scale
Definition: cmaterial.h:77
SFVEC3F m_ambientColor
Definition: cmaterial.h:256
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 - Shades an intersection point.
unsigned int m_reflections_nr_samples
nr of rays that will be interpolated for this material if it is reflective
Definition: cmaterial.h:270
const CPROCEDURALGENERATOR * m_normal_perturbator
Definition: cmaterial.h:272
PerlinNoise m_perlin
Definition: cmaterial.h:143
float m_shinness
Definition: cmaterial.h:264
PerlinNoise m_perlin
Definition: cmaterial.h:190
#define NULL
bool m_cast_shadows
true if this object will block the light
Definition: cmaterial.h:268
bool GetCastShadows() const
Definition: cmaterial.h:229
Blinn Phong based material https://en.wikipedia.org/wiki/Blinn%E2%80%93Phong_shading_model.
Definition: cmaterial.h:278
SFVEC3F Shade(const RAY &aRay, const HITINFO &aHitInfo, float NdotL, const SFVEC3F &aDiffuseObjColor, const SFVEC3F &aDirToLight, const SFVEC3F &aLightColor, float aShadowAttenuationFactor) const override
Shade - Shades an intersection point.
Definition: cmaterial.cpp:101
virtual ~CBOARDNORMAL()
Definition: cmaterial.h:69
virtual SFVEC3F Generate(const RAY &aRay, const HITINFO &aHitInfo) const =0
Generate - Generates a 3D vector based on the ray and hit information depending on the implementation...
void SetNrRefractionsSamples(unsigned int aNrRefractions)
Definition: cmaterial.h:220
PerlinNoise m_perlin
Definition: cmaterial.h:167
const CPROCEDURALGENERATOR * m_board_normal_generator
Definition: cmaterial.h:100
CBLINN_PHONG_MATERIAL(const SFVEC3F &aAmbient, const SFVEC3F &aEmissive, const SFVEC3F &aSpecular, float aShinness, float aTransparency, float aReflection)
Definition: cmaterial.h:283
float GetReflection() const
Definition: cmaterial.h:214
virtual ~CPLASTICNORMAL()
Definition: cmaterial.h:135
float GetTransparency() const
Definition: cmaterial.h:213
float GetShinness() const
Definition: cmaterial.h:212
void SetNrReflectionsSamples(unsigned int aNrReflections)
Definition: cmaterial.h:221
Stores the hit information of a ray with a point on the surface of a object.
Definition: hitinfo.h:40
glm::vec3 SFVEC3F
Definition: xv3d_types.h:47
void SetCastShadows(bool aCastShadows)
SetCastShadows - Set if the material can receive shadows.
Definition: cmaterial.h:227
SFVEC3F m_emissiveColor
Definition: cmaterial.h:262
float m_scale
Definition: cmaterial.h:102
float GetAbsorvance() const
Definition: cmaterial.h:215
SFVEC3F m_specularColor
Definition: cmaterial.h:263
void SetAbsorvance(float aAbsorvanceFactor)
Definition: cmaterial.h:219
unsigned int m_refraction_nr_samples
nr of rays that will be interpolated for this material if it is a transparent
Definition: cmaterial.h:269
virtual ~CPLASTICSHINENORMAL()
Definition: cmaterial.h:159
void PerturbeNormal(SFVEC3F &aNormal, const RAY &aRay, const HITINFO &aHitInfo) const
Definition: cmaterial.cpp:88
const CPROCEDURALGENERATOR * GetNormalPerturbator() const
Definition: cmaterial.h:251
A base class that can be used to derive a procedural generator implementation.
Definition: cmaterial.h:38
unsigned int GetNrReflectionsSamples() const
Definition: cmaterial.h:217
float m_absorbance
absorvance factor for the transparent material
Definition: cmaterial.h:266
SFVEC3F Generate(const RAY &aRay, const HITINFO &aHitInfo) const override
Generate - Generates a 3D vector based on the ray and hit information depending on the implementation...
Definition: cmaterial.cpp:228
SFVEC3F Generate(const RAY &aRay, const HITINFO &aHitInfo) const override
Generate - Generates a 3D vector based on the ray and hit information depending on the implementation...
Definition: cmaterial.cpp:256