[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [13450] trunk/blender/source/blender:

Brecht Van Lommel brechtvanlommel at pandora.be
Tue Jan 29 13:20:48 CET 2008


Revision: 13450
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=13450
Author:   blendix
Date:     2008-01-29 13:20:42 +0100 (Tue, 29 Jan 2008)

Log Message:
-----------

Bounding box clipping in the render engine.

Now bounding boxes are computed per object, and checked first before
zbuffering objects. For strands, bounding boxes are computed per
original face in the mesh. Overall the speed improvement from this 
is quite small (zbuffering is rarely the bottleneck), but it seems a
sensible thing to do anyway.

Modified Paths:
--------------
    trunk/blender/source/blender/blenkernel/intern/particle_system.c
    trunk/blender/source/blender/render/intern/include/render_types.h
    trunk/blender/source/blender/render/intern/include/renderdatabase.h
    trunk/blender/source/blender/render/intern/include/strand.h
    trunk/blender/source/blender/render/intern/source/convertblender.c
    trunk/blender/source/blender/render/intern/source/renderdatabase.c
    trunk/blender/source/blender/render/intern/source/strand.c
    trunk/blender/source/blender/render/intern/source/zbuf.c

Modified: trunk/blender/source/blender/blenkernel/intern/particle_system.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/particle_system.c	2008-01-29 09:51:29 UTC (rev 13449)
+++ trunk/blender/source/blender/blenkernel/intern/particle_system.c	2008-01-29 12:20:42 UTC (rev 13450)
@@ -780,6 +780,21 @@
 	return 0;
 }
 
+/* not thread safe, but qsort doesn't take userdata argument */
+static int *COMPARE_ORIG_INDEX = NULL;
+static int compare_orig_index(const void *p1, const void *p2)
+{
+	int index1 = COMPARE_ORIG_INDEX[*(const int*)p1];
+	int index2 = COMPARE_ORIG_INDEX[*(const int*)p2];
+
+	if(index1 < index2)
+		return -1;
+	else if(index1 == index2)
+		return 0;
+	else
+		return 1;
+}
+
 /* creates a distribution of coordinates on a DerivedMesh	*/
 /*															*/
 /* 1. lets check from what we are emitting					*/
@@ -1157,6 +1172,13 @@
 
 	MEM_freeN(sum);
 
