[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [32118] trunk/blender/source/blender: Fix #23901: displace node not working with negative values.

Brecht Van Lommel brechtvanlommel at pandora.be
Sat Sep 25 13:30:47 CEST 2010


Revision: 32118
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=32118
Author:   blendix
Date:     2010-09-25 13:30:46 +0200 (Sat, 25 Sep 2010)

Log Message:
-----------
Fix #23901: displace node not working with negative values.

Modified Paths:
--------------
    trunk/blender/source/blender/blenlib/BLI_math_base.h
    trunk/blender/source/blender/blenlib/intern/math_base_inline.c
    trunk/blender/source/blender/nodes/intern/CMP_nodes/CMP_displace.c

Modified: trunk/blender/source/blender/blenlib/BLI_math_base.h
===================================================================
--- trunk/blender/source/blender/blenlib/BLI_math_base.h	2010-09-25 10:11:36 UTC (rev 32117)
+++ trunk/blender/source/blender/blenlib/BLI_math_base.h	2010-09-25 11:30:46 UTC (rev 32118)
@@ -155,6 +155,8 @@
 MINLINE float minf(float a, float b);
 MINLINE float maxf(float a, float b);
 
+MINLINE float signf(float f);
+
 MINLINE float power_of_2(float f);
 
 MINLINE float shell_angle_to_dist(float angle);

Modified: trunk/blender/source/blender/blenlib/intern/math_base_inline.c
===================================================================
--- trunk/blender/source/blender/blenlib/intern/math_base_inline.c	2010-09-25 10:11:36 UTC (rev 32117)
+++ trunk/blender/source/blender/blenlib/intern/math_base_inline.c	2010-09-25 11:30:46 UTC (rev 32118)
@@ -122,5 +122,10 @@
 	return (a > b)? a: b;
 }
 
+MINLINE float signf(float f)
+{
+	return (f < 0.f)? -1.f: 1.f;
+}
+
 #endif /* BLI_MATH_BASE_INLINE */
 

Modified: trunk/blender/source/blender/nodes/intern/CMP_nodes/CMP_displace.c
===================================================================
--- trunk/blender/source/blender/nodes/intern/CMP_nodes/CMP_displace.c	2010-09-25 10:11:36 UTC (rev 32117)
+++ trunk/blender/source/blender/nodes/intern/CMP_nodes/CMP_displace.c	2010-09-25 11:30:46 UTC (rev 32118)
@@ -83,7 +83,7 @@
 			p_dy = vec[1] * ys;
 			
 			/* if no displacement, then just copy this pixel */
-			if (p_dx < DISPLACE_EPSILON && p_dy < DISPLACE_EPSILON) {
+			if (fabsf(p_dx) < DISPLACE_EPSILON && fabsf(p_dy) < DISPLACE_EPSILON) {
 				qd_getPixel(cbuf, x-cbuf->xof, y-cbuf->yof, col);
 				qd_setPixel(stackbuf, x, y, col);
 				continue;
@@ -99,10 +99,13 @@
 			qd_getPixel(vecbuf, x-vecbuf->xof, y-vecbuf->yof+1, vecdy);
 			d_dx = vecdx[0] * xs;
 			d_dy = vecdy[0] * ys;
-			
+
 			/* clamp derivatives to minimum displacement distance in UV space */
-			dxt = MAX2(p_dx - d_dx, DISPLACE_EPSILON)/(float)stackbuf->x;
-			dyt = MAX2(p_dy - d_dy, DISPLACE_EPSILON)/(float)stackbuf->y;
+			dxt = p_dx - d_dx;
+			dyt = p_dy - d_dy;
+
+			dxt = signf(dxt)*maxf(fabsf(dxt), DISPLACE_EPSILON)/(float)stackbuf->x;
+			dyt = signf(dyt)*maxf(fabsf(dyt), DISPLACE_EPSILON)/(float)stackbuf->y;
 			
 			ibuf_sample(ibuf, u, v, dxt, dyt, col);
 			qd_setPixel(stackbuf, x, y, col);





More information about the Bf-blender-cvs mailing list