|
|
|
|
|
|
using System.Reflection; |
|
|
|
using UnityEngine; |
|
|
|
using UnityEditor.Graphing; |
|
|
|
using UnityEditor.ShaderGraph.Drawing.Controls; |
|
|
|
public enum TextureType |
|
|
|
{ |
|
|
|
Default, |
|
|
|
Normal |
|
|
|
}; |
|
|
|
|
|
|
|
[Title("Input/Texture/Texture 2D")] |
|
|
|
public class Texture2DNode : AbstractMaterialNode, IGeneratesBodyCode, IMayRequireMeshUV |
|
|
|
{ |
|
|
|
|
|
|
UpdateNodeAfterDeserialization(); |
|
|
|
} |
|
|
|
|
|
|
|
[SerializeField] |
|
|
|
private TextureType m_TextureType = TextureType.Default; |
|
|
|
|
|
|
|
[EnumControl("Type")] |
|
|
|
public TextureType textureType |
|
|
|
{ |
|
|
|
get { return m_TextureType; } |
|
|
|
set |
|
|
|
{ |
|
|
|
if (m_TextureType == value) |
|
|
|
return; |
|
|
|
|
|
|
|
m_TextureType = value; |
|
|
|
if (onModified != null) |
|
|
|
{ |
|
|
|
onModified(this, ModificationScope.Graph); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public sealed override void UpdateNodeAfterDeserialization() |
|
|
|
{ |
|
|
|
AddSlot(new Vector4MaterialSlot(OutputSlotRGBAId, kOutputSlotRGBAName, kOutputSlotRGBAName, SlotType.Output, Vector4.zero)); |
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
visitor.AddShaderChunk(result, true); |
|
|
|
|
|
|
|
if (textureType == TextureType.Normal) |
|
|
|
visitor.AddShaderChunk(string.Format("{0}.rgb = UnpackNormal({0});", GetVariableNameForSlot(OutputSlotRGBAId)), true); |
|
|
|
|
|
|
|
visitor.AddShaderChunk(string.Format("{0} {1} = {2}.r;", precision, GetVariableNameForSlot(OutputSlotRId), GetVariableNameForSlot(OutputSlotRGBAId)), true); |
|
|
|
visitor.AddShaderChunk(string.Format("{0} {1} = {2}.g;", precision, GetVariableNameForSlot(OutputSlotGId), GetVariableNameForSlot(OutputSlotRGBAId)), true); |
|
|
|
visitor.AddShaderChunk(string.Format("{0} {1} = {2}.b;", precision, GetVariableNameForSlot(OutputSlotBId), GetVariableNameForSlot(OutputSlotRGBAId)), true); |
|
|
|