浏览代码

New node settings. Moved the createsettingselement to the master node

/main
Martin Thorzen 7 年前
当前提交
cfd61180
共有 9 个文件被更改,包括 72 次插入184 次删除
  1. 17
      HDPipeline/HDUnlitSubShader.cs
  2. 10
      com.unity.shadergraph/Editor/Data/MasterNodes/ISubShader.cs
  3. 41
      com.unity.shadergraph/Editor/Data/MasterNodes/PBRMasterNode.cs
  4. 13
      com.unity.shadergraph/Editor/Data/MasterNodes/UnlitMasterNode.cs
  5. 25
      com.unity.shadergraph/Editor/Data/Nodes/MasterNode.cs
  6. 11
      com.unity.shadergraph/Editor/Drawing/Views/PBRSettingsView.cs.meta
  7. 11
      com.unity.shadergraph/Editor/Drawing/Views/UnlitSettingsView.cs.meta
  8. 76
      com.unity.shadergraph/Editor/Drawing/Views/PBRSettingsView.cs
  9. 52
      com.unity.shadergraph/Editor/Drawing/Views/UnlitSettingsView.cs

17
HDPipeline/HDUnlitSubShader.cs


using System.IO;
using System.Linq;
using UnityEditor.Graphing;
using UnityEngine.Experimental.UIElements;
namespace UnityEditor.ShaderGraph
{

if (slot != null)
slots.Add(slot);
}
GraphUtil.GenerateSurfaceDescriptionStruct(surfaceDescriptionStruct, slots, true);
var usedSlots = new List<MaterialSlot>();

foreach (var slot in usedSlots)
{
surfaceOutputRemap.AddShaderChunk(slot.shaderOutputName
+ " = surf."
+ slot.shaderOutputName + ";", true);
+ " = surf."
+ slot.shaderOutputName + ";", true);
}
if (!File.Exists(templateLocation))

resultPass = resultPass.Replace("${LOD}", "" + materialOptions.lod);
return resultPass;
}
public IMasterNode owner { get; set; }
public string GetSubshader(IMasterNode inMasterNode, GenerationMode mode)
{

subShader.AddShaderChunk("}", true);
return subShader.GetShaderString(0);
}
public VisualElement CreateSettingsElement()
{
return null;
}
public void UpdateAfterDeserialization()
{
}
}
}

10
com.unity.shadergraph/Editor/Data/MasterNodes/ISubShader.cs


using System;
using UnityEditor.Graphing;
using UnityEngine.Experimental.UIElements;
namespace UnityEditor.ShaderGraph {
namespace UnityEditor.ShaderGraph
{
IMasterNode owner { get; set; }
VisualElement CreateSettingsElement();
void UpdateAfterDeserialization();
}
}

41
com.unity.shadergraph/Editor/Data/MasterNodes/PBRMasterNode.cs


{
[Serializable]
[Title("Master", "PBR")]
public class PBRMasterNode : MasterNode<IPBRSubShader>, IMayRequireNormal, IHasSettings
public class PBRMasterNode : MasterNode<IPBRSubShader>, IMayRequireNormal
{
public const string AlbedoSlotName = "Albedo";
public const string NormalSlotName = "Normal";

}
[SerializeField]
private Model m_Model = Model.Metallic;
Model m_Model = Model.Metallic;
[EnumControl("Workflow")]
public Model model

}
[SerializeField]
private SurfaceType m_SurfaceType;
SurfaceType m_SurfaceType;
[SerializeField]
bool m_SurfaceTypeHasValue;
[EnumControl("Surface")]
public SurfaceType surfaceType
public SurfaceType? surfaceType
get { return m_SurfaceType; }
get { return m_SurfaceTypeHasValue ? (SurfaceType?)m_SurfaceType : null; }
m_SurfaceType = value;
Dirty(ModificationScope.Graph);
if (value.HasValue)
m_SurfaceType = value.Value;
m_SurfaceTypeHasValue = value.HasValue;
private AlphaMode m_AlphaMode;
AlphaMode m_AlphaMode;
[SerializeField]
bool m_AlphaModeHasValue;
[EnumControl("Blend")]
public AlphaMode alphaMode
public AlphaMode? alphaMode
get { return m_AlphaMode; }
get { return m_AlphaModeHasValue ? (AlphaMode?)m_AlphaMode : null; }
m_AlphaMode = value;
Dirty(ModificationScope.Graph);
if (value.HasValue)
m_AlphaMode = value.Value;
m_AlphaModeHasValue = value.HasValue;
private bool m_TwoSided;
bool m_TwoSided;
[ToggleControl("Two Sided")]
public ToggleData twoSided

List<ISlot> slots = new List<ISlot>();
GetSlots(slots);
return slots.OfType<IMayRequireNormal>().Aggregate(NeededCoordinateSpace.None, (mask, node) => mask | node.RequiresNormal());
}
public VisualElement CreateSettingsElement()
{
return new PBRSettingsView(this);
}
}
}

13
com.unity.shadergraph/Editor/Data/MasterNodes/UnlitMasterNode.cs


