Blender V5.0
checker.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
7#include "kernel/svm/util.h"
8
10
11/* Checker */
12
14{
15 /* avoid precision issues on unit coordinates */
16 p.x = (p.x + 0.000001f) * 0.999999f;
17 p.y = (p.y + 0.000001f) * 0.999999f;
18 p.z = (p.z + 0.000001f) * 0.999999f;
19
20 const int xi = abs(float_to_int(floorf(p.x)));
21 const int yi = abs(float_to_int(floorf(p.y)));
22 const int zi = abs(float_to_int(floorf(p.z)));
23
24 return ((xi % 2 == yi % 2) == (zi % 2)) ? 1.0f : 0.0f;
25}
26
28{
29 uint co_offset;
30 uint color1_offset;
31 uint color2_offset;
32 uint scale_offset;
33 uint color_offset;
34 uint fac_offset;
35
36 svm_unpack_node_uchar4(node.y, &co_offset, &color1_offset, &color2_offset, &scale_offset);
37 svm_unpack_node_uchar2(node.z, &color_offset, &fac_offset);
38
39 const float3 co = stack_load_float3(stack, co_offset);
40 const float3 color1 = stack_load_float3(stack, color1_offset);
41 const float3 color2 = stack_load_float3(stack, color2_offset);
42 const float scale = stack_load_float_default(stack, scale_offset, node.w);
43
44 const float f = svm_checker(co * scale);
45
46 if (stack_valid(color_offset)) {
47 stack_store_float3(stack, color_offset, (f == 1.0f) ? color1 : color2);
48 }
49 if (stack_valid(fac_offset)) {
50 stack_store_float(stack, fac_offset, f);
51 }
52}
53
unsigned int uint
ccl_device_noinline void svm_node_tex_checker(ccl_private float *stack, const uint4 node)
Definition checker.h:27
CCL_NAMESPACE_BEGIN ccl_device float svm_checker(float3 p)
Definition checker.h:13
ccl_device_inline void stack_store_float(ccl_private float *stack, const uint a, const float f)
ccl_device_inline void stack_store_float3(ccl_private float *stack, const uint a, const float3 f)
ccl_device_inline float stack_load_float_default(const ccl_private float *stack, const uint a, const uint value)
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_uchar4(const uint i, ccl_private uint *x, ccl_private uint *y, ccl_private uint *z, ccl_private uint *w)
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 CCL_NAMESPACE_END
#define abs
ccl_device_inline int float_to_int(const float f)
Definition math_base.h:407
#define floorf
#define ccl_device
float z
Definition sky_math.h:136
float y
Definition sky_math.h:136
float x
Definition sky_math.h:136
uint y
Definition types_uint4.h:13
uint z
Definition types_uint4.h:13
uint w
Definition types_uint4.h:13