浏览代码

Fixed math in remap node

Added second output for screenPos that is pure XY UVs
/main
Andre McGrail 8 年前
当前提交
22cf545d
共有 2 个文件被更改,包括 22 次插入5 次删除
  1. 20
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Input/SceneData/ScreenPosNode.cs
  2. 7
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Math/Range/RemapNode.cs

20
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Input/SceneData/ScreenPosNode.cs


UpdateNodeAfterDeserialization();
}
private const int kOutputSlotId = 0;
private const string kOutputSlotName = "ScreenPos";
private const int kOutputSlot1Id = 0;
private const string kOutputSlot1Name = "Raw ScreenPos";
private const int kOutputSlot2Id = 1;
private const string kOutputSlot2Name = "Normalized";
public override bool hasPreview { get { return true; } }
public override PreviewMode previewMode

public sealed override void UpdateNodeAfterDeserialization()
{
AddSlot(new MaterialSlot(kOutputSlotId, kOutputSlotName, kOutputSlotName, SlotType.Output, SlotValueType.Vector4, Vector4.zero));
RemoveSlotsNameNotMatching(new[] { kOutputSlotId });
AddSlot(new MaterialSlot(kOutputSlot1Id, kOutputSlot1Name, kOutputSlot1Name, SlotType.Output, SlotValueType.Vector4, Vector4.zero));
AddSlot(new MaterialSlot(kOutputSlot2Id, kOutputSlot2Name, kOutputSlot2Name, SlotType.Output, SlotValueType.Vector3, Vector3.zero));
RemoveSlotsNameNotMatching(new[] { kOutputSlot1Id, kOutputSlot2Id });
string returnString = "";
switch (slotId){
case 0:
returnString = ShaderGeneratorNames.ScreenPosition;
break;
case 1:
returnString = "float3(" + ShaderGeneratorNames.ScreenPosition + ".xy / " + ShaderGeneratorNames.ScreenPosition + ".w, 0)";
break;
}
return ShaderGeneratorNames.ScreenPosition;
}

7
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Math/Range/RemapNode.cs


public void GenerateNodeFunction(ShaderGenerator visitor, GenerationMode generationMode)
{
//new = arg3.x + (arg1 - arg2.x) * (arg3.y - arg3.x) / (arg2.y - arg2.x)
//low2 + (value - low1) * (high2 - low2) / (high1 - low1)
//old = arg1 * ((arg3.y - arg3.x) / (arg2.y - arg2.x)) + arg3.x
outputString.AddShaderChunk ("return arg1 * ((arg3.y - arg3.x) / (arg2.y - arg2.x)) + arg3.x;", false);
outputString.AddShaderChunk ("return arg3.x + (arg1 - arg2.x) * (arg3.y - arg3.x) / (arg2.y - arg2.x);", false);
outputString.Deindent ();
outputString.AddShaderChunk ("}", false);

正在加载...
取消
保存