Demo Hotfixes

Replaced Unity TAA with PlayDead TAA
Custom keyboard layout test scene
Adjusted Aetheric Drive VFX to be more subtle
Reworked stardust VFX to reduce flickering artifacts
Added Action Bar & weapon groups saving/loading
Implemented security levels and faction safe zone visualization
Improved station placement (now include defensive turrets)
This commit is contained in:
Reinier Vens 2021-05-02 20:59:45 +01:00
commit 2c4520000b
128 changed files with 12821 additions and 561 deletions

View file

@ -0,0 +1,130 @@
// Copyright (c) <2015> <Playdead>
// This file is subject to the MIT License as seen in the root of this folder structure (LICENSE.TXT)
// AUTHOR: Lasse Jon Fuglsang Pedersen <lasse@playdead.com>
using UnityEngine;
public abstract class EffectBase : MonoBehaviour
{
public void EnsureArray<T>(ref T[] array, int size, T initialValue = default(T))
{
if (array == null || array.Length != size)
{
array = new T[size];
for (int i = 0; i != size; i++)
array[i] = initialValue;
}
}
public void EnsureArray<T>(ref T[,] array, int size0, int size1, T defaultValue = default(T))
{
if (array == null || array.Length != size0 * size1)
{
array = new T[size0, size1];
for (int i = 0; i != size0; i++)
{
for (int j = 0; j != size1; j++)
array[i, j] = defaultValue;
}
}
}
public void EnsureMaterial(ref Material material, Shader shader)
{
if (shader != null)
{
if (material == null || material.shader != shader)
material = new Material(shader);
if (material != null)
material.hideFlags = HideFlags.DontSave;
}
else
{
Debug.LogWarning("missing shader", this);
}
}
public void EnsureDepthTexture(Camera camera)
{
if ((camera.depthTextureMode & DepthTextureMode.Depth) == 0)
camera.depthTextureMode |= DepthTextureMode.Depth;
}
public void EnsureKeyword(Material material, string name, bool enabled)
{
if (enabled != material.IsKeywordEnabled(name))
{
if (enabled)
material.EnableKeyword(name);
else
material.DisableKeyword(name);
}
}
public bool EnsureRenderTarget(ref RenderTexture rt, int width, int height, RenderTextureFormat format, FilterMode filterMode, int depthBits = 0, int antiAliasing = 1)
{
if (rt != null && (rt.width != width || rt.height != height || rt.format != format || rt.filterMode != filterMode || rt.antiAliasing != antiAliasing))
{
RenderTexture.ReleaseTemporary(rt);
rt = null;
}
if (rt == null)
{
rt = RenderTexture.GetTemporary(width, height, depthBits, format, RenderTextureReadWrite.Default, antiAliasing);
rt.filterMode = filterMode;
rt.wrapMode = TextureWrapMode.Clamp;
return true;// new target
}
return false;// same target
}
public void ReleaseRenderTarget(ref RenderTexture rt)
{
if (rt != null)
{
RenderTexture.ReleaseTemporary(rt);
rt = null;
}
}
public void DrawFullscreenQuad()
{
GL.PushMatrix();
GL.LoadOrtho();
GL.Begin(GL.QUADS);
{
GL.MultiTexCoord2(0, 0.0f, 0.0f);
GL.Vertex3(0.0f, 0.0f, 0.0f); // BL
GL.MultiTexCoord2(0, 1.0f, 0.0f);
GL.Vertex3(1.0f, 0.0f, 0.0f); // BR
GL.MultiTexCoord2(0, 1.0f, 1.0f);
GL.Vertex3(1.0f, 1.0f, 0.0f); // TR
GL.MultiTexCoord2(0, 0.0f, 1.0f);
GL.Vertex3(0.0f, 1.0f, 0.0f); // TL
}
GL.End();
GL.PopMatrix();
}
public void DrawFullscreenTri()
{
GL.PushMatrix();
GL.LoadOrtho();
GL.Begin(GL.TRIANGLES);
{
GL.MultiTexCoord2(0, 0.0f, 0.0f);
GL.Vertex3(0.0f, 0.0f, 0.0f);
GL.MultiTexCoord2(0, 2.0f, 0.0f);
GL.Vertex3(2.0f, 0.0f, 0.0f);
GL.MultiTexCoord2(0, 0.0f, 2.0f);
GL.Vertex3(0.0f, 2.0f, 0.0f);
}
GL.End();
GL.PopMatrix();
}
}

View file

