This commit is contained in:
2025-11-14 18:44:06 +08:00
parent 10156da245
commit 22e867d077
7013 changed files with 2572882 additions and 1804 deletions

View File

@@ -0,0 +1,64 @@
using System;
namespace UnityEngine.PostProcessing
{
// Small wrapper on top of AnimationCurve to handle zero-key curves and keyframe looping
[Serializable]
public sealed class ColorGradingCurve
{
public AnimationCurve curve;
[SerializeField]
bool m_Loop;
[SerializeField]
float m_ZeroValue;
[SerializeField]
float m_Range;
AnimationCurve m_InternalLoopingCurve;
public ColorGradingCurve(AnimationCurve curve, float zeroValue, bool loop, Vector2 bounds)
{
this.curve = curve;
m_ZeroValue = zeroValue;
m_Loop = loop;
m_Range = bounds.magnitude;
}
public void Cache()
{
if (!m_Loop)
return;
var length = curve.length;
if (length < 2)
return;
if (m_InternalLoopingCurve == null)
m_InternalLoopingCurve = new AnimationCurve();
var prev = curve[length - 1];
prev.time -= m_Range;
var next = curve[0];
next.time += m_Range;
m_InternalLoopingCurve.keys = curve.keys;
m_InternalLoopingCurve.AddKey(prev);
m_InternalLoopingCurve.AddKey(next);
}
public float Evaluate(float t)
{
if (curve.length == 0)
return m_ZeroValue;
if (!m_Loop || curve.length == 1)
return curve.Evaluate(t);
return m_InternalLoopingCurve.Evaluate(t);
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 1bb6f2275f7eff940b6f0d72681e7877
timeCreated: 1473847739
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,144 @@
namespace UnityEngine.PostProcessing
{
using UnityObject = Object;
public static class GraphicsUtils
{
public static bool isLinearColorSpace
{
get { return QualitySettings.activeColorSpace == ColorSpace.Linear; }
}
public static bool supportsDX11
{
#if UNITY_WEBGL
get { return false; }
#else
get { return SystemInfo.graphicsShaderLevel >= 50 && SystemInfo.supportsComputeShaders; }
#endif
}
static Texture2D s_WhiteTexture;
public static Texture2D whiteTexture
{
get
{
if (s_WhiteTexture != null)
return s_WhiteTexture;
s_WhiteTexture = new Texture2D(1, 1, TextureFormat.ARGB32, false);
s_WhiteTexture.SetPixel(0, 0, new Color(1f, 1f, 1f, 1f));
s_WhiteTexture.Apply();
return s_WhiteTexture;
}
}
static Mesh s_Quad;
public static Mesh quad
{
get
{
if (s_Quad != null)
return s_Quad;
var vertices = new[]
{
new Vector3(-1f, -1f, 0f),
new Vector3( 1f, 1f, 0f),
new Vector3( 1f, -1f, 0f),
new Vector3(-1f, 1f, 0f)
};
var uvs = new[]
{
new Vector2(0f, 0f),
new Vector2(1f, 1f),
new Vector2(1f, 0f),
new Vector2(0f, 1f)
};
var indices = new[] { 0, 1, 2, 1, 0, 3 };
s_Quad = new Mesh
{
vertices = vertices,
uv = uvs,
triangles = indices
};
s_Quad.RecalculateNormals();
s_Quad.RecalculateBounds();
return s_Quad;
}
}
// Useful when rendering to MRT
public static void Blit(Material material, int pass)
{
GL.PushMatrix();
{
GL.LoadOrtho();
material.SetPass(pass);
GL.Begin(GL.TRIANGLE_STRIP);
{
GL.TexCoord2(0f, 0f); GL.Vertex3(0f, 0f, 0.1f);
GL.TexCoord2(1f, 0f); GL.Vertex3(1f, 0f, 0.1f);
GL.TexCoord2(0f, 1f); GL.Vertex3(0f, 1f, 0.1f);
GL.TexCoord2(1f, 1f); GL.Vertex3(1f, 1f, 0.1f);
}
GL.End();
}
GL.PopMatrix();
}
public static void ClearAndBlit(Texture source, RenderTexture destination, Material material, int pass, bool clearColor = true, bool clearDepth = false)
{
var oldRT = RenderTexture.active;
RenderTexture.active = destination;
GL.Clear(false, clearColor, Color.clear);
GL.PushMatrix();
{
GL.LoadOrtho();
material.SetTexture("_MainTex", source);
material.SetPass(pass);
GL.Begin(GL.TRIANGLE_STRIP);
{
GL.TexCoord2(0f, 0f); GL.Vertex3(0f, 0f, 0.1f);
GL.TexCoord2(1f, 0f); GL.Vertex3(1f, 0f, 0.1f);
GL.TexCoord2(0f, 1f); GL.Vertex3(0f, 1f, 0.1f);
GL.TexCoord2(1f, 1f); GL.Vertex3(1f, 1f, 0.1f);
}
GL.End();
}
GL.PopMatrix();
RenderTexture.active = oldRT;
}
public static void Destroy(UnityObject obj)
{
if (obj != null)
{
#if UNITY_EDITOR
if (Application.isPlaying)
UnityObject.Destroy(obj);
else
UnityObject.DestroyImmediate(obj);
#else
UnityObject.Destroy(obj);
#endif
}
}
public static void Dispose()
{
Destroy(s_Quad);
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: f40f0a1acf6ce2f419f2b71c667e8973
timeCreated: 1467635425
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,52 @@
using System;
using System.Collections.Generic;
namespace UnityEngine.PostProcessing
{
using UnityObject = Object;
public sealed class MaterialFactory : IDisposable
{
Dictionary<string, Material> m_Materials;
public MaterialFactory()
{
m_Materials = new Dictionary<string, Material>();
}
public Material Get(string shaderName)
{
Material material;
if (!m_Materials.TryGetValue(shaderName, out material))
{
var shader = Shader.Find(shaderName);
if (shader == null)
throw new ArgumentException(string.Format("Shader not found ({0})", shaderName));
material = new Material(shader)
{
name = string.Format("PostFX - {0}", shaderName.Substring(shaderName.LastIndexOf("/") + 1)),
hideFlags = HideFlags.DontSave
};
m_Materials.Add(shaderName, material);
}
return material;
}
public void Dispose()
{
var enumerator = m_Materials.GetEnumerator();
while (enumerator.MoveNext())
{
var material = enumerator.Current.Value;
GraphicsUtils.Destroy(material);
}
m_Materials.Clear();
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 594fad000c373f746864717c588e1815
timeCreated: 1466586851
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,64 @@
using System;
using System.Collections.Generic;
namespace UnityEngine.PostProcessing
{
public sealed class RenderTextureFactory : IDisposable
{
HashSet<RenderTexture> m_TemporaryRTs;
public RenderTextureFactory()
{
m_TemporaryRTs = new HashSet<RenderTexture>();
}
public RenderTexture Get(RenderTexture baseRenderTexture)
{
return Get(
baseRenderTexture.width,
baseRenderTexture.height,
baseRenderTexture.depth,
baseRenderTexture.format,
baseRenderTexture.sRGB ? RenderTextureReadWrite.sRGB : RenderTextureReadWrite.Linear,
baseRenderTexture.filterMode,
baseRenderTexture.wrapMode
);
}
public RenderTexture Get(int width, int height, int depthBuffer = 0, RenderTextureFormat format = RenderTextureFormat.ARGBHalf, RenderTextureReadWrite rw = RenderTextureReadWrite.Default, FilterMode filterMode = FilterMode.Bilinear, TextureWrapMode wrapMode = TextureWrapMode.Clamp, string name = "FactoryTempTexture")
{
var rt = RenderTexture.GetTemporary(width, height, depthBuffer, format, rw); // add forgotten param rw
rt.filterMode = filterMode;
rt.wrapMode = wrapMode;
rt.name = name;
m_TemporaryRTs.Add(rt);
return rt;
}
public void Release(RenderTexture rt)
{
if (rt == null)
return;
if (!m_TemporaryRTs.Contains(rt))
throw new ArgumentException(string.Format("Attempting to remove a RenderTexture that was not allocated: {0}", rt));
m_TemporaryRTs.Remove(rt);
RenderTexture.ReleaseTemporary(rt);
}
public void ReleaseAll()
{
var enumerator = m_TemporaryRTs.GetEnumerator();
while (enumerator.MoveNext())
RenderTexture.ReleaseTemporary(enumerator.Current);
m_TemporaryRTs.Clear();
}
public void Dispose()
{
ReleaseAll();
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: aec5694806c4d75449e231cfae69c329
timeCreated: 1467361102
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: