FWidthOpNode.cs 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. // Amplify Shader Editor - Visual Shader Editing Tool
  2. // Copyright (c) Amplify Creations, Lda <info@amplify.pt>
  3. namespace AmplifyShaderEditor
  4. {
  5. [System.Serializable]
  6. [NodeAttributes( "FWidth", "Math Operators", "Sum of approximate window-space partial derivatives magnitudes (Only valid on Fragment type ports)" )]
  7. public sealed class FWidthOpNode : SingleInputOp
  8. {
  9. private const string FWidthErrorMsg = "Attempting to connect an FWidth to a {0} type port. It is only valid on Fragment type ports";
  10. protected override void CommonInit( int uniqueId )
  11. {
  12. base.CommonInit( uniqueId );
  13. m_opName = "fwidth";
  14. m_previewShaderGUID = "81ea481faaef9c8459a555479ba64df7";
  15. m_inputPorts[ 0 ].CreatePortRestrictions( WirePortDataType.OBJECT,
  16. WirePortDataType.FLOAT ,
  17. WirePortDataType.FLOAT2,
  18. WirePortDataType.FLOAT3,
  19. WirePortDataType.FLOAT4,
  20. WirePortDataType.COLOR ,
  21. WirePortDataType.INT);
  22. //m_inputPorts[ 0 ].ChangeType( WirePortDataType.FLOAT4, false );
  23. }
  24. public override string GenerateShaderForOutput( int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalvar )
  25. {
  26. if( dataCollector.PortCategory == MasterNodePortCategory.Vertex ||
  27. dataCollector.PortCategory == MasterNodePortCategory.Tessellation )
  28. {
  29. UIUtils.ShowMessage( UniqueId, string.Format( FWidthErrorMsg, dataCollector.PortCategory ), MessageSeverity.Error );
  30. return GenerateErrorValue();
  31. }
  32. return base.GenerateShaderForOutput( outputId, ref dataCollector, ignoreLocalvar );
  33. }
  34. }
  35. }