ObjSpaceViewDirHlpNode.cs 1.9 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. using UnityEditor;
  6. namespace AmplifyShaderEditor
  7. {
  8. [Serializable]
  9. [NodeAttributes( "Object Space View Dir", "Object Transform", "Object space direction (not normalized) from given object space vertex position towards the camera",castType:null, shortcutKey:KeyCode.None, available:false, deprecated:true )]
  10. public sealed class ObjSpaceViewDirHlpNode : HelperParentNode
  11. {
  12. protected override void CommonInit( int uniqueId )
  13. {
  14. base.CommonInit( uniqueId );
  15. m_funcType = "ObjSpaceViewDir";
  16. //TODO: revisit this later
  17. m_funcLWFormatOverride = "( mul(GetWorldToObjectMatrix(), float4(_WorldSpaceCameraPos.xyz, 1)).xyz - {0}.xyz )";
  18. m_funcHDFormatOverride = "( mul(GetWorldToObjectMatrix(), float4(_WorldSpaceCameraPos.xyz, 1)).xyz - {0}.xyz )";
  19. m_inputPorts[ 0 ].ChangeType( WirePortDataType.FLOAT4, false );
  20. m_inputPorts[ 0 ].Vector4InternalData = new UnityEngine.Vector4( 0, 0, 0, 1 );
  21. m_outputPorts[ 0 ].ChangeType( WirePortDataType.FLOAT3, false );
  22. m_outputPorts[ 0 ].Name = "XYZ";
  23. AddOutputPort( WirePortDataType.FLOAT, "X" );
  24. AddOutputPort( WirePortDataType.FLOAT, "Y" );
  25. AddOutputPort( WirePortDataType.FLOAT, "Z" );
  26. m_previewShaderGUID = "c7852de24cec4a744b5358921e23feee";
  27. m_errorMessageTooltip = "This node still works but is now deprecated. Please use \"View Dir\" instead.";
  28. m_errorMessageTypeIsError = NodeMessageType.Warning;
  29. m_showErrorMessage = true;
  30. }
  31. protected override void OnUniqueIDAssigned()
  32. {
  33. base.OnUniqueIDAssigned();
  34. m_localVarName = "objectSpaceViewDir" + OutputId;
  35. }
  36. public override void DrawProperties()
  37. {
  38. base.DrawProperties();
  39. if ( m_showErrorMessage )
  40. {
  41. EditorGUILayout.HelpBox( m_errorMessageTooltip, MessageType.Warning );
  42. }
  43. }
  44. }
  45. }