You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

99 lines
3.1 KiB

  1. // Amplify Shader Editor - Visual Shader Editing Tool
  2. // Copyright (c) Amplify Creations, Lda <info@amplify.pt>
  3. using System;
  4. using UnityEngine;
  5. using UnityEditor;
  6. namespace AmplifyShaderEditor
  7. {
  8. [Serializable]
  9. [NodeAttributes( "Blend Normals", "Textures", "Blend Normals" )]
  10. public class BlendNormalsNode : ParentNode
  11. {
  12. public readonly static string[] ModeListStr = { "Tangent Normals", "Reoriented Tangent Normals", "Reoriented World Normals" };
  13. public readonly static int[] ModeListInt = { 0, 1, 2 };
  14. [SerializeField]
  15. public int m_selectedMode = 0;
  16. protected override void CommonInit( int uniqueId )
  17. {
  18. base.CommonInit( uniqueId );
  19. AddInputPort( WirePortDataType.FLOAT3, false, "Normal A" );
  20. AddInputPort( WirePortDataType.FLOAT3, false, "Normal B" );
  21. AddInputPort( WirePortDataType.FLOAT3, false, "Vertex Normal" );
  22. m_inputPorts[ 2 ].Visible = false;
  23. AddOutputPort( WirePortDataType.FLOAT3, "XYZ" );
  24. m_useInternalPortData = true;
  25. m_previewShaderGUID = "bcdf750ff5f70444f98b8a3efa50dc6f";
  26. }
  27. public override string GenerateShaderForOutput( int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalvar )
  28. {
  29. if( !( dataCollector.IsTemplate && dataCollector.IsSRP ) )
  30. dataCollector.AddToIncludes( UniqueId, Constants.UnityStandardUtilsLibFuncs );
  31. string _inputA = m_inputPorts[ 0 ].GeneratePortInstructions( ref dataCollector );
  32. string _inputB = m_inputPorts[ 1 ].GeneratePortInstructions( ref dataCollector );
  33. string result = "BlendNormals( " + _inputA + " , " + _inputB + " )";
  34. if( dataCollector.IsTemplate && dataCollector.IsSRP )
  35. {
  36. switch( m_selectedMode )
  37. {
  38. default:
  39. case 0:
  40. result = "BlendNormal( " + _inputA + " , " + _inputB + " )";
  41. break;
  42. case 1:
  43. result = "BlendNormalRNM( " + _inputA + " , " + _inputB + " )";
  44. break;
  45. case 2:
  46. string inputC = m_inputPorts[ 2 ].GeneratePortInstructions( ref dataCollector );
  47. result = "BlendNormalWorldspaceRNM( " + _inputA + " , " + _inputB + ", " + inputC + " )";
  48. break;
  49. }
  50. }
  51. return CreateOutputLocalVariable( 0, result, ref dataCollector );
  52. }
  53. public override void DrawProperties()
  54. {
  55. base.DrawProperties();
  56. if( ContainerGraph.IsSRP )
  57. {
  58. NodeUtils.DrawPropertyGroup( ref m_propertiesFoldout, Constants.ParameterLabelStr, () =>
  59. {
  60. EditorGUI.BeginChangeCheck();
  61. m_selectedMode = EditorGUILayoutIntPopup( "Mode", m_selectedMode, ModeListStr, ModeListInt );
  62. if( EditorGUI.EndChangeCheck() )
  63. {
  64. if( m_selectedMode == 2 )
  65. {
  66. m_inputPorts[ 2 ].Visible = true;
  67. }
  68. else
  69. {
  70. m_inputPorts[ 2 ].Visible = false;
  71. }
  72. m_sizeIsDirty = true;
  73. }
  74. } );
  75. }
  76. }
  77. public override void ReadFromString( ref string[] nodeParams )
  78. {
  79. base.ReadFromString( ref nodeParams );
  80. if( UIUtils.CurrentShaderVersion() > 14503 )
  81. m_selectedMode = Convert.ToInt32( GetCurrentParam( ref nodeParams ) );
  82. }
  83. public override void WriteToString( ref string nodeInfo, ref string connectionsInfo )
  84. {
  85. base.WriteToString( ref nodeInfo, ref connectionsInfo );
  86. IOUtils.AddFieldValueToString( ref nodeInfo, m_selectedMode );
  87. }
  88. }
  89. }