KiCad PCB EDA Suite
CCOPPERNORMAL Class Reference

#include <cmaterial.h>

Inheritance diagram for CCOPPERNORMAL:
CPROCEDURALGENERATOR

Public Member Functions

 CCOPPERNORMAL ()
 
 CCOPPERNORMAL (float aScale, const CPROCEDURALGENERATOR *aBoardNormalGenerator)
 
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. More...
 

Private Attributes

const CPROCEDURALGENERATORm_board_normal_generator
 
PerlinNoise m_copper_perlin
 
float m_scale
 

Detailed Description

Definition at line 73 of file cmaterial.h.

Constructor & Destructor Documentation

CCOPPERNORMAL::CCOPPERNORMAL ( )
inline

Definition at line 76 of file cmaterial.h.

References m_board_normal_generator, and m_scale.

77  {
79  m_scale = 1.0f;
80  }
const CPROCEDURALGENERATOR * m_board_normal_generator
Definition: cmaterial.h:88
float m_scale
Definition: cmaterial.h:90
CCOPPERNORMAL::CCOPPERNORMAL ( float  aScale,
const CPROCEDURALGENERATOR aBoardNormalGenerator 
)

Definition at line 170 of file cmaterial.cpp.

References m_board_normal_generator, m_copper_perlin, and m_scale.

171 {
172  m_board_normal_generator = aBoardNormalGenerator;
174  m_scale = 1.0f / aScale;
175 }
PerlinNoise m_copper_perlin
Definition: cmaterial.h:89
const CPROCEDURALGENERATOR * m_board_normal_generator
Definition: cmaterial.h:88
float m_scale
Definition: cmaterial.h:90

Member Function Documentation

SFVEC3F CCOPPERNORMAL::Generate ( const RAY aRay,
const HITINFO aHitInfo 
) const
overridevirtual

Generate - Generates a 3D vector based on the ray and hit information depending on the implementation.

Parameters
aRaythe camera ray that hits the object
aHitInfothe hit information
Returns
the result of the procedural

Implements CPROCEDURALGENERATOR.

Definition at line 178 of file cmaterial.cpp.

References Fast_RandFloat(), CPROCEDURALGENERATOR::Generate(), m_board_normal_generator, m_copper_perlin, HITINFO::m_HitPoint, m_scale, and PerlinNoise::noise().

179 {
181  {
182  const SFVEC3F boardNormal = m_board_normal_generator->Generate( aRay, aHitInfo );
183 
184  SFVEC3F hitPos = aHitInfo.m_HitPoint * m_scale;
185 
186  const float noise = (m_copper_perlin.noise( hitPos.x + Fast_RandFloat() * 0.1f,
187  hitPos.y ) - 0.5f) * 2.0f;
188 
189  float scratchPattern = (m_copper_perlin.noise( hitPos.x / 100.0f, hitPos.y * 20.0f ) - 0.5f);
190 
191  scratchPattern = glm::clamp( scratchPattern * 5.0f, -1.0f, 1.0f );
192 
193  const float x = glm::clamp( (noise + scratchPattern) * 0.04f, -0.10f, 0.10f );
194  const float y = glm::clamp( (noise + (noise * scratchPattern)) * 0.04f, -0.10f, 0.10f );
195 
196  return SFVEC3F( x, y, 0.0f ) + boardNormal * 0.85f;
197  }
198  else
199  return SFVEC3F(0.0f);
200 }
PerlinNoise m_copper_perlin
Definition: cmaterial.h:89
float Fast_RandFloat()
Definition: 3d_fastmath.cpp:45
SFVEC3F m_HitPoint
(12) hit position
Definition: hitinfo.h:49
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...
const CPROCEDURALGENERATOR * m_board_normal_generator
Definition: cmaterial.h:88
float noise(float x, float y, float z) const
Definition: PerlinNoise.cpp:97
glm::vec3 SFVEC3F
Definition: xv3d_types.h:47
float m_scale
Definition: cmaterial.h:90

Member Data Documentation

const CPROCEDURALGENERATOR* CCOPPERNORMAL::m_board_normal_generator
private

Definition at line 88 of file cmaterial.h.

Referenced by CCOPPERNORMAL(), and Generate().

PerlinNoise CCOPPERNORMAL::m_copper_perlin
private

Definition at line 89 of file cmaterial.h.

Referenced by CCOPPERNORMAL(), and Generate().

float CCOPPERNORMAL::m_scale
private

Definition at line 90 of file cmaterial.h.

Referenced by CCOPPERNORMAL(), and Generate().


The documentation for this class was generated from the following files: