阶段性完成
This commit is contained in:
@@ -0,0 +1,73 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.Rendering;
|
||||
|
||||
namespace LeTai.Asset.TranslucentImage
|
||||
{
|
||||
public static class BlurExecutor
|
||||
{
|
||||
static readonly int[] TEMP_RT = new int[14];
|
||||
|
||||
static BlurExecutor()
|
||||
{
|
||||
for (var i = 0; i < TEMP_RT.Length; i++)
|
||||
{
|
||||
TEMP_RT[i] = Shader.PropertyToID($"TI_intermediate_rt_{i}");
|
||||
}
|
||||
}
|
||||
|
||||
public readonly struct BlurExecutionData
|
||||
{
|
||||
public readonly RenderTargetIdentifier sourceTex;
|
||||
public readonly TranslucentImageSource blurSource;
|
||||
public readonly IBlurAlgorithm blurAlgorithm;
|
||||
|
||||
public BlurExecutionData(
|
||||
RenderTargetIdentifier sourceTex,
|
||||
TranslucentImageSource blurSource,
|
||||
IBlurAlgorithm blurAlgorithm
|
||||
)
|
||||
{
|
||||
this.sourceTex = sourceTex;
|
||||
this.blurSource = blurSource;
|
||||
this.blurAlgorithm = blurAlgorithm;
|
||||
}
|
||||
}
|
||||
|
||||
public static void ExecuteBlurWithTempTextures(CommandBuffer cmd, ref BlurExecutionData data)
|
||||
{
|
||||
var desc = data.blurSource.BlurredScreen.descriptor;
|
||||
desc.msaaSamples = 1;
|
||||
desc.useMipMap = false;
|
||||
desc.depthBufferBits = 0;
|
||||
|
||||
var cropRegionSize = data.blurSource.BlurRegion.size;
|
||||
var scratchesCount = data.blurAlgorithm.GetScratchesCount(desc.width / cropRegionSize.x,
|
||||
desc.height / cropRegionSize.y);
|
||||
for (int i = 0; i < scratchesCount; i++)
|
||||
{
|
||||
data.blurAlgorithm.GetNextScratchDescriptor(ref desc);
|
||||
cmd.GetTemporaryRT(TEMP_RT[i], desc, FilterMode.Bilinear);
|
||||
data.blurAlgorithm.SetScratch(i, TEMP_RT[i]);
|
||||
}
|
||||
|
||||
{
|
||||
ExecuteBlur(cmd, ref data);
|
||||
}
|
||||
|
||||
for (int i = 0; i < scratchesCount; i++)
|
||||
cmd.ReleaseTemporaryRT(TEMP_RT[i]);
|
||||
}
|
||||
|
||||
public static void ExecuteBlur(CommandBuffer cmd, ref BlurExecutionData data)
|
||||
{
|
||||
var blurSource = data.blurSource;
|
||||
|
||||
data.blurAlgorithm.Blur(cmd,
|
||||
data.sourceTex,
|
||||
blurSource.BlurRegion,
|
||||
blurSource.ActiveRegion,
|
||||
blurSource.BackgroundFill,
|
||||
blurSource.BlurredScreen);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user