KiCad PCB EDA Suite
CBLINN_PHONG_MATERIAL Class Reference

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

#include <cmaterial.h>

Inheritance diagram for CBLINN_PHONG_MATERIAL:
CMATERIAL

Public Member Functions

 CBLINN_PHONG_MATERIAL ()
 
 CBLINN_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 - Shades an intersection point. More...
 
const SFVEC3FGetAmbientColor () const
 
const SFVEC3FGetEmissiveColor () const
 
const SFVEC3FGetSpecularColor () const
 
float GetShinness () const
 
float GetTransparency () const
 
float GetReflection () const
 
float GetAbsorvance () const
 
unsigned int GetNrRefractionsSamples () const
 
unsigned int GetNrReflectionsSamples () const
 
unsigned int GetReflectionsRecursiveLevel () const
 
unsigned int GetRefractionsRecursiveLevel () const
 
void SetAbsorvance (float aAbsorvanceFactor)
 
void SetNrRefractionsSamples (unsigned int aNrRefractions)
 
void SetNrReflectionsSamples (unsigned int aNrReflections)
 
void SetReflectionsRecursiveLevel (unsigned int aReflectionsLevel)
 
void SetRefractionsRecursiveLevel (unsigned int aRefractionsLevel)
 
void SetCastShadows (bool aCastShadows)
 SetCastShadows - Set if the material can receive shadows. More...
 
bool GetCastShadows () const
 
void SetNormalPerturbator (const CPROCEDURALGENERATOR *aPerturbator)
 
const CPROCEDURALGENERATORGetNormalPerturbator () const
 
void PerturbeNormal (SFVEC3F &aNormal, const RAY &aRay, const HITINFO &aHitInfo) const
 

Static Public Member Functions

static void SetDefaultNrRefractionsSamples (unsigned int aNrRefractions)
 
static void SetDefaultNrReflectionsSamples (unsigned int aNrReflections)
 
static void SetDefaultRefractionsLevel (unsigned int aRefractionLevel)
 
static void SetDefaultReflectionsLevel (unsigned int aReflectionLevel)
 

Protected Attributes

SFVEC3F m_ambientColor
 
SFVEC3F m_emissiveColor
 
SFVEC3F m_specularColor
 
float m_shinness
 
float m_transparency
 1.0 is completely transparent, 0.0 completely opaque More...
 
float m_absorbance
 absorvance factor for the transparent material More...
 
float m_reflection
 1.0 completely reflective, 0.0 no reflective More...
 
bool m_cast_shadows
 true if this object will block the light More...
 
unsigned int m_refraction_nr_samples
 nr of rays that will be interpolated for this material if it is a transparent More...
 
unsigned int m_reflections_nr_samples
 nr of rays that will be interpolated for this material if it is reflective More...
 
unsigned int m_refractions_recursive_levels
 nr of levels it allows for refractions recursiveness More...
 
unsigned int m_reflections_recursive_levels
 nr of levels it allows for reflection recursiveness More...
 
const CPROCEDURALGENERATORm_normal_perturbator
 

Detailed Description

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

Definition at line 318 of file cmaterial.h.

Constructor & Destructor Documentation

◆ CBLINN_PHONG_MATERIAL() [1/2]

CBLINN_PHONG_MATERIAL::CBLINN_PHONG_MATERIAL ( )
inline

Definition at line 321 of file cmaterial.h.

321 : CMATERIAL() {}

◆ CBLINN_PHONG_MATERIAL() [2/2]

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

Definition at line 323 of file cmaterial.h.

328  : CMATERIAL( aAmbient,
329  aEmissive,
330  aSpecular,
331  aShinness,
332  aTransparency,
333  aReflection ) {}

Member Function Documentation

◆ GetAbsorvance()

float CMATERIAL::GetAbsorvance ( ) const
inlineinherited

Definition at line 249 of file cmaterial.h.

249 { return m_absorbance; }
float m_absorbance
absorvance factor for the transparent material
Definition: cmaterial.h:304

References CMATERIAL::m_absorbance.

Referenced by C3D_RENDER_RAYTRACING::shadeHit().

◆ GetAmbientColor()

