protected override void CalculateFactor() { // Factor _factor = VFXValue.Constant(15.0f) / (VFXValue.Constant(Mathf.PI) * _kernelSize6); }
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) }) }); }
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) { 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) }); } }
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 void CalculateFactor() { _factor = VFXValue.Constant(315.0f) / (VFXValue.Constant(64.0f) * VFXValue.Constant(Mathf.PI) * _kernelSize9); }
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[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) { VFXExpression lineDelta = (inputExpression[1] - inputExpression[0]); VFXExpression lineLength = new VFXExpressionMax(VFXOperatorUtility.Dot(lineDelta, lineDelta), VFXValue.Constant(Mathf.Epsilon)); VFXExpression t = VFXOperatorUtility.Dot(inputExpression[2] - inputExpression[0], lineDelta); t = VFXOperatorUtility.Clamp(t / lineLength, VFXValue.Constant(0.0f), VFXValue.Constant(1.0f)); VFXExpression pointOnLine = (inputExpression[0] + VFXOperatorUtility.CastFloat(t, lineDelta.valueType) * lineDelta); VFXExpression lineDistance = VFXOperatorUtility.Distance(inputExpression[2], pointOnLine); return(new VFXExpression[] { pointOnLine, lineDistance }); }
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); } }
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 t = new VFXExpressionSharedRandom(inputExpression[1] * VFXValue.Constant(2u) + VFXValue.Constant(1u)) * VFXValue.Constant(Mathf.PI * 2); var z = new VFXExpressionSharedRandom(inputExpression[1] * VFXValue.Constant(2u)) * VFXValue.Constant(2.0f) - VFXValue.Constant(1.0f); var w = VFXOperatorUtility.Sqrt(VFXValue.Constant(1.0f) - z * z); return(new[] { new VFXExpressionCombine(new VFXExpressionCos(t) * w, new VFXExpressionSin(t) * w, z) * VFXOperatorUtility.CastFloat(inputExpression[0], VFXValueType.Float3) }); }
protected override sealed VFXExpression[] BuildExpression(VFXExpression[] inputExpression) { // UpdateSolverTexture(true); // KernelSize: x - h, y - h^2, z - h^3, w - simulation scale // KernelFactors: x - poly6, y - spiky, z - viscosity, w - unused VFXExpression h = inputExpression[0]; VFXExpression simulationScale = inputExpression[1]; var poly6 = new Poly6Kernel(h); var spiky = new SpikyKernel(h); var viscosity = new ViscosityKernel(h); return(new VFXExpression[] { new VFXExpressionCombine(new [] { h, h * h, h * h * h, simulationScale }), new VFXExpressionCombine(new [] { poly6.GetFactor(), spiky.GetFactor(), viscosity.GetFactor(), VFXValue.Constant(0.0f) }), new VFXTexture2DValue(FluvioSolverData ? FluvioSolverData : null), new VFXExpressionCombine(new [] { VFXValue.Constant((float)(FluvioSolverData? FluvioSolverData.width : 0)), VFXValue.Constant((float)(FluvioSolverData ? FluvioSolverData.height : 0)) }), }); }
protected override IEnumerable <VFXNamedExpression> CollectGPUExpressions(IEnumerable <VFXNamedExpression> slotExpressions) { foreach (var exp in base.CollectGPUExpressions(slotExpressions)) { yield return(exp); } if (GetOrRefreshShaderGraphObject() == null) { yield return(slotExpressions.First(o => o.name == "smoothness")); switch (materialType) { case MaterialType.Standard: case MaterialType.SimpleLit: yield return(slotExpressions.First(o => o.name == "metallic")); break; case MaterialType.SpecularColor: yield return(slotExpressions.First(o => o.name == "specularColor")); break; case MaterialType.Translucent: case MaterialType.SimpleLitTranslucent: { yield return(slotExpressions.First(o => o.name == "thickness")); uint diffusionProfileHash = (diffusionProfileAsset?.profile != null) ? diffusionProfileAsset.profile.hash : 0; yield return(new VFXNamedExpression(VFXValue.Constant(diffusionProfileHash), "diffusionProfileHash")); break; } default: break; } if (allowTextures) { if (useBaseColorMap != BaseColorMapMode.None) { yield return(slotExpressions.First(o => o.name == "baseColorMap")); } if (useMaskMap) { yield return(slotExpressions.First(o => o.name == "maskMap")); } if (useNormalMap) { yield return(slotExpressions.First(o => o.name == "normalMap")); yield return(slotExpressions.First(o => o.name == "normalScale")); } if (useEmissiveMap) { yield return(slotExpressions.First(o => o.name == "emissiveMap")); yield return(slotExpressions.First(o => o.name == "emissiveScale")); } } if ((colorMode & ColorMode.BaseColor) == 0) { yield return(slotExpressions.First(o => o.name == "baseColor")); } if (((colorMode & ColorMode.Emissive) == 0) && useEmissive) { yield return(slotExpressions.First(o => o.name == "emissiveColor")); } } }
protected override sealed VFXExpression[] BuildExpression(VFXExpression[] inputExpression) { VFXExpression inverseTRS = new VFXExpressionInverseTRSMatrix(inputExpression[1]); VFXExpression scale = new VFXExpressionExtractScaleFromMatrix(inputExpression[1]); VFXExpression uvw = new VFXExpressionTransformPosition(inverseTRS, inputExpression[2]) + VFXValue.Constant(new Vector3(0.5f, 0.5f, 0.5f)); VFXExpression distanceExpr = new VFXExpressionSampleSDF(inputExpression[0], uvw, scale, inputExpression[3]); VFXExpression directionExpr = new VFXExpressionSampleSDFNormal(inputExpression[0], inverseTRS, uvw, inputExpression[3]) * VFXValue.Constant(new Vector3(-1.0f, -1.0f, -1.0f)); return(new[] { distanceExpr, directionExpr }); }