18 dir = dir.
x * T + dir.
y *
B + dir.
z *
D;
28 if (
fabsf(g) < 1e-3f) {
31 const float fac = 1 + g * (g - 2 *
cos_theta);
41 if (
fabsf(g) >= 1e-3f) {
61 const float a = 2 - 4 * rand.
x;
65 const float cos_theta = 1 / inv_u - inv_u;
81 if (
fabsf(g) < 1e-3f && alpha > 0.999f) {
84 else if (
fabsf(alpha) < 1e-3f) {
88 const float g2 =
sqr(g);
89 const float fac = 1 + g2 - 2 * g *
cos_theta;
91 ((1 + (alpha * (1 + 2 * g2)) * (1 / 3.0f)) * M_4PI_F * fac *
sqrtf(fac));
97 if (
fabsf(g) < 1e-2f) {
100 const float inv_alpha = 1.0f / alpha;
101 const float b_2 = (3 + alpha) * inv_alpha * (0.5f - rand);
103 return 1 / inv_u - inv_u / alpha;
105 const float g2 =
sqr(g), g3 = g * g2, g4 =
sqr(g2), g6 = g2 * g4;
106 const float pgp1_2 =
sqr(1 + g2);
107 const float T1a = alpha * (g4 - 1), T1a3 =
sqr(T1a) * T1a;
108 const float T2 = -1296 * (g2 - 1) * (alpha - alpha * g2) * T1a * (4 * g2 + alpha * pgp1_2);
109 const float T9 = 2 + g2 + g3 * (1 + 2 * g2) * (2 * rand - 1);
110 const float T3 = 3 * g2 * (1 + g * (2 * rand - 1)) + alpha *
T9;
111 const float T4a = 432 * T1a3 +
T2 + 432 * (alpha * (1 - g2)) *
sqr(
T3);
112 const float T10 = alpha * (2 * g4 - g2 - g6);
113 const float T4b = 144 *
T10, T4b3 =
sqr(T4b) * T4b;
114 const float T4 = T4a +
sqrtf(-4 * T4b3 +
sqr(T4a));
116 const float T8 = 48 * M_CBRT2_F *
T10;
117 const float T6 = (2 * T1a +
T8 * inv_T4p3 + 1 / (3 * M_CBRT2_F * inv_T4p3)) / (alpha * (1 - g2));
118 const float T5 = 6 * (1 + g2) +
T6;
119 const float T7 = 6 * (1 + g2) - (8 *
T3) / (alpha * (g2 - 1) *
sqrtf(
T5)) -
T6;
127 if (
fabsf(g) < 1e-3f && alpha > 0.999f) {
130 else if (
fabsf(alpha) < 1e-3f) {
142 float u = 4 * sin_htheta_sqr;
143 return u / (3 *
sqr(n - 1));
150 const float v = -
logf(2 *
B * (d90 - 1) + 1) /
logf(d90);
160 float cos_theta,
float delta,
float pow_delta_v,
float v,
float sin_htheta_sqr,
float pf_coeff)
162 const float m_delta = 1 - delta, m_pow_delta_v = 1 - pow_delta_v;
167 pf =
v * ((
v - 1) - (
v + 1) / sin_htheta_sqr) * (1 / (8 *
M_PI_F));
168 pf +=
v * (
v + 1) *
m_delta * (2 * (
v - 1) - (2 *
v + 1) / sin_htheta_sqr) *
172 pf = (
v *
m_delta - m_pow_delta_v + (delta * m_pow_delta_v -
v *
m_delta) / sin_htheta_sqr) /
185 const float n = coeffs.
x,
v = coeffs.
y;
186 const float pf_coeff = coeffs.
z * (1.0f / (16.0f *
M_PI_F));
187 const float sin_htheta_sqr = 0.5f * (1 -
cos_theta);
195 const float n = coeffs.
x,
v = coeffs.
y;
196 const float cdf_coeff = coeffs.
z * (1.0f / 8.0f);
197 const float pf_coeff = coeffs.
z * (1.0f / (16.0f *
M_PI_F));
200 for (
int it = 0; it < 20; it++) {
201 const float sin_htheta_sqr = 0.5f * (1 -
cos_theta);
203 const float pow_delta_v =
powf(delta,
v);
204 const float m_delta = 1 - delta, m_pow_delta_v = 1 - pow_delta_v;
210 cdf = 1 +
v * (1 - sin_htheta_sqr) * (1 - 0.5f * (
v + 1) *
m_delta);
213 cdf = (1 - pow_delta_v * delta - m_pow_delta_v * sin_htheta_sqr) / (
m_delta * pow_delta_v);
217 cos_theta, delta, pow_delta_v,
v, sin_htheta_sqr, pf_coeff);
220 float new_cos_theta =
cos_theta + M_1_2PI_F * (cdf - rand) /
pf;
223 if (new_cos_theta >= 1.0f) {
226 if (
fabsf(
cos_theta - new_cos_theta) < 1e-6f || new_cos_theta == 1.0f) {
227 return new_cos_theta;
MINLINE float safe_sqrtf(float a)
ATTR_WARN_UNUSED_RESULT const BMVert * v
ccl_device_inline float cos_theta(const float3 w)
ccl_device_inline float sin_theta(const float3 w)
#define ccl_device_inline
#define CCL_NAMESPACE_END
#define pf(_x, _i)
Prefetch 64.
ccl_device_inline float fast_inv_cbrtf(float x)
ccl_device_inline float sqr(float a)
ccl_device_inline float sin_from_cos(const float c)
ccl_device_inline void make_orthonormals(const float3 N, ccl_private float3 *a, ccl_private float3 *b)
ccl_device float phase_henyey_greenstein(float cos_theta, float g)
ccl_device float3 phase_henyey_greenstein_sample(float3 D, float g, float2 rand, ccl_private float *pdf)
ccl_device float phase_fournier_forand_newton(float rand, float3 coeffs)
ccl_device float phase_rayleigh(float cos_theta)
ccl_device float phase_draine(float cos_theta, float g, float alpha)
ccl_device float3 phase_fournier_forand_sample(float3 D, float3 coeffs, float2 rand, ccl_private float *pdf)
ccl_device float3 phase_rayleigh_sample(float3 D, float2 rand, ccl_private float *pdf)
ccl_device float phase_fournier_forand_delta(float n, float sin_htheta_sqr)
ccl_device_inline float3 phase_fournier_forand_coeffs(float B, float IOR)
ccl_device float phase_fournier_forand(float cos_theta, float3 coeffs)
ccl_device float phase_draine_sample_cos(float g, float alpha, float rand)
ccl_device float3 phase_draine_sample(float3 D, float g, float alpha, float2 rand, ccl_private float *pdf)
CCL_NAMESPACE_BEGIN ccl_device float3 phase_sample_direction(float3 D, float cos_theta, float rand)
ccl_device_inline float phase_fournier_forand_impl(float cos_theta, float delta, float pow_delta_v, float v, float sin_htheta_sqr, float pf_coeff)