@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 4e5bbb5f788c9d84d8173556caa0b920
timeCreated: 1438002115
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,172 @@
// Copyright (c) <2015> <Playdead>
// This file is subject to the MIT License as seen in the root of this folder structure (LICENSE.TXT)
// AUTHOR: Lasse Jon Fuglsang Pedersen <lasse@playdead.com>
#if UNITY_5_5_OR_NEWER
#define SUPPORT_STEREO
#endif
using UnityEngine;
public static class Vector2Extension
{
// positive if v2 is on the left side of v1
public static float SignedAngle(this Vector2 v1, Vector2 v2)
{
Vector2 n1 = v1.normalized;
Vector2 n2 = v2.normalized;
float dot = Vector2.Dot(n1, n2);
if (dot > 1.0f)
dot = 1.0f;
if (dot < -1.0f)
dot = -1.0f;
float theta = Mathf.Acos(dot);
float sgn = Vector2.Dot(new Vector2(-n1.y, n1.x), n2);
if (sgn >= 0.0f)
return theta;
else
return -theta;
}
public static Vector2 Rotate(this Vector2 v, float theta)
{
float cs = Mathf.Cos(theta);
float sn = Mathf.Sin(theta);
float x1 = v.x * cs - v.y * sn;
float y1 = v.x * sn + v.y * cs;
return new Vector2(x1, y1);
}
}
public static class Vector3Extension
{
public static Vector3 WithX(this Vector3 v, float x)
{
return new Vector3(x, v.y, v.z);
}
public static Vector3 WithY(this Vector3 v, float y)
{
return new Vector3(v.x, y, v.z);
}
public static Vector3 WithZ(this Vector3 v, float z)
{
return new Vector3(v.x, v.y, z);
}
}
public static class Matrix4x4Extension
{
public static Matrix4x4 GetPerspectiveProjection(float left, float right, float bottom, float top, float near, float far)
{
float x = (2.0f * near) / (right - left);
float y = (2.0f * near) / (top - bottom);
float a = (right + left) / (right - left);
float b = (top + bottom) / (top - bottom);
float c = -(far + near) / (far - near);
float d = -(2.0f * far * near) / (far - near);
float e = -1.0f;
Matrix4x4 m = new Matrix4x4();
m[0, 0] = x; m[0, 1] = 0; m[0, 2] = a; m[0, 3] = 0;
m[1, 0] = 0; m[1, 1] = y; m[1, 2] = b; m[1, 3] = 0;
m[2, 0] = 0; m[2, 1] = 0; m[2, 2] = c; m[2, 3] = d;
m[3, 0] = 0; m[3, 1] = 0; m[3, 2] = e; m[3, 3] = 0;
return m;
}
public static Matrix4x4 GetOrthographicProjection(float left, float right, float bottom, float top, float near, float far)
{
float x = 2.0f / (right - left);
float y = 2.0f / (top - bottom);
float z = -2.0f / (far - near);
float a = -(right + left) / (right - left);
float b = -(top + bottom) / (top - bottom);
float c = -(far + near) / (far - near);
float d = 1.0f;
Matrix4x4 m = new Matrix4x4();
m[0, 0] = x; m[0, 1] = 0; m[0, 2] = 0; m[0, 3] = a;
m[1, 0] = 0; m[1, 1] = y; m[1, 2] = 0; m[1, 3] = b;
m[2, 0] = 0; m[2, 1] = 0; m[2, 2] = z; m[2, 3] = c;
m[3, 0] = 0; m[3, 1] = 0; m[3, 2] = 0; m[3, 3] = d;
return m;
}
}
public static class CameraExtension
{
public static Vector4 GetProjectionExtents(this Camera camera)
{
return GetProjectionExtents(camera, 0.0f, 0.0f);
}
public static Vector4 GetProjectionExtents(this Camera camera, float texelOffsetX, float texelOffsetY)
{
if (camera == null)
return Vector4.zero;
float oneExtentY = camera.orthographic ? camera.orthographicSize : Mathf.Tan(0.5f * Mathf.Deg2Rad * camera.fieldOfView);
float oneExtentX = oneExtentY * camera.aspect;
float texelSizeX = oneExtentX / (0.5f * camera.pixelWidth);
float texelSizeY = oneExtentY / (0.5f * camera.pixelHeight);
float oneJitterX = texelSizeX * texelOffsetX;
float oneJitterY = texelSizeY * texelOffsetY;
return new Vector4(oneExtentX, oneExtentY, oneJitterX, oneJitterY);// xy = frustum extents at distance 1, zw = jitter at distance 1
}
#if SUPPORT_STEREO
public static Vector4 GetProjectionExtents(this Camera camera, Camera.StereoscopicEye eye)
{
return GetProjectionExtents(camera, eye, 0.0f, 0.0f);
}
public static Vector4 GetProjectionExtents(this Camera camera, Camera.StereoscopicEye eye, float texelOffsetX, float texelOffsetY)
{
Matrix4x4 inv = Matrix4x4.Inverse(camera.GetStereoProjectionMatrix(eye));
Vector3 ray00 = inv.MultiplyPoint3x4(new Vector3(-1.0f, -1.0f, 0.95f));
Vector3 ray11 = inv.MultiplyPoint3x4(new Vector3(1.0f, 1.0f, 0.95f));
ray00 /= -ray00.z;
ray11 /= -ray11.z;
float oneExtentX = 0.5f * (ray11.x - ray00.x);
float oneExtentY = 0.5f * (ray11.y - ray00.y);
float texelSizeX = oneExtentX / (0.5f * camera.pixelWidth);
float texelSizeY = oneExtentY / (0.5f * camera.pixelHeight);
float oneJitterX = 0.5f * (ray11.x + ray00.x) + texelSizeX * texelOffsetX;
float oneJitterY = 0.5f * (ray11.y + ray00.y) + texelSizeY * texelOffsetY;
return new Vector4(oneExtentX, oneExtentY, oneJitterX, oneJitterY);// xy = frustum extents at distance 1, zw = jitter at distance 1
}
#endif
public static Matrix4x4 GetProjectionMatrix(this Camera camera)
{
return GetProjectionMatrix(camera, 0.0f, 0.0f);
}
public static Matrix4x4 GetProjectionMatrix(this Camera camera, float texelOffsetX, float texelOffsetY)
{
if (camera == null)
return Matrix4x4.identity;
Vector4 extents = GetProjectionExtents(camera, texelOffsetX, texelOffsetY);
float cf = camera.farClipPlane;
float cn = camera.nearClipPlane;
float xm = extents.z - extents.x;
float xp = extents.z + extents.x;
float ym = extents.w - extents.y;
float yp = extents.w + extents.y;
if (camera.orthographic)
return Matrix4x4Extension.GetOrthographicProjection(xm, xp, ym, yp, cn, cf);
else
return Matrix4x4Extension.GetPerspectiveProjection(xm * cn, xp * cn, ym * cn, yp * cn, cn, cf);
}
}

View file

