[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [27216] branches/render25/source/blender: Render Branch: some WIP code before svn merge, saving irradiance cache to

Brecht Van Lommel brecht at blender.org
Tue Mar 2 12:35:58 CET 2010


Revision: 27216
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=27216
Author:   blendix
Date:     2010-03-02 12:35:57 +0100 (Tue, 02 Mar 2010)

Log Message:
-----------
Render Branch: some WIP code before svn merge, saving irradiance cache to
file, and fix for indirect light intensity.

Modified Paths:
--------------
    branches/render25/source/blender/blenlib/BLI_threads.h
    branches/render25/source/blender/blenlib/intern/threads.c
    branches/render25/source/blender/makesdna/DNA_world_types.h
    branches/render25/source/blender/makesrna/intern/rna_world.c
    branches/render25/source/blender/render/intern/include/cache.h
    branches/render25/source/blender/render/intern/include/camera.h
    branches/render25/source/blender/render/intern/include/material.h
    branches/render25/source/blender/render/intern/source/cache.c
    branches/render25/source/blender/render/intern/source/camera.c
    branches/render25/source/blender/render/intern/source/convertblender.c
    branches/render25/source/blender/render/intern/source/material.c
    branches/render25/source/blender/render/intern/source/path.c
    branches/render25/source/blender/render/intern/source/rayshade.c
    branches/render25/source/blender/render/intern/source/shadeoutput.c

Modified: branches/render25/source/blender/blenlib/BLI_threads.h
===================================================================
--- branches/render25/source/blender/blenlib/BLI_threads.h	2010-03-02 11:35:28 UTC (rev 27215)
+++ branches/render25/source/blender/blenlib/BLI_threads.h	2010-03-02 11:35:57 UTC (rev 27216)
@@ -60,6 +60,7 @@
 #define LOCK_IMAGE		0
 #define LOCK_PREVIEW	1
 #define LOCK_CUSTOM1	2
+#define LOCK_RCACHE		2
 
 void	BLI_lock_thread(int type);
 void	BLI_unlock_thread(int type);

Modified: branches/render25/source/blender/blenlib/intern/threads.c
===================================================================
--- branches/render25/source/blender/blenlib/intern/threads.c	2010-03-02 11:35:28 UTC (rev 27215)
+++ branches/render25/source/blender/blenlib/intern/threads.c	2010-03-02 11:35:57 UTC (rev 27216)
@@ -104,6 +104,7 @@
 static pthread_mutex_t _image_lock = PTHREAD_MUTEX_INITIALIZER;
 static pthread_mutex_t _preview_lock = PTHREAD_MUTEX_INITIALIZER;
 static pthread_mutex_t _custom1_lock = PTHREAD_MUTEX_INITIALIZER;
+static pthread_mutex_t _rcache_lock = PTHREAD_MUTEX_INITIALIZER;
 static int thread_levels= 0;	/* threads can be invoked inside threads */
 
 /* just a max for security reasons */
@@ -303,6 +304,8 @@
 		pthread_mutex_lock(&_preview_lock);
 	else if (type==LOCK_CUSTOM1)
 		pthread_mutex_lock(&_custom1_lock);
+	else if (type==LOCK_RCACHE)
+		pthread_mutex_lock(&_rcache_lock);
 }
 
 void BLI_unlock_thread(int type)
@@ -313,6 +316,8 @@
 		pthread_mutex_unlock(&_preview_lock);
 	else if(type==LOCK_CUSTOM1)
 		pthread_mutex_unlock(&_custom1_lock);
+	else if(type==LOCK_RCACHE)
+		pthread_mutex_unlock(&_rcache_lock);
 }
 
 /* Mutex Locks */

Modified: branches/render25/source/blender/makesdna/DNA_world_types.h
===================================================================
--- branches/render25/source/blender/makesdna/DNA_world_types.h	2010-03-02 11:35:28 UTC (rev 27215)
+++ branches/render25/source/blender/makesdna/DNA_world_types.h	2010-03-02 11:35:57 UTC (rev 27216)
@@ -154,9 +154,10 @@
 #define WO_AOSAMP_HAMMERSLEY		2
 
 /* aomode (use distances & random sampling modes) */
-#define WO_AODIST		1
-#define WO_AORNDSMP		2
-#define WO_AOCACHE		4
+#define WO_AODIST			1
+#define WO_AORNDSMP			2
+#define WO_AOCACHE			4
+#define WO_AOCACHE_FILE		8
 
 /* aocolor */
 #define WO_AOPLAIN	0

Modified: branches/render25/source/blender/makesrna/intern/rna_world.c
===================================================================
--- branches/render25/source/blender/makesrna/intern/rna_world.c	2010-03-02 11:35:28 UTC (rev 27215)
+++ branches/render25/source/blender/makesrna/intern/rna_world.c	2010-03-02 11:35:57 UTC (rev 27216)
@@ -327,6 +327,11 @@
 	RNA_def_property_ui_text(prop, "Cache", "Cache AO results and interpolate over neighbouring pixels for speedup.");
 	RNA_def_property_update(prop, 0, "rna_World_update");
 
