initial commit
This commit is contained in:
@@ -0,0 +1,96 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace UnityStandardAssets.CinematicEffects
|
||||
{
|
||||
[ExecuteInEditMode]
|
||||
[RequireComponent(typeof(Camera))]
|
||||
[AddComponentMenu("Image Effects/Cinematic/Anti-aliasing")]
|
||||
#if UNITY_5_4_OR_NEWER
|
||||
[ImageEffectAllowedInSceneView]
|
||||
#endif
|
||||
public class AntiAliasing : MonoBehaviour
|
||||
{
|
||||
public enum Method
|
||||
{
|
||||
Smaa,
|
||||
Fxaa
|
||||
}
|
||||
|
||||
[SerializeField]
|
||||
private SMAA m_SMAA = new SMAA();
|
||||
|
||||
[SerializeField]
|
||||
private FXAA m_FXAA = new FXAA();
|
||||
|
||||
[SerializeField, HideInInspector]
|
||||
private int m_Method = (int)Method.Smaa;
|
||||
public int method
|
||||
{
|
||||
get { return m_Method; }
|
||||
|
||||
set
|
||||
{
|
||||
if (m_Method == value)
|
||||
return;
|
||||
|
||||
m_Method = value;
|
||||
}
|
||||
}
|
||||
|
||||
public IAntiAliasing current
|
||||
{
|
||||
get
|
||||
{
|
||||
if (method == (int)Method.Smaa)
|
||||
return m_SMAA;
|
||||
else
|
||||
return m_FXAA;
|
||||
}
|
||||
}
|
||||
|
||||
private Camera m_Camera;
|
||||
public Camera cameraComponent
|
||||
{
|
||||
get
|
||||
{
|
||||
if (m_Camera == null)
|
||||
m_Camera = GetComponent<Camera>();
|
||||
|
||||
return m_Camera;
|
||||
}
|
||||
}
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
m_SMAA.Awake();
|
||||
m_FXAA.Awake();
|
||||
}
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
m_SMAA.OnEnable(this);
|
||||
m_FXAA.OnEnable(this);
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
m_SMAA.OnDisable();
|
||||
m_FXAA.OnDisable();
|
||||
}
|
||||
|
||||
private void OnPreCull()
|
||||
{
|
||||
current.OnPreCull(cameraComponent);
|
||||
}
|
||||
|
||||
private void OnPostRender()
|
||||
{
|
||||
current.OnPostRender(cameraComponent);
|
||||
}
|
||||
|
||||
private void OnRenderImage(RenderTexture source, RenderTexture destination)
|
||||
{
|
||||
current.OnRenderImage(cameraComponent, source, destination);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: fdc35e0180670ab4e8d2f9439137791f
|
||||
timeCreated: 1454589503
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 738f82ccf57b5974cb672f8032c72169
|
||||
folderAsset: yes
|
||||
timeCreated: 1454595975
|
||||
licenseType: Store
|
||||
DefaultImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,64 @@
|
||||
using System;
|
||||
using UnityEditor;
|
||||
|
||||
namespace UnityStandardAssets.CinematicEffects
|
||||
{
|
||||
[CustomEditor(typeof(AntiAliasing))]
|
||||
public class AntiAliasingEditor : Editor
|
||||
{
|
||||
private string[] methodNames =
|
||||
{
|
||||
"Subpixel Morphological Anti-aliasing",
|
||||
"Fast Approximate Anti-aliasing"
|
||||
};
|
||||
|
||||
private int m_SelectedMethod;
|
||||
|
||||
private SMAAEditor m_SMAAEditor = new SMAAEditor();
|
||||
private FXAAEditor m_FXAAEditor = new FXAAEditor();
|
||||
|
||||
IAntiAliasingEditor m_AntiAliasingEditor;
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
m_SMAAEditor.OnEnable(serializedObject, "m_SMAA");
|
||||
m_FXAAEditor.OnEnable(serializedObject, "m_FXAA");
|
||||
}
|
||||
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
var antiAliasingTarget = (AntiAliasing)target;
|
||||
|
||||
m_SelectedMethod = antiAliasingTarget.method;
|
||||
|
||||
EditorGUI.BeginChangeCheck();
|
||||
m_SelectedMethod = EditorGUILayout.Popup("Method", m_SelectedMethod, methodNames);
|
||||
|
||||
bool dirty = false;
|
||||
|
||||
if (EditorGUI.EndChangeCheck())
|
||||
{
|
||||
if (m_SelectedMethod < 0)
|
||||
m_SelectedMethod = 0;
|
||||
else if (m_SelectedMethod > 1)
|
||||
m_SelectedMethod = 1;
|
||||
|
||||
antiAliasingTarget.method = m_SelectedMethod;
|
||||
dirty = true;
|
||||
}
|
||||
|
||||
if (m_SelectedMethod == 0)
|
||||
m_AntiAliasingEditor = m_SMAAEditor;
|
||||
else
|
||||
m_AntiAliasingEditor = m_FXAAEditor;
|
||||
|
||||
dirty |= m_AntiAliasingEditor.OnInspectorGUI(antiAliasingTarget.current);
|
||||
|
||||
if (dirty)
|
||||
{
|
||||
EditorUtility.SetDirty(antiAliasingTarget);
|
||||
serializedObject.ApplyModifiedProperties();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6bd9375ab74a65448b556b0452e8c6af
|
||||
timeCreated: 1454593885
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,10 @@
|
||||
using UnityEditor;
|
||||
|
||||
namespace UnityStandardAssets.CinematicEffects
|
||||
{
|
||||
public interface IAntiAliasingEditor
|
||||
{
|
||||
void OnEnable(SerializedObject serializedObject, string path);
|
||||
bool OnInspectorGUI(IAntiAliasing target);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 015ee83e537e9e4438f403e2149c69ae
|
||||
timeCreated: 1454595240
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7629f5693f26f34448aa9c713d257e26
|
||||
folderAsset: yes
|
||||
timeCreated: 1453733554
|
||||
licenseType: Store
|
||||
DefaultImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 880813d23951c624d9d5c3e6d2a4e93c
|
||||
folderAsset: yes
|
||||
timeCreated: 1454331861
|
||||
licenseType: Store
|
||||
DefaultImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,57 @@
|
||||
using UnityEditor;
|
||||
|
||||
namespace UnityStandardAssets.CinematicEffects
|
||||
{
|
||||
public class FXAAEditor : IAntiAliasingEditor
|
||||
{
|
||||
private string[] presetNames =
|
||||
{
|
||||
"Extreme performance",
|
||||
"Performance",
|
||||
"Default",
|
||||
"Quality",
|
||||
"Extreme quality"
|
||||
};
|
||||
|
||||
|
||||
public void OnEnable(SerializedObject serializedObject, string path)
|
||||
{
|
||||
}
|
||||
|
||||
public bool OnInspectorGUI(IAntiAliasing target)
|
||||
{
|
||||
var fxaaTarget = (FXAA)target;
|
||||
|
||||
if (!fxaaTarget.validSourceFormat)
|
||||
EditorGUILayout.HelpBox("FXAA should be used at the end of the post-processing stack after conversion to LDR (after Tonemapping) to maximize quality and avoid artifacts.", MessageType.Warning);
|
||||
|
||||
int selectedPreset = 2;
|
||||
|
||||
if (fxaaTarget.preset.Equals(FXAA.Preset.extremePerformancePreset))
|
||||
selectedPreset = 0;
|
||||
else if (fxaaTarget.preset.Equals(FXAA.Preset.performancePreset))
|
||||
selectedPreset = 1;
|
||||
else if (fxaaTarget.preset.Equals(FXAA.Preset.defaultPreset))
|
||||
selectedPreset = 2;
|
||||
else if (fxaaTarget.preset.Equals(FXAA.Preset.qualityPreset))
|
||||
selectedPreset = 3;
|
||||
else if (fxaaTarget.preset.Equals(FXAA.Preset.extremeQualityPreset))
|
||||
selectedPreset = 4;
|
||||
|
||||
EditorGUI.BeginChangeCheck();
|
||||
selectedPreset = EditorGUILayout.Popup("Preset", selectedPreset, presetNames);
|
||||
|
||||
if (EditorGUI.EndChangeCheck())
|
||||
{
|
||||
if (selectedPreset < 0)
|
||||
selectedPreset = 0;
|
||||
else if (selectedPreset > 4)
|
||||
selectedPreset = 4;
|
||||
|
||||
fxaaTarget.preset = FXAA.availablePresets[selectedPreset];
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 60bfb637c85e3e04ea76962349fee327
|
||||
timeCreated: 1454331861
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,264 @@
|
||||
using UnityEngine;
|
||||
using System;
|
||||
|
||||
using Object = UnityEngine.Object;
|
||||
|
||||
namespace UnityStandardAssets.CinematicEffects
|
||||
{
|
||||
[Serializable]
|
||||
public class FXAA : IAntiAliasing
|
||||
{
|
||||
private Shader m_Shader;
|
||||
private Shader shader
|
||||
{
|
||||
get
|
||||
{
|
||||
if (m_Shader == null)
|
||||
m_Shader = Shader.Find("Hidden/Fast Approximate Anti-aliasing");
|
||||
|
||||
return m_Shader;
|
||||
}
|
||||
}
|
||||
|
||||
private Material m_Material;
|
||||
public Material material
|
||||
{
|
||||
get
|
||||
{
|
||||
if (m_Material == null)
|
||||
m_Material = ImageEffectHelper.CheckShaderAndCreateMaterial(shader);
|
||||
|
||||
return m_Material;
|
||||
}
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public struct QualitySettings
|
||||
{
|
||||
[Tooltip("The amount of desired sub-pixel aliasing removal. Effects the sharpeness of the output.")]
|
||||
[Range(0.0f, 1.0f)]
|
||||
public float subpixelAliasingRemovalAmount;
|
||||
|
||||
[Tooltip("The minimum amount of local contrast required to qualify a region as containing an edge.")]
|
||||
[Range(0.063f, 0.333f)]
|
||||
public float edgeDetectionThreshold;
|
||||
|
||||
[Tooltip("Local contrast adaptation value to disallow the algorithm from executing on the darker regions.")]
|
||||
[Range(0.0f, 0.0833f)]
|
||||
public float minimumRequiredLuminance;
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public struct ConsoleSettings
|
||||
{
|
||||
[Tooltip("The amount of spread applied to the sampling coordinates while sampling for subpixel information.")]
|
||||
[Range(0.33f, 0.5f)]
|
||||
public float subpixelSpreadAmount;
|
||||
|
||||
[Tooltip("This value dictates how sharp the edges in the image are kept; a higher value implies sharper edges.")]
|
||||
[Range(2.0f, 8.0f)]
|
||||
public float edgeSharpnessAmount;
|
||||
|
||||
[Tooltip("The minimum amount of local contrast required to qualify a region as containing an edge.")]
|
||||
[Range(0.125f, 0.25f)]
|
||||
public float edgeDetectionThreshold;
|
||||
|
||||
[Tooltip("Local contrast adaptation value to disallow the algorithm from executing on the darker regions.")]
|
||||
[Range(0.04f, 0.06f)]
|
||||
public float minimumRequiredLuminance;
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public struct Preset
|
||||
{
|
||||
[AttributeUsage(AttributeTargets.Field)]
|
||||
public class LayoutAttribute : PropertyAttribute
|
||||
{}
|
||||
|
||||
[Layout]
|
||||
public QualitySettings qualitySettings;
|
||||
|
||||
[Layout]
|
||||
public ConsoleSettings consoleSettings;
|
||||
|
||||
private static readonly Preset s_ExtremePerformance = new Preset
|
||||
{
|
||||
qualitySettings = new QualitySettings
|
||||
{
|
||||
subpixelAliasingRemovalAmount = 0.0f,
|
||||
edgeDetectionThreshold = 0.333f,
|
||||
minimumRequiredLuminance = 0.0833f
|
||||
},
|
||||
|
||||
consoleSettings = new ConsoleSettings
|
||||
{
|
||||
subpixelSpreadAmount = 0.33f,
|
||||
edgeSharpnessAmount = 8.0f,
|
||||
edgeDetectionThreshold = 0.25f,
|
||||
minimumRequiredLuminance = 0.06f
|
||||
}
|
||||
};
|
||||
|
||||
private static readonly Preset s_Performance = new Preset
|
||||
{
|
||||
qualitySettings = new QualitySettings
|
||||
{
|
||||
subpixelAliasingRemovalAmount = 0.25f,
|
||||
edgeDetectionThreshold = 0.25f,
|
||||
minimumRequiredLuminance = 0.0833f
|
||||
},
|
||||
|
||||
consoleSettings = new ConsoleSettings
|
||||
{
|
||||
subpixelSpreadAmount = 0.33f,
|
||||
edgeSharpnessAmount = 8.0f,
|
||||
edgeDetectionThreshold = 0.125f,
|
||||
minimumRequiredLuminance = 0.06f
|
||||
}
|
||||
};
|
||||
|
||||
private static readonly Preset s_Default = new Preset
|
||||
{
|
||||
qualitySettings = new QualitySettings
|
||||
{
|
||||
subpixelAliasingRemovalAmount = 0.75f,
|
||||
edgeDetectionThreshold = 0.166f,
|
||||
minimumRequiredLuminance = 0.0833f
|
||||
},
|
||||
|
||||
consoleSettings = new ConsoleSettings
|
||||
{
|
||||
subpixelSpreadAmount = 0.5f,
|
||||
edgeSharpnessAmount = 8.0f,
|
||||
edgeDetectionThreshold = 0.125f,
|
||||
minimumRequiredLuminance = 0.05f
|
||||
}
|
||||
};
|
||||
|
||||
private static readonly Preset s_Quality = new Preset
|
||||
{
|
||||
qualitySettings = new QualitySettings
|
||||
{
|
||||
subpixelAliasingRemovalAmount = 1.0f,
|
||||
edgeDetectionThreshold = 0.125f,
|
||||
minimumRequiredLuminance = 0.0625f
|
||||
},
|
||||
|
||||
consoleSettings = new ConsoleSettings
|
||||
{
|
||||
subpixelSpreadAmount = 0.5f,
|
||||
edgeSharpnessAmount = 4.0f,
|
||||
edgeDetectionThreshold = 0.125f,
|
||||
minimumRequiredLuminance = 0.04f
|
||||
}
|
||||
};
|
||||
|
||||
private static readonly Preset s_ExtremeQuality = new Preset
|
||||
{
|
||||
qualitySettings = new QualitySettings
|
||||
{
|
||||
subpixelAliasingRemovalAmount = 1.0f,
|
||||
edgeDetectionThreshold = 0.063f,
|
||||
minimumRequiredLuminance = 0.0312f
|
||||
},
|
||||
|
||||
consoleSettings = new ConsoleSettings
|
||||
{
|
||||
subpixelSpreadAmount = 0.5f,
|
||||
edgeSharpnessAmount = 2.0f,
|
||||
edgeDetectionThreshold = 0.125f,
|
||||
minimumRequiredLuminance = 0.04f
|
||||
}
|
||||
};
|
||||
|
||||
public static Preset extremePerformancePreset
|
||||
{
|
||||
get { return s_ExtremePerformance; }
|
||||
}
|
||||
|
||||
public static Preset performancePreset
|
||||
{
|
||||
get { return s_Performance; }
|
||||
}
|
||||
|
||||
public static Preset defaultPreset
|
||||
{
|
||||
get { return s_Default; }
|
||||
}
|
||||
|
||||
public static Preset qualityPreset
|
||||
{
|
||||
get { return s_Quality; }
|
||||
}
|
||||
|
||||
public static Preset extremeQualityPreset
|
||||
{
|
||||
get { return s_ExtremeQuality; }
|
||||
}
|
||||
}
|
||||
|
||||
[SerializeField, HideInInspector]
|
||||
public Preset preset = Preset.defaultPreset;
|
||||
|
||||
public static Preset[] availablePresets =
|
||||
{
|
||||
Preset.extremePerformancePreset,
|
||||
Preset.performancePreset,
|
||||
Preset.defaultPreset,
|
||||
Preset.qualityPreset,
|
||||
Preset.extremeQualityPreset
|
||||
};
|
||||
|
||||
public bool validSourceFormat { get; private set; }
|
||||
|
||||
private int m_QualitySettings;
|
||||
private int m_ConsoleSettings;
|
||||
|
||||
public void Awake()
|
||||
{
|
||||
m_QualitySettings = Shader.PropertyToID("_QualitySettings");
|
||||
m_ConsoleSettings = Shader.PropertyToID("_ConsoleSettings");
|
||||
}
|
||||
|
||||
public void OnEnable(AntiAliasing owner)
|
||||
{
|
||||
if (!ImageEffectHelper.IsSupported(shader, true, false, owner))
|
||||
owner.enabled = false;
|
||||
}
|
||||
|
||||
public void OnDisable()
|
||||
{
|
||||
if (m_Material != null)
|
||||
Object.DestroyImmediate(m_Material);
|
||||
}
|
||||
|
||||
public void OnPreCull(Camera camera)
|
||||
{
|
||||
}
|
||||
|
||||
public void OnPostRender(Camera camera)
|
||||
{
|
||||
}
|
||||
|
||||
public void OnRenderImage(Camera camera, RenderTexture source, RenderTexture destination)
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
validSourceFormat = true;
|
||||
|
||||
if (source.format == RenderTextureFormat.ARGBHalf
|
||||
|| source.format == RenderTextureFormat.ARGBFloat
|
||||
|| source.format == RenderTextureFormat.ARGB2101010)
|
||||
validSourceFormat = false;
|
||||
#endif
|
||||
|
||||
material.SetVector(m_QualitySettings, new Vector3(preset.qualitySettings.subpixelAliasingRemovalAmount,
|
||||
preset.qualitySettings.edgeDetectionThreshold, preset.qualitySettings.minimumRequiredLuminance));
|
||||
|
||||
material.SetVector(m_ConsoleSettings, new Vector4(preset.consoleSettings.subpixelSpreadAmount,
|
||||
preset.consoleSettings.edgeSharpnessAmount, preset.consoleSettings.edgeDetectionThreshold,
|
||||
preset.consoleSettings.minimumRequiredLuminance));
|
||||
|
||||
Graphics.Blit(source, destination, material, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8ca0fe85db4ef594fb0771b250c00e23
|
||||
timeCreated: 1453738651
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences:
|
||||
- shader: {fileID: 4800000, guid: 3eaaee164ee0fed4d9a0bbe8434805a6, type: 3}
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3f7cc4a9005f5f846957997471c28f2b
|
||||
folderAsset: yes
|
||||
timeCreated: 1455022968
|
||||
licenseType: Store
|
||||
DefaultImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,106 @@
|
||||
// Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)'
|
||||
|
||||
Shader "Hidden/Fast Approximate Anti-aliasing"
|
||||
{
|
||||
Properties
|
||||
{
|
||||
_MainTex ("Texture", 2D) = "white" {}
|
||||
}
|
||||
|
||||
CGINCLUDE
|
||||
#pragma fragmentoption ARB_precision_hint_fastest
|
||||
|
||||
#if defined(SHADER_API_PS3)
|
||||
#define FXAA_PS3 1
|
||||
|
||||
// Shaves off 2 cycles from the shader
|
||||
#define FXAA_EARLY_EXIT 0
|
||||
#elif defined(SHADER_API_XBOX360)
|
||||
#define FXAA_360 1
|
||||
|
||||
// Shaves off 10ms from the shader's execution time
|
||||
#define FXAA_EARLY_EXIT 1
|
||||
#else
|
||||
#define FXAA_PC 1
|
||||
#endif
|
||||
|
||||
#define FXAA_HLSL_3 1
|
||||
#define FXAA_QUALITY__PRESET 39
|
||||
|
||||
#define FXAA_GREEN_AS_LUMA 1
|
||||
|
||||
#pragma target 3.0
|
||||
#include "FXAA3.cginc"
|
||||
|
||||
float4 _MainTex_TexelSize;
|
||||
|
||||
float3 _QualitySettings;
|
||||
float4 _ConsoleSettings;
|
||||
|
||||
struct Input
|
||||
{
|
||||
float4 position : POSITION;
|
||||
float2 uv : TEXCOORD0;
|
||||
};
|
||||
|
||||
struct Varying
|
||||
{
|
||||
float4 position : SV_POSITION;
|
||||
float2 uv : TEXCOORD0;
|
||||
};
|
||||
|
||||
Varying vertex(Input input)
|
||||
{
|
||||
Varying output;
|
||||
|
||||
output.position = UnityObjectToClipPos(input.position);
|
||||
output.uv = input.uv;
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
sampler2D _MainTex;
|
||||
|
||||
float calculateLuma(float4 color)
|
||||
{
|
||||
return color.g * 1.963211 + color.r;
|
||||
}
|
||||
|
||||
fixed4 fragment(Varying input) : SV_Target
|
||||
{
|
||||
const float4 consoleUV = input.uv.xyxy + .5 * float4(-_MainTex_TexelSize.xy, _MainTex_TexelSize.xy);
|
||||
const float4 consoleSubpixelFrame = _ConsoleSettings.x * float4(-1., -1., 1., 1.) *
|
||||
_MainTex_TexelSize.xyxy;
|
||||
|
||||
const float4 consoleSubpixelFramePS3 = float4(-2., -2., 2., 2.) * _MainTex_TexelSize.xyxy;
|
||||
const float4 consoleSubpixelFrameXBOX = float4(8., 8., -4., -4.) * _MainTex_TexelSize.xyxy;
|
||||
|
||||
#if defined(SHADER_API_XBOX360)
|
||||
const float4 consoleConstants = float4(1., -1., .25, -.25);
|
||||
#else
|
||||
const float4 consoleConstants = float4(0., 0., 0., 0.);
|
||||
#endif
|
||||
|
||||
return FxaaPixelShader(input.uv, consoleUV, _MainTex, _MainTex, _MainTex, _MainTex_TexelSize.xy,
|
||||
consoleSubpixelFrame, consoleSubpixelFramePS3, consoleSubpixelFrameXBOX,
|
||||
_QualitySettings.x, _QualitySettings.y, _QualitySettings.z, _ConsoleSettings.y, _ConsoleSettings.z,
|
||||
_ConsoleSettings.w, consoleConstants);
|
||||
}
|
||||
ENDCG
|
||||
|
||||
SubShader
|
||||
{
|
||||
ZTest Always Cull Off ZWrite Off
|
||||
Fog { Mode off }
|
||||
|
||||
Pass
|
||||
{
|
||||
CGPROGRAM
|
||||
#pragma vertex vertex
|
||||
#pragma fragment fragment
|
||||
|
||||
#include "UnityCG.cginc"
|
||||
ENDCG
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3eaaee164ee0fed4d9a0bbe8434805a6
|
||||
timeCreated: 1453736553
|
||||
licenseType: Store
|
||||
ShaderImporter:
|
||||
defaultTextures: []
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b44d2ca11a7157e4db9f1e02f5249f95
|
||||
timeCreated: 1453990603
|
||||
licenseType: Store
|
||||
ShaderImporter:
|
||||
defaultTextures: []
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,14 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace UnityStandardAssets.CinematicEffects
|
||||
{
|
||||
public interface IAntiAliasing
|
||||
{
|
||||
void Awake();
|
||||
void OnEnable(AntiAliasing owner);
|
||||
void OnDisable();
|
||||
void OnPreCull(Camera camera);
|
||||
void OnPostRender(Camera camera);
|
||||
void OnRenderImage(Camera camera, RenderTexture source, RenderTexture destination);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 90329fa7c7a616243a47de84e6e5c041
|
||||
timeCreated: 1454590083
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d958f8498dd28db459dc41b661331fc8
|
||||
folderAsset: yes
|
||||
timeCreated: 1446717353
|
||||
licenseType: Store
|
||||
DefaultImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3ab9eab0d04085b4abd47b6b0657143c
|
||||
folderAsset: yes
|
||||
timeCreated: 1430588699
|
||||
licenseType: Store
|
||||
DefaultImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,106 @@
|
||||
using UnityEditor;
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
using System.Reflection;
|
||||
using UnityEngine.Serialization;
|
||||
|
||||
namespace UnityStandardAssets.CinematicEffects
|
||||
{
|
||||
public class SMAAEditor : IAntiAliasingEditor
|
||||
{
|
||||
private List<SerializedProperty> m_TopLevelFields = new List<SerializedProperty>();
|
||||
|
||||
[Serializable]
|
||||
class InfoMap
|
||||
{
|
||||
public string name;
|
||||
public bool experimental;
|
||||
public bool quality;
|
||||
public List<SerializedProperty> properties;
|
||||
}
|
||||
private List<InfoMap> m_GroupFields = new List<InfoMap>();
|
||||
|
||||
public void OnEnable(SerializedObject serializedObject, string path)
|
||||
{
|
||||
var topLevelSettings = typeof(SMAA).GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance).Where(x => x.GetCustomAttributes(typeof(SMAA.TopLevelSettings), false).Any());
|
||||
var settingsGroups = typeof(SMAA).GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance).Where(x => x.GetCustomAttributes(typeof(SMAA.SettingsGroup), false).Any());
|
||||
|
||||
foreach (var group in topLevelSettings)
|
||||
{
|
||||
var searchPath = path + "." + group.Name + ".";
|
||||
|
||||
foreach (var setting in group.FieldType.GetFields(BindingFlags.Instance | BindingFlags.Public))
|
||||
{
|
||||
var property = serializedObject.FindProperty(searchPath + setting.Name);
|
||||
if (property != null)
|
||||
m_TopLevelFields.Add(property);
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var group in settingsGroups)
|
||||
{
|
||||
var searchPath = path + "." + group.Name + ".";
|
||||
|
||||
foreach (var setting in group.FieldType.GetFields(BindingFlags.Instance | BindingFlags.Public))
|
||||
{
|
||||
var infoGroup = m_GroupFields.FirstOrDefault(x => x.name == group.Name);
|
||||
if (infoGroup == null)
|
||||
{
|
||||
infoGroup = new InfoMap();
|
||||
infoGroup.properties = new List<SerializedProperty>();
|
||||
infoGroup.name = group.Name;
|
||||
infoGroup.quality = group.FieldType == typeof(SMAA.QualitySettings);
|
||||
infoGroup.experimental = group.GetCustomAttributes(typeof(SMAA.ExperimentalGroup), false).Length > 0;
|
||||
m_GroupFields.Add(infoGroup);
|
||||
}
|
||||
|
||||
var property = serializedObject.FindProperty(searchPath + setting.Name);
|
||||
if (property != null)
|
||||
{
|
||||
infoGroup.properties.Add(property);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool OnInspectorGUI(IAntiAliasing target)
|
||||
{
|
||||
EditorGUI.BeginChangeCheck();
|
||||
|
||||
foreach (var setting in m_TopLevelFields)
|
||||
EditorGUILayout.PropertyField(setting);
|
||||
|
||||
foreach (var group in m_GroupFields)
|
||||
{
|
||||
if (group.quality && (target as SMAA).settings.quality != SMAA.QualityPreset.Custom)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
string title = ObjectNames.NicifyVariableName(group.name);
|
||||
if (group.experimental)
|
||||
title += " (Experimental)";
|
||||
|
||||
EditorGUILayout.Space();
|
||||
EditorGUILayout.LabelField(title, EditorStyles.boldLabel);
|
||||
EditorGUI.indentLevel++;
|
||||
|
||||
var enabledField = group.properties.FirstOrDefault(x => x.propertyPath == "m_SMAA." + group.name + ".enabled");
|
||||
if (enabledField != null && !enabledField.boolValue)
|
||||
{
|
||||
EditorGUILayout.PropertyField(enabledField);
|
||||
EditorGUI.indentLevel--;
|
||||
continue;
|
||||
}
|
||||
|
||||
foreach (var field in group.properties)
|
||||
EditorGUILayout.PropertyField(field);
|
||||
|
||||
EditorGUI.indentLevel--;
|
||||
}
|
||||
return EditorGUI.EndChangeCheck();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5c2ffc06b5a6ee64d8e1d9bdf074732c
|
||||
timeCreated: 1430643832
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9362798305520c448b294dd314a7daff
|
||||
folderAsset: yes
|
||||
timeCreated: 1430505545
|
||||
licenseType: Store
|
||||
DefaultImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 350 KiB |
@@ -0,0 +1,57 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e62aa7035ea66c94b90b2d8774d02cca
|
||||
timeCreated: 1432601000
|
||||
licenseType: Store
|
||||
TextureImporter:
|
||||
fileIDToRecycleName: {}
|
||||
serializedVersion: 2
|
||||
mipmaps:
|
||||
mipMapMode: 0
|
||||
enableMipMap: 0
|
||||
linearTexture: 1
|
||||
correctGamma: 0
|
||||
fadeOut: 0
|
||||
borderMipMap: 0
|
||||
mipMapFadeDistanceStart: 1
|
||||
mipMapFadeDistanceEnd: 3
|
||||
bumpmap:
|
||||
convertToNormalMap: 0
|
||||
externalNormalMap: 0
|
||||
heightScale: 0.25
|
||||
normalMapFilter: 0
|
||||
isReadable: 0
|
||||
grayScaleToAlpha: 0
|
||||
generateCubemap: 0
|
||||
cubemapConvolution: 0
|
||||
cubemapConvolutionSteps: 8
|
||||
cubemapConvolutionExponent: 1.5
|
||||
seamlessCubemap: 0
|
||||
textureFormat: -3
|
||||
maxTextureSize: 2048
|
||||
textureSettings:
|
||||
filterMode: 1
|
||||
aniso: 0
|
||||
mipBias: -1
|
||||
wrapMode: 1
|
||||
nPOTScale: 0
|
||||
lightmap: 0
|
||||
rGBM: 2
|
||||
compressionQuality: 50
|
||||
allowsAlphaSplitting: 0
|
||||
spriteMode: 0
|
||||
spriteExtrude: 1
|
||||
spriteMeshType: 1
|
||||
alignment: 0
|
||||
spritePivot: {x: 0.5, y: 0.5}
|
||||
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
|
||||
spritePixelsToUnits: 100
|
||||
alphaIsTransparency: 0
|
||||
textureType: 5
|
||||
buildTargetSettings: []
|
||||
spriteSheet:
|
||||
sprites: []
|
||||
outline: []
|
||||
spritePackingTag:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 74597699f47d8ae458dca68f79f1b21f
|
||||
timeCreated: 1430504573
|
||||
licenseType: Store
|
||||
ShaderImporter:
|
||||
defaultTextures: []
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,384 @@
|
||||
// Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)'
|
||||
|
||||
Shader "Hidden/Subpixel Morphological Anti-aliasing"
|
||||
{
|
||||
Properties
|
||||
{
|
||||
_MainTex ("Base (RGB)", 2D) = "white" {}
|
||||
}
|
||||
|
||||
CGINCLUDE
|
||||
|
||||
#pragma fragmentoption ARB_precision_hint_fastest
|
||||
#pragma target 3.0
|
||||
#pragma glsl
|
||||
#pragma exclude_renderers flash
|
||||
|
||||
sampler2D _MainTex;
|
||||
sampler2D _BlendTex;
|
||||
sampler2D _AreaTex;
|
||||
sampler2D _SearchTex;
|
||||
sampler2D _AccumulationTex;
|
||||
|
||||
sampler2D _CameraDepthTexture;
|
||||
|
||||
float4 _MainTex_TexelSize;
|
||||
|
||||
float4 _Metrics; // 1f / width, 1f / height, width, height
|
||||
float4 _Params1; // SMAA_THRESHOLD, SMAA_DEPTH_THRESHOLD, SMAA_MAX_SEARCH_STEPS, SMAA_MAX_SEARCH_STEPS_DIAG
|
||||
float2 _Params2; // SMAA_CORNER_ROUNDING, SMAA_LOCAL_CONTRAST_ADAPTATION_FACTOR
|
||||
float3 _Params3; // SMAA_PREDICATION_THRESHOLD, SMAA_PREDICATION_SCALE, SMAA_PREDICATION_STRENGTH
|
||||
|
||||
float4x4 _ReprojectionMatrix;
|
||||
float4 _SubsampleIndices;
|
||||
|
||||
#define SMAA_RT_METRICS _Metrics
|
||||
#define SMAA_THRESHOLD _Params1.x
|
||||
#define SMAA_DEPTH_THRESHOLD _Params1.y
|
||||
#define SMAA_MAX_SEARCH_STEPS _Params1.z
|
||||
#define SMAA_MAX_SEARCH_STEPS_DIAG _Params1.w
|
||||
#define SMAA_CORNER_ROUNDING _Params2.x
|
||||
#define SMAA_LOCAL_CONTRAST_ADAPTATION_FACTOR _Params2.y
|
||||
#define SMAA_PREDICATION_THRESHOLD _Params3.x
|
||||
#define SMAA_PREDICATION_SCALE _Params3.y
|
||||
#define SMAA_PREDICATION_STRENGTH _Params3.z
|
||||
|
||||
// Can't use SMAA_HLSL_3 as it won't compile with OpenGL, so lets make our own set of defines for Unity
|
||||
#define SMAA_CUSTOM_SL
|
||||
|
||||
#define mad(a, b, c) (a * b + c)
|
||||
#define SMAATexture2D(tex) sampler2D tex
|
||||
#define SMAATexturePass2D(tex) tex
|
||||
#define SMAASampleLevelZero(tex, coord) tex2Dlod(tex, float4(coord, 0.0, 0.0))
|
||||
#define SMAASampleLevelZeroPoint(tex, coord) tex2Dlod(tex, float4(coord, 0.0, 0.0))
|
||||
#define SMAASampleLevelZeroOffset(tex, coord, offset) tex2Dlod(tex, float4(coord + offset * SMAA_RT_METRICS.xy, 0.0, 0.0))
|
||||
#define SMAASample(tex, coord) tex2D(tex, coord)
|
||||
#define SMAASamplePoint(tex, coord) tex2D(tex, coord)
|
||||
#define SMAASampleOffset(tex, coord, offset) tex2D(tex, coord + offset * SMAA_RT_METRICS.xy)
|
||||
|
||||
#define SMAA_FLATTEN UNITY_FLATTEN
|
||||
#define SMAA_BRANCH UNITY_BRANCH
|
||||
// SMAA_CUSTOM_SL
|
||||
|
||||
#define SMAA_AREATEX_SELECT(sample) sample.rg
|
||||
#define SMAA_SEARCHTEX_SELECT(sample) sample.a
|
||||
#define SMAA_INCLUDE_VS 0
|
||||
|
||||
struct vInput
|
||||
{
|
||||
float4 pos : POSITION;
|
||||
float2 uv : TEXCOORD0;
|
||||
};
|
||||
|
||||
struct fInput_edge
|
||||
{
|
||||
float4 pos : SV_POSITION;
|
||||
float2 uv : TEXCOORD0;
|
||||
float4 offset[3] : TEXCOORD1;
|
||||
};
|
||||
|
||||
fInput_edge vert_edge(vInput i)
|
||||
{
|
||||
fInput_edge o;
|
||||
o.pos = UnityObjectToClipPos(i.pos);
|
||||
o.uv = i.uv;
|
||||
|
||||
#if UNITY_UV_STARTS_AT_TOP
|
||||
if (_MainTex_TexelSize.y < 0)
|
||||
o.uv.y = 1.0 - i.uv.y;
|
||||
#endif
|
||||
|
||||
o.offset[0] = mad(SMAA_RT_METRICS.xyxy, float4(-1.0, 0.0, 0.0, -1.0), o.uv.xyxy);
|
||||
o.offset[1] = mad(SMAA_RT_METRICS.xyxy, float4( 1.0, 0.0, 0.0, 1.0), o.uv.xyxy);
|
||||
o.offset[2] = mad(SMAA_RT_METRICS.xyxy, float4(-2.0, 0.0, 0.0, -2.0), o.uv.xyxy);
|
||||
return o;
|
||||
}
|
||||
|
||||
ENDCG
|
||||
|
||||
SubShader
|
||||
{
|
||||
ZTest Always Cull Off ZWrite Off
|
||||
Fog { Mode off }
|
||||
|
||||
// (0) Clear
|
||||
Pass
|
||||
{
|
||||
CGPROGRAM
|
||||
|
||||
#pragma vertex vert_img
|
||||
#pragma fragment frag
|
||||
#include "UnityCG.cginc"
|
||||
|
||||
float4 frag(v2f_img i) : SV_Target
|
||||
{
|
||||
return float4(0.0, 0.0, 0.0, 0.0);
|
||||
}
|
||||
|
||||
ENDCG
|
||||
}
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Edge Detection
|
||||
|
||||
// (1) Luma
|
||||
Pass
|
||||
{
|
||||
// TODO: Stencil not working
|
||||
// Stencil
|
||||
// {
|
||||
// Pass replace
|
||||
// Ref 1
|
||||
// }
|
||||
|
||||
CGPROGRAM
|
||||
|
||||
#pragma vertex vert_edge
|
||||
#pragma fragment frag
|
||||
#pragma multi_compile __ USE_PREDICATION
|
||||
|
||||
#if USE_PREDICATION
|
||||
#define SMAA_PREDICATION 1
|
||||
#else
|
||||
#define SMAA_PREDICATION 0
|
||||
#endif
|
||||
|
||||
#include "UnityCG.cginc"
|
||||
#include "SMAA.cginc"
|
||||
|
||||
float4 frag(fInput_edge i) : SV_Target
|
||||
{
|
||||
#if SMAA_PREDICATION
|
||||
return float4(SMAALumaEdgeDetectionPS(i.uv, i.offset, _MainTex, _CameraDepthTexture), 0.0, 0.0);
|
||||
#else
|
||||
return float4(SMAALumaEdgeDetectionPS(i.uv, i.offset, _MainTex), 0.0, 0.0);
|
||||
#endif
|
||||
}
|
||||
|
||||
ENDCG
|
||||
}
|
||||
|
||||
// (2) Color
|
||||
Pass
|
||||
{
|
||||
// TODO: Stencil not working
|
||||
// Stencil
|
||||
// {
|
||||
// Pass replace
|
||||
// Ref 1
|
||||
// }
|
||||
|
||||
CGPROGRAM
|
||||
|
||||
#pragma vertex vert_edge
|
||||
#pragma fragment frag
|
||||
#pragma multi_compile __ USE_PREDICATION
|
||||
|
||||
#if USE_PREDICATION
|
||||
#define SMAA_PREDICATION 1
|
||||
#else
|
||||
#define SMAA_PREDICATION 0
|
||||
#endif
|
||||
|
||||
#include "UnityCG.cginc"
|
||||
#include "SMAA.cginc"
|
||||
|
||||
float4 frag(fInput_edge i) : SV_Target
|
||||
{
|
||||
#if SMAA_PREDICATION
|
||||
return float4(SMAAColorEdgeDetectionPS(i.uv, i.offset, _MainTex, _CameraDepthTexture), 0.0, 0.0);
|
||||
#else
|
||||
return float4(SMAAColorEdgeDetectionPS(i.uv, i.offset, _MainTex), 0.0, 0.0);
|
||||
#endif
|
||||
}
|
||||
|
||||
ENDCG
|
||||
}
|
||||
|
||||
// (3) Depth
|
||||
Pass
|
||||
{
|
||||
// TODO: Stencil not working
|
||||
// Stencil
|
||||
// {
|
||||
// Pass replace
|
||||
// Ref 1
|
||||
// }
|
||||
|
||||
CGPROGRAM
|
||||
|
||||
#pragma vertex vert_edge
|
||||
#pragma fragment frag
|
||||
|
||||
#define SMAA_PREDICATION 0
|
||||
|
||||
#include "UnityCG.cginc"
|
||||
#include "SMAA.cginc"
|
||||
|
||||
float4 frag(fInput_edge i) : SV_Target
|
||||
{
|
||||
return float4(SMAADepthEdgeDetectionPS(i.uv, i.offset, _CameraDepthTexture), 0.0, 0.0);
|
||||
}
|
||||
|
||||
ENDCG
|
||||
}
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Blend Weights Calculation
|
||||
|
||||
// (4)
|
||||
Pass
|
||||
{
|
||||
// TODO: Stencil not working
|
||||
// Stencil
|
||||
// {
|
||||
// Pass keep
|
||||
// Comp equal
|
||||
// Ref 1
|
||||
// }
|
||||
|
||||
CGPROGRAM
|
||||
|
||||
#pragma vertex vert
|
||||
#pragma fragment frag
|
||||
#pragma multi_compile __ USE_DIAG_SEARCH
|
||||
#pragma multi_compile __ USE_CORNER_DETECTION
|
||||
|
||||
#if !defined(USE_DIAG_SEARCH)
|
||||
#define SMAA_DISABLE_DIAG_DETECTION
|
||||
#endif
|
||||
|
||||
#if !defined(USE_CORNER_DETECTION)
|
||||
#define SMAA_DISABLE_CORNER_DETECTION
|
||||
#endif
|
||||
|
||||
#include "UnityCG.cginc"
|
||||
#include "SMAA.cginc"
|
||||
|
||||
struct fInput
|
||||
{
|
||||
float4 pos : SV_POSITION;
|
||||
float2 uv : TEXCOORD0;
|
||||
float2 pixcoord : TEXCOORD1;
|
||||
float4 offset[3] : TEXCOORD2;
|
||||
};
|
||||
|
||||
fInput vert(vInput i)
|
||||
{
|
||||
fInput o;
|
||||
o.pos = UnityObjectToClipPos(i.pos);
|
||||
o.uv = i.uv;
|
||||
o.pixcoord = o.uv * SMAA_RT_METRICS.zw;
|
||||
|
||||
// We will use these offsets for the searches later on (see @PSEUDO_GATHER4):
|
||||
o.offset[0] = mad(SMAA_RT_METRICS.xyxy, float4(-0.25, -0.125, 1.25, -0.125), o.uv.xyxy);
|
||||
o.offset[1] = mad(SMAA_RT_METRICS.xyxy, float4(-0.125, -0.25, -0.125, 1.25), o.uv.xyxy);
|
||||
|
||||
// And these for the searches, they indicate the ends of the loops:
|
||||
o.offset[2] = mad(SMAA_RT_METRICS.xxyy, float4(-2.0, 2.0, -2.0, 2.0) * float(SMAA_MAX_SEARCH_STEPS),
|
||||
float4(o.offset[0].xz, o.offset[1].yw));
|
||||
|
||||
return o;
|
||||
}
|
||||
|
||||
float4 frag(fInput i) : SV_Target
|
||||
{
|
||||
return SMAABlendingWeightCalculationPS(i.uv, i.pixcoord, i.offset, _MainTex, _AreaTex, _SearchTex,
|
||||
_SubsampleIndices);
|
||||
}
|
||||
|
||||
ENDCG
|
||||
}
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Neighborhood Blending
|
||||
|
||||
// (5)
|
||||
Pass
|
||||
{
|
||||
CGPROGRAM
|
||||
|
||||
#pragma vertex vert
|
||||
#pragma fragment frag
|
||||
|
||||
#pragma multi_compile __ USE_UV_BASED_REPROJECTION
|
||||
|
||||
#if defined (USE_UV_BASED_REPROJECTION)
|
||||
#define SMAA_UV_BASED_REPROJECTION 1
|
||||
#endif
|
||||
|
||||
#include "UnityCG.cginc"
|
||||
#include "SMAA.cginc"
|
||||
|
||||
struct fInput
|
||||
{
|
||||
float4 pos : SV_POSITION;
|
||||
float2 uv : TEXCOORD0;
|
||||
float4 offset : TEXCOORD1;
|
||||
};
|
||||
|
||||
fInput vert(vInput i)
|
||||
{
|
||||
fInput o;
|
||||
o.pos = UnityObjectToClipPos(i.pos);
|
||||
o.uv = i.uv;
|
||||
o.offset = mad(SMAA_RT_METRICS.xyxy, float4(1.0, 0.0, 0.0, 1.0), o.uv.xyxy);
|
||||
return o;
|
||||
}
|
||||
|
||||
float4 frag(fInput i) : SV_Target
|
||||
{
|
||||
return SMAANeighborhoodBlendingPS(i.uv, i.offset, _MainTex, _BlendTex);
|
||||
}
|
||||
|
||||
ENDCG
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Accumulation Resolve
|
||||
|
||||
// (6)
|
||||
Pass
|
||||
{
|
||||
CGPROGRAM
|
||||
|
||||
#pragma vertex vert
|
||||
#pragma fragment frag
|
||||
|
||||
#pragma multi_compile __ USE_UV_BASED_REPROJECTION
|
||||
|
||||
#if defined (USE_UV_BASED_REPROJECTION)
|
||||
#define SMAA_UV_BASED_REPROJECTION 1
|
||||
#endif
|
||||
|
||||
#include "UnityCG.cginc"
|
||||
#include "SMAA.cginc"
|
||||
|
||||
struct fInput
|
||||
{
|
||||
float4 pos : SV_POSITION;
|
||||
float2 uv : TEXCOORD0;
|
||||
};
|
||||
|
||||
fInput vert(vInput i)
|
||||
{
|
||||
fInput o;
|
||||
o.pos = UnityObjectToClipPos(i.pos);
|
||||
o.uv = i.uv;
|
||||
return o;
|
||||
}
|
||||
|
||||
float4 frag(fInput i) : SV_Target
|
||||
{
|
||||
return SMAAResolvePS(i.uv, _MainTex, _AccumulationTex);
|
||||
}
|
||||
|
||||
ENDCG
|
||||
}
|
||||
}
|
||||
|
||||
FallBack off
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4505fec7a81214243b8e59edf89e3a53
|
||||
timeCreated: 1432603500
|
||||
licenseType: Store
|
||||
ShaderImporter:
|
||||
defaultTextures: []
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 3.0 KiB |
@@ -0,0 +1,57 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 387ed7c38eb63554db846987adb98e68
|
||||
timeCreated: 1432601000
|
||||
licenseType: Store
|
||||
TextureImporter:
|
||||
fileIDToRecycleName: {}
|
||||
serializedVersion: 2
|
||||
mipmaps:
|
||||
mipMapMode: 0
|
||||
enableMipMap: 0
|
||||
linearTexture: 1
|
||||
correctGamma: 0
|
||||
fadeOut: 0
|
||||
borderMipMap: 0
|
||||
mipMapFadeDistanceStart: 1
|
||||
mipMapFadeDistanceEnd: 3
|
||||
bumpmap:
|
||||
convertToNormalMap: 0
|
||||
externalNormalMap: 0
|
||||
heightScale: 0.25
|
||||
normalMapFilter: 0
|
||||
isReadable: 0
|
||||
grayScaleToAlpha: 1
|
||||
generateCubemap: 0
|
||||
cubemapConvolution: 0
|
||||
cubemapConvolutionSteps: 8
|
||||
cubemapConvolutionExponent: 1.5
|
||||
seamlessCubemap: 0
|
||||
textureFormat: 1
|
||||
maxTextureSize: 2048
|
||||
textureSettings:
|
||||
filterMode: 0
|
||||
aniso: -1
|
||||
mipBias: -1
|
||||
wrapMode: 1
|
||||
nPOTScale: 0
|
||||
lightmap: 0
|
||||
rGBM: 2
|
||||
compressionQuality: 50
|
||||
allowsAlphaSplitting: 0
|
||||
spriteMode: 0
|
||||
spriteExtrude: 1
|
||||
spriteMeshType: 1
|
||||
alignment: 0
|
||||
spritePivot: {x: 0.5, y: 0.5}
|
||||
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
|
||||
spritePixelsToUnits: 100
|
||||
alphaIsTransparency: 0
|
||||
textureType: 5
|
||||
buildTargetSettings: []
|
||||
spriteSheet:
|
||||
sprites: []
|
||||
outline: []
|
||||
spritePackingTag:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,507 @@
|
||||
using UnityEngine;
|
||||
using System;
|
||||
#if UNITY_EDITOR
|
||||
using UnityEditor;
|
||||
#endif
|
||||
using Object = UnityEngine.Object;
|
||||
|
||||
namespace UnityStandardAssets.CinematicEffects
|
||||
{
|
||||
[Serializable]
|
||||
public class SMAA : IAntiAliasing
|
||||
{
|
||||
[AttributeUsage(AttributeTargets.Field)]
|
||||
public class SettingsGroup : Attribute
|
||||
{}
|
||||
|
||||
[AttributeUsage(AttributeTargets.Field)]
|
||||
public class TopLevelSettings : Attribute
|
||||
{}
|
||||
|
||||
[AttributeUsage(AttributeTargets.Field)]
|
||||
public class ExperimentalGroup : Attribute
|
||||
{}
|
||||
|
||||
public enum DebugPass
|
||||
{
|
||||
Off,
|
||||
Edges,
|
||||
Weights,
|
||||
Accumulation
|
||||
}
|
||||
|
||||
public enum QualityPreset
|
||||
{
|
||||
Low = 0,
|
||||
Medium = 1,
|
||||
High = 2,
|
||||
Ultra = 3,
|
||||
Custom
|
||||
}
|
||||
|
||||
public enum EdgeDetectionMethod
|
||||
{
|
||||
Luma = 1,
|
||||
Color = 2,
|
||||
Depth = 3
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public struct GlobalSettings
|
||||
{
|
||||
[Tooltip("Use this to fine tune your settings when working in Custom quality mode. \"Accumulation\" only works when \"Temporal Filtering\" is enabled.")]
|
||||
public DebugPass debugPass;
|
||||
|
||||
[Tooltip("Low: 60% of the quality.\nMedium: 80% of the quality.\nHigh: 95% of the quality.\nUltra: 99% of the quality (overkill).")]
|
||||
public QualityPreset quality;
|
||||
|
||||
[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 EdgeDetectionMethod edgeDetectionMethod;
|
||||
|
||||
public static GlobalSettings defaultSettings
|
||||
{
|
||||
get
|
||||
{
|
||||
return new GlobalSettings
|
||||
{
|
||||
debugPass = DebugPass.Off,
|
||||
quality = QualityPreset.High,
|
||||
edgeDetectionMethod = EdgeDetectionMethod.Color
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public struct QualitySettings
|
||||
{
|
||||
[Tooltip("Enables/Disables diagonal processing.")]
|
||||
public bool diagonalDetection;
|
||||
|
||||
[Tooltip("Enables/Disables corner detection. Leave this on to avoid blurry corners.")]
|
||||
public bool cornerDetection;
|
||||
|
||||
[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;
|
||||
|
||||
[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;
|
||||
|
||||
[Range(0, 112)]
|
||||
[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;
|
||||
|
||||
[Range(0, 20)]
|
||||
[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;
|
||||
|
||||
[Range(0, 100)]
|
||||
[Tooltip("Specifies how much sharp corners will be rounded.")]
|
||||
public int cornerRounding;
|
||||
|
||||
[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;
|
||||
|
||||
public static QualitySettings[] presetQualitySettings =
|
||||
{
|
||||
// Low
|
||||
new QualitySettings
|
||||
{
|
||||
diagonalDetection = false,
|
||||
cornerDetection = false,
|
||||
threshold = 0.15f,
|
||||
depthThreshold = 0.01f,
|
||||
maxSearchSteps = 4,
|
||||
maxDiagonalSearchSteps = 8,
|
||||
cornerRounding = 25,
|
||||
localContrastAdaptationFactor = 2f
|
||||
},
|
||||
|
||||
// Medium
|
||||
new QualitySettings
|
||||
{
|
||||
diagonalDetection = false,
|
||||
cornerDetection = false,
|
||||
threshold = 0.1f,
|
||||
depthThreshold = 0.01f,
|
||||
maxSearchSteps = 8,
|
||||
maxDiagonalSearchSteps = 8,
|
||||
cornerRounding = 25,
|
||||
localContrastAdaptationFactor = 2f
|
||||
},
|
||||
|
||||
// High
|
||||
new QualitySettings
|
||||
{
|
||||
diagonalDetection = true,
|
||||
cornerDetection = true,
|
||||
threshold = 0.1f,
|
||||
depthThreshold = 0.01f,
|
||||
maxSearchSteps = 16,
|
||||
maxDiagonalSearchSteps = 8,
|
||||
cornerRounding = 25,
|
||||
localContrastAdaptationFactor = 2f
|
||||
},
|
||||
|
||||
// Ultra
|
||||
new QualitySettings
|
||||
{
|
||||
diagonalDetection = true,
|
||||
cornerDetection = true,
|
||||
threshold = 0.05f,
|
||||
depthThreshold = 0.01f,
|
||||
maxSearchSteps = 32,
|
||||
maxDiagonalSearchSteps = 16,
|
||||
cornerRounding = 25,
|
||||
localContrastAdaptationFactor = 2f
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public struct TemporalSettings
|
||||
{
|
||||
[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;
|
||||
|
||||
public bool UseTemporal()
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
return enabled && EditorApplication.isPlayingOrWillChangePlaymode;
|
||||
#else
|
||||
return enabled;
|
||||
#endif
|
||||
}
|
||||
|
||||
[Range(0.5f, 10.0f)]
|
||||
[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;
|
||||
|
||||
public static TemporalSettings defaultSettings
|
||||
{
|
||||
get
|
||||
{
|
||||
return new TemporalSettings
|
||||
{
|
||||
enabled = false,
|
||||
fuzzSize = 2f
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public struct PredicationSettings
|
||||
{
|
||||
[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;
|
||||
|
||||
[Min(0.0001f)]
|
||||
[Tooltip("Threshold to be used in the additional predication buffer.")]
|
||||
public float threshold;
|
||||
|
||||
[Range(1f, 5f)]
|
||||
[Tooltip("How much to scale the global threshold used for luma or color edge detection when using predication.")]
|
||||
public float scale;
|
||||
|
||||
[Range(0f, 1f)]
|
||||
[Tooltip("How much to locally decrease the threshold.")]
|
||||
public float strength;
|
||||
|
||||
public static PredicationSettings defaultSettings
|
||||
{
|
||||
get
|
||||
{
|
||||
return new PredicationSettings
|
||||
{
|
||||
enabled = false,
|
||||
threshold = 0.01f,
|
||||
scale = 2f,
|
||||
strength = 0.4f
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[TopLevelSettings]
|
||||
public GlobalSettings settings = GlobalSettings.defaultSettings;
|
||||
|
||||
[SettingsGroup]
|
||||
public QualitySettings quality = QualitySettings.presetQualitySettings[2];
|
||||
|
||||
[SettingsGroup]
|
||||
public PredicationSettings predication = PredicationSettings.defaultSettings;
|
||||
|
||||
[SettingsGroup, ExperimentalGroup]
|
||||
public TemporalSettings temporal = TemporalSettings.defaultSettings;
|
||||
|
||||
private Matrix4x4 m_ProjectionMatrix;
|
||||
private Matrix4x4 m_PreviousViewProjectionMatrix;
|
||||
private float m_FlipFlop = 1.0f;
|
||||
private RenderTexture m_Accumulation;
|
||||
|
||||
private Shader m_Shader;
|
||||
public Shader shader
|
||||
{
|
||||
get
|
||||
{
|
||||
if (m_Shader == null)
|
||||
m_Shader = Shader.Find("Hidden/Subpixel Morphological Anti-aliasing");
|
||||
|
||||
return m_Shader;
|
||||
}
|
||||
}
|
||||
|
||||
private Texture2D m_AreaTexture;
|
||||
private Texture2D areaTexture
|
||||
{
|
||||
get
|
||||
{
|
||||
if (m_AreaTexture == null)
|
||||
m_AreaTexture = Resources.Load<Texture2D>("AreaTex");
|
||||
return m_AreaTexture;
|
||||
}
|
||||
}
|
||||
|
||||
private Texture2D m_SearchTexture;
|
||||
private Texture2D searchTexture
|
||||
{
|
||||
get
|
||||
{
|
||||
if (m_SearchTexture == null)
|
||||
m_SearchTexture = Resources.Load<Texture2D>("SearchTex");
|
||||
return m_SearchTexture;
|
||||
}
|
||||
}
|
||||
|
||||
private Material m_Material;
|
||||
private Material material
|
||||
{
|
||||
get
|
||||
{
|
||||
if (m_Material == null)
|
||||
m_Material = ImageEffectHelper.CheckShaderAndCreateMaterial(shader);
|
||||
|
||||
return m_Material;
|
||||
}
|
||||
}
|
||||
|
||||
private int m_AreaTex;
|
||||
private int m_SearchTex;
|
||||
private int m_Metrics;
|
||||
private int m_Params1;
|
||||
private int m_Params2;
|
||||
private int m_Params3;
|
||||
private int m_ReprojectionMatrix;
|
||||
private int m_SubsampleIndices;
|
||||
private int m_BlendTex;
|
||||
private int m_AccumulationTex;
|
||||
|
||||
public void Awake()
|
||||
{
|
||||
m_AreaTex = Shader.PropertyToID("_AreaTex");
|
||||
m_SearchTex = Shader.PropertyToID("_SearchTex");
|
||||
m_Metrics = Shader.PropertyToID("_Metrics");
|
||||
m_Params1 = Shader.PropertyToID("_Params1");
|
||||
m_Params2 = Shader.PropertyToID("_Params2");
|
||||
m_Params3 = Shader.PropertyToID("_Params3");
|
||||
m_ReprojectionMatrix = Shader.PropertyToID("_ReprojectionMatrix");
|
||||
m_SubsampleIndices = Shader.PropertyToID("_SubsampleIndices");
|
||||
m_BlendTex = Shader.PropertyToID("_BlendTex");
|
||||
m_AccumulationTex = Shader.PropertyToID("_AccumulationTex");
|
||||
}
|
||||
|
||||
public void OnEnable(AntiAliasing owner)
|
||||
{
|
||||
if (!ImageEffectHelper.IsSupported(shader, true, false, owner))
|
||||
owner.enabled = false;
|
||||
}
|
||||
|
||||
public void OnDisable()
|
||||
{
|
||||
// Cleanup
|
||||
if (m_Material != null)
|
||||
Object.DestroyImmediate(m_Material);
|
||||
|
||||
if (m_Accumulation != null)
|
||||
Object.DestroyImmediate(m_Accumulation);
|
||||
|
||||
m_Material = null;
|
||||
m_Accumulation = null;
|
||||
}
|
||||
|
||||
public void OnPreCull(Camera camera)
|
||||
{
|
||||
if (temporal.UseTemporal())
|
||||
{
|
||||
m_ProjectionMatrix = camera.projectionMatrix;
|
||||
m_FlipFlop -= (2.0f * m_FlipFlop);
|
||||
|
||||
Matrix4x4 fuzz = Matrix4x4.identity;
|
||||
|
||||
fuzz.m03 = (0.25f * m_FlipFlop) * temporal.fuzzSize / camera.pixelWidth;
|
||||
fuzz.m13 = (-0.25f * m_FlipFlop) * temporal.fuzzSize / camera.pixelHeight;
|
||||
|
||||
camera.projectionMatrix = fuzz * camera.projectionMatrix;
|
||||
}
|
||||
}
|
||||
|
||||
public void OnPostRender(Camera camera)
|
||||
{
|
||||
if (temporal.UseTemporal())
|
||||
camera.ResetProjectionMatrix();
|
||||
}
|
||||
|
||||
public void OnRenderImage(Camera camera, RenderTexture source, RenderTexture destination)
|
||||
{
|
||||
int width = camera.pixelWidth;
|
||||
int height = camera.pixelHeight;
|
||||
|
||||
bool isFirstFrame = false;
|
||||
|
||||
QualitySettings preset = quality;
|
||||
|
||||
if (settings.quality != QualityPreset.Custom)
|
||||
preset = QualitySettings.presetQualitySettings[(int)settings.quality];
|
||||
|
||||
// Pass IDs
|
||||
int passEdgeDetection = (int)settings.edgeDetectionMethod;
|
||||
int passBlendWeights = 4;
|
||||
int passNeighborhoodBlending = 5;
|
||||
int passResolve = 6;
|
||||
|
||||
// Reprojection setup
|
||||
var viewProjectionMatrix = GL.GetGPUProjectionMatrix(m_ProjectionMatrix, true) * camera.worldToCameraMatrix;
|
||||
|
||||
// Uniforms
|
||||
material.SetTexture(m_AreaTex, areaTexture);
|
||||
material.SetTexture(m_SearchTex, searchTexture);
|
||||
|
||||
material.SetVector(m_Metrics, new Vector4(1f / width, 1f / height, width, height));
|
||||
material.SetVector(m_Params1, new Vector4(preset.threshold, preset.depthThreshold, preset.maxSearchSteps, preset.maxDiagonalSearchSteps));
|
||||
material.SetVector(m_Params2, new Vector2(preset.cornerRounding, preset.localContrastAdaptationFactor));
|
||||
|
||||
material.SetMatrix(m_ReprojectionMatrix, m_PreviousViewProjectionMatrix * Matrix4x4.Inverse(viewProjectionMatrix));
|
||||
|
||||
float subsampleIndex = (m_FlipFlop < 0.0f) ? 2.0f : 1.0f;
|
||||
material.SetVector(m_SubsampleIndices, new Vector4(subsampleIndex, subsampleIndex, subsampleIndex, 0.0f));
|
||||
|
||||
// Handle predication & depth-based edge detection
|
||||
Shader.DisableKeyword("USE_PREDICATION");
|
||||
|
||||
if (settings.edgeDetectionMethod == EdgeDetectionMethod.Depth)
|
||||
{
|
||||
camera.depthTextureMode |= DepthTextureMode.Depth;
|
||||
}
|
||||
else if (predication.enabled)
|
||||
{
|
||||
camera.depthTextureMode |= DepthTextureMode.Depth;
|
||||
Shader.EnableKeyword("USE_PREDICATION");
|
||||
material.SetVector(m_Params3, new Vector3(predication.threshold, predication.scale, predication.strength));
|
||||
}
|
||||
|
||||
// Diag search & corner detection
|
||||
Shader.DisableKeyword("USE_DIAG_SEARCH");
|
||||
Shader.DisableKeyword("USE_CORNER_DETECTION");
|
||||
|
||||
if (preset.diagonalDetection)
|
||||
Shader.EnableKeyword("USE_DIAG_SEARCH");
|
||||
|
||||
if (preset.cornerDetection)
|
||||
Shader.EnableKeyword("USE_CORNER_DETECTION");
|
||||
|
||||
// UV-based reprojection (up to Unity 5.x)
|
||||
Shader.DisableKeyword("USE_UV_BASED_REPROJECTION");
|
||||
|
||||
if (temporal.UseTemporal())
|
||||
Shader.EnableKeyword("USE_UV_BASED_REPROJECTION");
|
||||
|
||||
// Persistent textures and lazy-initializations
|
||||
if (m_Accumulation == null || (m_Accumulation.width != width || m_Accumulation.height != height))
|
||||
{
|
||||
if (m_Accumulation)
|
||||
RenderTexture.ReleaseTemporary(m_Accumulation);
|
||||
|
||||
m_Accumulation = RenderTexture.GetTemporary(width, height, 0, source.format, RenderTextureReadWrite.Linear);
|
||||
m_Accumulation.hideFlags = HideFlags.HideAndDontSave;
|
||||
|
||||
isFirstFrame = true;
|
||||
}
|
||||
|
||||
RenderTexture rt1 = TempRT(width, height, source.format);
|
||||
Graphics.Blit(null, rt1, material, 0); // Clear
|
||||
|
||||
// Edge Detection
|
||||
Graphics.Blit(source, rt1, material, passEdgeDetection);
|
||||
|
||||
if (settings.debugPass == DebugPass.Edges)
|
||||
{
|
||||
Graphics.Blit(rt1, destination);
|
||||
}
|
||||
else
|
||||
{
|
||||
RenderTexture rt2 = TempRT(width, height, source.format);
|
||||
Graphics.Blit(null, rt2, material, 0); // Clear
|
||||
|
||||
// Blend Weights
|
||||
Graphics.Blit(rt1, rt2, material, passBlendWeights);
|
||||
|
||||
if (settings.debugPass == DebugPass.Weights)
|
||||
{
|
||||
Graphics.Blit(rt2, destination);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Neighborhood Blending
|
||||
material.SetTexture(m_BlendTex, rt2);
|
||||
|
||||
if (temporal.UseTemporal())
|
||||
{
|
||||
// Temporal filtering
|
||||
Graphics.Blit(source, rt1, material, passNeighborhoodBlending);
|
||||
|
||||
if (settings.debugPass == DebugPass.Accumulation)
|
||||
{
|
||||
Graphics.Blit(m_Accumulation, destination);
|
||||
}
|
||||
else if (!isFirstFrame)
|
||||
{
|
||||
material.SetTexture(m_AccumulationTex, m_Accumulation);
|
||||
Graphics.Blit(rt1, destination, material, passResolve);
|
||||
}
|
||||
else
|
||||
{
|
||||
Graphics.Blit(rt1, destination);
|
||||
}
|
||||
|
||||
//Graphics.Blit(rt1, m_Accumulation);
|
||||
Graphics.Blit(destination, m_Accumulation);
|
||||
RenderTexture.active = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
Graphics.Blit(source, destination, material, passNeighborhoodBlending);
|
||||
}
|
||||
}
|
||||
|
||||
RenderTexture.ReleaseTemporary(rt2);
|
||||
}
|
||||
|
||||
RenderTexture.ReleaseTemporary(rt1);
|
||||
|
||||
// Store the future-previous frame's view-projection matrix
|
||||
m_PreviousViewProjectionMatrix = viewProjectionMatrix;
|
||||
}
|
||||
|
||||
private RenderTexture TempRT(int width, int height, RenderTextureFormat format)
|
||||
{
|
||||
// Skip the depth & stencil buffer creation when DebugPass is set to avoid flickering
|
||||
// int depthStencilBits = DebugPass == DebugPass.Off ? 24 : 0;
|
||||
int depthStencilBits = 0;
|
||||
return RenderTexture.GetTemporary(width, height, depthStencilBits, format, RenderTextureReadWrite.Linear);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9c2502951f8f3e743917c441eba57d1c
|
||||
timeCreated: 1454511067
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences:
|
||||
- m_Shader: {fileID: 4800000, guid: 4505fec7a81214243b8e59edf89e3a53, type: 3}
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user