You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
57 lines
1.9 KiB
57 lines
1.9 KiB
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using UnityEditor.ShaderGraph.Drawing.Controls;
|
|
using UnityEngine;
|
|
using UnityEditor.Graphing;
|
|
using UnityEditor.ShaderGraph.Internal;
|
|
|
|
namespace UnityEditor.ShaderGraph
|
|
{
|
|
[Title("Input", "Basic", "Float")]
|
|
class Vector1Node : AbstractMaterialNode, IGeneratesBodyCode, IPropertyFromNode
|
|
{
|
|
[SerializeField]
|
|
private float m_Value = 0;
|
|
|
|
const string kInputSlotXName = "X";
|
|
const string kOutputSlotName = "Out";
|
|
|
|
public const int InputSlotXId = 1;
|
|
public const int OutputSlotId = 0;
|
|
|
|
public Vector1Node()
|
|
{
|
|
name = "Float";
|
|
synonyms = new string[] { "Vector 1", "1", "v1", "vec1", "scalar" };
|
|
UpdateNodeAfterDeserialization();
|
|
}
|
|
|
|
public sealed override void UpdateNodeAfterDeserialization()
|
|
{
|
|
AddSlot(new Vector1MaterialSlot(InputSlotXId, kInputSlotXName, kInputSlotXName, SlotType.Input, m_Value));
|
|
AddSlot(new Vector1MaterialSlot(OutputSlotId, kOutputSlotName, kOutputSlotName, SlotType.Output, 0));
|
|
RemoveSlotsNameNotMatching(new[] { OutputSlotId, InputSlotXId });
|
|
}
|
|
|
|
public void GenerateNodeCode(ShaderStringBuilder sb, GenerationMode generationMode)
|
|
{
|
|
var inputValue = GetSlotValue(InputSlotXId, generationMode);
|
|
sb.AppendLine(string.Format("$precision {0} = {1};", GetVariableNameForSlot(OutputSlotId), inputValue));
|
|
}
|
|
|
|
public AbstractShaderProperty AsShaderProperty()
|
|
{
|
|
var slot = FindInputSlot<Vector1MaterialSlot>(InputSlotXId);
|
|
return new Vector1ShaderProperty { value = slot.value };
|
|
}
|
|
|
|
public override void OnAfterDeserialize()
|
|
{
|
|
base.OnAfterDeserialize();
|
|
|
|
name = "Float";
|
|
}
|
|
|
|
int IPropertyFromNode.outputSlotId { get { return OutputSlotId; } }
|
|
}
|
|
}
|