浏览代码

Wrapper Functions and accessors in Processor Base + Code Accessibility

/main
Thomas ICHÉ 4 年前
当前提交
be0e9a52
共有 21 个文件被更改,包括 395 次插入207 次删除
  1. 2
      Editor/Canvas/VFXToolboxCanvas.cs
  2. 16
      ImageSequencer/Editor/Attributes/ProcessorAttribute.cs
  3. 12
      ImageSequencer/Editor/ImageSequencerCanvas.cs
  4. 4
      ImageSequencer/Editor/ProcessingNode.cs
  5. 188
      ImageSequencer/Editor/Serialization/ProcessorBase.cs
  6. 12
      ImageSequencer/Editor/Serialization/Processors/AlphaFromRGBProcessor.cs
  7. 50
      ImageSequencer/Editor/Serialization/Processors/AssembleProcessor.cs
  8. 22
      ImageSequencer/Editor/Serialization/Processors/BreakFlipbookProcessor.cs
  9. 18
      ImageSequencer/Editor/Serialization/Processors/ColorCorrectionProcessor.cs
  10. 40
      ImageSequencer/Editor/Serialization/Processors/CropProcessor.cs
  11. 40
      ImageSequencer/Editor/Serialization/Processors/CustomMaterialProcessor.cs
  12. 10
      ImageSequencer/Editor/Serialization/Processors/DecimateProcessor.cs
  13. 18
      ImageSequencer/Editor/Serialization/Processors/FadeProcessor.cs
  14. 16
      ImageSequencer/Editor/Serialization/Processors/FixBordersProcessor.cs
  15. 42
      ImageSequencer/Editor/Serialization/Processors/LoopingProcessor.cs
  16. 12
      ImageSequencer/Editor/Serialization/Processors/PremultiplyAlphaProcessor.cs
  17. 14
      ImageSequencer/Editor/Serialization/Processors/RemapColorProcessor.cs
  18. 22
      ImageSequencer/Editor/Serialization/Processors/RemoveBackgroundProcessor.cs
  19. 18
      ImageSequencer/Editor/Serialization/Processors/ResizeProcessor.cs
  20. 26
      ImageSequencer/Editor/Serialization/Processors/RetimeProcessor.cs
  21. 20
      ImageSequencer/Editor/Serialization/Processors/RotateProcessor.cs

2
Editor/Canvas/VFXToolboxCanvas.cs


