[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [21393] branches/soc-2009-yukishiro/source /blender: add light node preview and correct light env preview

Jingyuan Huang jingyuan.huang at gmail.com
Tue Jul 7 03:21:05 CEST 2009


Revision: 21393
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=21393
Author:   yukishiro
Date:     2009-07-07 03:21:02 +0200 (Tue, 07 Jul 2009)

Log Message:
-----------
add light node preview and correct light env preview

Modified Paths:
--------------
    branches/soc-2009-yukishiro/source/blender/blenkernel/intern/icons.c
    branches/soc-2009-yukishiro/source/blender/editors/include/ED_previewrender.h
    branches/soc-2009-yukishiro/source/blender/editors/preview/SConscript
    branches/soc-2009-yukishiro/source/blender/editors/preview/previewrender.c
    branches/soc-2009-yukishiro/source/blender/editors/space_node/node_draw.c
    branches/soc-2009-yukishiro/source/blender/editors/space_node/node_header.c
    branches/soc-2009-yukishiro/source/blender/editors/space_node/space_node.c
    branches/soc-2009-yukishiro/source/blender/makesdna/DNA_ID.h
    branches/soc-2009-yukishiro/source/blender/nodes/CMakeLists.txt
    branches/soc-2009-yukishiro/source/blender/nodes/intern/LGT_nodes/LGT_lightenv.c
    branches/soc-2009-yukishiro/source/blender/nodes/intern/LGT_util.c
    branches/soc-2009-yukishiro/source/blender/nodes/intern/LGT_util.h
    branches/soc-2009-yukishiro/source/blender/render/intern/source/rendercore.c
    branches/soc-2009-yukishiro/source/blender/sh/CMakeLists.txt

Modified: branches/soc-2009-yukishiro/source/blender/blenkernel/intern/icons.c
===================================================================
--- branches/soc-2009-yukishiro/source/blender/blenkernel/intern/icons.c	2009-07-06 20:07:00 UTC (rev 21392)
+++ branches/soc-2009-yukishiro/source/blender/blenkernel/intern/icons.c	2009-07-07 01:21:02 UTC (rev 21393)
@@ -44,6 +44,7 @@
 #include "DNA_material_types.h"
 #include "DNA_texture_types.h"
 #include "DNA_world_types.h"
+#include "DNA_lightenv_types.h"
 
 #include "BLI_ghash.h"
 
@@ -208,7 +209,11 @@
 		Image *img  = (Image*)id;
 		if (!img->preview) img->preview = BKE_previewimg_create();
 		prv_img = img->preview;
-	} 
+	} else if (GS(id->name) == ID_LE) {
+		LightEnv *env = (LightEnv*)id;
+		if (!env->preview) env->preview = BKE_previewimg_create();
+		prv_img = env->preview;
+	}
 
 	return prv_img;
 }

Modified: branches/soc-2009-yukishiro/source/blender/editors/include/ED_previewrender.h
===================================================================
--- branches/soc-2009-yukishiro/source/blender/editors/include/ED_previewrender.h	2009-07-06 20:07:00 UTC (rev 21392)
+++ branches/soc-2009-yukishiro/source/blender/editors/include/ED_previewrender.h	2009-07-07 01:21:02 UTC (rev 21393)
@@ -71,6 +71,7 @@
 void ED_preview_free_dbase(void);
 
 void ED_preview_shader_job(const struct bContext *C, void *owner, struct ID *id, int sizex, int sizey);
+void ED_preview_lightenv_job(const struct bContext *C, void *owner, struct ID *id, int sizex, int sizey);
 void ED_preview_iconrender(struct Scene *scene, struct ID *id, int *rect, int sizex, int sizey);
 
 void ED_preview_draw(const struct bContext *C, void *idp, rcti *rect);

Modified: branches/soc-2009-yukishiro/source/blender/editors/preview/SConscript
===================================================================
--- branches/soc-2009-yukishiro/source/blender/editors/preview/SConscript	2009-07-06 20:07:00 UTC (rev 21392)
+++ branches/soc-2009-yukishiro/source/blender/editors/preview/SConscript	2009-07-07 01:21:02 UTC (rev 21393)
@@ -7,6 +7,6 @@
 incs += ' ../../windowmanager #/intern/guardedalloc #/extern/glew/include'
 incs += ' #/intern/guardedalloc ../../gpu'
 incs += ' ../../makesrna ../../render/extern/include  #/intern/elbeem/extern'
-incs += ' ../../blenloader'
+incs += ' ../../blenloader ../../sh'
 
 env.BlenderLib ( 'bf_editors_preview', sources, Split(incs), [], libtype=['core'], priority=[45] )

Modified: branches/soc-2009-yukishiro/source/blender/editors/preview/previewrender.c
===================================================================
--- branches/soc-2009-yukishiro/source/blender/editors/preview/previewrender.c	2009-07-06 20:07:00 UTC (rev 21392)
+++ branches/soc-2009-yukishiro/source/blender/editors/preview/previewrender.c	2009-07-07 01:21:02 UTC (rev 21393)
@@ -95,6 +95,8 @@
 
 #include "UI_interface.h"
 