+	prop= RNA_def_property(srna, "use_cache_file", PROP_BOOLEAN, PROP_NONE);
+	RNA_def_property_boolean_sdna(prop, NULL, "aomode", WO_AOCACHE_FILE);
+	RNA_def_property_ui_text(prop, "Cache File", "Dump cache to file and read back to reuse samples for faster re-rendering.");
+	RNA_def_property_update(prop, 0, "rna_World_update");
+
 	prop= RNA_def_property(srna, "samples", PROP_INT, PROP_NONE);
 	RNA_def_property_int_sdna(prop, NULL, "aosamp");
 	RNA_def_property_range(prop, 1, 128);

Modified: branches/render25/source/blender/render/intern/include/cache.h
===================================================================
--- branches/render25/source/blender/render/intern/include/cache.h	2010-03-02 11:35:28 UTC (rev 27215)
+++ branches/render25/source/blender/render/intern/include/cache.h	2010-03-02 11:35:57 UTC (rev 27216)
@@ -92,6 +92,10 @@
 	IrrCache *cache, float *ao, float env[3], float indirect[3],
 	float P[3], float dPdu[3], float dPdv[3], float N[3], int do_sample);
 
+void irr_cache_write(struct Render *re, struct IrrCache *cache);
+IrrCache *irr_cache_read(struct Render *re, int thread);
+void irr_cache_merge(struct Render *re, IrrCache *cache);
+
 /* Radiosity Cache */
 
 void radio_cache_create(struct Render *re, int thread);

Modified: branches/render25/source/blender/render/intern/include/camera.h
===================================================================
--- branches/render25/source/blender/render/intern/include/camera.h	2010-03-02 11:35:28 UTC (rev 27215)
+++ branches/render25/source/blender/render/intern/include/camera.h	2010-03-02 11:35:57 UTC (rev 27216)
@@ -75,6 +75,8 @@
 	/* matrices */
 	float viewmat[4][4];	/* world to camera */
 	float viewinv[4][4];	/* camera to world */
+	float viewnmat[3][3];	/* world to camera for normals */
+	float viewninv[3][3];	/* camera to world for normals */
 	float winmat[4][4];		/* camera to raster */
 	float viewzvec[3];		/* normalized z-axis of viewmat */
 

Modified: branches/render25/source/blender/render/intern/include/material.h
===================================================================
--- branches/render25/source/blender/render/intern/include/material.h	2010-03-02 11:35:28 UTC (rev 27215)
+++ branches/render25/source/blender/render/intern/include/material.h	2010-03-02 11:35:57 UTC (rev 27216)
@@ -36,7 +36,7 @@
  * color, alpha, bsdf, emit, .. must be done between begin and end. */
 
 void mat_shading_begin(struct Render *re, struct ShadeInput *shi,
-	struct ShadeMaterial *smat);
+	struct ShadeMaterial *smat, int do_textures);
 void mat_shading_end(struct Render *re, struct ShadeMaterial *smat);
 
 /* BSDF: combination of brdf and btdf

Modified: branches/render25/source/blender/render/intern/source/cache.c
===================================================================
--- branches/render25/source/blender/render/intern/source/cache.c	2010-03-02 11:35:28 UTC (rev 27215)
+++ branches/render25/source/blender/render/intern/source/cache.c	2010-03-02 11:35:57 UTC (rev 27216)
@@ -33,6 +33,7 @@
 #include "BLI_math.h"
 #include "BLI_memarena.h"
 #include "BLI_rand.h"
+#include "BLI_threads.h"
 
 #include "BKE_DerivedMesh.h"
 #include "BKE_global.h"
@@ -418,6 +419,7 @@
 	float N[3];						/* normal */
 	float dP;						/* radius */
 	float C[CACHE_DIMENSION];		/* irradiance */
+	int read;						/* read from file */
 } IrrCacheSample;
 
 typedef struct IrrCacheNode {
@@ -440,12 +442,14 @@
 	int thread;					/* thread owning the cache */
 
 	int totsample;
+	int totnode;
 	int totlookup;
 	int totpost;
 
 	/* options */
 	int neighbour_clamp;
 	int lsq_reconstruction;
+	int locked;
 
 	/* test: a stable global coordinate system may help */
 };
