KiCad PCB EDA Suite
BLINN_PHONG_MATERIAL Class Reference

Blinn Phong based material https://en.wikipedia.org/wiki/Blinn%E2%80%93Phong_shading_model. More...

#include <material.h>

Inheritance diagram for BLINN_PHONG_MATERIAL:
MATERIAL

Public Member Functions

 BLINN_PHONG_MATERIAL ()
 
 BLINN_PHONG_MATERIAL (const SFVEC3F &aAmbient, const SFVEC3F &aEmissive, const SFVEC3F &aSpecular, float aShinness, float aTransparency, float aReflection)
 
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. More...
 
const SFVEC3FGetAmbientColor () const
 
const SFVEC3FGetEmissiveColor () const
 
const SFVEC3FGetSpecularColor () const
 
float GetReflectivity () const
 
float GetTransparency () const
 
float GetReflection () const
 
float GetAbsorvance () const
 
unsigned int GetRefractionRayCount () const
 
unsigned int GetReflectionRayCount () const
 
unsigned int GetReflectionRecursionCount () const
 
unsigned int GetRefractionRecursionCount () const
 
void SetAbsorvance (float aAbsorvanceFactor)
 
void SetRefractionRayCount (unsigned int aCount)
 
void SetReflectionRayCount (unsigned int aCount)
 
void SetReflectionRecursionCount (unsigned int aCount)
 
void SetRefractionRecursionCount (unsigned int aCount)
 
void SetCastShadows (bool aCastShadows)
 Set if the material can receive shadows. More...
 
bool GetCastShadows () const
 
void SetGenerator (const MATERIAL_GENERATOR *aGenerator)
 
const MATERIAL_GENERATORGetGenerator () const
 
void Generate (SFVEC3F &aNormal, const RAY &aRay, const HITINFO &aHitInfo) const
 

Static Public Member Functions

static void SetDefaultRefractionRayCount (unsigned int aCount)
 
static void SetDefaultReflectionRayCount (unsigned int aCount)
 
static void SetDefaultRefractionRecursionCount (unsigned int aCount)
 
static void SetDefaultReflectionRecursionCount (unsigned int aCount)
 

Protected Attributes

SFVEC3F m_ambientColor
 
SFVEC3F m_emissiveColor
 
SFVEC3F m_specularColor
 
float m_reflectivity
 1.0 is completely transparent, 0.0 completely opaque. More...
 
float m_transparency
 
float m_absorbance
 absorbance factor for the transparent material. More...
 
float m_reflection
 1.0 completely reflective, 0.0 no reflective. More...
 
bool m_castShadows
 true if this object will block the light. More...
 
unsigned int m_refractionRayCount
 Number of rays that will be interpolated for this material if it is reflective. More...
 
unsigned int m_reflectionRayCount
 Number of levels it allows for refraction recursiveness. More...
 
unsigned int m_refractionRecursionCount
 Number of levels it allows for reflection recursiveness. More...
 
unsigned int m_reflectionRecursionCount
 
const MATERIAL_GENERATORm_generator
 

Detailed Description

Blinn Phong based material https://en.wikipedia.org/wiki/Blinn%E2%80%93Phong_shading_model.

Definition at line 382 of file material.h.

Constructor & Destructor Documentation

◆ BLINN_PHONG_MATERIAL() [1/2]

BLINN_PHONG_MATERIAL::BLINN_PHONG_MATERIAL ( )
inline

Definition at line 385 of file material.h.

385 : MATERIAL() {}
MATERIAL()
Definition: material.cpp:44

◆ BLINN_PHONG_MATERIAL() [2/2]

BLINN_PHONG_MATERIAL::BLINN_PHONG_MATERIAL ( const SFVEC3F aAmbient,
const SFVEC3F aEmissive,
const SFVEC3F aSpecular,
float  aShinness,
float  aTransparency,
float  aReflection 
)
inline

Definition at line 387 of file material.h.

389  :
390  MATERIAL( aAmbient, aEmissive, aSpecular, aShinness, aTransparency, aReflection ) {}
MATERIAL()
Definition: material.cpp:44