@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: e8364b88f137b7844ab5b8ca8776f54f
timeCreated: 1437997052
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,328 @@
// Copyright (c) <2015> <Playdead>
// This file is subject to the MIT License as seen in the root of this folder structure (LICENSE.TXT)
// AUTHOR: Lasse Jon Fuglsang Pedersen <lasse@playdead.com>
#if UNITY_5_5_OR_NEWER
#define SUPPORT_STEREO
#endif
using UnityEngine;
[ExecuteInEditMode]
[RequireComponent(typeof(Camera))]
[AddComponentMenu("Playdead/FrustumJitter")]
public class FrustumJitter : MonoBehaviour
{
#region Static point data
private static float[] points_Still = new float[] {
0.5f, 0.5f,
};
private static float[] points_Uniform2 = new float[] {
-0.25f, -0.25f,//ll
0.25f, 0.25f,//ur
};
private static float[] points_Uniform4 = new float[] {
-0.25f, -0.25f,//ll
0.25f, -0.25f,//lr
0.25f, 0.25f,//ur
-0.25f, 0.25f,//ul
};
private static float[] points_Uniform4_Helix = new float[] {
-0.25f, -0.25f,//ll 3 1
0.25f, 0.25f,//ur \/|
0.25f, -0.25f,//lr /\|
-0.25f, 0.25f,//ul 0 2
};
private static float[] points_Uniform4_DoubleHelix = new float[] {
-0.25f, -0.25f,//ll 3 1
0.25f, 0.25f,//ur \/|
0.25f, -0.25f,//lr /\|
-0.25f, 0.25f,//ul 0 2
-0.25f, -0.25f,//ll 6--7
0.25f, -0.25f,//lr \
-0.25f, 0.25f,//ul \
0.25f, 0.25f,//ur 4--5
};
private static float[] points_SkewButterfly = new float[] {
-0.250f, -0.250f,
0.250f, 0.250f,
0.125f, -0.125f,
-0.125f, 0.125f,
};
private static float[] points_Rotated4 = new float[] {
-0.125f, -0.375f,//ll
0.375f, -0.125f,//lr
0.125f, 0.375f,//ur
-0.375f, 0.125f,//ul
};
private static float[] points_Rotated4_Helix = new float[] {
-0.125f, -0.375f,//ll 3 1
0.125f, 0.375f,//ur \/|
0.375f, -0.125f,//lr /\|
-0.375f, 0.125f,//ul 0 2
};
private static float[] points_Rotated4_Helix2 = new float[] {
-0.125f, -0.375f,//ll 2--1
0.125f, 0.375f,//ur \/
-0.375f, 0.125f,//ul /\
0.375f, -0.125f,//lr 0 3
};
private static float[] points_Poisson10 = new float[] {
-0.16795960f*0.25f, 0.65544910f*0.25f,
-0.69096030f*0.25f, 0.59015970f*0.25f,
0.49843820f*0.25f, 0.83099720f*0.25f,
0.17230150f*0.25f, -0.03882703f*0.25f,
-0.60772670f*0.25f, -0.06013587f*0.25f,
0.65606390f*0.25f, 0.24007600f*0.25f,
0.80348370f*0.25f, -0.48096900f*0.25f,
0.33436540f*0.25f, -0.73007030f*0.25f,
-0.47839520f*0.25f, -0.56005300f*0.25f,
-0.12388120f*0.25f, -0.96633990f*0.25f,
};
private static float[] points_Pentagram = new float[] {
0.000000f*0.5f, 0.525731f*0.5f,// head
-0.309017f*0.5f, -0.425325f*0.5f,// lleg
0.500000f*0.5f, 0.162460f*0.5f,// rarm
-0.500000f*0.5f, 0.162460f*0.5f,// larm
0.309017f*0.5f, -0.425325f*0.5f,// rleg
};
private static float[] points_Halton_2_3_x8 = new float[8 * 2];
private static float[] points_Halton_2_3_x16 = new float[16 * 2];
private static float[] points_Halton_2_3_x32 = new float[32 * 2];
private static float[] points_Halton_2_3_x256 = new float[256 * 2];
private static float[] points_MotionPerp2 = new float[] {
0.00f, -0.25f,
0.00f, 0.25f,
};
#endregion
#region Static point data, static initialization
private static void TransformPattern(float[] seq, float theta, float scale)
{
float cs = Mathf.Cos(theta);
float sn = Mathf.Sin(theta);
for (int i = 0, j = 1, n = seq.Length; i != n; i += 2, j += 2)
{
float x = scale * seq[i];
float y = scale * seq[j];
seq[i] = x * cs - y * sn;
seq[j] = x * sn + y * cs;
}
}
// http://en.wikipedia.org/wiki/Halton_sequence
public static float HaltonSeq(int prime, int index = 1/* NOT! zero-based */)
{
float r = 0.0f;
float f = 1.0f;
int i = index;
while (i > 0)
{
f /= prime;
r += f * (i % prime);
i = (int)Mathf.Floor(i / (float)prime);
}
return r;
}
private static void InitializeHalton_2_3(float[] seq)
{
for (int i = 0, n = seq.Length / 2; i != n; i++)
{
float u = HaltonSeq(2, i + 1) - 0.5f;
float v = HaltonSeq(3, i + 1) - 0.5f;
seq[2 * i + 0] = u;
seq[2 * i + 1] = v;
}
}
static FrustumJitter()
{
// points_Pentagram
Vector2 vh = new Vector2(points_Pentagram[0] - points_Pentagram[2], points_Pentagram[1] - points_Pentagram[3]);
Vector2 vu = new Vector2(0.0f, 1.0f);
TransformPattern(points_Pentagram, Mathf.Deg2Rad * (0.5f * Vector2.Angle(vu, vh)), 1.0f);
// points_Halton_2_3_xN
InitializeHalton_2_3(points_Halton_2_3_x8);
InitializeHalton_2_3(points_Halton_2_3_x16);
InitializeHalton_2_3(points_Halton_2_3_x32);
InitializeHalton_2_3(points_Halton_2_3_x256);
}
#endregion
#region Static point data accessors
public enum Pattern
{
Still,
Uniform2,
Uniform4,
Uniform4_Helix,
Uniform4_DoubleHelix,
SkewButterfly,
Rotated4,
Rotated4_Helix,
Rotated4_Helix2,
Poisson10,
Pentagram,
Halton_2_3_X8,
Halton_2_3_X16,
Halton_2_3_X32,
Halton_2_3_X256,
MotionPerp2,
};
private static float[] AccessPointData(Pattern pattern)
{
switch (pattern)
{
case Pattern.Still:
return points_Still;
case Pattern.Uniform2:
return points_Uniform2;
case Pattern.Uniform4:
return points_Uniform4;
case Pattern.Uniform4_Helix:
return points_Uniform4_Helix;
case Pattern.Uniform4_DoubleHelix:
return points_Uniform4_DoubleHelix;
case Pattern.SkewButterfly:
return points_SkewButterfly;
case Pattern.Rotated4:
return points_Rotated4;
case Pattern.Rotated4_Helix:
return points_Rotated4_Helix;
case Pattern.Rotated4_Helix2:
return points_Rotated4_Helix2;
case Pattern.Poisson10:
return points_Poisson10;
case Pattern.Pentagram:
return points_Pentagram;
case Pattern.Halton_2_3_X8:
return points_Halton_2_3_x8;
case Pattern.Halton_2_3_X16:
return points_Halton_2_3_x16;
case Pattern.Halton_2_3_X32:
return points_Halton_2_3_x32;
case Pattern.Halton_2_3_X256:
return points_Halton_2_3_x256;
case Pattern.MotionPerp2:
return points_MotionPerp2;
default:
Debug.LogError("missing point distribution");
return points_Halton_2_3_x16;
}
}
public static int AccessLength(Pattern pattern)
{
return AccessPointData(pattern).Length / 2;
}
public Vector2 Sample(Pattern pattern, int index)
{
float[] points = AccessPointData(pattern);
int n = points.Length / 2;
int i = index % n;
float x = patternScale * points[2 * i + 0];
float y = patternScale * points[2 * i + 1];
if (pattern != Pattern.MotionPerp2)
return new Vector2(x, y);
else
return new Vector2(x, y).Rotate(Vector2.right.SignedAngle(focalMotionDir));
}
#endregion
private Camera _camera;
private Vector3 focalMotionPos = Vector3.zero;
private Vector3 focalMotionDir = Vector3.right;
public Pattern pattern = Pattern.Halton_2_3_X16;
public float patternScale = 1.0f;
public Vector4 activeSample = Vector4.zero;// xy = current sample, zw = previous sample
public int activeIndex = -2;
void Reset()
{
_camera = GetComponent<Camera>();
}
void Clear()
{
_camera.ResetProjectionMatrix();
activeSample = Vector4.zero;
activeIndex = -2;
}
void Awake()
{
Reset();
Clear();
}
void OnPreCull()
{
// update motion dir
{
Vector3 oldWorld = focalMotionPos;
Vector3 newWorld = _camera.transform.TransformVector(_camera.nearClipPlane * Vector3.forward);
Vector3 oldPoint = (_camera.worldToCameraMatrix * oldWorld);
Vector3 newPoint = (_camera.worldToCameraMatrix * newWorld);
Vector3 newDelta = (newPoint - oldPoint).WithZ(0.0f);
var mag = newDelta.magnitude;
if (mag != 0.0f)
{
var dir = newDelta / mag;// yes, apparently this is necessary instead of newDelta.normalized... because facepalm
if (dir.sqrMagnitude != 0.0f)
{
focalMotionPos = newWorld;
focalMotionDir = Vector3.Slerp(focalMotionDir, dir, 0.2f);
//Debug.Log("CHANGE focalMotionDir " + focalMotionDir.ToString("G4") + " delta was " + newDelta.ToString("G4") + " delta.mag " + newDelta.magnitude);
}
}
}
// update jitter
#if SUPPORT_STEREO
if (_camera.stereoEnabled)
{
Clear();
}
else
#endif
{
if (activeIndex == -2)
{
activeSample = Vector4.zero;
activeIndex += 1;
_camera.projectionMatrix = _camera.GetProjectionMatrix();
}
else
{
activeIndex += 1;
activeIndex %= AccessLength(pattern);
Vector2 sample = Sample(pattern, activeIndex);
activeSample.z = activeSample.x;
activeSample.w = activeSample.y;
activeSample.x = sample.x;
activeSample.y = sample.y;
_camera.projectionMatrix = _camera.GetProjectionMatrix(sample.x, sample.y);
}
}
}
void OnDisable()
{
Clear();
}
}

