[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [20488] branches/soc-2009-yukishiro/source /blender: add a routine to load probe image and start buttons for light

Jingyuan Huang jingyuan.huang at gmail.com
Fri May 29 06:21:33 CEST 2009


Revision: 20488
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=20488
Author:   yukishiro
Date:     2009-05-29 06:21:32 +0200 (Fri, 29 May 2009)

Log Message:
-----------
add a routine to load probe image and start buttons for light

Modified Paths:
--------------
    branches/soc-2009-yukishiro/source/blender/blenkernel/BKE_lightenv.h
    branches/soc-2009-yukishiro/source/blender/blenkernel/intern/lightenv.c
    branches/soc-2009-yukishiro/source/blender/editors/include/UI_resources.h
    branches/soc-2009-yukishiro/source/blender/editors/space_buttons/buttons_header.c
    branches/soc-2009-yukishiro/source/blender/editors/space_buttons/buttons_intern.h
    branches/soc-2009-yukishiro/source/blender/editors/space_buttons/space_buttons.c
    branches/soc-2009-yukishiro/source/blender/makesdna/DNA_lightenv_types.h
    branches/soc-2009-yukishiro/source/blender/render/CMakeLists.txt
    branches/soc-2009-yukishiro/source/blender/sh/CMakeLists.txt
    branches/soc-2009-yukishiro/source/blender/sh/SConscript
    branches/soc-2009-yukishiro/source/blender/sh/intern/compute.c

Modified: branches/soc-2009-yukishiro/source/blender/blenkernel/BKE_lightenv.h
===================================================================
--- branches/soc-2009-yukishiro/source/blender/blenkernel/BKE_lightenv.h	2009-05-29 00:54:52 UTC (rev 20487)
+++ branches/soc-2009-yukishiro/source/blender/blenkernel/BKE_lightenv.h	2009-05-29 04:21:32 UTC (rev 20488)
@@ -42,6 +42,8 @@
 void free_lightenv(struct LightEnv *env); 
 LightEnv* add_lightenv(char *name);
 
+void load_probe_image(struct LightEnv *env, char *image_name);
+
 LightEnv* get_scene_lightenv(struct Scene *scene);
 
 #ifdef __cplusplus

Modified: branches/soc-2009-yukishiro/source/blender/blenkernel/intern/lightenv.c
===================================================================
--- branches/soc-2009-yukishiro/source/blender/blenkernel/intern/lightenv.c	2009-05-29 00:54:52 UTC (rev 20487)
+++ branches/soc-2009-yukishiro/source/blender/blenkernel/intern/lightenv.c	2009-05-29 04:21:32 UTC (rev 20488)
@@ -36,7 +36,7 @@
 #include "BKE_blender.h"
 #include "BKE_displist.h"
 #include "BKE_global.h"
-//#include "BKE_icons.h"
+#include "BKE_image.h"
 #include "BKE_library.h"
 #include "BKE_main.h"
 
@@ -44,12 +44,15 @@
 #include "DNA_world_types.h"
 #include "DNA_scene_types.h"
 
+#include "IMB_imbuf_types.h"
+
 #include "SH_api.h"
 
 LightEnv deflightenv;
 
+
 // TODO: simple function to return value for 3 channels. needs improvement
-void def_synthetic(float theta, float phi, float *val)
+void def_synthetic(float theta, float phi, float val[3], void *data)
 {
         if (theta < M_PI / 6) {
                 val[0] = val[1] = val[2] = 1.0;
@@ -59,26 +62,36 @@
         }
 }
 
-static void init_lightenv(LightEnv *env)
+void probe_value(float i, float j, float val[3], void *data)
 {
-        env->mtex = NULL;
-        env->preview = NULL;
-        
+        ImBuf *ibuf = (ImBuf*)data; 
+        int offset = ibuf->x * j * 4 + i * 4;
+        float* fval = (float*)ibuf->rect_float + offset;
+
+        val[0] = fval[0];
+        val[1] = fval[1];
+        val[2] = fval[2];
+}
+
+static void load_probe_image(struct LightEnv *env, const char *image_name)
+{
+        env->probe_image = BKE_add_image_file(image_name, 0);
+        env->type = LE_PROBE;
+        env->func = probe_value;
         SH_ComputeLightCoefficients(env);
 }
 
 /* called on startup, in SH_init() */
 void init_def_lightenv(void)
 {
+        deflightenv.type = LE_DEFAULT;
         deflightenv.func = def_synthetic;
-        init_lightenv(&deflightenv);
+        SH_ComputeLightCoefficients(&deflightenv);
 }
 
 void free_lightenv(LightEnv *env)
 {
-        // free texture
-
-//	BKE_previewimg_free(&env->preview);
+        // free probe 
 }
 
 
@@ -87,7 +100,8 @@
         LightEnv *env;
 
 	env= alloc_libblock(&G.main->lightenv, ID_LE, name);
-        init_lightenv(env);
+        env->type = LE_DEFAULT;
+        SH_ComputeLightCoefficients(env);
 
         return env;
 }
