[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [21902] branches/soc-2009-yukishiro/source /blender: add lightenv output node

Jingyuan Huang jingyuan.huang at gmail.com
Sat Jul 25 23:33:16 CEST 2009


Revision: 21902
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=21902
Author:   yukishiro
Date:     2009-07-25 23:33:16 +0200 (Sat, 25 Jul 2009)

Log Message:
-----------
add lightenv output node

Modified Paths:
--------------
    branches/soc-2009-yukishiro/source/blender/blenkernel/BKE_node.h
    branches/soc-2009-yukishiro/source/blender/blenkernel/intern/lightenv.c
    branches/soc-2009-yukishiro/source/blender/blenkernel/intern/node.c
    branches/soc-2009-yukishiro/source/blender/editors/space_node/drawnode.c
    branches/soc-2009-yukishiro/source/blender/makesdna/DNA_lightenv_types.h
    branches/soc-2009-yukishiro/source/blender/nodes/TEX_node.h
    branches/soc-2009-yukishiro/source/blender/nodes/intern/TEX_nodes/TEX_lightenv.c
    branches/soc-2009-yukishiro/source/blender/nodes/intern/TEX_util.c
    branches/soc-2009-yukishiro/source/blender/nodes/intern/TEX_util.h
    branches/soc-2009-yukishiro/source/blender/sh/SH_api.h
    branches/soc-2009-yukishiro/source/blender/sh/intern/compute.c

Modified: branches/soc-2009-yukishiro/source/blender/blenkernel/BKE_node.h
===================================================================
--- branches/soc-2009-yukishiro/source/blender/blenkernel/BKE_node.h	2009-07-25 21:31:17 UTC (rev 21901)
+++ branches/soc-2009-yukishiro/source/blender/blenkernel/BKE_node.h	2009-07-25 21:33:16 UTC (rev 21902)
@@ -412,6 +412,7 @@
 #define TEX_NODE_SCALE      422
 #define TEX_NODE_AT         423
 #define TEX_NODE_LIGHTENV   424
+#define TEX_NODE_LGT_OUTPUT 425
 
 /* 501-599 reserved. Use like this: TEX_NODE_PROC + TEX_CLOUDS, etc */
 #define TEX_NODE_PROC      500

Modified: branches/soc-2009-yukishiro/source/blender/blenkernel/intern/lightenv.c
===================================================================
--- branches/soc-2009-yukishiro/source/blender/blenkernel/intern/lightenv.c	2009-07-25 21:31:17 UTC (rev 21901)
+++ branches/soc-2009-yukishiro/source/blender/blenkernel/intern/lightenv.c	2009-07-25 21:33:16 UTC (rev 21902)
@@ -88,6 +88,7 @@
 	env->degree = 2;
 	env->num_samples = 10;
 	env->output_width = env->output_height = 512;
+	env->Y = SH_allocate_Y();
 	SH_computeLightCoefficients(env);
 }
 
@@ -143,6 +144,7 @@
 
 void free_lightenv(LightEnv *env)
 {
+	SH_free_Y(env->Y);
 	if (env->preview) {
 		BKE_previewimg_free(&env->preview);
 	}
@@ -172,6 +174,7 @@
 	new_env->num_samples = env->num_samples;
 	new_env->output_width = env->output_width;
 	new_env->output_height = env->output_height;
+	new_env->Y = new_env->Y;
 
 	if (env->preview) new_env->preview = BKE_previewimg_copy(env->preview);
 

Modified: branches/soc-2009-yukishiro/source/blender/blenkernel/intern/node.c
===================================================================
--- branches/soc-2009-yukishiro/source/blender/blenkernel/intern/node.c	2009-07-25 21:31:17 UTC (rev 21901)
+++ branches/soc-2009-yukishiro/source/blender/blenkernel/intern/node.c	2009-07-25 21:33:16 UTC (rev 21902)
@@ -3047,6 +3047,7 @@
 	nodeRegisterType(ntypelist, &tex_node_bricks);
 	nodeRegisterType(ntypelist, &tex_node_image);
 	nodeRegisterType(ntypelist, &tex_node_lightenv);
+	nodeRegisterType(ntypelist, &tex_node_lightenv_output);
 	
 	nodeRegisterType(ntypelist, &tex_node_rotate);
 	nodeRegisterType(ntypelist, &tex_node_translate);

Modified: branches/soc-2009-yukishiro/source/blender/editors/space_node/drawnode.c
===================================================================
--- branches/soc-2009-yukishiro/source/blender/editors/space_node/drawnode.c	2009-07-25 21:31:17 UTC (rev 21901)
+++ branches/soc-2009-yukishiro/source/blender/editors/space_node/drawnode.c	2009-07-25 21:33:16 UTC (rev 21902)
@@ -2389,6 +2389,39 @@
 	return 30; // XXX
 }
 
