您最多选择25个主题
主题必须以中文或者字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
43 行
1.5 KiB
43 行
1.5 KiB
using UnityEngine.Graphing;
|
|
|
|
namespace UnityEngine.MaterialGraph
|
|
{
|
|
[Title ("Math/Color/LineartoRGB")]
|
|
public class LineartoRGBNode : Function1Input, IGeneratesFunction
|
|
{
|
|
public LineartoRGBNode()
|
|
{
|
|
name = "RGBtoLinear";
|
|
}
|
|
|
|
protected override string GetFunctionName ()
|
|
{
|
|
return "unity_lineartorgb_" + precision;
|
|
}
|
|
|
|
protected override MaterialSlot GetInputSlot ()
|
|
{
|
|
return new MaterialSlot (InputSlotId, GetInputSlotName (), kInputSlotShaderName, SlotType.Input, SlotValueType.Vector3, Vector4.zero);
|
|
}
|
|
|
|
protected override MaterialSlot GetOutputSlot ()
|
|
{
|
|
return new MaterialSlot (OutputSlotId, GetOutputSlotName (), kOutputSlotShaderName, SlotType.Output, SlotValueType.Vector3, Vector4.zero);
|
|
}
|
|
|
|
public void GenerateNodeFunction (ShaderGenerator visitor, GenerationMode generationMode)
|
|
{
|
|
var outputString = new ShaderGenerator ();
|
|
outputString.AddShaderChunk (GetFunctionPrototype ("arg1"), false);
|
|
outputString.AddShaderChunk ("{", false);
|
|
outputString.Indent ();
|
|
outputString.AddShaderChunk (precision + "3 sRGBLo = arg1 * 12.92;", false);
|
|
outputString.AddShaderChunk (precision + "3 sRGBHi = (pow(max(abs(arg1), 1.192092896e-07), "+precision+ "3(1.0 / 2.4, 1.0 / 2.4, 1.0 / 2.4)) * 1.055) - 0.055;", false);
|
|
outputString.AddShaderChunk ("return " + precision + "3(arg1 <= 0.0031308) ? sRGBLo : sRGBHi;", false);
|
|
outputString.Deindent ();
|
|
outputString.AddShaderChunk ("}", false);
|
|
|
|
visitor.AddShaderChunk (outputString.GetShaderString (0), true);
|
|
}
|
|
}
|
|
}
|