Browse Source
Split the FSR3 shaders aggregate class from the scriptable object part. This allows the shader references to be serialized as a single asset still, but also for them to be embedded inline inside of a different scriptable object (for PPV2)
fsr3
Split the FSR3 shaders aggregate class from the scriptable object part. This allows the shader references to be serialized as a single asset still, but also for them to be embedded inline inside of a different scriptable object (for PPV2)
fsr3
8 changed files with 182 additions and 150 deletions
-
23Assets/Fsr3UpscalerAssets.asset
-
0Assets/Fsr3UpscalerAssets.asset.meta
-
2Assets/Scenes/SampleScene.unity
-
151Assets/Scripts/Core/Fsr3UpscalerAssets.cs
-
0Assets/Scripts/Core/Fsr3UpscalerAssets.cs.meta
-
119Assets/Scripts/Core/Fsr3UpscalerShaders.cs
-
15Assets/Scripts/Fsr3UpscalerImageEffect.cs
-
22Assets/Shaders/FSR3/Fsr3UpscalerShaders.asset
@ -0,0 +1,23 @@ |
|||||
|
%YAML 1.1 |
||||
|
%TAG !u! tag:unity3d.com,2011: |
||||
|
--- !u!114 &11400000 |
||||
|
MonoBehaviour: |
||||
|
m_ObjectHideFlags: 0 |
||||
|
m_CorrespondingSourceObject: {fileID: 0} |
||||
|
m_PrefabInstance: {fileID: 0} |
||||
|
m_PrefabAsset: {fileID: 0} |
||||
|
m_GameObject: {fileID: 0} |
||||
|
m_Enabled: 1 |
||||
|
m_EditorHideFlags: 0 |
||||
|
m_Script: {fileID: 11500000, guid: db26e15a33db6ab42a38daab0ba2712f, type: 3} |
||||
|
m_Name: Fsr3UpscalerAssets |
||||
|
m_EditorClassIdentifier: |
||||
|
shaders: |
||||
|
computeLuminancePyramidPass: {fileID: 7200000, guid: d253be05abcdc80428503d3e4cce3a36, type: 3} |
||||
|
reconstructPreviousDepthPass: {fileID: 7200000, guid: 4f59e5b9179d74844ae06a30ae1e0629, type: 3} |
||||
|
depthClipPass: {fileID: 7200000, guid: 20e44016ed34b0d4b8de499d1b566c69, type: 3} |
||||
|
lockPass: {fileID: 7200000, guid: a135306e6d1857e43a86ef20db2a47fe, type: 3} |
||||
|
accumulatePass: {fileID: 7200000, guid: c9b45f0ae7673694ba57a4aadfe212e9, type: 3} |
||||
|
sharpenPass: {fileID: 7200000, guid: 7aaf5cfff022de2499e9b0412f947f6c, type: 3} |
||||
|
autoGenReactivePass: {fileID: 7200000, guid: 5716b91fdaa4e9e439df6b96a796fe6e, type: 3} |
||||
|
tcrAutoGenPass: {fileID: 7200000, guid: 75cdc6ef23f08ed498d4da511923fcea, type: 3} |
||||
@ -0,0 +1,151 @@ |
|||||
|
// Copyright (c) 2023 Nico de Poel
|
||||
|
//
|
||||
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
|
// of this software and associated documentation files (the "Software"), to deal
|
||||
|
// in the Software without restriction, including without limitation the rights
|
||||
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
|
// copies of the Software, and to permit persons to whom the Software is
|
||||
|
// furnished to do so, subject to the following conditions:
|
||||
|
//
|
||||
|
// The above copyright notice and this permission notice shall be included in all
|
||||
|
// copies or substantial portions of the Software.
|
||||
|
//
|
||||
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
|
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
|
// THE SOFTWARE.
|
||||
|
|
||||
|
using UnityEngine; |
||||
|
|
||||
|
namespace FidelityFX |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// Scriptable object containing all shader resources required by FidelityFX Super Resolution 3 (FSR3) Upscaler.
|
||||
|
/// These can be stored in an asset file and referenced from a scene or prefab, avoiding the need to load the shaders from a Resources folder.
|
||||
|
/// </summary>
|
||||
|
public class Fsr3UpscalerAssets : ScriptableObject |
||||
|
{ |
||||
|
public Fsr3UpscalerShaders shaders; |
||||
|
|
||||
|
#if UNITY_EDITOR
|
||||
|
private void Reset() |
||||
|
{ |
||||
|
shaders = new Fsr3UpscalerShaders |
||||
|
{ |
||||
|
computeLuminancePyramidPass = FindComputeShader("ffx_fsr3upscaler_compute_luminance_pyramid_pass"), |
||||
|
reconstructPreviousDepthPass = FindComputeShader("ffx_fsr3upscaler_reconstruct_previous_depth_pass"), |
||||
|
depthClipPass = FindComputeShader("ffx_fsr3upscaler_depth_clip_pass"), |
||||
|
lockPass = FindComputeShader("ffx_fsr3upscaler_lock_pass"), |
||||
|
accumulatePass = FindComputeShader("ffx_fsr3upscaler_accumulate_pass"), |
||||
|
sharpenPass = FindComputeShader("ffx_fsr3upscaler_rcas_pass"), |
||||
|
autoGenReactivePass = FindComputeShader("ffx_fsr3upscaler_autogen_reactive_pass"), |
||||
|
tcrAutoGenPass = FindComputeShader("ffx_fsr3upscaler_tcr_autogen_pass"), |
||||
|
}; |
||||
|
} |
||||
|
|
||||
|
private static ComputeShader FindComputeShader(string name) |
||||
|
{ |
||||
|
string[] assetGuids = UnityEditor.AssetDatabase.FindAssets($"t:ComputeShader {name}"); |
||||
|
if (assetGuids == null || assetGuids.Length == 0) |
||||
|
return null; |
||||
|
|
||||
|
string assetPath = UnityEditor.AssetDatabase.GUIDToAssetPath(assetGuids[0]); |
||||
|
return UnityEditor.AssetDatabase.LoadAssetAtPath<ComputeShader>(assetPath); |
||||
|
} |
||||
|
#endif
|
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// All the compute shaders used by the FSR3 Upscaler.
|
||||
|
/// </summary>
|
||||
|
[System.Serializable] |
||||
|
public class Fsr3UpscalerShaders |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// The compute shader used by the luminance pyramid computation pass.
|
||||
|
/// </summary>
|
||||
|
public ComputeShader computeLuminancePyramidPass; |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// The compute shader used by the previous depth reconstruction pass.
|
||||
|
/// </summary>
|
||||
|
public ComputeShader reconstructPreviousDepthPass; |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// The compute shader used by the depth clip pass.
|
||||
|
/// </summary>
|
||||
|
public ComputeShader depthClipPass; |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// The compute shader used by the lock pass.
|
||||
|
/// </summary>
|
||||
|
public ComputeShader lockPass; |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// The compute shader used by the accumulation pass.
|
||||
|
/// </summary>
|
||||
|
public ComputeShader accumulatePass; |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// The compute shader used by the RCAS sharpening pass.
|
||||
|
/// </summary>
|
||||
|
public ComputeShader sharpenPass; |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// The compute shader used to auto-generate a reactive mask.
|
||||
|
/// </summary>
|
||||
|
public ComputeShader autoGenReactivePass; |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// The compute shader used to auto-generate a transparency & composition mask.
|
||||
|
/// </summary>
|
||||
|
public ComputeShader tcrAutoGenPass; |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Returns a copy of this class and its contents.
|
||||
|
/// </summary>
|
||||
|
public Fsr3UpscalerShaders Clone() |
||||
|
{ |
||||
|
return (Fsr3UpscalerShaders)MemberwiseClone(); |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Returns a copy of this class with clones of all its shaders.
|
||||
|
/// This can be useful if you're running multiple FSR3 Upscaler instances with different shader configurations.
|
||||
|
/// Be sure to clean up these clones through Dispose once you're done with them.
|
||||
|
/// </summary>
|
||||
|
public Fsr3UpscalerShaders DeepCopy() |
||||
|
{ |
||||
|
return new Fsr3UpscalerShaders |
||||
|
{ |
||||
|
computeLuminancePyramidPass = Object.Instantiate(computeLuminancePyramidPass), |
||||
|
reconstructPreviousDepthPass = Object.Instantiate(reconstructPreviousDepthPass), |
||||
|
depthClipPass = Object.Instantiate(depthClipPass), |
||||
|
lockPass = Object.Instantiate(lockPass), |
||||
|
accumulatePass = Object.Instantiate(accumulatePass), |
||||
|
sharpenPass = Object.Instantiate(sharpenPass), |
||||
|
autoGenReactivePass = Object.Instantiate(autoGenReactivePass), |
||||
|
tcrAutoGenPass = Object.Instantiate(tcrAutoGenPass), |
||||
|
}; |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Destroy all the shaders within this instance.
|
||||
|
/// Use this only on clones created through DeepCopy.
|
||||
|
/// </summary>
|
||||
|
public void Dispose() |
||||
|
{ |
||||
|
Object.Destroy(computeLuminancePyramidPass); |
||||
|
Object.Destroy(reconstructPreviousDepthPass); |
||||
|
Object.Destroy(depthClipPass); |
||||
|
Object.Destroy(lockPass); |
||||
|
Object.Destroy(accumulatePass); |
||||
|
Object.Destroy(sharpenPass); |
||||
|
Object.Destroy(autoGenReactivePass); |
||||
|
Object.Destroy(tcrAutoGenPass); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -1,119 +0,0 @@ |
|||||
using System; |
|
||||
using UnityEngine; |
|
||||
|
|
||||
namespace FidelityFX |
|
||||
{ |
|
||||
/// <summary>
|
|
||||
/// All the compute shaders used by the FidelityFX Super Resolution 3 (FSR3) Upscaler.
|
|
||||
/// </summary>
|
|
||||
[Serializable] |
|
||||
public class Fsr3UpscalerShaders: ScriptableObject |
|
||||
{ |
|
||||
/// <summary>
|
|
||||
/// The compute shader used by the luminance pyramid computation pass.
|
|
||||
/// </summary>
|
|
||||
public ComputeShader computeLuminancePyramidPass; |
|
||||
|
|
||||
/// <summary>
|
|
||||
/// The compute shader used by the previous depth reconstruction pass.
|
|
||||
/// </summary>
|
|
||||
public ComputeShader reconstructPreviousDepthPass; |
|
||||
|
|
||||
/// <summary>
|
|
||||
/// The compute shader used by the depth clip pass.
|
|
||||
/// </summary>
|
|
||||
public ComputeShader depthClipPass; |
|
||||
|
|
||||
/// <summary>
|
|
||||
/// The compute shader used by the lock pass.
|
|
||||
/// </summary>
|
|
||||
public ComputeShader lockPass; |
|
||||
|
|
||||
/// <summary>
|
|
||||
/// The compute shader used by the accumulation pass.
|
|
||||
/// </summary>
|
|
||||
public ComputeShader accumulatePass; |
|
||||
|
|
||||
/// <summary>
|
|
||||
/// The compute shader used by the RCAS sharpening pass.
|
|
||||
/// </summary>
|
|
||||
public ComputeShader sharpenPass; |
|
||||
|
|
||||
/// <summary>
|
|
||||
/// The compute shader used to auto-generate a reactive mask.
|
|
||||
/// </summary>
|
|
||||
public ComputeShader autoGenReactivePass; |
|
||||
|
|
||||
/// <summary>
|
|
||||
/// The compute shader used to auto-generate a transparency & composition mask.
|
|
||||
/// </summary>
|
|
||||
public ComputeShader tcrAutoGenPass; |
|
||||
|
|
||||
/// <summary>
|
|
||||
/// Returns a copy of this class and its contents.
|
|
||||
/// </summary>
|
|
||||
public Fsr3UpscalerShaders Clone() |
|
||||
{ |
|
||||
return (Fsr3UpscalerShaders)MemberwiseClone(); |
|
||||
} |
|
||||
|
|
||||
/// <summary>
|
|
||||
/// Returns a copy of this class with clones of all its shaders.
|
|
||||
/// This can be useful if you're running multiple FSR3 Upscaler instances with different shader configurations.
|
|
||||
/// Be sure to clean up these clones through Dispose once you're done with them.
|
|
||||
/// </summary>
|
|
||||
public Fsr3UpscalerShaders DeepCopy() |
|
||||
{ |
|
||||
Fsr3UpscalerShaders copy = CreateInstance<Fsr3UpscalerShaders>(); |
|
||||
copy.computeLuminancePyramidPass = Instantiate(computeLuminancePyramidPass); |
|
||||
copy.reconstructPreviousDepthPass = Instantiate(reconstructPreviousDepthPass); |
|
||||
copy.depthClipPass = Instantiate(depthClipPass); |
|
||||
copy.lockPass = Instantiate(lockPass); |
|
||||
copy.accumulatePass = Instantiate(accumulatePass); |
|
||||
copy.sharpenPass = Instantiate(sharpenPass); |
|
||||
copy.autoGenReactivePass = Instantiate(autoGenReactivePass); |
|
||||
copy.tcrAutoGenPass = Instantiate(tcrAutoGenPass); |
|
||||
return copy; |
|
||||
} |
|
||||
|
|
||||
/// <summary>
|
|
||||
/// Destroy all the shaders within this instance.
|
|
||||
/// Use this only on clones created through DeepCopy.
|
|
||||
/// </summary>
|
|
||||
public void Dispose() |
|
||||
{ |
|
||||
Destroy(computeLuminancePyramidPass); |
|
||||
Destroy(reconstructPreviousDepthPass); |
|
||||
Destroy(depthClipPass); |
|
||||
Destroy(lockPass); |
|
||||
Destroy(accumulatePass); |
|
||||
Destroy(sharpenPass); |
|
||||
Destroy(autoGenReactivePass); |
|
||||
Destroy(tcrAutoGenPass); |
|
||||
} |
|
||||
|
|
||||
#if UNITY_EDITOR
|
|
||||
private void Reset() |
|
||||
{ |
|
||||
computeLuminancePyramidPass = FindComputeShader("ffx_fsr3upscaler_compute_luminance_pyramid_pass"); |
|
||||
reconstructPreviousDepthPass = FindComputeShader("ffx_fsr3upscaler_reconstruct_previous_depth_pass"); |
|
||||
depthClipPass = FindComputeShader("ffx_fsr3upscaler_depth_clip_pass"); |
|
||||
lockPass = FindComputeShader("ffx_fsr3upscaler_lock_pass"); |
|
||||
accumulatePass = FindComputeShader("ffx_fsr3upscaler_accumulate_pass"); |
|
||||
sharpenPass = FindComputeShader("ffx_fsr3upscaler_rcas_pass"); |
|
||||
autoGenReactivePass = FindComputeShader("ffx_fsr3upscaler_autogen_reactive_pass"); |
|
||||
tcrAutoGenPass = FindComputeShader("ffx_fsr3upscaler_tcr_autogen_pass"); |
|
||||
} |
|
||||
|
|
||||
private static ComputeShader FindComputeShader(string name) |
|
||||
{ |
|
||||
string[] assetGuids = UnityEditor.AssetDatabase.FindAssets($"t:ComputeShader {name}"); |
|
||||
if (assetGuids == null || assetGuids.Length == 0) |
|
||||
return null; |
|
||||
|
|
||||
string assetPath = UnityEditor.AssetDatabase.GUIDToAssetPath(assetGuids[0]); |
|
||||
return UnityEditor.AssetDatabase.LoadAssetAtPath<ComputeShader>(assetPath); |
|
||||
} |
|
||||
#endif
|
|
||||
} |
|
||||
} |
|
||||
@ -1,22 +0,0 @@ |
|||||
%YAML 1.1 |
|
||||
%TAG !u! tag:unity3d.com,2011: |
|
||||
--- !u!114 &11400000 |
|
||||
MonoBehaviour: |
|
||||
m_ObjectHideFlags: 0 |
|
||||
m_CorrespondingSourceObject: {fileID: 0} |
|
||||
m_PrefabInstance: {fileID: 0} |
|
||||
m_PrefabAsset: {fileID: 0} |
|
||||
m_GameObject: {fileID: 0} |
|
||||
m_Enabled: 1 |
|
||||
m_EditorHideFlags: 0 |
|
||||
m_Script: {fileID: 11500000, guid: db26e15a33db6ab42a38daab0ba2712f, type: 3} |
|
||||
m_Name: Fsr3UpscalerShaders |
|
||||
m_EditorClassIdentifier: |
|
||||
computeLuminancePyramidPass: {fileID: 7200000, guid: d253be05abcdc80428503d3e4cce3a36, type: 3} |
|
||||
reconstructPreviousDepthPass: {fileID: 7200000, guid: 4f59e5b9179d74844ae06a30ae1e0629, type: 3} |
|
||||
depthClipPass: {fileID: 7200000, guid: 20e44016ed34b0d4b8de499d1b566c69, type: 3} |
|
||||
lockPass: {fileID: 7200000, guid: a135306e6d1857e43a86ef20db2a47fe, type: 3} |
|
||||
accumulatePass: {fileID: 7200000, guid: c9b45f0ae7673694ba57a4aadfe212e9, type: 3} |
|
||||
sharpenPass: {fileID: 7200000, guid: 7aaf5cfff022de2499e9b0412f947f6c, type: 3} |
|
||||
autoGenReactivePass: {fileID: 7200000, guid: 5716b91fdaa4e9e439df6b96a796fe6e, type: 3} |
|
||||
tcrAutoGenPass: {fileID: 7200000, guid: 75cdc6ef23f08ed498d4da511923fcea, type: 3} |
|
||||
Write
Preview
Loading…
Cancel
Save
Reference in new issue