您最多选择25个主题
主题必须以中文或者字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
41 行
1.3 KiB
41 行
1.3 KiB
using UnityEngine.Graphing;
|
|
|
|
namespace UnityEngine.MaterialGraph
|
|
{
|
|
[Title ("Math/Color/RGBtoLuminance")]
|
|
public class RGBtoLuminance : Function1Input, IGeneratesFunction
|
|
{
|
|
public RGBtoLuminance()
|
|
{
|
|
name = "RGBtoLuminance";
|
|
}
|
|
|
|
protected override string GetFunctionName ()
|
|
{
|
|
return "unity_rgbtoluminance_" + precision;
|
|
}
|
|
|
|
protected override MaterialSlot GetInputSlot ()
|
|
{
|
|
return new MaterialSlot (InputSlotId, GetInputSlotName (), kInputSlotShaderName, SlotType.Input, SlotValueType.Vector3, Vector4.zero);
|
|
}
|
|
|
|
protected override MaterialSlot GetOutputSlot ()
|
|
{
|
|
}
|
|
|
|
// Convert rgb to luminance with rgb in linear space with sRGB primaries and D65 white point (from PostProcessing)
|
|
public void GenerateNodeFunction (ShaderGenerator visitor, GenerationMode generationMode)
|
|
{
|
|
var outputString = new ShaderGenerator ();
|
|
outputString.AddShaderChunk (GetFunctionPrototype ("arg1"), false);
|
|
outputString.AddShaderChunk ("{", false);
|
|
outputString.Indent ();
|
|
outputString.AddShaderChunk ("return dot(arg1, "+precision+outputDimension+"(0.2126729, 0.7151522, 0.0721750));", false);
|
|
outputString.Deindent ();
|
|
outputString.AddShaderChunk ("}", false);
|
|
|
|
visitor.AddShaderChunk (outputString.GetShaderString (0), true);
|
|
}
|
|
}
|
|
}
|