using System;
using System.Diagnostics.CodeAnalysis;
using System.IO;
#if UNITY_EDITOR
using UnityEditor;
using UnityEditor.ProjectWindowCallback;
using System.Reflection;
#endif
namespace UnityEngine.Rendering.Universal
{
///
/// Class containing shader and texture resources needed for Post Processing in URP.
///
///
///
[Serializable]
public class PostProcessData : ScriptableObject
{
#if UNITY_EDITOR
[SuppressMessage("Microsoft.Performance", "CA1812")]
internal class CreatePostProcessDataAsset : EndNameEditAction
{
public override void Action(int instanceId, string pathName, string resourceFile)
{
var instance = CreateInstance();
AssetDatabase.CreateAsset(instance, pathName);
Selection.activeObject = instance;
}
}
[MenuItem("Assets/Create/Rendering/URP Post-process Data", priority = CoreUtils.Sections.section5 + CoreUtils.Priorities.assetsCreateRenderingMenuPriority)]
static void CreatePostProcessData()
{
ProjectWindowUtil.StartNameEditingIfProjectWindowExists(0, CreateInstance(), "CustomPostProcessData.asset", null, null);
}
internal static PostProcessData GetDefaultPostProcessData()
{
var path = Path.Combine(UniversalRenderPipelineAsset.packagePath, "Runtime/Data/PostProcessData.asset");
return AssetDatabase.LoadAssetAtPath(path);
}
internal void Reset()
{
LoadResources(true);
}
internal void Populate()
{
LoadResources(false);
}
void LoadResources(bool reset)
{
if (GraphicsSettings.TryGetRenderPipelineSettings(out var defaultShaderResources))
{
if (shaders == null || reset)
shaders = new ShaderResources();
shaders.Populate(defaultShaderResources);
}
if (GraphicsSettings.TryGetRenderPipelineSettings(out var defaultTextureResources))
{
if (textures == null || reset)
textures = new TextureResources();
textures.Populate(defaultTextureResources);
}
}
#endif
///
/// Class containing shader resources used for Post Processing in URP.
///
[Serializable]
[SupportedOnRenderPipeline(typeof(UniversalRenderPipelineAsset))]
[Categorization.CategoryInfo(Name = "R: Default PostProcess Shaders", Order = 1000)]
[Categorization.ElementInfo(Order = 0), HideInInspector]
public sealed class ShaderResources : IRenderPipelineResources
{
///
/// The StopNan Post Processing shader.
///
[ResourcePath("Shaders/PostProcessing/StopNaN.shader")]
public Shader stopNanPS;
///
/// The SubpixelMorphologicalAntiAliasing SMAA Post Processing shader.
///
[ResourcePath("Shaders/PostProcessing/SubpixelMorphologicalAntialiasing.shader")]
public Shader subpixelMorphologicalAntialiasingPS;
///
/// The Gaussian Depth Of Field Post Processing shader.
///
[ResourcePath("Shaders/PostProcessing/GaussianDepthOfField.shader")]
public Shader gaussianDepthOfFieldPS;
///
/// The Bokeh Depth Of Field Post Processing shader.
///
[ResourcePath("Shaders/PostProcessing/BokehDepthOfField.shader")]
public Shader bokehDepthOfFieldPS;
///
/// The Motion Blur Post Processing shader.
///
[ResourcePath("Shaders/PostProcessing/CameraMotionBlur.shader")]
public Shader cameraMotionBlurPS;
///
/// The Panini Projection Post Processing shader.
///
[ResourcePath("Shaders/PostProcessing/PaniniProjection.shader")]
public Shader paniniProjectionPS;
///
/// The LUT Builder LDR Post Processing shader.
///
[ResourcePath("Shaders/PostProcessing/LutBuilderLdr.shader")]
public Shader lutBuilderLdrPS;
///
/// The LUT Builder HDR Post Processing shader.
///
[ResourcePath("Shaders/PostProcessing/LutBuilderHdr.shader")]
public Shader lutBuilderHdrPS;
///
/// The Bloom Post Processing shader.
///
[ResourcePath("Shaders/PostProcessing/Bloom.shader")]
public Shader bloomPS;
///
/// The Temporal-antialiasing Post Processing shader.
///
[ResourcePath("Shaders/PostProcessing/TemporalAA.shader")]
public Shader temporalAntialiasingPS;
///
/// The Lens Flare Post Processing shader.
///
[ResourcePath("Shaders/PostProcessing/LensFlareDataDriven.shader")]
public Shader LensFlareDataDrivenPS;
///
/// The Lens Flare Screen Space shader.
///
[ResourcePath("Shaders/PostProcessing/LensFlareScreenSpace.shader")]
public Shader LensFlareScreenSpacePS;
///
/// The Scaling Setup Post Processing shader.
///
[ResourcePath("Shaders/PostProcessing/ScalingSetup.shader")]
public Shader scalingSetupPS;
///
/// The Edge Adaptive Spatial Upsampling shader.
///
[ResourcePath("Shaders/PostProcessing/EdgeAdaptiveSpatialUpsampling.shader")]
public Shader easuPS;
///
/// The Uber Post Processing shader.
///
[ResourcePath("Shaders/PostProcessing/UberPost.shader")]
public Shader uberPostPS;
///
/// The Final Post Processing shader.
///
[ResourcePath("Shaders/PostProcessing/FinalPost.shader")]
public Shader finalPostPassPS;
#if UNITY_EDITOR
///
/// Copies all fields and resources from a source object into this object.
///
///
/// This method is available only in the Unity Editor. It uses the method to copy non-null field values. Use this to synchronize resource objects during runtime in the Editor.
///
///
/// The source object to copy data from. This object must not be null.
///
internal void Populate(ShaderResources source)
{
CoreUtils.PopulateNullFieldsFrom(source, this);
}
#endif
// This name must be unique within the entire PostProcessData set, as PostProcessDataAnalytics retrieves it.
[SerializeField][HideInInspector] int m_ShaderResourcesVersion = 0;
///
/// Gets the current version of the resource container.
///
///
/// This version is used exclusively for upgrading a project to ensure compatibility with resources configured in earlier Unity versions. Updating this version is an internal process during asset upgrades.
///
///
/// The version number of the resource container. This value is incremented when the resource container changes.
///
public int version => m_ShaderResourcesVersion;
///
/// Indicates whether the resource is available in a player build.
///
///
/// Always returns `false` because this resource is not designed to be included in player builds.
///
///
/// `false`, indicating that the resource is editor-only and unavailable in a player build.
///
public bool isAvailableInPlayerBuild => false;
}
///
/// Class containing texture resources used for Post Processing in URP.
///
[Serializable]
[SupportedOnRenderPipeline(typeof(UniversalRenderPipelineAsset))]
[Categorization.CategoryInfo(Name = "R: Default PostProcess Textures", Order = 1000)]
[Categorization.ElementInfo(Order = 0), HideInInspector]
public sealed class TextureResources : IRenderPipelineResources
{
///
/// Pre-baked Blue noise textures.
///
[ResourceFormattedPaths("Textures/BlueNoise16/L/LDR_LLL1_{0}.png", 0, 32)]
public Texture2D[] blueNoise16LTex;
///
/// Film Grain textures.
///
[ResourcePaths(new[]
{
"Textures/FilmGrain/Thin01.png",
"Textures/FilmGrain/Thin02.png",
"Textures/FilmGrain/Medium01.png",
"Textures/FilmGrain/Medium02.png",
"Textures/FilmGrain/Medium03.png",
"Textures/FilmGrain/Medium04.png",
"Textures/FilmGrain/Medium05.png",
"Textures/FilmGrain/Medium06.png",
"Textures/FilmGrain/Large01.png",
"Textures/FilmGrain/Large02.png"
})]
public Texture2D[] filmGrainTex;
///
/// SubpixelMorphologicalAntiAliasing SMAA area texture.
///
[ResourcePath("Textures/SMAA/AreaTex.tga")] public Texture2D smaaAreaTex;
///
/// SubpixelMorphologicalAntiAliasing SMAA search texture.
///
[ResourcePath("Textures/SMAA/SearchTex.tga")]
public Texture2D smaaSearchTex;
#if UNITY_EDITOR
///
/// Copies all fields and resources from a source object into this object.
///
///
/// This method is available only in the Unity Editor. It uses the method to copy non-null field values. Use this to synchronize resource objects during runtime in the Editor.
///
///
/// The source object to copy data from. This object must not be null.
///
internal void Populate(TextureResources source)
{
CoreUtils.PopulateNullFieldsFrom(source, this);
}
#endif
// This name must be unique within the entire PostProcessData set, as PostProcessDataAnalytics retrieves it.
[SerializeField][HideInInspector] int m_TexturesResourcesVersion = 0;
///
/// Gets the current version of the resource container.
///
///
/// This version is used exclusively for upgrading a project to ensure compatibility with resources configured in earlier Unity versions. Updating this version is an internal process during asset upgrades.
///
///
/// The version number of the resource container. This value is incremented when the resource container changes.
///
public int version => m_TexturesResourcesVersion;
///
/// Indicates whether the resource is available in a player build.
///
///
/// Always returns `false` because this resource is not designed to be included in player builds.
///
///
/// `false`, indicating that the resource is editor-only and unavailable in a player build.
///
public bool isAvailableInPlayerBuild => false;
}
///
/// Shader resources used for Post Processing in URP.
///
public ShaderResources shaders;
///
/// Texture resources used for Post Processing in URP.
///
public TextureResources textures;
}
}