ParallaxOffsetHlpNode.cs 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. // Amplify Shader Editor - Visual Shader Editing Tool
  2. // Copyright (c) Amplify Creations, Lda <info@amplify.pt>
  3. using System;
  4. namespace AmplifyShaderEditor
  5. {
  6. [Serializable]
  7. [NodeAttributes( "Parallax Offset", "UV Coordinates", "Calculates UV offset for parallax normal mapping" )]
  8. public sealed class ParallaxOffsetHlpNode : HelperParentNode
  9. {
  10. public readonly string[] ParallaxOffsetFunc =
  11. {
  12. "inline float2 ParallaxOffset( half h, half height, half3 viewDir )\n",
  13. "{\n",
  14. "\th = h * height - height/2.0;\n",
  15. "\tfloat3 v = normalize( viewDir );\n",
  16. "\tv.z += 0.42;\n",
  17. "\treturn h* (v.xy / v.z);\n",
  18. "}\n"
  19. };
  20. void OnSRPActionEvent( int outputId, ref MasterNodeDataCollector dataCollector )
  21. {
  22. dataCollector.AddFunction( ParallaxOffsetFunc[ 0 ], ParallaxOffsetFunc, false );
  23. }
  24. protected override void CommonInit( int uniqueId )
  25. {
  26. base.CommonInit( uniqueId );
  27. m_funcType = "ParallaxOffset";
  28. m_inputPorts[ 0 ].ChangeProperties( "H", WirePortDataType.FLOAT, false );
  29. AddInputPort( WirePortDataType.FLOAT, false, "Height" );
  30. AddInputPort( WirePortDataType.FLOAT3, false, "ViewDir (tan)" );
  31. m_outputPorts[ 0 ].ChangeType( WirePortDataType.FLOAT2, false );
  32. m_outputPorts[ 0 ].Name = "Out";
  33. OnHDAction = OnSRPActionEvent;
  34. OnLightweightAction = OnSRPActionEvent;
  35. m_previewShaderGUID = "6085f804c6fbf354eac039c11feaa7cc";
  36. }
  37. protected override void OnUniqueIDAssigned()
  38. {
  39. base.OnUniqueIDAssigned();
  40. m_localVarName = "paralaxOffset" + OutputId;
  41. }
  42. }
  43. }