View file

@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 899f97884c6d96b4ca20648ec109a37f
timeCreated: 1437991076
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,266 @@
// Copyright (c) <2015> <Playdead>
// This file is subject to the MIT License as seen in the root of this folder structure (LICENSE.TXT)
// AUTHOR: Lasse Jon Fuglsang Pedersen <lasse@playdead.com>
#if UNITY_5_5_OR_NEWER
#define SUPPORT_STEREO
#endif
using UnityEngine;
[ExecuteInEditMode]
[RequireComponent(typeof(Camera), typeof(FrustumJitter), typeof(VelocityBuffer))]
[AddComponentMenu("Playdead/TemporalReprojection")]
public class TemporalReprojection : EffectBase
{
private static RenderBuffer[] mrt = new RenderBuffer[2];
private Camera _camera;
private FrustumJitter _frustumJitter;
private VelocityBuffer _velocityBuffer;
#region dithering
public Texture ditherTex = null;
private const int NUM_DITHEROFS = 1024;
const float DITHERSIZ = 256;
private static int frameofs = 0;
private static Vector4[] ditheroffsets = null;
public static Vector4 GetFrame_DitherOffset()
{
if ( ditheroffsets == null )
init_ditheroffsets();
frameofs = (frameofs+1) % NUM_DITHEROFS;
return ditheroffsets[frameofs];
}
private static void init_ditheroffsets()
{
if ( ditheroffsets != null )
return;
ditheroffsets = new Vector4[NUM_DITHEROFS];
for ( int i=0, n=ditheroffsets.Length; i<n; ++i )
{
Vector4 p = new Vector4( DITHERSIZ * FrustumJitter.HaltonSeq(2, i+1),
DITHERSIZ * FrustumJitter.HaltonSeq(3, i+1),
DITHERSIZ * FrustumJitter.HaltonSeq(5, i+1),
DITHERSIZ * FrustumJitter.HaltonSeq(7, i+1) );
ditheroffsets[i] = new Vector4( Mathf.Floor(p.x),
Mathf.Floor(p.y),
Mathf.Floor(p.z),
Mathf.Floor(p.w) );
}
}
#endregion
public Shader reprojectionShader;
private Material reprojectionMaterial;
private RenderTexture[,] reprojectionBuffer;
private int[] reprojectionIndex = new int[2] { -1, -1 };
public enum Dilation
{
None, Dilate5X, Dilate3X3
};
public enum HistoryRectification
{
Clamping, CenterClipping, Clipping
};
public enum ColorSpace
{
RGB, Chroma /*YCoCg, YCrCg?*/
};
//public bool unjitterColorSamples = true;
//public bool unjitterNeighborhood = false;
//public bool unjitterReprojection = false;
[Tooltip("TAA colorspace. RGB is faster, Chroma is more better")]
public ColorSpace colorspace = ColorSpace.RGB;
[Tooltip("use soft-cubic for sampling maincolor")]
public bool useHigherOrderFilteringMainColor = false;
[Tooltip("use catmull-rom for sampling historybuffer")]
public bool useHigherOrderFilteringHistory = true;
[Tooltip("History color restricted by clamping (faster), centerClipping or clipping (better)")]
public HistoryRectification historyRectification = HistoryRectification.Clamping;
[Tooltip("Shrink color-aabb using variance of neighborhood")]
public bool useVarianceClipping = true;
[Tooltip("Smooth color-aabb using rounding")]
public bool useAABBRounding = true;
public Dilation dilation = Dilation.Dilate3X3;
public bool useMotionBlur = true;
[Range(0.0f, 1.0f)] public float feedbackMin = 0.88f;
[Range(0.0f, 1.0f)] public float feedbackMax = 0.97f;
public float motionBlurStrength = 1.0f;
public bool motionBlurIgnoreFF = false;
#region shaderparms
int jitter_id = -1; int JitterUVID() { if (jitter_id < 0) jitter_id = Shader.PropertyToID("_JitterUV"); return jitter_id; }
int vb_id =-1; int VelocityBufferID() { if (vb_id<0) vb_id=Shader.PropertyToID( "_VelocityBuffer" ); return vb_id; }
int vnm_id=-1; int VelocityNeighborMaxID() { if (vnm_id<0) vnm_id=Shader.PropertyToID( "_VelocityNeighborMax" ); return vnm_id; }
int maintex_id=-1; int MainTexID() { if (maintex_id<0) maintex_id=Shader.PropertyToID( "_MainTex" ); return maintex_id; }
int prevtex_id=-1; int PrevTexID() { if (prevtex_id<0) prevtex_id=Shader.PropertyToID( "_PrevTex" ); return prevtex_id; }
int fbmin_id=-1; int FeedbackMinID() { if (fbmin_id<0) fbmin_id=Shader.PropertyToID( "_FeedbackMin" ); return fbmin_id; }
int fbmax_id=-1; int FeedbackMinMaxID() { if (fbmax_id<0) fbmax_id=Shader.PropertyToID( "_FeedbackMinMax" ); return fbmax_id; }
int ms_id=-1; int MotionScaleID() { if (ms_id<0) ms_id=Shader.PropertyToID( "_MotionScale" ); return ms_id; }
int dithertex_id=-1; int DitherTexID() { if (dithertex_id<0) dithertex_id=Shader.PropertyToID( "_DitherTex" ); return dithertex_id; }
int ditherofslocal_id=-1; int DitherOffsetLocalID() { if (ditherofslocal_id<0) ditherofslocal_id=Shader.PropertyToID( "_DitherOffset_local" ); return ditherofslocal_id; }
#endregion
void Reset()
{
_camera = GetComponent<Camera>();
_frustumJitter = GetComponent<FrustumJitter>();
_velocityBuffer = GetComponent<VelocityBuffer>();
}
void Clear()
{
EnsureArray(ref reprojectionIndex, 2);
reprojectionIndex[0] = -1;
reprojectionIndex[1] = -1;
}
void Awake()
{
Reset();
Clear();
}
void Resolve(RenderTexture source, RenderTexture destination)
{
EnsureArray(ref reprojectionBuffer, 2, 2);
EnsureArray(ref reprojectionIndex, 2, initialValue: -1);
EnsureMaterial(ref reprojectionMaterial, reprojectionShader);
if (reprojectionMaterial == null)
{
Graphics.Blit(source, destination);
return;
}
#if SUPPORT_STEREO
int eyeIndex = (_camera.stereoActiveEye == Camera.MonoOrStereoscopicEye.Right) ? 1 : 0;
#else
int eyeIndex = 0;
#endif
int bufferW = source.width;
int bufferH = source.height;
if (EnsureRenderTarget(ref reprojectionBuffer[eyeIndex, 0], bufferW, bufferH, RenderTextureFormat.ARGB32, FilterMode.Bilinear, antiAliasing: source.antiAliasing))
Clear();
if (EnsureRenderTarget(ref reprojectionBuffer[eyeIndex, 1], bufferW, bufferH, RenderTextureFormat.ARGB32, FilterMode.Bilinear, antiAliasing: source.antiAliasing))
Clear();
#if SUPPORT_STEREO
bool stereoEnabled = _camera.stereoEnabled;
#else
bool stereoEnabled = false;
#endif
#if UNITY_EDITOR
bool allowMotionBlur = !stereoEnabled && Application.isPlaying;
#else
bool allowMotionBlur = !stereoEnabled;
#endif
EnsureKeyword(reprojectionMaterial, "CAMERA_PERSPECTIVE", !_camera.orthographic);
EnsureKeyword(reprojectionMaterial, "CAMERA_ORTHOGRAPHIC", _camera.orthographic);
//EnsureKeyword(reprojectionMaterial, "UNJITTER_COLORSAMPLES", unjitterColorSamples);
//EnsureKeyword(reprojectionMaterial, "UNJITTER_NEIGHBORHOOD", unjitterNeighborhood);
//EnsureKeyword(reprojectionMaterial, "UNJITTER_REPROJECTION", unjitterReprojection);
EnsureKeyword(reprojectionMaterial, "USE_CHROMA_COLORSPACE", colorspace == ColorSpace.Chroma);
EnsureKeyword(reprojectionMaterial, "USE_CLIPPING", historyRectification == HistoryRectification.CenterClipping || historyRectification == HistoryRectification.Clipping );
EnsureKeyword(reprojectionMaterial, "USE_CENTER_CLIPPING", historyRectification == HistoryRectification.CenterClipping );
EnsureKeyword(reprojectionMaterial, "USE_VARIANCE_CLIPPING", useVarianceClipping );
EnsureKeyword(reprojectionMaterial, "USE_AABB_ROUNDING", useAABBRounding );
EnsureKeyword(reprojectionMaterial, "USE_DILATION_5X", dilation == Dilation.Dilate5X);
EnsureKeyword(reprojectionMaterial, "USE_DILATION_3X3", dilation == Dilation.Dilate3X3);
EnsureKeyword(reprojectionMaterial, "USE_MOTION_BLUR", useMotionBlur && allowMotionBlur);
EnsureKeyword(reprojectionMaterial, "USE_MOTION_BLUR_NEIGHBORMAX", _velocityBuffer.activeVelocityNeighborMax != null);
EnsureKeyword(reprojectionMaterial, "USE_HIGHER_ORDER_TEXTURE_FILTERING_COLOR", useHigherOrderFilteringMainColor);
EnsureKeyword(reprojectionMaterial, "USE_HIGHER_ORDER_TEXTURE_FILTERING_HISTORY", useHigherOrderFilteringHistory);
if (reprojectionIndex[eyeIndex] == -1)// bootstrap
{
reprojectionIndex[eyeIndex] = 0;
reprojectionBuffer[eyeIndex, reprojectionIndex[eyeIndex]].DiscardContents();
Graphics.Blit(source, reprojectionBuffer[eyeIndex, reprojectionIndex[eyeIndex]]);
}
int indexRead = reprojectionIndex[eyeIndex];
int indexWrite = (reprojectionIndex[eyeIndex] + 1) % 2;
Vector4 jitterUV = _frustumJitter.activeSample;
jitterUV.x /= source.width;
jitterUV.y /= source.height;
jitterUV.z /= source.width;
jitterUV.w /= source.height;
reprojectionMaterial.SetVector(JitterUVID(), jitterUV);
reprojectionMaterial.SetTexture(VelocityBufferID(), _velocityBuffer.activeVelocityBuffer);
reprojectionMaterial.SetTexture(VelocityNeighborMaxID(), _velocityBuffer.activeVelocityNeighborMax);
reprojectionMaterial.SetTexture(MainTexID(), source);
reprojectionMaterial.SetTexture(PrevTexID(), reprojectionBuffer[eyeIndex, indexRead]);
reprojectionMaterial.SetFloat(FeedbackMinID(), feedbackMin);
reprojectionMaterial.SetFloat(FeedbackMinMaxID(), feedbackMax - feedbackMin);
reprojectionMaterial.SetFloat(MotionScaleID(), motionBlurStrength * (motionBlurIgnoreFF ? Mathf.Min(1.0f, 1.0f / _velocityBuffer.timeScale) : 1.0f));
reprojectionMaterial.SetTexture(DitherTexID(), ditherTex);
Vector4 ofs = GetFrame_DitherOffset();
reprojectionMaterial.SetVector( DitherOffsetLocalID(), GetFrame_DitherOffset() );
// reproject frame n-1 into output + history buffer
{
mrt[0] = reprojectionBuffer[eyeIndex, indexWrite].colorBuffer;
mrt[1] = destination.colorBuffer;
Graphics.SetRenderTarget(mrt, source.depthBuffer);
reprojectionMaterial.SetPass(0);
reprojectionBuffer[eyeIndex, indexWrite].DiscardContents();
//DrawFullscreenQuad();
DrawFullscreenTri();
reprojectionIndex[eyeIndex] = indexWrite;
}
}
void OnRenderImage(RenderTexture source, RenderTexture destination)
{
if (destination != null && source.antiAliasing == destination.antiAliasing)// resolve without additional blit when not end of chain
{
Resolve(source, destination);
}
else
{
RenderTexture internalDestination = RenderTexture.GetTemporary(source.width, source.height, 0, RenderTextureFormat.ARGB32, RenderTextureReadWrite.Default, source.antiAliasing);
{
Resolve(source, internalDestination);
Graphics.Blit(internalDestination, destination);
}
RenderTexture.ReleaseTemporary(internalDestination);
}
}
void OnApplicationQuit()
{
if (reprojectionBuffer != null)
{
ReleaseRenderTarget(ref reprojectionBuffer[0, 0]);
ReleaseRenderTarget(ref reprojectionBuffer[0, 1]);
ReleaseRenderTarget(ref reprojectionBuffer[1, 0]);
ReleaseRenderTarget(ref reprojectionBuffer[1, 1]);
}
}
}

