2
* Copyright 2012, Blender Foundation.
4
* This program is free software; you can redistribute it and/or
5
* modify it under the terms of the GNU General Public License
6
* as published by the Free Software Foundation; either version 2
7
* of the License, or (at your option) any later version.
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
14
* You should have received a copy of the GNU General Public License
15
* along with this program; if not, write to the Free Software Foundation,
16
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20
#include "node_texture.h"
24
float brick_noise(int n) /* fast integer noise */
28
nn = (n * (n * n * 60493 + 19990303) + 1376312589) & 2147483647;
29
return 0.5 * ((float)nn / 1073741824.0);
32
float brick(point p, float mortar_size, float bias,
33
float BrickWidth, float row_height, float offset_amount, int offset_frequency,
34
float squash_amount, int squash_frequency, float tint)
38
float brick_width = BrickWidth;
41
rownum = (int)floor(p[1] / row_height);
43
if (offset_frequency && squash_frequency) {
44
brick_width *= ((int)(rownum) % squash_frequency) ? 1.0 : squash_amount; /* squash */
45
offset = ((int)(rownum) % offset_frequency) ? 0 : (brick_width * offset_amount); /* offset */
48
bricknum = (int)floor((p[0] + offset) / brick_width);
50
x = (p[0] + offset) - brick_width * bricknum;
51
y = p[1] - row_height * rownum;
53
tint = clamp((brick_noise((rownum << 16) + (bricknum & 65535)) + bias), 0.0, 1.0);
55
return (x < mortar_size || y < mortar_size ||
56
x > (brick_width - mortar_size) ||
57
y > (row_height - mortar_size)) ? 1.0 : 0.0;
60
shader node_brick_texture(
62
matrix mapping = matrix(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0),
64
int OffsetFrequency = 2,
66
int SquashFrequency = 1,
72
float MortarSize = 0.02,
74
float BrickWidth = 0.5,
75
float RowHeight = 0.25,
76
output float Fac = 0.0,
77
output color Color = 0.2)
82
p = transform(mapping, p);
87
Fac = brick(p * Scale, MortarSize, Bias, BrickWidth, RowHeight,
88
Offset, OffsetFrequency, Squash, SquashFrequency, tint);
91
float facm = 1.0 - tint;
93
Col[0] = facm * (Color1[0]) + tint * Color2[0];
94
Col[1] = facm * (Color1[1]) + tint * Color2[1];
95
Col[2] = facm * (Color1[2]) + tint * Color2[2];
98
Color = (Fac == 1.0) ? Mortar: Col;