[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [46241] trunk/blender/source/blender/ render/intern: Fix strand render + instancing render bug, gave tile artifacts.

Brecht Van Lommel brechtvanlommel at pandora.be
Thu May 3 22:06:27 CEST 2012


Revision: 46241
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=46241
Author:   blendix
Date:     2012-05-03 20:06:25 +0000 (Thu, 03 May 2012)
Log Message:
-----------
Fix strand render + instancing render bug, gave tile artifacts.

Modified Paths:
--------------
    trunk/blender/source/blender/render/intern/include/strand.h
    trunk/blender/source/blender/render/intern/source/strand.c
    trunk/blender/source/blender/render/intern/source/zbuf.c

Modified: trunk/blender/source/blender/render/intern/include/strand.h
===================================================================
--- trunk/blender/source/blender/render/intern/include/strand.h	2012-05-03 19:57:24 UTC (rev 46240)
+++ trunk/blender/source/blender/render/intern/include/strand.h	2012-05-03 20:06:25 UTC (rev 46241)
@@ -101,7 +101,7 @@
 struct StrandShadeCache *strand_shade_cache_create(void);
 void strand_shade_cache_free(struct StrandShadeCache *cache);
 void strand_shade_segment(struct Render *re, struct StrandShadeCache *cache, struct StrandSegment *sseg, struct ShadeSample *ssamp, float t, float s, int addpassflag);
-void strand_shade_unref(struct StrandShadeCache *cache, struct StrandVert *svert);
+void strand_shade_unref(struct StrandShadeCache *cache, struct ObjectInstanceRen *obi, struct StrandRen *strand, struct StrandVert *svert);
 
 #endif
 

Modified: trunk/blender/source/blender/render/intern/source/strand.c
===================================================================
--- trunk/blender/source/blender/render/intern/source/strand.c	2012-05-03 19:57:24 UTC (rev 46240)
+++ trunk/blender/source/blender/render/intern/source/strand.c	2012-05-03 20:06:25 UTC (rev 46241)
@@ -328,8 +328,8 @@
 	StrandShadeCache *cache;
 
 	cache= MEM_callocN(sizeof(StrandShadeCache), "StrandShadeCache");
-	cache->resulthash= BLI_ghash_new(BLI_ghashutil_ptrhash, BLI_ghashutil_ptrcmp, "strand_shade_cache_create1 gh");
-	cache->refcounthash= BLI_ghash_new(BLI_ghashutil_ptrhash, BLI_ghashutil_ptrcmp, "strand_shade_cache_create2 gh");
+	cache->resulthash= BLI_ghash_new(BLI_ghashutil_pairhash, BLI_ghashutil_paircmp, "strand_shade_cache_create1 gh");
+	cache->refcounthash= BLI_ghash_new(BLI_ghashutil_pairhash, BLI_ghashutil_paircmp, "strand_shade_cache_create2 gh");
 	cache->memarena= BLI_memarena_new(BLI_MEMARENA_STD_BUFSIZE, "strand shade cache arena");
 	
 	return cache;
@@ -337,20 +337,26 @@
 
 void strand_shade_cache_free(StrandShadeCache *cache)
 {
-	BLI_ghash_free(cache->refcounthash, NULL, NULL);
-	BLI_ghash_free(cache->resulthash, NULL, (GHashValFreeFP)MEM_freeN);
+	BLI_ghash_free(cache->refcounthash, (GHashKeyFreeFP)BLI_ghashutil_pairfree, NULL);
+	BLI_ghash_free(cache->resulthash, (GHashKeyFreeFP)BLI_ghashutil_pairfree, (GHashValFreeFP)MEM_freeN);
 	BLI_memarena_free(cache->memarena);
 	MEM_freeN(cache);
 }
 
+static GHashPair *strand_shade_hash_pair(ObjectInstanceRen *obi, StrandRen *strand, StrandVert *svert)
+{
+	return BLI_ghashutil_pairalloc(obi, strand->index + (svert - strand->vert));
+}
+
 static void strand_shade_get(Render *re, StrandShadeCache *cache, ShadeSample *ssamp, StrandSegment *sseg, StrandVert *svert)
 {
 	ShadeResult *hashshr;
 	StrandPoint p;
 	int *refcount;
+	GHashPair *pair = strand_shade_hash_pair(sseg->obi, sseg->strand, svert);
 
-	hashshr= BLI_ghash_lookup(cache->resulthash, svert);
-	refcount= BLI_ghash_lookup(cache->refcounthash, svert);
+	hashshr= BLI_ghash_lookup(cache->resulthash, pair);
+	refcount= BLI_ghash_lookup(cache->refcounthash, pair);
 
 	if (!hashshr) {
 		/* not shaded yet, shade and insert into hash */
@@ -360,7 +366,7 @@
 
 		hashshr= MEM_callocN(sizeof(ShadeResult), "HashShadeResult");
 		*hashshr= ssamp->shr[0];
-		BLI_ghash_insert(cache->resulthash, svert, hashshr);
+		BLI_ghash_insert(cache->resulthash, strand_shade_hash_pair(sseg->obi, sseg->strand, svert), hashshr);
 	}
 	else
 		/* already shaded, just copy previous result from hash */
@@ -369,9 +375,11 @@
 	/* lower reference count and remove if not needed anymore by any samples */
 	(*refcount)--;
 	if (*refcount == 0) {
-		BLI_ghash_remove(cache->resulthash, svert, NULL, (GHashValFreeFP)MEM_freeN);
-		BLI_ghash_remove(cache->refcounthash, svert, NULL, NULL);
+		BLI_ghash_remove(cache->resulthash, pair, (GHashKeyFreeFP)BLI_ghashutil_pairfree, (GHashValFreeFP)MEM_freeN);
+		BLI_ghash_remove(cache->refcounthash, pair, (GHashKeyFreeFP)BLI_ghashutil_pairfree, NULL);
 	}
+
+	BLI_ghashutil_pairfree(pair);
 }
 
 void strand_shade_segment(Render *re, StrandShadeCache *cache, StrandSegment *sseg, ShadeSample *ssamp, float t, float s, int addpassflag)
@@ -394,31 +402,37 @@
 	}
 }
 
