[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [41044] branches/cycles: Cycles:

Brecht Van Lommel brechtvanlommel at pandora.be
Sun Oct 16 01:49:02 CEST 2011


Revision: 41044
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=41044
Author:   blendix
Date:     2011-10-15 23:49:01 +0000 (Sat, 15 Oct 2011)
Log Message:
-----------
Cycles:
* Sun, area and point lights with size now supported
* Cast shadow option to disable shadow casting for lamps
* Emission strength of materials tweaked such that setting strength to 1.0
  basically makes the material "shadeless" in that the value of the color
  input will be the resulting color in the image.

Modified Paths:
--------------
    branches/cycles/intern/cycles/blender/addon/ui.py
    branches/cycles/intern/cycles/blender/blender_object.cpp
    branches/cycles/intern/cycles/kernel/kernel_emission.h
    branches/cycles/intern/cycles/kernel/kernel_light.h
    branches/cycles/intern/cycles/kernel/osl/emissive.cpp
    branches/cycles/intern/cycles/kernel/svm/emissive.h
    branches/cycles/source/blender/blenkernel/BKE_blender.h
    branches/cycles/source/blender/blenloader/intern/readfile.c
    branches/cycles/source/blender/editors/space_node/node_edit.c
    branches/cycles/source/blender/nodes/shader/nodes/node_shader_emission.c

Modified: branches/cycles/intern/cycles/blender/addon/ui.py
===================================================================
--- branches/cycles/intern/cycles/blender/addon/ui.py	2011-10-15 20:57:07 UTC (rev 41043)
+++ branches/cycles/intern/cycles/blender/addon/ui.py	2011-10-15 23:49:01 UTC (rev 41044)
@@ -366,8 +366,7 @@
 
     @classmethod
     def poll(cls, context):
-        return False
-        #return context.lamp and CyclesButtonsPanel.poll(context)
+        return context.lamp and CyclesButtonsPanel.poll(context)
 
     def draw(self, context):
         layout = self.layout
@@ -505,17 +504,13 @@
         mat = context.material
         cmat = mat.cycles
 
-        layout.prop(mat, "diffuse_color", text="Viewport Color")
-
-        """
         split = layout.split()
-    
+
         col = split.column()
-        col.prop(cmat, "sample_as_light")
+        col.prop(mat, "diffuse_color", text="Viewport Color")
 
         col = split.column()
-        col.prop(cmat, "homogeneous_volume")
-        """
+        col.prop(cmat, "sample_as_light")
 
 class CyclesTexture_PT_context(CyclesButtonsPanel, Panel):
     bl_label = ""

Modified: branches/cycles/intern/cycles/blender/blender_object.cpp
===================================================================
--- branches/cycles/intern/cycles/blender/blender_object.cpp	2011-10-15 20:57:07 UTC (rev 41043)
+++ branches/cycles/intern/cycles/blender/blender_object.cpp	2011-10-15 23:49:01 UTC (rev 41044)
@@ -91,14 +91,11 @@
 	BL::Lamp b_lamp(b_ob.data());
 
 	/* type */
-#if 0
 	switch(b_lamp.type()) {
 		case BL::Lamp::type_POINT: {
 			BL::PointLamp b_point_lamp(b_lamp);
 			light->size = b_point_lamp.shadow_soft_size();
-#endif
 			light->type = LIGHT_POINT;
-#if 0
 			break;
 		}
 		case BL::Lamp::type_SPOT: {
@@ -132,11 +129,10 @@
 			break;
 		}
 	}
-#endif
 
-	/* location */
+	/* location and (inverted!) direction */
 	light->co = make_float3(tfm.x.w, tfm.y.w, tfm.z.w);
-	light->dir = make_float3(tfm.x.z, tfm.y.z, tfm.z.z);
+	light->dir = -make_float3(tfm.x.z, tfm.y.z, tfm.z.z);
 
 	/* shader */
 	vector<uint> used_shaders;
@@ -149,8 +145,8 @@
 	light->shader = used_shaders[0];
 
 	/* shadow */
-	//PointerRNA clamp = RNA_pointer_get(&b_lamp.ptr, "cycles");
-	//light->cast_shadow = get_boolean(clamp, "cast_shadow");
+	PointerRNA clamp = RNA_pointer_get(&b_lamp.ptr, "cycles");
+	light->cast_shadow = get_boolean(clamp, "cast_shadow");
 
 	/* tag */
 	light->tag_update(scene);

Modified: branches/cycles/intern/cycles/kernel/kernel_emission.h
===================================================================
--- branches/cycles/intern/cycles/kernel/kernel_emission.h	2011-10-15 20:57:07 UTC (rev 41043)
+++ branches/cycles/intern/cycles/kernel/kernel_emission.h	2011-10-15 23:49:01 UTC (rev 41044)
@@ -88,15 +88,12 @@
 		float mis_weight = power_heuristic(pdf, bsdf_pdf);
 		*eval *= mis_weight;
 	}