const SFVEC3F& CMATERIAL::GetAmbientColor ( ) const
inlineinherited

Definition at line 242 of file cmaterial.h.

242 { return m_ambientColor; }
SFVEC3F m_ambientColor
Definition: cmaterial.h:294

References CMATERIAL::m_ambientColor.

Referenced by C3D_RENDER_RAYTRACING::shadeHit().

◆ GetCastShadows()

bool CMATERIAL::GetCastShadows ( ) const
inlineinherited

Definition at line 267 of file cmaterial.h.

267 { return m_cast_shadows; }
bool m_cast_shadows
true if this object will block the light
Definition: cmaterial.h:306

References CMATERIAL::m_cast_shadows.

Referenced by CBVH_PBRT::IntersectP().

◆ GetEmissiveColor()

const SFVEC3F& CMATERIAL::GetEmissiveColor ( ) const
inlineinherited

Definition at line 243 of file cmaterial.h.

243 { return m_emissiveColor; }
SFVEC3F m_emissiveColor
Definition: cmaterial.h:300

References CMATERIAL::m_emissiveColor.

Referenced by C3D_RENDER_RAYTRACING::shadeHit().

◆ GetNormalPerturbator()

const CPROCEDURALGENERATOR* CMATERIAL::GetNormalPerturbator ( ) const
inlineinherited

Definition at line 289 of file cmaterial.h.

289 { return m_normal_perturbator; }
const CPROCEDURALGENERATOR * m_normal_perturbator
Definition: cmaterial.h:312

References CMATERIAL::m_normal_perturbator.

◆ GetNrReflectionsSamples()

unsigned int CMATERIAL::GetNrReflectionsSamples ( ) const
inlineinherited

Definition at line 251 of file cmaterial.h.

251 { return m_reflections_nr_samples; }
unsigned int m_reflections_nr_samples
nr of rays that will be interpolated for this material if it is reflective
Definition: cmaterial.h:308

References CMATERIAL::m_reflections_nr_samples.

Referenced by C3D_RENDER_RAYTRACING::shadeHit().

◆ GetNrRefractionsSamples()

unsigned int CMATERIAL::GetNrRefractionsSamples ( ) const
inlineinherited

Definition at line 250 of file cmaterial.h.

250 { return m_refraction_nr_samples; }
unsigned int m_refraction_nr_samples
nr of rays that will be interpolated for this material if it is a transparent
Definition: cmaterial.h:307

References CMATERIAL::m_refraction_nr_samples.

Referenced by C3D_RENDER_RAYTRACING::shadeHit().

◆ GetReflection()

float CMATERIAL::GetReflection ( ) const
inlineinherited

Definition at line 248 of file cmaterial.h.

248 { return m_reflection; }
float m_reflection
1.0 completely reflective, 0.0 no reflective
Definition: cmaterial.h:305

References CMATERIAL::m_reflection.

Referenced by C3D_RENDER_RAYTRACING::shadeHit().

◆ GetReflectionsRecursiveLevel()

unsigned int CMATERIAL::GetReflectionsRecursiveLevel ( ) const
inlineinherited

Definition at line 252 of file cmaterial.h.

unsigned int m_reflections_recursive_levels
nr of levels it allows for reflection recursiveness
Definition: cmaterial.h:310

References CMATERIAL::m_reflections_recursive_levels.

Referenced by C3D_RENDER_RAYTRACING::shadeHit().

◆ GetRefractionsRecursiveLevel()

unsigned int CMATERIAL::GetRefractionsRecursiveLevel ( ) const
inlineinherited

Definition at line 253 of file cmaterial.h.

unsigned int m_refractions_recursive_levels
nr of levels it allows for refractions recursiveness
Definition: cmaterial.h:309

References CMATERIAL::m_refractions_recursive_levels.

Referenced by C3D_RENDER_RAYTRACING::shadeHit().

◆ GetShinness()

float CMATERIAL::GetShinness ( ) const
inlineinherited

Definition at line 246 of file cmaterial.h.

246 { return m_shinness; }
float m_shinness
Definition: cmaterial.h:302

References CMATERIAL::m_shinness.

