LocalVertexPosNode.cs 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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. [NodeAttributes( "[Deprecated] Local Position", "Surface Data", "Interpolated Vertex Position in Local Space", null, KeyCode.None, true, true, "Vertex Position", typeof( PosVertexDataNode ) )]
  9. public sealed class LocalVertexPosNode : ParentNode
  10. {
  11. private const string VertexVarName = "localVertexPos";
  12. private readonly string VertexOnFrag = Constants.InputVarStr + "." + VertexVarName;
  13. private readonly string VertexOnVert = Constants.VertexShaderInputStr + ".vertex";
  14. [SerializeField]
  15. private bool m_addInstruction = false;
  16. public override void Reset()
  17. {
  18. base.Reset();
  19. m_addInstruction = true;
  20. }
  21. protected override void CommonInit( int uniqueId )
  22. {
  23. base.CommonInit( uniqueId );
  24. AddOutputVectorPorts( WirePortDataType.FLOAT3, "XYZ" );
  25. }
  26. public override string GenerateShaderForOutput( int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalvar )
  27. {
  28. if ( dataCollector.PortCategory == MasterNodePortCategory.Vertex || dataCollector.PortCategory == MasterNodePortCategory.Tessellation )
  29. {
  30. return GetOutputVectorItem( 0, outputId, VertexOnVert );
  31. }
  32. else
  33. {
  34. if ( m_addInstruction )
  35. {
  36. dataCollector.AddToInput( UniqueId, VertexVarName, WirePortDataType.FLOAT3 );
  37. dataCollector.AddVertexInstruction( Constants.VertexShaderOutputStr + "." + VertexVarName + " = " + Constants.VertexShaderInputStr + ".vertex.xyz ", UniqueId );
  38. m_addInstruction = false;
  39. }
  40. return GetOutputVectorItem( 0, outputId, VertexOnFrag );
  41. }
  42. }
  43. }
  44. }