public void ProcessOperatorFrac()
        {
            var a       = -1.5f;
            var b       = 0.2f;
            var resultA = a - Mathf.Floor(a);
            var resultB = b - Mathf.Floor(b);

            var value_a = new VFXValue <float>(a);
            var value_b = new VFXValue <float>(b);

            var expressionA = VFXOperatorUtility.Frac(value_a);
            var expressionB = VFXOperatorUtility.Frac(value_b);

            var context           = new VFXExpression.Context(VFXExpressionContextOption.CPUEvaluation);
            var resultExpressionA = context.Compile(expressionA);
            var resultExpressionB = context.Compile(expressionB);

            Assert.AreEqual(resultA, resultExpressionA.Get <float>());
            Assert.AreEqual(resultB, resultExpressionB.Get <float>());
        }
        public void ProcessOperatorDistance()
        {
            var a       = new Vector3(0.2f, 0.3f, 0.4f);
            var b       = new Vector3(1.0f, 2.3f, 5.4f);
            var resultA = Vector3.Distance(a, b);
            var resultB = Vector3.Dot(a - b, a - b);

            var value_a = new VFXValue <Vector3>(a);
            var value_b = new VFXValue <Vector3>(b);

            var expressionA = VFXOperatorUtility.Distance(value_a, value_b);
            var expressionB = VFXOperatorUtility.SqrDistance(value_a, value_b);

            var context           = new VFXExpression.Context(VFXExpressionContextOption.CPUEvaluation);
            var resultExpressionA = context.Compile(expressionA);
            var resultExpressionB = context.Compile(expressionB);

            Assert.AreEqual(resultA, resultExpressionA.Get <float>());
            Assert.AreEqual(resultB, resultExpressionB.Get <float>());
        }
Exemple #3
0
        public void CheckExpectedSequence_ApplyAddressingMode([ValueSource("ApplyAddressingModeTestCase_ValueSource")] ApplyAddressingModeTestCase addressingMode)
        {
            var computedSequence = new uint[addressingMode.expectedSequence.Length];

            for (uint index = 0u; index < computedSequence.Length; ++index)
            {
                var indexExpr = VFXValue.Constant(index);
                var countExpr = VFXValue.Constant(addressingMode.count);
                var computed  = VFXOperatorUtility.ApplyAddressingMode(indexExpr, countExpr, addressingMode.mode);

                var context = new VFXExpression.Context(VFXExpressionContextOption.CPUEvaluation);
                var result  = context.Compile(computed);

                computedSequence[index] = result.Get <uint>();
            }

            for (uint index = 0u; index < computedSequence.Length; ++index)
            {
                Assert.AreEqual(addressingMode.expectedSequence[index], computedSequence[index]);
            }
        }
Exemple #4
0
        public static CameraMatricesExpressions GetMatricesExpressions(IEnumerable <VFXNamedExpression> expressions)
        {
            var fov          = expressions.First(e => e.name == "Camera_fieldOfView");
            var aspect       = expressions.First(e => e.name == "Camera_aspectRatio");
            var near         = expressions.First(e => e.name == "Camera_nearPlane");
            var far          = expressions.First(e => e.name == "Camera_farPlane");
            var cameraMatrix = expressions.First(e => e.name == "Camera_transform");

            VFXExpression ViewToVFX  = cameraMatrix.exp;
            VFXExpression VFXToView  = new VFXExpressionInverseTRSMatrix(ViewToVFX);
            VFXExpression ViewToClip = VFXOperatorUtility.GetPerspectiveMatrix(fov.exp, aspect.exp, near.exp, far.exp);
            VFXExpression ClipToView = new VFXExpressionInverseMatrix(ViewToClip);

            return(new CameraMatricesExpressions()
            {
                ViewToVFX = new VFXNamedExpression(ViewToVFX, "ViewToVFX"),
                VFXToView = new VFXNamedExpression(VFXToView, "VFXToView"),
                ViewToClip = new VFXNamedExpression(ViewToClip, "ViewToClip"),
                ClipToView = new VFXNamedExpression(ClipToView, "ClipToView"),
            });
        }
        public void ProcessOperatorCross()
        {
            var a = new Vector3(1.1f, 2.2f, 3.3f);
            var b = new Vector3(4.4f, 5.5f, 6.6f);

            var value_a = new VFXValue <Vector3>(a);
            var value_b = new VFXValue <Vector3>(b);

            var expressionA = VFXOperatorUtility.Cross(value_a, value_b);

            var context = new VFXExpression.Context(VFXExpressionContextOption.CPUEvaluation);

            var resultExpressionA = context.Compile(expressionA);
            var resultValue       = resultExpressionA.Get <Vector3>();

            var expectedValue = Vector3.Cross(a, b);

            Assert.AreEqual(expectedValue.x, resultValue.x, 0.001f);
            Assert.AreEqual(expectedValue.y, resultValue.y, 0.001f);
            Assert.AreEqual(expectedValue.z, resultValue.z, 0.001f);
        }