+#include "SH_api.h"
+
 #include "previewrender_intern.h"
 
 #define PR_XMIN		10
@@ -415,40 +417,50 @@
 void ED_preview_draw(const bContext *C, void *idp, rcti *rect)
 {
 	if(idp) {
+		ID *id = (ID*)idp;
 		ScrArea *sa= CTX_wm_area(C);
-		SpaceButs *sbuts= sa->spacedata.first;
-		RenderResult rres;
 		int newx= rect->xmax-rect->xmin, newy= rect->ymax-rect->ymin;
-		int ok= 0;
-		char name[32];
-		
-		sprintf(name, "Preview %p", sa);
-		BLI_lock_malloc_thread();
-		RE_GetResultImage(RE_GetRender(name), &rres);
 
-		if(rres.rectf) {
+		if (GS(id->name) == ID_LE) {
+			PreviewImage * preview = BKE_previewimg_get(id);
+
+			ED_preview_lightenv_job(C, sa, idp, newx, newy);
+			glaDrawPixelsSafe(rect->xmin, rect->ymin, newx, newy, newx, GL_RGBA, GL_FLOAT, preview->rectf);
+		}
+		else {
+			SpaceButs *sbuts= sa->spacedata.first;
+			RenderResult rres;
+			int ok= 0;
+			char name[32];
 			
-			if( ABS(rres.rectx-newx)<2 && ABS(rres.recty-newy)<2 ) {
-				/* correct size, then black outline matches */
-				rect->xmax= rect->xmin + rres.rectx;
-				rect->ymax= rect->ymin + rres.recty;
+			sprintf(name, "Preview %p", sa);
+			BLI_lock_malloc_thread();
+			RE_GetResultImage(RE_GetRender(name), &rres);
+
+			if(rres.rectf) {
+				
+				if( ABS(rres.rectx-newx)<2 && ABS(rres.recty-newy)<2 ) {
+					/* correct size, then black outline matches */
+					rect->xmax= rect->xmin + rres.rectx;
+					rect->ymax= rect->ymin + rres.recty;
+				
+					glaDrawPixelsSafe(rect->xmin, rect->ymin, rres.rectx, rres.recty, rres.rectx, GL_RGBA, GL_FLOAT, rres.rectf);
+					ok= 1;
+				}
+			}
+			BLI_unlock_malloc_thread();
+
+			/* check for spacetype... */
+			if(sbuts->spacetype==SPACE_BUTS && sbuts->preview) {
+				sbuts->preview= 0;
+				ok= 0;
+			}
 			
-				glaDrawPixelsSafe(rect->xmin, rect->ymin, rres.rectx, rres.recty, rres.rectx, GL_RGBA, GL_FLOAT, rres.rectf);
-				ok= 1;
+			if(ok==0) {
+				ED_preview_shader_job(C, sa, idp, newx, newy);
 			}
 		}
-		BLI_unlock_malloc_thread();
-
-		/* check for spacetype... */
-		if(sbuts->spacetype==SPACE_BUTS && sbuts->preview) {
-			sbuts->preview= 0;
-			ok= 0;
-		}
-		
-		if(ok==0) {
-			ED_preview_shader_job(C, sa, idp, newx, newy);
-		}
-	}	
+	}
 }
 
 /* *************************** Preview for 3d window *********************** */
@@ -898,6 +910,22 @@
 	BKE_icon_changed(BKE_icon_getid(id));
 }
 
+// TODO: it's a fake job now
+void ED_preview_lightenv_job(const bContext *C, void *owner, ID *id, int sizex, int sizey)
+{
+	LightEnv * env = (LightEnv *)id;
+
+	if(env->nodetree && env->use_nodes) {
+		ntreeLightExecTree(env->nodetree, env);
+	}
+
+	// TODO write to env's preview
+	PreviewImage * preview = BKE_previewimg_get(id);
+	if (preview->rectf) MEM_freeN(preview->rectf);
+	preview->rectf= MEM_callocN(4*sizex + sizex*sizey*sizeof(float)*4, "lightenv preview rect");
+	SH_lightProbePreview(env, sizex, sizey, 0, 0, sizex, sizey, preview->rectf);
+}
+
 /* rect should be allocated, sizex/sizy pixels, 32 bits */
 void ED_preview_iconrender(Scene *scene, ID *id, int *rect, int sizex, int sizey)
 {

Modified: branches/soc-2009-yukishiro/source/blender/editors/space_node/node_draw.c
===================================================================
--- branches/soc-2009-yukishiro/source/blender/editors/space_node/node_draw.c	2009-07-06 20:07:00 UTC (rev 21392)
+++ branches/soc-2009-yukishiro/source/blender/editors/space_node/node_draw.c	2009-07-07 01:21:02 UTC (rev 21393)
@@ -922,7 +922,6 @@
 	int a;
 	
 	if(ntree==NULL) return;		/* groups... */
-	
 	/* node lines */
 	glEnable(GL_BLEND);
 	glEnable(GL_LINE_SMOOTH);

Modified: branches/soc-2009-yukishiro/source/blender/editors/space_node/node_header.c
===================================================================
--- branches/soc-2009-yukishiro/source/blender/editors/space_node/node_header.c	2009-07-06 20:07:00 UTC (rev 21392)
+++ branches/soc-2009-yukishiro/source/blender/editors/space_node/node_header.c	2009-07-07 01:21:02 UTC (rev 21393)
@@ -693,7 +693,7 @@
 			if (env) {
 				if (env->use_nodes && env->nodetree==NULL) {
 					node_lightenv_default(env);
-					//TODO: snode_set_context(snode, env);
+					snode_set_context(snode, scene);
 				}
 			}
 			ED_area_tag_redraw(CTX_wm_area(C));			

Modified: branches/soc-2009-yukishiro/source/blender/editors/space_node/space_node.c
===================================================================
--- branches/soc-2009-yukishiro/source/blender/editors/space_node/space_node.c	2009-07-06 20:07:00 UTC (rev 21392)
+++ branches/soc-2009-yukishiro/source/blender/editors/space_node/space_node.c	2009-07-07 01:21:02 UTC (rev 21393)
@@ -36,6 +36,7 @@
 #include "DNA_space_types.h"
 #include "DNA_scene_types.h"
 #include "DNA_screen_types.h"
+#include "DNA_lightenv_types.h"
 
 #include "MEM_guardedalloc.h"
 
@@ -175,6 +176,11 @@
 			if(scene->use_nodes)
 				snode_composite_job(C, sa);
 		}