+static int node_texture_buts_lightenv_output(uiBlock *block, bNodeTree *ntree, bNode *node, rctf *butr)
+{
+	if(block) {
+		uiBut *bt;
+		char *strp;
+
+		/* browse button lightenv */
+		uiBlockBeginAlign(block);
+		IDnames_to_pupstring(&strp, NULL, "", &(node->id), NULL, NULL);
+		node->menunr= 0;
+		bt= uiDefButS(block, MENU, B_NOP, strp,
+			butr->xmin, butr->ymin, 19, 19, &node->menunr, 0, 0, 0, 0, 
+			"Browse existing light envs");
+		uiButSetFunc(bt, node_browse_lightenv_cb, ntree, node);
+		if(strp) MEM_freeN(strp);
+
+		if(node->id == NULL) {
+			//
+		} else {
+			/* name button */
+			short width= (short)(butr->xmax-butr->xmin-19.0f);
+			bt= uiDefBut(block, TEX, B_NOP, "LE:",
+				butr->xmin+19, butr->ymin, width, 19, 
+				node->id->name+2, 0.0, 19.0, 0, 0, "LightEnv name");
+			uiButSetFunc(bt, node_ID_title_cb, node, NULL);
+		}
+		uiBlockEndAlign(block);
+	}
+
+	return 30; // XXX
+
+}
+
 /* only once called */
 static void node_texture_set_butfunc(bNodeType *ntype)
 {
@@ -2436,6 +2469,10 @@
 		case TEX_NODE_LIGHTENV:
 			ntype->butfunc = node_texture_buts_lightenv;
 			break;
+
+		case TEX_NODE_LGT_OUTPUT:
+			ntype->butfunc = node_texture_buts_lightenv_output;
+			break;
 			
 		default:
 			ntype->butfunc= NULL;

Modified: branches/soc-2009-yukishiro/source/blender/makesdna/DNA_lightenv_types.h
===================================================================
--- branches/soc-2009-yukishiro/source/blender/makesdna/DNA_lightenv_types.h	2009-07-25 21:31:17 UTC (rev 21901)
+++ branches/soc-2009-yukishiro/source/blender/makesdna/DNA_lightenv_types.h	2009-07-25 21:33:16 UTC (rev 21902)
@@ -42,6 +42,7 @@
 	int degree, num_samples;
 	int output_width, output_height;
 	float shcoeffs[25][3];
+	float **Y;
 
 	void (*light_func)(float i1, float i2, float val[3], void *data);
 	struct Image *probe_image; // image has preview

Modified: branches/soc-2009-yukishiro/source/blender/nodes/TEX_node.h
===================================================================
--- branches/soc-2009-yukishiro/source/blender/nodes/TEX_node.h	2009-07-25 21:31:17 UTC (rev 21901)
+++ branches/soc-2009-yukishiro/source/blender/nodes/TEX_node.h	2009-07-25 21:33:16 UTC (rev 21902)
@@ -56,6 +56,7 @@
 extern bNodeType tex_node_coord;
 extern bNodeType tex_node_distance;
 extern bNodeType tex_node_lightenv;
+extern bNodeType tex_node_lightenv_output;
 
 extern bNodeType tex_node_rotate;
 extern bNodeType tex_node_translate;

Modified: branches/soc-2009-yukishiro/source/blender/nodes/intern/TEX_nodes/TEX_lightenv.c
===================================================================
--- branches/soc-2009-yukishiro/source/blender/nodes/intern/TEX_nodes/TEX_lightenv.c	2009-07-25 21:31:17 UTC (rev 21901)
+++ branches/soc-2009-yukishiro/source/blender/nodes/intern/TEX_nodes/TEX_lightenv.c	2009-07-25 21:33:16 UTC (rev 21902)
@@ -30,6 +30,11 @@
 
 #include "../TEX_util.h"
 
+static bNodeSocketType inputs[] = {
+	{ SOCK_RGBA, 0, "Color",  0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f},
+	{ -1, 0, "" }
+};
+
 static bNodeSocketType outputs[]= {
 	{ SOCK_RGBA, 0, "Image",  0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f},
 	{ -1, 0, "" }
@@ -47,7 +52,6 @@
 	}
 };
 
-
 static void exec(void *data, bNode *node, bNodeStack **in, bNodeStack **out)
 {
 	tex_output(node, in, out[0], &colorfn);
@@ -55,6 +59,49 @@
 	tex_do_preview(node, out[0], data);
 }
 