@@ -510,7 +514,7 @@
 static IrrCache *irr_cache_new(Render *re, int thread)
 {
 	IrrCache *cache;
-	float bb[2][3];
+	float bb[2][3], viewbb[2][3];
 
 	cache= MEM_callocN(sizeof(IrrCache), "IrrCache");
 	cache->thread= thread;
@@ -520,7 +524,9 @@
 	BLI_memarena_use_calloc(cache->arena);
 
 	/* initialize root node with bounds */
-	render_instances_bound(&re->db, bb);
+	render_instances_bound(&re->db, viewbb);
+	INIT_MINMAX(bb[0], bb[1]);
+	box_minmax_bounds_m4(bb[0], bb[1], viewbb, re->cam.viewinv);
 	mid_v3_v3v3(cache->root.center, bb[0], bb[1]);
 	cache->root.side= MAX3(bb[1][0]-bb[0][0], bb[1][1]-bb[0][1], bb[1][2]-bb[0][2]);
 
@@ -550,7 +556,8 @@
 	/* increase stack size as more nodes are added */
 	if(cache->maxdepth > cache->stacksize) {
 		cache->stacksize= cache->maxdepth + 5;
-		MEM_freeN(cache->stack);
+		if(cache->stack)
+			MEM_freeN(cache->stack);
 		cache->stack= MEM_mallocN(sizeof(IrrCacheNode*)*cache->stacksize*8, "IrrCache stack");
 	}
 }
@@ -621,83 +628,100 @@
 	}
 }
 
-/* Add a Sample */
+/* Insert Sample */
 
-static void irr_cache_add(Render *re, ShadeInput *shi, IrrCache *cache, float *ao, float env[3], float indirect[3], float P[3], float dPdu[3], float dPdv[3], float N[3])
+static void irr_cache_insert(IrrCache *cache, IrrCacheSample *sample)
 {
-	IrrCacheSample *sample;
 	IrrCacheNode *node;
-	float Rmean;
+	float dist, P[3];
 	int i, j, depth;
+
+	copy_v3_v3(P, sample->P);
+
+	/* error multiplier */
+	dist = sample->dP/MAX_ERROR_K;
 	
-	ray_ao_env_indirect(re, shi, ao, env, indirect, &Rmean);
+	/* insert the new sample into the cache */
+	node= &cache->root;
+	depth= 0;
+	while(node->side > (2*dist)) {
+		depth++;
 
-	/* save sample to cache? */
-	if(1) { ///*(MAX_ERROR != 0) &&*/ (*ao > EPSILON)) { // XXX?
-		sample= BLI_memarena_alloc(cache->arena, sizeof(IrrCacheSample));
+		j= 0;
+		for(i=0; i<3; i++)
+			if(P[i] > node->center[i])
+				j |= 1 << i;
 
-		// XXX too large? try setting pixel dist to 0!
-		/* compute the radius of validity [Tabellion 2004] */
-		Rmean= minf(Rmean*0.5f, MAX_PIXEL_DIST*(len_v3(dPdu) + len_v3(dPdv))*0.5f);
-		
-		/* record the data */
-		copy_v3_v3(sample->P, P);
-		copy_v3_v3(sample->N, N);
-		sample->dP= Rmean;
-		irr_sample_set(sample->C, ao, env, indirect);
+		if(node->children[j] == NULL) {
+			IrrCacheNode *nnode= BLI_memarena_alloc(cache->arena, sizeof(IrrCacheNode));
 
-		if(cache->neighbour_clamp) {
-			/* neighbour clamping trick */
-			irr_cache_clamp_sample(cache, sample);
-			Rmean= sample->dP; /* copy dP back so we get the right place in the octree */
+			for(i=0; i<3; i++) {
+				float fac= (P[i] > node->center[i])? 0.25f: -0.25f;
+				nnode->center[i]= node->center[i] + fac*node->side;
+			}
+
+			nnode->side= node->side*0.5f;
+			node->children[j]= nnode;
+
+			cache->totnode++;
 		}
 
-		/* error multiplier */
-		Rmean /= MAX_ERROR_K;
-		
-		/* insert the new sample into the cache */
-		node= &cache->root;
-		depth= 0;
-		while(node->side > (2*Rmean)) {
-			depth++;
+		node= node->children[j];
+	}
 
-			j= 0;
-			for(i=0; i<3; i++)
-				if(P[i] > node->center[i])
-					j |= 1 << i;
+	sample->next= node->samples;
+	node->samples= sample;
 
-			if(node->children[j] == NULL) {
-				IrrCacheNode *nnode= BLI_memarena_alloc(cache->arena, sizeof(IrrCacheNode));
+	cache->maxdepth= MAX2(depth, cache->maxdepth);
+	irr_cache_check_stack(cache);
 
-				for(i=0; i<3; i++) {
-					float fac= (P[i] > node->center[i])? 0.25f: -0.25f;
-					nnode->center[i]= node->center[i] + fac*node->side;
-				}
+	cache->totsample++;
+}
 
-				nnode->side= node->side*0.5f;
-				node->children[j]= nnode;
-			}
+/* Add a Sample */
 
-			node= node->children[j];
-		}
+static void irr_cache_add(Render *re, ShadeInput *shi, IrrCache *cache, float *ao, float env[3], float indirect[3], float P[3], float dPdu[3], float dPdv[3], float N[3])
+{
+	IrrCacheSample *sample;
+	float Rmean;
+	
+	ray_ao_env_indirect(re, shi, ao, env, indirect, &Rmean);
 

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list