浏览代码

Channel Mask Node

/main
Matt Dean 7 年前
当前提交
13948f2d
共有 5 个文件被更改,包括 187 次插入1 次删除
  1. 2
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Artistic/Mask/ColorMaskNode.cs
  2. 107
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Artistic/Mask/ChannelMaskNode.cs
  3. 11
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Artistic/Mask/ChannelMaskNode.cs.meta
  4. 65
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Controls/ChannelEnumControl.cs
  5. 3
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Controls/ChannelEnumControl.cs.meta

2
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Artistic/Mask/ColorMaskNode.cs


[Slot(2, Binding.None)] Vector1 Range,
[Slot(3, Binding.None)] out Vector3 Out)
{
Out = Vector2.zero;
Out = Vector3.zero;
return
@"
{

107
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Artistic/Mask/ChannelMaskNode.cs


using System.Reflection;
using UnityEngine;
using UnityEditor.Graphing;
using UnityEditor.ShaderGraph.Drawing.Controls;
namespace UnityEditor.ShaderGraph
{
public enum TextureChannel
{
Red,
Green,
Blue,
Alpha
}
[Title("Artistic/Mask/Channel Mask")]
public class ChannelMaskNode : CodeFunctionNode
{
public ChannelMaskNode()
{
name = "Channel Mask";
}
[SerializeField]
private TextureChannel m_Channel = TextureChannel.Red;
[ChannelEnumControl("Channel")]
public TextureChannel channel
{
get { return m_Channel; }
set
{
if (m_Channel == value)
return;
m_Channel = value;
if (onModified != null)
{
onModified(this, ModificationScope.Graph);
}
}
}
protected override MethodInfo GetFunctionToConvert()
{
switch (m_Channel)
{
case TextureChannel.Green:
return GetType().GetMethod("Unity_ChannelMask_Green", BindingFlags.Static | BindingFlags.NonPublic);
case TextureChannel.Blue:
return GetType().GetMethod("Unity_ChannelMask_Blue", BindingFlags.Static | BindingFlags.NonPublic);
case TextureChannel.Alpha:
return GetType().GetMethod("Unity_ChannelMask_Alpha", BindingFlags.Static | BindingFlags.NonPublic);
default:
return GetType().GetMethod("Unity_ChannelMask_Red", BindingFlags.Static | BindingFlags.NonPublic);
}
}
static string Unity_ChannelMask_Red(
[Slot(0, Binding.None)] DynamicDimensionVector In,
[Slot(1, Binding.None)] out Vector4 Out)
{
Out = Vector4.zero;
return
@"
{
Out = In.xxxx;
}";
}
static string Unity_ChannelMask_Green(
[Slot(0, Binding.None)] DynamicDimensionVector In,
[Slot(1, Binding.None)] out Vector4 Out)
{
Out = Vector4.zero;
return
@"
{
Out = In.yyyy;
}";
}
static string Unity_ChannelMask_Blue(
[Slot(0, Binding.None)] DynamicDimensionVector In,
[Slot(1, Binding.None)] out Vector4 Out)
{
Out = Vector4.zero;
return
@"
{
Out = In.zzzz;
}";
}
static string Unity_ChannelMask_Alpha(
[Slot(0, Binding.None)] DynamicDimensionVector In,
[Slot(1, Binding.None)] out Vector4 Out)
{
Out = Vector4.zero;
return
@"
{
Out = In.wwww;
}";
}
}
}

11
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Artistic/Mask/ChannelMaskNode.cs.meta


fileFormatVersion: 2
guid: e3fd76d77a796b641ba3e9149086efc2
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

65
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Controls/ChannelEnumControl.cs


using System;
using System.Reflection;
using UnityEngine;
using UnityEngine.Experimental.UIElements;
namespace UnityEditor.ShaderGraph.Drawing.Controls
{
[AttributeUsage(AttributeTargets.Property)]
public class ChannelEnumControlAttribute : Attribute, IControlAttribute
{
string m_Label;
public ChannelEnumControlAttribute(string label = null)
{
m_Label = label;
}
public VisualElement InstantiateControl(AbstractMaterialNode node, PropertyInfo propertyInfo)
{
return new ChannelEnumControlView(m_Label, node, propertyInfo);
}
}
public class ChannelEnumControlView : VisualElement
{
GUIContent m_Label;
AbstractMaterialNode m_Node;
PropertyInfo m_PropertyInfo;
string[] popupEntries;
public ChannelEnumControlView(string label, AbstractMaterialNode node, PropertyInfo propertyInfo)
{
m_Node = node;
m_PropertyInfo = propertyInfo;
if (!propertyInfo.PropertyType.IsEnum)
throw new ArgumentException("Property must be an enum.", "propertyInfo");
m_Label = new GUIContent(label ?? ObjectNames.NicifyVariableName(propertyInfo.Name));
Add(new IMGUIContainer(OnGUIHandler));
}
void OnGUIHandler()
{
var entries = (Enum) m_PropertyInfo.GetValue(m_Node, null);
var value = (int)m_PropertyInfo.GetValue(m_Node, null);
using (var changeCheckScope = new EditorGUI.ChangeCheckScope())
{
int count = (int)SlotValueHelper.GetChannelCount(m_Node.FindSlot<MaterialSlot>(0).concreteValueType);
popupEntries = new string[count];
string[] enumNames = Enum.GetNames(entries.GetType());
for (int i = 0; i < popupEntries.Length; i++)
popupEntries[i] = enumNames[i];
value = EditorGUILayout.Popup(m_Label, value, popupEntries);
if (changeCheckScope.changed)
{
m_Node.owner.owner.RegisterCompleteObjectUndo("Change " + m_Node.name);
m_PropertyInfo.SetValue(m_Node, value, null);
}
}
}
}
}

3
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Controls/ChannelEnumControl.cs.meta


fileFormatVersion: 2
guid: 74fdde12d8253bd4c874acc555be0585
timeCreated: 1507817885
正在加载...
取消
保存