protected override VFXExpression[] BuildExpression(VFXExpression[] inputExpression) { VFXExpression input; if (Clamp) { input = VFXOperatorUtility.Clamp(inputExpression[0], inputExpression[1], inputExpression[2]); } else { input = inputExpression[0]; } return(new[] { VFXOperatorUtility.Fit(input, inputExpression[1], inputExpression[2], inputExpression[3], inputExpression[4]) }); }
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 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) }); } }
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>()); }
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) { 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) }); } }