[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [34959] trunk/blender/source/blender/nodes /intern: Bugfix #26128

Ton Roosendaal ton at blender.org
Fri Feb 18 13:34:32 CET 2011


Revision: 34959
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=34959
Author:   ton
Date:     2011-02-18 12:34:31 +0000 (Fri, 18 Feb 2011)
Log Message:
-----------
Bugfix #26128

Compositor/texture nodes: math node now allows to use pow() for
negative raising too, but only when that value is near-integer.
For other negative cases result is zero.
Patch provided by Aurel W

Modified Paths:
--------------
    trunk/blender/source/blender/nodes/intern/CMP_nodes/CMP_math.c
    trunk/blender/source/blender/nodes/intern/TEX_nodes/TEX_math.c

Modified: trunk/blender/source/blender/nodes/intern/CMP_nodes/CMP_math.c
===================================================================
--- trunk/blender/source/blender/nodes/intern/CMP_nodes/CMP_math.c	2011-02-18 10:35:37 UTC (rev 34958)
+++ trunk/blender/source/blender/nodes/intern/CMP_nodes/CMP_math.c	2011-02-18 12:34:31 UTC (rev 34959)
@@ -94,11 +94,18 @@
 		break;
 	case 10: /* Power */
 		{
-			/* Don't want any imaginary numbers... */
-			if( in[0] >= 0 )
+			/* Only raise negative numbers by full integers */
+			if( in[0] >= 0 ) {
 				out[0]= pow(in[0], in2[0]);
-			else
-				out[0]= 0.0;
+            } else {
+                float y_mod_1 = fmod(in2[0], 1);
+				/* if input value is not nearly an integer, fall back to zero, nicer than straight rounding */
+                if (y_mod_1 > 0.999 || y_mod_1 < 0.001) {
+                    out[0]= pow(in[0], round(in2[0]));
+                } else {
+                    out[0] = 0.0;
+                }
+            }
 		}
 		break;
 	case 11: /* Logarithm */

Modified: trunk/blender/source/blender/nodes/intern/TEX_nodes/TEX_math.c
===================================================================
--- trunk/blender/source/blender/nodes/intern/TEX_nodes/TEX_math.c	2011-02-18 10:35:37 UTC (rev 34958)
+++ trunk/blender/source/blender/nodes/intern/TEX_nodes/TEX_math.c	2011-02-18 12:34:31 UTC (rev 34959)
@@ -106,11 +106,17 @@
 		break;
 	case 10: /* Power */
 		{
-			/* Don't want any imaginary numbers... */
-			if( in0 >= 0 )
-				*out= pow(in0, in1);
-			else
-				*out= 0.0;
+			/* Only raise negative numbers by full integers */
+			if( in0 >= 0 ) {
+				out[0]= pow(in0, in1);
+            } else {
+                float y_mod_1 = fmod(in1, 1);
+                if (y_mod_1 > 0.999 || y_mod_1 < 0.001) {
+                    *out = pow(in0, round(in1));
+                } else {
+                    *out = 0.0;
+                }
+            }
 		}
 		break;
 	case 11: /* Logarithm */




More information about the Bf-blender-cvs mailing list