Blender V5.0
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
9#include "kernel/svm/util.h"
10
12
13/* Fresnel Node */
14
16 ccl_private float *stack,
17 const uint ior_offset,
18 const uint ior_value,
19 const uint node)
20{
21 uint normal_offset;
22 uint out_offset;
23 svm_unpack_node_uchar2(node, &normal_offset, &out_offset);
24 float eta = (stack_valid(ior_offset)) ? stack_load_float(stack, ior_offset) :
25 __uint_as_float(ior_value);
26 const float3 normal_in = stack_valid(normal_offset) ? stack_load_float3(stack, normal_offset) :
27 sd->N;
28
29 eta = fmaxf(eta, 1e-5f);
30 eta = (sd->flag & SD_BACKFACING) ? 1.0f / eta : eta;
31
32 const float f = fresnel_dielectric_cos(dot(sd->wi, normal_in), eta);
33
34 stack_store_float(stack, out_offset, f);
35}
36
37/* Layer Weight Node */
38
40 ccl_private float *stack,
41 const uint4 node)
42{
43 const uint blend_offset = node.y;
44 const uint blend_value = node.z;
45
46 uint type;
47 uint normal_offset;
48 uint out_offset;
49 svm_unpack_node_uchar3(node.w, &type, &normal_offset, &out_offset);
50
51 float blend = (stack_valid(blend_offset)) ? stack_load_float(stack, blend_offset) :
52 __uint_as_float(blend_value);
53 const float3 normal_in = (stack_valid(normal_offset)) ? stack_load_float3(stack, normal_offset) :
54 sd->N;
55
56 float f;
57
58 if (type == NODE_LAYER_WEIGHT_FRESNEL) {
59 float eta = fmaxf(1.0f - blend, 1e-5f);
60 eta = (sd->flag & SD_BACKFACING) ? eta : 1.0f / eta;
61
62 f = fresnel_dielectric_cos(dot(sd->wi, normal_in), eta);
63 }
64 else {
65 f = fabsf(dot(sd->wi, normal_in));
66
67 if (blend != 0.5f) {
68 blend = clamp(blend, 0.0f, 1.0f - 1e-5f);
69 blend = (blend < 0.5f) ? 2.0f * blend : 0.5f / (1.0f - blend);
70
71 f = powf(f, blend);
72 }
73
74 f = 1.0f - f;
75 }
76
77 stack_store_float(stack, out_offset, f);
78}
79
unsigned int uint
ccl_device float fresnel_dielectric_cos(const float cosi, const float eta)
Definition bsdf_util.h:110
dot(value.rgb, luminance_coefficients)") DEFINE_VALUE("REDUCE(lhs
ccl_device_inline float stack_load_float(const ccl_private float *stack, const uint a)
ccl_device_inline void stack_store_float(ccl_private float *stack, const uint a, const float f)
ccl_device_forceinline void svm_unpack_node_uchar2(const uint i, ccl_private uint *x, ccl_private uint *y)
ccl_device_forceinline void svm_unpack_node_uchar3(const uint i, ccl_private uint *x, ccl_private uint *y, ccl_private uint *z)
ccl_device_inline bool stack_valid(const uint a)
CCL_NAMESPACE_BEGIN ccl_device_inline float3 stack_load_float3(const ccl_private float *stack, const uint a)
#define ccl_private
#define ccl_device_noinline
#define powf(x, y)
#define CCL_NAMESPACE_END
#define __uint_as_float(x)
CCL_NAMESPACE_BEGIN ccl_device_noinline void svm_node_fresnel(ccl_private ShaderData *sd, ccl_private float *stack, const uint ior_offset, const uint ior_value, const uint node)
Definition fresnel.h:15
ccl_device_noinline void svm_node_layer_weight(ccl_private ShaderData *sd, ccl_private float *stack, const uint4 node)
Definition fresnel.h:39
constexpr T clamp(T, U, U) RET
@ NODE_LAYER_WEIGHT_FRESNEL
@ SD_BACKFACING
#define fabsf
#define fmaxf
uint y
Definition types_uint4.h:13
uint z
Definition types_uint4.h:13
uint w
Definition types_uint4.h:13
static int blend(const Tex *tex, const float texvec[3], TexResult *texres)