ObjSpaceLightDirHlpNode.cs 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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( "Object Space Light Dir", "Lighting", "Computes object space light direction (not normalized)" )]
  8. public sealed class ObjSpaceLightDirHlpNode : HelperParentNode
  9. {
  10. protected override void CommonInit( int uniqueId )
  11. {
  12. base.CommonInit( uniqueId );
  13. m_funcType = "ObjSpaceLightDir";
  14. m_inputPorts[ 0 ].Visible = false;
  15. m_outputPorts[ 0 ].ChangeType( WirePortDataType.FLOAT3, false );
  16. m_outputPorts[ 0 ].Name = "XYZ";
  17. AddOutputPort( WirePortDataType.FLOAT, "X" );
  18. AddOutputPort( WirePortDataType.FLOAT, "Y" );
  19. AddOutputPort( WirePortDataType.FLOAT, "Z" );
  20. m_useInternalPortData = false;
  21. m_previewShaderGUID = "c7852de24cec4a744b5358921e23feee";
  22. m_drawPreviewAsSphere = true;
  23. }
  24. public override string GenerateShaderForOutput( int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalvar )
  25. {
  26. if( dataCollector.IsTemplate )
  27. {
  28. //Template must have its Light Mode correctly configured on tags to work as intended
  29. return GetOutputVectorItem( 0, outputId, dataCollector.TemplateDataCollectorInstance.GetObjectSpaceLightDir( CurrentPrecisionType ) );
  30. }
  31. dataCollector.AddToIncludes( UniqueId, Constants.UnityCgLibFuncs );
  32. dataCollector.AddToInput( UniqueId, SurfaceInputs.WORLD_POS );
  33. string vertexPos = GeneratorUtils.GenerateVertexPosition( ref dataCollector, UniqueId, WirePortDataType.FLOAT4 );
  34. return GetOutputVectorItem( 0, outputId, GeneratorUtils.GenerateObjectLightDirection( ref dataCollector, UniqueId, CurrentPrecisionType, vertexPos ) );
  35. }
  36. }
  37. }