+	/* for hair, sort by origindex, allows optimizations in rendering */
+	if(part->type == PART_HAIR) {
+		COMPARE_ORIG_INDEX= dm->getFaceDataArray(dm, CD_ORIGINDEX);
+		if(COMPARE_ORIG_INDEX)
+			qsort(index, totpart, sizeof(int), compare_orig_index);
+	}
+
 	/* weights are no longer used except for FROM_PARTICLE, which needs them zeroed for indexing */
 	if(from==PART_FROM_PARTICLE){
 		for(i=0; i<tot; i++)

Modified: trunk/blender/source/blender/render/intern/include/render_types.h
===================================================================
--- trunk/blender/source/blender/render/intern/include/render_types.h	2008-01-29 09:51:29 UTC (rev 13449)
+++ trunk/blender/source/blender/render/intern/include/render_types.h	2008-01-29 12:20:42 UTC (rev 13450)
@@ -247,13 +247,15 @@
 	struct Scene *sce;
 	int index, psysindex, flag, lay;
 
+	float boundbox[2][3];
+
 	int totvert, totvlak, totstrand, tothalo;
 	int vertnodeslen, vlaknodeslen, strandnodeslen, blohalen;
 	struct VertTableNode *vertnodes;
 	struct VlakTableNode *vlaknodes;
 	struct StrandTableNode *strandnodes;
 	struct HaloRen **bloha;
-	ListBase strandbufs;
+	struct StrandBuffer *strandbuf;
 
 	char (*mtface)[32];
 	char (*mcol)[32];
@@ -346,7 +348,7 @@
 	int (*face)[4];
 	float (*co)[3];
 	/* for occlusion caching */
-	float (*col)[3];					/* for occlusion */
+	float (*col)[3];
 	/* for speedvectors */
 	float (*prevco)[3], (*nextco)[3];
 	int totvert, totface;
@@ -354,13 +356,14 @@
 
 typedef struct StrandBound {
 	int start, end;
-	float bbox[2][3];
+	float boundbox[2][3];
 } StrandBound;
 
 typedef struct StrandBuffer {
 	struct StrandBuffer *next, *prev;
 	struct StrandVert *vert;
-	int totvert;
+	struct StrandBound *bound;
+	int totvert, totbound;
 
 	struct ObjectRen *obr;
 	struct Material *ma;

Modified: trunk/blender/source/blender/render/intern/include/renderdatabase.h
===================================================================
--- trunk/blender/source/blender/render/intern/include/renderdatabase.h	2008-01-29 09:51:29 UTC (rev 13449)
+++ trunk/blender/source/blender/render/intern/include/renderdatabase.h	2008-01-29 12:20:42 UTC (rev 13450)
@@ -85,6 +85,7 @@
 
 void set_normalflags(struct Render *re, struct ObjectRen *obr);
 void project_renderdata(struct Render *re, void (*projectfunc)(float *, float mat[][4], float *),  int do_pano, float xoffs, int do_buckets);
+int clip_render_object(float boundbox[][3], float *bounds, float mat[][4]);
 
 /* functions are not exported... so wrong names */
 

Modified: trunk/blender/source/blender/render/intern/include/strand.h
===================================================================
--- trunk/blender/source/blender/render/intern/include/strand.h	2008-01-29 09:51:29 UTC (rev 13449)
+++ trunk/blender/source/blender/render/intern/include/strand.h	2008-01-29 12:20:42 UTC (rev 13450)
@@ -93,6 +93,7 @@
 
 void strand_eval_point(StrandSegment *sseg, StrandPoint *spoint);
 void render_strand_segment(struct Render *re, float winmat[][4], struct StrandPart *spart, struct ZSpan *zspan, int totzspan, StrandSegment *sseg);
+void strand_minmax(struct StrandRen *strand, float *min, float *max);
 
 struct StrandSurface *cache_strand_surface(struct Render *re, struct ObjectRen *obr, struct DerivedMesh *dm, float mat[][4], int timeoffset);
 void free_strand_surface(struct Render *re);

Modified: trunk/blender/source/blender/render/intern/source/convertblender.c
===================================================================
--- trunk/blender/source/blender/render/intern/source/convertblender.c	2008-01-29 09:51:29 UTC (rev 13449)
+++ trunk/blender/source/blender/render/intern/source/convertblender.c	2008-01-29 12:20:42 UTC (rev 13450)
@@ -111,6 +111,7 @@
 #include "strand.h"
 #include "texture.h"
 #include "sss.h"
+#include "strand.h"
 #include "zbuf.h"
 
 #ifndef DISABLE_YAFRAY /* disable yafray */
@@ -1482,6 +1483,7 @@
 	ParticleCacheKey *cache=0;
 	StrandBuffer *strandbuf=0;
 	StrandVert *svert=0;
+	StrandBound *sbound= 0;
 	StrandRen *strand=0;
 	RNG *rng= 0;
 	float loc[3],loc1[3],loc0[3],vel[3],mat[4][4],nmat[3][3],co[3],nor[3],time;
@@ -1491,6 +1493,7 @@
 	int i, a, k, max_k=0, totpart, totuv=0, override_uv=-1, dosimplify = 0, dosurfacecache = 0;
 	int path_possible=0, keys_possible=0, baked_keys=0, totchild=psys->totchild;
 	int seed, path_nbr=0, path=0, orco1=0, adapt=0, uv[3]={0,0,0}, num;
+	int totface, *origindex = 0;
 	char **uv_name=0;
 
 /* 1. check that everything is ok & updated */
@@ -1653,6 +1656,18 @@
 				else if((re->wrld.mode & WO_AMB_OCC) && (re->wrld.ao_gather_method == WO_AOGATHER_APPROX))
 					if(ma->amb != 0.0f)
 						dosurfacecache= 1;
+
+				totface= psmd->dm->getNumFaces(psmd->dm);
+				origindex= psmd->dm->getFaceDataArray(psmd->dm, CD_ORIGINDEX);
+				if(origindex) {
+					for(a=0; a<totface; a++)
+						strandbuf->totbound= MAX2(strandbuf->totbound, origindex[a]);
+					strandbuf->totbound++;
+				}
+				strandbuf->totbound++;
+				strandbuf->bound= MEM_callocN(sizeof(StrandBound)*strandbuf->totbound, "StrandBound");
+				sbound= strandbuf->bound;
+				sbound->start= sbound->end= 0;
 			}
 		}
 	}
@@ -1802,6 +1817,13 @@
 				cache = psys->childcache[a-totpart];
 				max_k = (int)cache->steps;
 			}
+
+			if(strandbuf) {
+				if(origindex[cpa->num]+1 > sbound - strandbuf->bound) {
+					sbound= strandbuf->bound + origindex[cpa->num]+1;
+					sbound->start= sbound->end= obr->totstrand;
+				}
+			}
 		}
 
 		/* surface normal shading setup */
@@ -1845,6 +1867,8 @@
 					}
 				}
 			}
+
+			sbound->end++;
 		}
 
 		/* strandco computation setup */
