diff --git a/Assets/Scripts/Fsr2Context.cs b/Assets/Scripts/Fsr2Context.cs index 789b800..89e147d 100644 --- a/Assets/Scripts/Fsr2Context.cs +++ b/Assets/Scripts/Fsr2Context.cs @@ -110,12 +110,13 @@ namespace FidelityFX if (_firstExecution) { - // TODO: clear values + _commandBuffer.SetRenderTarget(_resources.LockStatus[0]); + _commandBuffer.ClearRenderTarget(false, true, Color.clear); + _commandBuffer.SetRenderTarget(_resources.LockStatus[1]); + _commandBuffer.ClearRenderTarget(false, true, Color.clear); } - // TODO: setup resource indices for buffers that get swapped per frame int frameIndex = _resourceFrameIndex % 2; - bool resetAccumulation = dispatchParams.Reset || _firstExecution; _firstExecution = false; @@ -132,12 +133,21 @@ namespace FidelityFX int dispatchDstX = (_contextDescription.DisplaySize.x + (threadGroupWorkRegionDim - 1)) / threadGroupWorkRegionDim; int dispatchDstY = (_contextDescription.DisplaySize.y + (threadGroupWorkRegionDim - 1)) / threadGroupWorkRegionDim; + // Clear reconstructed depth for max depth store. if (resetAccumulation) { - // TODO: clear reconstructed depth for max depth store - // UnityEngine.RenderTexture.active = myRenderTextureToClear; - // GL.Clear(true, true, Color.clear); // This is a rather bleh solution but apparently it works... - // CommandBuffer: SetRenderTarget, ClearRenderTarget + _commandBuffer.SetRenderTarget(_resources.LockStatus[frameIndex ^ 1]); + _commandBuffer.ClearRenderTarget(false, true, Color.clear); + + _commandBuffer.SetRenderTarget(_resources.InternalUpscaled[frameIndex ^ 1]); + _commandBuffer.ClearRenderTarget(false, true, Color.clear); + + _commandBuffer.SetRenderTarget(_resources.SceneLuminance); + _commandBuffer.ClearRenderTarget(false, true, Color.clear); + + // Auto exposure always used to track luma changes in locking logic + _commandBuffer.SetRenderTarget(_resources.AutoExposure); + _commandBuffer.ClearRenderTarget(false, true, new Color(-1f, 1e8f, 0f, 0f)); } // Auto exposure diff --git a/Assets/Scripts/Fsr2Resources.cs b/Assets/Scripts/Fsr2Resources.cs index 59037c6..c8245be 100644 --- a/Assets/Scripts/Fsr2Resources.cs +++ b/Assets/Scripts/Fsr2Resources.cs @@ -34,12 +34,6 @@ namespace FidelityFX { maximumBias[i] = MaximumBias[i] / 2.0f; } - - // TODO: create resources, i.e. render textures used for intermediate results. - // Note that "aliasable" resources should be equivalent to GetTemporary render textures - // UAVs *may* be an issue with the PS4 not handling simultaneous reading and writing to an RT properly - // Unity does have Graphics.SetRandomWriteTarget for enabling UAV on ComputeBuffers or RTs - // Unity doesn't do 1D textures so just default to Texture2D // Resource FSR2_LanczosLutData: FFX_RESOURCE_USAGE_READ_ONLY, FFX_SURFACE_FORMAT_R16_SNORM, FFX_RESOURCE_FLAGS_NONE // R16_SNorm textures are not supported by Unity on most platforms, strangely enough. So instead we use R16_SFloat and upload pre-normalized float data. @@ -54,16 +48,16 @@ namespace FidelityFX // Resource FSR2_DefaultExposure: FFX_RESOURCE_USAGE_READ_ONLY, FFX_SURFACE_FORMAT_R32G32_FLOAT, FFX_RESOURCE_FLAGS_NONE DefaultExposure = new Texture2D(1, 1, GraphicsFormat.R32G32_SFloat, TextureCreationFlags.None) { name = "FSR2_DefaultExposure" }; - DefaultExposure.SetPixel(0, 0, Color.black); + DefaultExposure.SetPixel(0, 0, Color.clear); DefaultExposure.Apply(); // Resource FSR2_DefaultReactivityMask: FFX_RESOURCE_USAGE_READ_ONLY, FFX_SURFACE_FORMAT_R8_UNORM, FFX_RESOURCE_FLAGS_NONE DefaultReactive = new Texture2D(1, 1, GraphicsFormat.R8_UNorm, TextureCreationFlags.None) { name = "FSR2_DefaultReactivityMask" }; - DefaultReactive.SetPixel(0, 0, Color.black); + DefaultReactive.SetPixel(0, 0, Color.clear); DefaultReactive.Apply(); // Resource FSR2_AutoExposure: FFX_RESOURCE_USAGE_UAV, FFX_SURFACE_FORMAT_R32G32_FLOAT, FFX_RESOURCE_FLAGS_NONE - AutoExposure = new RenderTexture(1, 1, 1, GraphicsFormat.R32G32_SFloat) { name = "FSR2_AutoExposure", enableRandomWrite = true }; + AutoExposure = new RenderTexture(1, 1, 0, GraphicsFormat.R32G32_SFloat) { name = "FSR2_AutoExposure", enableRandomWrite = true }; AutoExposure.Create(); // Resource FSR2_ExposureMips: FFX_RESOURCE_USAGE_UAV, FFX_SURFACE_FORMAT_R16_FLOAT, FFX_RESOURCE_FLAGS_ALIASABLE @@ -90,7 +84,7 @@ namespace FidelityFX { for (int i = 0; i < 2; ++i) { - resource[i] = new RenderTexture(size.x, size.y, 1, format) { name = name + (i + 1), enableRandomWrite = true }; + resource[i] = new RenderTexture(size.x, size.y, 0, format) { name = name + (i + 1), enableRandomWrite = true }; resource[i].Create(); } }