浏览代码

Merge branch 'hackweek2017' of https://github.com/stramit/MaterialGraph into hackweek2017

/main
MingWai 8 年前
当前提交
bdfd3b5f
共有 8 个文件被更改,包括 217 次插入22 次删除
  1. 2
      MaterialGraphProject/Assets/NewNodes/WIP/POMNode.cs
  2. 1
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/MaterialGraphPresenter.cs
  3. 2
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/AbstractMaterialNode.cs
  4. 26
      MaterialGraphProject/Assets/Vlad/TextureAssetNode.cs
  5. 52
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/SamplerAssetPresenter.cs
  6. 12
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/SamplerAssetPresenter.cs.meta
  7. 136
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Input/Texture/SamplerAssetNode.cs
  8. 8
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Input/Texture/SamplerAssetNode.cs.meta

2
MaterialGraphProject/Assets/NewNodes/WIP/POMNode.cs


}
protected virtual MaterialSlot GetTextureSlot()
{
return new MaterialSlot(TextureSlotId, GetTextureSlotName(), kTextureSlotShaderName, SlotType.Input, SlotValueType.Texture2D, Vector4.zero);
return new MaterialSlot(TextureSlotId, GetTextureSlotName(), kTextureSlotShaderName, SlotType.Input, SlotValueType.Sampler2D, Vector4.zero);
}
protected virtual MaterialSlot GetOutputSlot()

1
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/MaterialGraphPresenter.cs


typeMapper[typeof(GradientNode)] = typeof(GradientNodePresenter);
typeMapper[typeof(ScatterNode)] = typeof(ScatterNodePresenter);
typeMapper[typeof(TextureNode)] = typeof(TextureNodePresenter);
typeMapper[typeof(SamplerAssetNode)] = typeof(SamplerAssetNodePresenter);
typeMapper[typeof(TextureSamplerNode)] = typeof(TextureSamplerNodePresenter);
typeMapper[typeof(TextureAssetNode)] = typeof(TextureAssetNodePresenter);
typeMapper[typeof(TextureLODNode)] = typeof(TextureLODNodePresenter);

2
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/AbstractMaterialNode.cs


return ConcreteSlotValueType.Matrix4;
case SlotValueType.SamplerState:
return ConcreteSlotValueType.SamplerState;
case SlotValueType.Sampler2D:
return ConcreteSlotValueType.Sampler2D;
}
return ConcreteSlotValueType.Error;
}

26
MaterialGraphProject/Assets/Vlad/TextureAssetNode.cs


[Title("Input/Texture/Texture Asset")]
public class TextureAssetNode : PropertyNode
{
protected const string outputTexture2D_name = "Texture2D";
protected const string outputSampler2D_name = "Sampler2D";
protected const string textureName = "Texture";
public const int outputTexture2D_id = 0;
public const int outputSampler2D_id = 1;
public const int textureID = 0;
[SerializeField]
private string m_SerializedTexture;

public sealed override void UpdateNodeAfterDeserialization()
{
AddSlot(new MaterialSlot(outputTexture2D_id, outputTexture2D_name, outputTexture2D_name, SlotType.Output, SlotValueType.Texture2D, Vector4.zero, false));
AddSlot(new MaterialSlot(outputSampler2D_id, outputSampler2D_name, outputSampler2D_name, SlotType.Output, SlotValueType.Sampler2D, Vector4.zero, false));
AddSlot(new MaterialSlot(textureID, textureName, textureName, SlotType.Output, SlotValueType.Texture2D, Vector4.zero, false));
get { return new[] { outputTexture2D_id, outputSampler2D_id }; }
get { return new[] { textureID }; }
}
public override void CollectPreviewMaterialProperties(List<PreviewProperty> properties)

: TexturePropertyChunk.ModifiableState.NonModifiable));
}
public override void GeneratePropertyUsages(ShaderGenerator visitor, GenerationMode generationMode)
{
var slotTexture2D = FindOutputSlot<MaterialSlot>(0);

visitor.AddShaderChunk("#endif", true);
}
}
var slotSampler2D = FindOutputSlot<MaterialSlot>(1);
if (slotSampler2D != null)
{
var edgesSampler2D = owner.GetEdges(slotSampler2D.slotReference).ToList();
if (edgesSampler2D.Count > 0)
{
visitor.AddShaderChunk("sampler2D " + propertyName + ";", true);
}
}
}

m_Texture = defaultTexture
};
}
public override PropertyType propertyType { get { return PropertyType.Texture; } }

52
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/SamplerAssetPresenter.cs