Member Function Documentation

◆ Generate()

void MATERIAL::Generate ( SFVEC3F aNormal,
const RAY aRay,
const HITINFO aHitInfo 
) const
inherited

Definition at line 93 of file material.cpp.

94 {
95  if( m_generator )
96  {
97  aNormal = aNormal + m_generator->Generate( aRay, aHitInfo );
98  aNormal = glm::normalize( aNormal );
99  }
100 }
const MATERIAL_GENERATOR * m_generator
Definition: material.h:370
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.

References MATERIAL_GENERATOR::Generate(), and MATERIAL::m_generator.

Referenced by LAYER_ITEM::Intersect(), ROUND_SEGMENT::Intersect(), DUMMY_BLOCK::Intersect(), CYLINDER::Intersect(), XY_PLANE::Intersect(), and TRIANGLE::Intersect().

◆ GetAbsorvance()

float MATERIAL::GetAbsorvance ( ) const
inlineinherited

Definition at line 279 of file material.h.

279 { return m_absorbance; }
float m_absorbance
absorbance factor for the transparent material.
Definition: material.h:354

References MATERIAL::m_absorbance.

Referenced by RENDER_3D_RAYTRACE::shadeHit().

◆ GetAmbientColor()

const SFVEC3F& MATERIAL::GetAmbientColor ( ) const
inlineinherited

Definition at line 272 of file material.h.

272 { return m_ambientColor; }
SFVEC3F m_ambientColor
Definition: material.h:342

References MATERIAL::m_ambientColor.

Referenced by RENDER_3D_RAYTRACE::shadeHit().

◆ GetCastShadows()

bool MATERIAL::GetCastShadows ( ) const
inlineinherited

Definition at line 313 of file material.h.

313 { return m_castShadows; }
bool m_castShadows
true if this object will block the light.
Definition: material.h:356

References MATERIAL::m_castShadows.

Referenced by BVH_PBRT::IntersectP().

◆ GetEmissiveColor()

const SFVEC3F& MATERIAL::GetEmissiveColor ( ) const
inlineinherited

Definition at line 273 of file material.h.

273 { return m_emissiveColor; }
SFVEC3F m_emissiveColor
Definition: material.h:348

References MATERIAL::m_emissiveColor.

Referenced by RENDER_3D_RAYTRACE::shadeHit().

◆ GetGenerator()

const MATERIAL_GENERATOR* MATERIAL::GetGenerator ( ) const
inlineinherited

Definition at line 337 of file material.h.

337 { return m_generator; }
const MATERIAL_GENERATOR * m_generator
Definition: material.h:370

References MATERIAL::m_generator.

◆ GetReflection()

float MATERIAL::GetReflection ( ) const
inlineinherited

Definition at line 278 of file material.h.

278 { return m_reflection; }
float m_reflection
1.0 completely reflective, 0.0 no reflective.
Definition: material.h:355

References MATERIAL::m_reflection.

Referenced by RENDER_3D_RAYTRACE::shadeHit().

◆ GetReflectionRayCount()

unsigned int MATERIAL::GetReflectionRayCount ( ) const
inlineinherited

Definition at line 281 of file material.h.

281 { return m_reflectionRayCount; }
unsigned int m_reflectionRayCount
Number of levels it allows for refraction recursiveness.
Definition: material.h:362

References MATERIAL::m_reflectionRayCount.

Referenced by RENDER_3D_RAYTRACE::shadeHit().

◆ GetReflectionRecursionCount()

unsigned int MATERIAL::GetReflectionRecursionCount ( ) const
inlineinherited

Definition at line 282 of file material.h.

282 { return m_reflectionRecursionCount; }
unsigned int m_reflectionRecursionCount
Definition: material.h:368

References MATERIAL::m_reflectionRecursionCount.

Referenced by RENDER_3D_RAYTRACE::shadeHit().

◆ GetReflectivity()

float MATERIAL::GetReflectivity ( ) const
inlineinherited

Definition at line 276 of file material.h.

276 { return m_reflectivity; }
float m_reflectivity
1.0 is completely transparent, 0.0 completely opaque.
Definition: material.h:350

