Commit 90a5e627 by Tim Reiter

added vignette and bloom (+several other standard asset image effect shaders)

parent 0d094b57
fileFormatVersion: 2
guid: 225198e07aaae3547a6d1f6e7177555f
folderAsset: yes
DefaultImporter:
userData:
assetBundleName:
using System;
using UnityEditor;
using UnityEngine;
namespace UnityStandardAssets.ImageEffects
{
[CustomEditor (typeof(BloomAndFlares))]
class BloomAndFlaresEditor : Editor
{
SerializedProperty tweakMode;
SerializedProperty screenBlendMode;
SerializedObject serObj;
SerializedProperty hdr;
SerializedProperty sepBlurSpread;
SerializedProperty useSrcAlphaAsMask;
SerializedProperty bloomIntensity;
SerializedProperty bloomthreshold;
SerializedProperty bloomBlurIterations;
SerializedProperty lensflares;
SerializedProperty hollywoodFlareBlurIterations;
SerializedProperty lensflareMode;
SerializedProperty hollyStretchWidth;
SerializedProperty lensflareIntensity;
SerializedProperty lensflarethreshold;
SerializedProperty flareColorA;
SerializedProperty flareColorB;
SerializedProperty flareColorC;
SerializedProperty flareColorD;
SerializedProperty lensFlareVignetteMask;
void OnEnable () {
serObj = new SerializedObject (target);
screenBlendMode = serObj.FindProperty("screenBlendMode");
hdr = serObj.FindProperty("hdr");
sepBlurSpread = serObj.FindProperty("sepBlurSpread");
useSrcAlphaAsMask = serObj.FindProperty("useSrcAlphaAsMask");
bloomIntensity = serObj.FindProperty("bloomIntensity");
bloomthreshold = serObj.FindProperty("bloomThreshold");
bloomBlurIterations = serObj.FindProperty("bloomBlurIterations");
lensflares = serObj.FindProperty("lensflares");
lensflareMode = serObj.FindProperty("lensflareMode");
hollywoodFlareBlurIterations = serObj.FindProperty("hollywoodFlareBlurIterations");
hollyStretchWidth = serObj.FindProperty("hollyStretchWidth");
lensflareIntensity = serObj.FindProperty("lensflareIntensity");
lensflarethreshold = serObj.FindProperty("lensflareThreshold");
flareColorA = serObj.FindProperty("flareColorA");
flareColorB = serObj.FindProperty("flareColorB");
flareColorC = serObj.FindProperty("flareColorC");
flareColorD = serObj.FindProperty("flareColorD");
lensFlareVignetteMask = serObj.FindProperty("lensFlareVignetteMask");
tweakMode = serObj.FindProperty("tweakMode");
}
public override void OnInspectorGUI () {
serObj.Update();
GUILayout.Label("HDR " + (hdr.enumValueIndex == 0 ? "auto detected, " : (hdr.enumValueIndex == 1 ? "forced on, " : "disabled, ")) + (useSrcAlphaAsMask.floatValue < 0.1f ? " ignoring alpha channel glow information" : " using alpha channel glow information"), EditorStyles.miniBoldLabel);
EditorGUILayout.PropertyField (tweakMode, new GUIContent("Tweak mode"));
EditorGUILayout.PropertyField (screenBlendMode, new GUIContent("Blend mode"));
EditorGUILayout.PropertyField (hdr, new GUIContent("HDR"));
// display info text when screen blend mode cannot be used
Camera cam = (target as BloomAndFlares).GetComponent<Camera>();
if (cam != null) {
if (screenBlendMode.enumValueIndex==0 && ((cam.hdr && hdr.enumValueIndex==0) || (hdr.enumValueIndex==1))) {
EditorGUILayout.HelpBox("Screen blend is not supported in HDR. Using 'Add' instead.", MessageType.Info);
}
}
if (1 == tweakMode.intValue)
EditorGUILayout.PropertyField (lensflares, new GUIContent("Cast lens flares"));
EditorGUILayout.Separator ();
EditorGUILayout.PropertyField (bloomIntensity, new GUIContent("Intensity"));
bloomthreshold.floatValue = EditorGUILayout.Slider ("threshold", bloomthreshold.floatValue, -0.05f, 4.0f);
bloomBlurIterations.intValue = EditorGUILayout.IntSlider ("Blur iterations", bloomBlurIterations.intValue, 1, 4);
sepBlurSpread.floatValue = EditorGUILayout.Slider ("Blur spread", sepBlurSpread.floatValue, 0.1f, 10.0f);
if (1 == tweakMode.intValue)
useSrcAlphaAsMask.floatValue = EditorGUILayout.Slider (new GUIContent("Use alpha mask", "Make alpha channel define glowiness"), useSrcAlphaAsMask.floatValue, 0.0f, 1.0f);
else
useSrcAlphaAsMask.floatValue = 0.0f;
if (1 == tweakMode.intValue) {
EditorGUILayout.Separator ();
if (lensflares.boolValue) {
// further lens flare tweakings
if (0 != tweakMode.intValue)
EditorGUILayout.PropertyField (lensflareMode, new GUIContent("Lens flare mode"));
else
lensflareMode.enumValueIndex = 0;
EditorGUILayout.PropertyField(lensFlareVignetteMask, new GUIContent("Lens flare mask", "This mask is needed to prevent lens flare artifacts"));
EditorGUILayout.PropertyField (lensflareIntensity, new GUIContent("Local intensity"));
lensflarethreshold.floatValue = EditorGUILayout.Slider ("Local threshold", lensflarethreshold.floatValue, 0.0f, 1.0f);
if (lensflareMode.intValue == 0) {
// ghosting
EditorGUILayout.BeginHorizontal ();
EditorGUILayout.PropertyField (flareColorA, new GUIContent("1st Color"));
EditorGUILayout.PropertyField (flareColorB, new GUIContent("2nd Color"));
EditorGUILayout.EndHorizontal ();
EditorGUILayout.BeginHorizontal ();
EditorGUILayout.PropertyField (flareColorC, new GUIContent("3rd Color"));
EditorGUILayout.PropertyField (flareColorD, new GUIContent("4th Color"));
EditorGUILayout.EndHorizontal ();
}
else if (lensflareMode.intValue == 1) {
// hollywood
EditorGUILayout.PropertyField (hollyStretchWidth, new GUIContent("Stretch width"));
hollywoodFlareBlurIterations.intValue = EditorGUILayout.IntSlider ("Blur iterations", hollywoodFlareBlurIterations.intValue, 1, 4);
EditorGUILayout.PropertyField (flareColorA, new GUIContent("Tint Color"));
}
else if (lensflareMode.intValue == 2) {
// both
EditorGUILayout.PropertyField (hollyStretchWidth, new GUIContent("Stretch width"));
hollywoodFlareBlurIterations.intValue = EditorGUILayout.IntSlider ("Blur iterations", hollywoodFlareBlurIterations.intValue, 1, 4);
EditorGUILayout.BeginHorizontal ();
EditorGUILayout.PropertyField (flareColorA, new GUIContent("1st Color"));
EditorGUILayout.PropertyField (flareColorB, new GUIContent("2nd Color"));
EditorGUILayout.EndHorizontal ();
EditorGUILayout.BeginHorizontal ();
EditorGUILayout.PropertyField (flareColorC, new GUIContent("3rd Color"));
EditorGUILayout.PropertyField (flareColorD, new GUIContent("4th Color"));
EditorGUILayout.EndHorizontal ();
}
}
} else
lensflares.boolValue = false; // disable lens flares in simple tweak mode
serObj.ApplyModifiedProperties();
}
}
}
fileFormatVersion: 2
guid: 4deca87cb459d1642ac8f734856ca84e
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
using System;
using UnityEditor;
using UnityEngine;
namespace UnityStandardAssets.ImageEffects
{
[CustomEditor (typeof(Bloom))]
class BloomEditor : Editor
{
SerializedProperty tweakMode;
SerializedProperty screenBlendMode;
SerializedObject serObj;
SerializedProperty hdr;
SerializedProperty quality;
SerializedProperty sepBlurSpread;
SerializedProperty bloomIntensity;
SerializedProperty bloomThresholdColor;
SerializedProperty bloomThreshold;
SerializedProperty bloomBlurIterations;
SerializedProperty hollywoodFlareBlurIterations;
SerializedProperty lensflareMode;
SerializedProperty hollyStretchWidth;
SerializedProperty lensflareIntensity;
SerializedProperty flareRotation;
SerializedProperty lensFlareSaturation;
SerializedProperty lensflareThreshold;
SerializedProperty flareColorA;
SerializedProperty flareColorB;
SerializedProperty flareColorC;
SerializedProperty flareColorD;
SerializedProperty lensFlareVignetteMask;
void OnEnable () {
serObj = new SerializedObject (target);
screenBlendMode = serObj.FindProperty("screenBlendMode");
hdr = serObj.FindProperty("hdr");
quality = serObj.FindProperty("quality");
sepBlurSpread = serObj.FindProperty("sepBlurSpread");
bloomIntensity = serObj.FindProperty("bloomIntensity");
bloomThreshold = serObj.FindProperty("bloomThreshold");
bloomThresholdColor = serObj.FindProperty("bloomThresholdColor");
bloomBlurIterations = serObj.FindProperty("bloomBlurIterations");
lensflareMode = serObj.FindProperty("lensflareMode");
hollywoodFlareBlurIterations = serObj.FindProperty("hollywoodFlareBlurIterations");
hollyStretchWidth = serObj.FindProperty("hollyStretchWidth");
lensflareIntensity = serObj.FindProperty("lensflareIntensity");
lensflareThreshold = serObj.FindProperty("lensflareThreshold");
lensFlareSaturation = serObj.FindProperty("lensFlareSaturation");
flareRotation = serObj.FindProperty("flareRotation");
flareColorA = serObj.FindProperty("flareColorA");
flareColorB = serObj.FindProperty("flareColorB");
flareColorC = serObj.FindProperty("flareColorC");
flareColorD = serObj.FindProperty("flareColorD");
lensFlareVignetteMask = serObj.FindProperty("lensFlareVignetteMask");
tweakMode = serObj.FindProperty("tweakMode");
}
public override void OnInspectorGUI () {
serObj.Update();
EditorGUILayout.LabelField("Glow and Lens Flares for bright screen pixels", EditorStyles.miniLabel);
EditorGUILayout.PropertyField (quality, new GUIContent("Quality", "High quality preserves high frequencies with bigger blurs and uses a better blending and down-/upsampling"));
EditorGUILayout.Separator ();
EditorGUILayout.PropertyField (tweakMode, new GUIContent("Mode"));
EditorGUILayout.PropertyField (screenBlendMode, new GUIContent("Blend"));
EditorGUILayout.PropertyField (hdr, new GUIContent("HDR"));
EditorGUILayout.Separator ();
// display info text when screen blend mode cannot be used
Camera cam = (target as Bloom).GetComponent<Camera>();
if (cam != null) {
if (screenBlendMode.enumValueIndex==0 && ((cam.hdr && hdr.enumValueIndex==0) || (hdr.enumValueIndex==1))) {
EditorGUILayout.HelpBox("Screen blend is not supported in HDR. Using 'Add' instead.", MessageType.Info);
}
}
EditorGUILayout.PropertyField (bloomIntensity, new GUIContent("Intensity"));
bloomThreshold.floatValue = EditorGUILayout.Slider ("Threshold", bloomThreshold.floatValue, -0.05f, 4.0f);
if (1 == tweakMode.intValue) {
EditorGUILayout.PropertyField(bloomThresholdColor, new GUIContent(" RGB Threshold"));
}
EditorGUILayout.Separator ();
bloomBlurIterations.intValue = EditorGUILayout.IntSlider ("Blur Iterations", bloomBlurIterations.intValue, 1, 4);
sepBlurSpread.floatValue = EditorGUILayout.Slider (" Sample Distance", sepBlurSpread.floatValue, 0.1f, 10.0f);
EditorGUILayout.Separator ();
if (1 == tweakMode.intValue) {
// further lens flare tweakings
if (0 != tweakMode.intValue)
EditorGUILayout.PropertyField (lensflareMode, new GUIContent("Lens Flares"));
else
lensflareMode.enumValueIndex = 0;
EditorGUILayout.PropertyField (lensflareIntensity, new GUIContent(" Local Intensity", "0 disables lens flares entirely (optimization)"));
lensflareThreshold.floatValue = EditorGUILayout.Slider ("Threshold", lensflareThreshold.floatValue, 0.0f, 4.0f);
if (Mathf.Abs(lensflareIntensity.floatValue) > Mathf.Epsilon) {
if (lensflareMode.intValue == 0) {
// ghosting
EditorGUILayout.BeginHorizontal ();
EditorGUILayout.PropertyField (flareColorA, new GUIContent(" 1st Color"));
EditorGUILayout.PropertyField (flareColorB, new GUIContent(" 2nd Color"));
EditorGUILayout.EndHorizontal ();
EditorGUILayout.BeginHorizontal ();
EditorGUILayout.PropertyField (flareColorC, new GUIContent(" 3rd Color"));
EditorGUILayout.PropertyField (flareColorD, new GUIContent(" 4th Color"));
EditorGUILayout.EndHorizontal ();
}
else if (lensflareMode.intValue == 1) {
// hollywood
EditorGUILayout.PropertyField (hollyStretchWidth, new GUIContent(" Stretch width"));
EditorGUILayout.PropertyField (flareRotation, new GUIContent( " Rotation"));
hollywoodFlareBlurIterations.intValue = EditorGUILayout.IntSlider (" Blur Iterations", hollywoodFlareBlurIterations.intValue, 1, 4);
EditorGUILayout.PropertyField (lensFlareSaturation, new GUIContent(" Saturation"));
EditorGUILayout.PropertyField (flareColorA, new GUIContent(" Tint Color"));
}
else if (lensflareMode.intValue == 2) {
// both
EditorGUILayout.PropertyField (hollyStretchWidth, new GUIContent(" Stretch width"));
hollywoodFlareBlurIterations.intValue = EditorGUILayout.IntSlider (" Blur Iterations", hollywoodFlareBlurIterations.intValue, 1, 4);
EditorGUILayout.PropertyField (lensFlareSaturation, new GUIContent(" Saturation"));
EditorGUILayout.BeginHorizontal ();
EditorGUILayout.PropertyField (flareColorA, new GUIContent(" 1st Color"));
EditorGUILayout.PropertyField (flareColorB, new GUIContent(" 2nd Color"));
EditorGUILayout.EndHorizontal ();
EditorGUILayout.BeginHorizontal ();
EditorGUILayout.PropertyField (flareColorC, new GUIContent(" 3rd Color"));
EditorGUILayout.PropertyField (flareColorD, new GUIContent(" 4th Color"));
EditorGUILayout.EndHorizontal ();
}
EditorGUILayout.PropertyField(lensFlareVignetteMask, new GUIContent(" Mask", "This mask is needed to prevent lens flare artifacts"));
}
}
serObj.ApplyModifiedProperties();
}
}
}
fileFormatVersion: 2
guid: 43fcc28c40e404d4eabfc88b1dbda7b5
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
using System;
using UnityEditor;
using UnityEngine;
namespace UnityStandardAssets.ImageEffects
{
[CustomEditor (typeof(VignetteAndChromaticAberration))]
class VignetteAndChromaticAberrationEditor : Editor
{
private SerializedObject m_SerObj;
private SerializedProperty m_Mode;
private SerializedProperty m_Intensity; // intensity == 0 disables pre pass (optimization)
private SerializedProperty m_ChromaticAberration;
private SerializedProperty m_AxialAberration;
private SerializedProperty m_Blur; // blur == 0 disables blur pass (optimization)
private SerializedProperty m_BlurSpread;
private SerializedProperty m_BlurDistance;
private SerializedProperty m_LuminanceDependency;
void OnEnable ()
{
m_SerObj = new SerializedObject (target);
m_Mode = m_SerObj.FindProperty ("mode");
m_Intensity = m_SerObj.FindProperty ("intensity");
m_ChromaticAberration = m_SerObj.FindProperty ("chromaticAberration");
m_AxialAberration = m_SerObj.FindProperty ("axialAberration");
m_Blur = m_SerObj.FindProperty ("blur");
m_BlurSpread = m_SerObj.FindProperty ("blurSpread");
m_LuminanceDependency = m_SerObj.FindProperty ("luminanceDependency");
m_BlurDistance = m_SerObj.FindProperty ("blurDistance");
}
public override void OnInspectorGUI ()
{
m_SerObj.Update ();
EditorGUILayout.LabelField("Simulates the common lens artifacts 'Vignette' and 'Aberration'", EditorStyles.miniLabel);
EditorGUILayout.PropertyField (m_Intensity, new GUIContent("Vignetting"));
EditorGUILayout.PropertyField (m_Blur, new GUIContent(" Blurred Corners"));
if (m_Blur.floatValue>0.0f)
EditorGUILayout.PropertyField (m_BlurSpread, new GUIContent(" Blur Distance"));
EditorGUILayout.Separator ();
EditorGUILayout.PropertyField (m_Mode, new GUIContent("Aberration"));
if (m_Mode.intValue>0)
{
EditorGUILayout.PropertyField (m_ChromaticAberration, new GUIContent(" Tangential Aberration"));
EditorGUILayout.PropertyField (m_AxialAberration, new GUIContent(" Axial Aberration"));
m_LuminanceDependency.floatValue = EditorGUILayout.Slider(" Contrast Dependency", m_LuminanceDependency.floatValue, 0.001f, 1.0f);
m_BlurDistance.floatValue = EditorGUILayout.Slider(" Blur Distance", m_BlurDistance.floatValue, 0.001f, 5.0f);
}
else
EditorGUILayout.PropertyField (m_ChromaticAberration, new GUIContent(" Chromatic Aberration"));
m_SerObj.ApplyModifiedProperties();
}
}
}
fileFormatVersion: 2
guid: 08126bf2baa528c4cb9c60340a24e5d6
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
fileFormatVersion: 2
guid: 82bcf04d8112e204eae4c5b3ccca54aa
folderAsset: yes
timeCreated: 1433529656
licenseType: Free
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: 115d1f9d9bd29064ab981e57c8fc8cdf
folderAsset: yes
DefaultImporter:
userData:
assetBundleName:
fileFormatVersion: 2
guid: d6e0c95a128e14227939c51b5d9ad74e
folderAsset: yes
DefaultImporter:
userData:
assetBundleName:
fileFormatVersion: 2
guid: cd3e1490c3d9a7a498538315414d5129
folderAsset: yes
DefaultImporter:
userData:
assetBundleName:
fileFormatVersion: 2
guid: 7fceaeb339b971b429c4cc600acabd13
MonoImporter:
serializedVersion: 2
defaultReferences:
- lensFlareVignetteMask: {fileID: 2800000, guid: 95ef4804fe0be4c999ddaa383536cde8,
type: 3}
- lensFlareShader: {fileID: 4800000, guid: 459fe69d2f6d74ddb92f04dbf45a866b, type: 3}
- screenBlendShader: {fileID: 4800000, guid: 7856cbff0a0ca45c787d5431eb805bb0, type: 3}
- blurAndFlaresShader: {fileID: 4800000, guid: be6e39cf196f146d5be72fbefb18ed75,
type: 3}
- brightPassFilterShader: {fileID: 4800000, guid: 0aeaa4cb29f5d4e9c8455f04c8575c8c,
type: 3}
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
fileFormatVersion: 2
guid: 02536f33053638549ab5c50ff3ecc0de
MonoImporter:
serializedVersion: 2
defaultReferences:
- lensFlareVignetteMask: {fileID: 2800000, guid: 95ef4804fe0be4c999ddaa383536cde8,
type: 3}
- lensFlareShader: {fileID: 4800000, guid: 459fe69d2f6d74ddb92f04dbf45a866b, type: 3}
- vignetteShader: {fileID: 4800000, guid: 627943dc7a9a74286b70a4f694a0acd5, type: 3}
- separableBlurShader: {fileID: 4800000, guid: a9df009a214e24a5ebbf271595f8d5b6,
type: 3}
- addBrightStuffOneOneShader: {fileID: 4800000, guid: f7898d203e9b94c0dbe2bf9dd5cb32c0,
type: 3}
- screenBlendShader: {fileID: 4800000, guid: 53b3960ee3d3d4a5caa8d5473d120187, type: 3}
- hollywoodFlaresShader: {fileID: 4800000, guid: e2baf3cae8edc4daf94c9adc2154be00,
type: 3}
- brightPassFilterShader: {fileID: 4800000, guid: 186c4c0d31e314f049595dcbaf4ca129,
type: 3}
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
using System;
using UnityEngine;
namespace UnityStandardAssets.ImageEffects
{
[ExecuteInEditMode]
[RequireComponent (typeof(Camera))]
[AddComponentMenu ("Image Effects/Bloom and Glow/Bloom (Optimized)")]
public class BloomOptimized : PostEffectsBase
{
public enum Resolution
{
Low = 0,
High = 1,
}
public enum BlurType
{
Standard = 0,
Sgx = 1,
}
[Range(0.0f, 1.5f)]
public float threshold = 0.25f;
[Range(0.0f, 2.5f)]
public float intensity = 0.75f;
[Range(0.25f, 5.5f)]
public float blurSize = 1.0f;
Resolution resolution = Resolution.Low;
[Range(1, 4)]
public int blurIterations = 1;
public BlurType blurType= BlurType.Standard;
public Shader fastBloomShader = null;
private Material fastBloomMaterial = null;
public override bool CheckResources ()
{
CheckSupport (false);
fastBloomMaterial = CheckShaderAndCreateMaterial (fastBloomShader, fastBloomMaterial);
if (!isSupported)
ReportAutoDisable ();
return isSupported;
}
void OnDisable ()
{
if (fastBloomMaterial)
DestroyImmediate (fastBloomMaterial);
}
void OnRenderImage (RenderTexture source, RenderTexture destination)
{
if (CheckResources() == false)
{
Graphics.Blit (source, destination);
return;
}
int divider = resolution == Resolution.Low ? 4 : 2;
float widthMod = resolution == Resolution.Low ? 0.5f : 1.0f;
fastBloomMaterial.SetVector ("_Parameter", new Vector4 (blurSize * widthMod, 0.0f, threshold, intensity));
source.filterMode = FilterMode.Bilinear;
var rtW= source.width/divider;
var rtH= source.height/divider;
// downsample
RenderTexture rt = RenderTexture.GetTemporary (rtW, rtH, 0, source.format);
rt.filterMode = FilterMode.Bilinear;
Graphics.Blit (source, rt, fastBloomMaterial, 1);
var passOffs= blurType == BlurType.Standard ? 0 : 2;
for(int i = 0; i < blurIterations; i++)
{
fastBloomMaterial.SetVector ("_Parameter", new Vector4 (blurSize * widthMod + (i*1.0f), 0.0f, threshold, intensity));
// vertical blur
RenderTexture rt2 = RenderTexture.GetTemporary (rtW, rtH, 0, source.format);
rt2.filterMode = FilterMode.Bilinear;
Graphics.Blit (rt, rt2, fastBloomMaterial, 2 + passOffs);
RenderTexture.ReleaseTemporary (rt);
rt = rt2;
// horizontal blur
rt2 = RenderTexture.GetTemporary (rtW, rtH, 0, source.format);
rt2.filterMode = FilterMode.Bilinear;
Graphics.Blit (rt, rt2, fastBloomMaterial, 3 + passOffs);
RenderTexture.ReleaseTemporary (rt);
rt = rt2;
}
fastBloomMaterial.SetTexture ("_Bloom", rt);
Graphics.Blit (source, destination, fastBloomMaterial, 0);
RenderTexture.ReleaseTemporary (rt);
}
}
}
fileFormatVersion: 2
guid: 4975a6e437fc3b149a8cd508ce5bdd69
MonoImporter:
serializedVersion: 2
defaultReferences:
- fastBloomShader: {fileID: 4800000, guid: 68a00c837b82e4c6d92e7da765dc5f1d, type: 3}
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
using System;
using UnityEngine;
namespace UnityStandardAssets.ImageEffects
{
[RequireComponent(typeof (Camera))]
[AddComponentMenu("")]
public class ImageEffectBase : MonoBehaviour
{
/// Provides a shader property that is set in the inspector
/// and a material instantiated from the shader
public Shader shader;
private Material m_Material;
protected virtual void Start()
{
// Disable if we don't support image effects
if (!SystemInfo.supportsImageEffects)
{
enabled = false;
return;
}
// Disable the image effect if the shader can't
// run on the users graphics card
if (!shader || !shader.isSupported)
enabled = false;
}
protected Material material
{
get
{
if (m_Material == null)
{
m_Material = new Material(shader);
m_Material.hideFlags = HideFlags.HideAndDontSave;
}
return m_Material;
}
}
protected virtual void OnDisable()
{
if (m_Material)
{
DestroyImmediate(m_Material);
}
}
}
}
fileFormatVersion: 2
guid: f6469eb0ad1119d6d00011d98d76c639
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
using System;
using UnityEngine;
namespace UnityStandardAssets.ImageEffects
{
/// A Utility class for performing various image based rendering tasks.
[AddComponentMenu("")]
public class ImageEffects
{
public static void RenderDistortion(Material material, RenderTexture source, RenderTexture destination, float angle, Vector2 center, Vector2 radius)
{
bool invertY = source.texelSize.y < 0.0f;
if (invertY)
{
center.y = 1.0f - center.y;
angle = -angle;
}
Matrix4x4 rotationMatrix = Matrix4x4.TRS(Vector3.zero, Quaternion.Euler(0, 0, angle), Vector3.one);
material.SetMatrix("_RotationMatrix", rotationMatrix);
material.SetVector("_CenterRadius", new Vector4(center.x, center.y, radius.x, radius.y));
material.SetFloat("_Angle", angle*Mathf.Deg2Rad);
Graphics.Blit(source, destination, material);
}
[Obsolete("Use Graphics.Blit(source,dest) instead")]
public static void Blit(RenderTexture source, RenderTexture dest)
{
Graphics.Blit(source, dest);
}
[Obsolete("Use Graphics.Blit(source, destination, material) instead")]
public static void BlitWithMaterial(Material material, RenderTexture source, RenderTexture dest)
{
Graphics.Blit(source, dest, material);
}
}
}
fileFormatVersion: 2
guid: 89a037199d11087f1100e2b844295342
MonoImporter:
serializedVersion: 2
defaultReferences:
- blitCopyShader: {fileID: 4800000, guid: 3338b5ea2f3cb594698fae65cf060346, type: 3}
- blitMultiplyShader: {fileID: 4800000, guid: 7034c801b78acab448cdcf845f7c352d,
type: 3}
- blitMultiply2XShader: {fileID: 4800000, guid: cde82987e0a884c4788c65f7b54390e8,
type: 3}
- blitAddShader: {fileID: 4800000, guid: c7515f214a63bdb42b6ae6335a00a8a4, type: 3}
- blitAddSmoothShader: {fileID: 4800000, guid: 7741a77a7c455d0418bc429bd508dc87,
type: 3}
- blitBlendShader: {fileID: 4800000, guid: f1cf7e9c98754c4429ff0f7cc1d9dd7b, type: 3}
executionOrder: 0
icon: {instanceID: 0}
userData:
using System;
using UnityEngine;
namespace UnityStandardAssets.ImageEffects
{
[ExecuteInEditMode]
[RequireComponent (typeof(Camera))]
public class PostEffectsBase : MonoBehaviour
{
protected bool supportHDRTextures = true;
protected bool supportDX11 = false;
protected bool isSupported = true;
protected Material CheckShaderAndCreateMaterial ( Shader s, Material m2Create)
{
if (!s)
{
Debug.Log("Missing shader in " + ToString ());
enabled = false;
return null;
}
if (s.isSupported && m2Create && m2Create.shader == s)
return m2Create;
if (!s.isSupported)
{
NotSupported ();
Debug.Log("The shader " + s.ToString() + " on effect "+ToString()+" is not supported on this platform!");
return null;
}
else
{
m2Create = new Material (s);
m2Create.hideFlags = HideFlags.DontSave;
if (m2Create)
return m2Create;
else return null;
}
}
protected Material CreateMaterial (Shader s, Material m2Create)
{
if (!s)
{
Debug.Log ("Missing shader in " + ToString ());
return null;
}
if (m2Create && (m2Create.shader == s) && (s.isSupported))
return m2Create;
if (!s.isSupported)
{
return null;
}
else
{
m2Create = new Material (s);
m2Create.hideFlags = HideFlags.DontSave;
if (m2Create)
return m2Create;
else return null;
}
}
void OnEnable ()
{
isSupported = true;
}
protected bool CheckSupport ()
{
return CheckSupport (false);
}
public virtual bool CheckResources ()
{
Debug.LogWarning ("CheckResources () for " + ToString() + " should be overwritten.");
return isSupported;
}
protected void Start ()
{
CheckResources ();
}
protected bool CheckSupport (bool needDepth)
{
isSupported = true;
supportHDRTextures = SystemInfo.SupportsRenderTextureFormat(RenderTextureFormat.ARGBHalf);
supportDX11 = SystemInfo.graphicsShaderLevel >= 50 && SystemInfo.supportsComputeShaders;
if (!SystemInfo.supportsImageEffects || !SystemInfo.supportsRenderTextures)
{
NotSupported ();
return false;
}
if (needDepth && !SystemInfo.SupportsRenderTextureFormat (RenderTextureFormat.Depth))
{
NotSupported ();
return false;
}
if (needDepth)
GetComponent<Camera>().depthTextureMode |= DepthTextureMode.Depth;
return true;
}
protected bool CheckSupport (bool needDepth, bool needHdr)
{
if (!CheckSupport(needDepth))
return false;
if (needHdr && !supportHDRTextures)
{
NotSupported ();
return false;
}
return true;
}
public bool Dx11Support ()
{
return supportDX11;
}
protected void ReportAutoDisable ()
{
Debug.LogWarning ("The image effect " + ToString() + " has been disabled as it's not supported on the current platform.");
}
// deprecated but needed for old effects to survive upgrading
bool CheckShader (Shader s)
{
Debug.Log("The shader " + s.ToString () + " on effect "+ ToString () + " is not part of the Unity 3.2+ effects suite anymore. For best performance and quality, please ensure you are using the latest Standard Assets Image Effects (Pro only) package.");
if (!s.isSupported)
{
NotSupported ();
return false;
}
else
{
return false;
}
}
protected void NotSupported ()
{
enabled = false;
isSupported = false;
return;
}
protected void DrawBorder (RenderTexture dest, Material material)
{
float x1;
float x2;
float y1;
float y2;
RenderTexture.active = dest;
bool invertY = true; // source.texelSize.y < 0.0ff;
// Set up the simple Matrix
GL.PushMatrix();
GL.LoadOrtho();
for (int i = 0; i < material.passCount; i++)
{
material.SetPass(i);
float y1_; float y2_;
if (invertY)
{
y1_ = 1.0f; y2_ = 0.0f;
}
else
{
y1_ = 0.0f; y2_ = 1.0f;
}
// left
x1 = 0.0f;
x2 = 0.0f + 1.0f/(dest.width*1.0f);
y1 = 0.0f;
y2 = 1.0f;
GL.Begin(GL.QUADS);
GL.TexCoord2(0.0f, y1_); GL.Vertex3(x1, y1, 0.1f);
GL.TexCoord2(1.0f, y1_); GL.Vertex3(x2, y1, 0.1f);
GL.TexCoord2(1.0f, y2_); GL.Vertex3(x2, y2, 0.1f);
GL.TexCoord2(0.0f, y2_); GL.Vertex3(x1, y2, 0.1f);
// right
x1 = 1.0f - 1.0f/(dest.width*1.0f);
x2 = 1.0f;
y1 = 0.0f;
y2 = 1.0f;
GL.TexCoord2(0.0f, y1_); GL.Vertex3(x1, y1, 0.1f);
GL.TexCoord2(1.0f, y1_); GL.Vertex3(x2, y1, 0.1f);
GL.TexCoord2(1.0f, y2_); GL.Vertex3(x2, y2, 0.1f);
GL.TexCoord2(0.0f, y2_); GL.Vertex3(x1, y2, 0.1f);
// top
x1 = 0.0f;
x2 = 1.0f;
y1 = 0.0f;
y2 = 0.0f + 1.0f/(dest.height*1.0f);
GL.TexCoord2(0.0f, y1_); GL.Vertex3(x1, y1, 0.1f);
GL.TexCoord2(1.0f, y1_); GL.Vertex3(x2, y1, 0.1f);
GL.TexCoord2(1.0f, y2_); GL.Vertex3(x2, y2, 0.1f);
GL.TexCoord2(0.0f, y2_); GL.Vertex3(x1, y2, 0.1f);
// bottom
x1 = 0.0f;
x2 = 1.0f;
y1 = 1.0f - 1.0f/(dest.height*1.0f);
y2 = 1.0f;
GL.TexCoord2(0.0f, y1_); GL.Vertex3(x1, y1, 0.1f);
GL.TexCoord2(1.0f, y1_); GL.Vertex3(x2, y1, 0.1f);
GL.TexCoord2(1.0f, y2_); GL.Vertex3(x2, y2, 0.1f);
GL.TexCoord2(0.0f, y2_); GL.Vertex3(x1, y2, 0.1f);
GL.End();
}
GL.PopMatrix();
}
}
}
fileFormatVersion: 2
guid: b6f4318ec6c2bf643a0f9edfeeaba0ec
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
using System;
using UnityEngine;
namespace UnityStandardAssets.ImageEffects
{
[ExecuteInEditMode]
[RequireComponent (typeof(Camera))]
class PostEffectsHelper : MonoBehaviour
{
void OnRenderImage (RenderTexture source, RenderTexture destination)
{
Debug.Log("OnRenderImage in Helper called ...");
}
static void DrawLowLevelPlaneAlignedWithCamera (
float dist ,
RenderTexture source, RenderTexture dest ,
Material material ,
Camera cameraForProjectionMatrix )
{
// Make the destination texture the target for all rendering
RenderTexture.active = dest;
// Assign the source texture to a property from a shader
material.SetTexture("_MainTex", source);
bool invertY = true; // source.texelSize.y < 0.0f;
// Set up the simple Matrix
GL.PushMatrix();
GL.LoadIdentity();
GL.LoadProjectionMatrix(cameraForProjectionMatrix.projectionMatrix);
float fovYHalfRad = cameraForProjectionMatrix.fieldOfView * 0.5f * Mathf.Deg2Rad;
float cotangent = Mathf.Cos(fovYHalfRad) / Mathf.Sin(fovYHalfRad);
float asp = cameraForProjectionMatrix.aspect;
float x1 = asp/-cotangent;
float x2 = asp/cotangent;
float y1 = 1.0f/-cotangent;
float y2 = 1.0f/cotangent;
float sc = 1.0f; // magic constant (for now)
x1 *= dist * sc;
x2 *= dist * sc;
y1 *= dist * sc;
y2 *= dist * sc;
float z1 = -dist;
for (int i = 0; i < material.passCount; i++)
{
material.SetPass(i);
GL.Begin(GL.QUADS);
float y1_; float y2_;
if (invertY)
{
y1_ = 1.0f; y2_ = 0.0f;
}
else
{
y1_ = 0.0f; y2_ = 1.0f;
}
GL.TexCoord2(0.0f, y1_); GL.Vertex3(x1, y1, z1);
GL.TexCoord2(1.0f, y1_); GL.Vertex3(x2, y1, z1);
GL.TexCoord2(1.0f, y2_); GL.Vertex3(x2, y2, z1);
GL.TexCoord2(0.0f, y2_); GL.Vertex3(x1, y2, z1);
GL.End();
}
GL.PopMatrix();
}
static void DrawBorder (
RenderTexture dest ,
Material material )
{
float x1;
float x2;
float y1;
float y2;
RenderTexture.active = dest;
bool invertY = true; // source.texelSize.y < 0.0ff;
// Set up the simple Matrix
GL.PushMatrix();
GL.LoadOrtho();
for (int i = 0; i < material.passCount; i++)
{
material.SetPass(i);
float y1_; float y2_;
if (invertY)
{
y1_ = 1.0f; y2_ = 0.0f;
}
else
{
y1_ = 0.0f; y2_ = 1.0f;
}
// left
x1 = 0.0f;
x2 = 0.0f + 1.0f/(dest.width*1.0f);
y1 = 0.0f;
y2 = 1.0f;
GL.Begin(GL.QUADS);
GL.TexCoord2(0.0f, y1_); GL.Vertex3(x1, y1, 0.1f);
GL.TexCoord2(1.0f, y1_); GL.Vertex3(x2, y1, 0.1f);
GL.TexCoord2(1.0f, y2_); GL.Vertex3(x2, y2, 0.1f);
GL.TexCoord2(0.0f, y2_); GL.Vertex3(x1, y2, 0.1f);
// right
x1 = 1.0f - 1.0f/(dest.width*1.0f);
x2 = 1.0f;
y1 = 0.0f;
y2 = 1.0f;
GL.TexCoord2(0.0f, y1_); GL.Vertex3(x1, y1, 0.1f);
GL.TexCoord2(1.0f, y1_); GL.Vertex3(x2, y1, 0.1f);
GL.TexCoord2(1.0f, y2_); GL.Vertex3(x2, y2, 0.1f);
GL.TexCoord2(0.0f, y2_); GL.Vertex3(x1, y2, 0.1f);
// top
x1 = 0.0f;
x2 = 1.0f;
y1 = 0.0f;
y2 = 0.0f + 1.0f/(dest.height*1.0f);
GL.TexCoord2(0.0f, y1_); GL.Vertex3(x1, y1, 0.1f);
GL.TexCoord2(1.0f, y1_); GL.Vertex3(x2, y1, 0.1f);
GL.TexCoord2(1.0f, y2_); GL.Vertex3(x2, y2, 0.1f);
GL.TexCoord2(0.0f, y2_); GL.Vertex3(x1, y2, 0.1f);
// bottom
x1 = 0.0f;
x2 = 1.0f;
y1 = 1.0f - 1.0f/(dest.height*1.0f);
y2 = 1.0f;
GL.TexCoord2(0.0f, y1_); GL.Vertex3(x1, y1, 0.1f);
GL.TexCoord2(1.0f, y1_); GL.Vertex3(x2, y1, 0.1f);
GL.TexCoord2(1.0f, y2_); GL.Vertex3(x2, y2, 0.1f);
GL.TexCoord2(0.0f, y2_); GL.Vertex3(x1, y2, 0.1f);
GL.End();
}
GL.PopMatrix();
}
static void DrawLowLevelQuad ( float x1, float x2, float y1, float y2, RenderTexture source, RenderTexture dest, Material material )
{
// Make the destination texture the target for all rendering
RenderTexture.active = dest;
// Assign the source texture to a property from a shader
material.SetTexture("_MainTex", source);
bool invertY = true; // source.texelSize.y < 0.0f;
// Set up the simple Matrix
GL.PushMatrix();
GL.LoadOrtho();
for (int i = 0; i < material.passCount; i++)
{
material.SetPass(i);
GL.Begin(GL.QUADS);
float y1_; float y2_;
if (invertY)
{
y1_ = 1.0f; y2_ = 0.0f;
}
else
{
y1_ = 0.0f; y2_ = 1.0f;
}
GL.TexCoord2(0.0f, y1_); GL.Vertex3(x1, y1, 0.1f);
GL.TexCoord2(1.0f, y1_); GL.Vertex3(x2, y1, 0.1f);
GL.TexCoord2(1.0f, y2_); GL.Vertex3(x2, y2, 0.1f);
GL.TexCoord2(0.0f, y2_); GL.Vertex3(x1, y2, 0.1f);
GL.End();
}
GL.PopMatrix();
}
}
}
fileFormatVersion: 2
guid: 50b03df8f04b5c441aaac5b7fccb4734
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
using System;
using UnityEngine;
using Object = UnityEngine.Object;
// same as Triangles but creates quads instead which generally
// saves fillrate at the expense for more triangles to issue
namespace UnityStandardAssets.ImageEffects
{
class Quads
{
static Mesh[] meshes;
static int currentQuads = 0;
static bool HasMeshes ()
{
if (meshes == null)
return false;
foreach (Mesh m in meshes)
if (null == m)
return false;
return true;
}
public static void Cleanup ()
{
if (meshes == null)
return;
for (int i = 0; i < meshes.Length; i++)
{
if (null != meshes[i])
{
Object.DestroyImmediate (meshes[i]);
meshes[i] = null;
}
}
meshes = null;
}
public static Mesh[] GetMeshes ( int totalWidth, int totalHeight)
{
if (HasMeshes () && (currentQuads == (totalWidth * totalHeight))) {
return meshes;
}
int maxQuads = 65000 / 6;
int totalQuads = totalWidth * totalHeight;
currentQuads = totalQuads;
int meshCount = Mathf.CeilToInt ((1.0f * totalQuads) / (1.0f * maxQuads));
meshes = new Mesh [meshCount];
int i = 0;
int index = 0;
for (i = 0; i < totalQuads; i += maxQuads)
{
int quads = Mathf.FloorToInt (Mathf.Clamp ((totalQuads-i), 0, maxQuads));
meshes[index] = GetMesh (quads, i, totalWidth, totalHeight);
index++;
}
return meshes;
}
static Mesh GetMesh (int triCount, int triOffset, int totalWidth, int totalHeight)
{
var mesh = new Mesh ();
mesh.hideFlags = HideFlags.DontSave;
var verts = new Vector3[triCount * 4];
var uvs = new Vector2[triCount * 4];
var uvs2 = new Vector2[triCount * 4];
var tris = new int[triCount * 6];
for (int i = 0; i < triCount; i++)
{
int i4 = i * 4;
int i6 = i * 6;
int vertexWithOffset = triOffset + i;
float x = Mathf.Floor (vertexWithOffset % totalWidth) / totalWidth;
float y = Mathf.Floor (vertexWithOffset / totalWidth) / totalHeight;
Vector3 position = new Vector3 (x * 2 - 1, y * 2 - 1, 1.0f);
verts[i4 + 0] = position;
verts[i4 + 1] = position;
verts[i4 + 2] = position;
verts[i4 + 3] = position;
uvs[i4 + 0] = new Vector2 (0.0f, 0.0f);
uvs[i4 + 1] = new Vector2 (1.0f, 0.0f);
uvs[i4 + 2] = new Vector2 (0.0f, 1.0f);
uvs[i4 + 3] = new Vector2 (1.0f, 1.0f);
uvs2[i4 + 0] = new Vector2 (x, y);
uvs2[i4 + 1] = new Vector2 (x, y);
uvs2[i4 + 2] = new Vector2 (x, y);
uvs2[i4 + 3] = new Vector2 (x, y);
tris[i6 + 0] = i4 + 0;
tris[i6 + 1] = i4 + 1;
tris[i6 + 2] = i4 + 2;
tris[i6 + 3] = i4 + 1;
tris[i6 + 4] = i4 + 2;
tris[i6 + 5] = i4 + 3;
}
mesh.vertices = verts;
mesh.triangles = tris;
mesh.uv = uvs;
mesh.uv2 = uvs2;
return mesh;
}
}
}
fileFormatVersion: 2
guid: a20852ce049f64e4695a48b6a354be83
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
using System;
using UnityEngine;
using Object = UnityEngine.Object;
namespace UnityStandardAssets.ImageEffects
{
class Triangles
{
private static Mesh[] meshes;
private static int currentTris = 0;
static bool HasMeshes()
{
if (meshes == null)
return false;
for (int i = 0; i < meshes.Length; i++)
if (null == meshes[i])
return false;
return true;
}
static void Cleanup()
{
if (meshes == null)
return;
for (int i = 0; i < meshes.Length; i++)
{
if (null != meshes[i])
{
Object.DestroyImmediate(meshes[i]);
meshes[i] = null;
}
}
meshes = null;
}
static Mesh[] GetMeshes(int totalWidth, int totalHeight)
{
if (HasMeshes() && (currentTris == (totalWidth * totalHeight)))
{
return meshes;
}
int maxTris = 65000 / 3;
int totalTris = totalWidth * totalHeight;
currentTris = totalTris;
int meshCount = Mathf.CeilToInt((1.0f * totalTris) / (1.0f * maxTris));
meshes = new Mesh[meshCount];
int i = 0;
int index = 0;
for (i = 0; i < totalTris; i += maxTris)
{
int tris = Mathf.FloorToInt(Mathf.Clamp((totalTris - i), 0, maxTris));
meshes[index] = GetMesh(tris, i, totalWidth, totalHeight);
index++;
}
return meshes;
}
static Mesh GetMesh(int triCount, int triOffset, int totalWidth, int totalHeight)
{
var mesh = new Mesh();
mesh.hideFlags = HideFlags.DontSave;
var verts = new Vector3[triCount * 3];
var uvs = new Vector2[triCount * 3];
var uvs2 = new Vector2[triCount * 3];
var tris = new int[triCount * 3];
for (int i = 0; i < triCount; i++)
{
int i3 = i * 3;
int vertexWithOffset = triOffset + i;
float x = Mathf.Floor(vertexWithOffset % totalWidth) / totalWidth;
float y = Mathf.Floor(vertexWithOffset / totalWidth) / totalHeight;
Vector3 position = new Vector3(x * 2 - 1, y * 2 - 1, 1.0f);
verts[i3 + 0] = position;
verts[i3 + 1] = position;
verts[i3 + 2] = position;
uvs[i3 + 0] = new Vector2(0.0f, 0.0f);
uvs[i3 + 1] = new Vector2(1.0f, 0.0f);
uvs[i3 + 2] = new Vector2(0.0f, 1.0f);
uvs2[i3 + 0] = new Vector2(x, y);
uvs2[i3 + 1] = new Vector2(x, y);
uvs2[i3 + 2] = new Vector2(x, y);
tris[i3 + 0] = i3 + 0;
tris[i3 + 1] = i3 + 1;
tris[i3 + 2] = i3 + 2;
}
mesh.vertices = verts;
mesh.triangles = tris;
mesh.uv = uvs;
mesh.uv2 = uvs2;
return mesh;
}
}
}
fileFormatVersion: 2
guid: 18b91636de2ba3445913e4cf38528dc8
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
using System;
using UnityEngine;
namespace UnityStandardAssets.ImageEffects
{
[ExecuteInEditMode]
[RequireComponent (typeof(Camera))]
[AddComponentMenu ("Image Effects/Camera/Vignette and Chromatic Aberration")]
public class VignetteAndChromaticAberration : PostEffectsBase
{
public enum AberrationMode
{
Simple = 0,
Advanced = 1,
}
public AberrationMode mode = AberrationMode.Simple;
public float intensity = 0.375f; // intensity == 0 disables pre pass (optimization)
public float chromaticAberration = 0.2f;
public float axialAberration = 0.5f;
public float blur = 0.0f; // blur == 0 disables blur pass (optimization)
public float blurSpread = 0.75f;
public float luminanceDependency = 0.25f;
public float blurDistance = 2.5f;
public Shader vignetteShader;
public Shader separableBlurShader;
public Shader chromAberrationShader;
private Material m_VignetteMaterial;
private Material m_SeparableBlurMaterial;
private Material m_ChromAberrationMaterial;
public override bool CheckResources ()
{
CheckSupport (false);
m_VignetteMaterial = CheckShaderAndCreateMaterial (vignetteShader, m_VignetteMaterial);
m_SeparableBlurMaterial = CheckShaderAndCreateMaterial (separableBlurShader, m_SeparableBlurMaterial);
m_ChromAberrationMaterial = CheckShaderAndCreateMaterial (chromAberrationShader, m_ChromAberrationMaterial);
if (!isSupported)
ReportAutoDisable ();
return isSupported;
}
void OnRenderImage (RenderTexture source, RenderTexture destination)
{
if ( CheckResources () == false)
{
Graphics.Blit (source, destination);
return;
}
int rtW = source.width;
int rtH = source.height;
bool doPrepass = (Mathf.Abs(blur)>0.0f || Mathf.Abs(intensity)>0.0f);
float widthOverHeight = (1.0f * rtW) / (1.0f * rtH);
const float oneOverBaseSize = 1.0f / 512.0f;
RenderTexture color = null;
RenderTexture color2A = null;
if (doPrepass)
{
color = RenderTexture.GetTemporary (rtW, rtH, 0, source.format);
// Blur corners
if (Mathf.Abs (blur)>0.0f)
{
color2A = RenderTexture.GetTemporary (rtW / 2, rtH / 2, 0, source.format);
Graphics.Blit (source, color2A, m_ChromAberrationMaterial, 0);
for(int i = 0; i < 2; i++)
{ // maybe make iteration count tweakable
m_SeparableBlurMaterial.SetVector ("offsets",new Vector4 (0.0f, blurSpread * oneOverBaseSize, 0.0f, 0.0f));
RenderTexture color2B = RenderTexture.GetTemporary (rtW / 2, rtH / 2, 0, source.format);
Graphics.Blit (color2A, color2B, m_SeparableBlurMaterial);
RenderTexture.ReleaseTemporary (color2A);
m_SeparableBlurMaterial.SetVector ("offsets",new Vector4 (blurSpread * oneOverBaseSize / widthOverHeight, 0.0f, 0.0f, 0.0f));
color2A = RenderTexture.GetTemporary (rtW / 2, rtH / 2, 0, source.format);
Graphics.Blit (color2B, color2A, m_SeparableBlurMaterial);
RenderTexture.ReleaseTemporary (color2B);
}
}
m_VignetteMaterial.SetFloat ("_Intensity", intensity); // intensity for vignette
m_VignetteMaterial.SetFloat ("_Blur", blur); // blur intensity
m_VignetteMaterial.SetTexture ("_VignetteTex", color2A); // blurred texture
Graphics.Blit (source, color, m_VignetteMaterial, 0); // prepass blit: darken & blur corners
}
m_ChromAberrationMaterial.SetFloat ("_ChromaticAberration", chromaticAberration);
m_ChromAberrationMaterial.SetFloat ("_AxialAberration", axialAberration);
m_ChromAberrationMaterial.SetVector ("_BlurDistance", new Vector2 (-blurDistance, blurDistance));
m_ChromAberrationMaterial.SetFloat ("_Luminance", 1.0f/Mathf.Max(Mathf.Epsilon, luminanceDependency));
if (doPrepass) color.wrapMode = TextureWrapMode.Clamp;
else source.wrapMode = TextureWrapMode.Clamp;
Graphics.Blit (doPrepass ? color : source, destination, m_ChromAberrationMaterial, mode == AberrationMode.Advanced ? 2 : 1);
RenderTexture.ReleaseTemporary (color);
RenderTexture.ReleaseTemporary (color2A);
}
}
}
fileFormatVersion: 2
guid: dd6d4281e5d7cd44d8c6e38bc2c1b8d8
MonoImporter:
serializedVersion: 2
defaultReferences:
- vignetteShader: {fileID: 4800000, guid: 627943dc7a9a74286b70a4f694a0acd5, type: 3}
- separableBlurShader: {fileID: 4800000, guid: e97c14fbb5ea04c3a902cc533d7fc5d1,
type: 3}
- chromAberrationShader: {fileID: 4800000, guid: 2b4f29398d9484ccfa9fd220449f5eee,
type: 3}
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
fileFormatVersion: 2
guid: b2145489f7c704db8acb14a52bddeee9
folderAsset: yes
DefaultImporter:
userData:
assetBundleName:
Shader "Hidden/BlendModesOverlay" {
Properties {
_MainTex ("Screen Blended", 2D) = "" {}
_Overlay ("Color", 2D) = "grey" {}
}
CGINCLUDE
#include "UnityCG.cginc"
struct v2f {
float4 pos : SV_POSITION;
float2 uv[2] : TEXCOORD0;
};
sampler2D _Overlay;
sampler2D _MainTex;
half _Intensity;
half4 _MainTex_TexelSize;
half4 _UV_Transform = half4(1, 0, 0, 1);
v2f vert( appdata_img v ) {
v2f o;
o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
o.uv[0] = float2(
dot(v.texcoord.xy, _UV_Transform.xy),
dot(v.texcoord.xy, _UV_Transform.zw)
);
#if UNITY_UV_STARTS_AT_TOP
if(_MainTex_TexelSize.y<0.0)
o.uv[0].y = 1.0-o.uv[0].y;
#endif
o.uv[1] = v.texcoord.xy;
return o;
}
half4 fragAddSub (v2f i) : SV_Target {
half4 toAdd = tex2D(_Overlay, i.uv[0]) * _Intensity;
return tex2D(_MainTex, i.uv[1]) + toAdd;
}
half4 fragMultiply (v2f i) : SV_Target {
half4 toBlend = tex2D(_Overlay, i.uv[0]) * _Intensity;
return tex2D(_MainTex, i.uv[1]) * toBlend;
}
half4 fragScreen (v2f i) : SV_Target {
half4 toBlend = (tex2D(_Overlay, i.uv[0]) * _Intensity);
return 1-(1-toBlend)*(1-(tex2D(_MainTex, i.uv[1])));
}
half4 fragOverlay (v2f i) : SV_Target {
half4 m = (tex2D(_Overlay, i.uv[0]));// * 255.0;
half4 color = (tex2D(_MainTex, i.uv[1]));//* 255.0;
// overlay blend mode
//color.rgb = (color.rgb/255.0) * (color.rgb + ((2*m.rgb)/( 255.0 )) * (255.0-color.rgb));
//color.rgb /= 255.0;
/*
if (Target > ½) R = 1 - (1-2x(Target-½)) x (1-Blend)
if (Target <= ½) R = (2xTarget) x Blend
*/
float3 check = step(0.5, color.rgb);
float3 result = 0;
result = check * (half3(1,1,1) - ( (half3(1,1,1) - 2*(color.rgb-0.5)) * (1-m.rgb)));
result += (1-check) * (2*color.rgb) * m.rgb;
return half4(lerp(color.rgb, result.rgb, (_Intensity)), color.a);
}
half4 fragAlphaBlend (v2f i) : SV_Target {
half4 toAdd = tex2D(_Overlay, i.uv[0]) ;
return lerp(tex2D(_MainTex, i.uv[1]), toAdd, toAdd.a);
}
ENDCG
Subshader {
ZTest Always Cull Off ZWrite Off
ColorMask RGB
Pass {
CGPROGRAM
#pragma vertex vert
#pragma fragment fragAddSub
ENDCG
}
Pass {
CGPROGRAM
#pragma vertex vert
#pragma fragment fragScreen
ENDCG
}
Pass {
CGPROGRAM
#pragma vertex vert
#pragma fragment fragMultiply
ENDCG
}
Pass {
CGPROGRAM
#pragma vertex vert
#pragma fragment fragOverlay
ENDCG
}
Pass {
CGPROGRAM
#pragma vertex vert
#pragma fragment fragAlphaBlend
ENDCG
}
}
Fallback off
} // shader
fileFormatVersion: 2
guid: 8c81db0e527d24acc9bcec04e87781bd
ShaderImporter:
userData:
Shader "Hidden/BlurEffectConeTap" {
Properties { _MainTex ("", any) = "" {} }
CGINCLUDE
#include "UnityCG.cginc"
struct v2f {
float4 pos : SV_POSITION;
half2 uv : TEXCOORD0;
half2 taps[4] : TEXCOORD1;
};
sampler2D _MainTex;
half4 _MainTex_TexelSize;
half4 _BlurOffsets;
v2f vert( appdata_img v ) {
v2f o;
o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
o.uv = v.texcoord - _BlurOffsets.xy * _MainTex_TexelSize.xy; // hack, see BlurEffect.cs for the reason for this. let's make a new blur effect soon
o.taps[0] = o.uv + _MainTex_TexelSize * _BlurOffsets.xy;
o.taps[1] = o.uv - _MainTex_TexelSize * _BlurOffsets.xy;
o.taps[2] = o.uv + _MainTex_TexelSize * _BlurOffsets.xy * half2(1,-1);
o.taps[3] = o.uv - _MainTex_TexelSize * _BlurOffsets.xy * half2(1,-1);
return o;
}
half4 frag(v2f i) : SV_Target {
half4 color = tex2D(_MainTex, i.taps[0]);
color += tex2D(_MainTex, i.taps[1]);
color += tex2D(_MainTex, i.taps[2]);
color += tex2D(_MainTex, i.taps[3]);
return color * 0.25;
}
ENDCG
SubShader {
Pass {
ZTest Always Cull Off ZWrite Off
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
ENDCG
}
}
Fallback off
}
fileFormatVersion: 2
guid: 57e6deea7c2924e22a5138e2b70bb4dc
ShaderImporter:
userData:
fileFormatVersion: 2
guid: 85a88efa8c871af4a9d17c64791b6f4f
ShaderImporter:
userData:
/*
NOTES: see CameraMotionBlur.shader
*/
Shader "Hidden/CameraMotionBlurDX11" {
Properties {
_MainTex ("-", 2D) = "" {}
_NoiseTex ("-", 2D) = "grey" {}
_VelTex ("-", 2D) = "black" {}
_NeighbourMaxTex ("-", 2D) = "black" {}
}
CGINCLUDE
#include "UnityCG.cginc"
// 'k' in paper
float _MaxRadiusOrKInPaper;
// 's' in paper
#define NUM_SAMPLES (19)
struct v2f {
float4 pos : SV_POSITION;
float2 uv : TEXCOORD0;
};
sampler2D _MainTex;
sampler2D_float _CameraDepthTexture;
sampler2D _VelTex;
sampler2D _NeighbourMaxTex;
sampler2D _NoiseTex;
float4 _MainTex_TexelSize;
float4 _CameraDepthTexture_TexelSize;
float4 _VelTex_TexelSize;
float4x4 _InvViewProj; // inverse view-projection matrix
float4x4 _PrevViewProj; // previous view-projection matrix
float4x4 _ToPrevViewProjCombined; // combined
float _Jitter;
float _VelocityScale;
float _DisplayVelocityScale;
float _MinVelocity;
float _SoftZDistance;
v2f vert(appdata_img v)
{
v2f o;
o.pos = mul (UNITY_MATRIX_MVP, v.vertex);
o.uv = v.texcoord.xy;
return o;
}
// returns vector with largest magnitude
float2 vmax(float2 a, float2 b)
{
float ma = dot(a, a);
float mb = dot(b, b);
return (ma > mb) ? a : b;
}
// find dominant velocity in each tile
float4 TileMax(v2f i) : SV_Target
{
float2 tilemax = float2(0.0, 0.0);
float2 srcPos = i.uv - _MainTex_TexelSize.xy * _MaxRadiusOrKInPaper * 0.5;
for(int y=0; y<(int)_MaxRadiusOrKInPaper; y++) {
for(int x=0; x<(int)_MaxRadiusOrKInPaper; x++) {
float2 v = tex2D(_MainTex, srcPos + float2(x,y) * _MainTex_TexelSize.xy).xy;
tilemax = vmax(tilemax, v);
}
}
return float4(tilemax, 0, 1);
}
// find maximum velocity in any adjacent tile
float4 NeighbourMax(v2f i) : SV_Target
{
float2 maxvel = float2(0.0, 0.0);
for(int y=-1; y<=1; y++) {
for(int x=-1; x<=1; x++) {
float2 v = tex2D(_MainTex, i.uv + float2(x,y) * _MainTex_TexelSize.xy).xy;
maxvel = vmax(maxvel, v);
}
}
return float4(maxvel, 0, 1);
}
float cone(float2 px, float2 py, float2 v)
{
return clamp(1.0 - (length(px - py) / length(v)), 0.0, 1.0);
}
float cylinder(float2 x, float2 y, float2 v)
{
float lv = length(v);
return 1.0 - smoothstep(0.95*lv, 1.05*lv, length(x - y));
}
float softDepthCompare(float za, float zb)
{
return clamp(1.0 - (za - zb) / _SoftZDistance, 0.0, 1.0);
}
float4 ReconstructFilterBlur(v2f i) : SV_Target
{
float2 x = i.uv;
float2 xf = x;
#if UNITY_UV_STARTS_AT_TOP
if (_MainTex_TexelSize.y < 0)
xf.y = 1-xf.y;
#endif
float2 x2 = xf;
float2 vn = tex2D(_NeighbourMaxTex, x2).xy; // largest velocity in neighbourhood
float4 cx = tex2D(_MainTex, x); // color at x
float zx = SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, x);
zx = -Linear01Depth(zx); // depth at x
float2 vx = tex2D(_VelTex, xf).xy; // vel at x
// random offset [-0.5, 0.5]
float j = (tex2D(_NoiseTex, i.uv * 11.0f ).r*2-1) * _Jitter;
// sample current pixel
float weight = 1.0;
float4 sum = cx * weight;
int centerSample = (int)(NUM_SAMPLES-1) / 2;
// in DX11 county we take more samples and interleave with sampling along vx direction to break up "patternized" look
for(int l=0; l<NUM_SAMPLES; l++)
{
if (l==centerSample) continue; // skip center sample
// Choose evenly placed filter taps along +-vN,
// but jitter the whole filter to prevent ghosting
float t = lerp(-1.0, 1.0, (l + j) / (-1 + _Jitter + (float)NUM_SAMPLES));
//float t = lerp(-1.0, 1.0, l / (float)(NUM_SAMPLES - 1));
float2 velInterlaved = lerp(vn, min(vx, normalize(vx) * _MainTex_TexelSize.xy * _MaxRadiusOrKInPaper), l%2==0);
float2 y = x + velInterlaved * t;
float2 yf = y;
#if UNITY_UV_STARTS_AT_TOP
if (_MainTex_TexelSize.y < 0)
yf.y = 1-yf.y;
#endif
// velocity at y
float2 vy = tex2Dlod(_VelTex, float4(yf,0,0)).xy;
float zy = SAMPLE_DEPTH_TEXTURE_LOD(_CameraDepthTexture, float4(y,0,0));
zy = -Linear01Depth(zy);
float f = softDepthCompare(zx, zy);
float b = softDepthCompare(zy, zx);
float alphay = f * cone(y, x, vy) + // blurry y in front of any x
b * cone(x, y, vx) + // any y behing blurry x; estimate background
cylinder(y, x, vy) * cylinder(x, y, vx) * 2.0; // simultaneous blurry x and y
float4 cy = tex2Dlod(_MainTex, float4(y,0,0));
sum += cy * alphay;
weight += alphay;
}
sum /= weight;
return sum;
}
ENDCG
Subshader {
// pass 0
Pass {
ZTest Always Cull Off ZWrite Off
CGPROGRAM
#pragma target 5.0
#pragma vertex vert
#pragma fragment TileMax
ENDCG
}
// pass 1
Pass {
ZTest Always Cull Off ZWrite Off
CGPROGRAM
#pragma target 5.0
#pragma vertex vert
#pragma fragment NeighbourMax
ENDCG
}
// pass 2
Pass {
ZTest Always Cull Off ZWrite Off
CGPROGRAM
#pragma target 5.0
#pragma vertex vert
#pragma fragment ReconstructFilterBlur
ENDCG
}
}
Fallback off
}
fileFormatVersion: 2
guid: f1b13d7a80660504a858ea24cfa418c6
ShaderImporter:
userData:
Shader "Hidden/ChromaticAberration" {
Properties {
_MainTex ("Base", 2D) = "" {}
}
CGINCLUDE
#include "UnityCG.cginc"
struct v2f {
float4 pos : SV_POSITION;
float2 uv : TEXCOORD0;
};
sampler2D _MainTex;
float4 _MainTex_TexelSize;
half _ChromaticAberration;
half _AxialAberration;
half _Luminance;
half2 _BlurDistance;
v2f vert( appdata_img v )
{
v2f o;
o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
o.uv = v.texcoord.xy;
return o;
}
half4 fragDs(v2f i) : SV_Target
{
half4 c = tex2D (_MainTex, i.uv.xy + _MainTex_TexelSize.xy * 0.5);
c += tex2D (_MainTex, i.uv.xy - _MainTex_TexelSize.xy * 0.5);
c += tex2D (_MainTex, i.uv.xy + _MainTex_TexelSize.xy * float2(0.5,-0.5));
c += tex2D (_MainTex, i.uv.xy - _MainTex_TexelSize.xy * float2(0.5,-0.5));
return c/4.0;
}
half4 frag(v2f i) : SV_Target
{
half2 coords = i.uv;
half2 uv = i.uv;
coords = (coords - 0.5) * 2.0;
half coordDot = dot (coords,coords);
half2 uvG = uv - _MainTex_TexelSize.xy * _ChromaticAberration * coords * coordDot;
half4 color = tex2D (_MainTex, uv);
#if SHADER_API_D3D9
// Work around Cg's code generation bug for D3D9 pixel shaders :(
color.g = color.g * 0.0001 + tex2D (_MainTex, uvG).g;
#else
color.g = tex2D (_MainTex, uvG).g;
#endif
return color;
}
// squeezing into SM2.0 with 9 samples:
static const int SmallDiscKernelSamples = 9;
static const half2 SmallDiscKernel[SmallDiscKernelSamples] =
{
half2(-0.926212,-0.40581),
half2(-0.695914,0.457137),
half2(-0.203345,0.820716),
half2(0.96234,-0.194983),
half2(0.473434,-0.480026),
half2(0.519456,0.767022),
half2(0.185461,-0.893124),
half2(0.89642,0.412458),
half2(-0.32194,-0.932615),
};
half4 fragComplex(v2f i) : SV_Target
{
half2 coords = i.uv;
half2 uv = i.uv;
// corner heuristic
coords = (coords - 0.5h) * 2.0h;
half coordDot = dot (coords,coords);
half4 color = tex2D (_MainTex, uv);
half tangentialStrength = _ChromaticAberration * coordDot * coordDot;
half maxOfs = clamp(max(_AxialAberration, tangentialStrength), _BlurDistance.x, _BlurDistance.y);
// we need a blurred sample tap for advanced aberration
// NOTE: it's relatively important that input is HDR
// and if you do have a proper HDR setup, lerping .rb might yield better results than .g
// (see below)
half4 blurredTap = color * 0.1h;
for(int l=0; l < SmallDiscKernelSamples; l++)
{
half2 sampleUV = uv + SmallDiscKernel[l].xy * _MainTex_TexelSize.xy * maxOfs;
half3 tap = tex2D(_MainTex, sampleUV).rgb;
blurredTap.rgb += tap;
}
blurredTap.rgb /= (float)SmallDiscKernelSamples + 0.2h;
// debug:
//return blurredTap;
half lumDiff = Luminance(abs(blurredTap.rgb-color.rgb));
half isEdge = saturate(_Luminance * lumDiff);
// debug #2:
//return isEdge;
color.rb = lerp(color.rb, blurredTap.rb, isEdge);
return color;
}
ENDCG
Subshader {
// 0: box downsample
Pass {
ZTest Always Cull Off ZWrite Off
CGPROGRAM
#pragma vertex vert
#pragma fragment fragDs
ENDCG
}
// 1: simple chrom aberration
Pass {
ZTest Always Cull Off ZWrite Off
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
ENDCG
}
// 2: simulates more chromatic aberration effects
Pass {
ZTest Always Cull Off ZWrite Off
CGPROGRAM
#pragma vertex vert
#pragma fragment fragComplex
ENDCG
}
}
Fallback off
} // shader
fileFormatVersion: 2
guid: 2b4f29398d9484ccfa9fd220449f5eee
ShaderImporter:
userData:
Shader "Hidden/ColorCorrection3DLut" {
Properties {
_MainTex ("Base (RGB)", 2D) = "" {}
}
CGINCLUDE
#include "UnityCG.cginc"
struct v2f {
float4 pos : SV_POSITION;
float2 uv : TEXCOORD0;
};
sampler2D _MainTex;
sampler3D _ClutTex;
float _Scale;
float _Offset;
v2f vert( appdata_img v )
{
v2f o;
o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
o.uv = v.texcoord.xy;
return o;
}
float4 frag(v2f i) : SV_Target
{
float4 c = tex2D(_MainTex, i.uv);
c.rgb = tex3D(_ClutTex, c.rgb * _Scale + _Offset).rgb;
return c;
}
float4 fragLinear(v2f i) : SV_Target
{
float4 c = tex2D(_MainTex, i.uv);
c.rgb= sqrt(c.rgb);
c.rgb = tex3D(_ClutTex, c.rgb * _Scale + _Offset).rgb;
c.rgb = c.rgb*c.rgb;
return c;
}
ENDCG
Subshader
{
Pass
{
ZTest Always Cull Off ZWrite Off
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma target 3.0
ENDCG
}
Pass
{
ZTest Always Cull Off ZWrite Off
CGPROGRAM
#pragma vertex vert
#pragma fragment fragLinear
#pragma target 3.0
ENDCG
}
}
Fallback off
}
fileFormatVersion: 2
guid: b61f0d8d8244b4b28aa66b0c8cb46a8d
ShaderImporter:
userData:
Shader "Hidden/ColorCorrectionCurves" {
Properties {
_MainTex ("Base (RGB)", 2D) = "" {}
_RgbTex ("_RgbTex (RGB)", 2D) = "" {}
_ZCurve ("_ZCurve (RGB)", 2D) = "" {}
_RgbDepthTex ("_RgbDepthTex (RGB)", 2D) = "" {}
}
// note: also have a look at ColorCorrectionCurvesSimple
// for a much simpler color correction without use of
// depth texture lookups
// Shader code pasted into all further CGPROGRAM blocks
CGINCLUDE
#include "UnityCG.cginc"
struct v2f {
float4 pos : SV_POSITION;
float2 uv : TEXCOORD0;
float2 uv2 : TEXCOORD1;
};
sampler2D _MainTex;
sampler2D_float _CameraDepthTexture;
float4 _CameraDepthTexture_ST;
uniform float4 _MainTex_TexelSize;
sampler2D _RgbTex;
sampler2D _ZCurve;
sampler2D _RgbDepthTex;
fixed _Saturation;
v2f vert( appdata_img v )
{
v2f o;
o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
o.uv = v.texcoord.xy;
o.uv2 = TRANSFORM_TEX(v.texcoord, _CameraDepthTexture);
#if UNITY_UV_STARTS_AT_TOP
if (_MainTex_TexelSize.y < 0)
o.uv2.y = 1-o.uv2.y;
#endif
return o;
}
half4 frag(v2f i) : SV_Target
{
half4 color = tex2D(_MainTex, i.uv);
half3 ycoords = half3(0.5,1.5,2.5) * 0.25;
half3 red = tex2D(_RgbTex, half2(color.r, ycoords.x)).rgb * half3(1,0,0);
half3 green = tex2D(_RgbTex, half2(color.g, ycoords.y)).rgb * half3(0,1,0);
half3 blue = tex2D(_RgbTex, half2(color.b, ycoords.z)).rgb * half3(0,0,1);
half theDepth = SAMPLE_DEPTH_TEXTURE( _CameraDepthTexture, i.uv2) ;
half zval = tex2D(_ZCurve, half2( Linear01Depth (theDepth), 0.5));
half3 depthRed = tex2D(_RgbDepthTex, half2(color.r, ycoords.x)).rgb * half3(1,0,0);
half3 depthGreen = tex2D(_RgbDepthTex, half2(color.g, ycoords.y)).rgb * half3(0,1,0);
half3 depthBlue = tex2D(_RgbDepthTex, half2(color.b, ycoords.z)).rgb * half3(0,0,1);
color = half4( lerp(red+green+blue, depthRed+depthBlue+depthGreen, zval), color.a);
half lum = Luminance(color.rgb);
color.rgb = lerp(half3(lum,lum,lum), color.rgb, _Saturation);
return color;
}
ENDCG
Subshader {
Pass {
ZTest Always Cull Off ZWrite Off
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
ENDCG
}
}
Fallback off
} // shader
fileFormatVersion: 2
guid: 62bcade1028c24ca1a39760ed84b9487
ShaderImporter:
userData:
Shader "Hidden/ColorCorrectionCurvesSimple" {
Properties {
_MainTex ("Base (RGB)", 2D) = "" {}
_RgbTex ("_RgbTex (RGB)", 2D) = "" {}
}
// Shader code pasted into all further CGPROGRAM blocks
CGINCLUDE
#include "UnityCG.cginc"
struct v2f {
float4 pos : SV_POSITION;
half2 uv : TEXCOORD0;
};
sampler2D _MainTex;
sampler2D _RgbTex;
fixed _Saturation;
v2f vert( appdata_img v )
{
v2f o;
o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
o.uv = v.texcoord.xy;
return o;
}
fixed4 frag(v2f i) : SV_Target
{
fixed4 color = tex2D(_MainTex, i.uv);
fixed3 red = tex2D(_RgbTex, half2(color.r, 0.5/4.0)).rgb * fixed3(1,0,0);
fixed3 green = tex2D(_RgbTex, half2(color.g, 1.5/4.0)).rgb * fixed3(0,1,0);
fixed3 blue = tex2D(_RgbTex, half2(color.b, 2.5/4.0)).rgb * fixed3(0,0,1);
color = fixed4(red+green+blue, color.a);
fixed lum = Luminance(color.rgb);
color.rgb = lerp(fixed3(lum,lum,lum), color.rgb, _Saturation);
return color;
}
ENDCG
Subshader {
Pass {
ZTest Always Cull Off ZWrite Off
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
ENDCG
}
}
Fallback off
} // shader
fileFormatVersion: 2
guid: 438ddd58d82c84d9eb1fdc56111702e1
ShaderImporter:
userData:
Shader "Hidden/Color Correction Effect" {
Properties {
_MainTex ("Base (RGB)", 2D) = "white" {}
_RampTex ("Base (RGB)", 2D) = "grayscaleRamp" {}
}
SubShader {
Pass {
ZTest Always Cull Off ZWrite Off
CGPROGRAM
#pragma vertex vert_img
#pragma fragment frag
#include "UnityCG.cginc"
uniform sampler2D _MainTex;
uniform sampler2D _RampTex;
fixed4 frag (v2f_img i) : SV_Target
{
fixed4 orig = tex2D(_MainTex, i.uv);
fixed rr = tex2D(_RampTex, orig.rr).r;
fixed gg = tex2D(_RampTex, orig.gg).g;
fixed bb = tex2D(_RampTex, orig.bb).b;
fixed4 color = fixed4(rr, gg, bb, orig.a);
return color;
}
ENDCG
}
}
Fallback off
}
fileFormatVersion: 2
guid: 67f8781cad112c75d0008dfa8d76c639
ShaderImporter:
userData:
Shader "Hidden/ColorCorrectionSelective" {
Properties {
_MainTex ("Base (RGB)", 2D) = "" {}
}
CGINCLUDE
#include "UnityCG.cginc"
struct v2f {
float4 pos : SV_POSITION;
float2 uv : TEXCOORD0;
};
sampler2D _MainTex;
float4 selColor;
float4 targetColor;
v2f vert( appdata_img v ) {
v2f o;
o.pos = mul (UNITY_MATRIX_MVP, v.vertex);
o.uv = v.texcoord.xy;
return o;
}
fixed4 frag(v2f i) : SV_Target {
fixed4 color = tex2D (_MainTex, i.uv);
fixed diff = saturate (2.0 * length (color.rgb - selColor.rgb));
color = lerp (targetColor, color, diff);
return color;
}
ENDCG
Subshader {
Pass {
ZTest Always Cull Off ZWrite Off
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
ENDCG
}
}
Fallback off
}
fileFormatVersion: 2
guid: e515e0f94cefc4c0db54b45cba621544
ShaderImporter:
userData:
fileFormatVersion: 2
guid: a40c1b84cf7fe418bae97a29041b85a4
folderAsset: yes
timeCreated: 1433531211
licenseType: Free
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:
// Calculates adaptation to minimum/maximum luminance values,
// based on "currently adapted" and "new values to adapt to"
// textures (both 1x1).
Shader "Hidden/Contrast Stretch Adaptation" {
Properties {
_MainTex ("Base (RGB)", 2D) = "white" {}
_CurTex ("Base (RGB)", 2D) = "white" {}
}
Category {
SubShader {
Pass {
ZTest Always Cull Off ZWrite Off
CGPROGRAM
#pragma vertex vert_img
#pragma fragment frag
#include "UnityCG.cginc"
uniform sampler2D _MainTex; // currently adapted to
uniform sampler2D _CurTex; // new value to adapt to
uniform float4 _AdaptParams; // x=adaptLerp, y=limitMinimum, z=limitMaximum
float4 frag (v2f_img i) : SV_Target {
// value is: max, min
float2 valAdapted = tex2D(_MainTex, i.uv).xy;
float2 valCur = tex2D(_CurTex, i.uv).xy;
// Calculate new adapted values: interpolate
// from valAdapted to valCur by script-supplied amount.
//
// Because we store adaptation levels in a simple 8 bit/channel
// texture, we might not have enough precision - the interpolation
// amount might be too small to change anything, and we'll never
// arrive at the needed values.
//
// So we make sure the change we do is at least 1/255th of the
// color range - this way we'll always change the value.
const float kMinChange = 1.0/255.0;
float2 delta = (valCur-valAdapted) * _AdaptParams.x;
delta.x = sign(delta.x) * max( kMinChange, abs(delta.x) );
delta.y = sign(delta.y) * max( kMinChange, abs(delta.y) );
float4 valNew;
valNew.xy = valAdapted + delta;
// Impose user limits on maximum/minimum values
valNew.x = max( valNew.x, _AdaptParams.z );
valNew.y = min( valNew.y, _AdaptParams.y );
// Optimization so that our final apply pass is faster:
// z = max-min (plus a small amount to prevent division by zero)
valNew.z = valNew.x - valNew.y + 0.01;
// w = min/(max-min)
valNew.w = valNew.y / valNew.z;
return valNew;
}
ENDCG
}
}
}
Fallback off
}
fileFormatVersion: 2
guid: 257bc83cbeb544540bd0e558aa9b1383
ShaderImporter:
userData:
// Final pass in the contrast stretch effect: apply
// color stretch to the original image, based on currently
// adapted to minimum/maximum luminances.
Shader "Hidden/Contrast Stretch Apply" {
Properties {
_MainTex ("Base (RGB)", 2D) = "white" {}
_AdaptTex ("Base (RGB)", 2D) = "white" {}
}
Category {
SubShader {
Pass {
ZTest Always Cull Off ZWrite Off
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
struct v2f {
float4 pos : SV_POSITION;
float2 uv[2] : TEXCOORD0;
};
uniform sampler2D _MainTex;
uniform sampler2D _AdaptTex;
v2f vert (appdata_img v)
{
v2f o;
o.pos = mul (UNITY_MATRIX_MVP, v.vertex);
o.uv[0] = MultiplyUV (UNITY_MATRIX_TEXTURE0, v.texcoord);
o.uv[1] = float2(0.5,0.5);
return o;
}
float4 frag (v2f i) : SV_Target
{
float4 col = tex2D(_MainTex, i.uv[0]);
float4 adapted = tex2D(_AdaptTex, i.uv[1]);
float vmul = 1.0 / adapted.z;
float vadd = -adapted.w;
col.rgb = col.rgb * vmul + vadd;
return col;
}
ENDCG
}
}
}
Fallback off
}
fileFormatVersion: 2
guid: f4901f25d4e1542589348bbb89563d8e
ShaderImporter:
userData:
// Outputs luminance (grayscale) of the input image _MainTex
Shader "Hidden/Contrast Stretch Luminance" {
Properties {
_MainTex ("Base (RGB)", 2D) = "white" {}
}
Category {
SubShader {
Pass {
ZTest Always Cull Off ZWrite Off
CGPROGRAM
#pragma vertex vert_img
#pragma fragment frag
#include "UnityCG.cginc"
uniform sampler2D _MainTex;
float4 frag (v2f_img i) : SV_Target
{
float4 col = tex2D(_MainTex, i.uv);
col.rgb = Luminance(col.rgb) * (1+col.a*2);
return col;
}
ENDCG
}
}
}
Fallback off
}
fileFormatVersion: 2
guid: befbb4b9c320b4b18a08ef7afb93b6c9
ShaderImporter:
userData:
// Reduces input image (_MainTex) by 2x2.
// Outputs maximum value in R, minimum in G.
Shader "Hidden/Contrast Stretch Reduction" {
Properties {
_MainTex ("Base (RGB)", 2D) = "white" {}
}
Category {
SubShader {
Pass {
ZTest Always Cull Off ZWrite Off
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
struct v2f {
float4 position : SV_POSITION;
float2 uv[4] : TEXCOORD0;
};
uniform sampler2D _MainTex;
v2f vert (appdata_img v) {
v2f o;
o.position = mul (UNITY_MATRIX_MVP, v.vertex);
float2 uv = MultiplyUV (UNITY_MATRIX_TEXTURE0, v.texcoord);
// Compute UVs to sample 2x2 pixel block.
o.uv[0] = uv + float2(0,0);
o.uv[1] = uv + float2(0,1);
o.uv[2] = uv + float2(1,0);
o.uv[3] = uv + float2(1,1);
return o;
}
float4 frag (v2f i) : SV_Target
{
// Sample pixel block
float4 v00 = tex2D(_MainTex, i.uv[0]);
float2 v01 = tex2D(_MainTex, i.uv[1]).xy;
float2 v10 = tex2D(_MainTex, i.uv[2]).xy;
float2 v11 = tex2D(_MainTex, i.uv[3]).xy;
float4 res;
// output x: maximum of the four values
res.x = max( max(v00.x,v01.x), max(v10.x,v11.x) );
// output y: minimum of the four values
res.y = min( min(v00.y,v01.y), min(v10.y,v11.y) );
// output zw unchanged from the first pixel
res.zw = v00.zw;
return res;
}
ENDCG
}
}
}
Fallback off
}
fileFormatVersion: 2
guid: 57b33a14b6d5347c5a85c36f6cb3b280
ShaderImporter:
userData:
Shader "Hidden/ContrastComposite" {
Properties {
_MainTex ("Base (RGB)", 2D) = "" {}
_MainTexBlurred ("Base Blurred (RGB)", 2D) = "" {}
}
// Shader code pasted into all further CGPROGRAM blocks
CGINCLUDE
#include "UnityCG.cginc"
struct v2f {
float4 pos : SV_POSITION;
float2 uv[2] : TEXCOORD0;
};
sampler2D _MainTex;
sampler2D _MainTexBlurred;
float4 _MainTex_TexelSize;
float intensity;
float threshhold;
v2f vert( appdata_img v ) {
v2f o;
o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
o.uv[0] = v.texcoord.xy;
o.uv[1] = v.texcoord.xy;
#if UNITY_UV_STARTS_AT_TOP
if (_MainTex_TexelSize.y < 0)
o.uv[0].y = 1-o.uv[0].y;
#endif
return o;
}
half4 frag(v2f i) : SV_Target
{
half4 color = tex2D (_MainTex, i.uv[1]);
half4 blurred = tex2D (_MainTexBlurred, (i.uv[0]));
half4 difff = color - blurred;
half4 signs = sign (difff);
difff = saturate ( (color-blurred) - threshhold) * signs * 1.0/(1.0-threshhold);
color += difff * intensity;
return color;
}
ENDCG
Subshader {
Pass {
ZTest Always Cull Off ZWrite Off
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
ENDCG
}
}
Fallback off
} // shader
fileFormatVersion: 2
guid: 273404942eede4ea1883ca1fb2942507
ShaderImporter:
userData:
Shader "Hidden/ConvertDepth" {
Properties {
_MainTex ("Base (RGB)", 2D) = "" {}
}
// Shader code pasted into all further CGPROGRAM blocks
CGINCLUDE
#include "UnityCG.cginc"
struct v2f {
float4 pos : SV_POSITION;
float2 uv : TEXCOORD0;
};
sampler2D _MainTex;
sampler2D_float _CameraDepthTexture;
v2f vert( appdata_img v )
{
v2f o;
o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
o.uv = v.texcoord.xy;
return o;
}
half4 frag(v2f i) : SV_Target
{
float d = SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, i.uv.xy);
d = Linear01Depth(d);
if(d>0.99999)
return half4(1,1,1,1);
else
return EncodeFloatRGBA(d);
}
ENDCG
Subshader {
Pass {
ZTest Always Cull Off ZWrite Off
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
ENDCG
}
}
Fallback off
} // shader
fileFormatVersion: 2
guid: 14768d3865b1342e3a861fbe19ba2db2
ShaderImporter:
userData:
Shader "Hidden/CreaseApply" {
Properties {
_MainTex ("Base (RGB)", 2D) = "white" {}
_HrDepthTex ("Base (RGB)", 2D) = "white" {}
_LrDepthTex ("Base (RGB)", 2D) = "white" {}
}
SubShader {
Pass {
ZTest Always Cull Off ZWrite Off
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
sampler2D _MainTex;
sampler2D _HrDepthTex;
sampler2D _LrDepthTex;
uniform float4 _MainTex_TexelSize;
uniform float intensity;
struct v2f {
float4 pos : SV_POSITION;
float2 uv : TEXCOORD0;
};
v2f vert( appdata_img v )
{
v2f o;
o.pos = mul (UNITY_MATRIX_MVP, v.vertex);
o.uv.xy = v.texcoord.xy;
return o;
}
half4 frag (v2f i) : SV_Target
{
float4 hrDepth = tex2D(_HrDepthTex, i.uv);
float4 lrDepth = tex2D(_LrDepthTex, i.uv);
hrDepth.a = DecodeFloatRGBA(hrDepth);
lrDepth.a = DecodeFloatRGBA(lrDepth);
float4 color = tex2D(_MainTex, i.uv);
return color * (1.0-abs(hrDepth.a-lrDepth.a)*intensity);
}
ENDCG
}
}
Fallback off
}
fileFormatVersion: 2
guid: b59984d82af624bd3b0c777f038276f2
ShaderImporter:
userData:
Shader "Hidden/EdgeDetect" {
Properties {
_MainTex ("Base (RGB)", 2D) = "" {}
}
CGINCLUDE
#include "UnityCG.cginc"
struct v2f {
float4 pos : SV_POSITION;
float2 uv[5] : TEXCOORD0;
};
struct v2fd {
float4 pos : SV_POSITION;
float2 uv[2] : TEXCOORD0;
};
sampler2D _MainTex;
uniform float4 _MainTex_TexelSize;
sampler2D _CameraDepthNormalsTexture;
sampler2D_float _CameraDepthTexture;
uniform half4 _Sensitivity;
uniform half4 _BgColor;
uniform half _BgFade;
uniform half _SampleDistance;
uniform float _Exponent;
uniform float _Threshold;
struct v2flum {
float4 pos : SV_POSITION;
float2 uv[3] : TEXCOORD0;
};
v2flum vertLum (appdata_img v)
{
v2flum o;
o.pos = mul (UNITY_MATRIX_MVP, v.vertex);
float2 uv = MultiplyUV( UNITY_MATRIX_TEXTURE0, v.texcoord );
o.uv[0] = uv;
o.uv[1] = uv + float2(-_MainTex_TexelSize.x, -_MainTex_TexelSize.y) * _SampleDistance;
o.uv[2] = uv + float2(+_MainTex_TexelSize.x, -_MainTex_TexelSize.y) * _SampleDistance;
return o;
}
fixed4 fragLum (v2flum i) : SV_Target
{
fixed4 original = tex2D(_MainTex, i.uv[0]);
// a very simple cross gradient filter
half3 p1 = original.rgb;
half3 p2 = tex2D(_MainTex, i.uv[1]).rgb;
half3 p3 = tex2D(_MainTex, i.uv[2]).rgb;
half3 diff = p1 * 2 - p2 - p3;
half len = dot(diff, diff);
len = step(len, _Threshold);
//if(len >= _Threshold)
// original.rgb = 0;
return len * lerp(original, _BgColor, _BgFade);
}
inline half CheckSame (half2 centerNormal, float centerDepth, half4 theSample)
{
// difference in normals
// do not bother decoding normals - there's no need here
half2 diff = abs(centerNormal - theSample.xy) * _Sensitivity.y;
half isSameNormal = (diff.x + diff.y) * _Sensitivity.y < 0.1;
// difference in depth
float sampleDepth = DecodeFloatRG (theSample.zw);
float zdiff = abs(centerDepth-sampleDepth);
// scale the required threshold by the distance
half isSameDepth = zdiff * _Sensitivity.x < 0.09 * centerDepth;
// return:
// 1 - if normals and depth are similar enough
// 0 - otherwise
return isSameNormal * isSameDepth;
}
v2f vertRobert( appdata_img v )
{
v2f o;
o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
float2 uv = v.texcoord.xy;
o.uv[0] = uv;
#if UNITY_UV_STARTS_AT_TOP
if (_MainTex_TexelSize.y < 0)
uv.y = 1-uv.y;
#endif
// calc coord for the X pattern
// maybe nicer TODO for the future: 'rotated triangles'
o.uv[1] = uv + _MainTex_TexelSize.xy * half2(1,1) * _SampleDistance;
o.uv[2] = uv + _MainTex_TexelSize.xy * half2(-1,-1) * _SampleDistance;
o.uv[3] = uv + _MainTex_TexelSize.xy * half2(-1,1) * _SampleDistance;
o.uv[4] = uv + _MainTex_TexelSize.xy * half2(1,-1) * _SampleDistance;
return o;
}
v2f vertThin( appdata_img v )
{
v2f o;
o.pos = mul (UNITY_MATRIX_MVP, v.vertex);
float2 uv = v.texcoord.xy;
o.uv[0] = uv;
#if UNITY_UV_STARTS_AT_TOP
if (_MainTex_TexelSize.y < 0)
uv.y = 1-uv.y;
#endif
o.uv[1] = uv;
o.uv[4] = uv;
// offsets for two additional samples
o.uv[2] = uv + float2(-_MainTex_TexelSize.x, -_MainTex_TexelSize.y) * _SampleDistance;
o.uv[3] = uv + float2(+_MainTex_TexelSize.x, -_MainTex_TexelSize.y) * _SampleDistance;
return o;
}
v2fd vertD( appdata_img v )
{
v2fd o;
o.pos = mul (UNITY_MATRIX_MVP, v.vertex);
float2 uv = v.texcoord.xy;
o.uv[0] = uv;
#if UNITY_UV_STARTS_AT_TOP
if (_MainTex_TexelSize.y < 0)
uv.y = 1-uv.y;
#endif
o.uv[1] = uv;
return o;
}
float4 fragDCheap(v2fd i) : SV_Target
{
// inspired by borderlands implementation of popular "sobel filter"
float centerDepth = Linear01Depth(SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, i.uv[1]));
float4 depthsDiag;
float4 depthsAxis;
float2 uvDist = _SampleDistance * _MainTex_TexelSize.xy;
depthsDiag.x = Linear01Depth(SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture,i.uv[1]+uvDist)); // TR
depthsDiag.y = Linear01Depth(SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture,i.uv[1]+uvDist*float2(-1,1))); // TL
depthsDiag.z = Linear01Depth(SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture,i.uv[1]-uvDist*float2(-1,1))); // BR
depthsDiag.w = Linear01Depth(SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture,i.uv[1]-uvDist)); // BL
depthsAxis.x = Linear01Depth(SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture,i.uv[1]+uvDist*float2(0,1))); // T
depthsAxis.y = Linear01Depth(SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture,i.uv[1]-uvDist*float2(1,0))); // L
depthsAxis.z = Linear01Depth(SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture,i.uv[1]+uvDist*float2(1,0))); // R
depthsAxis.w = Linear01Depth(SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture,i.uv[1]-uvDist*float2(0,1))); // B
depthsDiag -= centerDepth;
depthsAxis /= centerDepth;
const float4 HorizDiagCoeff = float4(1,1,-1,-1);
const float4 VertDiagCoeff = float4(-1,1,-1,1);
const float4 HorizAxisCoeff = float4(1,0,0,-1);
const float4 VertAxisCoeff = float4(0,1,-1,0);
float4 SobelH = depthsDiag * HorizDiagCoeff + depthsAxis * HorizAxisCoeff;
float4 SobelV = depthsDiag * VertDiagCoeff + depthsAxis * VertAxisCoeff;
float SobelX = dot(SobelH, float4(1,1,1,1));
float SobelY = dot(SobelV, float4(1,1,1,1));
float Sobel = sqrt(SobelX * SobelX + SobelY * SobelY);
Sobel = 1.0-pow(saturate(Sobel), _Exponent);
return Sobel * lerp(tex2D(_MainTex, i.uv[0].xy), _BgColor, _BgFade);
}
// pretty much also just a sobel filter, except for that edges "outside" the silhouette get discarded
// which makes it compatible with other depth based post fx
float4 fragD(v2fd i) : SV_Target
{
// inspired by borderlands implementation of popular "sobel filter"
float centerDepth = Linear01Depth(SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, i.uv[1]));
float4 depthsDiag;
float4 depthsAxis;
float2 uvDist = _SampleDistance * _MainTex_TexelSize.xy;
depthsDiag.x = Linear01Depth(SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture,i.uv[1]+uvDist)); // TR
depthsDiag.y = Linear01Depth(SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture,i.uv[1]+uvDist*float2(-1,1))); // TL
depthsDiag.z = Linear01Depth(SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture,i.uv[1]-uvDist*float2(-1,1))); // BR
depthsDiag.w = Linear01Depth(SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture,i.uv[1]-uvDist)); // BL
depthsAxis.x = Linear01Depth(SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture,i.uv[1]+uvDist*float2(0,1))); // T
depthsAxis.y = Linear01Depth(SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture,i.uv[1]-uvDist*float2(1,0))); // L
depthsAxis.z = Linear01Depth(SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture,i.uv[1]+uvDist*float2(1,0))); // R
depthsAxis.w = Linear01Depth(SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture,i.uv[1]-uvDist*float2(0,1))); // B
// make it work nicely with depth based image effects such as depth of field:
depthsDiag = (depthsDiag > centerDepth.xxxx) ? depthsDiag : centerDepth.xxxx;
depthsAxis = (depthsAxis > centerDepth.xxxx) ? depthsAxis : centerDepth.xxxx;
depthsDiag -= centerDepth;
depthsAxis /= centerDepth;
const float4 HorizDiagCoeff = float4(1,1,-1,-1);
const float4 VertDiagCoeff = float4(-1,1,-1,1);
const float4 HorizAxisCoeff = float4(1,0,0,-1);
const float4 VertAxisCoeff = float4(0,1,-1,0);
float4 SobelH = depthsDiag * HorizDiagCoeff + depthsAxis * HorizAxisCoeff;
float4 SobelV = depthsDiag * VertDiagCoeff + depthsAxis * VertAxisCoeff;
float SobelX = dot(SobelH, float4(1,1,1,1));
float SobelY = dot(SobelV, float4(1,1,1,1));
float Sobel = sqrt(SobelX * SobelX + SobelY * SobelY);
Sobel = 1.0-pow(saturate(Sobel), _Exponent);
return Sobel * lerp(tex2D(_MainTex, i.uv[0].xy), _BgColor, _BgFade);
}
half4 fragRobert(v2f i) : SV_Target {
half4 sample1 = tex2D(_CameraDepthNormalsTexture, i.uv[1].xy);
half4 sample2 = tex2D(_CameraDepthNormalsTexture, i.uv[2].xy);
half4 sample3 = tex2D(_CameraDepthNormalsTexture, i.uv[3].xy);
half4 sample4 = tex2D(_CameraDepthNormalsTexture, i.uv[4].xy);
half edge = 1.0;
edge *= CheckSame(sample1.xy, DecodeFloatRG(sample1.zw), sample2);
edge *= CheckSame(sample3.xy, DecodeFloatRG(sample3.zw), sample4);
return edge * lerp(tex2D(_MainTex, i.uv[0]), _BgColor, _BgFade);
}
half4 fragThin (v2f i) : SV_Target
{
half4 original = tex2D(_MainTex, i.uv[0]);
half4 center = tex2D (_CameraDepthNormalsTexture, i.uv[1]);
half4 sample1 = tex2D (_CameraDepthNormalsTexture, i.uv[2]);
half4 sample2 = tex2D (_CameraDepthNormalsTexture, i.uv[3]);
// encoded normal
half2 centerNormal = center.xy;
// decoded depth
float centerDepth = DecodeFloatRG (center.zw);
half edge = 1.0;
edge *= CheckSame(centerNormal, centerDepth, sample1);
edge *= CheckSame(centerNormal, centerDepth, sample2);
return edge * lerp(original, _BgColor, _BgFade);
}
ENDCG
Subshader {
Pass {
ZTest Always Cull Off ZWrite Off
CGPROGRAM
#pragma vertex vertThin
#pragma fragment fragThin
ENDCG
}
Pass {
ZTest Always Cull Off ZWrite Off
CGPROGRAM
#pragma vertex vertRobert
#pragma fragment fragRobert
ENDCG
}
Pass {
ZTest Always Cull Off ZWrite Off
CGPROGRAM
#pragma target 3.0
#pragma vertex vertD
#pragma fragment fragDCheap
ENDCG
}
Pass {
ZTest Always Cull Off ZWrite Off
CGPROGRAM
#pragma target 3.0
#pragma vertex vertD
#pragma fragment fragD
ENDCG
}
Pass {
ZTest Always Cull Off ZWrite Off
CGPROGRAM
#pragma target 3.0
#pragma vertex vertLum
#pragma fragment fragLum
ENDCG
}
}
Fallback off
} // shader
fileFormatVersion: 2
guid: 0d1644bdf064147baa97f235fc5b4903
ShaderImporter:
userData:
Shader "Hidden/FisheyeShader" {
Properties {
_MainTex ("Base (RGB)", 2D) = "" {}
}
// Shader code pasted into all further CGPROGRAM blocks
CGINCLUDE
#include "UnityCG.cginc"
struct v2f {
float4 pos : SV_POSITION;
float2 uv : TEXCOORD0;
};
sampler2D _MainTex;
float2 intensity;
v2f vert( appdata_img v )
{
v2f o;
o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
o.uv = v.texcoord.xy;
return o;
}
half4 frag(v2f i) : SV_Target
{
half2 coords = i.uv;
coords = (coords - 0.5) * 2.0;
half2 realCoordOffs;
realCoordOffs.x = (1-coords.y * coords.y) * intensity.y * (coords.x);
realCoordOffs.y = (1-coords.x * coords.x) * intensity.x * (coords.y);
half4 color = tex2D (_MainTex, i.uv - realCoordOffs);
return color;
}
ENDCG
Subshader {
Pass {
ZTest Always Cull Off ZWrite Off
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
ENDCG
}
}
Fallback off
} // shader
fileFormatVersion: 2
guid: 874ceab4425f64bccb1d14032f4452b1
ShaderImporter:
userData:
Shader "Hidden/GlobalFog" {
Properties {
_MainTex ("Base (RGB)", 2D) = "black" {}
}
CGINCLUDE
#include "UnityCG.cginc"
uniform sampler2D _MainTex;
uniform sampler2D_float _CameraDepthTexture;
// x = fog height
// y = FdotC (CameraY-FogHeight)
// z = k (FdotC > 0.0)
// w = a/2
uniform float4 _HeightParams;
// x = start distance
uniform float4 _DistanceParams;
int4 _SceneFogMode; // x = fog mode, y = use radial flag
float4 _SceneFogParams;
#ifndef UNITY_APPLY_FOG
half4 unity_FogColor;
half4 unity_FogDensity;
#endif
uniform float4 _MainTex_TexelSize;
// for fast world space reconstruction
uniform float4x4 _FrustumCornersWS;
uniform float4 _CameraWS;
struct v2f {
float4 pos : SV_POSITION;
float2 uv : TEXCOORD0;
float2 uv_depth : TEXCOORD1;
float4 interpolatedRay : TEXCOORD2;
};
v2f vert (appdata_img v)
{
v2f o;
half index = v.vertex.z;
v.vertex.z = 0.1;
o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
o.uv = v.texcoord.xy;
o.uv_depth = v.texcoord.xy;
#if UNITY_UV_STARTS_AT_TOP
if (_MainTex_TexelSize.y < 0)
o.uv.y = 1-o.uv.y;
#endif
o.interpolatedRay = _FrustumCornersWS[(int)index];
o.interpolatedRay.w = index;
return o;
}
// Applies one of standard fog formulas, given fog coordinate (i.e. distance)
half ComputeFogFactor (float coord)
{
float fogFac = 0.0;
if (_SceneFogMode.x == 1) // linear
{
// factor = (end-z)/(end-start) = z * (-1/(end-start)) + (end/(end-start))
fogFac = coord * _SceneFogParams.z + _SceneFogParams.w;
}
if (_SceneFogMode.x == 2) // exp
{
// factor = exp(-density*z)
fogFac = _SceneFogParams.y * coord; fogFac = exp2(-fogFac);
}
if (_SceneFogMode.x == 3) // exp2
{
// factor = exp(-(density*z)^2)
fogFac = _SceneFogParams.x * coord; fogFac = exp2(-fogFac*fogFac);
}
return saturate(fogFac);
}
// Distance-based fog
float ComputeDistance (float3 camDir, float zdepth)
{
float dist;
if (_SceneFogMode.y == 1)
dist = length(camDir);
else
dist = zdepth * _ProjectionParams.z;
// Built-in fog starts at near plane, so match that by
// subtracting the near value. Not a perfect approximation
// if near plane is very large, but good enough.
dist -= _ProjectionParams.y;
return dist;
}
// Linear half-space fog, from https://www.terathon.com/lengyel/Lengyel-UnifiedFog.pdf
float ComputeHalfSpace (float3 wsDir)
{
float3 wpos = _CameraWS + wsDir;
float FH = _HeightParams.x;
float3 C = _CameraWS;
float3 V = wsDir;
float3 P = wpos;
float3 aV = _HeightParams.w * V;
float FdotC = _HeightParams.y;
float k = _HeightParams.z;
float FdotP = P.y-FH;
float FdotV = wsDir.y;
float c1 = k * (FdotP + FdotC);
float c2 = (1-2*k) * FdotP;
float g = min(c2, 0.0);
g = -length(aV) * (c1 - g * g / abs(FdotV+1.0e-5f));
return g;
}
half4 ComputeFog (v2f i, bool distance, bool height) : SV_Target
{
half4 sceneColor = tex2D(_MainTex, i.uv);
// Reconstruct world space position & direction
// towards this screen pixel.
float rawDepth = SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture,i.uv_depth);
float dpth = Linear01Depth(rawDepth);
float4 wsDir = dpth * i.interpolatedRay;
float4 wsPos = _CameraWS + wsDir;
// Compute fog distance
float g = _DistanceParams.x;
if (distance)
g += ComputeDistance (wsDir, dpth);
if (height)
g += ComputeHalfSpace (wsDir);
// Compute fog amount
half fogFac = ComputeFogFactor (max(0.0,g));
// Do not fog skybox
if (rawDepth >= 0.999999)
fogFac = 1.0;
//return fogFac; // for debugging
// Lerp between fog color & original scene color
// by fog amount
return lerp (unity_FogColor, sceneColor, fogFac);
}
ENDCG
SubShader
{
ZTest Always Cull Off ZWrite Off Fog { Mode Off }
// 0: distance + height
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
half4 frag (v2f i) : SV_Target { return ComputeFog (i, true, true); }
ENDCG
}
// 1: distance
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
half4 frag (v2f i) : SV_Target { return ComputeFog (i, true, false); }
ENDCG
}
// 2: height
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
half4 frag (v2f i) : SV_Target { return ComputeFog (i, false, true); }
ENDCG
}
}
Fallback off
}
fileFormatVersion: 2
guid: 70d8568987ac0499f952b54c7c13e265
ShaderImporter:
userData:
Shader "Hidden/Grayscale Effect" {
Properties {
_MainTex ("Base (RGB)", 2D) = "white" {}
_RampTex ("Base (RGB)", 2D) = "grayscaleRamp" {}
}
SubShader {
Pass {
ZTest Always Cull Off ZWrite Off
CGPROGRAM
#pragma vertex vert_img
#pragma fragment frag
#include "UnityCG.cginc"
uniform sampler2D _MainTex;
uniform sampler2D _RampTex;
uniform half _RampOffset;
fixed4 frag (v2f_img i) : SV_Target
{
fixed4 original = tex2D(_MainTex, i.uv);
fixed grayscale = Luminance(original.rgb);
half2 remap = half2 (grayscale + _RampOffset, .5);
fixed4 output = tex2D(_RampTex, remap);
output.a = original.a;
return output;
}
ENDCG
}
}
Fallback off
}
fileFormatVersion: 2
guid: daf9781cad112c75d0008dfa8d76c639
ShaderImporter:
userData:
Shader "Hidden/MotionBlur" {
Properties {
_MainTex ("Base (RGB)", 2D) = "white" {}
_AccumOrig("AccumOrig", Float) = 0.65
}
SubShader {
ZTest Always Cull Off ZWrite Off
Pass {
Blend SrcAlpha OneMinusSrcAlpha
ColorMask RGB
BindChannels {
Bind "vertex", vertex
Bind "texcoord", texcoord
}
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
struct appdata_t {
float4 vertex : POSITION;
float2 texcoord : TEXCOORD;
};
struct v2f {
float4 vertex : SV_POSITION;
float2 texcoord : TEXCOORD;
};
float4 _MainTex_ST;
float _AccumOrig;
v2f vert (appdata_t v)
{
v2f o;
o.vertex = mul(UNITY_MATRIX_MVP, v.vertex);
o.texcoord = TRANSFORM_TEX(v.texcoord, _MainTex);
return o;
}
sampler2D _MainTex;
half4 frag (v2f i) : SV_Target
{
return half4(tex2D(_MainTex, i.texcoord).rgb, _AccumOrig );
}
ENDCG
}
Pass {
Blend One Zero
ColorMask A
BindChannels {
Bind "vertex", vertex
Bind "texcoord", texcoord
}
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
struct appdata_t {
float4 vertex : POSITION;
float2 texcoord : TEXCOORD;
};
struct v2f {
float4 vertex : SV_POSITION;
float2 texcoord : TEXCOORD;
};
float4 _MainTex_ST;
v2f vert (appdata_t v)
{
v2f o;
o.vertex = mul(UNITY_MATRIX_MVP, v.vertex);
o.texcoord = TRANSFORM_TEX(v.texcoord, _MainTex);
return o;
}
sampler2D _MainTex;
half4 frag (v2f i) : SV_Target
{
return tex2D(_MainTex, i.texcoord);
}
ENDCG
}
}
SubShader {
ZTest Always Cull Off ZWrite Off
Pass {
Blend SrcAlpha OneMinusSrcAlpha
ColorMask RGB
SetTexture [_MainTex] {
ConstantColor (0,0,0,[_AccumOrig])
Combine texture, constant
}
}
Pass {
Blend One Zero
ColorMask A
SetTexture [_MainTex] {
Combine texture
}
}
}
Fallback off
}
fileFormatVersion: 2
guid: e9ba2083ad114a07d000fbfb8d76c639
ShaderImporter:
userData:
Shader "Hidden/MotionBlurClear"
{
Properties { }
SubShader {
Pass {
//ZTest LEqual
ZTest Always // lame depth test
ZWrite Off // lame depth test
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
struct vs_input {
float4 vertex : POSITION;
};
struct ps_input {
float4 pos : SV_POSITION;
float4 screen : TEXCOORD0;
};
sampler2D_float _CameraDepthTexture;
ps_input vert (vs_input v)
{
ps_input o;
o.pos = mul (UNITY_MATRIX_MVP, v.vertex);
o.screen = ComputeScreenPos(o.pos);
COMPUTE_EYEDEPTH(o.screen.z);
return o;
}
float4 frag (ps_input i) : SV_Target
{
// superlame: manual depth test needed as we can't bind depth, FIXME for 4.x
// alternatively implement SM > 3 version where we write out custom depth
float d = SAMPLE_DEPTH_TEXTURE_PROJ(_CameraDepthTexture, UNITY_PROJ_COORD(i.screen));
d = LinearEyeDepth(d);
clip(d - i.screen.z + 1e-2f);
return float4(0, 0, 0, 0);
}
ENDCG
}
}
Fallback Off
}
fileFormatVersion: 2
guid: 7699c5fbfa27745a1abe111ab7bf9785
ShaderImporter:
userData:
Shader "Hidden/NoiseAndGrain" {
Properties {
_MainTex ("Base (RGB)", 2D) = "white" {}
_NoiseTex ("Noise (RGB)", 2D) = "white" {}
}
CGINCLUDE
#include "UnityCG.cginc"
sampler2D _MainTex;
sampler2D _NoiseTex;
float4 _NoiseTex_TexelSize;
uniform float4 _MainTex_TexelSize;
uniform float3 _NoisePerChannel;
uniform float3 _NoiseTilingPerChannel;
uniform float3 _NoiseAmount;
uniform float3 _ThreshholdRGB;
uniform float3 _MidGrey;
struct v2f
{
float4 pos : SV_POSITION;
float2 uv_screen : TEXCOORD0;
float4 uvRg : TEXCOORD1;
float2 uvB : TEXCOORD2;
};
struct appdata_img2
{
float4 vertex : POSITION;
float2 texcoord : TEXCOORD0;
float2 texcoord1 : TEXCOORD1;
};
inline float3 Overlay(float3 m, float3 color) {
color = saturate(color);
float3 check = step(float3(0.5,0.5,0.5), color.rgb);
float3 result = check * (float3(1,1,1) - ((float3(1,1,1) - 2*(color.rgb-0.5)) * (1-m.rgb)));
result += (1-check) * (2*color.rgb) * m.rgb;
return result;
}
v2f vert (appdata_img2 v)
{
v2f o;
o.pos = mul (UNITY_MATRIX_MVP, v.vertex);
#if UNITY_UV_STARTS_AT_TOP
o.uv_screen = v.vertex.xyxy;
if (_MainTex_TexelSize.y < 0)
o.uv_screen.y = 1-o.uv_screen.y;
#else
o.uv_screen = v.vertex.xy;
#endif
// different tiling for 3 channels
o.uvRg = v.texcoord.xyxy + v.texcoord1.xyxy * _NoiseTilingPerChannel.rrgg * _NoiseTex_TexelSize.xyxy;
o.uvB = v.texcoord.xy + v.texcoord1.xy * _NoiseTilingPerChannel.bb * _NoiseTex_TexelSize.xy;
return o;
}
float4 frag ( v2f i ) : SV_Target
{
float4 color = (tex2D (_MainTex, i.uv_screen.xy));
// black & white intensities
float2 blackWhiteCurve = Luminance(color.rgb) - _MidGrey.x; // maybe tweak middle grey
blackWhiteCurve.xy = saturate(blackWhiteCurve.xy * _MidGrey.yz); //float2(1.0/0.8, -1.0/0.2));
float finalIntensity = _NoiseAmount.x + max(0.0f, dot(_NoiseAmount.zy, blackWhiteCurve.xy));
// fetching & scaling noise (COMPILER BUG WORKAROUND)
float3 m = float3(0,0,0);
m += (tex2D(_NoiseTex, i.uvRg.xy) * float4(1,0,0,0)).rgb;
m += (tex2D(_NoiseTex, i.uvRg.zw) * float4(0,1,0,0)).rgb;
m += (tex2D(_NoiseTex, i.uvB.xy) * float4(0,0,1,0)).rgb;
m = saturate(lerp(float3(0.5,0.5,0.5), m, _NoisePerChannel.rgb * float3(finalIntensity,finalIntensity,finalIntensity) ));
return float4(Overlay(m, color.rgb), color.a);
}
float4 fragTmp ( v2f i ) : SV_Target
{
float4 color = (tex2D (_MainTex, i.uv_screen.xy));
// black & white intensities
float2 blackWhiteCurve = Luminance(color.rgb) - _MidGrey.x; // maybe tweak middle grey
blackWhiteCurve.xy = saturate(blackWhiteCurve.xy * _MidGrey.yz); //float2(1.0/0.8, -1.0/0.2));
float finalIntensity = _NoiseAmount.x + max(0.0f, dot(_NoiseAmount.zy, blackWhiteCurve.xy));
// fetching & scaling noise (COMPILER BUG WORKAROUND)
float3 m = float3(0,0,0);
m += (tex2D(_NoiseTex, i.uvRg.xy) * float4(1,0,0,0)).rgb;
m += (tex2D(_NoiseTex, i.uvRg.zw) * float4(0,1,0,0)).rgb;
m += (tex2D(_NoiseTex, i.uvB.xy) * float4(0,0,1,0)).rgb;
m = saturate(lerp(float3(0.5,0.5,0.5), m, _NoisePerChannel.rgb * float3(finalIntensity,finalIntensity,finalIntensity)));
return float4(m.rgb, color.a);
}
float4 fragOverlayBlend ( v2f i ) : SV_Target
{
float4 color = tex2D(_MainTex, i.uv_screen.xy);
float4 m = tex2D(_NoiseTex, i.uv_screen.xy);
return float4(Overlay(m, color.rgb), color.a);
}
ENDCG
SubShader {
ZTest Always Cull Off ZWrite Off Blend Off
Pass {
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
ENDCG
}
Pass {
CGPROGRAM
#pragma vertex vert
#pragma fragment fragOverlayBlend
ENDCG
}
Pass {
CGPROGRAM
#pragma vertex vert
#pragma fragment fragTmp
ENDCG
}
}
FallBack Off
}
fileFormatVersion: 2
guid: b0249d8c935344451aa4de6db76f0688
ShaderImporter:
userData:
Shader "Hidden/NoiseAndGrainDX11" {
Properties {
_MainTex ("Base (RGB)", 2D) = "white" {}
_NoiseTex ("Noise (RGB)", 2D) = "white" {}
}
CGINCLUDE
#include "UnityCG.cginc"
sampler2D _MainTex;
sampler2D _NoiseTex;
float4 _NoiseTex_TexelSize;
uniform float4 _MainTex_TexelSize;
uniform float3 _NoisePerChannel;
uniform float3 _NoiseTilingPerChannel;
uniform float3 _NoiseAmount;
uniform float3 _ThreshholdRGB;
uniform float3 _MidGrey;
uniform float _DX11NoiseTime;
// DX11 noise helper functions, credit: rgba/iq
int ihash(int n)
{
n = (n<<13)^n;
return (n*(n*n*15731+789221)+1376312589) & 2147483647;
}
float frand(int n)
{
return ihash(n) / 2147483647.0;
}
float cellNoise1f(int3 p)
{
return frand(p.z*65536 + p.y*256 + p.x);//*2.0-1.0;
}
float3 cellNoise3f(int3 p)
{
int i = p.z*65536 + p.y*256 + p.x;
return float3(frand(i), frand(i + 57), frand(i + 113));//*2.0-1.0;
}
struct v2f
{
float4 pos : SV_POSITION;
float2 uv_screen : TEXCOORD0;
float4 uvRg : TEXCOORD1;
float2 uvB : TEXCOORD2;
float2 uvOffsets : TEXCOORD4;
};
struct appdata_img2
{
float4 vertex : POSITION;
float2 texcoord : TEXCOORD0;
float2 texcoord1 : TEXCOORD1;
};
inline float3 Overlay(float3 m, float3 color) {
float3 check = step(0.5, color.rgb);
float3 result = check * (float3(1,1,1) - ((float3(1,1,1) - 2*(color.rgb-0.5)) * (1-m.rgb)));
result += (1-check) * (2*color.rgb) * m.rgb;
return result;
}
v2f vert (appdata_img2 v)
{
v2f o;
o.pos = mul (UNITY_MATRIX_MVP, v.vertex);
#if UNITY_UV_STARTS_AT_TOP
o.uv_screen = v.vertex.xyxy;
if (_MainTex_TexelSize.y < 0)
o.uv_screen.y = 1-o.uv_screen.y;
#else
o.uv_screen = v.vertex.xy;
#endif
// different tiling for 3 channels
o.uvRg = v.texcoord.xyxy + v.texcoord1.xyxy * _NoiseTilingPerChannel.rrgg * _NoiseTex_TexelSize.xyxy;
o.uvB = v.texcoord.xy + v.texcoord1.xy * _NoiseTilingPerChannel.bb * _NoiseTex_TexelSize.xy;
o.uvOffsets = v.texcoord.xy;
return o;
}
float4 fragDX11 ( v2f i ) : SV_Target
{
float4 color = saturate(tex2D (_MainTex, i.uv_screen.xy));
// black & white intensities
float2 blackWhiteCurve = Luminance(color.rgb) - _MidGrey.x; // maybe tweak middle grey
blackWhiteCurve.xy = saturate(blackWhiteCurve.xy * _MidGrey.yz); //float2(1.0/0.8, -1.0/0.2));
float finalIntensity = _NoiseAmount.x + max(0.0f, dot(_NoiseAmount.zy, blackWhiteCurve.xy));
float3 m = cellNoise3f(float3( (i.uv_screen.xy + i.uvOffsets) * _MainTex_TexelSize.zw, _DX11NoiseTime));
m = saturate(lerp(float3(0.5,0.5,0.5), m, _NoisePerChannel.rgb * finalIntensity));
return float4(Overlay(m, color.rgb), color.a);
}
float4 fragDX11Monochrome ( v2f i ) : SV_Target
{
float4 color = saturate(tex2D (_MainTex, i.uv_screen.xy));
// black & white intensities
float2 blackWhiteCurve = Luminance(color.rgb) - _MidGrey.x; // maybe tweak middle grey
blackWhiteCurve.xy = saturate(blackWhiteCurve.xy * _MidGrey.yz); //float2(1.0/0.8, -1.0/0.2));
float finalIntensity = _NoiseAmount.x + max(0.0f, dot(_NoiseAmount.zy, blackWhiteCurve.xy));
float3 m = cellNoise1f(float3( (i.uv_screen.xy + i.uvOffsets) * _MainTex_TexelSize.zw, _DX11NoiseTime));
m = saturate(lerp(float3(0.5,0.5,0.5), m, finalIntensity));
return float4(Overlay(m, color.rgb), color.a);
}
float4 fragDX11Tmp ( v2f i ) : SV_Target
{
float4 color = saturate(tex2D (_MainTex, i.uv_screen.xy));
// black & white intensities
float2 blackWhiteCurve = Luminance(color.rgb) - _MidGrey.x; // maybe tweak middle grey
blackWhiteCurve.xy = saturate(blackWhiteCurve.xy * _MidGrey.yz); //float2(1.0/0.8, -1.0/0.2));
float finalIntensity = _NoiseAmount.x + max(0.0f, dot(_NoiseAmount.zy, blackWhiteCurve.xy));
float3 m = cellNoise3f(float3( (i.uv_screen.xy + i.uvOffsets) * _MainTex_TexelSize.zw, _DX11NoiseTime));
m = saturate(lerp(float3(0.5,0.5,0.5), m, _NoisePerChannel.rgb * finalIntensity));
return float4(m.rgb, color.a);
}
float4 fragDX11MonochromeTmp ( v2f i ) : SV_Target
{
float4 color = saturate(tex2D (_MainTex, i.uv_screen.xy));
// black & white intensities
float2 blackWhiteCurve = Luminance(color.rgb) - _MidGrey.x; // maybe tweak middle grey
blackWhiteCurve.xy = saturate(blackWhiteCurve.xy * _MidGrey.yz); //float2(1.0/0.8, -1.0/0.2));
float finalIntensity = _NoiseAmount.x + max(0.0f, dot(_NoiseAmount.zy, blackWhiteCurve.xy));
float3 m = cellNoise1f(float3( (i.uv_screen.xy + i.uvOffsets) * _MainTex_TexelSize.zw, _DX11NoiseTime));
m = saturate(lerp(float3(0.5,0.5,0.5), m, finalIntensity));
return float4(m.rgb, color.a);
}
float4 fragOverlayBlend ( v2f i ) : SV_Target
{
float4 color = saturate(tex2D (_MainTex, i.uv_screen.xy));
float4 m = saturate(tex2D (_NoiseTex, i.uv_screen.xy));
return float4(Overlay(m, color.rgb), color.a);
}
ENDCG
SubShader {
ZTest Always Cull Off ZWrite Off Blend Off
Pass {
CGPROGRAM
#pragma exclude_renderers gles xbox360 ps3 d3d9
#pragma target 5.0
#pragma vertex vert
#pragma fragment fragDX11
ENDCG
}
Pass {
CGPROGRAM
#pragma exclude_renderers gles xbox360 ps3 d3d9
#pragma target 5.0
#pragma vertex vert
#pragma fragment fragDX11Monochrome
ENDCG
}
Pass {
CGPROGRAM
#pragma exclude_renderers gles xbox360 ps3 d3d9
#pragma target 5.0
#pragma vertex vert
#pragma fragment fragDX11Tmp
ENDCG
}
Pass {
CGPROGRAM
#pragma exclude_renderers gles xbox360 ps3 d3d9
#pragma target 5.0
#pragma vertex vert
#pragma fragment fragDX11MonochromeTmp
ENDCG
}
Pass {
CGPROGRAM
#pragma exclude_renderers gles xbox360 ps3 d3d9
#pragma target 5.0
#pragma vertex vert
#pragma fragment fragOverlayBlend
ENDCG
}
}
FallBack Off
}
fileFormatVersion: 2
guid: 8b30686bb4322ab42ad5eb50a0210b58
ShaderImporter:
userData:
Shader "Hidden/Noise Shader RGB" {
Properties {
_MainTex ("Base (RGB)", 2D) = "white" {}
_GrainTex ("Base (RGB)", 2D) = "gray" {}
_ScratchTex ("Base (RGB)", 2D) = "gray" {}
}
SubShader {
Pass {
ZTest Always Cull Off ZWrite Off
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
struct v2f {
float4 pos : SV_POSITION;
float2 uv : TEXCOORD0;
float2 uvg : TEXCOORD1; // grain
float2 uvs : TEXCOORD2; // scratch
};
uniform sampler2D _MainTex;
uniform sampler2D _GrainTex;
uniform sampler2D _ScratchTex;
uniform float4 _GrainOffsetScale;
uniform float4 _ScratchOffsetScale;
uniform fixed4 _Intensity; // x=grain, y=scratch
v2f vert (appdata_img v)
{
v2f o;
o.pos = mul (UNITY_MATRIX_MVP, v.vertex);
o.uv = MultiplyUV (UNITY_MATRIX_TEXTURE0, v.texcoord);
o.uvg = v.texcoord.xy * _GrainOffsetScale.zw + _GrainOffsetScale.xy;
o.uvs = v.texcoord.xy * _ScratchOffsetScale.zw + _ScratchOffsetScale.xy;
return o;
}
fixed4 frag (v2f i) : SV_Target
{
fixed4 col = tex2D(_MainTex, i.uv);
// sample noise texture and do a signed add
fixed3 grain = tex2D(_GrainTex, i.uvg).rgb * 2 - 1;
col.rgb += grain * _Intensity.x;
// sample scratch texture and do a signed add
fixed3 scratch = tex2D(_ScratchTex, i.uvs).rgb * 2 - 1;
col.rgb += scratch * _Intensity.y;
return col;
}
ENDCG
}
}
Fallback off
}
fileFormatVersion: 2
guid: 5d7f4c401ae8946bcb0d6ff68a9e7466
ShaderImporter:
userData:
Shader "Hidden/Noise Shader YUV" {
Properties {
_MainTex ("Base (RGB)", 2D) = "white" {}
_GrainTex ("Base (RGB)", 2D) = "gray" {}
_ScratchTex ("Base (RGB)", 2D) = "gray" {}
}
SubShader {
Pass {
ZTest Always Cull Off ZWrite Off
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
struct v2f {
float4 pos : SV_POSITION;
float2 uv : TEXCOORD0;
float2 uvg : TEXCOORD1; // grain
float2 uvs : TEXCOORD2; // scratch
};
uniform sampler2D _MainTex;
uniform sampler2D _GrainTex;
uniform sampler2D _ScratchTex;
uniform float4 _GrainOffsetScale;
uniform float4 _ScratchOffsetScale;
uniform fixed4 _Intensity; // x=grain, y=scratch
v2f vert (appdata_img v)
{
v2f o;
o.pos = mul (UNITY_MATRIX_MVP, v.vertex);
o.uv = MultiplyUV (UNITY_MATRIX_TEXTURE0, v.texcoord);
o.uvg = v.texcoord.xy * _GrainOffsetScale.zw + _GrainOffsetScale.xy;
o.uvs = v.texcoord.xy * _ScratchOffsetScale.zw + _ScratchOffsetScale.xy;
return o;
}
fixed4 frag (v2f i) : SV_Target
{
fixed4 col = tex2D(_MainTex, i.uv);
// convert to YUV
fixed3 yuv;
yuv.x = dot( col.rgb, half3(0.299,0.587,0.114) );
yuv.y = (col.b-yuv.x)*0.492;
yuv.z = (col.r-yuv.x)*0.877;
// sample noise texture and do a signed add
fixed3 grain = tex2D(_GrainTex, i.uvg).rgb * 2 - 1;
yuv.rgb += grain * _Intensity.x;
// convert back to rgb
col.r = yuv.z * 1.140 + yuv.x;
col.g = yuv.z * (-0.581) + yuv.y * (-0.395) + yuv.x;
col.b = yuv.y * 2.032 + yuv.x;
// sample scratch texture and add
fixed3 scratch = tex2D(_ScratchTex, i.uvs).rgb * 2 - 1;
col.rgb += scratch * _Intensity.y;
return col;
}
ENDCG
}
}
Fallback off
}
fileFormatVersion: 2
guid: 0e447868506ba49f0a73235b8a8b647a
ShaderImporter:
userData:
Shader "Hidden/PrepareSunShaftsBlur" {
Properties {
_MainTex ("Base", 2D) = "" {}
_Skybox ("Skybox", 2D) = "" {}
}
CGINCLUDE
#include "UnityCG.cginc"
struct v2f {
float4 pos : SV_POSITION;
float2 uv : TEXCOORD0;
};
sampler2D _MainTex;
sampler2D _Skybox;
sampler2D_float _CameraDepthTexture;
uniform half _NoSkyBoxMask;
uniform half4 _SunPosition;
v2f vert (appdata_img v) {
v2f o;
o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
o.uv = v.texcoord.xy;
return o;
}
half TransformColor (half4 skyboxValue) {
return max (skyboxValue.a, _NoSkyBoxMask * dot (skyboxValue.rgb, float3 (0.59,0.3,0.11)));
}
half4 frag (v2f i) : SV_Target {
float depthSample = SAMPLE_DEPTH_TEXTURE( _CameraDepthTexture, i.uv.xy);
half4 tex = tex2D (_MainTex, i.uv.xy);
depthSample = Linear01Depth (depthSample);
// consider maximum radius
half2 vec = _SunPosition.xy - i.uv.xy;
half dist = saturate (_SunPosition.w - length (vec.xy));
half4 outColor = 0;
// consider shafts blockers
if (depthSample > 0.99)
outColor = TransformColor (tex) * dist;
return outColor;
}
half4 fragNoDepthNeeded (v2f i) : SV_Target {
float4 sky = (tex2D (_Skybox, i.uv.xy));
float4 tex = (tex2D (_MainTex, i.uv.xy));
// consider maximum radius
half2 vec = _SunPosition.xy - i.uv.xy;
half dist = saturate (_SunPosition.w - length (vec));
half4 outColor = 0;
if (Luminance ( abs(sky.rgb - tex.rgb)) < 0.2)
outColor = TransformColor (sky) * dist;
return outColor;
}
ENDCG
Subshader {
Pass {
ZTest Always Cull Off ZWrite Off
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
ENDCG
}
Pass {
ZTest Always Cull Off ZWrite Off
CGPROGRAM
#pragma vertex vert
#pragma fragment fragNoDepthNeeded
ENDCG
}
}
Fallback off
} // shader
fileFormatVersion: 2
guid: 9ad381ed8492840ab9f165df743e4826
ShaderImporter:
userData:
Shader "Hidden/RadialBlur"
{
Properties {
_MainTex ("Base (RGB)", 2D) = "" {}
}
// Shader code pasted into all further CGPROGRAM blocks
CGINCLUDE
#include "UnityCG.cginc"
struct v2f {
float4 pos : SV_POSITION;
float2 uv : TEXCOORD0;
float2 blurVector : TEXCOORD1;
};
sampler2D _MainTex;
float4 _BlurRadius4;
float4 _SunPosition;
float4 _MainTex_TexelSize;
v2f vert( appdata_img v ) {
v2f o;
o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
o.uv.xy = v.texcoord.xy;
o.blurVector = (_SunPosition.xy - v.texcoord.xy) * _BlurRadius4.xy;
return o;
}
#define SAMPLES_FLOAT 6.0f
#define SAMPLES_INT 6
half4 frag(v2f i) : SV_Target
{
half4 color = half4(0,0,0,0);
for(int j = 0; j < SAMPLES_INT; j++)
{
half4 tmpColor = tex2D(_MainTex, i.uv.xy);
color += tmpColor;
i.uv.xy += i.blurVector;
}
return color / SAMPLES_FLOAT;
}
ENDCG
Subshader
{
Blend One Zero
Pass {
ZTest Always Cull Off ZWrite Off
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
ENDCG
} // Pass
} // Subshader
Fallback off
} // shader
fileFormatVersion: 2
guid: f58445347fe2e4b8396487ed2bfa02ad
ShaderImporter:
userData:
Shader "Hidden/SSAO" {
Properties {
_MainTex ("", 2D) = "" {}
_RandomTexture ("", 2D) = "" {}
_SSAO ("", 2D) = "" {}
}
Subshader {
ZTest Always Cull Off ZWrite Off
CGINCLUDE
// Common code used by several SSAO passes below
#include "UnityCG.cginc"
struct v2f_ao {
float4 pos : SV_POSITION;
float2 uv : TEXCOORD0;
float2 uvr : TEXCOORD1;
};
uniform float2 _NoiseScale;
float4 _CameraDepthNormalsTexture_ST;
v2f_ao vert_ao (appdata_img v)
{
v2f_ao o;
o.pos = mul (UNITY_MATRIX_MVP, v.vertex);
o.uv = TRANSFORM_TEX(v.texcoord, _CameraDepthNormalsTexture);
o.uvr = v.texcoord.xy * _NoiseScale;
return o;
}
sampler2D _CameraDepthNormalsTexture;
sampler2D _RandomTexture;
float4 _Params; // x=radius, y=minz, z=attenuation power, w=SSAO power
// HLSL and GLSL do not support arbitrarily sized arrays as function parameters (eg. float bla[]), whereas Cg does.
#if !defined(UNITY_COMPILER_CG)
# define INPUT_SAMPLE_COUNT 8
# include "frag_ao.cginc"
# undef INPUT_SAMPLE_COUNT
# define INPUT_SAMPLE_COUNT 14
# include "frag_ao.cginc"
# undef INPUT_SAMPLE_COUNT
# define INPUT_SAMPLE_COUNT 26
# include "frag_ao.cginc"
# undef INPUT_SAMPLE_COUNT
# define INPUT_SAMPLE_COUNT 34
# include "frag_ao.cginc"
# undef INPUT_SAMPLE_COUNT
#else
# define INPUT_SAMPLE_COUNT
# include "frag_ao.cginc"
#endif
ENDCG
// ---- SSAO pass, 8 samples
Pass {
CGPROGRAM
#pragma vertex vert_ao
#pragma fragment frag
#pragma target 3.0
half4 frag (v2f_ao i) : SV_Target
{
#define SAMPLE_COUNT 8
const float3 RAND_SAMPLES[SAMPLE_COUNT] = {
float3(0.01305719,0.5872321,-0.119337),
float3(0.3230782,0.02207272,-0.4188725),
float3(-0.310725,-0.191367,0.05613686),
float3(-0.4796457,0.09398766,-0.5802653),
float3(0.1399992,-0.3357702,0.5596789),
float3(-0.2484578,0.2555322,0.3489439),
float3(0.1871898,-0.702764,-0.2317479),
float3(0.8849149,0.2842076,0.368524),
};
return frag_ao (i, SAMPLE_COUNT, RAND_SAMPLES);
}
ENDCG
}
// ---- SSAO pass, 14 samples
Pass {
CGPROGRAM
#pragma vertex vert_ao
#pragma fragment frag
#pragma target 3.0
half4 frag (v2f_ao i) : SV_Target
{
#define SAMPLE_COUNT 14
const float3 RAND_SAMPLES[SAMPLE_COUNT] = {
float3(0.4010039,0.8899381,-0.01751772),
float3(0.1617837,0.1338552,-0.3530486),
float3(-0.2305296,-0.1900085,0.5025396),
float3(-0.6256684,0.1241661,0.1163932),
float3(0.3820786,-0.3241398,0.4112825),
float3(-0.08829653,0.1649759,0.1395879),
float3(0.1891677,-0.1283755,-0.09873557),
float3(0.1986142,0.1767239,0.4380491),
float3(-0.3294966,0.02684341,-0.4021836),
float3(-0.01956503,-0.3108062,-0.410663),
float3(-0.3215499,0.6832048,-0.3433446),
float3(0.7026125,0.1648249,0.02250625),
float3(0.03704464,-0.939131,0.1358765),
float3(-0.6984446,-0.6003422,-0.04016943),
};
return frag_ao (i, SAMPLE_COUNT, RAND_SAMPLES);
}
ENDCG
}
// ---- SSAO pass, 26 samples
Pass {
CGPROGRAM
#pragma vertex vert_ao
#pragma fragment frag
#pragma target 3.0
half4 frag (v2f_ao i) : SV_Target
{
#define SAMPLE_COUNT 26
const float3 RAND_SAMPLES[SAMPLE_COUNT] = {
float3(0.2196607,0.9032637,0.2254677),
float3(0.05916681,0.2201506,-0.1430302),
float3(-0.4152246,0.1320857,0.7036734),
float3(-0.3790807,0.1454145,0.100605),
float3(0.3149606,-0.1294581,0.7044517),
float3(-0.1108412,0.2162839,0.1336278),
float3(0.658012,-0.4395972,-0.2919373),
float3(0.5377914,0.3112189,0.426864),
float3(-0.2752537,0.07625949,-0.1273409),
float3(-0.1915639,-0.4973421,-0.3129629),
float3(-0.2634767,0.5277923,-0.1107446),
float3(0.8242752,0.02434147,0.06049098),
float3(0.06262707,-0.2128643,-0.03671562),
float3(-0.1795662,-0.3543862,0.07924347),
float3(0.06039629,0.24629,0.4501176),
float3(-0.7786345,-0.3814852,-0.2391262),
float3(0.2792919,0.2487278,-0.05185341),
float3(0.1841383,0.1696993,-0.8936281),
float3(-0.3479781,0.4725766,-0.719685),
float3(-0.1365018,-0.2513416,0.470937),
float3(0.1280388,-0.563242,0.3419276),
float3(-0.4800232,-0.1899473,0.2398808),
float3(0.6389147,0.1191014,-0.5271206),
float3(0.1932822,-0.3692099,-0.6060588),
float3(-0.3465451,-0.1654651,-0.6746758),
float3(0.2448421,-0.1610962,0.1289366),
};
return frag_ao (i, SAMPLE_COUNT, RAND_SAMPLES);
}
ENDCG
}
// ---- Blur pass
Pass {
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma target 3.0
#include "UnityCG.cginc"
struct v2f {
float4 pos : SV_POSITION;
float2 uv : TEXCOORD0;
};
float4 _MainTex_ST;
v2f vert (appdata_img v)
{
v2f o;
o.pos = mul (UNITY_MATRIX_MVP, v.vertex);
o.uv = TRANSFORM_TEX (v.texcoord, _CameraDepthNormalsTexture);
return o;
}
sampler2D _SSAO;
float3 _TexelOffsetScale;
inline half CheckSame (half4 n, half4 nn)
{
// difference in normals
half2 diff = abs(n.xy - nn.xy);
half sn = (diff.x + diff.y) < 0.1;
// difference in depth
float z = DecodeFloatRG (n.zw);
float zz = DecodeFloatRG (nn.zw);
float zdiff = abs(z-zz) * _ProjectionParams.z;
half sz = zdiff < 0.2;
return sn * sz;
}
half4 frag( v2f i ) : SV_Target
{
#define NUM_BLUR_SAMPLES 4
float2 o = _TexelOffsetScale.xy;
half sum = tex2D(_SSAO, i.uv).r * (NUM_BLUR_SAMPLES + 1);
half denom = NUM_BLUR_SAMPLES + 1;
half4 geom = tex2D (_CameraDepthNormalsTexture, i.uv);
for (int s = 0; s < NUM_BLUR_SAMPLES; ++s)
{
float2 nuv = i.uv + o * (s+1);
half4 ngeom = tex2D (_CameraDepthNormalsTexture, nuv.xy);
half coef = (NUM_BLUR_SAMPLES - s) * CheckSame (geom, ngeom);
sum += tex2D (_SSAO, nuv.xy).r * coef;
denom += coef;
}
for (int s = 0; s < NUM_BLUR_SAMPLES; ++s)
{
float2 nuv = i.uv - o * (s+1);
half4 ngeom = tex2D (_CameraDepthNormalsTexture, nuv.xy);
half coef = (NUM_BLUR_SAMPLES - s) * CheckSame (geom, ngeom);
sum += tex2D (_SSAO, nuv.xy).r * coef;
denom += coef;
}
return sum / denom;
}
ENDCG
}
// ---- Composite pass
Pass {
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
struct v2f {
float4 pos : SV_POSITION;
float2 uv[2] : TEXCOORD0;
};
v2f vert (appdata_img v)
{
v2f o;
o.pos = mul (UNITY_MATRIX_MVP, v.vertex);
o.uv[0] = MultiplyUV (UNITY_MATRIX_TEXTURE0, v.texcoord);
o.uv[1] = MultiplyUV (UNITY_MATRIX_TEXTURE1, v.texcoord);
return o;
}
sampler2D _MainTex;
sampler2D _SSAO;
half4 frag( v2f i ) : SV_Target
{
half4 c = tex2D (_MainTex, i.uv[0]);
half ao = tex2D (_SSAO, i.uv[1]).r;
ao = pow (ao, _Params.w);
c.rgb *= ao;
return c;
}
ENDCG
}
}
Fallback off
}
fileFormatVersion: 2
guid: 43ca18288c424f645aaa1e9e07f04c50
ShaderImporter:
userData:
fileFormatVersion: 2
guid: 95616c020c5604dda96cf76afbbc0272
ShaderImporter:
userData:
Shader "Hidden/Sepiatone Effect" {
Properties {
_MainTex ("Base (RGB)", 2D) = "white" {}
}
SubShader {
Pass {
ZTest Always Cull Off ZWrite Off
CGPROGRAM
#pragma vertex vert_img
#pragma fragment frag
#include "UnityCG.cginc"
uniform sampler2D _MainTex;
fixed4 frag (v2f_img i) : SV_Target
{
fixed4 original = tex2D(_MainTex, i.uv);
// get intensity value (Y part of YIQ color space)
fixed Y = dot (fixed3(0.299, 0.587, 0.114), original.rgb);
// Convert to Sepia Tone by adding constant
fixed4 sepiaConvert = float4 (0.191, -0.054, -0.221, 0.0);
fixed4 output = sepiaConvert + Y;
output.a = original.a;
return output;
}
ENDCG
}
}
Fallback off
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment