1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
|
// Amplify Shader Editor - Visual Shader Editing Tool
// Copyright (c) Amplify Creations, Lda <info@amplify.pt>
//https://docs.unity3d.com/Manual/SL-BuiltinFunctions.html
using System;
using UnityEngine;
namespace AmplifyShaderEditor
{
[Serializable]
public class HelperParentNode : ParentNode
{
[SerializeField]
protected string m_funcType = string.Empty;
[SerializeField]
protected string m_funcLWFormatOverride = string.Empty;
[SerializeField]
protected string m_funcHDFormatOverride = string.Empty;
protected string m_localVarName = null;
protected override void CommonInit( int uniqueId )
{
base.CommonInit( uniqueId );
AddInputPort( WirePortDataType.FLOAT, false, Constants.EmptyPortValue );
AddOutputPort( WirePortDataType.FLOAT, Constants.EmptyPortValue );
m_useInternalPortData = true;
}
public override string GetIncludes()
{
return Constants.UnityCgLibFuncs;
}
public override string GenerateShaderForOutput( int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalvar )
{
if( m_outputPorts[ 0 ].IsLocalValue( dataCollector.PortCategory ) )
return GetOutputVectorItem( 0, outputId, m_outputPorts[ 0 ].LocalValue( dataCollector.PortCategory ) );
base.GenerateShaderForOutput( outputId, ref dataCollector, ignoreLocalvar );
if( !( dataCollector.IsTemplate && dataCollector.IsSRP ) )
dataCollector.AddToIncludes( UniqueId, Constants.UnityCgLibFuncs );
string concatResults = string.Empty;
bool first = true;
for( int i = 0; i < m_inputPorts.Count; i++ )
{
if( m_inputPorts[ i ].Visible )
{
if( !first )
{
concatResults += " , ";
}
else
{
first = false;
}
string result = string.Empty;
if( m_inputPorts[ i ].IsConnected )
{
result = m_inputPorts[ i ].GeneratePortInstructions( ref dataCollector );
}
else
{
result = m_inputPorts[ i ].WrappedInternalData;
}
concatResults += result;
}
}
string finalResult = m_funcType + "( " + concatResults + " )";
if( dataCollector.IsTemplate )
{
if( dataCollector.TemplateDataCollectorInstance.CurrentSRPType == TemplateSRPType.Lightweight && !string.IsNullOrEmpty( m_funcLWFormatOverride ) )
{
finalResult = string.Format( m_funcLWFormatOverride, concatResults );
}
else if( dataCollector.TemplateDataCollectorInstance.CurrentSRPType == TemplateSRPType.HD && !string.IsNullOrEmpty( m_funcHDFormatOverride ) )
{
finalResult = string.Format( m_funcHDFormatOverride, concatResults );
}
}
RegisterLocalVariable( 0, finalResult, ref dataCollector, m_localVarName );
return GetOutputVectorItem( 0, outputId, m_outputPorts[ 0 ].LocalValue( dataCollector.PortCategory ) );
}
}
}
|