10#include "gpu_shader_codegen_lib.glsl"
24 return a2 / (
M_PI *
square((1.0f - NH2) + a2 * NH2));
29 return 2.0f / (1.0f +
sqrt(1.0f + a2 * (1.0f /
square(NX) - 1.0f)));
62 float2 Vt_alpha = alpha * Vt.xy;
69 float k = (1.0f - a2) * s2 / (s2 + a2 *
square(Vt.
z));
87 pdf =
D / (2.0f * (k * Vt.
z + Vh_norm));
92 pdf =
D * (t - Vt.
z) / (2.0f * len_Vt_alpha_sqr);
105 float NV =
dot(
N,
V);
110 eval.throughput = 0.0f;
123 alpha =
max(1e-3f, alpha);
131 float one_minus_NV2 =
saturate(1.0f - NV2);
132 float s2 =
square(1.0f +
sqrt(one_minus_NV2));
133 float len_ai_sqr = a2 * one_minus_NV2;
134 float t =
sqrt(len_ai_sqr + NV2);
136 float k = (1.0f - a2) * s2 / (s2 + a2 * NV2);
137 eval.pdf = 1.0f / (2.0f * (k * NV + t));
140 eval.pdf = (t - NV) / (2.0f * len_ai_sqr);
143 float NH =
dot(
N,
H);
154 eval.throughput = (0.25f * G_V * G_L) / NV;
155 eval.weight = eval.throughput / eval.pdf;
158 eval.throughput *=
D;
178 G_V = 2.0f * Vh.
z / (1.0f + Vh.
z);
207 if (thickness.
value() != 0.0f) {
227 float VH =
dot(Vt, Ht);
228 float LH =
dot(Lt, Ht);
229 float Ht2 =
square(ior * LH + VH);
230 float pdf =
D * G_V *
abs(VH * LH) *
square(ior) / (Vt.
z * Ht2);
243 if (thickness.
value() != 0.0f) {
247 float LV =
dot(
L,
V);
248 if (do_clamp &&
is_equal(ior, 1.0f, 1e-4f)) {
253 eval.weight = eval.throughput;
257 bool valid = (ior < 1.0f) ? (LV < -ior) : (LV * ior < -1.0f);
261 eval.throughput = 0.0f;
269 H = (ior < 1.0f) ?
H : -
H;
275 float NH =
dot(
N,
H);
276 float NV =
dot(
N,
V);
284 alpha =
max(1e-3f, alpha);
296 eval.pdf = (
D * G_V * VH * LH *
square(ior * inv_len_H)) / NV;
297 eval.throughput = eval.pdf * G_L;
340 float m =
square(roughness);
342 float smoothness = 1.0f - m;
343 float fac = smoothness * (
sqrt(smoothness) + m);
356 float m =
square(roughness);
358 float smoothness = 1.0f - m;
359 float fac = smoothness * (
sqrt(smoothness) + m);
392 if (thickness.
value() != 0.0f) {
393 ClosureRefraction bsdf = to_closure_refraction(cl);
404 if (thickness.
value() != 0.0f) {
405 ClosureRefraction bsdf = to_closure_refraction(cl);
415 ClosureReflection cl,
422 light.
type = LIGHT_SPECULAR;
429 ClosureRefraction cl,
437 if (thickness.
value() != 0.0f) {
446 light.
type = LIGHT_TRANSMISSION;
457 ClosureThinRefraction cl,
464 light.
type = LIGHT_TRANSMISSION;
ccl_device_inline float cos_theta(const float3 w)
ccl_device_inline float sin_theta(const float3 w)
ThicknessIsect shape_intersect(float3 N, float3 L)
BsdfSample bxdf_ggx_sample_refraction(float3 rand, float3 Vt, float alpha, float ior, Thickness thickness, const bool do_clamp)
float bxdf_ggx_perceived_roughness_reflection(float roughness)
float3 bxdf_ggx_dominant_direction_reflection(float3 N, float3 V, float roughness)
float bxdf_ggx_D(float NH, float a2)
LightProbeRay bxdf_ggx_lightprobe_reflection(ClosureReflection cl, float3 V)
LightProbeRay bxdf_ggx_lightprobe_thin_glass_transmission(ClosureThinRefraction cl, float3 V)
float3 bxdf_ggx_sample_vndf(float3 rand, float3 Vt, float alpha, float &G_V)
LightProbeRay bxdf_ggx_lightprobe_transmission(ClosureRefraction cl, float3 V, Thickness thickness)
ClosureLight bxdf_ggx_light_reflection(const UtilityTexture &util_tx, ClosureReflection cl, float3 V)
void bxdf_ggx_context_amend_transmission(ClosureUndetermined &cl, float3 &V, Thickness thickness)
BsdfEval bxdf_ggx_eval_refraction(float3 N, float3 L, float3 V, float alpha, float ior, Thickness thickness, const bool do_clamp)
BsdfEval bxdf_ggx_eval_reflection(float3 N, float3 L, float3 V, float alpha, bool do_clamp)
ClosureLight bxdf_ggx_light_thin_glass_transmission(const UtilityTexture &util_tx, ClosureThinRefraction cl, float3 V)
ClosureLight bxdf_ggx_light_transmission(const UtilityTexture &util_tx, ClosureRefraction cl, float3 V, Thickness thickness)
float3 bxdf_ggx_dominant_direction_transmission(float3 N, float3 V, float ior, float roughness)
BsdfSample bxdf_ggx_sample_reflection(float3 rand, float3 Vt, float alpha, bool do_clamp)
float bxdf_ggx_perceived_roughness_transmission(float roughness, float ior)
float bxdf_ggx_smith_G1(float NX, float a2)
Ray bxdf_ggx_ray_amend_transmission(ClosureUndetermined cl, float3 V, Ray ray, Thickness thickness)
#define BSDF_ROUGHNESS_THRESHOLD
VecBase< T, D > refract(VecOp< T, D >, VecOp< T, D >, float) RET
VecBase< T, D > reflect(VecOp< T, D >, VecOp< T, D >) RET
VecBase< float, D > normalize(VecOp< float, D >) RET
float dot(VecOp< float, D >, VecOp< float, D >) RET
float length(VecOp< float, D >) RET
bool is_equal(float a, float b, const float epsilon)
VecT normalize_and_get_length(VecT vector, float &out_length)
float length_squared(VecT a)
VecT safe_normalize(VecT vector)
KERNEL_FEATURE_LIGHT_PASSES KERNEL_FEATURE_PATH_GUIDING float
float perceptual_roughness
packed_float3 dominant_direction
static void pack_ltc_lut(ClosureLight &cl, const UtilityTexture &util_tx, float3 N, float3 V, float cos_theta, float roughness)
CCL_NAMESPACE_BEGIN struct Window V