initial commit

This commit is contained in:
2026-05-29 18:21:53 +03:00
commit 66ddf0ead0
2184 changed files with 1384338 additions and 0 deletions

View File

@@ -0,0 +1,6 @@
fileFormatVersion: 2
guid: cd3e1490c3d9a7a498538315414d5129
folderAsset: yes
DefaultImporter:
userData:
assetBundleName:

View File

@@ -0,0 +1,362 @@
using System;
using UnityEngine;
namespace UnityStandardAssets.ImageEffects
{
[ExecuteInEditMode]
[RequireComponent (typeof(Camera))]
[AddComponentMenu ("Image Effects/Bloom and Glow/Bloom")]
public class Bloom : PostEffectsBase
{
public enum LensFlareStyle
{
Ghosting = 0,
Anamorphic = 1,
Combined = 2,
}
public enum TweakMode
{
Basic = 0,
Complex = 1,
}
public enum HDRBloomMode
{
Auto = 0,
On = 1,
Off = 2,
}
public enum BloomScreenBlendMode
{
Screen = 0,
Add = 1,
}
public enum BloomQuality
{
Cheap = 0,
High = 1,
}
public TweakMode tweakMode = 0;
public BloomScreenBlendMode screenBlendMode = BloomScreenBlendMode.Add;
public HDRBloomMode hdr = HDRBloomMode.Auto;
private bool doHdr = false;
public float sepBlurSpread = 2.5f;
public BloomQuality quality = BloomQuality.High;
public float bloomIntensity = 0.5f;
public float bloomThreshold = 0.5f;
public Color bloomThresholdColor = Color.white;
public int bloomBlurIterations = 2;
public int hollywoodFlareBlurIterations = 2;
public float flareRotation = 0.0f;
public LensFlareStyle lensflareMode = (LensFlareStyle) 1;
public float hollyStretchWidth = 2.5f;
public float lensflareIntensity = 0.0f;
public float lensflareThreshold = 0.3f;
public float lensFlareSaturation = 0.75f;
public Color flareColorA = new Color (0.4f, 0.4f, 0.8f, 0.75f);
public Color flareColorB = new Color (0.4f, 0.8f, 0.8f, 0.75f);
public Color flareColorC = new Color (0.8f, 0.4f, 0.8f, 0.75f);
public Color flareColorD = new Color (0.8f, 0.4f, 0.0f, 0.75f);
public Texture2D lensFlareVignetteMask;
public Shader lensFlareShader;
private Material lensFlareMaterial;
public Shader screenBlendShader;
private Material screenBlend;
public Shader blurAndFlaresShader;
private Material blurAndFlaresMaterial;
public Shader brightPassFilterShader;
private Material brightPassFilterMaterial;
public override bool CheckResources ()
{
CheckSupport (false);
screenBlend = CheckShaderAndCreateMaterial (screenBlendShader, screenBlend);
lensFlareMaterial = CheckShaderAndCreateMaterial(lensFlareShader,lensFlareMaterial);
blurAndFlaresMaterial = CheckShaderAndCreateMaterial (blurAndFlaresShader, blurAndFlaresMaterial);
brightPassFilterMaterial = CheckShaderAndCreateMaterial(brightPassFilterShader, brightPassFilterMaterial);
if (!isSupported)
ReportAutoDisable ();
return isSupported;
}
public void OnRenderImage (RenderTexture source, RenderTexture destination)
{
if (CheckResources()==false)
{
Graphics.Blit (source, destination);
return;
}
// screen blend is not supported when HDR is enabled (will cap values)
doHdr = false;
if (hdr == HDRBloomMode.Auto)
#if UNITY_5_6_OR_NEWER
doHdr = source.format == RenderTextureFormat.ARGBHalf && GetComponent<Camera>().allowHDR;
#else
doHdr = source.format == RenderTextureFormat.ARGBHalf && GetComponent<Camera>().hdr;
#endif
else {
doHdr = hdr == HDRBloomMode.On;
}
doHdr = doHdr && supportHDRTextures;
BloomScreenBlendMode realBlendMode = screenBlendMode;
if (doHdr)
realBlendMode = BloomScreenBlendMode.Add;
var rtFormat= (doHdr) ? RenderTextureFormat.ARGBHalf : RenderTextureFormat.Default;
var rtW2= source.width/2;
var rtH2= source.height/2;
var rtW4= source.width/4;
var rtH4= source.height/4;
float widthOverHeight = (1.0f * source.width) / (1.0f * source.height);
float oneOverBaseSize = 1.0f / 512.0f;
// downsample
RenderTexture quarterRezColor = RenderTexture.GetTemporary (rtW4, rtH4, 0, rtFormat);
RenderTexture halfRezColorDown = RenderTexture.GetTemporary (rtW2, rtH2, 0, rtFormat);
if (quality > BloomQuality.Cheap) {
Graphics.Blit (source, halfRezColorDown, screenBlend, 2);
RenderTexture rtDown4 = RenderTexture.GetTemporary (rtW4, rtH4, 0, rtFormat);
Graphics.Blit (halfRezColorDown, rtDown4, screenBlend, 2);
Graphics.Blit (rtDown4, quarterRezColor, screenBlend, 6);
RenderTexture.ReleaseTemporary(rtDown4);
}
else {
Graphics.Blit (source, halfRezColorDown);
Graphics.Blit (halfRezColorDown, quarterRezColor, screenBlend, 6);
}
RenderTexture.ReleaseTemporary (halfRezColorDown);
// cut colors (thresholding)
RenderTexture secondQuarterRezColor = RenderTexture.GetTemporary (rtW4, rtH4, 0, rtFormat);
BrightFilter (bloomThreshold * bloomThresholdColor, quarterRezColor, secondQuarterRezColor);
// blurring
if (bloomBlurIterations < 1) bloomBlurIterations = 1;
else if (bloomBlurIterations > 10) bloomBlurIterations = 10;
for (int iter = 0; iter < bloomBlurIterations; iter++)
{
float spreadForPass = (1.0f + (iter * 0.25f)) * sepBlurSpread;
// vertical blur
RenderTexture blur4 = RenderTexture.GetTemporary (rtW4, rtH4, 0, rtFormat);
blurAndFlaresMaterial.SetVector ("_Offsets", new Vector4 (0.0f, spreadForPass * oneOverBaseSize, 0.0f, 0.0f));
Graphics.Blit (secondQuarterRezColor, blur4, blurAndFlaresMaterial, 4);
RenderTexture.ReleaseTemporary(secondQuarterRezColor);
secondQuarterRezColor = blur4;
// horizontal blur
blur4 = RenderTexture.GetTemporary (rtW4, rtH4, 0, rtFormat);
blurAndFlaresMaterial.SetVector ("_Offsets", new Vector4 ((spreadForPass / widthOverHeight) * oneOverBaseSize, 0.0f, 0.0f, 0.0f));
Graphics.Blit (secondQuarterRezColor, blur4, blurAndFlaresMaterial, 4);
RenderTexture.ReleaseTemporary (secondQuarterRezColor);
secondQuarterRezColor = blur4;
if (quality > BloomQuality.Cheap)
{
if (iter == 0)
{
Graphics.SetRenderTarget(quarterRezColor);
GL.Clear(false, true, Color.black); // Clear to avoid RT restore
Graphics.Blit (secondQuarterRezColor, quarterRezColor);
}
else
{
quarterRezColor.MarkRestoreExpected(); // using max blending, RT restore expected
Graphics.Blit (secondQuarterRezColor, quarterRezColor, screenBlend, 10);
}
}
}
if (quality > BloomQuality.Cheap)
{
Graphics.SetRenderTarget(secondQuarterRezColor);
GL.Clear(false, true, Color.black); // Clear to avoid RT restore
Graphics.Blit (quarterRezColor, secondQuarterRezColor, screenBlend, 6);
}
// lens flares: ghosting, anamorphic or both (ghosted anamorphic flares)
if (lensflareIntensity > Mathf.Epsilon)
{
RenderTexture rtFlares4 = RenderTexture.GetTemporary (rtW4, rtH4, 0, rtFormat);
if (lensflareMode == 0)
{
// ghosting only
BrightFilter (lensflareThreshold, secondQuarterRezColor, rtFlares4);
if (quality > BloomQuality.Cheap)
{
// smooth a little
blurAndFlaresMaterial.SetVector ("_Offsets", new Vector4 (0.0f, (1.5f) / (1.0f * quarterRezColor.height), 0.0f, 0.0f));
Graphics.SetRenderTarget(quarterRezColor);
GL.Clear(false, true, Color.black); // Clear to avoid RT restore
Graphics.Blit (rtFlares4, quarterRezColor, blurAndFlaresMaterial, 4);
blurAndFlaresMaterial.SetVector ("_Offsets", new Vector4 ((1.5f) / (1.0f * quarterRezColor.width), 0.0f, 0.0f, 0.0f));
Graphics.SetRenderTarget(rtFlares4);
GL.Clear(false, true, Color.black); // Clear to avoid RT restore
Graphics.Blit (quarterRezColor, rtFlares4, blurAndFlaresMaterial, 4);
}
// no ugly edges!
Vignette (0.975f, rtFlares4, rtFlares4);
BlendFlares (rtFlares4, secondQuarterRezColor);
}
else
{
//Vignette (0.975ff, rtFlares4, rtFlares4);
//DrawBorder(rtFlares4, screenBlend, 8);
float flareXRot = 1.0f * Mathf.Cos(flareRotation);
float flareyRot = 1.0f * Mathf.Sin(flareRotation);
float stretchWidth = (hollyStretchWidth * 1.0f / widthOverHeight) * oneOverBaseSize;
blurAndFlaresMaterial.SetVector ("_Offsets", new Vector4 (flareXRot, flareyRot, 0.0f, 0.0f));
blurAndFlaresMaterial.SetVector ("_Threshhold", new Vector4 (lensflareThreshold, 1.0f, 0.0f, 0.0f));
blurAndFlaresMaterial.SetVector ("_TintColor", new Vector4 (flareColorA.r, flareColorA.g, flareColorA.b, flareColorA.a) * flareColorA.a * lensflareIntensity);
blurAndFlaresMaterial.SetFloat ("_Saturation", lensFlareSaturation);
// "pre and cut"
quarterRezColor.DiscardContents();
Graphics.Blit (rtFlares4, quarterRezColor, blurAndFlaresMaterial, 2);
// "post"
rtFlares4.DiscardContents();
Graphics.Blit (quarterRezColor, rtFlares4, blurAndFlaresMaterial, 3);
blurAndFlaresMaterial.SetVector ("_Offsets", new Vector4 (flareXRot * stretchWidth, flareyRot * stretchWidth, 0.0f, 0.0f));
// stretch 1st
blurAndFlaresMaterial.SetFloat ("_StretchWidth", hollyStretchWidth);
quarterRezColor.DiscardContents();
Graphics.Blit (rtFlares4, quarterRezColor, blurAndFlaresMaterial, 1);
// stretch 2nd
blurAndFlaresMaterial.SetFloat ("_StretchWidth", hollyStretchWidth * 2.0f);
rtFlares4.DiscardContents();
Graphics.Blit (quarterRezColor, rtFlares4, blurAndFlaresMaterial, 1);
// stretch 3rd
blurAndFlaresMaterial.SetFloat ("_StretchWidth", hollyStretchWidth * 4.0f);
quarterRezColor.DiscardContents();
Graphics.Blit (rtFlares4, quarterRezColor, blurAndFlaresMaterial, 1);
// additional blur passes
for (int iter = 0; iter < hollywoodFlareBlurIterations; iter++)
{
stretchWidth = (hollyStretchWidth * 2.0f / widthOverHeight) * oneOverBaseSize;
blurAndFlaresMaterial.SetVector ("_Offsets", new Vector4 (stretchWidth * flareXRot, stretchWidth * flareyRot, 0.0f, 0.0f));
rtFlares4.DiscardContents();
Graphics.Blit (quarterRezColor, rtFlares4, blurAndFlaresMaterial, 4);
blurAndFlaresMaterial.SetVector ("_Offsets", new Vector4 (stretchWidth * flareXRot, stretchWidth * flareyRot, 0.0f, 0.0f));
quarterRezColor.DiscardContents();
Graphics.Blit (rtFlares4, quarterRezColor, blurAndFlaresMaterial, 4);
}
if (lensflareMode == (LensFlareStyle) 1)
// anamorphic lens flares
AddTo (1.0f, quarterRezColor, secondQuarterRezColor);
else
{
// "combined" lens flares
Vignette (1.0f, quarterRezColor, rtFlares4);
BlendFlares (rtFlares4, quarterRezColor);
AddTo (1.0f, quarterRezColor, secondQuarterRezColor);
}
}
RenderTexture.ReleaseTemporary (rtFlares4);
}
int blendPass = (int) realBlendMode;
//if (Mathf.Abs(chromaticBloom) < Mathf.Epsilon)
// blendPass += 4;
screenBlend.SetFloat ("_Intensity", bloomIntensity);
screenBlend.SetTexture ("_ColorBuffer", source);
if (quality > BloomQuality.Cheap)
{
RenderTexture halfRezColorUp = RenderTexture.GetTemporary (rtW2, rtH2, 0, rtFormat);
Graphics.Blit (secondQuarterRezColor, halfRezColorUp);
Graphics.Blit (halfRezColorUp, destination, screenBlend, blendPass);
RenderTexture.ReleaseTemporary (halfRezColorUp);
}
else
Graphics.Blit (secondQuarterRezColor, destination, screenBlend, blendPass);
RenderTexture.ReleaseTemporary (quarterRezColor);
RenderTexture.ReleaseTemporary (secondQuarterRezColor);
}
private void AddTo (float intensity_, RenderTexture from, RenderTexture to)
{
screenBlend.SetFloat ("_Intensity", intensity_);
to.MarkRestoreExpected(); // additive blending, RT restore expected
Graphics.Blit (from, to, screenBlend, 9);
}
private void BlendFlares (RenderTexture from, RenderTexture to)
{
lensFlareMaterial.SetVector ("colorA", new Vector4 (flareColorA.r, flareColorA.g, flareColorA.b, flareColorA.a) * lensflareIntensity);
lensFlareMaterial.SetVector ("colorB", new Vector4 (flareColorB.r, flareColorB.g, flareColorB.b, flareColorB.a) * lensflareIntensity);
lensFlareMaterial.SetVector ("colorC", new Vector4 (flareColorC.r, flareColorC.g, flareColorC.b, flareColorC.a) * lensflareIntensity);
lensFlareMaterial.SetVector ("colorD", new Vector4 (flareColorD.r, flareColorD.g, flareColorD.b, flareColorD.a) * lensflareIntensity);
to.MarkRestoreExpected(); // additive blending, RT restore expected
Graphics.Blit (from, to, lensFlareMaterial);
}
private void BrightFilter (float thresh, RenderTexture from, RenderTexture to)
{
brightPassFilterMaterial.SetVector ("_Threshhold", new Vector4 (thresh, thresh, thresh, thresh));
Graphics.Blit (from, to, brightPassFilterMaterial, 0);
}
private void BrightFilter (Color threshColor, RenderTexture from, RenderTexture to)
{
brightPassFilterMaterial.SetVector ("_Threshhold", threshColor);
Graphics.Blit (from, to, brightPassFilterMaterial, 1);
}
private void Vignette (float amount, RenderTexture from, RenderTexture to)
{
if (lensFlareVignetteMask)
{
screenBlend.SetTexture ("_ColorBuffer", lensFlareVignetteMask);
to.MarkRestoreExpected(); // using blending, RT restore expected
Graphics.Blit (from == to ? null : from, to, screenBlend, from == to ? 7 : 3);
}
else if (from != to)
{
Graphics.SetRenderTarget (to);
GL.Clear(false, true, Color.black); // clear destination to avoid RT restore
Graphics.Blit (from, to);
}
}
}
}

View File

@@ -0,0 +1,17 @@
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:

View File

