Blender  V3.3
brick.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 /* Brick */
9 
10 ccl_device_inline float brick_noise(uint n) /* fast integer noise */
11 {
12  uint nn;
13  n = (n + 1013) & 0x7fffffff;
14  n = (n >> 13) ^ n;
15  nn = (n * (n * n * 60493 + 19990303) + 1376312589) & 0x7fffffff;
16  return 0.5f * ((float)nn / 1073741824.0f);
17 }
18 
20  float mortar_size,
21  float mortar_smooth,
22  float bias,
23  float brick_width,
24  float row_height,
25  float offset_amount,
26  int offset_frequency,
27  float squash_amount,
28  int squash_frequency)
29 {
30  int bricknum, rownum;
31  float offset = 0.0f;
32  float x, y;
33 
34  rownum = floor_to_int(p.y / row_height);
35 
36  if (offset_frequency && squash_frequency) {
37  brick_width *= (rownum % squash_frequency) ? 1.0f : squash_amount; /* squash */
38  offset = (rownum % offset_frequency) ? 0.0f : (brick_width * offset_amount); /* offset */
39  }
40 
41  bricknum = floor_to_int((p.x + offset) / brick_width);
42 
43  x = (p.x + offset) - brick_width * bricknum;
44  y = p.y - row_height * rownum;
45 
46  float tint = saturatef((brick_noise((rownum << 16) + (bricknum & 0xFFFF)) + bias));
47  float min_dist = min(min(x, y), min(brick_width - x, row_height - y));
48 
49  float mortar;
50  if (min_dist >= mortar_size) {
51  mortar = 0.0f;
52  }
53  else if (mortar_smooth == 0.0f) {
54  mortar = 1.0f;
55  }
56  else {
57  min_dist = 1.0f - min_dist / mortar_size;
58  mortar = (min_dist < mortar_smooth) ? smoothstepf(min_dist / mortar_smooth) : 1.0f;
59  }
60 
61  return make_float2(tint, mortar);
62 }
63 
65  KernelGlobals kg, ccl_private ShaderData *sd, ccl_private float *stack, uint4 node, int offset)
66 {
67  uint4 node2 = read_node(kg, &offset);
68  uint4 node3 = read_node(kg, &offset);
69  uint4 node4 = read_node(kg, &offset);
70 
71  /* Input and Output Sockets */
72  uint co_offset, color1_offset, color2_offset, mortar_offset, scale_offset;
73  uint mortar_size_offset, bias_offset, brick_width_offset, row_height_offset;
74  uint color_offset, fac_offset, mortar_smooth_offset;
75 
76  /* RNA properties */
77  uint offset_frequency, squash_frequency;
78 
79  svm_unpack_node_uchar4(node.y, &co_offset, &color1_offset, &color2_offset, &mortar_offset);
81  node.z, &scale_offset, &mortar_size_offset, &bias_offset, &brick_width_offset);
83  node.w, &row_height_offset, &color_offset, &fac_offset, &mortar_smooth_offset);
84 
85  svm_unpack_node_uchar2(node2.x, &offset_frequency, &squash_frequency);
86 
87  float3 co = stack_load_float3(stack, co_offset);
88 
89  float3 color1 = stack_load_float3(stack, color1_offset);
90  float3 color2 = stack_load_float3(stack, color2_offset);
91  float3 mortar = stack_load_float3(stack, mortar_offset);
92 
93  float scale = stack_load_float_default(stack, scale_offset, node2.y);
94  float mortar_size = stack_load_float_default(stack, mortar_size_offset, node2.z);
95  float mortar_smooth = stack_load_float_default(stack, mortar_smooth_offset, node4.x);
96  float bias = stack_load_float_default(stack, bias_offset, node2.w);
97  float brick_width = stack_load_float_default(stack, brick_width_offset, node3.x);
98  float row_height = stack_load_float_default(stack, row_height_offset, node3.y);
99  float offset_amount = __int_as_float(node3.z);
100  float squash_amount = __int_as_float(node3.w);
101 
102  float2 f2 = svm_brick(co * scale,
103  mortar_size,
104  mortar_smooth,
105  bias,
106  brick_width,
107  row_height,
108  offset_amount,
109  offset_frequency,
110  squash_amount,
111  squash_frequency);
112 
113  float tint = f2.x;
114  float f = f2.y;
115 
116  if (f != 1.0f) {
117  float facm = 1.0f - tint;
118  color1 = facm * color1 + tint * color2;
119  }
120 
121  if (stack_valid(color_offset))
122  stack_store_float3(stack, color_offset, color1 * (1.0f - f) + mortar * f);
123  if (stack_valid(fac_offset))
124  stack_store_float(stack, fac_offset, f);
125  return offset;
126 }
127 
typedef float(TangentPoint)[2]
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 const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint y
ccl_device_noinline int svm_node_tex_brick(KernelGlobals kg, ccl_private ShaderData *sd, ccl_private float *stack, uint4 node, int offset)
Definition: brick.h:64
CCL_NAMESPACE_BEGIN ccl_device_inline float brick_noise(uint n)
Definition: brick.h:10
ccl_device_noinline_cpu float2 svm_brick(float3 p, float mortar_size, float mortar_smooth, float bias, float brick_width, float row_height, float offset_amount, int offset_frequency, float squash_amount, int squash_frequency)
Definition: brick.h:19
#define ccl_private
Definition: cuda/compat.h:48
#define ccl_device_noinline_cpu
Definition: cuda/compat.h:41
#define ccl_device_inline
Definition: cuda/compat.h:34
#define ccl_device_noinline
Definition: cuda/compat.h:40
#define CCL_NAMESPACE_END
Definition: cuda/compat.h:9
OperationNode * node
const KernelGlobalsCPU *ccl_restrict KernelGlobals
ccl_gpu_kernel_postfix ccl_global float int int int int float bool int offset
ccl_device_inline void stack_store_float3(ccl_private float *stack, uint a, float3 f)
CCL_NAMESPACE_BEGIN ccl_device_inline float3 stack_load_float3(ccl_private float *stack, uint a)
ccl_device_inline uint4 read_node(KernelGlobals kg, ccl_private int *offset)
ccl_device_forceinline void svm_unpack_node_uchar2(uint i, ccl_private uint *x, ccl_private uint *y)
ccl_device_inline float stack_load_float_default(ccl_private float *stack, uint a, uint value)
ccl_device_inline void stack_store_float(ccl_private float *stack, uint a, float f)
ccl_device_forceinline void svm_unpack_node_uchar4(uint i, ccl_private uint *x, ccl_private uint *y, ccl_private uint *z, ccl_private uint *w)
ccl_device_inline bool stack_valid(uint a)
ShaderData
Definition: kernel/types.h:925
#define make_float2(x, y)
Definition: metal/compat.h:203
#define min(a, b)
Definition: sort.c:35
float x
Definition: types_float2.h:15
float y
Definition: types_float2.h:15
float y
float x
uint x
Definition: types_uint4.h:15
uint y
Definition: types_uint4.h:15
uint z
Definition: types_uint4.h:15
uint w
Definition: types_uint4.h:15
ccl_device_inline float saturatef(float a)
Definition: util/math.h:404
ccl_device_inline int floor_to_int(float f)
Definition: util/math.h:415
ccl_device_inline float smoothstepf(float f)
Definition: util/math.h:484
ccl_device_inline float __int_as_float(int i)
Definition: util/math.h:253