Skip to content

Commit f4358b3

Browse files
committed
fixed flipped image bug and added jpg/exr support to base recorder
1 parent 61ee3dc commit f4358b3

File tree

6 files changed

+43
-13
lines changed

6 files changed

+43
-13
lines changed

source/Core/FrameRecorder/Core/Engine/FrameRecorderAttribute.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@ namespace UnityEngine.FrameRecorder
44
{
55

66
/// <summary>
7-
/// What is this:
8-
/// Motivation :
9-
/// Notes:
7+
/// What is this: Class attribute that decorates classes that are Recorders and provides the information needed to register it with the RecorderInventory class.
8+
/// Motivation : Provide a way to dynamically discover Recorder classes and provide a classification system and link between the recorder classes and their Settings classes.
109
/// </summary>
1110
[AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = false)]
1211
public class FrameRecorderAttribute : Attribute

source/Core/FrameRecorder/Inputs/CBRenderTexture/Engine/CBRenderTextureInput.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ public override void NewFrameStarting(RecordingSession session)
140140

141141
// TODO: This should not be here!!!
142142
m_mat_copy = new Material(CopyShader);
143-
if (m_Camera.targetTexture != null)
143+
if (m_Camera.targetTexture != null || cbSettings.m_FlipVertical )
144144
m_mat_copy.EnableKeyword("OFFSCREEN");
145145

146146
var tid = Shader.PropertyToID("_TmpFrameBuffer");
Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1-

2-
3-
namespace UnityEngine.FrameRecorder.Input
1+
namespace UnityEngine.FrameRecorder.Input
42
{
53
public class CBRenderTextureInputSettings : InputSettings<CBRenderTextureInput>
64
{
75
public EImageSource source = EImageSource.GameDisplay;
86
public EImageDimension m_RenderSize = EImageDimension.x720p_HD;
97
public string m_CameraTag;
108
public RenderTexture m_SourceRTxtr;
9+
public bool m_FlipVertical = false;
1110
}
1211
}

source/Core/FrameRecorder/Recorders/PNG/Editor/PNGRecorderEditor.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ public class PNGRecorderEditor : RecorderEditor
1010
{
1111
SerializedProperty m_DestinationPath;
1212
SerializedProperty m_BaseFileName;
13+
SerializedProperty m_OutputFormat;
1314

1415
string[] m_Candidates;
1516

@@ -31,6 +32,7 @@ protected void OnEnable()
3132
m_Inputs = pf.Find(w => w.m_SourceSettings);
3233
m_DestinationPath = pf.Find(w => w.m_DestinationPath);
3334
m_BaseFileName = pf.Find(w => w.m_BaseFileName);
35+
m_OutputFormat = pf.Find(w => w.m_OutputFormat);
3436
}
3537

3638
protected override void OnEncodingGroupGui()
@@ -48,7 +50,11 @@ protected override void OnInputGui()
4850
if (index != newIndex)
4951
{
5052
var newType = newIndex == 0 ? typeof(CBRenderTextureInputSettings) : typeof(AdamBeautyInputSettings);
51-
var newSettings = (RecorderInputSetting)Activator.CreateInstance(newType);
53+
var newSettings = ScriptableObject.CreateInstance(newType) as RecorderInputSetting;
54+
if (newType == typeof(CBRenderTextureInputSettings))
55+
{
56+
(newSettings as CBRenderTextureInputSettings).m_FlipVertical = true;
57+
}
5258
ChangeInputSettings(0, newSettings);
5359
}
5460

@@ -57,6 +63,8 @@ protected override void OnInputGui()
5763

5864
protected override void OnOutputGui()
5965
{
66+
EditorGUILayout.PropertyField(m_OutputFormat, new GUIContent("Output format"));
67+
6068
GUILayout.BeginHorizontal();
6169
EditorGUILayout.LabelField("Directory");
6270
m_DestinationPath.stringValue = EditorGUILayout.TextField(m_DestinationPath.stringValue);

source/Core/FrameRecorder/Recorders/PNG/Engine/PNGRecorder.cs

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@
55

66
namespace UnityEngine.FrameRecorder
77
{
8-
[FrameRecorder(typeof(PNGRecorderSettings),"Video", "PNG" )]
8+
[FrameRecorder(typeof(PNGRecorderSettings),"Video", "PNG, Jpeg, OpenEXR" )]
99
public class PNGRecorder : GenericRecorder<PNGRecorderSettings>
1010
{
1111
string MakeFileName(RecordingSession session)
1212
{
1313
var fileName = m_Settings.m_DestinationPath;
1414
if (fileName.Length > 0 && !fileName.EndsWith("/"))
1515
fileName += "/";
16-
fileName += m_Settings.m_BaseFileName + recordedFramesCount + ".png";
16+
fileName += m_Settings.m_BaseFileName + recordedFramesCount + "." + m_Settings.m_OutputFormat;
1717
return fileName;
1818
}
1919

@@ -26,14 +26,29 @@ public override void RecordFrame(RecordingSession session)
2626

2727
var width = input.outputRT.width;
2828
var height = input.outputRT.height;
29-
var tex = new Texture2D(width, height, TextureFormat.RGB24, false);
29+
var tex = new Texture2D(width, height, m_Settings.m_OutputFormat != PNGRecordeOutputFormat.EXR ? TextureFormat.RGBA32 : TextureFormat.RGBAFloat, false);
3030
var backupActive = RenderTexture.active;
3131
RenderTexture.active = input.outputRT;
3232
tex.ReadPixels(new Rect(0, 0, width, height), 0, 0);
3333
tex.Apply();
3434
RenderTexture.active = backupActive;
3535

36-
var bytes = tex.EncodeToPNG();
36+
byte[] bytes;
37+
switch (m_Settings.m_OutputFormat)
38+
{
39+
case PNGRecordeOutputFormat.PNG:
40+
bytes = tex.EncodeToPNG();
41+
break;
42+
case PNGRecordeOutputFormat.JPEG:
43+
bytes = tex.EncodeToJPG();
44+
break;
45+
case PNGRecordeOutputFormat.EXR:
46+
bytes = tex.EncodeToEXR();
47+
break;
48+
default:
49+
throw new ArgumentOutOfRangeException();
50+
}
51+
3752
UnityHelpers.Destroy(tex);
3853

3954
if (!Directory.Exists(m_Settings.m_DestinationPath))

source/Core/FrameRecorder/Recorders/PNG/Engine/PNGRecorderSettings.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,20 @@
33

44
namespace UnityEngine.FrameRecorder
55
{
6+
7+
public enum PNGRecordeOutputFormat
8+
{
9+
PNG,
10+
JPEG,
11+
EXR
12+
}
13+
614
[ExecuteInEditMode]
715
public class PNGRecorderSettings : RecorderSettings
816
{
9-
public string m_BaseFileName = "pngFile";
17+
public string m_BaseFileName = "image";
1018
public string m_DestinationPath = "Recorder";
19+
public PNGRecordeOutputFormat m_OutputFormat = PNGRecordeOutputFormat.JPEG;
1120

1221
public override List<RecorderInputSetting> GetDefaultSourcesSettings()
1322
{

0 commit comments

Comments
 (0)