protected override sealed VFXExpression[] BuildExpression(VFXExpression[] inputExpression) { if (mask.Length == 0) { return new VFXExpression[] { } } ; var inputComponents = (inputExpression.Length > 0) ? VFXOperatorUtility.ExtractComponents(inputExpression[0]).ToArray() : new VFXExpression[0]; var componentStack = new Stack <VFXExpression>(); int outputSize = mask.Length; for (int iComponent = 0; iComponent < outputSize; iComponent++) { char componentChar = char.ToLower(mask[iComponent]); int currentComponent = Math.Min(CharToComponentIndex(componentChar), inputComponents.Length - 1); componentStack.Push(inputComponents[currentComponent]); } VFXExpression finalExpression = null; if (componentStack.Count == 1) { finalExpression = componentStack.Pop(); } else { finalExpression = new VFXExpressionCombine(componentStack.Reverse().ToArray()); } return(new[] { finalExpression }); } }
protected override sealed VFXExpression[] BuildExpression(VFXExpression[] inputExpression) { var components = VFXOperatorUtility.ExtractComponents(inputExpression[0]); VFXExpression rgb = new VFXExpressionCombine(components.Take(3).ToArray()); return(new[] { new VFXExpressionRGBtoHSV(rgb) }); }
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 }); }
protected override sealed VFXExpression[] BuildExpression(VFXExpression[] inputExpression) { var location = new VFXExpressionCombine( new VFXExpressionCastUintToFloat(inputExpression[1]), new VFXExpressionCastUintToFloat(inputExpression[2])); return(new[] { new VFXExpressionLoadCameraBuffer(inputExpression[0], location) }); }
protected override sealed VFXExpression[] BuildExpression(VFXExpression[] inputExpression) { var location = new VFXExpressionCombine( new VFXExpressionCastUintToFloat(inputExpression[1]), new VFXExpressionCastUintToFloat(inputExpression[2]), new VFXExpressionCastUintToFloat(inputExpression[3]), new VFXExpressionCastUintToFloat(inputExpression[4])); return(new[] { new VFXExpressionLoadTexture2DArray(inputExpression[0], location) }); }
VFXExpression AngleFadeSimplification(VFXExpression angleFadeExp) { angleFadeExp = angleFadeExp / VFXValue.Constant(new Vector2(180.0f, 180.0f)); var angleStart = new VFXExpressionExtractComponent(angleFadeExp, 0); var angleEnd = new VFXExpressionExtractComponent(angleFadeExp, 1); var range = new VFXExpressionMax(VFXValue.Constant(0.0001f), angleEnd - angleStart); var simplifiedAngleFade = new VFXExpressionCombine( VFXValue.Constant(1.0f) - (VFXValue.Constant(0.25f) - angleStart) / range, VFXValue.Constant(-0.25f) / range); return(simplifiedAngleFade); }
protected override sealed VFXExpression[] BuildExpression(VFXExpression[] inputExpression) { VFXExpression parameters = new VFXExpressionCombine(inputExpression[1], inputExpression[2], inputExpression[4]); if (type == NoiseType.Curl) { if (curlDimensions == CurlDimensionCount.Two) { return(new[] { new VFXExpressionPerlinCurlNoise2D(inputExpression[0], parameters, inputExpression[3]) }); } else { return(new[] { new VFXExpressionPerlinCurlNoise3D(inputExpression[0], parameters, inputExpression[3]) }); } } else { VFXExpression rangeMultiplier = (inputExpression[5].y - inputExpression[5].x); if (dimensions == DimensionCount.One) { VFXExpression noise = new VFXExpressionPerlinNoise1D(inputExpression[0], parameters, inputExpression[3]); VFXExpression x = VFXOperatorUtility.Fit(noise.x, VFXValue.Constant(0.0f), VFXValue.Constant(1.0f), inputExpression[5].x, inputExpression[5].y); VFXExpression y = noise.y * rangeMultiplier; return(new[] { x, y }); } else if (dimensions == DimensionCount.Two) { VFXExpression noise = new VFXExpressionPerlinNoise2D(inputExpression[0], parameters, inputExpression[3]); VFXExpression x = VFXOperatorUtility.Fit(noise.x, VFXValue.Constant(0.0f), VFXValue.Constant(1.0f), inputExpression[5].x, inputExpression[5].y); VFXExpression y = noise.y * rangeMultiplier; VFXExpression z = noise.z * rangeMultiplier; return(new[] { x, new VFXExpressionCombine(y, z) }); } else { VFXExpression noise = new VFXExpressionPerlinNoise3D(inputExpression[0], parameters, inputExpression[3]); VFXExpression x = VFXOperatorUtility.Fit(noise.x, VFXValue.Constant(0.0f), VFXValue.Constant(1.0f), inputExpression[5].x, inputExpression[5].y); VFXExpression y = noise.y * rangeMultiplier; VFXExpression z = noise.z * rangeMultiplier; VFXExpression w = noise.w * rangeMultiplier; return(new[] { x, new VFXExpressionCombine(y, z, w) }); } } }
protected override sealed VFXExpression[] BuildExpression(VFXExpression[] inputExpression) { var mask = new Component[4] { x, y, z, w }; // var mask = new Component[4] { Component.X, Component.Y, Component.Z, Component.W }; int maskSize = 4; while (maskSize > 1 && mask[maskSize - 1] == Component.None) { --maskSize; } var inputComponents = VFXOperatorUtility.ExtractComponents(inputExpression[0]).ToArray(); var componentStack = new Stack <VFXExpression>(); int outputSize = GetMaskSize(mask); for (int iComponent = 0; iComponent < outputSize; iComponent++) { Component currentComponent = mask[iComponent]; if (currentComponent != Component.None && (int)currentComponent < inputComponents.Length) { componentStack.Push(inputComponents[(int)currentComponent]); } else { componentStack.Push(VFXValue <float> .Default); } } VFXExpression finalExpression = null; if (componentStack.Count == 1) { finalExpression = componentStack.Pop(); } else { finalExpression = new VFXExpressionCombine(componentStack.Reverse().ToArray()); } return(new[] { finalExpression }); }
protected override sealed VFXExpression[] BuildExpression(VFXExpression[] inputExpression) { VFXExpression parameters = new VFXExpressionCombine(inputExpression[1], inputExpression[2], inputExpression[4]); if (dimensions == DimensionCount.One) { return new[] { new VFXExpressionValueNoise1D(inputExpression[0], parameters, inputExpression[3]) } } ; else if (dimensions == DimensionCount.Two) { return new[] { new VFXExpressionValueNoise2D(inputExpression[0], parameters, inputExpression[3]) } } ; else { return new[] { new VFXExpressionValueNoise3D(inputExpression[0], parameters, inputExpression[3]) } }; } }
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) }); }
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) }); } }
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); // renormalize XY from viewport position [0, 1] to clip position [-1, 1] VFXExpression viewportPosExpression = inputExpression[0]; VFXExpression oneExpression = VFXValue.Constant(1.0f); VFXExpression twoExpression = VFXValue.Constant(2.0f); VFXExpression clipPosExpression = new VFXExpressionCombine(viewportPosExpression.x * twoExpression - oneExpression, viewportPosExpression.y * twoExpression - oneExpression, oneExpression, oneExpression); // result = clipPos * ClipToView * ViewToVFX VFXExpression viewPosExpression = new VFXExpressionTransformVector4(matricesExpressions.ClipToView.exp, clipPosExpression); viewPosExpression = new VFXExpressionCombine(viewPosExpression.x, viewPosExpression.y, viewPosExpression.z) * viewportPosExpression.zzz; VFXExpression positionExpression = new VFXExpressionTransformPosition(matricesExpressions.ViewToVFX.exp, viewPosExpression); return(new VFXExpression[] { positionExpression }); }
private static IEnumerable <VFXNamedExpression> GetExpressionsImpl( InitializeSolver initializeBlock, SolverDataParameters solverDataParams, IEnumerable <VFXNamedExpression> fluid, VFXExpression h, VFXExpression mass, VFXExpression density, VFXExpression gravity) { // Fluid if (fluid == null || h == null || mass == null || density == null) { var defaultFluid = Fluid.defaultValue; h = VFXValue.Constant(defaultFluid.SmoothingDistance); if (solverDataParams.HasFlag(SolverDataParameters.Fluid_ParticleMass)) { yield return(new VFXNamedExpression( GetParticleMass( initializeBlock, h, VFXValue.Constant(defaultFluid.ParticleMass), VFXValue.Constant(defaultFluid.Density) ), "solverData_Fluid_ParticleMass")); } if (solverDataParams.HasFlag(SolverDataParameters.Fluid_Density)) { yield return(new VFXNamedExpression( VFXValue.Constant(defaultFluid.Density), "solverData_Fluid_Density")); } if (solverDataParams.HasFlag(SolverDataParameters.Fluid_MinimumDensity)) { yield return(new VFXNamedExpression( VFXValue.Constant(defaultFluid.MinimumDensity), "solverData_Fluid_MinimumDensity")); } if (solverDataParams.HasFlag(SolverDataParameters.Fluid_GasConstant)) { yield return(new VFXNamedExpression( VFXValue.Constant(defaultFluid.GasConstant), "solverData_Fluid_GasConstant")); } if (solverDataParams.HasFlag(SolverDataParameters.Fluid_Viscosity)) { yield return(new VFXNamedExpression( VFXValue.Constant(defaultFluid.Viscosity), "solverData_Fluid_Viscosity")); } if (solverDataParams.HasFlag(SolverDataParameters.Fluid_SurfaceTension)) { yield return(new VFXNamedExpression( VFXValue.Constant(defaultFluid.SurfaceTension), "solverData_Fluid_SurfaceTension")); } if (solverDataParams.HasFlag(SolverDataParameters.Fluid_BuoyancyCoefficient)) { yield return(new VFXNamedExpression( VFXValue.Constant(defaultFluid.BuoyancyCoefficient), "solverData_Fluid_BuoyancyCoefficient")); } } else { foreach (var expression in fluid) { if (Enum.TryParse(expression.name, out SolverDataParameters solverDataParameter) && solverDataParams.HasFlag(solverDataParameter)) { if (solverDataParameter == SolverDataParameters.Fluid_ParticleMass) { yield return(new VFXNamedExpression( GetParticleMass(initializeBlock, h, mass, density), "solverData_Fluid_ParticleMass")); continue; } yield return(new VFXNamedExpression(expression.exp, $"solverData_{expression.name}")); } } ; } // KernelSize: x - h, y - h^2, z - h^3, w - h / 2 if (solverDataParams.HasFlag(SolverDataParameters.KernelSize)) { yield return(new VFXNamedExpression(new VFXExpressionCombine(new [] { h, h * h, h * h * h, h * VFXValue.Constant(0.5f), }), "solverData_KernelSize")); } // KernelFactors: x - poly6, y - spiky, z - viscosity if (solverDataParams.HasFlag(SolverDataParameters.KernelFactors)) { var poly6 = new Poly6Kernel(h); var spiky = new SpikyKernel(h); var viscosity = new ViscosityKernel(h); yield return(new VFXNamedExpression(new VFXExpressionCombine(new [] { poly6.GetFactor(), spiky.GetFactor(), viscosity.GetFactor() }), "solverData_KernelFactors")); } // Gravity if (solverDataParams.HasFlag(SolverDataParameters.Gravity)) { if (gravity == null) { gravity = new VFXExpressionCombine(new [] { VFXValue.Constant(0.0f), VFXValue.Constant(-9.81f), VFXValue.Constant(0.0f), }); } yield return(new VFXNamedExpression(gravity, "solverData_Gravity")); } }
protected override sealed VFXExpression[] BuildExpression(VFXExpression[] inputExpression) { VFXExpression parameters = new VFXExpressionCombine(inputExpression[2], inputExpression[3], inputExpression[4]); return(new[] { new VFXExpressionVoroNoise2D(inputExpression[0], parameters) * inputExpression[1] }); }
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); } }
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) }); } }
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()); }