23 #ifndef __BSDF_HAIR_PRINCIPLED_H__
24 # define __BSDF_HAIR_PRINCIPLED_H__
54 "PrincipledHairBSDF is too large!");
56 "PrincipledHairExtra is too large!");
67 return 2.0f * p * gamma_t - 2.0f * gamma_o + p *
M_PI_F;
86 return v / (s *
sqr(1.0f +
v));
98 return 1.0f / (1.0f +
expf(arg));
106 float val = 1.0f + 0.25f *
x;
107 float pow_x_2i =
sqr(
x);
110 for (
int i = 2; i < 10; i++) {
112 float newval = val + pow_x_2i / (pow_4_i * i_fac_2);
151 float x = -s *
logf(1.0f / (u * (1.0f - 2.0f * cdf_minuspi) + cdf_minuspi) - 1.0f);
157 float phi,
int p,
float s,
float gamma_o,
float gamma_t)
166 float sin_theta_i,
float cos_theta_i,
float sin_theta_o,
float cos_theta_o,
float v)
168 float inv_v = 1.0f /
v;
169 float cos_arg = cos_theta_i * cos_theta_o * inv_v;
170 float sin_arg = sin_theta_i * sin_theta_o * inv_v;
173 float val =
expf(i0 - sin_arg - inv_v + 0.6931f +
logf(0.5f * inv_v));
178 float val = (
expf(-sin_arg) * i0) / (
sinhf(inv_v) * 2.0f *
v);
194 bsdf->
v =
clamp(bsdf->
v, 0.001f, 1.0f);
195 bsdf->
s =
clamp(bsdf->
s, 0.001f, 1.0f);
200 bsdf->
v =
sqr(0.726f * bsdf->
v + 0.812f *
sqr(bsdf->
v) + 3.700f *
pow20(bsdf->
v));
250 float totweight = Ap[0].w + Ap[1].w + Ap[2].w + Ap[3].w;
267 float sin_2alpha = 2.0f * sin_1alpha * cos_1alpha;
268 float cos_2alpha =
sqr(cos_1alpha) -
sqr(sin_1alpha);
269 float sin_4alpha = 2.0f * sin_2alpha * cos_2alpha;
270 float cos_4alpha =
sqr(cos_2alpha) -
sqr(sin_2alpha);
272 angles[0] = sin_theta_i * cos_2alpha + cos_theta_i * sin_2alpha;
273 angles[1] =
fabsf(cos_theta_i * cos_2alpha - sin_theta_i * sin_2alpha);
274 angles[2] = sin_theta_i * cos_1alpha - cos_theta_i * sin_1alpha;
275 angles[3] =
fabsf(cos_theta_i * cos_1alpha + sin_theta_i * sin_1alpha);
276 angles[4] = sin_theta_i * cos_4alpha - cos_theta_i * sin_4alpha;
277 angles[5] =
fabsf(cos_theta_i * cos_4alpha + sin_theta_i * sin_4alpha);
299 float sin_theta_o = wo.
x;
303 float sin_theta_t = sin_theta_o / bsdf->
eta;
310 float sin_gamma_t = sin_gamma_o * cos_theta_o /
sqrtf(
sqr(bsdf->
eta) -
sqr(sin_theta_o));
318 float sin_theta_i = wi.
x;
322 float phi = phi_i - phi_o;
339 F += Ap[1] * Mp * Np;
345 F += Ap[2] * Mp * Np;
351 F += Ap[3] * Mp * Np;
385 float sin_theta_o = wo.
x;
389 float sin_theta_t = sin_theta_o / bsdf->
eta;
396 float sin_gamma_t = sin_gamma_o * cos_theta_o /
sqrtf(
sqr(bsdf->
eta) -
sqr(sin_theta_o));
406 if (u[0].
x < Ap[p].
w) {
420 u[1].
x =
max(u[1].
x, 1e-5f);
421 float fac = 1.0f +
v *
logf(u[1].
x + (1.0f - u[1].
x) *
expf(-2.0f /
v));
422 float sin_theta_i = -fac * sin_theta_o +
429 sin_theta_i = angles[2 * p];
430 cos_theta_i = angles[2 * p + 1];
440 float phi_i = phi_o + phi;
456 F += Ap[1] * Mp * Np;
462 F += Ap[2] * Mp * Np;
468 F += Ap[3] * Mp * Np;
474 *omega_in =
X * sin_theta_i +
Y * cos_theta_i *
cosf(phi_i) +
Z * cos_theta_i *
sinf(phi_i);
476 # ifdef __RAY_DIFFERENTIALS__
478 *domega_in_dx = (2 *
dot(
N, sd->dI.dx)) *
N - sd->dI.dx;
479 *domega_in_dy = (2 *
dot(
N, sd->dI.dy)) *
N - sd->dI.dy;
498 const float azimuthal_roughness)
500 const float x = azimuthal_roughness;
501 return (((((0.245f *
x) + 5.574f) *
x - 10.73f) *
x + 2.532f) *
x - 0.215f) *
x + 5.969f;
515 return sigma * sigma;
519 const float pheomelanin)
521 return eumelanin *
make_float3(0.506f, 0.841f, 1.653f) +
MINLINE float safe_sqrtf(float a)
MINLINE float safe_divide(float a, float b)
MINLINE float safe_asinf(float a)
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint y
ATTR_WARN_UNUSED_RESULT const BMVert * v
ccl_device_inline float logistic_cdf(float x, float s)
CCL_NAMESPACE_BEGIN typedef ccl_addr_space struct PrincipledHairExtra PrincipledHairExtra
ccl_device int bsdf_principled_hair_sample(KernelGlobals *kg, const ShaderClosure *sc, ShaderData *sd, float randu, float randv, float3 *eval, float3 *omega_in, float3 *domega_in_dx, float3 *domega_in_dy, float *pdf)
ccl_device_inline float4 combine_with_energy(KernelGlobals *kg, float3 c)
ccl_device_inline float logistic(float x, float s)
ccl_device_inline float delta_phi(int p, float gamma_o, float gamma_t)
ccl_device void bsdf_principled_hair_blur(ShaderClosure *sc, float roughness)
ccl_device_inline float log_bessel_I0(float x)
ccl_device float3 bsdf_principled_hair_albedo(ShaderClosure *sc)
ccl_device_inline float longitudinal_scattering(float sin_theta_i, float cos_theta_i, float sin_theta_o, float cos_theta_o, float v)
ccl_device_inline float3 bsdf_principled_hair_sigma_from_concentration(const float eumelanin, const float pheomelanin)
ccl_device_inline float bsdf_principled_hair_albedo_roughness_scale(const float azimuthal_roughness)
ccl_device_inline float sample_trimmed_logistic(float u, float s)
ccl_addr_space struct PrincipledHairBSDF PrincipledHairBSDF
ccl_device_inline void hair_alpha_angles(float sin_theta_i, float cos_theta_i, float alpha, float *angles)
ccl_device_inline float wrap_angle(float a)
ccl_device_inline float azimuthal_scattering(float phi, int p, float s, float gamma_o, float gamma_t)
ccl_device_inline float bessel_I0(float x)
ccl_device_inline float trimmed_logistic(float x, float s)
ccl_device float3 bsdf_principled_hair_eval(KernelGlobals *kg, const ShaderData *sd, const ShaderClosure *sc, const float3 omega_in, float *pdf)
ccl_device_inline void hair_attenuation(KernelGlobals *kg, float f, float3 T, float4 *Ap)
ccl_device_inline float3 bsdf_principled_hair_sigma_from_reflectance(const float3 color, const float azimuthal_roughness)
ccl_device_inline float cos_from_sin(const float s)
ccl_device float fresnel_dielectric_cos(float cosi, float eta)
SIMD_FORCE_INLINE const btScalar & w() const
Return the w value.
static CCL_NAMESPACE_BEGIN const double alpha
ccl_device float linear_rgb_to_gray(KernelGlobals *kg, float3 c)
#define kernel_assert(cond)
#define ccl_device_inline
#define CCL_NAMESPACE_END
#define make_float2(x, y)
#define make_float4(x, y, z, w)
#define make_float3(x, y, z)
ccl_device float lcg_step_float_addrspace(ccl_addr_space uint *rng)
@ PRIMITIVE_MOTION_CURVE_RIBBON
static const pxr::TfToken roughness("roughness", pxr::TfToken::Immortal)
unsigned __int64 uint64_t
PrincipledHairExtra * extra
@ CLOSURE_BSDF_HAIR_PRINCIPLED_ID
__forceinline avxf cross(const avxf &a, const avxf &b)
ccl_device_inline float pow22(float a)
ccl_device_inline float pow20(float a)
ccl_device_inline float sqr(float a)
ccl_device_inline float3 safe_divide_color(float3 a, float3 b)
ccl_device_inline bool isfinite_safe(float f)
ccl_device_inline float3 float4_to_float3(const float4 a)
ccl_device_inline int clamp(int a, int mn, int mx)
ccl_device_inline float dot(const float2 &a, const float2 &b)
ccl_device_inline float2 safe_normalize(const float2 &a)
ccl_device_inline float3 exp3(float3 v)
ccl_device_inline float3 log3(float3 v)
ccl_device_inline bool isfinite3_safe(float3 v)