45 float sinInc = glm::sin( aInclination );
47 return SFVEC3F( sinInc * glm::cos( aAzimuth ), sinInc * glm::sin( aAzimuth ),
48 glm::cos( aInclination ) );
71 const float Xi1 = (float) rand() / (float) RAND_MAX;
72 const float Xi2 = (float) rand() / (float) RAND_MAX;
74 const float theta = acos( sqrt( 1.0f - Xi1 ) );
75 const float phi = 2.0f * glm::pi<float>() * Xi2;
77 const float xs = sinf( theta ) * cosf( phi );
78 const float ys = cosf( theta );
79 const float zs = sinf( theta ) * sinf( phi );
81 const SFVEC3F y( n.x, n.y, n.z );
84 if( fabs( h.x ) <= fabs( h.y ) && fabs( h.x ) <= fabs( h.z ) )
86 else if( fabs( h.y ) <= fabs( h.x ) && fabs( h.y ) <= fabs( h.z ) )
92 const SFVEC3F x = glm::normalize( glm::cross( h, y ) );
93 const SFVEC3F z = glm::normalize( glm::cross( x, y ) );
95 SFVEC3F direction = xs * x + ys * y + zs * z;
96 return glm::normalize( direction );
115 float cosThetaI = -glm::dot( aNormal, aInVector );
116 float sin2ThetaI = glm::max( 0.0f, 1.0f - cosThetaI * cosThetaI );
117 float sin2ThetaT = aRin_over_Rout * aRin_over_Rout * sin2ThetaI;
120 if( sin2ThetaT >= 1.0f )
123 float cosThetaT = sqrtf( 1.0f - sin2ThetaT );
125 aOutVector = glm::normalize( aRin_over_Rout * aInVector +
126 ( aRin_over_Rout * cosThetaI - cosThetaT ) *
133inline float mapf(
float x,
float in_min,
float in_max,
float out_min,
float out_max )
135 x = glm::clamp( x, in_min, in_max );
137 return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
142 return (aColor.r * 0.2126f +
150 const float luminance = glm::min(
151 ( ( (
float) ( (
unsigned int) ( 4.0f *
RGBtoGray( aDiffuseColor ) ) ) + 0.5f ) / 4.0f )
155 const float maxValue = glm::max( glm::max( glm::max( aDiffuseColor.r, aDiffuseColor.g ),
156 aDiffuseColor.b ), FLT_EPSILON );
158 return ( aDiffuseColor /
SFVEC3F( maxValue ) ) * 0.125f + luminance * 0.875f;
173 return -2.0f * ( t * t ) + 1.0f;
181 return t * t * ( 3.0f - 2.0f * t );
Defines math related functions.
float mapf(float x, float in_min, float in_max, float out_min, float out_max)
float RGBtoGray(const SFVEC3F &aColor)
SFVEC3F CosWeightedRandomHemisphereDirection(const SFVEC3F &n)
float BezierBlend(float t)
SFVEC3F MaterialDiffuseToColorCAD(const SFVEC3F &aDiffuseColor)
bool Refract(const SFVEC3F &aInVector, const SFVEC3F &aNormal, float aRin_over_Rout, SFVEC3F &aOutVector)
Based on: https://github.com/mmp/pbrt-v3/blob/master/src/core/reflection.h See also: http://www....
SFVEC3F UniformRandomHemisphereDirection()
float QuadricEasingInOut(float t)
SFVEC3F SphericalToCartesian(float aInclination, float aAzimuth)
https://en.wikipedia.org/wiki/Spherical_coordinate_system