Exemple #6
0
        protected override sealed VFXExpression[] BuildExpression(VFXExpression[] inputExpression)
        {
            var mesh = inputExpression[0];

            var meshVertexStride = new VFXExpressionMeshVertexStride(mesh);
            var meshVertexCount  = new VFXExpressionMeshVertexCount(mesh);
            var vertexIndex      = VFXOperatorUtility.ApplyAddressingMode(inputExpression[1], meshVertexCount, mode);

            var outputExpressions = new List <VFXExpression>();

            foreach (var vertexAttribute in GetOutputVertexAttributes())
            {
                var meshChannelOffset = new VFXExpressionMeshChannelOffset(mesh, VFXValue.Constant <uint>((uint)GetActualVertexAttribute(vertexAttribute)));

                var           outputType = GetOutputType(vertexAttribute);
                VFXExpression sampled    = null;
                if (vertexAttribute == VertexAttributeFlag.Color)
                {
                    sampled = new VFXExpressionSampleMeshColor(mesh, vertexIndex, meshChannelOffset, meshVertexStride);
                }
                else if (outputType == typeof(float))
                {
                    sampled = new VFXExpressionSampleMeshFloat(mesh, vertexIndex, meshChannelOffset, meshVertexStride);
                }
                else if (outputType == typeof(Vector2))
                {
                    sampled = new VFXExpressionSampleMeshFloat2(mesh, vertexIndex, meshChannelOffset, meshVertexStride);
                }
                else if (outputType == typeof(Vector3))
                {
                    sampled = new VFXExpressionSampleMeshFloat3(mesh, vertexIndex, meshChannelOffset, meshVertexStride);
                }
                else
                {
                    sampled = new VFXExpressionSampleMeshFloat4(mesh, vertexIndex, meshChannelOffset, meshVertexStride);
                }
                outputExpressions.Add(sampled);
            }
            return(outputExpressions.ToArray());
        }
        protected override sealed VFXExpression[] BuildExpression(VFXExpression[] inputExpression)
        {
            VFXExpression parameters = new VFXExpressionCombine(inputExpression[1], inputExpression[3], inputExpression[4]);

            VFXExpression result;

            if (dimensions == DimensionCount.Two)
            {
                if (type == NoiseType.Value)
                {
                    result = new VFXExpressionValueCurlNoise2D(inputExpression[0], parameters, inputExpression[2]);
                }
                else if (type == NoiseType.Perlin)
                {
                    result = new VFXExpressionPerlinCurlNoise2D(inputExpression[0], parameters, inputExpression[2]);
                }
                else
                {
                    result = new VFXExpressionCellularCurlNoise2D(inputExpression[0], parameters, inputExpression[2]);
                }
            }
            else
            {
                if (type == NoiseType.Value)
                {
                    result = new VFXExpressionValueCurlNoise3D(inputExpression[0], parameters, inputExpression[2]);
                }
                else if (type == NoiseType.Perlin)
                {
                    result = new VFXExpressionPerlinCurlNoise3D(inputExpression[0], parameters, inputExpression[2]);
                }
                else
                {
                    result = new VFXExpressionCellularCurlNoise3D(inputExpression[0], parameters, inputExpression[2]);
                }
            }

            return(new[] { result *VFXOperatorUtility.CastFloat(inputExpression[5], result.valueType) });
        }
        public void ProcessOperatorPolarToRectangular()
        {
            var theta    = 0.5f;
            var distance = 0.2f;

            var rectangular = new Vector2(Mathf.Cos(theta), Mathf.Sin(theta)) * distance;

            var value_theta    = new VFXValue <float>(theta);
            var value_distance = new VFXValue <float>(distance);

            var expressionA = VFXOperatorUtility.PolarToRectangular(value_theta, value_distance);
            var expressionB = VFXOperatorUtility.RectangularToPolar(expressionA);

            var context            = new VFXExpression.Context(VFXExpressionContextOption.CPUEvaluation);
            var resultExpressionA  = context.Compile(expressionA);
            var resultExpressionB0 = context.Compile(expressionB[0]);
            var resultExpressionB1 = context.Compile(expressionB[1]);

            Assert.AreEqual(rectangular, resultExpressionA.Get <Vector2>());
            Assert.AreEqual(theta, resultExpressionB0.Get <float>());
            Assert.AreEqual(distance, resultExpressionB1.Get <float>());
        }