+		else if(snode->treetype==NTREE_LIGHT) {
+			LightEnv *env = (LightEnv *)snode->id;
+			if(env->use_nodes)
+				ED_preview_lightenv_job(C, sa, snode->id, 100, 100); 
+		}
 	}
 }
 

Modified: branches/soc-2009-yukishiro/source/blender/makesdna/DNA_ID.h
===================================================================
--- branches/soc-2009-yukishiro/source/blender/makesdna/DNA_ID.h	2009-07-06 20:07:00 UTC (rev 21392)
+++ branches/soc-2009-yukishiro/source/blender/makesdna/DNA_ID.h	2009-07-07 01:21:02 UTC (rev 21393)
@@ -132,6 +132,7 @@
 	short changed[2];
 	short pad0, pad1;
 	unsigned int * rect[2];
+	float * rectf; // TODO
 } PreviewImage;
 
 /**

Modified: branches/soc-2009-yukishiro/source/blender/nodes/CMakeLists.txt
===================================================================
--- branches/soc-2009-yukishiro/source/blender/nodes/CMakeLists.txt	2009-07-06 20:07:00 UTC (rev 21392)
+++ branches/soc-2009-yukishiro/source/blender/nodes/CMakeLists.txt	2009-07-07 01:21:02 UTC (rev 21393)
@@ -23,7 +23,7 @@
 #
 # ***** END GPL LICENSE BLOCK *****
 
-FILE(GLOB SRC intern/*.c intern/CMP_nodes/*.c intern/SHD_nodes/*.c intern/TEX_nodes/*.c)
+FILE(GLOB SRC intern/*.c intern/CMP_nodes/*.c intern/SHD_nodes/*.c intern/TEX_nodes/*.c intern/LGT_nodes/*.c)
 
 SET(INC 
   . ../../../intern/guardedalloc ../editors/include ../blenlib ../makesdna

Modified: branches/soc-2009-yukishiro/source/blender/nodes/intern/LGT_nodes/LGT_lightenv.c
===================================================================
--- branches/soc-2009-yukishiro/source/blender/nodes/intern/LGT_nodes/LGT_lightenv.c	2009-07-06 20:07:00 UTC (rev 21392)
+++ branches/soc-2009-yukishiro/source/blender/nodes/intern/LGT_nodes/LGT_lightenv.c	2009-07-07 01:21:02 UTC (rev 21393)
@@ -26,34 +26,28 @@
  * ***** END GPL LICENSE BLOCK *****
  */
 
-#include "../TEX_util.h"
+#include "../LGT_util.h"
 
 static bNodeSocketType outputs[]= {
 	{ SOCK_RGBA, 0, "Color", 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f },
 	{ -1, 0, "" }
 };
 
-//static void lgt_do_preview(bNode *node, bNodeStack *ns, LightCallData *cdata)
-//{
-//	LightEnv *env;
-//	bNodePreview *preview;
-//	int x, y;
-//
-//	if(!(node->typeinfo->flag & NODE_PREVIEW))
-//		return;
-//
-//	init_preview(node);
-//	preview = node->preview;
-//
-//	SH_lightProbePreview(env, preview->xsize, preview->ysize,
-//		0, 0, preview->xsize, preview->ysize, preview->rect);
-//
-//			//tex_input_rgba(result, ns, cdata->coord, cdata->thread);
-//}
-
 static void exec(void *data, bNode *node, bNodeStack **in, bNodeStack **out)
 {
-	// only out[0]
+	LightCallData * lcd = (LightCallData *)data;
+	LightEnv * env = (LightEnv *)node->id;
+	bNodePreview *preview;
+
+	if(!(node->typeinfo->flag & NODE_PREVIEW))
+		return;
+

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list