summaryrefslogtreecommitdiff
path: root/Thronefall_1_57/Decompile/FlatKit/BlitTexturePass.cs
diff options
context:
space:
mode:
authorchai <215380520@qq.com>2024-05-19 16:05:58 +0800
committerchai <215380520@qq.com>2024-05-19 16:05:58 +0800
commit8e13e7e2874adc8982e16d1d2ed2e28d7480b45f (patch)
tree63ef85c460288891f5a593d69afeca16cba050b3 /Thronefall_1_57/Decompile/FlatKit/BlitTexturePass.cs
parentc5f145786f4c6d2fe4bea831dfc16e52228920a5 (diff)
+1.57
Diffstat (limited to 'Thronefall_1_57/Decompile/FlatKit/BlitTexturePass.cs')
-rw-r--r--Thronefall_1_57/Decompile/FlatKit/BlitTexturePass.cs80
1 files changed, 80 insertions, 0 deletions
diff --git a/Thronefall_1_57/Decompile/FlatKit/BlitTexturePass.cs b/Thronefall_1_57/Decompile/FlatKit/BlitTexturePass.cs
new file mode 100644
index 0000000..5b9e754
--- /dev/null
+++ b/Thronefall_1_57/Decompile/FlatKit/BlitTexturePass.cs
@@ -0,0 +1,80 @@
+using UnityEngine;
+using UnityEngine.Rendering;
+using UnityEngine.Rendering.Universal;
+
+namespace FlatKit;
+
+internal class BlitTexturePass : ScriptableRenderPass
+{
+ public static readonly string CopyEffectShaderName = "Hidden/FlatKit/CopyTexture";
+
+ private ProfilingSampler _profilingSampler;
+
+ private Material _effectMaterial;
+
+ private Material _copyMaterial;
+
+ private RenderTargetHandle _temporaryColorTexture;
+
+ public void Setup(Material effectMaterial, bool useDepth, bool useNormals, bool useColor)
+ {
+ _effectMaterial = effectMaterial;
+ string text = effectMaterial.name.Substring(effectMaterial.name.LastIndexOf('/') + 1);
+ _profilingSampler = new ProfilingSampler("Blit " + text);
+ _copyMaterial = CoreUtils.CreateEngineMaterial(CopyEffectShaderName);
+ ConfigureInput((useColor ? ScriptableRenderPassInput.Color : ScriptableRenderPassInput.None) | (useDepth ? ScriptableRenderPassInput.Depth : ScriptableRenderPassInput.None) | (useNormals ? ScriptableRenderPassInput.Normal : ScriptableRenderPassInput.None));
+ }
+
+ public override void OnCameraSetup(CommandBuffer cmd, ref RenderingData renderingData)
+ {
+ ConfigureTarget(new RenderTargetIdentifier(renderingData.cameraData.renderer.cameraColorTarget, 0, CubemapFace.Unknown, -1));
+ }
+
+ public override void Execute(ScriptableRenderContext context, ref RenderingData renderingData)
+ {
+ if (_effectMaterial == null || renderingData.cameraData.camera.cameraType != CameraType.Game)
+ {
+ return;
+ }
+ _temporaryColorTexture = default(RenderTargetHandle);
+ CommandBuffer commandBuffer = CommandBufferPool.Get();
+ using (new ProfilingScope(commandBuffer, _profilingSampler))
+ {
+ RenderTextureDescriptor cameraTargetDescriptor = renderingData.cameraData.cameraTargetDescriptor;
+ cameraTargetDescriptor.depthBufferBits = 0;
+ SetSourceSize(commandBuffer, cameraTargetDescriptor);
+ RTHandle cameraColorTargetHandle = renderingData.cameraData.renderer.cameraColorTargetHandle;
+ commandBuffer.GetTemporaryRT(_temporaryColorTexture.id, cameraTargetDescriptor);
+ if (renderingData.cameraData.xrRendering)
+ {
+ _effectMaterial.EnableKeyword("_USE_DRAW_PROCEDURAL");
+ commandBuffer.SetRenderTarget(_temporaryColorTexture.Identifier());
+ commandBuffer.DrawMesh(RenderingUtils.fullscreenMesh, Matrix4x4.identity, _effectMaterial, 0, 0);
+ commandBuffer.SetGlobalTexture("_EffectTexture", _temporaryColorTexture.Identifier());
+ commandBuffer.SetRenderTarget(new RenderTargetIdentifier(cameraColorTargetHandle, 0, CubemapFace.Unknown, -1));
+ commandBuffer.DrawMesh(RenderingUtils.fullscreenMesh, Matrix4x4.identity, _copyMaterial, 0, 0);
+ }
+ else
+ {
+ _effectMaterial.DisableKeyword("_USE_DRAW_PROCEDURAL");
+ commandBuffer.Blit(cameraColorTargetHandle, _temporaryColorTexture.Identifier(), _effectMaterial, 0);
+ commandBuffer.Blit(_temporaryColorTexture.Identifier(), cameraColorTargetHandle);
+ }
+ }
+ context.ExecuteCommandBuffer(commandBuffer);
+ commandBuffer.Clear();
+ CommandBufferPool.Release(commandBuffer);
+ }
+
+ private static void SetSourceSize(CommandBuffer cmd, RenderTextureDescriptor desc)
+ {
+ float num = desc.width;
+ float num2 = desc.height;
+ if (desc.useDynamicScale)
+ {
+ num *= ScalableBufferManager.widthScaleFactor;
+ num2 *= ScalableBufferManager.heightScaleFactor;
+ }
+ cmd.SetGlobalVector("_SourceSize", new Vector4(num, num2, 1f / num, 1f / num2));
+ }
+}