[Bf-blender-cvs] [fc62d5a3b36] soc-2018-hair-shader: Cleanup: add some comments, guard against NaNs in hair_ap.

Brecht Van Lommel noreply at git.blender.org
Sun May 27 01:40:39 CEST 2018


Commit: fc62d5a3b3622efa69a02377bc15ab6f6f1e389c
Author: Brecht Van Lommel
Date:   Sat May 26 22:44:09 2018 +0200
Branches: soc-2018-hair-shader
https://developer.blender.org/rBfc62d5a3b3622efa69a02377bc15ab6f6f1e389c

Cleanup: add some comments, guard against NaNs in hair_ap.

===================================================================

M	intern/cycles/kernel/closure/bsdf_hair_principled.h

===================================================================

diff --git a/intern/cycles/kernel/closure/bsdf_hair_principled.h b/intern/cycles/kernel/closure/bsdf_hair_principled.h
index 5c2df2fc328..c17294b90d6 100644
--- a/intern/cycles/kernel/closure/bsdf_hair_principled.h
+++ b/intern/cycles/kernel/closure/bsdf_hair_principled.h
@@ -169,15 +169,25 @@ ccl_device int bsdf_principled_hair_setup(KernelGlobals *kg, ShaderData *sd, Pri
 
 ccl_device_inline void hair_ap(float f, float3 T, float4 *Ap)
 {
+	/* Primary specular (R). */
 	Ap[0] = make_float4(f, f, f, f);
+
+	/* Transmission (TT). */
 	float3 col = sqr(1.0f - f) * T;
 	Ap[1] = combine_with_energy(col);
+
+	/* Secondary specular (TRT). */
 	col *= T*f;
 	Ap[2] = combine_with_energy(col);
-	col *= T*f;
-	Ap[3] = combine_with_energy(col / (make_float3(1.0f, 1.0f, 1.0f) - T*f));
 
-	float fac = 1.0f / (Ap[0].w + Ap[1].w + Ap[2].w + Ap[3].w);
+	/* Residual component. */
+	col *= safe_divide_color(T*f, make_float3(1.0f, 1.0f, 1.0f) - T*f);
+	Ap[3] = combine_with_energy(col);
+
+	/* Normalize sampling weights. */
+	float totweight = Ap[0].w + Ap[1].w + Ap[2].w + Ap[3].w;
+	float fac = safe_divide(1.0f, totweight);
+
 	Ap[0].w *= fac;
 	Ap[1].w *= fac;
 	Ap[2].w *= fac;



More information about the Bf-blender-cvs mailing list