@@ -0,0 +1,318 @@
using System;
using UnityEngine;
namespace UnityStandardAssets.ImageEffects
{
public enum LensflareStyle34
{
Ghosting = 0,
Anamorphic = 1,
Combined = 2,
}
public enum TweakMode34
{
Basic = 0,
Complex = 1,
}
public enum HDRBloomMode
{
Auto = 0,
On = 1,
Off = 2,
}
public enum BloomScreenBlendMode
{
Screen = 0,
Add = 1,
}
[ExecuteInEditMode]
[RequireComponent(typeof(Camera))]
[AddComponentMenu("Image Effects/Bloom and Glow/BloomAndFlares (3.5, Deprecated)")]
public class BloomAndFlares : PostEffectsBase
{
public TweakMode34 tweakMode = 0;
public BloomScreenBlendMode screenBlendMode = BloomScreenBlendMode.Add;
public HDRBloomMode hdr = HDRBloomMode.Auto;
private bool doHdr = false;
public float sepBlurSpread = 1.5f;
public float useSrcAlphaAsMask = 0.5f;
public float bloomIntensity = 1.0f;
public float bloomThreshold = 0.5f;
public int bloomBlurIterations = 2;
public bool lensflares = false;
public int hollywoodFlareBlurIterations = 2;
public LensflareStyle34 lensflareMode = (LensflareStyle34)1;
public float hollyStretchWidth = 3.5f;
public float lensflareIntensity = 1.0f;
public float lensflareThreshold = 0.3f;
public Color flareColorA = new Color(0.4f, 0.4f, 0.8f, 0.75f);
public Color flareColorB = new Color(0.4f, 0.8f, 0.8f, 0.75f);
public Color flareColorC = new Color(0.8f, 0.4f, 0.8f, 0.75f);
public Color flareColorD = new Color(0.8f, 0.4f, 0.0f, 0.75f);
public Texture2D lensFlareVignetteMask;
public Shader lensFlareShader;
private Material lensFlareMaterial;
public Shader vignetteShader;
private Material vignetteMaterial;
public Shader separableBlurShader;
private Material separableBlurMaterial;
public Shader addBrightStuffOneOneShader;
private Material addBrightStuffBlendOneOneMaterial;
public Shader screenBlendShader;
private Material screenBlend;
public Shader hollywoodFlaresShader;
private Material hollywoodFlaresMaterial;
public Shader brightPassFilterShader;
private Material brightPassFilterMaterial;
public override bool CheckResources()
{
CheckSupport(false);
screenBlend = CheckShaderAndCreateMaterial(screenBlendShader, screenBlend);
lensFlareMaterial = CheckShaderAndCreateMaterial(lensFlareShader, lensFlareMaterial);
vignetteMaterial = CheckShaderAndCreateMaterial(vignetteShader, vignetteMaterial);
separableBlurMaterial = CheckShaderAndCreateMaterial(separableBlurShader, separableBlurMaterial);
addBrightStuffBlendOneOneMaterial = CheckShaderAndCreateMaterial(addBrightStuffOneOneShader, addBrightStuffBlendOneOneMaterial);
hollywoodFlaresMaterial = CheckShaderAndCreateMaterial(hollywoodFlaresShader, hollywoodFlaresMaterial);
brightPassFilterMaterial = CheckShaderAndCreateMaterial(brightPassFilterShader, brightPassFilterMaterial);
if (!isSupported)
ReportAutoDisable();
return isSupported;
}
void OnRenderImage(RenderTexture source, RenderTexture destination)
{
if (CheckResources() == false)
{
Graphics.Blit(source, destination);
return;
}
// screen blend is not supported when HDR is enabled (will cap values)
doHdr = false;
if (hdr == HDRBloomMode.Auto)
#if UNITY_5_6_OR_NEWER
doHdr = source.format == RenderTextureFormat.ARGBHalf && GetComponent<Camera>().allowHDR;
#else
doHdr = source.format == RenderTextureFormat.ARGBHalf && GetComponent<Camera>().hdr;
#endif
else
{
doHdr = hdr == HDRBloomMode.On;
}
doHdr = doHdr && supportHDRTextures;
BloomScreenBlendMode realBlendMode = screenBlendMode;
if (doHdr)
realBlendMode = BloomScreenBlendMode.Add;
var rtFormat = (doHdr) ? RenderTextureFormat.ARGBHalf : RenderTextureFormat.Default;
RenderTexture halfRezColor = RenderTexture.GetTemporary(source.width / 2, source.height / 2, 0, rtFormat);
RenderTexture quarterRezColor = RenderTexture.GetTemporary(source.width / 4, source.height / 4, 0, rtFormat);
RenderTexture secondQuarterRezColor = RenderTexture.GetTemporary(source.width / 4, source.height / 4, 0, rtFormat);
RenderTexture thirdQuarterRezColor = RenderTexture.GetTemporary(source.width / 4, source.height / 4, 0, rtFormat);
float widthOverHeight = (1.0f * source.width) / (1.0f * source.height);
float oneOverBaseSize = 1.0f / 512.0f;
// downsample
Graphics.Blit(source, halfRezColor, screenBlend, 2); // <- 2 is stable downsample
Graphics.Blit(halfRezColor, quarterRezColor, screenBlend, 2); // <- 2 is stable downsample
RenderTexture.ReleaseTemporary(halfRezColor);
// cut colors (thresholding)
BrightFilter(bloomThreshold, useSrcAlphaAsMask, quarterRezColor, secondQuarterRezColor);
quarterRezColor.DiscardContents();
// blurring
if (bloomBlurIterations < 1) bloomBlurIterations = 1;
for (int iter = 0; iter < bloomBlurIterations; iter++)
{
float spreadForPass = (1.0f + (iter * 0.5f)) * sepBlurSpread;
separableBlurMaterial.SetVector("offsets", new Vector4(0.0f, spreadForPass * oneOverBaseSize, 0.0f, 0.0f));
RenderTexture src = iter == 0 ? secondQuarterRezColor : quarterRezColor;
Graphics.Blit(src, thirdQuarterRezColor, separableBlurMaterial);
src.DiscardContents();
separableBlurMaterial.SetVector("offsets", new Vector4((spreadForPass / widthOverHeight) * oneOverBaseSize, 0.0f, 0.0f, 0.0f));
Graphics.Blit(thirdQuarterRezColor, quarterRezColor, separableBlurMaterial);
thirdQuarterRezColor.DiscardContents();
}
// lens flares: ghosting, anamorphic or a combination
if (lensflares)
{
if (lensflareMode == 0)
{
BrightFilter(lensflareThreshold, 0.0f, quarterRezColor, thirdQuarterRezColor);
quarterRezColor.DiscardContents();
// smooth a little, this needs to be resolution dependent
/*
separableBlurMaterial.SetVector ("offsets", Vector4 (0.0ff, (2.0ff) / (1.0ff * quarterRezColor.height), 0.0ff, 0.0ff));
Graphics.Blit (thirdQuarterRezColor, secondQuarterRezColor, separableBlurMaterial);
separableBlurMaterial.SetVector ("offsets", Vector4 ((2.0ff) / (1.0ff * quarterRezColor.width), 0.0ff, 0.0ff, 0.0ff));
Graphics.Blit (secondQuarterRezColor, thirdQuarterRezColor, separableBlurMaterial);
*/
// no ugly edges!
Vignette(0.975f, thirdQuarterRezColor, secondQuarterRezColor);
thirdQuarterRezColor.DiscardContents();
BlendFlares(secondQuarterRezColor, quarterRezColor);
secondQuarterRezColor.DiscardContents();
}
// (b) hollywood/anamorphic flares?
else
{
// thirdQuarter has the brightcut unblurred colors
// quarterRezColor is the blurred, brightcut buffer that will end up as bloom
hollywoodFlaresMaterial.SetVector("_threshold", new Vector4(lensflareThreshold, 1.0f / (1.0f - lensflareThreshold), 0.0f, 0.0f));
hollywoodFlaresMaterial.SetVector("tintColor", new Vector4(flareColorA.r, flareColorA.g, flareColorA.b, flareColorA.a) * flareColorA.a * lensflareIntensity);
Graphics.Blit(thirdQuarterRezColor, secondQuarterRezColor, hollywoodFlaresMaterial, 2);
thirdQuarterRezColor.DiscardContents();
Graphics.Blit(secondQuarterRezColor, thirdQuarterRezColor, hollywoodFlaresMaterial, 3);
secondQuarterRezColor.DiscardContents();
hollywoodFlaresMaterial.SetVector("offsets", new Vector4((sepBlurSpread * 1.0f / widthOverHeight) * oneOverBaseSize, 0.0f, 0.0f, 0.0f));
hollywoodFlaresMaterial.SetFloat("stretchWidth", hollyStretchWidth);
Graphics.Blit(thirdQuarterRezColor, secondQuarterRezColor, hollywoodFlaresMaterial, 1);
thirdQuarterRezColor.DiscardContents();
hollywoodFlaresMaterial.SetFloat("stretchWidth", hollyStretchWidth * 2.0f);
Graphics.Blit(secondQuarterRezColor, thirdQuarterRezColor, hollywoodFlaresMaterial, 1);
secondQuarterRezColor.DiscardContents();
hollywoodFlaresMaterial.SetFloat("stretchWidth", hollyStretchWidth * 4.0f);
Graphics.Blit(thirdQuarterRezColor, secondQuarterRezColor, hollywoodFlaresMaterial, 1);
thirdQuarterRezColor.DiscardContents();
if (lensflareMode == (LensflareStyle34)1)
{
for (int itera = 0; itera < hollywoodFlareBlurIterations; itera++)
{
separableBlurMaterial.SetVector("offsets", new Vector4((hollyStretchWidth * 2.0f / widthOverHeight) * oneOverBaseSize, 0.0f, 0.0f, 0.0f));
Graphics.Blit(secondQuarterRezColor, thirdQuarterRezColor, separableBlurMaterial);
secondQuarterRezColor.DiscardContents();
separableBlurMaterial.SetVector("offsets", new Vector4((hollyStretchWidth * 2.0f / widthOverHeight) * oneOverBaseSize, 0.0f, 0.0f, 0.0f));
Graphics.Blit(thirdQuarterRezColor, secondQuarterRezColor, separableBlurMaterial);
thirdQuarterRezColor.DiscardContents();
}
AddTo(1.0f, secondQuarterRezColor, quarterRezColor);
secondQuarterRezColor.DiscardContents();
}
else
{
// (c) combined
for (int ix = 0; ix < hollywoodFlareBlurIterations; ix++)
{
separableBlurMaterial.SetVector("offsets", new Vector4((hollyStretchWidth * 2.0f / widthOverHeight) * oneOverBaseSize, 0.0f, 0.0f, 0.0f));
Graphics.Blit(secondQuarterRezColor, thirdQuarterRezColor, separableBlurMaterial);
secondQuarterRezColor.DiscardContents();
separableBlurMaterial.SetVector("offsets", new Vector4((hollyStretchWidth * 2.0f / widthOverHeight) * oneOverBaseSize, 0.0f, 0.0f, 0.0f));
Graphics.Blit(thirdQuarterRezColor, secondQuarterRezColor, separableBlurMaterial);
thirdQuarterRezColor.DiscardContents();
}
Vignette(1.0f, secondQuarterRezColor, thirdQuarterRezColor);
secondQuarterRezColor.DiscardContents();
BlendFlares(thirdQuarterRezColor, secondQuarterRezColor);
thirdQuarterRezColor.DiscardContents();
AddTo(1.0f, secondQuarterRezColor, quarterRezColor);
secondQuarterRezColor.DiscardContents();
}
}
}
// screen blend bloom results to color buffer
screenBlend.SetFloat("_Intensity", bloomIntensity);
screenBlend.SetTexture("_ColorBuffer", source);
Graphics.Blit(quarterRezColor, destination, screenBlend, (int)realBlendMode);
RenderTexture.ReleaseTemporary(quarterRezColor);
RenderTexture.ReleaseTemporary(secondQuarterRezColor);
RenderTexture.ReleaseTemporary(thirdQuarterRezColor);
}
private void AddTo(float intensity_, RenderTexture from, RenderTexture to)
{
addBrightStuffBlendOneOneMaterial.SetFloat("_Intensity", intensity_);
Graphics.Blit(from, to, addBrightStuffBlendOneOneMaterial);
}
private void BlendFlares(RenderTexture from, RenderTexture to)
{
lensFlareMaterial.SetVector("colorA", new Vector4(flareColorA.r, flareColorA.g, flareColorA.b, flareColorA.a) * lensflareIntensity);
lensFlareMaterial.SetVector("colorB", new Vector4(flareColorB.r, flareColorB.g, flareColorB.b, flareColorB.a) * lensflareIntensity);
lensFlareMaterial.SetVector("colorC", new Vector4(flareColorC.r, flareColorC.g, flareColorC.b, flareColorC.a) * lensflareIntensity);
lensFlareMaterial.SetVector("colorD", new Vector4(flareColorD.r, flareColorD.g, flareColorD.b, flareColorD.a) * lensflareIntensity);
Graphics.Blit(from, to, lensFlareMaterial);
}
private void BrightFilter(float thresh, float useAlphaAsMask, RenderTexture from, RenderTexture to)
{
if (doHdr)
brightPassFilterMaterial.SetVector("threshold", new Vector4(thresh, 1.0f, 0.0f, 0.0f));
else
brightPassFilterMaterial.SetVector("threshold", new Vector4(thresh, 1.0f / (1.0f - thresh), 0.0f, 0.0f));
brightPassFilterMaterial.SetFloat("useSrcAlphaAsMask", useAlphaAsMask);
Graphics.Blit(from, to, brightPassFilterMaterial);
}
private void Vignette(float amount, RenderTexture from, RenderTexture to)
{
if (lensFlareVignetteMask)
{
screenBlend.SetTexture("_ColorBuffer", lensFlareVignetteMask);
Graphics.Blit(from, to, screenBlend, 3);
}
else
{
vignetteMaterial.SetFloat("vignetteIntensity", amount);
Graphics.Blit(from, to, vignetteMaterial);
}
}
}
}

View File

@@ -0,0 +1,22 @@
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:

View File

@@ -0,0 +1,109 @@
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);
}
}
}

View File

@@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: 4975a6e437fc3b149a8cd508ce5bdd69
MonoImporter:
serializedVersion: 2
defaultReferences:
- fastBloomShader: {fileID: 4800000, guid: 68a00c837b82e4c6d92e7da765dc5f1d, type: 3}
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:

View File

@@ -0,0 +1,55 @@
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);
}
}
}
}

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: f6469eb0ad1119d6d00011d98d76c639
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:

View File

@@ -0,0 +1,42 @@
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);
}
}
}

View File

@@ -0,0 +1,17 @@
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:

View File

@@ -0,0 +1,261 @@
using System;
using System.Collections.Generic;
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;
private List<Material> createdMaterials = new List<Material> ();
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;
}
m2Create = new Material (s);
createdMaterials.Add (m2Create);
m2Create.hideFlags = HideFlags.DontSave;
return m2Create;
}
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;
}
m2Create = new Material (s);
createdMaterials.Add (m2Create);
m2Create.hideFlags = HideFlags.DontSave;
return m2Create;
}
void OnEnable ()
{
isSupported = true;
}
void OnDestroy ()
{
RemoveCreatedMaterials ();
}
private void RemoveCreatedMaterials ()
{
while (createdMaterials.Count > 0)
{
Material mat = createdMaterials[0];
createdMaterials.RemoveAt (0);
#if UNITY_EDITOR
DestroyImmediate (mat);
#else
Destroy(mat);
#endif
}
}
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)
{
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();
}
}
}

View File

@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: b6f4318ec6c2bf643a0f9edfeeaba0ec
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:

View File

@@ -0,0 +1,188 @@
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();
}
}
}

View File

@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 50b03df8f04b5c441aaac5b7fccb4734
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:

View File

@@ -0,0 +1,125 @@
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;
}
}
}

View File

@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: a20852ce049f64e4695a48b6a354be83
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:

View File