References MATERIAL::m_reflectivity.

◆ GetRefractionRayCount()

unsigned int MATERIAL::GetRefractionRayCount ( ) const
inlineinherited

Definition at line 280 of file material.h.

280 { return m_refractionRayCount; }
unsigned int m_refractionRayCount
Number of rays that will be interpolated for this material if it is reflective.
Definition: material.h:359

References MATERIAL::m_refractionRayCount.

Referenced by RENDER_3D_RAYTRACE::shadeHit().

◆ GetRefractionRecursionCount()

unsigned int MATERIAL::GetRefractionRecursionCount ( ) const
inlineinherited

Definition at line 283 of file material.h.

283 { return m_refractionRecursionCount; }
unsigned int m_refractionRecursionCount
Number of levels it allows for reflection recursiveness.
Definition: material.h:365

References MATERIAL::m_refractionRecursionCount.

Referenced by RENDER_3D_RAYTRACE::shadeHit().

◆ GetSpecularColor()

const SFVEC3F& MATERIAL::GetSpecularColor ( ) const
inlineinherited

Definition at line 274 of file material.h.

274 { return m_specularColor; }
SFVEC3F m_specularColor
Definition: material.h:349

References MATERIAL::m_specularColor.

Referenced by RENDER_3D_RAYTRACE::shadeHit().

◆ GetTransparency()

float MATERIAL::GetTransparency ( ) const
inlineinherited

Definition at line 277 of file material.h.

277 { return m_transparency; }
float m_transparency
Definition: material.h:353

References MATERIAL::m_transparency.

Referenced by RENDER_3D_RAYTRACE::addModels(), and OBJECT_3D::SetMaterial().

◆ SetAbsorvance()

void MATERIAL::SetAbsorvance ( float  aAbsorvanceFactor)
inlineinherited

Definition at line 285 of file material.h.

285 { m_absorbance = aAbsorvanceFactor; }
float m_absorbance
absorbance factor for the transparent material.
Definition: material.h:354

References MATERIAL::m_absorbance.

◆ SetCastShadows()

void MATERIAL::SetCastShadows ( bool  aCastShadows)
inlineinherited

Set if the material can receive shadows.

Parameters
aCastShadowstrue yes it can, false not it cannot

Definition at line 311 of file material.h.

311 { m_castShadows = aCastShadows; }
bool m_castShadows
true if this object will block the light.
Definition: material.h:356

References MATERIAL::m_castShadows.

◆ SetDefaultReflectionRayCount()

static void MATERIAL::SetDefaultReflectionRayCount ( unsigned int  aCount)
inlinestaticinherited

Definition at line 251 of file material.h.

252  {
254  }
static int m_defaultReflectionRayCount
Definition: material.h:374

References MATERIAL::m_defaultReflectionRayCount.

Referenced by RENDER_3D_RAYTRACE::setupMaterials().

◆ SetDefaultReflectionRecursionCount()

static void MATERIAL::SetDefaultReflectionRecursionCount ( unsigned int  aCount)
inlinestaticinherited

Definition at line 261 of file material.h.

262  {
264  }
static int m_defaultFeflectionRecursionCount
Definition: material.h:376

References MATERIAL::m_defaultFeflectionRecursionCount.

Referenced by RENDER_3D_RAYTRACE::setupMaterials().

◆ SetDefaultRefractionRayCount()

static void MATERIAL::SetDefaultRefractionRayCount ( unsigned int  aCount)
inlinestaticinherited

Definition at line 246 of file material.h.

247  {
249  }
static int m_defaultRefractionRayCount
Definition: material.h:373

References MATERIAL::m_defaultRefractionRayCount.

Referenced by RENDER_3D_RAYTRACE::setupMaterials().

◆ SetDefaultRefractionRecursionCount()

static void MATERIAL::SetDefaultRefractionRecursionCount ( unsigned int  aCount)
inlinestaticinherited

Definition at line 256 of file material.h.

257  {
259  }
static int m_defaultRefractionRecursionCount
Definition: material.h:375

