|
|
@ -3,7 +3,7 @@ using UnityEngine.Experimental.Rendering; |
|
|
|
|
|
|
|
|
namespace FidelityFX.FrameGen |
|
|
namespace FidelityFX.FrameGen |
|
|
{ |
|
|
{ |
|
|
internal class OpticalFlowResources |
|
|
|
|
|
|
|
|
internal class OpticalFlowResources: FfxResourcesBase |
|
|
{ |
|
|
{ |
|
|
public readonly RenderTexture[][] OpticalFlowInputLevels = |
|
|
public readonly RenderTexture[][] OpticalFlowInputLevels = |
|
|
{ |
|
|
{ |
|
|
@ -36,11 +36,6 @@ namespace FidelityFX.FrameGen |
|
|
Vector2Int opticalFlowInputTextureSize = contextDescription.resolution; |
|
|
Vector2Int opticalFlowInputTextureSize = contextDescription.resolution; |
|
|
Vector2Int opticalFlowTextureSize = OpticalFlow.GetOpticalFlowTextureSize(contextDescription.resolution, OpticalFlow.MinBlockSize); |
|
|
Vector2Int opticalFlowTextureSize = OpticalFlow.GetOpticalFlowTextureSize(contextDescription.resolution, OpticalFlow.MinBlockSize); |
|
|
|
|
|
|
|
|
// TODO: this seems useless, delete unless something comes up
|
|
|
|
|
|
Vector2Int opticalFlowHistogramTextureSize = OpticalFlow.GetOpticalFlowHistogramSize(0); |
|
|
|
|
|
Vector2Int globalMotionSearchMaxDispatchSize = OpticalFlow.GetGlobalMotionSearchDispatchSize(0); |
|
|
|
|
|
int globalMotionSearchTextureWidth = 4 + (globalMotionSearchMaxDispatchSize.x * globalMotionSearchMaxDispatchSize.y); |
|
|
|
|
|
|
|
|
|
|
|
for (int level = 0; level < OpticalFlow.OpticalFlowMaxPyramidLevels; ++level) |
|
|
for (int level = 0; level < OpticalFlow.OpticalFlowMaxPyramidLevels; ++level) |
|
|
{ |
|
|
{ |
|
|
CreateDoubleBufferedResource(OpticalFlowInputLevels[level], $"OPTICALFLOW_OpticalFlowInputLevel{level}-", opticalFlowInputTextureSize, GraphicsFormat.R8_UInt); |
|
|
CreateDoubleBufferedResource(OpticalFlowInputLevels[level], $"OPTICALFLOW_OpticalFlowInputLevel{level}-", opticalFlowInputTextureSize, GraphicsFormat.R8_UInt); |
|
|
@ -77,36 +72,5 @@ namespace FidelityFX.FrameGen |
|
|
{ |
|
|
{ |
|
|
return (x + (y - 1)) & ~(y - 1); |
|
|
return (x + (y - 1)) & ~(y - 1); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
private static RenderTexture CreateResource(string name, Vector2Int size, GraphicsFormat format) |
|
|
|
|
|
{ |
|
|
|
|
|
var rt = new RenderTexture(size.x, size.y, 0, format) { name = name, enableRandomWrite = true }; |
|
|
|
|
|
rt.Create(); |
|
|
|
|
|
return rt; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private static void CreateDoubleBufferedResource(RenderTexture[] resource, string name, Vector2Int size, GraphicsFormat format) |
|
|
|
|
|
{ |
|
|
|
|
|
for (int i = 0; i < 2; ++i) |
|
|
|
|
|
{ |
|
|
|
|
|
resource[i] = new RenderTexture(size.x, size.y, 0, format) { name = name + (i + 1), enableRandomWrite = true }; |
|
|
|
|
|
resource[i].Create(); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private static void DestroyResource(ref RenderTexture resource) |
|
|
|
|
|
{ |
|
|
|
|
|
if (resource == null) |
|
|
|
|
|
return; |
|
|
|
|
|
|
|
|
|
|
|
resource.Release(); |
|
|
|
|
|
resource = null; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private static void DestroyResource(RenderTexture[] resource) |
|
|
|
|
|
{ |
|
|
|
|
|
for (int i = 0; i < resource.Length; ++i) |
|
|
|
|
|
DestroyResource(ref resource[i]); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |