[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [27874] branches/render25/source/blender/ render/intern/source/lamp.c: Render Branch: Sun lamps now can cast soft shadows again.

Brecht Van Lommel brecht at blender.org
Tue Mar 30 19:10:24 CEST 2010


Revision: 27874
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=27874
Author:   blendix
Date:     2010-03-30 19:10:24 +0200 (Tue, 30 Mar 2010)

Log Message:
-----------
Render Branch: Sun lamps now can cast soft shadows again. They look
different however than trunk, because they used to depend on the lamp
location while the light depends only on the rotation. So that has
changed now and only the rotation should have an influence. This also
means the soft size does not define a size in blender units, but rather
a fraction of the hemisphere.

Modified Paths:
--------------
    branches/render25/source/blender/render/intern/source/lamp.c

Modified: branches/render25/source/blender/render/intern/source/lamp.c
===================================================================
--- branches/render25/source/blender/render/intern/source/lamp.c	2010-03-30 15:49:49 UTC (rev 27873)
+++ branches/render25/source/blender/render/intern/source/lamp.c	2010-03-30 17:10:24 UTC (rev 27874)
@@ -238,46 +238,51 @@
 	return (fac != 0.0f);
 }
 
+static void sphere_lamp_location(float lco[3], float co[3], float center[3], float size, float r[2])
+{
+	/* sphere light source */
+	float ru[3], rv[3], v[3], s[3], disc[3];
+
+	/* calc tangent plane vectors */
+	v[0] = co[0] - center[0];
+	v[1] = co[1] - center[1];
+	v[2] = co[2] - center[2];
+	normalize_v3(v);
+	ortho_basis_v3v3_v3(ru, rv, v);
+	
+	/* sampling, returns quasi-random vector in area_size disc */
+	sample_project_disc(disc, size, r);
+
+	/* distribute disc samples across the tangent plane */
+	s[0] = disc[0]*ru[0] + disc[1]*rv[0];
+	s[1] = disc[0]*ru[1] + disc[1]*rv[1];
+	s[2] = disc[0]*ru[2] + disc[1]*rv[2];
+
+	add_v3_v3v3(lco, center, s);
+}
+
 static void lamp_sample_location(float lco[3], LampRen *lar, float co[3], float r[2])
 {
 	switch(lar->type) {
 		case LA_LOCAL:
 		case LA_SPOT: {
-			if(r) {
-				/* sphere shadow source */
-				float ru[3], rv[3], v[3], s[3], disc[3];
-				
-				/* calc tangent plane vectors */
-				v[0] = co[0] - lar->co[0];
-				v[1] = co[1] - lar->co[1];
-				v[2] = co[2] - lar->co[2];
-				normalize_v3(v);
-				ortho_basis_v3v3_v3(ru, rv, v);
-				
-				/* sampling, returns quasi-random vector in area_size disc */
-				sample_project_disc(disc, lar->area_size, r);
-
-				/* distribute disc samples across the tangent plane */
-				s[0] = disc[0]*ru[0] + disc[1]*rv[0];
-				s[1] = disc[0]*ru[1] + disc[1]*rv[1];
-				s[2] = disc[0]*ru[2] + disc[1]*rv[2];
-				
-				add_v3_v3v3(lco, lar->co, s);
-			}
-			else
-				copy_v3_v3(lco, lar->co);
+			if(r) sphere_lamp_location(lco, co, lar->co, lar->area_size, r);
+			else copy_v3_v3(lco, lar->co);
 			break;
 		}
 		case LA_AREA: {
-			if(r)
-				area_lamp_location(lco, lar, r[0], r[1]);
-			else
-				copy_v3_v3(lco, lar->co);
+			if(r) area_lamp_location(lco, lar, r[0], r[1]);
+			else copy_v3_v3(lco, lar->co);
 			break;
 		}
 		case LA_HEMI:
 		case LA_SUN: {
-			madd_v3_v3v3fl(lco, co, lar->vec, -RE_RAYTRACE_MAXDIST);
+			float lampco[3];
+
+			madd_v3_v3v3fl(lampco, co, lar->vec, -RE_RAYTRACE_MAXDIST);
+
+			if(r) sphere_lamp_location(lco, co, lampco, lar->area_size*RE_RAYTRACE_MAXDIST, r);
+			else copy_v3_v3(lco, lampco);
 			break;
 		}
 		default: {





More information about the Bf-blender-cvs mailing list