Files
Dec2017-Script-Dump/Assembly-CSharp-firstpass/CinematicEffects/SMAA.cs
T
2026-06-04 11:42:34 +02:00

526 lines
17 KiB
C#

using System;
using UnityEngine;
namespace UnityStandardAssets.CinematicEffects
{
// Token: 0x0200000A RID: 10
[Serializable]
public class SMAA : IAntiAliasing
{
// Token: 0x1700000C RID: 12
// (get) Token: 0x06000023 RID: 35 RVA: 0x0000263D File Offset: 0x00000A3D
public Shader shader
{
get
{
if (this.m_Shader == null)
{
this.m_Shader = Shader.Find("Hidden/Subpixel Morphological Anti-aliasing");
}
return this.m_Shader;
}
}
// Token: 0x1700000D RID: 13
// (get) Token: 0x06000024 RID: 36 RVA: 0x00002666 File Offset: 0x00000A66
private Texture2D areaTexture
{
get
{
if (this.m_AreaTexture == null)
{
this.m_AreaTexture = Resources.Load<Texture2D>("AreaTex");
}
return this.m_AreaTexture;
}
}
// Token: 0x1700000E RID: 14
// (get) Token: 0x06000025 RID: 37 RVA: 0x0000268F File Offset: 0x00000A8F
private Texture2D searchTexture
{
get
{
if (this.m_SearchTexture == null)
{
this.m_SearchTexture = Resources.Load<Texture2D>("SearchTex");
}
return this.m_SearchTexture;
}
}
// Token: 0x1700000F RID: 15
// (get) Token: 0x06000026 RID: 38 RVA: 0x000026B8 File Offset: 0x00000AB8
private Material material
{
get
{
if (this.m_Material == null)
{
this.m_Material = ImageEffectHelper.CheckShaderAndCreateMaterial(this.shader);
}
return this.m_Material;
}
}
// Token: 0x06000027 RID: 39 RVA: 0x000026E2 File Offset: 0x00000AE2
public void OnEnable(AntiAliasing owner)
{
if (!ImageEffectHelper.IsSupported(this.shader, true, false, owner))
{
owner.enabled = false;
}
}
// Token: 0x06000028 RID: 40 RVA: 0x00002700 File Offset: 0x00000B00
public void OnDisable()
{
if (this.m_Material != null)
{
global::UnityEngine.Object.DestroyImmediate(this.m_Material);
}
if (this.m_Accumulation != null)
{
global::UnityEngine.Object.DestroyImmediate(this.m_Accumulation);
}
this.m_Material = null;
this.m_Accumulation = null;
}
// Token: 0x06000029 RID: 41 RVA: 0x00002754 File Offset: 0x00000B54
public void OnPreCull(Camera camera)
{
if (this.temporal.UseTemporal())
{
this.m_ProjectionMatrix = camera.projectionMatrix;
this.m_FlipFlop -= 2f * this.m_FlipFlop;
Matrix4x4 identity = Matrix4x4.identity;
identity.m03 = 0.25f * this.m_FlipFlop * this.temporal.fuzzSize / (float)camera.pixelWidth;
identity.m13 = -0.25f * this.m_FlipFlop * this.temporal.fuzzSize / (float)camera.pixelHeight;
camera.projectionMatrix = identity * camera.projectionMatrix;
}
}
// Token: 0x0600002A RID: 42 RVA: 0x000027FC File Offset: 0x00000BFC
public void OnPostRender(Camera camera)
{
if (this.temporal.UseTemporal())
{
camera.ResetProjectionMatrix();
}
}
// Token: 0x0600002B RID: 43 RVA: 0x00002814 File Offset: 0x00000C14
public void OnRenderImage(Camera camera, RenderTexture source, RenderTexture destination)
{
int pixelWidth = camera.pixelWidth;
int pixelHeight = camera.pixelHeight;
bool flag = false;
SMAA.QualitySettings qualitySettings = this.quality;
if (this.settings.quality != SMAA.QualityPreset.Custom)
{
qualitySettings = SMAA.QualitySettings.presetQualitySettings[(int)this.settings.quality];
}
int edgeDetectionMethod = (int)this.settings.edgeDetectionMethod;
int num = 4;
int num2 = 5;
int num3 = 6;
Matrix4x4 matrix4x = GL.GetGPUProjectionMatrix(this.m_ProjectionMatrix, true) * camera.worldToCameraMatrix;
this.material.SetTexture("_AreaTex", this.areaTexture);
this.material.SetTexture("_SearchTex", this.searchTexture);
this.material.SetVector("_Metrics", new Vector4(1f / (float)pixelWidth, 1f / (float)pixelHeight, (float)pixelWidth, (float)pixelHeight));
this.material.SetVector("_Params1", new Vector4(qualitySettings.threshold, qualitySettings.depthThreshold, (float)qualitySettings.maxSearchSteps, (float)qualitySettings.maxDiagonalSearchSteps));
this.material.SetVector("_Params2", new Vector2((float)qualitySettings.cornerRounding, qualitySettings.localContrastAdaptationFactor));
this.material.SetMatrix("_ReprojectionMatrix", this.m_PreviousViewProjectionMatrix * Matrix4x4.Inverse(matrix4x));
float num4 = ((this.m_FlipFlop >= 0f) ? 1f : 2f);
this.material.SetVector("_SubsampleIndices", new Vector4(num4, num4, num4, 0f));
Shader.DisableKeyword("USE_PREDICATION");
if (this.settings.edgeDetectionMethod == SMAA.EdgeDetectionMethod.Depth)
{
camera.depthTextureMode |= DepthTextureMode.Depth;
}
else if (this.predication.enabled)
{
camera.depthTextureMode |= DepthTextureMode.Depth;
Shader.EnableKeyword("USE_PREDICATION");
this.material.SetVector("_Params3", new Vector3(this.predication.threshold, this.predication.scale, this.predication.strength));
}
Shader.DisableKeyword("USE_DIAG_SEARCH");
Shader.DisableKeyword("USE_CORNER_DETECTION");
if (qualitySettings.diagonalDetection)
{
Shader.EnableKeyword("USE_DIAG_SEARCH");
}
if (qualitySettings.cornerDetection)
{
Shader.EnableKeyword("USE_CORNER_DETECTION");
}
Shader.DisableKeyword("USE_UV_BASED_REPROJECTION");
if (this.temporal.UseTemporal())
{
Shader.EnableKeyword("USE_UV_BASED_REPROJECTION");
}
if (this.m_Accumulation == null || this.m_Accumulation.width != pixelWidth || this.m_Accumulation.height != pixelHeight)
{
if (this.m_Accumulation)
{
RenderTexture.ReleaseTemporary(this.m_Accumulation);
}
this.m_Accumulation = RenderTexture.GetTemporary(pixelWidth, pixelHeight, 0, source.format, RenderTextureReadWrite.Linear);
this.m_Accumulation.hideFlags = HideFlags.HideAndDontSave;
flag = true;
}
RenderTexture renderTexture = this.TempRT(pixelWidth, pixelHeight, source.format);
Graphics.Blit(null, renderTexture, this.material, 0);
Graphics.Blit(source, renderTexture, this.material, edgeDetectionMethod);
if (this.settings.debugPass == SMAA.DebugPass.Edges)
{
Graphics.Blit(renderTexture, destination);
}
else
{
RenderTexture renderTexture2 = this.TempRT(pixelWidth, pixelHeight, source.format);
Graphics.Blit(null, renderTexture2, this.material, 0);
Graphics.Blit(renderTexture, renderTexture2, this.material, num);
if (this.settings.debugPass == SMAA.DebugPass.Weights)
{
Graphics.Blit(renderTexture2, destination);
}
else
{
this.material.SetTexture("_BlendTex", renderTexture2);
if (this.temporal.UseTemporal())
{
Graphics.Blit(source, renderTexture, this.material, num2);
if (this.settings.debugPass == SMAA.DebugPass.Accumulation)
{
Graphics.Blit(this.m_Accumulation, destination);
}
else if (!flag)
{
this.material.SetTexture("_AccumulationTex", this.m_Accumulation);
Graphics.Blit(renderTexture, destination, this.material, num3);
}
else
{
Graphics.Blit(renderTexture, destination);
}
Graphics.Blit(destination, this.m_Accumulation);
RenderTexture.active = null;
}
else
{
Graphics.Blit(source, destination, this.material, num2);
}
}
RenderTexture.ReleaseTemporary(renderTexture2);
}
RenderTexture.ReleaseTemporary(renderTexture);
this.m_PreviousViewProjectionMatrix = matrix4x;
}
// Token: 0x0600002C RID: 44 RVA: 0x00002C74 File Offset: 0x00001074
private RenderTexture TempRT(int width, int height, RenderTextureFormat format)
{
int num = 0;
return RenderTexture.GetTemporary(width, height, num, format, RenderTextureReadWrite.Linear);
}
// Token: 0x0400001B RID: 27
[SMAA.TopLevelSettings]
public SMAA.GlobalSettings settings = SMAA.GlobalSettings.defaultSettings;
// Token: 0x0400001C RID: 28
[SMAA.SettingsGroup]
public SMAA.QualitySettings quality = SMAA.QualitySettings.presetQualitySettings[2];
// Token: 0x0400001D RID: 29
[SMAA.SettingsGroup]
public SMAA.PredicationSettings predication = SMAA.PredicationSettings.defaultSettings;
// Token: 0x0400001E RID: 30
[SMAA.SettingsGroup]
[SMAA.ExperimentalGroup]
public SMAA.TemporalSettings temporal = SMAA.TemporalSettings.defaultSettings;
// Token: 0x0400001F RID: 31
private Matrix4x4 m_ProjectionMatrix;
// Token: 0x04000020 RID: 32
private Matrix4x4 m_PreviousViewProjectionMatrix;
// Token: 0x04000021 RID: 33
private float m_FlipFlop = 1f;
// Token: 0x04000022 RID: 34
private RenderTexture m_Accumulation;
// Token: 0x04000023 RID: 35
private Shader m_Shader;
// Token: 0x04000024 RID: 36
private Texture2D m_AreaTexture;
// Token: 0x04000025 RID: 37
private Texture2D m_SearchTexture;
// Token: 0x04000026 RID: 38
private Material m_Material;
// Token: 0x0200000B RID: 11
[AttributeUsage(AttributeTargets.Field)]
public class SettingsGroup : Attribute
{
}
// Token: 0x0200000C RID: 12
[AttributeUsage(AttributeTargets.Field)]
public class TopLevelSettings : Attribute
{
}
// Token: 0x0200000D RID: 13
[AttributeUsage(AttributeTargets.Field)]
public class ExperimentalGroup : Attribute
{
}
// Token: 0x0200000E RID: 14
public enum DebugPass
{
// Token: 0x04000028 RID: 40
Off,
// Token: 0x04000029 RID: 41
Edges,
// Token: 0x0400002A RID: 42
Weights,
// Token: 0x0400002B RID: 43
Accumulation
}
// Token: 0x0200000F RID: 15
public enum QualityPreset
{
// Token: 0x0400002D RID: 45
Low,
// Token: 0x0400002E RID: 46
Medium,
// Token: 0x0400002F RID: 47
High,
// Token: 0x04000030 RID: 48
Ultra,
// Token: 0x04000031 RID: 49
Custom
}
// Token: 0x02000010 RID: 16
public enum EdgeDetectionMethod
{
// Token: 0x04000033 RID: 51
Luma = 1,
// Token: 0x04000034 RID: 52
Color,
// Token: 0x04000035 RID: 53
Depth
}
// Token: 0x02000011 RID: 17
[Serializable]
public struct GlobalSettings
{
// Token: 0x17000010 RID: 16
// (get) Token: 0x06000030 RID: 48 RVA: 0x00002CA8 File Offset: 0x000010A8
public static SMAA.GlobalSettings defaultSettings
{
get
{
return new SMAA.GlobalSettings
{
debugPass = SMAA.DebugPass.Off,
quality = SMAA.QualityPreset.High,
edgeDetectionMethod = SMAA.EdgeDetectionMethod.Color
};
}
}
// Token: 0x04000036 RID: 54
[Tooltip("Use this to fine tune your settings when working in Custom quality mode. \"Accumulation\" only works when \"Temporal Filtering\" is enabled.")]
public SMAA.DebugPass debugPass;
// Token: 0x04000037 RID: 55
[Tooltip("Low: 60% of the quality.\nMedium: 80% of the quality.\nHigh: 95% of the quality.\nUltra: 99% of the quality (overkill).")]
public SMAA.QualityPreset quality;
// Token: 0x04000038 RID: 56
[Tooltip("You've three edge detection methods to choose from: luma, color or depth.\nThey represent different quality/performance and anti-aliasing/sharpness tradeoffs, so our recommendation is for you to choose the one that best suits your particular scenario:\n\n- Depth edge detection is usually the fastest but it may miss some edges.\n- Luma edge detection is usually more expensive than depth edge detection, but catches visible edges that depth edge detection can miss.\n- Color edge detection is usually the most expensive one but catches chroma-only edges.")]
public SMAA.EdgeDetectionMethod edgeDetectionMethod;
}
// Token: 0x02000012 RID: 18
[Serializable]
public struct QualitySettings
{
// Token: 0x04000039 RID: 57
[Tooltip("Enables/Disables diagonal processing.")]
public bool diagonalDetection;
// Token: 0x0400003A RID: 58
[Tooltip("Enables/Disables corner detection. Leave this on to avoid blurry corners.")]
public bool cornerDetection;
// Token: 0x0400003B RID: 59
[Range(0f, 0.5f)]
[Tooltip("Specifies the threshold or sensitivity to edges. Lowering this value you will be able to detect more edges at the expense of performance.\n0.1 is a reasonable value, and allows to catch most visible edges. 0.05 is a rather overkill value, that allows to catch 'em all.")]
public float threshold;
// Token: 0x0400003C RID: 60
[Min(0.0001f)]
[Tooltip("Specifies the threshold for depth edge detection. Lowering this value you will be able to detect more edges at the expense of performance.")]
public float depthThreshold;
// Token: 0x0400003D RID: 61
[Range(0f, 112f)]
[Tooltip("Specifies the maximum steps performed in the horizontal/vertical pattern searches, at each side of the pixel.\nIn number of pixels, it's actually the double. So the maximum line length perfectly handled by, for example 16, is 64 (by perfectly, we meant that longer lines won't look as good, but still antialiased).")]
public int maxSearchSteps;
// Token: 0x0400003E RID: 62
[Range(0f, 20f)]
[Tooltip("Specifies the maximum steps performed in the diagonal pattern searches, at each side of the pixel. In this case we jump one pixel at time, instead of two.\nOn high-end machines it is cheap (between a 0.8x and 0.9x slower for 16 steps), but it can have a significant impact on older machines.")]
public int maxDiagonalSearchSteps;
// Token: 0x0400003F RID: 63
[Range(0f, 100f)]
[Tooltip("Specifies how much sharp corners will be rounded.")]
public int cornerRounding;
// Token: 0x04000040 RID: 64
[Min(0f)]
[Tooltip("If there is an neighbor edge that has a local contrast factor times bigger contrast than current edge, current edge will be discarded.\nThis allows to eliminate spurious crossing edges, and is based on the fact that, if there is too much contrast in a direction, that will hide perceptually contrast in the other neighbors.")]
public float localContrastAdaptationFactor;
// Token: 0x04000041 RID: 65
public static SMAA.QualitySettings[] presetQualitySettings = new SMAA.QualitySettings[]
{
new SMAA.QualitySettings
{
diagonalDetection = false,
cornerDetection = false,
threshold = 0.15f,
depthThreshold = 0.01f,
maxSearchSteps = 4,
maxDiagonalSearchSteps = 8,
cornerRounding = 25,
localContrastAdaptationFactor = 2f
},
new SMAA.QualitySettings
{
diagonalDetection = false,
cornerDetection = false,
threshold = 0.1f,
depthThreshold = 0.01f,
maxSearchSteps = 8,
maxDiagonalSearchSteps = 8,
cornerRounding = 25,
localContrastAdaptationFactor = 2f
},
new SMAA.QualitySettings
{
diagonalDetection = true,
cornerDetection = true,
threshold = 0.1f,
depthThreshold = 0.01f,
maxSearchSteps = 16,
maxDiagonalSearchSteps = 8,
cornerRounding = 25,
localContrastAdaptationFactor = 2f
},
new SMAA.QualitySettings
{
diagonalDetection = true,
cornerDetection = true,
threshold = 0.05f,
depthThreshold = 0.01f,
maxSearchSteps = 32,
maxDiagonalSearchSteps = 16,
cornerRounding = 25,
localContrastAdaptationFactor = 2f
}
};
}
// Token: 0x02000013 RID: 19
[Serializable]
public struct TemporalSettings
{
// Token: 0x06000032 RID: 50 RVA: 0x00002E7B File Offset: 0x0000127B
public bool UseTemporal()
{
return this.enabled;
}
// Token: 0x17000011 RID: 17
// (get) Token: 0x06000033 RID: 51 RVA: 0x00002E84 File Offset: 0x00001284
public static SMAA.TemporalSettings defaultSettings
{
get
{
return new SMAA.TemporalSettings
{
enabled = false,
fuzzSize = 2f
};
}
}
// Token: 0x04000042 RID: 66
[Tooltip("Temporal filtering makes it possible for the SMAA algorithm to benefit from minute subpixel information available that has been accumulated over many frames.")]
public bool enabled;
// Token: 0x04000043 RID: 67
[Range(0.5f, 10f)]
[Tooltip("The size of the fuzz-displacement (jitter) in pixels applied to the camera's perspective projection matrix.\nUsed for 2x temporal anti-aliasing.")]
public float fuzzSize;
}
// Token: 0x02000014 RID: 20
[Serializable]
public struct PredicationSettings
{
// Token: 0x17000012 RID: 18
// (get) Token: 0x06000034 RID: 52 RVA: 0x00002EB0 File Offset: 0x000012B0
public static SMAA.PredicationSettings defaultSettings
{
get
{
return new SMAA.PredicationSettings
{
enabled = false,
threshold = 0.01f,
scale = 2f,
strength = 0.4f
};
}
}
// Token: 0x04000044 RID: 68
[Tooltip("Predicated thresholding allows to better preserve texture details and to improve performance, by decreasing the number of detected edges using an additional buffer (the detph buffer).\nIt locally decreases the luma or color threshold if an edge is found in an additional buffer (so the global threshold can be higher).")]
public bool enabled;
// Token: 0x04000045 RID: 69
[Min(0.0001f)]
[Tooltip("Threshold to be used in the additional predication buffer.")]
public float threshold;
// Token: 0x04000046 RID: 70
[Range(1f, 5f)]
[Tooltip("How much to scale the global threshold used for luma or color edge detection when using predication.")]
public float scale;
// Token: 0x04000047 RID: 71
[Range(0f, 1f)]
[Tooltip("How much to locally decrease the threshold.")]
public float strength;
}
}
}