Exemple #9
0
        protected override sealed VFXExpression[] BuildExpression(VFXExpression[] inputExpression)
        {
            VFXExpression[] expressions = new VFXExpression[asset.surfaces.Length + 1];
            expressions[0] = VFXValue.Constant((uint)asset.PointCount);

            for (int i = 0; i < asset.surfaces.Length; i++)
            {
                var           surfaceExpr = VFXValue.Constant(asset.surfaces[i]);
                VFXExpression height      = new VFXExpressionTextureHeight(surfaceExpr);
                VFXExpression width       = new VFXExpressionTextureWidth(surfaceExpr);
                VFXExpression u_index     = VFXOperatorUtility.ApplyAddressingMode(inputExpression[0], new VFXExpressionMin(height * width, expressions[0]), mode);
                VFXExpression y           = u_index / width;
                VFXExpression x           = u_index - (y * width);

                Type outputType = GetOutputType(asset.surfaces[i]);
                var  type       = typeof(VFXExpressionSampleAttributeMap <>).MakeGenericType(outputType);
                var  outputExpr = Activator.CreateInstance(type, new object[] { surfaceExpr, x, y });

                expressions[i + 1] = (VFXExpression)outputExpr;
            }

            return(expressions);
        }
        protected override sealed VFXExpression[] BuildExpression(VFXExpression[] inputExpression)
        {
            VFXExpression parameters = new VFXExpressionCombine(inputExpression[1], inputExpression[2], inputExpression[4]);

            if (dimensions == DimensionCount.One)
            {
                VFXExpression noise = new VFXExpressionPerlinNoise1D(inputExpression[0], parameters, inputExpression[3]);
                noise = VFXOperatorUtility.Fit(noise, VFXValue.Constant(new Vector2(-1.0f, -1.0f)), VFXValue.Constant(Vector2.one), VFXOperatorUtility.CastFloat(inputExpression[5].x, noise.valueType), VFXOperatorUtility.CastFloat(inputExpression[5].y, noise.valueType));
                return(new[] { noise.x, noise.y });
            }
            else if (dimensions == DimensionCount.Two)
            {
                VFXExpression noise = new VFXExpressionPerlinNoise2D(inputExpression[0], parameters, inputExpression[3]);
                noise = VFXOperatorUtility.Fit(noise, VFXValue.Constant(new Vector3(-1.0f, -1.0f, -1.0f)), VFXValue.Constant(Vector3.one), VFXOperatorUtility.CastFloat(inputExpression[5].x, noise.valueType), VFXOperatorUtility.CastFloat(inputExpression[5].y, noise.valueType));
                return(new[] { noise.x, new VFXExpressionCombine(noise.y, noise.z) });
            }
            else
            {
                VFXExpression noise = new VFXExpressionPerlinNoise3D(inputExpression[0], parameters, inputExpression[3]);
                noise = VFXOperatorUtility.Fit(noise, VFXValue.Constant(new Vector4(-1.0f, -1.0f, -1.0f, -1.0f)), VFXValue.Constant(Vector4.one), VFXOperatorUtility.CastFloat(inputExpression[5].x, noise.valueType), VFXOperatorUtility.CastFloat(inputExpression[5].y, noise.valueType));
                return(new[] { noise.x, new VFXExpressionCombine(noise.y, noise.z, noise.w) });
            }
        }
 private void GetPositionAndDirectionFromIndex(VFXExpression indexExpr, IEnumerable <VFXNamedExpression> expressions, out VFXExpression positionExpr, out VFXExpression directionExpr)
 {
     if (shape == SequentialShape.Line)
     {
         var start = expressions.First(o => o.name == "Start").exp;
         var end   = expressions.First(o => o.name == "End").exp;
         var count = expressions.First(o => o.name == "Count").exp;
         positionExpr  = VFXOperatorUtility.SequentialLine(start, end, indexExpr, count, mode);
         directionExpr = VFXOperatorUtility.SafeNormalize(end - start);
     }
     else if (shape == SequentialShape.Circle)
     {
         var center = expressions.First(o => o.name == "Center").exp;
         var normal = expressions.First(o => o.name == "Normal").exp;
         var up     = expressions.First(o => o.name == "Up").exp;
         var radius = expressions.First(o => o.name == "Radius").exp;
         var count  = expressions.First(o => o.name == "Count").exp;
         positionExpr  = VFXOperatorUtility.SequentialCircle(center, radius, normal, up, indexExpr, count, mode);
         directionExpr = VFXOperatorUtility.SafeNormalize(positionExpr - center);
     }
     else if (shape == SequentialShape.ThreeDimensional)
     {
         var origin = expressions.First(o => o.name == "Origin").exp;
         var axisX  = expressions.First(o => o.name == "AxisX").exp;
         var axisY  = expressions.First(o => o.name == "AxisY").exp;
         var axisZ  = expressions.First(o => o.name == "AxisZ").exp;
         var countX = expressions.First(o => o.name == "CountX").exp;
         var countY = expressions.First(o => o.name == "CountY").exp;
         var countZ = expressions.First(o => o.name == "CountZ").exp;
         positionExpr  = VFXOperatorUtility.Sequential3D(origin, axisX, axisY, axisZ, indexExpr, countX, countY, countZ, mode);
         directionExpr = VFXOperatorUtility.SafeNormalize(positionExpr - origin);
     }
     else
     {
         throw new NotImplementedException();
     }
 }
