[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [20524] branches/soc-2009-yukishiro/source /blender: add a function to output hdr from sh coeffs ( tested with two probe images).
Jingyuan Huang
jingyuan.huang at gmail.com
Sun May 31 03:33:47 CEST 2009
Revision: 20524
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=20524
Author: yukishiro
Date: 2009-05-31 03:33:44 +0200 (Sun, 31 May 2009)
Log Message:
-----------
add a function to output hdr from sh coeffs (tested with two probe images). also use verts/faces from dm instead of mesh
Modified Paths:
--------------
branches/soc-2009-yukishiro/source/blender/blenkernel/intern/DerivedMesh.c
branches/soc-2009-yukishiro/source/blender/blenkernel/intern/lightenv.c
branches/soc-2009-yukishiro/source/blender/editors/sculpt_paint/paint_light.c
branches/soc-2009-yukishiro/source/blender/editors/space_view3d/drawobject.c
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/intern/DerivedMesh.c
===================================================================
--- branches/soc-2009-yukishiro/source/blender/blenkernel/intern/DerivedMesh.c 2009-05-31 01:22:34 UTC (rev 20523)
+++ branches/soc-2009-yukishiro/source/blender/blenkernel/intern/DerivedMesh.c 2009-05-31 01:33:44 UTC (rev 20524)
@@ -1585,10 +1585,10 @@
static void add_sh_mcol_dm(Scene *scene, Object *ob, DerivedMesh *dm)
{
- Mesh *me = ob->data;
unsigned char *shcol;
+ int totface = dm->getNumFaces(dm);
- shcol = MEM_callocN (sizeof (unsigned char) * me->totface * 4 * 4, "sh color");
+ shcol = MEM_callocN (sizeof (unsigned char) * totface * 4 * 4, "sh color");
CustomData_add_layer(&dm->faceData, CD_SH_MCOL, CD_ASSIGN, shcol, dm->numFaceData);
}
Modified: branches/soc-2009-yukishiro/source/blender/blenkernel/intern/lightenv.c
===================================================================
--- branches/soc-2009-yukishiro/source/blender/blenkernel/intern/lightenv.c 2009-05-31 01:22:34 UTC (rev 20523)
+++ branches/soc-2009-yukishiro/source/blender/blenkernel/intern/lightenv.c 2009-05-31 01:33:44 UTC (rev 20524)
@@ -45,6 +45,7 @@
#include "DNA_scene_types.h"
#include "IMB_imbuf_types.h"
+#include "IMB_imbuf.h"
#include "SH_api.h"
@@ -73,7 +74,7 @@
val[2] = fval[2];
}
-static void load_probe_image(struct LightEnv *env, const char *image_name)
+static void load_probe_image(LightEnv *env, const char *image_name)
{
env->probe_image = BKE_add_image_file(image_name, 0);
env->type = LE_PROBE;
@@ -81,6 +82,14 @@
SH_ComputeLightCoefficients(env);
}
+static void save_probe_image(LightEnv *env, char *image_name, int w, int h)
+{
+ ImBuf * ibuf= IMB_allocImBuf(w, h, 32, IB_rectfloat, 0);
+ SH_ReconstructLightProbe(env, ibuf);
+ IMB_saveiff(ibuf, image_name, 0);
+ IMB_freeImBuf(ibuf);
+}
+
/* called on startup, in SH_init() */
void init_def_lightenv(void)
{
Modified: branches/soc-2009-yukishiro/source/blender/editors/sculpt_paint/paint_light.c
===================================================================
--- branches/soc-2009-yukishiro/source/blender/editors/sculpt_paint/paint_light.c 2009-05-31 01:22:34 UTC (rev 20523)
+++ branches/soc-2009-yukishiro/source/blender/editors/sculpt_paint/paint_light.c 2009-05-31 01:33:44 UTC (rev 20524)
@@ -78,7 +78,7 @@
typedef struct ShJob {
Scene *scene;
- wmWindow *win;
+ View3D *v3d;
short *stop;
short *do_update;
} ShJob;
@@ -97,7 +97,7 @@
sj->stop= stop;
sj->do_update= do_update;
- SH_ComputeSceneCoefficients(sj->scene);
+ SH_ComputeSceneCoefficients(sj->scene, sj->v3d);
}
static void toggle_paint_cursor(bContext *C, int enable)
@@ -115,32 +115,34 @@
// TODO: problem with using a job for the scene is that info header would display a render button....
+// TODO: somehow starting a job sometimes causes the application to hang. need investigation
static void initial_computation(bContext *C)
{
Scene *scene= CTX_data_scene(C);
- wmJob *job;
- ShJob *sj;
+ SH_ComputeSceneCoefficients(scene, CTX_wm_view3d(C));
+ //wmJob *job;
+ //ShJob *sj;
- /* only one job at a time */
- if(WM_jobs_test(CTX_wm_manager(C), scene)) return;
+ ///* only one job at a time */
+ //if(WM_jobs_test(CTX_wm_manager(C), scene)) return;
- /* handle UI stuff */
- WM_cursor_wait(1);
+ ///* handle UI stuff */
+ //WM_cursor_wait(1);
- /* job custom data */
- sj= MEM_callocN(sizeof(ShJob), "SH job");
- sj->scene= scene;
- sj->win= CTX_wm_window(C);
+ ///* job custom data */
+ //sj= MEM_callocN(sizeof(ShJob), "SH job");
+ //sj->scene= scene;
+ //sj->v3d= CTX_wm_view3d(C);
- /* setup job */
- job= WM_jobs_get(CTX_wm_manager(C), CTX_wm_window(C), scene);
- WM_jobs_customdata(job, sj, sh_freejob);
- WM_jobs_timer(job, 0.2, NC_SCENE|ND_SH_RESULT, 0);
- WM_jobs_callbacks(job, sh_startjob, NULL, NULL);
+ ///* setup job */
+ //job= WM_jobs_get(CTX_wm_manager(C), CTX_wm_window(C), scene);
+ //WM_jobs_customdata(job, sj, sh_freejob);
+ //WM_jobs_timer(job, 0.2, NC_SCENE|ND_SH_RESULT, 0);
+ //WM_jobs_callbacks(job, sh_startjob, NULL, NULL);
- /* start job */
- WM_jobs_start(job);
- WM_cursor_wait(0);
+ ///* start job */
+ //WM_jobs_start(job);
+ //WM_cursor_wait(0);
}
Modified: branches/soc-2009-yukishiro/source/blender/editors/space_view3d/drawobject.c
===================================================================
--- branches/soc-2009-yukishiro/source/blender/editors/space_view3d/drawobject.c 2009-05-31 01:22:34 UTC (rev 20523)
+++ branches/soc-2009-yukishiro/source/blender/editors/space_view3d/drawobject.c 2009-05-31 01:33:44 UTC (rev 20524)
@@ -2290,7 +2290,8 @@
int k;
// TODO: get vertex material colour
- mat = me->mat[0]; //me->mat[(int)v.mat_nr];
+ if (me->mat) mat = me->mat[0];
+
if (mat != NULL) {
color[0] = mat->r;
color[1] = mat->g;
@@ -2442,20 +2443,23 @@
dm->drawMappedFaces(dm, wpaint__setSolidDrawOptions, NULL, 0);
}
else if(G.f & G_LIGHTPAINT) {
- glDisable(GL_LIGHTING);
-
unsigned char *shcol;
LightEnv *env;
MShCoeffs *mco;
- MFace *mf = me->mface;
- int i;
+ MFace *mf = dm->getFaceArray(dm);//= me->mface;
+ int num_faces, i;
+ glDisable(GL_LIGHTING);
+ glColorMaterial(GL_FRONT,GL_AMBIENT_AND_DIFFUSE);
+ glEnable(GL_COLOR_MATERIAL);
+ glShadeModel(GL_SMOOTH);
+
shcol = DM_get_face_data_layer(dm, CD_SH_MCOL);
mco = CustomData_get_layer(&me->vdata, CD_MSHCOEFFS);
env = get_scene_lightenv(scene);
- // TODO: should get faces from dm?
- for (i=0; i<me->totface; i++, mf++) {
+ // TODO: calculation shouldn't be done every update
+ for (i=0; i<totface; i++, mf++) {
calc_sh_vert_color(ob, mf->v1, mco, env->shcoeffs, &shcol[(i*4 + 0) * 4]);
calc_sh_vert_color(ob, mf->v1, mco, env->shcoeffs, &shcol[(i*4 + 1) * 4]);
calc_sh_vert_color(ob, mf->v1, mco, env->shcoeffs, &shcol[(i*4 + 2) * 4]);
Modified: branches/soc-2009-yukishiro/source/blender/sh/SH_api.h
===================================================================
--- branches/soc-2009-yukishiro/source/blender/sh/SH_api.h 2009-05-31 01:22:34 UTC (rev 20523)
+++ branches/soc-2009-yukishiro/source/blender/sh/SH_api.h 2009-05-31 01:33:44 UTC (rev 20524)
@@ -30,13 +30,16 @@
#define _SH_API_H
struct Scene;
+struct View3D;
struct LightEnv;
+struct ImBuf;
void SH_init();
void SH_exit();
-void SH_ComputeSceneCoefficients(struct Scene *scene);
+void SH_ComputeSceneCoefficients(struct Scene *scene, struct View3D *v3d);
void SH_ComputeLightCoefficients(struct LightEnv *env);
+void SH_ReconstructLightProbe(struct LightEnv *env, struct ImBuf *ibuf);
void SH_from_disc(int L, float *n, float area, float *shresult);
float SH_eval(float *sh, float *v);
Modified: branches/soc-2009-yukishiro/source/blender/sh/intern/compute.c
===================================================================
--- branches/soc-2009-yukishiro/source/blender/sh/intern/compute.c 2009-05-31 01:22:34 UTC (rev 20523)
+++ branches/soc-2009-yukishiro/source/blender/sh/intern/compute.c 2009-05-31 01:33:44 UTC (rev 20524)
@@ -42,7 +42,9 @@
#include "DNA_node_types.h"
#include "DNA_object_types.h"
#include "DNA_scene_types.h"
+#include "DNA_view3d_types.h"
+#include "BKE_DerivedMesh.h"
#include "BKE_lightenv.h"
#include "BKE_mesh.h"
#include "BKE_customdata.h"
@@ -248,30 +250,40 @@
}
-void SH_ComputeSceneCoefficients(Scene *scene)
+void SH_ComputeSceneCoefficients(Scene *scene, View3D *v3d)
{
Base *base = scene->basact;
Object *ob;
Mesh *me;
+ DerivedMesh *dm;
MShCoeffs *coeffs;
MVert v;
int i, k, m;
float N, *y_val;
- int num_sh=(L+1)*(L+1);
+ int num_verts, num_sh=(L+1)*(L+1);
float weight=4.0f/(float)NUM_SAMPLES;
// for now, just use single-thread
+ // use derived mesh...
for (base = scene->basact; base; base = base->next) {
ob = base->object;
me = get_mesh(ob);
-
if (me == NULL) continue;
- coeffs= CustomData_add_layer(&me->vdata, CD_MSHCOEFFS, CD_CALLOC, NULL, me->totvert);
+ dm = mesh_get_derived_final(scene, ob, v3d->customdata_mask);
+ num_verts = dm->getNumVerts(dm);
+ printf("# v %d\n", num_verts);
- for (i = 0; i < me->totvert; i++) {
- v = me->mvert[i];
+ if (CustomData_has_layer(&me->vdata, CD_MSHCOEFFS)) {
+ printf("has layer\n");
+ continue;
+ }
+ coeffs= CustomData_add_layer(&me->vdata, CD_MSHCOEFFS, CD_CALLOC, NULL, num_verts);
+
+ for (i = 0; i < num_verts; i++) {
+ dm->getVert(dm, i, &v);
+
for (k = 0; k < NUM_SAMPLES; k++) {
N = (samples[k][0] * v.no[0] +
samples[k][1] * v.no[1] +
@@ -354,6 +366,49 @@
}
}
+void SH_ReconstructLightProbe(LightEnv *env, ImBuf *ibuf)
+{
+ int m, i, j;
+ float phi, theta, *y_val, *lval;
+ float u, v, r, delta;
+ int offset, num_sh = (L+1)*(L+1);
+ Vec3 pnt;
+ ShCoeffs Y;
+
+ Y = allocate_ShCoeffs();
+ delta = 2.0f / (float)ibuf->x;
+
+ for (i = 0; i < ibuf->x; i++) {
+ for (j = 0; j < ibuf->y; j++) {
+ offset = ibuf->x * j * 4 + i * 4;
+ lval = (float*)ibuf->rect_float + offset;
+
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list