@@ -0,0 +1,69 @@
using System;
using UnityEngine;
namespace UnityStandardAssets.ImageEffects
{
[ExecuteInEditMode]
[RequireComponent (typeof(Camera))]
[AddComponentMenu ("Image Effects/Other/Screen Overlay")]
public class ScreenOverlay : PostEffectsBase
{
public enum OverlayBlendMode
{
Additive = 0,
ScreenBlend = 1,
Multiply = 2,
Overlay = 3,
AlphaBlend = 4,
}
public OverlayBlendMode blendMode = OverlayBlendMode.Overlay;
public float intensity = 1.0f;
public Texture2D texture = null;
public Shader overlayShader = null;
private Material overlayMaterial = null;
public override bool CheckResources ()
{
CheckSupport (false);
overlayMaterial = CheckShaderAndCreateMaterial (overlayShader, overlayMaterial);
if (!isSupported)
ReportAutoDisable ();
return isSupported;
}
void OnRenderImage (RenderTexture source, RenderTexture destination)
{
if (CheckResources() == false)
{
Graphics.Blit (source, destination);
return;
}
Vector4 UV_Transform = new Vector4(1, 0, 0, 1);
#if UNITY_WP8
// WP8 has no OS support for rotating screen with device orientation,
// so we do those transformations ourselves.
if (Screen.orientation == ScreenOrientation.LandscapeLeft) {
UV_Transform = new Vector4(0, -1, 1, 0);
}
if (Screen.orientation == ScreenOrientation.LandscapeRight) {
UV_Transform = new Vector4(0, 1, -1, 0);
}
if (Screen.orientation == ScreenOrientation.PortraitUpsideDown) {
UV_Transform = new Vector4(-1, 0, 0, -1);
}
#endif
overlayMaterial.SetVector("_UV_Transform", UV_Transform);
overlayMaterial.SetFloat ("_Intensity", intensity);
overlayMaterial.SetTexture ("_Overlay", texture);
Graphics.Blit (source, destination, overlayMaterial, (int) blendMode);
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 6f19108706fdce9469603d07980eb8ad
MonoImporter:
serializedVersion: 2
defaultReferences:
- texture: {instanceID: 0}
- overlayShader: {fileID: 4800000, guid: 8c81db0e527d24acc9bcec04e87781bd, type: 3}
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:

View File

@@ -0,0 +1,151 @@
using System;
using UnityEngine;
namespace UnityStandardAssets.ImageEffects
{
[ExecuteInEditMode]
[RequireComponent (typeof(Camera))]
[AddComponentMenu ("Image Effects/Rendering/Sun Shafts")]
public class SunShafts : PostEffectsBase
{
public enum SunShaftsResolution
{
Low = 0,
Normal = 1,
High = 2,
}
public enum ShaftsScreenBlendMode
{
Screen = 0,
Add = 1,
}
public SunShaftsResolution resolution = SunShaftsResolution.Normal;
public ShaftsScreenBlendMode screenBlendMode = ShaftsScreenBlendMode.Screen;
public Transform sunTransform;
public int radialBlurIterations = 2;
public Color sunColor = Color.white;
public Color sunThreshold = new Color(0.87f,0.74f,0.65f);
public float sunShaftBlurRadius = 2.5f;
public float sunShaftIntensity = 1.15f;
public float maxRadius = 0.75f;
public bool useDepthTexture = true;
public Shader sunShaftsShader;
private Material sunShaftsMaterial;
public Shader simpleClearShader;
private Material simpleClearMaterial;
public override bool CheckResources () {
CheckSupport (useDepthTexture);
sunShaftsMaterial = CheckShaderAndCreateMaterial (sunShaftsShader, sunShaftsMaterial);
simpleClearMaterial = CheckShaderAndCreateMaterial (simpleClearShader, simpleClearMaterial);
if (!isSupported)
ReportAutoDisable ();
return isSupported;
}
void OnRenderImage (RenderTexture source, RenderTexture destination) {
if (CheckResources()==false) {
Graphics.Blit (source, destination);
return;
}
// we actually need to check this every frame
if (useDepthTexture)
GetComponent<Camera>().depthTextureMode |= DepthTextureMode.Depth;
int divider = 4;
if (resolution == SunShaftsResolution.Normal)
divider = 2;
else if (resolution == SunShaftsResolution.High)
divider = 1;
Vector3 v = Vector3.one * 0.5f;
if (sunTransform)
v = GetComponent<Camera>().WorldToViewportPoint (sunTransform.position);
else
v = new Vector3(0.5f, 0.5f, 0.0f);
int rtW = source.width / divider;
int rtH = source.height / divider;
RenderTexture lrColorB;
RenderTexture lrDepthBuffer = RenderTexture.GetTemporary (rtW, rtH, 0);
// mask out everything except the skybox
// we have 2 methods, one of which requires depth buffer support, the other one is just comparing images
sunShaftsMaterial.SetVector ("_BlurRadius4", new Vector4 (1.0f, 1.0f, 0.0f, 0.0f) * sunShaftBlurRadius );
sunShaftsMaterial.SetVector ("_SunPosition", new Vector4 (v.x, v.y, v.z, maxRadius));
sunShaftsMaterial.SetVector ("_SunThreshold", sunThreshold);
if (!useDepthTexture) {
#if UNITY_5_6_OR_NEWER
var format = GetComponent<Camera>().allowHDR ? RenderTextureFormat.DefaultHDR : RenderTextureFormat.Default;
#else
var format = GetComponent<Camera>().hdr ? RenderTextureFormat.DefaultHDR : RenderTextureFormat.Default;
#endif
RenderTexture tmpBuffer = RenderTexture.GetTemporary (source.width, source.height, 0, format);
RenderTexture.active = tmpBuffer;
GL.ClearWithSkybox (false, GetComponent<Camera>());
sunShaftsMaterial.SetTexture ("_Skybox", tmpBuffer);
Graphics.Blit (source, lrDepthBuffer, sunShaftsMaterial, 3);
RenderTexture.ReleaseTemporary (tmpBuffer);
}
else {
Graphics.Blit (source, lrDepthBuffer, sunShaftsMaterial, 2);
}
// paint a small black small border to get rid of clamping problems
DrawBorder (lrDepthBuffer, simpleClearMaterial);
// radial blur:
radialBlurIterations = Mathf.Clamp (radialBlurIterations, 1, 4);
float ofs = sunShaftBlurRadius * (1.0f / 768.0f);
sunShaftsMaterial.SetVector ("_BlurRadius4", new Vector4 (ofs, ofs, 0.0f, 0.0f));
sunShaftsMaterial.SetVector ("_SunPosition", new Vector4 (v.x, v.y, v.z, maxRadius));
for (int it2 = 0; it2 < radialBlurIterations; it2++ ) {
// each iteration takes 2 * 6 samples
// we update _BlurRadius each time to cheaply get a very smooth look
lrColorB = RenderTexture.GetTemporary (rtW, rtH, 0);
Graphics.Blit (lrDepthBuffer, lrColorB, sunShaftsMaterial, 1);
RenderTexture.ReleaseTemporary (lrDepthBuffer);
ofs = sunShaftBlurRadius * (((it2 * 2.0f + 1.0f) * 6.0f)) / 768.0f;
sunShaftsMaterial.SetVector ("_BlurRadius4", new Vector4 (ofs, ofs, 0.0f, 0.0f) );
lrDepthBuffer = RenderTexture.GetTemporary (rtW, rtH, 0);
Graphics.Blit (lrColorB, lrDepthBuffer, sunShaftsMaterial, 1);
RenderTexture.ReleaseTemporary (lrColorB);
ofs = sunShaftBlurRadius * (((it2 * 2.0f + 2.0f) * 6.0f)) / 768.0f;
sunShaftsMaterial.SetVector ("_BlurRadius4", new Vector4 (ofs, ofs, 0.0f, 0.0f) );
}
// put together:
if (v.z >= 0.0f)
sunShaftsMaterial.SetVector ("_SunColor", new Vector4 (sunColor.r, sunColor.g, sunColor.b, sunColor.a) * sunShaftIntensity);
else
sunShaftsMaterial.SetVector ("_SunColor", Vector4.zero); // no backprojection !
sunShaftsMaterial.SetTexture ("_ColorBuffer", lrDepthBuffer);
Graphics.Blit (source, destination, sunShaftsMaterial, (screenBlendMode == ShaftsScreenBlendMode.Screen) ? 0 : 4);
RenderTexture.ReleaseTemporary (lrDepthBuffer);
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 60e318a6043c1cb4a8ce1c8805bab930
MonoImporter:
serializedVersion: 2
defaultReferences:
- sunTransform: {instanceID: 0}
- sunShaftsShader: {fileID: 4800000, guid: d3b1c8c1036784176946f5cfbfb7fe4c, type: 3}
- simpleClearShader: {fileID: 4800000, guid: f688f89ed5eb847c5b19c934a0f1e772, type: 3}
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:

View File

@@ -0,0 +1,112 @@
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;
}
}
}

View File

@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 18b91636de2ba3445913e4cf38528dc8
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:

View File

@@ -0,0 +1,6 @@
fileFormatVersion: 2
guid: b2145489f7c704db8acb14a52bddeee9
folderAsset: yes
DefaultImporter:
userData:
assetBundleName:

View File

@@ -0,0 +1,136 @@
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;
half4 _Overlay_ST;
sampler2D _MainTex;
half4 _MainTex_ST;
half _Intensity;
half4 _MainTex_TexelSize;
half4 _UV_Transform = half4(1, 0, 0, 1);
v2f vert( appdata_img v ) {
v2f o;
o.pos = UnityObjectToClipPos(v.vertex);
o.uv[0] = UnityStereoScreenSpaceUVAdjust(float2(
dot(v.texcoord.xy, _UV_Transform.xy),
dot(v.texcoord.xy, _UV_Transform.zw)
), _Overlay_ST);
#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] = UnityStereoScreenSpaceUVAdjust(v.texcoord.xy, _MainTex_ST);
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(half3(0.5,0.5,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 * _Intensity);
}
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

View File

@@ -0,0 +1,4 @@
fileFormatVersion: 2
guid: 8c81db0e527d24acc9bcec04e87781bd
ShaderImporter:
userData:

View File

@@ -0,0 +1,52 @@
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 _MainTex_ST;
half4 _BlurOffsets;
v2f vert( appdata_img v ) {
v2f o;
o.pos = UnityObjectToClipPos(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
#ifdef UNITY_SINGLE_PASS_STEREO
// we need to keep texel size correct after the uv adjustment.
o.taps[0] = UnityStereoScreenSpaceUVAdjust(o.uv + _MainTex_TexelSize * _BlurOffsets.xy * (1.0f / _MainTex_ST.xy), _MainTex_ST);
o.taps[1] = UnityStereoScreenSpaceUVAdjust(o.uv - _MainTex_TexelSize * _BlurOffsets.xy * (1.0f / _MainTex_ST.xy), _MainTex_ST);
o.taps[2] = UnityStereoScreenSpaceUVAdjust(o.uv + _MainTex_TexelSize * _BlurOffsets.xy * half2(1, -1) * (1.0f / _MainTex_ST.xy), _MainTex_ST);
o.taps[3] = UnityStereoScreenSpaceUVAdjust(o.uv - _MainTex_TexelSize * _BlurOffsets.xy * half2(1, -1) * (1.0f / _MainTex_ST.xy), _MainTex_ST);
#else
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);
#endif
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
}

View File

@@ -0,0 +1,4 @@
fileFormatVersion: 2
guid: 57e6deea7c2924e22a5138e2b70bb4dc
ShaderImporter:
userData:

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: a40c1b84cf7fe418bae97a29041b85a4

View File

@@ -0,0 +1,70 @@
// 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
half4 _MainTex_ST;
half4 _CurTex_ST;
float4 frag (v2f_img i) : SV_Target {
// value is: max, min
float2 valAdapted = tex2D(_MainTex, UnityStereoScreenSpaceUVAdjust(i.uv, _MainTex_ST)).xy;
float2 valCur = tex2D(_CurTex, UnityStereoScreenSpaceUVAdjust(i.uv, _MainTex_ST)).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
}

View File

@@ -0,0 +1,4 @@
fileFormatVersion: 2
guid: 257bc83cbeb544540bd0e558aa9b1383
ShaderImporter:
userData:

View File

@@ -0,0 +1,56 @@
// 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;
half4 _MainTex_ST;
v2f vert (appdata_img v)
{
v2f o;
o.pos = UnityObjectToClipPos(v.vertex);
o.uv[0] = MultiplyUV (UNITY_MATRIX_TEXTURE0, UnityStereoScreenSpaceUVAdjust(v.texcoord, _MainTex_ST));
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
}

View File

@@ -0,0 +1,4 @@
fileFormatVersion: 2
guid: f4901f25d4e1542589348bbb89563d8e
ShaderImporter:
userData:

View File

@@ -0,0 +1,36 @@
// 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;
half4 _MainTex_ST;
float4 frag (v2f_img i) : SV_Target
{
float4 col = tex2D(_MainTex, UnityStereoScreenSpaceUVAdjust(i.uv, _MainTex_ST));
col.rgb = Luminance(col.rgb) * (1+col.a*2);
return col;
}
ENDCG
}
}
}
Fallback off
}

View File

@@ -0,0 +1,4 @@
fileFormatVersion: 2
guid: befbb4b9c320b4b18a08ef7afb93b6c9
ShaderImporter:
userData:

View File

@@ -0,0 +1,66 @@
// 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;
half4 _MainTex_ST;
v2f vert (appdata_img v) {
v2f o;
o.position = UnityObjectToClipPos(v.vertex);
float2 uv = MultiplyUV (UNITY_MATRIX_TEXTURE0, v.texcoord);
// Compute UVs to sample 2x2 pixel block.
o.uv[0] = UnityStereoScreenSpaceUVAdjust(uv + float2(0,0), _MainTex_ST);
o.uv[1] = UnityStereoScreenSpaceUVAdjust(uv + float2(0,1), _MainTex_ST);
o.uv[2] = UnityStereoScreenSpaceUVAdjust(uv + float2(1,0), _MainTex_ST);
o.uv[3] = UnityStereoScreenSpaceUVAdjust(uv + float2(1,1), _MainTex_ST);
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
}

View File

@@ -0,0 +1,4 @@
fileFormatVersion: 2
guid: 57b33a14b6d5347c5a85c36f6cb3b280
ShaderImporter:
userData:

View File

@@ -0,0 +1,70 @@
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;
half4 _MainTex_ST;
half4 _MainTexBlurred_ST;
float intensity;
float threshold;
v2f vert( appdata_img v ) {
v2f o;
o.pos = UnityObjectToClipPos(v.vertex);
o.uv[0] = UnityStereoScreenSpaceUVAdjust(v.texcoord.xy, _MainTexBlurred_ST);
o.uv[1] = UnityStereoScreenSpaceUVAdjust(v.texcoord.xy, _MainTex_ST);
#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 difference = color - blurred;
half4 signs = sign (difference);
half4 enhancement = saturate (abs(difference) - threshold) * signs * 1.0/(1.0-threshold);
color += enhancement * intensity;
return color;
}
ENDCG
Subshader {
Pass {
ZTest Always Cull Off ZWrite Off
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
ENDCG
}
}
Fallback off
} // shader

View File

@@ -0,0 +1,4 @@
fileFormatVersion: 2
guid: 273404942eede4ea1883ca1fb2942507
ShaderImporter:
userData:

View File