References MATERIAL::m_defaultRefractionRecursionCount.

Referenced by RENDER_3D_RAYTRACE::setupMaterials().

◆ SetGenerator()

void MATERIAL::SetGenerator ( const MATERIAL_GENERATOR aGenerator)
inlineinherited

Definition at line 332 of file material.h.

333  {
334  m_generator = aGenerator;
335  }
const MATERIAL_GENERATOR * m_generator
Definition: material.h:370

References MATERIAL::m_generator.

Referenced by RENDER_3D_RAYTRACE::getModelMaterial().

◆ SetReflectionRayCount()

void MATERIAL::SetReflectionRayCount ( unsigned int  aCount)
inlineinherited

Definition at line 291 of file material.h.

292  {
293  m_reflectionRayCount = aCount;
294  }
unsigned int m_reflectionRayCount
Number of levels it allows for refraction recursiveness.
Definition: material.h:362

References MATERIAL::m_reflectionRayCount.

◆ SetReflectionRecursionCount()

void MATERIAL::SetReflectionRecursionCount ( unsigned int  aCount)
inlineinherited

Definition at line 296 of file material.h.

297  {
299  }
unsigned int m_reflectionRecursionCount
Definition: material.h:368

References MATERIAL::m_reflectionRecursionCount.

◆ SetRefractionRayCount()

void MATERIAL::SetRefractionRayCount ( unsigned int  aCount)
inlineinherited

Definition at line 286 of file material.h.

287  {
288  m_refractionRayCount = aCount;
289  }
unsigned int m_refractionRayCount
Number of rays that will be interpolated for this material if it is reflective.
Definition: material.h:359

References MATERIAL::m_refractionRayCount.

◆ SetRefractionRecursionCount()

void MATERIAL::SetRefractionRecursionCount ( unsigned int  aCount)
inlineinherited

Definition at line 301 of file material.h.

302  {
304  }
unsigned int m_refractionRecursionCount
Number of levels it allows for reflection recursiveness.
Definition: material.h:365

References MATERIAL::m_refractionRecursionCount.

◆ Shade()

SFVEC3F BLINN_PHONG_MATERIAL::Shade ( const RAY aRay,
const HITINFO aHitInfo,
float  NdotL,
const SFVEC3F aDiffuseObjColor,
const SFVEC3F aDirToLight,
const SFVEC3F aLightColor,
float  aShadowAttenuationFactor 
) const
overridevirtual

Shade an intersection point.

Parameters
aRaythe camera ray that hits the object
aHitInfothe hit information
NdotLthe dot product between Normal and Light
aDiffuseObjColordiffuse object color
aDirToLighta vector of the incident light direction
aLightColorthe light color
aShadowAttenuationFactor0.0f total in shadow, 1.0f completely not in shadow
Returns
the resultant color

Implements MATERIAL.

Definition at line 104 of file material.cpp.

108 {
109  wxASSERT( NdotL >= FLT_EPSILON );
110 
111  // This is a hack to get some kind of fake ambient illumination
112  // There is no logic behind this, just pure artistic experimentation
113  if( aShadowAttenuationFactor > FLT_EPSILON )
114  {
115  // Calculate the diffuse light factoring in light color,
116  // power and the attenuation
117  const SFVEC3F diffuse = NdotL * aLightColor;
118 
119  // Calculate the half vector between the light vector and the view vector.
120  const SFVEC3F H = glm::normalize( aDirToLight - aRay.m_Dir );
121 
122  //Intensity of the specular light
123  const float NdotH = glm::dot( H, aHitInfo.m_HitNormal );
124  const float intensitySpecular = glm::pow( glm::max( NdotH, 0.0f ), m_reflectivity );
125 
126  return m_ambientColor +
127  aShadowAttenuationFactor * ( diffuse * aDiffuseObjColor + SPECULAR_FACTOR *
128  aLightColor * intensitySpecular * m_specularColor );
129  }
130 
131  return m_ambientColor;
132 }
#define SPECULAR_FACTOR
Definition: material.cpp:41
SFVEC3F m_ambientColor
Definition: material.h:342
SFVEC3F m_Dir
Definition: ray.h:72
#define H(x, y, z)
Definition: md5_hash.cpp:17
SFVEC3F m_specularColor
Definition: material.h:349
glm::vec3 SFVEC3F
Definition: xv3d_types.h:44
SFVEC3F m_HitNormal
(12) normal at the hit point
Definition: hitinfo.h:42
float m_reflectivity
1.0 is completely transparent, 0.0 completely opaque.
Definition: material.h:350