◆ GetSpecularColor()

const SFVEC3F& CMATERIAL::GetSpecularColor ( ) const
inlineinherited

Definition at line 244 of file cmaterial.h.

244 { return m_specularColor; }
SFVEC3F m_specularColor
Definition: cmaterial.h:301

References CMATERIAL::m_specularColor.

Referenced by C3D_RENDER_RAYTRACING::shadeHit().

◆ GetTransparency()

float CMATERIAL::GetTransparency ( ) const
inlineinherited

Definition at line 247 of file cmaterial.h.

247 { return m_transparency; }
float m_transparency
1.0 is completely transparent, 0.0 completely opaque
Definition: cmaterial.h:303

References CMATERIAL::m_transparency.

Referenced by C3D_RENDER_RAYTRACING::add_3D_models(), and COBJECT::SetMaterial().

◆ PerturbeNormal()

void CMATERIAL::PerturbeNormal ( SFVEC3F aNormal,
const RAY aRay,
const HITINFO aHitInfo 
) const
inherited

Definition at line 97 of file cmaterial.cpp.

100 {
102  {
103  aNormal = aNormal + m_normal_perturbator->Generate( aRay, aHitInfo );
104  aNormal = glm::normalize( aNormal );
105  }
106 }
const CPROCEDURALGENERATOR * m_normal_perturbator
Definition: cmaterial.h:312
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...

References CPROCEDURALGENERATOR::Generate(), and CMATERIAL::m_normal_perturbator.

Referenced by CDUMMYBLOCK::Intersect(), CLAYERITEM::Intersect(), CROUNDSEG::Intersect(), CVCYLINDER::Intersect(), CXYPLANE::Intersect(), and CTRIANGLE::Intersect().

◆ SetAbsorvance()

void CMATERIAL::SetAbsorvance ( float  aAbsorvanceFactor)
inlineinherited

Definition at line 255 of file cmaterial.h.

255 { m_absorbance = aAbsorvanceFactor; }
float m_absorbance
absorvance factor for the transparent material
Definition: cmaterial.h:304

References CMATERIAL::m_absorbance.

◆ SetCastShadows()

void CMATERIAL::SetCastShadows ( bool  aCastShadows)
inlineinherited

SetCastShadows - Set if the material can receive shadows.

Parameters
aCastShadows- true yes it can, false not it cannot

Definition at line 265 of file cmaterial.h.

265 { m_cast_shadows = aCastShadows; }
bool m_cast_shadows
true if this object will block the light
Definition: cmaterial.h:306

References CMATERIAL::m_cast_shadows.

◆ SetDefaultNrReflectionsSamples()

static void CMATERIAL::SetDefaultNrReflectionsSamples ( unsigned int  aNrReflections)
inlinestaticinherited

Definition at line 220 of file cmaterial.h.

220 { m_default_nrsamples_reflections = aNrReflections; }
static int m_default_nrsamples_reflections
Definition: cmaterial.h:227

References CMATERIAL::m_default_nrsamples_reflections.

Referenced by C3D_RENDER_RAYTRACING::setupMaterials().

◆ SetDefaultNrRefractionsSamples()

static void CMATERIAL::SetDefaultNrRefractionsSamples ( unsigned int  aNrRefractions)
inlinestaticinherited

Definition at line 219 of file cmaterial.h.

219 { m_default_nrsamples_refractions = aNrRefractions; }
static int m_default_nrsamples_refractions
Definition: cmaterial.h:226

References CMATERIAL::m_default_nrsamples_refractions.

Referenced by C3D_RENDER_RAYTRACING::setupMaterials().

◆ SetDefaultReflectionsLevel()

static void CMATERIAL::SetDefaultReflectionsLevel ( unsigned int  aReflectionLevel)
inlinestaticinherited

Definition at line 223 of file cmaterial.h.

223 { m_default_reflections_recursive_levels = aReflectionLevel; }
static int m_default_reflections_recursive_levels
Definition: cmaterial.h:229

References CMATERIAL::m_default_reflections_recursive_levels.

Referenced by C3D_RENDER_RAYTRACING::setupMaterials().