@@ -0,0 +1,56 @@
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;
half4 _CameraDepthTexture_ST;
v2f vert( appdata_img v )
{
v2f o;
o.pos = UnityObjectToClipPos(v.vertex);
o.uv = UnityStereoScreenSpaceUVAdjust(v.texcoord.xy, _CameraDepthTexture_ST);
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

View File

@@ -0,0 +1,4 @@
fileFormatVersion: 2
guid: 14768d3865b1342e3a861fbe19ba2db2
ShaderImporter:
userData:

View File

@@ -0,0 +1,97 @@
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 = UnityObjectToClipPos(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

View File

@@ -0,0 +1,4 @@
fileFormatVersion: 2
guid: 9ad381ed8492840ab9f165df743e4826
ShaderImporter:
userData:

View File

@@ -0,0 +1,261 @@
/**
\author Michael Mara and Morgan McGuire, Casual Effects. 2015.
*/
#ifndef SCREEN_SPACE_RAYTRACE_INCLUDED
#define SCREEN_SPACE_RAYTRACE_INCLUDED
sampler2D_float _CameraDepthTexture;
float distanceSquared(float2 A, float2 B) {
A -= B;
return dot(A, A);
}
float distanceSquared(float3 A, float3 B) {
A -= B;
return dot(A, A);
}
void swap(inout float v0, inout float v1) {
float temp = v0;
v0 = v1;
v1 = temp;
}
bool isIntersecting(float rayZMin, float rayZMax, float sceneZ, float layerThickness) {
return (rayZMax >= sceneZ - layerThickness) && (rayZMin <= sceneZ);
}
void rayIterations(inout float2 P, inout float stepDirection, inout float end, inout int stepCount, inout int maxSteps, inout bool intersecting,
inout float sceneZ, inout float2 dP, inout float3 Q, inout float3 dQ, inout float k, inout float dk,
inout float rayZMin, inout float rayZMax, inout float prevZMaxEstimate, inout bool permute, inout float2 hitPixel,
inout float2 invSize, inout float layerThickness) {
UNITY_LOOP
for (;
( (P.x * stepDirection) <= end) &&
(stepCount < maxSteps) &&
(!intersecting);
P += dP, Q.z += dQ.z, k += dk, stepCount += 1) {
// The depth range that the ray covers within this loop iteration.
// Assume that the ray is moving in increasing z and swap if backwards.
rayZMin = prevZMaxEstimate;
//rayZMin = (dQ.z * -0.5 + Q.z) / (dk * -0.5 + k);
// Compute the value at 1/2 pixel into the future
rayZMax = (dQ.z * 0.5 + Q.z) / (dk * 0.5 + k);
prevZMaxEstimate = rayZMax;
if (rayZMin > rayZMax) { swap(rayZMin, rayZMax); }
// Undo the homogeneous operation to obtain the camera-space
// Q at each point
hitPixel = permute ? P.yx : P;
sceneZ = tex2Dlod(_CameraDepthTexture, float4(hitPixel * invSize,0,0)).r;
sceneZ = -LinearEyeDepth(sceneZ);
intersecting = isIntersecting(rayZMin, rayZMax, sceneZ, layerThickness);
} // pixel on ray
P -= dP, Q.z -= dQ.z, k -= dk;
}
/**
\param csOrigin must have z < -0.01, and project within the valid screen rectangle
\param stepRate Set to 1.0 by default, higher to step faster
*/
bool castDenseScreenSpaceRay
(float3 csOrigin,
float3 csDirection,
float4x4 projectToPixelMatrix,
float2 csZBufferSize,
float3 clipInfo,
float jitterFraction,
int maxSteps,
float layerThickness,
float maxRayTraceDistance,
out float2 hitPixel,
int stepRate,
bool refine,
out float3 csHitPoint,
out float stepCount) {
float2 invSize = float2(1.0 / csZBufferSize.x, 1.0 / csZBufferSize.y);
// Initialize to off screen
hitPixel = float2(-1, -1);
float nearPlaneZ = -0.01;
// Clip ray to a near plane in 3D (doesn't have to be *the* near plane, although that would be a good idea)
float rayLength = ((csOrigin.z + csDirection.z * maxRayTraceDistance) > nearPlaneZ) ?
((nearPlaneZ - csOrigin.z) / csDirection.z) :
maxRayTraceDistance;
float3 csEndPoint = csDirection * rayLength + csOrigin;
// Project into screen space
// This matrix has a lot of zeroes in it. We could expand
// out these multiplies to avoid multiplying by zero
// ...but 16 MADDs are not a big deal compared to what's ahead
float4 H0 = mul(projectToPixelMatrix, float4(csOrigin, 1.0));
float4 H1 = mul(projectToPixelMatrix, float4(csEndPoint, 1.0));
// There are a lot of divisions by w that can be turned into multiplications
// at some minor precision loss...and we need to interpolate these 1/w values
// anyway.
//
// Because the caller was required to clip to the near plane,
// this homogeneous division (projecting from 4D to 2D) is guaranteed
// to succeed.
float k0 = 1.0 / H0.w;
float k1 = 1.0 / H1.w;
// Screen-space endpoints
float2 P0 = H0.xy * k0;
float2 P1 = H1.xy * k1;
// Switch the original points to values that interpolate linearly in 2D:
float3 Q0 = csOrigin * k0;
float3 Q1 = csEndPoint * k1;
#if 1 // Clipping to the screen coordinates. We could simply modify maxSteps instead
float yMax = csZBufferSize.y - 0.5;
float yMin = 0.5;
float xMax = csZBufferSize.x - 0.5;
float xMin = 0.5;
// 2D interpolation parameter
float alpha = 0.0;
// P0 must be in bounds
if (P1.y > yMax || P1.y < yMin) {
float yClip = (P1.y > yMax) ? yMax : yMin;
float yAlpha = (P1.y - yClip) / (P1.y - P0.y); // Denominator is not zero, since P0 != P1 (or P0 would have been clipped!)
alpha = yAlpha;
}
// P0 must be in bounds
if (P1.x > xMax || P1.x < xMin) {
float xClip = (P1.x > xMax) ? xMax : xMin;
float xAlpha = (P1.x - xClip) / (P1.x - P0.x); // Denominator is not zero, since P0 != P1 (or P0 would have been clipped!)
alpha = max(alpha, xAlpha);
}
// These are all in homogeneous space, so they interpolate linearly
P1 = lerp(P1, P0, alpha);
k1 = lerp(k1, k0, alpha);
Q1 = lerp(Q1, Q0, alpha);
#endif
// We're doing this to avoid divide by zero (rays exactly parallel to an eye ray)
P1 = (distanceSquared(P0, P1) < 0.0001) ? P0 + float2(0.01, 0.01) : P1;
float2 delta = P1 - P0;
// Assume horizontal
bool permute = false;
if (abs(delta.x) < abs(delta.y)) {
// More-vertical line. Create a permutation that swaps x and y in the output
permute = true;
// Directly swizzle the inputs
delta = delta.yx;
P1 = P1.yx;
P0 = P0.yx;
}
// From now on, "x" is the primary iteration direction and "y" is the secondary one
float stepDirection = sign(delta.x);
float invdx = stepDirection / delta.x;
float2 dP = float2(stepDirection, invdx * delta.y);
// Track the derivatives of Q and k
float3 dQ = (Q1 - Q0) * invdx;
float dk = (k1 - k0) * invdx;
dP *= stepRate;
dQ *= stepRate;
dk *= stepRate;
P0 += dP * jitterFraction;
Q0 += dQ * jitterFraction;
k0 += dk * jitterFraction;
// Slide P from P0 to P1, (now-homogeneous) Q from Q0 to Q1, and k from k0 to k1
float3 Q = Q0;
float k = k0;
// We track the ray depth at +/- 1/2 pixel to treat pixels as clip-space solid
// voxels. Because the depth at -1/2 for a given pixel will be the same as at
// +1/2 for the previous iteration, we actually only have to compute one value
// per iteration.
float prevZMaxEstimate = csOrigin.z;
stepCount = 0.0;
float rayZMax = prevZMaxEstimate, rayZMin = prevZMaxEstimate;
float sceneZ = 100000;
// P1.x is never modified after this point, so pre-scale it by
// the step direction for a signed comparison
float end = P1.x * stepDirection;
bool intersecting = isIntersecting(rayZMin, rayZMax, sceneZ, layerThickness);
// We only advance the z field of Q in the inner loop, since
// Q.xy is never used until after the loop terminates
//int rayIterations = min(maxSteps, stepsToGetOffscreen);
float2 P = P0;
int originalStepCount = 0;
rayIterations(P, stepDirection, end, originalStepCount, maxSteps, intersecting,
sceneZ, dP, Q, dQ, k, dk,
rayZMin, rayZMax, prevZMaxEstimate, permute, hitPixel,
invSize, layerThickness);
stepCount = originalStepCount;
if (refine && intersecting && stepRate > 1) {
// We're going back a step.
P -= dP, Q.z -= dQ.z, k -= dk;
prevZMaxEstimate = Q.z / k;
rayZMin = prevZMaxEstimate;
rayZMax = prevZMaxEstimate;
intersecting = false;
int refinementStepCount = 0;
int refinementMaxSteps = stepRate;
float refinementConstant = 1.0 / stepRate;
dQ.z *= refinementConstant;
dP *= refinementConstant;
dk *= refinementConstant;
// Refinement
rayIterations(P, stepDirection, end, refinementStepCount, refinementMaxSteps, intersecting,
sceneZ, dP, Q, dQ, k, dk,
rayZMin, rayZMax, prevZMaxEstimate, permute, hitPixel,
invSize, layerThickness);
stepCount += refinementStepCount * refinementConstant - 1.0;
//stepCount = refinementStepCount;
intersecting = true;
}
// Loop only advanced the Z component. Now that we know where we are going
// update xy
Q.xy += dQ.xy * stepCount;
// Q is a vector, so we are trying to get by with 1 division instead of 3.
csHitPoint = Q * (1.0 / k);
return intersecting;
}
#endif // SCREEN_SPACE_RAYTRACE_INCLUDED

View File

@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 26c67b7245085cf438e3d42d50d94f55
timeCreated: 1425661779
licenseType: Store
ShaderImporter:
defaultTextures: []
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,54 @@
Shader "Hidden/ShowAlphaChannel" {
Properties {
_MainTex ("Base (RGB)", 2D) = "white" {}
_EdgeTex ("_EdgeTex", 2D) = "white" {}
}
SubShader {
Pass {
ZTest Always Cull Off ZWrite Off
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
uniform sampler2D _MainTex;
uniform sampler2D _EdgeTex;
uniform float4 _MainTex_TexelSize;
float filterRadius;
struct v2f {
float4 pos : SV_POSITION;
float2 uv : TEXCOORD0;
};
v2f vert( appdata_img v )
{
v2f o;
o.pos = UnityObjectToClipPos(v.vertex);
o.uv = v.texcoord.xy;
return o;
}
half4 frag (v2f i) : SV_Target
{
half4 color = tex2D(_MainTex, i.uv.xy);
half edges = color.a;
return edges;
}
ENDCG
}
}
Fallback off
}

View File

@@ -0,0 +1,4 @@
fileFormatVersion: 2
guid: da310021e2a4142429d95c537846dc38
ShaderImporter:
userData:

View File

@@ -0,0 +1,41 @@
Shader "Hidden/SimpleClear" {
Properties {
_MainTex ("Base (RGB)", 2D) = "white" {}
}
SubShader {
Pass {
ZTest Always Cull Off ZWrite Off
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
uniform sampler2D _MainTex;
uniform float4 _MainTex_TexelSize;
struct v2f {
float4 pos : SV_POSITION;
};
v2f vert( appdata_img v )
{
v2f o;
o.pos = UnityObjectToClipPos(v.vertex);
return o;
}
half4 frag (v2f i) : SV_Target
{
return half4(0,0,0,0);
}
ENDCG
}
}
Fallback off
}

View File

@@ -0,0 +1,4 @@
fileFormatVersion: 2
guid: f688f89ed5eb847c5b19c934a0f1e772
ShaderImporter:
userData:

View File

@@ -0,0 +1,227 @@
Shader "Hidden/SunShaftsComposite" {
Properties {
_MainTex ("Base", 2D) = "" {}
_ColorBuffer ("Color", 2D) = "" {}
_Skybox ("Skybox", 2D) = "" {}
}
CGINCLUDE
#include "UnityCG.cginc"
struct v2f {
float4 pos : SV_POSITION;
float2 uv : TEXCOORD0;
#if UNITY_UV_STARTS_AT_TOP
float2 uv1 : TEXCOORD1;
#endif
};
struct v2f_radial {
float4 pos : SV_POSITION;
float2 uv : TEXCOORD0;
float2 blurVector : TEXCOORD1;
};
sampler2D _MainTex;
sampler2D _ColorBuffer;
sampler2D _Skybox;
sampler2D_float _CameraDepthTexture;
uniform half4 _SunThreshold;
uniform half4 _SunColor;
uniform half4 _BlurRadius4;
uniform half4 _SunPosition;
uniform half4 _MainTex_TexelSize;
half4 _MainTex_ST;
half4 _ColorBuffer_ST;
half4 _Skybox_ST;
half4 _CameraDepthTexture_ST;
#define SAMPLES_FLOAT 6.0f
#define SAMPLES_INT 6
v2f vert( appdata_img v ) {
v2f o;
o.pos = UnityObjectToClipPos(v.vertex);
o.uv = v.texcoord.xy;
#if UNITY_UV_STARTS_AT_TOP
o.uv1 = v.texcoord.xy;
if (_MainTex_TexelSize.y < 0)
o.uv1.y = 1-o.uv1.y;
#endif
return o;
}
half4 fragScreen(v2f i) : SV_Target {
half4 colorA = tex2D (_MainTex, UnityStereoScreenSpaceUVAdjust(i.uv.xy, _MainTex_ST));
#if UNITY_UV_STARTS_AT_TOP
half4 colorB = tex2D (_ColorBuffer, UnityStereoScreenSpaceUVAdjust(i.uv1.xy, _ColorBuffer_ST));
#else
half4 colorB = tex2D (_ColorBuffer, UnityStereoScreenSpaceUVAdjust(i.uv.xy, _ColorBuffer_ST));
#endif
half4 depthMask = saturate (colorB * _SunColor);
return 1.0f - (1.0f-colorA) * (1.0f-depthMask);
}
half4 fragAdd(v2f i) : SV_Target {
half4 colorA = tex2D (_MainTex, UnityStereoScreenSpaceUVAdjust(i.uv.xy, _MainTex_ST));
#if UNITY_UV_STARTS_AT_TOP
half4 colorB = tex2D (_ColorBuffer, UnityStereoScreenSpaceUVAdjust(i.uv1.xy, _ColorBuffer_ST));
#else
half4 colorB = tex2D (_ColorBuffer, UnityStereoScreenSpaceUVAdjust(i.uv.xy, _ColorBuffer_ST));
#endif
half4 depthMask = saturate (colorB * _SunColor);
return colorA + depthMask;
}
v2f_radial vert_radial( appdata_img v ) {
v2f_radial o;
o.pos = UnityObjectToClipPos(v.vertex);
o.uv.xy = v.texcoord.xy;
o.blurVector = (_SunPosition.xy - v.texcoord.xy) * _BlurRadius4.xy;
return o;
}
half4 frag_radial(v2f_radial i) : SV_Target
{
half4 color = half4(0,0,0,0);
for(int j = 0; j < SAMPLES_INT; j++)
{
half4 tmpColor = tex2D(_MainTex, UnityStereoScreenSpaceUVAdjust(i.uv.xy, _MainTex_ST));
color += tmpColor;
i.uv.xy += i.blurVector;
}
return color / SAMPLES_FLOAT;
}
half TransformColor (half4 skyboxValue) {
return dot(max(skyboxValue.rgb - _SunThreshold.rgb, half3(0,0,0)), half3(1,1,1)); // threshold and convert to greyscale
}
half4 frag_depth (v2f i) : SV_Target {
#if UNITY_UV_STARTS_AT_TOP
float depthSample = SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, UnityStereoScreenSpaceUVAdjust(i.uv1.xy, _CameraDepthTexture_ST));
#else
float depthSample = SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, UnityStereoScreenSpaceUVAdjust(i.uv.xy, _CameraDepthTexture_ST));
#endif
half4 tex = tex2D (_MainTex, UnityStereoScreenSpaceUVAdjust(i.uv.xy, _MainTex_ST));
depthSample = Linear01Depth (depthSample);
// consider maximum radius
#if UNITY_UV_STARTS_AT_TOP
half2 vec = _SunPosition.xy - i.uv1.xy;
#else
half2 vec = _SunPosition.xy - i.uv.xy;
#endif
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 frag_nodepth (v2f i) : SV_Target {
#if UNITY_UV_STARTS_AT_TOP
float4 sky = (tex2D (_Skybox, UnityStereoScreenSpaceUVAdjust(i.uv1.xy, _Skybox_ST)));
#else
float4 sky = (tex2D (_Skybox, UnityStereoScreenSpaceUVAdjust(i.uv.xy, _Skybox_ST)));
#endif
float4 tex = (tex2D (_MainTex, UnityStereoScreenSpaceUVAdjust(i.uv.xy, _MainTex_ST)));
// consider maximum radius
#if UNITY_UV_STARTS_AT_TOP
half2 vec = _SunPosition.xy - i.uv1.xy;
#else
half2 vec = _SunPosition.xy - i.uv.xy;
#endif
half dist = saturate (_SunPosition.w - length (vec));
half4 outColor = 0;
// find unoccluded sky pixels
// consider pixel values that differ significantly between framebuffer and sky-only buffer as occluded
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 fragScreen
ENDCG
}
Pass {
ZTest Always Cull Off ZWrite Off
CGPROGRAM
#pragma vertex vert_radial
#pragma fragment frag_radial
ENDCG
}
Pass {
ZTest Always Cull Off ZWrite Off
CGPROGRAM
#pragma vertex vert
#pragma fragment frag_depth
ENDCG
}
Pass {
ZTest Always Cull Off ZWrite Off
CGPROGRAM
#pragma vertex vert
#pragma fragment frag_nodepth
ENDCG
}
Pass {
ZTest Always Cull Off ZWrite Off
CGPROGRAM
#pragma vertex vert
#pragma fragment fragAdd
ENDCG
}
}
Fallback off
} // shader

