浏览代码

Added RGBtoLinear and LinearToRGB

/main
Matt Dean 8 年前
当前提交
43f98d51
共有 4 个文件被更改,包括 110 次插入0 次删除
  1. 43
      MaterialGraphProject/Assets/Matt/LinearToRGB.cs
  2. 12
      MaterialGraphProject/Assets/Matt/LinearToRGB.cs.meta
  3. 43
      MaterialGraphProject/Assets/Matt/RGBtoLinear.cs
  4. 12
      MaterialGraphProject/Assets/Matt/RGBtoLinear.cs.meta

43
MaterialGraphProject/Assets/Matt/LinearToRGB.cs


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);
}
}
}

12
MaterialGraphProject/Assets/Matt/LinearToRGB.cs.meta


fileFormatVersion: 2
guid: 667e5671fc459344c889207ff866ab08
timeCreated: 1444218016
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

43
MaterialGraphProject/Assets/Matt/RGBtoLinear.cs


using UnityEngine.Graphing;
namespace UnityEngine.MaterialGraph
{
[Title ("Math/Color/RGBtoLinear")]
public class RGBtoLinearNode : Function1Input, IGeneratesFunction
{
public RGBtoLinearNode()
{
name = "RGBtoLinear";
}
protected override string GetFunctionName ()
{
return "unity_rgbtolinear_" + 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 linearRGBLo = arg1 / 12.92;", false);
outputString.AddShaderChunk (precision + "3 linearRGBHi = pow(max(abs((arg1 + 0.055) / 1.055), 1.192092896e-07), "+precision+"3(2.4, 2.4, 2.4));", false);
outputString.AddShaderChunk ("return " + precision + "3(arg1 <= 0.04045) ? linearRGBLo : linearRGBHi;", false);
outputString.Deindent ();
outputString.AddShaderChunk ("}", false);
visitor.AddShaderChunk (outputString.GetShaderString (0), true);
}
}
}

12
MaterialGraphProject/Assets/Matt/RGBtoLinear.cs.meta


fileFormatVersion: 2
guid: e282583a8fbbf2742bd10d617611c8b0
timeCreated: 1444218016
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
正在加载...
取消
保存