-	else if(!(ls.shader & SHADER_AREA_LIGHT)) {
-		/* ensure point light works in Watts, this should be handled
-		 * elsewhere but for now together with the diffuse emission
-		 * closure it works out to the right value */
-		*eval *= 0.25f;
+	/* todo: clean up these weights */
+	else if(ls.shader & SHADER_AREA_LIGHT)
+		*eval *= 0.25f; /* area lamp */
+	else if(ls.t != FLT_MAX)
+		*eval *= 0.25f*M_1_PI_F; /* point lamp */
 
-		/* XXX verify with other light types */
-	}
-
 	if(ls.shader & SHADER_CAST_SHADOW) {
 		/* setup ray */
 		ray->P = ray_offset(sd->P, sd->Ng);

Modified: branches/cycles/intern/cycles/kernel/kernel_light.h
===================================================================
--- branches/cycles/intern/cycles/kernel/kernel_light.h	2011-10-15 20:57:07 UTC (rev 41043)
+++ branches/cycles/intern/cycles/kernel/kernel_light.h	2011-10-15 23:49:01 UTC (rev 41044)
@@ -75,8 +75,8 @@
 			D = distant_light_sample(D, size, randu, randv);
 
 		ls->P = D;
-		ls->Ng = -D;
-		ls->D = D;
+		ls->Ng = D;
+		ls->D = -D;
 		ls->t = FLT_MAX;
 	}
 	else {
@@ -120,9 +120,9 @@
 	if(t == FLT_MAX)
 		return pdf;
 
-	float cos_pi = fabsf(dot(Ng, I));
+	float cos_pi = dot(Ng, I);
 
-	if(cos_pi == 0.0f)
+	if(cos_pi <= 0.0f)
 		return 0.0f;
 
 	return t*t*pdf/cos_pi;

Modified: branches/cycles/intern/cycles/kernel/osl/emissive.cpp
===================================================================
--- branches/cycles/intern/cycles/kernel/osl/emissive.cpp	2011-10-15 20:57:07 UTC (rev 41043)
+++ branches/cycles/intern/cycles/kernel/osl/emissive.cpp	2011-10-15 23:49:01 UTC (rev 41044)
@@ -64,7 +64,7 @@
     Color3 eval (const Vec3 &Ng, const Vec3 &omega_out) const
     {
         float cosNO = fabsf(Ng.dot(omega_out));
-        float res = cosNO > 0 ? 1.0f / float(M_PI) : 0.0f;
+        float res = cosNO > 0 ? 1.0f: 0.0f;
         return Color3(res, res, res);
     }
 
@@ -91,7 +91,7 @@
                const Vec3 &omega_out) const
     {
         float cosNO = Ng.dot(omega_out);
-        return cosNO > 0 ? 1.0f / float(M_PI) : 0.0f;
+        return cosNO > 0 ? 1.0f: 0.0f;
     }
 };
 

Modified: branches/cycles/intern/cycles/kernel/svm/emissive.h
===================================================================
--- branches/cycles/intern/cycles/kernel/svm/emissive.h	2011-10-15 20:57:07 UTC (rev 41043)
+++ branches/cycles/intern/cycles/kernel/svm/emissive.h	2011-10-15 23:49:01 UTC (rev 41044)
@@ -37,7 +37,7 @@
 __device float3 emissive_eval(const float3 Ng, const float3 I)
 {
 	float cosNO = fabsf(dot(Ng, I));
-	float res = (cosNO > 0.0f)? M_1_PI_F: 0.0f;
+	float res = (cosNO > 0.0f)? 1.0f: 0.0f;
 	
 	return make_float3(res, res, res);
 }
@@ -48,7 +48,7 @@
 __device float emissive_pdf(const float3 Ng, const float3 I)
 {
 	float cosNO = fabsf(dot(Ng, I));
-	return (cosNO > 0.0f)? M_1_PI_F: 0.0f;
+	return (cosNO > 0.0f)? 1.0f: 0.0f;
 }
 
 __device float3 svm_emissive_eval(ShaderData *sd, ShaderClosure *sc)

Modified: branches/cycles/source/blender/blenkernel/BKE_blender.h
===================================================================
--- branches/cycles/source/blender/blenkernel/BKE_blender.h	2011-10-15 20:57:07 UTC (rev 41043)
+++ branches/cycles/source/blender/blenkernel/BKE_blender.h	2011-10-15 23:49:01 UTC (rev 41044)
@@ -44,7 +44,7 @@
  * and keep comment above the defines.
  * Use STRINGIFY() rather than defining with quotes */
 #define BLENDER_VERSION			259