View File

@@ -0,0 +1,4 @@
fileFormatVersion: 2
guid: d3b1c8c1036784176946f5cfbfb7fe4c
ShaderImporter:
userData:

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: d6ef58fc6f637406bbe6814a19c377f8

View File

@@ -0,0 +1,116 @@
Shader "Hidden/Blend" {
Properties {
_MainTex ("Screen Blended", 2D) = "" {}
_ColorBuffer ("Color", 2D) = "" {}
}
CGINCLUDE
#include "UnityCG.cginc"
struct v2f {
float4 pos : SV_POSITION;
float2 uv[2] : TEXCOORD0;
};
struct v2f_mt {
float4 pos : SV_POSITION;
float2 uv[4] : TEXCOORD0;
};
sampler2D _ColorBuffer;
sampler2D _MainTex;
half _Intensity;
half4 _ColorBuffer_TexelSize;
half4 _ColorBuffer_ST;
half4 _MainTex_TexelSize;
half4 _MainTex_ST;
v2f vert( appdata_img v ) {
v2f o;
o.pos = UnityObjectToClipPos(v.vertex);
o.uv[0] = v.texcoord.xy;
o.uv[1] = v.texcoord.xy;
#if UNITY_UV_STARTS_AT_TOP
if (_ColorBuffer_TexelSize.y < 0)
o.uv[1].y = 1-o.uv[1].y;
#endif
return o;
}
v2f_mt vertMultiTap( appdata_img v ) {
v2f_mt o;
o.pos = UnityObjectToClipPos(v.vertex);
o.uv[0] = v.texcoord.xy + _MainTex_TexelSize.xy * 0.5;
o.uv[1] = v.texcoord.xy - _MainTex_TexelSize.xy * 0.5;
o.uv[2] = v.texcoord.xy - _MainTex_TexelSize.xy * half2(1,-1) * 0.5;
o.uv[3] = v.texcoord.xy + _MainTex_TexelSize.xy * half2(1,-1) * 0.5;
return o;
}
half4 fragScreen (v2f i) : SV_Target {
half4 toBlend = saturate (tex2D(_MainTex, UnityStereoScreenSpaceUVAdjust(i.uv[0], _MainTex_ST)) * _Intensity);
return 1-(1-toBlend)*(1-tex2D(_ColorBuffer, UnityStereoScreenSpaceUVAdjust(i.uv[1], _ColorBuffer_ST)));
}
half4 fragAdd (v2f i) : SV_Target {
return tex2D(_MainTex, UnityStereoScreenSpaceUVAdjust(i.uv[0].xy, _MainTex_ST)) * _Intensity + tex2D(_ColorBuffer, UnityStereoScreenSpaceUVAdjust(i.uv[1], _ColorBuffer_ST));
}
half4 fragVignetteBlend (v2f i) : SV_Target {
return tex2D(_MainTex, UnityStereoScreenSpaceUVAdjust(i.uv[0].xy, _MainTex_ST)) * tex2D(_ColorBuffer, UnityStereoScreenSpaceUVAdjust(i.uv[0], _ColorBuffer_ST));
}
half4 fragMultiTap (v2f_mt i) : SV_Target {
half4 outColor = tex2D(_MainTex, UnityStereoScreenSpaceUVAdjust(i.uv[0].xy, _MainTex_ST));
outColor += tex2D(_MainTex, UnityStereoScreenSpaceUVAdjust(i.uv[1].xy, _MainTex_ST));
outColor += tex2D(_MainTex, UnityStereoScreenSpaceUVAdjust(i.uv[2].xy, _MainTex_ST));
outColor += tex2D(_MainTex, UnityStereoScreenSpaceUVAdjust(i.uv[3].xy, _MainTex_ST));
return outColor * 0.25;
}
ENDCG
Subshader {
ZTest Always Cull Off ZWrite Off
// 0: nicer & softer "screen" blend mode
Pass {
CGPROGRAM
#pragma vertex vert
#pragma fragment fragScreen
ENDCG
}
// 1: simple "add" blend mode
Pass {
CGPROGRAM
#pragma vertex vert
#pragma fragment fragAdd
ENDCG
}
// 2: used for "stable" downsampling
Pass {
CGPROGRAM
#pragma vertex vertMultiTap
#pragma fragment fragMultiTap
ENDCG
}
// 3: vignette blending
Pass {
CGPROGRAM
#pragma vertex vert
#pragma fragment fragVignetteBlend
ENDCG
}
}
Fallback off
} // shader

View File

@@ -0,0 +1,4 @@
fileFormatVersion: 2
guid: 53b3960ee3d3d4a5caa8d5473d120187
ShaderImporter:
userData:

View File

@@ -0,0 +1,222 @@
Shader "Hidden/BlendForBloom" {
Properties {
_MainTex ("Screen Blended", 2D) = "" {}
_ColorBuffer ("Color", 2D) = "" {}
}
CGINCLUDE
#include "UnityCG.cginc"
struct v2f {
float4 pos : SV_POSITION;
float2 uv[2] : TEXCOORD0;
};
struct v2f_mt {
float4 pos : SV_POSITION;
float2 uv[5] : TEXCOORD0;
};
sampler2D _ColorBuffer;
sampler2D _MainTex;
half _Intensity;
half4 _ColorBuffer_TexelSize;
half4 _ColorBuffer_ST;
half4 _MainTex_TexelSize;
half4 _MainTex_ST;
v2f vert( appdata_img v ) {
v2f o;
o.pos = UnityObjectToClipPos(v.vertex);
o.uv[0] = v.texcoord.xy;
o.uv[1] = v.texcoord.xy;
#if UNITY_UV_STARTS_AT_TOP
if (_ColorBuffer_TexelSize.y < 0)
o.uv[1].y = 1-o.uv[1].y;
#endif
return o;
}
v2f_mt vertMultiTap( appdata_img v ) {
v2f_mt o;
o.pos = UnityObjectToClipPos(v.vertex);
o.uv[4] = v.texcoord.xy;
o.uv[0] = v.texcoord.xy + _MainTex_TexelSize.xy * 0.5;
o.uv[1] = v.texcoord.xy - _MainTex_TexelSize.xy * 0.5;
o.uv[2] = v.texcoord.xy - _MainTex_TexelSize.xy * half2(1,-1) * 0.5;
o.uv[3] = v.texcoord.xy + _MainTex_TexelSize.xy * half2(1,-1) * 0.5;
return o;
}
half4 fragScreen (v2f i) : SV_Target {
half4 addedbloom = tex2D(_MainTex, UnityStereoScreenSpaceUVAdjust(i.uv[0].xy, _MainTex_ST)) * _Intensity;
half4 screencolor = tex2D(_ColorBuffer, UnityStereoScreenSpaceUVAdjust(i.uv[1], _ColorBuffer_ST));
return 1-(1-addedbloom)*(1-screencolor);
}
half4 fragScreenCheap(v2f i) : SV_Target {
half4 addedbloom = tex2D(_MainTex, UnityStereoScreenSpaceUVAdjust(i.uv[0].xy, _MainTex_ST)) * _Intensity;
half4 screencolor = tex2D(_ColorBuffer, UnityStereoScreenSpaceUVAdjust(i.uv[1], _ColorBuffer_ST));
return 1-(1-addedbloom)*(1-screencolor);
}
half4 fragAdd (v2f i) : SV_Target {
half4 addedbloom = tex2D(_MainTex, UnityStereoScreenSpaceUVAdjust(i.uv[0].xy, _MainTex_ST));
half4 screencolor = tex2D(_ColorBuffer, UnityStereoScreenSpaceUVAdjust(i.uv[1], _ColorBuffer_ST));
return _Intensity * addedbloom + screencolor;
}
half4 fragAddCheap (v2f i) : SV_Target {
half4 addedbloom = tex2D(_MainTex, UnityStereoScreenSpaceUVAdjust(i.uv[0].xy, _MainTex_ST));
half4 screencolor = tex2D(_ColorBuffer, UnityStereoScreenSpaceUVAdjust(i.uv[1], _ColorBuffer_ST));
return _Intensity * addedbloom + screencolor;
}
half4 fragVignetteMul (v2f i) : SV_Target {
return tex2D(_MainTex, UnityStereoScreenSpaceUVAdjust(i.uv[0].xy, _MainTex_ST)) * tex2D(_ColorBuffer, UnityStereoScreenSpaceUVAdjust(i.uv[0], _ColorBuffer_ST));
}
half4 fragVignetteBlend (v2f i) : SV_Target {
return half4(1,1,1, tex2D(_ColorBuffer, UnityStereoScreenSpaceUVAdjust(i.uv[0], _ColorBuffer_ST)).r);
}
half4 fragClear (v2f i) : SV_Target {
return 0;
}
half4 fragAddOneOne (v2f i) : SV_Target {
half4 addedColors = tex2D(_MainTex, UnityStereoScreenSpaceUVAdjust(i.uv[0].xy, _MainTex_ST));
return addedColors * _Intensity;
}
half4 frag1Tap (v2f i) : SV_Target {
return tex2D(_MainTex, UnityStereoScreenSpaceUVAdjust(i.uv[0].xy, _MainTex_ST));
}
half4 fragMultiTapMax (v2f_mt i) : SV_Target {
half4 outColor = tex2D(_MainTex, UnityStereoScreenSpaceUVAdjust(i.uv[4].xy, _MainTex_ST));
outColor = max(outColor, tex2D(_MainTex, UnityStereoScreenSpaceUVAdjust(i.uv[0].xy, _MainTex_ST)));
outColor = max(outColor, tex2D(_MainTex, UnityStereoScreenSpaceUVAdjust(i.uv[1].xy, _MainTex_ST)));
outColor = max(outColor, tex2D(_MainTex, UnityStereoScreenSpaceUVAdjust(i.uv[2].xy, _MainTex_ST)));
outColor = max(outColor, tex2D(_MainTex, UnityStereoScreenSpaceUVAdjust(i.uv[3].xy, _MainTex_ST)));
return outColor;
}
half4 fragMultiTapBlur (v2f_mt i) : SV_Target {
half4 outColor = 0;
outColor += tex2D(_MainTex, UnityStereoScreenSpaceUVAdjust(i.uv[0].xy, _MainTex_ST));
outColor += tex2D(_MainTex, UnityStereoScreenSpaceUVAdjust(i.uv[1].xy, _MainTex_ST));
outColor += tex2D(_MainTex, UnityStereoScreenSpaceUVAdjust(i.uv[2].xy, _MainTex_ST));
outColor += tex2D(_MainTex, UnityStereoScreenSpaceUVAdjust(i.uv[3].xy, _MainTex_ST));
return outColor/4;
}
ENDCG
Subshader {
ZTest Always Cull Off ZWrite Off
// 0: nicer & softer "screen" blend mode
Pass {
CGPROGRAM
#pragma vertex vert
#pragma fragment fragScreen
ENDCG
}
// 1: "add" blend mode
Pass {
CGPROGRAM
#pragma vertex vert
#pragma fragment fragAdd
ENDCG
}
// 2: several taps, maxxed
Pass {
CGPROGRAM
#pragma vertex vertMultiTap
#pragma fragment fragMultiTapMax
ENDCG
}
// 3: vignette blending
Pass {
CGPROGRAM
#pragma vertex vert
#pragma fragment fragVignetteMul
ENDCG
}
// 4: nicer & softer "screen" blend mode(cheapest)
Pass {
CGPROGRAM
#pragma vertex vert
#pragma fragment fragScreenCheap
ENDCG
}
// 5: "add" blend mode (cheapest)
Pass {
CGPROGRAM
#pragma vertex vert
#pragma fragment fragAddCheap
ENDCG
}
// 6: used for "stable" downsampling (blur)
Pass {
CGPROGRAM
#pragma vertex vertMultiTap
#pragma fragment fragMultiTapBlur
ENDCG
}
// 7: vignette blending (blend to dest)
Pass {
Blend Zero SrcAlpha
CGPROGRAM
#pragma vertex vert
#pragma fragment fragVignetteBlend
ENDCG
}
// 8: clear
Pass {
CGPROGRAM
#pragma vertex vert
#pragma fragment fragClear
ENDCG
}
// 9: fragAddOneOne
Pass {
Blend One One
CGPROGRAM
#pragma vertex vert
#pragma fragment fragAddOneOne
ENDCG
}
// 10: max blend
Pass {
BlendOp Max
Blend One One
CGPROGRAM
#pragma vertex vert
#pragma fragment frag1Tap
ENDCG
}
}
Fallback off
} // shader

View File

@@ -0,0 +1,4 @@
fileFormatVersion: 2
guid: 7856cbff0a0ca45c787d5431eb805bb0
ShaderImporter:
userData:

View File

@@ -0,0 +1,49 @@
Shader "Hidden/BlendOneOne" {
Properties {
_MainTex ("-", 2D) = "" {}
}
CGINCLUDE
#include "UnityCG.cginc"
struct v2f {
float4 pos : SV_POSITION;
float2 uv : TEXCOORD0;
};
sampler2D _MainTex;
half4 _MainTex_ST;
half _Intensity;
v2f vert( appdata_img v ) {
v2f o;
o.pos = UnityObjectToClipPos(v.vertex);
o.uv = UnityStereoScreenSpaceUVAdjust(v.texcoord.xy, _MainTex_ST);
return o;
}
half4 frag(v2f i) : SV_Target {
return tex2D(_MainTex, i.uv) * _Intensity;
}
ENDCG
Subshader {
Pass {
BlendOp Add
Blend One One
ZTest Always Cull Off ZWrite Off
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
ENDCG
}
}
Fallback off
}

View File

@@ -0,0 +1,4 @@
fileFormatVersion: 2
guid: f7898d203e9b94c0dbe2bf9dd5cb32c0
ShaderImporter:
userData:

View File

