SurfaceShaderINParentNode.cs 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. // Amplify Shader Editor - Visual Shader Editing Tool
  2. // Copyright (c) Amplify Creations, Lda <info@amplify.pt>
  3. using System;
  4. using UnityEngine;
  5. namespace AmplifyShaderEditor
  6. {
  7. [Serializable]
  8. public class SurfaceShaderINParentNode : ParentNode
  9. {
  10. [SerializeField]
  11. protected SurfaceInputs m_currentInput;
  12. [SerializeField]
  13. protected string m_currentInputValueStr;
  14. [SerializeField]
  15. protected string m_currentInputDecStr;
  16. protected override void CommonInit( int uniqueId )
  17. {
  18. base.CommonInit( uniqueId );
  19. m_currentInput = SurfaceInputs.UV_COORDS;
  20. m_textLabelWidth = 65;
  21. m_customPrecision = true;
  22. }
  23. public override void DrawProperties()
  24. {
  25. base.DrawProperties();
  26. DrawPrecisionProperty();
  27. }
  28. //This needs to be called on the end of the CommonInit on all children
  29. protected void InitialSetup()
  30. {
  31. m_currentInputValueStr = Constants.InputVarStr + "." + UIUtils.GetInputValueFromType( m_currentInput );
  32. string outputName = "Out";
  33. switch ( m_currentInput )
  34. {
  35. case SurfaceInputs.DEPTH:
  36. {
  37. AddOutputPort( WirePortDataType.FLOAT, outputName );
  38. }
  39. break;
  40. case SurfaceInputs.UV_COORDS:
  41. {
  42. outputName = "UV";
  43. AddOutputVectorPorts( WirePortDataType.FLOAT2, outputName );
  44. }
  45. break;
  46. case SurfaceInputs.UV2_COORDS:
  47. {
  48. outputName = "UV";
  49. AddOutputVectorPorts( WirePortDataType.FLOAT2, outputName );
  50. }
  51. break;
  52. case SurfaceInputs.VIEW_DIR:
  53. {
  54. outputName = "XYZ";
  55. AddOutputVectorPorts( WirePortDataType.FLOAT3, outputName );
  56. }
  57. break;
  58. case SurfaceInputs.COLOR:
  59. {
  60. outputName = "RGBA";
  61. AddOutputVectorPorts( WirePortDataType.FLOAT4, outputName );
  62. }
  63. break;
  64. case SurfaceInputs.SCREEN_POS:
  65. {
  66. outputName = "XYZW";
  67. AddOutputVectorPorts( WirePortDataType.FLOAT4, outputName );
  68. }
  69. break;
  70. case SurfaceInputs.WORLD_POS:
  71. {
  72. outputName = "XYZ";
  73. AddOutputVectorPorts( WirePortDataType.FLOAT3, outputName );
  74. }
  75. break;
  76. case SurfaceInputs.WORLD_REFL:
  77. {
  78. outputName = "XYZ";
  79. AddOutputVectorPorts( WirePortDataType.FLOAT3, outputName );
  80. }
  81. break;
  82. case SurfaceInputs.WORLD_NORMAL:
  83. {
  84. outputName = "XYZ";
  85. AddOutputVectorPorts( WirePortDataType.FLOAT3, outputName );
  86. }
  87. break;
  88. }
  89. }
  90. public override string GenerateShaderForOutput( int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalVar )
  91. {
  92. dataCollector.AddToInput( UniqueId, m_currentInput, UIUtils.CurrentWindow.CurrentGraph.CurrentPrecision );
  93. switch ( m_currentInput )
  94. {
  95. case SurfaceInputs.VIEW_DIR:
  96. case SurfaceInputs.WORLD_REFL:
  97. case SurfaceInputs.WORLD_NORMAL:
  98. {
  99. dataCollector.AddToInput( UniqueId, SurfaceInputs.INTERNALDATA, addSemiColon: false );
  100. }
  101. break;
  102. case SurfaceInputs.WORLD_POS:
  103. case SurfaceInputs.DEPTH:
  104. case SurfaceInputs.UV_COORDS:
  105. case SurfaceInputs.UV2_COORDS:
  106. case SurfaceInputs.COLOR:
  107. case SurfaceInputs.SCREEN_POS: break;
  108. };
  109. return GetOutputVectorItem( 0, outputId, m_currentInputValueStr );
  110. }
  111. }
  112. }