@@ -100,3 +114,5 @@
         if (world->lightenv == NULL) return &deflightenv;
         return world->lightenv;
 }
+
+

Modified: branches/soc-2009-yukishiro/source/blender/editors/include/UI_resources.h
===================================================================
--- branches/soc-2009-yukishiro/source/blender/editors/include/UI_resources.h	2009-05-29 00:54:52 UTC (rev 20487)
+++ branches/soc-2009-yukishiro/source/blender/editors/include/UI_resources.h	2009-05-29 04:21:32 UTC (rev 20488)
@@ -136,7 +136,7 @@
 	ICON_PARTICLES,
 	ICON_PHYSICS,
 	ICON_SPEAKER,
-	ICON_BLANK041,
+	ICON_LIGHT,
 	ICON_BLANK042,
 	ICON_BLANK043,
 	ICON_BLANK044,

Modified: branches/soc-2009-yukishiro/source/blender/editors/space_buttons/buttons_header.c
===================================================================
--- branches/soc-2009-yukishiro/source/blender/editors/space_buttons/buttons_header.c	2009-05-29 00:54:52 UTC (rev 20487)
+++ branches/soc-2009-yukishiro/source/blender/editors/space_buttons/buttons_header.c	2009-05-29 04:21:32 UTC (rev 20488)
@@ -190,6 +190,7 @@
 	uiBlockBeginAlign(block);
 	uiDefIconButS(block, ROW, B_CONTEXT_SWITCH,	ICON_SCENE,		xco, yco, XIC, YIC, &(sbuts->mainb), 0.0, (float)BCONTEXT_SCENE, 0, 0, "Scene");
 	uiDefIconButS(block, ROW, B_CONTEXT_SWITCH,	ICON_WORLD,		xco+=XIC, yco, XIC, YIC, &(sbuts->mainb), 0.0, (float)BCONTEXT_WORLD, 0, 0, "World");