-#define BLENDER_SUBVERSION		4
+#define BLENDER_SUBVERSION		5
 
 #define BLENDER_MINVERSION		250
 #define BLENDER_MINSUBVERSION	0

Modified: branches/cycles/source/blender/blenloader/intern/readfile.c
===================================================================
--- branches/cycles/source/blender/blenloader/intern/readfile.c	2011-10-15 20:57:07 UTC (rev 41043)
+++ branches/cycles/source/blender/blenloader/intern/readfile.c	2011-10-15 23:49:01 UTC (rev 41044)
@@ -2057,6 +2057,30 @@
 	}
 }
 
+static void ntree_tmp_cycles_emission_version_patch(FileData *fd, Library *lib, bNodeTree *ntree)
+{
+	bNode *node;
+	bNodeSocket *sock;
+	bNodeSocketValueFloat *valfloat;
+
+	for(node=ntree->nodes.first; node; node=node->next) {
+		if(node->type == SH_NODE_EMISSION) {
+			for(sock=node->inputs.first; sock; sock=sock->next) {
+				if(strcmp(sock->name, "Strength") == 0) {
+					valfloat= sock->default_value;
+					valfloat->value /= M_PI;
+				}
+			}
+		}
+		else if(node->type == NODE_GROUP) {
+			bNodeTree *ntree= newlibadr(fd, lib, node->id);
+
+			if(ntree)
+				ntree_tmp_cycles_emission_version_patch(fd, lib, ntree);
+		}
+	}
+}
+
 static void ntree_tmp_cycles_version_patch(bNodeTree *ntree)
 {
 	bNode *node;
@@ -12296,6 +12320,31 @@
 
 	}
 
+	if(main->versionfile < 259 || (main->versionfile == 259 && main->subversionfile < 5)) {
+		Scene *sce;
+		Base *base;
+		Material *ma;
+
+		/* compatibility tweak */
+		for(sce = main->scene.first; sce; sce = sce->id.next) {
+			if(strcmp(sce->r.engine, "CYCLES") == 0) {
+				for(base = sce->base.first; base; base=base->next) {
+					Object *ob= newlibadr(fd, lib, base->object);
+
+					if(ob && ob->type == OB_LAMP) {
+						Lamp *la= newlibadr(fd, lib, ob->data);
+						if(la)
+							la->area_size= 0.0f;
+					}
+				}
+			}
+		}
+
+		for(ma = main->mat.first; ma; ma= ma->id.next)
+			if(ma->nodetree)
+				ntree_tmp_cycles_emission_version_patch(fd, lib, ma->nodetree);
+	}
+
 	/* put compatibility code here until next subversion bump */
 	{
 	}

Modified: branches/cycles/source/blender/editors/space_node/node_edit.c
===================================================================
--- branches/cycles/source/blender/editors/space_node/node_edit.c	2011-10-15 20:57:07 UTC (rev 41043)
+++ branches/cycles/source/blender/editors/space_node/node_edit.c	2011-10-15 23:49:01 UTC (rev 41044)
@@ -331,6 +331,16 @@
 	fromsock= in->outputs.first;
 	tosock= out->inputs.first;
 	nodeAddLink(ntree, in, fromsock, out, tosock);
+
+	if(GS(id->name) == ID_LA) {
+		Lamp *la= (Lamp*)id;
+
+		if(la->type == LA_LOCAL || la->type == LA_SPOT || la->type == LA_AREA) {
+			bNodeSocket *sock= in->inputs.last;
+			bNodeSocketValueFloat *default_value= sock->default_value;
+			default_value->value= 100.0f;
+		}
+	}
 	
 	ntreeUpdateTree(ntree);
 }

Modified: branches/cycles/source/blender/nodes/shader/nodes/node_shader_emission.c
===================================================================
--- branches/cycles/source/blender/nodes/shader/nodes/node_shader_emission.c	2011-10-15 20:57:07 UTC (rev 41043)
+++ branches/cycles/source/blender/nodes/shader/nodes/node_shader_emission.c	2011-10-15 23:49:01 UTC (rev 41044)
@@ -33,7 +33,7 @@
 
 static bNodeSocketTemplate sh_node_emission_in[]= {
 	{	SOCK_RGBA, 1, "Color",		0.8f, 0.8f, 0.8f, 1.0f, 0.0f, 1.0f},
-	{	SOCK_FLOAT, 1, "Strength",	30.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1000000.0f},
+	{	SOCK_FLOAT, 1, "Strength",	1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1000000.0f},
 	{	-1, 0, ""	}
 };
 




More information about the Bf-blender-cvs mailing list