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
 
void SetAbsorvance (float aAbsorvanceFactor)
 
void SetNrRefractionsSamples (unsigned int aNrRefractions)
 
void SetNrReflectionsSamples (unsigned int aNrReflections)
 
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
 

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...
 
const CPROCEDURALGENERATORm_normal_perturbator
 

Detailed Description

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

Definition at line 278 of file cmaterial.h.

Constructor & Destructor Documentation

◆ CBLINN_PHONG_MATERIAL() [1/2]

CBLINN_PHONG_MATERIAL::CBLINN_PHONG_MATERIAL ( )
inline

Definition at line 281 of file cmaterial.h.

281 : 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 283 of file cmaterial.h.

288  : CMATERIAL( aAmbient,
289  aEmissive,
290  aSpecular,
291  aShinness,
292  aTransparency,
293  aReflection ) {}

Member Function Documentation

◆ GetAbsorvance()

float CMATERIAL::GetAbsorvance ( ) const
inlineinherited

Definition at line 215 of file cmaterial.h.

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

References CMATERIAL::m_absorbance.

Referenced by C3D_RENDER_RAYTRACING::shadeHit().

◆ GetAmbientColor()

const SFVEC3F& CMATERIAL::GetAmbientColor ( ) const
inlineinherited

Definition at line 208 of file cmaterial.h.

208 { return m_ambientColor; }
SFVEC3F m_ambientColor
Definition: cmaterial.h:256

References CMATERIAL::m_ambientColor.

Referenced by C3D_RENDER_RAYTRACING::shadeHit().

◆ GetCastShadows()

bool CMATERIAL::GetCastShadows ( ) const
inlineinherited

Definition at line 229 of file cmaterial.h.

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

References CMATERIAL::m_cast_shadows.

Referenced by CBVH_PBRT::IntersectP().

◆ GetEmissiveColor()

const SFVEC3F& CMATERIAL::GetEmissiveColor ( ) const
inlineinherited

Definition at line 209 of file cmaterial.h.

209 { return m_emissiveColor; }
SFVEC3F m_emissiveColor
Definition: cmaterial.h:262

References CMATERIAL::m_emissiveColor.

Referenced by C3D_RENDER_RAYTRACING::shadeHit().

◆ GetNormalPerturbator()

const CPROCEDURALGENERATOR* CMATERIAL::GetNormalPerturbator ( ) const
inlineinherited

Definition at line 251 of file cmaterial.h.

251 { return m_normal_perturbator; }
const CPROCEDURALGENERATOR * m_normal_perturbator
Definition: cmaterial.h:272

References CMATERIAL::m_normal_perturbator.

◆ GetNrReflectionsSamples()

unsigned int CMATERIAL::GetNrReflectionsSamples ( ) const
inlineinherited

Definition at line 217 of file cmaterial.h.

217 { 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:270

References CMATERIAL::m_reflections_nr_samples.

Referenced by C3D_RENDER_RAYTRACING::shadeHit().

◆ GetNrRefractionsSamples()

unsigned int CMATERIAL::GetNrRefractionsSamples ( ) const
inlineinherited

Definition at line 216 of file cmaterial.h.

216 { 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:269

References CMATERIAL::m_refraction_nr_samples.

Referenced by C3D_RENDER_RAYTRACING::shadeHit().

◆ GetReflection()

float CMATERIAL::GetReflection ( ) const
inlineinherited

Definition at line 214 of file cmaterial.h.

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

References CMATERIAL::m_reflection.

Referenced by C3D_RENDER_RAYTRACING::shadeHit().

◆ GetShinness()

float CMATERIAL::GetShinness ( ) const
inlineinherited

Definition at line 212 of file cmaterial.h.

212 { return m_shinness; }
float m_shinness
Definition: cmaterial.h:264

References CMATERIAL::m_shinness.

◆ GetSpecularColor()

const SFVEC3F& CMATERIAL::GetSpecularColor ( ) const
inlineinherited

Definition at line 210 of file cmaterial.h.

210 { return m_specularColor; }
SFVEC3F m_specularColor
Definition: cmaterial.h:263

References CMATERIAL::m_specularColor.

Referenced by C3D_RENDER_RAYTRACING::shadeHit().

◆ GetTransparency()

float CMATERIAL::GetTransparency ( ) const
inlineinherited

Definition at line 213 of file cmaterial.h.

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

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 88 of file cmaterial.cpp.

91 {
93  {
94  aNormal = aNormal + m_normal_perturbator->Generate( aRay, aHitInfo );
95  aNormal = glm::normalize( aNormal );
96  }
97 }
const CPROCEDURALGENERATOR * m_normal_perturbator
Definition: cmaterial.h:272
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 219 of file cmaterial.h.

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

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 227 of file cmaterial.h.

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

References CMATERIAL::m_cast_shadows.

◆ SetNormalPerturbator()

void CMATERIAL::SetNormalPerturbator ( const CPROCEDURALGENERATOR aPerturbator)
inlineinherited

Definition at line 250 of file cmaterial.h.

250 { m_normal_perturbator = aPerturbator; }
const CPROCEDURALGENERATOR * m_normal_perturbator
Definition: cmaterial.h:272

References CMATERIAL::m_normal_perturbator.

Referenced by C3D_RENDER_RAYTRACING::add_3D_models().

◆ SetNrReflectionsSamples()

void CMATERIAL::SetNrReflectionsSamples ( unsigned int  aNrReflections)
inlineinherited

Definition at line 221 of file cmaterial.h.

221 { 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:270

References CMATERIAL::m_reflections_nr_samples.

◆ SetNrRefractionsSamples()

void CMATERIAL::SetNrRefractionsSamples ( unsigned int  aNrRefractions)
inlineinherited

Definition at line 220 of file cmaterial.h.

220 { 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:269

References CMATERIAL::m_refraction_nr_samples.

◆ 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 101 of file cmaterial.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  //const float ambientFactor = glm::max( ( (1.0f - NdotL) /** (1.0f - NdotL)*/ ) *
114  // ( AMBIENT_FACTOR + AMBIENT_FACTOR ),
115  // AMBIENT_FACTOR );
116 
117  if( aShadowAttenuationFactor > FLT_EPSILON )
118  {
119  // Calculate the diffuse light factoring in light color,
120  // power and the attenuation
121  const SFVEC3F diffuse = NdotL * aLightColor;
122 
123  // Calculate the half vector between the light vector and the view vector.
124  const SFVEC3F H = glm::normalize( aDirToLight - aRay.m_Dir );
125 
126  //Intensity of the specular light
127  const float NdotH = glm::dot( H, aHitInfo.m_HitNormal );
128  const float intensitySpecular = glm::pow( glm::max( NdotH, 0.0f ),
129  m_shinness );
130 
131  return m_ambientColor +
132  aShadowAttenuationFactor * ( diffuse * aDiffuseObjColor +
134  aLightColor *
135  intensitySpecular *
136  m_specularColor );
137  }
138 
139  return m_ambientColor;
140 }
SFVEC3F m_ambientColor
Definition: cmaterial.h:256
float m_shinness
Definition: cmaterial.h:264
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:37
SFVEC3F m_HitNormal
(12) normal at the hit point
Definition: hitinfo.h:42
SFVEC3F m_specularColor
Definition: cmaterial.h:263

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 266 of file cmaterial.h.

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

◆ m_ambientColor

SFVEC3F CMATERIAL::m_ambientColor
protectedinherited

Definition at line 256 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 268 of file cmaterial.h.

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

◆ m_emissiveColor

SFVEC3F CMATERIAL::m_emissiveColor
protectedinherited

Definition at line 262 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 267 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 270 of file cmaterial.h.

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

◆ 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 269 of file cmaterial.h.

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

◆ m_shinness

float CMATERIAL::m_shinness
protectedinherited

Definition at line 264 of file cmaterial.h.

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

◆ m_specularColor

SFVEC3F CMATERIAL::m_specularColor
protectedinherited

Definition at line 263 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 265 of file cmaterial.h.

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


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