Cleanup: rename function
The name #ensure_valid_reflection seems to indicate that the resulted reflection must be valid, whereas in the reality it only ensure validity for specular reflections. The new name matches the behavior better.
This commit is contained in:
@@ -105,7 +105,10 @@ ccl_device_forceinline Spectrum interpolate_fresnel_color(float3 L,
|
||||
return mix(F0, one_spectrum(), inverse_lerp(real_F0, 1.0f, real_F));
|
||||
}
|
||||
|
||||
ccl_device float3 ensure_valid_reflection(float3 Ng, float3 I, float3 N)
|
||||
/* If the shading normal results in specular reflection in the lower hemisphere, raise the shading
|
||||
* normal towards the geometry normal so that the specular reflection is just above the surface.
|
||||
* Only used for glossy materials. */
|
||||
ccl_device float3 ensure_valid_specular_reflection(float3 Ng, float3 I, float3 N)
|
||||
{
|
||||
const float3 R = 2 * dot(N, I) * N - I;
|
||||
|
||||
@@ -180,14 +183,14 @@ ccl_device float3 ensure_valid_reflection(float3 Ng, float3 I, float3 N)
|
||||
return Nx * X + Nz * Ng;
|
||||
}
|
||||
|
||||
/* Do not call #ensure_valid_reflection if the primitive type is curve or if the geometry
|
||||
/* Do not call #ensure_valid_specular_reflection if the primitive type is curve or if the geometry
|
||||
* normal and the shading normal is the same. */
|
||||
ccl_device float3 maybe_ensure_valid_reflection(ccl_private ShaderData *sd, float3 N)
|
||||
ccl_device float3 maybe_ensure_valid_specular_reflection(ccl_private ShaderData *sd, float3 N)
|
||||
{
|
||||
if ((sd->type & PRIMITIVE_CURVE) || isequal(sd->Ng, N)) {
|
||||
return N;
|
||||
}
|
||||
return ensure_valid_reflection(sd->Ng, sd->wi, N);
|
||||
return ensure_valid_specular_reflection(sd->Ng, sd->wi, N);
|
||||
}
|
||||
|
||||
CCL_NAMESPACE_END
|
||||
|
||||
@@ -142,7 +142,7 @@ ccl_device void osl_closure_reflection_setup(KernelGlobals kg,
|
||||
return;
|
||||
}
|
||||
|
||||
bsdf->N = ensure_valid_reflection(sd->Ng, sd->wi, closure->N);
|
||||
bsdf->N = ensure_valid_specular_reflection(sd->Ng, sd->wi, closure->N);
|
||||
|
||||
sd->flag |= bsdf_reflection_setup(bsdf);
|
||||
}
|
||||
@@ -163,7 +163,7 @@ ccl_device void osl_closure_refraction_setup(KernelGlobals kg,
|
||||
return;
|
||||
}
|
||||
|
||||
bsdf->N = ensure_valid_reflection(sd->Ng, sd->wi, closure->N);
|
||||
bsdf->N = ensure_valid_specular_reflection(sd->Ng, sd->wi, closure->N);
|
||||
bsdf->ior = closure->ior;
|
||||
|
||||
sd->flag |= bsdf_refraction_setup(bsdf);
|
||||
@@ -204,7 +204,7 @@ ccl_device void osl_closure_dielectric_bsdf_setup(KernelGlobals kg,
|
||||
return;
|
||||
}
|
||||
|
||||
bsdf->N = ensure_valid_reflection(sd->Ng, sd->wi, closure->N);
|
||||
bsdf->N = ensure_valid_specular_reflection(sd->Ng, sd->wi, closure->N);
|
||||
bsdf->alpha_x = closure->alpha_x;
|
||||
bsdf->alpha_y = closure->alpha_y;
|
||||
bsdf->ior = closure->ior;
|
||||
@@ -266,7 +266,7 @@ ccl_device void osl_closure_conductor_bsdf_setup(KernelGlobals kg,
|
||||
return;
|
||||
}
|
||||
|
||||
bsdf->N = ensure_valid_reflection(sd->Ng, sd->wi, closure->N);
|
||||
bsdf->N = ensure_valid_specular_reflection(sd->Ng, sd->wi, closure->N);
|
||||
bsdf->alpha_x = closure->alpha_x;
|
||||
bsdf->alpha_y = closure->alpha_y;
|
||||
bsdf->ior = 0.0f;
|
||||
@@ -313,7 +313,7 @@ ccl_device void osl_closure_generalized_schlick_bsdf_setup(
|
||||
return;
|
||||
}
|
||||
|
||||
bsdf->N = ensure_valid_reflection(sd->Ng, sd->wi, closure->N);
|
||||
bsdf->N = ensure_valid_specular_reflection(sd->Ng, sd->wi, closure->N);
|
||||
bsdf->alpha_x = closure->alpha_x;
|
||||
bsdf->alpha_y = closure->alpha_y;
|
||||
bsdf->ior = ior_from_F0(closure->f0);
|
||||
@@ -375,7 +375,7 @@ ccl_device void osl_closure_microfacet_setup(KernelGlobals kg,
|
||||
return;
|
||||
}
|
||||
|
||||
bsdf->N = ensure_valid_reflection(sd->Ng, sd->wi, closure->N);
|
||||
bsdf->N = ensure_valid_specular_reflection(sd->Ng, sd->wi, closure->N);
|
||||
bsdf->alpha_x = closure->alpha_x;
|
||||
bsdf->alpha_y = closure->alpha_y;
|
||||
bsdf->ior = closure->ior;
|
||||
@@ -440,7 +440,7 @@ ccl_device void osl_closure_microfacet_ggx_setup(
|
||||
return;
|
||||
}
|
||||
|
||||
bsdf->N = ensure_valid_reflection(sd->Ng, sd->wi, closure->N);
|
||||
bsdf->N = ensure_valid_specular_reflection(sd->Ng, sd->wi, closure->N);
|
||||
bsdf->alpha_x = bsdf->alpha_y = closure->alpha_x;
|
||||
|
||||
sd->flag |= bsdf_microfacet_ggx_setup(bsdf);
|
||||
@@ -463,7 +463,7 @@ ccl_device void osl_closure_microfacet_ggx_aniso_setup(
|
||||
return;
|
||||
}
|
||||
|
||||
bsdf->N = ensure_valid_reflection(sd->Ng, sd->wi, closure->N);
|
||||
bsdf->N = ensure_valid_specular_reflection(sd->Ng, sd->wi, closure->N);
|
||||
bsdf->alpha_x = closure->alpha_x;
|
||||
bsdf->alpha_y = closure->alpha_y;
|
||||
bsdf->T = closure->T;
|
||||
@@ -488,7 +488,7 @@ ccl_device void osl_closure_microfacet_ggx_refraction_setup(
|
||||
return;
|
||||
}
|
||||
|
||||
bsdf->N = ensure_valid_reflection(sd->Ng, sd->wi, closure->N);
|
||||
bsdf->N = ensure_valid_specular_reflection(sd->Ng, sd->wi, closure->N);
|
||||
bsdf->alpha_x = closure->alpha_x;
|
||||
bsdf->ior = closure->ior;
|
||||
|
||||
@@ -520,7 +520,7 @@ ccl_device void osl_closure_microfacet_ggx_fresnel_setup(
|
||||
return;
|
||||
}
|
||||
|
||||
bsdf->N = ensure_valid_reflection(sd->Ng, sd->wi, closure->N);
|
||||
bsdf->N = ensure_valid_specular_reflection(sd->Ng, sd->wi, closure->N);
|
||||
bsdf->alpha_x = closure->alpha_x;
|
||||
bsdf->alpha_y = bsdf->alpha_x;
|
||||
bsdf->ior = closure->ior;
|
||||
@@ -556,7 +556,7 @@ ccl_device void osl_closure_microfacet_ggx_aniso_fresnel_setup(
|
||||
return;
|
||||
}
|
||||
|
||||
bsdf->N = ensure_valid_reflection(sd->Ng, sd->wi, closure->N);
|
||||
bsdf->N = ensure_valid_specular_reflection(sd->Ng, sd->wi, closure->N);
|
||||
bsdf->alpha_x = closure->alpha_x;
|
||||
bsdf->alpha_y = closure->alpha_y;
|
||||
bsdf->ior = closure->ior;
|
||||
@@ -597,7 +597,7 @@ ccl_device void osl_closure_microfacet_multi_ggx_setup(
|
||||
return;
|
||||
}
|
||||
|
||||
bsdf->N = ensure_valid_reflection(sd->Ng, sd->wi, closure->N);
|
||||
bsdf->N = ensure_valid_specular_reflection(sd->Ng, sd->wi, closure->N);
|
||||
bsdf->alpha_x = closure->alpha_x;
|
||||
bsdf->alpha_y = bsdf->alpha_x;
|
||||
bsdf->ior = 1.0f;
|
||||
@@ -636,7 +636,7 @@ ccl_device void osl_closure_microfacet_multi_ggx_glass_setup(
|
||||
return;
|
||||
}
|
||||
|
||||
bsdf->N = ensure_valid_reflection(sd->Ng, sd->wi, closure->N);
|
||||
bsdf->N = ensure_valid_specular_reflection(sd->Ng, sd->wi, closure->N);
|
||||
bsdf->alpha_x = closure->alpha_x;
|
||||
bsdf->alpha_y = bsdf->alpha_x;
|
||||
bsdf->ior = closure->ior;
|
||||
@@ -675,7 +675,7 @@ ccl_device void osl_closure_microfacet_multi_ggx_aniso_setup(
|
||||
return;
|
||||
}
|
||||
|
||||
bsdf->N = ensure_valid_reflection(sd->Ng, sd->wi, closure->N);
|
||||
bsdf->N = ensure_valid_specular_reflection(sd->Ng, sd->wi, closure->N);
|
||||
bsdf->alpha_x = closure->alpha_x;
|
||||
bsdf->alpha_y = closure->alpha_y;
|
||||
bsdf->ior = 1.0f;
|
||||
@@ -716,7 +716,7 @@ ccl_device void osl_closure_microfacet_multi_ggx_fresnel_setup(
|
||||
return;
|
||||
}
|
||||
|
||||
bsdf->N = ensure_valid_reflection(sd->Ng, sd->wi, closure->N);
|
||||
bsdf->N = ensure_valid_specular_reflection(sd->Ng, sd->wi, closure->N);
|
||||
bsdf->alpha_x = closure->alpha_x;
|
||||
bsdf->alpha_y = bsdf->alpha_x;
|
||||
bsdf->ior = closure->ior;
|
||||
@@ -756,7 +756,7 @@ ccl_device void osl_closure_microfacet_multi_ggx_glass_fresnel_setup(
|
||||
return;
|
||||
}
|
||||
|
||||
bsdf->N = ensure_valid_reflection(sd->Ng, sd->wi, closure->N);
|
||||
bsdf->N = ensure_valid_specular_reflection(sd->Ng, sd->wi, closure->N);
|
||||
bsdf->alpha_x = closure->alpha_x;
|
||||
bsdf->alpha_y = bsdf->alpha_x;
|
||||
bsdf->ior = closure->ior;
|
||||
@@ -796,7 +796,7 @@ ccl_device void osl_closure_microfacet_multi_ggx_aniso_fresnel_setup(
|
||||
return;
|
||||
}
|
||||
|
||||
bsdf->N = ensure_valid_reflection(sd->Ng, sd->wi, closure->N);
|
||||
bsdf->N = ensure_valid_specular_reflection(sd->Ng, sd->wi, closure->N);
|
||||
bsdf->alpha_x = closure->alpha_x;
|
||||
bsdf->alpha_y = closure->alpha_y;
|
||||
bsdf->ior = closure->ior;
|
||||
@@ -829,7 +829,7 @@ ccl_device void osl_closure_microfacet_beckmann_setup(
|
||||
return;
|
||||
}
|
||||
|
||||
bsdf->N = ensure_valid_reflection(sd->Ng, sd->wi, closure->N);
|
||||
bsdf->N = ensure_valid_specular_reflection(sd->Ng, sd->wi, closure->N);
|
||||
bsdf->alpha_x = bsdf->alpha_y = closure->alpha_x;
|
||||
|
||||
sd->flag |= bsdf_microfacet_beckmann_setup(bsdf);
|
||||
@@ -852,7 +852,7 @@ ccl_device void osl_closure_microfacet_beckmann_aniso_setup(
|
||||
return;
|
||||
}
|
||||
|
||||
bsdf->N = ensure_valid_reflection(sd->Ng, sd->wi, closure->N);
|
||||
bsdf->N = ensure_valid_specular_reflection(sd->Ng, sd->wi, closure->N);
|
||||
bsdf->alpha_x = closure->alpha_x;
|
||||
bsdf->alpha_y = closure->alpha_y;
|
||||
bsdf->T = closure->T;
|
||||
@@ -877,7 +877,7 @@ ccl_device void osl_closure_microfacet_beckmann_refraction_setup(
|
||||
return;
|
||||
}
|
||||
|
||||
bsdf->N = ensure_valid_reflection(sd->Ng, sd->wi, closure->N);
|
||||
bsdf->N = ensure_valid_specular_reflection(sd->Ng, sd->wi, closure->N);
|
||||
bsdf->alpha_x = closure->alpha_x;
|
||||
bsdf->ior = closure->ior;
|
||||
|
||||
@@ -903,7 +903,7 @@ ccl_device void osl_closure_ashikhmin_velvet_setup(
|
||||
return;
|
||||
}
|
||||
|
||||
bsdf->N = ensure_valid_reflection(sd->Ng, sd->wi, closure->N);
|
||||
bsdf->N = ensure_valid_specular_reflection(sd->Ng, sd->wi, closure->N);
|
||||
bsdf->sigma = closure->sigma;
|
||||
|
||||
sd->flag |= bsdf_ashikhmin_velvet_setup(bsdf);
|
||||
@@ -926,7 +926,7 @@ ccl_device void osl_closure_ashikhmin_shirley_setup(
|
||||
return;
|
||||
}
|
||||
|
||||
bsdf->N = ensure_valid_reflection(sd->Ng, sd->wi, closure->N);
|
||||
bsdf->N = ensure_valid_specular_reflection(sd->Ng, sd->wi, closure->N);
|
||||
bsdf->alpha_x = closure->alpha_x;
|
||||
bsdf->alpha_y = closure->alpha_y;
|
||||
bsdf->T = closure->T;
|
||||
@@ -950,7 +950,7 @@ ccl_device void osl_closure_diffuse_toon_setup(KernelGlobals kg,
|
||||
return;
|
||||
}
|
||||
|
||||
bsdf->N = ensure_valid_reflection(sd->Ng, sd->wi, closure->N);
|
||||
bsdf->N = ensure_valid_specular_reflection(sd->Ng, sd->wi, closure->N);
|
||||
bsdf->size = closure->size;
|
||||
bsdf->smooth = closure->smooth;
|
||||
|
||||
@@ -973,7 +973,7 @@ ccl_device void osl_closure_glossy_toon_setup(KernelGlobals kg,
|
||||
return;
|
||||
}
|
||||
|
||||
bsdf->N = ensure_valid_reflection(sd->Ng, sd->wi, closure->N);
|
||||
bsdf->N = ensure_valid_specular_reflection(sd->Ng, sd->wi, closure->N);
|
||||
bsdf->size = closure->size;
|
||||
bsdf->smooth = closure->smooth;
|
||||
|
||||
@@ -1042,7 +1042,7 @@ ccl_device void osl_closure_principled_clearcoat_setup(
|
||||
return;
|
||||
}
|
||||
|
||||
bsdf->N = ensure_valid_reflection(sd->Ng, sd->wi, closure->N);
|
||||
bsdf->N = ensure_valid_specular_reflection(sd->Ng, sd->wi, closure->N);
|
||||
bsdf->alpha_x = closure->clearcoat_roughness;
|
||||
bsdf->alpha_y = closure->clearcoat_roughness;
|
||||
bsdf->ior = 1.5f;
|
||||
@@ -1134,7 +1134,7 @@ ccl_device void osl_closure_phong_ramp_setup(KernelGlobals kg,
|
||||
return;
|
||||
}
|
||||
|
||||
bsdf->N = ensure_valid_reflection(sd->Ng, sd->wi, closure->N);
|
||||
bsdf->N = ensure_valid_specular_reflection(sd->Ng, sd->wi, closure->N);
|
||||
bsdf->exponent = closure->exponent;
|
||||
|
||||
bsdf->colors = (float3 *)closure_alloc_extra(sd, sizeof(float3) * 8);
|
||||
@@ -1210,7 +1210,7 @@ ccl_device void osl_closure_hair_reflection_setup(KernelGlobals kg,
|
||||
return;
|
||||
}
|
||||
|
||||
bsdf->N = ensure_valid_reflection(sd->Ng, sd->wi, closure->N);
|
||||
bsdf->N = ensure_valid_specular_reflection(sd->Ng, sd->wi, closure->N);
|
||||
bsdf->T = closure->T;
|
||||
bsdf->roughness1 = closure->roughness1;
|
||||
bsdf->roughness2 = closure->roughness2;
|
||||
@@ -1236,7 +1236,7 @@ ccl_device void osl_closure_hair_transmission_setup(
|
||||
return;
|
||||
}
|
||||
|
||||
bsdf->N = ensure_valid_reflection(sd->Ng, sd->wi, closure->N);
|
||||
bsdf->N = ensure_valid_specular_reflection(sd->Ng, sd->wi, closure->N);
|
||||
bsdf->T = closure->T;
|
||||
bsdf->roughness1 = closure->roughness1;
|
||||
bsdf->roughness2 = closure->roughness2;
|
||||
@@ -1268,7 +1268,7 @@ ccl_device void osl_closure_principled_hair_setup(KernelGlobals kg,
|
||||
return;
|
||||
}
|
||||
|
||||
bsdf->N = ensure_valid_reflection(sd->Ng, sd->wi, closure->N);
|
||||
bsdf->N = ensure_valid_specular_reflection(sd->Ng, sd->wi, closure->N);
|
||||
bsdf->sigma = closure->sigma;
|
||||
bsdf->v = closure->v;
|
||||
bsdf->s = closure->s;
|
||||
|
||||
@@ -117,7 +117,7 @@ ccl_device_noinline int svm_node_closure_bsdf(KernelGlobals kg,
|
||||
float ior = (sd->flag & SD_BACKFACING) ? 1.0f / eta : eta;
|
||||
|
||||
/* Calculate fresnel for refraction. */
|
||||
float3 valid_reflection_N = maybe_ensure_valid_reflection(sd, N);
|
||||
float3 valid_reflection_N = maybe_ensure_valid_specular_reflection(sd, N);
|
||||
float cosNI = dot(valid_reflection_N, sd->wi);
|
||||
float fresnel = fresnel_dielectric_cos(cosNI, ior);
|
||||
|
||||
@@ -140,7 +140,7 @@ ccl_device_noinline int svm_node_closure_bsdf(KernelGlobals kg,
|
||||
float3 clearcoat_normal = stack_valid(data_cn_ssr.x) ?
|
||||
stack_load_float3(stack, data_cn_ssr.x) :
|
||||
sd->N;
|
||||
clearcoat_normal = maybe_ensure_valid_reflection(sd, clearcoat_normal);
|
||||
clearcoat_normal = maybe_ensure_valid_specular_reflection(sd, clearcoat_normal);
|
||||
float3 subsurface_radius = stack_valid(data_cn_ssr.y) ?
|
||||
stack_load_float3(stack, data_cn_ssr.y) :
|
||||
one_float3();
|
||||
@@ -457,7 +457,7 @@ ccl_device_noinline int svm_node_closure_bsdf(KernelGlobals kg,
|
||||
sd, sizeof(DiffuseBsdf), weight);
|
||||
|
||||
if (bsdf) {
|
||||
bsdf->N = maybe_ensure_valid_reflection(sd, N);
|
||||
bsdf->N = maybe_ensure_valid_specular_reflection(sd, N);
|
||||
sd->flag |= bsdf_translucent_setup(bsdf);
|
||||
}
|
||||
break;
|
||||
@@ -486,7 +486,7 @@ ccl_device_noinline int svm_node_closure_bsdf(KernelGlobals kg,
|
||||
|
||||
float roughness = sqr(param1);
|
||||
|
||||
bsdf->N = maybe_ensure_valid_reflection(sd, N);
|
||||
bsdf->N = maybe_ensure_valid_specular_reflection(sd, N);
|
||||
bsdf->ior = 1.0f;
|
||||
bsdf->fresnel = NULL;
|
||||
|
||||
@@ -550,7 +550,7 @@ ccl_device_noinline int svm_node_closure_bsdf(KernelGlobals kg,
|
||||
sd, sizeof(MicrofacetBsdf), weight);
|
||||
|
||||
if (bsdf) {
|
||||
bsdf->N = maybe_ensure_valid_reflection(sd, N);
|
||||
bsdf->N = maybe_ensure_valid_specular_reflection(sd, N);
|
||||
bsdf->T = zero_float3();
|
||||
bsdf->fresnel = NULL;
|
||||
|
||||
@@ -593,7 +593,7 @@ ccl_device_noinline int svm_node_closure_bsdf(KernelGlobals kg,
|
||||
sd, sizeof(MicrofacetBsdf), weight);
|
||||
|
||||
if (bsdf) {
|
||||
bsdf->N = maybe_ensure_valid_reflection(sd, N);
|
||||
bsdf->N = maybe_ensure_valid_specular_reflection(sd, N);
|
||||
bsdf->T = zero_float3();
|
||||
bsdf->fresnel = NULL;
|
||||
|
||||
@@ -642,7 +642,7 @@ ccl_device_noinline int svm_node_closure_bsdf(KernelGlobals kg,
|
||||
break;
|
||||
}
|
||||
|
||||
bsdf->N = maybe_ensure_valid_reflection(sd, N);
|
||||
bsdf->N = maybe_ensure_valid_specular_reflection(sd, N);
|
||||
bsdf->fresnel = fresnel;
|
||||
bsdf->T = zero_float3();
|
||||
|
||||
@@ -748,7 +748,7 @@ ccl_device_noinline int svm_node_closure_bsdf(KernelGlobals kg,
|
||||
float coat = stack_load_float_default(stack, coat_ofs, data_node2.y);
|
||||
float m0_roughness = 1.0f - clamp(coat, 0.0f, 1.0f);
|
||||
|
||||
bsdf->N = maybe_ensure_valid_reflection(sd, N);
|
||||
bsdf->N = maybe_ensure_valid_specular_reflection(sd, N);
|
||||
bsdf->v = roughness;
|
||||
bsdf->s = radial_roughness;
|
||||
bsdf->m0_roughness = m0_roughness;
|
||||
@@ -816,7 +816,7 @@ ccl_device_noinline int svm_node_closure_bsdf(KernelGlobals kg,
|
||||
sd, sizeof(HairBsdf), weight);
|
||||
|
||||
if (bsdf) {
|
||||
bsdf->N = maybe_ensure_valid_reflection(sd, N);
|
||||
bsdf->N = maybe_ensure_valid_specular_reflection(sd, N);
|
||||
bsdf->roughness1 = param1;
|
||||
bsdf->roughness2 = param2;
|
||||
bsdf->offset = -stack_load_float(stack, data_node.z);
|
||||
|
||||
@@ -136,7 +136,7 @@ void accumulate_light(vec3 light, float fac, inout vec4 accum)
|
||||
}
|
||||
|
||||
/* Same thing as Cycles without the comments to make it shorter. */
|
||||
vec3 ensure_valid_reflection(vec3 Ng, vec3 I, vec3 N)
|
||||
vec3 ensure_valid_specular_reflection(vec3 Ng, vec3 I, vec3 N)
|
||||
{
|
||||
vec3 R = -reflect(I, N);
|
||||
|
||||
|
||||
@@ -53,7 +53,7 @@ ClosureEvalGlossy closure_Glossy_eval_init(inout ClosureInputGlossy cl_in,
|
||||
cl_out.radiance = vec3(0.0);
|
||||
|
||||
#ifndef STEP_RESOLVE /* SSR */
|
||||
cl_in.N = ensure_valid_reflection(cl_common.Ng, cl_common.V, cl_in.N);
|
||||
cl_in.N = ensure_valid_specular_reflection(cl_common.Ng, cl_common.V, cl_in.N);
|
||||
#endif
|
||||
|
||||
float NV = dot(cl_in.N, cl_common.V);
|
||||
|
||||
Reference in New Issue
Block a user