Blender V5.3
brick.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#include "kernel/svm/util.h"
9
11
12/* Brick */
13
14ccl_device_inline float brick_noise(uint n) /* fast integer noise */
15{
16 uint nn;
17 n = (n + 1013) & 0x7fffffff;
18 n = (n >> 13) ^ n;
19 nn = (n * (n * n * 60493 + 19990303) + 1376312589) & 0x7fffffff;
20 return 0.5f * ((float)nn / 1073741824.0f);
21}
22
24 const float mortar_size,
25 const float mortar_smooth,
26 const float bias,
27 float brick_width,
28 const float row_height,
29 const float offset_amount,
30 const int offset_frequency,
31 const float squash_amount,
32 const int squash_frequency)
33{
34 int bricknum;
35 int rownum;
36 float offset = 0.0f;
37 float x;
38 float y;
39
40 rownum = floor_to_int(p.y / row_height);
41
42 if (offset_frequency && squash_frequency) {
43 brick_width *= (rownum % squash_frequency) ? 1.0f : squash_amount; /* squash */
44 offset = (rownum % offset_frequency) ? 0.0f : (brick_width * offset_amount); /* offset */
45 }
46
47 bricknum = floor_to_int((p.x + offset) / brick_width);
48
49 x = (p.x + offset) - brick_width * bricknum;
50 y = p.y - row_height * rownum;
51
52 const float tint = saturatef((brick_noise((rownum << 16) + (bricknum & 0xFFFF)) + bias));
53 float min_dist = min(min(x, y), min(brick_width - x, row_height - y));
54
55 float mortar;
56 if (min_dist >= mortar_size) {
57 mortar = 0.0f;
58 }
59 else if (mortar_smooth == 0.0f) {
60 mortar = 1.0f;
61 }
62 else {
63 min_dist = 1.0f - min_dist / mortar_size;
64 mortar = smoothstepf(min_dist / mortar_smooth);
65 }
66
67 return make_float2(tint, mortar);
68}
69
72{
73 const float3 co = stack_load_float3(stack, node.co);
74
75 float3 color1 = stack_load(stack, node.color1);
76 const float3 color2 = stack_load(stack, node.color2);
77 const float3 mortar = stack_load(stack, node.mortar);
78
79 const float scale = stack_load(stack, node.scale);
80 const float mortar_size = stack_load(stack, node.mortar_size);
81 const float mortar_smooth = stack_load(stack, node.mortar_smooth);
82 const float bias = stack_load(stack, node.bias);
83 const float brick_width = stack_load(stack, node.brick_width);
84 const float row_height = stack_load(stack, node.row_height);
85
86 const float2 f2 = svm_brick(co * scale,
87 mortar_size,
88 mortar_smooth,
89 bias,
90 brick_width,
91 row_height,
92 node.offset_amount,
93 node.offset_frequency,
94 node.squash_amount,
95 node.squash_frequency);
96
97 const float tint = f2.x;
98 const float f = f2.y;
99
100 if (f != 1.0f) {
101 const float facm = 1.0f - tint;
102 color1 = facm * color1 + tint * color2;
103 }
104
105 if (stack_valid(node.color_offset)) {
106 stack_store_float3(stack, node.color_offset, color1 * (1.0f - f) + mortar * f);
107 }
108 if (stack_valid(node.fac_offset)) {
109 stack_store_float(stack, node.fac_offset, f);
110 }
111}
112
ccl_device_noinline void svm_node_tex_brick(ccl_private float *ccl_restrict stack, const ccl_global SVMNodeTexBrick &ccl_restrict node)
Definition brick.h:70
ccl_device_noinline_cpu float2 svm_brick(const float3 p, const float mortar_size, const float mortar_smooth, const float bias, float brick_width, const float row_height, const float offset_amount, const int offset_frequency, const float squash_amount, const int squash_frequency)
Definition brick.h:23
CCL_NAMESPACE_BEGIN ccl_device_inline float brick_noise(uint n)
Definition brick.h:14
ccl_device_inline void stack_store_float(ccl_private float *stack, const uint a, const float f)
ccl_device_inline float3 stack_load_float3(const ccl_private float *stack, const uint a)
ccl_device_inline void stack_store_float3(ccl_private float *stack, const uint a, const float3 f)
ccl_device_inline bool stack_valid(const uint a)
ccl_device_inline T stack_load(const ccl_private float *stack, const uint a)
#define ccl_restrict
#define ccl_private
#define ccl_device_noinline_cpu
#define ccl_device_inline
#define ccl_global
#define ccl_device_noinline
#define CCL_NAMESPACE_END
#define saturatef(x)
float3x3 scale(float3x3 mat, float2 scale)
ccl_device_inline float smoothstepf(const float f)
Definition math_base.h:532
ccl_device_inline int floor_to_int(const float f)
Definition math_base.h:459
#define make_float2
KERNEL_FEATURE_LIGHT_PASSES KERNEL_FEATURE_PATH_GUIDING float
#define min(a, b)
Definition sort.cc:38
float x
float y
float y
Definition sky_math.h:136
float x
Definition sky_math.h:136