@@ -0,0 +1,203 @@
Shader "Hidden/BlurAndFlares" {
Properties {
_MainTex ("Base (RGB)", 2D) = "" {}
_NonBlurredTex ("Base (RGB)", 2D) = "" {}
}
CGINCLUDE
#include "UnityCG.cginc"
struct v2f {
half4 pos : SV_POSITION;
half2 uv : TEXCOORD0;
};
struct v2f_opts {
half4 pos : SV_POSITION;
half2 uv[7] : TEXCOORD0;
};
struct v2f_blur {
half4 pos : SV_POSITION;
half2 uv : TEXCOORD0;
half4 uv01 : TEXCOORD1;
half4 uv23 : TEXCOORD2;
half4 uv45 : TEXCOORD3;
half4 uv67 : TEXCOORD4;
};
half4 _Offsets;
half4 _TintColor;
half _StretchWidth;
half2 _Threshhold;
half _Saturation;
half4 _MainTex_TexelSize;
half4 _MainTex_ST;
sampler2D _MainTex;
sampler2D _NonBlurredTex;
v2f vert (appdata_img v) {
v2f o;
o.pos = UnityObjectToClipPos(v.vertex);
o.uv = v.texcoord.xy;
return o;
}
v2f_blur vertWithMultiCoords2 (appdata_img v) {
v2f_blur o;
o.pos = UnityObjectToClipPos(v.vertex);
o.uv.xy = UnityStereoScreenSpaceUVAdjust(v.texcoord.xy, _MainTex_ST);
o.uv01 = UnityStereoScreenSpaceUVAdjust(v.texcoord.xyxy + _Offsets.xyxy * half4(1,1, -1,-1), _MainTex_ST);
o.uv23 = UnityStereoScreenSpaceUVAdjust(v.texcoord.xyxy + _Offsets.xyxy * half4(1,1, -1,-1) * 2.0, _MainTex_ST);
o.uv45 = UnityStereoScreenSpaceUVAdjust(v.texcoord.xyxy + _Offsets.xyxy * half4(1,1, -1,-1) * 3.0, _MainTex_ST);
o.uv67 = UnityStereoScreenSpaceUVAdjust(v.texcoord.xyxy + _Offsets.xyxy * half4(1,1, -1,-1) * 4.0, _MainTex_ST);
o.uv67 = UnityStereoScreenSpaceUVAdjust(v.texcoord.xyxy + _Offsets.xyxy * half4(1,1, -1,-1) * 5.0, _MainTex_ST);
return o;
}
v2f_opts vertStretch (appdata_img v) {
v2f_opts o;
o.pos = UnityObjectToClipPos(v.vertex);
half b = _StretchWidth;
o.uv[0] = UnityStereoScreenSpaceUVAdjust(v.texcoord.xy, _MainTex_ST);
o.uv[1] = UnityStereoScreenSpaceUVAdjust(v.texcoord.xy + b * 2.0 * _Offsets.xy, _MainTex_ST);
o.uv[2] = UnityStereoScreenSpaceUVAdjust(v.texcoord.xy - b * 2.0 * _Offsets.xy, _MainTex_ST);
o.uv[3] = UnityStereoScreenSpaceUVAdjust(v.texcoord.xy + b * 4.0 * _Offsets.xy, _MainTex_ST);
o.uv[4] = UnityStereoScreenSpaceUVAdjust(v.texcoord.xy - b * 4.0 * _Offsets.xy, _MainTex_ST);
o.uv[5] = UnityStereoScreenSpaceUVAdjust(v.texcoord.xy + b * 6.0 * _Offsets.xy, _MainTex_ST);
o.uv[6] = UnityStereoScreenSpaceUVAdjust(v.texcoord.xy - b * 6.0 * _Offsets.xy, _MainTex_ST);
return o;
}
v2f_opts vertWithMultiCoords (appdata_img v) {
v2f_opts o;
o.pos = UnityObjectToClipPos(v.vertex);
o.uv[0] = UnityStereoScreenSpaceUVAdjust(v.texcoord.xy, _MainTex_ST);
o.uv[1] = UnityStereoScreenSpaceUVAdjust(v.texcoord.xy + 0.5 * _MainTex_TexelSize.xy * _Offsets.xy, _MainTex_ST);
o.uv[2] = UnityStereoScreenSpaceUVAdjust(v.texcoord.xy - 0.5 * _MainTex_TexelSize.xy * _Offsets.xy, _MainTex_ST);
o.uv[3] = UnityStereoScreenSpaceUVAdjust(v.texcoord.xy + 1.5 * _MainTex_TexelSize.xy * _Offsets.xy, _MainTex_ST);
o.uv[4] = UnityStereoScreenSpaceUVAdjust(v.texcoord.xy - 1.5 * _MainTex_TexelSize.xy * _Offsets.xy, _MainTex_ST);
o.uv[5] = UnityStereoScreenSpaceUVAdjust(v.texcoord.xy + 2.5 * _MainTex_TexelSize.xy * _Offsets.xy, _MainTex_ST);
o.uv[6] = UnityStereoScreenSpaceUVAdjust(v.texcoord.xy - 2.5 * _MainTex_TexelSize.xy * _Offsets.xy, _MainTex_ST);
return o;
}
half4 fragPostNoBlur (v2f i) : SV_Target {
half4 color = tex2D (_MainTex, i.uv);
return color * 1.0/(1.0 + Luminance(color.rgb) + 0.5); // this also makes it a little noisy
}
half4 fragGaussBlur (v2f_blur i) : SV_Target {
half4 color = half4 (0,0,0,0);
color += 0.225 * tex2D (_MainTex, i.uv);
color += 0.150 * tex2D (_MainTex, i.uv01.xy);
color += 0.150 * tex2D (_MainTex, i.uv01.zw);
color += 0.110 * tex2D (_MainTex, i.uv23.xy);
color += 0.110 * tex2D (_MainTex, i.uv23.zw);
color += 0.075 * tex2D (_MainTex, i.uv45.xy);
color += 0.075 * tex2D (_MainTex, i.uv45.zw);
color += 0.0525 * tex2D (_MainTex, i.uv67.xy);
color += 0.0525 * tex2D (_MainTex, i.uv67.zw);
return color;
}
half4 fragPreAndCut (v2f_opts i) : SV_Target {
half4 color = tex2D (_MainTex, i.uv[0]);
color += tex2D (_MainTex, i.uv[1]);
color += tex2D (_MainTex, i.uv[2]);
color += tex2D (_MainTex, i.uv[3]);
color += tex2D (_MainTex, i.uv[4]);
color += tex2D (_MainTex, i.uv[5]);
color += tex2D (_MainTex, i.uv[6]);
color = max(color / 7.0 - _Threshhold.xxxx, float4(0,0,0,0));
half lum = Luminance(color.rgb);
color.rgb = lerp(half3(lum,lum,lum), color.rgb, _Saturation) * _TintColor.rgb;
return color;
}
half4 fragStretch (v2f_opts i) : SV_Target {
half4 color = tex2D (_MainTex, i.uv[0]);
color = max (color, tex2D (_MainTex, i.uv[1]));
color = max (color, tex2D (_MainTex, i.uv[2]));
color = max (color, tex2D (_MainTex, i.uv[3]));
color = max (color, tex2D (_MainTex, i.uv[4]));
color = max (color, tex2D (_MainTex, i.uv[5]));
color = max (color, tex2D (_MainTex, i.uv[6]));
return color;
}
half4 fragPost (v2f_opts i) : SV_Target {
half4 color = tex2D (_MainTex, i.uv[0]);
color += tex2D (_MainTex, i.uv[1]);
color += tex2D (_MainTex, i.uv[2]);
color += tex2D (_MainTex, i.uv[3]);
color += tex2D (_MainTex, i.uv[4]);
color += tex2D (_MainTex, i.uv[5]);
color += tex2D (_MainTex, i.uv[6]);
return color * 1.0/(7.0 + Luminance(color.rgb) + 0.5); // this also makes it a little noisy
}
ENDCG
Subshader {
ZTest Always Cull Off ZWrite Off
Pass {
CGPROGRAM
#pragma vertex vert
#pragma fragment fragPostNoBlur
ENDCG
}
Pass {
CGPROGRAM
#pragma vertex vertStretch
#pragma fragment fragStretch
ENDCG
}
// 2
Pass {
CGPROGRAM
#pragma vertex vertWithMultiCoords
#pragma fragment fragPreAndCut
ENDCG
}
// 3
Pass {
CGPROGRAM
#pragma vertex vertWithMultiCoords
#pragma fragment fragPost
ENDCG
}
// 4
Pass {
CGPROGRAM
#pragma vertex vertWithMultiCoords2
#pragma fragment fragGaussBlur
ENDCG
}
}
Fallback off
}

View File

@@ -0,0 +1,4 @@
fileFormatVersion: 2
guid: be6e39cf196f146d5be72fbefb18ed75
ShaderImporter:
userData:

View File

@@ -0,0 +1,58 @@
Shader "Hidden/BrightPassFilterForBloom"
{
Properties
{
_MainTex ("Base (RGB)", 2D) = "" {}
}
CGINCLUDE
#include "UnityCG.cginc"
struct v2f
{
float4 pos : SV_POSITION;
float2 uv : TEXCOORD0;
};
sampler2D _MainTex;
half4 _MainTex_ST;
half4 threshold;
half useSrcAlphaAsMask;
v2f vert( appdata_img v )
{
v2f o;
o.pos = UnityObjectToClipPos(v.vertex);
o.uv = UnityStereoScreenSpaceUVAdjust(v.texcoord.xy, _MainTex_ST);
return o;
}
half4 frag(v2f i) : SV_Target
{
half4 color = tex2D(_MainTex, i.uv);
//color = color * saturate((color-threshhold.x) * 75.0); // didn't go well with HDR and din't make sense
color = color * lerp(1.0, color.a, useSrcAlphaAsMask);
color = max(half4(0,0,0,0), color-threshold.x);
return color;
}
ENDCG
Subshader
{
Pass
{
ZTest Always Cull Off ZWrite Off
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
ENDCG
}
}
Fallback off
}

View File

@@ -0,0 +1,4 @@
fileFormatVersion: 2
guid: 186c4c0d31e314f049595dcbaf4ca129
ShaderImporter:
userData:

View File

@@ -0,0 +1,75 @@
Shader "Hidden/BrightPassFilter2"
{
Properties
{
_MainTex ("Base (RGB)", 2D) = "" {}
}
CGINCLUDE
#include "UnityCG.cginc"
struct v2f
{
float4 pos : SV_POSITION;
float2 uv : TEXCOORD0;
};
sampler2D _MainTex;
half4 _MainTex_ST;
half4 _Threshhold;
v2f vert( appdata_img v )
{
v2f o;
o.pos = UnityObjectToClipPos(v.vertex);
o.uv = UnityStereoScreenSpaceUVAdjust(v.texcoord.xy, _MainTex_ST);
return o;
}
half4 fragScalarThresh(v2f i) : SV_Target
{
half4 color = tex2D(_MainTex, i.uv);
color.rgb = color.rgb;
color.rgb = max(half3(0,0,0), color.rgb-_Threshhold.xxx);
return color;
}
half4 fragColorThresh(v2f i) : SV_Target
{
half4 color = tex2D(_MainTex, i.uv);
color.rgb = max(half3(0,0,0), color.rgb-_Threshhold.rgb);
return color;
}
ENDCG
Subshader
{
Pass
{
ZTest Always Cull Off ZWrite Off
CGPROGRAM
#pragma vertex vert
#pragma fragment fragScalarThresh
ENDCG
}
Pass
{
ZTest Always Cull Off ZWrite Off
CGPROGRAM
#pragma vertex vert
#pragma fragment fragColorThresh
ENDCG
}
}
Fallback off
}

View File

@@ -0,0 +1,4 @@
fileFormatVersion: 2
guid: 0aeaa4cb29f5d4e9c8455f04c8575c8c
ShaderImporter:
userData:

View File

@@ -0,0 +1,61 @@
Shader "Hidden/LensFlareCreate" {
Properties {
_MainTex ("Base (RGB)", 2D) = "" {}
}
CGINCLUDE
#include "UnityCG.cginc"
struct v2f {
float4 pos : SV_POSITION;
float2 uv[4] : TEXCOORD0;
};
fixed4 colorA;
fixed4 colorB;
fixed4 colorC;
fixed4 colorD;
sampler2D _MainTex;
half4 _MainTex_ST;
v2f vert( appdata_img v ) {
v2f o;
o.pos = UnityObjectToClipPos(v.vertex);
o.uv[0] = UnityStereoScreenSpaceUVAdjust(( ( v.texcoord.xy - 0.5 ) * -0.85 ) + 0.5, _MainTex_ST);
o.uv[1] = UnityStereoScreenSpaceUVAdjust(( ( v.texcoord.xy - 0.5 ) * -1.45 ) + 0.5, _MainTex_ST);
o.uv[2] = UnityStereoScreenSpaceUVAdjust(( ( v.texcoord.xy - 0.5 ) * -2.55 ) + 0.5, _MainTex_ST);
o.uv[3] = UnityStereoScreenSpaceUVAdjust(( ( v.texcoord.xy - 0.5 ) * -4.15 ) + 0.5, _MainTex_ST);
return o;
}
fixed4 frag(v2f i) : SV_Target {
fixed4 color = float4 (0,0,0,0);
color += tex2D(_MainTex, i.uv[0] ) * colorA;
color += tex2D(_MainTex, i.uv[1] ) * colorB;
color += tex2D(_MainTex, i.uv[2] ) * colorC;
color += tex2D(_MainTex, i.uv[3] ) * colorD;
return color;
}
ENDCG
Subshader {
Blend One One
Pass {
ZTest Always Cull Off ZWrite Off
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
ENDCG
}
}
Fallback off
} // shader

View File

@@ -0,0 +1,4 @@
fileFormatVersion: 2
guid: 459fe69d2f6d74ddb92f04dbf45a866b
ShaderImporter:
userData:

View File

@@ -0,0 +1,287 @@
Shader "Hidden/FastBloom" {
Properties {
_MainTex ("Base (RGB)", 2D) = "white" {}
_Bloom ("Bloom (RGB)", 2D) = "black" {}
}
CGINCLUDE
#include "UnityCG.cginc"
sampler2D _MainTex;
sampler2D _Bloom;
uniform half4 _MainTex_TexelSize;
half4 _MainTex_ST;
uniform half4 _Parameter;
uniform half4 _OffsetsA;
uniform half4 _OffsetsB;
#define ONE_MINUS_THRESHHOLD_TIMES_INTENSITY _Parameter.w
#define THRESHHOLD _Parameter.z
struct v2f_simple
{
float4 pos : SV_POSITION;
half2 uv : TEXCOORD0;
#if UNITY_UV_STARTS_AT_TOP
half2 uv2 : TEXCOORD1;
#endif
};
v2f_simple vertBloom ( appdata_img v )
{
v2f_simple o;
o.pos = UnityObjectToClipPos(v.vertex);
o.uv = UnityStereoScreenSpaceUVAdjust(v.texcoord, _MainTex_ST);
#if UNITY_UV_STARTS_AT_TOP
o.uv2 = o.uv;
if (_MainTex_TexelSize.y < 0.0)
o.uv.y = 1.0 - o.uv.y;
#endif
return o;
}
struct v2f_tap
{
float4 pos : SV_POSITION;
half2 uv20 : TEXCOORD0;
half2 uv21 : TEXCOORD1;
half2 uv22 : TEXCOORD2;
half2 uv23 : TEXCOORD3;
};
v2f_tap vert4Tap ( appdata_img v )
{
v2f_tap o;
o.pos = UnityObjectToClipPos(v.vertex);
o.uv20 = UnityStereoScreenSpaceUVAdjust(v.texcoord + _MainTex_TexelSize.xy, _MainTex_ST);
o.uv21 = UnityStereoScreenSpaceUVAdjust(v.texcoord + _MainTex_TexelSize.xy * half2(-0.5h,-0.5h), _MainTex_ST);
o.uv22 = UnityStereoScreenSpaceUVAdjust(v.texcoord + _MainTex_TexelSize.xy * half2(0.5h,-0.5h), _MainTex_ST);
o.uv23 = UnityStereoScreenSpaceUVAdjust(v.texcoord + _MainTex_TexelSize.xy * half2(-0.5h,0.5h), _MainTex_ST);
return o;
}
fixed4 fragBloom ( v2f_simple i ) : SV_Target
{
#if UNITY_UV_STARTS_AT_TOP
fixed4 color = tex2D(_MainTex, i.uv2);
return color + tex2D(_Bloom, i.uv);
#else
fixed4 color = tex2D(_MainTex, i.uv);
return color + tex2D(_Bloom, i.uv);
#endif
}
fixed4 fragDownsample ( v2f_tap i ) : SV_Target
{
fixed4 color = tex2D (_MainTex, i.uv20);
color += tex2D (_MainTex, i.uv21);
color += tex2D (_MainTex, i.uv22);
color += tex2D (_MainTex, i.uv23);
return max(color/4 - THRESHHOLD, 0) * ONE_MINUS_THRESHHOLD_TIMES_INTENSITY;
}
// weight curves
static const half curve[7] = { 0.0205, 0.0855, 0.232, 0.324, 0.232, 0.0855, 0.0205 }; // gauss'ish blur weights
static const half4 curve4[7] = { half4(0.0205,0.0205,0.0205,0), half4(0.0855,0.0855,0.0855,0), half4(0.232,0.232,0.232,0),
half4(0.324,0.324,0.324,1), half4(0.232,0.232,0.232,0), half4(0.0855,0.0855,0.0855,0), half4(0.0205,0.0205,0.0205,0) };
struct v2f_withBlurCoords8
{
float4 pos : SV_POSITION;
half4 uv : TEXCOORD0;
half2 offs : TEXCOORD1;
};
struct v2f_withBlurCoordsSGX
{
float4 pos : SV_POSITION;
half2 uv : TEXCOORD0;
half4 offs[3] : TEXCOORD1;
};
v2f_withBlurCoords8 vertBlurHorizontal (appdata_img v)
{
v2f_withBlurCoords8 o;
o.pos = UnityObjectToClipPos(v.vertex);
o.uv = half4(v.texcoord.xy,1,1);
o.offs = _MainTex_TexelSize.xy * half2(1.0, 0.0) * _Parameter.x;
return o;
}
v2f_withBlurCoords8 vertBlurVertical (appdata_img v)
{
v2f_withBlurCoords8 o;
o.pos = UnityObjectToClipPos(v.vertex);
o.uv = half4(v.texcoord.xy,1,1);
o.offs = _MainTex_TexelSize.xy * half2(0.0, 1.0) * _Parameter.x;
return o;
}
half4 fragBlur8 ( v2f_withBlurCoords8 i ) : SV_Target
{
half2 uv = i.uv.xy;
half2 netFilterWidth = i.offs;
half2 coords = uv - netFilterWidth * 3.0;
half4 color = 0;
for( int l = 0; l < 7; l++ )
{
half4 tap = tex2D(_MainTex, UnityStereoScreenSpaceUVAdjust(coords, _MainTex_ST));
color += tap * curve4[l];
coords += netFilterWidth;
}
return color;
}
v2f_withBlurCoordsSGX vertBlurHorizontalSGX (appdata_img v)
{
v2f_withBlurCoordsSGX o;
o.pos = UnityObjectToClipPos(v.vertex);
o.uv = v.texcoord.xy;
half offsetMagnitude = _MainTex_TexelSize.x * _Parameter.x;
o.offs[0] = v.texcoord.xyxy + offsetMagnitude * half4(-3.0h, 0.0h, 3.0h, 0.0h);
o.offs[1] = v.texcoord.xyxy + offsetMagnitude * half4(-2.0h, 0.0h, 2.0h, 0.0h);
o.offs[2] = v.texcoord.xyxy + offsetMagnitude * half4(-1.0h, 0.0h, 1.0h, 0.0h);
return o;
}
v2f_withBlurCoordsSGX vertBlurVerticalSGX (appdata_img v)
{
v2f_withBlurCoordsSGX o;
o.pos = UnityObjectToClipPos(v.vertex);
o.uv = half4(v.texcoord.xy,1,1);
half offsetMagnitude = _MainTex_TexelSize.y * _Parameter.x;
o.offs[0] = v.texcoord.xyxy + offsetMagnitude * half4(0.0h, -3.0h, 0.0h, 3.0h);
o.offs[1] = v.texcoord.xyxy + offsetMagnitude * half4(0.0h, -2.0h, 0.0h, 2.0h);
o.offs[2] = v.texcoord.xyxy + offsetMagnitude * half4(0.0h, -1.0h, 0.0h, 1.0h);
return o;
}
half4 fragBlurSGX ( v2f_withBlurCoordsSGX i ) : SV_Target
{
half2 uv = i.uv.xy;
half4 color = tex2D(_MainTex, UnityStereoScreenSpaceUVAdjust(i.uv, _MainTex_ST)) * curve4[3];
for( int l = 0; l < 3; l++ )
{
half4 tapA = tex2D(_MainTex, UnityStereoScreenSpaceUVAdjust(i.offs[l].xy, _MainTex_ST));
half4 tapB = tex2D(_MainTex, UnityStereoScreenSpaceUVAdjust(i.offs[l].zw, _MainTex_ST));
color += (tapA + tapB) * curve4[l];
}
return color;
}
ENDCG
SubShader {
ZTest Off Cull Off ZWrite Off Blend Off
// 0
Pass {
CGPROGRAM
#pragma vertex vertBloom
#pragma fragment fragBloom
ENDCG
}
// 1
Pass {
CGPROGRAM
#pragma vertex vert4Tap
#pragma fragment fragDownsample
ENDCG
}
// 2
Pass {
ZTest Always
Cull Off
CGPROGRAM
#pragma vertex vertBlurVertical
#pragma fragment fragBlur8
ENDCG
}
// 3
Pass {
ZTest Always
Cull Off
CGPROGRAM
#pragma vertex vertBlurHorizontal
#pragma fragment fragBlur8
ENDCG
}
// alternate blur
// 4
Pass {
ZTest Always
Cull Off
CGPROGRAM
#pragma vertex vertBlurVerticalSGX
#pragma fragment fragBlurSGX
ENDCG
}
// 5
Pass {
ZTest Always
Cull Off
CGPROGRAM
#pragma vertex vertBlurHorizontalSGX
#pragma fragment fragBlurSGX
ENDCG
}
}
FallBack Off
}

