/*! Cosine weighted sphere sampling. Up direction is the z direction. */ inline direction_sample cosineSampleSphere(real u, real v) { const real phi = two_pi<real>() * u; const real vv = 2.0f * (v - 0.5f); const real cosTheta = sign(vv) * sqrt(abs(vv)); const real sinTheta = cos2sin(cosTheta); return direction_sample(directionFromPhiCosThetaSinTheta(phi, cosTheta, sinTheta), 2.0f * cosTheta * one_over_pi<real>()); }
/*! Uniform sampling of spherical cone. Cone direction is the z * direction. */ inline direction_sample uniformSampleCone(real u, real v, real angle) { const real phi = two_pi<real>() * u; const real cosTheta = 1.0f - v * (1.0f - cos(angle)); const real sinTheta = cos2sin(cosTheta); return direction_sample(directionFromPhiCosThetaSinTheta(phi, cosTheta, sinTheta), 1.f / (four_pi<real>() * sqr(sin(0.5f * angle)))); }
/*! Samples hemisphere with power cosine distribution. Up direction * is the z direction. */ inline direction_sample powerCosineSampleHemisphere(real u, real v, real exp) { const real phi = two_pi<real>() * u; const real cosTheta = pow(v, 1.f / (exp + 1)); const real sinTheta = cos2sin(cosTheta); return direction_sample(directionFromPhiCosThetaSinTheta(phi, cosTheta, sinTheta), (exp + 1.0f) * pow(cosTheta, exp) * one_over_two_pi<real>()); }
/*! Samples the distribution. \param s is the sample location * provided by the caller. */ inline Vec3fa AnisotropicBlinn__sample(const AnisotropicBlinn* This, const float sx, const float sy) { const float phi =float(two_pi)*sx; const float sinPhi0 = sqrtf(This->nx+1)*sinf(phi); const float cosPhi0 = sqrtf(This->ny+1)*cosf(phi); const float norm = rsqrt(sqr(sinPhi0)+sqr(cosPhi0)); const float sinPhi = sinPhi0*norm; const float cosPhi = cosPhi0*norm; const float n = This->nx*sqr(cosPhi)+This->ny*sqr(sinPhi); const float cosTheta = powf(sy,rcp(n+1)); const float sinTheta = cos2sin(cosTheta); const float pdf = This->norm1*powf(cosTheta,n); const Vec3fa h = Vec3fa(cosPhi * sinTheta, sinPhi * sinTheta, cosTheta); const Vec3fa wh = h.x*This->dx + h.y*This->dy + h.z*This->dz; return Vec3fa(wh,pdf); }
/*! Uniform hemisphere sampling. Up direction is the z direction. */ inline direction_sample uniformSampleHemisphere(real u, real v) { const real phi = two_pi<real>() * u; const real cosTheta = v, sinTheta = cos2sin(v); return direction_sample(directionFromPhiCosThetaSinTheta(phi, cosTheta, sinTheta), one_over_two_pi<real>()); }
/*! Uniform sphere sampling. */ inline direction_sample uniformSampleSphere(real u, real v) { const auto phi = two_pi<real>() * u; const auto cosTheta = 1 - 2 * v, sinTheta = cos2sin(cosTheta); return direction_sample { directionFromPhiCosThetaSinTheta(phi, cosTheta, sinTheta), one_over_four_pi<real>() }; }