Exemple #12
0
        public static CameraMatricesExpressions GetMatricesExpressions(IEnumerable <VFXNamedExpression> expressions, VFXCoordinateSpace cameraSpace, VFXCoordinateSpace outputSpace)
        {
            var fov          = expressions.First(e => e.name == "Camera_fieldOfView");
            var aspect       = expressions.First(e => e.name == "Camera_aspectRatio");
            var near         = expressions.First(e => e.name == "Camera_nearPlane");
            var far          = expressions.First(e => e.name == "Camera_farPlane");
            var cameraMatrix = expressions.First(e => e.name == "Camera_transform");
            var isOrtho      = expressions.First(e => e.name == "Camera_orthographic");
            var orthoSize    = expressions.First(e => e.name == "Camera_orthographicSize");
            var lensShift    = expressions.First(e => e.name == "Camera_lensShift");

            VFXExpression ViewToVFX = cameraMatrix.exp;

            if (cameraSpace == VFXCoordinateSpace.World && outputSpace == VFXCoordinateSpace.Local)
            {
                ViewToVFX = new VFXExpressionTransformMatrix(VFXBuiltInExpression.WorldToLocal, cameraMatrix.exp);
            }
            else if (cameraSpace == VFXCoordinateSpace.Local && outputSpace == VFXCoordinateSpace.World)
            {
                ViewToVFX = new VFXExpressionTransformMatrix(VFXBuiltInExpression.LocalToWorld, cameraMatrix.exp);
            }

            VFXExpression VFXToView  = new VFXExpressionInverseTRSMatrix(ViewToVFX);
            VFXExpression ViewToClip = new VFXExpressionBranch(isOrtho.exp,
                                                               VFXOperatorUtility.GetOrthographicMatrix(orthoSize.exp, aspect.exp, near.exp, far.exp),
                                                               VFXOperatorUtility.GetPerspectiveMatrix(fov.exp, aspect.exp, near.exp, far.exp, lensShift.exp));
            VFXExpression ClipToView = new VFXExpressionInverseMatrix(ViewToClip);

            return(new CameraMatricesExpressions()
            {
                ViewToVFX = new VFXNamedExpression(ViewToVFX, "ViewToVFX"),
                VFXToView = new VFXNamedExpression(VFXToView, "VFXToView"),
                ViewToClip = new VFXNamedExpression(ViewToClip, "ViewToClip"),
                ClipToView = new VFXNamedExpression(ClipToView, "ClipToView"),
            });
        }
        public void ProcessOperatorLerp()
        {
            var a       = new Vector3(0.2f, 0.3f, 0.4f);
            var b       = new Vector3(1.0f, 2.3f, 5.4f);
            var c       = 0.2f;
            var d       = 1.5f;
            var resultA = Vector3.LerpUnclamped(a, b, c);
            var resultB = Vector3.LerpUnclamped(a, b, d);

            var value_a = new VFXValue <Vector3>(a);
            var value_b = new VFXValue <Vector3>(b);
            var value_c = new VFXValue <float>(c);
            var value_d = new VFXValue <float>(d);

            var expressionA = VFXOperatorUtility.Lerp(value_a, value_b, VFXOperatorUtility.CastFloat(value_c, value_b.valueType));
            var expressionB = VFXOperatorUtility.Lerp(value_a, value_b, VFXOperatorUtility.CastFloat(value_d, value_b.valueType));

            var context           = new VFXExpression.Context(VFXExpressionContextOption.CPUEvaluation);
            var resultExpressionA = context.Compile(expressionA);
            var resultExpressionB = context.Compile(expressionB);

            Assert.AreEqual((resultA - resultExpressionA.Get <Vector3>()).magnitude, 0.0f, 0.001f);
            Assert.AreEqual((resultB - resultExpressionB.Get <Vector3>()).magnitude, 0.0f, 0.001f);
        }
        public void ProcessOperatorFit()
        {
            var value       = 0.4f;
            var oldRangeMin = 0.2f;
            var oldRangeMax = 1.2f;
            var newRangeMin = 3.2f;
            var newRangeMax = 5.2f;

            var percent = (value - oldRangeMin) / (oldRangeMax - oldRangeMin);
            var result  = Mathf.LerpUnclamped(newRangeMin, newRangeMax, percent);

            var value_a = new VFXValue <float>(value);
            var value_b = new VFXValue <float>(oldRangeMin);
            var value_c = new VFXValue <float>(oldRangeMax);
            var value_d = new VFXValue <float>(newRangeMin);
            var value_e = new VFXValue <float>(newRangeMax);

            var expression = VFXOperatorUtility.Fit(value_a, value_b, value_c, value_d, value_e);

            var context          = new VFXExpression.Context(VFXExpressionContextOption.CPUEvaluation);
            var resultExpression = context.Compile(expression);

            Assert.AreEqual(result, resultExpression.Get <float>());
        }
Exemple #15
0
 protected override sealed VFXExpression[] BuildExpression(VFXExpression[] inputExpression)
 {
     return(new[] { VFXOperatorUtility.Exp(inputExpression[0], _base) });
 }
Exemple #16
0
        public static IEnumerable <VFXExpression> SampleTriangleAttribute(VFXExpression source, VFXExpression triangleIndex, VFXExpression coord, SurfaceCoordinates coordMode, IEnumerable <VertexAttribute> vertexAttributes)
        {
            bool skinnedMesh = source.valueType == UnityEngine.VFX.VFXValueType.SkinnedMeshRenderer;
            var  mesh        = !skinnedMesh ? source : new VFXExpressionMeshFromSkinnedMeshRenderer(source);

            var meshIndexCount  = new VFXExpressionMeshIndexCount(mesh);
            var meshIndexFormat = new VFXExpressionMeshIndexFormat(mesh);

            var threeUint = VFXOperatorUtility.ThreeExpression[UnityEngine.VFX.VFXValueType.Uint32];
            var baseIndex = triangleIndex * threeUint;

            var sampledIndex_A = new VFXExpressionSampleIndex(mesh, baseIndex, meshIndexFormat);
            var sampledIndex_B = new VFXExpressionSampleIndex(mesh, baseIndex + VFXValue.Constant <uint>(1u), meshIndexFormat);
            var sampledIndex_C = new VFXExpressionSampleIndex(mesh, baseIndex + VFXValue.Constant <uint>(2u), meshIndexFormat);

            var allInputValues = new List <VFXExpression>();
            var sampling_A     = SampleVertexAttribute(source, sampledIndex_A, vertexAttributes).ToArray();
            var sampling_B     = SampleVertexAttribute(source, sampledIndex_B, vertexAttributes).ToArray();
            var sampling_C     = SampleVertexAttribute(source, sampledIndex_C, vertexAttributes).ToArray();

            VFXExpression barycentricCoordinates = null;
            var           one = VFXOperatorUtility.OneExpression[UnityEngine.VFX.VFXValueType.Float];

            if (coordMode == SurfaceCoordinates.Barycentric)
            {
                var barycentricCoordinateInput = coord;
                barycentricCoordinates = new VFXExpressionCombine(barycentricCoordinateInput.x, barycentricCoordinateInput.y, one - barycentricCoordinateInput.x - barycentricCoordinateInput.y);
            }
            else if (coordMode == SurfaceCoordinates.Uniform)
            {
                //https://hal.archives-ouvertes.fr/hal-02073696v2/document
                var input = coord;

                var half2  = VFXOperatorUtility.HalfExpression[UnityEngine.VFX.VFXValueType.Float2];
                var zero   = VFXOperatorUtility.ZeroExpression[UnityEngine.VFX.VFXValueType.Float];
                var t      = input * half2;
                var offset = t.y - t.x;
                var pred   = new VFXExpressionCondition(UnityEngine.VFX.VFXValueType.Float, VFXCondition.Greater, offset, zero);
                var t2     = new VFXExpressionBranch(pred, t.y + offset, t.y);
                var t1     = new VFXExpressionBranch(pred, t.x, t.x - offset);
                var t3     = one - t2 - t1;
                barycentricCoordinates = new VFXExpressionCombine(t1, t2, t3);

                /* Possible variant See http://inis.jinr.ru/sl/vol1/CMC/Graphics_Gems_1,ed_A.Glassner.pdf (p24) uniform distribution from two numbers in triangle generating barycentric coordinate
                 * var input = VFXOperatorUtility.Saturate(inputExpression[2]);
                 * var s = input.x;
                 * var t = VFXOperatorUtility.Sqrt(input.y);
                 * var a = one - t;
                 * var b = (one - s) * t;
                 * var c = s * t;
                 * barycentricCoordinates = new VFXExpressionCombine(a, b, c);
                 */
            }
            else
            {
                throw new InvalidOperationException("No supported surfaceCoordinates : " + coord);
            }

            for (int i = 0; i < vertexAttributes.Count(); ++i)
            {
                var outputValueType = sampling_A[i].valueType;

                var barycentricCoordinateX = VFXOperatorUtility.CastFloat(barycentricCoordinates.x, outputValueType);
                var barycentricCoordinateY = VFXOperatorUtility.CastFloat(barycentricCoordinates.y, outputValueType);
                var barycentricCoordinateZ = VFXOperatorUtility.CastFloat(barycentricCoordinates.z, outputValueType);

                var r = sampling_A[i] * barycentricCoordinateX + sampling_B[i] * barycentricCoordinateY + sampling_C[i] * barycentricCoordinateZ;
                yield return(r);
            }
        }
Exemple #17
0
 protected override sealed VFXExpression[] BuildExpression(VFXExpression[] inputExpression)
 {
     VFXExpression[] rgb = VFXOperatorUtility.ExtractComponents(new VFXExpressionHSVtoRGB(inputExpression[0])).Take(3).ToArray();
     return(new[] { new VFXExpressionCombine(new[] { rgb[0], rgb[1], rgb[2], VFXValue.Constant(1.0f) }) });
 }
Exemple #18
0
        protected override VFXExpression[] BuildExpression(VFXExpression[] inputExpression)
        {
            VFXExpression clamped = VFXOperatorUtility.Clamp(inputExpression[0], inputExpression[1], inputExpression[2]);

            return(new[] { VFXOperatorUtility.Fit(clamped, inputExpression[1], inputExpression[2], inputExpression[3], inputExpression[4]) });
        }
 protected override sealed VFXExpression[] BuildExpression(VFXExpression[] inputExpression)
 {
     return(new VFXExpression[] { VFXOperatorUtility.ConeVolume(inputExpression[1], inputExpression[2], inputExpression[3]) });
 }
 protected override sealed VFXExpression[] BuildExpression(VFXExpression[] inputExpression)
 {
     return(new[] { VFXOperatorUtility.SphericalToRectangular(inputExpression[0], inputExpression[1], inputExpression[2]) });
 }
Exemple #21
0
 protected override sealed VFXExpression[] BuildExpression(VFXExpression[] inputExpression)
 {
     return(new[] { VFXOperatorUtility.PolarToRectangular(VFXOperatorUtility.DegToRad(inputExpression[0]), inputExpression[1]) });
 }
        protected override sealed VFXExpression[] BuildExpression(VFXExpression[] inputExpression)
        {
            var expressions = Block.CameraHelper.AddCameraExpressions(GetExpressionsFromSlots(this), camera);

            // camera matrix is already in world even in custom mode due to GetOutputSpaceFromSlot returning world space
            Block.CameraMatricesExpressions matricesExpressions = Block.CameraHelper.GetMatricesExpressions(expressions, VFXCoordinateSpace.World, VFXCoordinateSpace.World);

            // result = position * VFXToView * ViewToClip
            VFXExpression positionExpression = inputExpression[0];
            VFXExpression viewPosExpression  = new VFXExpressionTransformPosition(matricesExpressions.VFXToView.exp, positionExpression);
            VFXExpression clipPosExpression  = new VFXExpressionTransformVector4(matricesExpressions.ViewToClip.exp, VFXOperatorUtility.CastFloat(viewPosExpression, VFXValueType.Float4, 1.0f));

            // normalize using w component and renormalize to range [0, 1]
            VFXExpression halfExpression       = VFXValue.Constant(0.5f);
            VFXExpression normalizedExpression = new VFXExpressionCombine(new VFXExpression[]
            {
                (clipPosExpression.x / clipPosExpression.w) * halfExpression + halfExpression,
                (clipPosExpression.y / clipPosExpression.w) * halfExpression + halfExpression,
                viewPosExpression.z     // The z position is in world units from the camera
            });

            return(new VFXExpression[]
            {
                normalizedExpression
            });
        }
Exemple #23
0
 protected override sealed VFXExpression[] BuildExpression(VFXExpression[] inputExpression)
 {
     return(VFXOperatorUtility.RectangularToPolar(inputExpression[0]));
 }
Exemple #24
0
        protected override VFXExpression[] BuildExpression(VFXExpression[] inputExpression)
        {
            var type = inputExpression[0].valueType;

            VFXExpression input;

            if (Clamp)
            {
                input = VFXOperatorUtility.Saturate(inputExpression[0]);
            }
            else
            {
                input = inputExpression[0];
            }

            return(new[] { VFXOperatorUtility.Mad(input, VFXOperatorUtility.TwoExpression[type], VFXOperatorUtility.Negate(VFXOperatorUtility.OneExpression[type])) });
        }
        protected override sealed VFXExpression[] BuildExpression(VFXExpression[] inputExpression)
        {
            var expression = inputExpression[0];

            return(new[] { VFXOperatorUtility.Reciprocal(expression) });
        }
        protected override VFXExpression[] BuildExpression(VFXExpression[] inputExpression)
        {
            // Offset to compensate for the numerous custom camera generated expressions
            _customCameraOffset = 0;

            // Get the extra number of expressions if a custom camera input is used
            if (camera == CameraMode.Custom)
            {
                _customCameraOffset = GetInputSlot(0).children.Count() - 1;
            }

            // List to gather all output expressions as their number can vary
            List <VFXExpression> outputs = new List <VFXExpression>();

            // Camera expressions
            var expressions = Block.CameraHelper.AddCameraExpressions(GetExpressionsFromSlots(this), camera);

            Block.CameraMatricesExpressions camMatrices = Block.CameraHelper.GetMatricesExpressions(expressions);

            var Camera_depthBuffer = expressions.First(e => e.name == "Camera_depthBuffer").exp;
            var CamPixDim          = expressions.First(e => e.name == "Camera_pixelDimensions").exp;

            // Set uvs
            VFXExpression uv = VFXValue.Constant <Vector2>();

            // Determine how the particles are spawned on the screen
            switch (mode)
            {
            case PositionMode.Random:
                // Random UVs
                uv = new VFXExpressionCombine(VFXOperatorUtility.FixedRandom(0, VFXSeedMode.PerParticle), VFXOperatorUtility.FixedRandom(1, VFXSeedMode.PerParticle));
                break;

            case PositionMode.Sequential:
                // Pixel perfect spawn
                VFXExpression gridStep = inputExpression[inputSlots.IndexOf(inputSlots.First(o => o.name == "GridStep")) + _customCameraOffset];

                VFXExpression sSizeX = new VFXExpressionCastFloatToUint(CamPixDim.x / new VFXExpressionCastUintToFloat(gridStep));
                VFXExpression sSizeY = new VFXExpressionCastFloatToUint(CamPixDim.y / new VFXExpressionCastUintToFloat(gridStep));

                VFXExpression nbPixels   = sSizeX * sSizeY;
                VFXExpression particleID = new VFXAttributeExpression(VFXAttribute.ParticleId);
                VFXExpression id         = VFXOperatorUtility.Modulo(particleID, nbPixels);

                VFXExpression shift = new VFXExpressionBitwiseRightShift(gridStep, VFXValue.Constant <uint>(1));

                VFXExpression U = VFXOperatorUtility.Modulo(id, sSizeX) * gridStep + shift;
                VFXExpression V = id / sSizeX * gridStep + shift;

                VFXExpression ids = new VFXExpressionCombine(new VFXExpressionCastUintToFloat(U), new VFXExpressionCastUintToFloat(V));

                uv = new VFXExpressionDivide(ids + VFXOperatorUtility.CastFloat(VFXValue.Constant(0.5f), VFXValueType.Float2), CamPixDim);
                break;

            case PositionMode.Custom:
                // Custom UVs
                uv = inputExpression[inputSlots.IndexOf(inputSlots.FirstOrDefault(o => o.name == "UVSpawn")) + _customCameraOffset];
                break;
            }

            VFXExpression projpos = uv * VFXValue.Constant <Vector2>(new Vector2(2f, 2f)) - VFXValue.Constant <Vector2>(Vector2.one);
            VFXExpression uvs     = new VFXExpressionCombine(uv.x * CamPixDim.x, uv.y * CamPixDim.y, VFXValue.Constant(0f), VFXValue.Constant(0f));

            // Get depth
            VFXExpression depth = new VFXExpressionExtractComponent(new VFXExpressionLoadTexture2DArray(Camera_depthBuffer, uvs), 0);

            if (SystemInfo.usesReversedZBuffer)
            {
                depth = VFXOperatorUtility.OneExpression[depth.valueType] - depth;
            }

            VFXExpression isAlive = VFXValue.Constant(true);

            // Determine how the particles are culled
            switch (cullMode)
            {
            case CullMode.None:
                // do nothing
                break;

            case CullMode.Range:

                VFXExpression depthRange = inputExpression[inputSlots.IndexOf(inputSlots.LastOrDefault(o => o.name == "DepthRange")) + _customCameraOffset];

                VFXExpression nearRangeCheck = new VFXExpressionCondition(VFXCondition.Less, depth, depthRange.x);
                VFXExpression farRangeCheck  = new VFXExpressionCondition(VFXCondition.Greater, depth, depthRange.y);
                VFXExpression logicOr        = new VFXExpressionLogicalOr(nearRangeCheck, farRangeCheck);
                isAlive = new VFXExpressionBranch(logicOr, VFXValue.Constant(false), VFXValue.Constant(true));
                break;

            case CullMode.FarPlane:
                VFXExpression farPlaneCheck = new VFXExpressionCondition(VFXCondition.GreaterOrEqual, depth, VFXValue.Constant(1f) - VFXValue.Constant(Mathf.Epsilon));
                isAlive = new VFXExpressionBranch(farPlaneCheck, VFXValue.Constant(false), VFXValue.Constant(true));
                break;
            }

            VFXExpression zMultiplier = inputExpression[inputSlots.IndexOf(inputSlots.First(o => o.name == "ZMultiplier")) + _customCameraOffset];

            VFXExpression clipPos = new VFXExpressionCombine(projpos.x, projpos.y,
                                                             depth * zMultiplier * VFXValue.Constant(2f) - VFXValue.Constant(1f),
                                                             VFXValue.Constant(1f)
                                                             );

            VFXExpression clipToVFX = new VFXExpressionTransformMatrix(camMatrices.ViewToVFX.exp, camMatrices.ClipToView.exp);
            VFXExpression vfxPos    = new VFXExpressionTransformVector4(clipToVFX, clipPos);
            VFXExpression position  = new VFXExpressionCombine(vfxPos.x, vfxPos.y, vfxPos.z) / VFXOperatorUtility.CastFloat(vfxPos.w, VFXValueType.Float3);

            VFXExpression color = VFXValue.Constant <Vector4>();

            // Assigning the color output to the corresponding color buffer value
            if (inheritSceneColor)
            {
                VFXExpression Camera_colorBuffer = expressions.First(e => e.name == "Camera_colorBuffer").exp;
                VFXExpression tempColor          = new VFXExpressionLoadTexture2DArray(Camera_colorBuffer, uvs);
                color = new VFXExpressionCombine(tempColor.x, tempColor.y, tempColor.z, VFXValue.Constant(1.0f));
            }

            // Add expressions in the right output order
            outputs.Add(position);

            if (inheritSceneColor)
            {
                outputs.Add(color);
            }

            if (cullMode != CullMode.None)
            {
                outputs.Add(isAlive);
            }

            return(outputs.ToArray());
        }
 protected override sealed VFXExpression[] BuildExpression(VFXExpression[] inputExpression)
 {
     return(new VFXExpression[] { VFXOperatorUtility.BoxVolume(new VFXExpressionExtractScaleFromMatrix(inputExpression[0])) });
 }
