Blender V5.3
gpu_shader_material_tex_brick.bsl.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2019-2022 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
5#pragma once
6
8
10 float mortar_size,
11 float mortar_smooth,
12 float bias,
13 float brick_width,
14 float row_height,
15 float offset_amount,
16 int offset_frequency,
17 float squash_amount,
18 int squash_frequency)
19{
20 int bricknum, rownum;
21 float offset = 0.0f;
22 float x, y;
23
24 rownum = int(floor(p.y / row_height));
25
26 if (offset_frequency != 0 && squash_frequency != 0) {
27 brick_width *= (rownum % squash_frequency != 0) ? 1.0f : squash_amount; /* squash */
28 offset = (rownum % offset_frequency != 0) ? 0.0f : (brick_width * offset_amount); /* offset */
29 }
30
31 bricknum = int(floor((p.x + offset) / brick_width));
32
33 x = (p.x + offset) - brick_width * bricknum;
34 y = p.y - row_height * rownum;
35
36 float tint = clamp((integer_noise((rownum << 16) + (bricknum & 0xFFFF)) + bias), 0.0f, 1.0f);
37
38 float min_dist = min(min(x, y), min(brick_width - x, row_height - y));
39 if (min_dist >= mortar_size) {
40 return float2(tint, 0.0f);
41 }
42 if (mortar_smooth == 0.0f) {
43 return float2(tint, 1.0f);
44 }
45 min_dist = 1.0f - min_dist / mortar_size;
46 return float2(tint, smoothstep(0.0f, mortar_smooth, min_dist));
47}
48
49[[node]]
51 float4 color1,
52 float4 color2,
53 float4 mortar,
54 float scale,
55 float mortar_size,
56 float mortar_smooth,
57 float bias,
58 float brick_width,
59 float row_height,
60 float offset_amount,
61 float offset_frequency,
62 float squash_amount,
63 float squash_frequency,
64 float4 &color,
65 float &fac)
66{
68 mortar_size,
69 mortar_smooth,
70 bias,
71 brick_width,
72 row_height,
73 offset_amount,
74 int(offset_frequency),
75 squash_amount,
76 int(squash_frequency));
77 float tint = f2.x;
78 float f = f2.y;
79 if (f != 1.0f) {
80 float facm = 1.0f - tint;
81 color1 = facm * color1 + tint * color2;
82 }
83 color = mix(color1, mortar, f);
84 fac = f;
85}
float integer_noise(int n)
T smoothstep(T, T, T) RET
#define floor
constexpr T clamp(T, U, U) RET
void node_tex_brick(float3 co, float4 color1, float4 color2, float4 mortar, float scale, float mortar_size, float mortar_smooth, float bias, float brick_width, float row_height, float offset_amount, float offset_frequency, float squash_amount, float squash_frequency, float4 &color, float &fac)
float2 calc_brick_texture(float3 p, float mortar_size, float mortar_smooth, float bias, float brick_width, float row_height, float offset_amount, int offset_frequency, float squash_amount, int squash_frequency)
float3x3 scale(float3x3 mat, float2 scale)
#define mix
#define min(a, b)
Definition sort.cc:38
float x
float y
float y
Definition sky_math.h:136
float x
Definition sky_math.h:136