Blender  V2.93
svm_fresnel.h
Go to the documentation of this file.
1 /*
2  * Copyright 2011-2013 Blender Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
18 
19 /* Fresnel Node */
20 
22  ShaderData *sd, float *stack, uint ior_offset, uint ior_value, uint node)
23 {
24  uint normal_offset, out_offset;
25  svm_unpack_node_uchar2(node, &normal_offset, &out_offset);
26  float eta = (stack_valid(ior_offset)) ? stack_load_float(stack, ior_offset) :
27  __uint_as_float(ior_value);
28  float3 normal_in = stack_valid(normal_offset) ? stack_load_float3(stack, normal_offset) : sd->N;
29 
30  eta = fmaxf(eta, 1e-5f);
31  eta = (sd->flag & SD_BACKFACING) ? 1.0f / eta : eta;
32 
33  float f = fresnel_dielectric_cos(dot(sd->I, normal_in), eta);
34 
35  stack_store_float(stack, out_offset, f);
36 }
37 
38 /* Layer Weight Node */
39 
41 {
42  uint blend_offset = node.y;
43  uint blend_value = node.z;
44 
45  uint type, normal_offset, out_offset;
46  svm_unpack_node_uchar3(node.w, &type, &normal_offset, &out_offset);
47 
48  float blend = (stack_valid(blend_offset)) ? stack_load_float(stack, blend_offset) :
49  __uint_as_float(blend_value);
50  float3 normal_in = (stack_valid(normal_offset)) ? stack_load_float3(stack, normal_offset) :
51  sd->N;
52 
53  float f;
54 
56  float eta = fmaxf(1.0f - blend, 1e-5f);
57  eta = (sd->flag & SD_BACKFACING) ? eta : 1.0f / eta;
58 
59  f = fresnel_dielectric_cos(dot(sd->I, normal_in), eta);
60  }
61  else {
62  f = fabsf(dot(sd->I, normal_in));
63 
64  if (blend != 0.5f) {
65  blend = clamp(blend, 0.0f, 1.0f - 1e-5f);
66  blend = (blend < 0.5f) ? 2.0f * blend : 0.5f / (1.0f - blend);
67 
68  f = powf(f, blend);
69  }
70 
71  f = 1.0f - f;
72  }
73 
74  stack_store_float(stack, out_offset, f);
75 }
76 
unsigned int uint
Definition: BLI_sys_types.h:83
_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:104
OperationNode * node
CCL_NAMESPACE_BEGIN ccl_device_inline float3 stack_load_float3(float *stack, uint a)
ccl_device_inline float stack_load_float(float *stack, uint a)
ccl_device_forceinline void svm_unpack_node_uchar3(uint i, uint *x, uint *y, uint *z)
ccl_device_inline void stack_store_float(float *stack, uint a, float f)
ccl_device_forceinline void svm_unpack_node_uchar2(uint i, uint *x, uint *y)
ccl_device_inline bool stack_valid(uint a)
#define ccl_device
#define powf(x, y)
#define CCL_NAMESPACE_END
#define fmaxf(x, y)
#define fabsf(x)
@ SD_BACKFACING
Definition: kernel_types.h:843
ShaderData
ccl_device void svm_node_layer_weight(ShaderData *sd, float *stack, uint4 node)
Definition: svm_fresnel.h:40
CCL_NAMESPACE_BEGIN ccl_device void svm_node_fresnel(ShaderData *sd, float *stack, uint ior_offset, uint ior_value, uint node)
Definition: svm_fresnel.h:21
@ NODE_LAYER_WEIGHT_FRESNEL
Definition: svm_types.h:454
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:232
ccl_device_inline int clamp(int a, int mn, int mx)
Definition: util_math.h:283
ccl_device_inline float dot(const float2 &a, const float2 &b)