You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
52 lines
1.7 KiB
52 lines
1.7 KiB
using UnityEngine;
|
|
|
|
namespace FidelityFX
|
|
{
|
|
public static class FfxUtils
|
|
{
|
|
public static float GetMipmapBiasOffset(int renderWidth, int displayWidth)
|
|
{
|
|
return Mathf.Log((float)renderWidth / displayWidth, 2.0f) - 1.0f;
|
|
}
|
|
|
|
public static int GetJitterPhaseCount(int renderWidth, int displayWidth)
|
|
{
|
|
const float basePhaseCount = 8.0f;
|
|
int jitterPhaseCount = (int)(basePhaseCount * Mathf.Pow((float)displayWidth / renderWidth, 2.0f));
|
|
return jitterPhaseCount;
|
|
}
|
|
|
|
public static void GetJitterOffset(out float outX, out float outY, int index, int phaseCount)
|
|
{
|
|
outX = Halton((index % phaseCount) + 1, 2) - 0.5f;
|
|
outY = Halton((index % phaseCount) + 1, 3) - 0.5f;
|
|
}
|
|
|
|
// Calculate halton number for index and base.
|
|
private static float Halton(int index, int @base)
|
|
{
|
|
float f = 1.0f, result = 0.0f;
|
|
|
|
for (int currentIndex = index; currentIndex > 0;) {
|
|
|
|
f /= @base;
|
|
result += f * (currentIndex % @base);
|
|
currentIndex = (int)Mathf.Floor((float)currentIndex / @base);
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
public static float Lanczos2(float value)
|
|
{
|
|
return Mathf.Abs(value) < Mathf.Epsilon ? 1.0f : Mathf.Sin(Mathf.PI * value) / (Mathf.PI * value) * (Mathf.Sin(0.5f * Mathf.PI * value) / (0.5f * Mathf.PI * value));
|
|
}
|
|
|
|
#if !UNITY_2021_1_OR_NEWER
|
|
internal static void SetBufferData(this CommandBuffer commandBuffer, ComputeBuffer computeBuffer, Array data)
|
|
{
|
|
commandBuffer.SetComputeBufferData(computeBuffer, data);
|
|
}
|
|
#endif
|
|
}
|
|
}
|