[Bf-blender-cvs] [e69877c217d] microfacet_hair: Cleanup: renaming and formatting comments

Weizhen Huang noreply at git.blender.org
Thu Jan 12 19:52:40 CET 2023


Commit: e69877c217d9ef27a52f3f2bf07b46ee2cfd0ffd
Author: Weizhen Huang
Date:   Thu Jan 12 19:52:24 2023 +0100
Branches: microfacet_hair
https://developer.blender.org/rBe69877c217d9ef27a52f3f2bf07b46ee2cfd0ffd

Cleanup: renaming and formatting comments

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

M	intern/cycles/blender/shader.cpp
M	intern/cycles/kernel/closure/bsdf_hair_microfacet.h
M	intern/cycles/kernel/osl/shaders/node_microfacet_hair_bsdf.osl
M	intern/cycles/kernel/osl/shaders/stdcycles.h
M	intern/cycles/kernel/svm/closure.h
M	intern/cycles/kernel/svm/types.h
M	intern/cycles/scene/shader_nodes.cpp
M	intern/cycles/scene/shader_nodes.h
M	source/blender/makesrna/intern/rna_nodetree.c
M	source/blender/nodes/shader/nodes/node_shader_bsdf_hair_microfacet.cc

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

diff --git a/intern/cycles/blender/shader.cpp b/intern/cycles/blender/shader.cpp
index 099a48af84d..2a697c1d50a 100644
--- a/intern/cycles/blender/shader.cpp
+++ b/intern/cycles/blender/shader.cpp
@@ -668,10 +668,10 @@ static ShaderNode *add_node(Scene *scene,
                                                     "parametrization",
                                                     NODE_MICROFACET_HAIR_NUM,
                                                     NODE_MICROFACET_HAIR_REFLECTANCE));
-    microfacet_hair->set_cross_section_type(
+    microfacet_hair->set_cross_section(
         (NodeMicrofacetHairCrossSectionType)get_enum(b_microfacet_hair_node.ptr,
-                                                     "cross_section_type",
-                                                     NODE_MICROFACET_HAIR_CROSS_SECTION_TYPE_NUM,
+                                                     "cross_section",
+                                                     NODE_MICROFACET_HAIR_CROSS_SECTION_NUM,
                                                      NODE_MICROFACET_HAIR_CIRCULAR));
     microfacet_hair->set_distribution_type(
         (NodeMicrofacetHairDistributionType)get_enum(b_microfacet_hair_node.ptr,
diff --git a/intern/cycles/kernel/closure/bsdf_hair_microfacet.h b/intern/cycles/kernel/closure/bsdf_hair_microfacet.h
index 2381d5a5239..ff372ab947b 100644
--- a/intern/cycles/kernel/closure/bsdf_hair_microfacet.h
+++ b/intern/cycles/kernel/closure/bsdf_hair_microfacet.h
@@ -12,6 +12,7 @@
 CCL_NAMESPACE_BEGIN
 
 typedef struct MicrofacetHairExtra {
+  /* TODO: is this necessary? */
   float R;
   float TT;
   float TRT;
@@ -30,7 +31,7 @@ typedef struct MicrofacetHairBSDF {
   /* Microfacet distribution roughness. */
   float roughness;
   /* Cuticle tilt angle. */
-  float alpha;
+  float tilt;
   /* IOR. */
   float eta;
 
@@ -38,7 +39,7 @@ typedef struct MicrofacetHairBSDF {
   int distribution_type;
 
   /* Circular/Elliptical */
-  int cross_section_type;
+  int cross_section;
 
   /* Extra closure. */
   ccl_private MicrofacetHairExtra *extra;
@@ -58,21 +59,21 @@ ccl_device int bsdf_microfacet_hair_setup(ccl_private ShaderData *sd,
 
   bsdf->roughness = clamp(bsdf->roughness, 0.001f, 1.0f);
 
-  /* Compute local frame, aligned to curve tangent and ray direction. */
-  float3 Y = safe_normalize(sd->dPdu);
-  float3 X = safe_normalize(cross(Y, sd->I));
-
-  /* h -1..0..1 means the rays goes from grazing the hair, to hitting it at
-   * the center, to grazing the other edge. This is the sine of the angle
-   * between sd->Ng and Z, as seen from the tangent X. */
+  /* Compute local frame. The Y axis is aligned with the curve tangent; the X axis is perpendicular
+   to the ray direction for circular cross-sections, or aligned with the major axis for elliptical
+   cross-sections. */
+  const float3 Y = safe_normalize(sd->dPdu);
+  const float3 X = safe_normalize(cross(Y, sd->I));
 
-  float h = (sd->type & PRIMITIVE_CURVE_RIBBON) ? -sd->v : -dot(X, sd->N);
+  /* h -1..0..1 means the rays goes from grazing the hair, to hitting it at the center, to grazing
+   * the other edge. This is the cosine of the angle between sd->N and X. */
+  const float h = (sd->type & PRIMITIVE_CURVE_RIBBON) ? -sd->v : -dot(X, sd->N);
 
   kernel_assert(fabsf(h) < 1.0f + 1e-4f);
   kernel_assert(isfinite_safe(X));
   kernel_assert(isfinite_safe(h));
 
-  if (bsdf->cross_section_type == NODE_MICROFACET_HAIR_ELLIPTIC) {
+  if (bsdf->cross_section == NODE_MICROFACET_HAIR_ELLIPTIC) {
     /* Local frame is independent of the ray direction for elliptical hairs. */
     bsdf->extra->geom.w = h;
   }
@@ -140,13 +141,13 @@ ccl_device_inline float2 dir_sph(const float3 w)
   return make_float2(dir_theta(w), dir_phi(w));
 }
 
-/* Compute the vector direction given spherical coordinates */
-ccl_device_inline float3 sph_dir(float theta, float gamma)
+/* Compute the vector direction given spherical coordinates. */
+ccl_device_inline float3 sph_dir(float theta, float phi)
 {
-  float sin_theta, cos_theta, sin_gamma, cos_gamma;
+  float sin_theta, cos_theta, sin_phi, cos_phi;
   fast_sincosf(theta, &sin_theta, &cos_theta);
-  fast_sincosf(gamma, &sin_gamma, &cos_gamma);
-  return make_float3(sin_gamma * cos_theta, sin_theta, cos_gamma * cos_theta);
+  fast_sincosf(phi, &sin_phi, &cos_phi);
+  return make_float3(sin_phi * cos_theta, sin_theta, cos_phi * cos_theta);
 }
 
 /* Utility functions for elliptical cross-sections. */
@@ -189,7 +190,7 @@ ccl_device float3 sphg_dir(float theta, float gamma, float a, float b)
 
 /** \} */
 
-/* sample microfacets from a tilted mesonormal */
+/* Sample microfacets from a tilted mesonormal. */
 ccl_device_inline float3 sample_wh(KernelGlobals kg,
                                    const bool beckmann,
                                    const float roughness,
@@ -197,7 +198,7 @@ ccl_device_inline float3 sample_wh(KernelGlobals kg,
                                    const float3 wm,
                                    const float2 rand)
 {
-  /* Coordinate transformation for microfacet sampling */
+  /* Coordinate transformation for microfacet sampling. */
   float3 s, t;
   const float3 n = wm;
   make_orthonormals(n, &s, &t);
@@ -212,13 +213,13 @@ ccl_device_inline float3 sample_wh(KernelGlobals kg,
   return wh;
 }
 
-/* Check micronormal/mesonormal direct visiblity from v */
+/* Check micronormal/mesonormal direct visiblity from direction v. */
 ccl_device_inline bool microfacet_visible(const float3 v, const float3 m, const float3 h)
 {
   return (dot(v, h) > 0.0f && dot(v, m) > 0.0f);
 }
 
-/* Check micronormal/mesonormal direct visiblity from wi and wo */
+/* Check micronormal/mesonormal direct visiblity from directinos wi and wo. */
 ccl_device_inline bool microfacet_visible(const float3 wi,
                                           const float3 wo,
                                           const float3 m,
@@ -227,22 +228,22 @@ ccl_device_inline bool microfacet_visible(const float3 wi,
   return microfacet_visible(wi, m, h) && microfacet_visible(wo, m, h);
 }
 
-/* Check micronormal/mesonormal statistical visiblity from v: Smith's separable shadowing/masking
- * term */
+/* Smith's separable shadowing/masking term. */
 ccl_device_inline float smith_g1(
     const bool beckmann, const float roughness, const float3 v, const float3 m, const float3 h)
 {
   /* Assume consistent orientation (can't see the back of the microfacet from the front and vice
-   * versa) */
+   * versa). */
   float cos_vm = dot(v, m);
-  if (dot(v, h) <= 0.0f || cos_vm <= 0.0f)
+  if (dot(v, h) <= 0.0f || cos_vm <= 0.0f) {
     return 0.0f;
+  }
 
   return beckmann ? bsdf_beckmann_G1(roughness, cos_vm) :
                     2.0f / (1.0f + sqrtf(1.0f + sqr(roughness) * (1.0f / sqr(cos_vm) - 1.0f)));
 }
 
-/* Smith's separable shadowing-masking approximation */
+/* Geometry term. */
 ccl_device_inline float G(const bool beckmann,
                           const float roughness,
                           const float3 wi,
@@ -253,24 +254,20 @@ ccl_device_inline float G(const bool beckmann,
   return smith_g1(beckmann, roughness, wi, m, h) * smith_g1(beckmann, roughness, wo, m, h);
 }
 
-/* Normal Distribution Function */
+/* Normal Distribution Function. */
 ccl_device float D(const bool beckmann, const float roughness, const float3 m, const float3 h)
 {
-  float cos_theta = dot(h, m);
+  const float cos_theta = dot(h, m);
 
-  float result;
   const float roughness2 = sqr(roughness);
   const float cos_theta2 = sqr(cos_theta);
 
-  if (beckmann) {
-    result = expf((1.0f - 1.0f / cos_theta2) / roughness2) /
-             (M_PI_F * roughness2 * sqr(cos_theta2));
-  }
-  else { /* GGX */
-    result = roughness2 / (M_PI_F * sqr(1.0f + (roughness2 - 1.0f) * cos_theta2));
-  }
+  const float result = beckmann ?
+                           expf((1.0f - 1.0f / cos_theta2) / roughness2) /
+                               (M_PI_F * roughness2 * sqr(cos_theta2)) :
+                           roughness2 / (M_PI_F * sqr(1.0f + (roughness2 - 1.0f) * cos_theta2));
 
-  /* Prevent potential numerical issues in other stages of the model */
+  /* Prevent potential numerical issues in other stages of the model. */
   return (result * cos_theta > 1e-20f) ? result : 0.0f;
 }
 
@@ -292,7 +289,7 @@ ccl_device float fresnel(float cos_theta_i, float eta, ccl_private float *cos_th
 
   /* Using Snell's law, calculate the squared cosine of the angle between the surface normal and
    * the transmitted ray. */
-  float cos_theta_t_sqr = 1.0f - (1.0f - cos_theta_i * cos_theta_i) / (eta * eta);
+  const float cos_theta_t_sqr = 1.0f - (1.0f - cos_theta_i * cos_theta_i) / (eta * eta);
   *cos_theta_t = safe_sqrtf(cos_theta_t_sqr);
 
   if (cos_theta_t_sqr <= 0) {
@@ -301,17 +298,16 @@ ccl_device float fresnel(float cos_theta_i, float eta, ccl_private float *cos_th
   }
 
   /* Amplitudes of reflected waves. */
-  float a_s = (cos_theta_i - eta * (*cos_theta_t)) / (cos_theta_i + eta * (*cos_theta_t));
-  float a_p = (*cos_theta_t - eta * cos_theta_i) / (*cos_theta_t + eta * cos_theta_i);
-
-  float r = 0.5f * (sqr(a_s) + sqr(a_p));
+  const float a_s = (cos_theta_i - eta * (*cos_theta_t)) / (cos_theta_i + eta * (*cos_theta_t));
+  const float a_p = (*cos_theta_t - eta * cos_theta_i) / (*cos_theta_t + eta * cos_theta_i);
 
   /* Adjust the sign of the transmitted direction to be relative to the surface normal. */
   *cos_theta_t = -(*cos_theta_t);
 
-  return r;
+  return 0.5f * (sqr(a_s) + sqr(a_p));
 }
 
+/* Refract the incident ray, given the cosine of the refraction angle and the inverse IOR. */
 ccl_device_inline float3 refract_angle(const float3 incident,
                                        const float3 normal,
                                        const float cos_theta_t,
@@ -325,35 +321,39 @@ ccl_device float3 bsdf_microfacet_hair_eval_r_circular(ccl_private const ShaderC
                                                        const float3 wo)
 {
   ccl_private MicrofacetHairBSDF *bsdf = (ccl_private MicrofacetHairBSDF *)sc;
-  const float tilt = -bsdf->alpha;
+  const float tilt = -bsdf->tilt;
   const float roughness = bsdf->roughness;
   const float eta = bsdf->eta;
   const 

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list