浏览代码

Remove all legacy matrices from Shader Graph (#1652)

* Removed all legacy matrices from Shader Graph
* Change None enum entry to -1
* Fixes for PR
/main
GitHub 6 年前
当前提交
f0c6fbeb
共有 4 个文件被更改,包括 52 次插入19 次删除
  1. 1
      com.unity.shadergraph/CHANGELOG.md
  2. 62
      com.unity.shadergraph/Editor/Data/Nodes/Input/Matrix/TransformationMatrixNode.cs
  3. 2
      com.unity.shadergraph/Editor/Data/Nodes/Input/Scene/CameraNode.cs
  4. 6
      com.unity.shadergraph/Editor/Data/Util/MatrixNames.cs

1
com.unity.shadergraph/CHANGELOG.md


- If the current render pipeline is not compatible, master nodes now display an error badge.
- The preview shader now only considers the current render pipeline. Because of this there is less code to compile, and therefore the preview shader will compile faster.
- When you rename a shader graph or sub shader graph locally on your disk, the title of the Shader Graph window, black board, and preview also updates.
- Removed legacy matrices from Transfomation Matrix node.
- The Lightweight PBR subshader now normalizes normal, tangent, and view direction correctly.
- Texture 2D Array and Texture 3D nodes can no longer be used in the vertex shader.
- Shader graphs using alpha clip now generate correct depth and shadow passes.

62
com.unity.shadergraph/Editor/Data/Nodes/Input/Matrix/TransformationMatrixNode.cs


{
public enum TransformationMatrixType
{
None = -1,
ModelView,
View,
Projection,

WorldToObject
};
public enum UnityMatrixType
{
Model,
InverseModel,
View,
InverseView,
Projection,
InverseProjection,
ViewProjection,
InverseViewProjection
}
static Dictionary<TransformationMatrixType, string> m_matrixList = new Dictionary<TransformationMatrixType, string>
static Dictionary<UnityMatrixType, string> m_MatrixList = new Dictionary<UnityMatrixType, string>
{TransformationMatrixType.ModelView, "UNITY_MATRIX_MV"},
{TransformationMatrixType.View, "UNITY_MATRIX_V"},
{TransformationMatrixType.Projection, "UNITY_MATRIX_P"},
{TransformationMatrixType.ViewProjection, "UNITY_MATRIX_VP"},
{TransformationMatrixType.TransposeModelView, "UNITY_MATRIX_T_MV"},
{TransformationMatrixType.InverseTransposeModelView, "UNITY_MATRIX_IT_MV"},
{TransformationMatrixType.ObjectToWorld, "UNITY_MATRIX_M"},
{TransformationMatrixType.WorldToObject, "UNITY_MATRIX_I_M"},
{UnityMatrixType.Model, "UNITY_MATRIX_M"},
{UnityMatrixType.InverseModel, "UNITY_MATRIX_I_M"},
{UnityMatrixType.View, "UNITY_MATRIX_V"},
{UnityMatrixType.InverseView, "UNITY_MATRIX_I_V"},
{UnityMatrixType.Projection, "UNITY_MATRIX_P"},
{UnityMatrixType.InverseProjection, "UNITY_MATRIX_I_P"},
{UnityMatrixType.ViewProjection, "UNITY_MATRIX_VP"},
{UnityMatrixType.InverseViewProjection, "UNITY_MATRIX_I_VP"},
};
static Dictionary<TransformationMatrixType, UnityMatrixType> m_MatrixUpgrade = new Dictionary<TransformationMatrixType, UnityMatrixType>
{
{TransformationMatrixType.ModelView, UnityMatrixType.Model},
{TransformationMatrixType.View, UnityMatrixType.View},
{TransformationMatrixType.Projection, UnityMatrixType.Projection},
{TransformationMatrixType.ViewProjection, UnityMatrixType.ViewProjection},
{TransformationMatrixType.TransposeModelView, UnityMatrixType.Model},
{TransformationMatrixType.InverseTransposeModelView, UnityMatrixType.Model},
{TransformationMatrixType.ObjectToWorld, UnityMatrixType.Model},
{TransformationMatrixType.WorldToObject, UnityMatrixType.InverseModel},
[SerializeField]
private UnityMatrixType m_MatrixType = UnityMatrixType.Model;
private const int kOutputSlotId = 0;
private const string kOutputSlotName = "Out";

public TransformationMatrixType matrix
public UnityMatrixType matrixType
get { return m_matrix; }
get { return m_MatrixType; }
if (m_matrix == value)
if (m_MatrixType == value)
m_matrix = value;
m_MatrixType = value;
Dirty(ModificationScope.Graph);
}
}

public sealed override void UpdateNodeAfterDeserialization()
{
if(m_matrix != TransformationMatrixType.None)
{
m_MatrixType = m_MatrixUpgrade[m_matrix];
m_matrix = TransformationMatrixType.None;
}
AddSlot(new Matrix4MaterialSlot(kOutputSlotId, kOutputSlotName, kOutputSlotName, SlotType.Output));
RemoveSlotsNameNotMatching(new[] { kOutputSlotId });
}

return m_matrixList[matrix].ToString(CultureInfo.InvariantCulture);
return m_MatrixList[matrixType].ToString(CultureInfo.InvariantCulture);
}
public bool RequiresVertexColor()

2
com.unity.shadergraph/Editor/Data/Nodes/Input/Scene/CameraNode.cs


switch (slotId)
{
case OutputSlot1Id:
return "-1 * mul(unity_ObjectToWorld, UNITY_MATRIX_IT_MV [2].xyz)";
return "-1 * mul(unity_ObjectToWorld, transpose(mul(UNITY_MATRIX_I_M, UNITY_MATRIX_I_V)) [2].xyz)";
case OutputSlot2Id:
return "unity_OrthoParams.w";
case OutputSlot3Id:

6
com.unity.shadergraph/Editor/Data/Util/MatrixNames.cs


public const string View = "UNITY_MATRIX_V";
public const string ViewInverse = "UNITY_MATRIX_I_V";
public const string Projection = "UNITY_MATRIX_P";
public const string ProjectionInverse = "UNITY_MATRIX_I_P";
public const string ModelView = "UNITY_MATRIX_MV";
public const string ModelViewTransposed = "UNITY_MATRIX_T_MV";
public const string ModelViewInverseTransposed = "UNITY_MATRIX_IT_MV";
public const string ModelViewProjection = "UNITY_MATRIX_MVP";
public const string ViewProjectionInverse = "UNITY_MATRIX_I_VP";
}
}
正在加载...
取消
保存