using UnityEngine;
namespace UnityEditor.Experimental.VFX.Toolbox.ImageSequencer
{
///
/// 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.
///
public abstract class ProcessorBase : ScriptableObject
{
///
/// Asset Path of the Shader used for this processor (eg: "Assets/Shaders/MyShader.shader")
///
public abstract string shaderPath { get; }
///
/// Name of the Processor
///
public abstract string processorName { get; }
///
/// Display Label text of the processor (will be displayed in the processor list and asset inspector)
///
public virtual string label => processorName;
///
/// Number of U (Columns) defined by this processor. Implement to override default (passthrough input sequence's numU)
///
public virtual int numU => inputSequenceNumU;
///
/// Number of V (Rows) defined by this processor. Implement to override default (passthrough input sequence's numV)
///
public virtual int numV => inputSequenceNumV;
///
/// Number of frames defined by this processor. Implement to override default (passthrough input's sequence length)
///
public virtual int sequenceLength => processingNode.InputSequence.length;
///
/// Determines the actual processing of the frame. Will be called when this frame is requested by the Image Sequencer.
///
/// the requested frame index
///
public abstract bool Process(int frame);
///
/// 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)
///
public virtual void UpdateOutputSize()
{
processingNode.SetOutputSize(processingNode.InputSequence.width, processingNode.InputSequence.height);
}
///
/// Displays the Processor inspector in the left pane of the Image Sequencer
///
/// Whether the inspector has already caught changes.
/// The processor's serializedObject
/// whether there has changes to apply
public abstract bool OnInspectorGUI(bool changed, SerializedObject serializedObject);
///
/// Displays the Processor's Canvas Helpers as overlay.
///
/// The Image Sequencer Canvas currently drawn
/// whether the canvas needs to redraw
public virtual bool OnCanvasGUI(ImageSequencerCanvas canvas)
{
return false;
}
///
/// 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.
///
public abstract void Default();
#region PROCESSINGNODE ACCESS
///
/// The Input Sequence Frame Count
///
public int inputSequenceLength => processingNode.InputSequence.length;
///
/// The Input Sequence Frame Width (in pixels)
///
public int inputSequenceWidth => processingNode.InputSequence.width;
///
/// The Input Sequence Frame Height (in pixels)
///
public int inputSequenceHeight => processingNode.InputSequence.height;
///
/// The Input Sequence Flipbook U Count (Columns)
///
public int inputSequenceNumU => processingNode.InputSequence.numU;
///
/// The Input Sequence Flipbook V Count (Rows)
///
public int inputSequenceNumV => processingNode.InputSequence.numV;
///
/// Whether the Input frame Sequence is the Asset's Input Frame List (use to determine whether it needs gamma correction or not)
///
public bool isInputFrameSequence => processingNode.InputSequence.processingNode == null;
///
/// 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)
///
public bool isCurrentlyPreviewed => processingNode.isCurrentlyPreviewed;
///
/// The current Image Sequencer Viewport's preview sequence length. Please not that this is not necessarily this Processor's preview, use isCurrentlyPreviewed to check.
///
public int previewSequenceLength => processingNode.previewSequenceLength;
///
/// The current Image Sequencer Viewport's preview image index. Please not that this is not necessarily this Processor's preview, use isCurrentlyPreviewed to check.
///
public int previewCurrentFrame => processingNode.previewCurrentFrame;
///
/// The material internally used for this processor. It is created from the shader defined using this.shaderPath.
///
public Material material => processingNode.material;
///
/// Requests the Texture (and its Processing) of the Input Sequence Image at given index.
///
/// The index of the Frame to be returned.
/// The texture object corresponding to the frame.
public Texture RequestInputTexture(int index)
{
return processingNode.InputSequence.RequestFrame(index).texture;
}
///
/// Requests the Texture of the Output Sequence Image at given index.
///
/// The index of the Frame to be returned.
/// The texture object corresponding to the frame.
public Texture RequestOutputTexture(int index)
{
return processingNode.OutputSequence.frames[index].texture;
}
///
/// Sets the Output Size to the Processing Node
///
///
///
public void SetOutputSize(int width, int height)
{
processingNode.SetOutputSize(width, height);
}
///
/// Process the Frame at Given Index, using given material and texture as MainTexture.
///
/// Frame Index to process
/// Texture object to pass as MainTexture
/// Material to use for the procesing
public void ProcessFrame(int outputIndex, Texture mainTexture, Material material)
{
processingNode.ExecuteShaderAndDump(outputIndex, mainTexture, material);
}
///
/// Process the Frame at Given Index, using default processor material and texture as MainTexture.
///
/// Frame Index to process
/// Texture object to pass as MainTexture
public void ProcessFrame(int outputIndex, Texture mainTexture = null)
{
processingNode.ExecuteShaderAndDump(outputIndex, mainTexture);
}
///
/// Invalidates the Processor (will require to rebake frames)
///
public void Invalidate()
{
processingNode.Invalidate();
}
#endregion
#region INTERNAL
private ProcessingNode processingNode;
internal void AttachTo(ProcessingNode processor)
{
this.processingNode = processor;
}
#endregion
}
}