View File

@@ -0,0 +1,4 @@
fileFormatVersion: 2
guid: 68a00c837b82e4c6d92e7da765dc5f1d
ShaderImporter:
userData:

View File

@@ -0,0 +1,234 @@
Shader "Hidden/FastBlur" {
Properties {
_MainTex ("Base (RGB)", 2D) = "white" {}
_Bloom ("Bloom (RGB)", 2D) = "black" {}
}
CGINCLUDE
#include "UnityCG.cginc"
sampler2D _MainTex;
sampler2D _Bloom;
uniform half4 _MainTex_TexelSize;
half4 _MainTex_ST;
half4 _Bloom_ST;
uniform half4 _Parameter;
struct v2f_tap
{
float4 pos : SV_POSITION;
half2 uv20 : TEXCOORD0;
half2 uv21 : TEXCOORD1;
half2 uv22 : TEXCOORD2;
half2 uv23 : TEXCOORD3;
};
v2f_tap vert4Tap ( appdata_img v )
{
v2f_tap o;
o.pos = UnityObjectToClipPos(v.vertex);
o.uv20 = UnityStereoScreenSpaceUVAdjust(v.texcoord + _MainTex_TexelSize.xy, _MainTex_ST);
o.uv21 = UnityStereoScreenSpaceUVAdjust(v.texcoord + _MainTex_TexelSize.xy * half2(-0.5h,-0.5h), _MainTex_ST);
o.uv22 = UnityStereoScreenSpaceUVAdjust(v.texcoord + _MainTex_TexelSize.xy * half2(0.5h,-0.5h), _MainTex_ST);
o.uv23 = UnityStereoScreenSpaceUVAdjust(v.texcoord + _MainTex_TexelSize.xy * half2(-0.5h,0.5h), _MainTex_ST);
return o;
}
fixed4 fragDownsample ( v2f_tap i ) : SV_Target
{
fixed4 color = tex2D (_MainTex, i.uv20);
color += tex2D (_MainTex, i.uv21);
color += tex2D (_MainTex, i.uv22);
color += tex2D (_MainTex, i.uv23);
return color / 4;
}
// weight curves
static const half curve[7] = { 0.0205, 0.0855, 0.232, 0.324, 0.232, 0.0855, 0.0205 }; // gauss'ish blur weights
static const half4 curve4[7] = { half4(0.0205,0.0205,0.0205,0), half4(0.0855,0.0855,0.0855,0), half4(0.232,0.232,0.232,0),
half4(0.324,0.324,0.324,1), half4(0.232,0.232,0.232,0), half4(0.0855,0.0855,0.0855,0), half4(0.0205,0.0205,0.0205,0) };
struct v2f_withBlurCoords8
{
float4 pos : SV_POSITION;
half4 uv : TEXCOORD0;
half2 offs : TEXCOORD1;
};
struct v2f_withBlurCoordsSGX
{
float4 pos : SV_POSITION;
half2 uv : TEXCOORD0;
half4 offs[3] : TEXCOORD1;
};
v2f_withBlurCoords8 vertBlurHorizontal (appdata_img v)
{
v2f_withBlurCoords8 o;
o.pos = UnityObjectToClipPos(v.vertex);
o.uv = half4(v.texcoord.xy,1,1);
o.offs = _MainTex_TexelSize.xy * half2(1.0, 0.0) * _Parameter.x;
return o;
}
v2f_withBlurCoords8 vertBlurVertical (appdata_img v)
{
v2f_withBlurCoords8 o;
o.pos = UnityObjectToClipPos(v.vertex);
o.uv = half4(v.texcoord.xy,1,1);
o.offs = _MainTex_TexelSize.xy * half2(0.0, 1.0) * _Parameter.x;
return o;
}
half4 fragBlur8 ( v2f_withBlurCoords8 i ) : SV_Target
{
half2 uv = i.uv.xy;
half2 netFilterWidth = i.offs;
half2 coords = uv - netFilterWidth * 3.0;
half4 color = 0;
for( int l = 0; l < 7; l++ )
{
half4 tap = tex2D(_MainTex, UnityStereoScreenSpaceUVAdjust(coords, _MainTex_ST));
color += tap * curve4[l];
coords += netFilterWidth;
}
return color;
}
v2f_withBlurCoordsSGX vertBlurHorizontalSGX (appdata_img v)
{
v2f_withBlurCoordsSGX o;
o.pos = UnityObjectToClipPos(v.vertex);
o.uv = UnityStereoScreenSpaceUVAdjust(v.texcoord.xy, _MainTex_ST);
half offsetMagnitude = _MainTex_TexelSize.x * _Parameter.x;
o.offs[0] = UnityStereoScreenSpaceUVAdjust(v.texcoord.xyxy + offsetMagnitude * half4(-3.0h, 0.0h, 3.0h, 0.0h), _MainTex_ST);
o.offs[1] = UnityStereoScreenSpaceUVAdjust(v.texcoord.xyxy + offsetMagnitude * half4(-2.0h, 0.0h, 2.0h, 0.0h), _MainTex_ST);
o.offs[2] = UnityStereoScreenSpaceUVAdjust(v.texcoord.xyxy + offsetMagnitude * half4(-1.0h, 0.0h, 1.0h, 0.0h), _MainTex_ST);
return o;
}
v2f_withBlurCoordsSGX vertBlurVerticalSGX (appdata_img v)
{
v2f_withBlurCoordsSGX o;
o.pos = UnityObjectToClipPos(v.vertex);
o.uv = half4(UnityStereoScreenSpaceUVAdjust(v.texcoord.xy, _MainTex_ST),1,1);
half offsetMagnitude = _MainTex_TexelSize.y * _Parameter.x;
o.offs[0] = UnityStereoScreenSpaceUVAdjust(v.texcoord.xyxy + offsetMagnitude * half4(0.0h, -3.0h, 0.0h, 3.0h), _MainTex_ST);
o.offs[1] = UnityStereoScreenSpaceUVAdjust(v.texcoord.xyxy + offsetMagnitude * half4(0.0h, -2.0h, 0.0h, 2.0h), _MainTex_ST);
o.offs[2] = UnityStereoScreenSpaceUVAdjust(v.texcoord.xyxy + offsetMagnitude * half4(0.0h, -1.0h, 0.0h, 1.0h), _MainTex_ST);
return o;
}
half4 fragBlurSGX ( v2f_withBlurCoordsSGX i ) : SV_Target
{
half2 uv = i.uv.xy;
half4 color = tex2D(_MainTex, i.uv) * curve4[3];
for( int l = 0; l < 3; l++ )
{
half4 tapA = tex2D(_MainTex, i.offs[l].xy);
half4 tapB = tex2D(_MainTex, i.offs[l].zw);
color += (tapA + tapB) * curve4[l];
}
return color;
}
ENDCG
SubShader {
ZTest Off Cull Off ZWrite Off Blend Off
// 0
Pass {
CGPROGRAM
#pragma vertex vert4Tap
#pragma fragment fragDownsample
ENDCG
}
// 1
Pass {
ZTest Always
Cull Off
CGPROGRAM
#pragma vertex vertBlurVertical
#pragma fragment fragBlur8
ENDCG
}
// 2
Pass {
ZTest Always
Cull Off
CGPROGRAM
#pragma vertex vertBlurHorizontal
#pragma fragment fragBlur8
ENDCG
}
// alternate blur
// 3
Pass {
ZTest Always
Cull Off
CGPROGRAM
#pragma vertex vertBlurVerticalSGX
#pragma fragment fragBlurSGX
ENDCG
}
// 4
Pass {
ZTest Always
Cull Off
CGPROGRAM
#pragma vertex vertBlurHorizontalSGX
#pragma fragment fragBlurSGX
ENDCG
}
}
FallBack Off
}

View File

@@ -0,0 +1,4 @@
fileFormatVersion: 2
guid: f9d5fa183cd6b45eeb1491f74863cd91
ShaderImporter:
userData:

View File

@@ -0,0 +1,155 @@
Shader "Hidden/MultipassHollywoodFlares" {
Properties {
_MainTex ("Base (RGB)", 2D) = "" {}
_NonBlurredTex ("Base (RGB)", 2D) = "" {}
}
CGINCLUDE
#include "UnityCG.cginc"
struct v2f {
half4 pos : SV_POSITION;
half2 uv : TEXCOORD0;
};
struct v2f_opts {
half4 pos : SV_POSITION;
half2 uv[7] : TEXCOORD0;
};
half4 offsets;
half4 tintColor;
half stretchWidth;
half2 _Threshhold;
half4 _MainTex_TexelSize;
half4 _MainTex_ST;
sampler2D _MainTex;
sampler2D _NonBlurredTex;
v2f vert (appdata_img v) {
v2f o;
o.pos = UnityObjectToClipPos(v.vertex);
o.uv = v.texcoord.xy;
return o;
}
v2f_opts vertStretch (appdata_img v) {
v2f_opts o;
o.pos = UnityObjectToClipPos(v.vertex);
half b = stretchWidth;
o.uv[0] = UnityStereoScreenSpaceUVAdjust(v.texcoord.xy, _MainTex_ST);
o.uv[1] = UnityStereoScreenSpaceUVAdjust(v.texcoord.xy + b * 2.0 * offsets.xy, _MainTex_ST);
o.uv[2] = UnityStereoScreenSpaceUVAdjust(v.texcoord.xy - b * 2.0 * offsets.xy, _MainTex_ST);
o.uv[3] = UnityStereoScreenSpaceUVAdjust(v.texcoord.xy + b * 4.0 * offsets.xy, _MainTex_ST);
o.uv[4] = UnityStereoScreenSpaceUVAdjust(v.texcoord.xy - b * 4.0 * offsets.xy, _MainTex_ST);
o.uv[5] = UnityStereoScreenSpaceUVAdjust(v.texcoord.xy + b * 6.0 * offsets.xy, _MainTex_ST);
o.uv[6] = UnityStereoScreenSpaceUVAdjust(v.texcoord.xy - b * 6.0 * offsets.xy, _MainTex_ST);
return o;
}
v2f_opts vertVerticalCoords (appdata_img v) {
v2f_opts o;
o.pos = UnityObjectToClipPos(v.vertex);
o.uv[0] = UnityStereoScreenSpaceUVAdjust(v.texcoord.xy, _MainTex_ST);
o.uv[1] = UnityStereoScreenSpaceUVAdjust(v.texcoord.xy + 0.5 * _MainTex_TexelSize.xy * half2(0,1), _MainTex_ST);
o.uv[2] = UnityStereoScreenSpaceUVAdjust(v.texcoord.xy - 0.5 * _MainTex_TexelSize.xy * half2(0,1), _MainTex_ST);
o.uv[3] = UnityStereoScreenSpaceUVAdjust(v.texcoord.xy + 1.5 * _MainTex_TexelSize.xy * half2(0,1), _MainTex_ST);
o.uv[4] = UnityStereoScreenSpaceUVAdjust(v.texcoord.xy - 1.5 * _MainTex_TexelSize.xy * half2(0,1), _MainTex_ST);
o.uv[5] = UnityStereoScreenSpaceUVAdjust(v.texcoord.xy + 2.5 * _MainTex_TexelSize.xy * half2(0,1), _MainTex_ST);
o.uv[6] = UnityStereoScreenSpaceUVAdjust(v.texcoord.xy - 2.5 * _MainTex_TexelSize.xy * half2(0,1), _MainTex_ST);
return o;
}
// deprecated
half4 fragPrepare (v2f i) : SV_Target {
half4 color = tex2D (_MainTex, i.uv);
half4 colorNb = tex2D (_NonBlurredTex, i.uv);
return color * tintColor * 0.5 + colorNb * normalize (tintColor) * 0.5;
}
half4 fragPreAndCut (v2f_opts i) : SV_Target {
half4 color = tex2D (_MainTex, i.uv[0]);
color += tex2D (_MainTex, i.uv[1]);
color += tex2D (_MainTex, i.uv[2]);
color += tex2D (_MainTex, i.uv[3]);
color += tex2D (_MainTex, i.uv[4]);
color += tex2D (_MainTex, i.uv[5]);
color += tex2D (_MainTex, i.uv[6]);
return max(color / 7.0 - _Threshhold.x, 0.0) * _Threshhold.y * tintColor;
}
half4 fragStretch (v2f_opts i) : SV_Target {
half4 color = tex2D (_MainTex, i.uv[0]);
color = max (color, tex2D (_MainTex, i.uv[1]));
color = max (color, tex2D (_MainTex, i.uv[2]));
color = max (color, tex2D (_MainTex, i.uv[3]));
color = max (color, tex2D (_MainTex, i.uv[4]));
color = max (color, tex2D (_MainTex, i.uv[5]));
color = max (color, tex2D (_MainTex, i.uv[6]));
return color;
}
half4 fragPost (v2f_opts i) : SV_Target {
half4 color = tex2D (_MainTex, i.uv[0]);
color += tex2D (_MainTex, i.uv[1]);
color += tex2D (_MainTex, i.uv[2]);
color += tex2D (_MainTex, i.uv[3]);
color += tex2D (_MainTex, i.uv[4]);
color += tex2D (_MainTex, i.uv[5]);
color += tex2D (_MainTex, i.uv[6]);
return color * 1.0/(7.0 + Luminance(color.rgb) + 0.5); // this also makes it a little noisy
}
ENDCG
Subshader {
ZTest Always Cull Off ZWrite Off
Pass {
CGPROGRAM
#pragma vertex vert
#pragma fragment fragPrepare
ENDCG
}
Pass {
CGPROGRAM
#pragma vertex vertStretch
#pragma fragment fragStretch
ENDCG
}
Pass {
CGPROGRAM
#pragma vertex vertVerticalCoords
#pragma fragment fragPreAndCut
ENDCG
}
Pass {
CGPROGRAM
#pragma vertex vertVerticalCoords
#pragma fragment fragPost
ENDCG
}
}
Fallback off
}

