VertexBinormalNode.cs 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. // Amplify Shader Editor - Visual Shader Editing Tool
  2. // Copyright (c) Amplify Creations, Lda <info@amplify.pt>
  3. //
  4. // Custom Node Vertex Binormal World
  5. // Donated by Community Member Kebrus
  6. using UnityEngine;
  7. using System;
  8. namespace AmplifyShaderEditor
  9. {
  10. [Serializable]
  11. [NodeAttributes( "World Bitangent", "Surface Data", "Per pixel world bitangent vector", null, KeyCode.None, true, false, null, null, "kebrus" )]
  12. public sealed class VertexBinormalNode : ParentNode
  13. {
  14. protected override void CommonInit( int uniqueId )
  15. {
  16. base.CommonInit( uniqueId );
  17. AddOutputVectorPorts( WirePortDataType.FLOAT3, "XYZ" );
  18. m_drawPreviewAsSphere = true;
  19. m_previewShaderGUID = "76873532ab67d2947beaf07151383cbe";
  20. }
  21. public override void PropagateNodeData( NodeData nodeData, ref MasterNodeDataCollector dataCollector )
  22. {
  23. base.PropagateNodeData( nodeData, ref dataCollector );
  24. dataCollector.DirtyNormal = true;
  25. }
  26. public override string GenerateShaderForOutput( int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalvar )
  27. {
  28. if ( dataCollector.IsTemplate )
  29. return GetOutputVectorItem( 0, outputId, dataCollector.TemplateDataCollectorInstance.GetWorldBinormal( CurrentPrecisionType ) );
  30. if( dataCollector.PortCategory == MasterNodePortCategory.Fragment || dataCollector.PortCategory == MasterNodePortCategory.Debug )
  31. {
  32. dataCollector.ForceNormal = true;
  33. dataCollector.AddToInput( UniqueId, SurfaceInputs.WORLD_NORMAL, UIUtils.CurrentWindow.CurrentGraph.CurrentPrecision );
  34. dataCollector.AddToInput( UniqueId, SurfaceInputs.INTERNALDATA, addSemiColon: false );
  35. }
  36. string worldBitangent = GeneratorUtils.GenerateWorldBitangent( ref dataCollector, UniqueId );
  37. return GetOutputVectorItem( 0, outputId, worldBitangent );
  38. }
  39. }
  40. }