Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 30 additions & 9 deletions Moments Recorder/Scripts/Recorder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ public float EstimatedMemoryUse
int m_MaxFrameCount;
float m_Time;
float m_TimePerFrame;
float m_AbsoluteTime;
Queue<RenderTexture> m_Frames;
RenderTexture m_RecycledRenderTexture;
ReflectionUtils<Recorder> m_ReflectionUtils;
Expand Down Expand Up @@ -206,6 +207,8 @@ public void Record()
}

State = RecorderState.Recording;
m_Time = 0f;
m_AbsoluteTime = 0f;
}

/// <summary>
Expand Down Expand Up @@ -288,44 +291,62 @@ void OnDestroy()
{
FlushMemory();
}



public System.Action<float> OnUpdateTime;

float m_LastTime;
void OnRenderImage(RenderTexture source, RenderTexture destination)
{
if (State != RecorderState.Recording)
{
Graphics.Blit(source, destination);
return;
}

m_Time += Time.unscaledDeltaTime;

if (m_LastTime == 0) {
m_LastTime = Time.time;
}

float deltaTime = Time.time - m_LastTime;

m_LastTime = Time.time;

m_Time += deltaTime;


if (m_Time >= m_TimePerFrame)
{
m_AbsoluteTime += m_TimePerFrame;
// Limit the amount of frames stored in memory
if (m_Frames.Count >= m_MaxFrameCount)
m_RecycledRenderTexture = m_Frames.Dequeue();


if (OnUpdateTime != null) {
OnUpdateTime(m_AbsoluteTime);
}

m_Time -= m_TimePerFrame;

// Frame data
RenderTexture rt = m_RecycledRenderTexture;
m_RecycledRenderTexture = null;

if (rt == null)
{
rt = new RenderTexture(m_Width, m_Height, 0, RenderTextureFormat.ARGB32);
rt.wrapMode = TextureWrapMode.Clamp;
rt.filterMode = FilterMode.Bilinear;
rt.anisoLevel = 0;
}

Graphics.Blit(source, rt);
m_Frames.Enqueue(rt);
}

Graphics.Blit(source, destination);
}

#endregion

#region Methods
Expand Down