浏览代码

Step1 for LevelNode

/main
Florent Guinier 8 年前
当前提交
ce59a9db
共有 5 个文件被更改,包括 147 次插入0 次删除
  1. 1
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/MaterialGraphPresenter.cs
  2. 42
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/LevelNodePresenter.cs
  3. 12
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/LevelNodePresenter.cs.meta
  4. 84
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/LevelNode.cs
  5. 8
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/LevelNode.cs.meta

1
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/MaterialGraphPresenter.cs


typeMapper[typeof(MasterRemapInputNode)] = typeof(RemapInputNodePresenter);
typeMapper[typeof(AbstractSubGraphIONode)] = typeof(SubgraphIONodePresenter);
typeMapper[typeof(AbstractSurfaceMasterNode)] = typeof(SurfaceMasterPresenter);
typeMapper[typeof(LevelNode)] = typeof(LevelNodePresenter);
}
}
}

42
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/LevelNodePresenter.cs


using System;
using System.Collections.Generic;
using RMGUI.GraphView;
using UnityEditor.Graphing.Drawing;
using UnityEngine.MaterialGraph;
namespace UnityEditor.MaterialGraph.Drawing
{
class LevelControlPresenter : GraphControlPresenter
{
public override void OnGUIHandler()
{
base.OnGUIHandler();
var tNode = node as LevelNode;
if (tNode == null)
return;
tNode.inputMin = EditorGUILayout.FloatField("InputMin:", tNode.inputMin);
tNode.inputMax = EditorGUILayout.FloatField("InputMax:", tNode.inputMax);
tNode.inputGamma = EditorGUILayout.FloatField("InputGamma:", tNode.inputGamma);
tNode.outputMin = EditorGUILayout.FloatField("OutputMin:", tNode.outputMin);
tNode.outputMax = EditorGUILayout.FloatField("OutputMax:", tNode.outputMax);
}
public override float GetHeight()
{
return (EditorGUIUtility.singleLineHeight * 5 + EditorGUIUtility.standardVerticalSpacing) + EditorGUIUtility.standardVerticalSpacing;
}
}
[Serializable]
public class LevelNodePresenter : PropertyNodePresenter
{
protected override IEnumerable<GraphElementPresenter> GetControlData()
{
var instance = CreateInstance<LevelControlPresenter>();
instance.Initialize(node);
return new List<GraphElementPresenter>(base.GetControlData()) { instance };
}
}
}

12
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/LevelNodePresenter.cs.meta


fileFormatVersion: 2
guid: 224a0b135d08f2c46a9486ae3e9fb082
timeCreated: 1495457202
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

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


namespace UnityEngine.MaterialGraph
{
[Title("Art/Level Node")]
public class LevelNode : Function1Input, IGeneratesFunction
{
[SerializeField]
private float m_InputMin = 0.0f;
[SerializeField]
private float m_InputMax = 1.0f;
[SerializeField]
private float m_InputGamma = 1.0f;
[SerializeField]
private float m_OutputMin = 0.0f;
[SerializeField]
private float m_OutputMax = 1.0f;
public float inputMin
{
get { return m_InputMin; }
set { m_InputMin = value; }
}
public float inputMax
{
get { return m_InputMax; }
set { m_InputMax = value; }
}
public float inputGamma
{
get { return m_InputGamma; }
set { m_InputGamma = value; }
}
public float outputMin
{
get { return m_OutputMin; }
set { m_OutputMin = value; }
}
public float outputMax
{
get { return m_OutputMax; }
set { m_OutputMax = value; }
}
public LevelNode()
{
name = "LevelNode";
}
protected override string GetFunctionName()
{
return "unity_level_" + precision;
}
protected override string GetFunctionCallBody(string inputValue)
{
float inputInvGamma = 1.0f / m_InputGamma;
return GetFunctionName() + "(" + inputValue + ", " + m_InputMin + ", " + m_InputMax + ", " + inputInvGamma + ", " + m_OutputMin + ", " + m_OutputMax + ")";
}
public void GenerateNodeFunction(ShaderGenerator visitor, GenerationMode generationMode)
{
var outputString = new ShaderGenerator();
outputString.AddShaderChunk("inline " + precision + outputDimension + " unity_level_" + precision + " (" + precision + outputDimension + " arg1, "
+ precision + " inputMin, "
+ precision + " inputMax, "
+ precision + " inputInvGamma, "
+ precision + " outputMin, "
+ precision + " outputMax)", false);
outputString.AddShaderChunk("{", false);
outputString.Indent();
outputString.AddShaderChunk(precision + inputDimension + " colorMinClamped = max(arg1 - inputMin, 0.0);", false);
outputString.AddShaderChunk(precision + inputDimension + " colorMinMaxClamped = min(colorMinClamped / (inputMax - inputMin), 1.0);", false);
outputString.AddShaderChunk("return lerp(outputMin, outputMax, pow(colorMinMaxClamped, inputInvGamma));", false);
outputString.Deindent();
outputString.AddShaderChunk("}", false);
visitor.AddShaderChunk(outputString.GetShaderString(0), true);
}
}
}

8
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/LevelNode.cs.meta


fileFormatVersion: 2
guid: afcb18d0b92d93d45a34c5699ed4ff49
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
正在加载...
取消
保存