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
This commit is contained in:
Ton Roosendaal 2011-02-18 12:34:31 +00:00
parent b74601078d
commit 538ad31bfb
2 changed files with 22 additions and 9 deletions

@ -94,11 +94,18 @@ static void do_math(bNode *node, float *out, float *in, float *in2)
break; break;
case 10: /* Power */ case 10: /* Power */
{ {
/* Don't want any imaginary numbers... */ /* Only raise negative numbers by full integers */
if( in[0] >= 0 ) if( in[0] >= 0 ) {
out[0]= pow(in[0], in2[0]); out[0]= pow(in[0], in2[0]);
else } else {
out[0]= 0.0; 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; break;
case 11: /* Logarithm */ case 11: /* Logarithm */

@ -106,11 +106,17 @@ static void valuefn(float *out, TexParams *p, bNode *node, bNodeStack **in, shor
break; break;
case 10: /* Power */ case 10: /* Power */
{ {
/* Don't want any imaginary numbers... */ /* Only raise negative numbers by full integers */
if( in0 >= 0 ) if( in0 >= 0 ) {
*out= pow(in0, in1); out[0]= pow(in0, in1);
else } else {
*out= 0.0; 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; break;
case 11: /* Logarithm */ case 11: /* Logarithm */