Blender  V2.93
node_texture_bricks.c
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  *
16  * The Original Code is Copyright (C) 2005 Blender Foundation.
17  * All rights reserved.
18  */
19 
24 #include "NOD_texture.h"
25 #include "node_texture_util.h"
26 
27 #include <math.h>
28 
30  {SOCK_RGBA, N_("Bricks 1"), 0.596f, 0.282f, 0.0f, 1.0f},
31  {SOCK_RGBA, N_("Bricks 2"), 0.632f, 0.504f, 0.05f, 1.0f},
32  {SOCK_RGBA, N_("Mortar"), 0.0f, 0.0f, 0.0f, 1.0f},
33  {SOCK_FLOAT, N_("Thickness"), 0.02f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_UNSIGNED},
34  {SOCK_FLOAT, N_("Bias"), 0.0f, 0.0f, 0.0f, 0.0f, -1.0f, 1.0f, PROP_NONE},
35  {SOCK_FLOAT, N_("Brick Width"), 0.5f, 0.0f, 0.0f, 0.0f, 0.001f, 99.0f, PROP_UNSIGNED},
36  {SOCK_FLOAT, N_("Row Height"), 0.25f, 0.0f, 0.0f, 0.0f, 0.001f, 99.0f, PROP_UNSIGNED},
37  {-1, ""},
38 };
40  {SOCK_RGBA, N_("Color")},
41  {-1, ""},
42 };
43 
44 static void init(bNodeTree *UNUSED(ntree), bNode *node)
45 {
46  node->custom3 = 0.5; /* offset */
47  node->custom4 = 1.0; /* squash */
48 }
49 
50 static float noise(int n) /* fast integer noise */
51 {
52  int nn;
53  n = (n >> 13) ^ n;
54  nn = (n * (n * n * 60493 + 19990303) + 1376312589) & 0x7fffffff;
55  return 0.5f * ((float)nn / 1073741824.0f);
56 }
57 
58 static void colorfn(float *out, TexParams *p, bNode *node, bNodeStack **in, short thread)
59 {
60  const float *co = p->co;
61 
62  float x = co[0];
63  float y = co[1];
64 
65  int bricknum, rownum;
66  float offset = 0;
67  float ins_x, ins_y;
68  float tint;
69 
70  float bricks1[4];
71  float bricks2[4];
72  float mortar[4];
73 
74  float mortar_thickness = tex_input_value(in[3], p, thread);
75  float bias = tex_input_value(in[4], p, thread);
76  float brick_width = tex_input_value(in[5], p, thread);
77  float row_height = tex_input_value(in[6], p, thread);
78 
79  tex_input_rgba(bricks1, in[0], p, thread);
80  tex_input_rgba(bricks2, in[1], p, thread);
81  tex_input_rgba(mortar, in[2], p, thread);
82 
83  rownum = (int)floor(y / row_height);
84 
85  if (node->custom1 && node->custom2) {
86  brick_width *= ((int)(rownum) % node->custom2) ? 1.0f : node->custom4; /* squash */
87  offset = ((int)(rownum) % node->custom1) ? 0 : (brick_width * node->custom3); /* offset */
88  }
89 
90  bricknum = (int)floor((x + offset) / brick_width);
91 
92  ins_x = (x + offset) - brick_width * bricknum;
93  ins_y = y - row_height * rownum;
94 
95  tint = noise((rownum << 16) + (bricknum & 0xFFFF)) + bias;
96  CLAMP(tint, 0.0f, 1.0f);
97 
98  if (ins_x < mortar_thickness || ins_y < mortar_thickness ||
99  ins_x > (brick_width - mortar_thickness) || ins_y > (row_height - mortar_thickness)) {
100  copy_v4_v4(out, mortar);
101  }
102  else {
103  copy_v4_v4(out, bricks1);
104  ramp_blend(MA_RAMP_BLEND, out, tint, bricks2);
105  }
106 }
107 
108 static void exec(void *data,
109  int UNUSED(thread),
110  bNode *node,
111  bNodeExecData *execdata,
112  bNodeStack **in,
113  bNodeStack **out)
114 {
115  tex_output(node, execdata, in, out[0], &colorfn, data);
116 }
117 
119 {
120  static bNodeType ntype;
121 
125  node_type_init(&ntype, init);
126  node_type_exec(&ntype, NULL, NULL, exec);
127 
128  nodeRegisterType(&ntype);
129 }
typedef float(TangentPoint)[2]
void ramp_blend(int type, float r_col[3], const float fac, const float col[3])
Definition: material.c:1395
void node_type_socket_templates(struct bNodeType *ntype, struct bNodeSocketTemplate *inputs, struct bNodeSocketTemplate *outputs)
Definition: node.cc:4527
void node_type_init(struct bNodeType *ntype, void(*initfunc)(struct bNodeTree *ntree, struct bNode *node))
Definition: node.cc:4559
#define NODE_CLASS_PATTERN
Definition: BKE_node.h:345
void node_type_size_preset(struct bNodeType *ntype, eNodeSizePreset size)
Definition: node.cc:4577
void node_type_exec(struct bNodeType *ntype, NodeInitExecFunction init_exec_fn, NodeFreeExecFunction free_exec_fn, NodeExecFunction exec_fn)
Definition: node.cc:4635
void nodeRegisterType(struct bNodeType *ntype)
Definition: node.cc:1298
@ NODE_SIZE_MIDDLE
Definition: BKE_node.h:372
MINLINE void copy_v4_v4(float r[4], const float a[4])
#define UNUSED(x)
#define N_(msgid)
#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 RGB to Bright Vector Camera CLAMP
Group RGB to Bright Vector Camera Vector Combine Material Light Line Style Layer Add Ambient Diffuse Glossy Refraction Transparent Toon Principled Hair Volume Principled Light Particle Volume Image Sky Noise Wave Voronoi Brick Texture Vector Combine Vertex Separate Vector White RGB Map Separate Set Z Dilate Combine Combine Color Channel Split ID Combine Luminance Directional Alpha Distance Hue Movie Ellipse Bokeh View Corner Anti TEX_NODE_BRICKS
@ PROP_NONE
Definition: RNA_types.h:113
@ PROP_UNSIGNED
Definition: RNA_types.h:129
OperationNode * node
bNodeTree * ntree
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)
void tex_node_type_base(struct bNodeType *ntype, int type, const char *name, short nclass, short flag)
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.h:95
Defines a node type.
Definition: BKE_node.h:221
ccl_device_inline float2 floor(const float2 &a)