[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [15534] branches/soc-2008-unclezeiv/source /blender/render/intern/source/lightcuts.c: Support for textured area lights : textures associated with an area light now affect the actual color of the light throughout the area .

Davide Vercelli davide.vercelli at gmail.com
Sat Jul 12 01:22:41 CEST 2008


Revision: 15534
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=15534
Author:   unclezeiv
Date:     2008-07-12 01:22:41 +0200 (Sat, 12 Jul 2008)

Log Message:
-----------
Support for textured area lights: textures associated with an area light now affect the actual color of the light throughout the area. Limitations: currently only the first channel is supported.

Modified Paths:
--------------
    branches/soc-2008-unclezeiv/source/blender/render/intern/source/lightcuts.c

Modified: branches/soc-2008-unclezeiv/source/blender/render/intern/source/lightcuts.c
===================================================================
--- branches/soc-2008-unclezeiv/source/blender/render/intern/source/lightcuts.c	2008-07-11 19:46:35 UTC (rev 15533)
+++ branches/soc-2008-unclezeiv/source/blender/render/intern/source/lightcuts.c	2008-07-11 23:22:41 UTC (rev 15534)
@@ -38,6 +38,7 @@
 #include "DNA_lamp_types.h"
 #include "DNA_material_types.h"
 #include "DNA_listBase.h"
+#include "DNA_texture_types.h"
 #include "MEM_guardedalloc.h"
 #include "PIL_time.h"
 #include "RE_pipeline.h"
@@ -680,9 +681,11 @@
 	float area, gapx, gapy, factor, realw, realh;
 	float xdir[3];
 	float ydir[3];
-	float stepx, stepy;
+	float stepx, stepy, texvec[2];
 	LampRen *lar;
 	float density;
+	Tex *tex;
+	int use_texture= 0;
 	
 	density= sqrtf(re->r.lightcuts_area_density);
 
@@ -704,6 +707,12 @@
 		printf("Err: required light density would violate light limit\n");
 		return;
 	}
+	
+	/* XXX: add multichannel/stencil/etc. support */
+	if (orig->mtex[0] && orig->mtex[0]->tex) {
+		tex= orig->mtex[0]->tex;
+		use_texture= 1;
+	}
 
 	for (x=0; x<smpx; x++) {
 		for (y=0; y<smpy; y++) {
@@ -721,17 +730,35 @@
 			lar = (LampRen *)MEM_callocN(sizeof(LampRen), "lampren");
 
 			create_lamp_oriented(re, lar, orig);
-			lar->r= orig->r * factor;
-			lar->g= orig->g * factor;
-			lar->b= orig->b * factor;
-			lar->energy= orig->energy * factor;
-
+			
 			/* place a light in its own square with random jittering */
-			stepx= orig->area_size * (gapx * (x + BLI_frand()) - 0.5f);
-			stepy= orig->area_sizey * (gapy * (y + BLI_frand()) - 0.5f);
+			texvec[0]= gapx * (x + BLI_frand());
+			texvec[1]= gapy * (y + BLI_frand());
+			stepx= orig->area_size * (texvec[0] - 0.5f);
+			stepy= orig->area_sizey * (texvec[1] - 0.5f);
 			lar->co[0]= orig->co[0] + xdir[0] * stepx + ydir[0] * stepy;
 			lar->co[1]= orig->co[1] + xdir[1] * stepx + ydir[1] * stepy;
 			lar->co[2]= orig->co[2] + xdir[2] * stepx + ydir[2] * stepy;
+			
+			if (use_texture) {
+				int ret;
+				TexResult texres= {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0, NULL};
+				
+				/* NOTE: not using osatex */
+				texvec[0]= 1.0f - texvec[0]*2.0f;
+				texvec[1]= texvec[1]*2.0f - 1.0f;
+				ret= multitex_ext(tex, texvec, NULL, NULL, 0, &texres);
+				
+				lar->r= texres.tr * factor * orig->energy;
+				lar->g= texres.tg * factor * orig->energy;
+				lar->b= texres.tb * factor * orig->energy;
+			}
+			else {
+				lar->r= orig->r * factor;
+				lar->g= orig->g * factor;
+				lar->b= orig->b * factor;	
+			}
+			lar->energy= orig->energy * factor;
 
 #ifdef LIGHTCUTS_DEBUG
 			printf("coordinates: %4f %4f %4f\n", lar->co[0], lar->co[1], lar->co[2]);





More information about the Bf-blender-cvs mailing list