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 
50  virtual SFVEC3F Generate( const RAY &aRay,
51  const HITINFO &aHitInfo ) const = 0;
52 
53 protected:
54 
55 };
56 
57 
58 // Procedural generation of the board normals
60 {
61 public:
63  CBOARDNORMAL( float aScale );
64 
65  // Imported from CPROCEDURALGENERATOR
66  SFVEC3F Generate( const RAY &aRay,
67  const HITINFO &aHitInfo ) const override;
68 private:
69  float m_scale;
70 };
71 
72 // Procedural generation of the copper normals
74 {
75 public:
77  {
79  m_scale = 1.0f;
80  }
81 
82  CCOPPERNORMAL( float aScale, const CPROCEDURALGENERATOR *aBoardNormalGenerator );
83 
84  // Imported from CPROCEDURALGENERATOR
85  SFVEC3F Generate( const RAY &aRay,
86  const HITINFO &aHitInfo ) const override;
87 private:
90  float m_scale;
91 };
92 
93 // Procedural generation of the solder mask
95 {
96 public:
98  CSOLDERMASKNORMAL( const CPROCEDURALGENERATOR *aCopperNormalGenerator );
99 
100  // Imported from CPROCEDURALGENERATOR
101  SFVEC3F Generate( const RAY &aRay,
102  const HITINFO &aHitInfo ) const override;
103 private:
105 };
106 
107 
108 // Procedural generation of the plastic normals
110 {
111 public:
113  {
114  m_scale = 1.0f;
115  }
116 
117  CPLASTICNORMAL( float aScale );
118 
119  // Imported from CPROCEDURALGENERATOR
120  SFVEC3F Generate( const RAY &aRay,
121  const HITINFO &aHitInfo ) const override;
122 private:
124  float m_scale;
125 };
126 
127 
128 // Procedural generation of the shiny plastic normals
130 {
131 public:
133  {
134  m_scale = 1.0f;
135  }
136 
137  CPLASTICSHINENORMAL( float aScale );
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 // Procedural generation of the shiny brushed metal
149 {
150 public:
152  {
153  m_scale = 1.0f;
154  }
155 
156  CMETALBRUSHEDNORMAL( float aScale );
157 
158  // Imported from CPROCEDURALGENERATOR
159  SFVEC3F Generate( const RAY &aRay,
160  const HITINFO &aHitInfo ) const override;
161 private:
163  float m_scale;
164 };
165 
168 {
169 public:
170  CMATERIAL();
171  CMATERIAL( const SFVEC3F &aAmbient,
172  const SFVEC3F &aEmissive,
173  const SFVEC3F &aSpecular,
174  float aShinness,
175  float aTransparency,
176  float aReflection );
177 
178  const SFVEC3F &GetAmbientColor() const { return m_ambientColor; }
179  const SFVEC3F &GetEmissiveColor() const { return m_emissiveColor; }
180  const SFVEC3F &GetSpecularColor() const { return m_specularColor; }
181 
182  float GetShinness() const { return m_shinness; }
183  float GetTransparency() const { return m_transparency; }
184  float GetReflection() const { return m_reflection; }
185  float GetAbsorvance() const { return m_absorbance; }
186  unsigned int GetNrRefractionsSamples() const { return m_refraction_nr_samples; }
187  unsigned int GetNrReflectionsSamples() const { return m_reflections_nr_samples; }
188 
189  void SetAbsorvance( float aAbsorvanceFactor ) { m_absorbance = aAbsorvanceFactor; }
190  void SetNrRefractionsSamples( unsigned int aNrRefractions ) { m_refraction_nr_samples = aNrRefractions; }
191  void SetNrReflectionsSamples( unsigned int aNrReflections ) { m_reflections_nr_samples = aNrReflections; }
192 
197  void SetCastShadows( bool aCastShadows ) { m_cast_shadows = aCastShadows; }
198 
199  bool GetCastShadows() const { return m_cast_shadows; }
200 
212  virtual SFVEC3F Shade( const RAY &aRay,
213  const HITINFO &aHitInfo,
214  float NdotL,
215  const SFVEC3F &aDiffuseObjColor,
216  const SFVEC3F &aDirToLight,
217  const SFVEC3F &aLightColor,
218  float aShadowAttenuationFactor ) const = 0;
219 
220  void SetNormalPerturbator( const CPROCEDURALGENERATOR *aPerturbator ) { m_normal_perturbator = aPerturbator; }
222 
223  void PerturbeNormal( SFVEC3F &aNormal, const RAY &aRay, const HITINFO &aHitInfo ) const;
224 
225 protected:
227 
228  // NOTE: we will not use diffuse color material here,
229  // because it will be stored in object, since there are objects (i.e: triangles)
230  // that can have per vertex color
231 
234  float m_shinness;
236  float m_absorbance;
237  float m_reflection;
239  unsigned int m_refraction_nr_samples;
241 
243 };
244 
245 
249 {
250 public:
252 
253  CBLINN_PHONG_MATERIAL( const SFVEC3F &aAmbient,
254  const SFVEC3F &aEmissive,
255  const SFVEC3F &aSpecular,
256  float aShinness,
257  float aTransparency,
258  float aReflection ) : CMATERIAL( aAmbient,
259  aEmissive,
260  aSpecular,
261  aShinness,
262  aTransparency,
263  aReflection ) {}
264 
265  // Imported from CMATERIAL
266  SFVEC3F Shade( const RAY &aRay,
267  const HITINFO &aHitInfo,
268  float NdotL,
269  const SFVEC3F &aDiffuseObjColor,
270  const SFVEC3F &aDirToLight,
271  const SFVEC3F &aLightColor,
272  float aShadowAttenuationFactor ) const override;
273 };
274 
275 #endif // _CMATERIAL_H_
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
float GetTransparency() const
Definition: cmaterial.h:183
const CPROCEDURALGENERATOR * m_copper_normal_generator
Definition: cmaterial.h:104
This source code comes from the project: https://github.com/sol-prog/Perlin_Noise.
const SFVEC3F & GetAmbientColor() const
Definition: cmaterial.h:178
A base material class that can be used to derive a material implementation.
Definition: cmaterial.h:167
float GetAbsorvance() const
Definition: cmaterial.h:185
PerlinNoise m_copper_perlin
Definition: cmaterial.h:89
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
const SFVEC3F & GetSpecularColor() const
Definition: cmaterial.h:180
Definition: ray.h:43
void SetNormalPerturbator(const CPROCEDURALGENERATOR *aPerturbator)
Definition: cmaterial.h:220
float m_reflection
1.0 completely reflective, 0.0 no reflective
Definition: cmaterial.h:237
float m_transparency
1.0 is completely transparent, 0.0 completely opaque
Definition: cmaterial.h:235
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:69
SFVEC3F m_ambientColor
Definition: cmaterial.h:226
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:240
const CPROCEDURALGENERATOR * m_normal_perturbator
Definition: cmaterial.h:242
PerlinNoise m_perlin
Definition: cmaterial.h:123
float m_shinness
Definition: cmaterial.h:234
PerlinNoise m_perlin
Definition: cmaterial.h:162
bool m_cast_shadows
true if this object will block the light
Definition: cmaterial.h:238
unsigned int GetNrReflectionsSamples() const
Definition: cmaterial.h:187
void PerturbeNormal(SFVEC3F &aNormal, const RAY &aRay, const HITINFO &aHitInfo) const
Definition: cmaterial.cpp:88
bool GetCastShadows() const
Definition: cmaterial.h:199
Blinn Phong based material https://en.wikipedia.org/wiki/Blinn%E2%80%93Phong_shading_model.
Definition: cmaterial.h:248
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 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:190
PerlinNoise m_perlin
Definition: cmaterial.h:143
const CPROCEDURALGENERATOR * m_board_normal_generator
Definition: cmaterial.h:88
unsigned int GetNrRefractionsSamples() const
Definition: cmaterial.h:186
CBLINN_PHONG_MATERIAL(const SFVEC3F &aAmbient, const SFVEC3F &aEmissive, const SFVEC3F &aSpecular, float aShinness, float aTransparency, float aReflection)
Definition: cmaterial.h:253
void SetNrReflectionsSamples(unsigned int aNrReflections)
Definition: cmaterial.h:191
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:197
SFVEC3F m_emissiveColor
Definition: cmaterial.h:232
float m_scale
Definition: cmaterial.h:90
const SFVEC3F & GetEmissiveColor() const
Definition: cmaterial.h:179
SFVEC3F m_specularColor
Definition: cmaterial.h:233
void SetAbsorvance(float aAbsorvanceFactor)
Definition: cmaterial.h:189
unsigned int m_refraction_nr_samples
nr of rays that will be interpolated for this material if it is a transparent
Definition: cmaterial.h:239
float GetShinness() const
Definition: cmaterial.h:182
A base class that can be used to derive a procedural generator implementation.
Definition: cmaterial.h:38
const CPROCEDURALGENERATOR * GetNormalPerturbator() const
Definition: cmaterial.h:221
float m_absorbance
absorvance factor for the transparent material
Definition: cmaterial.h:236
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
float GetReflection() const
Definition: cmaterial.h:184
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