15 const float phi =
M_2PI_F * rand;
29 if (
fabsf(g) < 1e-3f) {
32 const float fac = 1 + g * (g - 2 *
cos_theta);
42 if (
fabsf(g) >= 1e-3f) {
62 const float a = 2 - 4 * rand.
x;
66 const float cos_theta = 1 / inv_u - inv_u;
82 if (
fabsf(g) < 1e-3f && alpha > 0.999f) {
85 if (
fabsf(alpha) < 1e-3f) {
89 const float g2 =
sqr(g);
90 const float fac = 1 + g2 - 2 * g *
cos_theta;
92 ((1 + (alpha * (1 + 2 * g2)) * (1 / 3.0f)) *
M_4PI_F * fac *
sqrtf(fac));
98 if (
fabsf(g) < 1e-2f) {
101 const float inv_alpha = 1.0f / alpha;
102 const float b_2 = (3 + alpha) * inv_alpha * (0.5f - rand);
104 return 1 / inv_u - inv_u / alpha;
106 const float g2 =
sqr(g);
107 const float g3 = g * g2;
108 const float g4 =
sqr(g2);
109 const float g6 = g2 * g4;
110 const float pgp1_2 =
sqr(1 + g2);
111 const float T1a = alpha * (g4 - 1);
112 const float T1a3 =
sqr(T1a) * T1a;
113 const float T2 = -1296 * (g2 - 1) * (alpha - alpha * g2) * T1a * (4 * g2 + alpha * pgp1_2);
114 const float T9 = 2 + g2 + g3 * (1 + 2 * g2) * (2 * rand - 1);
115 const float T3 = 3 * g2 * (1 + g * (2 * rand - 1)) + alpha *
T9;
116 const float T4a = 432 * T1a3 +
T2 + 432 * (alpha * (1 - g2)) *
sqr(
T3);
117 const float T10 = alpha * (2 * g4 - g2 - g6);
118 const float T4b = 144 *
T10;
119 const float T4b3 =
sqr(T4b) * T4b;
120 const float T4 = T4a +
sqrtf(-4 * T4b3 +
sqr(T4a));
123 const float T6 = (2 * T1a +
T8 * inv_T4p3 + 1 / (3 *
M_CBRT2_F * inv_T4p3)) / (alpha * (1 - g2));
124 const float T5 = 6 * (1 + g2) +
T6;
125 const float T7 = 6 * (1 + g2) - (8 *
T3) / (alpha * (g2 - 1) *
sqrtf(
T5)) -
T6;
133 if (
fabsf(g) < 1e-3f && alpha > 0.999f) {
136 if (
fabsf(alpha) < 1e-3f) {
148 const float u = 4 * sin_htheta_sqr;
149 return u / (3 *
sqr(n - 1));
156 const float v = -
logf(2 *
B * (d90 - 1) + 1) /
logf(d90);
167 const float pow_delta_v,
169 float sin_htheta_sqr,
170 const float pf_coeff)
172 const float m_delta = 1 - delta;
173 const float m_pow_delta_v = 1 - pow_delta_v;
178 pf =
v * ((
v - 1) - (
v + 1) / sin_htheta_sqr) * (1 / (8 *
M_PI_F));
179 pf +=
v * (
v + 1) *
m_delta * (2 * (
v - 1) - (2 *
v + 1) / sin_htheta_sqr) *
183 pf = (
v *
m_delta - m_pow_delta_v + (delta * m_pow_delta_v -
v *
m_delta) / sin_htheta_sqr) /
196 const float n = coeffs.
x;
197 const float v = coeffs.
y;
198 const float pf_coeff = coeffs.
z * (1.0f / (16.0f *
M_PI_F));
199 const float sin_htheta_sqr = 0.5f * (1 -
cos_theta);
207 const float n = coeffs.
x;
208 const float v = coeffs.
y;
209 const float cdf_coeff = coeffs.
z * (1.0f / 8.0f);
210 const float pf_coeff = coeffs.
z * (1.0f / (16.0f *
M_PI_F));
213 for (
int it = 0; it < 20; it++) {
214 const float sin_htheta_sqr = 0.5f * (1 -
cos_theta);
216 const float pow_delta_v =
powf(delta,
v);
217 const float m_delta = 1 - delta;
218 const float m_pow_delta_v = 1 - pow_delta_v;
224 cdf = 1 +
v * (1 - sin_htheta_sqr) * (1 - 0.5f * (
v + 1) *
m_delta);
227 cdf = (1 - pow_delta_v * delta - m_pow_delta_v * sin_htheta_sqr) / (
m_delta * pow_delta_v);
231 cos_theta, delta, pow_delta_v,
v, sin_htheta_sqr, pf_coeff);
237 if (new_cos_theta >= 1.0f) {
240 if (
fabsf(
cos_theta - new_cos_theta) < 1e-6f || new_cos_theta == 1.0f) {
241 return new_cos_theta;
276 *g_HG = 13.8f *
sqr(d);
277 *g_D = 1.1456f * d *
fast_sinf(9.29044f * d);
279 *
w = 0.252977f - 312.983f *
powf(d, 4.3f);
284 *g_HG = 0.862f - 0.143f *
sqr(log_d);
285 const float a = (log_d - 0.238604f) * (log_d + 1.00667f);
286 const float b = 0.507522f - 0.15677f * log_d;
287 const float c = 1.19692f *
fast_cosf(a /
b) + 1.37932f * log_d + 0.0625835f;
288 *g_D = 0.379685f *
fast_cosf(c) + 0.344213f;
290 *
w = 0.146209f *
fast_cosf(3.38707f * log_d + 2.11193f) + 0.316072f + 0.0778917f * log_d;
295 *g_HG = 0.0604931f *
fast_logf(log_d) + 0.940256f;
296 *g_D = 0.500411f - (0.081287f / (-2.0f * log_d +
fast_tanf(log_d) + 1.27551f));
297 *alpha = 7.30354f * log_d + 6.31675f;
299 *
w = 0.026914f * (log_d - temp) + 0.3764f;
303 *g_HG =
fast_expf(-0.0990567f / (d - 1.67154f));
304 *g_D =
fast_expf(-2.20679f / (d + 3.91029f) - 0.428934f);
305 *alpha =
fast_expf(3.62489f - 8.29288f / (d + 5.52825f));
306 *
w =
fast_expf(-0.599085f / (d - 0.641583f) - 0.665888f);
MINLINE float safe_sqrtf(float a)
ATTR_WARN_UNUSED_RESULT const BMVert * v
ccl_device_inline float cos_theta(const float3 w)
SIMD_FORCE_INLINE const btScalar & w() const
Return the w value.
ccl_device float3 spherical_cos_to_direction(const float cos_theta, const float phi)
ccl_device_inline T to_global(const float2 p, const T X, const T Y)
#define ccl_device_inline
#define CCL_NAMESPACE_END
#define pf(_x, _i)
Prefetch 64.
ccl_device float fast_tanf(float x)
ccl_device_inline float fast_expf(const float x)
ccl_device float fast_sinf(float x)
ccl_device float fast_cosf(float x)
ccl_device_inline float fast_inv_cbrtf(const float x)
ccl_device_inline float fast_logf(const float x)
ccl_device_inline void make_orthonormals(const float3 N, ccl_private float3 *a, ccl_private float3 *b)
ccl_device_inline float phase_fournier_forand_impl(float cos_theta, const float delta, const float pow_delta_v, const float v, float sin_htheta_sqr, const float pf_coeff)
ccl_device float phase_draine(const float cos_theta, const float g, float alpha)
ccl_device float3 phase_draine_sample(const float3 D, const float g, float alpha, const float2 rand, ccl_private float *pdf)
ccl_device float3 phase_henyey_greenstein_sample(const float3 D, const float g, const float2 rand, ccl_private float *pdf)
ccl_device_inline float3 phase_fournier_forand_coeffs(const float B, const float IOR)
ccl_device float phase_fournier_forand_newton(const float rand, const float3 coeffs)
ccl_device float3 phase_rayleigh_sample(const float3 D, const float2 rand, ccl_private float *pdf)
ccl_device float phase_henyey_greenstein(const float cos_theta, const float g)
ccl_device void phase_mie_fitted_parameters(float d, ccl_private float *g_HG, ccl_private float *g_D, ccl_private float *alpha, ccl_private float *w)
ccl_device float phase_draine_sample_cos(const float g, const float alpha, const float rand)
ccl_device float phase_fournier_forand_delta(const float n, const float sin_htheta_sqr)
CCL_NAMESPACE_BEGIN ccl_device float3 phase_sample_direction(const float3 D, const float cos_theta, const float rand)
ccl_device float3 phase_fournier_forand_sample(const float3 D, const float3 coeffs, const float2 rand, ccl_private float *pdf)
ccl_device float phase_rayleigh(const float cos_theta)
ccl_device float phase_fournier_forand(const float cos_theta, const float3 coeffs)