KiCad PCB EDA Suite
Loading...
Searching...
No Matches
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 The 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, see <https://www.gnu.org/licenses/>.
19 */
20
21#ifndef MATERIAL_H
22#define MATERIAL_H
23
24#include "ray.h"
25#include "hitinfo.h"
26#include "PerlinNoise.h"
27
32{
33public:
35
37 {
38 }
39
47 virtual SFVEC3F Generate( const RAY& aRay, const HITINFO& aHitInfo ) const = 0;
48};
49
50
52{
53public:
55 BOARD_NORMAL( float aScale );
56
57 virtual ~BOARD_NORMAL()
58 {
59 }
60
61 SFVEC3F Generate( const RAY& aRay, const HITINFO& aHitInfo ) const override;
62
63private:
64 float m_scale;
65};
66
67
72{
73public:
75 {
77 m_scale = 1.0f;
78 }
79
80 COPPER_NORMAL( float aScale, const MATERIAL_GENERATOR* aBoardNormalGenerator );
81
83 {
84 }
85
86 SFVEC3F Generate( const RAY& aRay, const HITINFO& aHitInfo ) const override;
87
88private:
90 float m_scale;
91};
92
93
95{
96public:
98 {
99 m_scale = 1.0f;
100 }
101
102 PLATED_COPPER_NORMAL( float aScale )
103 {
104 m_scale = 1.0f / aScale;
105 }
106
108 {
109 }
110
111 SFVEC3F Generate( const RAY& aRay, const HITINFO& aHitInfo ) const override;
112
113private:
114 float m_scale;
115};
116
117
122{
123public:
125 SOLDER_MASK_NORMAL( const MATERIAL_GENERATOR* aCopperNormalGenerator );
126
128 {
129 }
130
131 SFVEC3F Generate( const RAY& aRay, const HITINFO& aHitInfo ) const override;
132
133private:
135};
136
137
142{
143public:
145 {
146 m_scale = 1.0f;
147 }
148
149 PLASTIC_NORMAL( float aScale );
150
152 {
153 }
154
155 SFVEC3F Generate( const RAY& aRay, const HITINFO& aHitInfo ) const override;
156
157private:
158 float m_scale;
159};
160
161
166{
167public:
169 {
170 m_scale = 1.0f;
171 }
172
173 PLASTIC_SHINE_NORMAL( float aScale );
174
176 {
177 }
178
179 // Imported from MATERIAL_GENERATOR
180 SFVEC3F Generate( const RAY& aRay, const HITINFO& aHitInfo ) const override;
181
182private:
183 float m_scale;
184};
185
186
191{
192public:
194 {
195 m_scale = 1.0f;
196 }
197
198 BRUSHED_METAL_NORMAL( float aScale );
199
201 {
202 }
203
204 SFVEC3F Generate( const RAY& aRay, const HITINFO& aHitInfo ) const override;
205
206private:
207 float m_scale;
208};
209
210
212{
213public:
215 {
216 m_scale = 1.0f;
217 }
218
219 SILK_SCREEN_NORMAL( float aScale );
220
222 {
223 }
224
225 SFVEC3F Generate( const RAY& aRay, const HITINFO& aHitInfo ) const override;
226
227private:
228 float m_scale;
229};
230
231
236{
237public:
238 static void SetDefaultRefractionRayCount( unsigned int aCount )
239 {
241 }
242
243 static void SetDefaultReflectionRayCount( unsigned int aCount )
244 {
246 }
247
248 static void SetDefaultRefractionRecursionCount( unsigned int aCount )
249 {
251 }
252
253 static void SetDefaultReflectionRecursionCount( unsigned int aCount )
254 {
256 }
257
258 MATERIAL();
259 MATERIAL( const SFVEC3F& aAmbient, const SFVEC3F& aEmissive, const SFVEC3F& aSpecular,
260 float aShinness, float aTransparency, float aReflection );
261
262 virtual ~MATERIAL() {}
263
264 const SFVEC3F& GetAmbientColor() const { return m_ambientColor; }
265 const SFVEC3F& GetEmissiveColor() const { return m_emissiveColor; }
266 const SFVEC3F& GetSpecularColor() const { return m_specularColor; }
267
268 float GetReflectivity() const { return m_reflectivity; }
269 float GetTransparency() const { return m_transparency; }
270 float GetReflection() const { return m_reflection; }
271 float GetAbsorvance() const { return m_absorbance; }
272 unsigned int GetRefractionRayCount() const { return m_refractionRayCount; }
273 unsigned int GetReflectionRayCount() const { return m_reflectionRayCount; }
276
277 void SetAbsorvance( float aAbsorvanceFactor ) { m_absorbance = aAbsorvanceFactor; }
278 void SetRefractionRayCount( unsigned int aCount )
279 {
280 m_refractionRayCount = aCount;
281 }
282
283 void SetReflectionRayCount( unsigned int aCount )
284 {
285 m_reflectionRayCount = aCount;
286 }
287
288 void SetReflectionRecursionCount( unsigned int aCount )
289 {
291 }
292
293 void SetRefractionRecursionCount( unsigned int aCount )
294 {
296 }
297
303 void SetCastShadows( bool aCastShadows ) { m_castShadows = aCastShadows; }
304
305 bool GetCastShadows() const { return m_castShadows; }
306
319 virtual SFVEC3F Shade( const RAY& aRay, const HITINFO& aHitInfo, float NdotL,
320 const SFVEC3F& aDiffuseObjColor, const SFVEC3F& aDirToLight,
321 const SFVEC3F& aLightColor,
322 float aShadowAttenuationFactor ) const = 0;
323
324 void SetGenerator( const MATERIAL_GENERATOR* aGenerator )
325 {
326 m_generator = aGenerator;
327 }
328
329 const MATERIAL_GENERATOR* GetGenerator() const { return m_generator; }
330
331 void Generate( SFVEC3F& aNormal, const RAY& aRay, const HITINFO& aHitInfo ) const;
332
333protected:
335
336 // NOTE: we will not use diffuse color material here,
337 // because it will be stored in object, since there are objects (i.e: triangles)
338 // that can have per vertex color
339
343
349
352
355
358
361
363
364private:
369};
370
371
375{
376public:
378
379 BLINN_PHONG_MATERIAL( const SFVEC3F& aAmbient, const SFVEC3F& aEmissive,
380 const SFVEC3F& aSpecular, float aShinness, float aTransparency,
381 float aReflection ) :
382 MATERIAL( aAmbient, aEmissive, aSpecular, aShinness, aTransparency, aReflection ) {}
383
384 // Imported from MATERIAL
385 SFVEC3F Shade( const RAY& aRay, const HITINFO& aHitInfo, float NdotL,
386 const SFVEC3F& aDiffuseObjColor, const SFVEC3F& aDirToLight,
387 const SFVEC3F& aLightColor, float aShadowAttenuationFactor ) const override;
388};
389
390#endif // MATERIAL_H
This source code comes from the project: https://github.com/sol-prog/Perlin_Noise.
BLINN_PHONG_MATERIAL(const SFVEC3F &aAmbient, const SFVEC3F &aEmissive, const SFVEC3F &aSpecular, float aShinness, float aTransparency, float aReflection)
Definition material.h:379
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: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:142
float m_scale
Definition material.h:64
virtual ~BOARD_NORMAL()
Definition material.h:57
virtual ~BRUSHED_METAL_NORMAL()
Definition material.h:200
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:282
float m_scale
Definition material.h:90
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:168
const MATERIAL_GENERATOR * m_board_normal_generator
Definition material.h:89
virtual ~COPPER_NORMAL()
Definition material.h:82
A base class that can be used to derive procedurally generated materials.
Definition material.h:32
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:36
float GetReflectivity() const
Definition material.h:268
float GetAbsorvance() const
Definition material.h:271
SFVEC3F m_emissiveColor
Definition material.h:340
const MATERIAL_GENERATOR * GetGenerator() const
Definition material.h:329
void SetReflectionRayCount(unsigned int aCount)
Definition material.h:283
unsigned int m_refractionRayCount
Number of rays that will be interpolated for this material if it is transparent.
Definition material.h:351
unsigned int m_refractionRecursionCount
Number of levels it allows for refraction recursiveness.
Definition material.h:357
static void SetDefaultReflectionRayCount(unsigned int aCount)
Definition material.h:243
void SetRefractionRecursionCount(unsigned int aCount)
Definition material.h:293
static void SetDefaultRefractionRayCount(unsigned int aCount)
Definition material.h:238
float m_absorbance
absorbance factor for the transparent material.
Definition material.h:346
unsigned int m_reflectionRayCount
Number of rays that will be interpolated for this material if it is reflective.
Definition material.h:354
unsigned int m_reflectionRecursionCount
Number of levels it allows for reflection recursiveness.
Definition material.h:360
bool GetCastShadows() const
Definition material.h:305
static int m_defaultReflectionRayCount
Definition material.h:366
static int m_defaultRefractionRayCount
Definition material.h:365
static void SetDefaultRefractionRecursionCount(unsigned int aCount)
Definition material.h:248
void SetCastShadows(bool aCastShadows)
Set if the material can receive shadows.
Definition material.h:303
void SetGenerator(const MATERIAL_GENERATOR *aGenerator)
Definition material.h:324
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:264
unsigned int GetReflectionRecursionCount() const
Definition material.h:274
static int m_defaultRefractionRecursionCount
Definition material.h:367
float GetTransparency() const
Definition material.h:269
unsigned int GetRefractionRayCount() const
Definition material.h:272
bool m_castShadows
true if this object will block the light.
Definition material.h:348
unsigned int GetRefractionRecursionCount() const
Definition material.h:275
virtual ~MATERIAL()
Definition material.h:262
void Generate(SFVEC3F &aNormal, const RAY &aRay, const HITINFO &aHitInfo) const
Definition material.cpp:86
SFVEC3F m_ambientColor
Definition material.h:334
float m_transparency
1.0 is completely transparent, 0.0 completely opaque.
Definition material.h:345
float m_reflection
1.0 completely reflective, 0.0 no reflective.
Definition material.h:347
const MATERIAL_GENERATOR * m_generator
Definition material.h:362
const SFVEC3F & GetSpecularColor() const
Definition material.h:266
void SetReflectionRecursionCount(unsigned int aCount)
Definition material.h:288
static void SetDefaultReflectionRecursionCount(unsigned int aCount)
Definition material.h:253
float m_reflectivity
Definition material.h:342
static int m_defaultFeflectionRecursionCount
Definition material.h:368
void SetRefractionRayCount(unsigned int aCount)
Definition material.h:278
const SFVEC3F & GetEmissiveColor() const
Definition material.h:265
SFVEC3F m_specularColor
Definition material.h:341
void SetAbsorvance(float aAbsorvanceFactor)
Definition material.h:277
float GetReflection() const
Definition material.h:270
unsigned int GetReflectionRayCount() const
Definition material.h:273
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:233
virtual ~PLASTIC_NORMAL()
Definition material.h:151
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:258
virtual ~PLASTIC_SHINE_NORMAL()
Definition material.h:175
virtual ~PLATED_COPPER_NORMAL()
Definition material.h:107
PLATED_COPPER_NORMAL(float aScale)
Definition material.h:102
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:216
virtual ~SILK_SCREEN_NORMAL()
Definition material.h:221
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:305
const MATERIAL_GENERATOR * m_copper_normal_generator
Definition material.h:134
virtual ~SOLDER_MASK_NORMAL()
Definition material.h:127
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:201
Stores the hit information of a ray with a point on the surface of a object.
Definition hitinfo.h:32
Definition ray.h:59
glm::vec3 SFVEC3F
Definition xv3d_types.h:40