View File

@@ -0,0 +1,4 @@
fileFormatVersion: 2
guid: e2baf3cae8edc4daf94c9adc2154be00
ShaderImporter:
userData:

View File

@@ -0,0 +1,70 @@
Shader "Hidden/SeparableBlurPlus" {
Properties {
_MainTex ("Base (RGB)", 2D) = "" {}
}
CGINCLUDE
#include "UnityCG.cginc"
struct v2f {
half4 pos : SV_POSITION;
half2 uv : TEXCOORD0;
half4 uv01 : TEXCOORD1;
half4 uv23 : TEXCOORD2;
half4 uv45 : TEXCOORD3;
half4 uv67 : TEXCOORD4;
};
half4 offsets;
sampler2D _MainTex;
half4 _MainTex_ST;
v2f vert (appdata_img v) {
v2f o;
o.pos = UnityObjectToClipPos(v.vertex);
o.uv.xy = v.texcoord.xy;
o.uv01 = v.texcoord.xyxy + offsets.xyxy * half4(1,1, -1,-1);
o.uv23 = v.texcoord.xyxy + offsets.xyxy * half4(1,1, -1,-1) * 2.0;
o.uv45 = v.texcoord.xyxy + offsets.xyxy * half4(1,1, -1,-1) * 3.0;
o.uv67 = v.texcoord.xyxy + offsets.xyxy * half4(1,1, -1,-1) * 4.5;
o.uv67 = v.texcoord.xyxy + offsets.xyxy * half4(1,1, -1,-1) * 6.5;
return o;
}
half4 frag (v2f i) : SV_Target {
half4 color = half4 (0,0,0,0);
color += 0.225 * tex2D(_MainTex, UnityStereoScreenSpaceUVAdjust(i.uv, _MainTex_ST));
color += 0.150 * tex2D(_MainTex, UnityStereoScreenSpaceUVAdjust(i.uv01.xy, _MainTex_ST));
color += 0.150 * tex2D(_MainTex, UnityStereoScreenSpaceUVAdjust(i.uv01.zw, _MainTex_ST));
color += 0.110 * tex2D(_MainTex, UnityStereoScreenSpaceUVAdjust(i.uv23.xy, _MainTex_ST));
color += 0.110 * tex2D(_MainTex, UnityStereoScreenSpaceUVAdjust(i.uv23.zw, _MainTex_ST));
color += 0.075 * tex2D(_MainTex, UnityStereoScreenSpaceUVAdjust(i.uv45.xy, _MainTex_ST));
color += 0.075 * tex2D(_MainTex, UnityStereoScreenSpaceUVAdjust(i.uv45.zw, _MainTex_ST));
color += 0.0525 * tex2D(_MainTex, UnityStereoScreenSpaceUVAdjust(i.uv67.xy, _MainTex_ST));
color += 0.0525 * tex2D(_MainTex, UnityStereoScreenSpaceUVAdjust(i.uv67.zw, _MainTex_ST));
return color;
}
ENDCG
Subshader {
Pass {
ZTest Always Cull Off ZWrite Off
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
ENDCG
}
}
Fallback off
} // shader

View File

@@ -0,0 +1,4 @@
fileFormatVersion: 2
guid: a9df009a214e24a5ebbf271595f8d5b6
ShaderImporter:
userData:

View File

@@ -0,0 +1,57 @@
Shader "Hidden/VignetteShader" {
Properties {
_MainTex ("Base (RGB)", 2D) = "" {}
}
CGINCLUDE
#include "UnityCG.cginc"
struct v2f {
float4 pos : SV_POSITION;
float2 uv : TEXCOORD0;
};
sampler2D _MainTex;
float4 _MainTex_TexelSize;
float vignetteIntensity;
v2f vert( appdata_img v ) {
v2f o;
o.pos = UnityObjectToClipPos(v.vertex);
o.uv = v.texcoord.xy;
return o;
}
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);
half4 color = tex2D (_MainTex, uv);
float mask = 1.0 - coordDot * vignetteIntensity;
return color * mask;
}
ENDCG
Subshader {
Pass {
ZTest Always Cull Off ZWrite Off
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
ENDCG
}
}
Fallback off
} // shader

View File

@@ -0,0 +1,4 @@
fileFormatVersion: 2
guid: 562f620336e024ac99992ff05725a89a
ShaderImporter:
userData:

View File

@@ -0,0 +1,6 @@
fileFormatVersion: 2
guid: f9372f23586ef470b97d53856af88487
folderAsset: yes
DefaultImporter:
userData:
assetBundleName:

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.9 KiB

View File

@@ -0,0 +1,35 @@
fileFormatVersion: 2
guid: ecd9a2c463dcb476891e43d7c9f16ffa
TextureImporter:
serializedVersion: 2
mipmaps:
mipMapMode: 0
enableMipMap: 0
linearTexture: 0
correctGamma: 0
fadeOut: 0
borderMipMap: 0
mipMapFadeDistanceStart: 1
mipMapFadeDistanceEnd: 3
bumpmap:
convertToNormalMap: 0
externalNormalMap: 0
heightScale: .25
normalMapFilter: 0
isReadable: 1
grayScaleToAlpha: 0
generateCubemap: 0
seamlessCubemap: 0
textureFormat: -3
maxTextureSize: 2048
textureSettings:
filterMode: -1
aniso: -1
mipBias: -1
wrapMode: -1
nPOTScale: 1
lightmap: 0
compressionQuality: 50
textureType: 5
buildTargetSettings: []
userData:

View File

@@ -0,0 +1,35 @@
fileFormatVersion: 2
guid: a4cdca73d61814d33ac1587f6c163bca
TextureImporter:
serializedVersion: 2
mipmaps:
mipMapMode: 0
enableMipMap: 1
linearTexture: 0
correctGamma: 0
fadeOut: 0
borderMipMap: 0
mipMapFadeDistanceStart: 1
mipMapFadeDistanceEnd: 3
bumpmap:
convertToNormalMap: 0
externalNormalMap: 0
heightScale: .25
normalMapFilter: 0
isReadable: 0
grayScaleToAlpha: 0
generateCubemap: 0
seamlessCubemap: 0
textureFormat: -1
maxTextureSize: 64
textureSettings:
filterMode: -1
aniso: -1
mipBias: -1
wrapMode: 1
nPOTScale: 1
lightmap: 0
compressionQuality: 50
textureType: -1
buildTargetSettings: []
userData:

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

View File

@@ -0,0 +1,35 @@
fileFormatVersion: 2
guid: 31f5a8611c4ed1245b18456206e798dc
TextureImporter:
serializedVersion: 2
mipmaps:
mipMapMode: 0
enableMipMap: 0
linearTexture: 0
correctGamma: 0
fadeOut: 0
borderMipMap: 0
mipMapFadeDistanceStart: 2
mipMapFadeDistanceEnd: 3
bumpmap:
convertToNormalMap: 0
externalNormalMap: 0
heightScale: .25
normalMapFilter: 0
isReadable: 0
grayScaleToAlpha: 0
generateCubemap: 0
seamlessCubemap: 0
textureFormat: 3
maxTextureSize: 1024
textureSettings:
filterMode: 1
aniso: 1
mipBias: -1
wrapMode: 0
nPOTScale: 0
lightmap: 0
compressionQuality: 50
textureType: -1
buildTargetSettings: []
userData:

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 KiB

View File

@@ -0,0 +1,35 @@
fileFormatVersion: 2
guid: a4b474cd484494a4aaa4bbf928219d09
TextureImporter:
serializedVersion: 2
mipmaps:
mipMapMode: 0
enableMipMap: 0
linearTexture: 0
correctGamma: 0
fadeOut: 0
borderMipMap: 0
mipMapFadeDistanceStart: 1
mipMapFadeDistanceEnd: 3
bumpmap:
convertToNormalMap: 0
externalNormalMap: 0
heightScale: .25
normalMapFilter: 0
isReadable: 1
grayScaleToAlpha: 0
generateCubemap: 0
seamlessCubemap: 0
textureFormat: -3
maxTextureSize: 2048
textureSettings:
filterMode: -1
aniso: -1
mipBias: -1
wrapMode: -1
nPOTScale: 1
lightmap: 0
compressionQuality: 50
textureType: 5
buildTargetSettings: []
userData:

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

View File

@@ -0,0 +1,35 @@
fileFormatVersion: 2
guid: e80c3c84ea861404d8a427db8b7abf04
TextureImporter:
serializedVersion: 2
mipmaps:
mipMapMode: 0
enableMipMap: 0
linearTexture: 0
correctGamma: 0
fadeOut: 0
borderMipMap: 0
mipMapFadeDistanceStart: 2
mipMapFadeDistanceEnd: 3
bumpmap:
convertToNormalMap: 0
externalNormalMap: 0
heightScale: .25
normalMapFilter: 0
isReadable: 0
grayScaleToAlpha: 0
generateCubemap: 0
seamlessCubemap: 0
textureFormat: 3
maxTextureSize: 64
textureSettings:
filterMode: 2
aniso: 1
mipBias: -1
wrapMode: 0
nPOTScale: 0
lightmap: 0
compressionQuality: 50
textureType: -1
buildTargetSettings: []
userData:

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.9 KiB

View File

@@ -0,0 +1,35 @@
fileFormatVersion: 2
guid: 6205c27cc031f4e66b8ea90d1bfaa158
TextureImporter:
serializedVersion: 2
mipmaps:
mipMapMode: 0
enableMipMap: 1
linearTexture: 0
correctGamma: 0
fadeOut: 0
borderMipMap: 0
mipMapFadeDistanceStart: 2
mipMapFadeDistanceEnd: 3
bumpmap:
convertToNormalMap: 0
externalNormalMap: 0
heightScale: .25
normalMapFilter: 0
isReadable: 0
grayScaleToAlpha: 0
generateCubemap: 0
seamlessCubemap: 0
textureFormat: -1
maxTextureSize: 1024
textureSettings:
filterMode: 1
aniso: 1
mipBias: 0
wrapMode: 0
nPOTScale: 1
lightmap: 0
compressionQuality: 50
textureType: 0
buildTargetSettings: []
userData:

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

View File

@@ -0,0 +1,35 @@
fileFormatVersion: 2
guid: a181ca8e3c62f3e4b8f183f6c586b032
TextureImporter:
serializedVersion: 2
mipmaps:
mipMapMode: 0
enableMipMap: 0
linearTexture: 0
correctGamma: 0
fadeOut: 0
borderMipMap: 0
mipMapFadeDistanceStart: 2
mipMapFadeDistanceEnd: 3
bumpmap:
convertToNormalMap: 0
externalNormalMap: 0
heightScale: .25
normalMapFilter: 0
isReadable: 0
grayScaleToAlpha: 0
generateCubemap: 0
seamlessCubemap: 0
textureFormat: 3
maxTextureSize: 1024
textureSettings:
filterMode: 0
aniso: 1
mipBias: -1
wrapMode: 0
nPOTScale: 0
lightmap: 0
compressionQuality: 50
textureType: -1
buildTargetSettings: []
userData:

View File

@@ -0,0 +1,35 @@
fileFormatVersion: 2
guid: fc00ec05a89da4ff695a4273715cd5ce
TextureImporter:
serializedVersion: 2
mipmaps:
mipMapMode: 0
enableMipMap: 1
linearTexture: 0
correctGamma: 0
fadeOut: 0
borderMipMap: 0
mipMapFadeDistanceStart: 1
mipMapFadeDistanceEnd: 3
bumpmap:
convertToNormalMap: 0
externalNormalMap: 0
heightScale: .25
normalMapFilter: 0
isReadable: 0
grayScaleToAlpha: 0
generateCubemap: 0
seamlessCubemap: 0
textureFormat: -1
maxTextureSize: 64
textureSettings:
filterMode: -1
aniso: -1
mipBias: -1
wrapMode: 1
nPOTScale: 1
lightmap: 0
compressionQuality: 50
textureType: -1
buildTargetSettings: []
userData:

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.2 KiB

View File

@@ -0,0 +1,35 @@
fileFormatVersion: 2
guid: 95ef4804fe0be4c999ddaa383536cde8
TextureImporter:
serializedVersion: 2
mipmaps:
mipMapMode: 0
enableMipMap: 1
linearTexture: 0
correctGamma: 0
fadeOut: 0
borderMipMap: 0
mipMapFadeDistanceStart: 1
mipMapFadeDistanceEnd: 3
bumpmap:
convertToNormalMap: 0
externalNormalMap: 0
heightScale: .25
normalMapFilter: 0
isReadable: 0
grayScaleToAlpha: 0
generateCubemap: 0
seamlessCubemap: 0
textureFormat: -1
maxTextureSize: 1024
textureSettings:
filterMode: 1
aniso: 1
mipBias: 0
wrapMode: 1
nPOTScale: 1
lightmap: 0
compressionQuality: 50
textureType: -1
buildTargetSettings: []
userData:

Binary file not shown.

After

Width:  |  Height:  |  Size: 77 B

View File

@@ -0,0 +1,35 @@
fileFormatVersion: 2
guid: d440902fad11e807d00044888d76c639
TextureImporter:
serializedVersion: 2
mipmaps:
mipMapMode: 0
enableMipMap: 0
linearTexture: 1
correctGamma: 0
fadeOut: 0
borderMipMap: 0
mipMapFadeDistanceStart: 2
mipMapFadeDistanceEnd: 3
bumpmap:
convertToNormalMap: 0
externalNormalMap: 0
heightScale: .25
normalMapFilter: 0
isReadable: 0
grayScaleToAlpha: 0
generateCubemap: 0
seamlessCubemap: 0
textureFormat: -3
maxTextureSize: 1024
textureSettings:
filterMode: 0
aniso: 1
mipBias: 0
wrapMode: 1
nPOTScale: 0
lightmap: 0
compressionQuality: 50
textureType: -1
buildTargetSettings: []
userData:

Binary file not shown.

After

Width:  |  Height:  |  Size: 77 B

View File

@@ -0,0 +1,35 @@
fileFormatVersion: 2
guid: e9a9781cad112c75d0008dfa8d76c639
TextureImporter:
serializedVersion: 2
mipmaps:
mipMapMode: 0
enableMipMap: 1
linearTexture: 0
correctGamma: 0
fadeOut: 0
borderMipMap: 0
mipMapFadeDistanceStart: 2
mipMapFadeDistanceEnd: 3
bumpmap:
convertToNormalMap: 0
externalNormalMap: 0
heightScale: .25
normalMapFilter: 0
isReadable: 0
grayScaleToAlpha: 0
generateCubemap: 0
seamlessCubemap: 0
textureFormat: 3
maxTextureSize: 1024
textureSettings:
filterMode: 1
aniso: 1
mipBias: 0
wrapMode: 1
nPOTScale: 0
lightmap: 0
compressionQuality: 50
textureType: -1
buildTargetSettings: []
userData: