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

Constructor & Destructor Documentation

CBLINN_PHONG_MATERIAL::CBLINN_PHONG_MATERIAL ( )
inline

Definition at line 251 of file cmaterial.h.

251 : CMATERIAL() {}
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 253 of file cmaterial.h.

258  : CMATERIAL( aAmbient,
259  aEmissive,
260  aSpecular,
261  aShinness,
262  aTransparency,
263  aReflection ) {}

Member Function Documentation

float CMATERIAL::GetAbsorvance ( ) const
inlineinherited

Definition at line 185 of file cmaterial.h.

References CMATERIAL::m_absorbance.

Referenced by C3D_RENDER_RAYTRACING::shadeHit().

185 { return m_absorbance; }
float m_absorbance
absorvance factor for the transparent material
Definition: cmaterial.h:236
const SFVEC3F& CMATERIAL::GetAmbientColor ( ) const
inlineinherited

Definition at line 178 of file cmaterial.h.

References CMATERIAL::m_ambientColor.

Referenced by C3D_RENDER_RAYTRACING::shadeHit().

178 { return m_ambientColor; }
SFVEC3F m_ambientColor
Definition: cmaterial.h:226
bool CMATERIAL::GetCastShadows ( ) const
inlineinherited

Definition at line 199 of file cmaterial.h.

References CMATERIAL::m_cast_shadows.

Referenced by CBVH_PBRT::IntersectP().

199 { return m_cast_shadows; }
bool m_cast_shadows
true if this object will block the light
Definition: cmaterial.h:238
const SFVEC3F& CMATERIAL::GetEmissiveColor ( ) const
inlineinherited

Definition at line 179 of file cmaterial.h.

References CMATERIAL::m_emissiveColor.

Referenced by C3D_RENDER_RAYTRACING::shadeHit().

179 { return m_emissiveColor; }
SFVEC3F m_emissiveColor
Definition: cmaterial.h:232
const CPROCEDURALGENERATOR* CMATERIAL::GetNormalPerturbator ( ) const
inlineinherited

Definition at line 221 of file cmaterial.h.

References CMATERIAL::m_normal_perturbator.

221 { return m_normal_perturbator; }
const CPROCEDURALGENERATOR * m_normal_perturbator
Definition: cmaterial.h:242
unsigned int CMATERIAL::GetNrReflectionsSamples ( ) const
inlineinherited

Definition at line 187 of file cmaterial.h.

References CMATERIAL::m_reflections_nr_samples.

Referenced by C3D_RENDER_RAYTRACING::shadeHit().

187 { 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:240
unsigned int CMATERIAL::GetNrRefractionsSamples ( ) const
inlineinherited

Definition at line 186 of file cmaterial.h.

References CMATERIAL::m_refraction_nr_samples.

Referenced by C3D_RENDER_RAYTRACING::shadeHit().

186 { 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:239
float CMATERIAL::GetReflection ( ) const
inlineinherited

Definition at line 184 of file cmaterial.h.

References CMATERIAL::m_reflection.

Referenced by C3D_RENDER_RAYTRACING::shadeHit().

184 { return m_reflection; }
float m_reflection
1.0 completely reflective, 0.0 no reflective
Definition: cmaterial.h:237
float CMATERIAL::GetShinness ( ) const
inlineinherited

Definition at line 182 of file cmaterial.h.

References CMATERIAL::m_shinness.

182 { return m_shinness; }
float m_shinness
Definition: cmaterial.h:234
const SFVEC3F& CMATERIAL::GetSpecularColor ( ) const
inlineinherited

Definition at line 180 of file cmaterial.h.

References CMATERIAL::m_specularColor.

Referenced by C3D_RENDER_RAYTRACING::shadeHit().

180 { return m_specularColor; }
SFVEC3F m_specularColor
Definition: cmaterial.h:233
float CMATERIAL::GetTransparency ( ) const
inlineinherited

Definition at line 183 of file cmaterial.h.

References CMATERIAL::m_transparency.

Referenced by C3D_RENDER_RAYTRACING::shadeHit().

183 { return m_transparency; }
float m_transparency
1.0 is completely transparent, 0.0 completely opaque
Definition: cmaterial.h:235
void CMATERIAL::PerturbeNormal ( SFVEC3F aNormal,
const RAY aRay,
const HITINFO aHitInfo 
) const
inherited

Definition at line 88 of file cmaterial.cpp.

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

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

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:242
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...
void CMATERIAL::SetAbsorvance ( float  aAbsorvanceFactor)
inlineinherited

Definition at line 189 of file cmaterial.h.

References CMATERIAL::m_absorbance.

189 { m_absorbance = aAbsorvanceFactor; }
float m_absorbance
absorvance factor for the transparent material
Definition: cmaterial.h:236
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 197 of file cmaterial.h.

References CMATERIAL::m_cast_shadows.

197 { m_cast_shadows = aCastShadows; }
bool m_cast_shadows
true if this object will block the light
Definition: cmaterial.h:238
void CMATERIAL::SetNormalPerturbator ( const CPROCEDURALGENERATOR aPerturbator)
inlineinherited

Definition at line 220 of file cmaterial.h.

References CMATERIAL::m_normal_perturbator.

Referenced by C3D_RENDER_RAYTRACING::add_3D_models().

220 { m_normal_perturbator = aPerturbator; }
const CPROCEDURALGENERATOR * m_normal_perturbator
Definition: cmaterial.h:242
void CMATERIAL::SetNrReflectionsSamples ( unsigned int  aNrReflections)
inlineinherited

Definition at line 191 of file cmaterial.h.

References CMATERIAL::m_reflections_nr_samples.

191 { 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:240
void CMATERIAL::SetNrRefractionsSamples ( unsigned int  aNrRefractions)
inlineinherited

Definition at line 190 of file cmaterial.h.

References CMATERIAL::m_refraction_nr_samples.

190 { 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:239
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.

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

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:226
float m_shinness
Definition: cmaterial.h:234
SFVEC3F m_Dir
Definition: ray.h:48
#define max(a, b)
Definition: auxiliary.h:86
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:233

Member Data Documentation

float CMATERIAL::m_absorbance
protectedinherited

absorvance factor for the transparent material

Definition at line 236 of file cmaterial.h.

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

SFVEC3F CMATERIAL::m_ambientColor
protectedinherited

Definition at line 226 of file cmaterial.h.

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

bool CMATERIAL::m_cast_shadows
protectedinherited

true if this object will block the light

Definition at line 238 of file cmaterial.h.

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

SFVEC3F CMATERIAL::m_emissiveColor
protectedinherited

Definition at line 232 of file cmaterial.h.

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

const CPROCEDURALGENERATOR* CMATERIAL::m_normal_perturbator
protectedinherited
float CMATERIAL::m_reflection
protectedinherited

1.0 completely reflective, 0.0 no reflective

Definition at line 237 of file cmaterial.h.

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

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

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

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

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

float CMATERIAL::m_shinness
protectedinherited

Definition at line 234 of file cmaterial.h.

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

SFVEC3F CMATERIAL::m_specularColor
protectedinherited

Definition at line 233 of file cmaterial.h.

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

float CMATERIAL::m_transparency
protectedinherited

1.0 is completely transparent, 0.0 completely opaque

Definition at line 235 of file cmaterial.h.

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


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