Blender V5.3
gpu_shader_material_layer_weight.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
9
10[[node]]
11void node_layer_weight(float blend,
12 float3 N,
14 ShadingData &sd,
15 float &fresnel,
16 float &facing)
17{
18 N = normalize(N);
19
20 /* fresnel */
21 float eta = max(1.0f - blend, 0.00001f);
22 float3 V = coordinate_impl(kg, sd, sd.P, sd.N).incoming;
23
24 fresnel = fresnel_dielectric(V, N, (sd.front_facing) ? 1.0f / eta : eta);
25
26 /* facing */
27 facing = abs(dot(V, N));
28 if (blend != 0.5f) {
29 blend = clamp(blend, 0.0f, 0.99999f);
30 blend = (blend < 0.5f) ? 2.0f * blend : 0.5f / (1.0f - blend);
31 facing = pow(facing, blend);
32 }
33 facing = 1.0f - facing;
34}
btScalar max
Coordinates coordinate_impl(KernelGlobals &kg, const ShadingData &sd, float3 P, float3 N)
#define resource_table
#define pow
VecBase< float, D > normalize(VecOp< float, D >) RET
float dot(VecOp< float, D >, VecOp< float, D >) RET
#define abs
constexpr T clamp(T, U, U) RET
float fresnel_dielectric(float3 Incoming, float3 Normal, float eta)
void node_layer_weight(float blend, float3 N, KernelGlobals &kg, ShadingData &sd, float &fresnel, float &facing)
#define N
CCL_NAMESPACE_BEGIN struct Window V