References H, MATERIAL::m_ambientColor, RAY::m_Dir, HITINFO::m_HitNormal, MATERIAL::m_reflectivity, MATERIAL::m_specularColor, and SPECULAR_FACTOR.

Member Data Documentation

◆ m_absorbance

float MATERIAL::m_absorbance
protectedinherited

absorbance factor for the transparent material.

Definition at line 354 of file material.h.

Referenced by MATERIAL::GetAbsorvance(), MATERIAL::MATERIAL(), and MATERIAL::SetAbsorvance().

◆ m_ambientColor

SFVEC3F MATERIAL::m_ambientColor
protectedinherited

Definition at line 342 of file material.h.

Referenced by MATERIAL::GetAmbientColor(), MATERIAL::MATERIAL(), and Shade().

◆ m_castShadows

bool MATERIAL::m_castShadows
protectedinherited

true if this object will block the light.

Number of rays that will be interpolated for this material if it is transparent.

Definition at line 356 of file material.h.

Referenced by MATERIAL::GetCastShadows(), MATERIAL::MATERIAL(), and MATERIAL::SetCastShadows().

◆ m_emissiveColor

SFVEC3F MATERIAL::m_emissiveColor
protectedinherited

Definition at line 348 of file material.h.

Referenced by MATERIAL::GetEmissiveColor(), and MATERIAL::MATERIAL().

◆ m_generator

const MATERIAL_GENERATOR* MATERIAL::m_generator
protectedinherited

◆ m_reflection

float MATERIAL::m_reflection
protectedinherited

1.0 completely reflective, 0.0 no reflective.

Definition at line 355 of file material.h.

Referenced by MATERIAL::GetReflection(), and MATERIAL::MATERIAL().

◆ m_reflectionRayCount

unsigned int MATERIAL::m_reflectionRayCount
protectedinherited

Number of levels it allows for refraction recursiveness.

Definition at line 362 of file material.h.

Referenced by MATERIAL::GetReflectionRayCount(), MATERIAL::MATERIAL(), and MATERIAL::SetReflectionRayCount().

◆ m_reflectionRecursionCount

unsigned int MATERIAL::m_reflectionRecursionCount
protectedinherited

◆ m_reflectivity

float MATERIAL::m_reflectivity
protectedinherited

1.0 is completely transparent, 0.0 completely opaque.

Definition at line 350 of file material.h.

Referenced by MATERIAL::GetReflectivity(), MATERIAL::MATERIAL(), and Shade().

◆ m_refractionRayCount

unsigned int MATERIAL::m_refractionRayCount
protectedinherited

Number of rays that will be interpolated for this material if it is reflective.

Definition at line 359 of file material.h.

Referenced by MATERIAL::GetRefractionRayCount(), MATERIAL::MATERIAL(), and MATERIAL::SetRefractionRayCount().

◆ m_refractionRecursionCount

unsigned int MATERIAL::m_refractionRecursionCount
protectedinherited

Number of levels it allows for reflection recursiveness.

Definition at line 365 of file material.h.

Referenced by MATERIAL::GetRefractionRecursionCount(), MATERIAL::MATERIAL(), and MATERIAL::SetRefractionRecursionCount().

◆ m_specularColor

SFVEC3F MATERIAL::m_specularColor
protectedinherited

Definition at line 349 of file material.h.

Referenced by MATERIAL::GetSpecularColor(), MATERIAL::MATERIAL(), and Shade().

◆ m_transparency

float MATERIAL::m_transparency
protectedinherited

Definition at line 353 of file material.h.

Referenced by MATERIAL::GetTransparency(), and MATERIAL::MATERIAL().


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