mirror of
https://github.com/imperialsushi/gutterball-3.git
synced 2025-06-15 05:07:42 +00:00
New Version 1.6
New 125 balls & powerups. Improved graphics.
This commit is contained in:
parent
b35433ae45
commit
71779ef7ac
9413 changed files with 193360 additions and 264803 deletions
|
@ -0,0 +1,161 @@
|
|||
|
||||
#pragma strict
|
||||
|
||||
@script ExecuteInEditMode
|
||||
@script RequireComponent (Camera)
|
||||
@script AddComponentMenu ("Image Effects/Antialiasing (Fullscreen)")
|
||||
|
||||
enum AAMode {
|
||||
FXAA2 = 0,
|
||||
FXAA3Console = 1,
|
||||
FXAA1PresetA = 2,
|
||||
FXAA1PresetB = 3,
|
||||
NFAA = 4,
|
||||
SSAA = 5,
|
||||
DLAA = 6,
|
||||
}
|
||||
|
||||
class AntialiasingAsPostEffect extends PostEffectsBase {
|
||||
public var mode : AAMode = AAMode.FXAA3Console;
|
||||
|
||||
public var showGeneratedNormals : boolean = false;
|
||||
public var offsetScale : float = 0.2;
|
||||
public var blurRadius : float = 18.0;
|
||||
|
||||
public var edgeThresholdMin : float = 0.05f;
|
||||
public var edgeThreshold : float = 0.2f;
|
||||
public var edgeSharpness : float = 4.0f;
|
||||
|
||||
public var dlaaSharp : boolean = false;
|
||||
|
||||
public var ssaaShader : Shader;
|
||||
private var ssaa : Material;
|
||||
public var dlaaShader : Shader;
|
||||
private var dlaa : Material;
|
||||
public var nfaaShader : Shader;
|
||||
private var nfaa : Material;
|
||||
public var shaderFXAAPreset2 : Shader;
|
||||
private var materialFXAAPreset2 : Material;
|
||||
public var shaderFXAAPreset3 : Shader;
|
||||
private var materialFXAAPreset3 : Material;
|
||||
public var shaderFXAAII : Shader;
|
||||
private var materialFXAAII : Material;
|
||||
public var shaderFXAAIII : Shader;
|
||||
private var materialFXAAIII : Material;
|
||||
|
||||
function CurrentAAMaterial () : Material
|
||||
{
|
||||
var returnValue : Material = null;
|
||||
|
||||
switch(mode) {
|
||||
case AAMode.FXAA3Console:
|
||||
returnValue = materialFXAAIII;
|
||||
break;
|
||||
case AAMode.FXAA2:
|
||||
returnValue = materialFXAAII;
|
||||
break;
|
||||
case AAMode.FXAA1PresetA:
|
||||
returnValue = materialFXAAPreset2;
|
||||
break;
|
||||
case AAMode.FXAA1PresetB:
|
||||
returnValue = materialFXAAPreset3;
|
||||
break;
|
||||
case AAMode.NFAA:
|
||||
returnValue = nfaa;
|
||||
break;
|
||||
case AAMode.SSAA:
|
||||
returnValue = ssaa;
|
||||
break;
|
||||
case AAMode.DLAA:
|
||||
returnValue = dlaa;
|
||||
break;
|
||||
default:
|
||||
returnValue = null;
|
||||
break;
|
||||
}
|
||||
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
function CheckResources () {
|
||||
CheckSupport (false);
|
||||
|
||||
materialFXAAPreset2 = CreateMaterial (shaderFXAAPreset2, materialFXAAPreset2);
|
||||
materialFXAAPreset3 = CreateMaterial (shaderFXAAPreset3, materialFXAAPreset3);
|
||||
materialFXAAII = CreateMaterial (shaderFXAAII, materialFXAAII);
|
||||
materialFXAAIII = CreateMaterial (shaderFXAAIII, materialFXAAIII);
|
||||
nfaa = CreateMaterial (nfaaShader, nfaa);
|
||||
ssaa = CreateMaterial (ssaaShader, ssaa);
|
||||
dlaa = CreateMaterial (dlaaShader, dlaa);
|
||||
|
||||
if(!ssaaShader.isSupported) {
|
||||
NotSupported ();
|
||||
ReportAutoDisable ();
|
||||
}
|
||||
|
||||
return isSupported;
|
||||
}
|
||||
|
||||
function OnRenderImage (source : RenderTexture, destination : RenderTexture) {
|
||||
if(CheckResources()==false) {
|
||||
Graphics.Blit (source, destination);
|
||||
return;
|
||||
}
|
||||
|
||||
// .............................................................................
|
||||
// FXAA antialiasing modes .....................................................
|
||||
|
||||
if (mode == AAMode.FXAA3Console && (materialFXAAIII != null)) {
|
||||
materialFXAAIII.SetFloat("_EdgeThresholdMin", edgeThresholdMin);
|
||||
materialFXAAIII.SetFloat("_EdgeThreshold", edgeThreshold);
|
||||
materialFXAAIII.SetFloat("_EdgeSharpness", edgeSharpness);
|
||||
|
||||
Graphics.Blit (source, destination, materialFXAAIII);
|
||||
}
|
||||
else if (mode == AAMode.FXAA1PresetB && (materialFXAAPreset3 != null)) {
|
||||
Graphics.Blit (source, destination, materialFXAAPreset3);
|
||||
}
|
||||
else if(mode == AAMode.FXAA1PresetA && materialFXAAPreset2 != null) {
|
||||
source.anisoLevel = 4;
|
||||
Graphics.Blit (source, destination, materialFXAAPreset2);
|
||||
source.anisoLevel = 0;
|
||||
}
|
||||
else if(mode == AAMode.FXAA2 && materialFXAAII != null) {
|
||||
Graphics.Blit (source, destination, materialFXAAII);
|
||||
}
|
||||
else if (mode == AAMode.SSAA && ssaa != null) {
|
||||
|
||||
// .............................................................................
|
||||
// SSAA antialiasing ...........................................................
|
||||
|
||||
Graphics.Blit (source, destination, ssaa);
|
||||
}
|
||||
else if (mode == AAMode.DLAA && dlaa != null) {
|
||||
|
||||
// .............................................................................
|
||||
// DLAA antialiasing ...........................................................
|
||||
|
||||
source.anisoLevel = 0;
|
||||
var interim : RenderTexture = RenderTexture.GetTemporary (source.width, source.height);
|
||||
Graphics.Blit (source, interim, dlaa, 0);
|
||||
Graphics.Blit (interim, destination, dlaa, dlaaSharp ? 2 : 1);
|
||||
RenderTexture.ReleaseTemporary (interim);
|
||||
}
|
||||
else if (mode == AAMode.NFAA && nfaa != null) {
|
||||
|
||||
// .............................................................................
|
||||
// nfaa antialiasing ..............................................
|
||||
|
||||
source.anisoLevel = 0;
|
||||
|
||||
nfaa.SetFloat("_OffsetScale", offsetScale);
|
||||
nfaa.SetFloat("_BlurRadius", blurRadius);
|
||||
|
||||
Graphics.Blit (source, destination, nfaa, showGeneratedNormals ? 1 : 0);
|
||||
}
|
||||
else {
|
||||
// none of the AA is supported, fallback to a simple blit
|
||||
Graphics.Blit (source, destination);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 5625ff10b23e09d4c86012ffb66455c1
|
||||
TextScriptImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,259 @@
|
|||
|
||||
#pragma strict
|
||||
|
||||
@script ExecuteInEditMode
|
||||
@script RequireComponent (Camera)
|
||||
@script AddComponentMenu ("Image Effects/Bloom (HDR, Lens Flares)")
|
||||
|
||||
enum LensflareStyle34 {
|
||||
Ghosting = 0,
|
||||
Anamorphic = 1,
|
||||
Combined = 2,
|
||||
}
|
||||
|
||||
enum TweakMode34 {
|
||||
Basic = 0,
|
||||
Complex = 1,
|
||||
}
|
||||
|
||||
enum HDRBloomMode {
|
||||
Auto = 0,
|
||||
On = 1,
|
||||
Off = 2,
|
||||
}
|
||||
|
||||
enum BloomScreenBlendMode {
|
||||
Screen = 0,
|
||||
Add = 1,
|
||||
}
|
||||
|
||||
class BloomAndLensFlares extends PostEffectsBase {
|
||||
public var tweakMode : TweakMode34 = 0;
|
||||
public var screenBlendMode : BloomScreenBlendMode = BloomScreenBlendMode.Add;
|
||||
|
||||
public var hdr : HDRBloomMode = HDRBloomMode.Auto;
|
||||
private var doHdr : boolean = false;
|
||||
public var sepBlurSpread : float = 1.5f;
|
||||
public var useSrcAlphaAsMask : float = 0.5f;
|
||||
|
||||
public var bloomIntensity : float = 1.0f;
|
||||
public var bloomThreshhold : float = 0.5f;
|
||||
public var bloomBlurIterations : int = 2;
|
||||
|
||||
public var lensflares : boolean = false;
|
||||
public var hollywoodFlareBlurIterations : int = 2;
|
||||
public var lensflareMode : LensflareStyle34 = 1;
|
||||
public var hollyStretchWidth : float = 3.5f;
|
||||
public var lensflareIntensity : float = 1.0f;
|
||||
public var lensflareThreshhold : float = 0.3f;
|
||||
public var flareColorA : Color = Color (0.4f, 0.4f, 0.8f, 0.75f);
|
||||
public var flareColorB : Color = Color (0.4f, 0.8f, 0.8f, 0.75f);
|
||||
public var flareColorC : Color = Color (0.8f, 0.4f, 0.8f, 0.75f);
|
||||
public var flareColorD : Color = Color (0.8f, 0.4f, 0.0f, 0.75f);
|
||||
public var blurWidth : float = 1.0f;
|
||||
public var lensFlareVignetteMask : Texture2D;
|
||||
|
||||
public var lensFlareShader : Shader;
|
||||
private var lensFlareMaterial : Material;
|
||||
|
||||
public var vignetteShader : Shader;
|
||||
private var vignetteMaterial : Material;
|
||||
|
||||
public var separableBlurShader : Shader;
|
||||
private var separableBlurMaterial : Material;
|
||||
|
||||
public var addBrightStuffOneOneShader: Shader;
|
||||
private var addBrightStuffBlendOneOneMaterial : Material;
|
||||
|
||||
public var screenBlendShader : Shader;
|
||||
private var screenBlend : Material;
|
||||
|
||||
public var hollywoodFlaresShader: Shader;
|
||||
private var hollywoodFlaresMaterial : Material;
|
||||
|
||||
public var brightPassFilterShader : Shader;
|
||||
private var brightPassFilterMaterial : Material;
|
||||
|
||||
function CheckResources () : boolean {
|
||||
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;
|
||||
}
|
||||
|
||||
function OnRenderImage (source : RenderTexture, destination : RenderTexture) {
|
||||
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)
|
||||
doHdr = source.format == RenderTextureFormat.ARGBHalf && camera.hdr;
|
||||
else {
|
||||
doHdr = hdr == HDRBloomMode.On;
|
||||
}
|
||||
|
||||
doHdr = doHdr && supportHDRTextures;
|
||||
|
||||
var realBlendMode : BloomScreenBlendMode = screenBlendMode;
|
||||
if(doHdr)
|
||||
realBlendMode = BloomScreenBlendMode.Add;
|
||||
|
||||
var rtFormat = (doHdr) ? RenderTextureFormat.ARGBHalf : RenderTextureFormat.Default;
|
||||
var halfRezColor : RenderTexture = RenderTexture.GetTemporary (source.width / 2, source.height / 2, 0, rtFormat);
|
||||
var quarterRezColor : RenderTexture = RenderTexture.GetTemporary (source.width / 4, source.height / 4, 0, rtFormat);
|
||||
var secondQuarterRezColor : RenderTexture = RenderTexture.GetTemporary (source.width / 4, source.height / 4, 0, rtFormat);
|
||||
var thirdQuarterRezColor : RenderTexture = RenderTexture.GetTemporary (source.width / 4, source.height / 4, 0, rtFormat);
|
||||
|
||||
var widthOverHeight : float = (1.0f * source.width) / (1.0f * source.height);
|
||||
var oneOverBaseSize : float = 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 (threshholding)
|
||||
|
||||
BrightFilter (bloomThreshhold, useSrcAlphaAsMask, quarterRezColor, secondQuarterRezColor);
|
||||
|
||||
// blurring
|
||||
|
||||
if (bloomBlurIterations < 1) bloomBlurIterations = 1;
|
||||
|
||||
for (var iter : int = 0; iter < bloomBlurIterations; iter++ ) {
|
||||
var spreadForPass : float = (1.0f + (iter * 0.5f)) * sepBlurSpread;
|
||||
separableBlurMaterial.SetVector ("offsets", Vector4 (0.0f, spreadForPass * oneOverBaseSize, 0.0f, 0.0f));
|
||||
Graphics.Blit (iter == 0 ? secondQuarterRezColor : quarterRezColor, thirdQuarterRezColor, separableBlurMaterial);
|
||||
separableBlurMaterial.SetVector ("offsets", Vector4 ((spreadForPass / widthOverHeight) * oneOverBaseSize, 0.0f, 0.0f, 0.0f));
|
||||
Graphics.Blit (thirdQuarterRezColor, quarterRezColor, separableBlurMaterial);
|
||||
}
|
||||
|
||||
// lens flares: ghosting, anamorphic or a combination
|
||||
|
||||
if (lensflares) {
|
||||
|
||||
if (lensflareMode == 0) {
|
||||
|
||||
BrightFilter (lensflareThreshhold, 0.0f, quarterRezColor, thirdQuarterRezColor);
|
||||
|
||||
// smooth a little, this needs to be resolution dependent
|
||||
/*
|
||||
separableBlurMaterial.SetVector ("offsets", Vector4 (0.0f, (2.0f) / (1.0f * quarterRezColor.height), 0.0f, 0.0f));
|
||||
Graphics.Blit (thirdQuarterRezColor, secondQuarterRezColor, separableBlurMaterial);
|
||||
separableBlurMaterial.SetVector ("offsets", Vector4 ((2.0f) / (1.0f * quarterRezColor.width), 0.0f, 0.0f, 0.0f));
|
||||
Graphics.Blit (secondQuarterRezColor, thirdQuarterRezColor, separableBlurMaterial);
|
||||
*/
|
||||
// no ugly edges!
|
||||
|
||||
Vignette (0.975, thirdQuarterRezColor, secondQuarterRezColor);
|
||||
BlendFlares (secondQuarterRezColor, quarterRezColor);
|
||||
}
|
||||
|
||||
// (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 ("_Threshhold", Vector4 (lensflareThreshhold, 1.0f / (1.0f - lensflareThreshhold), 0.0f, 0.0f));
|
||||
hollywoodFlaresMaterial.SetVector ("tintColor", Vector4 (flareColorA.r, flareColorA.g, flareColorA.b, flareColorA.a) * flareColorA.a * lensflareIntensity);
|
||||
Graphics.Blit (thirdQuarterRezColor, secondQuarterRezColor, hollywoodFlaresMaterial, 2);
|
||||
Graphics.Blit (secondQuarterRezColor, thirdQuarterRezColor, hollywoodFlaresMaterial, 3);
|
||||
|
||||
hollywoodFlaresMaterial.SetVector ("offsets", Vector4 ((sepBlurSpread * 1.0f / widthOverHeight) * oneOverBaseSize, 0.0, 0.0, 0.0));
|
||||
hollywoodFlaresMaterial.SetFloat ("stretchWidth", hollyStretchWidth);
|
||||
Graphics.Blit (thirdQuarterRezColor, secondQuarterRezColor, hollywoodFlaresMaterial, 1);
|
||||
hollywoodFlaresMaterial.SetFloat ("stretchWidth", hollyStretchWidth * 2.0f);
|
||||
Graphics.Blit (secondQuarterRezColor, thirdQuarterRezColor, hollywoodFlaresMaterial, 1);
|
||||
hollywoodFlaresMaterial.SetFloat ("stretchWidth", hollyStretchWidth * 4.0f);
|
||||
Graphics.Blit (thirdQuarterRezColor, secondQuarterRezColor, hollywoodFlaresMaterial, 1);
|
||||
|
||||
if (lensflareMode == 1) {
|
||||
for (var itera : int = 0; itera < hollywoodFlareBlurIterations; itera++ ) {
|
||||
separableBlurMaterial.SetVector ("offsets", Vector4 ((hollyStretchWidth * 2.0f / widthOverHeight) * oneOverBaseSize, 0.0, 0.0, 0.0));
|
||||
Graphics.Blit (secondQuarterRezColor, thirdQuarterRezColor, separableBlurMaterial);
|
||||
separableBlurMaterial.SetVector ("offsets", Vector4 ((hollyStretchWidth * 2.0f / widthOverHeight) * oneOverBaseSize, 0.0, 0.0, 0.0));
|
||||
Graphics.Blit (thirdQuarterRezColor, secondQuarterRezColor, separableBlurMaterial);
|
||||
}
|
||||
|
||||
AddTo (1.0, secondQuarterRezColor, quarterRezColor);
|
||||
}
|
||||
else {
|
||||
|
||||
// (c) combined
|
||||
|
||||
for (var ix : int = 0; ix < hollywoodFlareBlurIterations; ix++ ) {
|
||||
separableBlurMaterial.SetVector ("offsets", Vector4 ((hollyStretchWidth * 2.0f / widthOverHeight) * oneOverBaseSize, 0.0, 0.0, 0.0));
|
||||
Graphics.Blit (secondQuarterRezColor, thirdQuarterRezColor, separableBlurMaterial);
|
||||
separableBlurMaterial.SetVector ("offsets", Vector4 ((hollyStretchWidth * 2.0f / widthOverHeight) * oneOverBaseSize, 0.0, 0.0, 0.0));
|
||||
Graphics.Blit (thirdQuarterRezColor, secondQuarterRezColor, separableBlurMaterial);
|
||||
}
|
||||
|
||||
Vignette (1.0, secondQuarterRezColor, thirdQuarterRezColor);
|
||||
BlendFlares (thirdQuarterRezColor, secondQuarterRezColor);
|
||||
AddTo (1.0, secondQuarterRezColor, quarterRezColor);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// screen blend bloom results to color buffer
|
||||
|
||||
screenBlend.SetFloat ("_Intensity", bloomIntensity);
|
||||
screenBlend.SetTexture ("_ColorBuffer", source);
|
||||
Graphics.Blit (quarterRezColor, destination, screenBlend, realBlendMode);
|
||||
|
||||
RenderTexture.ReleaseTemporary (quarterRezColor);
|
||||
RenderTexture.ReleaseTemporary (secondQuarterRezColor);
|
||||
RenderTexture.ReleaseTemporary (thirdQuarterRezColor);
|
||||
}
|
||||
|
||||
private function AddTo (intensity_ : float, from : RenderTexture, to : RenderTexture) {
|
||||
addBrightStuffBlendOneOneMaterial.SetFloat ("_Intensity", intensity_);
|
||||
Graphics.Blit (from, to, addBrightStuffBlendOneOneMaterial);
|
||||
}
|
||||
|
||||
private function BlendFlares (from : RenderTexture, to : RenderTexture) {
|
||||
lensFlareMaterial.SetVector ("colorA", Vector4 (flareColorA.r, flareColorA.g, flareColorA.b, flareColorA.a) * lensflareIntensity);
|
||||
lensFlareMaterial.SetVector ("colorB", Vector4 (flareColorB.r, flareColorB.g, flareColorB.b, flareColorB.a) * lensflareIntensity);
|
||||
lensFlareMaterial.SetVector ("colorC", Vector4 (flareColorC.r, flareColorC.g, flareColorC.b, flareColorC.a) * lensflareIntensity);
|
||||
lensFlareMaterial.SetVector ("colorD", Vector4 (flareColorD.r, flareColorD.g, flareColorD.b, flareColorD.a) * lensflareIntensity);
|
||||
Graphics.Blit (from, to, lensFlareMaterial);
|
||||
}
|
||||
|
||||
private function BrightFilter (thresh : float, useAlphaAsMask : float, from : RenderTexture, to : RenderTexture) {
|
||||
if(doHdr)
|
||||
brightPassFilterMaterial.SetVector ("threshhold", Vector4 (thresh, 1.0f, 0.0f, 0.0f));
|
||||
else
|
||||
brightPassFilterMaterial.SetVector ("threshhold", Vector4 (thresh, 1.0f / (1.0f-thresh), 0.0f, 0.0f));
|
||||
brightPassFilterMaterial.SetFloat ("useSrcAlphaAsMask", useAlphaAsMask);
|
||||
Graphics.Blit (from, to, brightPassFilterMaterial);
|
||||
}
|
||||
|
||||
private function Vignette (amount : float, from : RenderTexture, to : RenderTexture) {
|
||||
if(lensFlareVignetteMask) {
|
||||
screenBlend.SetTexture ("_ColorBuffer", lensFlareVignetteMask);
|
||||
Graphics.Blit (from, to, screenBlend, 3);
|
||||
}
|
||||
else {
|
||||
vignetteMaterial.SetFloat ("vignetteIntensity", amount);
|
||||
Graphics.Blit (from, to, vignetteMaterial);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 8a281f2ebe8ea7f40822aa76207daf0f
|
||||
TextScriptImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,110 @@
|
|||
using UnityEngine;
|
||||
using System.Collections;
|
||||
|
||||
[ExecuteInEditMode]
|
||||
[AddComponentMenu("Image Effects/Blur")]
|
||||
public class BlurEffect : MonoBehaviour
|
||||
{
|
||||
/// Blur iterations - larger number means more blur.
|
||||
public int iterations = 3;
|
||||
|
||||
/// Blur spread for each iteration. Lower values
|
||||
/// give better looking blur, but require more iterations to
|
||||
/// get large blurs. Value is usually between 0.5 and 1.0.
|
||||
public float blurSpread = 0.6f;
|
||||
|
||||
|
||||
// --------------------------------------------------------
|
||||
// The blur iteration shader.
|
||||
// Basically it just takes 4 texture samples and averages them.
|
||||
// By applying it repeatedly and spreading out sample locations
|
||||
// we get a Gaussian blur approximation.
|
||||
|
||||
public Shader blurShader = null;
|
||||
|
||||
//private static string blurMatString =
|
||||
|
||||
static Material m_Material = null;
|
||||
protected Material material {
|
||||
get {
|
||||
if (m_Material == null) {
|
||||
m_Material = new Material(blurShader);
|
||||
m_Material.hideFlags = HideFlags.DontSave;
|
||||
}
|
||||
return m_Material;
|
||||
}
|
||||
}
|
||||
|
||||
protected void OnDisable() {
|
||||
if( m_Material ) {
|
||||
DestroyImmediate( m_Material );
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------------
|
||||
|
||||
protected void Start()
|
||||
{
|
||||
// Disable if we don't support image effects
|
||||
if (!SystemInfo.supportsImageEffects) {
|
||||
enabled = false;
|
||||
return;
|
||||
}
|
||||
// Disable if the shader can't run on the users graphics card
|
||||
if (!blurShader || !material.shader.isSupported) {
|
||||
enabled = false;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Performs one blur iteration.
|
||||
public void FourTapCone (RenderTexture source, RenderTexture dest, int iteration)
|
||||
{
|
||||
float off = 0.5f + iteration*blurSpread;
|
||||
Graphics.BlitMultiTap (source, dest, material,
|
||||
new Vector2(-off, -off),
|
||||
new Vector2(-off, off),
|
||||
new Vector2( off, off),
|
||||
new Vector2( off, -off)
|
||||
);
|
||||
}
|
||||
|
||||
// Downsamples the texture to a quarter resolution.
|
||||
private void DownSample4x (RenderTexture source, RenderTexture dest)
|
||||
{
|
||||
float off = 1.0f;
|
||||
Graphics.BlitMultiTap (source, dest, material,
|
||||
new Vector2(-off, -off),
|
||||
new Vector2(-off, off),
|
||||
new Vector2( off, off),
|
||||
new Vector2( off, -off)
|
||||
);
|
||||
}
|
||||
|
||||
// Called by the camera to apply the image effect
|
||||
void OnRenderImage (RenderTexture source, RenderTexture destination) {
|
||||
RenderTexture buffer = RenderTexture.GetTemporary(source.width/4, source.height/4, 0);
|
||||
RenderTexture buffer2 = RenderTexture.GetTemporary(source.width/4, source.height/4, 0);
|
||||
|
||||
// Copy source to the 4x4 smaller texture.
|
||||
DownSample4x (source, buffer);
|
||||
|
||||
// Blur the small texture
|
||||
bool oddEven = true;
|
||||
for(int i = 0; i < iterations; i++)
|
||||
{
|
||||
if( oddEven )
|
||||
FourTapCone (buffer, buffer2, i);
|
||||
else
|
||||
FourTapCone (buffer2, buffer, i);
|
||||
oddEven = !oddEven;
|
||||
}
|
||||
if( oddEven )
|
||||
Graphics.Blit(buffer, destination);
|
||||
else
|
||||
Graphics.Blit(buffer2, destination);
|
||||
|
||||
RenderTexture.ReleaseTemporary(buffer);
|
||||
RenderTexture.ReleaseTemporary(buffer2);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 39b0c9f855975684d9e178ae3055e4da
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,44 @@
|
|||
|
||||
// pseudo image effect that displays useful info for your image effects
|
||||
|
||||
#pragma strict
|
||||
|
||||
@script ExecuteInEditMode
|
||||
@script RequireComponent (Camera)
|
||||
@script AddComponentMenu ("Image Effects/Camera Info")
|
||||
|
||||
class CameraInfo extends MonoBehaviour {
|
||||
|
||||
// display current depth texture mode
|
||||
public var currentDepthMode : DepthTextureMode;
|
||||
// render path
|
||||
public var currentRenderPath : RenderingPath;
|
||||
// number of official image fx used
|
||||
public var recognizedPostFxCount : int = 0;
|
||||
|
||||
#if UNITY_EDITOR
|
||||
function Start () {
|
||||
UpdateInfo ();
|
||||
}
|
||||
|
||||
function Update () {
|
||||
if (currentDepthMode != camera.depthTextureMode)
|
||||
camera.depthTextureMode = currentDepthMode;
|
||||
if (currentRenderPath != camera.actualRenderingPath)
|
||||
camera.renderingPath = currentRenderPath;
|
||||
|
||||
UpdateInfo ();
|
||||
}
|
||||
|
||||
function UpdateInfo () {
|
||||
currentDepthMode = camera.depthTextureMode;
|
||||
currentRenderPath = camera.actualRenderingPath;
|
||||
var fx : PostEffectsBase[] = gameObject.GetComponents.<PostEffectsBase> ();
|
||||
var fxCount : int = 0;
|
||||
for (var post : PostEffectsBase in fx)
|
||||
if (post.enabled)
|
||||
fxCount++;
|
||||
recognizedPostFxCount = fxCount;
|
||||
}
|
||||
#endif
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 62039e0070cb09f4d9e27c47d1640356
|
||||
TextScriptImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,156 @@
|
|||
|
||||
#pragma strict
|
||||
@script ExecuteInEditMode
|
||||
@script AddComponentMenu ("Image Effects/Color Correction")
|
||||
|
||||
enum ColorCorrectionMode {
|
||||
Simple = 0,
|
||||
Advanced = 1
|
||||
}
|
||||
|
||||
class ColorCorrectionCurves extends PostEffectsBase
|
||||
{
|
||||
public var redChannel : AnimationCurve;
|
||||
public var greenChannel : AnimationCurve;
|
||||
public var blueChannel : AnimationCurve;
|
||||
|
||||
public var useDepthCorrection : boolean = false;
|
||||
|
||||
public var zCurve : AnimationCurve;
|
||||
public var depthRedChannel : AnimationCurve;
|
||||
public var depthGreenChannel : AnimationCurve;
|
||||
public var depthBlueChannel : AnimationCurve;
|
||||
|
||||
private var ccMaterial : Material;
|
||||
private var ccDepthMaterial : Material;
|
||||
private var selectiveCcMaterial : Material;
|
||||
|
||||
private var rgbChannelTex : Texture2D;
|
||||
private var rgbDepthChannelTex : Texture2D;
|
||||
private var zCurveTex : Texture2D;
|
||||
|
||||
public var selectiveCc : boolean = false;
|
||||
|
||||
public var selectiveFromColor : Color = Color.white;
|
||||
public var selectiveToColor : Color = Color.white;
|
||||
|
||||
public var mode : ColorCorrectionMode;
|
||||
|
||||
public var updateTextures : boolean = true;
|
||||
|
||||
public var colorCorrectionCurvesShader : Shader = null;
|
||||
public var simpleColorCorrectionCurvesShader : Shader = null;
|
||||
public var colorCorrectionSelectiveShader : Shader = null;
|
||||
|
||||
private var updateTexturesOnStartup : boolean = true;
|
||||
|
||||
function Start () {
|
||||
super ();
|
||||
updateTexturesOnStartup = true;
|
||||
}
|
||||
|
||||
function Awake () { }
|
||||
|
||||
function CheckResources () : boolean {
|
||||
CheckSupport (mode == ColorCorrectionMode.Advanced);
|
||||
|
||||
ccMaterial = CheckShaderAndCreateMaterial (simpleColorCorrectionCurvesShader, ccMaterial);
|
||||
ccDepthMaterial = CheckShaderAndCreateMaterial (colorCorrectionCurvesShader, ccDepthMaterial);
|
||||
selectiveCcMaterial = CheckShaderAndCreateMaterial (colorCorrectionSelectiveShader, selectiveCcMaterial);
|
||||
|
||||
if (!rgbChannelTex)
|
||||
rgbChannelTex = new Texture2D (256, 4, TextureFormat.ARGB32, false, true);
|
||||
if (!rgbDepthChannelTex)
|
||||
rgbDepthChannelTex = new Texture2D (256, 4, TextureFormat.ARGB32, false, true);
|
||||
if (!zCurveTex)
|
||||
zCurveTex = new Texture2D (256, 1, TextureFormat.ARGB32, false, true);
|
||||
|
||||
rgbChannelTex.hideFlags = HideFlags.DontSave;
|
||||
rgbDepthChannelTex.hideFlags = HideFlags.DontSave;
|
||||
zCurveTex.hideFlags = HideFlags.DontSave;
|
||||
|
||||
rgbChannelTex.wrapMode = TextureWrapMode.Clamp;
|
||||
rgbDepthChannelTex.wrapMode = TextureWrapMode.Clamp;
|
||||
zCurveTex.wrapMode = TextureWrapMode.Clamp;
|
||||
|
||||
if(!isSupported)
|
||||
ReportAutoDisable ();
|
||||
return isSupported;
|
||||
}
|
||||
|
||||
public function UpdateParameters ()
|
||||
{
|
||||
if (redChannel && greenChannel && blueChannel) {
|
||||
for (var i : float = 0.0f; i <= 1.0f; i += 1.0f / 255.0f) {
|
||||
var rCh : float = Mathf.Clamp (redChannel.Evaluate(i), 0.0f, 1.0f);
|
||||
var gCh : float = Mathf.Clamp (greenChannel.Evaluate(i), 0.0f, 1.0f);
|
||||
var bCh : float = Mathf.Clamp (blueChannel.Evaluate(i), 0.0f, 1.0f);
|
||||
|
||||
rgbChannelTex.SetPixel (Mathf.Floor(i*255.0f), 0, Color(rCh,rCh,rCh) );
|
||||
rgbChannelTex.SetPixel (Mathf.Floor(i*255.0f), 1, Color(gCh,gCh,gCh) );
|
||||
rgbChannelTex.SetPixel (Mathf.Floor(i*255.0f), 2, Color(bCh,bCh,bCh) );
|
||||
|
||||
var zC : float = Mathf.Clamp (zCurve.Evaluate(i), 0.0,1.0);
|
||||
|
||||
zCurveTex.SetPixel (Mathf.Floor(i*255.0), 0, Color(zC,zC,zC) );
|
||||
|
||||
rCh = Mathf.Clamp (depthRedChannel.Evaluate(i), 0.0f,1.0f);
|
||||
gCh = Mathf.Clamp (depthGreenChannel.Evaluate(i), 0.0f,1.0f);
|
||||
bCh = Mathf.Clamp (depthBlueChannel.Evaluate(i), 0.0f,1.0f);
|
||||
|
||||
rgbDepthChannelTex.SetPixel (Mathf.Floor(i*255.0f), 0, Color(rCh,rCh,rCh) );
|
||||
rgbDepthChannelTex.SetPixel (Mathf.Floor(i*255.0f), 1, Color(gCh,gCh,gCh) );
|
||||
rgbDepthChannelTex.SetPixel (Mathf.Floor(i*255.0f), 2, Color(bCh,bCh,bCh) );
|
||||
}
|
||||
|
||||
rgbChannelTex.Apply ();
|
||||
rgbDepthChannelTex.Apply ();
|
||||
zCurveTex.Apply ();
|
||||
}
|
||||
}
|
||||
|
||||
function UpdateTextures () {
|
||||
UpdateParameters ();
|
||||
}
|
||||
|
||||
function OnRenderImage (source : RenderTexture, destination : RenderTexture) {
|
||||
if(CheckResources()==false) {
|
||||
Graphics.Blit (source, destination);
|
||||
return;
|
||||
}
|
||||
|
||||
if (updateTexturesOnStartup) {
|
||||
UpdateParameters ();
|
||||
updateTexturesOnStartup = false;
|
||||
}
|
||||
|
||||
if (useDepthCorrection)
|
||||
camera.depthTextureMode |= DepthTextureMode.Depth;
|
||||
|
||||
var renderTarget2Use : RenderTexture = destination;
|
||||
|
||||
if (selectiveCc) {
|
||||
renderTarget2Use = RenderTexture.GetTemporary (source.width, source.height);
|
||||
}
|
||||
|
||||
if (useDepthCorrection) {
|
||||
ccDepthMaterial.SetTexture ("_RgbTex", rgbChannelTex);
|
||||
ccDepthMaterial.SetTexture ("_ZCurve", zCurveTex);
|
||||
ccDepthMaterial.SetTexture ("_RgbDepthTex", rgbDepthChannelTex);
|
||||
|
||||
Graphics.Blit (source, renderTarget2Use, ccDepthMaterial);
|
||||
}
|
||||
else {
|
||||
ccMaterial.SetTexture ("_RgbTex", rgbChannelTex);
|
||||
Graphics.Blit (source, renderTarget2Use, ccMaterial);
|
||||
}
|
||||
|
||||
if (selectiveCc) {
|
||||
selectiveCcMaterial.SetColor ("selColor", selectiveFromColor);
|
||||
selectiveCcMaterial.SetColor ("targetColor", selectiveToColor);
|
||||
Graphics.Blit (renderTarget2Use, destination, selectiveCcMaterial);
|
||||
|
||||
RenderTexture.ReleaseTemporary (renderTarget2Use);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 5649d7b3a44087f4d9f628839fa27a8c
|
||||
TextScriptImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,14 @@
|
|||
using UnityEngine;
|
||||
using System.Collections;
|
||||
|
||||
[ExecuteInEditMode]
|
||||
[AddComponentMenu("Image Effects/Color Correction (Ramp)")]
|
||||
public class ColorCorrectionEffect : ImageEffectBase {
|
||||
public Texture textureRamp;
|
||||
|
||||
// Called by camera to apply image effect
|
||||
void OnRenderImage (RenderTexture source, RenderTexture destination) {
|
||||
material.SetTexture ("_RampTex", textureRamp);
|
||||
Graphics.Blit (source, destination, material);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 78c576d3b8be522459ce0e7060da3e34
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,64 @@
|
|||
|
||||
#pragma strict
|
||||
|
||||
@script ExecuteInEditMode
|
||||
@script RequireComponent(Camera)
|
||||
@script AddComponentMenu("Image Effects/Contrast Enhance (Unsharp Mask)")
|
||||
|
||||
class ContrastEnhance extends PostEffectsBase {
|
||||
public var intensity : float = 0.5;
|
||||
public var threshhold : float = 0.0;
|
||||
|
||||
private var separableBlurMaterial : Material;
|
||||
private var contrastCompositeMaterial : Material;
|
||||
|
||||
public var blurSpread : float = 1.0;
|
||||
|
||||
public var separableBlurShader : Shader = null;
|
||||
public var contrastCompositeShader : Shader = null;
|
||||
|
||||
function CheckResources () : boolean {
|
||||
CheckSupport (false);
|
||||
|
||||
contrastCompositeMaterial = CheckShaderAndCreateMaterial (contrastCompositeShader, contrastCompositeMaterial);
|
||||
separableBlurMaterial = CheckShaderAndCreateMaterial (separableBlurShader, separableBlurMaterial);
|
||||
|
||||
if(!isSupported)
|
||||
ReportAutoDisable ();
|
||||
return isSupported;
|
||||
}
|
||||
|
||||
function OnRenderImage (source : RenderTexture, destination : RenderTexture) {
|
||||
if(CheckResources()==false) {
|
||||
Graphics.Blit (source, destination);
|
||||
return;
|
||||
}
|
||||
|
||||
var halfRezColor : RenderTexture = RenderTexture.GetTemporary (source.width / 2.0, source.height / 2.0, 0);
|
||||
var quarterRezColor : RenderTexture = RenderTexture.GetTemporary (source.width / 4.0, source.height / 4.0, 0);
|
||||
var secondQuarterRezColor : RenderTexture = RenderTexture.GetTemporary (source.width / 4.0, source.height / 4.0, 0);
|
||||
|
||||
// ddownsample
|
||||
|
||||
Graphics.Blit (source, halfRezColor);
|
||||
Graphics.Blit (halfRezColor, quarterRezColor);
|
||||
|
||||
// blur
|
||||
|
||||
separableBlurMaterial.SetVector ("offsets", Vector4 (0.0, (blurSpread * 1.0) / quarterRezColor.height, 0.0, 0.0));
|
||||
Graphics.Blit (quarterRezColor, secondQuarterRezColor, separableBlurMaterial);
|
||||
separableBlurMaterial.SetVector ("offsets", Vector4 ((blurSpread * 1.0) / quarterRezColor.width, 0.0, 0.0, 0.0));
|
||||
Graphics.Blit (secondQuarterRezColor, quarterRezColor, separableBlurMaterial);
|
||||
|
||||
// composite
|
||||
|
||||
contrastCompositeMaterial.SetTexture ("_MainTexBlurred", quarterRezColor);
|
||||
contrastCompositeMaterial.SetFloat ("intensity", intensity);
|
||||
contrastCompositeMaterial.SetFloat ("threshhold", threshhold);
|
||||
Graphics.Blit (source, destination, contrastCompositeMaterial);
|
||||
|
||||
RenderTexture.ReleaseTemporary (halfRezColor);
|
||||
RenderTexture.ReleaseTemporary (quarterRezColor);
|
||||
RenderTexture.ReleaseTemporary (secondQuarterRezColor);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 8d58f1708e3fd8849b5d8f51b9e109e6
|
||||
TextScriptImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,191 @@
|
|||
using UnityEngine;
|
||||
using System.Collections;
|
||||
|
||||
[ExecuteInEditMode]
|
||||
[AddComponentMenu("Image Effects/Contrast Stretch")]
|
||||
public class ContrastStretchEffect : MonoBehaviour
|
||||
{
|
||||
/// Adaptation speed - percents per frame, if playing at 30FPS.
|
||||
/// Default is 0.02 (2% each 1/30s).
|
||||
public float adaptationSpeed = 0.02f;
|
||||
|
||||
/// If our scene is really dark (or really bright), we might not want to
|
||||
/// stretch its contrast to the full range.
|
||||
/// limitMinimum=0, limitMaximum=1 is the same as not applying the effect at all.
|
||||
/// limitMinimum=1, limitMaximum=0 is always stretching colors to full range.
|
||||
|
||||
/// The limit on the minimum luminance (0...1) - we won't go above this.
|
||||
public float limitMinimum = 0.2f;
|
||||
|
||||
/// The limit on the maximum luminance (0...1) - we won't go below this.
|
||||
public float limitMaximum = 0.6f;
|
||||
|
||||
|
||||
// To maintain adaptation levels over time, we need two 1x1 render textures
|
||||
// and ping-pong between them.
|
||||
private RenderTexture[] adaptRenderTex = new RenderTexture[2];
|
||||
private int curAdaptIndex = 0;
|
||||
|
||||
|
||||
// Computes scene luminance (grayscale) image
|
||||
public Shader shaderLum;
|
||||
private Material m_materialLum;
|
||||
protected Material materialLum {
|
||||
get {
|
||||
if( m_materialLum == null ) {
|
||||
m_materialLum = new Material(shaderLum);
|
||||
m_materialLum.hideFlags = HideFlags.HideAndDontSave;
|
||||
}
|
||||
return m_materialLum;
|
||||
}
|
||||
}
|
||||
|
||||
// Reduces size of the image by 2x2, while computing maximum/minimum values.
|
||||
// By repeatedly applying this shader, we reduce the initial luminance image
|
||||
// to 1x1 image with minimum/maximum luminances found.
|
||||
public Shader shaderReduce;
|
||||
private Material m_materialReduce;
|
||||
protected Material materialReduce {
|
||||
get {
|
||||
if( m_materialReduce == null ) {
|
||||
m_materialReduce = new Material(shaderReduce);
|
||||
m_materialReduce.hideFlags = HideFlags.HideAndDontSave;
|
||||
}
|
||||
return m_materialReduce;
|
||||
}
|
||||
}
|
||||
|
||||
// Adaptation shader - gradually "adapts" minimum/maximum luminances,
|
||||
// based on currently adapted 1x1 image and the actual 1x1 image of the current scene.
|
||||
public Shader shaderAdapt;
|
||||
private Material m_materialAdapt;
|
||||
protected Material materialAdapt {
|
||||
get {
|
||||
if( m_materialAdapt == null ) {
|
||||
m_materialAdapt = new Material(shaderAdapt);
|
||||
m_materialAdapt.hideFlags = HideFlags.HideAndDontSave;
|
||||
}
|
||||
return m_materialAdapt;
|
||||
}
|
||||
}
|
||||
|
||||
// Final pass - stretches the color values of the original scene, based on currently
|
||||
// adpated minimum/maximum values.
|
||||
public Shader shaderApply;
|
||||
private Material m_materialApply;
|
||||
protected Material materialApply {
|
||||
get {
|
||||
if( m_materialApply == null ) {
|
||||
m_materialApply = new Material(shaderApply);
|
||||
m_materialApply.hideFlags = HideFlags.HideAndDontSave;
|
||||
}
|
||||
return m_materialApply;
|
||||
}
|
||||
}
|
||||
|
||||
void Start()
|
||||
{
|
||||
// Disable if we don't support image effects
|
||||
if (!SystemInfo.supportsImageEffects) {
|
||||
enabled = false;
|
||||
return;
|
||||
}
|
||||
|
||||
if (!shaderAdapt.isSupported || !shaderApply.isSupported || !shaderLum.isSupported || !shaderReduce.isSupported) {
|
||||
enabled = false;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void OnEnable()
|
||||
{
|
||||
for( int i = 0; i < 2; ++i )
|
||||
{
|
||||
if( !adaptRenderTex[i] ) {
|
||||
adaptRenderTex[i] = new RenderTexture( 1, 1, 32 );
|
||||
adaptRenderTex[i].hideFlags = HideFlags.HideAndDontSave;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void OnDisable()
|
||||
{
|
||||
for( int i = 0; i < 2; ++i )
|
||||
{
|
||||
DestroyImmediate( adaptRenderTex[i] );
|
||||
adaptRenderTex[i] = null;
|
||||
}
|
||||
if( m_materialLum )
|
||||
DestroyImmediate( m_materialLum );
|
||||
if( m_materialReduce )
|
||||
DestroyImmediate( m_materialReduce );
|
||||
if( m_materialAdapt )
|
||||
DestroyImmediate( m_materialAdapt );
|
||||
if( m_materialApply )
|
||||
DestroyImmediate( m_materialApply );
|
||||
}
|
||||
|
||||
|
||||
/// Apply the filter
|
||||
void OnRenderImage (RenderTexture source, RenderTexture destination)
|
||||
{
|
||||
// Blit to smaller RT and convert to luminance on the way
|
||||
const int TEMP_RATIO = 1; // 4x4 smaller
|
||||
RenderTexture rtTempSrc = RenderTexture.GetTemporary(source.width/TEMP_RATIO, source.height/TEMP_RATIO);
|
||||
Graphics.Blit (source, rtTempSrc, materialLum);
|
||||
|
||||
// Repeatedly reduce this image in size, computing min/max luminance values
|
||||
// In the end we'll have 1x1 image with min/max luminances found.
|
||||
const int FINAL_SIZE = 1;
|
||||
//const int FINAL_SIZE = 1;
|
||||
while( rtTempSrc.width > FINAL_SIZE || rtTempSrc.height > FINAL_SIZE )
|
||||
{
|
||||
const int REDUCE_RATIO = 2; // our shader does 2x2 reduction
|
||||
int destW = rtTempSrc.width / REDUCE_RATIO;
|
||||
if( destW < FINAL_SIZE ) destW = FINAL_SIZE;
|
||||
int destH = rtTempSrc.height / REDUCE_RATIO;
|
||||
if( destH < FINAL_SIZE ) destH = FINAL_SIZE;
|
||||
RenderTexture rtTempDst = RenderTexture.GetTemporary(destW,destH);
|
||||
Graphics.Blit (rtTempSrc, rtTempDst, materialReduce);
|
||||
|
||||
// Release old src temporary, and make new temporary the source
|
||||
RenderTexture.ReleaseTemporary( rtTempSrc );
|
||||
rtTempSrc = rtTempDst;
|
||||
}
|
||||
|
||||
// Update viewer's adaptation level
|
||||
CalculateAdaptation( rtTempSrc );
|
||||
|
||||
// Apply contrast strech to the original scene, using currently adapted parameters
|
||||
materialApply.SetTexture("_AdaptTex", adaptRenderTex[curAdaptIndex] );
|
||||
Graphics.Blit (source, destination, materialApply);
|
||||
|
||||
RenderTexture.ReleaseTemporary( rtTempSrc );
|
||||
}
|
||||
|
||||
|
||||
/// Helper function to do gradual adaptation to min/max luminances
|
||||
private void CalculateAdaptation( Texture curTexture )
|
||||
{
|
||||
int prevAdaptIndex = curAdaptIndex;
|
||||
curAdaptIndex = (curAdaptIndex+1) % 2;
|
||||
|
||||
// Adaptation speed is expressed in percents/frame, based on 30FPS.
|
||||
// Calculate the adaptation lerp, based on current FPS.
|
||||
float adaptLerp = 1.0f - Mathf.Pow( 1.0f - adaptationSpeed, 30.0f * Time.deltaTime );
|
||||
const float kMinAdaptLerp = 0.01f;
|
||||
adaptLerp = Mathf.Clamp( adaptLerp, kMinAdaptLerp, 1 );
|
||||
|
||||
materialAdapt.SetTexture("_CurTex", curTexture );
|
||||
materialAdapt.SetVector("_AdaptParams", new Vector4(
|
||||
adaptLerp,
|
||||
limitMinimum,
|
||||
limitMaximum,
|
||||
0.0f
|
||||
));
|
||||
Graphics.Blit (
|
||||
adaptRenderTex[prevAdaptIndex],
|
||||
adaptRenderTex[curAdaptIndex],
|
||||
materialAdapt);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 6b87dfd0d71713d4789a9b698ec86576
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,66 @@
|
|||
|
||||
#pragma strict
|
||||
|
||||
@script ExecuteInEditMode
|
||||
@script RequireComponent (Camera)
|
||||
@script AddComponentMenu ("Image Effects/Crease")
|
||||
|
||||
class Crease extends PostEffectsBase {
|
||||
public var intensity : float = 0.5;
|
||||
public var softness : int = 1;
|
||||
public var spread : float = 1.0;
|
||||
|
||||
public var blurShader : Shader;
|
||||
private var blurMaterial : Material = null;
|
||||
|
||||
public var depthFetchShader : Shader;
|
||||
private var depthFetchMaterial : Material = null;
|
||||
|
||||
public var creaseApplyShader : Shader;
|
||||
private var creaseApplyMaterial : Material = null;
|
||||
|
||||
function CheckResources () : boolean {
|
||||
CheckSupport (true);
|
||||
|
||||
blurMaterial = CheckShaderAndCreateMaterial (blurShader, blurMaterial);
|
||||
depthFetchMaterial = CheckShaderAndCreateMaterial (depthFetchShader, depthFetchMaterial);
|
||||
creaseApplyMaterial = CheckShaderAndCreateMaterial (creaseApplyShader, creaseApplyMaterial);
|
||||
|
||||
if(!isSupported)
|
||||
ReportAutoDisable ();
|
||||
return isSupported;
|
||||
}
|
||||
|
||||
function OnRenderImage (source : RenderTexture, destination : RenderTexture) {
|
||||
if(CheckResources()==false) {
|
||||
Graphics.Blit (source, destination);
|
||||
return;
|
||||
}
|
||||
|
||||
var widthOverHeight : float = (1.0f * source.width) / (1.0f * source.height);
|
||||
var oneOverBaseSize : float = 1.0f / 512.0f;
|
||||
|
||||
var hrTex : RenderTexture = RenderTexture.GetTemporary (source.width, source.height, 0);
|
||||
var lrTex1 : RenderTexture = RenderTexture.GetTemporary (source.width / 2, source.height / 2, 0);
|
||||
var lrTex2 : RenderTexture = RenderTexture.GetTemporary (source.width / 2, source.height / 2, 0);
|
||||
|
||||
Graphics.Blit (source,hrTex, depthFetchMaterial);
|
||||
Graphics.Blit (hrTex, lrTex1);
|
||||
|
||||
for(var i : int = 0; i < softness; i++) {
|
||||
blurMaterial.SetVector ("offsets", Vector4 (0.0, spread * oneOverBaseSize, 0.0, 0.0));
|
||||
Graphics.Blit (lrTex1, lrTex2, blurMaterial);
|
||||
blurMaterial.SetVector ("offsets", Vector4 (spread * oneOverBaseSize / widthOverHeight, 0.0, 0.0, 0.0));
|
||||
Graphics.Blit (lrTex2, lrTex1, blurMaterial);
|
||||
}
|
||||
|
||||
creaseApplyMaterial.SetTexture ("_HrDepthTex", hrTex);
|
||||
creaseApplyMaterial.SetTexture ("_LrDepthTex", lrTex1);
|
||||
creaseApplyMaterial.SetFloat ("intensity", intensity);
|
||||
Graphics.Blit (source,destination, creaseApplyMaterial);
|
||||
|
||||
RenderTexture.ReleaseTemporary (hrTex);
|
||||
RenderTexture.ReleaseTemporary (lrTex1);
|
||||
RenderTexture.ReleaseTemporary (lrTex2);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 0b025245fe12f0d42bfd907db3d3952a
|
||||
TextScriptImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,415 @@
|
|||
|
||||
#pragma strict
|
||||
|
||||
@script ExecuteInEditMode
|
||||
@script RequireComponent (Camera)
|
||||
@script AddComponentMenu ("Image Effects/Depth of Field (3.4)")
|
||||
|
||||
enum Dof34QualitySetting {
|
||||
OnlyBackground = 1,
|
||||
BackgroundAndForeground = 2,
|
||||
}
|
||||
|
||||
enum DofResolution {
|
||||
High = 2,
|
||||
Medium = 3,
|
||||
Low = 4,
|
||||
}
|
||||
|
||||
enum DofBlurriness {
|
||||
Low = 1,
|
||||
High = 2,
|
||||
VeryHigh = 4,
|
||||
}
|
||||
|
||||
enum BokehDestination {
|
||||
Background = 0x1,
|
||||
Foreground = 0x2,
|
||||
BackgroundAndForeground = 0x3,
|
||||
}
|
||||
|
||||
class DepthOfField34 extends PostEffectsBase {
|
||||
|
||||
static private var SMOOTH_DOWNSAMPLE_PASS : int = 6;
|
||||
static private var BOKEH_EXTRA_BLUR : float = 2.0f;
|
||||
|
||||
public var quality : Dof34QualitySetting = Dof34QualitySetting.OnlyBackground;
|
||||
public var resolution : DofResolution = DofResolution.Low;
|
||||
public var simpleTweakMode : boolean = true;
|
||||
|
||||
public var focalPoint : float = 1.0f;
|
||||
public var smoothness : float = 0.5f;
|
||||
|
||||
public var focalZDistance : float = 0.0f;
|
||||
public var focalZStartCurve : float = 1.0f;
|
||||
public var focalZEndCurve : float = 1.0f;
|
||||
|
||||
private var focalStartCurve : float = 2.0f;
|
||||
private var focalEndCurve : float = 2.0f;
|
||||
private var focalDistance01 : float = 0.1f;
|
||||
|
||||
public var objectFocus : Transform = null;
|
||||
public var focalSize : float = 0.0f;
|
||||
|
||||
public var bluriness : DofBlurriness = DofBlurriness.High;
|
||||
public var maxBlurSpread : float = 1.75f;
|
||||
|
||||
public var foregroundBlurExtrude : float = 1.15f;
|
||||
|
||||
public var dofBlurShader : Shader;
|
||||
private var dofBlurMaterial : Material = null;
|
||||
|
||||
public var dofShader : Shader;
|
||||
private var dofMaterial : Material = null;
|
||||
|
||||
public var visualize : boolean = false;
|
||||
public var bokehDestination : BokehDestination = BokehDestination.Background;
|
||||
|
||||
private var widthOverHeight : float = 1.25f;
|
||||
private var oneOverBaseSize : float = 1.0f / 512.0f;
|
||||
|
||||
public var bokeh : boolean = false;
|
||||
public var bokehSupport : boolean = true;
|
||||
public var bokehShader : Shader;
|
||||
public var bokehTexture : Texture2D;
|
||||
public var bokehScale : float = 2.4f;
|
||||
public var bokehIntensity : float = 0.15f;
|
||||
public var bokehThreshholdContrast : float = 0.1f;
|
||||
public var bokehThreshholdLuminance : float = 0.55f;
|
||||
public var bokehDownsample : int = 1;
|
||||
private var bokehMaterial : Material;
|
||||
|
||||
function CreateMaterials () {
|
||||
dofBlurMaterial = CheckShaderAndCreateMaterial (dofBlurShader, dofBlurMaterial);
|
||||
dofMaterial = CheckShaderAndCreateMaterial (dofShader,dofMaterial);
|
||||
bokehSupport = bokehShader.isSupported;
|
||||
|
||||
if(bokeh && bokehSupport && bokehShader)
|
||||
bokehMaterial = CheckShaderAndCreateMaterial (bokehShader, bokehMaterial);
|
||||
}
|
||||
|
||||
function CheckResources () : boolean {
|
||||
CheckSupport (true);
|
||||
|
||||
dofBlurMaterial = CheckShaderAndCreateMaterial (dofBlurShader, dofBlurMaterial);
|
||||
dofMaterial = CheckShaderAndCreateMaterial (dofShader,dofMaterial);
|
||||
bokehSupport = bokehShader.isSupported;
|
||||
|
||||
if(bokeh && bokehSupport && bokehShader)
|
||||
bokehMaterial = CheckShaderAndCreateMaterial (bokehShader, bokehMaterial);
|
||||
|
||||
if(!isSupported)
|
||||
ReportAutoDisable ();
|
||||
return isSupported;
|
||||
}
|
||||
|
||||
function OnDisable () {
|
||||
Quads.Cleanup ();
|
||||
}
|
||||
|
||||
function OnEnable() {
|
||||
camera.depthTextureMode |= DepthTextureMode.Depth;
|
||||
}
|
||||
|
||||
function FocalDistance01 (worldDist : float) : float {
|
||||
return camera.WorldToViewportPoint((worldDist-camera.nearClipPlane) * camera.transform.forward + camera.transform.position).z / (camera.farClipPlane-camera.nearClipPlane);
|
||||
}
|
||||
|
||||
function GetDividerBasedOnQuality () {
|
||||
var divider : int = 1;
|
||||
if (resolution == DofResolution.Medium)
|
||||
divider = 2;
|
||||
else if (resolution == DofResolution.Low)
|
||||
divider = 2;
|
||||
return divider;
|
||||
}
|
||||
|
||||
function GetLowResolutionDividerBasedOnQuality (baseDivider : int) {
|
||||
var lowTexDivider : int = baseDivider;
|
||||
if (resolution == DofResolution.High)
|
||||
lowTexDivider *= 2;
|
||||
if (resolution == DofResolution.Low)
|
||||
lowTexDivider *= 2;
|
||||
return lowTexDivider;
|
||||
}
|
||||
|
||||
private var foregroundTexture : RenderTexture = null;
|
||||
private var mediumRezWorkTexture : RenderTexture = null;
|
||||
private var finalDefocus : RenderTexture = null;
|
||||
private var lowRezWorkTexture : RenderTexture = null;
|
||||
private var bokehSource : RenderTexture = null;
|
||||
private var bokehSource2 : RenderTexture = null;
|
||||
|
||||
function OnRenderImage (source : RenderTexture, destination : RenderTexture) {
|
||||
if(CheckResources()==false) {
|
||||
Graphics.Blit (source, destination);
|
||||
return;
|
||||
}
|
||||
|
||||
if (smoothness < 0.1f)
|
||||
smoothness = 0.1f;
|
||||
|
||||
// update needed focal & rt size parameter
|
||||
|
||||
bokeh = bokeh && bokehSupport;
|
||||
var bokehBlurAmplifier : float = bokeh ? BOKEH_EXTRA_BLUR : 1.0f;
|
||||
|
||||
var blurForeground : boolean = quality > Dof34QualitySetting.OnlyBackground;
|
||||
var focal01Size : float = focalSize / (camera.farClipPlane - camera.nearClipPlane);;
|
||||
|
||||
if (simpleTweakMode) {
|
||||
focalDistance01 = objectFocus ? (camera.WorldToViewportPoint (objectFocus.position)).z / (camera.farClipPlane) : FocalDistance01 (focalPoint);
|
||||
focalStartCurve = focalDistance01 * smoothness;
|
||||
focalEndCurve = focalStartCurve;
|
||||
blurForeground = blurForeground && (focalPoint > (camera.nearClipPlane + Mathf.Epsilon));
|
||||
}
|
||||
else {
|
||||
if(objectFocus) {
|
||||
var vpPoint = camera.WorldToViewportPoint (objectFocus.position);
|
||||
vpPoint.z = (vpPoint.z) / (camera.farClipPlane);
|
||||
focalDistance01 = vpPoint.z;
|
||||
}
|
||||
else
|
||||
focalDistance01 = FocalDistance01 (focalZDistance);
|
||||
|
||||
focalStartCurve = focalZStartCurve;
|
||||
focalEndCurve = focalZEndCurve;
|
||||
blurForeground = blurForeground && (focalPoint > (camera.nearClipPlane + Mathf.Epsilon));
|
||||
}
|
||||
|
||||
widthOverHeight = (1.0f * source.width) / (1.0f * source.height);
|
||||
oneOverBaseSize = 1.0f / 512.0f;
|
||||
|
||||
dofMaterial.SetFloat ("_ForegroundBlurExtrude", foregroundBlurExtrude);
|
||||
dofMaterial.SetVector ("_CurveParams", Vector4 (simpleTweakMode ? 1.0f / focalStartCurve : focalStartCurve, simpleTweakMode ? 1.0f / focalEndCurve : focalEndCurve, focal01Size * 0.5, focalDistance01));
|
||||
dofMaterial.SetVector ("_InvRenderTargetSize", Vector4 (1.0 / (1.0 * source.width), 1.0 / (1.0 * source.height),0.0,0.0));
|
||||
|
||||
var divider : int = GetDividerBasedOnQuality ();
|
||||
var lowTexDivider : int = GetLowResolutionDividerBasedOnQuality (divider);
|
||||
|
||||
AllocateTextures (blurForeground, source, divider, lowTexDivider);
|
||||
|
||||
// WRITE COC to alpha channel
|
||||
// source is only being bound to detect y texcoord flip
|
||||
Graphics.Blit (source, source, dofMaterial, 3);
|
||||
|
||||
// better DOWNSAMPLE (could actually be weighted for higher quality)
|
||||
Downsample (source, mediumRezWorkTexture);
|
||||
|
||||
// BLUR A LITTLE first, which has two purposes
|
||||
// 1.) reduce jitter, noise, aliasing
|
||||
// 2.) produce the little-blur buffer used in composition later
|
||||
Blur (mediumRezWorkTexture, mediumRezWorkTexture, DofBlurriness.Low, 4, maxBlurSpread);
|
||||
|
||||
if (bokeh && (bokehDestination & BokehDestination.Background)) {
|
||||
dofMaterial.SetVector ("_Threshhold", Vector4(bokehThreshholdContrast, bokehThreshholdLuminance, 0.95f, 0.0f));
|
||||
|
||||
// add and mark the parts that should end up as bokeh shapes
|
||||
Graphics.Blit (mediumRezWorkTexture, bokehSource2, dofMaterial, 11);
|
||||
|
||||
// remove those parts (maybe even a little tittle bittle more) from the regurlarly blurred buffer
|
||||
//Graphics.Blit (mediumRezWorkTexture, lowRezWorkTexture, dofMaterial, 10);
|
||||
Graphics.Blit (mediumRezWorkTexture, lowRezWorkTexture);//, dofMaterial, 10);
|
||||
|
||||
// maybe you want to reblur the small blur ... but not really needed.
|
||||
//Blur (mediumRezWorkTexture, mediumRezWorkTexture, DofBlurriness.Low, 4, maxBlurSpread);
|
||||
|
||||
// bigger BLUR
|
||||
Blur (lowRezWorkTexture, lowRezWorkTexture, bluriness, 0, maxBlurSpread * bokehBlurAmplifier);
|
||||
}
|
||||
else {
|
||||
// bigger BLUR
|
||||
Downsample (mediumRezWorkTexture, lowRezWorkTexture);
|
||||
Blur (lowRezWorkTexture, lowRezWorkTexture, bluriness, 0, maxBlurSpread);
|
||||
}
|
||||
|
||||
dofBlurMaterial.SetTexture ("_TapLow", lowRezWorkTexture);
|
||||
dofBlurMaterial.SetTexture ("_TapMedium", mediumRezWorkTexture);
|
||||
Graphics.Blit (null, finalDefocus, dofBlurMaterial, 3);
|
||||
|
||||
// we are only adding bokeh now if the background is the only part we have to deal with
|
||||
if (bokeh && (bokehDestination & BokehDestination.Background))
|
||||
AddBokeh (bokehSource2, bokehSource, finalDefocus);
|
||||
|
||||
dofMaterial.SetTexture ("_TapLowBackground", finalDefocus);
|
||||
dofMaterial.SetTexture ("_TapMedium", mediumRezWorkTexture); // needed for debugging/visualization
|
||||
|
||||
// FINAL DEFOCUS (background)
|
||||
Graphics.Blit (source, blurForeground ? foregroundTexture : destination, dofMaterial, visualize ? 2 : 0);
|
||||
|
||||
// FINAL DEFOCUS (foreground)
|
||||
if (blurForeground) {
|
||||
// WRITE COC to alpha channel
|
||||
Graphics.Blit (foregroundTexture, source, dofMaterial, 5);
|
||||
|
||||
// DOWNSAMPLE (unweighted)
|
||||
Downsample (source, mediumRezWorkTexture);
|
||||
|
||||
// BLUR A LITTLE first, which has two purposes
|
||||
// 1.) reduce jitter, noise, aliasing
|
||||
// 2.) produce the little-blur buffer used in composition later
|
||||
BlurFg (mediumRezWorkTexture, mediumRezWorkTexture, DofBlurriness.Low, 2, maxBlurSpread);
|
||||
|
||||
if (bokeh && (bokehDestination & BokehDestination.Foreground)) {
|
||||
dofMaterial.SetVector ("_Threshhold", Vector4(bokehThreshholdContrast * 0.5f, bokehThreshholdLuminance, 0.0f, 0.0f));
|
||||
|
||||
// add and mark the parts that should end up as bokeh shapes
|
||||
Graphics.Blit (mediumRezWorkTexture, bokehSource2, dofMaterial, 11);
|
||||
|
||||
// remove the parts (maybe even a little tittle bittle more) that will end up in bokeh space
|
||||
//Graphics.Blit (mediumRezWorkTexture, lowRezWorkTexture, dofMaterial, 10);
|
||||
Graphics.Blit (mediumRezWorkTexture, lowRezWorkTexture);//, dofMaterial, 10);
|
||||
|
||||
// big BLUR
|
||||
BlurFg (lowRezWorkTexture, lowRezWorkTexture, bluriness, 1, maxBlurSpread * bokehBlurAmplifier);
|
||||
}
|
||||
else {
|
||||
// big BLUR
|
||||
BlurFg (mediumRezWorkTexture, lowRezWorkTexture, bluriness, 1, maxBlurSpread);
|
||||
}
|
||||
|
||||
// simple upsample once
|
||||
Graphics.Blit (lowRezWorkTexture, finalDefocus);
|
||||
|
||||
dofMaterial.SetTexture ("_TapLowForeground", finalDefocus);
|
||||
Graphics.Blit (source, destination, dofMaterial, visualize ? 1 : 4);
|
||||
|
||||
if (bokeh && (bokehDestination & BokehDestination.Foreground))
|
||||
AddBokeh (bokehSource2, bokehSource, destination);
|
||||
}
|
||||
|
||||
ReleaseTextures ();
|
||||
}
|
||||
|
||||
function Blur (from : RenderTexture, to : RenderTexture, iterations : DofBlurriness, blurPass: int, spread : float) {
|
||||
var tmp : RenderTexture = RenderTexture.GetTemporary (to.width, to.height);
|
||||
if (iterations > 1) {
|
||||
BlurHex (from, to, blurPass, spread, tmp);
|
||||
if (iterations > 2) {
|
||||
dofBlurMaterial.SetVector ("offsets", Vector4 (0.0, spread * oneOverBaseSize, 0.0, 0.0));
|
||||
Graphics.Blit (to, tmp, dofBlurMaterial, blurPass);
|
||||
dofBlurMaterial.SetVector ("offsets", Vector4 (spread / widthOverHeight * oneOverBaseSize, 0.0, 0.0, 0.0));
|
||||
Graphics.Blit (tmp, to, dofBlurMaterial, blurPass);
|
||||
}
|
||||
}
|
||||
else {
|
||||
dofBlurMaterial.SetVector ("offsets", Vector4 (0.0, spread * oneOverBaseSize, 0.0, 0.0));
|
||||
Graphics.Blit (from, tmp, dofBlurMaterial, blurPass);
|
||||
dofBlurMaterial.SetVector ("offsets", Vector4 (spread / widthOverHeight * oneOverBaseSize, 0.0, 0.0, 0.0));
|
||||
Graphics.Blit (tmp, to, dofBlurMaterial, blurPass);
|
||||
}
|
||||
RenderTexture.ReleaseTemporary (tmp);
|
||||
}
|
||||
|
||||
function BlurFg (from : RenderTexture, to : RenderTexture, iterations : DofBlurriness, blurPass: int, spread : float) {
|
||||
// we want a nice, big coc, hence we need to tap once from this (higher resolution) texture
|
||||
dofBlurMaterial.SetTexture ("_TapHigh", from);
|
||||
|
||||
var tmp : RenderTexture = RenderTexture.GetTemporary (to.width, to.height);
|
||||
if (iterations > 1) {
|
||||
BlurHex (from, to, blurPass, spread, tmp);
|
||||
if (iterations > 2) {
|
||||
dofBlurMaterial.SetVector ("offsets", Vector4 (0.0, spread * oneOverBaseSize, 0.0, 0.0));
|
||||
Graphics.Blit (to, tmp, dofBlurMaterial, blurPass);
|
||||
dofBlurMaterial.SetVector ("offsets", Vector4 (spread / widthOverHeight * oneOverBaseSize, 0.0, 0.0, 0.0));
|
||||
Graphics.Blit (tmp, to, dofBlurMaterial, blurPass);
|
||||
}
|
||||
}
|
||||
else {
|
||||
dofBlurMaterial.SetVector ("offsets", Vector4 (0.0, spread * oneOverBaseSize, 0.0, 0.0));
|
||||
Graphics.Blit (from, tmp, dofBlurMaterial, blurPass);
|
||||
dofBlurMaterial.SetVector ("offsets", Vector4 (spread / widthOverHeight * oneOverBaseSize, 0.0, 0.0, 0.0));
|
||||
Graphics.Blit (tmp, to, dofBlurMaterial, blurPass);
|
||||
}
|
||||
RenderTexture.ReleaseTemporary (tmp);
|
||||
}
|
||||
|
||||
function BlurHex (from : RenderTexture, to : RenderTexture, blurPass: int, spread : float, tmp : RenderTexture) {
|
||||
dofBlurMaterial.SetVector ("offsets", Vector4 (0.0, spread * oneOverBaseSize, 0.0, 0.0));
|
||||
Graphics.Blit (from, tmp, dofBlurMaterial, blurPass);
|
||||
dofBlurMaterial.SetVector ("offsets", Vector4 (spread / widthOverHeight * oneOverBaseSize, 0.0, 0.0, 0.0));
|
||||
Graphics.Blit (tmp, to, dofBlurMaterial, blurPass);
|
||||
dofBlurMaterial.SetVector ("offsets", Vector4 (spread / widthOverHeight * oneOverBaseSize, spread * oneOverBaseSize, 0.0, 0.0));
|
||||
Graphics.Blit (to, tmp, dofBlurMaterial, blurPass);
|
||||
dofBlurMaterial.SetVector ("offsets", Vector4 (spread / widthOverHeight * oneOverBaseSize, -spread * oneOverBaseSize, 0.0, 0.0));
|
||||
Graphics.Blit (tmp, to, dofBlurMaterial, blurPass);
|
||||
}
|
||||
|
||||
function Downsample (from : RenderTexture, to : RenderTexture) {
|
||||
dofMaterial.SetVector ("_InvRenderTargetSize", Vector4 (1.0f / (1.0f * to.width), 1.0f / (1.0f * to.height), 0.0f, 0.0f));
|
||||
Graphics.Blit (from, to, dofMaterial, SMOOTH_DOWNSAMPLE_PASS);
|
||||
}
|
||||
|
||||
function AddBokeh (bokehInfo : RenderTexture, tempTex : RenderTexture, finalTarget : RenderTexture) {
|
||||
if (bokehMaterial) {
|
||||
var meshes : Mesh[] = Quads.GetMeshes (tempTex.width, tempTex.height); // quads: exchanging more triangles with less overdraw
|
||||
|
||||
RenderTexture.active = tempTex;
|
||||
GL.Clear (false, true, Color (0.0f, 0.0f, 0.0f, 0.0f));
|
||||
|
||||
GL.PushMatrix ();
|
||||
GL.LoadIdentity ();
|
||||
|
||||
// point filter mode is important, otherwise we get bokeh shape & size artefacts
|
||||
bokehInfo.filterMode = FilterMode.Point;
|
||||
|
||||
var arW : float = (bokehInfo.width * 1.0f) / (bokehInfo.height * 1.0f);
|
||||
var sc : float = 2.0f / (1.0f * bokehInfo.width);
|
||||
sc += bokehScale * maxBlurSpread * BOKEH_EXTRA_BLUR * oneOverBaseSize;
|
||||
|
||||
bokehMaterial.SetTexture ("_Source", bokehInfo);
|
||||
bokehMaterial.SetTexture ("_MainTex", bokehTexture);
|
||||
bokehMaterial.SetVector ("_ArScale", Vector4 (sc, sc * arW, 0.5f, 0.5f * arW));
|
||||
bokehMaterial.SetFloat ("_Intensity", bokehIntensity);
|
||||
bokehMaterial.SetPass (0);
|
||||
|
||||
for (var m : Mesh in meshes)
|
||||
if (m) Graphics.DrawMeshNow (m, Matrix4x4.identity);
|
||||
|
||||
GL.PopMatrix ();
|
||||
|
||||
Graphics.Blit (tempTex, finalTarget, dofMaterial, 8);
|
||||
|
||||
// important to set back as we sample from this later on
|
||||
bokehInfo.filterMode = FilterMode.Bilinear;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function ReleaseTextures () {
|
||||
if (foregroundTexture) RenderTexture.ReleaseTemporary (foregroundTexture);
|
||||
if (finalDefocus) RenderTexture.ReleaseTemporary (finalDefocus);
|
||||
if (mediumRezWorkTexture) RenderTexture.ReleaseTemporary (mediumRezWorkTexture);
|
||||
if (lowRezWorkTexture) RenderTexture.ReleaseTemporary (lowRezWorkTexture);
|
||||
if (bokehSource) RenderTexture.ReleaseTemporary (bokehSource);
|
||||
if (bokehSource2) RenderTexture.ReleaseTemporary (bokehSource2);
|
||||
}
|
||||
|
||||
function AllocateTextures (blurForeground : boolean, source : RenderTexture, divider : int, lowTexDivider : int) {
|
||||
foregroundTexture = null;
|
||||
if (blurForeground)
|
||||
foregroundTexture = RenderTexture.GetTemporary (source.width, source.height, 0);
|
||||
mediumRezWorkTexture = RenderTexture.GetTemporary (source.width / divider, source.height / divider, 0);
|
||||
finalDefocus = RenderTexture.GetTemporary (source.width / divider, source.height / divider, 0);
|
||||
lowRezWorkTexture = RenderTexture.GetTemporary (source.width / lowTexDivider, source.height / lowTexDivider, 0);
|
||||
bokehSource = null;
|
||||
bokehSource2 = null;
|
||||
if (bokeh) {
|
||||
bokehSource = RenderTexture.GetTemporary (source.width / (lowTexDivider * bokehDownsample), source.height / (lowTexDivider * bokehDownsample), 0, RenderTextureFormat.ARGBHalf);
|
||||
bokehSource2 = RenderTexture.GetTemporary (source.width / (lowTexDivider * bokehDownsample), source.height / (lowTexDivider * bokehDownsample), 0, RenderTextureFormat.ARGBHalf);
|
||||
bokehSource.filterMode = FilterMode.Bilinear;
|
||||
bokehSource2.filterMode = FilterMode.Bilinear;
|
||||
RenderTexture.active = bokehSource2;
|
||||
GL.Clear (false, true, Color(0.0f, 0.0f, 0.0f, 0.0f));
|
||||
}
|
||||
|
||||
// to make sure: always use bilinear filter setting
|
||||
|
||||
source.filterMode = FilterMode.Bilinear;
|
||||
finalDefocus.filterMode = FilterMode.Bilinear;
|
||||
mediumRezWorkTexture.filterMode = FilterMode.Bilinear;
|
||||
lowRezWorkTexture.filterMode = FilterMode.Bilinear;
|
||||
if (foregroundTexture)
|
||||
foregroundTexture.filterMode = FilterMode.Bilinear;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
fileFormatVersion: 2
|
||||
guid: c350f79afe5e1ce4e91230b7b1e4b2f1
|
||||
TextScriptImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,158 @@
|
|||
|
||||
#pragma strict
|
||||
|
||||
@script ExecuteInEditMode
|
||||
@script RequireComponent (Camera)
|
||||
@script AddComponentMenu ("Image Effects/Depth of Field (HDR, Scatter, Lens Blur)")
|
||||
|
||||
class DepthOfFieldScatter extends PostEffectsBase {
|
||||
public var visualizeFocus : boolean = false;
|
||||
|
||||
public var focalLength : float = 10.0f;
|
||||
public var focalSize : float = 0.05f;
|
||||
public var aperture : float = 10.0f;
|
||||
|
||||
public var focalTransform : Transform = null;
|
||||
|
||||
public var maxBlurSize : float = 2.0f;
|
||||
|
||||
public enum BlurQuality {
|
||||
Low = 0,
|
||||
Medium = 1,
|
||||
High = 2,
|
||||
}
|
||||
|
||||
public enum BlurResolution {
|
||||
High = 0,
|
||||
Low = 1,
|
||||
}
|
||||
|
||||
public var blurQuality : BlurQuality = BlurQuality.Medium;
|
||||
public var blurResolution : BlurResolution = BlurResolution.Low;
|
||||
|
||||
public var foregroundBlur : boolean = false;
|
||||
public var foregroundOverlap : float = 0.55f;
|
||||
|
||||
public var dofHdrShader : Shader;
|
||||
|
||||
private var focalDistance01 : float = 10.0f;
|
||||
private var dofHdrMaterial : Material = null;
|
||||
|
||||
function CheckResources () : boolean {
|
||||
CheckSupport (true);
|
||||
|
||||
dofHdrMaterial = CheckShaderAndCreateMaterial (dofHdrShader, dofHdrMaterial);
|
||||
|
||||
if(!isSupported)
|
||||
ReportAutoDisable ();
|
||||
return isSupported;
|
||||
}
|
||||
|
||||
function FocalDistance01 (worldDist : float) : float {
|
||||
return camera.WorldToViewportPoint((worldDist-camera.nearClipPlane) * camera.transform.forward + camera.transform.position).z / (camera.farClipPlane-camera.nearClipPlane);
|
||||
}
|
||||
|
||||
function OnRenderImage (source : RenderTexture, destination : RenderTexture) {
|
||||
if(CheckResources () == false) {
|
||||
Graphics.Blit (source, destination);
|
||||
return;
|
||||
}
|
||||
|
||||
var i : int = 0;
|
||||
var internalBlurWidth : float = maxBlurSize;
|
||||
var blurRtDivider : int = blurResolution == BlurResolution.High ? 1 : 2;
|
||||
|
||||
// clamp values so they make sense
|
||||
|
||||
if (aperture < 0.0f) aperture = 0.0f;
|
||||
if (maxBlurSize < 0.0f) maxBlurSize = 0.0f;
|
||||
focalSize = Mathf.Clamp(focalSize, 0.0f, 0.3f);
|
||||
|
||||
// focal & coc calculations
|
||||
|
||||
focalDistance01 = focalTransform ? (camera.WorldToViewportPoint (focalTransform.position)).z / (camera.farClipPlane) : FocalDistance01 (focalLength);
|
||||
|
||||
var isInHdr : boolean = source.format == RenderTextureFormat.ARGBHalf;
|
||||
|
||||
var scene : RenderTexture = blurRtDivider > 1 ? RenderTexture.GetTemporary (source.width/blurRtDivider, source.height/blurRtDivider, 0, source.format) : null;
|
||||
if (scene) scene.filterMode = FilterMode.Bilinear;
|
||||
var rtLow : RenderTexture = RenderTexture.GetTemporary (source.width/(2*blurRtDivider), source.height/(2*blurRtDivider), 0, source.format);
|
||||
var rtLow2 : RenderTexture = RenderTexture.GetTemporary (source.width/(2*blurRtDivider), source.height/(2*blurRtDivider), 0, source.format);
|
||||
if (rtLow) rtLow.filterMode = FilterMode.Bilinear;
|
||||
if (rtLow2) rtLow2.filterMode = FilterMode.Bilinear;
|
||||
|
||||
dofHdrMaterial.SetVector ("_CurveParams", Vector4 (0.0f, focalSize, aperture/10.0f, focalDistance01));
|
||||
|
||||
// foreground blur
|
||||
|
||||
if (foregroundBlur) {
|
||||
var rtLowTmp : RenderTexture = RenderTexture.GetTemporary (source.width/(2*blurRtDivider), source.height/(2*blurRtDivider), 0, source.format);
|
||||
|
||||
// Capture foreground CoC only in alpha channel and increase CoC radius
|
||||
Graphics.Blit (source, rtLow2, dofHdrMaterial, 4);
|
||||
dofHdrMaterial.SetTexture("_FgOverlap", rtLow2);
|
||||
|
||||
var fgAdjustment : float = internalBlurWidth * foregroundOverlap * 0.225f;
|
||||
dofHdrMaterial.SetVector ("_Offsets", Vector4 (0.0f, fgAdjustment , 0.0f, fgAdjustment));
|
||||
Graphics.Blit (rtLow2, rtLowTmp, dofHdrMaterial, 2);
|
||||
dofHdrMaterial.SetVector ("_Offsets", Vector4 (fgAdjustment, 0.0f, 0.0f, fgAdjustment));
|
||||
Graphics.Blit (rtLowTmp, rtLow, dofHdrMaterial, 2);
|
||||
|
||||
dofHdrMaterial.SetTexture("_FgOverlap", null); // NEW: not needed anymore
|
||||
// apply adjust FG coc back to high rez coc texture
|
||||
Graphics.Blit(rtLow, source, dofHdrMaterial, 7);
|
||||
|
||||
RenderTexture.ReleaseTemporary(rtLowTmp);
|
||||
}
|
||||
else
|
||||
dofHdrMaterial.SetTexture("_FgOverlap", null); // ugly FG overlaps as a result
|
||||
|
||||
// capture remaing CoC (fore & *background*)
|
||||
|
||||
Graphics.Blit (source, source, dofHdrMaterial, foregroundBlur ? 3 : 0);
|
||||
|
||||
var cocRt : RenderTexture = source;
|
||||
|
||||
if(blurRtDivider>1) {
|
||||
Graphics.Blit (source, scene, dofHdrMaterial, 6);
|
||||
cocRt = scene;
|
||||
}
|
||||
|
||||
// spawn a few low rez parts in high rez image to get a bigger blur
|
||||
// resulting quality is higher than directly blending preblurred buffers
|
||||
|
||||
Graphics.Blit(cocRt, rtLow2, dofHdrMaterial, 6);
|
||||
Graphics.Blit(rtLow2, cocRt, dofHdrMaterial, 8);
|
||||
|
||||
// blur and apply to color buffer
|
||||
|
||||
var blurPassNumber : int = 10;
|
||||
switch(blurQuality) {
|
||||
case BlurQuality.Low:
|
||||
blurPassNumber = blurRtDivider > 1 ? 13 : 10;
|
||||
break;
|
||||
case BlurQuality.Medium:
|
||||
blurPassNumber = blurRtDivider > 1 ? 12 : 11;
|
||||
break;
|
||||
case BlurQuality.High:
|
||||
blurPassNumber = blurRtDivider > 1 ? 15 : 14;
|
||||
break;
|
||||
default:
|
||||
Debug.Log("DOF couldn't find valid blur quality setting", transform);
|
||||
break;
|
||||
}
|
||||
|
||||
if(visualizeFocus) {
|
||||
Graphics.Blit (source, destination, dofHdrMaterial, 1);
|
||||
}
|
||||
else {
|
||||
dofHdrMaterial.SetVector ("_Offsets", Vector4 (0.0f, 0.0f , 0.0f, internalBlurWidth));
|
||||
dofHdrMaterial.SetTexture("_LowRez", cocRt); // only needed in low resolution profile. and then, ugh, we get an ugly transition from nonblur -> blur areas
|
||||
Graphics.Blit (source, destination, dofHdrMaterial, blurPassNumber);
|
||||
}
|
||||
|
||||
if(rtLow) RenderTexture.ReleaseTemporary(rtLow);
|
||||
if(rtLow2) RenderTexture.ReleaseTemporary(rtLow2);
|
||||
if(scene) RenderTexture.ReleaseTemporary(scene);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 80dab52fbf02a0f4e8d67625d6105000
|
||||
TextScriptImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,17 @@
|
|||
// Implements Edge Detection using a Roberts cross filter.
|
||||
|
||||
using UnityEngine;
|
||||
|
||||
[ExecuteInEditMode]
|
||||
[AddComponentMenu("Image Effects/Edge Detection (Color)")]
|
||||
public class EdgeDetectEffect : ImageEffectBase
|
||||
{
|
||||
public float threshold = 0.2F;
|
||||
|
||||
// Called by camera to apply image effect
|
||||
void OnRenderImage (RenderTexture source, RenderTexture destination)
|
||||
{
|
||||
material.SetFloat ("_Treshold", threshold * threshold);
|
||||
Graphics.Blit (source, destination, material);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 8d1ce50d1c6331d43ac0305078d3fc14
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,60 @@
|
|||
|
||||
#pragma strict
|
||||
|
||||
@script ExecuteInEditMode
|
||||
@script RequireComponent (Camera)
|
||||
@script AddComponentMenu ("Image Effects/Edge Detection (Geometry)")
|
||||
|
||||
enum EdgeDetectMode {
|
||||
Thin = 0,
|
||||
Thick = 1,
|
||||
}
|
||||
|
||||
class EdgeDetectEffectNormals extends PostEffectsBase {
|
||||
|
||||
public var mode : EdgeDetectMode = EdgeDetectMode.Thin;
|
||||
public var sensitivityDepth : float = 1.0;
|
||||
public var sensitivityNormals : float = 1.0;
|
||||
|
||||
public var edgesOnly : float = 0.0;
|
||||
public var edgesOnlyBgColor : Color = Color.white;
|
||||
|
||||
public var edgeDetectShader : Shader;
|
||||
private var edgeDetectMaterial : Material = null;
|
||||
|
||||
function CheckResources () : boolean {
|
||||
CheckSupport (true);
|
||||
|
||||
edgeDetectMaterial = CheckShaderAndCreateMaterial (edgeDetectShader,edgeDetectMaterial);
|
||||
|
||||
if(!isSupported)
|
||||
ReportAutoDisable ();
|
||||
return isSupported;
|
||||
}
|
||||
|
||||
@ImageEffectOpaque
|
||||
function OnRenderImage (source : RenderTexture, destination : RenderTexture) {
|
||||
if(CheckResources()==false) {
|
||||
Graphics.Blit (source, destination);
|
||||
return;
|
||||
}
|
||||
|
||||
var sensitivity : Vector2 = Vector2 (sensitivityDepth, sensitivityNormals);
|
||||
|
||||
source.filterMode = FilterMode.Point;
|
||||
|
||||
edgeDetectMaterial.SetVector ("sensitivity", Vector4 (sensitivity.x, sensitivity.y, 1.0, sensitivity.y));
|
||||
edgeDetectMaterial.SetFloat ("_BgFade", edgesOnly);
|
||||
|
||||
var vecCol : Vector4 = edgesOnlyBgColor;
|
||||
edgeDetectMaterial.SetVector ("_BgColor", vecCol);
|
||||
|
||||
if (mode == EdgeDetectMode.Thin) {
|
||||
Graphics.Blit (source, destination, edgeDetectMaterial, 0);
|
||||
}
|
||||
else {
|
||||
Graphics.Blit (source, destination, edgeDetectMaterial, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
fileFormatVersion: 2
|
||||
guid: a06c3e0053862f74cbc83978002c2e72
|
||||
TextScriptImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,37 @@
|
|||
|
||||
#pragma strict
|
||||
|
||||
@script ExecuteInEditMode
|
||||
@script RequireComponent (Camera)
|
||||
@script AddComponentMenu ("Image Effects/Fisheye")
|
||||
|
||||
class Fisheye extends PostEffectsBase {
|
||||
public var strengthX : float = 0.05f;
|
||||
public var strengthY : float = 0.05f;
|
||||
|
||||
public var fishEyeShader : Shader = null;
|
||||
private var fisheyeMaterial : Material = null;
|
||||
|
||||
function CheckResources () : boolean {
|
||||
CheckSupport (false);
|
||||
fisheyeMaterial = CheckShaderAndCreateMaterial(fishEyeShader,fisheyeMaterial);
|
||||
|
||||
if(!isSupported)
|
||||
ReportAutoDisable ();
|
||||
return isSupported;
|
||||
}
|
||||
|
||||
function OnRenderImage (source : RenderTexture, destination : RenderTexture) {
|
||||
if(CheckResources()==false) {
|
||||
Graphics.Blit (source, destination);
|
||||
return;
|
||||
}
|
||||
|
||||
var oneOverBaseSize : float = 80.0f / 512.0f; // to keep values more like in the old version of fisheye
|
||||
|
||||
var ar : float = (source.width * 1.0f) / (source.height * 1.0f);
|
||||
|
||||
fisheyeMaterial.SetVector ("intensity", Vector4 (strengthX * ar * oneOverBaseSize, strengthY * oneOverBaseSize, strengthX * ar * oneOverBaseSize, strengthY * oneOverBaseSize));
|
||||
Graphics.Blit (source, destination, fisheyeMaterial);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 458e4343d76766e45b91208a4e03cdb9
|
||||
TextScriptImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,125 @@
|
|||
|
||||
#pragma strict
|
||||
|
||||
@script ExecuteInEditMode
|
||||
@script RequireComponent (Camera)
|
||||
@script AddComponentMenu ("Image Effects/Global Fog")
|
||||
|
||||
class GlobalFog extends PostEffectsBase {
|
||||
|
||||
enum FogMode {
|
||||
AbsoluteYAndDistance = 0,
|
||||
AbsoluteY = 1,
|
||||
Distance = 2,
|
||||
RelativeYAndDistance = 3,
|
||||
}
|
||||
|
||||
public var fogMode : FogMode = FogMode.AbsoluteYAndDistance;
|
||||
|
||||
private var CAMERA_NEAR : float = 0.5f;
|
||||
private var CAMERA_FAR : float = 50.0f;
|
||||
private var CAMERA_FOV : float = 60.0f;
|
||||
private var CAMERA_ASPECT_RATIO : float = 1.333333f;
|
||||
|
||||
public var startDistance : float = 200.0f;
|
||||
public var globalDensity : float = 1.0f;
|
||||
public var heightScale : float = 100.0f;
|
||||
public var height : float = 0.0f;
|
||||
|
||||
public var globalFogColor : Color = Color.grey;
|
||||
|
||||
public var fogShader : Shader;
|
||||
private var fogMaterial : Material = null;
|
||||
|
||||
function CheckResources () : boolean {
|
||||
CheckSupport (true);
|
||||
|
||||
fogMaterial = CheckShaderAndCreateMaterial (fogShader, fogMaterial);
|
||||
|
||||
if(!isSupported)
|
||||
ReportAutoDisable ();
|
||||
return isSupported;
|
||||
}
|
||||
|
||||
function OnRenderImage (source : RenderTexture, destination : RenderTexture) {
|
||||
if(CheckResources()==false) {
|
||||
Graphics.Blit (source, destination);
|
||||
return;
|
||||
}
|
||||
|
||||
CAMERA_NEAR = camera.nearClipPlane;
|
||||
CAMERA_FAR = camera.farClipPlane;
|
||||
CAMERA_FOV = camera.fieldOfView;
|
||||
CAMERA_ASPECT_RATIO = camera.aspect;
|
||||
|
||||
var frustumCorners : Matrix4x4 = Matrix4x4.identity;
|
||||
var vec : Vector4;
|
||||
var corner : Vector3;
|
||||
|
||||
var fovWHalf : float = CAMERA_FOV * 0.5f;
|
||||
|
||||
var toRight : Vector3 = camera.transform.right * CAMERA_NEAR * Mathf.Tan (fovWHalf * Mathf.Deg2Rad) * CAMERA_ASPECT_RATIO;
|
||||
var toTop : Vector3 = camera.transform.up * CAMERA_NEAR * Mathf.Tan (fovWHalf * Mathf.Deg2Rad);
|
||||
|
||||
var topLeft : Vector3 = (camera.transform.forward * CAMERA_NEAR - toRight + toTop);
|
||||
var CAMERA_SCALE : float = topLeft.magnitude * CAMERA_FAR/CAMERA_NEAR;
|
||||
|
||||
topLeft.Normalize();
|
||||
topLeft *= CAMERA_SCALE;
|
||||
|
||||
var topRight : Vector3 = (camera.transform.forward * CAMERA_NEAR + toRight + toTop);
|
||||
topRight.Normalize();
|
||||
topRight *= CAMERA_SCALE;
|
||||
|
||||
var bottomRight : Vector3 = (camera.transform.forward * CAMERA_NEAR + toRight - toTop);
|
||||
bottomRight.Normalize();
|
||||
bottomRight *= CAMERA_SCALE;
|
||||
|
||||
var bottomLeft : Vector3 = (camera.transform.forward * CAMERA_NEAR - toRight - toTop);
|
||||
bottomLeft.Normalize();
|
||||
bottomLeft *= CAMERA_SCALE;
|
||||
|
||||
frustumCorners.SetRow (0, topLeft);
|
||||
frustumCorners.SetRow (1, topRight);
|
||||
frustumCorners.SetRow (2, bottomRight);
|
||||
frustumCorners.SetRow (3, bottomLeft);
|
||||
|
||||
fogMaterial.SetMatrix ("_FrustumCornersWS", frustumCorners);
|
||||
fogMaterial.SetVector ("_CameraWS", camera.transform.position);
|
||||
fogMaterial.SetVector ("_StartDistance", Vector4 (1.0f / startDistance, (CAMERA_SCALE-startDistance)));
|
||||
fogMaterial.SetVector ("_Y", Vector4 (height, 1.0f / heightScale));
|
||||
|
||||
fogMaterial.SetFloat ("_GlobalDensity", globalDensity * 0.01f);
|
||||
fogMaterial.SetColor ("_FogColor", globalFogColor);
|
||||
|
||||
CustomGraphicsBlit (source, destination, fogMaterial, fogMode);
|
||||
}
|
||||
|
||||
static function CustomGraphicsBlit (source : RenderTexture, dest : RenderTexture, fxMaterial : Material, passNr : int) {
|
||||
RenderTexture.active = dest;
|
||||
|
||||
fxMaterial.SetTexture ("_MainTex", source);
|
||||
|
||||
GL.PushMatrix ();
|
||||
GL.LoadOrtho ();
|
||||
|
||||
fxMaterial.SetPass (passNr);
|
||||
|
||||
GL.Begin (GL.QUADS);
|
||||
|
||||
GL.MultiTexCoord2 (0, 0.0f, 0.0f);
|
||||
GL.Vertex3 (0.0f, 0.0f, 3.0f); // BL
|
||||
|
||||
GL.MultiTexCoord2 (0, 1.0f, 0.0f);
|
||||
GL.Vertex3 (1.0f, 0.0f, 2.0f); // BR
|
||||
|
||||
GL.MultiTexCoord2 (0, 1.0f, 1.0f);
|
||||
GL.Vertex3 (1.0f, 1.0f, 1.0f); // TR
|
||||
|
||||
GL.MultiTexCoord2 (0, 0.0f, 1.0f);
|
||||
GL.Vertex3 (0.0f, 1.0f, 0.0); // TL
|
||||
|
||||
GL.End ();
|
||||
GL.PopMatrix ();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 9a8496efbef64f64e90b11e233b1e7c4
|
||||
TextScriptImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
File diff suppressed because one or more lines are too long
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 662d99c7569802446a90664ce8e8d42d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,15 @@
|
|||
using UnityEngine;
|
||||
|
||||
[ExecuteInEditMode]
|
||||
[AddComponentMenu("Image Effects/Grayscale")]
|
||||
public class GrayscaleEffect : ImageEffectBase {
|
||||
public Texture textureRamp;
|
||||
public float rampOffset;
|
||||
|
||||
// Called by camera to apply image effect
|
||||
void OnRenderImage (RenderTexture source, RenderTexture destination) {
|
||||
material.SetTexture("_RampTex", textureRamp);
|
||||
material.SetFloat("_RampOffset", rampOffset);
|
||||
Graphics.Blit (source, destination, material);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: d24a424b799e2b24e884848e88b34c0a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,40 @@
|
|||
using UnityEngine;
|
||||
|
||||
[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 );
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 6b2e96fa5fab0044f90e9f1a8715b596
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,37 @@
|
|||
using UnityEngine;
|
||||
//using System;
|
||||
|
||||
/// 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);
|
||||
}
|
||||
|
||||
[System.Obsolete("Use Graphics.Blit(source,dest) instead")]
|
||||
public static void Blit(RenderTexture source, RenderTexture dest)
|
||||
{
|
||||
Graphics.Blit(source, dest);
|
||||
}
|
||||
|
||||
[System.Obsolete("Use Graphics.Blit(source, destination, material) instead")]
|
||||
public static void BlitWithMaterial(Material material, RenderTexture source, RenderTexture dest)
|
||||
{
|
||||
Graphics.Blit(source, dest, material);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 644202adf8f0ce34cb20fe20ab74fdf4
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,67 @@
|
|||
using UnityEngine;
|
||||
|
||||
// This class implements simple ghosting type Motion Blur.
|
||||
// If Extra Blur is selected, the scene will allways be a little blurred,
|
||||
// as it is scaled to a smaller resolution.
|
||||
// The effect works by accumulating the previous frames in an accumulation
|
||||
// texture.
|
||||
[ExecuteInEditMode]
|
||||
[AddComponentMenu("Image Effects/Motion Blur (Color Accumulation)")]
|
||||
[RequireComponent(typeof(Camera))]
|
||||
|
||||
public class MotionBlur : ImageEffectBase
|
||||
{
|
||||
public float blurAmount = 0.8f;
|
||||
public bool extraBlur = false;
|
||||
|
||||
private RenderTexture accumTexture;
|
||||
|
||||
override protected void Start()
|
||||
{
|
||||
if(!SystemInfo.supportsRenderTextures)
|
||||
{
|
||||
enabled = false;
|
||||
return;
|
||||
}
|
||||
base.Start();
|
||||
}
|
||||
|
||||
override protected void OnDisable()
|
||||
{
|
||||
base.OnDisable();
|
||||
DestroyImmediate(accumTexture);
|
||||
}
|
||||
|
||||
// Called by camera to apply image effect
|
||||
void OnRenderImage (RenderTexture source, RenderTexture destination)
|
||||
{
|
||||
// Create the accumulation texture
|
||||
if (accumTexture == null || accumTexture.width != source.width || accumTexture.height != source.height)
|
||||
{
|
||||
DestroyImmediate(accumTexture);
|
||||
accumTexture = new RenderTexture(source.width, source.height, 0);
|
||||
accumTexture.hideFlags = HideFlags.HideAndDontSave;
|
||||
Graphics.Blit( source, accumTexture );
|
||||
}
|
||||
|
||||
// If Extra Blur is selected, downscale the texture to 4x4 smaller resolution.
|
||||
if (extraBlur)
|
||||
{
|
||||
RenderTexture blurbuffer = RenderTexture.GetTemporary(source.width/4, source.height/4, 0);
|
||||
Graphics.Blit(accumTexture, blurbuffer);
|
||||
Graphics.Blit(blurbuffer,accumTexture);
|
||||
RenderTexture.ReleaseTemporary(blurbuffer);
|
||||
}
|
||||
|
||||
// Clamp the motion blur variable, so it can never leave permanent trails in the image
|
||||
blurAmount = Mathf.Clamp( blurAmount, 0.0f, 0.92f );
|
||||
|
||||
// Setup the texture and floating point values in the shader
|
||||
material.SetTexture("_MainTex", accumTexture);
|
||||
material.SetFloat("_AccumOrig", 1.0F-blurAmount);
|
||||
|
||||
// Render the image using the motion blur shader
|
||||
Graphics.Blit (source, accumTexture, material);
|
||||
Graphics.Blit (accumTexture, destination);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 9ee02d8f8d9b97b4cbaad7fc8aaca038
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,107 @@
|
|||
|
||||
#pragma strict
|
||||
|
||||
@script ExecuteInEditMode
|
||||
@script RequireComponent (Camera)
|
||||
@script AddComponentMenu ("Image Effects/Noise And Grain (Overlay)")
|
||||
|
||||
class NoiseAndGrain extends PostEffectsBase {
|
||||
|
||||
public var strength : float = 1.0f;
|
||||
public var blackIntensity : float = 1.0f;
|
||||
public var whiteIntensity : float = 1.0f;
|
||||
|
||||
public var redChannelNoise : float = 0.975f;
|
||||
public var greenChannelNoise : float = 0.875f;
|
||||
public var blueChannelNoise : float = 1.2f;
|
||||
|
||||
public var redChannelTiling : float = 24.0f;
|
||||
public var greenChannelTiling : float = 28.0f;
|
||||
public var blueChannelTiling : float = 34.0f;
|
||||
|
||||
public var filterMode : FilterMode = FilterMode.Bilinear;
|
||||
|
||||
public var noiseShader : Shader;
|
||||
public var noiseTexture : Texture2D;
|
||||
|
||||
private var noiseMaterial : Material = null;
|
||||
|
||||
function CheckResources () : boolean {
|
||||
CheckSupport (false);
|
||||
|
||||
noiseMaterial = CheckShaderAndCreateMaterial (noiseShader, noiseMaterial);
|
||||
|
||||
if(!isSupported)
|
||||
ReportAutoDisable ();
|
||||
return isSupported;
|
||||
}
|
||||
|
||||
function OnRenderImage (source : RenderTexture, destination : RenderTexture) {
|
||||
if(CheckResources()==false) {
|
||||
Graphics.Blit (source, destination);
|
||||
return;
|
||||
}
|
||||
|
||||
noiseMaterial.SetVector ("_NoisePerChannel", Vector3(redChannelNoise, greenChannelNoise, blueChannelNoise));
|
||||
noiseMaterial.SetVector ("_NoiseTilingPerChannel", Vector3(redChannelTiling, greenChannelTiling, blueChannelTiling));
|
||||
noiseMaterial.SetVector ("_NoiseAmount", Vector3(strength, blackIntensity, whiteIntensity));
|
||||
noiseMaterial.SetTexture ("_NoiseTex", noiseTexture);
|
||||
noiseTexture.filterMode = filterMode;
|
||||
|
||||
DrawNoiseQuadGrid (source, destination, noiseMaterial, noiseTexture, 0);
|
||||
}
|
||||
|
||||
static function DrawNoiseQuadGrid (source : RenderTexture, dest : RenderTexture, fxMaterial : Material, noise : Texture2D, passNr : int) {
|
||||
RenderTexture.active = dest;
|
||||
|
||||
var noiseSize : float = (noise.width * 1.0f);
|
||||
|
||||
var tileSize : float = noiseSize;
|
||||
|
||||
var subDs : float = (1.0f * source.width) / tileSize;
|
||||
|
||||
fxMaterial.SetTexture ("_MainTex", source);
|
||||
|
||||
GL.PushMatrix ();
|
||||
GL.LoadOrtho ();
|
||||
|
||||
var aspectCorrection : float = (1.0f * source.width) / (1.0f * source.height);
|
||||
var stepSizeX : float = 1.0f / subDs;
|
||||
var stepSizeY : float = stepSizeX * aspectCorrection;
|
||||
var texTile : float = tileSize / (noise.width * 1.0f);
|
||||
|
||||
fxMaterial.SetPass (passNr);
|
||||
|
||||
GL.Begin (GL.QUADS);
|
||||
|
||||
for (var x1 : float = 0.0; x1 < 1.0; x1 += stepSizeX) {
|
||||
for (var y1 : float = 0.0; y1 < 1.0; y1 += stepSizeY) {
|
||||
|
||||
var tcXStart : float = Random.Range (0.0f, 1.0f);
|
||||
var tcYStart : float = Random.Range (0.0f, 1.0f);
|
||||
|
||||
tcXStart = Mathf.Floor(tcXStart*noiseSize) / noiseSize;
|
||||
tcYStart = Mathf.Floor(tcYStart*noiseSize) / noiseSize;
|
||||
|
||||
//var texTileMod : float = Mathf.Sign (Random.Range (-1.0f, 1.0f));
|
||||
var texTileMod : float = 1.0f / noiseSize;
|
||||
|
||||
GL.MultiTexCoord2 (0, tcXStart, tcYStart);
|
||||
GL.MultiTexCoord2 (1, 0.0f, 0.0f);
|
||||
GL.Vertex3 (x1, y1, 0.1);
|
||||
GL.MultiTexCoord2 (0, tcXStart + texTile * texTileMod, tcYStart);
|
||||
GL.MultiTexCoord2 (1, 1.0f, 0.0f);
|
||||
GL.Vertex3 (x1 + stepSizeX, y1, 0.1);
|
||||
GL.MultiTexCoord2 (0, tcXStart + texTile * texTileMod, tcYStart + texTile * texTileMod);
|
||||
GL.MultiTexCoord2 (1, 1.0f, 1.0f);
|
||||
GL.Vertex3 (x1 + stepSizeX, y1 + stepSizeY, 0.1);
|
||||
GL.MultiTexCoord2 (0, tcXStart, tcYStart + texTile * texTileMod);
|
||||
GL.MultiTexCoord2 (1, 0.0f, 1.0f);
|
||||
GL.Vertex3 (x1, y1 + stepSizeY, 0.1);
|
||||
}
|
||||
}
|
||||
|
||||
GL.End ();
|
||||
GL.PopMatrix ();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 06fa8d3070985a947ad07f3794aa66f7
|
||||
TextScriptImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,130 @@
|
|||
using UnityEngine;
|
||||
|
||||
[ExecuteInEditMode]
|
||||
[RequireComponent (typeof(Camera))]
|
||||
[AddComponentMenu("Image Effects/Noise")]
|
||||
public class NoiseEffect : MonoBehaviour
|
||||
{
|
||||
/// Monochrome noise just adds grain. Non-monochrome noise
|
||||
/// more resembles VCR as it adds noise in YUV color space,
|
||||
/// thus introducing magenta/green colors.
|
||||
public bool monochrome = true;
|
||||
private bool rgbFallback = false;
|
||||
|
||||
// Noise grain takes random intensity from Min to Max.
|
||||
public float grainIntensityMin = 0.1f;
|
||||
public float grainIntensityMax = 0.2f;
|
||||
|
||||
/// The size of the noise grains (1 = one pixel).
|
||||
public float grainSize = 2.0f;
|
||||
|
||||
// Scratches take random intensity from Min to Max.
|
||||
public float scratchIntensityMin = 0.05f;
|
||||
public float scratchIntensityMax = 0.25f;
|
||||
|
||||
/// Scratches jump to another locations at this times per second.
|
||||
public float scratchFPS = 10.0f;
|
||||
/// While scratches are in the same location, they jitter a bit.
|
||||
public float scratchJitter = 0.01f;
|
||||
|
||||
public Texture grainTexture;
|
||||
public Texture scratchTexture;
|
||||
public Shader shaderRGB;
|
||||
public Shader shaderYUV;
|
||||
private Material m_MaterialRGB;
|
||||
private Material m_MaterialYUV;
|
||||
|
||||
private float scratchTimeLeft = 0.0f;
|
||||
private float scratchX, scratchY;
|
||||
|
||||
protected void Start ()
|
||||
{
|
||||
// Disable if we don't support image effects
|
||||
if (!SystemInfo.supportsImageEffects) {
|
||||
enabled = false;
|
||||
return;
|
||||
}
|
||||
|
||||
if( shaderRGB == null || shaderYUV == null )
|
||||
{
|
||||
Debug.Log( "Noise shaders are not set up! Disabling noise effect." );
|
||||
enabled = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
if( !shaderRGB.isSupported ) // disable effect if RGB shader is not supported
|
||||
enabled = false;
|
||||
else if( !shaderYUV.isSupported ) // fallback to RGB if YUV is not supported
|
||||
rgbFallback = true;
|
||||
}
|
||||
}
|
||||
|
||||
protected Material material {
|
||||
get {
|
||||
if( m_MaterialRGB == null ) {
|
||||
m_MaterialRGB = new Material( shaderRGB );
|
||||
m_MaterialRGB.hideFlags = HideFlags.HideAndDontSave;
|
||||
}
|
||||
if( m_MaterialYUV == null && !rgbFallback ) {
|
||||
m_MaterialYUV = new Material( shaderYUV );
|
||||
m_MaterialYUV.hideFlags = HideFlags.HideAndDontSave;
|
||||
}
|
||||
return (!rgbFallback && !monochrome) ? m_MaterialYUV : m_MaterialRGB;
|
||||
}
|
||||
}
|
||||
|
||||
protected void OnDisable() {
|
||||
if( m_MaterialRGB )
|
||||
DestroyImmediate( m_MaterialRGB );
|
||||
if( m_MaterialYUV )
|
||||
DestroyImmediate( m_MaterialYUV );
|
||||
}
|
||||
|
||||
private void SanitizeParameters()
|
||||
{
|
||||
grainIntensityMin = Mathf.Clamp( grainIntensityMin, 0.0f, 5.0f );
|
||||
grainIntensityMax = Mathf.Clamp( grainIntensityMax, 0.0f, 5.0f );
|
||||
scratchIntensityMin = Mathf.Clamp( scratchIntensityMin, 0.0f, 5.0f );
|
||||
scratchIntensityMax = Mathf.Clamp( scratchIntensityMax, 0.0f, 5.0f );
|
||||
scratchFPS = Mathf.Clamp( scratchFPS, 1, 30 );
|
||||
scratchJitter = Mathf.Clamp( scratchJitter, 0.0f, 1.0f );
|
||||
grainSize = Mathf.Clamp( grainSize, 0.1f, 50.0f );
|
||||
}
|
||||
|
||||
// Called by the camera to apply the image effect
|
||||
void OnRenderImage (RenderTexture source, RenderTexture destination)
|
||||
{
|
||||
SanitizeParameters();
|
||||
|
||||
if( scratchTimeLeft <= 0.0f )
|
||||
{
|
||||
scratchTimeLeft = Random.value * 2 / scratchFPS; // we have sanitized it earlier, won't be zero
|
||||
scratchX = Random.value;
|
||||
scratchY = Random.value;
|
||||
}
|
||||
scratchTimeLeft -= Time.deltaTime;
|
||||
|
||||
Material mat = material;
|
||||
|
||||
mat.SetTexture("_GrainTex", grainTexture);
|
||||
mat.SetTexture("_ScratchTex", scratchTexture);
|
||||
float grainScale = 1.0f / grainSize; // we have sanitized it earlier, won't be zero
|
||||
mat.SetVector("_GrainOffsetScale", new Vector4(
|
||||
Random.value,
|
||||
Random.value,
|
||||
(float)Screen.width / (float)grainTexture.width * grainScale,
|
||||
(float)Screen.height / (float)grainTexture.height * grainScale
|
||||
));
|
||||
mat.SetVector("_ScratchOffsetScale", new Vector4(
|
||||
scratchX + Random.value*scratchJitter,
|
||||
scratchY + Random.value*scratchJitter,
|
||||
(float)Screen.width / (float) scratchTexture.width,
|
||||
(float)Screen.height / (float) scratchTexture.height
|
||||
));
|
||||
mat.SetVector("_Intensity", new Vector4(
|
||||
Random.Range(grainIntensityMin, grainIntensityMax),
|
||||
Random.Range(scratchIntensityMin, scratchIntensityMax),
|
||||
0, 0 ));
|
||||
Graphics.Blit (source, destination, mat);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 7228eabf28cb40544b940e00cd9d42cd
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,204 @@
|
|||
|
||||
#pragma strict
|
||||
|
||||
@script ExecuteInEditMode
|
||||
@script RequireComponent (Camera)
|
||||
|
||||
class PostEffectsBase extends MonoBehaviour {
|
||||
protected var supportHDRTextures : boolean = true;
|
||||
protected var isSupported : boolean = true;
|
||||
|
||||
function CheckShaderAndCreateMaterial (s : Shader, m2Create : Material) : Material {
|
||||
if (!s) {
|
||||
Debug.Log("Missing shader in " + this.ToString ());
|
||||
enabled = false;
|
||||
return null;
|
||||
}
|
||||
|
||||
if (s.isSupported && m2Create && m2Create.shader == s)
|
||||
return m2Create;
|
||||
|
||||
if (!s.isSupported) {
|
||||
NotSupported ();
|
||||
Debug.LogError("The shader " + s.ToString() + " on effect "+this.ToString()+" is not supported on this platform!");
|
||||
return null;
|
||||
}
|
||||
else {
|
||||
m2Create = new Material (s);
|
||||
m2Create.hideFlags = HideFlags.DontSave;
|
||||
if (m2Create)
|
||||
return m2Create;
|
||||
else return null;
|
||||
}
|
||||
}
|
||||
|
||||
function CreateMaterial (s : Shader, m2Create : Material) : Material {
|
||||
if (!s) {
|
||||
Debug.Log ("Missing shader in " + this.ToString ());
|
||||
return null;
|
||||
}
|
||||
|
||||
if (m2Create && (m2Create.shader == s) && (s.isSupported))
|
||||
return m2Create;
|
||||
|
||||
if (!s.isSupported) {
|
||||
return null;
|
||||
}
|
||||
else {
|
||||
m2Create = new Material (s);
|
||||
m2Create.hideFlags = HideFlags.DontSave;
|
||||
if (m2Create)
|
||||
return m2Create;
|
||||
else return null;
|
||||
}
|
||||
}
|
||||
|
||||
function OnEnable() {
|
||||
isSupported = true;
|
||||
}
|
||||
|
||||
// deprecated but needed for old effects to survive upgrade
|
||||
function CheckSupport () : boolean {
|
||||
return CheckSupport (false);
|
||||
}
|
||||
|
||||
function CheckResources () : boolean {
|
||||
Debug.LogWarning ("CheckResources () for " + this.ToString() + " should be overwritten.");
|
||||
return isSupported;
|
||||
}
|
||||
|
||||
function Start () {
|
||||
CheckResources ();
|
||||
}
|
||||
|
||||
function CheckSupport (needDepth : boolean) : boolean {
|
||||
isSupported = true;
|
||||
supportHDRTextures = SystemInfo.SupportsRenderTextureFormat(RenderTextureFormat.ARGBHalf);
|
||||
|
||||
if (!SystemInfo.supportsImageEffects || !SystemInfo.supportsRenderTextures) {
|
||||
NotSupported ();
|
||||
return false;
|
||||
}
|
||||
|
||||
if(needDepth && !SystemInfo.SupportsRenderTextureFormat (RenderTextureFormat.Depth)) {
|
||||
NotSupported ();
|
||||
return false;
|
||||
}
|
||||
|
||||
if(needDepth)
|
||||
camera.depthTextureMode |= DepthTextureMode.Depth;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
function CheckSupport (needDepth : boolean, needHdr : boolean) : boolean {
|
||||
if(!CheckSupport(needDepth))
|
||||
return false;
|
||||
|
||||
if(needHdr && !supportHDRTextures) {
|
||||
NotSupported ();
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
function ReportAutoDisable () {
|
||||
Debug.LogWarning ("The image effect " + this.ToString() + " has been disabled as it's not supported on the current platform.");
|
||||
}
|
||||
|
||||
// deprecated but needed for old effects to survive upgrading
|
||||
function CheckShader (s : Shader) : boolean {
|
||||
Debug.Log("The shader " + s.ToString () + " on effect "+ this.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;
|
||||
}
|
||||
}
|
||||
|
||||
function NotSupported () {
|
||||
enabled = false;
|
||||
isSupported = false;
|
||||
return;
|
||||
}
|
||||
|
||||
function DrawBorder (dest : RenderTexture, material : Material ) {
|
||||
var x1 : float;
|
||||
var x2 : float;
|
||||
var y1 : float;
|
||||
var y2 : float;
|
||||
|
||||
RenderTexture.active = dest;
|
||||
var invertY : boolean = true; // source.texelSize.y < 0.0f;
|
||||
// Set up the simple Matrix
|
||||
GL.PushMatrix();
|
||||
GL.LoadOrtho();
|
||||
|
||||
for (var i : int = 0; i < material.passCount; i++)
|
||||
{
|
||||
material.SetPass(i);
|
||||
|
||||
var y1_ : float; var y2_ : float;
|
||||
if (invertY)
|
||||
{
|
||||
y1_ = 1.0; y2_ = 0.0;
|
||||
}
|
||||
else
|
||||
{
|
||||
y1_ = 0.0; y2_ = 1.0;
|
||||
}
|
||||
|
||||
// left
|
||||
x1 = 0.0;
|
||||
x2 = 0.0 + 1.0/(dest.width*1.0);
|
||||
y1 = 0.0;
|
||||
y2 = 1.0;
|
||||
GL.Begin(GL.QUADS);
|
||||
|
||||
GL.TexCoord2(0.0, y1_); GL.Vertex3(x1, y1, 0.1);
|
||||
GL.TexCoord2(1.0, y1_); GL.Vertex3(x2, y1, 0.1);
|
||||
GL.TexCoord2(1.0, y2_); GL.Vertex3(x2, y2, 0.1);
|
||||
GL.TexCoord2(0.0, y2_); GL.Vertex3(x1, y2, 0.1);
|
||||
|
||||
// right
|
||||
x1 = 1.0 - 1.0/(dest.width*1.0);
|
||||
x2 = 1.0;
|
||||
y1 = 0.0;
|
||||
y2 = 1.0;
|
||||
|
||||
GL.TexCoord2(0.0, y1_); GL.Vertex3(x1, y1, 0.1);
|
||||
GL.TexCoord2(1.0, y1_); GL.Vertex3(x2, y1, 0.1);
|
||||
GL.TexCoord2(1.0, y2_); GL.Vertex3(x2, y2, 0.1);
|
||||
GL.TexCoord2(0.0, y2_); GL.Vertex3(x1, y2, 0.1);
|
||||
|
||||
// top
|
||||
x1 = 0.0;
|
||||
x2 = 1.0;
|
||||
y1 = 0.0;
|
||||
y2 = 0.0 + 1.0/(dest.height*1.0);
|
||||
|
||||
GL.TexCoord2(0.0, y1_); GL.Vertex3(x1, y1, 0.1);
|
||||
GL.TexCoord2(1.0, y1_); GL.Vertex3(x2, y1, 0.1);
|
||||
GL.TexCoord2(1.0, y2_); GL.Vertex3(x2, y2, 0.1);
|
||||
GL.TexCoord2(0.0, y2_); GL.Vertex3(x1, y2, 0.1);
|
||||
|
||||
// bottom
|
||||
x1 = 0.0;
|
||||
x2 = 1.0;
|
||||
y1 = 1.0 - 1.0/(dest.height*1.0);
|
||||
y2 = 1.0;
|
||||
|
||||
GL.TexCoord2(0.0, y1_); GL.Vertex3(x1, y1, 0.1);
|
||||
GL.TexCoord2(1.0, y1_); GL.Vertex3(x2, y1, 0.1);
|
||||
GL.TexCoord2(1.0, y2_); GL.Vertex3(x2, y2, 0.1);
|
||||
GL.TexCoord2(0.0, y2_); GL.Vertex3(x1, y2, 0.1);
|
||||
|
||||
GL.End();
|
||||
}
|
||||
|
||||
GL.PopMatrix();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
fileFormatVersion: 2
|
||||
guid: a899b974b1f0a694386d51d8d4709160
|
||||
TextScriptImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,188 @@
|
|||
|
||||
@script ExecuteInEditMode
|
||||
@script RequireComponent (Camera)
|
||||
|
||||
class PostEffectsHelper extends MonoBehaviour
|
||||
{
|
||||
function Start () {
|
||||
|
||||
}
|
||||
|
||||
|
||||
function OnRenderImage (source : RenderTexture, destination : RenderTexture) {
|
||||
Debug.Log("OnRenderImage in Helper called ...");
|
||||
}
|
||||
|
||||
static function DrawLowLevelPlaneAlignedWithCamera(
|
||||
dist : float,
|
||||
source : RenderTexture, dest : RenderTexture,
|
||||
material : Material,
|
||||
cameraForProjectionMatrix : Camera )
|
||||
{
|
||||
// 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);
|
||||
var invertY : boolean = true; // source.texelSize.y < 0.0f;
|
||||
// Set up the simple Matrix
|
||||
GL.PushMatrix();
|
||||
GL.LoadIdentity();
|
||||
GL.LoadProjectionMatrix(cameraForProjectionMatrix.projectionMatrix);
|
||||
|
||||
var fovYHalfRad : float = cameraForProjectionMatrix.fieldOfView * 0.5 * Mathf.Deg2Rad;
|
||||
var cotangent : float = Mathf.Cos(fovYHalfRad) / Mathf.Sin(fovYHalfRad);
|
||||
var asp : float = cameraForProjectionMatrix.aspect;
|
||||
|
||||
var x1 : float = asp/-cotangent;
|
||||
var x2 : float = asp/cotangent;
|
||||
var y1 : float = 1.0/-cotangent;
|
||||
var y2 : float = 1.0/cotangent;
|
||||
|
||||
var sc : float = 1.0; // magic constant (for now)
|
||||
|
||||
x1 *= dist * sc;
|
||||
x2 *= dist * sc;
|
||||
y1 *= dist * sc;
|
||||
y2 *= dist * sc;
|
||||
|
||||
var z1 : float = -dist;
|
||||
|
||||
for (var i : int = 0; i < material.passCount; i++)
|
||||
{
|
||||
material.SetPass(i);
|
||||
|
||||
GL.Begin(GL.QUADS);
|
||||
var y1_ : float; var y2_ : float;
|
||||
if (invertY)
|
||||
{
|
||||
y1_ = 1.0; y2_ = 0.0;
|
||||
}
|
||||
else
|
||||
{
|
||||
y1_ = 0.0; y2_ = 1.0;
|
||||
}
|
||||
GL.TexCoord2(0.0, y1_); GL.Vertex3(x1, y1, z1);
|
||||
GL.TexCoord2(1.0, y1_); GL.Vertex3(x2, y1, z1);
|
||||
GL.TexCoord2(1.0, y2_); GL.Vertex3(x2, y2, z1);
|
||||
GL.TexCoord2(0.0, y2_); GL.Vertex3(x1, y2, z1);
|
||||
GL.End();
|
||||
}
|
||||
|
||||
GL.PopMatrix();
|
||||
}
|
||||
|
||||
static function DrawBorder (
|
||||
dest : RenderTexture,
|
||||
material : Material )
|
||||
{
|
||||
var x1 : float;
|
||||
var x2 : float;
|
||||
var y1 : float;
|
||||
var y2 : float;
|
||||
|
||||
RenderTexture.active = dest;
|
||||
var invertY : boolean = true; // source.texelSize.y < 0.0f;
|
||||
// Set up the simple Matrix
|
||||
GL.PushMatrix();
|
||||
GL.LoadOrtho();
|
||||
|
||||
for (var i : int = 0; i < material.passCount; i++)
|
||||
{
|
||||
material.SetPass(i);
|
||||
|
||||
var y1_ : float; var y2_ : float;
|
||||
if (invertY)
|
||||
{
|
||||
y1_ = 1.0; y2_ = 0.0;
|
||||
}
|
||||
else
|
||||
{
|
||||
y1_ = 0.0; y2_ = 1.0;
|
||||
}
|
||||
|
||||
// left
|
||||
x1 = 0.0;
|
||||
x2 = 0.0 + 1.0/(dest.width*1.0);
|
||||
y1 = 0.0;
|
||||
y2 = 1.0;
|
||||
GL.Begin(GL.QUADS);
|
||||
|
||||
GL.TexCoord2(0.0, y1_); GL.Vertex3(x1, y1, 0.1);
|
||||
GL.TexCoord2(1.0, y1_); GL.Vertex3(x2, y1, 0.1);
|
||||
GL.TexCoord2(1.0, y2_); GL.Vertex3(x2, y2, 0.1);
|
||||
GL.TexCoord2(0.0, y2_); GL.Vertex3(x1, y2, 0.1);
|
||||
|
||||
// right
|
||||
x1 = 1.0 - 1.0/(dest.width*1.0);
|
||||
x2 = 1.0;
|
||||
y1 = 0.0;
|
||||
y2 = 1.0;
|
||||
|
||||
GL.TexCoord2(0.0, y1_); GL.Vertex3(x1, y1, 0.1);
|
||||
GL.TexCoord2(1.0, y1_); GL.Vertex3(x2, y1, 0.1);
|
||||
GL.TexCoord2(1.0, y2_); GL.Vertex3(x2, y2, 0.1);
|
||||
GL.TexCoord2(0.0, y2_); GL.Vertex3(x1, y2, 0.1);
|
||||
|
||||
// top
|
||||
x1 = 0.0;
|
||||
x2 = 1.0;
|
||||
y1 = 0.0;
|
||||
y2 = 0.0 + 1.0/(dest.height*1.0);
|
||||
|
||||
GL.TexCoord2(0.0, y1_); GL.Vertex3(x1, y1, 0.1);
|
||||
GL.TexCoord2(1.0, y1_); GL.Vertex3(x2, y1, 0.1);
|
||||
GL.TexCoord2(1.0, y2_); GL.Vertex3(x2, y2, 0.1);
|
||||
GL.TexCoord2(0.0, y2_); GL.Vertex3(x1, y2, 0.1);
|
||||
|
||||
// bottom
|
||||
x1 = 0.0;
|
||||
x2 = 1.0;
|
||||
y1 = 1.0 - 1.0/(dest.height*1.0);
|
||||
y2 = 1.0;
|
||||
|
||||
GL.TexCoord2(0.0, y1_); GL.Vertex3(x1, y1, 0.1);
|
||||
GL.TexCoord2(1.0, y1_); GL.Vertex3(x2, y1, 0.1);
|
||||
GL.TexCoord2(1.0, y2_); GL.Vertex3(x2, y2, 0.1);
|
||||
GL.TexCoord2(0.0, y2_); GL.Vertex3(x1, y2, 0.1);
|
||||
|
||||
GL.End();
|
||||
}
|
||||
|
||||
GL.PopMatrix();
|
||||
}
|
||||
|
||||
static function DrawLowLevelQuad( x1 : float, x2 : float, y1 : float, y2 : float, source : RenderTexture, dest : RenderTexture, 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);
|
||||
var invertY : boolean = true; // source.texelSize.y < 0.0f;
|
||||
// Set up the simple Matrix
|
||||
GL.PushMatrix();
|
||||
GL.LoadOrtho();
|
||||
|
||||
for (var i : int = 0; i < material.passCount; i++)
|
||||
{
|
||||
material.SetPass(i);
|
||||
|
||||
GL.Begin(GL.QUADS);
|
||||
var y1_ : float; var y2_ : float;
|
||||
if (invertY)
|
||||
{
|
||||
y1_ = 1.0; y2_ = 0.0;
|
||||
}
|
||||
else
|
||||
{
|
||||
y1_ = 0.0; y2_ = 1.0;
|
||||
}
|
||||
GL.TexCoord2(0.0, y1_); GL.Vertex3(x1, y1, 0.1);
|
||||
GL.TexCoord2(1.0, y1_); GL.Vertex3(x2, y1, 0.1);
|
||||
GL.TexCoord2(1.0, y2_); GL.Vertex3(x2, y2, 0.1);
|
||||
GL.TexCoord2(0.0, y2_); GL.Vertex3(x1, y2, 0.1);
|
||||
GL.End();
|
||||
}
|
||||
|
||||
GL.PopMatrix();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
fileFormatVersion: 2
|
||||
guid: a5409280edc45e14dbd328ebd2c76d69
|
||||
TextScriptImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,115 @@
|
|||
|
||||
// same as Triangles but creates quads instead which generally
|
||||
// saves fillrate at the expense for more triangles to issue
|
||||
|
||||
#pragma strict
|
||||
|
||||
static var meshes : Mesh[];
|
||||
static var currentQuads : int = 0;
|
||||
|
||||
static function HasMeshes () : boolean {
|
||||
if (!meshes)
|
||||
return false;
|
||||
for (var m : Mesh in meshes)
|
||||
if (null == m)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static function Cleanup () {
|
||||
if (!meshes)
|
||||
return;
|
||||
|
||||
for (var m : Mesh in meshes) {
|
||||
if (null != m) {
|
||||
DestroyImmediate (m);
|
||||
m = null;
|
||||
}
|
||||
}
|
||||
meshes = null;
|
||||
}
|
||||
|
||||
static function GetMeshes (totalWidth : int, totalHeight : int) : Mesh[]
|
||||
{
|
||||
if (HasMeshes () && (currentQuads == (totalWidth * totalHeight))) {
|
||||
return meshes;
|
||||
}
|
||||
|
||||
var maxQuads : int = 65000 / 6;
|
||||
var totalQuads : int = totalWidth * totalHeight;
|
||||
currentQuads = totalQuads;
|
||||
|
||||
var meshCount : int = Mathf.CeilToInt ((1.0f * totalQuads) / (1.0f * maxQuads));
|
||||
|
||||
meshes = new Mesh [meshCount];
|
||||
|
||||
var i : int = 0;
|
||||
var index : int = 0;
|
||||
for (i = 0; i < totalQuads; i += maxQuads) {
|
||||
var quads : int = Mathf.FloorToInt (Mathf.Clamp ((totalQuads-i), 0, maxQuads));
|
||||
|
||||
meshes[index] = GetMesh (quads, i, totalWidth, totalHeight);
|
||||
index++;
|
||||
}
|
||||
|
||||
return meshes;
|
||||
}
|
||||
|
||||
static function GetMesh (triCount : int, triOffset : int, totalWidth : int, totalHeight : int) : Mesh
|
||||
{
|
||||
var mesh = new Mesh ();
|
||||
mesh.hideFlags = HideFlags.DontSave;
|
||||
|
||||
var verts : Vector3[] = new Vector3[triCount*4];
|
||||
var uvs : Vector2[] = new Vector2[triCount*4];
|
||||
var uvs2 : Vector2[] = new Vector2[triCount*4];
|
||||
var tris : int[] = new int[triCount*6];
|
||||
|
||||
var size : float = 0.0075f;
|
||||
|
||||
for (var i : int = 0; i < triCount; i++)
|
||||
{
|
||||
var i4 : int = i * 4;
|
||||
var i6 : int = i * 6;
|
||||
|
||||
var vertexWithOffset : int = triOffset + i;
|
||||
|
||||
var x : float = Mathf.Floor(vertexWithOffset % totalWidth) / totalWidth;
|
||||
var y : float = Mathf.Floor(vertexWithOffset / totalWidth) / totalHeight;
|
||||
|
||||
var position : Vector3 = Vector3 (x*2-1,y*2-1, 1.0);
|
||||
|
||||
verts[i4 + 0] = position;
|
||||
verts[i4 + 1] = position;
|
||||
verts[i4 + 2] = position;
|
||||
verts[i4 + 3] = position;
|
||||
|
||||
uvs[i4 + 0] = Vector2 (0.0f, 0.0f);
|
||||
uvs[i4 + 1] = Vector2 (1.0f, 0.0f);
|
||||
uvs[i4 + 2] = Vector2 (0.0f, 1.0f);
|
||||
uvs[i4 + 3] = Vector2 (1.0f, 1.0f);
|
||||
|
||||
uvs2[i4 + 0] = Vector2 (x, y);
|
||||
uvs2[i4 + 1] = Vector2 (x, y);
|
||||
uvs2[i4 + 2] = Vector2 (x, y);
|
||||
uvs2[i4 + 3] = 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;
|
||||
}
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 8b99781953624794c85d1c1426404ff4
|
||||
TextScriptImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,194 @@
|
|||
using UnityEngine;
|
||||
|
||||
[ExecuteInEditMode]
|
||||
[RequireComponent (typeof(Camera))]
|
||||
[AddComponentMenu("Image Effects/Screen Space Ambient Occlusion")]
|
||||
public class SSAOEffect : MonoBehaviour
|
||||
{
|
||||
public enum SSAOSamples {
|
||||
Low = 0,
|
||||
Medium = 1,
|
||||
High = 2,
|
||||
}
|
||||
|
||||
public float m_Radius = 0.4f;
|
||||
public SSAOSamples m_SampleCount = SSAOSamples.Medium;
|
||||
public float m_OcclusionIntensity = 1.5f;
|
||||
public int m_Blur = 2;
|
||||
public int m_Downsampling = 2;
|
||||
public float m_OcclusionAttenuation = 1.0f;
|
||||
public float m_MinZ = 0.01f;
|
||||
|
||||
public Shader m_SSAOShader;
|
||||
private Material m_SSAOMaterial;
|
||||
|
||||
public Texture2D m_RandomTexture;
|
||||
|
||||
private bool m_Supported;
|
||||
|
||||
private static Material CreateMaterial (Shader shader)
|
||||
{
|
||||
if (!shader)
|
||||
return null;
|
||||
Material m = new Material (shader);
|
||||
m.hideFlags = HideFlags.HideAndDontSave;
|
||||
return m;
|
||||
}
|
||||
private static void DestroyMaterial (Material mat)
|
||||
{
|
||||
if (mat)
|
||||
{
|
||||
DestroyImmediate (mat);
|
||||
mat = null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void OnDisable()
|
||||
{
|
||||
DestroyMaterial (m_SSAOMaterial);
|
||||
}
|
||||
|
||||
void Start()
|
||||
{
|
||||
if (!SystemInfo.supportsImageEffects || !SystemInfo.SupportsRenderTextureFormat (RenderTextureFormat.Depth))
|
||||
{
|
||||
m_Supported = false;
|
||||
enabled = false;
|
||||
return;
|
||||
}
|
||||
|
||||
CreateMaterials ();
|
||||
if (!m_SSAOMaterial || m_SSAOMaterial.passCount != 5)
|
||||
{
|
||||
m_Supported = false;
|
||||
enabled = false;
|
||||
return;
|
||||
}
|
||||
|
||||
//CreateRandomTable (26, 0.2f);
|
||||
|
||||
m_Supported = true;
|
||||
}
|
||||
|
||||
void OnEnable () {
|
||||
GetComponent<Camera>().depthTextureMode |= DepthTextureMode.DepthNormals;
|
||||
}
|
||||
|
||||
private void CreateMaterials ()
|
||||
{
|
||||
if (!m_SSAOMaterial && m_SSAOShader.isSupported)
|
||||
{
|
||||
m_SSAOMaterial = CreateMaterial (m_SSAOShader);
|
||||
m_SSAOMaterial.SetTexture ("_RandomTexture", m_RandomTexture);
|
||||
}
|
||||
}
|
||||
|
||||
[ImageEffectOpaque]
|
||||
void OnRenderImage (RenderTexture source, RenderTexture destination)
|
||||
{
|
||||
if (!m_Supported || !m_SSAOShader.isSupported) {
|
||||
enabled = false;
|
||||
return;
|
||||
}
|
||||
CreateMaterials ();
|
||||
|
||||
m_Downsampling = Mathf.Clamp (m_Downsampling, 1, 6);
|
||||
m_Radius = Mathf.Clamp (m_Radius, 0.05f, 1.0f);
|
||||
m_MinZ = Mathf.Clamp (m_MinZ, 0.00001f, 0.5f);
|
||||
m_OcclusionIntensity = Mathf.Clamp (m_OcclusionIntensity, 0.5f, 4.0f);
|
||||
m_OcclusionAttenuation = Mathf.Clamp (m_OcclusionAttenuation, 0.2f, 2.0f);
|
||||
m_Blur = Mathf.Clamp (m_Blur, 0, 4);
|
||||
|
||||
// Render SSAO term into a smaller texture
|
||||
RenderTexture rtAO = RenderTexture.GetTemporary (source.width / m_Downsampling, source.height / m_Downsampling, 0);
|
||||
float fovY = GetComponent<Camera>().fieldOfView;
|
||||
float far = GetComponent<Camera>().farClipPlane;
|
||||
float y = Mathf.Tan (fovY * Mathf.Deg2Rad * 0.5f) * far;
|
||||
float x = y * GetComponent<Camera>().aspect;
|
||||
m_SSAOMaterial.SetVector ("_FarCorner", new Vector3(x,y,far));
|
||||
int noiseWidth, noiseHeight;
|
||||
if (m_RandomTexture) {
|
||||
noiseWidth = m_RandomTexture.width;
|
||||
noiseHeight = m_RandomTexture.height;
|
||||
} else {
|
||||
noiseWidth = 1; noiseHeight = 1;
|
||||
}
|
||||
m_SSAOMaterial.SetVector ("_NoiseScale", new Vector3 ((float)rtAO.width / noiseWidth, (float)rtAO.height / noiseHeight, 0.0f));
|
||||
m_SSAOMaterial.SetVector ("_Params", new Vector4(
|
||||
m_Radius,
|
||||
m_MinZ,
|
||||
1.0f / m_OcclusionAttenuation,
|
||||
m_OcclusionIntensity));
|
||||
|
||||
bool doBlur = m_Blur > 0;
|
||||
Graphics.Blit (doBlur ? null : source, rtAO, m_SSAOMaterial, (int)m_SampleCount);
|
||||
|
||||
if (doBlur)
|
||||
{
|
||||
// Blur SSAO horizontally
|
||||
RenderTexture rtBlurX = RenderTexture.GetTemporary (source.width, source.height, 0);
|
||||
m_SSAOMaterial.SetVector ("_TexelOffsetScale",
|
||||
new Vector4 ((float)m_Blur / source.width, 0,0,0));
|
||||
m_SSAOMaterial.SetTexture ("_SSAO", rtAO);
|
||||
Graphics.Blit (null, rtBlurX, m_SSAOMaterial, 3);
|
||||
RenderTexture.ReleaseTemporary (rtAO); // original rtAO not needed anymore
|
||||
|
||||
// Blur SSAO vertically
|
||||
RenderTexture rtBlurY = RenderTexture.GetTemporary (source.width, source.height, 0);
|
||||
m_SSAOMaterial.SetVector ("_TexelOffsetScale",
|
||||
new Vector4 (0, (float)m_Blur/source.height, 0,0));
|
||||
m_SSAOMaterial.SetTexture ("_SSAO", rtBlurX);
|
||||
Graphics.Blit (source, rtBlurY, m_SSAOMaterial, 3);
|
||||
RenderTexture.ReleaseTemporary (rtBlurX); // blurX RT not needed anymore
|
||||
|
||||
rtAO = rtBlurY; // AO is the blurred one now
|
||||
}
|
||||
|
||||
// Modulate scene rendering with SSAO
|
||||
m_SSAOMaterial.SetTexture ("_SSAO", rtAO);
|
||||
Graphics.Blit (source, destination, m_SSAOMaterial, 4);
|
||||
|
||||
RenderTexture.ReleaseTemporary (rtAO);
|
||||
}
|
||||
|
||||
/*
|
||||
private void CreateRandomTable (int count, float minLength)
|
||||
{
|
||||
Random.seed = 1337;
|
||||
Vector3[] samples = new Vector3[count];
|
||||
// initial samples
|
||||
for (int i = 0; i < count; ++i)
|
||||
samples[i] = Random.onUnitSphere;
|
||||
// energy minimization: push samples away from others
|
||||
int iterations = 100;
|
||||
while (iterations-- > 0) {
|
||||
for (int i = 0; i < count; ++i) {
|
||||
Vector3 vec = samples[i];
|
||||
Vector3 res = Vector3.zero;
|
||||
// minimize with other samples
|
||||
for (int j = 0; j < count; ++j) {
|
||||
Vector3 force = vec - samples[j];
|
||||
float fac = Vector3.Dot (force, force);
|
||||
if (fac > 0.00001f)
|
||||
res += force * (1.0f / fac);
|
||||
}
|
||||
samples[i] = (samples[i] + res * 0.5f).normalized;
|
||||
}
|
||||
}
|
||||
// now scale samples between minLength and 1.0
|
||||
for (int i = 0; i < count; ++i) {
|
||||
samples[i] = samples[i] * Random.Range (minLength, 1.0f);
|
||||
}
|
||||
|
||||
string table = string.Format ("#define SAMPLE_COUNT {0}\n", count);
|
||||
table += "const float3 RAND_SAMPLES[SAMPLE_COUNT] = {\n";
|
||||
for (int i = 0; i < count; ++i) {
|
||||
Vector3 v = samples[i];
|
||||
table += string.Format("\tfloat3({0},{1},{2}),\n", v.x, v.y, v.z);
|
||||
}
|
||||
table += "};\n";
|
||||
Debug.Log (table);
|
||||
}
|
||||
*/
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 59cad7eaa13c7e24d8170b2c989e6856
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,45 @@
|
|||
|
||||
#pragma strict
|
||||
|
||||
@script ExecuteInEditMode
|
||||
@script RequireComponent (Camera)
|
||||
@script AddComponentMenu ("Image Effects/Screen Overlay")
|
||||
|
||||
class ScreenOverlay extends PostEffectsBase {
|
||||
|
||||
enum OverlayBlendMode {
|
||||
AddSub = 0,
|
||||
ScreenBlend = 1,
|
||||
Multiply = 2,
|
||||
Overlay = 3,
|
||||
AlphaBlend = 4,
|
||||
}
|
||||
|
||||
public var blendMode : OverlayBlendMode = OverlayBlendMode.Overlay;
|
||||
public var intensity : float = 1.0f;
|
||||
public var texture : Texture2D;
|
||||
|
||||
public var overlayShader : Shader;
|
||||
|
||||
private var overlayMaterial : Material = null;
|
||||
|
||||
function CheckResources () : boolean {
|
||||
CheckSupport (false);
|
||||
|
||||
overlayMaterial = CheckShaderAndCreateMaterial (overlayShader, overlayMaterial);
|
||||
|
||||
if(!isSupported)
|
||||
ReportAutoDisable ();
|
||||
return isSupported;
|
||||
}
|
||||
|
||||
function OnRenderImage (source : RenderTexture, destination : RenderTexture) {
|
||||
if(CheckResources()==false) {
|
||||
Graphics.Blit (source, destination);
|
||||
return;
|
||||
}
|
||||
overlayMaterial.SetFloat ("_Intensity", intensity);
|
||||
overlayMaterial.SetTexture ("_Overlay", texture);
|
||||
Graphics.Blit (source, destination, overlayMaterial, blendMode);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
fileFormatVersion: 2
|
||||
guid: fb663ad833c016f45a44d918b13d5895
|
||||
TextScriptImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,11 @@
|
|||
using UnityEngine;
|
||||
|
||||
[ExecuteInEditMode]
|
||||
[AddComponentMenu("Image Effects/Sepia Tone")]
|
||||
public class SepiaToneEffect : ImageEffectBase {
|
||||
|
||||
// Called by camera to apply image effect
|
||||
void OnRenderImage (RenderTexture source, RenderTexture destination) {
|
||||
Graphics.Blit (source, destination, material);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 4a0d605e08e9d4c49bf65e5df89ed51f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,145 @@
|
|||
|
||||
|
||||
@script ExecuteInEditMode
|
||||
@script RequireComponent (Camera)
|
||||
@script AddComponentMenu ("Image Effects/Sun Shafts")
|
||||
|
||||
enum SunShaftsResolution {
|
||||
Low = 0,
|
||||
Normal = 1,
|
||||
High = 2,
|
||||
}
|
||||
|
||||
enum ShaftsScreenBlendMode {
|
||||
Screen = 0,
|
||||
Add = 1,
|
||||
}
|
||||
|
||||
class SunShafts extends PostEffectsBase
|
||||
{
|
||||
public var resolution : SunShaftsResolution = SunShaftsResolution.Normal;
|
||||
public var screenBlendMode : ShaftsScreenBlendMode = ShaftsScreenBlendMode.Screen;
|
||||
|
||||
public var sunTransform : Transform;
|
||||
public var radialBlurIterations : int = 2;
|
||||
public var sunColor : Color = Color.white;
|
||||
public var sunShaftBlurRadius : float = 2.5f;
|
||||
public var sunShaftIntensity : float = 1.15;
|
||||
public var useSkyBoxAlpha : float = 0.75f;
|
||||
|
||||
public var maxRadius : float = 0.75f;
|
||||
|
||||
public var useDepthTexture : boolean = true;
|
||||
|
||||
public var sunShaftsShader : Shader;
|
||||
private var sunShaftsMaterial : Material;
|
||||
|
||||
public var simpleClearShader : Shader;
|
||||
private var simpleClearMaterial : Material;
|
||||
|
||||
function CheckResources () : boolean {
|
||||
CheckSupport (useDepthTexture);
|
||||
|
||||
sunShaftsMaterial = CheckShaderAndCreateMaterial (sunShaftsShader, sunShaftsMaterial);
|
||||
simpleClearMaterial = CheckShaderAndCreateMaterial (simpleClearShader, simpleClearMaterial);
|
||||
|
||||
if(!isSupported)
|
||||
ReportAutoDisable ();
|
||||
return isSupported;
|
||||
}
|
||||
|
||||
function OnRenderImage (source : RenderTexture, destination : RenderTexture) {
|
||||
if(CheckResources()==false) {
|
||||
Graphics.Blit (source, destination);
|
||||
return;
|
||||
}
|
||||
|
||||
// we actually need to check this every frame
|
||||
if(useDepthTexture)
|
||||
camera.depthTextureMode |= DepthTextureMode.Depth;
|
||||
|
||||
var divider : float = 4.0;
|
||||
if (resolution == SunShaftsResolution.Normal)
|
||||
divider = 2.0;
|
||||
else if (resolution == SunShaftsResolution.High)
|
||||
divider = 1.0;
|
||||
|
||||
var v : Vector3 = Vector3.one * 0.5;
|
||||
if (sunTransform)
|
||||
v = camera.WorldToViewportPoint (sunTransform.position);
|
||||
else
|
||||
v = Vector3(0.5, 0.5, 0.0);
|
||||
|
||||
var secondQuarterRezColor : RenderTexture = RenderTexture.GetTemporary (source.width / divider, source.height / divider, 0);
|
||||
var lrDepthBuffer : RenderTexture = RenderTexture.GetTemporary (source.width / divider, source.height / divider, 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", Vector4 (1.0, 1.0, 0.0, 0.0) * sunShaftBlurRadius );
|
||||
sunShaftsMaterial.SetVector ("_SunPosition", Vector4 (v.x, v.y, v.z, maxRadius));
|
||||
sunShaftsMaterial.SetFloat ("_NoSkyBoxMask", 1.0f - useSkyBoxAlpha);
|
||||
|
||||
if (!useDepthTexture) {
|
||||
var tmpBuffer : RenderTexture = RenderTexture.GetTemporary (source.width, source.height, 0);
|
||||
RenderTexture.active = tmpBuffer;
|
||||
GL.ClearWithSkybox (false, 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 = ClampBlurIterationsToSomethingThatMakesSense (radialBlurIterations);
|
||||
|
||||
var ofs : float = sunShaftBlurRadius * (1.0f / 768.0f);
|
||||
|
||||
sunShaftsMaterial.SetVector ("_BlurRadius4", Vector4 (ofs, ofs, 0.0f, 0.0f));
|
||||
sunShaftsMaterial.SetVector ("_SunPosition", Vector4 (v.x, v.y, v.z, maxRadius));
|
||||
|
||||
for (var it2 : int = 0; it2 < radialBlurIterations; it2++ ) {
|
||||
// each iteration takes 2 * 6 samples
|
||||
// we update _BlurRadius each time to cheaply get a very smooth look
|
||||
|
||||
Graphics.Blit (lrDepthBuffer, secondQuarterRezColor, sunShaftsMaterial, 1);
|
||||
ofs = sunShaftBlurRadius * (((it2 * 2.0f + 1.0f) * 6.0f)) / 768.0f;
|
||||
sunShaftsMaterial.SetVector ("_BlurRadius4", Vector4 (ofs, ofs, 0.0f, 0.0f) );
|
||||
|
||||
Graphics.Blit (secondQuarterRezColor, lrDepthBuffer, sunShaftsMaterial, 1);
|
||||
ofs = sunShaftBlurRadius * (((it2 * 2.0f + 2.0f) * 6.0f)) / 768.0f;
|
||||
sunShaftsMaterial.SetVector ("_BlurRadius4", Vector4 (ofs, ofs, 0.0f, 0.0f) );
|
||||
}
|
||||
|
||||
// put together:
|
||||
|
||||
if (v.z >= 0.0)
|
||||
sunShaftsMaterial.SetVector ("_SunColor", 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);
|
||||
RenderTexture.ReleaseTemporary (secondQuarterRezColor);
|
||||
}
|
||||
|
||||
// helper functions
|
||||
|
||||
private function ClampBlurIterationsToSomethingThatMakesSense (its : int) : int {
|
||||
if (its < 1)
|
||||
return 1;
|
||||
else if (its > 4)
|
||||
return 4;
|
||||
else
|
||||
return its;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 6a674adb08faa4b41afe006287ec01ba
|
||||
TextScriptImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,121 @@
|
|||
|
||||
#pragma strict
|
||||
|
||||
@script ExecuteInEditMode
|
||||
@script RequireComponent (Camera)
|
||||
@script AddComponentMenu ("Image Effects/Tilt shift")
|
||||
|
||||
class TiltShift extends PostEffectsBase {
|
||||
public var tiltShiftShader : Shader;
|
||||
private var tiltShiftMaterial : Material = null;
|
||||
|
||||
public var renderTextureDivider : int = 2;
|
||||
public var blurIterations : int = 2;
|
||||
public var enableForegroundBlur : boolean = true;
|
||||
public var foregroundBlurIterations : int = 2;
|
||||
public var maxBlurSpread : float = 1.5f;
|
||||
|
||||
public var focalPoint : float = 30.0f;
|
||||
public var smoothness : float = 1.65f;
|
||||
|
||||
public var visualizeCoc : boolean = false;
|
||||
|
||||
// these values will be automatically determined
|
||||
|
||||
private var start01 : float = 0.0f;
|
||||
private var distance01 : float = 0.2f;
|
||||
private var end01 : float = 1.0f;
|
||||
private var curve : float = 1.0f;
|
||||
|
||||
function CheckResources () : boolean {
|
||||
CheckSupport (true);
|
||||
|
||||
tiltShiftMaterial = CheckShaderAndCreateMaterial (tiltShiftShader, tiltShiftMaterial);
|
||||
|
||||
if(!isSupported)
|
||||
ReportAutoDisable ();
|
||||
return isSupported;
|
||||
}
|
||||
|
||||
function OnRenderImage (source : RenderTexture, destination : RenderTexture) {
|
||||
if(CheckResources()==false) {
|
||||
Graphics.Blit (source, destination);
|
||||
return;
|
||||
}
|
||||
|
||||
var widthOverHeight : float = (1.0f * source.width) / (1.0f * source.height);
|
||||
var oneOverBaseSize : float = 1.0f / 512.0f;
|
||||
|
||||
// clamp some values
|
||||
|
||||
renderTextureDivider = renderTextureDivider < 1 ? 1 : renderTextureDivider;
|
||||
renderTextureDivider = renderTextureDivider > 4 ? 4 : renderTextureDivider;
|
||||
blurIterations = blurIterations < 1 ? 0 : blurIterations;
|
||||
blurIterations = blurIterations > 4 ? 4 : blurIterations;
|
||||
|
||||
// automagically calculate parameters based on focalPoint
|
||||
|
||||
var focalPoint01 : float = camera.WorldToViewportPoint (focalPoint * camera.transform.forward + camera.transform.position).z / (camera.farClipPlane);
|
||||
|
||||
distance01 = focalPoint01;
|
||||
start01 = 0.0;
|
||||
end01 = 1.0;
|
||||
start01 = Mathf.Min (focalPoint01 - Mathf.Epsilon, start01);
|
||||
end01 = Mathf.Max (focalPoint01 + Mathf.Epsilon, end01);
|
||||
curve = smoothness * distance01;
|
||||
|
||||
// resources
|
||||
|
||||
var cocTex : RenderTexture = RenderTexture.GetTemporary (source.width, source.height, 0);
|
||||
var cocTex2 : RenderTexture = RenderTexture.GetTemporary (source.width, source.height, 0);
|
||||
var lrTex1 : RenderTexture = RenderTexture.GetTemporary (source.width / renderTextureDivider, source.height / renderTextureDivider, 0);
|
||||
var lrTex2 : RenderTexture = RenderTexture.GetTemporary (source.width / renderTextureDivider, source.height / renderTextureDivider, 0);
|
||||
|
||||
// coc
|
||||
|
||||
tiltShiftMaterial.SetVector ("_SimpleDofParams", Vector4 (start01, distance01, end01, curve));
|
||||
tiltShiftMaterial.SetTexture ("_Coc", cocTex);
|
||||
|
||||
if (enableForegroundBlur) {
|
||||
Graphics.Blit (source, cocTex, tiltShiftMaterial, 0);
|
||||
Graphics.Blit (cocTex, lrTex1); // downwards (only really needed if lrTex resolution is different)
|
||||
|
||||
for (var fgBlurIter : int = 0; fgBlurIter < foregroundBlurIterations; fgBlurIter++ ) {
|
||||
tiltShiftMaterial.SetVector ("offsets", Vector4 (0.0, (maxBlurSpread * 0.75f) * oneOverBaseSize, 0.0, 0.0));
|
||||
Graphics.Blit (lrTex1, lrTex2, tiltShiftMaterial, 3);
|
||||
tiltShiftMaterial.SetVector ("offsets", Vector4 ((maxBlurSpread * 0.75f / widthOverHeight) * oneOverBaseSize, 0.0, 0.0, 0.0));
|
||||
Graphics.Blit (lrTex2, lrTex1, tiltShiftMaterial, 3);
|
||||
}
|
||||
|
||||
Graphics.Blit (lrTex1, cocTex2, tiltShiftMaterial, 7); // upwards (only really needed if lrTex resolution is different)
|
||||
tiltShiftMaterial.SetTexture ("_Coc", cocTex2);
|
||||
} else {
|
||||
RenderTexture.active = cocTex;
|
||||
GL.Clear (false, true, Color.black);
|
||||
}
|
||||
|
||||
// combine coc's
|
||||
Graphics.Blit (source, cocTex, tiltShiftMaterial, 5);
|
||||
tiltShiftMaterial.SetTexture ("_Coc", cocTex);
|
||||
|
||||
// downsample & blur
|
||||
|
||||
Graphics.Blit (source, lrTex2);
|
||||
|
||||
for (var iter : int = 0; iter < blurIterations; iter++ ) {
|
||||
tiltShiftMaterial.SetVector ("offsets", Vector4 (0.0, (maxBlurSpread * 1.0f) * oneOverBaseSize, 0.0, 0.0));
|
||||
Graphics.Blit (lrTex2, lrTex1, tiltShiftMaterial, 6);
|
||||
tiltShiftMaterial.SetVector ("offsets", Vector4 ((maxBlurSpread * 1.0f / widthOverHeight) * oneOverBaseSize, 0.0, 0.0, 0.0));
|
||||
Graphics.Blit (lrTex1, lrTex2, tiltShiftMaterial, 6);
|
||||
}
|
||||
|
||||
tiltShiftMaterial.SetTexture ("_Blurred", lrTex2);
|
||||
|
||||
Graphics.Blit (source, destination, tiltShiftMaterial, visualizeCoc ? 4 : 1);
|
||||
|
||||
RenderTexture.ReleaseTemporary (cocTex);
|
||||
RenderTexture.ReleaseTemporary (cocTex2);
|
||||
RenderTexture.ReleaseTemporary (lrTex1);
|
||||
RenderTexture.ReleaseTemporary (lrTex2);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
fileFormatVersion: 2
|
||||
guid: b962a7d108b314246a7d0613b386e0d9
|
||||
TextScriptImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,223 @@
|
|||
|
||||
#pragma strict
|
||||
|
||||
@script ExecuteInEditMode
|
||||
@script RequireComponent (Camera)
|
||||
@script AddComponentMenu ("Image Effects/Tonemapping")
|
||||
|
||||
class Tonemapping extends PostEffectsBase {
|
||||
|
||||
public enum TonemapperType {
|
||||
SimpleReinhard = 0x0,
|
||||
UserCurve = 0x1,
|
||||
Hable = 0x2,
|
||||
Photographic = 0x3,
|
||||
OptimizedHejiDawson = 0x4,
|
||||
AdaptiveReinhard = 0x5,
|
||||
AdaptiveReinhardAutoWhite = 0x6,
|
||||
};
|
||||
|
||||
public enum AdaptiveTexSize {
|
||||
Square16 = 16,
|
||||
Square32 = 32,
|
||||
Square64 = 64,
|
||||
Square128 = 128,
|
||||
Square256 = 256,
|
||||
Square512 = 512,
|
||||
Square1024 = 1024,
|
||||
};
|
||||
|
||||
public var type : TonemapperType = TonemapperType.SimpleReinhard;
|
||||
public var adaptiveTextureSize = AdaptiveTexSize.Square256;
|
||||
|
||||
// CURVE parameter
|
||||
public var remapCurve : AnimationCurve;
|
||||
private var curveTex : Texture2D = null;
|
||||
|
||||
// UNCHARTED parameter
|
||||
public var exposureAdjustment : float = 1.5f;
|
||||
|
||||
// REINHARD parameter
|
||||
public var middleGrey : float = 0.4f;
|
||||
public var white : float = 2.0f;
|
||||
public var adaptionSpeed : float = 1.5f;
|
||||
|
||||
// usual & internal stuff
|
||||
public var tonemapper : Shader = null;
|
||||
public var validRenderTextureFormat : boolean = true;
|
||||
private var tonemapMaterial : Material = null;
|
||||
private var rt : RenderTexture = null;
|
||||
|
||||
function CheckResources () : boolean {
|
||||
CheckSupport (false, true);
|
||||
|
||||
tonemapMaterial = CheckShaderAndCreateMaterial(tonemapper, tonemapMaterial);
|
||||
if (!curveTex && type == TonemapperType.UserCurve) {
|
||||
curveTex = new Texture2D (256, 1, TextureFormat.ARGB32, false, true);
|
||||
curveTex.filterMode = FilterMode.Bilinear;
|
||||
curveTex.wrapMode = TextureWrapMode.Clamp;
|
||||
curveTex.hideFlags = HideFlags.DontSave;
|
||||
}
|
||||
|
||||
if(!isSupported)
|
||||
ReportAutoDisable ();
|
||||
return isSupported;
|
||||
}
|
||||
|
||||
public function UpdateCurve () : float {
|
||||
var range : float = 1.0f;
|
||||
if(!remapCurve)
|
||||
remapCurve = new AnimationCurve(Keyframe(0, 0), Keyframe(2, 1));
|
||||
if (remapCurve) {
|
||||
if(remapCurve.length)
|
||||
range = remapCurve[remapCurve.length-1].time;
|
||||
for (var i : float = 0.0f; i <= 1.0f; i += 1.0f / 255.0f) {
|
||||
var c : float = remapCurve.Evaluate(i * 1.0f * range);
|
||||
curveTex.SetPixel (Mathf.Floor(i*255.0f), 0, Color(c,c,c));
|
||||
}
|
||||
curveTex.Apply ();
|
||||
}
|
||||
return 1.0f / range;
|
||||
}
|
||||
|
||||
function CreateInternalRenderTexture () : boolean {
|
||||
if (rt) {
|
||||
return false;
|
||||
}
|
||||
rt = new RenderTexture(1,1, 0, RenderTextureFormat.ARGBHalf);
|
||||
var oldrt : RenderTexture = RenderTexture.active;
|
||||
RenderTexture.active = rt;
|
||||
GL.Clear(false, true, Color.white);
|
||||
rt.hideFlags = HideFlags.DontSave;
|
||||
RenderTexture.active = oldrt;
|
||||
return true;
|
||||
}
|
||||
|
||||
// a new attribute we introduced in 3.5 indicating that the image filter chain will continue in LDR
|
||||
@ImageEffectTransformsToLDR
|
||||
function OnRenderImage (source : RenderTexture, destination : RenderTexture) {
|
||||
if(CheckResources()==false) {
|
||||
Graphics.Blit (source, destination);
|
||||
return;
|
||||
}
|
||||
|
||||
#if UNITY_EDITOR
|
||||
validRenderTextureFormat = true;
|
||||
if(source.format != RenderTextureFormat.ARGBHalf) {
|
||||
validRenderTextureFormat = false;
|
||||
}
|
||||
#endif
|
||||
|
||||
// clamp some values to not go out of a valid range
|
||||
|
||||
exposureAdjustment = exposureAdjustment < 0.001f ? 0.001f : exposureAdjustment;
|
||||
|
||||
// SimpleReinhard tonemappers (local, non adaptive)
|
||||
|
||||
if(type == TonemapperType.UserCurve) {
|
||||
var rangeScale : float = UpdateCurve ();
|
||||
tonemapMaterial.SetFloat("_RangeScale", rangeScale);
|
||||
tonemapMaterial.SetTexture("_Curve", curveTex);
|
||||
Graphics.Blit(source, destination, tonemapMaterial, 4);
|
||||
return;
|
||||
}
|
||||
|
||||
if(type == TonemapperType.SimpleReinhard) {
|
||||
tonemapMaterial.SetFloat("_ExposureAdjustment", exposureAdjustment);
|
||||
Graphics.Blit(source, destination, tonemapMaterial, 6);
|
||||
return;
|
||||
}
|
||||
|
||||
if(type == TonemapperType.Hable) {
|
||||
tonemapMaterial.SetFloat("_ExposureAdjustment", exposureAdjustment);
|
||||
Graphics.Blit(source, destination, tonemapMaterial, 5);
|
||||
return;
|
||||
}
|
||||
|
||||
if(type == TonemapperType.Photographic) {
|
||||
tonemapMaterial.SetFloat("_ExposureAdjustment", exposureAdjustment);
|
||||
Graphics.Blit(source, destination, tonemapMaterial, 8);
|
||||
return;
|
||||
}
|
||||
|
||||
if(type == TonemapperType.OptimizedHejiDawson) {
|
||||
tonemapMaterial.SetFloat("_ExposureAdjustment", 0.5f * exposureAdjustment);
|
||||
Graphics.Blit(source, destination, tonemapMaterial, 7);
|
||||
return;
|
||||
}
|
||||
|
||||
// still here?
|
||||
// => more complex adaptive tone mapping:
|
||||
// builds an average log luminance, tonemaps according to
|
||||
// middle grey and white values (user controlled)
|
||||
// AdaptiveReinhardAutoWhite will calculate white value automagically
|
||||
|
||||
var freshlyBrewedInternalRt : boolean = CreateInternalRenderTexture ();
|
||||
|
||||
var rtSquared : RenderTexture = RenderTexture.GetTemporary(adaptiveTextureSize, adaptiveTextureSize, 0, RenderTextureFormat.ARGBHalf);
|
||||
Graphics.Blit(source, rtSquared);
|
||||
|
||||
var downsample : int = Mathf.Log(rtSquared.width * 1.0f, 2);
|
||||
|
||||
var div : int = 2;
|
||||
var rts : RenderTexture[] = new RenderTexture[downsample];
|
||||
for(var i : int = 0; i < downsample; i++) {
|
||||
rts[i] = RenderTexture.GetTemporary(rtSquared.width / div, rtSquared.width / div, 0, RenderTextureFormat.ARGBHalf);
|
||||
div *= 2;
|
||||
}
|
||||
|
||||
var ar : float = (source.width * 1.0f) / (source.height * 1.0f);
|
||||
|
||||
// downsample pyramid
|
||||
|
||||
var lumRt = rts[downsample-1];
|
||||
Graphics.Blit(rtSquared, rts[0], tonemapMaterial, 1);
|
||||
if (type == TonemapperType.AdaptiveReinhardAutoWhite) {
|
||||
for(i = 0; i < downsample-1; i++) {
|
||||
Graphics.Blit(rts[i], rts[i+1], tonemapMaterial, 9);
|
||||
lumRt = rts[i+1];
|
||||
}
|
||||
}
|
||||
else if (type == TonemapperType.AdaptiveReinhard) {
|
||||
for(i = 0; i < downsample-1; i++) {
|
||||
Graphics.Blit(rts[i], rts[i+1]);
|
||||
lumRt = rts[i+1];
|
||||
}
|
||||
}
|
||||
|
||||
// we have the needed values, let's apply adaptive tonemapping
|
||||
|
||||
adaptionSpeed = adaptionSpeed < 0.001f ? 0.001f : adaptionSpeed;
|
||||
#if UNITY_EDITOR
|
||||
tonemapMaterial.SetFloat("_AdaptionSpeed", adaptionSpeed);
|
||||
if(Application.isPlaying && !freshlyBrewedInternalRt)
|
||||
Graphics.Blit(lumRt, rt, tonemapMaterial, 2);
|
||||
else
|
||||
Graphics.Blit(lumRt, rt, tonemapMaterial, 3);
|
||||
#else
|
||||
tonemapMaterial.SetFloat("_AdaptionSpeed", adaptionSpeed);
|
||||
Graphics.Blit(lumRt, rt, tonemapMaterial, 2);
|
||||
#endif
|
||||
|
||||
middleGrey = middleGrey < 0.001f ? 0.001f : middleGrey;
|
||||
tonemapMaterial.SetVector("_HdrParams", Vector4(middleGrey, middleGrey, middleGrey, white*white));
|
||||
tonemapMaterial.SetTexture("_SmallTex", rt);
|
||||
if (type == TonemapperType.AdaptiveReinhard) {
|
||||
Graphics.Blit (source, destination, tonemapMaterial, 0);
|
||||
}
|
||||
else if(type == TonemapperType.AdaptiveReinhardAutoWhite) {
|
||||
Graphics.Blit (source, destination, tonemapMaterial, 10);
|
||||
}
|
||||
else {
|
||||
Debug.LogError("No valid adaptive tonemapper type found!");
|
||||
Graphics.Blit (source, destination); // at least we get the TransformToLDR effect
|
||||
}
|
||||
|
||||
// cleanup for adaptive
|
||||
|
||||
for(i = 0; i < downsample; i++) {
|
||||
RenderTexture.ReleaseTemporary(rts[i]);
|
||||
}
|
||||
RenderTexture.ReleaseTemporary(rtSquared);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 1fafa3b2bfd3642478d3e46fce471ad3
|
||||
TextScriptImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,102 @@
|
|||
|
||||
#pragma strict
|
||||
|
||||
static var meshes : Mesh[];
|
||||
static var currentTris : int = 0;
|
||||
|
||||
static function HasMeshes () : boolean {
|
||||
if (!meshes)
|
||||
return false;
|
||||
for (var m : Mesh in meshes)
|
||||
if (null == m)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static function Cleanup () {
|
||||
if (!meshes)
|
||||
return;
|
||||
|
||||
for (var m : Mesh in meshes) {
|
||||
if (null != m) {
|
||||
DestroyImmediate (m);
|
||||
m = null;
|
||||
}
|
||||
}
|
||||
meshes = null;
|
||||
}
|
||||
|
||||
static function GetMeshes (totalWidth : int, totalHeight : int) : Mesh[]
|
||||
{
|
||||
if (HasMeshes () && (currentTris == (totalWidth * totalHeight))) {
|
||||
return meshes;
|
||||
}
|
||||
|
||||
var maxTris : int = 65000 / 3;
|
||||
var totalTris : int = totalWidth * totalHeight;
|
||||
currentTris = totalTris;
|
||||
|
||||
var meshCount : int = Mathf.CeilToInt ((1.0f * totalTris) / (1.0f * maxTris));
|
||||
|
||||
meshes = new Mesh[meshCount];
|
||||
|
||||
var i : int = 0;
|
||||
var index : int = 0;
|
||||
for (i = 0; i < totalTris; i += maxTris) {
|
||||
var tris : int = Mathf.FloorToInt (Mathf.Clamp ((totalTris-i), 0, maxTris));
|
||||
|
||||
meshes[index] = GetMesh (tris, i, totalWidth, totalHeight);
|
||||
index++;
|
||||
}
|
||||
|
||||
return meshes;
|
||||
}
|
||||
|
||||
static function GetMesh (triCount : int, triOffset : int, totalWidth : int, totalHeight : int) : Mesh
|
||||
{
|
||||
var mesh = new Mesh ();
|
||||
mesh.hideFlags = HideFlags.DontSave;
|
||||
|
||||
var verts : Vector3[] = new Vector3[triCount*3];
|
||||
var uvs : Vector2[] = new Vector2[triCount*3];
|
||||
var uvs2 : Vector2[] = new Vector2[triCount*3];
|
||||
var tris : int[] = new int[triCount*3];
|
||||
|
||||
var size : float = 0.0075f;
|
||||
|
||||
for (var i : int = 0; i < triCount; i++)
|
||||
{
|
||||
var i3 : int = i * 3;
|
||||
var vertexWithOffset : int = triOffset + i;
|
||||
|
||||
var x : float = Mathf.Floor(vertexWithOffset % totalWidth) / totalWidth;
|
||||
var y : float = Mathf.Floor(vertexWithOffset / totalWidth) / totalHeight;
|
||||
|
||||
var position : Vector3 = Vector3 (x*2-1,y*2-1, 1.0);
|
||||
|
||||
verts[i3 + 0] = position;
|
||||
verts[i3 + 1] = position;
|
||||
verts[i3 + 2] = position;
|
||||
|
||||
uvs[i3 + 0] = Vector2 (0.0f, 0.0f);
|
||||
uvs[i3 + 1] = Vector2 (1.0f, 0.0f);
|
||||
uvs[i3 + 2] = Vector2 (0.0f, 1.0f);
|
||||
|
||||
uvs2[i3 + 0] = Vector2 (x, y);
|
||||
uvs2[i3 + 1] = Vector2 (x, y);
|
||||
uvs2[i3 + 2] = 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;
|
||||
}
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
fileFormatVersion: 2
|
||||
guid: fd7c7357063367e4c97a886210912c9a
|
||||
TextScriptImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,14 @@
|
|||
using UnityEngine;
|
||||
|
||||
[ExecuteInEditMode]
|
||||
[AddComponentMenu("Image Effects/Twirl")]
|
||||
public class TwirlEffect : ImageEffectBase {
|
||||
public Vector2 radius = new Vector2(0.3F,0.3F);
|
||||
public float angle = 50;
|
||||
public Vector2 center = new Vector2 (0.5F, 0.5F);
|
||||
|
||||
// Called by camera to apply image effect
|
||||
void OnRenderImage (RenderTexture source, RenderTexture destination) {
|
||||
ImageEffects.RenderDistortion (material, source, destination, angle, center, radius);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 1688b0939f16c944c929f809afcf0b3e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,77 @@
|
|||
|
||||
#pragma strict
|
||||
|
||||
@script ExecuteInEditMode
|
||||
@script RequireComponent (Camera)
|
||||
@script AddComponentMenu ("Image Effects/Vignette and Chromatic Aberration")
|
||||
|
||||
class Vignetting extends PostEffectsBase {
|
||||
|
||||
public var intensity : float = 0.375f;
|
||||
public var chromaticAberration : float = 0.2f;
|
||||
public var blur : float = 0.1f;
|
||||
public var blurSpread : float = 1.5f;
|
||||
|
||||
// needed shaders & materials
|
||||
|
||||
public var vignetteShader : Shader;
|
||||
private var vignetteMaterial : Material;
|
||||
|
||||
public var separableBlurShader : Shader;
|
||||
private var separableBlurMaterial : Material;
|
||||
|
||||
public var chromAberrationShader : Shader;
|
||||
private var chromAberrationMaterial : Material;
|
||||
|
||||
function CheckResources () : boolean {
|
||||
CheckSupport (false);
|
||||
|
||||
vignetteMaterial = CheckShaderAndCreateMaterial (vignetteShader, vignetteMaterial);
|
||||
separableBlurMaterial = CheckShaderAndCreateMaterial (separableBlurShader, separableBlurMaterial);
|
||||
chromAberrationMaterial = CheckShaderAndCreateMaterial (chromAberrationShader, chromAberrationMaterial);
|
||||
|
||||
if(!isSupported)
|
||||
ReportAutoDisable ();
|
||||
return isSupported;
|
||||
}
|
||||
|
||||
function OnRenderImage (source : RenderTexture, destination : RenderTexture) {
|
||||
if(CheckResources()==false) {
|
||||
Graphics.Blit (source, destination);
|
||||
return;
|
||||
}
|
||||
|
||||
var widthOverHeight : float = (1.0f * source.width) / (1.0f * source.height);
|
||||
var oneOverBaseSize : float = 1.0f / 512.0f;
|
||||
|
||||
var color : RenderTexture = RenderTexture.GetTemporary (source.width, source.height, 0);
|
||||
var halfRezColor : RenderTexture = RenderTexture.GetTemporary (source.width / 2.0, source.height / 2.0, 0);
|
||||
var quarterRezColor : RenderTexture = RenderTexture.GetTemporary (source.width / 4.0, source.height / 4.0, 0);
|
||||
var secondQuarterRezColor : RenderTexture = RenderTexture.GetTemporary (source.width / 4.0, source.height / 4.0, 0);
|
||||
|
||||
Graphics.Blit (source, halfRezColor, chromAberrationMaterial, 0);
|
||||
Graphics.Blit (halfRezColor, quarterRezColor);
|
||||
|
||||
for (var it : int = 0; it < 2; it++ ) {
|
||||
separableBlurMaterial.SetVector ("offsets", Vector4 (0.0, blurSpread * oneOverBaseSize, 0.0, 0.0));
|
||||
Graphics.Blit (quarterRezColor, secondQuarterRezColor, separableBlurMaterial);
|
||||
separableBlurMaterial.SetVector ("offsets", Vector4 (blurSpread * oneOverBaseSize / widthOverHeight, 0.0, 0.0, 0.0));
|
||||
Graphics.Blit (secondQuarterRezColor, quarterRezColor, separableBlurMaterial);
|
||||
}
|
||||
|
||||
vignetteMaterial.SetFloat ("_Intensity", intensity);
|
||||
vignetteMaterial.SetFloat ("_Blur", blur);
|
||||
vignetteMaterial.SetTexture ("_VignetteTex", quarterRezColor);
|
||||
Graphics.Blit (source, color, vignetteMaterial);
|
||||
|
||||
chromAberrationMaterial.SetFloat ("_ChromaticAberration", chromaticAberration);
|
||||
Graphics.Blit (color, destination, chromAberrationMaterial, 1);
|
||||
|
||||
RenderTexture.ReleaseTemporary (color);
|
||||
RenderTexture.ReleaseTemporary (halfRezColor);
|
||||
RenderTexture.ReleaseTemporary (quarterRezColor);
|
||||
RenderTexture.ReleaseTemporary (secondQuarterRezColor);
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 8533689ab9bf7624db3fb52517776b93
|
||||
TextScriptImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,14 @@
|
|||
using UnityEngine;
|
||||
|
||||
[ExecuteInEditMode]
|
||||
[AddComponentMenu("Image Effects/Vortex")]
|
||||
public class VortexEffect : ImageEffectBase {
|
||||
public Vector2 radius = new Vector2(0.4F,0.4F);
|
||||
public float angle = 50;
|
||||
public Vector2 center = new Vector2(0.5F, 0.5F);
|
||||
|
||||
// Called by camera to apply image effect
|
||||
void OnRenderImage (RenderTexture source, RenderTexture destination) {
|
||||
ImageEffects.RenderDistortion (material, source, destination, angle, center, radius);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 97a5d7eeb2d8f254ca9de7bffc8b08e8
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 8a14bfde6ee94ea4dac7283c9fda4b21
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 08fb27fc05695984d91f7d342453f90e
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,124 @@
|
|||
// Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)'
|
||||
|
||||
Shader "Hidden/BlendModesOverlay" {
|
||||
Properties {
|
||||
_MainTex ("Screen Blended", 2D) = "" {}
|
||||
_Overlay ("Color", 2D) = "white" {}
|
||||
}
|
||||
|
||||
CGINCLUDE
|
||||
|
||||
#include "UnityCG.cginc"
|
||||
|
||||
struct v2f {
|
||||
float4 pos : POSITION;
|
||||
float2 uv[2] : TEXCOORD0;
|
||||
};
|
||||
|
||||
sampler2D _Overlay;
|
||||
sampler2D _MainTex;
|
||||
|
||||
half _Intensity;
|
||||
half4 _MainTex_TexelSize;
|
||||
|
||||
v2f vert( appdata_img v ) {
|
||||
v2f o;
|
||||
o.pos = UnityObjectToClipPos(v.vertex);
|
||||
o.uv[0] = v.texcoord.xy;
|
||||
|
||||
#if SHADER_API_D3D9 || SHADER_API_D3D11 || SHADER_API_XBOX360
|
||||
if(_MainTex_TexelSize.y<0.0)
|
||||
o.uv[0].y = 1.0-o.uv[0].y;
|
||||
#endif
|
||||
|
||||
o.uv[1] = v.texcoord.xy;
|
||||
return o;
|
||||
}
|
||||
|
||||
half4 fragAddSub (v2f i) : COLOR {
|
||||
half4 toAdd = tex2D(_Overlay, i.uv[0]) * _Intensity;
|
||||
return tex2D(_MainTex, i.uv[1]) + toAdd;
|
||||
}
|
||||
|
||||
half4 fragMultiply (v2f i) : COLOR {
|
||||
half4 toBlend = tex2D(_Overlay, i.uv[0]) * _Intensity;
|
||||
return tex2D(_MainTex, i.uv[1]) * toBlend;
|
||||
}
|
||||
|
||||
half4 fragScreen (v2f i) : COLOR {
|
||||
half4 toBlend = (tex2D(_Overlay, i.uv[0]) * _Intensity);
|
||||
return 1-saturate(1-toBlend)*(1-(tex2D(_MainTex, i.uv[1])));
|
||||
}
|
||||
|
||||
half4 fragOverlay (v2f i) : COLOR {
|
||||
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;
|
||||
return color;
|
||||
}
|
||||
|
||||
half4 fragAlphaBlend (v2f i) : COLOR {
|
||||
half4 toAdd = tex2D(_Overlay, i.uv[0]) ;
|
||||
return lerp(tex2D(_MainTex, i.uv[1]), toAdd, toAdd.a);
|
||||
}
|
||||
|
||||
|
||||
ENDCG
|
||||
|
||||
Subshader {
|
||||
ZTest Always Cull Off ZWrite Off
|
||||
Fog { Mode off }
|
||||
ColorMask RGB
|
||||
|
||||
Pass {
|
||||
|
||||
CGPROGRAM
|
||||
#pragma fragmentoption ARB_precision_hint_fastest
|
||||
#pragma vertex vert
|
||||
#pragma fragment fragAddSub
|
||||
ENDCG
|
||||
}
|
||||
|
||||
Pass {
|
||||
|
||||
CGPROGRAM
|
||||
#pragma fragmentoption ARB_precision_hint_fastest
|
||||
#pragma vertex vert
|
||||
#pragma fragment fragScreen
|
||||
ENDCG
|
||||
}
|
||||
|
||||
Pass {
|
||||
|
||||
CGPROGRAM
|
||||
#pragma fragmentoption ARB_precision_hint_fastest
|
||||
#pragma vertex vert
|
||||
#pragma fragment fragMultiply
|
||||
ENDCG
|
||||
}
|
||||
|
||||
Pass {
|
||||
|
||||
CGPROGRAM
|
||||
#pragma fragmentoption ARB_precision_hint_fastest
|
||||
#pragma vertex vert
|
||||
#pragma fragment fragOverlay
|
||||
ENDCG
|
||||
}
|
||||
|
||||
Pass {
|
||||
|
||||
CGPROGRAM
|
||||
#pragma fragmentoption ARB_precision_hint_fastest
|
||||
#pragma vertex vert
|
||||
#pragma fragment fragAlphaBlend
|
||||
ENDCG
|
||||
}
|
||||
}
|
||||
|
||||
Fallback off
|
||||
|
||||
} // shader
|
|
@ -0,0 +1,9 @@
|
|||
fileFormatVersion: 2
|
||||
guid: d629a140529beaa419374a4776e4cc23
|
||||
ShaderImporter:
|
||||
externalObjects: {}
|
||||
defaultTextures: []
|
||||
nonModifiableTextures: []
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,55 @@
|
|||
// Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)'
|
||||
|
||||
Shader "Hidden/BlurEffectConeTap" {
|
||||
Properties { _MainTex ("", any) = "" {} }
|
||||
SubShader {
|
||||
Pass {
|
||||
ZTest Always Cull Off ZWrite Off Fog { Mode Off }
|
||||
SetTexture [_MainTex] {constantColor (0,0,0,0.25) combine texture * constant alpha}
|
||||
SetTexture [_MainTex] {constantColor (0,0,0,0.25) combine texture * constant + previous}
|
||||
SetTexture [_MainTex] {constantColor (0,0,0,0.25) combine texture * constant + previous}
|
||||
SetTexture [_MainTex] {constantColor (0,0,0,0.25) combine texture * constant + previous}
|
||||
}
|
||||
}
|
||||
CGINCLUDE
|
||||
#include "UnityCG.cginc"
|
||||
struct v2f {
|
||||
float4 pos : POSITION;
|
||||
half2 uv : TEXCOORD0;
|
||||
half2 taps[4] : TEXCOORD1;
|
||||
};
|
||||
sampler2D _MainTex;
|
||||
half4 _MainTex_TexelSize;
|
||||
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
|
||||
o.taps[0] = o.uv + _MainTex_TexelSize * _BlurOffsets.xy;
|
||||
o.taps[1] = o.uv - _MainTex_TexelSize * _BlurOffsets.xy;
|
||||
o.taps[2] = o.uv + _MainTex_TexelSize * _BlurOffsets.xy * half2(1,-1);
|
||||
o.taps[3] = o.uv - _MainTex_TexelSize * _BlurOffsets.xy * half2(1,-1);
|
||||
return o;
|
||||
}
|
||||
half4 frag(v2f i) : COLOR {
|
||||
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
|
||||
Fog { Mode off }
|
||||
|
||||
CGPROGRAM
|
||||
#pragma fragmentoption ARB_precision_hint_fastest
|
||||
#pragma vertex vert
|
||||
#pragma fragment frag
|
||||
ENDCG
|
||||
}
|
||||
}
|
||||
Fallback off
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 8ce1716f0928fb14e854a505b32b0972
|
||||
ShaderImporter:
|
||||
externalObjects: {}
|
||||
defaultTextures: []
|
||||
nonModifiableTextures: []
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,88 @@
|
|||
// Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)'
|
||||
|
||||
Shader "Hidden/ChromaticAberrationShader" {
|
||||
Properties {
|
||||
_MainTex ("Base", 2D) = "" {}
|
||||
}
|
||||
|
||||
CGINCLUDE
|
||||
|
||||
#include "UnityCG.cginc"
|
||||
|
||||
struct v2f {
|
||||
float4 pos : POSITION;
|
||||
float2 uv : TEXCOORD0;
|
||||
};
|
||||
|
||||
sampler2D _MainTex;
|
||||
|
||||
float4 _MainTex_TexelSize;
|
||||
float _ChromaticAberration;
|
||||
|
||||
|
||||
v2f vert( appdata_img v ) {
|
||||
v2f o;
|
||||
o.pos = UnityObjectToClipPos(v.vertex);
|
||||
|
||||
#if SHADER_API_D3D9 || SHADER_API_D3D11 || SHADER_API_XBOX360
|
||||
if (_MainTex_TexelSize.y < 0)
|
||||
v.texcoord.y = 1.0 - v.texcoord.y ;
|
||||
#endif
|
||||
|
||||
o.uv = v.texcoord.xy;
|
||||
return o;
|
||||
}
|
||||
|
||||
half4 fragSimpleCopy(v2f i) : COLOR {
|
||||
return tex2D (_MainTex, i.uv.xy);
|
||||
}
|
||||
|
||||
half4 frag(v2f i) : COLOR {
|
||||
half2 coords = i.uv;
|
||||
half2 uv = i.uv;
|
||||
|
||||
coords = (coords - 0.5) * 2.0;
|
||||
half coordDot = dot (coords,coords);
|
||||
|
||||
float2 uvG = uv - _MainTex_TexelSize.xy * _ChromaticAberration * coords * coordDot;
|
||||
half4 color = tex2D (_MainTex, uv);
|
||||
#if SHADER_API_D3D9
|
||||
// Work around Cg's code generation bug for D3D9 pixel shaders :(
|
||||
color.g = color.g * 0.0001 + tex2D (_MainTex, uvG).g;
|
||||
#else
|
||||
color.g = tex2D (_MainTex, uvG).g;
|
||||
#endif
|
||||
|
||||
return color;
|
||||
}
|
||||
|
||||
ENDCG
|
||||
|
||||
Subshader {
|
||||
Pass {
|
||||
ZTest Always Cull Off ZWrite Off
|
||||
Fog { Mode off }
|
||||
|
||||
CGPROGRAM
|
||||
|
||||
#pragma vertex vert
|
||||
#pragma fragment fragSimpleCopy
|
||||
|
||||
ENDCG
|
||||
}
|
||||
Pass {
|
||||
ZTest Always Cull Off ZWrite Off
|
||||
Fog { Mode off }
|
||||
|
||||
CGPROGRAM
|
||||
|
||||
#pragma vertex vert
|
||||
#pragma fragment frag
|
||||
|
||||
ENDCG
|
||||
}
|
||||
}
|
||||
|
||||
Fallback off
|
||||
|
||||
} // shader
|
|
@ -0,0 +1,9 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 507bf3bf614e27b42898afcf0e47c7e9
|
||||
ShaderImporter:
|
||||
externalObjects: {}
|
||||
defaultTextures: []
|
||||
nonModifiableTextures: []
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,94 @@
|
|||
// Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)'
|
||||
|
||||
Shader "Hidden/ColorCorrectionCurves" {
|
||||
Properties {
|
||||
_MainTex ("Base (RGB)", 2D) = "" {}
|
||||
|
||||
_RgbTex ("_RgbTex (RGB)", 2D) = "" {}
|
||||
|
||||
_ZCurve ("_ZCurve (RGB)", 2D) = "" {}
|
||||
|
||||
_RgbDepthTex ("_RgbDepthTex (RGB)", 2D) = "" {}
|
||||
}
|
||||
|
||||
// note: also have a look at ColorCorrectionCurvesSimple
|
||||
// for a much simpler color correction without use of
|
||||
// depth texture lookups
|
||||
|
||||
// Shader code pasted into all further CGPROGRAM blocks
|
||||
CGINCLUDE
|
||||
|
||||
#pragma fragmentoption ARB_precision_hint_fastest
|
||||
|
||||
#include "UnityCG.cginc"
|
||||
|
||||
struct v2f {
|
||||
float4 pos : POSITION;
|
||||
float2 uv : TEXCOORD0;
|
||||
float2 uv2 : TEXCOORD1;
|
||||
};
|
||||
|
||||
sampler2D _MainTex;
|
||||
sampler2D _CameraDepthTexture;
|
||||
|
||||
float4 _CameraDepthTexture_ST;
|
||||
uniform float4 _MainTex_TexelSize;
|
||||
|
||||
sampler2D _RgbTex;
|
||||
|
||||
sampler2D _ZCurve;
|
||||
|
||||
sampler2D _RgbDepthTex;
|
||||
|
||||
v2f vert( appdata_img v )
|
||||
{
|
||||
v2f o;
|
||||
o.pos = UnityObjectToClipPos(v.vertex);
|
||||
o.uv = v.texcoord.xy;
|
||||
o.uv2 = TRANSFORM_TEX(v.texcoord, _CameraDepthTexture);
|
||||
|
||||
#if SHADER_API_D3D9
|
||||
if (_MainTex_TexelSize.y < 0)
|
||||
o.uv2.y = 1-o.uv2.y;
|
||||
#endif
|
||||
|
||||
return o;
|
||||
}
|
||||
|
||||
half4 frag(v2f i) : COLOR
|
||||
{
|
||||
half4 color = tex2D(_MainTex, i.uv);
|
||||
|
||||
half3 ycoords = half3(0.5,1.5,2.5) * 0.25;
|
||||
|
||||
half3 red = tex2D(_RgbTex, half2(color.r, ycoords.x)).rgb * half3(1,0,0);
|
||||
half3 green = tex2D(_RgbTex, half2(color.g, ycoords.y)).rgb * half3(0,1,0);
|
||||
half3 blue = tex2D(_RgbTex, half2(color.b, ycoords.z)).rgb * half3(0,0,1);
|
||||
|
||||
half theDepth = UNITY_SAMPLE_DEPTH( tex2D (_CameraDepthTexture, i.uv2) );
|
||||
half zval = tex2D(_ZCurve, half2( Linear01Depth (theDepth), 0.5));
|
||||
|
||||
half3 depthRed = tex2D(_RgbDepthTex, half2(color.r, ycoords.x)).rgb * half3(1,0,0);
|
||||
half3 depthGreen = tex2D(_RgbDepthTex, half2(color.g, ycoords.y)).rgb * half3(0,1,0);
|
||||
half3 depthBlue = tex2D(_RgbDepthTex, half2(color.b, ycoords.z)).rgb * half3(0,0,1);
|
||||
|
||||
return half4( lerp(red+green+blue, depthRed+depthBlue+depthGreen, zval), color.a);
|
||||
}
|
||||
|
||||
ENDCG
|
||||
|
||||
Subshader {
|
||||
Pass {
|
||||
ZTest Always Cull Off ZWrite Off
|
||||
Fog { Mode off }
|
||||
|
||||
CGPROGRAM
|
||||
#pragma vertex vert
|
||||
#pragma fragment frag
|
||||
ENDCG
|
||||
}
|
||||
}
|
||||
|
||||
Fallback off
|
||||
|
||||
} // shader
|
|
@ -0,0 +1,9 @@
|
|||
fileFormatVersion: 2
|
||||
guid: d0bb680a6a2e31949a0a38363c56003d
|
||||
ShaderImporter:
|
||||
externalObjects: {}
|
||||
defaultTextures: []
|
||||
nonModifiableTextures: []
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,62 @@
|
|||
// Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)'
|
||||
|
||||
Shader "Hidden/ColorCorrectionCurvesSimple" {
|
||||
Properties {
|
||||
_MainTex ("Base (RGB)", 2D) = "" {}
|
||||
_RgbTex ("_RgbTex (RGB)", 2D) = "" {}
|
||||
}
|
||||
|
||||
// Shader code pasted into all further CGPROGRAM blocks
|
||||
CGINCLUDE
|
||||
|
||||
#pragma fragmentoption ARB_precision_hint_fastest
|
||||
|
||||
#include "UnityCG.cginc"
|
||||
|
||||
struct v2f {
|
||||
float4 pos : POSITION;
|
||||
half2 uv : TEXCOORD0;
|
||||
};
|
||||
|
||||
sampler2D _MainTex;
|
||||
|
||||
sampler2D _RgbTex;
|
||||
|
||||
v2f vert( appdata_img v )
|
||||
{
|
||||
v2f o;
|
||||
o.pos = UnityObjectToClipPos(v.vertex);
|
||||
o.uv = v.texcoord.xy;
|
||||
return o;
|
||||
}
|
||||
|
||||
fixed4 frag(v2f i) : COLOR
|
||||
{
|
||||
fixed4 color = tex2D(_MainTex, i.uv);
|
||||
|
||||
fixed3 red = tex2D(_RgbTex, half2(color.r, 0.5/4.0)).rgb * fixed3(1,0,0);
|
||||
fixed3 green = tex2D(_RgbTex, half2(color.g, 1.5/4.0)).rgb * fixed3(0,1,0);
|
||||
fixed3 blue = tex2D(_RgbTex, half2(color.b, 2.5/4.0)).rgb * fixed3(0,0,1);
|
||||
|
||||
color = fixed4(red+green+blue, color.a);
|
||||
|
||||
return color;
|
||||
}
|
||||
|
||||
ENDCG
|
||||
|
||||
Subshader {
|
||||
Pass {
|
||||
ZTest Always Cull Off ZWrite Off
|
||||
Fog { Mode off }
|
||||
|
||||
CGPROGRAM
|
||||
#pragma vertex vert
|
||||
#pragma fragment frag
|
||||
ENDCG
|
||||
}
|
||||
}
|
||||
|
||||
Fallback off
|
||||
|
||||
} // shader
|
|
@ -0,0 +1,9 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 2051186b48dd3cd47814c53ee3be4e5f
|
||||
ShaderImporter:
|
||||
externalObjects: {}
|
||||
defaultTextures: []
|
||||
nonModifiableTextures: []
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,40 @@
|
|||
Shader "Hidden/Color Correction Effect" {
|
||||
Properties {
|
||||
_MainTex ("Base (RGB)", 2D) = "white" {}
|
||||
_RampTex ("Base (RGB)", 2D) = "grayscaleRamp" {}
|
||||
}
|
||||
|
||||
SubShader {
|
||||
Pass {
|
||||
ZTest Always Cull Off ZWrite Off
|
||||
Fog { Mode off }
|
||||
|
||||
CGPROGRAM
|
||||
#pragma vertex vert_img
|
||||
#pragma fragment frag
|
||||
#pragma fragmentoption ARB_precision_hint_fastest
|
||||
#include "UnityCG.cginc"
|
||||
|
||||
uniform sampler2D _MainTex;
|
||||
uniform sampler2D _RampTex;
|
||||
|
||||
fixed4 frag (v2f_img i) : COLOR
|
||||
{
|
||||
fixed4 orig = tex2D(_MainTex, i.uv);
|
||||
|
||||
fixed rr = tex2D(_RampTex, orig.rr).r + 0.00001; // numbers to workaround Cg's bug at D3D code generation :(
|
||||
fixed gg = tex2D(_RampTex, orig.gg).g + 0.00002;
|
||||
fixed bb = tex2D(_RampTex, orig.bb).b + 0.00003;
|
||||
|
||||
fixed4 color = fixed4(rr, gg, bb, orig.a);
|
||||
|
||||
return color;
|
||||
}
|
||||
ENDCG
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Fallback off
|
||||
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 389e9a90e301abc4dbccc75030e3b506
|
||||
ShaderImporter:
|
||||
externalObjects: {}
|
||||
defaultTextures: []
|
||||
nonModifiableTextures: []
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,56 @@
|
|||
// Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)'
|
||||
|
||||
Shader "Hidden/ColorCorrectionSelective" {
|
||||
Properties {
|
||||
_MainTex ("Base (RGB)", 2D) = "" {}
|
||||
}
|
||||
|
||||
CGINCLUDE
|
||||
|
||||
#include "UnityCG.cginc"
|
||||
|
||||
struct v2f {
|
||||
float4 pos : POSITION;
|
||||
float2 uv : TEXCOORD0;
|
||||
};
|
||||
|
||||
sampler2D _MainTex;
|
||||
|
||||
float4 selColor;
|
||||
float4 targetColor;
|
||||
|
||||
v2f vert( appdata_img v ) {
|
||||
v2f o;
|
||||
o.pos = UnityObjectToClipPos (v.vertex);
|
||||
o.uv = v.texcoord.xy;
|
||||
return o;
|
||||
}
|
||||
|
||||
float4 frag(v2f i) : COLOR {
|
||||
float4 color = tex2D (_MainTex, i.uv);
|
||||
|
||||
float differenz = 1.0 - saturate (length (color.rgb - selColor.rgb));
|
||||
color = lerp (color, targetColor, differenz);
|
||||
return color;
|
||||
}
|
||||
|
||||
ENDCG
|
||||
|
||||
Subshader {
|
||||
Pass {
|
||||
ZTest Always Cull Off ZWrite Off
|
||||
Fog { Mode off }
|
||||
|
||||
CGPROGRAM
|
||||
|
||||
#pragma fragmentoption ARB_precision_hint_fastest
|
||||
#pragma vertex vert
|
||||
#pragma fragment frag
|
||||
|
||||
ENDCG
|
||||
}
|
||||
}
|
||||
|
||||
Fallback off
|
||||
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
fileFormatVersion: 2
|
||||
guid: f76ed8bdabe97a846ba6bc08230024c0
|
||||
ShaderImporter:
|
||||
externalObjects: {}
|
||||
defaultTextures: []
|
||||
nonModifiableTextures: []
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 0397adecad4731049a472a41107afb2c
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -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
|
||||
Fog { Mode off }
|
||||
|
||||
CGPROGRAM
|
||||
#pragma vertex vert_img
|
||||
#pragma fragment frag
|
||||
#pragma fragmentoption ARB_precision_hint_fastest
|
||||
#include "UnityCG.cginc"
|
||||
|
||||
uniform sampler2D _MainTex; // currently adapted to
|
||||
uniform sampler2D _CurTex; // new value to adapt to
|
||||
uniform float4 _AdaptParams; // x=adaptLerp, y=limitMinimum, z=limitMaximum
|
||||
|
||||
float4 frag (v2f_img i) : COLOR {
|
||||
// value is: max, min
|
||||
float2 valAdapted = tex2D(_MainTex, i.uv).xy;
|
||||
float2 valCur = tex2D(_CurTex, i.uv).xy;
|
||||
|
||||
// Calculate new adapted values: interpolate
|
||||
// from valAdapted to valCur by script-supplied amount.
|
||||
//
|
||||
// Because we store adaptation levels in a simple 8 bit/channel
|
||||
// texture, we might not have enough precision - the interpolation
|
||||
// amount might be too small to change anything, and we'll never
|
||||
// arrive at the needed values.
|
||||
//
|
||||
// So we make sure the change we do is at least 1/255th of the
|
||||
// color range - this way we'll always change the value.
|
||||
const float kMinChange = 1.0/255.0;
|
||||
float2 delta = (valCur-valAdapted) * _AdaptParams.x;
|
||||
delta.x = sign(delta.x) * max( kMinChange, abs(delta.x) );
|
||||
delta.y = sign(delta.y) * max( kMinChange, abs(delta.y) );
|
||||
|
||||
float4 valNew;
|
||||
valNew.xy = valAdapted + delta;
|
||||
|
||||
// Impose user limits on maximum/minimum values
|
||||
valNew.x = max( valNew.x, _AdaptParams.z );
|
||||
valNew.y = min( valNew.y, _AdaptParams.y );
|
||||
|
||||
// Optimization so that our final apply pass is faster:
|
||||
// z = max-min (plus a small amount to prevent division by zero)
|
||||
valNew.z = valNew.x - valNew.y + 0.01;
|
||||
// w = min/(max-min)
|
||||
valNew.w = valNew.y / valNew.z;
|
||||
|
||||
return valNew;
|
||||
}
|
||||
ENDCG
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Fallback off
|
||||
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 975d70169e1053e4980279a9170560a7
|
||||
ShaderImporter:
|
||||
externalObjects: {}
|
||||
defaultTextures: []
|
||||
nonModifiableTextures: []
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,59 @@
|
|||
// Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)'
|
||||
|
||||
// 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
|
||||
Fog { Mode off }
|
||||
|
||||
CGPROGRAM
|
||||
#pragma vertex vert
|
||||
#pragma fragment frag
|
||||
#pragma fragmentoption ARB_precision_hint_fastest
|
||||
#include "UnityCG.cginc"
|
||||
|
||||
struct v2f {
|
||||
float4 pos : POSITION;
|
||||
float2 uv[2] : TEXCOORD0;
|
||||
};
|
||||
|
||||
uniform sampler2D _MainTex;
|
||||
uniform sampler2D _AdaptTex;
|
||||
|
||||
v2f vert (appdata_img v)
|
||||
{
|
||||
v2f o;
|
||||
o.pos = UnityObjectToClipPos (v.vertex);
|
||||
o.uv[0] = MultiplyUV (UNITY_MATRIX_TEXTURE0, v.texcoord);
|
||||
o.uv[1] = float2(0.5,0.5);
|
||||
return o;
|
||||
}
|
||||
|
||||
float4 frag (v2f i) : COLOR
|
||||
{
|
||||
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
|
||||
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
fileFormatVersion: 2
|
||||
guid: c071ccacdcec7c340a92f1e7ffb0d7ce
|
||||
ShaderImporter:
|
||||
externalObjects: {}
|
||||
defaultTextures: []
|
||||
nonModifiableTextures: []
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,37 @@
|
|||
// 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
|
||||
Fog { Mode off }
|
||||
|
||||
CGPROGRAM
|
||||
#pragma vertex vert_img
|
||||
#pragma fragment frag
|
||||
#pragma fragmentoption ARB_precision_hint_fastest
|
||||
#include "UnityCG.cginc"
|
||||
|
||||
uniform sampler2D _MainTex;
|
||||
|
||||
float4 frag (v2f_img i) : COLOR
|
||||
{
|
||||
float4 col = tex2D(_MainTex, i.uv);
|
||||
col.rgb = Luminance(col.rgb) * (1+col.a*2);
|
||||
return col;
|
||||
}
|
||||
ENDCG
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Fallback off
|
||||
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
fileFormatVersion: 2
|
||||
guid: ffd2ab4c9f842bb4fa99f67fa0f7fa2c
|
||||
ShaderImporter:
|
||||
externalObjects: {}
|
||||
defaultTextures: []
|
||||
nonModifiableTextures: []
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,69 @@
|
|||
// Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)'
|
||||
|
||||
// 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
|
||||
Fog { Mode off }
|
||||
|
||||
CGPROGRAM
|
||||
#pragma vertex vert
|
||||
#pragma fragment frag
|
||||
#pragma fragmentoption ARB_precision_hint_fastest
|
||||
#include "UnityCG.cginc"
|
||||
|
||||
struct v2f {
|
||||
float4 position : POSITION;
|
||||
float2 uv[4] : TEXCOORD0;
|
||||
};
|
||||
|
||||
uniform sampler2D _MainTex;
|
||||
|
||||
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] = uv + float2(0,0);
|
||||
o.uv[1] = uv + float2(0,1);
|
||||
o.uv[2] = uv + float2(1,0);
|
||||
o.uv[3] = uv + float2(1,1);
|
||||
return o;
|
||||
}
|
||||
|
||||
float4 frag (v2f i) : COLOR
|
||||
{
|
||||
// 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
|
||||
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 1628c99ba3c6cfe448ac06fddc3bb224
|
||||
ShaderImporter:
|
||||
externalObjects: {}
|
||||
defaultTextures: []
|
||||
nonModifiableTextures: []
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,71 @@
|
|||
// Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)'
|
||||
|
||||
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 : POSITION;
|
||||
float2 uv[2] : TEXCOORD0;
|
||||
};
|
||||
|
||||
sampler2D _MainTex;
|
||||
sampler2D _MainTexBlurred;
|
||||
|
||||
float4 _MainTex_TexelSize;
|
||||
|
||||
float intensity;
|
||||
float threshhold;
|
||||
|
||||
v2f vert( appdata_img v ) {
|
||||
v2f o;
|
||||
o.pos = UnityObjectToClipPos(v.vertex);
|
||||
|
||||
o.uv[0] = v.texcoord.xy;
|
||||
o.uv[1] = v.texcoord.xy;
|
||||
#if SHADER_API_D3D9
|
||||
if (_MainTex_TexelSize.y < 0)
|
||||
o.uv[0].y = 1-o.uv[0].y;
|
||||
#endif
|
||||
return o;
|
||||
}
|
||||
|
||||
half4 frag(v2f i) : COLOR
|
||||
{
|
||||
half4 color = tex2D (_MainTex, i.uv[1]);
|
||||
half4 blurred = tex2D (_MainTexBlurred, (i.uv[0]));
|
||||
|
||||
half4 difff = color - blurred;
|
||||
half4 signs = sign (difff);
|
||||
|
||||
difff = saturate ( (color-blurred) - threshhold) * signs * 1.0/(1.0-threshhold);
|
||||
color += difff * intensity;
|
||||
|
||||
return color;
|
||||
}
|
||||
|
||||
ENDCG
|
||||
|
||||
Subshader {
|
||||
Pass {
|
||||
ZTest Always Cull Off ZWrite Off
|
||||
Fog { Mode off }
|
||||
|
||||
CGPROGRAM
|
||||
#pragma fragmentoption ARB_precision_hint_fastest
|
||||
#pragma vertex vert
|
||||
#pragma fragment frag
|
||||
ENDCG
|
||||
}
|
||||
}
|
||||
|
||||
Fallback off
|
||||
|
||||
} // shader
|
|
@ -0,0 +1,9 @@
|
|||
fileFormatVersion: 2
|
||||
guid: b3de9c284149b9e44a743a258f65c742
|
||||
ShaderImporter:
|
||||
externalObjects: {}
|
||||
defaultTextures: []
|
||||
nonModifiableTextures: []
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,58 @@
|
|||
// Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)'
|
||||
|
||||
Shader "Hidden/ConvertDepth" {
|
||||
Properties {
|
||||
_MainTex ("Base (RGB)", 2D) = "" {}
|
||||
}
|
||||
|
||||
// Shader code pasted into all further CGPROGRAM blocks
|
||||
CGINCLUDE
|
||||
|
||||
#include "UnityCG.cginc"
|
||||
|
||||
struct v2f {
|
||||
float4 pos : POSITION;
|
||||
float2 uv : TEXCOORD0;
|
||||
};
|
||||
|
||||
sampler2D _MainTex;
|
||||
sampler2D _CameraDepthTexture;
|
||||
|
||||
v2f vert( appdata_img v )
|
||||
{
|
||||
v2f o;
|
||||
o.pos = UnityObjectToClipPos(v.vertex);
|
||||
o.uv = v.texcoord.xy;
|
||||
return o;
|
||||
}
|
||||
|
||||
half4 frag(v2f i) : COLOR
|
||||
{
|
||||
float d = UNITY_SAMPLE_DEPTH( tex2D(_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
|
||||
Fog { Mode off }
|
||||
|
||||
CGPROGRAM
|
||||
#pragma fragmentoption ARB_precision_hint_fastest
|
||||
#pragma vertex vert
|
||||
#pragma fragment frag
|
||||
ENDCG
|
||||
}
|
||||
}
|
||||
|
||||
Fallback off
|
||||
|
||||
} // shader
|
|
@ -0,0 +1,9 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 515b3f2768e317742a07c4ec40a67697
|
||||
ShaderImporter:
|
||||
externalObjects: {}
|
||||
defaultTextures: []
|
||||
nonModifiableTextures: []
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,65 @@
|
|||
// Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)'
|
||||
|
||||
|
||||
|
||||
Shader "Hidden/CreaseApply" {
|
||||
Properties {
|
||||
_MainTex ("Base (RGB)", 2D) = "white" {}
|
||||
_HrDepthTex ("Base (RGB)", 2D) = "white" {}
|
||||
_LrDepthTex ("Base (RGB)", 2D) = "white" {}
|
||||
}
|
||||
|
||||
SubShader {
|
||||
Pass {
|
||||
ZTest Always Cull Off ZWrite Off
|
||||
Fog { Mode off }
|
||||
|
||||
CGPROGRAM
|
||||
#pragma fragmentoption ARB_precision_hint_fastest
|
||||
#pragma vertex vert
|
||||
#pragma fragment frag
|
||||
#include "UnityCG.cginc"
|
||||
|
||||
sampler2D _MainTex;
|
||||
sampler2D _HrDepthTex;
|
||||
sampler2D _LrDepthTex;
|
||||
|
||||
uniform float4 _MainTex_TexelSize;
|
||||
|
||||
uniform float intensity;
|
||||
|
||||
struct v2f {
|
||||
float4 pos : POSITION;
|
||||
float2 uv : TEXCOORD0;
|
||||
};
|
||||
|
||||
v2f vert( appdata_img v )
|
||||
{
|
||||
v2f o;
|
||||
o.pos = UnityObjectToClipPos (v.vertex);
|
||||
o.uv.xy = v.texcoord.xy;
|
||||
return o;
|
||||
}
|
||||
|
||||
half4 frag (v2f i) : COLOR
|
||||
{
|
||||
float4 hrDepth = tex2D(_HrDepthTex, i.uv);
|
||||
float4 lrDepth = tex2D(_LrDepthTex, i.uv);
|
||||
|
||||
hrDepth.a = DecodeFloatRGBA(hrDepth);
|
||||
lrDepth.a = DecodeFloatRGBA(lrDepth);
|
||||
|
||||
float4 color = tex2D(_MainTex, i.uv);
|
||||
|
||||
return color * (1.0-abs(hrDepth.a-lrDepth.a)*intensity);
|
||||
}
|
||||
|
||||
ENDCG
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Fallback off
|
||||
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue