浏览代码

Fixes to Screen Position Node

- Added Raw type (no divide by w, needed for uv projection)
- Removed unused method
- Switched output to vec4
- Renamed slot vars
- Fixed output
/main
Matt Dean 7 年前
当前提交
627c384a
共有 1 个文件被更改,包括 17 次插入18 次删除
  1. 35
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/Geometry/ScreenPositionNode.cs

35
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/Geometry/ScreenPositionNode.cs


public enum ScreenSpaceType
{
Default,
Raw,
Center,
Tiled
};

}
}
string GetCurrentType()
{
return System.Enum.GetName(typeof(ScreenSpaceType), m_ScreenSpaceType);
}
private const int kOutputSlot1Id = 0;
private const string kOutputSlot1Name = "Out";
private const int kOutputSlotId = 0;
private const string kOutputSlotName = "Out";
public override bool hasPreview { get { return true; } }
public override PreviewMode previewMode

public sealed override void UpdateNodeAfterDeserialization()
{
AddSlot(new Vector2MaterialSlot(kOutputSlot1Id, kOutputSlot1Name, kOutputSlot1Name, SlotType.Output, Vector2.zero));
RemoveSlotsNameNotMatching(new[] { kOutputSlot1Id });
}
public override string GetVariableNameForSlot(int slotId)
{
return ShaderGeneratorNames.ScreenPosition;
AddSlot(new Vector4MaterialSlot(kOutputSlotId, kOutputSlotName, kOutputSlotName, SlotType.Output, Vector4.zero));
RemoveSlotsNameNotMatching(new[] { kOutputSlotId });
}
public void GenerateNodeCode(ShaderGenerator visitor, GenerationMode generationMode)

case ScreenSpaceType.Raw:
visitor.AddShaderChunk(string.Format("{0}4 {1} = {2};", precision, GetVariableNameForSlot(kOutputSlotId),
ShaderGeneratorNames.ScreenPosition), true);
break;
visitor.AddShaderChunk(string.Format("{0} = {1};", ShaderGeneratorNames.ScreenPosition, "float4((" + ShaderGeneratorNames.ScreenPosition + ".xy / " + ShaderGeneratorNames.ScreenPosition + ".w) * 2 - 1, 0, 0)"), false);
visitor.AddShaderChunk(string.Format("{0}4 {1} = {2};", precision, GetVariableNameForSlot(kOutputSlotId),
"float4((" + ShaderGeneratorNames.ScreenPosition + ".xy / " + ShaderGeneratorNames.ScreenPosition + ".w) * 2 - 1, 0, 0)"), true);
visitor.AddShaderChunk(string.Format("{0} = {1};", ShaderGeneratorNames.ScreenPosition, "float4((" + ShaderGeneratorNames.ScreenPosition + ".xy / " + ShaderGeneratorNames.ScreenPosition + ".w) * 2 - 1, 0, 0)"), false);
visitor.AddShaderChunk(string.Format("{0} = {1};", ShaderGeneratorNames.ScreenPosition, "float4(" + ShaderGeneratorNames.ScreenPosition + ".x * _ScreenParams.x / _ScreenParams.y, " + ShaderGeneratorNames.ScreenPosition + ".y, 0, 0)"), false);
visitor.AddShaderChunk(string.Format("{0}4 {1} = {2};", precision, GetVariableNameForSlot(kOutputSlotId),
"float4((" + ShaderGeneratorNames.ScreenPosition + ".xy / " + ShaderGeneratorNames.ScreenPosition + ".w) * 2 - 1, 0, 0)"), true);
visitor.AddShaderChunk(string.Format("{0} = {1};", GetVariableNameForSlot(kOutputSlotId),
"float4(" + ShaderGeneratorNames.ScreenPosition + ".x * _ScreenParams.x / _ScreenParams.y, " + ShaderGeneratorNames.ScreenPosition + ".y, 0, 0)"), true);
visitor.AddShaderChunk(string.Format("{0} = {1};", ShaderGeneratorNames.ScreenPosition, "float4(" + ShaderGeneratorNames.ScreenPosition + ".xy / " + ShaderGeneratorNames.ScreenPosition + ".w, 0, 0)"), false);
visitor.AddShaderChunk(string.Format("{0}4 {1} = {2};", precision, GetVariableNameForSlot(kOutputSlotId),
"float4(" + ShaderGeneratorNames.ScreenPosition + ".xy / " + ShaderGeneratorNames.ScreenPosition + ".w, 0, 0)"), true);
break;
}
}

正在加载...
取消
保存