Blender V5.3
gpu_shader_material_fresnel.bsl.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2019-2022 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
5#pragma once
6
8
9float fresnel_dielectric_cos(float cosi, float eta)
10{
11 /* compute fresnel reflectance without explicitly computing
12 * the refracted direction */
13 float c = abs(cosi);
14 float g = eta * eta - 1.0f + c * c;
15 float result;
16
17 if (g > 0.0f) {
18 g = sqrt(g);
19 float A = (g - c) / (g + c);
20 float B = (c * (g + c) - 1.0f) / (c * (g - c) + 1.0f);
21 result = 0.5f * A * A * (1.0f + B * B);
22 }
23 else {
24 result = 1.0f; /* TIR (no refracted component) */
25 }
26
27 return result;
28}
29
30float fresnel_dielectric(float3 Incoming, float3 Normal, float eta)
31{
32 /* compute fresnel reflectance without explicitly computing
33 * the refracted direction */
34 return fresnel_dielectric_cos(dot(Incoming, Normal), eta);
35}
36
37[[node]]
39 float ior, float3 N, [[resource_table]] KernelGlobals &kg, ShadingData &sd, float &result)
40{
41 N = normalize(N);
42 float3 V = coordinate_impl(kg, sd, sd.P, sd.N).incoming;
43
44 float eta = max(ior, 0.00001f);
45 result = fresnel_dielectric(V, N, sd.front_facing ? eta : 1.0f / eta);
46}
#define A
btScalar max
Coordinates coordinate_impl(KernelGlobals &kg, const ShadingData &sd, float3 P, float3 N)
#define resource_table
VecBase< float, D > normalize(VecOp< float, D >) RET
float dot(VecOp< float, D >, VecOp< float, D >) RET
#define abs
#define sqrt
void node_fresnel(float ior, float3 N, KernelGlobals &kg, ShadingData &sd, float &result)
float fresnel_dielectric_cos(float cosi, float eta)
float fresnel_dielectric(float3 Incoming, float3 Normal, float eta)
#define N
#define B
CCL_NAMESPACE_BEGIN struct Window V