View file

@ -0,0 +1,14 @@
fileFormatVersion: 2
guid: 65f5677aa325c184f801528d78a73827
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences:
- ditherTex: {fileID: 2800000, guid: 859f329ee8606864ea19dbf373a5ec56, type: 3}
- reprojectionShader: {fileID: 4800000, guid: 7ca93c1a56ee0154b8c714591d6d211a,
type: 3}
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,282 @@
// Copyright (c) <2015> <Playdead>
// This file is subject to the MIT License as seen in the root of this folder structure (LICENSE.TXT)
// AUTHOR: Lasse Jon Fuglsang Pedersen <lasse@playdead.com>
#if UNITY_5_5_OR_NEWER
#define SUPPORT_STEREO
#endif
using UnityEngine;
[ExecuteInEditMode]
[RequireComponent(typeof(Camera), typeof(FrustumJitter))]
[AddComponentMenu("Playdead/VelocityBuffer")]
public class VelocityBuffer : EffectBase
{
#if UNITY_PS4
private const RenderTextureFormat velocityFormat = RenderTextureFormat.RGHalf;
#else
private const RenderTextureFormat velocityFormat = RenderTextureFormat.RGFloat;
#endif
private Camera _camera;
private FrustumJitter _frustumJitter;
public Shader velocityShader;
private Material velocityMaterial;
private RenderTexture[] velocityBuffer;
private RenderTexture[] velocityNeighborMax;
private bool[] paramInitialized;
private Vector4[] paramProjectionExtents;
private Matrix4x4[] paramCurrV;
private Matrix4x4[] paramCurrVP;
private Matrix4x4[] paramPrevVP;
private Matrix4x4[] paramPrevVP_NoFlip;
private int activeEyeIndex = -1;
public RenderTexture activeVelocityBuffer { get { return (activeEyeIndex != -1) ? velocityBuffer[activeEyeIndex] : null; } }
public RenderTexture activeVelocityNeighborMax { get { return (activeEyeIndex != -1) ? velocityNeighborMax[activeEyeIndex] : null; } }
public enum NeighborMaxSupport
{
TileSize10,
TileSize20,
TileSize40,
};
public bool neighborMaxGen = false;
public NeighborMaxSupport neighborMaxSupport = NeighborMaxSupport.TileSize20;
private float timeScaleNextFrame;
public float timeScale { get; private set; }
#if UNITY_EDITOR
[Header("Stats")]
public int numResident = 0;
public int numRendered = 0;
public int numDrawCalls = 0;
#endif
void Reset()
{
_camera = GetComponent<Camera>();
_frustumJitter = GetComponent<FrustumJitter>();
}
void Clear()
{
EnsureArray(ref paramInitialized, 2);
paramInitialized[0] = false;
paramInitialized[1] = false;
}
void Awake()
{
Reset();
Clear();
}
void Start()
{
timeScaleNextFrame = Time.timeScale;
}
void OnPreRender()
{
EnsureDepthTexture(_camera);
}
void OnPostRender()
{
EnsureArray(ref velocityBuffer, 2);
EnsureArray(ref velocityNeighborMax, 2);
EnsureArray(ref paramInitialized, 2, initialValue: false);
EnsureArray(ref paramProjectionExtents, 2);
EnsureArray(ref paramCurrV, 2);
EnsureArray(ref paramCurrVP, 2);
EnsureArray(ref paramPrevVP, 2);
EnsureArray(ref paramPrevVP_NoFlip, 2);
EnsureMaterial(ref velocityMaterial, velocityShader);
if (velocityMaterial == null)
return;
timeScale = timeScaleNextFrame;
timeScaleNextFrame = (Time.timeScale == 0.0f) ? timeScaleNextFrame : Time.timeScale;
#if SUPPORT_STEREO
int eyeIndex = (_camera.stereoActiveEye == Camera.MonoOrStereoscopicEye.Right) ? 1 : 0;
#else
int eyeIndex = 0;
#endif
int bufferW = _camera.pixelWidth;
int bufferH = _camera.pixelHeight;
if (EnsureRenderTarget(ref velocityBuffer[eyeIndex], bufferW, bufferH, velocityFormat, FilterMode.Point, depthBits: 16))
Clear();
EnsureKeyword(velocityMaterial, "CAMERA_PERSPECTIVE", !_camera.orthographic);
EnsureKeyword(velocityMaterial, "CAMERA_ORTHOGRAPHIC", _camera.orthographic);
EnsureKeyword(velocityMaterial, "TILESIZE_10", neighborMaxSupport == NeighborMaxSupport.TileSize10);
EnsureKeyword(velocityMaterial, "TILESIZE_20", neighborMaxSupport == NeighborMaxSupport.TileSize20);
EnsureKeyword(velocityMaterial, "TILESIZE_40", neighborMaxSupport == NeighborMaxSupport.TileSize40);
#if SUPPORT_STEREO
if (_camera.stereoEnabled)
{
for (int i = 0; i != 2; i++)
{
Camera.StereoscopicEye eye = (Camera.StereoscopicEye)i;
Matrix4x4 currV = _camera.GetStereoViewMatrix(eye);
Matrix4x4 currP = GL.GetGPUProjectionMatrix(_camera.GetStereoProjectionMatrix(eye), true);
Matrix4x4 currP_NoFlip = GL.GetGPUProjectionMatrix(_camera.GetStereoProjectionMatrix(eye), false);
Matrix4x4 prevV = paramInitialized[i] ? paramCurrV[i] : currV;
paramInitialized[i] = true;
paramProjectionExtents[i] = _camera.GetProjectionExtents(eye);
paramCurrV[i] = currV;
paramCurrVP[i] = currP * currV;
paramPrevVP[i] = currP * prevV;
paramPrevVP_NoFlip[i] = currP_NoFlip * prevV;
}
}
else
#endif
{
Matrix4x4 currV = _camera.worldToCameraMatrix;
Matrix4x4 currP = GL.GetGPUProjectionMatrix(_camera.projectionMatrix, true);
Matrix4x4 currP_NoFlip = GL.GetGPUProjectionMatrix(_camera.projectionMatrix, false);
Matrix4x4 prevV = paramInitialized[0] ? paramCurrV[0] : currV;
paramInitialized[0] = true;
paramProjectionExtents[0] = _frustumJitter.enabled ? _camera.GetProjectionExtents(_frustumJitter.activeSample.x, _frustumJitter.activeSample.y) : _camera.GetProjectionExtents();
paramCurrV[0] = currV;
paramCurrVP[0] = currP * currV;
paramPrevVP[0] = currP * prevV;
paramPrevVP_NoFlip[0] = currP_NoFlip * prevV;
}
RenderTexture activeRT = RenderTexture.active;
RenderTexture.active = velocityBuffer[eyeIndex];
{
GL.Clear(true, true, Color.black);
const int kPrepass = 0;
const int kVertices = 1;
const int kVerticesSkinned = 2;
const int kTileMax = 3;
const int kNeighborMax = 4;
// 0: prepass
#if SUPPORT_STEREO
velocityMaterial.SetVectorArray("_ProjectionExtents", paramProjectionExtents);
velocityMaterial.SetMatrixArray("_CurrV", paramCurrV);
velocityMaterial.SetMatrixArray("_CurrVP", paramCurrVP);
velocityMaterial.SetMatrixArray("_PrevVP", paramPrevVP);
velocityMaterial.SetMatrixArray("_PrevVP_NoFlip", paramPrevVP_NoFlip);
#else
velocityMaterial.SetVector("_ProjectionExtents", paramProjectionExtents[0]);
velocityMaterial.SetMatrix("_CurrV", paramCurrV[0]);
velocityMaterial.SetMatrix("_CurrVP", paramCurrVP[0]);
velocityMaterial.SetMatrix("_PrevVP", paramPrevVP[0]);
velocityMaterial.SetMatrix("_PrevVP_NoFlip", paramPrevVP_NoFlip[0]);
#endif
velocityMaterial.SetPass(kPrepass);
DrawFullscreenQuad();
// 1 + 2: vertices + vertices skinned
var obs = VelocityBufferTag.activeObjects;
#if UNITY_EDITOR
numResident = obs.Count;
numRendered = 0;
numDrawCalls = 0;
#endif
for (int i = 0, n = obs.Count; i != n; i++)
{
var ob = obs[i];
if (ob != null && ob.rendering && ob.mesh != null)
{
velocityMaterial.SetMatrix("_CurrM", ob.localToWorldCurr);
velocityMaterial.SetMatrix("_PrevM", ob.localToWorldPrev);
velocityMaterial.SetPass(ob.meshSmrActive ? kVerticesSkinned : kVertices);
for (int j = 0; j != ob.mesh.subMeshCount; j++)
{
Graphics.DrawMeshNow(ob.mesh, Matrix4x4.identity, j);
#if UNITY_EDITOR
numDrawCalls++;
#endif
}
#if UNITY_EDITOR
numRendered++;
#endif
}
}
// 3 + 4: tilemax + neighbormax
if (neighborMaxGen)
{
int tileSize = 1;
switch (neighborMaxSupport)
{
case NeighborMaxSupport.TileSize10: tileSize = 10; break;
case NeighborMaxSupport.TileSize20: tileSize = 20; break;
case NeighborMaxSupport.TileSize40: tileSize = 40; break;
}
int neighborMaxW = bufferW / tileSize;
int neighborMaxH = bufferH / tileSize;
EnsureRenderTarget(ref velocityNeighborMax[eyeIndex], neighborMaxW, neighborMaxH, velocityFormat, FilterMode.Bilinear);
// tilemax
RenderTexture tileMax = RenderTexture.GetTemporary(neighborMaxW, neighborMaxH, 0, velocityFormat);
RenderTexture.active = tileMax;
{
velocityMaterial.SetTexture("_VelocityTex", velocityBuffer[eyeIndex]);
velocityMaterial.SetVector("_VelocityTex_TexelSize", new Vector4(1.0f / bufferW, 1.0f / bufferH, 0.0f, 0.0f));
velocityMaterial.SetPass(kTileMax);
DrawFullscreenQuad();
}
// neighbormax
RenderTexture.active = velocityNeighborMax[eyeIndex];
{
velocityMaterial.SetTexture("_VelocityTex", tileMax);
velocityMaterial.SetVector("_VelocityTex_TexelSize", new Vector4(1.0f / neighborMaxW, 1.0f / neighborMaxH, 0.0f, 0.0f));
velocityMaterial.SetPass(kNeighborMax);
DrawFullscreenQuad();
}
RenderTexture.ReleaseTemporary(tileMax);
}
else
{
ReleaseRenderTarget(ref velocityNeighborMax[0]);
ReleaseRenderTarget(ref velocityNeighborMax[1]);
}
}
RenderTexture.active = activeRT;
activeEyeIndex = eyeIndex;
}
void OnApplicationQuit()
{
if (velocityBuffer != null)
{
ReleaseRenderTarget(ref velocityBuffer[0]);
ReleaseRenderTarget(ref velocityBuffer[1]);
}
if (velocityNeighborMax != null)
{
ReleaseRenderTarget(ref velocityNeighborMax[0]);
ReleaseRenderTarget(ref velocityNeighborMax[1]);
}
}
}

