76 float sinInc = glm::sin( aInclination );
78 return SFVEC3F( sinInc * glm::cos( aAzimuth ), sinInc * glm::sin( aAzimuth ),
79 glm::cos( aInclination ) );
102 const float Xi1 = (float) rand() / (float) RAND_MAX;
103 const float Xi2 = (float) rand() / (float) RAND_MAX;
105 const float theta = acos( sqrt( 1.0f - Xi1 ) );
106 const float phi = 2.0f * glm::pi<float>() * Xi2;
108 const float xs = sinf( theta ) * cosf( phi );
109 const float ys = cosf( theta );
110 const float zs = sinf( theta ) * sinf( phi );
112 const SFVEC3F y( n.x, n.y, n.z );
115 if( fabs( h.x ) <= fabs( h.y ) && fabs( h.x ) <= fabs( h.z ) )
117 else if( fabs( h.y ) <= fabs( h.x ) && fabs( h.y ) <= fabs( h.z ) )
123 const SFVEC3F x = glm::normalize( glm::cross( h, y ) );
124 const SFVEC3F z = glm::normalize( glm::cross( x, y ) );
126 SFVEC3F direction = xs * x + ys * y + zs * z;
127 return glm::normalize( direction );
146 float cosThetaI = -glm::dot( aNormal, aInVector );
147 float sin2ThetaI = glm::max( 0.0f, 1.0f - cosThetaI * cosThetaI );
148 float sin2ThetaT = aRin_over_Rout * aRin_over_Rout * sin2ThetaI;
151 if( sin2ThetaT >= 1.0f )
154 float cosThetaT = sqrtf( 1.0f - sin2ThetaT );
156 aOutVector = glm::normalize( aRin_over_Rout * aInVector +
157 ( aRin_over_Rout * cosThetaI - cosThetaT ) *
164inline float mapf(
float x,
float in_min,
float in_max,
float out_min,
float out_max )
166 x = glm::clamp( x, in_min, in_max );
168 return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
173 return (aColor.r * 0.2126f +
181 const float luminance = glm::min(
182 ( ( (
float) ( (
unsigned int) ( 4.0f *
RGBtoGray( aDiffuseColor ) ) ) + 0.5f ) / 4.0f )
186 const float maxValue = glm::max( glm::max( glm::max( aDiffuseColor.r, aDiffuseColor.g ),
187 aDiffuseColor.b ), FLT_EPSILON );
189 return ( aDiffuseColor /
SFVEC3F( maxValue ) ) * 0.125f + luminance * 0.875f;
204 return -2.0f * ( t * t ) + 1.0f;
212 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)
SFVEC3F InterpolateModelRotation(const SFVEC3F &aStart, const SFVEC3F &aEnd, float aT)
Interpolate between two model orientations along the shortest arc.
SFVEC3F CalcModelRotation(const glm::mat3 &aRotation)
Recover the FP_3DMODEL angles that CalcModelMatrix() would turn into aRotation.
glm::mat4 CalcModelMatrix(const SFVEC3F &aOffset, const SFVEC3F &aRotation, const SFVEC3F &aScale)
Build the model-to-footprint transform used by rendering and picking.
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