+        uiDefIconButS(block, ROW, B_CONTEXT_SWITCH,     ICON_LIGHT,             xco+=XIC, yco, XIC, YIC, &(sbuts->mainb), 0.0, (float)BCONTEXT_LIGHT, 0, 0, "Light");
 	
 	// Specific panels, check on active object seletion
 	if(ob) {

Modified: branches/soc-2009-yukishiro/source/blender/editors/space_buttons/buttons_intern.h
===================================================================
--- branches/soc-2009-yukishiro/source/blender/editors/space_buttons/buttons_intern.h	2009-05-29 00:54:52 UTC (rev 20487)
+++ branches/soc-2009-yukishiro/source/blender/editors/space_buttons/buttons_intern.h	2009-05-29 04:21:32 UTC (rev 20488)
@@ -45,6 +45,7 @@
 #define BCONTEXT_GAME		8
 #define BCONTEXT_BONE		9
 #define BCONTEXT_MODIFIER	10
+#define BCONTEXT_LIGHT          11
 
 /* buts->scaflag */		
 #define BUTS_SENS_SEL		1

Modified: branches/soc-2009-yukishiro/source/blender/editors/space_buttons/space_buttons.c
===================================================================
--- branches/soc-2009-yukishiro/source/blender/editors/space_buttons/space_buttons.c	2009-05-29 00:54:52 UTC (rev 20487)
+++ branches/soc-2009-yukishiro/source/blender/editors/space_buttons/space_buttons.c	2009-05-29 04:21:32 UTC (rev 20488)
@@ -188,6 +188,8 @@
 		ED_region_panels(C, ar, vertical, "bone");
 	else if(sbuts->mainb == BCONTEXT_MODIFIER)
 		ED_region_panels(C, ar, vertical, "modifier");
+        else if(sbuts->mainb == BCONTEXT_LIGHT)
+		ED_region_panels(C, ar, vertical, "light");
 
     sbuts->re_align= 0;
 	sbuts->mainbo= sbuts->mainb;

Modified: branches/soc-2009-yukishiro/source/blender/makesdna/DNA_lightenv_types.h
===================================================================
--- branches/soc-2009-yukishiro/source/blender/makesdna/DNA_lightenv_types.h	2009-05-29 00:54:52 UTC (rev 20487)
+++ branches/soc-2009-yukishiro/source/blender/makesdna/DNA_lightenv_types.h	2009-05-29 04:21:32 UTC (rev 20488)
@@ -33,10 +33,10 @@
 #define DNA_LIGHTENV_TYPES_H
 
 #include "DNA_ID.h"
-#include "DNA_texture_types.h"
+#include "DNA_image_types.h"
 #include "DNA_scriptlink_types.h"
 
-typedef void (*light_func)(float theta, float phi, float *val);
+typedef void (*light_func)(float i1, float i2, float val[3], void *data);
 
 typedef struct LightEnv {
         ID id;
@@ -44,11 +44,8 @@
         short flag, type;
         float shcoeffs[25][3];
         light_func func;
-        struct MTex *mtex;
+        struct Image *probe_image; // image has preview
 
-	/* previews */
-	struct PreviewImage *preview;
-
 	ScriptLink scriptlink;
 
 } LightEnv;
@@ -58,7 +55,7 @@
 
 
 /* type */
-#define LE_DEFAULT
-#define LE_TEX
+#define LE_DEFAULT      1
+#define LE_PROBE        2
 
 #endif // DNA_LIGHTENV_TYPES_H

Modified: branches/soc-2009-yukishiro/source/blender/render/CMakeLists.txt
===================================================================
--- branches/soc-2009-yukishiro/source/blender/render/CMakeLists.txt	2009-05-29 00:54:52 UTC (rev 20487)
+++ branches/soc-2009-yukishiro/source/blender/render/CMakeLists.txt	2009-05-29 04:21:32 UTC (rev 20488)
@@ -29,7 +29,8 @@
 SET(INC 
   intern/include ../../../intern/guardedalloc ../blenlib ../makesdna
   extern/include ../blenkernel ../radiosity/extern/include ../imbuf
-  ../quicktime ../include ../../kernel/gen_messaging ../yafray ../blenloader
+  ../quicktime ../include ../../kernel/gen_messaging ../yafray 
+  ../blenloader ../sh
 )
 
 IF(NOT WITH_YAFRAY)

Modified: branches/soc-2009-yukishiro/source/blender/sh/CMakeLists.txt
===================================================================
--- branches/soc-2009-yukishiro/source/blender/sh/CMakeLists.txt	2009-05-29 00:54:52 UTC (rev 20487)
+++ branches/soc-2009-yukishiro/source/blender/sh/CMakeLists.txt	2009-05-29 04:21:32 UTC (rev 20488)
@@ -28,7 +28,7 @@
 
 SET(INC 
   intern/include ../../../intern/guardedalloc ../blenlib ../makesdna
-  extern/include ../blenkernel ../blenloader
+  extern/include ../blenkernel ../blenloader ../imbuf
 )
 
 BLENDERLIB_NOLIST(bf_sh "${SRC}" "${INC}")

Modified: branches/soc-2009-yukishiro/source/blender/sh/SConscript
===================================================================
--- branches/soc-2009-yukishiro/source/blender/sh/SConscript	2009-05-29 00:54:52 UTC (rev 20487)
+++ branches/soc-2009-yukishiro/source/blender/sh/SConscript	2009-05-29 04:21:32 UTC (rev 20488)
@@ -5,7 +5,7 @@
 sources = env.Glob('intern/*.c')
 
 incs = '#/intern/guardedalloc ../blenlib ../makesdna'
-incs += ' extern/include ../blenkernel ../blenloader'
+incs += ' extern/include ../blenkernel ../blenloader ../imbuf'
 
 env.BlenderLib ( libname = 'bf_sh', sources = sources, includes = Split(incs), libtype='core', priority=145, compileflags=cflags )
 

Modified: branches/soc-2009-yukishiro/source/blender/sh/intern/compute.c
===================================================================
--- branches/soc-2009-yukishiro/source/blender/sh/intern/compute.c	2009-05-29 00:54:52 UTC (rev 20487)
+++ branches/soc-2009-yukishiro/source/blender/sh/intern/compute.c	2009-05-29 04:21:32 UTC (rev 20488)
@@ -46,7 +46,11 @@
 #include "BKE_lightenv.h"
 #include "BKE_mesh.h"
 #include "BKE_customdata.h"
+#include "BKE_image.h"
 
+#include "IMB_imbuf_types.h"
+
+#define sinc(x) (fabs(x) < 1.0e-4 ? 1.0 : sin(x)/(x))
 #define v3_new_vec(a, b, c, u) { u[0] = a; u[1] = b; u[2] = c; }
 #define L 4
 #define NUM_SAMPLES 100
@@ -290,23 +294,63 @@
 
 void SH_ComputeLightCoefficients(LightEnv *env)
 {
-        int k, m;
-        float phi, theta, *y_val;
-        float l_val[3];
+        int k, m, i, j;
+        float phi, theta, *y_val, l_val[3];
+        float u, v, r, delta, dA, d_omega;
         int num_sh = (L+1)*(L+1);
+        ImBuf *ibuf;
+        Vec3 pnt;
+        ShCoeffs Y;
 
         // scaling is not done for light coeffs. an extra factor would be used
-        for (k = 0; k < NUM_SAMPLES; k++) {
-                phi = sample_angles[k][0];
-                theta = sample_angles[k][1];
-                env->func(phi, theta, l_val);
+        if (env->type == LE_DEFAULT) {
+                for (k = 0; k < NUM_SAMPLES; k++) {
+                        phi = sample_angles[k][0];

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list