[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [21140] branches/soc-2009-yukishiro/source /blender: an incomplete attempt to add sh shadow coeffs calculation

Jingyuan Huang jingyuan.huang at gmail.com
Wed Jun 24 23:03:37 CEST 2009


Revision: 21140
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=21140
Author:   yukishiro
Date:     2009-06-24 23:03:37 +0200 (Wed, 24 Jun 2009)

Log Message:
-----------
an incomplete attempt to add sh shadow coeffs calculation

Modified Paths:
--------------
    branches/soc-2009-yukishiro/source/blender/editors/sculpt_paint/paint_light.c
    branches/soc-2009-yukishiro/source/blender/sh/SConscript
    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/editors/sculpt_paint/paint_light.c
===================================================================
--- branches/soc-2009-yukishiro/source/blender/editors/sculpt_paint/paint_light.c	2009-06-24 19:38:40 UTC (rev 21139)
+++ branches/soc-2009-yukishiro/source/blender/editors/sculpt_paint/paint_light.c	2009-06-24 21:03:37 UTC (rev 21140)
@@ -110,7 +110,7 @@
 	if (sj->scene->lightenv == NULL) 
 		add_lightenv(sj->scene, "LightEnv");
 
-	SH_computeSceneCoefficients(sj->scene, sj->mask, sj->recompute);
+	SH_computeSceneCoefficients(sj->scene, sj->mask, 0, sj->recompute);
 }
 
 

Modified: branches/soc-2009-yukishiro/source/blender/sh/SConscript
===================================================================
--- branches/soc-2009-yukishiro/source/blender/sh/SConscript	2009-06-24 19:38:40 UTC (rev 21139)
+++ branches/soc-2009-yukishiro/source/blender/sh/SConscript	2009-06-24 21:03:37 UTC (rev 21140)
@@ -8,6 +8,7 @@
 incs = 'intern/levmar'
 incs += ' #/intern/guardedalloc ../blenlib ../makesdna'
 incs += ' extern/include ../blenkernel ../blenloader ../imbuf'
+incs += ' ../render/extern/include'
 
 env.BlenderLib ( libname = 'bf_sh', sources = sources, includes = Split(incs), libtype='core', priority=145, compileflags=cflags )
 

Modified: branches/soc-2009-yukishiro/source/blender/sh/SH_api.h
===================================================================
--- branches/soc-2009-yukishiro/source/blender/sh/SH_api.h	2009-06-24 19:38:40 UTC (rev 21139)
+++ branches/soc-2009-yukishiro/source/blender/sh/SH_api.h	2009-06-24 21:03:37 UTC (rev 21140)
@@ -37,7 +37,8 @@
 void SH_init();
 void SH_exit();
 
-void SH_computeSceneCoefficients(struct Scene *scene, unsigned int customdata_mask, short recompute);
+void SH_computeSceneCoefficients(struct Scene *scene, unsigned int customdata_mask, 
+				 short compute_shadow, short recompute);
 void SH_computeLightCoefficients(struct LightEnv *env);
 
 void SH_rotateLightEnv(struct LightEnv *env, float quat[4]);

Modified: branches/soc-2009-yukishiro/source/blender/sh/intern/compute.c
===================================================================
--- branches/soc-2009-yukishiro/source/blender/sh/intern/compute.c	2009-06-24 19:38:40 UTC (rev 21139)
+++ branches/soc-2009-yukishiro/source/blender/sh/intern/compute.c	2009-06-24 21:03:37 UTC (rev 21140)
@@ -51,9 +51,12 @@
 #include "BKE_mesh.h"
 #include "BKE_customdata.h"
 #include "BKE_image.h"
+#include "BKE_utildefines.h"
 
 #include "IMB_imbuf_types.h"
 
+#include "RE_raytrace.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
@@ -439,7 +442,85 @@
         }
 }
 
