Blender V5.3
fresnel.h
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2011-2022 Blender Foundation
2 *
3 * SPDX-License-Identifier: Apache-2.0 */
4
5#pragma once
6
8
10#include "kernel/svm/util.h"
11
13
14/* Fresnel Node */
15
17 ccl_private float *ccl_restrict stack,
19{
20 float eta = stack_load(stack, node.ior);
21 const float3 normal_in = stack_load_float3_default(stack, node.normal_offset, sd->N);
22
23 eta = fmaxf(eta, 1e-5f);
24 eta = (sd->runtime_flag & SR_BACKFACING) ? 1.0f / eta : eta;
25
26 const float f = fresnel_dielectric_cos(dot(sd->wi, normal_in), eta);
27
28 stack_store_float(stack, node.out_offset, f);
29}
30
31/* Layer Weight Node */
32
34 ccl_private float *ccl_restrict stack,
36 node)
37{
38 float blend = stack_load(stack, node.blend);
39 const float3 normal_in = stack_load_float3_default(stack, node.normal_offset, sd->N);
40
41 float f;
42
43 if (node.weight_type == NODE_LAYER_WEIGHT_FRESNEL) {
44 float eta = fmaxf(1.0f - blend, 1e-5f);
45 eta = (sd->runtime_flag & SR_BACKFACING) ? eta : 1.0f / eta;
46
47 f = fresnel_dielectric_cos(dot(sd->wi, normal_in), eta);
48 }
49 else {
50 f = fabsf(dot(sd->wi, normal_in));
51
52 if (blend != 0.5f) {
53 blend = clamp(blend, 0.0f, 1.0f - 1e-5f);
54 blend = (blend < 0.5f) ? 2.0f * blend : 0.5f / (1.0f - blend);
55
56 f = powf(f, blend);
57 }
58
59 f = 1.0f - f;
60 }
61
62 stack_store_float(stack, node.out_offset, f);
63}
64
ccl_device_inline float3 stack_load_float3_default(const ccl_private float *stack, const uint a, const float3 value)
ccl_device_inline void stack_store_float(ccl_private float *stack, const uint a, const float f)
ccl_device_inline T stack_load(const ccl_private float *stack, const uint a)
#define ccl_restrict
#define ccl_private
#define ccl_global
#define ccl_device_noinline
#define powf(x, y)
#define CCL_NAMESPACE_END
ccl_device_noinline void svm_node_layer_weight(ccl_private ShaderData *sd, ccl_private float *ccl_restrict stack, const ccl_global SVMNodeLayerWeight &ccl_restrict node)
Definition fresnel.h:33
CCL_NAMESPACE_BEGIN ccl_device_noinline void svm_node_fresnel(ccl_private ShaderData *sd, ccl_private float *ccl_restrict stack, const ccl_global SVMNodeFresnel &ccl_restrict node)
Definition fresnel.h:16
float dot(VecOp< float, D >, VecOp< float, D >) RET
constexpr T clamp(T, U, U) RET
float fresnel_dielectric_cos(float cosi, float eta)
@ NODE_LAYER_WEIGHT_FRESNEL
@ SR_BACKFACING
#define fabsf
#define fmaxf