|
|
|
|
|
|
namespace UnityEngine.MaterialGraph |
|
|
|
{ |
|
|
|
[Title ("Math/Range/Remap")] |
|
|
|
public class RemapNode : Function2Input, IGeneratesFunction |
|
|
|
public class RemapNode : AbstractMaterialNode, IGeneratesBodyCode, IGeneratesFunction |
|
|
|
/*protected const string kInputSlot1ShaderName = "Input1"; |
|
|
|
protected const string kInputSlot2ShaderName = "Input2"; |
|
|
|
protected const string kInputSlot1ShaderName = "Input1"; |
|
|
|
protected const string kInputSlot2ShaderName = "InMinMax"; |
|
|
|
protected const string kInputSlot3ShaderName = "OutMinMax"; |
|
|
|
public const int OutputSlotId = 2; |
|
|
|
public const int InputSlot3Id = 2; |
|
|
|
public const int OutputSlotId = 3; |
|
|
|
*/ |
|
|
|
|
|
|
|
public override bool hasPreview |
|
|
|
{ |
|
|
|
get { return true; } |
|
|
|
} |
|
|
|
name = "RemapNode"; |
|
|
|
//UpdateNodeAfterDeserialization ();
|
|
|
|
name = "Remap"; |
|
|
|
protected override string GetFunctionName () |
|
|
|
public string GetFunctionName () |
|
|
|
//need to override the type of slot two somehow///////////////////////////////////////////////////
|
|
|
|
/*override MaterialSlot GetInputSlot2 () |
|
|
|
public sealed override void UpdateNodeAfterDeserialization() |
|
|
|
return new MaterialSlot (InputSlot2Id, GetInputSlot2Name (), kInputSlot2ShaderName, SlotType.Input, SlotValueType.Vector4, Vector4.zero); |
|
|
|
}*/ |
|
|
|
AddSlot(GetInputSlot1()); |
|
|
|
AddSlot(GetInputSlot2()); |
|
|
|
AddSlot(GetInputSlot3()); |
|
|
|
AddSlot(GetOutputSlot()); |
|
|
|
RemoveSlotsNameNotMatching(validSlots); |
|
|
|
} |
|
|
|
public void GenerateNodeFunction (ShaderGenerator visitor, GenerationMode generationMode) |
|
|
|
protected int[] validSlots |
|
|
|
var outputString = new ShaderGenerator (); |
|
|
|
outputString.AddShaderChunk (GetFunctionPrototype ("arg1", "arg2"), false); |
|
|
|
outputString.AddShaderChunk ("{", false); |
|
|
|
outputString.Indent (); |
|
|
|
outputString.AddShaderChunk ("return ((arg1 * (arg2.y - arg2.x)) * (arg2.w - arg2.z))+arg2.z;", false); |
|
|
|
outputString.Deindent (); |
|
|
|
outputString.AddShaderChunk ("}", false); |
|
|
|
|
|
|
|
visitor.AddShaderChunk (outputString.GetShaderString (0), true); |
|
|
|
get { return new[] {InputSlot1Id, InputSlot2Id, InputSlot3Id, OutputSlotId}; } |
|
|
|
/* |
|
|
|
public sealed override void UpdateNodeAfterDeserialization () |
|
|
|
protected virtual MaterialSlot GetInputSlot1() |
|
|
|
AddSlot (GetInputSlot1 ()); |
|
|
|
AddSlot (GetInputSlot2 ()); |
|
|
|
AddSlot (GetOutputSlot ()); |
|
|
|
RemoveSlotsNameNotMatching (validSlots); |
|
|
|
return new MaterialSlot(InputSlot1Id, GetInputSlot1Name(), kInputSlot1ShaderName, SlotType.Input, SlotValueType.Dynamic, Vector4.zero); |
|
|
|
protected int[] validSlots { |
|
|
|
get { return new[] { InputSlot1Id, InputSlot2Id, OutputSlotId }; } |
|
|
|
protected virtual MaterialSlot GetInputSlot2() |
|
|
|
{ |
|
|
|
return new MaterialSlot(InputSlot2Id, GetInputSlot2Name(), kInputSlot2ShaderName, SlotType.Input, SlotValueType.Vector2, Vector2.zero); |
|
|
|
protected virtual MaterialSlot GetInputSlot1 () |
|
|
|
protected virtual MaterialSlot GetInputSlot3() |
|
|
|
return new MaterialSlot (InputSlot1Id, GetInputSlot1Name (), kInputSlot1ShaderName, SlotType.Input, SlotValueType.Dynamic, Vector4.zero); |
|
|
|
return new MaterialSlot(InputSlot3Id, GetInputSlot3Name(), kInputSlot3ShaderName, SlotType.Input, SlotValueType.Vector2, Vector2.zero); |
|
|
|
protected virtual MaterialSlot GetInputSlot2 () |
|
|
|
protected virtual MaterialSlot GetOutputSlot() |
|
|
|
return new MaterialSlot (InputSlot2Id, GetInputSlot2Name (), kInputSlot2ShaderName, SlotType.Input, SlotValueType.Vector4, Vector4.zero); |
|
|
|
return new MaterialSlot(OutputSlotId, GetOutputSlotName(), kOutputSlotShaderName, SlotType.Output, SlotValueType.Dynamic, Vector4.zero); |
|
|
|
protected virtual MaterialSlot GetOutputSlot () |
|
|
|
protected virtual string GetInputSlot1Name() |
|
|
|
return new MaterialSlot (OutputSlotId, GetOutputSlotName (), kOutputSlotShaderName, SlotType.Output, SlotValueType.Dynamic, Vector4.zero); |
|
|
|
return "Input"; |
|
|
|
protected virtual string GetInputSlot1Name () |
|
|
|
protected virtual string GetInputSlot2Name() |
|
|
|
return "Input1"; |
|
|
|
return "InMinMax"; |
|
|
|
protected virtual string GetInputSlot2Name () |
|
|
|
protected virtual string GetInputSlot3Name() |
|
|
|
return "RemapVector"; |
|
|
|
return "OutMinMax"; |
|
|
|
protected virtual string GetOutputSlotName () |
|
|
|
protected virtual string GetOutputSlotName() |
|
|
|
//protected abstract string GetFunctionName ();
|
|
|
|
|
|
|
|
/*protected virtual string GetFunctionPrototype (string arg1Name, string arg2Name) |
|
|
|
protected virtual string GetFunctionPrototype(string arg1Name, string arg2Name, string arg3Name) |
|
|
|
return "inline " + precision + outputDimension + " " + GetFunctionName () + " (" |
|
|
|
+ precision + input1Dimension + " " + arg1Name + ", " |
|
|
|
+ precision + input2Dimension + " " + arg2Name + ")"; |
|
|
|
} |
|
|
|
|
|
|
|
public void GenerateNodeCode (ShaderGenerator visitor, GenerationMode generationMode) |
|
|
|
{ |
|
|
|
NodeUtils.SlotConfigurationExceptionIfBadConfiguration (this, new[] { InputSlot1Id, InputSlot2Id }, new[] { OutputSlotId }); |
|
|
|
string input1Value = GetSlotValue (InputSlot1Id, generationMode); |
|
|
|
string input2Value = GetSlotValue (InputSlot2Id, generationMode); |
|
|
|
visitor.AddShaderChunk (precision + outputDimension + " " + GetVariableNameForSlot (OutputSlotId) + " = " + GetFunctionCallBody (input1Value, input2Value) + ";", true); |
|
|
|
return "inline " + precision + outputDimension + " " + GetFunctionName() + " (" |
|
|
|
+ precision + input1Dimension + " " + arg1Name + ", " |
|
|
|
+ precision + input2Dimension + " " + arg2Name + ", " |
|
|
|
+ precision + input3Dimension + " " + arg3Name + ")"; |
|
|
|
protected virtual string GetFunctionCallBody (string input1Value, string input2Value) |
|
|
|
public void GenerateNodeCode(ShaderGenerator visitor, GenerationMode generationMode) |
|
|
|
return GetFunctionName () + " (" + input1Value + ", " + input2Value + ")"; |
|
|
|
}*/ |
|
|
|
NodeUtils.SlotConfigurationExceptionIfBadConfiguration(this, new[] { InputSlot1Id, InputSlot2Id, InputSlot3Id }, new[] { OutputSlotId }); |
|
|
|
string input1Value = GetSlotValue(InputSlot1Id, generationMode); |
|
|
|
string input2Value = GetSlotValue(InputSlot2Id, generationMode); |
|
|
|
string input3Value = GetSlotValue(InputSlot3Id, generationMode); |
|
|
|
/*public string outputDimension { |
|
|
|
get { return ConvertConcreteSlotValueTypeToString (FindOutputSlot<MaterialSlot> (OutputSlotId).concreteValueType); } |
|
|
|
visitor.AddShaderChunk(precision + outputDimension + " " + GetVariableNameForSlot(OutputSlotId) + " = " + GetFunctionCallBody(input1Value, input2Value, input3Value) + ";", true); |
|
|
|
private string input1Dimension { |
|
|
|
get { return ConvertConcreteSlotValueTypeToString (FindInputSlot<MaterialSlot> (InputSlot1Id).concreteValueType); } |
|
|
|
} |
|
|
|
|
|
|
|
private string input2Dimension { |
|
|
|
get { return ConvertConcreteSlotValueTypeToString (FindInputSlot<MaterialSlot> (InputSlot2Id).concreteValueType); } |
|
|
|
}*/ |
|
|
|
public void GenerateNodeFunction(ShaderGenerator visitor, GenerationMode generationMode) |
|
|
|
{ |
|
|
|
var outputString = new ShaderGenerator (); |
|
|
|
outputString.AddShaderChunk (GetFunctionPrototype ("arg1", "arg2", "arg3"), false); |
|
|
|
outputString.AddShaderChunk ("{", false); |
|
|
|
outputString.Indent (); |
|
|
|
outputString.AddShaderChunk ("return arg1 * ((arg3.y - arg3.x) / (arg2.y - arg2.x)) + arg3.x;", false); |
|
|
|
outputString.Deindent (); |
|
|
|
outputString.AddShaderChunk ("}", false); |
|
|
|
/// <summary>
|
|
|
|
/// Gets the type of the property.*/
|
|
|
|
/// </summary>
|
|
|
|
/// <value>The type of the property.</value>
|
|
|
|
|
|
|
|
/*public override PropertyType propertyType { |
|
|
|
get { return PropertyType.Vector4; } |
|
|
|
visitor.AddShaderChunk (outputString.GetShaderString (0), true); |
|
|
|
public Vector4 value { |
|
|
|
get { return m_Value; } |
|
|
|
set { |
|
|
|
if (m_Value == value) |
|
|
|
return; |
|
|
|
|
|
|
|
m_Value = value; |
|
|
|
|
|
|
|
if (onModified != null) |
|
|
|
onModified (this, ModificationScope.Node); |
|
|
|
} |
|
|
|
}*/ |
|
|
|
|
|
|
|
/*public override void GeneratePropertyBlock (PropertyGenerator visitor, GenerationMode generationMode) |
|
|
|
protected virtual string GetFunctionCallBody(string inputValue1, string inputValue2, string inputValue3) |
|
|
|
if (exposedState == ExposedState.Exposed) |
|
|
|
visitor.AddShaderProperty (new VectorPropertyChunk (propertyName, description, m_Value, PropertyChunk.HideState.Visible)); |
|
|
|
return GetFunctionName() + " (" + inputValue1 + ", " + inputValue2 + ", " + inputValue3 + ")"; |
|
|
|
public override void GeneratePropertyUsages (ShaderGenerator visitor, GenerationMode generationMode) |
|
|
|
public string outputDimension |
|
|
|
if (exposedState == ExposedState.Exposed || generationMode.IsPreview ()) |
|
|
|
visitor.AddShaderChunk (precision + "3 " + propertyName + ";", false); |
|
|
|
}*/ |
|
|
|
|
|
|
|
/*public void GenerateNodeCode (ShaderGenerator visitor, GenerationMode generationMode) |
|
|
|
get { return ConvertConcreteSlotValueTypeToString(FindOutputSlot<MaterialSlot>(OutputSlotId).concreteValueType); } |
|
|
|
} |
|
|
|
private string input1Dimension |
|
|
|
if (exposedState == ExposedState.Exposed || generationMode.IsPreview ()) |
|
|
|
return; |
|
|
|
var input1Value = GetSlotValue (InputSlot1Id, generationMode); |
|
|
|
var input2Value = GetSlotValue (InputSlot2Id, generationMode); |
|
|
|
visitor.AddShaderChunk (precision + "4 " + propertyName + " = " + input1Value + " * ((" + input2Value + ".w - " + input2Value + ".z) + " + input2Value + ".z);", false); |
|
|
|
get { return ConvertConcreteSlotValueTypeToString(FindInputSlot<MaterialSlot>(InputSlot1Id).concreteValueType); } |
|
|
|
public override bool hasPreview { |
|
|
|
get { return true; } |
|
|
|
private string input2Dimension |
|
|
|
{ |
|
|
|
get { return ConvertConcreteSlotValueTypeToString(FindInputSlot<MaterialSlot>(InputSlot2Id).concreteValueType); } |
|
|
|
public override PreviewProperty GetPreviewProperty () |
|
|
|
public string input3Dimension |
|
|
|
return new PreviewProperty { |
|
|
|
m_Name = propertyName, |
|
|
|
m_PropType = PropertyType.Vector4, |
|
|
|
m_Vector4 = m_Value |
|
|
|
}; |
|
|
|
}*/ |
|
|
|
get { return ConvertConcreteSlotValueTypeToString(FindInputSlot<MaterialSlot>(InputSlot3Id).concreteValueType); } |
|
|
|
} |
|
|
|
} |
|
|
|
} |