Blender V4.3
node_texture_bricks.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2005 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
9#include "BKE_material.h"
10#include "BLI_math_vector.h"
11#include "DNA_material_types.h"
12#include "node_texture_util.hh"
13
14#include <cmath>
15
17 {SOCK_RGBA, N_("Bricks 1"), 0.596f, 0.282f, 0.0f, 1.0f},
18 {SOCK_RGBA, N_("Bricks 2"), 0.632f, 0.504f, 0.05f, 1.0f},
19 {SOCK_RGBA, N_("Mortar"), 0.0f, 0.0f, 0.0f, 1.0f},
20 {SOCK_FLOAT, N_("Thickness"), 0.02f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_UNSIGNED},
21 {SOCK_FLOAT, N_("Bias"), 0.0f, 0.0f, 0.0f, 0.0f, -1.0f, 1.0f, PROP_NONE},
22 {SOCK_FLOAT, N_("Brick Width"), 0.5f, 0.0f, 0.0f, 0.0f, 0.001f, 99.0f, PROP_UNSIGNED},
23 {SOCK_FLOAT, N_("Row Height"), 0.25f, 0.0f, 0.0f, 0.0f, 0.001f, 99.0f, PROP_UNSIGNED},
24 {-1, ""},
25};
27 {SOCK_RGBA, N_("Color")},
28 {-1, ""},
29};
30
31static void init(bNodeTree * /*ntree*/, bNode *node)
32{
33 node->custom3 = 0.5; /* offset */
34 node->custom4 = 1.0; /* squash */
35}
36
37static float noise(int n) /* fast integer noise */
38{
39 int nn;
40 n = (n >> 13) ^ n;
41 nn = (n * (n * n * 60493 + 19990303) + 1376312589) & 0x7fffffff;
42 return 0.5f * (float(nn) / 1073741824.0f);
43}
44
45static void colorfn(float *out, TexParams *p, bNode *node, bNodeStack **in, short thread)
46{
47 const float *co = p->co;
48
49 float x = co[0];
50 float y = co[1];
51
52 int bricknum, rownum;
53 float offset = 0;
54 float ins_x, ins_y;
55 float tint;
56
57 float bricks1[4];
58 float bricks2[4];
59 float mortar[4];
60
61 float mortar_thickness = tex_input_value(in[3], p, thread);
62 float bias = tex_input_value(in[4], p, thread);
63 float brick_width = tex_input_value(in[5], p, thread);
64 float row_height = tex_input_value(in[6], p, thread);
65
66 tex_input_rgba(bricks1, in[0], p, thread);
67 tex_input_rgba(bricks2, in[1], p, thread);
68 tex_input_rgba(mortar, in[2], p, thread);
69
70 rownum = int(floor(y / row_height));
71
72 if (node->custom1 && node->custom2) {
73 brick_width *= (int(rownum) % node->custom2) ? 1.0f : node->custom4; /* squash */
74 offset = (int(rownum) % node->custom1) ? 0 : (brick_width * node->custom3); /* offset */
75 }
76
77 bricknum = int(floor((x + offset) / brick_width));
78
79 ins_x = (x + offset) - brick_width * bricknum;
80 ins_y = y - row_height * rownum;
81
82 tint = noise((rownum << 16) + (bricknum & 0xFFFF)) + bias;
83 CLAMP(tint, 0.0f, 1.0f);
84
85 if (ins_x < mortar_thickness || ins_y < mortar_thickness ||
86 ins_x > (brick_width - mortar_thickness) || ins_y > (row_height - mortar_thickness))
87 {
88 copy_v4_v4(out, mortar);
89 }
90 else {
91 copy_v4_v4(out, bricks1);
92 ramp_blend(MA_RAMP_BLEND, out, tint, bricks2);
93 }
94}
95
96static void exec(void *data,
97 int /*thread*/,
98 bNode *node,
99 bNodeExecData *execdata,
100 bNodeStack **in,
101 bNodeStack **out)
102{
103 tex_output(node, execdata, in, out[0], &colorfn, static_cast<TexCallData *>(data));
104}
105
107{
108 static blender::bke::bNodeType ntype;
109
110 tex_node_type_base(&ntype, TEX_NODE_BRICKS, "Bricks", NODE_CLASS_PATTERN);
111 blender::bke::node_type_socket_templates(&ntype, inputs, outputs);
113 ntype.initfunc = init;
114 ntype.exec_fn = exec;
115 ntype.flag |= NODE_PREVIEW;
116
118}
General operations, lookup, etc. for materials.
void ramp_blend(int type, float r_col[3], float fac, const float col[3])
#define NODE_CLASS_PATTERN
Definition BKE_node.hh:413
MINLINE void copy_v4_v4(float r[4], const float a[4])
#define CLAMP(a, b, c)
@ MA_RAMP_BLEND
@ NODE_PREVIEW
@ SOCK_FLOAT
@ SOCK_RGBA
@ PROP_NONE
Definition RNA_types.hh:136
@ PROP_UNSIGNED
Definition RNA_types.hh:152
void init()
draw_view in_light_buf[] float
draw_view push_constant(Type::INT, "radiance_src") .push_constant(Type capture_info_buf storage_buf(1, Qualifier::READ, "ObjectBounds", "bounds_buf[]") .push_constant(Type draw_view int
ccl_device_inline float2 floor(const float2 a)
void node_type_size_preset(bNodeType *ntype, eNodeSizePreset size)
Definition node.cc:4614
void node_type_socket_templates(bNodeType *ntype, bNodeSocketTemplate *inputs, bNodeSocketTemplate *outputs)
Definition node.cc:4570
void node_register_type(bNodeType *ntype)
Definition node.cc:1708
static void exec(void *data, int, bNode *node, bNodeExecData *execdata, bNodeStack **in, bNodeStack **out)
void register_node_type_tex_bricks()
static void colorfn(float *out, TexParams *p, bNode *node, bNodeStack **in, short thread)
void tex_node_type_base(blender::bke::bNodeType *ntype, int type, const char *name, short nclass)
float tex_input_value(bNodeStack *in, TexParams *params, short thread)
void tex_input_rgba(float *out, bNodeStack *in, TexParams *params, short thread)
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.hh:103
Defines a node type.
Definition BKE_node.hh:218
NodeExecFunction exec_fn
Definition BKE_node.hh:316
void(* initfunc)(bNodeTree *ntree, bNode *node)
Definition BKE_node.hh:267
#define N_(msgid)