{
[Serializable]
[Title("Master", "Unlit")]
public class UnlitMasterNode : MasterNode<IUnlitSubShader>, IHasSettings
public class UnlitMasterNode : MasterNode<IUnlitSubShader>
{
public const string ColorSlotName = "Color";
public const string AlphaSlotName = "Alpha";

[SerializeField]
private SurfaceType m_SurfaceType;
SurfaceType m_SurfaceType;
[EnumControl("Surface")]
public SurfaceType surfaceType

}
[SerializeField]
private AlphaMode m_AlphaMode;
AlphaMode m_AlphaMode;
[EnumControl("Blend")]
public AlphaMode alphaMode

}
[SerializeField]
private bool m_TwoSided;
bool m_TwoSided;
[ToggleControl("Two Sided")]
public ToggleData twoSided

AlphaSlotId,
AlphaThresholdSlotId
});
}
public VisualElement CreateSettingsElement()
{
return new UnlitSettingsView(this);
}
}
}

25
com.unity.shadergraph/Editor/Data/Nodes/MasterNode.cs


using UnityEditor.Graphing;
using UnityEditor.Graphing.Util;
using UnityEngine;
using UnityEngine.Experimental.UIElements;
public abstract class MasterNode<T> : AbstractMaterialNode, IMasterNode where T : class, ISubShader
public abstract class MasterNode<T> : AbstractMaterialNode, IMasterNode, IHasSettings
where T : class, ISubShader
{
[NonSerialized]
List<T> m_SubShaders = new List<T>();

}
}
}
foreach (var subShader in subShaders)
{
subShader.owner = this;
subShader.UpdateAfterDeserialization();
}
}
public VisualElement CreateSettingsElement()
{
// do staff
var container = new VisualElement();
foreach (var subShader in subShaders)
{
var settingsElement = subShader.CreateSettingsElement();
if (settingsElement != null)
container.Add(settingsElement);
}
//return new MasterSettingsView(this);
return container;
}
}
}

11
com.unity.shadergraph/Editor/Drawing/Views/PBRSettingsView.cs.meta


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

11
com.unity.shadergraph/Editor/Drawing/Views/UnlitSettingsView.cs.meta


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

76
com.unity.shadergraph/Editor/Drawing/Views/PBRSettingsView.cs


using System;
using System.Linq;
using UnityEditor.Experimental.UIElements;
using UnityEditor.Graphing;
using UnityEditor.Graphing.Util;
using UnityEngine;
using UnityEngine.Experimental.UIElements;
namespace UnityEditor.ShaderGraph.Drawing
{
public class PBRSettingsView : VisualElement
{
PBRMasterNode m_Node;
public PBRSettingsView(INode node)
{
AddStyleSheetPath("Styles/PBRSettings");
m_Node = (PBRMasterNode)node;
this.Add(new VisualElement { name = "container" }, (container) =>
{
container.Add(new VisualElement(), (row) =>
{
row.AddToClassList("row");
row.Add(new Label("Model"), (label) =>
{
label.AddToClassList("label");
});
row.Add(new EnumField(PBRMasterNode.Model.Metallic), (enumField) =>
{
enumField.value = m_Node.model;
enumField.OnValueChanged(ChangeModel);
enumField.AddToClassList("enumcontainer");
});
});
container.Add(new VisualElement(), (row) =>
{
row.AddToClassList("row");
row.Add(new Label("Alpha Mode"), (label) =>
{
label.AddToClassList("label");
});
row.Add(new EnumField(AlphaMode.Additive), (enumField) =>
{
enumField.value = m_Node.alphaMode;
enumField.OnValueChanged(ChangeAlphaMode);
enumField.AddToClassList("enumcontainer");
});
});
});
}
void ChangeModel(ChangeEvent<Enum> evt)
{
if (Equals(m_Node.model, evt.newValue))
return;
m_Node.owner.owner.RegisterCompleteObjectUndo("Enum Change");
m_Node.model = (PBRMasterNode.Model)evt.newValue;
}
void ChangeAlphaMode(ChangeEvent<Enum> evt)
{
if (Equals(m_Node.alphaMode, evt.newValue))
return;
m_Node.owner.owner.RegisterCompleteObjectUndo("Alpha Mode Change");
m_Node.alphaMode = (AlphaMode)evt.newValue;
}
}
}

52
com.unity.shadergraph/Editor/Drawing/Views/UnlitSettingsView.cs


using System;
using System.Linq;
using UnityEditor.Experimental.UIElements;
using UnityEditor.Graphing;
using UnityEditor.Graphing.Util;
using UnityEngine;
using UnityEngine.Experimental.UIElements;
namespace UnityEditor.ShaderGraph.Drawing
{
public class UnlitSettingsView : VisualElement
{
VisualElement m_Container;
EnumField m_AlphaMode;
UnlitMasterNode m_Node;
public UnlitSettingsView(INode node)
{
AddStyleSheetPath("Styles/UnlitSettings");
m_Node = (UnlitMasterNode)node;
this.Add(new VisualElement{ name="container" }, (container) =>
{
container.Add( new VisualElement(), (row) =>
{
row.AddToClassList("row");
row.Add(new Label { text = "Alpha Mode"}, (label) =>
{
label.AddToClassList("label");
});
row.Add(new EnumField(AlphaMode.Additive), (enumField) =>
{
enumField.AddToClassList("enumcontainer");
enumField.value = m_Node.alphaMode;
enumField.OnValueChanged(ChangeAlphaMode);
});
});
} );
}
void ChangeAlphaMode(ChangeEvent<Enum> evt)
{
if (Equals(m_Node.alphaMode, evt.newValue))
return;
m_Node.owner.owner.RegisterCompleteObjectUndo("Alpha Mode Change");
m_Node.alphaMode = (AlphaMode)evt.newValue;
}
}
}
正在加载...
取消
保存