[Bf-cycles] Brick Texture for Cycles (Patch)
Thomas Dinges
blender at dingto.org
Tue Aug 21 20:25:34 CEST 2012
Hi Brecht,
Welcome back! :)
I implemented a Brick Texture Shader for Cycles, based on the BI
internal one. It has several options to tweak the look of the bricks.
I attached a patch.
Picture of the Texture: http://temp.dingto.org/brick_texture5.png
ToDo/Bugs:
* There are some input sockets, which are passed over to the shader as
expected, but I have problems with the 2 float RNA values.
See nodes.cpp, I have offset = 0.5f; and squash = 1.0f; I can't find a
way to pass those 2 values to the svm code correctly.
The other two values coming from RNA (offset_frequency and
squash_frequency) work fine, but they are integer.
* The Texture only works fine on X vector, y and z have issues, but
that's the same limitation as in the BI Brick node.
Could you take a look / review please? :)
Best regards,
Thomas
--
Thomas Dinges
Blender Developer, Artist and Musician
www.dingto.org
-------------- next part --------------
Index: intern/cycles/app/cycles_xml.cpp
===================================================================
--- intern/cycles/app/cycles_xml.cpp (revision 50079)
+++ intern/cycles/app/cycles_xml.cpp (working copy)
@@ -379,6 +379,9 @@
else if(string_iequals(node.name(), "checker_texture")) {
snode = new CheckerTextureNode();
}
+ else if(string_iequals(node.name(), "brick_texture")) {
+ snode = new BrickTextureNode();
+ }
else if(string_iequals(node.name(), "gradient_texture")) {
GradientTextureNode *blend = new GradientTextureNode();
xml_read_enum(&blend->type, GradientTextureNode::type_enum, node, "type");
Index: intern/cycles/blender/blender_shader.cpp
===================================================================
--- intern/cycles/blender/blender_shader.cpp (revision 50079)
+++ intern/cycles/blender/blender_shader.cpp (working copy)
@@ -459,6 +459,17 @@
node = checker;
break;
}
+ case BL::ShaderNode::type_TEX_BRICK: {
+ BL::ShaderNodeTexBrick b_brick_node(b_node);
+ BrickTextureNode *brick = new BrickTextureNode();
+ brick->offset = b_brick_node.offset();
+ brick->offset_frequency = b_brick_node.offset_frequency();
+ brick->squash = b_brick_node.squash();
+ brick->squash_frequency = b_brick_node.squash_frequency();
+ get_tex_mapping(&brick->tex_mapping, b_brick_node.texture_mapping());
+ node = brick;
+ break;
+ }
case BL::ShaderNode::type_TEX_NOISE: {
BL::ShaderNodeTexNoise b_noise_node(b_node);
NoiseTextureNode *noise = new NoiseTextureNode();
Index: intern/cycles/kernel/CMakeLists.txt
===================================================================
--- intern/cycles/kernel/CMakeLists.txt (revision 50079)
+++ intern/cycles/kernel/CMakeLists.txt (working copy)
@@ -61,6 +61,7 @@
svm/svm_closure.h
svm/svm_convert.h
svm/svm_checker.h
+ svm/svm_brick.h
svm/svm_displace.h
svm/svm_fresnel.h
svm/svm_gamma.h
Index: intern/cycles/kernel/svm/svm.h
===================================================================
--- intern/cycles/kernel/svm/svm.h (revision 50079)
+++ intern/cycles/kernel/svm/svm.h (working copy)
@@ -154,6 +154,7 @@
#include "svm_value.h"
#include "svm_voronoi.h"
#include "svm_checker.h"
+#include "svm_brick.h"
CCL_NAMESPACE_BEGIN
@@ -249,6 +250,9 @@
case NODE_TEX_CHECKER:
svm_node_tex_checker(kg, sd, stack, node, &offset);
break;
+ case NODE_TEX_BRICK:
+ svm_node_tex_brick(kg, sd, stack, node, &offset);
+ break;
#endif
case NODE_CAMERA:
svm_node_camera(kg, sd, stack, node.y, node.z, node.w);
Index: intern/cycles/kernel/svm/svm_brick.h
===================================================================
--- intern/cycles/kernel/svm/svm_brick.h (revision 0)
+++ intern/cycles/kernel/svm/svm_brick.h (working copy)
@@ -0,0 +1,113 @@
+/*
+ * Copyright 2012, Blender Foundation.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+CCL_NAMESPACE_BEGIN
+
+/* Brick */
+
+__device_noinline float noise(int n) /* fast integer noise */
+{
+ int nn;
+ n = (n >> 13) ^ n;
+ nn = (n * (n * n * 60493 + 19990303) + 1376312589) & 0x7fffffff;
+ return 0.5f * ((float)nn / 1073741824.0f);
+}
+
+__device_noinline float svm_brick(float3 p, float scale, float mortar_size, float bias,
+ float brick_width, float row_height, float offset_amount, int offset_frequency,
+ float squash_amount, int squash_frequency, float &tint)
+{
+ p *= scale;
+
+ int bricknum, rownum;
+ float offset = 0.0f;
+ float x, y;
+ float bricks1[4], bricks2[4], mortar[4];
+
+ rownum = (int)floor(p.y / row_height);
+
+ if(offset_frequency && squash_frequency) {
+ brick_width *= ((int)(rownum) % squash_frequency ) ? 1.0f : squash_amount; /* squash */
+ offset = ((int)(rownum) % offset_frequency ) ? 0 : (brick_width*offset_amount); /* offset */
+ }
+
+ bricknum = (int)floor((p.x+offset) / brick_width);
+
+ x = (p.x+offset) - brick_width*bricknum;
+ y = p.y - row_height*rownum;
+
+ tint = clamp((noise((rownum << 16) + (bricknum & 0xFFFF)) + bias), 0.0f, 1.0f);
+
+ return (x < mortar_size || y < mortar_size ||
+ x > (brick_width - mortar_size) ||
+ y > (row_height - mortar_size)) ? 1.0f : 0.0f;
+}
+
+__device void svm_node_tex_brick(KernelGlobals *kg, ShaderData *sd, float *stack, uint4 node, int *offset)
+{
+ uint4 node2 = read_node(kg, offset);
+ uint4 node3 = read_node(kg, offset);
+
+ /* Input and Output Sockets */
+ uint co_offset, color1_offset, color2_offset, mortar_offset, scale_offset;
+ uint mortar_size_offset, bias_offset, brick_width_offset, row_height_offset;
+ uint color_offset, fac_offset;
+
+ /* RNA properties */
+ uint offset_amount, offset_frequency, squash_amount, squash_frequency;
+
+ float tint;
+
+ decode_node_uchar4(node.y, &co_offset, &color1_offset, &color2_offset, &mortar_offset);
+ decode_node_uchar4(node.z, &scale_offset, &mortar_size_offset, &bias_offset, &brick_width_offset);
+ decode_node_uchar4(node.w, &row_height_offset, &color_offset, &fac_offset, NULL);
+
+ decode_node_uchar4(node2.x, &offset_frequency, &squash_frequency, &offset_amount, &squash_amount);
+
+ float3 co = stack_load_float3(stack, co_offset);
+
+ float3 color1 = stack_load_float3(stack, color1_offset);
+ float3 color2 = stack_load_float3(stack, color2_offset);
+ float3 mortar = stack_load_float3(stack, mortar_offset);
+
+ float scale = stack_load_float_default(stack, scale_offset, node2.y);
+ float mortar_size = stack_load_float_default(stack, mortar_size_offset, node2.z);
+ float bias = stack_load_float_default(stack, bias_offset, node2.w);
+ float brick_width = stack_load_float_default(stack, brick_width_offset, node3.x);
+ float row_height = stack_load_float_default(stack, row_height_offset, node3.y);
+
+ float f = svm_brick(co, scale, mortar_size, bias, brick_width, row_height,
+ offset_amount, offset_frequency, squash_amount, squash_frequency,
+ tint);
+
+ if(f != 1.0f) {
+ float facm = 1.0f - tint;
+
+ color1.x = facm * (color1.x) + tint * color2.x;
+ color1.y = facm * (color1.y) + tint * color2.y;
+ color1.z = facm * (color1.z) + tint * color2.z;
+ }
+
+ if(stack_valid(color_offset))
+ stack_store_float3(stack, color_offset, (f == 1.0f)? mortar: color1);
+ if(stack_valid(fac_offset))
+ stack_store_float(stack, fac_offset, f);
+}
+
+CCL_NAMESPACE_END
+
Index: intern/cycles/kernel/svm/svm_types.h
===================================================================
--- intern/cycles/kernel/svm/svm_types.h (revision 50079)
+++ intern/cycles/kernel/svm/svm_types.h (working copy)
@@ -89,7 +89,8 @@
NODE_MIN_MAX,
NODE_LIGHT_FALLOFF,
NODE_OBJECT_INFO,
- NODE_PARTICLE_INFO
+ NODE_PARTICLE_INFO,
+ NODE_TEX_BRICK
} NodeType;
typedef enum NodeAttributeType {
Index: intern/cycles/render/nodes.cpp
===================================================================
--- intern/cycles/render/nodes.cpp (revision 50079)
+++ intern/cycles/render/nodes.cpp (working copy)
@@ -873,6 +873,98 @@
compiler.add(this, "node_checker_texture");
}
+/* Brick Texture */
+
+BrickTextureNode::BrickTextureNode()
+: TextureNode("brick_texture")
+{
+ offset = 0.5f;
+ offset_frequency = 2;
+ squash = 1.0f;
+ squash_frequency = 2;
+
+ add_input("Vector", SHADER_SOCKET_POINT, ShaderInput::TEXTURE_GENERATED);
+ add_input("Color1", SHADER_SOCKET_COLOR);
+ add_input("Color2", SHADER_SOCKET_COLOR);
+ add_input("Mortar", SHADER_SOCKET_COLOR);
+ add_input("Scale", SHADER_SOCKET_FLOAT, 5.0f);
+ add_input("Mortar Size", SHADER_SOCKET_FLOAT, 0.02f);
+ add_input("Bias", SHADER_SOCKET_FLOAT, 0.0f);
+ add_input("Brick Width", SHADER_SOCKET_FLOAT, 0.5f);
+ add_input("Row Height", SHADER_SOCKET_FLOAT, 0.25f);
+
+ add_output("Color", SHADER_SOCKET_COLOR);
+ add_output("Fac", SHADER_SOCKET_FLOAT);
+}
+
+void BrickTextureNode::compile(SVMCompiler& compiler)
+{
+ ShaderInput *vector_in = input("Vector");
+ ShaderInput *color1_in = input("Color1");
+ ShaderInput *color2_in = input("Color2");
+ ShaderInput *mortar_in = input("Mortar");
+ ShaderInput *scale_in = input("Scale");
+ ShaderInput *mortar_size_in = input("Mortar Size");
+ ShaderInput *bias_in = input("Bias");
+ ShaderInput *brick_width_in = input("Brick Width");
+ ShaderInput *row_height_in = input("Row Height");
+
+ ShaderOutput *color_out = output("Color");
+ ShaderOutput *fac_out = output("Fac");
+
+ compiler.stack_assign(vector_in);
+ compiler.stack_assign(color1_in);
+ compiler.stack_assign(color2_in);
+ compiler.stack_assign(mortar_in);
+ if(scale_in->link) compiler.stack_assign(scale_in);
+ if(mortar_size_in->link) compiler.stack_assign(mortar_size_in);
+ if(bias_in->link) compiler.stack_assign(bias_in);
+ if(brick_width_in->link) compiler.stack_assign(brick_width_in);
+ if(row_height_in->link) compiler.stack_assign(row_height_in);
+
+ int vector_offset = vector_in->stack_offset;
+
+ if(!tex_mapping.skip()) {
+ vector_offset = compiler.stack_find_offset(SHADER_SOCKET_VECTOR);
+ tex_mapping.compile(compiler, vector_in->stack_offset, vector_offset);
+ }
+
+ if(!color_out->links.empty())
+ compiler.stack_assign(color_out);
+ if(!fac_out->links.empty())
+ compiler.stack_assign(fac_out);
+
+ compiler.add_node(NODE_TEX_BRICK,
+ compiler.encode_uchar4(vector_offset,
+ color1_in->stack_offset, color2_in->stack_offset, mortar_in->stack_offset),
+ compiler.encode_uchar4(scale_in->stack_offset,
+ mortar_size_in->stack_offset, bias_in->stack_offset, brick_width_in->stack_offset),
+ compiler.encode_uchar4(row_height_in->stack_offset,
+ color_out->stack_offset, fac_out->stack_offset));
+
+ compiler.add_node(compiler.encode_uchar4(offset_frequency, squash_frequency, offset, squash),
+ __float_as_int(scale_in->value.x),
+ __float_as_int(mortar_size_in->value.x),
+ __float_as_int(bias_in->value.x));
+
+ compiler.add_node(__float_as_int(brick_width_in->value.x),
+ __float_as_int(row_height_in->value.x),
+ __float_as_int(offset),
+ __float_as_int(squash));
+
+ if(vector_offset != vector_in->stack_offset)
+ compiler.stack_clear_offset(vector_in->type, vector_offset);
+}
+
+void BrickTextureNode::compile(OSLCompiler& compiler)
+{
+ compiler.parameter("Offset", offset);
+ compiler.parameter("Offset Frequency", offset_frequency);
+ compiler.parameter("Squash", squash);
+ compiler.parameter("Squash Frequency", squash_frequency);
+ compiler.add(this, "node_brick_texture");
+}
+
/* Normal */
NormalNode::NormalNode()
Index: intern/cycles/render/nodes.h
===================================================================
--- intern/cycles/render/nodes.h (revision 50079)
+++ intern/cycles/render/nodes.h (working copy)
@@ -155,6 +155,14 @@
SHADER_NODE_CLASS(CheckerTextureNode)
};
+class BrickTextureNode : public TextureNode {
+public:
+ SHADER_NODE_CLASS(BrickTextureNode)
+
+ float offset, squash;
+ int offset_frequency, squash_frequency;
+};
+
class MappingNode : public ShaderNode {
public:
SHADER_NODE_CLASS(MappingNode)
Index: source/blender/blenkernel/BKE_node.h
===================================================================
--- source/blender/blenkernel/BKE_node.h (revision 50079)
+++ source/blender/blenkernel/BKE_node.h (working copy)
@@ -538,6 +538,7 @@
#define SH_NODE_LIGHT_FALLOFF 166
#define SH_NODE_OBJECT_INFO 167
#define SH_NODE_PARTICLE_INFO 168
+#define SH_NODE_TEX_BRICK 169
/* custom defines options for Material node */
#define SH_NODE_MAT_DIFF 1
Index: source/blender/blenkernel/intern/node.c
===================================================================
--- source/blender/blenkernel/intern/node.c (revision 50079)
+++ source/blender/blenkernel/intern/node.c (working copy)
@@ -2213,6 +2213,7 @@
register_node_type_sh_tex_gradient(ttype);
register_node_type_sh_tex_magic(ttype);
register_node_type_sh_tex_checker(ttype);
+ register_node_type_sh_tex_brick(ttype);
}
static void registerTextureNodes(bNodeTreeType *ttype)
Index: source/blender/editors/space_node/drawnode.c
===================================================================
--- source/blender/editors/space_node/drawnode.c (revision 50079)
+++ source/blender/editors/space_node/drawnode.c (working copy)
@@ -1359,6 +1359,19 @@
uiItemR(layout, ptr, "turbulence_depth", 0, NULL, ICON_NONE);
}
+static void node_shader_buts_tex_brick(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
+{
+ uiLayout *col;
+
+ col = uiLayoutColumn(layout, TRUE);
+ uiItemR(col, ptr, "offset", 0, IFACE_("Offset"), ICON_NONE);
+ uiItemR(col, ptr, "offset_frequency", 0, IFACE_("Frequency"), ICON_NONE);
+
+ col = uiLayoutColumn(layout, TRUE);
+ uiItemR(col, ptr, "squash", 0, IFACE_("Squash"), ICON_NONE);
+ uiItemR(col, ptr, "squash_frequency", 0, IFACE_("Frequency"), ICON_NONE);
+}
+
static void node_shader_buts_tex_wave(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
{
uiItemR(layout, ptr, "wave_type", 0, "", ICON_NONE);
@@ -1443,6 +1456,9 @@
case SH_NODE_TEX_MAGIC:
ntype->uifunc = node_shader_buts_tex_magic;
break;
+ case SH_NODE_TEX_BRICK:
+ ntype->uifunc = node_shader_buts_tex_brick;
+ break;
case SH_NODE_TEX_WAVE:
ntype->uifunc = node_shader_buts_tex_wave;
break;
Index: source/blender/makesdna/DNA_node_types.h
===================================================================
--- source/blender/makesdna/DNA_node_types.h (revision 50079)
+++ source/blender/makesdna/DNA_node_types.h (working copy)
@@ -621,6 +621,12 @@
NodeTexBase base;
} NodeTexChecker;
+typedef struct NodeTexBrick {
+ NodeTexBase base;
+ int offset_freq, squash_freq;
+ float offset, squash;
+} NodeTexBrick;
+
typedef struct NodeTexEnvironment {
NodeTexBase base;
ImageUser iuser;
Index: source/blender/makesrna/intern/rna_nodetree.c
===================================================================
--- source/blender/makesrna/intern/rna_nodetree.c (revision 50079)
+++ source/blender/makesrna/intern/rna_nodetree.c (working copy)
@@ -1580,6 +1580,43 @@
def_sh_tex(srna);
}
+static void def_sh_tex_brick(StructRNA *srna)
+{
+ PropertyRNA *prop;
+
+ RNA_def_struct_sdna_from(srna, "NodeTexBrick", "storage");
+ def_sh_tex(srna);
+
+ prop = RNA_def_property(srna, "offset_frequency", PROP_INT, PROP_NONE);
+ RNA_def_property_int_sdna(prop, NULL, "offset_freq");
+ RNA_def_property_int_default(prop, 2);
+ RNA_def_property_range(prop, 1, 99);
+ RNA_def_property_ui_text(prop, "Offset Frequency", "");
+ RNA_def_property_update(prop, 0, "rna_Node_update");
+
+ prop = RNA_def_property(srna, "squash_frequency", PROP_INT, PROP_NONE);
+ RNA_def_property_int_sdna(prop, NULL, "squash_freq");
+ RNA_def_property_int_default(prop, 2);
+ RNA_def_property_range(prop, 1, 99);
+ RNA_def_property_ui_text(prop, "Squash Frequency", "");
+ RNA_def_property_update(prop, 0, "rna_Node_update");
+
+ prop = RNA_def_property(srna, "offset", PROP_FLOAT, PROP_NONE);
+ RNA_def_property_float_sdna(prop, NULL, "offset");
+ RNA_def_property_float_default(prop, 0.5f);
+ RNA_def_property_range(prop, 0.0f, 1.0f);
+ RNA_def_property_ui_text(prop, "Offset Amount", "");
+ RNA_def_property_update(prop, 0, "rna_Node_update");
+
+ prop = RNA_def_property(srna, "squash", PROP_FLOAT, PROP_NONE);
+ RNA_def_property_float_sdna(prop, NULL, "squash");
+ RNA_def_property_float_default(prop, 1.0f);
+ RNA_def_property_range(prop, 0.0f, 99.0f);
+ RNA_def_property_ui_text(prop, "Squash Amount", "");
+ RNA_def_property_update(prop, 0, "rna_Node_update");
+
+}
+
static void def_sh_tex_magic(StructRNA *srna)
{
PropertyRNA *prop;
Index: source/blender/makesrna/intern/rna_nodetree_types.h
===================================================================
--- source/blender/makesrna/intern/rna_nodetree_types.h (revision 50079)
+++ source/blender/makesrna/intern/rna_nodetree_types.h (working copy)
@@ -91,6 +91,7 @@
DefNode( ShaderNode, SH_NODE_TEX_MUSGRAVE, def_sh_tex_musgrave, "TEX_MUSGRAVE", TexMusgrave, "Musgrave Texture", "" )
DefNode( ShaderNode, SH_NODE_TEX_VORONOI, def_sh_tex_voronoi, "TEX_VORONOI", TexVoronoi, "Voronoi Texture", "" )
DefNode( ShaderNode, SH_NODE_TEX_CHECKER, def_sh_tex_checker, "TEX_CHECKER", TexChecker, "Checker Texture", "" )
+DefNode( ShaderNode, SH_NODE_TEX_BRICK, def_sh_tex_brick, "TEX_BRICK", TexBrick, "Brick Texture", "" )
DefNode( ShaderNode, SH_NODE_TEX_COORD, 0, "TEX_COORD", TexCoord, "Texture Coordinate","" )
DefNode( CompositorNode, CMP_NODE_VIEWER, def_cmp_viewer, "VIEWER", Viewer, "Viewer", "" )
Index: source/blender/nodes/CMakeLists.txt
===================================================================
--- source/blender/nodes/CMakeLists.txt (revision 50079)
+++ source/blender/nodes/CMakeLists.txt (working copy)
@@ -179,6 +179,7 @@
shader/nodes/node_shader_tex_voronoi.c
shader/nodes/node_shader_tex_wave.c
shader/nodes/node_shader_tex_checker.c
+ shader/nodes/node_shader_tex_brick.c
shader/node_shader_tree.c
shader/node_shader_util.c
Index: source/blender/nodes/NOD_shader.h
===================================================================
--- source/blender/nodes/NOD_shader.h (revision 50079)
+++ source/blender/nodes/NOD_shader.h (working copy)
@@ -108,6 +108,7 @@
void register_node_type_sh_tex_musgrave(struct bNodeTreeType *ttype);
void register_node_type_sh_tex_noise(struct bNodeTreeType *ttype);
void register_node_type_sh_tex_checker(struct bNodeTreeType *ttype);
+void register_node_type_sh_tex_brick(struct bNodeTreeType *ttype);
#endif
Index: source/blender/nodes/shader/nodes/node_shader_tex_brick.c
===================================================================
--- source/blender/nodes/shader/nodes/node_shader_tex_brick.c (revision 0)
+++ source/blender/nodes/shader/nodes/node_shader_tex_brick.c (working copy)
@@ -0,0 +1,90 @@
+/*
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) 2005 Blender Foundation.
+ * All rights reserved.
+ *
+ * The Original Code is: all of this file.
+ *
+ * Contributor(s): none yet.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+#include "../node_shader_util.h"
+
+/* **************** OUTPUT ******************** */
+
+static bNodeSocketTemplate sh_node_tex_brick_in[]= {
+ { SOCK_VECTOR, 1, N_("Vector"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_NONE, SOCK_HIDE_VALUE},
+ { SOCK_RGBA, 1, N_("Color1"), 0.8f, 0.8f, 0.8f, 1.0f, 0.0f, 1.0f},
+ { SOCK_RGBA, 1, N_("Color2"), 0.2f, 0.2f, 0.2f, 1.0f, 0.0f, 1.0f},
+ { SOCK_RGBA, 1, N_("Mortar"), 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f},
+ { SOCK_FLOAT, 1, N_("Scale"), 5.0f, 0.0f, 0.0f, 0.0f, -1000.0f, 1000.0f},
+ { SOCK_FLOAT, 1, N_("Mortar Size"), 0.02f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f},
+ { SOCK_FLOAT, 1, N_("Bias"), 0.0f, 0.0f, 0.0f, 0.0f, -1.0f, 1.0f},
+ { SOCK_FLOAT, 1, N_("Brick Width"), 0.5f, 0.0f, 0.0f, 0.0f, 0.001f, 99.0f},
+ { SOCK_FLOAT, 1, N_("Row Height"), 0.25f, 0.0f, 0.0f, 0.0f, 0.001f, 99.0f},
+ { -1, 0, "" }
+};
+
+static bNodeSocketTemplate sh_node_tex_brick_out[]= {
+ { SOCK_RGBA, 0, N_("Color"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f},
+ { SOCK_FLOAT, 0, N_("Fac"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f},
+ { -1, 0, "" }
+};
+
+static void node_shader_init_tex_brick(bNodeTree *UNUSED(ntree), bNode* node, bNodeTemplate *UNUSED(ntemp))
+{
+ NodeTexBrick *tex = MEM_callocN(sizeof(NodeTexBrick), "NodeTexBrick");
+ default_tex_mapping(&tex->base.tex_mapping);
+ default_color_mapping(&tex->base.color_mapping);
+
+ tex->offset = 0.5f;
+ tex->squash = 1.0f;
+ tex->offset_freq = 2;
+ tex->squash_freq = 2;
+
+ node->storage = tex;
+}
+
+static int node_shader_gpu_tex_brick(GPUMaterial *mat, bNode *node, GPUNodeStack *in, GPUNodeStack *out)
+{
+ if (!in[0].link)
+ in[0].link = GPU_attribute(CD_ORCO, "");
+
+ node_shader_gpu_tex_mapping(mat, node, in, out);
+
+ return GPU_stack_link(mat, "node_tex_brick", in, out);
+}
+
+/* node type definition */
+void register_node_type_sh_tex_brick(bNodeTreeType *ttype)
+{
+ static bNodeType ntype;
+
+ node_type_base(ttype, &ntype, SH_NODE_TEX_BRICK, "Brick Texture", NODE_CLASS_TEXTURE, NODE_OPTIONS);
+ node_type_compatibility(&ntype, NODE_NEW_SHADING);
+ node_type_socket_templates(&ntype, sh_node_tex_brick_in, sh_node_tex_brick_out);
+ node_type_size(&ntype, 150, 60, 200);
+ node_type_init(&ntype, node_shader_init_tex_brick);
+ node_type_storage(&ntype, "NodeTexBrick", node_free_standard_storage, node_copy_standard_storage);
+ node_type_exec(&ntype, NULL);
+ node_type_gpu(&ntype, node_shader_gpu_tex_brick);
+
+ nodeRegisterType(ttype, &ntype);
+}
More information about the Bf-cycles
mailing list