[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [36549] branches/particles-2010/source/ blender: Implemented node groups for GLSL shading materials.
Lukas Toenne
lukas.toenne at googlemail.com
Sun May 8 16:23:39 CEST 2011
Revision: 36549
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=36549
Author: lukastoenne
Date: 2011-05-08 14:23:38 +0000 (Sun, 08 May 2011)
Log Message:
-----------
Implemented node groups for GLSL shading materials.
Fixed a couple of bugs.
Modified Paths:
--------------
branches/particles-2010/source/blender/blenkernel/BKE_node.h
branches/particles-2010/source/blender/blenkernel/intern/node.c
branches/particles-2010/source/blender/blenloader/intern/readfile.c
branches/particles-2010/source/blender/makesdna/DNA_node_types.h
branches/particles-2010/source/blender/nodes/intern/SHD_nodes/SHD_common.c
branches/particles-2010/source/blender/nodes/intern/SHD_nodes/SHD_normal.c
branches/particles-2010/source/blender/nodes/intern/SHD_nodetree.c
branches/particles-2010/source/blender/nodes/intern/SHD_util.c
branches/particles-2010/source/blender/nodes/intern/SHD_util.h
Modified: branches/particles-2010/source/blender/blenkernel/BKE_node.h
===================================================================
--- branches/particles-2010/source/blender/blenkernel/BKE_node.h 2011-05-08 12:51:05 UTC (rev 36548)
+++ branches/particles-2010/source/blender/blenkernel/BKE_node.h 2011-05-08 14:23:38 UTC (rev 36549)
@@ -200,6 +200,8 @@
void (*newexecfunc)(void *data, int thread, struct bNode *, void *nodedata, struct bNodeStack **, struct bNodeStack **);
/* gpu */
int (*gpufunc)(struct GPUMaterial *mat, struct bNode *node, struct GPUNodeStack *in, struct GPUNodeStack *out);
+ /* extended gpu function */
+ int (*gpuextfunc)(struct GPUMaterial *mat, struct bNode *node, void *nodedata, struct GPUNodeStack *in, struct GPUNodeStack *out);
} bNodeType;
/* node->exec, now in use for composites (#define for break is same as ready yes) */
@@ -390,11 +392,12 @@
void (*edit_clear)(struct bNode *node));
void node_type_exec(struct bNodeType *ntype, void (*execfunc)(void *data, struct bNode *, struct bNodeStack **, struct bNodeStack **));
-void node_type_gpu(struct bNodeType *ntype, int (*gpufunc)(struct GPUMaterial *mat, struct bNode *node, struct GPUNodeStack *in, struct GPUNodeStack *out));
void node_type_exec_new(struct bNodeType *ntype,
void *(*initexecfunc)(struct bNode *node),
void (*freeexecfunc)(struct bNode *node, void *nodedata),
void (*newexecfunc)(void *data, int thread, struct bNode *, void *nodedata, struct bNodeStack **, struct bNodeStack **));
+void node_type_gpu(struct bNodeType *ntype, int (*gpufunc)(struct GPUMaterial *mat, struct bNode *node, struct GPUNodeStack *in, struct GPUNodeStack *out));
+void node_type_gpu_ext(struct bNodeType *ntype, int (*gpuextfunc)(struct GPUMaterial *mat, struct bNode *node, void *nodedata, struct GPUNodeStack *in, struct GPUNodeStack *out));
/* ************** COMMON NODES *************** */
Modified: branches/particles-2010/source/blender/blenkernel/intern/node.c
===================================================================
--- branches/particles-2010/source/blender/blenkernel/intern/node.c 2011-05-08 12:51:05 UTC (rev 36548)
+++ branches/particles-2010/source/blender/blenkernel/intern/node.c 2011-05-08 14:23:38 UTC (rev 36549)
@@ -1733,11 +1733,6 @@
ntype->execfunc = execfunc;
}
-void node_type_gpu(struct bNodeType *ntype, int (*gpufunc)(struct GPUMaterial *mat, struct bNode *node, struct GPUNodeStack *in, struct GPUNodeStack *out))
-{
- ntype->gpufunc = gpufunc;
-}
-
void node_type_exec_new(struct bNodeType *ntype,
void *(*initexecfunc)(struct bNode *node),
void (*freeexecfunc)(struct bNode *node, void *nodedata),
@@ -1748,7 +1743,17 @@
ntype->newexecfunc = newexecfunc;
}
+void node_type_gpu(struct bNodeType *ntype, int (*gpufunc)(struct GPUMaterial *mat, struct bNode *node, struct GPUNodeStack *in, struct GPUNodeStack *out))
+{
+ ntype->gpufunc = gpufunc;
+}
+void node_type_gpu_ext(struct bNodeType *ntype, int (*gpuextfunc)(struct GPUMaterial *mat, struct bNode *node, void *nodedata, struct GPUNodeStack *in, struct GPUNodeStack *out))
+{
+ ntype->gpuextfunc = gpuextfunc;
+}
+
+
static bNodeType *is_nodetype_registered(ListBase *typelist, int type)
{
bNodeType *ntype= typelist->first;
Modified: branches/particles-2010/source/blender/blenloader/intern/readfile.c
===================================================================
--- branches/particles-2010/source/blender/blenloader/intern/readfile.c 2011-05-08 12:51:05 UTC (rev 36548)
+++ branches/particles-2010/source/blender/blenloader/intern/readfile.c 2011-05-08 14:23:38 UTC (rev 36549)
@@ -2114,7 +2114,7 @@
bNodeTree *ntree;
int i;
bNodeTreeType *ntreetype;
-
+
/* this crashes blender on undo/redo
if(open==1) {
reinit_nodesystem();
@@ -2199,9 +2199,6 @@
link_list(fd, &node->inputs);
link_list(fd, &node->outputs);
- link_list(fd, &node->inpanels);
- link_list(fd, &node->outpanels);
-
node->storage= newdataadr(fd, node->storage);
if(node->storage) {
/* could be handlerized at some point */
@@ -6895,6 +6892,9 @@
bNodeSocketValueVector *valvector;
bNodeSocketValueRGBA *valrgba;
+ if (sock->default_value)
+ return;
+
switch (sock->type) {
case SOCK_FLOAT:
valfloat = sock->default_value = MEM_callocN(sizeof(bNodeSocketValueFloat), "default socket value");
Modified: branches/particles-2010/source/blender/makesdna/DNA_node_types.h
===================================================================
--- branches/particles-2010/source/blender/makesdna/DNA_node_types.h 2011-05-08 12:51:05 UTC (rev 36548)
+++ branches/particles-2010/source/blender/makesdna/DNA_node_types.h 2011-05-08 14:23:38 UTC (rev 36549)
@@ -142,7 +142,6 @@
short nr; /* number of this node in list, used for UI exec events */
ListBase inputs, outputs;
- ListBase inpanels, outpanels;
struct bNode *parent; /* parent node */
struct ID *id; /* optional link to libdata */
void *storage; /* custom data, must be struct, for storage in file */
Modified: branches/particles-2010/source/blender/nodes/intern/SHD_nodes/SHD_common.c
===================================================================
--- branches/particles-2010/source/blender/nodes/intern/SHD_nodes/SHD_common.c 2011-05-08 12:51:05 UTC (rev 36548)
+++ branches/particles-2010/source/blender/nodes/intern/SHD_nodes/SHD_common.c 2011-05-08 14:23:38 UTC (rev 36549)
@@ -68,12 +68,36 @@
}
}
+static void copy_gpu_stack(GPUNodeStack *to, GPUNodeStack *from)
+{
+ if (to != from) {
+ copy_v4_v4(to->vec, from->vec);
+ to->link = from->link;
+
+ /* tag as copy to prevent freeing */
+// to->is_copy = 1;
+ }
+}
+
+static void move_gpu_stack(GPUNodeStack *to, GPUNodeStack *from)
+{
+ if (to != from) {
+ copy_v4_v4(to->vec, from->vec);
+ to->link = from->link;
+// to->is_copy = from->is_copy;
+
+// zero_v4(from->vec);
+ from->link = NULL;
+// from->is_copy = 0;
+ }
+}
+
/**** GROUP ****/
static void *group_initexec(bNode *node)
{
bNodeTree *ngroup= (bNodeTree*)node->id;
- void *exec;
+ bNodeTreeExec *exec;
/* initialize the internal node tree execution */
exec = ntreeShaderBeginExecTree(ngroup);
@@ -89,7 +113,6 @@
}
/* Copy inputs to the internal stack.
- * This is a shallow copy, no buffers are duplicated here!
*/
static void group_copy_inputs(bNode *node, bNodeStack **in, bNodeStack *gstack)
{
@@ -142,6 +165,47 @@
ntreeReleaseThreadStack(nts);
}
+static void group_gpu_copy_inputs(bNode *node, GPUNodeStack *in, bNodeStack *gstack)
+{
+ bNodeSocket *sock;
+ bNodeStack *ns;
+ int a;
+ for (sock=node->inputs.first, a=0; sock; sock=sock->next, ++a) {
+ if (sock->groupsock) {
+ ns = node_get_socket_stack(gstack, sock->groupsock);
+ /* convert the external gpu stack back to internal node stack data */
+ node_data_from_gpu_stack(ns, &in[a]);
+ }
+ }
+}
+
+/* Copy internal results to the external outputs.
+ */
+static void group_gpu_move_outputs(bNode *node, GPUNodeStack *out, bNodeStack *gstack)
+{
+ bNodeSocket *sock;
+ bNodeStack *ns;
+ int a;
+ for (sock=node->outputs.first, a=0; sock; sock=sock->next, ++a) {
+ if (sock->groupsock) {
+ ns = node_get_socket_stack(gstack, sock->groupsock);
+ /* convert the node stack data result back to gpu stack */
+ node_gpu_stack_from_data(&out[a], ns);
+ }
+ }
+}
+
+static int gpu_group_execute(GPUMaterial *mat, bNode *node, void *nodedata, GPUNodeStack *in, GPUNodeStack *out)
+{
+ bNodeTreeExec *exec= (bNodeTreeExec*)nodedata;
+
+ group_gpu_copy_inputs(node, in, exec->stack);
+ ntreeExecGPUNodes(exec, mat, (node->flag & NODE_GROUP_EDIT));
+ group_gpu_move_outputs(node, out, exec->stack);
+
+ return 1;
+}
+
void register_node_type_group_shader(ListBase *lb)
{
static bNodeType ntype;
@@ -156,6 +220,7 @@
node_type_update(&ntype, NULL, node_group_verify);
node_type_edit(&ntype, node_group_edit_get, node_group_edit_set, node_group_edit_clear);
node_type_exec_new(&ntype, group_initexec, group_freeexec, group_execute);
+ node_type_gpu_ext(&ntype, gpu_group_execute);
nodeRegisterType(lb, &ntype);
}
Modified: branches/particles-2010/source/blender/nodes/intern/SHD_nodes/SHD_normal.c
===================================================================
--- branches/particles-2010/source/blender/nodes/intern/SHD_nodes/SHD_normal.c 2011-05-08 12:51:05 UTC (rev 36548)
+++ branches/particles-2010/source/blender/nodes/intern/SHD_nodes/SHD_normal.c 2011-05-08 14:23:38 UTC (rev 36549)
@@ -57,7 +57,7 @@
nodestack_get_vec(vec, SOCK_VECTOR, in[0]);
- VECCOPY(out[0]->vec, (float*)sock->default_value);
+ VECCOPY(out[0]->vec, ((bNodeSocketValueVector*)sock->default_value)->value);
/* render normals point inside... the widget points outside */
out[1]->vec[0]= -INPR(out[0]->vec, vec);
}
@@ -65,7 +65,7 @@
static int gpu_shader_normal(GPUMaterial *mat, bNode *node, GPUNodeStack *in, GPUNodeStack *out)
{
bNodeSocket *sock= node->outputs.first;
- GPUNodeLink *vec = GPU_uniform((float*)sock->default_value);
+ GPUNodeLink *vec = GPU_uniform(((bNodeSocketValueVector*)sock->default_value)->value);
return GPU_stack_link(mat, "normal", in, out, vec);
}
Modified: branches/particles-2010/source/blender/nodes/intern/SHD_nodetree.c
===================================================================
--- branches/particles-2010/source/blender/nodes/intern/SHD_nodetree.c 2011-05-08 12:51:05 UTC (rev 36548)
+++ branches/particles-2010/source/blender/nodes/intern/SHD_nodetree.c 2011-05-08 14:23:38 UTC (rev 36549)
@@ -96,115 +96,15 @@
/* GPU material from shader nodes */
-static void gpu_from_node_stack(ListBase *sockets, bNodeStack **ns, GPUNodeStack *gs)
-{
- bNodeSocket *sock;
- int i;
-
- for (sock=sockets->first, i=0; sock; sock=sock->next, i++) {
- memset(&gs[i], 0, sizeof(gs[i]));
-
- QUATCOPY(gs[i].vec, ns[i]->vec);
- gs[i].link= ns[i]->data;
-
- if (sock->type == SOCK_FLOAT)
- gs[i].type= GPU_FLOAT;
- else if (sock->type == SOCK_VECTOR)
- gs[i].type= GPU_VEC3;
- else if (sock->type == SOCK_RGBA)
- gs[i].type= GPU_VEC4;
- else
- gs[i].type= GPU_NONE;
-
- gs[i].name = "";
- gs[i].hasinput= ns[i]->hasinput && ns[i]->data;
- gs[i].hasoutput= ns[i]->hasoutput && ns[i]->data;
- gs[i].sockettype= ns[i]->sockettype;
- }
-
- gs[i].type= GPU_NONE;
-}
-
-static void data_from_gpu_stack(ListBase *sockets, bNodeStack **ns, GPUNodeStack *gs)
-{
- bNodeSocket *sock;
- int i;
-
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list