32 const bool is_compositor =
b.tree_or_null() &&
b.tree_or_null()->type ==
NTREE_COMPOSIT;
39 .default_input_type(default_input_type);
42 .default_value({0.8f, 0.8f, 0.8f, 1.0f})
43 .description(
"Color of the first reference brick");
45 .default_value({0.2f, 0.2f, 0.2f, 1.0f})
46 .description(
"Color of the second reference brick");
48 .default_value({0.0f, 0.0f, 0.0f, 1.0f})
56 .description(
"Scale of the texture");
63 "Size of the filling between the bricks (known as \"mortar\"). "
71 "Blurs/softens the edge between the mortar and the bricks. "
72 "This can be useful with a texture and displacement textures");
78 "The color variation between Color1 and Color2. "
79 "Values of -1 and 1 only use one of the two colors. "
80 "Values in between mix the colors");
86 .description(
"Ratio of brick's width relative to the texture scale");
92 .description(
"Ratio of brick's row height relative to the texture scale");
154 const int offset_freq_;
156 const int squash_freq_;
160 const int offset_freq,
162 const int squash_freq)
163 : offset_(offset), offset_freq_(offset_freq), squash_(squash), squash_freq_(squash_freq)
165 static const mf::Signature
signature = []() {
167 mf::SignatureBuilder builder{
"BrickTexture",
signature};
168 builder.single_input<
float3>(
"Vector");
172 builder.single_input<
float>(
"Scale");
173 builder.single_input<
float>(
"Mortar Size");
174 builder.single_input<
float>(
"Mortar Smooth");
175 builder.single_input<
float>(
"Bias");
176 builder.single_input<
float>(
"Brick Width");
177 builder.single_input<
float>(
"Row Height");
178 builder.single_output<
ColorGeometry4f>(
"Color", mf::ParamFlag::SupportsUnusedOutput);
179 builder.single_output<
float>(
"Fac", mf::ParamFlag::SupportsUnusedOutput);
188 n = (n + 1013) & 0x7fffffff;
190 const uint nn = (n * (n * n * 60493 + 19990303) + 1376312589) & 0x7fffffff;
191 return 0.5f * (
float(nn) / 1073741824.0f);
196 const float ff = f * f;
197 return (3.0f * ff - 2.0f * ff * f);
207 int offset_frequency,
209 int squash_frequency)
213 const int rownum = int(
floorf(p.y / row_height));
215 if (offset_frequency && squash_frequency) {
216 brick_width *= (rownum % squash_frequency) ? 1.0f : squash_amount;
217 offset = (rownum % offset_frequency) ? 0.0f : (brick_width * offset_amount);
220 const int bricknum = int(
floorf((p.x + offset) / brick_width));
222 const float x = (p.x + offset) - brick_width * bricknum;
223 const float y = p.y - row_height * rownum;
226 brick_noise((rownum << 16) + (bricknum & 0xFFFF)) + bias, 0.0f, 1.0f);
227 float min_dist = std::min({
x,
y, brick_width -
x, row_height -
y});
230 if (min_dist >= mortar_size) {
233 else if (mortar_smooth == 0.0f) {
237 min_dist = 1.0f - min_dist / mortar_size;
238 mortar = (min_dist < mortar_smooth) ?
smoothstepf(min_dist / mortar_smooth) : 1.0f;
241 return float2(tint, mortar);
254 const VArray<float> &mortar_size = params.readonly_single_input<
float>(5,
"Mortar Size");
255 const VArray<float> &mortar_smooth = params.readonly_single_input<
float>(6,
"Mortar Smooth");
256 const VArray<float> &bias = params.readonly_single_input<
float>(7,
"Bias");
257 const VArray<float> &brick_width = params.readonly_single_input<
float>(8,
"Brick Width");
258 const VArray<float> &row_height = params.readonly_single_input<
float>(9,
"Row Height");
261 params.uninitialized_single_output_if_required<
ColorGeometry4f>(10,
"Color");
262 MutableSpan<float> r_fac = params.uninitialized_single_output_if_required<
float>(11,
"Fac");
264 const bool store_fac = !r_fac.
is_empty();
265 const bool store_color = !r_color.is_empty();
279 float4 color_data, color1, color2, mortar;
284 const float tint = f2.x;
285 const float f = f2.y;
288 const float facm = 1.0f - tint;
289 color_data = color1 * facm + color2 * tint;
293 color_data = color_data * (1.0f - f) + mortar * f;
304 static constexpr int8_t id = 0;
307 hash.add(offset_freq_);
309 hash.add(squash_freq_);
331 ntype.
ui_name =
"Brick Texture";
332 ntype.
ui_description =
"Generate a procedural texture producing bricks";
335 ntype.
declare = file_ns::sh_node_tex_brick_declare;
336 ntype.
draw_buttons = file_ns::node_shader_buts_tex_brick;
338 ntype.
initfunc = file_ns::node_shader_init_tex_brick;
341 ntype.
gpu_fn = file_ns::node_shader_gpu_tex_brick;
#define NODE_CLASS_TEXTURE
#define SH_NODE_TEX_BRICK
constexpr bool is_empty() const
const Signature & signature() const
void set_signature(const Signature *signature)
void construct_and_set_matching_fn(Args &&...args)
static float brick_noise(uint n)
BrickFunction(const float offset, const int offset_freq, const float squash, const int squash_freq)
static float smoothstepf(const float f)
void call(const IndexMask &mask, mf::Params params, mf::Context) const override
void hash_unique(UniqueHashBytes &hash) const override
static float2 brick(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)
void node_register_type(bNodeType &ntype)
void node_type_storage(bNodeType &ntype, std::optional< StringRefNull > storagename, void(*freefunc)(bNode *node), void(*copyfunc)(bNodeTree *dest_ntree, bNode *dest_node, const bNode *src_node))
static void sh_node_brick_build_multi_function(NodeMultiFunctionBuilder &builder)
static void node_shader_buts_tex_brick(ui::Layout &layout, bContext *, PointerRNA *ptr)
static void sh_node_tex_brick_declare(NodeDeclarationBuilder &b)
static void node_shader_init_tex_brick(bNodeTree *, bNode *node)
static int node_shader_gpu_tex_brick(GPUMaterial *mat, bNode *node, bNodeExecData *, GPUNodeStack *in, GPUNodeStack *out)
@ ITEM_R_SPLIT_EMPTY_NAME
bool GPU_stack_link(GPUMaterial *mat, const bNode *node, const char *name, GPUNodeStack *in, GPUNodeStack *out,...)
GPUNodeLink * GPU_uniform(const float *num)
VecBase< float, 4 > float4
GPUNodeLink * GPU_constant(const float *num)
VecBase< float, 2 > float2
void node_shader_gpu_tex_mapping(GPUMaterial *mat, bNode *node, GPUNodeStack *in, GPUNodeStack *)
void node_shader_gpu_default_tex_coord(GPUMaterial *mat, bNode *node, GPUNodeLink **link)
void BKE_texture_mapping_default(struct TexMapping *texmap, int type)
void register_node_type_sh_tex_brick()
@ NODE_DEFAULT_INPUT_POSITION_FIELD
@ NODE_DEFAULT_INPUT_UNIFORM_IMAGE_COORDINATES
void node_copy_standard_storage(bNodeTree *, bNode *dest_node, const bNode *src_node)
ColorSceneLinear4f< eAlpha::Premultiplied > ColorGeometry4f
MINLINE void copy_v4_v4(float r[4], const float a[4])
void node_free_standard_storage(bNode *node)
VecBase< float, 3 > float3
void BKE_texture_colormapping_default(struct ColorMapping *colormap)
void common_node_type_base(bke::bNodeType *ntype, UString idname, const std::optional< int16_t > legacy_type)
MINLINE float clamp_f(float value, float min, float max)
KERNEL_FEATURE_LIGHT_PASSES KERNEL_FEATURE_PATH_GUIDING float
ColorMapping color_mapping
static constexpr int _160
static constexpr int _180
void(*) draw_buttons(ui::Layout &, bContext *C, PointerRNA *ptr)
std::string ui_description
NodeGPUExecFunction gpu_fn
NodeMultiFunctionBuildFunction build_multi_function
void(*) initfunc(bNodeTree *ntree, bNode *node)
const char * enum_name_legacy
NodeDeclareFunction declare
void prop(PointerRNA *ptr, PropertyRNA *prop, int index, int value, eUI_Item_Flag flag, std::optional< StringRef > name_opt, int icon, std::optional< StringRef > placeholder=std::nullopt)
Layout & column(bool align)