Blender V5.0
node_fresnel.h
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2009-2010 Sony Pictures Imageworks Inc., et al. All Rights Reserved.
2 * SPDX-FileCopyrightText: 2011-2022 Blender Foundation
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 *
6 * Adapted code from Open Shading Language. */
7
8float fresnel_dielectric_cos(float cosi, float eta)
9{
10 /* compute fresnel reflectance without explicitly computing
11 * the refracted direction */
12 float c = fabs(cosi);
13 float g = eta * eta - 1 + c * c;
14 float result;
15
16 if (g > 0) {
17 g = sqrt(g);
18 float A = (g - c) / (g + c);
19 float B = (c * (g + c) - 1) / (c * (g - c) + 1);
20 result = 0.5 * A * A * (1 + B * B);
21 }
22 else {
23 result = 1.0; /* TIR (no refracted component) */
24 }
25
26 return result;
27}
28
29color fresnel_conductor(float cosi, color eta, color k)
30{
31 color cosi2 = color(cosi * cosi);
32 color one = color(1, 1, 1);
33 color tmp_f = eta * eta + k * k;
34 color tmp = tmp_f * cosi2;
35 color Rparl2 = (tmp - (2.0 * eta * cosi) + one) / (tmp + (2.0 * eta * cosi) + one);
36 color Rperp2 = (tmp_f - (2.0 * eta * cosi) + cosi2) / (tmp_f + (2.0 * eta * cosi) + cosi2);
37 return (Rparl2 + Rperp2) * 0.5;
38}
39
40float F0_from_ior(float eta)
41{
42 float f0 = (eta - 1.0) / (eta + 1.0);
43 return f0 * f0;
44}
45
46float ior_from_F0(float f0)
47{
48 float sqrt_f0 = sqrt(clamp(f0, 0.0, 0.99));
49 return (1.0 + sqrt_f0) / (1.0 - sqrt_f0);
50}
#define A
#define sqrt
constexpr T clamp(T, U, U) RET
ccl_device_inline float2 fabs(const float2 a)
#define B
float ior_from_F0(float f0)
color fresnel_conductor(float cosi, color eta, color k)
float fresnel_dielectric_cos(float cosi, float eta)
Definition node_fresnel.h:8
float F0_from_ior(float eta)