View file

@ -0,0 +1,15 @@
fileFormatVersion: 2
guid: b642ff60407fe724bafa6602199213c0
timeCreated: 1438011374
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences:
- velocityShader: {fileID: 4800000, guid: 0d7f09e63dd99504ca6e04212a21ec72, type: 3}
- velocityBuffer: {instanceID: 0}
- velocityNeighborMax: {instanceID: 0}
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,143 @@
// Copyright (c) <2015> <Playdead>
// This file is subject to the MIT License as seen in the root of this folder structure (LICENSE.TXT)
// AUTHOR: Lasse Jon Fuglsang Pedersen <lasse@playdead.com>
using System;
using System.Collections.Generic;
using UnityEngine;
[AddComponentMenu("Playdead/VelocityBufferTag")]
public class VelocityBufferTag : MonoBehaviour
{
#if UNITY_5_6_OR_NEWER
private static List<Vector3> temporaryVertexStorage = new List<Vector3>(512);
#endif
public static List<VelocityBufferTag> activeObjects = new List<VelocityBufferTag>(128);
private Transform _transform;
[NonSerialized, HideInInspector] public SkinnedMeshRenderer meshSmr;
[NonSerialized, HideInInspector] public bool meshSmrActive;
[NonSerialized, HideInInspector] public Mesh mesh;
[NonSerialized, HideInInspector] public Matrix4x4 localToWorldPrev;
[NonSerialized, HideInInspector] public Matrix4x4 localToWorldCurr;
private const int framesNotRenderedSleepThreshold = 60;
private int framesNotRendered = framesNotRenderedSleepThreshold;
public bool rendering { get { return (framesNotRendered < framesNotRenderedSleepThreshold); } }
void Reset()
{
_transform = this.transform;
var smr = GetComponent<SkinnedMeshRenderer>();
if (smr != null)
{
if (mesh == null || meshSmrActive == false)
{
mesh = new Mesh();
mesh.hideFlags = HideFlags.HideAndDontSave;
}
meshSmrActive = true;
meshSmr = smr;
}
else
{
var mf = GetComponent<MeshFilter>();
if (mf != null)
mesh = mf.sharedMesh;
else
mesh = null;
meshSmrActive = false;
meshSmr = null;
}
// force restart
framesNotRendered = framesNotRenderedSleepThreshold;
}
void Awake()
{
Reset();
}
void TagUpdate(bool restart)
{
if (meshSmrActive && meshSmr == null)
{
Reset();
}
if (meshSmrActive)
{
if (restart)
{
meshSmr.BakeMesh(mesh);
#if UNITY_5_6_OR_NEWER
mesh.GetVertices(temporaryVertexStorage);
mesh.SetNormals(temporaryVertexStorage);
#else
mesh.normals = mesh.vertices;// garbage ahoy
#endif
}
else
{
#if UNITY_5_6_OR_NEWER
mesh.GetVertices(temporaryVertexStorage);
meshSmr.BakeMesh(mesh);
mesh.SetNormals(temporaryVertexStorage);
#else
Vector3[] vs = mesh.vertices;// garbage ahoy
meshSmr.BakeMesh(mesh);
mesh.normals = vs;
#endif
}
}
if (restart)
{
localToWorldCurr = _transform.localToWorldMatrix;
localToWorldPrev = localToWorldCurr;
}
else
{
localToWorldPrev = localToWorldCurr;
localToWorldCurr = _transform.localToWorldMatrix;
}
}
void LateUpdate()
{
if (framesNotRendered < framesNotRenderedSleepThreshold)
{
framesNotRendered++;
TagUpdate(restart: false);
}
}
void OnWillRenderObject()
{
if (Camera.current != Camera.main)
return;// ignore anything but main cam
if (framesNotRendered >= framesNotRenderedSleepThreshold)
TagUpdate(restart: true);
framesNotRendered = 0;
}
void OnEnable()
{
activeObjects.Add(this);
}
void OnDisable()
{
activeObjects.Remove(this);
// force restart
framesNotRendered = framesNotRenderedSleepThreshold;
}
}

View file

@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 1cc21c48ee370cb42a042622dd21640d
timeCreated: 1437991033
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: