Example #1
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());
        }
Example #2
0
        public static IEnumerable <VFXExpression> SampleVertexAttribute(VFXExpression source, VFXExpression vertexIndex, IEnumerable <VertexAttribute> vertexAttributes)
        {
            bool skinnedMesh = source.valueType == UnityEngine.VFX.VFXValueType.SkinnedMeshRenderer;
            var  mesh        = !skinnedMesh ? source : new VFXExpressionMeshFromSkinnedMeshRenderer(source);

            foreach (var vertexAttribute in vertexAttributes)
            {
                var channelIndex      = VFXValue.Constant <uint>((uint)vertexAttribute);
                var meshVertexStride  = new VFXExpressionMeshVertexStride(mesh, channelIndex);
                var meshChannelOffset = new VFXExpressionMeshChannelOffset(mesh, channelIndex);

                var           outputType = GetOutputType(vertexAttribute);
                VFXExpression sampled    = null;

                var meshChannelFormatAndDimension = new VFXExpressionMeshChannelInfos(mesh, channelIndex);
                var vertexOffset = vertexIndex * meshVertexStride + meshChannelOffset;

                if (!skinnedMesh)
                {
                    if (vertexAttribute == VertexAttribute.Color)
                    {
                        sampled = new VFXExpressionSampleMeshColor(source, vertexOffset, meshChannelFormatAndDimension);
                    }
                    else if (outputType == typeof(float))
                    {
                        sampled = new VFXExpressionSampleMeshFloat(source, vertexOffset, meshChannelFormatAndDimension);
                    }
                    else if (outputType == typeof(Vector2))
                    {
                        sampled = new VFXExpressionSampleMeshFloat2(source, vertexOffset, meshChannelFormatAndDimension);
                    }
                    else if (outputType == typeof(Vector3))
                    {
                        sampled = new VFXExpressionSampleMeshFloat3(source, vertexOffset, meshChannelFormatAndDimension);
                    }
                    else
                    {
                        sampled = new VFXExpressionSampleMeshFloat4(source, vertexOffset, meshChannelFormatAndDimension);
                    }
                }
                else
                {
                    if (vertexAttribute == VertexAttribute.Color)
                    {
                        sampled = new VFXExpressionSampleSkinnedMeshRendererColor(source, vertexOffset, meshChannelFormatAndDimension);
                    }
                    else if (outputType == typeof(float))
                    {
                        sampled = new VFXExpressionSampleSkinnedMeshRendererFloat(source, vertexOffset, meshChannelFormatAndDimension);
                    }
                    else if (outputType == typeof(Vector2))
                    {
                        sampled = new VFXExpressionSampleSkinnedMeshRendererFloat2(source, vertexOffset, meshChannelFormatAndDimension);
                    }
                    else if (outputType == typeof(Vector3))
                    {
                        sampled = new VFXExpressionSampleSkinnedMeshRendererFloat3(source, vertexOffset, meshChannelFormatAndDimension);
                    }
                    else
                    {
                        sampled = new VFXExpressionSampleSkinnedMeshRendererFloat4(source, vertexOffset, meshChannelFormatAndDimension);
                    }
                }

                yield return(sampled);
            }
        }