Thomas ICHÉ
6 年前
当前提交
c1e6e672
共有 58 个文件被更改,包括 2748 次插入 和 0 次删除
-
9com.unity.vfx-toolbox/Workbench.meta
-
9com.unity.vfx-toolbox/Workbench/Editor.meta
-
9com.unity.vfx-toolbox/Workbench/Editor/Brushes.meta
-
22com.unity.vfx-toolbox/Workbench/Editor/Brushes/FlowPaintBrush.cs
-
12com.unity.vfx-toolbox/Workbench/Editor/Brushes/FlowPaintBrush.cs.meta
-
8com.unity.vfx-toolbox/Workbench/Editor/EditorResources.meta
-
9com.unity.vfx-toolbox/Workbench/Editor/EditorResources/PaintBrush Icon.png
-
76com.unity.vfx-toolbox/Workbench/Editor/EditorResources/PaintBrush Icon.png.meta
-
14com.unity.vfx-toolbox/Workbench/Editor/EditorResources/Workbench Icon.png
-
76com.unity.vfx-toolbox/Workbench/Editor/EditorResources/Workbench Icon.png.meta
-
32com.unity.vfx-toolbox/Workbench/Editor/PaintBrush.cs
-
11com.unity.vfx-toolbox/Workbench/Editor/PaintBrush.cs.meta
-
12com.unity.vfx-toolbox/Workbench/Editor/PaintBrushCollection.cs
-
12com.unity.vfx-toolbox/Workbench/Editor/PaintBrushCollection.cs.meta
-
80com.unity.vfx-toolbox/Workbench/Editor/PaintBrushCollectionEditor.cs
-
12com.unity.vfx-toolbox/Workbench/Editor/PaintBrushCollectionEditor.cs.meta
-
53com.unity.vfx-toolbox/Workbench/Editor/PaintBrushEditor.cs
-
12com.unity.vfx-toolbox/Workbench/Editor/PaintBrushEditor.cs.meta
-
80com.unity.vfx-toolbox/Workbench/Editor/PaintBrushUtility.cs
-
12com.unity.vfx-toolbox/Workbench/Editor/PaintBrushUtility.cs.meta
-
34com.unity.vfx-toolbox/Workbench/Editor/PaintBuffer.cs
-
12com.unity.vfx-toolbox/Workbench/Editor/PaintBuffer.cs.meta
-
9com.unity.vfx-toolbox/Workbench/Editor/Tools.meta
-
329com.unity.vfx-toolbox/Workbench/Editor/Tools/FlowMapPainter.cs
-
12com.unity.vfx-toolbox/Workbench/Editor/Tools/FlowMapPainter.cs.meta
-
142com.unity.vfx-toolbox/Workbench/Editor/Tools/NoiseGenerator.cs
-
12com.unity.vfx-toolbox/Workbench/Editor/Tools/NoiseGenerator.cs.meta
-
340com.unity.vfx-toolbox/Workbench/Editor/Tools/ProgressionMapGenerator.cs
-
12com.unity.vfx-toolbox/Workbench/Editor/Tools/ProgressionMapGenerator.cs.meta
-
9com.unity.vfx-toolbox/Workbench/Editor/Tools/Shaders.meta
-
129com.unity.vfx-toolbox/Workbench/Editor/Tools/Shaders/ClassicNoise2D.hlsl
-
9com.unity.vfx-toolbox/Workbench/Editor/Tools/Shaders/ClassicNoise2D.hlsl.meta
-
75com.unity.vfx-toolbox/Workbench/Editor/Tools/Shaders/FlowMapPainter.DisplayFlow.shader
-
9com.unity.vfx-toolbox/Workbench/Editor/Tools/Shaders/FlowMapPainter.DisplayFlow.shader.meta
-
59com.unity.vfx-toolbox/Workbench/Editor/Tools/Shaders/FlowMapPainter.shader
-
9com.unity.vfx-toolbox/Workbench/Editor/Tools/Shaders/FlowMapPainter.shader.meta
-
84com.unity.vfx-toolbox/Workbench/Editor/Tools/Shaders/NoiseGen.shader
-
9com.unity.vfx-toolbox/Workbench/Editor/Tools/Shaders/NoiseGen.shader.meta
-
141com.unity.vfx-toolbox/Workbench/Editor/Tools/Shaders/SimplexNoise2D.hlsl
-
9com.unity.vfx-toolbox/Workbench/Editor/Tools/Shaders/SimplexNoise2D.hlsl.meta
-
347com.unity.vfx-toolbox/Workbench/Editor/Workbench.cs
-
12com.unity.vfx-toolbox/Workbench/Editor/Workbench.cs.meta
-
12com.unity.vfx-toolbox/Workbench/Editor/WorkbenchBehaviour.cs
-
11com.unity.vfx-toolbox/Workbench/Editor/WorkbenchBehaviour.cs.meta
-
109com.unity.vfx-toolbox/Workbench/Editor/WorkbenchBehaviourFactory.cs
-
12com.unity.vfx-toolbox/Workbench/Editor/WorkbenchBehaviourFactory.cs.meta
-
57com.unity.vfx-toolbox/Workbench/Editor/WorkbenchImageCanvas.cs
-
12com.unity.vfx-toolbox/Workbench/Editor/WorkbenchImageCanvas.cs.meta
-
96com.unity.vfx-toolbox/Workbench/Editor/WorkbenchInspector.cs
-
12com.unity.vfx-toolbox/Workbench/Editor/WorkbenchInspector.cs.meta
-
52com.unity.vfx-toolbox/Workbench/Editor/WorkbenchToolBase.cs
-
12com.unity.vfx-toolbox/Workbench/Editor/WorkbenchToolBase.cs.meta
|
|||
fileFormatVersion: 2 |
|||
guid: fbf88505ce95fd34cb1edd3c6d1b50df |
|||
folderAsset: yes |
|||
timeCreated: 1474993084 |
|||
licenseType: Pro |
|||
DefaultImporter: |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: a6397eefc2394054db92a3063525d907 |
|||
folderAsset: yes |
|||
timeCreated: 1474993084 |
|||
licenseType: Pro |
|||
DefaultImporter: |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: 75ddedcf6bdee724ea02a1bc5752673a |
|||
folderAsset: yes |
|||
timeCreated: 1478089189 |
|||
licenseType: Pro |
|||
DefaultImporter: |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Reflection; |
|||
using UnityEngine; |
|||
|
|||
namespace UnityEditor.VFXToolbox.Workbench |
|||
{ |
|||
public class FlowPaintBrush : PaintBrush |
|||
{ |
|||
[Range(0.0f,10.0f)] |
|||
public float MotionIntensity; |
|||
[Range(-1.0f,1.0f)] |
|||
public float TextureIntensity; |
|||
|
|||
public override void Default() |
|||
{ |
|||
base.Default(); |
|||
MotionIntensity = 1.0f; |
|||
TextureIntensity = 1.0f; |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 87047c08dd06ff44898d5c3b2524204c |
|||
timeCreated: 1478089190 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: 8310290e841f45748aa4ea6bbac0401b |
|||
folderAsset: yes |
|||
DefaultImporter: |
|||
externalObjects: {} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: 6c401c5fa1280db41954ee940b8e8d24 |
|||
timeCreated: 1478256801 |
|||
licenseType: Pro |
|||
TextureImporter: |
|||
fileIDToRecycleName: {} |
|||
serializedVersion: 4 |
|||
mipmaps: |
|||
mipMapMode: 0 |
|||
enableMipMap: 0 |
|||
sRGBTexture: 0 |
|||
linearTexture: 0 |
|||
fadeOut: 0 |
|||
borderMipMap: 0 |
|||
mipMapFadeDistanceStart: 1 |
|||
mipMapFadeDistanceEnd: 3 |
|||
bumpmap: |
|||
convertToNormalMap: 0 |
|||
externalNormalMap: 0 |
|||
heightScale: 0.25 |
|||
normalMapFilter: 0 |
|||
isReadable: 0 |
|||
grayScaleToAlpha: 0 |
|||
generateCubemap: 6 |
|||
cubemapConvolution: 0 |
|||
seamlessCubemap: 0 |
|||
textureFormat: 1 |
|||
maxTextureSize: 2048 |
|||
textureSettings: |
|||
filterMode: -1 |
|||
aniso: 1 |
|||
mipBias: -1 |
|||
wrapMode: 1 |
|||
nPOTScale: 0 |
|||
lightmap: 0 |
|||
compressionQuality: 50 |
|||
spriteMode: 0 |
|||
spriteExtrude: 1 |
|||
spriteMeshType: 1 |
|||
alignment: 0 |
|||
spritePivot: {x: 0.5, y: 0.5} |
|||
spriteBorder: {x: 0, y: 0, z: 0, w: 0} |
|||
spritePixelsToUnits: 100 |
|||
alphaUsage: 1 |
|||
alphaIsTransparency: 1 |
|||
spriteTessellationDetail: -1 |
|||
textureType: 2 |
|||
textureShape: 1 |
|||
maxTextureSizeSet: 0 |
|||
compressionQualitySet: 0 |
|||
textureFormatSet: 0 |
|||
platformSettings: |
|||
- buildTarget: DefaultTexturePlatform |
|||
maxTextureSize: 2048 |
|||
textureFormat: -1 |
|||
textureCompression: 1 |
|||
compressionQuality: 50 |
|||
crunchedCompression: 0 |
|||
allowsAlphaSplitting: 0 |
|||
overridden: 0 |
|||
- buildTarget: Standalone |
|||
maxTextureSize: 2048 |
|||
textureFormat: -1 |
|||
textureCompression: 1 |
|||
compressionQuality: 50 |
|||
crunchedCompression: 0 |
|||
allowsAlphaSplitting: 0 |
|||
overridden: 0 |
|||
spriteSheet: |
|||
serializedVersion: 2 |
|||
sprites: [] |
|||
outline: [] |
|||
spritePackingTag: |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: 07dc82adf399fc0408633eace96835a4 |
|||
timeCreated: 1478255007 |
|||
licenseType: Pro |
|||
TextureImporter: |
|||
fileIDToRecycleName: {} |
|||
serializedVersion: 4 |
|||
mipmaps: |
|||
mipMapMode: 0 |
|||
enableMipMap: 0 |
|||
sRGBTexture: 0 |
|||
linearTexture: 0 |
|||
fadeOut: 0 |
|||
borderMipMap: 0 |
|||
mipMapFadeDistanceStart: 1 |
|||
mipMapFadeDistanceEnd: 3 |
|||
bumpmap: |
|||
convertToNormalMap: 0 |
|||
externalNormalMap: 0 |
|||
heightScale: 0.25 |
|||
normalMapFilter: 0 |
|||
isReadable: 0 |
|||
grayScaleToAlpha: 0 |
|||
generateCubemap: 6 |
|||
cubemapConvolution: 0 |
|||
seamlessCubemap: 0 |
|||
textureFormat: 1 |
|||
maxTextureSize: 2048 |
|||
textureSettings: |
|||
filterMode: -1 |
|||
aniso: 1 |
|||
mipBias: -1 |
|||
wrapMode: 1 |
|||
nPOTScale: 0 |
|||
lightmap: 0 |
|||
compressionQuality: 50 |
|||
spriteMode: 0 |
|||
spriteExtrude: 1 |
|||
spriteMeshType: 1 |
|||
alignment: 0 |
|||
spritePivot: {x: 0.5, y: 0.5} |
|||
spriteBorder: {x: 0, y: 0, z: 0, w: 0} |
|||
spritePixelsToUnits: 100 |
|||
alphaUsage: 1 |
|||
alphaIsTransparency: 1 |
|||
spriteTessellationDetail: -1 |
|||
textureType: 2 |
|||
textureShape: 1 |
|||
maxTextureSizeSet: 0 |
|||
compressionQualitySet: 0 |
|||
textureFormatSet: 0 |
|||
platformSettings: |
|||
- buildTarget: DefaultTexturePlatform |
|||
maxTextureSize: 2048 |
|||
textureFormat: -1 |
|||
textureCompression: 1 |
|||
compressionQuality: 50 |
|||
crunchedCompression: 0 |
|||
allowsAlphaSplitting: 0 |
|||
overridden: 0 |
|||
- buildTarget: Standalone |
|||
maxTextureSize: 2048 |
|||
textureFormat: -1 |
|||
textureCompression: 1 |
|||
compressionQuality: 50 |
|||
crunchedCompression: 0 |
|||
allowsAlphaSplitting: 0 |
|||
overridden: 0 |
|||
spriteSheet: |
|||
serializedVersion: 2 |
|||
sprites: [] |
|||
outline: [] |
|||
spritePackingTag: |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Reflection; |
|||
using UnityEngine; |
|||
|
|||
namespace UnityEditor.VFXToolbox.Workbench |
|||
{ |
|||
public class PaintBrush : ScriptableObject |
|||
{ |
|||
public Texture2D Texture; |
|||
[Range(1.0f,512.0f)] |
|||
public float Size; |
|||
[Range(0.0f,5.0f)] |
|||
public float Opacity; |
|||
[Range(0.1f,1.0f)] |
|||
public float Spacing; |
|||
|
|||
public virtual void Default() |
|||
{ |
|||
Size = 4.0f; |
|||
Size = 64.0f; |
|||
Opacity = 0.5f; |
|||
Spacing = 0.1f; |
|||
} |
|||
|
|||
public virtual bool DrawBrushCanvasPreview(Vector2 screenPosition, float radius) |
|||
{ |
|||
Handles.DrawWireDisc(screenPosition, Vector3.forward, radius); |
|||
return true; |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 41097ee657bfb244a833b906464746d8 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {fileID: 2800000, guid: 6c401c5fa1280db41954ee940b8e8d24, type: 3} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Reflection; |
|||
using UnityEngine; |
|||
|
|||
namespace UnityEditor.VFXToolbox.Workbench |
|||
{ |
|||
public class PaintBrushCollection : ScriptableObject |
|||
{ |
|||
public PaintBrush[] Brushes; |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: ab08d8e3fc8ed3d418077bc76728360a |
|||
timeCreated: 1487582342 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Reflection; |
|||
using UnityEngine; |
|||
|
|||
namespace UnityEditor.VFXToolbox.Workbench |
|||
{ |
|||
[CustomEditor(typeof(PaintBrushCollection))] |
|||
public class PaintBrushCollectionEditor : Editor |
|||
{ |
|||
SerializedProperty m_Brushes; |
|||
|
|||
UnityEngine.Object m_OjbectToAdd; |
|||
bool debug = false; |
|||
|
|||
public virtual void OnEnable() |
|||
{ |
|||
m_Brushes = serializedObject.FindProperty("Brushes"); |
|||
} |
|||
|
|||
public override void OnInspectorGUI() |
|||
{ |
|||
serializedObject.Update(); |
|||
|
|||
|
|||
|
|||
|
|||
debug = EditorGUILayout.Toggle(VFXToolboxGUIUtility.Get("Debug"), debug); |
|||
if (debug) |
|||
OnDebugInspectorGUI(); |
|||
|
|||
serializedObject.ApplyModifiedProperties(); |
|||
|
|||
|
|||
|
|||
|
|||
} |
|||
|
|||
#region TODELETE
|
|||
private void OnDebugInspectorGUI() |
|||
{ |
|||
int count = m_Brushes.arraySize; |
|||
int todelete = -1; |
|||
for(int i = 0; i < count; i++) |
|||
{ |
|||
using(new GUILayout.HorizontalScope()) |
|||
{ |
|||
EditorGUILayout.ObjectField(m_Brushes.GetArrayElementAtIndex(i)); |
|||
if(GUILayout.Button(VFXToolboxGUIUtility.Get("-"),GUILayout.Width(24))) |
|||
{ |
|||
todelete = i; |
|||
} |
|||
} |
|||
} |
|||
|
|||
if (todelete >= 0) |
|||
{ |
|||
// Twice... seriously...
|
|||
m_Brushes.DeleteArrayElementAtIndex(todelete); |
|||
m_Brushes.DeleteArrayElementAtIndex(todelete); |
|||
|
|||
} |
|||
|
|||
|
|||
EditorGUILayout.Space(); |
|||
|
|||
using(new GUILayout.HorizontalScope()) |
|||
{ |
|||
m_OjbectToAdd = EditorGUILayout.ObjectField(VFXToolboxGUIUtility.Get("Brush to Add"), m_OjbectToAdd, typeof(PaintBrush),false); |
|||
if(GUILayout.Button(VFXToolboxGUIUtility.Get("+"),GUILayout.Width(24))) |
|||
{ |
|||
m_Brushes.InsertArrayElementAtIndex(count); |
|||
m_Brushes.GetArrayElementAtIndex(count).objectReferenceValue = m_OjbectToAdd; |
|||
m_OjbectToAdd = null; |
|||
} |
|||
} |
|||
} |
|||
#endregion
|
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 2c24df5002c6aa649913648f695dfffe |
|||
timeCreated: 1487582449 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Reflection; |
|||
using UnityEngine; |
|||
|
|||
namespace UnityEditor.VFXToolbox.Workbench |
|||
{ |
|||
|
|||
[CustomEditor(typeof(FlowPaintBrush))] |
|||
public class FlowPaintBrushEditor : PaintBrushEditor |
|||
{ |
|||
|
|||
} |
|||
|
|||
[CustomEditor(typeof(PaintBrush))] |
|||
public class PaintBrushEditor : Editor |
|||
{ |
|||
SerializedProperty m_BrushTexture; |
|||
SerializedProperty m_BrushSize; |
|||
SerializedProperty m_BrushOpacity; |
|||
SerializedProperty m_BrushSpacing; |
|||
|
|||
public virtual void OnEnable() |
|||
{ |
|||
m_BrushTexture = serializedObject.FindProperty("Texture"); |
|||
m_BrushSize = serializedObject.FindProperty("Size"); |
|||
m_BrushOpacity = serializedObject.FindProperty("Opacity"); |
|||
m_BrushSpacing = serializedObject.FindProperty("Spacing"); |
|||
} |
|||
|
|||
public override void OnInspectorGUI() |
|||
{ |
|||
using (new GUILayout.HorizontalScope()) |
|||
{ |
|||
|
|||
Texture2D texture = m_BrushTexture.objectReferenceValue as Texture2D; |
|||
if(texture != null) |
|||
{ |
|||
GUILayout.FlexibleSpace(); |
|||
Rect r = GUILayoutUtility.GetRect(texture.width, texture.height); |
|||
GUILayout.FlexibleSpace(); |
|||
EditorGUI.DrawTextureTransparent(r, texture); |
|||
} |
|||
} |
|||
|
|||
EditorGUILayout.PropertyField(m_BrushSize); |
|||
EditorGUILayout.PropertyField(m_BrushOpacity); |
|||
EditorGUILayout.PropertyField(m_BrushSpacing); |
|||
|
|||
base.OnInspectorGUI(); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 665712b16804202499864e9aaa00828f |
|||
timeCreated: 1478191603 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System.Collections; |
|||
using System.Collections.Generic; |
|||
using UnityEngine; |
|||
using System; |
|||
|
|||
namespace UnityEditor.VFXToolbox.Workbench |
|||
{ |
|||
public class PaintBrushUtility |
|||
{ |
|||
public static PaintBrush[] paintBrushes |
|||
{ |
|||
get { if (s_CachedPaintBrushes == null) UpdatePaintBrushes(); return s_CachedPaintBrushes; } |
|||
} |
|||
private static PaintBrush[] s_CachedPaintBrushes; |
|||
|
|||
public static void UpdatePaintBrushes() |
|||
{ |
|||
List<PaintBrush> brushes = new List<PaintBrush>(); |
|||
var guids = AssetDatabase.FindAssets("t:PaintBrush"); |
|||
foreach(string guid in guids) |
|||
{ |
|||
brushes.Add(AssetDatabase.LoadAssetAtPath<PaintBrush>(AssetDatabase.GUIDToAssetPath(guid))); |
|||
} |
|||
s_CachedPaintBrushes = brushes.ToArray(); |
|||
} |
|||
|
|||
public class BrushListEditor |
|||
{ |
|||
public PaintBrush selectedBrush; |
|||
public Type m_FilteredType; |
|||
private PaintBrush[] m_CachedBrushes; |
|||
private Vector2 m_ScrollData = new Vector2(0,0); |
|||
public BrushListEditor(Type filteredType) |
|||
{ |
|||
m_FilteredType = filteredType; |
|||
selectedBrush = null; |
|||
CacheBrushes(); |
|||
} |
|||
|
|||
public void UpdatePaintBrushes() |
|||
{ |
|||
PaintBrushUtility.UpdatePaintBrushes(); |
|||
CacheBrushes(); |
|||
} |
|||
|
|||
private void CacheBrushes() |
|||
{ |
|||
List<PaintBrush> filtered = new List<PaintBrush>(); |
|||
|
|||
foreach(PaintBrush brush in PaintBrushUtility.paintBrushes) |
|||
{ |
|||
if (brush.GetType() == m_FilteredType) |
|||
filtered.Add(brush); |
|||
} |
|||
|
|||
m_CachedBrushes = filtered.ToArray(); |
|||
} |
|||
|
|||
public void DoGUILayout() |
|||
{ |
|||
if (m_CachedBrushes == null) |
|||
CacheBrushes(); |
|||
|
|||
using (new EditorGUILayout.ScrollViewScope(m_ScrollData,false,false)) |
|||
{ |
|||
foreach (PaintBrush brush in m_CachedBrushes) |
|||
{ |
|||
|
|||
} |
|||
} |
|||
|
|||
|
|||
|
|||
} |
|||
} |
|||
|
|||
} |
|||
} |
|||
|
|||
|
|
|||
fileFormatVersion: 2 |
|||
guid: 4318f3e3e8611b5448b5e86a0efe090b |
|||
timeCreated: 1485781372 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Reflection; |
|||
using UnityEngine; |
|||
|
|||
namespace UnityEditor.VFXToolbox.Workbench |
|||
{ |
|||
public class PaintBuffer : ScriptableObject |
|||
{ |
|||
public int Width; |
|||
public int Height; |
|||
public Color[] data; |
|||
|
|||
public void FromRenderTexture(RenderTexture texture) |
|||
{ |
|||
if(Width != texture.width || Height != texture.height) |
|||
{ |
|||
Width = texture.width; |
|||
Height = texture.height; |
|||
data = VFXToolboxUtility.ReadBack(texture); |
|||
} |
|||
else |
|||
{ |
|||
Color[] newdata = VFXToolboxUtility.ReadBack(texture); |
|||
for (int i = 0; i < data.Length; i++) |
|||
{ |
|||
data[i] = newdata[i]; |
|||
} |
|||
} |
|||
|
|||
} |
|||
|
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 4c8b6631f582a884c866ce833982ac0a |
|||
timeCreated: 1475831964 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: 3c9db1ce737f20e43be09224b3ecf0af |
|||
folderAsset: yes |
|||
timeCreated: 1475162029 |
|||
licenseType: Pro |
|||
DefaultImporter: |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System; |
|||
using System.Collections.Generic; |
|||
using UnityEngine; |
|||
using UnityEditor.VFXToolbox; |
|||
|
|||
namespace UnityEditor.VFXToolbox.Workbench |
|||
{ |
|||
public class FlowMapPainter : WorkbenchToolBase |
|||
{ |
|||
[MenuItem("Assets/Create/Visual Effects/Workbench/FlowMap Painter", priority = 301)] |
|||
private static void MenuCreateAsset() |
|||
{ |
|||
WorkbenchBehaviourFactory.CreateWorkbenchAsset("New FlowMap", CreateInstance<FlowMapPainter>()); |
|||
} |
|||
|
|||
// Serializable
|
|||
public int PaintDataWidth; |
|||
public int PaintDataHeight; |
|||
public PaintBuffer PaintData; |
|||
public FlowPaintBrush Brush; |
|||
|
|||
public FlowMapPainterViewMode ViewMode; |
|||
public Texture2D PreviewTexture; |
|||
|
|||
[Range(0.0f,5.0f)] |
|||
public float PreviewIntensity; |
|||
[Range(1.0f,15.0f)] |
|||
public float PreviewCycleDuration; |
|||
[Range(0.1f,15.0f)] |
|||
public float PreviewTile; |
|||
|
|||
// Runtime
|
|||
private RenderTexture m_RenderTexture; |
|||
private RenderTexture m_PreviewRT; |
|||
private Material m_Material; |
|||
private Material m_PreviewMaterial; |
|||
|
|||
private SerializedObject m_Object; |
|||
|
|||
private SerializedProperty m_Width; |
|||
private SerializedProperty m_Height; |
|||
|
|||
private SerializedProperty m_Brush; |
|||
private SerializedProperty m_BrushTexture; |
|||
private SerializedProperty m_BrushMotionIntensity; |
|||
private SerializedProperty m_BrushTextureIntensity; |
|||
private SerializedProperty m_BrushSize; |
|||
private SerializedProperty m_BrushOpacity; |
|||
private SerializedProperty m_BrushSpacing; |
|||
|
|||
private SerializedProperty m_ViewMode; |
|||
private SerializedProperty m_PreviewTexture; |
|||
private SerializedProperty m_PreviewIntensity; |
|||
private SerializedProperty m_PreviewCycleDuration; |
|||
private SerializedProperty m_PreviewTile; |
|||
|
|||
private Vector2 m_PrevBrushPos; |
|||
private Vector2 m_PrevBrushDirection; |
|||
|
|||
public enum FlowMapPainterViewMode |
|||
{ |
|||
Texture = 0, |
|||
Flow = 1 |
|||
} |
|||
|
|||
public void OnEnable() |
|||
{ |
|||
m_Object = new SerializedObject(this); |
|||
m_Width = m_Object.FindProperty("PaintDataWidth"); |
|||
m_Height = m_Object.FindProperty("PaintDataHeight"); |
|||
|
|||
m_Brush = m_Object.FindProperty("Brush"); |
|||
|
|||
m_ViewMode = m_Object.FindProperty("ViewMode"); |
|||
m_PreviewTexture = m_Object.FindProperty("PreviewTexture"); |
|||
m_PreviewIntensity = m_Object.FindProperty("PreviewIntensity"); |
|||
m_PreviewCycleDuration = m_Object.FindProperty("PreviewCycleDuration"); |
|||
m_PreviewTile = m_Object.FindProperty("PreviewTile"); |
|||
} |
|||
|
|||
public override bool OnInspectorGUI() |
|||
{ |
|||
bool bchanged = false; |
|||
m_Object.Update(); |
|||
EditorGUI.BeginChangeCheck(); |
|||
|
|||
VFXToolboxGUIUtility.ToggleableHeader(true, false, "Output Image Options"); |
|||
EditorGUILayout.PropertyField(m_Width); |
|||
EditorGUILayout.PropertyField(m_Height); |
|||
|
|||
VFXToolboxGUIUtility.ToggleableHeader(true, false, "Brush Options"); |
|||
EditorGUILayout.PropertyField(m_Brush); |
|||
|
|||
|
|||
VFXToolboxGUIUtility.ToggleableHeader(true, false, "Preview Options"); |
|||
EditorGUILayout.PropertyField(m_ViewMode); |
|||
|
|||
if(ViewMode == FlowMapPainterViewMode.Flow) |
|||
{ |
|||
EditorGUILayout.PropertyField(m_PreviewTexture); |
|||
EditorGUILayout.PropertyField(m_PreviewIntensity); |
|||
EditorGUILayout.PropertyField(m_PreviewCycleDuration); |
|||
EditorGUILayout.PropertyField(m_PreviewTile); |
|||
} |
|||
|
|||
|
|||
if (EditorGUI.EndChangeCheck()) |
|||
{ |
|||
bchanged = true; |
|||
} |
|||
|
|||
m_Object.ApplyModifiedProperties(); |
|||
|
|||
if(bchanged) |
|||
{ |
|||
UpdateRenderTarget(); |
|||
UpdatePaintData(); |
|||
} |
|||
|
|||
return bchanged; |
|||
} |
|||
|
|||
public override void Default(WorkbenchBehaviour asset) |
|||
{ |
|||
base.Default(asset); |
|||
PaintDataWidth = 256; |
|||
PaintDataHeight = 256; |
|||
ViewMode = FlowMapPainterViewMode.Texture; |
|||
PreviewIntensity = 0.2f; |
|||
PreviewCycleDuration = 2.0f; |
|||
PreviewTile = 4.0f; |
|||
} |
|||
|
|||
public void UpdatePaintData() |
|||
{ |
|||
if (PaintData == null) |
|||
{ |
|||
PaintData = CreateInstance<PaintBuffer>(); |
|||
PaintData.hideFlags = HideFlags.HideInHierarchy; |
|||
AssetDatabase.AddObjectToAsset(PaintData, this); |
|||
UpdateRenderTarget(); |
|||
Clear(); |
|||
SavePaintData(); |
|||
EditorUtility.SetDirty(this); |
|||
AssetDatabase.SaveAssets(); |
|||
} |
|||
else if(PaintData.Width != PaintDataWidth || PaintData.Height != PaintDataHeight) |
|||
{ |
|||
PaintData.FromRenderTexture(m_RenderTexture); |
|||
EditorUtility.SetDirty(this); |
|||
} |
|||
} |
|||
|
|||
public void UpdateRenderTarget() |
|||
{ |
|||
if (m_RenderTexture.width != PaintDataWidth || m_RenderTexture.height != PaintDataHeight) |
|||
{ |
|||
RenderTexture newRT = RenderTexture.GetTemporary(PaintDataWidth, PaintDataHeight, 0, RenderTextureFormat.ARGB32, RenderTextureReadWrite.Linear); |
|||
RenderTexture.ReleaseTemporary(m_RenderTexture); |
|||
m_RenderTexture = newRT; |
|||
Clear(); |
|||
} |
|||
} |
|||
|
|||
public override void Initialize() |
|||
{ |
|||
m_RenderTexture = RenderTexture.GetTemporary(PaintDataWidth, PaintDataHeight, 0, RenderTextureFormat.ARGB32, RenderTextureReadWrite.Linear); |
|||
m_Material = new Material(Shader.Find("VFXToolbox/ImageScripter/FlowMapPaint")); |
|||
if (PaintData != null) |
|||
{ |
|||
Texture2D temp = new Texture2D(PaintDataWidth, PaintDataHeight, TextureFormat.ARGB32, false, true); |
|||
temp.SetPixels(PaintData.data); |
|||
temp.Apply(); |
|||
Graphics.Blit(temp, m_RenderTexture); |
|||
} |
|||
else |
|||
{ |
|||
Clear(); |
|||
UpdatePaintData(); |
|||
SavePaintData(); |
|||
} |
|||
} |
|||
|
|||
private void SavePaintData() |
|||
{ |
|||
PaintData.FromRenderTexture(m_RenderTexture); |
|||
EditorUtility.SetDirty(PaintData); |
|||
} |
|||
|
|||
private void Clear() |
|||
{ |
|||
RenderTexture backup = RenderTexture.active; |
|||
RenderTexture.active = m_RenderTexture; |
|||
GL.Clear(false, true, new Color(0.5f, 0.5f, 0.0f, 1.0f)); |
|||
RenderTexture.active = backup; |
|||
} |
|||
|
|||
public override void Dispose() |
|||
{ |
|||
RenderTexture.ReleaseTemporary(m_RenderTexture); |
|||
} |
|||
|
|||
public override void Update() |
|||
{ |
|||
UpdateRenderTarget(); |
|||
} |
|||
|
|||
public override bool OnCanvasGUI(WorkbenchImageCanvas canvas) |
|||
{ |
|||
bool needRepaint = false; |
|||
|
|||
if(Event.current.type == EventType.Repaint) |
|||
{ |
|||
if(ViewMode == FlowMapPainterViewMode.Flow) |
|||
{ |
|||
if (m_PreviewRT == null) |
|||
m_PreviewRT = RenderTexture.GetTemporary(PaintDataWidth, PaintDataHeight, 0, RenderTextureFormat.ARGB32); |
|||
|
|||
if(m_PreviewRT.width != PaintDataWidth || m_PreviewRT.height != PaintDataHeight) |
|||
{ |
|||
RenderTexture.ReleaseTemporary(m_PreviewRT); |
|||
m_PreviewRT = RenderTexture.GetTemporary(PaintDataWidth, PaintDataHeight, 0, RenderTextureFormat.ARGB32); |
|||
} |
|||
if (m_PreviewMaterial == null) |
|||
m_PreviewMaterial = new Material(Shader.Find("VFXToolbox/ImageScripter/FlowMapPainter.DisplayFlow")); |
|||
|
|||
m_PreviewMaterial.SetTexture("_MainTex", PreviewTexture); |
|||
m_PreviewMaterial.SetTexture("_FlowTex", m_RenderTexture); |
|||
m_PreviewMaterial.SetFloat("_EdTime", (float)(EditorApplication.timeSinceStartup%PreviewCycleDuration)); |
|||
m_PreviewMaterial.SetFloat("_Intensity", PreviewIntensity); |
|||
m_PreviewMaterial.SetFloat("_Cycle", PreviewCycleDuration); |
|||
m_PreviewMaterial.SetFloat("_Tile", PreviewTile); |
|||
|
|||
RenderTexture bkp = RenderTexture.active; |
|||
RenderTexture.active = m_PreviewRT; |
|||
|
|||
#if !UNITY_2018_2_OR_NEWER
|
|||
GL.sRGBWrite = QualitySettings.activeColorSpace == ColorSpace.Linear; |
|||
#endif
|
|||
Graphics.Blit(PreviewTexture, m_PreviewRT, m_PreviewMaterial); |
|||
|
|||
#if !UNITY_2018_2_OR_NEWER
|
|||
GL.sRGBWrite = false; |
|||
#endif
|
|||
RenderTexture.active = bkp; |
|||
|
|||
canvas.texture = m_PreviewRT; |
|||
needRepaint = true; |
|||
} |
|||
else |
|||
{ |
|||
canvas.texture = m_RenderTexture; |
|||
} |
|||
} |
|||
|
|||
Vector2 TopLeft = canvas.CanvasToScreen(new Vector2(m_RenderTexture.width / 2, m_RenderTexture.height / 2)); |
|||
Vector2 BottomRight = canvas.CanvasToScreen(new Vector2(-m_RenderTexture.width / 2, -m_RenderTexture.height / 2)); |
|||
|
|||
if (Brush != null) |
|||
{ |
|||
if ((Event.current.type == EventType.MouseDown || Event.current.type == EventType.MouseDrag) && Event.current.button == 0) |
|||
{ |
|||
Vector2 localMousePos = Event.current.mousePosition; |
|||
Vector2 brushPos = new Vector2((localMousePos.x - TopLeft.x) / (BottomRight.x - TopLeft.x), (localMousePos.y - TopLeft.y) / (BottomRight.y - TopLeft.y)); |
|||
|
|||
if (Event.current.type == EventType.MouseDown) |
|||
{ |
|||
m_PrevBrushPos = brushPos; |
|||
m_PrevBrushDirection = Vector2.zero; |
|||
} |
|||
|
|||
Vector2 pos = brushPos; |
|||
pos.Scale(new Vector2(m_RenderTexture.width, m_RenderTexture.height)); |
|||
|
|||
Vector2 brushDirection = (brushPos - m_PrevBrushPos) * Brush.MotionIntensity; |
|||
|
|||
PaintSegment(brushPos, m_PrevBrushPos, brushDirection, m_PrevBrushDirection); |
|||
m_PrevBrushPos = brushPos; |
|||
m_PrevBrushDirection = brushDirection; |
|||
|
|||
} |
|||
else if (Event.current.type == EventType.MouseUp) |
|||
{ |
|||
Undo.RegisterCompleteObjectUndo(PaintData, "Paint"); |
|||
UpdatePaintData(); |
|||
SavePaintData(); |
|||
} |
|||
|
|||
needRepaint |= Brush.DrawBrushCanvasPreview(Event.current.mousePosition, Brush.Size * canvas.zoom * 0.5f); |
|||
} |
|||
|
|||
return needRepaint; |
|||
} |
|||
|
|||
public void PaintSegment(Vector2 position, Vector2 prevPosition, Vector2 direction, Vector2 prevDirection) |
|||
{ |
|||
Vector2 size = new Vector2(PaintDataWidth, PaintDataHeight); |
|||
|
|||
Vector2 absPosition = position; |
|||
Vector2 absPrevPosition = prevPosition; |
|||
absPosition.Scale(size); |
|||
absPrevPosition.Scale(size); |
|||
|
|||
float dist = Vector2.Distance(absPosition, absPrevPosition); |
|||
float space = Brush.Spacing * Brush.Size * 0.5f; |
|||
int n = (int)Mathf.Floor(dist/space) + 2; |
|||
|
|||
m_Material.SetTexture("_MainTex", Brush.Texture); |
|||
m_Material.SetFloat("_BrushOpacity", Brush.Opacity); |
|||
|
|||
for(int i = 0; i < n; i++) |
|||
{ |
|||
float t = (float)(i) / (float)(n-1); |
|||
Vector2 curPos = Vector2.Lerp(prevPosition, position, t); |
|||
Vector2 curDir = Vector2.Lerp(prevDirection, direction, t); |
|||
curPos.Scale(size); |
|||
m_Material.SetVector("_Direction", curDir); |
|||
VFXToolboxUtility.BlitRect(new Rect(curPos.x - Brush.Size / 2, curPos.y - Brush.Size / 2, Brush.Size, Brush.Size), m_RenderTexture, Brush.Texture, m_Material); |
|||
} |
|||
} |
|||
|
|||
public static string GetCategory() |
|||
{ return "Flow Tools"; } |
|||
public static string GetName() |
|||
{ return "FlowMap Painter"; } |
|||
|
|||
|
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 113448613266bc94fbecb0f2c3df5ee3 |
|||
timeCreated: 1475508594 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System.Collections; |
|||
using System.Collections.Generic; |
|||
using UnityEngine; |
|||
using UnityEditor.VFXToolbox; |
|||
using System; |
|||
|
|||
namespace UnityEditor.VFXToolbox.Workbench |
|||
{ |
|||
public class NoiseGenerator : WorkbenchToolBase |
|||
{ |
|||
[MenuItem("Assets/Create/Visual Effects/Workbench/Noise Generator", priority = 301)] |
|||
private static void MenuCreateAsset() |
|||
{ |
|||
WorkbenchBehaviourFactory.CreateWorkbenchAsset("New Noise Generator", CreateInstance<NoiseGenerator>()); |
|||
} |
|||
// Serializable
|
|||
public int Width; |
|||
public int Height; |
|||
public int Depth; |
|||
public float Phase; |
|||
|
|||
// Runtime
|
|||
private RenderTexture m_RenderTexture; |
|||
private Material m_Material; |
|||
|
|||
// Serialziation
|
|||
private SerializedObject m_Object; |
|||
private SerializedProperty m_Width; |
|||
private SerializedProperty m_Height; |
|||
private SerializedProperty m_Depth; |
|||
private SerializedProperty m_Phase; |
|||
|
|||
public void OnEnable() |
|||
{ |
|||
m_Object = new SerializedObject(this); |
|||
m_Width = m_Object.FindProperty("Width"); |
|||
m_Height = m_Object.FindProperty("Height"); |
|||
m_Depth = m_Object.FindProperty("Depth"); |
|||
m_Phase = m_Object.FindProperty("Phase"); |
|||
} |
|||
|
|||
public override void Dispose() |
|||
{ |
|||
RenderTexture.ReleaseTemporary(m_RenderTexture); |
|||
} |
|||
|
|||
public override void Default(WorkbenchBehaviour asset) |
|||
{ |
|||
base.Default(asset); |
|||
Width = 256; |
|||
Height = 256; |
|||
Depth = 5; |
|||
Phase = 0.0f; |
|||
} |
|||
|
|||
public void UpdateRenderTarget() |
|||
{ |
|||
if (m_RenderTexture.width != Width || m_RenderTexture.height != Height) |
|||
{ |
|||
RenderTexture newRT = RenderTexture.GetTemporary(Width, Height, 0, RenderTextureFormat.ARGB32, RenderTextureReadWrite.Linear); |
|||
RenderTexture.ReleaseTemporary(m_RenderTexture); |
|||
m_RenderTexture = newRT; |
|||
Clear(); |
|||
} |
|||
} |
|||
|
|||
private void Clear() |
|||
{ |
|||
RenderTexture backup = RenderTexture.active; |
|||
RenderTexture.active = m_RenderTexture; |
|||
GL.Clear(false, true, new Color(0.5f, 0.0f, 0.5f, 1.0f)); |
|||
RenderTexture.active = backup; |
|||
} |
|||
|
|||
public override void Initialize() |
|||
{ |
|||
m_RenderTexture = RenderTexture.GetTemporary(Width, Height, 0, RenderTextureFormat.ARGB32, RenderTextureReadWrite.Linear); |
|||
m_Material = new Material(Shader.Find("VFXToolbox/ImageScripter/NoiseGen")); |
|||
} |
|||
|
|||
public override bool OnCanvasGUI(WorkbenchImageCanvas canvas) |
|||
{ |
|||
canvas.texture = m_RenderTexture; |
|||
return false; |
|||
} |
|||
|
|||
public override bool OnInspectorGUI() |
|||
{ |
|||
bool changed = false; |
|||
m_Object.Update(); |
|||
EditorGUI.BeginChangeCheck(); |
|||
|
|||
EditorGUILayout.PropertyField(m_Width); |
|||
EditorGUILayout.PropertyField(m_Height); |
|||
EditorGUILayout.IntSlider(m_Depth, 1, 7); |
|||
EditorGUILayout.Slider(m_Phase, 0.0f, 50.0f); |
|||
if (EditorGUI.EndChangeCheck()) |
|||
{ |
|||
changed = true; |
|||
} |
|||
|
|||
m_Object.ApplyModifiedProperties(); |
|||
|
|||
if (changed) |
|||
{ |
|||
UpdateRenderTarget(); |
|||
Update(); |
|||
return true; |
|||
} |
|||
|
|||
return false; |
|||
} |
|||
|
|||
public override void Update() |
|||
{ |
|||
m_Material.SetInt("_depth", Depth); |
|||
m_Material.SetInt("_width", Width); |
|||
m_Material.SetInt("_height", Height); |
|||
m_Material.SetFloat("_phase", Phase); |
|||
|
|||
RenderTexture bkp = RenderTexture.active; |
|||
RenderTexture.active = m_RenderTexture; |
|||
|
|||
#if !UNITY_2018_2_OR_NEWER
|
|||
GL.sRGBWrite = QualitySettings.activeColorSpace == ColorSpace.Linear; |
|||
#endif
|
|||
|
|||
Graphics.Blit(null, m_RenderTexture, m_Material); |
|||
|
|||
#if !UNITY_2018_2_OR_NEWER
|
|||
GL.sRGBWrite = false; |
|||
#endif
|
|||
RenderTexture.active = bkp; |
|||
} |
|||
|
|||
public static string GetCategory() |
|||
{ return "Misc"; } |
|||
public static string GetName() |
|||
{ return "Noise Generator"; } |
|||
|
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 66be5224f82721c40acad262eb78721b |
|||
timeCreated: 1488290315 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System; |
|||
using System.Collections.Generic; |
|||
using UnityEngine; |
|||
using UnityEditor.VFXToolbox; |
|||
|
|||
namespace UnityEditor.VFXToolbox.Workbench |
|||
{ |
|||
public class ProgressionMapGenerator : WorkbenchToolBase |
|||
{ |
|||
// Serializable
|
|||
public int PaintDataWidth; |
|||
public int PaintDataHeight; |
|||
public PaintBuffer PaintData; |
|||
|
|||
public FlowPaintBrush Brush; |
|||
|
|||
public ViewMode PreviewMode; |
|||
public Texture2D BaseTexture; |
|||
public Texture2D FinalTexture; |
|||
|
|||
[Range(0.0f,5.0f)] |
|||
public float PreviewIntensity; |
|||
[Range(1.0f,15.0f)] |
|||
public float PreviewCycleDuration; |
|||
[Range(0.1f,15.0f)] |
|||
public float PreviewTile; |
|||
|
|||
// Runtime
|
|||
private RenderTexture m_RenderTexture; |
|||
private RenderTexture m_PreviewRT; |
|||
private Material m_Material; |
|||
private Material m_PreviewMaterial; |
|||
|
|||
private SerializedObject m_Object; |
|||
|
|||
private SerializedProperty m_Width; |
|||
private SerializedProperty m_Height; |
|||
|
|||
private SerializedProperty m_Brush; |
|||
private SerializedProperty m_BrushTexture; |
|||
private SerializedProperty m_BrushMotionIntensity; |
|||
private SerializedProperty m_BrushTextureIntensity; |
|||
private SerializedProperty m_BrushSize; |
|||
private SerializedProperty m_BrushOpacity; |
|||
private SerializedProperty m_BrushSpacing; |
|||
|
|||
private SerializedProperty m_ViewMode; |
|||
private SerializedProperty m_BaseTexture; |
|||
private SerializedProperty m_FinalTexture; |
|||
|
|||
private SerializedProperty m_PreviewIntensity; |
|||
private SerializedProperty m_PreviewCycleDuration; |
|||
private SerializedProperty m_PreviewTile; |
|||
|
|||
private Vector2 m_PrevBrushPos; |
|||
private Vector2 m_PrevBrushDirection; |
|||
|
|||
public enum ViewMode |
|||
{ |
|||
BaseTexture = 0, |
|||
OutputProgressionMap = 1, |
|||
Animated = 2 |
|||
} |
|||
|
|||
public void OnEnable() |
|||
{ |
|||
m_Object = new SerializedObject(this); |
|||
m_Width = m_Object.FindProperty("PaintDataWidth"); |
|||
m_Height = m_Object.FindProperty("PaintDataHeight"); |
|||
|
|||
m_Brush = m_Object.FindProperty("Brush"); |
|||
|
|||
m_ViewMode = m_Object.FindProperty("PreviewMode"); |
|||
m_BaseTexture = m_Object.FindProperty("BaseTexture"); |
|||
m_FinalTexture = m_Object.FindProperty("FinalTexture"); |
|||
|
|||
m_PreviewIntensity = m_Object.FindProperty("PreviewIntensity"); |
|||
m_PreviewCycleDuration = m_Object.FindProperty("PreviewCycleDuration"); |
|||
m_PreviewTile = m_Object.FindProperty("PreviewTile"); |
|||
} |
|||
|
|||
public override bool OnInspectorGUI() |
|||
{ |
|||
bool bchanged = false; |
|||
m_Object.Update(); |
|||
EditorGUI.BeginChangeCheck(); |
|||
|
|||
using (new VFXToolboxGUIUtility.HeaderSectionScope("Output Image Options")) |
|||
{ |
|||
EditorGUILayout.PropertyField(m_Width); |
|||
EditorGUILayout.PropertyField(m_Height); |
|||
} |
|||
|
|||
using (new VFXToolboxGUIUtility.HeaderSectionScope("Output Image Options")) |
|||
{ |
|||
EditorGUILayout.PropertyField(m_Brush); |
|||
} |
|||
|
|||
using (new VFXToolboxGUIUtility.HeaderSectionScope("Output Image Options")) |
|||
{ |
|||
EditorGUILayout.PropertyField(m_ViewMode); |
|||
switch(PreviewMode) |
|||
{ |
|||
case ViewMode.BaseTexture: |
|||
EditorGUILayout.PropertyField(m_BaseTexture); |
|||
break; |
|||
case ViewMode.OutputProgressionMap: |
|||
|
|||
break; |
|||
case ViewMode.Animated: |
|||
EditorGUILayout.PropertyField(m_FinalTexture); |
|||
EditorGUILayout.PropertyField(m_PreviewIntensity); |
|||
EditorGUILayout.PropertyField(m_PreviewCycleDuration); |
|||
EditorGUILayout.PropertyField(m_PreviewTile); |
|||
break; |
|||
} |
|||
} |
|||
|
|||
if (EditorGUI.EndChangeCheck()) |
|||
{ |
|||
bchanged = true; |
|||
} |
|||
|
|||
m_Object.ApplyModifiedProperties(); |
|||
|
|||
if(bchanged) |
|||
{ |
|||
UpdateRenderTarget(); |
|||
UpdatePaintData(); |
|||
} |
|||
|
|||
return bchanged; |
|||
} |
|||
|
|||
public override void Default(WorkbenchBehaviour asset) |
|||
{ |
|||
base.Default(asset); |
|||
PaintDataWidth = 256; |
|||
PaintDataHeight = 256; |
|||
PreviewMode = ViewMode.BaseTexture; |
|||
PreviewIntensity = 0.2f; |
|||
PreviewCycleDuration = 2.0f; |
|||
PreviewTile = 4.0f; |
|||
} |
|||
|
|||
public void UpdatePaintData() |
|||
{ |
|||
if (PaintData == null) |
|||
{ |
|||
PaintData = CreateInstance<PaintBuffer>(); |
|||
PaintData.hideFlags = HideFlags.HideInHierarchy; |
|||
AssetDatabase.AddObjectToAsset(PaintData, this); |
|||
UpdateRenderTarget(); |
|||
Clear(); |
|||
SavePaintData(); |
|||
EditorUtility.SetDirty(this); |
|||
AssetDatabase.SaveAssets(); |
|||
} |
|||
else if(PaintData.Width != PaintDataWidth || PaintData.Height != PaintDataHeight) |
|||
{ |
|||
PaintData.FromRenderTexture(m_RenderTexture); |
|||
EditorUtility.SetDirty(this); |
|||
} |
|||
} |
|||
|
|||
public void UpdateRenderTarget() |
|||
{ |
|||
if (m_RenderTexture.width != PaintDataWidth || m_RenderTexture.height != PaintDataHeight) |
|||
{ |
|||
RenderTexture newRT = RenderTexture.GetTemporary(PaintDataWidth, PaintDataHeight, 0, RenderTextureFormat.ARGB32, RenderTextureReadWrite.Linear); |
|||
RenderTexture.ReleaseTemporary(m_RenderTexture); |
|||
m_RenderTexture = newRT; |
|||
Clear(); |
|||
} |
|||
} |
|||
|
|||
public override void Initialize() |
|||
{ |
|||
m_RenderTexture = RenderTexture.GetTemporary(PaintDataWidth, PaintDataHeight, 0, RenderTextureFormat.ARGB32, RenderTextureReadWrite.Linear); |
|||
m_Material = new Material(Shader.Find("VFXToolbox/ImageScripter/FlowMapPaint")); |
|||
if (PaintData != null) |
|||
{ |
|||
Texture2D temp = new Texture2D(PaintDataWidth, PaintDataHeight, TextureFormat.ARGB32, false, true); |
|||
temp.SetPixels(PaintData.data); |
|||
temp.Apply(); |
|||
Graphics.Blit(temp, m_RenderTexture); |
|||
} |
|||
else |
|||
{ |
|||
Clear(); |
|||
UpdatePaintData(); |
|||
SavePaintData(); |
|||
} |
|||
} |
|||
|
|||
private void SavePaintData() |
|||
{ |
|||
PaintData.FromRenderTexture(m_RenderTexture); |
|||
EditorUtility.SetDirty(PaintData); |
|||
} |
|||
|
|||
private void Clear() |
|||
{ |
|||
RenderTexture backup = RenderTexture.active; |
|||
RenderTexture.active = m_RenderTexture; |
|||
GL.Clear(false, true, new Color(0.5f, 0.5f, 0.0f, 1.0f)); |
|||
RenderTexture.active = backup; |
|||
} |
|||
|
|||
public override void Dispose() |
|||
{ |
|||
RenderTexture.ReleaseTemporary(m_RenderTexture); |
|||
} |
|||
|
|||
public override void Update() |
|||
{ |
|||
UpdateRenderTarget(); |
|||
} |
|||
|
|||
public override bool OnCanvasGUI(WorkbenchImageCanvas canvas) |
|||
{ |
|||
bool needRepaint = false; |
|||
|
|||
if(Event.current.type == EventType.Repaint) |
|||
{ |
|||
switch(PreviewMode) |
|||
{ |
|||
case ViewMode.BaseTexture: |
|||
canvas.texture = BaseTexture; |
|||
break; |
|||
case ViewMode.OutputProgressionMap: |
|||
canvas.texture = m_RenderTexture; |
|||
break; |
|||
case ViewMode.Animated: |
|||
|
|||
if (m_PreviewRT == null) |
|||
m_PreviewRT = RenderTexture.GetTemporary(PaintDataWidth, PaintDataHeight, 0, RenderTextureFormat.ARGB32); |
|||
|
|||
if(m_PreviewRT.width != PaintDataWidth || m_PreviewRT.height != PaintDataHeight) |
|||
{ |
|||
RenderTexture.ReleaseTemporary(m_PreviewRT); |
|||
m_PreviewRT = RenderTexture.GetTemporary(PaintDataWidth, PaintDataHeight, 0, RenderTextureFormat.ARGB32); |
|||
} |
|||
if (m_PreviewMaterial == null) |
|||
m_PreviewMaterial = new Material(Shader.Find("VFXToolbox/ImageScripter/FlowMapPainter.DisplayFlow")); |
|||
|
|||
m_PreviewMaterial.SetTexture("_MainTex", BaseTexture); |
|||
m_PreviewMaterial.SetTexture("_FlowTex", m_RenderTexture); |
|||
m_PreviewMaterial.SetFloat("_EdTime", (float)(EditorApplication.timeSinceStartup%PreviewCycleDuration)); |
|||
m_PreviewMaterial.SetFloat("_Intensity", PreviewIntensity); |
|||
m_PreviewMaterial.SetFloat("_Cycle", PreviewCycleDuration); |
|||
m_PreviewMaterial.SetFloat("_Tile", PreviewTile); |
|||
|
|||
RenderTexture bkp = RenderTexture.active; |
|||
RenderTexture.active = m_PreviewRT; |
|||
GL.sRGBWrite = QualitySettings.activeColorSpace == ColorSpace.Linear; |
|||
Graphics.Blit(BaseTexture, m_PreviewRT, m_PreviewMaterial); |
|||
GL.sRGBWrite = false; |
|||
RenderTexture.active = bkp; |
|||
|
|||
canvas.texture = m_PreviewRT; |
|||
needRepaint = true; |
|||
break; |
|||
} |
|||
} |
|||
|
|||
Vector2 TopLeft = canvas.CanvasToScreen(new Vector2(m_RenderTexture.width / 2, m_RenderTexture.height / 2)); |
|||
Vector2 BottomRight = canvas.CanvasToScreen(new Vector2(-m_RenderTexture.width / 2, -m_RenderTexture.height / 2)); |
|||
|
|||
if (Brush != null) |
|||
{ |
|||
if ((Event.current.type == EventType.MouseDown || Event.current.type == EventType.MouseDrag) && Event.current.button == 0) |
|||
{ |
|||
Vector2 localMousePos = Event.current.mousePosition; |
|||
Vector2 brushPos = new Vector2((localMousePos.x - TopLeft.x) / (BottomRight.x - TopLeft.x), (localMousePos.y - TopLeft.y) / (BottomRight.y - TopLeft.y)); |
|||
|
|||
if (Event.current.type == EventType.MouseDown) |
|||
{ |
|||
m_PrevBrushPos = brushPos; |
|||
m_PrevBrushDirection = Vector2.zero; |
|||
} |
|||
|
|||
Vector2 pos = brushPos; |
|||
pos.Scale(new Vector2(m_RenderTexture.width, m_RenderTexture.height)); |
|||
|
|||
Vector2 brushDirection = (brushPos - m_PrevBrushPos) * Brush.MotionIntensity; |
|||
|
|||
PaintSegment(brushPos, m_PrevBrushPos, brushDirection, m_PrevBrushDirection); |
|||
m_PrevBrushPos = brushPos; |
|||
m_PrevBrushDirection = brushDirection; |
|||
|
|||
} |
|||
else if (Event.current.type == EventType.MouseUp) |
|||
{ |
|||
Undo.RegisterCompleteObjectUndo(PaintData, "Paint"); |
|||
UpdatePaintData(); |
|||
SavePaintData(); |
|||
} |
|||
|
|||
needRepaint |= Brush.DrawBrushCanvasPreview(Event.current.mousePosition, Brush.Size * canvas.zoom * 0.5f); |
|||
} |
|||
|
|||
return needRepaint; |
|||
} |
|||
|
|||
public void PaintSegment(Vector2 position, Vector2 prevPosition, Vector2 direction, Vector2 prevDirection) |
|||
{ |
|||
Vector2 size = new Vector2(PaintDataWidth, PaintDataHeight); |
|||
|
|||
Vector2 absPosition = position; |
|||
Vector2 absPrevPosition = prevPosition; |
|||
absPosition.Scale(size); |
|||
absPrevPosition.Scale(size); |
|||
|
|||
float dist = Vector2.Distance(absPosition, absPrevPosition); |
|||
float space = Brush.Spacing * Brush.Size * 0.5f; |
|||
int n = (int)Mathf.Floor(dist/space) + 2; |
|||
|
|||
m_Material.SetTexture("_MainTex", Brush.Texture); |
|||
m_Material.SetFloat("_BrushOpacity", Brush.Opacity); |
|||
|
|||
for(int i = 0; i < n; i++) |
|||
{ |
|||
float t = (float)(i) / (float)(n-1); |
|||
Vector2 curPos = Vector2.Lerp(prevPosition, position, t); |
|||
Vector2 curDir = Vector2.Lerp(prevDirection, direction, t); |
|||
curPos.Scale(size); |
|||
m_Material.SetVector("_Direction", curDir); |
|||
VFXToolboxUtility.BlitRect(new Rect(curPos.x - Brush.Size / 2, curPos.y - Brush.Size / 2, Brush.Size, Brush.Size), m_RenderTexture, Brush.Texture, m_Material); |
|||
} |
|||
} |
|||
|
|||
public static string GetCategory() |
|||
{ return "Other VFX Tools"; } |
|||
public static string GetName() |
|||
{ return "Progression Map Generator"; } |
|||
|
|||
|
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: dd19cb3b8e0b03d4d83328d359656ce4 |
|||
timeCreated: 1485771593 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: dbfc55e60454dbb4ea04f36afc32c29b |
|||
folderAsset: yes |
|||
timeCreated: 1475666665 |
|||
licenseType: Pro |
|||
DefaultImporter: |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
// |
|||
// Noise Shader Library for Unity - https://github.com/keijiro/NoiseShader |
|||
// |
|||
// Original work (webgl-noise) Copyright (C) 2011 Stefan Gustavson |
|||
// Translation and modification was made by Keijiro Takahashi. |
|||
// |
|||
// This shader is based on the webgl-noise GLSL shader. For further details |
|||
// of the original shader, please see the following description from the |
|||
// original source code. |
|||
// |
|||
|
|||
// |
|||
// GLSL textureless classic 2D noise "cnoise", |
|||
// with an RSL-style periodic variant "pnoise". |
|||
// Author: Stefan Gustavson (stefan.gustavson@liu.se) |
|||
// Version: 2011-08-22 |
|||
// |
|||
// Many thanks to Ian McEwan of Ashima Arts for the |
|||
// ideas for permutation and gradient selection. |
|||
// |
|||
// Copyright (c) 2011 Stefan Gustavson. All rights reserved. |
|||
// Distributed under the MIT license. See LICENSE file. |
|||
// https://github.com/ashima/webgl-noise |
|||
// |
|||
|
|||
float4 mod(float4 x, float4 y) |
|||
{ |
|||
return x - y * floor(x / y); |
|||
} |
|||
|
|||
float4 mod289(float4 x) |
|||
{ |
|||
return x - floor(x / 289.0) * 289.0; |
|||
} |
|||
|
|||
float4 permute(float4 x) |
|||
{ |
|||
return mod289(((x*34.0)+1.0)*x); |
|||
} |
|||
|
|||
float4 taylorInvSqrt(float4 r) |
|||
{ |
|||
return (float4)1.79284291400159 - r * 0.85373472095314; |
|||
} |
|||
|
|||
float2 fade(float2 t) { |
|||
return t*t*t*(t*(t*6.0-15.0)+10.0); |
|||
} |
|||
|
|||
// Classic Perlin noise |
|||
float cnoise(float2 P) |
|||
{ |
|||
float4 Pi = floor(P.xyxy) + float4(0.0, 0.0, 1.0, 1.0); |
|||
float4 Pf = frac (P.xyxy) - float4(0.0, 0.0, 1.0, 1.0); |
|||
Pi = mod289(Pi); // To avoid truncation effects in permutation |
|||
float4 ix = Pi.xzxz; |
|||
float4 iy = Pi.yyww; |
|||
float4 fx = Pf.xzxz; |
|||
float4 fy = Pf.yyww; |
|||
|
|||
float4 i = permute(permute(ix) + iy); |
|||
|
|||
float4 gx = frac(i / 41.0) * 2.0 - 1.0 ; |
|||
float4 gy = abs(gx) - 0.5 ; |
|||
float4 tx = floor(gx + 0.5); |
|||
gx = gx - tx; |
|||
|
|||
float2 g00 = float2(gx.x,gy.x); |
|||
float2 g10 = float2(gx.y,gy.y); |
|||
float2 g01 = float2(gx.z,gy.z); |
|||
float2 g11 = float2(gx.w,gy.w); |
|||
|
|||
float4 norm = taylorInvSqrt(float4(dot(g00, g00), dot(g01, g01), dot(g10, g10), dot(g11, g11))); |
|||
g00 *= norm.x; |
|||
g01 *= norm.y; |
|||
g10 *= norm.z; |
|||
g11 *= norm.w; |
|||
|
|||
float n00 = dot(g00, float2(fx.x, fy.x)); |
|||
float n10 = dot(g10, float2(fx.y, fy.y)); |
|||
float n01 = dot(g01, float2(fx.z, fy.z)); |
|||
float n11 = dot(g11, float2(fx.w, fy.w)); |
|||
|
|||
float2 fade_xy = fade(Pf.xy); |
|||
float2 n_x = lerp(float2(n00, n01), float2(n10, n11), fade_xy.x); |
|||
float n_xy = lerp(n_x.x, n_x.y, fade_xy.y); |
|||
return 2.3 * n_xy; |
|||
} |
|||
|
|||
// Classic Perlin noise, periodic variant |
|||
float pnoise(float2 P, float2 rep) |
|||
{ |
|||
float4 Pi = floor(P.xyxy) + float4(0.0, 0.0, 1.0, 1.0); |
|||
float4 Pf = frac (P.xyxy) - float4(0.0, 0.0, 1.0, 1.0); |
|||
Pi = mod(Pi, rep.xyxy); // To create noise with explicit period |
|||
Pi = mod289(Pi); // To avoid truncation effects in permutation |
|||
float4 ix = Pi.xzxz; |
|||
float4 iy = Pi.yyww; |
|||
float4 fx = Pf.xzxz; |
|||
float4 fy = Pf.yyww; |
|||
|
|||
float4 i = permute(permute(ix) + iy); |
|||
|
|||
float4 gx = frac(i / 41.0) * 2.0 - 1.0 ; |
|||
float4 gy = abs(gx) - 0.5 ; |
|||
float4 tx = floor(gx + 0.5); |
|||
gx = gx - tx; |
|||
|
|||
float2 g00 = float2(gx.x,gy.x); |
|||
float2 g10 = float2(gx.y,gy.y); |
|||
float2 g01 = float2(gx.z,gy.z); |
|||
float2 g11 = float2(gx.w,gy.w); |
|||
|
|||
float4 norm = taylorInvSqrt(float4(dot(g00, g00), dot(g01, g01), dot(g10, g10), dot(g11, g11))); |
|||
g00 *= norm.x; |
|||
g01 *= norm.y; |
|||
g10 *= norm.z; |
|||
g11 *= norm.w; |
|||
|
|||
float n00 = dot(g00, float2(fx.x, fy.x)); |
|||
float n10 = dot(g10, float2(fx.y, fy.y)); |
|||
float n01 = dot(g01, float2(fx.z, fy.z)); |
|||
float n11 = dot(g11, float2(fx.w, fy.w)); |
|||
|
|||
float2 fade_xy = fade(Pf.xy); |
|||
float2 n_x = lerp(float2(n00, n01), float2(n10, n11), fade_xy.x); |
|||
float n_xy = lerp(n_x.x, n_x.y, fade_xy.y); |
|||
return 2.3 * n_xy; |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: cfdaee82db64bf14db1492d05ffa0a47 |
|||
ShaderImporter: |
|||
externalObjects: {} |
|||
defaultTextures: [] |
|||
nonModifiableTextures: [] |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
Shader "VFXToolbox/ImageScripter/FlowMapPainter.DisplayFlow" |
|||
{ |
|||
Properties |
|||
{ |
|||
_MainTex ("Texture", any) = "" {} |
|||
_FlowTex ("FlowTex", any) = "" {} |
|||
_EdTime ("_EdTime", float) = 0.0 |
|||
_Intensity("_Intensity", Float) = 0.2 |
|||
_Cycle("_Cycle", Float) = 2.0 |
|||
_Tile("Tile", Float) = 4.0 |
|||
} |
|||
|
|||
SubShader { |
|||
|
|||
Tags { "ForceSupported" = "True" "RenderType"="Overlay" } |
|||
Lighting Off |
|||
Blend SrcAlpha OneMinusSrcAlpha |
|||
Cull Off |
|||
ZWrite Off |
|||
ZTest Always |
|||
|
|||
Pass { |
|||
CGPROGRAM |
|||
#pragma vertex vert |
|||
#pragma fragment frag |
|||
|
|||
#include "UnityCG.cginc" |
|||
|
|||
struct appdata_t { |
|||
float4 vertex : POSITION; |
|||
float2 texcoord : TEXCOORD0; |
|||
}; |
|||
|
|||
struct v2f { |
|||
float4 vertex : SV_POSITION; |
|||
float2 texcoord : TEXCOORD0; |
|||
}; |
|||
|
|||
sampler2D _MainTex; |
|||
sampler2D _FlowTex; |
|||
float _EdTime; |
|||
float _Intensity; |
|||
float _Cycle; |
|||
float _Tile; |
|||
|
|||
v2f vert (appdata_t v) |
|||
{ |
|||
v2f o; |
|||
o.vertex = UnityObjectToClipPos(v.vertex); |
|||
o.texcoord = v.texcoord; |
|||
return o; |
|||
} |
|||
|
|||
float triangleWave(float x, float phase) |
|||
{ |
|||
return abs(frac(x/phase)-0.5)*2; |
|||
} |
|||
|
|||
fixed4 frag (v2f i) : SV_Target |
|||
{ |
|||
float tA = (_EdTime % _Cycle)-1.0f; |
|||
float tB = ((_EdTime+(_Cycle/2)) % _Cycle)-1.0f; |
|||
float tT = triangleWave(_EdTime, _Cycle); |
|||
|
|||
float2 flow = tex2Dlod(_FlowTex, float4(i.texcoord.x,i.texcoord.y,0,0)).rg - 0.5f; |
|||
flow *= float2(1,-1) * (_Intensity / _Cycle); |
|||
float3 colA = tex2Dlod(_MainTex, float4((i.texcoord-0.5) * _Tile - flow * tA,0,0)).rgb; |
|||
float3 colB = tex2Dlod(_MainTex, float4((i.texcoord-0.5) * _Tile - flow * tB,0,0)).rgb; |
|||
return float4(lerp(colA, colB, smoothstep(0,1,tT)),1); |
|||
} |
|||
ENDCG |
|||
} |
|||
} |
|||
Fallback off |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 90113502b33414447b22b808442ca537 |
|||
timeCreated: 1475766251 |
|||
licenseType: Pro |
|||
ShaderImporter: |
|||
defaultTextures: [] |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
Shader "VFXToolbox/ImageScripter/FlowMapPaint" |
|||
{ |
|||
Properties |
|||
{ |
|||
_MainTex ("Texture", any) = "" {} |
|||
_Direction ("Direction", Vector) = (0.0,0.0,0.0,0.0) |
|||
_BrushOpacity ("BrushOpacity", Float) = 1.0 |
|||
} |
|||
|
|||
SubShader { |
|||
|
|||
Tags { "ForceSupported" = "True" "RenderType"="Overlay" } |
|||
ColorMask RGB |
|||
Lighting Off |
|||
Blend SrcAlpha OneMinusSrcAlpha |
|||
Cull Off |
|||
ZWrite Off |
|||
ZTest Always |
|||
|
|||
Pass { |
|||
CGPROGRAM |
|||
#pragma vertex vert |
|||
#pragma fragment frag |
|||
|
|||
#include "UnityCG.cginc" |
|||
|
|||
struct appdata_t { |
|||
float4 vertex : POSITION; |
|||
float2 texcoord : TEXCOORD0; |
|||
}; |
|||
|
|||
struct v2f { |
|||
float4 vertex : SV_POSITION; |
|||
float2 texcoord : TEXCOORD0; |
|||
}; |
|||
|
|||
sampler2D _MainTex; |
|||
float4 _Direction; |
|||
float _BrushOpacity; |
|||
|
|||
v2f vert (appdata_t v) |
|||
{ |
|||
v2f o; |
|||
o.vertex = UnityObjectToClipPos(v.vertex); |
|||
o.texcoord = v.texcoord; |
|||
return o; |
|||
} |
|||
|
|||
fixed4 frag (v2f i) : SV_Target |
|||
{ |
|||
float4 c = tex2D(_MainTex, i.texcoord); |
|||
float2 noise = c.rg - 0.5f; |
|||
return float4(saturate(_Direction.x+noise.x+0.5f),saturate(_Direction.y+noise.y+0.5f),0.0f,saturate(c.a * _BrushOpacity)); |
|||
} |
|||
ENDCG |
|||
} |
|||
} |
|||
Fallback off |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: aa7f8468ed4357a4b9e7a6567c3c7869 |
|||
timeCreated: 1475666675 |
|||
licenseType: Pro |
|||
ShaderImporter: |
|||
defaultTextures: [] |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
// Based on 3d Value noise (iQ https://www.shadertoy.com/view/4sfGzS) |
|||
Shader "VFXToolbox/ImageScripter/NoiseGen" |
|||
{ |
|||
Properties |
|||
{ |
|||
_depth("Noise Depth", Int) = 5 |
|||
_width("Width", Int) = 256 |
|||
_height("Height", Int) = 256 |
|||
_phase("Phase", Float) = 0.0 |
|||
} |
|||
SubShader |
|||
{ |
|||
Tags { "RenderType" = "Opaque" } |
|||
ColorMask RGB |
|||
Lighting Off |
|||
Cull Off |
|||
ZWrite Off |
|||
ZTest Always |
|||
LOD 100 |
|||
|
|||
Pass |
|||
{ |
|||
CGPROGRAM |
|||
#pragma vertex vert |
|||
#pragma fragment frag |
|||
|
|||
#include "UnityCG.cginc" |
|||
#include "SimplexNoise2D.hlsl" |
|||
|
|||
int _depth; |
|||
int _width; |
|||
int _height; |
|||
float _phase; |
|||
|
|||
struct appdata |
|||
{ |
|||
float4 vertex : POSITION; |
|||
float2 uv : TEXCOORD0; |
|||
}; |
|||
|
|||
struct v2f |
|||
{ |
|||
float2 uv : TEXCOORD0; |
|||
float4 vertex : SV_POSITION; |
|||
}; |
|||
|
|||
v2f vert (appdata v) |
|||
{ |
|||
v2f o; |
|||
o.vertex = UnityObjectToClipPos(v.vertex); |
|||
o.uv = v.uv; |
|||
return o; |
|||
} |
|||
|
|||
half4 frag (v2f i) : SV_Target |
|||
{ |
|||
const float epsilon = 0.0001; |
|||
|
|||
float2 uv = i.uv * 4.0 + float2(0.2, 1) * _phase; |
|||
float2 o = 0.5; |
|||
float s = 1.0; |
|||
float w = 0.5; |
|||
|
|||
for (int i = 0; i < _depth + 3; i++) |
|||
{ |
|||
|
|||
float2 coord = uv * s; |
|||
float2 period = s * 2.0; |
|||
|
|||
float v0 = snoise(coord); |
|||
float vx = snoise(coord + float2(epsilon, 0)); |
|||
float vy = snoise(coord + float2(0, epsilon)); |
|||
|
|||
o += w * float2(vx - v0, vy - v0) / epsilon; |
|||
|
|||
s *= 2.0; |
|||
w *= 0.5; |
|||
} |
|||
return float4(o.x, o.y, 0, 1); |
|||
} |
|||
ENDCG |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 07121ed0a68da7e499b387f24d9f3671 |
|||
timeCreated: 1488291508 |
|||
licenseType: Pro |
|||
ShaderImporter: |
|||
defaultTextures: [] |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
// |
|||
// Noise Shader Library for Unity - https://github.com/keijiro/NoiseShader |
|||
// |
|||
// Original work (webgl-noise) Copyright (C) 2011 Ashima Arts. |
|||
// Translation and modification was made by Keijiro Takahashi. |
|||
// |
|||
// This shader is based on the webgl-noise GLSL shader. For further details |
|||
// of the original shader, please see the following description from the |
|||
// original source code. |
|||
// |
|||
|
|||
// |
|||
// Description : Array and textureless GLSL 2D simplex noise function. |
|||
// Author : Ian McEwan, Ashima Arts. |
|||
// Maintainer : ijm |
|||
// Lastmod : 20110822 (ijm) |
|||
// License : Copyright (C) 2011 Ashima Arts. All rights reserved. |
|||
// Distributed under the MIT License. See LICENSE file. |
|||
// https://github.com/ashima/webgl-noise |
|||
// |
|||
|
|||
float3 mod289(float3 x) |
|||
{ |
|||
return x - floor(x / 289.0) * 289.0; |
|||
} |
|||
|
|||
float2 mod289(float2 x) |
|||
{ |
|||
return x - floor(x / 289.0) * 289.0; |
|||
} |
|||
|
|||
float3 permute(float3 x) |
|||
{ |
|||
return mod289((x * 34.0 + 1.0) * x); |
|||
} |
|||
|
|||
float3 taylorInvSqrt(float3 r) |
|||
{ |
|||
return 1.79284291400159 - 0.85373472095314 * r; |
|||
} |
|||
|
|||
float snoise(float2 v) |
|||
{ |
|||
const float4 C = float4( 0.211324865405187, // (3.0-sqrt(3.0))/6.0 |
|||
0.366025403784439, // 0.5*(sqrt(3.0)-1.0) |
|||
-0.577350269189626, // -1.0 + 2.0 * C.x |
|||
0.024390243902439); // 1.0 / 41.0 |
|||
// First corner |
|||
float2 i = floor(v + dot(v, C.yy)); |
|||
float2 x0 = v - i + dot(i, C.xx); |
|||
|
|||
// Other corners |
|||
float2 i1; |
|||
i1.x = step(x0.y, x0.x); |
|||
i1.y = 1.0 - i1.x; |
|||
|
|||
// x1 = x0 - i1 + 1.0 * C.xx; |
|||
// x2 = x0 - 1.0 + 2.0 * C.xx; |
|||
float2 x1 = x0 + C.xx - i1; |
|||
float2 x2 = x0 + C.zz; |
|||
|
|||
// Permutations |
|||
i = mod289(i); // Avoid truncation effects in permutation |
|||
float3 p = |
|||
permute(permute(i.y + float3(0.0, i1.y, 1.0)) |
|||
+ i.x + float3(0.0, i1.x, 1.0)); |
|||
|
|||
float3 m = max(0.5 - float3(dot(x0, x0), dot(x1, x1), dot(x2, x2)), 0.0); |
|||
m = m * m; |
|||
m = m * m; |
|||
|
|||
// Gradients: 41 points uniformly over a line, mapped onto a diamond. |
|||
// The ring size 17*17 = 289 is close to a multiple of 41 (41*7 = 287) |
|||
float3 x = 2.0 * frac(p * C.www) - 1.0; |
|||
float3 h = abs(x) - 0.5; |
|||
float3 ox = floor(x + 0.5); |
|||
float3 a0 = x - ox; |
|||
|
|||
// Normalise gradients implicitly by scaling m |
|||
m *= taylorInvSqrt(a0 * a0 + h * h); |
|||
|
|||
// Compute final noise value at P |
|||
float3 g; |
|||
g.x = a0.x * x0.x + h.x * x0.y; |
|||
g.y = a0.y * x1.x + h.y * x1.y; |
|||
g.z = a0.z * x2.x + h.z * x2.y; |
|||
return 130.0 * dot(m, g); |
|||
} |
|||
|
|||
float3 snoise_grad(float2 v) |
|||
{ |
|||
const float4 C = float4( 0.211324865405187, // (3.0-sqrt(3.0))/6.0 |
|||
0.366025403784439, // 0.5*(sqrt(3.0)-1.0) |
|||
-0.577350269189626, // -1.0 + 2.0 * C.x |
|||
0.024390243902439); // 1.0 / 41.0 |
|||
// First corner |
|||
float2 i = floor(v + dot(v, C.yy)); |
|||
float2 x0 = v - i + dot(i, C.xx); |
|||
|
|||
// Other corners |
|||
float2 i1; |
|||
i1.x = step(x0.y, x0.x); |
|||
i1.y = 1.0 - i1.x; |
|||
|
|||
// x1 = x0 - i1 + 1.0 * C.xx; |
|||
// x2 = x0 - 1.0 + 2.0 * C.xx; |
|||
float2 x1 = x0 + C.xx - i1; |
|||
float2 x2 = x0 + C.zz; |
|||
|
|||
// Permutations |
|||
i = mod289(i); // Avoid truncation effects in permutation |
|||
float3 p = |
|||
permute(permute(i.y + float3(0.0, i1.y, 1.0)) |
|||
+ i.x + float3(0.0, i1.x, 1.0)); |
|||
|
|||
float3 m = max(0.5 - float3(dot(x0, x0), dot(x1, x1), dot(x2, x2)), 0.0); |
|||
float3 m2 = m * m; |
|||
float3 m3 = m2 * m; |
|||
float3 m4 = m2 * m2; |
|||
|
|||
// Gradients: 41 points uniformly over a line, mapped onto a diamond. |
|||
// The ring size 17*17 = 289 is close to a multiple of 41 (41*7 = 287) |
|||
float3 x = 2.0 * frac(p * C.www) - 1.0; |
|||
float3 h = abs(x) - 0.5; |
|||
float3 ox = floor(x + 0.5); |
|||
float3 a0 = x - ox; |
|||
|
|||
// Normalise gradients |
|||
float3 norm = taylorInvSqrt(a0 * a0 + h * h); |
|||
float2 g0 = float2(a0.x, h.x) * norm.x; |
|||
float2 g1 = float2(a0.y, h.y) * norm.y; |
|||
float2 g2 = float2(a0.z, h.z) * norm.z; |
|||
|
|||
// Compute noise and gradient at P |
|||
float2 grad = |
|||
-6.0 * m3.x * x0 * dot(x0, g0) + m4.x * g0 + |
|||
-6.0 * m3.y * x1 * dot(x1, g1) + m4.y * g1 + |
|||
-6.0 * m3.z * x2 * dot(x2, g2) + m4.z * g2; |
|||
float3 px = float3(dot(x0, g0), dot(x1, g1), dot(x2, g2)); |
|||
return 130.0 * float3(grad, dot(m4, px)); |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: f12d0ce1fb1e8964d99ba3f8b35b107a |
|||
ShaderImporter: |
|||
externalObjects: {} |
|||
defaultTextures: [] |
|||
nonModifiableTextures: [] |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using UnityEngine; |
|||
using System; |
|||
using System.Collections.Generic; |
|||
|
|||
namespace UnityEditor.VFXToolbox.Workbench |
|||
{ |
|||
public class Workbench : EditorWindow |
|||
{ |
|||
Splitter m_Splitter; |
|||
WorkbenchImageCanvas m_Canvas; |
|||
Texture2D m_Texture; |
|||
private bool m_Dirty; |
|||
|
|||
WorkbenchBehaviour m_Asset; |
|||
|
|||
[MenuItem("Window/Visual Effects/Workbench")] |
|||
public static void OpenEditor() |
|||
{ |
|||
GetWindow(typeof(Workbench)); |
|||
} |
|||
|
|||
public void OnEnable() |
|||
{ |
|||
if(m_Asset != null) |
|||
{ |
|||
LoadAsset(m_Asset); |
|||
} |
|||
|
|||
Selection.selectionChanged -= OnSelectionChange; |
|||
Selection.selectionChanged += OnSelectionChange; |
|||
Undo.undoRedoPerformed -= OnUndoRedo; |
|||
Undo.undoRedoPerformed += OnUndoRedo; |
|||
} |
|||
|
|||
public void OnDisable() |
|||
{ |
|||
if(m_Asset != null) |
|||
{ |
|||
UnloadAsset(); |
|||
} |
|||
Selection.selectionChanged -= OnSelectionChange; |
|||
Undo.undoRedoPerformed -= OnUndoRedo; |
|||
} |
|||
|
|||
public void OnUndoRedo() |
|||
{ |
|||
if(m_Asset != null) |
|||
{ |
|||
ReloadAsset(); |
|||
} |
|||
} |
|||
|
|||
public void OnSelectionChange() |
|||
{ |
|||
if (Selection.activeObject is WorkbenchBehaviour) |
|||
{ |
|||
LoadAsset(Selection.activeObject as WorkbenchBehaviour); |
|||
} |
|||
} |
|||
|
|||
public void ReloadAsset() |
|||
{ |
|||
m_Asset.tool.Dispose(); |
|||
m_Asset.tool.Initialize(); |
|||
Invalidate(); |
|||
} |
|||
|
|||
public void LoadAsset(WorkbenchBehaviour asset) |
|||
{ |
|||
if (m_Asset == asset) |
|||
return; // Not gonna reload the same asset
|
|||
|
|||
if (m_Asset != null && m_Asset != asset) |
|||
{ |
|||
UnloadAsset(); |
|||
wantsMouseMove = false; |
|||
} |
|||
|
|||
m_Asset = asset; |
|||
|
|||
if(m_Asset.tool != null) |
|||
{ |
|||
m_Asset.tool.Initialize(); |
|||
wantsMouseMove = true; |
|||
} |
|||
|
|||
Invalidate(); |
|||
} |
|||
|
|||
public void UnloadAsset() |
|||
{ |
|||
if(m_Asset.tool != null) |
|||
m_Asset.tool.Dispose(); |
|||
m_Asset = null; |
|||
} |
|||
|
|||
public void OnGUI() |
|||
{ |
|||
m_Dirty = false; |
|||
string title = "Workbench"; |
|||
if(m_Asset != null && m_Asset.tool != null) |
|||
{ |
|||
title = m_Asset.tool.name; |
|||
} |
|||
titleContent = VFXToolboxGUIUtility.GetTextAndIcon(title, "SettingsIcon"); |
|||
|
|||
Rect toolbarRect = new Rect(0, 0, position.width, 18); |
|||
Rect splitterRect = new Rect(0,18,position.width , position.height-18); |
|||
|
|||
if (m_Splitter == null) |
|||
m_Splitter = new Splitter(320.0f, OnDrawInspector, OnDrawCanvas, Splitter.SplitLockMode.LeftMinMax, new Vector2(320,480)); |
|||
|
|||
if (m_Canvas == null) |
|||
m_Canvas = new WorkbenchImageCanvas(splitterRect,this); |
|||
|
|||
using (new GUILayout.AreaScope(toolbarRect, GUIContent.none, EditorStyles.toolbar)) |
|||
using (new GUILayout.HorizontalScope()) |
|||
{ |
|||
GUILayout.Space(m_Splitter.value); |
|||
OnDrawToolbar(); |
|||
GUILayout.FlexibleSpace(); |
|||
} |
|||
|
|||
m_Splitter.DoSplitter(splitterRect); |
|||
|
|||
HandleDropData(); |
|||
|
|||
if (m_Dirty) |
|||
Repaint(); |
|||
} |
|||
|
|||
private void OnDrawToolbar() |
|||
{ |
|||
using (new EditorGUILayout.HorizontalScope(EditorStyles.toolbar)) |
|||
{ |
|||
bool prev; |
|||
|
|||
bool bMaskR = m_Canvas.maskR; |
|||
bool bMaskG = m_Canvas.maskG; |
|||
bool bMaskB = m_Canvas.maskB; |
|||
bool bMaskA = m_Canvas.maskA; |
|||
bool bMaskRGB = bMaskR && bMaskG && bMaskB; |
|||
|
|||
bMaskRGB = GUILayout.Toggle(bMaskRGB, styles.iconRGB, EditorStyles.toolbarButton); |
|||
|
|||
if(bMaskRGB != (bMaskR && bMaskG && bMaskB)) |
|||
{ |
|||
bMaskR = bMaskG = bMaskB = bMaskRGB; |
|||
|
|||
m_Canvas.maskR = bMaskR; |
|||
m_Canvas.maskG = bMaskG; |
|||
m_Canvas.maskB = bMaskB; |
|||
|
|||
} |
|||
|
|||
prev = bMaskR; |
|||
bMaskR = GUILayout.Toggle(bMaskR, VFXToolboxGUIUtility.Get("R"),styles.MaskRToggle); |
|||
|
|||
if (bMaskR != prev) |
|||
m_Canvas.maskR = bMaskR; |
|||
|
|||
prev = bMaskG; |
|||
bMaskG = GUILayout.Toggle(bMaskG, VFXToolboxGUIUtility.Get("G"),styles.MaskGToggle); |
|||
if (bMaskG != prev) |
|||
m_Canvas.maskG = bMaskG; |
|||
|
|||
prev = bMaskB; |
|||
bMaskB = GUILayout.Toggle(bMaskB, VFXToolboxGUIUtility.Get("B"),styles.MaskBToggle); |
|||
if (bMaskB != prev) |
|||
m_Canvas.maskB = bMaskB; |
|||
|
|||
prev = bMaskA; |
|||
bMaskA = GUILayout.Toggle(bMaskA, VFXToolboxGUIUtility.Get("A"),styles.MaskAToggle); |
|||
if (bMaskA != prev) |
|||
m_Canvas.maskA = bMaskA; |
|||
|
|||
|
|||
GUILayout.Space(20); |
|||
{ |
|||
Rect brightnessRect = GUILayoutUtility.GetRect(160, 24); |
|||
GUI.Box(brightnessRect, GUIContent.none, EditorStyles.toolbarButton); |
|||
GUI.Label(new RectOffset(4, 0, 0, 0).Remove(brightnessRect), VFXToolboxGUIUtility.GetTextAndIcon("Background|Sets the Background Brightness", "CheckerFloor"), EditorStyles.miniLabel); |
|||
|
|||
float newBrightness = GUI.HorizontalSlider(new RectOffset(82, 4, 0, 0).Remove(brightnessRect), m_Canvas.BackgroundBrightness, 0.0f, 1.0f); |
|||
if (m_Canvas.BackgroundBrightness != newBrightness) |
|||
m_Canvas.BackgroundBrightness = newBrightness; |
|||
} |
|||
|
|||
GUILayout.FlexibleSpace(); |
|||
} |
|||
|
|||
} |
|||
|
|||
private void OnDrawCanvas(Rect rect) |
|||
{ |
|||
m_Canvas.displayRect = rect; |
|||
|
|||
if (m_Asset != null) |
|||
m_Canvas.OnGUI(m_Asset.tool); |
|||
else |
|||
m_Canvas.OnGUI(); |
|||
} |
|||
|
|||
private void OnDrawInspector(Rect rect) |
|||
{ |
|||
if(m_Asset != null) |
|||
{ |
|||
using (new GUILayout.AreaScope(rect, GUIContent.none, styles.inspector)) |
|||
{ |
|||
if(m_Asset.tool != null) |
|||
{ |
|||
EditorGUILayout.InspectorTitlebar(false, m_Asset.tool); |
|||
m_Asset.tool.OnInspectorGUI(); |
|||
} |
|||
else |
|||
{ |
|||
EditorGUILayout.HelpBox("No Script Currently Assigned, please select one using the menu", MessageType.Warning); |
|||
using(new GUILayout.HorizontalScope()) |
|||
{ |
|||
EditorGUILayout.LabelField("New Script", GUILayout.Width(EditorGUIUtility.labelWidth)); |
|||
|
|||
if (GUILayout.Button("Select", EditorStyles.popup)) |
|||
{ |
|||
GenericMenu menu = new GenericMenu(); |
|||
var types = VFXToolboxUtility.FindConcreteSubclasses<WorkbenchToolBase>(); |
|||
|
|||
foreach(Type t in types) |
|||
{ |
|||
string category = WorkbenchToolBase.GetCategory(t); |
|||
string name = WorkbenchToolBase.GetName(t); |
|||
string path = (category.Length > 0 ? category + "/" : "") + name; |
|||
menu.AddItem(VFXToolboxGUIUtility.Get(path), false, AddObject, t); |
|||
} |
|||
menu.ShowAsContext(); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
} |
|||
else |
|||
{ |
|||
using (new GUILayout.AreaScope(rect, GUIContent.none, styles.inspector)) |
|||
{ |
|||
EditorGUILayout.HelpBox("No Asset Selected, please create an asset inside the Project Window to Edit It", MessageType.Warning); |
|||
} |
|||
} |
|||
} |
|||
|
|||
public void AddObject(object o) |
|||
{ |
|||
WorkbenchInspector inspector = (WorkbenchInspector)Editor.CreateEditor(m_Asset); |
|||
inspector.AddObject(o as Type); |
|||
} |
|||
|
|||
public void Invalidate() |
|||
{ |
|||
m_Dirty = true; |
|||
} |
|||
|
|||
private bool HandleDropData() |
|||
{ |
|||
if(DragAndDrop.paths.Length > 0) |
|||
{ |
|||
DragAndDrop.visualMode = DragAndDropVisualMode.Link; |
|||
if( Event.current.type == EventType.DragExited) |
|||
{ |
|||
foreach(string path in DragAndDrop.paths) |
|||
{ |
|||
Texture2D t = AssetDatabase.LoadAssetAtPath<Texture2D>(path); |
|||
if(t != null) |
|||
{ |
|||
m_Canvas.texture = t; |
|||
return true; |
|||
} |
|||
} |
|||
} |
|||
} |
|||
return false; |
|||
} |
|||
|
|||
#region styles
|
|||
public static Styles styles |
|||
{ |
|||
get |
|||
{ |
|||
if (s_Styles == null) |
|||
s_Styles = new Styles(); |
|||
return |
|||
s_Styles; |
|||
} |
|||
} |
|||
|
|||
private static Styles s_Styles; |
|||
|
|||
public class Styles |
|||
{ |
|||
public readonly GUIStyle separator = (GUIStyle)"sv_iconselector_sep"; |
|||
public GUIStyle inspector { get { return m_Inspector; } } |
|||
private GUIStyle m_Inspector; |
|||
|
|||
public readonly GUIContent iconRGB = EditorGUIUtility.IconContent("PreTextureRGB", "Toggle RGB/Alpha only"); |
|||
public readonly GUIContent iconMipMapUp = EditorGUIUtility.IconContent("PreTextureMipMapLow", "Go one MipMap up (smaller size)"); |
|||
public readonly GUIContent iconMipMapDown = EditorGUIUtility.IconContent("PreTextureMipMapHigh", "Go one MipMap down (higher size)"); |
|||
|
|||
public GUIStyle MaskRToggle { get { if (EditorGUIUtility.isProSkin) return m_MaskRTogglePro; else return m_MaskRToggle; } } |
|||
public GUIStyle MaskGToggle { get { if (EditorGUIUtility.isProSkin) return m_MaskGTogglePro; else return m_MaskGToggle; } } |
|||
public GUIStyle MaskBToggle { get { if (EditorGUIUtility.isProSkin) return m_MaskBTogglePro; else return m_MaskBToggle; } } |
|||
public GUIStyle MaskAToggle { get { if (EditorGUIUtility.isProSkin) return m_MaskATogglePro; else return m_MaskAToggle; } } |
|||
|
|||
private GUIStyle m_MaskRToggle; |
|||
private GUIStyle m_MaskRTogglePro; |
|||
private GUIStyle m_MaskGToggle; |
|||
private GUIStyle m_MaskGTogglePro; |
|||
private GUIStyle m_MaskBToggle; |
|||
private GUIStyle m_MaskBTogglePro; |
|||
private GUIStyle m_MaskAToggle; |
|||
private GUIStyle m_MaskATogglePro; |
|||
|
|||
public Styles() |
|||
{ |
|||
m_Inspector = new GUIStyle(EditorStyles.inspectorDefaultMargins); |
|||
|
|||
m_MaskRToggle = new GUIStyle(EditorStyles.toolbarButton); |
|||
m_MaskGToggle = new GUIStyle(EditorStyles.toolbarButton); |
|||
m_MaskBToggle= new GUIStyle(EditorStyles.toolbarButton); |
|||
m_MaskAToggle= new GUIStyle(EditorStyles.toolbarButton); |
|||
|
|||
m_MaskRToggle.onNormal.textColor = new Color(1.0f, 0.0f, 0.0f); |
|||
m_MaskGToggle.onNormal.textColor = new Color(0.0f, 0.6f, 0.2f); |
|||
m_MaskBToggle.onNormal.textColor = new Color(0.0f, 0.2f, 1.0f); |
|||
m_MaskAToggle.onNormal.textColor = new Color(0.5f, 0.5f, 0.5f); |
|||
|
|||
m_MaskRTogglePro = new GUIStyle(EditorStyles.toolbarButton); |
|||
m_MaskGTogglePro= new GUIStyle(EditorStyles.toolbarButton); |
|||
m_MaskBTogglePro= new GUIStyle(EditorStyles.toolbarButton); |
|||
m_MaskATogglePro= new GUIStyle(EditorStyles.toolbarButton); |
|||
|
|||
m_MaskRTogglePro.onNormal.textColor = new Color(2.0f, 0.3f, 0.3f); |
|||
m_MaskGTogglePro.onNormal.textColor = new Color(0.5f, 2.0f, 0.1f); |
|||
m_MaskBTogglePro.onNormal.textColor = new Color(0.2f, 0.6f, 2.0f); |
|||
m_MaskATogglePro.onNormal.textColor = new Color(2.0f, 2.0f, 2.0f); |
|||
} |
|||
} |
|||
|
|||
#endregion
|
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 85c93d0862acd9747848a1a254226dcd |
|||
timeCreated: 1474993084 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System.Collections.Generic; |
|||
using UnityEngine; |
|||
|
|||
namespace UnityEditor.VFXToolbox.Workbench |
|||
{ |
|||
public class WorkbenchBehaviour : ScriptableObject |
|||
{ |
|||
public WorkbenchToolBase tool; |
|||
|
|||
} |
|||
} |
|||
|
|
|||
fileFormatVersion: 2 |
|||
guid: 4dccf541cd9203d4f8086a24e03385e8 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {fileID: 2800000, guid: 07dc82adf399fc0408633eace96835a4, type: 3} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using UnityEngine; |
|||
using UnityEditor.ProjectWindowCallback; |
|||
using System.IO; |
|||
|
|||
namespace UnityEditor.VFXToolbox.Workbench |
|||
{ |
|||
public class WorkbenchBehaviourFactory |
|||
{ |
|||
[MenuItem("Assets/Create/Visual Effects/Workbench/Empty Workbench", priority = 301)] |
|||
private static void MenuCreateAsset() |
|||
{ |
|||
WorkbenchBehaviourFactory.CreateWorkbenchAsset("New Workbench"); |
|||
} |
|||
|
|||
public static void CreateWorkbenchAsset(string defaultName, WorkbenchToolBase defaultTool = null) |
|||
{ |
|||
var icon = (Texture2D)null; |
|||
var action = ScriptableObject.CreateInstance<DoCreateWorkbenchBehaviour>(); |
|||
action.SetTool(defaultTool); |
|||
ProjectWindowUtil.StartNameEditingIfProjectWindowExists(0, action, defaultName + ".asset", icon, null); |
|||
|
|||
} |
|||
|
|||
[MenuItem("Assets/Create/Visual Effects/Workbench/Brushes/Flow Brush", priority = 301)] |
|||
private static void MenuCreateFlowBrush() |
|||
{ |
|||
var icon = (Texture2D)null; |
|||
ProjectWindowUtil.StartNameEditingIfProjectWindowExists(0, ScriptableObject.CreateInstance<DoCreateFlowBrush>(), "New Flow Brush.asset", icon, null); |
|||
} |
|||
/* |
|||
[MenuItem("Assets/Create/Visual Effects/Tools/Brush Collection", priority = 301)] |
|||
private static void MenuCreatePaintBrushCollection() |
|||
{ |
|||
var icon = (Texture2D)null; |
|||
ProjectWindowUtil.StartNameEditingIfProjectWindowExists(0, ScriptableObject.CreateInstance<DoCreatePaintBrushCollectionAsset>(), "New Brush Collection.asset", icon, null); |
|||
}*/ |
|||
|
|||
internal static WorkbenchBehaviour CreateWorkbenchAssetAtPath(string path, WorkbenchToolBase tool) |
|||
{ |
|||
WorkbenchBehaviour asset = ScriptableObject.CreateInstance<WorkbenchBehaviour>(); |
|||
asset.name = Path.GetFileName(path); |
|||
AssetDatabase.CreateAsset(asset, path); |
|||
if(tool != null) |
|||
{ |
|||
AssetDatabase.AddObjectToAsset(tool, asset); |
|||
tool.Default(asset); |
|||
tool.name = tool.GetType().Name; |
|||
tool.hideFlags = HideFlags.HideInHierarchy; |
|||
EditorUtility.SetDirty(asset); |
|||
tool.Initialize(); |
|||
AssetDatabase.SaveAssets(); |
|||
} |
|||
|
|||
return asset; |
|||
} |
|||
|
|||
internal static FlowPaintBrush CreateFlowPaintBrushAssetAtPath(string path) |
|||
{ |
|||
FlowPaintBrush asset = ScriptableObject.CreateInstance<FlowPaintBrush>(); |
|||
asset.name = Path.GetFileName(path); |
|||
AssetDatabase.CreateAsset(asset, path); |
|||
return asset; |
|||
} |
|||
|
|||
/* internal static PaintBrushCollection CreatePaintBrushCollectionAssetAtPath(string path) |
|||
{ |
|||
PaintBrushCollection asset = ScriptableObject.CreateInstance<PaintBrushCollection>(); |
|||
asset.name = Path.GetFileName(path); |
|||
AssetDatabase.CreateAsset(asset, path); |
|||
return asset; |
|||
}*/ |
|||
} |
|||
|
|||
internal class DoCreateWorkbenchBehaviour : EndNameEditAction |
|||
{ |
|||
private WorkbenchToolBase m_Tool; |
|||
|
|||
public void SetTool(WorkbenchToolBase tool) |
|||
{ |
|||
m_Tool = tool; |
|||
} |
|||
|
|||
public override void Action(int instanceId, string pathName, string resourceFile) |
|||
{ |
|||
WorkbenchBehaviour asset = WorkbenchBehaviourFactory.CreateWorkbenchAssetAtPath(pathName, m_Tool); |
|||
ProjectWindowUtil.ShowCreatedAsset(asset); |
|||
} |
|||
} |
|||
|
|||
|
|||
internal class DoCreateFlowBrush : EndNameEditAction |
|||
{ |
|||
public override void Action(int instanceId, string pathName, string resourceFile) |
|||
{ |
|||
FlowPaintBrush asset = WorkbenchBehaviourFactory.CreateFlowPaintBrushAssetAtPath(pathName); |
|||
ProjectWindowUtil.ShowCreatedAsset(asset); |
|||
} |
|||
} |
|||
/* |
|||
internal class DoCreatePaintBrushCollectionAsset : EndNameEditAction |
|||
{ |
|||
public override void Action(int instanceId, string pathName, string resourceFile) |
|||
{ |
|||
PaintBrushCollection asset = ImageScriptAssetFactory.CreatePaintBrushCollectionAssetAtPath(pathName); |
|||
ProjectWindowUtil.ShowCreatedAsset(asset); |
|||
} |
|||
}*/ |
|||
|
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 32fa3db175d0ef4498aff832bb914a55 |
|||
timeCreated: 1475161579 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System; |
|||
using System.Collections.Generic; |
|||
using UnityEngine; |
|||
using UnityEditor; |
|||
using UnityEditor.VFXToolbox; |
|||
|
|||
namespace UnityEditor.VFXToolbox.Workbench |
|||
{ |
|||
public class WorkbenchImageCanvas : VFXToolboxCanvas |
|||
{ |
|||
private Texture m_Texture; |
|||
private Workbench m_Editor; |
|||
|
|||
public WorkbenchImageCanvas(Rect displayRect, Workbench editorWindow) |
|||
: base (displayRect) |
|||
{ |
|||
m_Editor = editorWindow; |
|||
} |
|||
|
|||
public override void Invalidate(bool needRedraw) |
|||
{ |
|||
base.Invalidate(needRedraw); |
|||
m_Editor.Invalidate(); |
|||
} |
|||
|
|||
protected override Texture GetTexture() |
|||
{ |
|||
return m_Texture; |
|||
} |
|||
|
|||
protected override void SetTexture(Texture tex) |
|||
{ |
|||
m_Texture = tex; |
|||
Invalidate(true); |
|||
} |
|||
|
|||
public override void OnGUI() |
|||
{ |
|||
texture = null; |
|||
base.OnGUI(); |
|||
} |
|||
|
|||
public void OnGUI(WorkbenchToolBase currentTool) |
|||
{ |
|||
base.OnGUI(); |
|||
|
|||
if (currentTool != null) |
|||
{ |
|||
using (new GUI.ClipScope(displayRect)) |
|||
{ |
|||
if (currentTool.OnCanvasGUI(this)) |
|||
Invalidate(false); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 76685ef3ce4edb44d9fd3677d2c01cff |
|||
timeCreated: 1475500629 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using UnityEngine; |
|||
using UnityEditor.ProjectWindowCallback; |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.IO; |
|||
using System.Reflection; |
|||
|
|||
namespace UnityEditor.VFXToolbox.Workbench |
|||
{ |
|||
[CustomEditor(typeof(WorkbenchBehaviour))] |
|||
public class WorkbenchInspector : Editor |
|||
{ |
|||
|
|||
public SerializedProperty tool |
|||
{ |
|||
get |
|||
{ |
|||
if (m_Tool == null) |
|||
m_Tool = serializedObject.FindProperty("tool"); |
|||
return m_Tool; |
|||
} |
|||
} |
|||
|
|||
private SerializedProperty m_Tool; |
|||
|
|||
public override void OnInspectorGUI() |
|||
{ |
|||
serializedObject.Update(); |
|||
|
|||
if(GUILayout.Button("Open Editor", GUILayout.Height(48))) |
|||
{ |
|||
Workbench window = EditorWindow.GetWindow<Workbench>(); |
|||
window.LoadAsset((WorkbenchBehaviour)serializedObject.targetObject); |
|||
} |
|||
|
|||
string toolName = tool.objectReferenceValue == null ? "(No Tool Installed)" : (tool.objectReferenceValue as WorkbenchToolBase).GetType().Name; |
|||
|
|||
using(new GUILayout.HorizontalScope()) |
|||
{ |
|||
EditorGUILayout.LabelField("Workbench Tool", GUILayout.Width(EditorGUIUtility.labelWidth)); |
|||
|
|||
if (GUILayout.Button(toolName, EditorStyles.popup)) |
|||
{ |
|||
GenericMenu menu = new GenericMenu(); |
|||
var types = VFXToolboxUtility.FindConcreteSubclasses<WorkbenchToolBase>(); |
|||
|
|||
foreach(Type t in types) |
|||
{ |
|||
string category = WorkbenchToolBase.GetCategory(t); |
|||
string name = WorkbenchToolBase.GetName(t); |
|||
string path = (category.Length > 0 ? category + "/" : "") + name; |
|||
menu.AddItem(VFXToolboxGUIUtility.Get(path), false, AddObject, t); |
|||
} |
|||
menu.ShowAsContext(); |
|||
} |
|||
} |
|||
using (new EditorGUI.DisabledGroupScope(true)) |
|||
{ |
|||
if (tool.objectReferenceValue != null) |
|||
{ |
|||
EditorGUILayout.Foldout(true, toolName + " Properties"); |
|||
(tool.objectReferenceValue as WorkbenchToolBase).OnInspectorGUI(); |
|||
} |
|||
} |
|||
|
|||
serializedObject.ApplyModifiedProperties(); |
|||
} |
|||
|
|||
public void AddObject(object type) |
|||
{ |
|||
if((Type)type != null) |
|||
{ |
|||
if (tool != null) |
|||
{ |
|||
if( EditorUtility.DisplayDialog("Changing tools", "You are about to change the tool set up in this asset, this action cannot be undone, are you sure you want to continue?", "Yes", "No") == false) |
|||
{ |
|||
// Cancel
|
|||
return; |
|||
} |
|||
|
|||
} |
|||
DestroyImmediate(tool.objectReferenceValue,true); |
|||
var newTool = CreateInstance((Type)type); |
|||
AssetDatabase.AddObjectToAsset(newTool, serializedObject.targetObject); |
|||
(newTool as WorkbenchToolBase).Default((WorkbenchBehaviour)serializedObject.targetObject); |
|||
newTool.name = ((Type)type).Name; |
|||
newTool.hideFlags = HideFlags.HideInHierarchy; |
|||
tool.objectReferenceValue = newTool; |
|||
EditorUtility.SetDirty(serializedObject.targetObject); |
|||
serializedObject.ApplyModifiedProperties(); |
|||
(newTool as WorkbenchToolBase).Initialize(); |
|||
} |
|||
} |
|||
|
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: d592115b07a140641a18147953d41d3c |
|||
timeCreated: 1475162029 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Reflection; |
|||
using UnityEngine; |
|||
|
|||
namespace UnityEditor.VFXToolbox.Workbench |
|||
{ |
|||
public abstract class WorkbenchToolBase : ScriptableObject |
|||
{ |
|||
protected WorkbenchBehaviour m_Asset; |
|||
|
|||
public abstract bool OnInspectorGUI(); |
|||
|
|||
public virtual void Default(WorkbenchBehaviour asset) |
|||
{ |
|||
m_Asset = asset; |
|||
asset.tool = this; |
|||
} |
|||
|
|||
public abstract void Initialize(); |
|||
public abstract void Dispose(); |
|||
public abstract bool OnCanvasGUI(WorkbenchImageCanvas canvas); |
|||
public abstract void Update(); |
|||
|
|||
public static string GetCategory(Type t) |
|||
{ |
|||
return (string)InvokeTypeStatic(t, "GetCategory"); |
|||
} |
|||
|
|||
public static string GetName(Type t) |
|||
{ |
|||
return (string)InvokeTypeStatic(t, "GetName"); |
|||
} |
|||
|
|||
private static object InvokeTypeStatic(Type t, string MethodName, object[] parameters = null) |
|||
{ |
|||
try |
|||
{ |
|||
var descMethod = t.GetMethod(MethodName, BindingFlags.Public | BindingFlags.Static); |
|||
if (descMethod != null && descMethod.ReturnType == typeof(string) && descMethod.GetParameters().Length == 0) |
|||
{ |
|||
return descMethod.Invoke(null,parameters); |
|||
} |
|||
} |
|||
catch (Exception e) |
|||
{ |
|||
Debug.LogError("Error fetching Category from processor : "+ t.Name +" - "+ e.Message); |
|||
} |
|||
return ""; |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: df91a6ef181b7da4e870283dc42a372c |
|||
timeCreated: 1475162029 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
撰写
预览
正在加载...
取消
保存
Reference in new issue