+static void ray_coords_func(RayFace *face, float **v1, float **v2, float **v3, float **v4)
+{
+	//MFace *mface= (MFace*)face;
+	//float (*verts)[3]= HeatSys->heat.verts;
 
+	//*v1= verts[mface->v1];
+	//*v2= verts[mface->v2];
+	//*v3= verts[mface->v3];
+	//*v4= (mface->v4)? verts[mface->v4]: NULL;
+}
+
+static int ray_check_func(Isect *is, int ob, RayFace *face)
+{
+	//float *v1, *v2, *v3, *v4, nor[3];
+
+	///* don't intersect if the ray faces along the face normal */
+	//heat_ray_coords_func(face, &v1, &v2, &v3, &v4);
+
+	//if(v4) CalcNormFloat4(v1, v2, v3, v4, nor);
+	//else CalcNormFloat(v1, v2, v3, nor);
+
+	//return (INPR(nor, is->vec) < 0);
+	return 0;
+}
+
+static float *ray_get_transform(void *userdata, int i)
+{
+	//ObjectInstanceRen *obi= RAY_OBJECT_GET((Render*)userdata, i);
+
+	//return (obi->flag & R_TRANSFORMED)? (float*)obi->mat: NULL;
+	return NULL;
+}
+
+static void create_ray_tree(Scene *scene, unsigned int customdata_mask, RayTree *tree)
+{
+        Base *base= NULL;
+        Object *ob= NULL;
+        Mesh *me= NULL;
+        DerivedMesh *dm= NULL;
+	MFace *faces= NULL;
+
+        int i, num_faces= 0, totface= 0;
+	float min[3], max[3];
+	INIT_MINMAX(min, max);
+
+        for (base = scene->base.first; base; base = base->next) {
+                ob = base->object;
+                me = get_mesh(ob);
+                if (me == NULL) continue;
+
+                dm = mesh_get_derived_final(scene, ob, customdata_mask);
+		dm->getMinMax(dm, min, max);
+
+		totface += dm->getNumFaces(dm);
+	}
+
+	//XXX: 64 is constant... and cb functions...
+	tree= RE_ray_tree_create(64, totface, min, max,
+		ray_coords_func, ray_check_func, ray_get_transform, NULL);
+
+	// add faces
+	for (base = scene->base.first; base; base = base->next) {
+                ob = base->object;
+                me = get_mesh(ob);
+                if (me == NULL) continue;
+
+                dm = mesh_get_derived_final(scene, ob, customdata_mask);
+		num_faces = dm->getNumFaces(dm);
+		faces = dm->getFaceArray(dm);
+
+		for (i = 0; i < num_faces; i++) {
+			RE_ray_tree_add_face(tree, 0, faces+i);
+		}
+	}
+
+	RE_ray_tree_done(tree);
+}
+
+
 /* called on startup, in WM_init() */
 void SH_init()
 {
@@ -472,7 +553,7 @@
 }
 
 
-void SH_computeSceneCoefficients(Scene *scene, unsigned int customdata_mask, short recompute)
+void SH_computeSceneCoefficients(Scene *scene, unsigned int customdata_mask, short compute_shadow, short recompute)
 {
         Base *base= NULL;
         Object *ob= NULL;
@@ -480,15 +561,20 @@
         DerivedMesh *dm= NULL;
         MShCoeffs *coeffs= NULL;
         MVert* verts= NULL;
+	RayTree *tree = NULL;
 	LightEnv* env=scene->lightenv;
 
+	Isect isec;
         int i, k, m;
         float N, *y_val;
         int num_verts= 0;
 	int num_sh= (env->degree + 1) * (env->degree + 1);
         float weight= 4.0f/(float)NUM_SAMPLES;
+	int visible;
 
-        // for now, just use single-thread
+	if (compute_shadow) 
+		create_ray_tree(scene, customdata_mask, tree);
+
         // use derived mesh...
         for (base = scene->base.first; base; base = base->next) {
                 ob = base->object;
@@ -512,10 +598,27 @@
                                      samples[k][2] * verts[i].no[2]) / 32767.0;
 
                                 if (N > 0) {
-                                        y_val = *(samples_Y[k]);
-                                        for (m = 0; m < num_sh; m++) {
-                                                coeffs[i].val[m] += N * y_val[m];
-                                        }
+					if (compute_shadow) {
+						memset(&isec, 0, sizeof(isec));
+						isec.mode= RE_RAY_SHADOW;
+						isec.lay= -1;
+						isec.face_last= NULL;
+						//isec.faceorig= mface;
+						VECCOPY(isec.start, verts[i].co);
+						VECCOPY(isec.end, samples[k]);
+
+						visible= !RE_ray_tree_intersect(tree, &isec);
+					} 
+					else {
+						visible = 1;
+					}
+
+					if (visible) {
+                                        	y_val = *(samples_Y[k]);
+                                        	for (m = 0; m < num_sh; m++) {
+                                        	        coeffs[i].val[m] += N * y_val[m];
+                                        	}
+					}
                                 }
                         }
                         for (m = 0; m < num_sh; m++) {





More information about the Bf-blender-cvs mailing list