Blender  V2.93
node_shader_bump.c
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  *
16  * The Original Code is Copyright (C) 2005 Blender Foundation.
17  * All rights reserved.
18  */
19 
24 #include "node_shader_util.h"
25 
26 /* **************** BUMP ******************** */
27 /* clang-format off */
29  {SOCK_FLOAT, N_("Strength"), 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_FACTOR},
30  {SOCK_FLOAT, N_("Distance"), 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1000.0f},
31  {SOCK_FLOAT, N_("Height"), 1.0f, 1.0f, 1.0f, 1.0f, -1000.0f, 1000.0f, PROP_NONE, SOCK_HIDE_VALUE},
32  {SOCK_FLOAT, N_("Height_dx"), 1.0f, 1.0f, 1.0f, 1.0f, -1000.0f, 1000.0f, PROP_NONE, SOCK_UNAVAIL},
33  {SOCK_FLOAT, N_("Height_dy"), 1.0f, 1.0f, 1.0f, 1.0f, -1000.0f, 1000.0f, PROP_NONE, SOCK_UNAVAIL},
34  {SOCK_VECTOR, N_("Normal"), 0.0f, 0.0f, 0.0f, 1.0f, -1.0f, 1.0f, PROP_NONE, SOCK_HIDE_VALUE},
35  {-1, ""}
36 };
37 /* clang-format on */
38 
39 static bNodeSocketTemplate sh_node_bump_out[] = {{SOCK_VECTOR, "Normal"}, {-1, ""}};
40 
41 static int gpu_shader_bump(GPUMaterial *mat,
42  bNode *node,
43  bNodeExecData *UNUSED(execdata),
44  GPUNodeStack *in,
45  GPUNodeStack *out)
46 {
47  if (!in[5].link) {
48  GPU_link(mat, "world_normals_get", &in[5].link);
49  }
50 
51  float invert = (node->custom1) ? -1.0 : 1.0;
52 
53  return GPU_stack_link(
54  mat, node, "node_bump", in, out, GPU_builtin(GPU_VIEW_POSITION), GPU_constant(&invert));
55 }
56 
57 /* node type definition */
59 {
60  static bNodeType ntype;
61 
64  node_type_storage(&ntype, "", NULL, NULL);
66 
67  nodeRegisterType(&ntype);
68 }
void node_type_gpu(struct bNodeType *ntype, NodeGPUExecFunction gpu_fn)
Definition: node.cc:4645
void node_type_socket_templates(struct bNodeType *ntype, struct bNodeSocketTemplate *inputs, struct bNodeSocketTemplate *outputs)
Definition: node.cc:4527
void node_type_storage(struct bNodeType *ntype, const char *storagename, void(*freefunc)(struct bNode *node), void(*copyfunc)(struct bNodeTree *dest_ntree, struct bNode *dest_node, const struct bNode *src_node))
Definition: node.cc:4599
#define NODE_CLASS_OP_VECTOR
Definition: BKE_node.h:337
void nodeRegisterType(struct bNodeType *ntype)
Definition: node.cc:1298
#define UNUSED(x)
#define N_(msgid)
@ SOCK_HIDE_VALUE
@ SOCK_UNAVAIL
@ SOCK_VECTOR
@ SOCK_FLOAT
GPUNodeLink * GPU_builtin(eGPUBuiltin builtin)
GPUNodeLink * GPU_constant(const float *num)
@ GPU_VIEW_POSITION
Definition: GPU_material.h:91
bool GPU_link(GPUMaterial *mat, const char *name,...)
bool GPU_stack_link(GPUMaterial *mat, struct bNode *node, const char *name, GPUNodeStack *in, GPUNodeStack *out,...)
Group RGB to Bright Vector Camera Vector Combine Material Light Line Style Layer Add Ambient Diffuse Glossy Refraction Transparent Toon Principled Hair Volume Principled Light Particle Volume SH_NODE_BUMP
@ PROP_NONE
Definition: RNA_types.h:113
@ PROP_FACTOR
Definition: RNA_types.h:131
OperationNode * node
void register_node_type_sh_bump(void)
static bNodeSocketTemplate sh_node_bump_in[]
static bNodeSocketTemplate sh_node_bump_out[]
static int gpu_shader_bump(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
void sh_node_type_base(struct bNodeType *ntype, int type, const char *name, short nclass, short flag)
Compact definition of a node socket.
Definition: BKE_node.h:95
Defines a node type.
Definition: BKE_node.h:221
CCL_NAMESPACE_BEGIN ccl_device float invert(float color, float factor)
Definition: svm_invert.h:19