浏览代码

Level node (this time working :))

/main
Florent Guinier 8 年前
当前提交
6f40e6a8
共有 1 个文件被更改,包括 92 次插入7 次删除
  1. 99
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/LevelNode.cs

99
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/LevelNode.cs


using UnityEngine.Graphing;
using System.Collections.Generic;
namespace UnityEngine.MaterialGraph
{
[Title("Art/Level Node")]

public float inputMin
{
get { return m_InputMin; }
set { m_InputMin = value; }
set
{
if (m_InputMin == value)
return;
m_InputMin = value;
if (onModified != null)
onModified(this, ModificationScope.Node);
}
set { m_InputMax = value; }
set
{
if (m_InputMax == value)
return;
m_InputMax = value;
if (onModified != null)
onModified(this, ModificationScope.Node);
}
set { m_InputGamma = value; }
set
{
if (m_InputGamma == value)
return;
m_InputGamma = value;
if (onModified != null)
onModified(this, ModificationScope.Node);
}
set { m_OutputMin = value; }
set
{
if (m_OutputMin == value)
return;
m_OutputMin = value;
if (onModified != null)
onModified(this, ModificationScope.Node);
}
set { m_OutputMax = value; }
set
{
if (m_OutputMax == value)
return;
m_OutputMax = value;
if (onModified != null)
onModified(this, ModificationScope.Node);
}
}
public LevelNode()

return "unity_level_" + precision;
}
public override void GeneratePropertyUsages(ShaderGenerator visitor, GenerationMode generationMode)
{
if (generationMode.IsPreview())
{
string propGuid = guid.ToString().Replace("-", "_");
visitor.AddShaderChunk(precision + " inputMin" + propGuid +";", true);
visitor.AddShaderChunk(precision + " inputMax" + propGuid + ";", true);
visitor.AddShaderChunk(precision + " inputInvGamma" + propGuid + ";", true);
visitor.AddShaderChunk(precision + " outputMin" + propGuid + ";", true);
visitor.AddShaderChunk(precision + " outputMax" + propGuid + ";", true);
}
}
public void GenerateNodeCode(ShaderGenerator visitor, GenerationMode generationMode)
{
if (generationMode.IsPreview())
return;
float inputInvGamma = 1.0f / m_InputGamma;
string propGuid = guid.ToString().Replace("-", "_");
visitor.AddShaderChunk(precision + " inputMin" + propGuid + " = " + m_InputMin + ";", true);
visitor.AddShaderChunk(precision + " inputMax" + propGuid + " = " + m_InputMax + ";", true);
visitor.AddShaderChunk(precision + " inputInvGamma" + propGuid + " = " + inputInvGamma + ";", true);
visitor.AddShaderChunk(precision + " outputMin" + propGuid + " = " + m_OutputMin + ";", true);
visitor.AddShaderChunk(precision + " outputMax" + propGuid + " = " + m_OutputMax + ";", true);
}
float inputInvGamma = 1.0f / m_InputGamma;
return GetFunctionName() + "(" + inputValue + ", " + m_InputMin + ", " + m_InputMax + ", " + inputInvGamma + ", " + m_OutputMin + ", " + m_OutputMax + ")";
string propGuid = guid.ToString().Replace("-", "_");
return GetFunctionName() + "(" + inputValue +
", inputMin" + propGuid +
", inputMax" + propGuid +
", inputInvGamma" + propGuid +
", outputMin" + propGuid +
", outputMax" + propGuid +
");";
}
public void GenerateNodeFunction(ShaderGenerator visitor, GenerationMode generationMode)

outputString.AddShaderChunk("}", false);
visitor.AddShaderChunk(outputString.GetShaderString(0), true);
}
public override void CollectPreviewMaterialProperties(List<PreviewProperty> properties)
{
string propGuid = guid.ToString().Replace("-", "_");
base.CollectPreviewMaterialProperties(properties);
float inputInvGamma = 1.0f / m_InputGamma;
properties.Add(new PreviewProperty { m_Name = "inputMin" + propGuid, m_PropType = PropertyType.Float, m_Float = m_InputMin } );
properties.Add(new PreviewProperty { m_Name = "inputMax" + propGuid, m_PropType = PropertyType.Float, m_Float = m_InputMax } );
properties.Add(new PreviewProperty { m_Name = "inputInvGamma" + propGuid, m_PropType = PropertyType.Float, m_Float = inputInvGamma });
properties.Add(new PreviewProperty { m_Name = "outputMin" + propGuid, m_PropType = PropertyType.Float, m_Float = m_OutputMin });
properties.Add(new PreviewProperty { m_Name = "outputMax" + propGuid, m_PropType = PropertyType.Float, m_Float = m_OutputMax });
}
}
}
正在加载...
取消
保存