namespace UnityEditor.VFXToolbox
{
internal abstract class VFXToolboxCanvas
public abstract class VFXToolboxCanvas
{
public Rect displayRect
{

16
ImageSequencer/Editor/Attributes/ProcessorAttribute.cs


namespace UnityEditor.VFXToolbox.ImageSequencer
{
/// <summary>
/// Attribute for Class derived from ProcessorBase.
/// Determines the ImageSequencer menu name and category for the processor when adding new processors to the asset.
/// </summary>
/// <summary>
/// Menu Category where the Processor will be stored into
/// </summary>
/// <summary>
/// Processor name used to display in the menu
/// </summary>
/// <summary>
/// Defines a Processor Entry in the ImageSequencer add Processor Menu.
/// </summary>
/// <param name="category">Menu Category where the Processor will be stored into</param>
/// <param name="name">Processor name used to display in the menu</param>
public ProcessorAttribute(string category, string name)
{
this.category = category;

12
ImageSequencer/Editor/ImageSequencerCanvas.cs


namespace UnityEditor.VFXToolbox.ImageSequencer
{
internal class ImageSequencerCanvas : VFXToolboxCanvas
public class ImageSequencerCanvas : VFXToolboxCanvas
{
public bool showExtraInfo
{

}
}
public ProcessingFrameSequence sequence
internal ProcessingFrameSequence sequence
{
get
{

}
}
public ProcessingFrame currentFrame
internal ProcessingFrame currentFrame
{
get {
return m_ProcessingFrame;

private bool m_IsScrobbing;
public ImageSequencerCanvas(Rect displayRect, ImageSequencer editorWindow)
internal ImageSequencerCanvas(Rect displayRect, ImageSequencer editorWindow)
:base(displayRect)
{
m_ImageSequencerWindow = editorWindow;

Handles.color = Color.white;
}
public void OnGUI(ImageSequencer editor)
internal void OnGUI(ImageSequencer editor)
{
OnGUI();

}
public void DrawSequenceControls(Rect ViewportArea, ImageSequencer editor)
internal void DrawSequenceControls(Rect ViewportArea, ImageSequencer editor)
{
m_PlayControlsRect = new Rect(ViewportArea.x , (ViewportArea.y + ViewportArea.height), ViewportArea.width , 100);

4
ImageSequencer/Editor/ProcessingNode.cs


public Material material { get; private set; }
public bool isCurrentlyPreviewed => m_ProcessingNodeStack.imageSequencer.previewCanvas.sequence.processingNode == this;
public int currentPreviewFrame => m_ProcessingNodeStack.imageSequencer.previewCanvas.currentFrameIndex;
public int currentPreviewSequenceLength => m_ProcessingNodeStack.imageSequencer.previewCanvas.numFrames;
public int previewCurrentFrame => m_ProcessingNodeStack.imageSequencer.previewCanvas.currentFrameIndex;
public int previewSequenceLength => m_ProcessingNodeStack.imageSequencer.previewCanvas.numFrames;
public ProcessingNode(ProcessingNodeStack processorStack, ProcessorInfo info)
{

188
ImageSequencer/Editor/Serialization/ProcessorBase.cs


namespace UnityEditor.VFXToolbox.ImageSequencer
{
internal abstract class ProcessorBase : ScriptableObject
/// <summary>
/// Base Class for Custom Processors. Derive from this class to add a new Processor.
/// In order to populate processors in the menu, you need to implement the [ProcessorAttribute] to the class.
/// </summary>
public abstract class ProcessorBase : ScriptableObject
/// <summary>
/// Asset Path of the Shader used for this processor (eg: "Assets/Shaders/MyShader.shader")
/// </summary>
/// <summary>
/// Name of the Processor
/// </summary>
/// <summary>
/// Display Label text of the processor (will be displayed in the processor list and asset inspector)
/// </summary>
protected ProcessingNode processor;
/// <summary>
/// Number of U (Columns) defined by this processor. Implement to override default (passthrough input sequence's numU)
/// </summary>
public virtual int numU => inputSequenceNumU;
/// <summary>
/// Number of V (Rows) defined by this processor. Implement to override default (passthrough input sequence's numV)
/// </summary>
public virtual int numV => inputSequenceNumV;
public void AttachTo(ProcessingNode processor)
{
this.processor = processor;
}
/// <summary>
/// Number of frames defined by this processor. Implement to override default (passthrough input's sequence length)
/// </summary>
public virtual int sequenceLength => processingNode.InputSequence.length;
public virtual int numU => processor.InputSequence.numU;
public virtual int numV => processor.InputSequence.numV;
public virtual int sequenceLength => processor.InputSequence.length;
/// <summary>
/// Determines the actual processing of the frame. Will be called when this frame is requested by the Image Sequencer.
/// </summary>
/// <param name="frame">the requested frame index</param>
/// <returns></returns>
/// <summary>
/// Updates the output size of the processing node (resets internal render targets), implement to override the default (passthrough the input sequence frame width and height)
/// </summary>
processor.SetOutputSize(processor.InputSequence.width, processor.InputSequence.height);
processingNode.SetOutputSize(processingNode.InputSequence.width, processingNode.InputSequence.height);
/// <summary>
/// Displays the Processor inspector in the left pane of the Image Sequencer
/// </summary>
/// <param name="changed">Whether the inspector has already caught changes.</param>
/// <param name="serializedObject">The processor's serializedObject</param>
/// <returns>whether there has changes to apply</returns>
/// <summary>
/// Displays the Processor's Canvas Helpers as overlay.
/// </summary>
/// <param name="canvas">The Image Sequencer Canvas currently drawn</param>
/// <returns>whether the canvas needs to redraw</returns>
/// <summary>
/// Sets the default values of the processor. Will be called to configure the default state when a new processor is added to the Image Sequence.
/// </summary>
#region PROCESSINGNODE ACCESS
/// <summary>
/// The Input Sequence Frame Count
/// </summary>
public int inputSequenceLength => processingNode.InputSequence.length;
/// <summary>
/// The Input Sequence Frame Width (in pixels)
/// </summary>
public int inputSequenceWidth => processingNode.InputSequence.width;
/// <summary>
/// The Input Sequence Frame Height (in pixels)
/// </summary>
public int inputSequenceHeight => processingNode.InputSequence.height;
/// <summary>
/// The Input Sequence Flipbook U Count (Columns)
/// </summary>
public int inputSequenceNumU => processingNode.InputSequence.numU;
/// <summary>
/// The Input Sequence Flipbook V Count (Rows)
/// </summary>
public int inputSequenceNumV => processingNode.InputSequence.numV;
/// <summary>
/// Whether the Input frame Sequence is the Asset's Input Frame List (use to determine whether it needs gamma correction or not)
/// </summary>
public bool isInputFrameSequence => processingNode.InputSequence.processingNode == null;
/// <summary>
/// Whether the current processor is being previewed in the Image Sequencer Viewport, or not (for example, when the view is locked to another processor's result)
/// </summary>
public bool isCurrentlyPreviewed => processingNode.isCurrentlyPreviewed;
/// <summary>
/// The current Image Sequencer Viewport's preview sequence length. Please not that this is not necessarily this Processor's preview, use isCurrentlyPreviewed to check.
/// </summary>
public int previewSequenceLength => processingNode.previewSequenceLength;
/// <summary>
/// The current Image Sequencer Viewport's preview image index. Please not that this is not necessarily this Processor's preview, use isCurrentlyPreviewed to check.
/// </summary>
public int previewCurrentFrame => processingNode.previewCurrentFrame;
/// <summary>
/// The material internally used for this processor. It is created from the shader defined using this.shaderPath.
/// </summary>
public Material material => processingNode.material;
/// <summary>
/// Requests the Texture (and its Processing) of the Input Sequence Image at given index.
/// </summary>
/// <param name="index">The index of the Frame to be returned.</param>
/// <returns>The texture object corresponding to the frame.</returns>
public Texture RequestInputTexture(int index)
{
return processingNode.InputSequence.RequestFrame(index).texture;
}
/// <summary>
/// Requests the Texture of the Output Sequence Image at given index.
/// </summary>
/// <param name="index">The index of the Frame to be returned.</param>
/// <returns>The texture object corresponding to the frame.</returns>
public Texture RequestOutputTexture(int index)
{
return processingNode.OutputSequence.frames[index].texture;
}
/// <summary>
/// Sets the Output Size to the Processing Node
/// </summary>
/// <param name="width"></param>
/// <param name="height"></param>
public void SetOutputSize(int width, int height)
{
processingNode.SetOutputSize(width, height);
}
/// <summary>
/// Process the Frame at Given Index, using given material and texture as MainTexture.
/// </summary>
/// <param name="outputIndex">Frame Index to process</param>
/// <param name="mainTexture">Texture object to pass as MainTexture</param>
/// <param name="material">Material to use for the procesing</param>
public void ProcessFrame(int outputIndex, Texture mainTexture, Material material)
{
processingNode.ExecuteShaderAndDump(outputIndex, mainTexture, material);
}
/// <summary>
/// Process the Frame at Given Index, using default processor material and texture as MainTexture.
/// </summary>
/// <param name="outputIndex">Frame Index to process</param>
/// <param name="mainTexture">Texture object to pass as MainTexture</param>
public void ProcessFrame(int outputIndex, Texture mainTexture = null)
{
processingNode.ExecuteShaderAndDump(outputIndex, mainTexture);
}
/// <summary>
/// Invalidates the Processor (will require to rebake frames)
/// </summary>
public void Invalidate()
{
processingNode.Invalidate();
}
#endregion
#region INTERNAL
private ProcessingNode processingNode;
internal void AttachTo(ProcessingNode processor)
{
this.processingNode = processor;
}
#endregion
}
}

12
ImageSequencer/Editor/Serialization/Processors/AlphaFromRGBProcessor.cs


namespace UnityEditor.VFXToolbox.ImageSequencer
{
[Processor("Color","Alpha From RGB")]
class AlphaFromRGBProcessor : ProcessorBase
internal class AlphaFromRGBProcessor : ProcessorBase
{
public Color BWFilterTint;

public override bool Process(int frame)
{
Texture inputFrame = processor.InputSequence.RequestFrame(frame).texture;
processor.material.SetTexture("_MainTex", inputFrame);
processor.material.SetVector("_RGBTint", BWFilterTint);
Texture inputFrame = RequestInputTexture(frame);
material.SetTexture("_MainTex", inputFrame);
material.SetVector("_RGBTint", BWFilterTint);
processor.ExecuteShaderAndDump(frame, inputFrame);
ProcessFrame(frame, inputFrame);
return true;
}

if (EditorGUI.EndChangeCheck())
{
processor.Invalidate();
Invalidate();
changed = true;
}

50
ImageSequencer/Editor/Serialization/Processors/AssembleProcessor.cs


{
default:
case AssembleMode.FullSpriteSheet:
return FlipbookNumU * processor.InputSequence.numU;
return FlipbookNumU * inputSequenceNumU;
return processor.InputSequence.numU;
return inputSequenceNumU;
public override int numV => FlipbookNumV * processor.InputSequence.numV;
public override int numV => FlipbookNumV * inputSequenceNumV;
public override int sequenceLength
{

return 1;
case AssembleMode.VerticalSequence:
return processor.InputSequence.length / FlipbookNumV;
return inputSequenceLength / FlipbookNumV;
}
}
}

{
case AssembleMode.FullSpriteSheet:
processor.SetOutputSize(processor.InputSequence.width * FlipbookNumU, processor.InputSequence.height * FlipbookNumV);
SetOutputSize(inputSequenceWidth * FlipbookNumU, inputSequenceHeight * FlipbookNumV);
processor.SetOutputSize(processor.InputSequence.width, processor.InputSequence.height * FlipbookNumV);
SetOutputSize(inputSequenceWidth, inputSequenceHeight * FlipbookNumV);
break;
}
}

public override bool Process(int frame)
{
int length = processor.InputSequence.length;
int length = inputSequenceLength;
RenderTexture backup = RenderTexture.active;

Vector2 size = new Vector2(1.0f / FlipbookNumU, 1.0f / FlipbookNumV);
int idx = Mathf.Clamp(i, 0, length - 1);
Texture currentTexture = processor.InputSequence.RequestFrame(idx).texture;
Texture currentTexture = RequestInputTexture(idx);
processor.material.SetTexture("_MainTex", currentTexture);
processor.material.SetVector("_CC", ClipCoordinates);
material.SetTexture("_MainTex", currentTexture);
material.SetVector("_CC", ClipCoordinates);
Graphics.Blit(currentTexture, (RenderTexture)processor.OutputSequence.frames[0].texture, processor.material);
Graphics.Blit(currentTexture, (RenderTexture)RequestOutputTexture(0), material);
}
RenderTexture.active = backup;

case AssembleMode.VerticalSequence:
// Blit Every N'th Image inside output
int cycleLength = processor.InputSequence.length / FlipbookNumV;
int cycleLength = inputSequenceLength / FlipbookNumV;
for (int i = 0; i < FlipbookNumV; i++)
{

Vector2 size = new Vector2(1.0f, 1.0f / FlipbookNumV);
int idx = Mathf.Clamp((i * cycleLength) + frame, 0, length - 1);
Texture currentTexture = processor.InputSequence.RequestFrame(idx).texture;
Texture currentTexture = RequestInputTexture(idx);
processor.material.SetTexture("_MainTex", currentTexture);
processor.material.SetVector("_CC", ClipCoordinates);
material.SetTexture("_MainTex", currentTexture);
material.SetVector("_CC", ClipCoordinates);
Graphics.Blit(currentTexture, (RenderTexture)processor.OutputSequence.frames[frame].texture, processor.material);
Graphics.Blit(currentTexture, (RenderTexture)RequestOutputTexture(frame), material);
}
RenderTexture.active = backup;

int newU = EditorGUILayout.IntField(VFXToolboxGUIUtility.Get("Columns (U) : "), flipbookNumU.intValue);
int newV = EditorGUILayout.IntField(VFXToolboxGUIUtility.Get("Rows (V) : "), flipbookNumV.intValue);
if (processor.InputSequence.length > 0)
if (inputSequenceLength > 0)
{
using (new GUILayout.HorizontalScope())
{

float frameRatio = (float)processor.InputSequence.frames[0].texture.width / (float)processor.InputSequence.frames[0].texture.height;
int length = processor.InputSequence.frames.Count;
float frameRatio = (float)inputSequenceWidth / (float)inputSequenceHeight;
int length = inputSequenceLength;
List<int> ratios = new List<int>();
SortedDictionary<int, float> coeffs = new SortedDictionary<int, float>();
float rad = Mathf.Sqrt(length);

menu.AddItem(new GUIContent(value + " x " + (length / value) + ((kvp.Value == 0.0f) ? " (PERFECT)" : "")), false,
(o) => {
var seq_length = processor.InputSequence.length;
var seq_length = inputSequenceLength;
var seq_numU = (int)o;
var seq_numV = seq_length / seq_numU;
serializedObject.Update();

serializedObject.ApplyModifiedProperties();
UpdateOutputSize();
processor.Invalidate();
Invalidate();
}
, value);
}

if (newU != flipbookNumU.intValue)
{
newU = Mathf.Clamp(newU, 1, processor.InputSequence.length / newV);
newU = Mathf.Clamp(newU, 1, inputSequenceLength / newV);
newV = Mathf.Clamp(newV, 1, processor.InputSequence.length / newU);
newV = Mathf.Clamp(newV, 1, inputSequenceLength / newU);
flipbookNumV.intValue = newV;
}
break;

if (numRows != flipbookNumV.intValue)
{
numRows = Mathf.Clamp(numRows, 1, processor.InputSequence.length);
numRows = Mathf.Clamp(numRows, 1, inputSequenceLength);
flipbookNumV.intValue = numRows;
}

if (EditorGUI.EndChangeCheck())
{
UpdateOutputSize();
processor.Invalidate();
Invalidate();
hasChanged = true;
}

22
ImageSequencer/Editor/Serialization/Processors/BreakFlipbookProcessor.cs


public override void UpdateOutputSize()
{
int width = (int)Mathf.Ceil((float)processor.InputSequence.RequestFrame(0).texture.width / FlipbookNumU);
int height = (int)Mathf.Ceil((float)processor.InputSequence.RequestFrame(0).texture.height / FlipbookNumV);
processor.SetOutputSize(width, height);
int width = (int)Mathf.Ceil((float)inputSequenceWidth / FlipbookNumU);
int height = (int)Mathf.Ceil((float)inputSequenceHeight / FlipbookNumV);
SetOutputSize(width, height);
public override int sequenceLength => Mathf.Min(FlipbookNumU, processor.InputSequence.width) * Mathf.Min(FlipbookNumV, processor.InputSequence.height);
public override int sequenceLength => Mathf.Min(FlipbookNumU, inputSequenceWidth) * Mathf.Min(FlipbookNumV, inputSequenceHeight);
Texture texture = processor.InputSequence.RequestFrame(0).texture;
processor.material.SetTexture("_MainTex", texture);
Texture texture = RequestInputTexture(0);
material.SetTexture("_MainTex", texture);
Vector4 rect = new Vector4();
int u = Mathf.Min(FlipbookNumU, texture.width);

rect.z = 1.0f / u;
rect.w = 1.0f / v;
processor.material.SetVector("_Rect", rect);
processor.ExecuteShaderAndDump(frame, texture);
material.SetVector("_Rect", rect);
ProcessFrame(frame, texture);
return true;
}

EditorGUI.BeginChangeCheck();
int newU = Mathf.Clamp(EditorGUILayout.IntField(VFXToolboxGUIUtility.Get("Columns (U) : "), flipbookNumU.intValue), 1, processor.InputSequence.width);
int newV = Mathf.Clamp(EditorGUILayout.IntField(VFXToolboxGUIUtility.Get("Rows (V) : "), flipbookNumV.intValue), 1, processor.InputSequence.height);
int newU = Mathf.Clamp(EditorGUILayout.IntField(VFXToolboxGUIUtility.Get("Columns (U) : "), flipbookNumU.intValue), 1, inputSequenceWidth);
int newV = Mathf.Clamp(EditorGUILayout.IntField(VFXToolboxGUIUtility.Get("Rows (V) : "), flipbookNumV.intValue), 1, inputSequenceHeight);
if (newU != flipbookNumU.intValue || flipbookNumV.intValue != newV)
GUI.changed = true;

}
}
processor.Invalidate();
Invalidate();
hasChanged = true;
}

18
ImageSequencer/Editor/Serialization/Processors/ColorCorrectionProcessor.cs


namespace UnityEditor.VFXToolbox.ImageSequencer
{
[Processor("Color","Color Correction")]
class ColorCorrectionProcessor : ProcessorBase
internal class ColorCorrectionProcessor : ProcessorBase
{
[FloatSlider(0.0f,2.0f)]
public float Brightness;

}
CurveToTextureUtility.CurveToTexture(AlphaCurve, ref m_CurveTexture);
Texture inputFrame = processor.InputSequence.RequestFrame(frame).texture;
processor.material.SetTexture("_MainTex", inputFrame);
processor.material.SetFloat("_Brightness", Brightness);
processor.material.SetFloat("_Contrast", Contrast);
processor.material.SetFloat("_Saturation", Saturation);
Texture inputFrame = RequestInputTexture(frame);
material.SetTexture("_MainTex", inputFrame);
material.SetFloat("_Brightness", Brightness);
material.SetFloat("_Contrast", Contrast);
material.SetFloat("_Saturation", Saturation);
processor.material.SetTexture("_AlphaCurve", m_CurveTexture);
material.SetTexture("_AlphaCurve", m_CurveTexture);
processor.ExecuteShaderAndDump(frame, inputFrame);
ProcessFrame(frame, inputFrame);
return true;
}

if (EditorGUI.EndChangeCheck() || curveChanged)
{
processor.Invalidate();
Invalidate();
changed = true;
}

40
ImageSequencer/Editor/Serialization/Processors/CropProcessor.cs


namespace UnityEditor.VFXToolbox.ImageSequencer
{
[Processor("Common","Crop")]
class CropProcessor : ProcessorBase
internal class CropProcessor : ProcessorBase
{
public uint Crop_Top;
public uint Crop_Bottom;

public override void UpdateOutputSize()
{
int width = (processor.InputSequence.width - (int)Crop_Left) - (int)Crop_Right;
int height = (processor.InputSequence.height - (int)Crop_Top) - (int)Crop_Bottom;
processor.SetOutputSize(width, height);
int width = (inputSequenceWidth - (int)Crop_Left) - (int)Crop_Right;
int height = (inputSequenceHeight - (int)Crop_Top) - (int)Crop_Bottom;
SetOutputSize(width, height);
}
public override void Default()

Crop_Right = 0;
AutoCropThreshold = 0.003f;
}
Texture texture = processor.InputSequence.RequestFrame(frame).texture;
processor.material.SetTexture("_MainTex", texture);
processor.material.SetVector("_CropFactors", new Vector4(
Texture texture = RequestInputTexture(frame);
material.SetTexture("_MainTex", texture);
material.SetVector("_CropFactors", new Vector4(
(float)Crop_Left / texture.width,
(float)Crop_Right / texture.width,
(float)Crop_Top / texture.height,

processor.ExecuteShaderAndDump(frame, texture);
ProcessFrame(frame, texture);
int sourceWidth = processor.InputSequence.width;
int sourceHeight = processor.InputSequence.height;
int sourceWidth = inputSequenceWidth;
int sourceHeight = inputSequenceHeight;
var crop_top = serializedObject.FindProperty("Crop_Top");
var crop_bottom = serializedObject.FindProperty("Crop_Bottom");

if (EditorGUI.EndChangeCheck())
{
UpdateOutputSize();
processor.Invalidate();
Invalidate();
changed = true;
}

private void FindProperValues(float threshold, ref SerializedProperty top, ref SerializedProperty bottom, ref SerializedProperty left, ref SerializedProperty right)
{
int width = processor.InputSequence.width;
int height = processor.InputSequence.height;
int width = inputSequenceWidth;
int height = inputSequenceHeight;
int minX = width;
int maxX = 0;

Color[] colors;
RenderTexture tempRT = RenderTexture.GetTemporary(width, height, 0, RenderTextureFormat.ARGBHalf, RenderTextureReadWrite.Linear);
for (int i = 0; i < processor.InputSequence.frames.Count; i++)
for (int i = 0; i < inputSequenceLength; i++)
ProcessingFrame f = processor.InputSequence.frames[i];
Texture t = RequestInputTexture(i);
VFXToolboxGUIUtility.DisplayProgressBar("Crop processor", "Evaluating closest bound (Frame #" + i + " on " + processor.InputSequence.frames.Count + "...)", (float)i / processor.InputSequence.frames.Count);
if (processor.InputSequence.processingNode != null)
VFXToolboxGUIUtility.DisplayProgressBar("Crop processor", "Evaluating closest bound (Frame #" + i + " on " + inputSequenceLength + "...)", (float)i / inputSequenceLength);
if (!isInputFrameSequence)
f.Process();
colors = VFXToolboxUtility.ReadBack(f.texture as RenderTexture);
colors = VFXToolboxUtility.ReadBack(t as RenderTexture);
Graphics.Blit(f.texture, tempRT);
Graphics.Blit(t, tempRT);
colors = VFXToolboxUtility.ReadBack(tempRT);
}

40
ImageSequencer/Editor/Serialization/Processors/CustomMaterialProcessor.cs


using UnityEngine;
using UnityEngine.Serialization;
namespace UnityEditor.VFXToolbox.ImageSequencer
{

public Material material;
[FormerlySerializedAs("material")]
public Material customMaterial;
public override string label => $"{processorName} ({((material == null) ? "Not Set" : material.name)})";
public override string label => $"{processorName} ({((customMaterial == null) ? "Not Set" : customMaterial.name)})";
material = null;
customMaterial = null;
Texture inputFrame = processor.InputSequence.RequestFrame(frame).texture;
Texture inputFrame = RequestInputTexture(frame);
if (material != null)
if (customMaterial != null)
material.SetTexture("_InputFrame", inputFrame);
material.SetVector("_FrameData", new Vector4(processor.OutputWidth, processor.OutputHeight, frame, sequenceLength));
material.SetVector("_FlipbookData", new Vector4(processor.NumU, processor.NumV, 0, 0));
processor.ExecuteShaderAndDump(frame, inputFrame, material);
customMaterial.SetTexture("_InputFrame", inputFrame);
customMaterial.SetVector("_FrameData", new Vector4(inputSequenceWidth, inputSequenceHeight, frame, sequenceLength));
customMaterial.SetVector("_FlipbookData", new Vector4(inputSequenceNumU, inputSequenceNumV, 0, 0));
ProcessFrame(frame, inputFrame, customMaterial);
processor.material.SetTexture("_MainTex", inputFrame);
processor.ExecuteShaderAndDump(frame, inputFrame);
material.SetTexture("_MainTex", inputFrame);
ProcessFrame(frame, inputFrame);
}
return true;
}

public override bool OnInspectorGUI(bool changed, SerializedObject serializedObject)
{
EditorGUI.BeginChangeCheck();
Material mat = (Material)EditorGUILayout.ObjectField(VFXToolboxGUIUtility.Get("Material"), material, typeof(Material), false);
Material mat = (Material)EditorGUILayout.ObjectField(VFXToolboxGUIUtility.Get("Material"), customMaterial, typeof(Material), false);
material = mat;
customMaterial = mat;
processor.Invalidate();
Invalidate();
if (material != null)
if (customMaterial != null)
Editor.CreateCachedEditor(material, typeof(MaterialEditor), ref m_MaterialEditor);
Editor.CreateCachedEditor(customMaterial, typeof(MaterialEditor), ref m_MaterialEditor);
if (m_CachedShader != material.shader)
if (m_CachedShader != customMaterial.shader)
m_CachedShader = material.shader;
m_CachedShader = customMaterial.shader;
processor.Invalidate();
Invalidate();
changed = true;
}

10
ImageSequencer/Editor/Serialization/Processors/DecimateProcessor.cs


public override string processorName => "Decimate";
public override int sequenceLength => Mathf.Max(1, (int)Mathf.Floor((float)processor.InputSequence.length / DecimateBy));
public override int sequenceLength => Mathf.Max(1, (int)Mathf.Floor((float)inputSequenceLength / DecimateBy));
public override void Default()
{

EditorGUI.BeginChangeCheck();
int newDecimate = Mathf.Clamp(EditorGUILayout.IntField(VFXToolboxGUIUtility.Get("Decimate by"), (int)DecimateBy), 2, processor.InputSequence.length);
int newDecimate = Mathf.Clamp(EditorGUILayout.IntField(VFXToolboxGUIUtility.Get("Decimate by"), (int)DecimateBy), 2, inputSequenceLength);
if (newDecimate != decimateBy.intValue)
{

public override bool Process(int frame)
{
int targetFrame = frame * DecimateBy;
Texture texture = processor.InputSequence.RequestFrame(targetFrame).texture;
processor.material.SetTexture("_MainTex", texture);
processor.ExecuteShaderAndDump(frame, texture);
Texture texture = RequestInputTexture(targetFrame);
material.SetTexture("_MainTex", texture);
ProcessFrame(frame, texture);
return true;
}
}

18
ImageSequencer/Editor/Serialization/Processors/FadeProcessor.cs


namespace UnityEditor.VFXToolbox.ImageSequencer
{
[Processor("Sequence","Fade")]
class FadeProcessor : ProcessorBase
internal class FadeProcessor : ProcessorBase
{
public AnimationCurve FadeCurve;
public Color FadeToColor;

public override bool Process(int frame)
{
Texture inputFrame = processor.InputSequence.RequestFrame(frame).texture;
processor.material.SetTexture("_MainTex", inputFrame);
processor.material.SetColor("_FadeToColor", FadeToColor);
processor.material.SetFloat("_Ratio", FadeCurve.Evaluate(((float)frame) / sequenceLength));
processor.ExecuteShaderAndDump(frame, inputFrame);
Texture inputFrame = RequestInputTexture(frame);
material.SetTexture("_MainTex", inputFrame);
material.SetColor("_FadeToColor", FadeToColor);
material.SetFloat("_Ratio", FadeCurve.Evaluate(((float)frame) / sequenceLength));
ProcessFrame(frame, inputFrame);
return true;
}

if (EditorGUI.EndChangeCheck())
{
processor.Invalidate();
Invalidate();
changed = true;
}

void OnCurveFieldGUI(Rect renderArea, Rect curveArea)
{
float seqRatio = -1.0f;
if (processor.isCurrentlyPreviewed)
if (isCurrentlyPreviewed)
seqRatio = (processor.currentPreviewSequenceLength > 1) ? (float)processor.currentPreviewFrame / (processor.currentPreviewSequenceLength - 1) : 0.0f;
seqRatio = (previewSequenceLength > 1) ? (float)previewCurrentFrame / (previewSequenceLength - 1) : 0.0f;
}
// If previewing current sequence : draw trackbar

16
ImageSequencer/Editor/Serialization/Processors/FixBordersProcessor.cs


public override bool Process(int frame)
{
Texture inputFrame = processor.InputSequence.RequestFrame(frame).texture;
processor.material.SetTexture("_MainTex", inputFrame);
processor.material.SetVector("_FixFactors", FixFactors);
processor.material.SetColor("_FadeToColor", FadeToColor);
processor.material.SetFloat("_FadeToAlpha", FadeToAlpha);
processor.material.SetFloat("_Exponent", Exponent);
processor.ExecuteShaderAndDump(frame, inputFrame);
Texture inputFrame = RequestInputTexture(frame);
material.SetTexture("_MainTex", inputFrame);
material.SetVector("_FixFactors", FixFactors);
material.SetColor("_FadeToColor", FadeToColor);
material.SetFloat("_FadeToAlpha", FadeToAlpha);
material.SetFloat("_Exponent", Exponent);
ProcessFrame(frame, inputFrame);
return true;
}

if (EditorGUI.EndChangeCheck())
{
processor.Invalidate();
Invalidate();
changed = true;
}

42
ImageSequencer/Editor/Serialization/Processors/LoopingProcessor.cs


{
get
{
if (processor.InputSequence.length > 0)
if (inputSequenceLength > 0)
return outputSequenceLength;
else
return 0;

public override bool Process(int frame)
{
int inputlength = processor.InputSequence.length;
int inputlength = inputSequenceLength;
int outputlength = sequenceLength;
float t = (float)frame / outputlength;

int Prev = Mathf.Clamp((int)Mathf.Ceil(syncFrame + frame), 0, inputlength - 1);
int Next = Mathf.Clamp((int)Mathf.Floor(syncFrame - (outputlength - frame)), 0, inputlength - 1);
Texture prevtex = processor.InputSequence.RequestFrame(Prev).texture;
Texture nexttex = processor.InputSequence.RequestFrame(Next).texture;
Texture prevtex = RequestInputTexture(Prev);
Texture nexttex = RequestInputTexture(Next);
processor.material.SetTexture("_MainTex", prevtex);
processor.material.SetTexture("_AltTex", nexttex);
processor.material.SetFloat("_BlendFactor", blendFactor);
material.SetTexture("_MainTex", prevtex);
material.SetTexture("_AltTex", nexttex);
material.SetFloat("_BlendFactor", blendFactor);
processor.ExecuteShaderAndDump(frame, prevtex);
ProcessFrame(frame, prevtex);
return true;
}

EditorGUI.BeginChangeCheck();
int sync = syncFrame.intValue;
int newSync = EditorGUILayout.IntSlider(VFXToolboxGUIUtility.Get("Input Sync Frame|The frame from input sequence that will be used at start and end of the output sequence."), sync, 0 + outputSequenceLength.intValue, processor.InputSequence.length - outputSequenceLength.intValue);
int newSync = EditorGUILayout.IntSlider(VFXToolboxGUIUtility.Get("Input Sync Frame|The frame from input sequence that will be used at start and end of the output sequence."), sync, 0 + outputSequenceLength.intValue, inputSequenceLength - outputSequenceLength.intValue);
newSync = Mathf.Clamp(newSync, 0 + outputSequenceLength.intValue, processor.InputSequence.length - outputSequenceLength.intValue);
newSync = Mathf.Clamp(newSync, 0 + outputSequenceLength.intValue, inputSequenceLength - outputSequenceLength.intValue);
int newlength = EditorGUILayout.IntSlider(VFXToolboxGUIUtility.Get("Output Sequence Length|How many frames will be in the output sequence?"), length, 2, (processor.InputSequence.length / 2) + 1);
int newlength = EditorGUILayout.IntSlider(VFXToolboxGUIUtility.Get("Output Sequence Length|How many frames will be in the output sequence?"), length, 2, (inputSequenceLength / 2) + 1);
newlength = Mathf.Min(newlength, Mathf.Max(1, (processor.InputSequence.length / 2)));
newlength = Mathf.Min(newlength, Mathf.Max(1, (inputSequenceLength / 2)));
syncFrame.intValue = Mathf.Clamp(syncFrame.intValue, 0 + outputSequenceLength.intValue, processor.InputSequence.length - outputSequenceLength.intValue);
syncFrame.intValue = Mathf.Clamp(syncFrame.intValue, 0 + outputSequenceLength.intValue, inputSequenceLength - outputSequenceLength.intValue);
if (processor.isCurrentlyPreviewed)
if (isCurrentlyPreviewed)
seqRatio = (processor.currentPreviewSequenceLength > 1) ? (float)processor.currentPreviewFrame / (processor.currentPreviewSequenceLength - 1) : 0.0f;
seqRatio = (previewSequenceLength > 1) ? (float)previewCurrentFrame / (previewSequenceLength - 1) : 0.0f;
}
// Draw Preview

AnimationCurve curve = serializedObject.FindProperty("curve").animationCurveValue;
using (new GUI.ClipScope(gradient_rect))
{
int seqLen = processor.OutputSequence.length;
int seqLen = this.outputSequenceLength;
int syncF = syncFrame.intValue;
float w = Mathf.Ceil((float)width / seqLen);

void OnCurveFieldGUI(Rect renderArea, Rect curveArea)
{
float seqRatio = -1.0f;
if (processor.isCurrentlyPreviewed)
if (isCurrentlyPreviewed)
seqRatio = (processor.currentPreviewSequenceLength > 1) ? (float)processor.currentPreviewFrame / (processor.currentPreviewSequenceLength - 1) : 0.0f;
seqRatio = (previewSequenceLength > 1) ? (float)previewCurrentFrame / (previewSequenceLength - 1) : 0.0f;
}
// If previewing current sequence : draw trackbar

public override bool OnCanvasGUI(ImageSequencerCanvas canvas)
{
int inLength = processor.InputSequence.length;
int inLength = inputSequenceLength;
int outLength = sequenceLength;
int syncFrame = this.syncFrame;

#if !UNITY_2018_2_OR_NEWER
GL.sRGBWrite = (QualitySettings.activeColorSpace == ColorSpace.Linear);
#endif
GUI.DrawTexture(imgARect, processor.InputSequence.RequestFrame(inSeqAIDX).texture);
GUI.DrawTexture(imgARect, RequestInputTexture(inSeqAIDX));
#if !UNITY_2018_2_OR_NEWER
GL.sRGBWrite = false;
#endif

#if !UNITY_2018_2_OR_NEWER
GL.sRGBWrite = (QualitySettings.activeColorSpace == ColorSpace.Linear);
#endif
GUI.DrawTexture(imgBRect, processor.InputSequence.RequestFrame(inSeqBIDX).texture);
GUI.DrawTexture(imgBRect, RequestInputTexture(inSeqBIDX));
#if !UNITY_2018_2_OR_NEWER
GL.sRGBWrite = false;
#endif

12
ImageSequencer/Editor/Serialization/Processors/PremultiplyAlphaProcessor.cs


}
public override bool Process(int frame)
{
Texture inputFrame = processor.InputSequence.RequestFrame(frame).texture;
processor.material.SetTexture("_MainTex", inputFrame);
processor.material.SetInt("_RemoveAlpha", RemoveAlpha ? 1 : 0);
processor.material.SetFloat("_AlphaValue", AlphaValue);
processor.ExecuteShaderAndDump(frame, inputFrame);
Texture inputFrame = RequestInputTexture(frame);
material.SetTexture("_MainTex", inputFrame);
material.SetInt("_RemoveAlpha", RemoveAlpha ? 1 : 0);
material.SetFloat("_AlphaValue", AlphaValue);
ProcessFrame(frame, inputFrame);
return true;
}
public override bool OnInspectorGUI(bool changed, SerializedObject serializedObject)

if (EditorGUI.EndChangeCheck())
{
processor.Invalidate();
Invalidate();
changed = true;
}

14
ImageSequencer/Editor/Serialization/Processors/RemapColorProcessor.cs


}
CurveToTextureUtility.GradientToTexture(Gradient, ref m_GradientTexture);
Texture inputFrame = processor.InputSequence.RequestFrame(frame).texture;
processor.material.SetTexture("_MainTex", inputFrame);
Texture inputFrame = RequestInputTexture(frame);
material.SetTexture("_MainTex", inputFrame);
processor.material.SetFloat("_Mode", (int)ColorSource);
material.SetFloat("_Mode", (int)ColorSource);
processor.material.SetTexture("_Gradient", m_GradientTexture);
material.SetTexture("_Gradient", m_GradientTexture);
processor.ExecuteShaderAndDump(frame, inputFrame);
ProcessFrame(frame, inputFrame);
return true;
}

if (EditorGUI.EndChangeCheck())
{
processor.Invalidate();
Invalidate();
changed = true;
}

m_GradientTexture.filterMode = FilterMode.Bilinear;
CurveToTextureUtility.GradientToTexture(Gradient, ref m_GradientTexture);
}
}
}

22
ImageSequencer/Editor/Serialization/Processors/RemoveBackgroundProcessor.cs


public override bool Process(int frame)
{
Texture tex = processor.InputSequence.RequestFrame(frame).texture;
processor.SetOutputSize(tex.width, tex.height);
processor.material.SetTexture("_MainTex", tex);
processor.material.SetColor("_BackgroundColor", BackgroundColor);
processor.ExecuteShaderAndDump(frame, tex);
Texture tex = RequestInputTexture(frame);
SetOutputSize(tex.width, tex.height);
material.SetTexture("_MainTex", tex);
material.SetColor("_BackgroundColor", BackgroundColor);
ProcessFrame(frame, tex);
return true;
}

EditorGUILayout.PropertyField(bgColor, VFXToolboxGUIUtility.Get("Background Color"));
if (GUILayout.Button(VFXToolboxGUIUtility.Get("Grab"), GUILayout.Width(40)))
{
if (processor.InputSequence.length > 0)
if (inputSequenceLength > 0)
processor.InputSequence.RequestFrame(0);
var texture = RequestInputTexture(0);
if (processor.InputSequence.frames[0].texture is RenderTexture)
if (texture is RenderTexture)
background = VFXToolboxUtility.ReadBack((RenderTexture)processor.InputSequence.frames[0].texture)[0];
background = VFXToolboxUtility.ReadBack((RenderTexture)texture)[0];
Texture2D inputFrame = (Texture2D)processor.InputSequence.frames[0].texture;
Texture2D inputFrame = (Texture2D)texture;
RenderTexture rt = RenderTexture.GetTemporary(inputFrame.width, inputFrame.height, 0, RenderTextureFormat.ARGBHalf, RenderTextureReadWrite.Linear);
Graphics.Blit(inputFrame, rt);
background = VFXToolboxUtility.ReadBack(rt)[0];

if (EditorGUI.EndChangeCheck())
{
UpdateOutputSize();
processor.Invalidate();
Invalidate();
changed = true;
}
GUILayout.Space(20);

18
ImageSequencer/Editor/Serialization/Processors/ResizeProcessor.cs


namespace UnityEditor.VFXToolbox.ImageSequencer
{
[Processor("Common","Resize")]
class ResizeProcessor : ProcessorBase
internal class ResizeProcessor : ProcessorBase
{
public ushort Width;
public ushort Height;

public override void UpdateOutputSize()
{
processor.SetOutputSize(Width, Height);
SetOutputSize(Width, Height);
Texture texture = processor.InputSequence.RequestFrame(frame).texture;
Texture texture = RequestInputTexture(frame);
processor.material.SetTexture("_MainTex", texture);
processor.material.SetVector("_KernelAndSize", kernelAndSize);
processor.ExecuteShaderAndDump(frame, texture);
material.SetTexture("_MainTex", texture);
material.SetVector("_KernelAndSize", kernelAndSize);
ProcessFrame(frame, texture);
return true;
}

var out_width = serializedObject.FindProperty("Width");
out_width.intValue = (int)o;
serializedObject.ApplyModifiedProperties();
processor.Invalidate();
Invalidate();
UpdateOutputSize();
}, s);
}

var out_height = serializedObject.FindProperty("Height");
out_height.intValue = (int)o;
serializedObject.ApplyModifiedProperties();
processor.Invalidate();
Invalidate();
UpdateOutputSize();
}, s);
}

if (EditorGUI.EndChangeCheck())
{
UpdateOutputSize();
processor.Invalidate();
Invalidate();
changed = true;
}

26
ImageSequencer/Editor/Serialization/Processors/RetimeProcessor.cs


{
get
{
if (processor.InputSequence.length > 0)
if (inputSequenceLength > 0)
return outputSequenceLength;
else
return 0;

public override bool Process(int frame)
{
int inputlength = processor.InputSequence.length;
int inputlength = inputSequenceLength;
int outputlength = sequenceLength;
float t = (float)frame / outputlength;

int Prev = Mathf.Clamp((int)Mathf.Floor(Frame), 0, inputlength - 1);
int Next = Mathf.Clamp((int)Mathf.Ceil(Frame), 0, inputlength - 1);
Texture prevtex = processor.InputSequence.RequestFrame(Prev).texture;
Texture nexttex = processor.InputSequence.RequestFrame(Next).texture;
Texture prevtex = RequestInputTexture(Prev);
Texture nexttex = RequestInputTexture(Next);
processor.material.SetTexture("_MainTex", prevtex);
processor.material.SetTexture("_AltTex", nexttex);
processor.material.SetFloat("_BlendFactor", blendFactor);
material.SetTexture("_MainTex", prevtex);
material.SetTexture("_AltTex", nexttex);
material.SetFloat("_BlendFactor", blendFactor);
processor.ExecuteShaderAndDump(frame, prevtex);
ProcessFrame(frame, prevtex);
return true;
}

{
if (m_CurveDrawer == null)
{
m_CurveDrawer = new CurveDrawer("Retime Curve", 0.0f, 1.0f, 0.0f, processor.InputSequence.length, 140, false);
m_CurveDrawer = new CurveDrawer("Retime Curve", 0.0f, 1.0f, 0.0f, inputSequenceLength, 140, false);
m_CurveDrawer.AddCurve(serializedObject.FindProperty("curve"), new Color(0.5f, 0.75f, 1.0f), "Retime Curve");
m_CurveDrawer.OnPostGUI = OnCurveFieldGUI;
}

EditorGUI.BeginChangeCheck();
int length = outputSequenceLength.intValue;
int newlength = EditorGUILayout.IntSlider(VFXToolboxGUIUtility.Get("Sequence Length"), length, 1, processor.InputSequence.length);
int newlength = EditorGUILayout.IntSlider(VFXToolboxGUIUtility.Get("Sequence Length"), length, 1, inputSequenceLength);
if (newlength != length)
{
outputSequenceLength.intValue = newlength;

if (useCurve.boolValue)
{
m_CurveDrawer.SetBounds(new Rect(0, 0, 1, processor.InputSequence.length - 1));
m_CurveDrawer.SetBounds(new Rect(0, 0, 1, inputSequenceLength - 1));
if (m_CurveDrawer.OnGUILayout())
{

void OnCurveFieldGUI(Rect renderArea, Rect curveArea)
{
float seqRatio = -1.0f;
if (processor.isCurrentlyPreviewed)
if (isCurrentlyPreviewed)
seqRatio = (processor.currentPreviewSequenceLength > 1) ? (float)processor.currentPreviewFrame / (processor.currentPreviewSequenceLength - 1) : 0.0f;
seqRatio = (previewSequenceLength > 1) ? (float)previewCurrentFrame / (previewSequenceLength - 1) : 0.0f;
}
// If previewing current sequence : draw trackbar

20
ImageSequencer/Editor/Serialization/Processors/RotateProcessor.cs


namespace UnityEditor.VFXToolbox.ImageSequencer
{
[Processor("Common","Rotate")]
class RotateProcessor : ProcessorBase
internal class RotateProcessor : ProcessorBase
{
public enum RotateMode
{

public override string label => $"{processorName} ({FrameRotateMode})";
public override int numU => (FrameRotateMode == RotateMode.None || FrameRotateMode == RotateMode.Rotate180) ? base.numU : base.numV;
public override int numV => (FrameRotateMode == RotateMode.None || FrameRotateMode == RotateMode.Rotate180) ? base.numV : base.numU;
processor.SetOutputSize(processor.InputSequence.width, processor.InputSequence.height);
SetOutputSize(inputSequenceWidth, inputSequenceHeight);
processor.SetOutputSize(processor.InputSequence.height, processor.InputSequence.width);
SetOutputSize(inputSequenceHeight, inputSequenceWidth);
}
public override void Default()

public override bool Process(int frame)
{
UpdateOutputSize();
Texture texture = processor.InputSequence.RequestFrame(frame).texture;
processor.material.SetTexture("_MainTex", texture);
processor.material.SetInt("_Mode", (int)FrameRotateMode);
processor.ExecuteShaderAndDump(frame, texture);
Texture texture = RequestInputTexture(frame);
material.SetTexture("_MainTex", texture);
material.SetInt("_Mode", (int)FrameRotateMode);
ProcessFrame(frame, texture);
return true;
}

if (EditorGUI.EndChangeCheck())
{
UpdateOutputSize();
processor.Invalidate();
Invalidate();
changed = true;
}

正在加载...
取消
保存