Fix T38439: allow IOR in range [0, inf] instead of [1, inf] in Cycles.

The same can be achieved by flipping normals on the mesh, but it can be
convenient to do this in the shader.
This commit is contained in:
Brecht Van Lommel 2014-02-03 17:06:37 +01:00
parent 8b1731e13d
commit eff3bd4e98
Notes: blender-bot 2023-02-14 11:15:42 +01:00
Referenced by issue #38439, Index of refraction < 1 renders wrong in cycles
8 changed files with 9 additions and 9 deletions

View File

@ -22,7 +22,7 @@ shader node_fresnel(
normal Normal = N,
output float Fac = 0.0)
{
float f = max(IOR, 1.0 + 1e-5);
float f = max(IOR, 1e-5);
float eta = backfacing() ? 1.0 / f: f;
float cosi = dot(I, Normal);
Fac = fresnel_dielectric_cos(cosi, eta);

View File

@ -25,7 +25,7 @@ shader node_glass_bsdf(
normal Normal = N,
output closure color BSDF = 0)
{
float f = max(IOR, 1.0 + 1e-5);
float f = max(IOR, 1e-5);
float eta = backfacing() ? 1.0 / f: f;
float cosi = dot(I, Normal);
float Fr = fresnel_dielectric_cos(cosi, eta);

View File

@ -24,7 +24,7 @@ shader node_refraction_bsdf(
normal Normal = N,
output closure color BSDF = 0)
{
float f = max(IOR, 1.0 + 1e-5);
float f = max(IOR, 1e-5);
float eta = backfacing() ? 1.0 / f: f;
if (distribution == "Sharp")

View File

@ -225,7 +225,7 @@ ccl_device void svm_node_closure_bsdf(KernelGlobals *kg, ShaderData *sd, float *
sc->N = N;
sc->data0 = param1;
float eta = fmaxf(param2, 1.0f + 1e-5f);
float eta = fmaxf(param2, 1e-5f);
sc->data1 = (sd->flag & SD_BACKFACING)? 1.0f/eta: eta;
/* setup bsdf */
@ -247,7 +247,7 @@ ccl_device void svm_node_closure_bsdf(KernelGlobals *kg, ShaderData *sd, float *
break;
#endif
/* index of refraction */
float eta = fmaxf(param2, 1.0f + 1e-5f);
float eta = fmaxf(param2, 1e-5f);
eta = (sd->flag & SD_BACKFACING)? 1.0f/eta: eta;
/* fresnel */

View File

@ -25,7 +25,7 @@ ccl_device void svm_node_fresnel(ShaderData *sd, float *stack, uint ior_offset,
float eta = (stack_valid(ior_offset))? stack_load_float(stack, ior_offset): __uint_as_float(ior_value);
float3 normal_in = stack_valid(normal_offset)? stack_load_float3(stack, normal_offset): sd->N;
eta = fmaxf(eta, 1.0f + 1e-5f);
eta = fmaxf(eta, 1e-5f);
eta = (sd->flag & SD_BACKFACING)? 1.0f/eta: eta;
float f = fresnel_dielectric_cos(dot(sd->I, normal_in), eta);

View File

@ -32,7 +32,7 @@
static bNodeSocketTemplate sh_node_bsdf_glass_in[] = {
{ SOCK_RGBA, 1, N_("Color"), 0.8f, 0.8f, 0.8f, 1.0f, 0.0f, 1.0f},
{ SOCK_FLOAT, 1, N_("Roughness"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_FACTOR},
{ SOCK_FLOAT, 1, N_("IOR"), 1.45f, 0.0f, 0.0f, 0.0f, 1.0f, 1000.0f},
{ SOCK_FLOAT, 1, N_("IOR"), 1.45f, 0.0f, 0.0f, 0.0f, 0.0f, 1000.0f},
{ SOCK_VECTOR, 1, N_("Normal"), 0.0f, 0.0f, 0.0f, 1.0f, -1.0f, 1.0f, PROP_NONE, SOCK_HIDE_VALUE},
{ -1, 0, "" }
};

View File

@ -32,7 +32,7 @@
static bNodeSocketTemplate sh_node_bsdf_refraction_in[] = {
{ SOCK_RGBA, 1, N_("Color"), 0.8f, 0.8f, 0.8f, 1.0f, 0.0f, 1.0f},
{ SOCK_FLOAT, 1, N_("Roughness"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_FACTOR},
{ SOCK_FLOAT, 1, N_("IOR"), 1.45f, 0.0f, 0.0f, 0.0f, 1.0f, 1000.0f},
{ SOCK_FLOAT, 1, N_("IOR"), 1.45f, 0.0f, 0.0f, 0.0f, 0.0f, 1000.0f},
{ SOCK_VECTOR, 1, N_("Normal"), 0.0f, 0.0f, 0.0f, 1.0f, -1.0f, 1.0f, PROP_NONE, SOCK_HIDE_VALUE},
{ -1, 0, "" }
};

View File

@ -29,7 +29,7 @@
/* **************** Fresnel ******************** */
static bNodeSocketTemplate sh_node_fresnel_in[] = {
{ SOCK_FLOAT, 1, N_("IOR"), 1.45f, 0.0f, 0.0f, 0.0f, 1.0f, 1000.0f},
{ SOCK_FLOAT, 1, N_("IOR"), 1.45f, 0.0f, 0.0f, 0.0f, 0.0f, 1000.0f},
{ SOCK_VECTOR, 1, N_("Normal"), 0.0f, 0.0f, 0.0f, 1.0f, -1.0f, 1.0f, PROP_NONE, SOCK_HIDE_VALUE},
{ -1, 0, "" }
};