Blender  V3.3
fresnel.h
Go to the documentation of this file.
1 /* SPDX-License-Identifier: Apache-2.0
2  * Copyright 2011-2022 Blender Foundation */
3 
4 #pragma once
5 
7 
8 /* Fresnel Node */
9 
11  ccl_private float *stack,
12  uint ior_offset,
13  uint ior_value,
14  uint node)
15 {
16  uint normal_offset, out_offset;
17  svm_unpack_node_uchar2(node, &normal_offset, &out_offset);
18  float eta = (stack_valid(ior_offset)) ? stack_load_float(stack, ior_offset) :
19  __uint_as_float(ior_value);
20  float3 normal_in = stack_valid(normal_offset) ? stack_load_float3(stack, normal_offset) : sd->N;
21 
22  eta = fmaxf(eta, 1e-5f);
23  eta = (sd->flag & SD_BACKFACING) ? 1.0f / eta : eta;
24 
25  float f = fresnel_dielectric_cos(dot(sd->I, normal_in), eta);
26 
27  stack_store_float(stack, out_offset, f);
28 }
29 
30 /* Layer Weight Node */
31 
33  ccl_private float *stack,
34  uint4 node)
35 {
36  uint blend_offset = node.y;
37  uint blend_value = node.z;
38 
39  uint type, normal_offset, out_offset;
40  svm_unpack_node_uchar3(node.w, &type, &normal_offset, &out_offset);
41 
42  float blend = (stack_valid(blend_offset)) ? stack_load_float(stack, blend_offset) :
43  __uint_as_float(blend_value);
44  float3 normal_in = (stack_valid(normal_offset)) ? stack_load_float3(stack, normal_offset) :
45  sd->N;
46 
47  float f;
48 
50  float eta = fmaxf(1.0f - blend, 1e-5f);
51  eta = (sd->flag & SD_BACKFACING) ? eta : 1.0f / eta;
52 
53  f = fresnel_dielectric_cos(dot(sd->I, normal_in), eta);
54  }
55  else {
56  f = fabsf(dot(sd->I, normal_in));
57 
58  if (blend != 0.5f) {
59  blend = clamp(blend, 0.0f, 1.0f - 1e-5f);
60  blend = (blend < 0.5f) ? 2.0f * blend : 0.5f / (1.0f - blend);
61 
62  f = powf(f, blend);
63  }
64 
65  f = 1.0f - f;
66  }
67 
68  stack_store_float(stack, out_offset, f);
69 }
70 
unsigned int uint
Definition: BLI_sys_types.h:67
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum type
ccl_device float fresnel_dielectric_cos(float cosi, float eta)
Definition: bsdf_util.h:79
#define ccl_private
Definition: cuda/compat.h:48
#define powf(x, y)
Definition: cuda/compat.h:103
#define ccl_device_noinline
Definition: cuda/compat.h:40
#define CCL_NAMESPACE_END
Definition: cuda/compat.h:9
OperationNode * node
ccl_device_noinline void svm_node_layer_weight(ccl_private ShaderData *sd, ccl_private float *stack, uint4 node)
Definition: fresnel.h:32
CCL_NAMESPACE_BEGIN ccl_device_noinline void svm_node_fresnel(ccl_private ShaderData *sd, ccl_private float *stack, uint ior_offset, uint ior_value, uint node)
Definition: fresnel.h:10
CCL_NAMESPACE_BEGIN ccl_device_inline float3 stack_load_float3(ccl_private float *stack, uint a)
ccl_device_forceinline void svm_unpack_node_uchar3(uint i, ccl_private uint *x, ccl_private uint *y, ccl_private uint *z)
ccl_device_forceinline void svm_unpack_node_uchar2(uint i, ccl_private uint *x, ccl_private uint *y)
ccl_device_inline void stack_store_float(ccl_private float *stack, uint a, float f)
ccl_device_inline float stack_load_float(ccl_private float *stack, uint a)
ccl_device_inline bool stack_valid(uint a)
@ NODE_LAYER_WEIGHT_FRESNEL
@ SD_BACKFACING
Definition: kernel/types.h:738
ShaderData
Definition: kernel/types.h:925
#define fmaxf(x, y)
Definition: metal/compat.h:228
#define fabsf(x)
Definition: metal/compat.h:219
T dot(const vec_base< T, Size > &a, const vec_base< T, Size > &b)
T clamp(const T &a, const T &min, const T &max)
static int blend(const Tex *tex, const float texvec[3], TexResult *texres)
ccl_device_inline float __uint_as_float(uint i)
Definition: util/math.h:273