◆ SetDefaultRefractionsLevel()

static void CMATERIAL::SetDefaultRefractionsLevel ( unsigned int  aRefractionLevel)
inlinestaticinherited

Definition at line 222 of file cmaterial.h.

222 { m_default_refractions_recursive_levels = aRefractionLevel; }
static int m_default_refractions_recursive_levels
Definition: cmaterial.h:228

References CMATERIAL::m_default_refractions_recursive_levels.

Referenced by C3D_RENDER_RAYTRACING::setupMaterials().

◆ SetNormalPerturbator()

void CMATERIAL::SetNormalPerturbator ( const CPROCEDURALGENERATOR aPerturbator)
inlineinherited

Definition at line 288 of file cmaterial.h.

288 { m_normal_perturbator = aPerturbator; }
const CPROCEDURALGENERATOR * m_normal_perturbator
Definition: cmaterial.h:312

References CMATERIAL::m_normal_perturbator.

Referenced by C3D_RENDER_RAYTRACING::add_3D_models().

◆ SetNrReflectionsSamples()

void CMATERIAL::SetNrReflectionsSamples ( unsigned int  aNrReflections)
inlineinherited

Definition at line 257 of file cmaterial.h.

257 { m_reflections_nr_samples = aNrReflections; }
unsigned int m_reflections_nr_samples
nr of rays that will be interpolated for this material if it is reflective
Definition: cmaterial.h:308

References CMATERIAL::m_reflections_nr_samples.

◆ SetNrRefractionsSamples()

void CMATERIAL::SetNrRefractionsSamples ( unsigned int  aNrRefractions)
inlineinherited

Definition at line 256 of file cmaterial.h.

256 { m_refraction_nr_samples = aNrRefractions; }
unsigned int m_refraction_nr_samples
nr of rays that will be interpolated for this material if it is a transparent
Definition: cmaterial.h:307

References CMATERIAL::m_refraction_nr_samples.

◆ SetReflectionsRecursiveLevel()

void CMATERIAL::SetReflectionsRecursiveLevel ( unsigned int  aReflectionsLevel)
inlineinherited

Definition at line 258 of file cmaterial.h.

258 { m_reflections_recursive_levels = aReflectionsLevel; }
unsigned int m_reflections_recursive_levels
nr of levels it allows for reflection recursiveness
Definition: cmaterial.h:310

References CMATERIAL::m_reflections_recursive_levels.

◆ SetRefractionsRecursiveLevel()

void CMATERIAL::SetRefractionsRecursiveLevel ( unsigned int  aRefractionsLevel)
inlineinherited

Definition at line 259 of file cmaterial.h.

259 { m_refractions_recursive_levels = aRefractionsLevel; }
unsigned int m_refractions_recursive_levels
nr of levels it allows for refractions recursiveness
Definition: cmaterial.h:309

References CMATERIAL::m_refractions_recursive_levels.

◆ Shade()

SFVEC3F CBLINN_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 - Shades 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 CMATERIAL.

Definition at line 110 of file cmaterial.cpp.

117 {
118  wxASSERT( NdotL >= FLT_EPSILON );
119 
120  // This is a hack to get some kind of fake ambient illumination
121  // There is no logic behind this, just pure artistic experimentation
122  //const float ambientFactor = glm::max( ( (1.0f - NdotL) /** (1.0f - NdotL)*/ ) *
123  // ( AMBIENT_FACTOR + AMBIENT_FACTOR ),
124  // AMBIENT_FACTOR );
125 
126  if( aShadowAttenuationFactor > FLT_EPSILON )
127  {
128  // Calculate the diffuse light factoring in light color,
129  // power and the attenuation
130  const SFVEC3F diffuse = NdotL * aLightColor;
131 
132  // Calculate the half vector between the light vector and the view vector.
133  const SFVEC3F H = glm::normalize( aDirToLight - aRay.m_Dir );
134 
135  //Intensity of the specular light
136  const float NdotH = glm::dot( H, aHitInfo.m_HitNormal );
137  const float intensitySpecular = glm::pow( glm::max( NdotH, 0.0f ),
138  m_shinness );
139 
140  return m_ambientColor +
141  aShadowAttenuationFactor * ( diffuse * aDiffuseObjColor +
143  aLightColor *
144  intensitySpecular *
145  m_specularColor );
146  }
147 
148  return m_ambientColor;
149 }
SFVEC3F m_ambientColor
Definition: cmaterial.h:294
float m_shinness
Definition: cmaterial.h:302
SFVEC3F m_Dir
Definition: ray.h:72
#define H(x, y, z)
Definition: md5_hash.cpp:17
glm::vec3 SFVEC3F
Definition: xv3d_types.h:47
#define SPECULAR_FACTOR
Definition: cmaterial.cpp:42
SFVEC3F m_HitNormal
(12) normal at the hit point
Definition: hitinfo.h:42
SFVEC3F m_specularColor
Definition: cmaterial.h:301

