Florent Guinier
8 年前
当前提交
ce59a9db
共有 5 个文件被更改,包括 147 次插入 和 0 次删除
-
1MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/MaterialGraphPresenter.cs
-
42MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/LevelNodePresenter.cs
-
12MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/LevelNodePresenter.cs.meta
-
84MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/LevelNode.cs
-
8MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/LevelNode.cs.meta
|
|||
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 }; |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 224a0b135d08f2c46a9486ae3e9fb082 |
|||
timeCreated: 1495457202 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
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); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: afcb18d0b92d93d45a34c5699ed4ff49 |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
撰写
预览
正在加载...
取消
保存
Reference in new issue