NormalVertexDataNode.cs 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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( "Vertex Normal", "Vertex Data", "Vertex normal vector in object space, can be used in both local vertex offset and fragment outputs" )]
  7. public sealed class NormalVertexDataNode : VertexDataNode
  8. {
  9. protected override void CommonInit( int uniqueId )
  10. {
  11. base.CommonInit( uniqueId );
  12. m_currentVertexData = "normal";
  13. ChangeOutputProperties( 0, "XYZ", WirePortDataType.FLOAT3 );
  14. m_outputPorts[ 4 ].Visible = false;
  15. m_drawPreviewAsSphere = true;
  16. m_previewShaderGUID = "6b24b06c33f9fe84c8a2393f13ab5406";
  17. }
  18. public override string GenerateShaderForOutput( int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalVar )
  19. {
  20. string vertexNormal = string.Empty;
  21. if( dataCollector.MasterNodeCategory == AvailableShaderTypes.Template )
  22. {
  23. vertexNormal = dataCollector.TemplateDataCollectorInstance.GetVertexNormal( CurrentPrecisionType );
  24. return GetOutputVectorItem( 0, outputId, vertexNormal );
  25. }
  26. if( dataCollector.PortCategory == MasterNodePortCategory.Fragment || dataCollector.PortCategory == MasterNodePortCategory.Debug )
  27. {
  28. dataCollector.AddToInput( UniqueId, SurfaceInputs.WORLD_NORMAL, UIUtils.CurrentWindow.CurrentGraph.CurrentPrecision );
  29. if( dataCollector.DirtyNormal )
  30. {
  31. dataCollector.AddToInput( UniqueId, SurfaceInputs.INTERNALDATA, addSemiColon: false );
  32. dataCollector.ForceNormal = true;
  33. }
  34. }
  35. vertexNormal = GeneratorUtils.GenerateVertexNormal( ref dataCollector, UniqueId, CurrentPrecisionType );
  36. return GetOutputVectorItem( 0, outputId, vertexNormal );
  37. }
  38. }
  39. }