102 float slope_x, slope_y;
103 float cos_phi_i = 1.0f;
104 float sin_phi_i = 0.0f;
106 if (wi_.
z >= 0.99999f) {
110 slope_x = r *
cosf(phi);
111 slope_y = r *
sinf(phi);
115 const float cos_theta_i = wi_.
z;
117 const float tan_theta_i = sin_theta_i / cos_theta_i;
118 const float cot_theta_i = 1.0f / tan_theta_i;
119 const float erf_a =
fast_erff(cot_theta_i);
120 const float exp_a2 =
expf(-cot_theta_i * cot_theta_i);
121 const float SQRT_PI_INV = 0.56418958354f;
123 float invlen = 1.0f / sin_theta_i;
124 cos_phi_i = wi_.
x * invlen;
125 sin_phi_i = wi_.
y * invlen;
142 const float K = tan_theta_i * SQRT_PI_INV;
143 const float y_approx = rand.
x * (1.0f + erf_a +
K * (1 - erf_a * erf_a));
144 const float y_exact = rand.
x * (1.0f + erf_a +
K * exp_a2);
145 float b =
K > 0 ? (0.5f -
sqrtf(
K * (
K - y_approx + 1.0f) + 0.25f)) /
K : y_approx - 1.0f;
155 const float precision = 1e-6f;
156 const int max_iter = 3;
158 while (
fabsf(current.
y) > precision && iter++ < max_iter) {
166 const float newton_x = current.
x - current.
y / (1.0f - inv_erf * tan_theta_i);
167 current.
x = (newton_x >= begin.
x && newton_x <= end.
x) ? newton_x : 0.5f * (begin.
x + end.
x);
169 current.
y = 1.0f + current.
x +
K *
expf(-
sqr(inv_erf)) - y_exact;
177 float tmp = cos_phi_i * slope_x - sin_phi_i * slope_y;
178 slope_y = sin_phi_i * slope_x + cos_phi_i * slope_y;
182 slope_x = alpha_x * slope_x;
183 slope_y = alpha_y * slope_y;
202 float lensq =
sqr(wi_.
x) +
sqr(wi_.
y);
231 const float cos_theta_i,
238 const bool has_transmission =
CLOSURE_IS_GLASS(bsdf->type) || !has_reflection;
249 *r_reflectance =
F * fresnel->reflection_tint;
250 *r_transmittance = (1.0f -
F) * fresnel->transmission_tint;
262 const float mu =
saturatef(1.0f - cos_theta_i);
263 const float mu5 =
sqr(
sqr(mu)) * mu;
265 *r_reflectance =
saturate(F_schlick - fresnel->b * cos_theta_i * mu5 * mu);
272 if (fresnel->thin_film.thickness > 0.1f) {
279 fresnel->thin_film.ior,
282 fresnel->thin_film.thickness,
299 else if (fresnel->exponent < 0.0f) {
305 F =
mix(fresnel->f0, fresnel->f90, s);
309 const float cos_theta_t_sq = 1.0f - (1.0f -
sqr(cos_theta_i)) /
sqr(bsdf->ior);
310 if (cos_theta_t_sq <= 0.0f) {
312 *r_reflectance = fresnel->reflection_tint * (
float)has_reflection;
316 const float cos_theta_t =
sqrtf(cos_theta_t_sq);
318 *r_cos_theta_t = cos_theta_t;
323 const float fresnel_angle = ((bsdf->ior < 1.0f) ? cos_theta_t : cos_theta_i);
324 const float s =
powf(1.0f - fresnel_angle, fresnel->exponent);
325 F =
mix(fresnel->f0, fresnel->f90, s);
327 *r_reflectance =
F * fresnel->reflection_tint;
328 *r_transmittance = (
one_spectrum() -
F) * fresnel->transmission_tint;
336 if (has_transmission &&
fresnel_dielectric(cos_theta_i, bsdf->ior, r_cos_theta_t) == 1.0f) {
341 *r_reflectance *= (
float)has_reflection;
342 *r_transmittance *= (
float)has_transmission;
350 const float mu =
dot(sd->wi, bsdf->N);
351 const float rough =
sqrtf(
sqrtf(bsdf->alpha_x * bsdf->alpha_y));
361 float ior = bsdf->ior;
368 float z =
sqrtf(
fabsf((ior - 1.0f) / (ior + 1.0f)));
378 const float missing_factor = ((1.0f - E) / E);
379 bsdf->energy_scale = 1.0f + missing_factor;
392 bsdf->weight *= darkening;
393 bsdf->sample_weight *=
average(darkening);
411 const bool eval_reflection,
412 const bool eval_transmission)
414 const float cos_NI =
dot(sd->wi, bsdf->N);
415 Spectrum reflectance, transmittance;
418 reflectance *= (
float)eval_reflection;
419 transmittance *= (
float)eval_transmission;
426 if (fresnel->thin_film.thickness > 0.1f) {
431 float rough =
sqrtf(
sqrtf(bsdf->alpha_x * bsdf->alpha_y));
433 if (fresnel->exponent < 0.0f) {
434 float z =
sqrtf(
fabsf((bsdf->ior - 1.0f) / (bsdf->ior + 1.0f)));
436 kg, rough, cos_NI,
z,
kernel_data.tables.ggx_gen_schlick_ior_s, 16, 16, 16);
439 float z = 1.0f / (0.2f * fresnel->exponent + 1.0f);
441 kg, rough, cos_NI,
z,
kernel_data.tables.ggx_gen_schlick_s, 16, 16, 16);
443 reflectance =
mix(fresnel->f0, fresnel->f90, s) * fresnel->reflection_tint;
448 float rough =
sqrtf(
sqrtf(bsdf->alpha_x * bsdf->alpha_y));
450 kg, rough, cos_NI, 0.5f,
kernel_data.tables.ggx_gen_schlick_s, 16, 16, 16);
455 return reflectance + transmittance;
463template<MicrofacetType m_type>
468 return 0.5f * (
sqrtf(1.0f + sqr_alpha_tan_n) - 1.0f);
473 if (sqr_alpha_tan_n < 0.39f) {
479 return ((0.396f * a - 1.259f) * a + 1.0f) / ((2.181f * a + 3.535f) * a);
488template<MicrofacetType m_type>
491 const float sqr_alpha_tan_n = (
sqr(alpha_x *
V.x) +
sqr(alpha_y *
V.y)) /
sqr(
V.z);
502template<MicrofacetType m_type>
511 const float cos_NH2 =
min(
sqr(cos_NH), 1.0f);
512 const float one_minus_cos_NH2 = 1.0f - cos_NH2;
515 return 1.0f / (
expf(one_minus_cos_NH2 / (cos_NH2 * alpha2)) *
M_PI_F * alpha2 *
sqr(cos_NH2));
519 return alpha2 / (
M_PI_F *
sqr(one_minus_cos_NH2 + alpha2 * cos_NH2));
523template<MicrofacetType m_type>
528 const float cos_NH2 =
sqr(
H.z);
529 const float alpha2 = alpha_x * alpha_y;
546template<MicrofacetType m_type>
558 const bool has_transmission =
CLOSURE_IS_GLASS(bsdf->type) || !has_reflection;
561 const float cos_NI =
dot(
N, wi);
562 const float cos_NO =
dot(
N, wo);
563 const float cos_NgO =
dot(Ng, wo);
565 const float alpha_x = bsdf->alpha_x;
566 const float alpha_y = bsdf->alpha_y;
568 const bool is_transmission = (cos_NO < 0.0f);
578 (is_transmission && !has_transmission) || (!is_transmission && !has_reflection))
587 float3 H = is_transmission ? -(bsdf->ior * wo + wi) : (wi + wo);
592 const float cos_HI =
dot(
H, wi);
593 Spectrum reflectance, transmittance;
600 const float cos_NH =
dot(
N,
H);
601 float D, lambdaI, lambdaO;
605 if (alpha_x == alpha_y || is_transmission) {
606 float alpha2 = alpha_x * alpha_y;
625 float common =
D / cos_NI *
626 (is_transmission ?
sqr(bsdf->ior * inv_len_H) *
fabsf(cos_HI *
dot(
H, wo)) :
629 const float pdf_reflect =
average(reflectance) /
average(reflectance + transmittance);
630 const float lobe_pdf = is_transmission ? 1.0f - pdf_reflect : pdf_reflect;
632 *pdf = common * lobe_pdf / (1.0f + lambdaI);
633 return (is_transmission ? transmittance : reflectance) * common / (1.0f + lambdaO + lambdaI);
636template<MicrofacetType m_type>
651 const float cos_NI =
dot(
N, wi);
657 const float m_eta = bsdf->ior;
658 const float m_inv_eta = 1.0f / bsdf->ior;
659 const float alpha_x = bsdf->alpha_x;
660 const float alpha_y = bsdf->alpha_y;
672 if (alpha_x == alpha_y) {
690 H =
X * local_H.
x +
Y * local_H.
y +
N * local_H.
z;
692 const float cos_HI =
dot(
H, wi);
697 Spectrum reflectance, transmittance;
705 const float pdf_reflect =
average(reflectance) /
average(reflectance + transmittance);
706 const bool do_refract = (rand.
z >= pdf_reflect);
709 *wo = do_refract ?
refract_angle(wi,
H, cos_HO, m_inv_eta) : 2.0f * cos_HI *
H - wi;
710 if ((
dot(Ng, *wo) < 0) != do_refract) {
715 *eval = transmittance;
716 *pdf = 1.0f - pdf_reflect;
718 m_singular = m_singular || (
fabsf(m_eta - 1.0f) < 1e-4f);
731 float D, lambdaI, lambdaO;
734 if (alpha_x == alpha_y || do_refract) {
735 float alpha2 = alpha_x * alpha_y;
736 const float cos_NH = local_H.
z;
737 const float cos_NO =
dot(
N, *wo);
744 const float3 local_O = 2.0f * cos_HI * local_H - local_I;
752 const float common =
D / cos_NI *
753 (do_refract ?
fabsf(cos_HI * cos_HO) /
sqr(cos_HO + cos_HI * m_inv_eta) :
756 *pdf *= common / (1.0f + lambdaI);
757 *eval *= common / (1.0f + lambdaI + lambdaO);
760 *sampled_roughness =
make_float2(alpha_x, alpha_y);
761 *eta = do_refract ? m_eta : 1.0f;
774 const bool preserve_energy)
777 bsdf->fresnel = fresnel;
780 if (preserve_energy) {
797 const bool preserve_energy)
800 bsdf->fresnel = fresnel;
803 if (preserve_energy) {
814 const bool preserve_energy)
816 fresnel->f0 =
saturate(fresnel->f0);
818 bsdf->fresnel = fresnel;
821 if (preserve_energy) {
824 if (
is_zero(fresnel->transmission_tint)) {
826 if (fresnel->exponent < 0.0f) {
827 const float eta = bsdf->ior;
835 real_Fss = 0.997118f + eta * (0.1014f - eta * (0.965241f + eta * 0.130607f));
838 real_Fss = (eta - 1.0f) / (4.08567f + 1.00071f * eta);
844 s = 2.0f / ((fresnel->exponent + 3.0f) * fresnel->exponent + 2.0f);
847 Fss = fresnel->reflection_tint *
mix(fresnel->f0, fresnel->f90, s);
852 Fss = fresnel->transmission_tint;
864 const bool preserve_energy)
877 const float f = 6.0f / 7.0f;
878 const float f5 =
sqr(
sqr(f)) * f;
880 fresnel->b = F_schlick * (7.0f / (f5 * f)) * (
one_spectrum() - f82_tint);
884 bsdf->fresnel = fresnel;
887 if (preserve_energy) {
929 bsdf->alpha_x =
saturatef(bsdf->alpha_x);
930 bsdf->alpha_y =
saturatef(bsdf->alpha_y);
933 bsdf->energy_scale = 1.0f;
941 bsdf->alpha_x =
saturatef(bsdf->alpha_x);
942 bsdf->alpha_y = bsdf->alpha_x;
945 bsdf->energy_scale = 1.0f;
953 bsdf->alpha_x =
saturatef(bsdf->alpha_x);
954 bsdf->alpha_y = bsdf->alpha_x;
957 bsdf->energy_scale = 1.0f;
968 bsdf->alpha_y =
fmaxf(roughness, bsdf->alpha_y);
995 kg, sc, Ng, wi, rand, eval, wo, pdf, sampled_roughness, eta);
1007 bsdf->alpha_x =
saturatef(bsdf->alpha_x);
1008 bsdf->alpha_y =
saturatef(bsdf->alpha_y);
1018 bsdf->alpha_x =
saturatef(bsdf->alpha_x);
1019 bsdf->alpha_y = bsdf->alpha_x;
1029 bsdf->alpha_x =
saturatef(bsdf->alpha_x);
1030 bsdf->alpha_y = bsdf->alpha_x;
1060 kg, sc, Ng, wi, rand, eval, wo, pdf, sampled_roughness, eta);
MINLINE float signf(float f)
MINLINE float safe_sqrtf(float a)
MINLINE float safe_divide(float a, float b)
Group Output data from inside of a node group A color picker Mix two input colors RGB to Convert a color s luminance to a grayscale value Generate a normal vector and a dot product Brightness Control the brightness and contrast of the input color Vector Map input vector components with curves Camera Retrieve information about the camera and how it relates to the current shading point s position Clamp a value between a minimum and a maximum Vector Perform vector math operation Invert Invert a color
ccl_device int bsdf_microfacet_sample(KernelGlobals kg, ccl_private const ShaderClosure *sc, float3 Ng, float3 wi, const float3 rand, ccl_private Spectrum *eval, ccl_private float3 *wo, ccl_private float *pdf, ccl_private float2 *sampled_roughness, ccl_private float *eta)
ccl_device_forceinline float3 microfacet_beckmann_sample_vndf(const float3 wi, const float alpha_x, const float alpha_y, const float2 rand)
ccl_device_inline float bsdf_lambda(float alpha2, float cos_N)
ccl_device Spectrum bsdf_microfacet_ggx_eval(KernelGlobals kg, ccl_private const ShaderClosure *sc, const float3 Ng, const float3 wi, const float3 wo, ccl_private float *pdf)
ccl_device_forceinline float3 microfacet_ggx_sample_vndf(const float3 wi, const float alpha_x, const float alpha_y, const float2 rand)
ccl_device void bsdf_microfacet_setup_fresnel_dielectric_tint(KernelGlobals kg, ccl_private MicrofacetBsdf *bsdf, ccl_private const ShaderData *sd, ccl_private FresnelDielectricTint *fresnel, const bool preserve_energy)
ccl_device int bsdf_microfacet_beckmann_glass_setup(ccl_private MicrofacetBsdf *bsdf)
ccl_device void bsdf_microfacet_setup_fresnel_conductor(KernelGlobals kg, ccl_private MicrofacetBsdf *bsdf, ccl_private const ShaderData *sd, ccl_private FresnelConductor *fresnel, const bool preserve_energy)
ccl_device int bsdf_microfacet_beckmann_setup(ccl_private MicrofacetBsdf *bsdf)
ccl_device_inline float bsdf_D(float alpha2, float cos_NH)
ccl_device_inline float bsdf_aniso_D(float alpha_x, float alpha_y, float3 H)
ccl_device_forceinline int bsdf_microfacet_eval_flag(const ccl_private MicrofacetBsdf *bsdf)
ccl_device int bsdf_microfacet_beckmann_sample(KernelGlobals kg, ccl_private const ShaderClosure *sc, float3 Ng, float3 wi, const float3 rand, ccl_private Spectrum *eval, ccl_private float3 *wo, ccl_private float *pdf, ccl_private float2 *sampled_roughness, ccl_private float *eta)
ccl_device void bsdf_microfacet_setup_fresnel_dielectric(KernelGlobals kg, ccl_private MicrofacetBsdf *bsdf, ccl_private const ShaderData *sd)
ccl_device_inline float bsdf_aniso_lambda(float alpha_x, float alpha_y, float3 V)
ccl_device void bsdf_microfacet_setup_fresnel_generalized_schlick(KernelGlobals kg, ccl_private MicrofacetBsdf *bsdf, ccl_private const ShaderData *sd, ccl_private FresnelGeneralizedSchlick *fresnel, const bool preserve_energy)
ccl_device Spectrum bsdf_microfacet_estimate_albedo(KernelGlobals kg, ccl_private const ShaderData *sd, ccl_private const MicrofacetBsdf *bsdf, const bool eval_reflection, const bool eval_transmission)
ccl_device_inline float bsdf_G(float alpha2, float cos_N)
ccl_device_inline float bsdf_lambda_from_sqr_alpha_tan_n(float sqr_alpha_tan_n)
ccl_device int bsdf_microfacet_beckmann_refraction_setup(ccl_private MicrofacetBsdf *bsdf)
ccl_device int bsdf_microfacet_ggx_sample(KernelGlobals kg, ccl_private const ShaderClosure *sc, float3 Ng, float3 wi, const float3 rand, ccl_private Spectrum *eval, ccl_private float3 *wo, ccl_private float *pdf, ccl_private float2 *sampled_roughness, ccl_private float *eta)
ccl_device int bsdf_microfacet_ggx_glass_setup(ccl_private MicrofacetBsdf *bsdf)
ccl_device int bsdf_microfacet_ggx_setup(ccl_private MicrofacetBsdf *bsdf)
ccl_device void bsdf_microfacet_setup_fresnel_constant(KernelGlobals kg, ccl_private MicrofacetBsdf *bsdf, ccl_private const ShaderData *sd, const Spectrum color)
ccl_device void bsdf_microfacet_blur(ccl_private ShaderClosure *sc, float roughness)
ccl_device_forceinline void microfacet_fresnel(KernelGlobals kg, ccl_private const MicrofacetBsdf *bsdf, const float cos_theta_i, ccl_private float *r_cos_theta_t, ccl_private Spectrum *r_reflectance, ccl_private Spectrum *r_transmittance)
ccl_device Spectrum bsdf_microfacet_beckmann_eval(KernelGlobals kg, ccl_private const ShaderClosure *sc, const float3 Ng, const float3 wi, const float3 wo, ccl_private float *pdf)
ccl_device void bsdf_microfacet_setup_fresnel_f82_tint(KernelGlobals kg, ccl_private MicrofacetBsdf *bsdf, ccl_private const ShaderData *sd, ccl_private FresnelF82Tint *fresnel, const Spectrum f82_tint, const bool preserve_energy)
ccl_device int bsdf_microfacet_ggx_refraction_setup(ccl_private MicrofacetBsdf *bsdf)
ccl_device Spectrum bsdf_microfacet_eval(KernelGlobals kg, ccl_private const ShaderClosure *sc, const float3 Ng, const float3 wi, const float3 wo, ccl_private float *pdf)
ccl_device_inline void microfacet_ggx_preserve_energy(KernelGlobals kg, ccl_private MicrofacetBsdf *bsdf, ccl_private const ShaderData *sd, const Spectrum Fss)
ccl_device float F0_from_ior(float ior)
ccl_device Spectrum fresnel_conductor(float cosi, const Spectrum eta, const Spectrum k)
ccl_device Spectrum fresnel_iridescence(KernelGlobals kg, float eta1, float eta2, float eta3, float cos_theta_1, float thickness, ccl_private float *r_cos_theta_3)
ccl_device_forceinline float fresnel_dielectric(float cos_theta_i, float eta, ccl_private float *r_cos_theta_t)
ccl_device_inline float3 refract_angle(const float3 incident, const float3 normal, const float cos_theta_t, const float inv_eta)
SIMD_FORCE_INLINE const btScalar & z() const
Return the z value.
SIMD_FORCE_INLINE btVector3 & normalize()
Normalize this vector x^2 + y^2 + z^2 = 1.
local_group_size(16, 16) .push_constant(Type b
additional_info("compositor_sum_squared_difference_float_shared") .push_constant(Type output_img float dot(value.rgb, luminance_coefficients)") .define("LOAD(value)"
#define kernel_assert(cond)
const KernelGlobalsCPU *ccl_restrict KernelGlobals
#define ccl_device_forceinline
#define ccl_device_inline
#define CCL_NAMESPACE_END
draw_view in_light_buf[] float
#define CLOSURE_IS_GLASS(type)
#define CLOSURE_IS_REFRACTION(type)
@ CLOSURE_BSDF_MICROFACET_GGX_REFRACTION_ID
@ CLOSURE_BSDF_MICROFACET_GGX_GLASS_ID
@ CLOSURE_BSDF_MICROFACET_GGX_ID
@ CLOSURE_BSDF_MICROFACET_BECKMANN_REFRACTION_ID
@ CLOSURE_BSDF_MICROFACET_BECKMANN_GLASS_ID
@ CLOSURE_BSDF_MICROFACET_BECKMANN_ID
#define BSDF_ROUGHNESS_SQ_THRESH
@ SD_BSDF_HAS_TRANSMISSION
CCL_NAMESPACE_BEGIN ccl_device float lookup_table_read(KernelGlobals kg, float x, int offset, int size)
ccl_device float lookup_table_read_2D(KernelGlobals kg, float x, float y, int offset, int xsize, int ysize)
ccl_device float lookup_table_read_3D(KernelGlobals kg, float x, float y, float z, int offset, int xsize, int ysize, int zsize)
ccl_device_inline float fast_erff(float x)
ccl_device_inline float fast_ierff(float x)
ccl_device_inline float len_squared(const float2 a)
ccl_device_inline bool is_zero(const float2 a)
ccl_device_inline float average(const float2 a)
ccl_device_inline float cross(const float2 a, const float2 b)
ccl_device_inline bool isequal(const float2 a, const float2 b)
CCL_NAMESPACE_BEGIN ccl_device float2 sample_uniform_disk(const float2 rand)
ccl_device void make_orthonormals_tangent(const float3 N, const float3 T, ccl_private float3 *a, ccl_private float3 *b)
Spectrum transmission_tint
FresnelThinFilm thin_film
Spectrum transmission_tint
FresnelThinFilm thin_film
ccl_private void * fresnel
#define FOREACH_SPECTRUM_CHANNEL(counter)
#define GET_SPECTRUM_CHANNEL(v, i)
SPECTRUM_DATA_TYPE Spectrum
ccl_device_inline float inverse_lerp(float a, float b, float x)
ccl_device_inline float sqr(float a)
ccl_device_inline float sin_from_cos(const float c)
ccl_device_inline float inversesqrtf(float f)
ccl_device_inline void make_orthonormals(const float3 N, ccl_private float3 *a, ccl_private float3 *b)
ccl_device_inline float2 float3_to_float2(const float3 a)
CCL_NAMESPACE_BEGIN struct Window V