tags: unity
The Smoothstep in unity and unity shaderlab is not the same thing. Essence So record it
public float Lerp(float a, float b, float value)
{
if(value <= 1 && value >= 0)
{
return a * (1 - value) + b * value;
}
else if(value < 0)
{
return a;
}
else
{
return b;
}
}
public float InverseLerp(float a, float b, float value)
{
if (a != b)
return Mathf.Clamp01((value - a) / (b - a));
else
return 0.0f;
}
float SmoothStep(float a, float b, float value)
{
if(value <= 1 && value >= 0)
{
value = value * value * (3 - 2 * value);
return a * (1 - value) + b * value;
}
else if(value < 0)
{
return a;
}
else
{
return b;
}
}
float SmoothStep(float a, float b, float x)
{
x = clamp((x - a) / (b- a), 0,1);
return x * x * (3 - 2 * x);
}
public static float SmoothDamp(float current, float target, ref float currentVelocity, float smoothTime, [DefaultValue("Mathf.Infinity")] float maxSpeed, [DefaultValue("Time.deltaTime")] float deltaTime)
{
smoothTime = Mathf.Max(0.0001f, smoothTime);
float num = 2f / smoothTime;
float num2 = num * deltaTime;
float num3 = 1f / (1f + num2 + 0.48f * num2 * num2 + 0.235f * num2 * num2 * num2);
float num4 = current - target;
float num5 = target;
float num6 = maxSpeed * smoothTime;
num4 = Mathf.Clamp(num4, -num6, num6);
target = current - num4;
float num7 = (currentVelocity + num * num4) * deltaTime;
currentVelocity = (currentVelocity - num * num7) * num3;
float num8 = target + (num4 + num7) * num3;
if (num5 - current > 0f == num8 > num5)
{
num8 = num5;
currentVelocity = (num8 - num5) / deltaTime;
}
return num8;
}
Interpolated this thing, for many newcomers, just stay in the stage of use, know when to use, but the operation mechanism is not very understandable. Recently, many newcomers have such an idea: have a...
The mathf.lerp function is used between two values for interpolation for smooth transition. VAR interpolation result = mathf.lerp (from, to, rate) // rate is the value of 0 ~ 1 Unity does not provid...
Lerp, is returned interpolation between two values, generally have three parameters. Returns to the initial value of a parameter, the second parameter is the final value, the interpolation is a floati...
In the Unity, the Lerp function can achieve the easing effect. using UnityEngine; using System.Collections; public class test : MonoBehaviour { } If Lerp (from (start), to (end), value), then How the ...
1. Unity interpolation function Lerp() Briefly understand the interpolation function through the official documentation (https://docs.unity3d.com/ScriptReference/index.html), you can see that there ar...
SmoothDamp smooth buffer movement, mostly used for camera movement Lerp, each move is n% of the remaining distance to the target point Where t is the percentage of the remaining distance, Lerp can mov...
Write in front Unity’s Lerp and SmoothDamp are commonly used in scenes such as object movement, some gradual changes, or camera following. Although Mathf, Vector2, Vector3, etc. have these two f...
Unity uses LERP to move uniform speed Using the LERP difference, the third parameter in the LERP is actually the percentage of two value differences, so if you use a fixed value directly, it will lead...