diff options
Diffstat (limited to 'source/blender/nodes/shader')
-rw-r--r-- | source/blender/nodes/shader/node_shader_util.c | 2 | ||||
-rw-r--r-- | source/blender/nodes/shader/nodes/node_shader_mapping.c | 102 |
2 files changed, 20 insertions, 84 deletions
diff --git a/source/blender/nodes/shader/node_shader_util.c b/source/blender/nodes/shader/node_shader_util.c index 65676a5ea91..a2b18b61480 100644 --- a/source/blender/nodes/shader/node_shader_util.c +++ b/source/blender/nodes/shader/node_shader_util.c @@ -280,7 +280,7 @@ void node_shader_gpu_tex_mapping(GPUMaterial *mat, tmat2 = GPU_uniform((float *)texmap->mat[2]); tmat3 = GPU_uniform((float *)texmap->mat[3]); - GPU_link(mat, "mapping", in[0].link, tmat0, tmat1, tmat2, tmat3, tmin, tmax, &in[0].link); + GPU_link(mat, "mapping_mat4", in[0].link, tmat0, tmat1, tmat2, tmat3, tmin, tmax, &in[0].link); if (texmap->type == TEXMAP_TYPE_NORMAL) { GPU_link(mat, "vector_normalize", in[0].link, &in[0].link); diff --git a/source/blender/nodes/shader/nodes/node_shader_mapping.c b/source/blender/nodes/shader/nodes/node_shader_mapping.c index e58a5d72f28..d607fcdc7a1 100644 --- a/source/blender/nodes/shader/nodes/node_shader_mapping.c +++ b/source/blender/nodes/shader/nodes/node_shader_mapping.c @@ -25,7 +25,10 @@ /* **************** MAPPING ******************** */ static bNodeSocketTemplate sh_node_mapping_in[] = { - {SOCK_VECTOR, 1, N_("Vector"), 0.0f, 0.0f, 0.0f, 1.0f, -1.0f, 1.0f, PROP_NONE}, + {SOCK_VECTOR, 1, N_("Vector"), 0.0f, 0.0f, 0.0f, 1.0f, -FLT_MAX, FLT_MAX, PROP_NONE}, + {SOCK_VECTOR, 1, N_("Location"), 0.0f, 0.0f, 0.0f, 1.0f, -FLT_MAX, FLT_MAX, PROP_TRANSLATION}, + {SOCK_VECTOR, 1, N_("Rotation"), 0.0f, 0.0f, 0.0f, 1.0f, -FLT_MAX, FLT_MAX, PROP_EULER}, + {SOCK_VECTOR, 1, N_("Scale"), 1.0f, 1.0f, 1.0f, 1.0f, -FLT_MAX, FLT_MAX, PROP_XYZ}, {-1, 0, ""}, }; @@ -34,91 +37,27 @@ static bNodeSocketTemplate sh_node_mapping_out[] = { {-1, 0, ""}, }; -static void *node_shader_initexec_mapping(bNodeExecContext *UNUSED(context), - bNode *node, - bNodeInstanceKey UNUSED(key)) -{ - TexMapping *texmap = node->storage; - BKE_texture_mapping_init(texmap); - return NULL; -} - -/* do the regular mapping options for blender textures */ -static void node_shader_exec_mapping(void *UNUSED(data), - int UNUSED(thread), - bNode *node, - bNodeExecData *UNUSED(execdata), - bNodeStack **in, - bNodeStack **out) -{ - TexMapping *texmap = node->storage; - float *vec = out[0]->vec; - - /* stack order input: vector */ - /* stack order output: vector */ - nodestack_get_vec(vec, SOCK_VECTOR, in[0]); - mul_m4_v3(texmap->mat, vec); - - if (texmap->flag & TEXMAP_CLIP_MIN) { - if (vec[0] < texmap->min[0]) { - vec[0] = texmap->min[0]; - } - if (vec[1] < texmap->min[1]) { - vec[1] = texmap->min[1]; - } - if (vec[2] < texmap->min[2]) { - vec[2] = texmap->min[2]; - } - } - if (texmap->flag & TEXMAP_CLIP_MAX) { - if (vec[0] > texmap->max[0]) { - vec[0] = texmap->max[0]; - } - if (vec[1] > texmap->max[1]) { - vec[1] = texmap->max[1]; - } - if (vec[2] > texmap->max[2]) { - vec[2] = texmap->max[2]; - } - } - - if (texmap->type == TEXMAP_TYPE_NORMAL) { - normalize_v3(vec); - } -} - -static void node_shader_init_mapping(bNodeTree *UNUSED(ntree), bNode *node) -{ - node->storage = BKE_texture_mapping_add(TEXMAP_TYPE_POINT); -} - static int gpu_shader_mapping(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out) { - TexMapping *texmap = node->storage; - float domin = (texmap->flag & TEXMAP_CLIP_MIN) != 0; - float domax = (texmap->flag & TEXMAP_CLIP_MAX) != 0; - static float max[3] = {FLT_MAX, FLT_MAX, FLT_MAX}; - static float min[3] = {-FLT_MAX, -FLT_MAX, -FLT_MAX}; - GPUNodeLink *tmin, *tmax, *tmat0, *tmat1, *tmat2, *tmat3; - - tmin = GPU_uniform((domin) ? texmap->min : min); - tmax = GPU_uniform((domax) ? texmap->max : max); - tmat0 = GPU_uniform((float *)texmap->mat[0]); - tmat1 = GPU_uniform((float *)texmap->mat[1]); - tmat2 = GPU_uniform((float *)texmap->mat[2]); - tmat3 = GPU_uniform((float *)texmap->mat[3]); - - GPU_stack_link(mat, node, "mapping", in, out, tmat0, tmat1, tmat2, tmat3, tmin, tmax); - - if (texmap->type == TEXMAP_TYPE_NORMAL) { - GPU_link(mat, "vector_normalize", out[0].link, &out[0].link); - } + static const char *names[] = { + [NODE_MAPPING_TYPE_POINT] = "mapping_point", + [NODE_MAPPING_TYPE_TEXTURE] = "mapping_texture", + [NODE_MAPPING_TYPE_VECTOR] = "mapping_vector", + [NODE_MAPPING_TYPE_NORMAL] = "mapping_normal", + }; + + return GPU_stack_link(mat, node, names[node->custom1], in, out); +} - return true; +static void node_shader_update_mapping(bNodeTree *UNUSED(ntree), bNode *node) +{ + bNodeSocket *sock = nodeFindSocket(node, SOCK_IN, "Location"); + nodeSetSocketAvailability( + sock, ELEM(node->custom1, NODE_MAPPING_TYPE_POINT, NODE_MAPPING_TYPE_TEXTURE)); } void register_node_type_sh_mapping(void) @@ -127,11 +66,8 @@ void register_node_type_sh_mapping(void) sh_node_type_base(&ntype, SH_NODE_MAPPING, "Mapping", NODE_CLASS_OP_VECTOR, 0); node_type_socket_templates(&ntype, sh_node_mapping_in, sh_node_mapping_out); - node_type_size(&ntype, 320, 160, 360); - node_type_init(&ntype, node_shader_init_mapping); - node_type_storage(&ntype, "TexMapping", node_free_standard_storage, node_copy_standard_storage); - node_type_exec(&ntype, node_shader_initexec_mapping, NULL, node_shader_exec_mapping); node_type_gpu(&ntype, gpu_shader_mapping); + node_type_update(&ntype, node_shader_update_mapping); nodeRegisterType(&ntype); } |