static public VFXExpression GetPerspectiveMatrix(VFXExpression fov, VFXExpression aspect, VFXExpression zNear, VFXExpression zFar)
        {
            var fovHalf   = fov / TwoExpression[VFXValueType.Float];
            var cotangent = new VFXExpressionCos(fovHalf) / new VFXExpressionSin(fovHalf);
            var deltaZ    = zNear - zFar;

            var zero = ZeroExpression[VFXValueType.Float];
            var m0   = new VFXExpressionCombine(cotangent / aspect, zero, zero, zero);
            var m1   = new VFXExpressionCombine(zero, cotangent, zero, zero);
            var m2   = new VFXExpressionCombine(zero, zero, MinusOneExpression[VFXValueType.Float] * (zFar + zNear) / deltaZ, OneExpression[VFXValueType.Float]);
            var m3   = new VFXExpressionCombine(zero, zero, TwoExpression[VFXValueType.Float] * zNear * zFar / deltaZ, zero);

            return(new VFXExpressionVector4sToMatrix(m0, m1, m2, m3));
        }
        static public VFXExpression SequentialCircle(VFXExpression center, VFXExpression radius, VFXExpression normal, VFXExpression up, VFXExpression index, VFXExpression count)
        {
            VFXExpression dt = new VFXExpressionCastUintToFloat(VFXOperatorUtility.Modulo(index, count));

            dt = dt / new VFXExpressionCastUintToFloat(count);

            var cos  = new VFXExpressionCos(dt * VFXOperatorUtility.TauExpression[VFXValueType.Float]) as VFXExpression;
            var sin  = new VFXExpressionSin(dt * VFXOperatorUtility.TauExpression[VFXValueType.Float]) as VFXExpression;
            var left = VFXOperatorUtility.Normalize(VFXOperatorUtility.Cross(normal, up));

            radius = new VFXExpressionCombine(radius, radius, radius);
            sin    = new VFXExpressionCombine(sin, sin, sin);
            cos    = new VFXExpressionCombine(cos, cos, cos);

            return(center + (cos * up + sin * left) * radius);
        }
        static public VFXExpression SphericalToRectangular(VFXExpression theta, VFXExpression phi, VFXExpression distance)
        {
            //x = cos(theta) * cos(phi) * distance
            //y = sin(theta) * cos(phi) * distance
            //z = sin(phi) * distance
            var cosTheta = new VFXExpressionCos(theta);
            var cosPhi   = new VFXExpressionCos(phi);
            var sinTheta = new VFXExpressionSin(theta);
            var sinPhi   = new VFXExpressionSin(phi);

            var x = (cosTheta * cosPhi);
            var y = sinPhi;
            var z = (sinTheta * cosPhi);

            var result = new VFXExpressionCombine(new VFXExpression[] { x, y, z });

            return(result * CastFloat(distance, VFXValueType.Float3));
        }
Example #4
0
        static public VFXExpression SequentialCircle(VFXExpression center, VFXExpression radius, VFXExpression normal, VFXExpression up, VFXExpression index, VFXExpression count, SequentialAddressingMode mode)
        {
            VFXExpression countForAddressing = count;

            if (mode == SequentialAddressingMode.Clamp || mode == SequentialAddressingMode.Mirror)
            {
                //Explicitly close the circle loop, if `index` equals to `count`, adds an extra step.
                countForAddressing = count + OneExpression[VFXValueType.Uint32];
            }
            VFXExpression dt = ApplyAddressingMode(index, countForAddressing, mode);

            dt = new VFXExpressionCastUintToFloat(dt);
            dt = dt / new VFXExpressionCastUintToFloat(count);

            var cos  = new VFXExpressionCos(dt * VFXOperatorUtility.TauExpression[VFXValueType.Float]) as VFXExpression;
            var sin  = new VFXExpressionSin(dt * VFXOperatorUtility.TauExpression[VFXValueType.Float]) as VFXExpression;
            var left = VFXOperatorUtility.Normalize(VFXOperatorUtility.Cross(normal, up));

            radius = new VFXExpressionCombine(radius, radius, radius);
            sin    = new VFXExpressionCombine(sin, sin, sin);
            cos    = new VFXExpressionCombine(cos, cos, cos);

            return(center + (cos * up + sin * left) * radius);
        }