-void strand_shade_unref(StrandShadeCache *cache, StrandVert *svert)
+void strand_shade_unref(StrandShadeCache *cache, ObjectInstanceRen *obi, StrandRen *strand, StrandVert *svert)
 {
+	GHashPair *pair = strand_shade_hash_pair(obi, strand, svert);
 	int *refcount;
 
 	/* lower reference count and remove if not needed anymore by any samples */
-	refcount= BLI_ghash_lookup(cache->refcounthash, svert);
+	refcount= BLI_ghash_lookup(cache->refcounthash, pair);
 
 	(*refcount)--;
 	if (*refcount == 0) {
-		BLI_ghash_remove(cache->resulthash, svert, NULL, (GHashValFreeFP)MEM_freeN);
-		BLI_ghash_remove(cache->refcounthash, svert, NULL, NULL);
+		BLI_ghash_remove(cache->resulthash, pair, (GHashKeyFreeFP)BLI_ghashutil_pairfree, (GHashValFreeFP)MEM_freeN);
+		BLI_ghash_remove(cache->refcounthash, pair, (GHashKeyFreeFP)BLI_ghashutil_pairfree, NULL);
 	}
+
+	BLI_ghashutil_pairfree(pair);
 }
 
-static void strand_shade_refcount(StrandShadeCache *cache, StrandVert *svert)
+static void strand_shade_refcount(StrandShadeCache *cache, StrandSegment *sseg, StrandVert *svert)
 {
-	int *refcount= BLI_ghash_lookup(cache->refcounthash, svert);
+	GHashPair *pair = strand_shade_hash_pair(sseg->obi, sseg->strand, svert);
+	int *refcount= BLI_ghash_lookup(cache->refcounthash, pair);
 
 	if (!refcount) {
 		refcount= BLI_memarena_alloc(cache->memarena, sizeof(int));
 		*refcount= 1;
-		BLI_ghash_insert(cache->refcounthash, svert, refcount);
+		BLI_ghash_insert(cache->refcounthash, pair, refcount);
 	}
-	else
+	else {
 		(*refcount)++;
+		BLI_ghashutil_pairfree(pair);
+	}
 }
 
 /* *************** */
@@ -580,8 +594,8 @@
 			}
 
 			if (cache) {
-				strand_shade_refcount(cache, sseg->v[1]);
-				strand_shade_refcount(cache, sseg->v[2]);
+				strand_shade_refcount(cache, sseg, sseg->v[1]);
+				strand_shade_refcount(cache, sseg, sseg->v[2]);
 			}
 			spart->totapixbuf[offset]++;
 		}

Modified: trunk/blender/source/blender/render/intern/source/zbuf.c
===================================================================
--- trunk/blender/source/blender/render/intern/source/zbuf.c	2012-05-03 19:57:24 UTC (rev 46240)
+++ trunk/blender/source/blender/render/intern/source/zbuf.c	2012-05-03 20:06:25 UTC (rev 46241)
@@ -3748,8 +3748,8 @@
 			strand= RE_findOrAddStrand(obr, row[totface].p-1);
 			svert= strand->vert + row[totface].segment;
 
-			strand_shade_unref(cache, svert);
-			strand_shade_unref(cache, svert+1);
+			strand_shade_unref(cache, obi, strand, svert);
+			strand_shade_unref(cache, obi, strand, svert+1);
 		}
 	}
 }




More information about the Bf-blender-cvs mailing list