References H, CMATERIAL::m_ambientColor, RAY::m_Dir, HITINFO::m_HitNormal, CMATERIAL::m_shinness, CMATERIAL::m_specularColor, and SPECULAR_FACTOR.

Member Data Documentation

◆ m_absorbance

float CMATERIAL::m_absorbance
protectedinherited

absorvance factor for the transparent material

Definition at line 304 of file cmaterial.h.

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

◆ m_ambientColor

SFVEC3F CMATERIAL::m_ambientColor
protectedinherited

Definition at line 294 of file cmaterial.h.

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

◆ m_cast_shadows

bool CMATERIAL::m_cast_shadows
protectedinherited

true if this object will block the light

Definition at line 306 of file cmaterial.h.

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

◆ m_emissiveColor

SFVEC3F CMATERIAL::m_emissiveColor
protectedinherited

Definition at line 300 of file cmaterial.h.

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

◆ m_normal_perturbator

const CPROCEDURALGENERATOR* CMATERIAL::m_normal_perturbator
protectedinherited

◆ m_reflection

float CMATERIAL::m_reflection
protectedinherited

1.0 completely reflective, 0.0 no reflective

Definition at line 305 of file cmaterial.h.

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

◆ m_reflections_nr_samples

unsigned int CMATERIAL::m_reflections_nr_samples
protectedinherited

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

Definition at line 308 of file cmaterial.h.

Referenced by CMATERIAL::CMATERIAL(), CMATERIAL::GetNrReflectionsSamples(), and CMATERIAL::SetNrReflectionsSamples().

◆ m_reflections_recursive_levels

unsigned int CMATERIAL::m_reflections_recursive_levels
protectedinherited

nr of levels it allows for reflection recursiveness

Definition at line 310 of file cmaterial.h.

Referenced by CMATERIAL::CMATERIAL(), CMATERIAL::GetReflectionsRecursiveLevel(), and CMATERIAL::SetReflectionsRecursiveLevel().

◆ m_refraction_nr_samples

unsigned int CMATERIAL::m_refraction_nr_samples
protectedinherited

nr of rays that will be interpolated for this material if it is a transparent

Definition at line 307 of file cmaterial.h.

Referenced by CMATERIAL::CMATERIAL(), CMATERIAL::GetNrRefractionsSamples(), and CMATERIAL::SetNrRefractionsSamples().

◆ m_refractions_recursive_levels

unsigned int CMATERIAL::m_refractions_recursive_levels
protectedinherited

nr of levels it allows for refractions recursiveness

Definition at line 309 of file cmaterial.h.

Referenced by CMATERIAL::CMATERIAL(), CMATERIAL::GetRefractionsRecursiveLevel(), and CMATERIAL::SetRefractionsRecursiveLevel().

◆ m_shinness

float CMATERIAL::m_shinness
protectedinherited

Definition at line 302 of file cmaterial.h.

Referenced by CMATERIAL::CMATERIAL(), CMATERIAL::GetShinness(), and Shade().

◆ m_specularColor

SFVEC3F CMATERIAL::m_specularColor
protectedinherited

Definition at line 301 of file cmaterial.h.

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

◆ m_transparency

float CMATERIAL::m_transparency
protectedinherited

1.0 is completely transparent, 0.0 completely opaque

Definition at line 303 of file cmaterial.h.

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


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