浏览代码

Make PBR master node be able to require normal and remove BoundVector3MaterialSlot

/main
Jens Holm 7 年前
当前提交
a83bd958
共有 3 个文件被更改,包括 10 次插入62 次删除
  1. 12
      com.unity.shadergraph/Editor/Data/MasterNodes/PBRMasterNode.cs
  2. 11
      com.unity.shadergraph/Editor/Data/Graphs/BoundVector3MaterialSlot.cs.meta
  3. 49
      com.unity.shadergraph/Editor/Data/Graphs/BoundVector3MaterialSlot.cs

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


using System;
using System.Linq;
using System.Collections.Generic;
using UnityEditor.Graphing;
using UnityEditor.ShaderGraph.Drawing.Controls;
using UnityEngine;

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

{
name = "PBR Master";
AddSlot(new ColorRGBMaterialSlot(AlbedoSlotId, AlbedoSlotName, AlbedoSlotName, SlotType.Input, Color.grey, ShaderStage.Fragment));
AddSlot(new BoundVector3MaterialSlot(NormalSlotId, NormalSlotName, NormalSlotName, new Vector3(0, 0, 1), CoordinateSpace.Tangent, ShaderStage.Fragment));
AddSlot(new NormalMaterialSlot(NormalSlotId, NormalSlotName, NormalSlotName, CoordinateSpace.Tangent, ShaderStage.Fragment));
AddSlot(new ColorRGBMaterialSlot(EmissionSlotId, EmissionSlotName, EmissionSlotName, SlotType.Input, Color.black, ShaderStage.Fragment));
if (model == Model.Metallic)
AddSlot(new Vector1MaterialSlot(MetallicSlotId, MetallicSlotName, MetallicSlotName, SlotType.Input, 0, ShaderStage.Fragment));

if (!subShaders.Any())
AddSubShader(new LightWeightPBRSubShader());
}
public NeededCoordinateSpace RequiresNormal()
{
List<ISlot> slots = new List<ISlot>();
GetSlots(slots);
return slots.OfType<IMayRequireNormal>().Aggregate(NeededCoordinateSpace.None, (mask, node) => mask | node.RequiresNormal());
}
}
}

11
com.unity.shadergraph/Editor/Data/Graphs/BoundVector3MaterialSlot.cs.meta


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

49
com.unity.shadergraph/Editor/Data/Graphs/BoundVector3MaterialSlot.cs


using System;
using UnityEditor.Graphing;
using UnityEditor.ShaderGraph.Drawing.Slots;
using UnityEngine;
using UnityEngine.Experimental.UIElements;
namespace UnityEditor.ShaderGraph
{
[Serializable]
public class BoundVector3MaterialSlot : SpaceMaterialSlot
{
[SerializeField]
private CoordinateSpace m_Space;
public BoundVector3MaterialSlot()
{
}
public BoundVector3MaterialSlot(
int slotId,
string displayName,
string shaderOutputName,
Vector3 value,
CoordinateSpace space,
ShaderStage shaderStage = ShaderStage.Dynamic,
bool hidden = false)
: base(slotId, displayName, shaderOutputName, space, shaderStage, hidden)
{
this.value = value;
}
public override VisualElement InstantiateControl()
{
return new LabelSlotControlView(space + " Space");
}
protected override string ConcreteSlotValueAsVariable(AbstractMaterialNode.OutputPrecision precision)
{
return precision + String.Format("3 ({0}, {1}, {2})", NodeUtils.FloatToShaderValue(value.x), NodeUtils.FloatToShaderValue(value.y), NodeUtils.FloatToShaderValue(value.z));
}
public override void CopyValuesFrom(MaterialSlot foundSlot)
{
var slot = foundSlot as BoundVector3MaterialSlot;
if (slot != null)
value = slot.value;
}
}
}
正在加载...
取消
保存