+void output_do_preview(bNode *node, bNodeStack *ns, TexCallData *cdata)
+{
+	int x, y;
+	float *result;
+	bNodePreview *preview;
+	LightEnv *env = (LightEnv *)node->id;
+	
+	if(!cdata->do_preview)
+		return;
+	
+	if(!(node->typeinfo->flag & NODE_PREVIEW))
+		return;
+	
+	init_preview(node);
+	preview = node->preview;
+	memset(env->shcoeffs, 0, sizeof(float) * 75);
+	
+	for(x=0; x<preview->xsize; x++)
+	for(y=0; y<preview->ysize; y++)
+	{
+		cdata->coord[0] = ((float) x / preview->xsize) * 2.0 - 1;
+		cdata->coord[1] = ((float) y / preview->ysize) * 2.0 - 1;
+		
+		result = preview->rect + 4 * (preview->xsize*y + x);
+		
+		tex_input_rgba(result, ns, cdata->coord, cdata->thread);
+		SH_ComputeLightCoefficient(env, cdata->coord[0], cdata->coord[1], 
+				preview->xsize, preview->ysize, result);
+	}
+}
+
+static void exec_output(void *data, bNode *node, bNodeStack **in, bNodeStack **out)
+{
+	LightEnv *env = (LightEnv *)node->id;
+
+	if (env == NULL) {
+		node->id = (ID *)add_lightenv("LightEnvNode");
+	}
+
+	output_do_preview(node, in[0], data);
+}
+
+
 bNodeType tex_node_lightenv= {
 	/* *next,*prev */	NULL, NULL,
 	/* type code   */	TEX_NODE_LIGHTENV,
@@ -72,3 +119,22 @@
 	/* id          */	NULL
 };
 
+
+bNodeType tex_node_lightenv_output= {
+	/* *next,*prev */	NULL, NULL,
+	/* type code   */	TEX_NODE_LGT_OUTPUT,
+	/* name        */	"LightEnv",
+	/* width+range */	120, 80, 300,
+	/* class+opts  */	NODE_CLASS_OUTPUT, NODE_PREVIEW|NODE_OPTIONS,
+	/* input sock  */	inputs,
+	/* output sock */	NULL,
+	/* storage     */	"",
+	/* execfunc    */	exec_output,
+	/* butfunc     */	NULL,
+	/* initfunc    */	NULL,
+	/* freestoragefunc */	NULL,
+	/* copystoragefunc */	NULL,
+	/* id          */	NULL
+};
+
+

Modified: branches/soc-2009-yukishiro/source/blender/nodes/intern/TEX_util.c
===================================================================
--- branches/soc-2009-yukishiro/source/blender/nodes/intern/TEX_util.c	2009-07-25 21:31:17 UTC (rev 21901)
+++ branches/soc-2009-yukishiro/source/blender/nodes/intern/TEX_util.c	2009-07-25 21:33:16 UTC (rev 21902)
@@ -95,7 +95,7 @@
 	return out[0];
 }
 
-static void init_preview(bNode *node)
+void init_preview(bNode *node)
 {
 	int xsize = (int)(node->prvr.xmax - node->prvr.xmin);
 	int ysize = (int)(node->prvr.ymax - node->prvr.ymin);

Modified: branches/soc-2009-yukishiro/source/blender/nodes/intern/TEX_util.h
===================================================================
--- branches/soc-2009-yukishiro/source/blender/nodes/intern/TEX_util.h	2009-07-25 21:31:17 UTC (rev 21901)
+++ branches/soc-2009-yukishiro/source/blender/nodes/intern/TEX_util.h	2009-07-25 21:33:16 UTC (rev 21902)
@@ -98,6 +98,7 @@
 
 void tex_output(bNode *node, bNodeStack **in, bNodeStack *out, TexFn texfn);
 void tex_do_preview(bNode *node, bNodeStack *ns, TexCallData *cdata);
+void init_preview(bNode *node);
 
 void ntreeTexUpdatePreviews( bNodeTree* nodetree );
 void ntreeTexExecTree(bNodeTree *nodes, TexResult *texres, float *coord, char do_preview, short thread, struct Tex *tex, short which_output, int cfra);

Modified: branches/soc-2009-yukishiro/source/blender/sh/SH_api.h
===================================================================
--- branches/soc-2009-yukishiro/source/blender/sh/SH_api.h	2009-07-25 21:31:17 UTC (rev 21901)
+++ branches/soc-2009-yukishiro/source/blender/sh/SH_api.h	2009-07-25 21:33:16 UTC (rev 21902)
@@ -37,10 +37,14 @@
 void SH_init();
 void SH_exit();
 
+float** SH_allocate_Y();
+void SH_free_Y(float** Y);
+
 void SH_computeSceneCoefficients(struct Scene *scene, unsigned int customdata_mask, 
 				 short compute_shadow, short recompute);
 void SH_computeMeshCoefficients(struct Scene *scene, struct Object *ob, unsigned int customdata_mask);
 void SH_computeLightCoefficients(struct LightEnv *env);
+void SH_ComputeLightCoefficient(struct LightEnv *env, float u, float v, float xsize, float ysize, float *val);
 
 void SH_rotateLightEnv(struct LightEnv *env, float quat[4], float viewmat[][4], float viewinv[][4]);
 

Modified: branches/soc-2009-yukishiro/source/blender/sh/intern/compute.c
===================================================================
--- branches/soc-2009-yukishiro/source/blender/sh/intern/compute.c	2009-07-25 21:31:17 UTC (rev 21901)
+++ branches/soc-2009-yukishiro/source/blender/sh/intern/compute.c	2009-07-25 21:33:16 UTC (rev 21902)
@@ -80,14 +80,14 @@
 static ShCoeffs *samples_Y;
 
 
-static void free_ShCoeffs(ShCoeffs sh_coeffs)

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list