static public VFXExpression SafeNormalize(VFXExpression v) { var sqrDist = Dot(v, v); var condition = new VFXExpressionCondition(VFXValueType.Float, VFXCondition.Less, sqrDist, VFXOperatorUtility.EpsilonSqrExpression[VFXValueType.Float]); return(new VFXExpressionBranch(condition, VFXOperatorUtility.ZeroExpression[v.valueType], Normalize(v))); }
static public VFXExpression ApplyAddressingMode(VFXExpression index, VFXExpression count, SequentialAddressingMode mode) { VFXExpression r = null; if (mode == SequentialAddressingMode.Wrap) { r = Modulo(index, count); } else if (mode == SequentialAddressingMode.Clamp) { var countMinusOne = count - OneExpression[VFXValueType.Uint32]; r = new VFXExpressionMin(index, countMinusOne); } else if (mode == SequentialAddressingMode.Mirror) { var two = TwoExpression[VFXValueType.Uint32]; var cycle = count * two - two; cycle = new VFXExpressionMax(cycle, OneExpression[VFXValueType.Uint32]); var modulo = Modulo(index, cycle); //var compare = new VFXExpressionCondition(VFXCondition.Less, new VFXExpressionCastUintToFloat(modulo), new VFXExpressionCastUintToFloat(count)); <= Use this line for 7.x.x/8.x.x/9.x.x backport var compare = new VFXExpressionCondition(VFXValueType.Uint32, VFXCondition.Less, modulo, count); r = new VFXExpressionBranch(compare, modulo, cycle - modulo); } return(r); }
static public VFXExpression IsTRSMatrixZeroScaled(VFXExpression matrix) { var i = new VFXExpressionMatrixToVector3s(matrix, VFXValue.Constant(0)); var j = new VFXExpressionMatrixToVector3s(matrix, VFXValue.Constant(1)); var k = new VFXExpressionMatrixToVector3s(matrix, VFXValue.Constant(2)); var sqrLengthI = Dot(i, i); var sqrLengthJ = Dot(j, j); var sqrLengthK = Dot(k, k); var epsilon = EpsilonSqrExpression[VFXValueType.Float]; var compareI = new VFXExpressionCondition(VFXValueType.Float, VFXCondition.Less, sqrLengthI, epsilon); var compareJ = new VFXExpressionCondition(VFXValueType.Float, VFXCondition.Less, sqrLengthJ, epsilon); var compareK = new VFXExpressionCondition(VFXValueType.Float, VFXCondition.Less, sqrLengthK, epsilon); var condition = new VFXExpressionLogicalOr(compareI, new VFXExpressionLogicalOr(compareJ, compareK)); return(condition); }