Forum: Poser Technical


Subject: Better documentation on the Math_Functions node?

odf opened this issue on Oct 19, 2024 ยท 14 posts


odf posted Sun, 20 October 2024 at 1:52 AM Online Now!

For reference, here's what I have so far (in Python, after import numpy as _np). Not super-confident about those last three, so I might dig for my texture baking kit for Poser and do a numerical comparison on top of the visual one. There may also be some edge cases I got wrong.


def bias(a, b):
    return a**(_np.log(b) / _np.log(0.5))


def gain(a, b):
    return _np.where(
        a < 0.5,
        bias(a * 2, 1 - b) / 2,
        1 - bias((1 - a) * 2, 1 - b) / 2
    )


op = {
    OpCode.Add: lambda a, b: a + b,
    OpCode.Subtract: lambda a, b: a - b,
    OpCode.Multiply: lambda a, b: a * b,
    OpCode.Divide: lambda a, b: a / b,
    OpCode.Sin: lambda a, _: _np.sin(a),
    OpCode.Cos: lambda a, _: _np.cos(a),
    OpCode.Tan: lambda a, _: _np.tan(a),
    OpCode.Sqrt: lambda a, _: _np.sqrt(a),
    OpCode.Pow: lambda a, b: a ** b,
    OpCode.Exp: lambda a, _: _np.exp(a),
    OpCode.Log: lambda a, b: _np.log(a) / _np.log(b),
    OpCode.Mod: lambda a, b: a % (_np.sign(a) * b),
    OpCode.Abs: lambda a, _: _np.abs(a),
    OpCode.Sign: lambda a, _: _np.sign(a),
    OpCode.Min: lambda a, b: _np.minimum(a, b),
    OpCode.Max: lambda a, b: _np.maximum(a, b),
    OpCode.Clamp: lambda a, _: _np.clip(a, 0, 1),
    OpCode.Ceil: lambda a, _: _np.ceil(a),
    OpCode.Floor: lambda a, _: _np.floor(a),
    OpCode.Round: lambda a, _: _np.round(a),
    OpCode.Step: lambda a, b: (a <= b).astype(_np.float32),
    OpCode.Smoothstep: lambda a, _: _np.clip(3 * a**2 - 2 * a**3, 0, 1),
    OpCode.Bias: bias,
    OpCode.Gain: gain,
}

-- I'm not mad at you, just Westphalian.