Blender  V3.3
node_texture_bricks.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later
2  * Copyright 2005 Blender Foundation. All rights reserved. */
3 
8 #include "NOD_texture.h"
9 #include "node_texture_util.h"
10 
11 #include <math.h>
12 
14  {SOCK_RGBA, N_("Bricks 1"), 0.596f, 0.282f, 0.0f, 1.0f},
15  {SOCK_RGBA, N_("Bricks 2"), 0.632f, 0.504f, 0.05f, 1.0f},
16  {SOCK_RGBA, N_("Mortar"), 0.0f, 0.0f, 0.0f, 1.0f},
17  {SOCK_FLOAT, N_("Thickness"), 0.02f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_UNSIGNED},
18  {SOCK_FLOAT, N_("Bias"), 0.0f, 0.0f, 0.0f, 0.0f, -1.0f, 1.0f, PROP_NONE},
19  {SOCK_FLOAT, N_("Brick Width"), 0.5f, 0.0f, 0.0f, 0.0f, 0.001f, 99.0f, PROP_UNSIGNED},
20  {SOCK_FLOAT, N_("Row Height"), 0.25f, 0.0f, 0.0f, 0.0f, 0.001f, 99.0f, PROP_UNSIGNED},
21  {-1, ""},
22 };
24  {SOCK_RGBA, N_("Color")},
25  {-1, ""},
26 };
27 
28 static void init(bNodeTree *UNUSED(ntree), bNode *node)
29 {
30  node->custom3 = 0.5; /* offset */
31  node->custom4 = 1.0; /* squash */
32 }
33 
34 static float noise(int n) /* fast integer noise */
35 {
36  int nn;
37  n = (n >> 13) ^ n;
38  nn = (n * (n * n * 60493 + 19990303) + 1376312589) & 0x7fffffff;
39  return 0.5f * ((float)nn / 1073741824.0f);
40 }
41 
42 static void colorfn(float *out, TexParams *p, bNode *node, bNodeStack **in, short thread)
43 {
44  const float *co = p->co;
45 
46  float x = co[0];
47  float y = co[1];
48 
49  int bricknum, rownum;
50  float offset = 0;
51  float ins_x, ins_y;
52  float tint;
53 
54  float bricks1[4];
55  float bricks2[4];
56  float mortar[4];
57 
58  float mortar_thickness = tex_input_value(in[3], p, thread);
59  float bias = tex_input_value(in[4], p, thread);
60  float brick_width = tex_input_value(in[5], p, thread);
61  float row_height = tex_input_value(in[6], p, thread);
62 
63  tex_input_rgba(bricks1, in[0], p, thread);
64  tex_input_rgba(bricks2, in[1], p, thread);
65  tex_input_rgba(mortar, in[2], p, thread);
66 
67  rownum = (int)floor(y / row_height);
68 
69  if (node->custom1 && node->custom2) {
70  brick_width *= ((int)(rownum) % node->custom2) ? 1.0f : node->custom4; /* squash */
71  offset = ((int)(rownum) % node->custom1) ? 0 : (brick_width * node->custom3); /* offset */
72  }
73 
74  bricknum = (int)floor((x + offset) / brick_width);
75 
76  ins_x = (x + offset) - brick_width * bricknum;
77  ins_y = y - row_height * rownum;
78 
79  tint = noise((rownum << 16) + (bricknum & 0xFFFF)) + bias;
80  CLAMP(tint, 0.0f, 1.0f);
81 
82  if (ins_x < mortar_thickness || ins_y < mortar_thickness ||
83  ins_x > (brick_width - mortar_thickness) || ins_y > (row_height - mortar_thickness)) {
84  copy_v4_v4(out, mortar);
85  }
86  else {
87  copy_v4_v4(out, bricks1);
88  ramp_blend(MA_RAMP_BLEND, out, tint, bricks2);
89  }
90 }
91 
92 static void exec(void *data,
93  int UNUSED(thread),
94  bNode *node,
95  bNodeExecData *execdata,
96  bNodeStack **in,
97  bNodeStack **out)
98 {
99  tex_output(node, execdata, in, out[0], &colorfn, data);
100 }
101 
103 {
104  static bNodeType ntype;
105 
109  node_type_init(&ntype, init);
110  node_type_exec(&ntype, NULL, NULL, exec);
111  ntype.flag |= NODE_PREVIEW;
112 
113  nodeRegisterType(&ntype);
114 }
typedef float(TangentPoint)[2]
void ramp_blend(int type, float r_col[3], float fac, const float col[3])
Definition: material.c:1611
void node_type_socket_templates(struct bNodeType *ntype, struct bNodeSocketTemplate *inputs, struct bNodeSocketTemplate *outputs)
Definition: node.cc:4358
#define TEX_NODE_BRICKS
Definition: BKE_node.h:1350
void node_type_init(struct bNodeType *ntype, void(*initfunc)(struct bNodeTree *ntree, struct bNode *node))
Definition: node.cc:4390
#define NODE_CLASS_PATTERN
Definition: BKE_node.h:354
void node_type_size_preset(struct bNodeType *ntype, eNodeSizePreset size)
Definition: node.cc:4408
void node_type_exec(struct bNodeType *ntype, NodeInitExecFunction init_exec_fn, NodeFreeExecFunction free_exec_fn, NodeExecFunction exec_fn)
Definition: node.cc:4455
void nodeRegisterType(struct bNodeType *ntype)
Definition: node.cc:1357
@ NODE_SIZE_MIDDLE
Definition: BKE_node.h:366
MINLINE void copy_v4_v4(float r[4], const float a[4])
#define UNUSED(x)
#define MA_RAMP_BLEND
#define NODE_PREVIEW
@ SOCK_FLOAT
@ SOCK_RGBA
_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
Group Output data from inside of a node group A color picker Mix two input colors RGB to Convert a color s luminance to a grayscale value Generate a normal vector and a dot product Bright Control the brightness and contrast of the input color Vector Map an input vectors to used to fine tune the interpolation of the input Camera Retrieve information about the camera and how it relates to the current shading point s position CLAMP
@ PROP_NONE
Definition: RNA_types.h:126
@ PROP_UNSIGNED
Definition: RNA_types.h:142
Definition: thread.h:34
OperationNode * node
bNodeTree * ntree
ccl_gpu_kernel_postfix ccl_global float int int int int float bool int offset
T floor(const T &a)
static const pxr::TfToken out("out", pxr::TfToken::Immortal)
void register_node_type_tex_bricks(void)
static float noise(int n)
static bNodeSocketTemplate outputs[]
static bNodeSocketTemplate inputs[]
static void exec(void *data, int UNUSED(thread), bNode *node, bNodeExecData *execdata, bNodeStack **in, bNodeStack **out)
static void colorfn(float *out, TexParams *p, bNode *node, bNodeStack **in, short thread)
static void init(bNodeTree *UNUSED(ntree), bNode *node)
float tex_input_value(bNodeStack *in, TexParams *params, short thread)
void tex_input_rgba(float *out, bNodeStack *in, TexParams *params, short thread)
void tex_node_type_base(struct bNodeType *ntype, int type, const char *name, short nclass)
void tex_output(bNode *node, bNodeExecData *execdata, bNodeStack **in, bNodeStack *out, TexFn texfn, TexCallData *cdata)
const float * co
Compact definition of a node socket.
Definition: BKE_node.h:84
Defines a node type.
Definition: BKE_node.h:226
short flag
Definition: BKE_node.h:236
#define N_(msgid)