@@ -3841,6 +3865,11 @@
 static void finalize_render_object(Render *re, ObjectRen *obr, int timeoffset)
 {
 	Object *ob= obr->ob;
+	VertRen *ver= NULL;
+	StrandRen *strand= NULL;
+	StrandBound *sbound= NULL;
+	float min[3], max[3], smin[3], smax[3];
+	int a, b;
 
 	if(obr->totvert || obr->totvlak || obr->tothalo || obr->totstrand) {
 		/* the exception below is because displace code now is in init_render_mesh call, 
@@ -3858,6 +3887,36 @@
 
 			check_non_flat_quads(obr);
 			set_fullsample_flag(re, obr);
+
+			/* compute bounding boxes for clipping */
+			INIT_MINMAX(min, max);
+			for(a=0; a<obr->totvert; a++) {
+				if((a & 255)==0) ver= obr->vertnodes[a>>8].vert;
+				else ver++;
+
+				DO_MINMAX(ver->co, min, max);
+			}
+
+			if(obr->strandbuf) {
+				sbound= obr->strandbuf->bound;
+				for(b=0; b<obr->strandbuf->totbound; b++, sbound++) {
+					INIT_MINMAX(smin, smax);
+
+					for(a=sbound->start; a<sbound->end; a++) {
+						strand= RE_findOrAddStrand(obr, a);
+						strand_minmax(strand, smin, smax);
+					}
+
+					VECCOPY(sbound->boundbox[0], smin);
+					VECCOPY(sbound->boundbox[1], smax);
+
+					DO_MINMAX(smin, min, max);
+					DO_MINMAX(smax, min, max);
+				}
+			}
+
+			VECCOPY(obr->boundbox[0], min);
+			VECCOPY(obr->boundbox[1], max);
 		}
 	}
 }
@@ -4674,7 +4733,7 @@
 	}
 
 	if(obr->strandnodes) {
-		strandbuf= obr->strandbufs.first;
+		strandbuf= obr->strandbuf;
 		mesh= (strandbuf)? strandbuf->surface: NULL;
 
 		/* compute speed vectors at surface vertices */

Modified: trunk/blender/source/blender/render/intern/source/renderdatabase.c
===================================================================
--- trunk/blender/source/blender/render/intern/source/renderdatabase.c	2008-01-29 09:51:29 UTC (rev 13449)
+++ trunk/blender/source/blender/render/intern/source/renderdatabase.c	2008-01-29 12:20:42 UTC (rev 13450)
@@ -711,7 +711,7 @@
 	strandbuf->totvert= totvert;
 	strandbuf->obr= obr;
 
-	BLI_addtail(&obr->strandbufs, strandbuf);
+	obr->strandbuf= strandbuf;
 
 	return strandbuf;
 }
@@ -842,9 +842,12 @@
 			obr->strandnodeslen= 0;
 		}
 
-		for(strandbuf=obr->strandbufs.first; strandbuf; strandbuf=strandbuf->next)
+		strandbuf= obr->strandbuf;
+		if(strandbuf) {
 			if(strandbuf->vert) MEM_freeN(strandbuf->vert);
-		BLI_freelistN(&obr->strandbufs);
+			if(strandbuf->bound) MEM_freeN(strandbuf->bound);
+			MEM_freeN(strandbuf);
+		}
 
 		if(obr->mtface)
 			MEM_freeN(obr->mtface);
@@ -1342,13 +1345,11 @@
 	re->instancetable= newlist;
 }
 
-#if 0
-int clip_render_object(ObjectInstanceRen *obi, float *bounds, float winmat[][4])
+int clip_render_object(float boundbox[][3], float *bounds, float winmat[][4])
 {
-	float mat[4][4], vec[4], max, min, (*boundbox)[3];
+	float mat[4][4], vec[4];
 	int a, fl, flag= -1;
 
-	boundbox= obi->obr->boundbox;
 	Mat4CpyMat4(mat, winmat);
 
 	for(a=0; a<8; a++) {
@@ -1374,22 +1375,10 @@
 		if(vec[2] < -vec[3]) fl |= 16;
 		if(vec[2] > vec[3]) fl |= 32;
 
-#if 0
-		max= vec[3];
-		min= -vec[3];
-
-		wco= ho[3];
-		if(vec[0] < min) fl |= 1;
-		if(vec[0] > max) fl |= 2;
-		if(vec[1] < min) fl |= 4;
-		if(vec[1] > max) fl |= 8;
-#endif
-		
 		flag &= fl;
 		if(flag==0) return 0;
 	}
 
 	return flag;
 }
-#endif
 

Modified: trunk/blender/source/blender/render/intern/source/strand.c
===================================================================
--- trunk/blender/source/blender/render/intern/source/strand.c	2008-01-29 09:51:29 UTC (rev 13449)
+++ trunk/blender/source/blender/render/intern/source/strand.c	2008-01-29 12:20:42 UTC (rev 13450)
@@ -750,12 +750,13 @@
 	ZSpan zspan;
 	StrandRen *strand=0;
 	StrandVert *svert;
+	StrandBound *sbound;
 	StrandPart spart;
 	StrandSegment sseg;
 	StrandSortSegment *sortsegments = NULL, *sortseg, *firstseg;
 	MemArena *memarena;
 	float z[4], bounds[4], winmat[4][4];
-	int a, b, i, totsegment, clip[4];
+	int a, b, c, i, totsegment, clip[4];
 
 	if(re->test_break())
 		return 0;
@@ -800,58 +801,66 @@
 	sortseg= sortsegments;
 	totsegment= 0;
 

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list