Exemple #28
0
        protected override sealed VFXExpression[] BuildExpression(VFXExpression[] inputExpression)
        {
            VFXExpression parameters      = new VFXExpressionCombine(inputExpression[1], inputExpression[3], inputExpression[4]);
            VFXExpression rangeMultiplier = (inputExpression[5].y - inputExpression[5].x);

            VFXExpression result;
            VFXExpression rangeMin = VFXValue.Constant(0.0f);
            VFXExpression rangeMax = VFXValue.Constant(1.0f);

            if (dimensions == DimensionCount.One)
            {
                if (type == NoiseType.Value)
                {
                    result = new VFXExpressionValueNoise1D(inputExpression[0], parameters, inputExpression[2]);
                }
                else if (type == NoiseType.Perlin)
                {
                    result   = new VFXExpressionPerlinNoise1D(inputExpression[0], parameters, inputExpression[2]);
                    rangeMin = VFXValue.Constant(-1.0f);
                }
                else
                {
                    result = new VFXExpressionCellularNoise1D(inputExpression[0], parameters, inputExpression[2]);
                }

                VFXExpression x = VFXOperatorUtility.Fit(result.x, rangeMin, rangeMax, inputExpression[5].x, inputExpression[5].y);
                VFXExpression y = result.y * rangeMultiplier;
                return(new[] { x, y });
            }
            else if (dimensions == DimensionCount.Two)
            {
                if (type == NoiseType.Value)
                {
                    result = new VFXExpressionValueNoise2D(inputExpression[0], parameters, inputExpression[2]);
                }
                else if (type == NoiseType.Perlin)
                {
                    result   = new VFXExpressionPerlinNoise2D(inputExpression[0], parameters, inputExpression[2]);
                    rangeMin = VFXValue.Constant(-1.0f);
                }
                else
                {
                    result = new VFXExpressionCellularNoise2D(inputExpression[0], parameters, inputExpression[2]);
                }

                VFXExpression x = VFXOperatorUtility.Fit(result.x, rangeMin, rangeMax, inputExpression[5].x, inputExpression[5].y);
                VFXExpression y = result.y * rangeMultiplier;
                VFXExpression z = result.z * rangeMultiplier;
                return(new[] { x, new VFXExpressionCombine(y, z) });
            }
            else
            {
                if (type == NoiseType.Value)
                {
                    result = new VFXExpressionValueNoise3D(inputExpression[0], parameters, inputExpression[2]);
                }
                else if (type == NoiseType.Perlin)
                {
                    result   = new VFXExpressionPerlinNoise3D(inputExpression[0], parameters, inputExpression[2]);
                    rangeMin = VFXValue.Constant(-1.0f);
                }
                else
                {
                    result = new VFXExpressionCellularNoise3D(inputExpression[0], parameters, inputExpression[2]);
                }

                VFXExpression x = VFXOperatorUtility.Fit(result.x, rangeMin, rangeMax, inputExpression[5].x, inputExpression[5].y);
                VFXExpression y = result.y * rangeMultiplier;
                VFXExpression z = result.z * rangeMultiplier;
                VFXExpression w = result.w * rangeMultiplier;
                return(new[] { x, new VFXExpressionCombine(y, z, w) });
            }
        }
Exemple #29
0
 protected override sealed VFXExpression[] BuildExpression(VFXExpression[] inputExpression)
 {
     return(new[] { VFXOperatorUtility.Lerp(inputExpression[0], inputExpression[1], inputExpression[2]) });
 }
Exemple #30
0
 protected override sealed VFXExpression[] BuildExpression(VFXExpression[] inputExpression)
 {
     return(new[] { VFXOperatorUtility.ColorLuma(inputExpression[0]) });
 }