浏览代码

Custom Material Shader Generator

/feature-create-processor-and-material-from-menu
Thomas ICHÉ 4 年前
当前提交
85c9aa40
共有 4 个文件被更改,包括 125 次插入0 次删除
  1. 8
      Editor/ImageSequencer/EditorTemplates.meta
  2. 106
      Editor/ImageSequencer/EditorTemplates/ImageSequencerCustomShaderTemplateFactory.cs
  3. 11
      Editor/ImageSequencer/EditorTemplates/ImageSequencerCustomShaderTemplateFactory.cs.meta

8
Editor/ImageSequencer/EditorTemplates.meta


fileFormatVersion: 2
guid: 9d239ec7163605d4db190de7c23cb789
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

106
Editor/ImageSequencer/EditorTemplates/ImageSequencerCustomShaderTemplateFactory.cs


using System.IO;
using System.Linq;
using System.Text;
using UnityEditor.ProjectWindowCallback;
using UnityEngine;
namespace UnityEditor.Experimental.VFX.Toolbox.ImageSequencer
{
internal class ImageSequencerCustomShaderTemplateFactory
{
[MenuItem("Assets/Create/Visual Effects/Image Sequencer/Custom Material Shader")]
static void CreateStaticEditorShaderTemplate()
{
var icon = EditorGUIUtility.FindTexture("Shader Icon");
ProjectWindowUtil.StartNameEditingIfProjectWindowExists(0, ScriptableObject.CreateInstance<DoCreateImageSequencerCustomShader>(), "New Custom Shader.shader", icon, null);
}
public static Shader CreateShaderAtPath(string path)
{
string name = path.Split('/').Last().Replace(".shader", "");
Debug.Log(name);
StringBuilder sb = new StringBuilder();
sb.AppendFormat("Shader \"ImageSequencer/{0}\"", name);
sb.Append(@"
{
Properties
{
}
SubShader
{
Tags { ""RenderType"" = ""Opaque"" }
LOD 100
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include ""UnityCG.cginc""
struct appdata
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
};
struct v2f
{
float2 uv : TEXCOORD0;
float4 vertex : SV_POSITION;
};
// ImageSequencer CustomMaterial uniforms
// ======================================
//
// sampler2D _InputFrame; // Input Frame (from previous sequence)
//
// float4 _FrameData; // Frame Data
// // x, y : width (x) and height (y) in pixels
// // z, w : sequence index (z) and length (w)
//
// float4 _FlipbookData; // Flipbook Data
// // x, y : number of columns (x) and rows (y)
//
sampler2D _InputFrame;
float4 _FrameData;
float4 _FlipbookData;
v2f vert(appdata v)
{
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
o.uv = v.uv;
return o;
}
fixed4 frag(v2f i) : SV_Target
{
// Process the Color
fixed4 col = tex2D(_InputFrame, i.uv);
return col;
}
ENDCG
}
}
}");
File.WriteAllText(path, sb.ToString());
AssetDatabase.ImportAsset(path);
return AssetDatabase.LoadAssetAtPath<Shader>(path);
}
}
internal class DoCreateImageSequencerCustomShader : EndNameEditAction
{
public override void Action(int instanceId, string pathName, string resourceFile)
{
Shader asset = ImageSequencerCustomShaderTemplateFactory.CreateShaderAtPath(pathName);
ProjectWindowUtil.ShowCreatedAsset(asset);
}
}
}

11
Editor/ImageSequencer/EditorTemplates/ImageSequencerCustomShaderTemplateFactory.cs.meta


fileFormatVersion: 2
guid: 7e4a42824d0f61745a7c3e3299a23fbf
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
正在加载...
取消
保存