using System;
using System.Collections.Generic;
using RMGUI.GraphView;
using UnityEditor.Graphing.Drawing;
using UnityEngine;
using UnityEngine.MaterialGraph;
namespace UnityEditor.MaterialGraph.Drawing
{
class SamplerAssetControlPresenter : GraphControlPresenter
{
private string[] m_TextureTypeNames;
private string[] textureTypeNames
{
get
{
if (m_TextureTypeNames == null)
m_TextureTypeNames = Enum.GetNames(typeof(TextureType));
return m_TextureTypeNames;
}
}
public override void OnGUIHandler()
{
base.OnGUIHandler();
var tNode = node as UnityEngine.MaterialGraph.SamplerAssetNode;
if (tNode == null)
return;
tNode.exposedState = (PropertyNode.ExposedState)EditorGUILayout.EnumPopup(new GUIContent("Exposed"), tNode.exposedState);
tNode.defaultTexture = EditorGUILayout.MiniThumbnailObjectField(new GUIContent("Texture"), tNode.defaultTexture, typeof(Texture), null) as Texture;
tNode.textureType = (TextureType)EditorGUILayout.Popup((int)tNode.textureType, textureTypeNames, EditorStyles.popup);
}
public override float GetHeight()
{
return 3 * (EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing) + EditorGUIUtility.standardVerticalSpacing;
}
}
[Serializable]
public class SamplerAssetNodePresenter : MaterialNodePresenter
{
protected override IEnumerable<GraphElementPresenter> GetControlData()
{
var instance = CreateInstance<SamplerAssetControlPresenter>();
instance.Initialize(node);
return new List<GraphElementPresenter> { instance };
}
}
}

12
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/SamplerAssetPresenter.cs.meta


fileFormatVersion: 2
guid: ec47786947b3100438fbe355a2a23000
timeCreated: 1495754404
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

136
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Input/Texture/SamplerAssetNode.cs


using System;
using System.Collections.Generic;
using System.Linq;
#if UNITY_EDITOR
using UnityEditor;
#endif
using UnityEngine.Graphing;
namespace UnityEngine.MaterialGraph
{
[Title("Input/Texture/Sampler Asset")]
public class SamplerAssetNode : PropertyNode
{
protected const string kOutputSlotRGBAName = "Sampler2D";
public const int OutputID = 0;
[SerializeField]
private string m_SerializedTexture;
[SerializeField]
private TextureType m_TextureType;
[Serializable]
private class TextureHelper
{
public Texture texture;
}
public override bool hasPreview { get { return false; } }
#if UNITY_EDITOR
public Texture defaultTexture
{
get
{
if (string.IsNullOrEmpty(m_SerializedTexture))
return null;
var tex = new TextureHelper();
EditorJsonUtility.FromJsonOverwrite(m_SerializedTexture, tex);
return tex.texture;
}
set
{
if (defaultTexture == value)
return;
var tex = new TextureHelper();
tex.texture = value;
m_SerializedTexture = EditorJsonUtility.ToJson(tex, true);
if (onModified != null)
{
onModified(this, ModificationScope.Node);
}
}
}
#else
public Texture defaultTexture {get; set; }
#endif
public TextureType textureType
{
get { return m_TextureType; }
set
{
if (m_TextureType == value)
return;
m_TextureType = value;
if (onModified != null)
{
onModified(this, ModificationScope.Graph);
}
}
}
public SamplerAssetNode()
{
name = "SamplerAsset";
UpdateNodeAfterDeserialization();
}
public sealed override void UpdateNodeAfterDeserialization()
{
AddSlot(new MaterialSlot(OutputID, kOutputSlotRGBAName, kOutputSlotRGBAName, SlotType.Output, SlotValueType.Sampler2D, Vector4.zero));
RemoveSlotsNameNotMatching(validSlots);
}
protected int[] validSlots
{
get { return new[] { OutputID }; }
}
public override void CollectPreviewMaterialProperties(List<PreviewProperty> properties)
{
properties.Add(GetPreviewProperty());
}
// Properties
public override void GeneratePropertyBlock(PropertyGenerator visitor, GenerationMode generationMode)
{
visitor.AddShaderProperty(
new TexturePropertyChunk(
propertyName,
description,
defaultTexture, m_TextureType,
PropertyChunk.HideState.Visible,
exposedState == ExposedState.Exposed ?
TexturePropertyChunk.ModifiableState.Modifiable
: TexturePropertyChunk.ModifiableState.NonModifiable));
}
public override void GeneratePropertyUsages(ShaderGenerator visitor, GenerationMode generationMode)
{
visitor.AddShaderChunk("sampler2D " + propertyName + ";", true);
}
public override PreviewProperty GetPreviewProperty()
{
return new PreviewProperty
{
m_Name = propertyName,
m_PropType = PropertyType.Texture,
m_Texture = defaultTexture
};
}
public override PropertyType propertyType { get { return PropertyType.Texture; } }
}
}

8
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Input/Texture/SamplerAssetNode.cs.meta


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