Cleanup: code-style, duplicate header
[blender.git] / source / blender / nodes / shader / nodes / node_shader_tex_brick.c
1 /*
2  * ***** BEGIN GPL LICENSE BLOCK *****
3  *
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. 
8  *
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.
13  *
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.
17  *
18  * The Original Code is Copyright (C) 2005 Blender Foundation.
19  * All rights reserved.
20  *
21  * The Original Code is: all of this file.
22  *
23  * Contributor(s): none yet.
24  *
25  * ***** END GPL LICENSE BLOCK *****
26  */
27
28 #include "../node_shader_util.h"
29
30 /* **************** OUTPUT ******************** */
31
32 static bNodeSocketTemplate sh_node_tex_brick_in[] = {
33         {       SOCK_VECTOR, 1, N_("Vector"),           0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_NONE, SOCK_HIDE_VALUE | SOCK_NO_INTERNAL_LINK},
34         {       SOCK_RGBA, 1,   N_("Color1"),           0.8f, 0.8f, 0.8f, 1.0f, 0.0f, 1.0f},
35         {       SOCK_RGBA, 1,   N_("Color2"),           0.2f, 0.2f, 0.2f, 1.0f, 0.0f, 1.0f},
36         {       SOCK_RGBA, 1,   N_("Mortar"),           0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, PROP_NONE, SOCK_NO_INTERNAL_LINK},
37         {       SOCK_FLOAT, 1,  N_("Scale"),            5.0f, 0.0f, 0.0f, 0.0f, -1000.0f, 1000.0f, PROP_NONE, SOCK_NO_INTERNAL_LINK},
38         {       SOCK_FLOAT, 1,  N_("Mortar Size"),      0.02f, 0.0f, 0.0f, 0.0f, 0.0f, 0.125f, PROP_NONE, SOCK_NO_INTERNAL_LINK},
39         {       SOCK_FLOAT, 1,  N_("Mortar Smooth"),    0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_NONE, SOCK_NO_INTERNAL_LINK},
40         {       SOCK_FLOAT, 1,  N_("Bias"),                 0.0f, 0.0f, 0.0f, 0.0f, -1.0f, 1.0f, PROP_NONE, SOCK_NO_INTERNAL_LINK},
41         {       SOCK_FLOAT, 1,  N_("Brick Width"),      0.5f, 0.0f, 0.0f, 0.0f, 0.01f, 100.0f, PROP_NONE, SOCK_NO_INTERNAL_LINK},
42         {       SOCK_FLOAT, 1,  N_("Row Height"),   0.25f, 0.0f, 0.0f, 0.0f, 0.01f, 100.0f, PROP_NONE, SOCK_NO_INTERNAL_LINK},
43         {       -1, 0, ""       }
44 };
45
46 static bNodeSocketTemplate sh_node_tex_brick_out[] = {
47         {       SOCK_RGBA, 0, N_("Color"),              0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f},
48         {       SOCK_FLOAT, 0, N_("Fac"),               0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_FACTOR, SOCK_NO_INTERNAL_LINK},
49         {       -1, 0, ""       }
50 };
51
52 static void node_shader_init_tex_brick(bNodeTree *UNUSED(ntree), bNode *node)
53 {
54         NodeTexBrick *tex = MEM_callocN(sizeof(NodeTexBrick), "NodeTexBrick");
55         BKE_texture_mapping_default(&tex->base.tex_mapping, TEXMAP_TYPE_POINT);
56         BKE_texture_colormapping_default(&tex->base.color_mapping);
57         
58         tex->offset = 0.5f;
59         tex->squash = 1.0f;
60         tex->offset_freq = 2;
61         tex->squash_freq = 2;
62
63         node->storage = tex;
64
65         for (bNodeSocket *sock = node->inputs.first; sock; sock = sock->next) {
66                 if (STREQ(sock->name, "Mortar Smooth")) {
67                         ((bNodeSocketValueFloat *)sock->default_value)->value = 0.1f;
68                 }
69         }
70 }
71
72 static int node_shader_gpu_tex_brick(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
73 {
74         if (!in[0].link) {
75                 in[0].link = GPU_attribute(CD_ORCO, "");
76                 GPU_link(mat, "generated_from_orco", in[0].link, &in[0].link);
77         }
78
79         node_shader_gpu_tex_mapping(mat, node, in, out);
80         NodeTexBrick *tex = (NodeTexBrick *)node->storage;
81         float offset_freq = tex->offset_freq;
82         float squash_freq = tex->squash_freq;
83         return GPU_stack_link(mat, "node_tex_brick",
84                               in, out,
85                               GPU_uniform(&tex->offset), GPU_uniform(&offset_freq),
86                               GPU_uniform(&tex->squash), GPU_uniform(&squash_freq));
87 }
88
89 /* node type definition */
90 void register_node_type_sh_tex_brick(void)
91 {
92         static bNodeType ntype;
93
94         sh_node_type_base(&ntype, SH_NODE_TEX_BRICK, "Brick Texture", NODE_CLASS_TEXTURE, 0);
95         node_type_compatibility(&ntype, NODE_NEW_SHADING);
96         node_type_socket_templates(&ntype, sh_node_tex_brick_in, sh_node_tex_brick_out);
97         node_type_size_preset(&ntype, NODE_SIZE_MIDDLE);
98         node_type_init(&ntype, node_shader_init_tex_brick);
99         node_type_storage(&ntype, "NodeTexBrick", node_free_standard_storage, node_copy_standard_storage);
100         node_type_gpu(&ntype, node_shader_gpu_tex_brick);
101
102         nodeRegisterType(&ntype);
103 }