Welcome to mirror list, hosted at ThFree Co, Russian Federation.

node_brick_texture.osl « shaders « kernel « cycles « intern - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: e26e8dbff2cc5876c6cbcf7fa502a4383697816c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/*
 * Copyright 2011-2013 Blender Foundation
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include "stdosl.h"
#include "node_texture.h"

/* Brick */

float brick_noise(int n) /* fast integer noise */
{
	int nn;
	n = (n >> 13) ^ n;
	nn = (n * (n * n * 60493 + 19990303) + 1376312589) & 2147483647;
	return 0.5 * ((float)nn / 1073741824.0);
}

float brick(point p, float mortar_size, float bias,
	float BrickWidth, float row_height, float offset_amount, int offset_frequency,
	float squash_amount, int squash_frequency, float tint)
{
	int bricknum, rownum;
	float offset = 0.0;
	float brick_width = BrickWidth;
	float x, y;

	rownum = (int)floor(p[1] / row_height);
	
	if (offset_frequency && squash_frequency) {
		brick_width *= (rownum % squash_frequency) ? 1.0 : squash_amount;                /* squash */
		offset       = (rownum % offset_frequency) ? 0.0 : (brick_width * offset_amount);  /* offset */
	}

	bricknum = (int)floor((p[0] + offset) / brick_width);

	x = (p[0] + offset) - brick_width * bricknum;
	y = p[1] - row_height * rownum;

	tint = clamp((brick_noise((rownum << 16) + (bricknum & 65535)) + bias), 0.0, 1.0);

	return (x < mortar_size || y < mortar_size ||
	        x > (brick_width - mortar_size) ||
	        y > (row_height - mortar_size)) ? 1.0 : 0.0;
}

shader node_brick_texture(
	int use_mapping = 0,
	matrix mapping = matrix(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0),
	float Offset = 0.5,
	int OffsetFrequency = 2,
	float Squash = 1.0,
	int SquashFrequency = 1,
	point Vector = P,
	color Color1 = 0.2,
	color Color2 = 0.8,
	color Mortar = 0.0,
	float Scale = 5.0,
	float MortarSize = 0.02,
	float Bias = 0.0,
	float BrickWidth = 0.5,
	float RowHeight = 0.25,
	output float Fac = 0.0,
	output color Color = 0.2)
{
	point p = Vector;

	if (use_mapping)
		p = transform(mapping, p);

	float tint = 0.0;
	color Col = Color1;
	
	Fac = brick(p * Scale, MortarSize, Bias, BrickWidth, RowHeight,
		Offset, OffsetFrequency, Squash, SquashFrequency, tint);
		
	if (Fac != 1.0) {
		float facm = 1.0 - tint;
		Col = facm * Color1 + tint * Color2;
	}
	
	Color = (Fac == 1.0) ? Mortar : Col;
}