浏览代码

Merge branch 'hackweek2017' of https://github.com/stramit/MaterialGraph into hackweek2017

/main
bfogerty 7 年前
当前提交
995a95bc
共有 42 个文件被更改,包括 919 次插入67 次删除
  1. 1
      MaterialGraphProject/Assets/Eduardo/ConstantsNode.cs
  2. 2
      MaterialGraphProject/Assets/Eduardo/EduardoTestGraph.ShaderGraph
  3. 4
      MaterialGraphProject/Assets/Eduardo/EduardoTestMat.mat
  4. 2
      MaterialGraphProject/Assets/Matt/Test.ShaderGraph
  5. 4
      MaterialGraphProject/Assets/Matt/Test.ShaderGraph.meta
  6. 3
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/MaterialGraphPresenter.cs
  7. 16
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/Vector1NodePresenter.cs
  8. 42
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Procedural/VoronoiNoise.cs
  9. 116
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Math/Matrix/MatrixMultiplyNode.cs
  10. 21
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Math/Matrix/MatrixTransposeNode.cs
  11. 41
      MaterialGraphProject/Assets/Andre/Nodes/Editor/TransformNodePresenter.cs
  12. 12
      MaterialGraphProject/Assets/Andre/Nodes/Editor/TransformNodePresenter.cs.meta
  13. 34
      MaterialGraphProject/Assets/Andre/Nodes/TransformNode.cs
  14. 12
      MaterialGraphProject/Assets/Andre/Nodes/TransformNode.cs.meta
  15. 14
      MaterialGraphProject/Assets/Matt/CommonMatrixType.cs
  16. 12
      MaterialGraphProject/Assets/Matt/CommonMatrixType.cs.meta
  17. 9
      MaterialGraphProject/Assets/Matt/Examples.meta
  18. 51
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/MatrixCommonNodePresenter.cs
  19. 12
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/MatrixCommonNodePresenter.cs.meta
  20. 43
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/ScatterNodePresenter.cs
  21. 12
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/ScatterNodePresenter.cs.meta
  22. 68
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Input/Matrix/MatrixCommonNode.cs
  23. 12
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Input/Matrix/MatrixCommonNode.cs.meta
  24. 9
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Math/Matrix.meta
  25. 55
      MaterialGraphProject/Assets/_MingWai/ColorBalanceNode.cs
  26. 12
      MaterialGraphProject/Assets/_MingWai/ColorBalanceNode.cs.meta
  27. 67
      MaterialGraphProject/Assets/_MingWai/RandomRangeNode.cs
  28. 12
      MaterialGraphProject/Assets/_MingWai/RandomRangeNode.cs.meta
  29. 121
      MaterialGraphProject/Assets/_MingWai/ScatterNode.cs
  30. 12
      MaterialGraphProject/Assets/_MingWai/ScatterNode.cs.meta
  31. 1
      MaterialGraphProject/Assets/Matt/Examples/HueStrip.ShaderGraph
  32. 9
      MaterialGraphProject/Assets/Matt/Examples/HueStrip.ShaderGraph.meta
  33. 1
      MaterialGraphProject/Assets/Matt/Examples/Swirl.ShaderGraph
  34. 9
      MaterialGraphProject/Assets/Matt/Examples/Swirl.ShaderGraph.meta
  35. 123
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Math/Matrix/MatrixMultiplyByVectorNode.cs
  36. 12
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Math/Matrix/MatrixMultiplyByVectorNode.cs.meta
  37. 0
      /MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Math/Matrix/MatrixMultiplyNode.cs
  38. 0
      /MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Math/Matrix/MatrixMultiplyNode.cs.meta
  39. 0
      /MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Math/Matrix/MatrixTransposeNode.cs
  40. 0
      /MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Math/Matrix/MatrixTransposeNode.cs.meta

1
MaterialGraphProject/Assets/Eduardo/ConstantsNode.cs


static Dictionary<ConstantType, float> m_constantList = new Dictionary<ConstantType, float>
{
{ConstantType.PI, 3.1415926f },
{ConstantType.TAU, 6.28318530f},
{ConstantType.PHI, 1.618034f},
{ConstantType.E, 2.718282f},

2
MaterialGraphProject/Assets/Eduardo/EduardoTestGraph.ShaderGraph
文件差异内容过多而无法显示
查看文件

4
MaterialGraphProject/Assets/Eduardo/EduardoTestMat.mat


m_Texture: {fileID: 2800000, guid: 6ff1e57e8df9d2948bb6d703d02af730, type: 3}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- Texture_ec519094_93da_4612_af61_2f8bcdc6589e_Uniform:
m_Texture: {fileID: 2800000, guid: 6ff1e57e8df9d2948bb6d703d02af730, type: 3}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _BumpMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}

2
MaterialGraphProject/Assets/Matt/Test.ShaderGraph
文件差异内容过多而无法显示
查看文件

4
MaterialGraphProject/Assets/Matt/Test.ShaderGraph.meta


fileFormatVersion: 2
guid: 62568f909ca80d342836892f01cb06c9
timeCreated: 1495663356
guid: fd03b3a3f54f741498f9bea81e951ebb
timeCreated: 1495668190
licenseType: Pro
ScriptedImporter:
userData:

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


typeMapper[typeof(AbstractMaterialNode)] = typeof(MaterialNodePresenter);
typeMapper[typeof(ColorNode)] = typeof(ColorNodePresenter);
typeMapper[typeof(GradientNode)] = typeof(GradientNodePresenter);
typeMapper[typeof(ScatterNode)] = typeof(ScatterNodePresenter);
typeMapper[typeof(TextureNode)] = typeof(TextureNodePresenter);
typeMapper[typeof(TextureAssetNode)] = typeof(TextureAssetNodePresenter);
typeMapper[typeof(TextureLODNode)] = typeof(TextureLODNodePresenter);

typeMapper[typeof(Matrix2Node)] = typeof(Matrix2NodePresenter);
typeMapper[typeof(Matrix3Node)] = typeof(Matrix3NodePresenter);
typeMapper[typeof(Matrix4Node)] = typeof(Matrix4NodePresenter);
typeMapper[typeof(MatrixCommonNode)] = typeof(MatrixCommonNodePresenter);
typeMapper[typeof(TransformNode)] = typeof(TransformNodePresenter);
}
}
}

16
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/Vector1NodePresenter.cs


{
class Vector1ControlPresenter : GraphControlPresenter
{
[SerializeField]
private int dynamicHeight;
public override void OnGUIHandler()
{

tNode.floatType = (FloatPropertyChunk.FloatType)EditorGUILayout.EnumPopup ("Float", tNode.floatType);
dynamicHeight = 8;
dynamicHeight = 16;
tNode.floatType = FloatPropertyChunk.FloatType.Range;
tNode.value = EditorGUILayout.Slider (tNode.value, tNode.rangeValues.x, tNode.rangeValues.y);
EditorGUILayout.BeginHorizontal ();

tNode.rangeValues = ranges;
break;
case FloatPropertyChunk.FloatType.PowerSlider:
dynamicHeight = 16;
//very dirty...
for (int i = 0; i < 15; i++) {
EditorGUILayout.Space ();
}
//power needs to be name
ranges.z = EditorGUILayout.FloatField (ranges.z);
ranges.z = EditorGUILayout.FloatField ("Power", ranges.z);
dynamicHeight = 8;
bool toggleState = tNode.value == 0f ? false : true;
tNode.floatType = FloatPropertyChunk.FloatType.Toggle;
toggleState = EditorGUILayout.Toggle (toggleState);

public override float GetHeight()
{
return (EditorGUIUtility.singleLineHeight + dynamicHeight * EditorGUIUtility.standardVerticalSpacing) + EditorGUIUtility.standardVerticalSpacing;
return (EditorGUIUtility.singleLineHeight + 16 * EditorGUIUtility.standardVerticalSpacing) + EditorGUIUtility.standardVerticalSpacing;
}
}

42
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Procedural/VoronoiNoise.cs


namespace UnityEngine.MaterialGraph
{
[Title("Procedural/Voronoi Noise")]
public class VoronoiNoiseNode : Function2Input, IGeneratesFunction
public class VoronoiNoiseNode : FunctionNInNOut, IGeneratesFunction
AddSlot("UV", "uv", Graphing.SlotType.Input, SlotValueType.Vector2, Vector4.zero);
AddSlot("AngleOffset", "angleOffset", Graphing.SlotType.Input, SlotValueType.Vector1, new Vector4(2.0f,0,0,0));
AddSlot("Cellular", "n1", Graphing.SlotType.Output, SlotValueType.Vector1, Vector4.zero);
AddSlot("Tile", "n2", Graphing.SlotType.Output, SlotValueType.Vector1, Vector4.zero);
AddSlot("1 - Cellular", "n3", Graphing.SlotType.Output, SlotValueType.Vector1, Vector4.zero);
}
protected override string GetFunctionName()

protected override string GetInputSlot1Name()
{
return "UV";
}
protected override MaterialSlot GetInputSlot1()
{
return new MaterialSlot(InputSlot1Id, GetInputSlot1Name(), kInputSlot1ShaderName, UnityEngine.Graphing.SlotType.Input, SlotValueType.Vector2, Vector2.zero);
}
protected override string GetInputSlot2Name()
{
return "AngleOffset";
}
protected override MaterialSlot GetInputSlot2()
public override bool hasPreview
return new MaterialSlot(InputSlot2Id, GetInputSlot2Name(), kInputSlot2ShaderName, UnityEngine.Graphing.SlotType.Input, SlotValueType.Vector1, Vector2.zero);
}
protected override MaterialSlot GetOutputSlot()
{
return new MaterialSlot(OutputSlotId, GetOutputSlotName(), kOutputSlotShaderName, UnityEngine.Graphing.SlotType.Output, SlotValueType.Vector3, Vector3.zero);
get
{
return true;
}
}
public void GenerateNodeFunction(ShaderGenerator visitor, GenerationMode generationMode)

outputString.Deindent();
outputString.AddShaderChunk("}", false);
outputString.AddShaderChunk(GetFunctionPrototype("uv", "angleOffset"), false);
outputString.AddShaderChunk(GetFunctionPrototype(), false);
outputString.AddShaderChunk("{", false);
outputString.Indent();

outputString.AddShaderChunk("float3 res = float3(8.0, 0.0, 0.0);", false);
outputString.AddShaderChunk("for(int y=-1; y<=1; y++)", false);
outputString.AddShaderChunk("{", false);

outputString.Indent();
outputString.AddShaderChunk("res = float3(d, offset.x, offset.y);", false);
outputString.AddShaderChunk("n1 = res.x;", false);
outputString.AddShaderChunk("n2 = res.y;", false);
outputString.AddShaderChunk("n3 = 1.0 - res.x;", false);
outputString.Deindent();
outputString.AddShaderChunk("}", false);

outputString.Deindent();
outputString.AddShaderChunk("}", false);
outputString.AddShaderChunk("return res;", false);
outputString.Deindent();

116
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Math/Matrix/MatrixMultiplyNode.cs


namespace UnityEngine.MaterialGraph
{
[Title("Math/Matrix/Multiply")]
public class MatrixMultiplyNode : Function2Input, IGeneratesFunction
[Title("Math/Matrix/MultiplyMatrix")]
public class MatrixMultiplyNode : AbstractMaterialNode, IGeneratesBodyCode, IGeneratesFunction
protected const string kInputSlot1ShaderName = "Input1";
protected const string kInputSlot2ShaderName = "Input2";
protected const string kOutputSlotShaderName = "Output";
public const int InputSlot1Id = 0;
public const int InputSlot2Id = 1;
public const int OutputSlotId = 2;
public override bool hasPreview
{
get { return false; }
}
name = "MatrixMultiply";
name = "MultiplyMatrix";
UpdateNodeAfterDeserialization();
protected override string GetFunctionName()
protected string GetFunctionName()
public void GenerateNodeFunction(ShaderGenerator visitor, GenerationMode generationMode)
public sealed override void UpdateNodeAfterDeserialization()
var outputString = new ShaderGenerator();
outputString.AddShaderChunk(GetFunctionPrototype("arg1", "arg2"), false);
outputString.AddShaderChunk("{", false);
outputString.Indent();
outputString.AddShaderChunk("return mul(arg1, arg2);", false);
outputString.Deindent();
outputString.AddShaderChunk("}", false);
AddSlot(GetInputSlot1());
AddSlot(GetInputSlot2());
AddSlot(GetOutputSlot());
RemoveSlotsNameNotMatching(validSlots);
}
visitor.AddShaderChunk(outputString.GetShaderString(0), true);
protected int[] validSlots
{
get { return new[] { InputSlot1Id, InputSlot2Id, OutputSlotId }; }
public override bool hasPreview
protected MaterialSlot GetInputSlot1()
get { return false; }
return new MaterialSlot(InputSlot1Id, GetInputSlot1Name(), kInputSlot1ShaderName, SlotType.Input, SlotValueType.Matrix4, Vector4.zero);
/*protected override MaterialSlot GetInputSlot1()
protected MaterialSlot GetInputSlot2()
return new MaterialSlot(InputSlot1Id, GetInputSlot1Name(), kInputSlot1ShaderName, SlotType.Input, SlotValueType.Matrix3, Vector4.zero);
return new MaterialSlot(InputSlot2Id, GetInputSlot2Name(), kInputSlot2ShaderName, SlotType.Input, SlotValueType.Matrix4, Vector4.zero);
protected override MaterialSlot GetInputSlot2()
protected MaterialSlot GetOutputSlot()
return new MaterialSlot(InputSlot2Id, GetInputSlot2Name(), kInputSlot2ShaderName, SlotType.Input, SlotValueType.Matrix3, Vector4.zero);
return new MaterialSlot(OutputSlotId, GetOutputSlotName(), kOutputSlotShaderName, SlotType.Output, SlotValueType.Matrix4, Vector4.zero);
protected override MaterialSlot GetOutputSlot()
protected virtual string GetInputSlot1Name()
return new MaterialSlot(OutputSlotId, GetOutputSlotName(), kOutputSlotShaderName, SlotType.Output, SlotValueType.Matrix3, Vector4.zero);
}*/
return "Input1";
}
protected virtual string GetInputSlot2Name()
{
return "Input2";
}
protected string GetOutputSlotName()
{
return "Output";
}
protected string GetFunctionPrototype(string arg1Name, string arg2Name)
{
return "inline " + precision + outputDimension + " " + GetFunctionName() + " ("
+ precision + input1Dimension + " " + arg1Name + ", "
+ precision + input2Dimension + " " + arg2Name + ")";
}
public void GenerateNodeCode(ShaderGenerator visitor, GenerationMode generationMode)
{
NodeUtils.SlotConfigurationExceptionIfBadConfiguration(this, new[] { InputSlot1Id, InputSlot2Id }, new[] { OutputSlotId });
string input1Value = GetSlotValue(InputSlot1Id, generationMode);
string input2Value = GetSlotValue(InputSlot2Id, generationMode);
visitor.AddShaderChunk(precision + outputDimension + " " + GetVariableNameForSlot(OutputSlotId) + " = " + GetFunctionCallBody(input1Value, input2Value) + ";", true);
}
protected string GetFunctionCallBody(string input1Value, string input2Value)
{
return GetFunctionName() + " (" + input1Value + ", " + input2Value + ")";
}
public string outputDimension
{
get { return ConvertConcreteSlotValueTypeToString(FindInputSlot<MaterialSlot>(InputSlot2Id).concreteValueType); }
}
private string input1Dimension
{
get { return ConvertConcreteSlotValueTypeToString(FindInputSlot<MaterialSlot>(InputSlot1Id).concreteValueType); }
}
private string input2Dimension
{
get { return ConvertConcreteSlotValueTypeToString(FindInputSlot<MaterialSlot>(InputSlot2Id).concreteValueType); }
}
public void GenerateNodeFunction(ShaderGenerator visitor, GenerationMode generationMode)
{
var outputString = new ShaderGenerator();
outputString.AddShaderChunk(GetFunctionPrototype("arg1", "arg2"), false);
outputString.AddShaderChunk("{", false);
outputString.Indent();
outputString.AddShaderChunk("return mul(arg1, arg2);", false);
outputString.Deindent();
outputString.AddShaderChunk("}", false);
visitor.AddShaderChunk(outputString.GetShaderString(0), true);
}
}
}

21
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Math/Matrix/MatrixTransposeNode.cs


using UnityEngine.Graphing;
[Title("Matrix/Transpose Node")]
[Title("Math/Matrix/TransposeMatrix")]
name = "MatrixTranspose";
name = "TransposeMatrix";
}
public override bool hasPreview
{
get { return false; }
}
public void GenerateNodeFunction(ShaderGenerator visitor, GenerationMode generationMode)

outputString.AddShaderChunk("}", false);
visitor.AddShaderChunk(outputString.GetShaderString(0), true);
}
protected override MaterialSlot GetInputSlot()
{
return new MaterialSlot(InputSlotId, GetInputSlotName(), kInputSlotShaderName, SlotType.Input, SlotValueType.Matrix4, Vector4.zero);
}
protected override MaterialSlot GetOutputSlot()
{
return new MaterialSlot(OutputSlotId, GetOutputSlotName(), kOutputSlotShaderName, SlotType.Output, SlotValueType.Matrix4, Vector4.zero);
}
}
}

41
MaterialGraphProject/Assets/Andre/Nodes/Editor/TransformNodePresenter.cs


using System;
using System.Collections.Generic;
using RMGUI.GraphView;
using UnityEditor.Graphing.Drawing;
using UnityEngine.MaterialGraph;
using UnityEngine;
namespace UnityEditor.MaterialGraph.Drawing
{
class TransformControlPresenter : GraphControlPresenter
{
public override void OnGUIHandler()
{
base.OnGUIHandler();
var tNode = node as TransformNode;
if (tNode == null)
return;
//tNode.floatType = (FloatPropertyChunk.FloatType)EditorGUILayout.EnumPopup ("Float", tNode.floatType);
}
public override float GetHeight()
{
return (EditorGUIUtility.singleLineHeight + 16 * EditorGUIUtility.standardVerticalSpacing) + EditorGUIUtility.standardVerticalSpacing;
}
}
[Serializable]
public class TransformNodePresenter : PropertyNodePresenter
{
protected override IEnumerable<GraphElementPresenter> GetControlData()
{
var instance = CreateInstance<TransformControlPresenter>();
instance.Initialize(node);
return new List<GraphElementPresenter>(base.GetControlData()) { instance };
}
}
}

12
MaterialGraphProject/Assets/Andre/Nodes/Editor/TransformNodePresenter.cs.meta


fileFormatVersion: 2
guid: 01ea0408c41734e0b8b28e0983f7a700
timeCreated: 1476732809
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

34
MaterialGraphProject/Assets/Andre/Nodes/TransformNode.cs


namespace UnityEngine.MaterialGraph
{
[Title ("Math/Vector/Transform")]
public class TransformNode : Function1Input
{
public TransformNode ()
{
name = "Transform";
}
protected override string GetFunctionName ()
{
//mul(unity_WorldToObject, float4(i.posWorld.rgb,0) ).xyz - world to local
//mul( tangentTransform, i.posWorld.rgb ).xyz - world to tangent
//mul( UNITY_MATRIX_V, float4(i.posWorld.rgb,0) ).xyz - world to view
//mul( unity_ObjectToWorld, float4(i.posWorld.rgb,0) ).xyz - local to world
//mul( tangentTransform, mul( unity_ObjectToWorld, float4(i.posWorld.rgb,0) ).xyz - local to tangent
//mul( UNITY_MATRIX_MV, float4(i.posWorld.rgb,0) ).xyz - local to view
//mul( i.posWorld.rgb, tangentTransform ).xyz - tangent to world
//mul( unity_WorldToObject, float4(mul( i.posWorld.rgb, tangentTransform ),0) ).xyz - tangent to local
//mul( UNITY_MATRIX_V, float4(mul( i.posWorld.rgb, tangentTransform ),0) ).xyz - tangent to view
//mul( float4(i.posWorld.rgb,0), UNITY_MATRIX_V ).xyz - view to world
//mul( float4(i.posWorld.rgb,0), UNITY_MATRIX_MV ).xyz - view to local
//mul( tangentTransform, mul( float4(i.posWorld.rgb,0), UNITY_MATRIX_V ).xyz ).xyz - view to tangent
return "exp";
}
}
}

12
MaterialGraphProject/Assets/Andre/Nodes/TransformNode.cs.meta


fileFormatVersion: 2
guid: 1d252394349e74b278276a6e0857635e
timeCreated: 1490745697
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

14
MaterialGraphProject/Assets/Matt/CommonMatrixType.cs


namespace UnityEngine.MaterialGraph
{
public enum CommonMatrixType
{
ModelView,
View,
Projection,
ViewProjection,
TransposeModelView,
InverseTransposeModelView,
ObjectToWorld,
WorldToObject
};
}

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


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

9
MaterialGraphProject/Assets/Matt/Examples.meta


fileFormatVersion: 2
guid: 6a5311f2c2db6e34f8da2333309aab50
folderAsset: yes
timeCreated: 1495713891
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

51
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/MatrixCommonNodePresenter.cs


using System;
using System.Collections.Generic;
using UnityEngine.MaterialGraph;
using RMGUI.GraphView;
using UnityEditor.Graphing.Drawing;
namespace UnityEditor.MaterialGraph.Drawing
{
[Serializable]
class MatrixCommonContolPresenter : GraphControlPresenter
{
private string[] m_MatrixTypeNames;
private string[] matrixTypeNames
{
get
{
if (m_MatrixTypeNames == null)
m_MatrixTypeNames = Enum.GetNames(typeof(CommonMatrixType));
return m_MatrixTypeNames;
}
}
public override void OnGUIHandler()
{
base.OnGUIHandler();
var cNode = node as UnityEngine.MaterialGraph.MatrixCommonNode;
if (cNode == null)
return;
cNode.matrix = (CommonMatrixType)EditorGUILayout.Popup((int)cNode.matrix, matrixTypeNames, EditorStyles.popup);
}
public override float GetHeight()
{
return EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
}
}
[Serializable]
public class MatrixCommonNodePresenter : MaterialNodePresenter
{
protected override IEnumerable<GraphElementPresenter> GetControlData()
{
var instance = CreateInstance<MatrixCommonContolPresenter>();
instance.Initialize(node);
return new List<GraphElementPresenter> { instance };
}
}
}

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


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

43
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/ScatterNodePresenter.cs


using System;
using System.Collections.Generic;
using RMGUI.GraphView;
using UnityEditor.Graphing.Drawing;
namespace UnityEditor.MaterialGraph.Drawing
{
[Serializable]
class ScatterContolPresenter : GraphControlPresenter
{
public override void OnGUIHandler()
{
base.OnGUIHandler();
var cNode = node as UnityEngine.MaterialGraph.ScatterNode;
if (cNode == null)
return;
cNode.num = EditorGUILayout.IntField(cNode.num, "Number", null);
cNode.num = Math.Min(cNode.num, 50); //prevent infinite => hang!
}
public override float GetHeight()
{
return EditorGUIUtility.singleLineHeight + 10 * EditorGUIUtility.standardVerticalSpacing;
}
}
[Serializable]
public class ScatterNodePresenter : MaterialNodePresenter
{
protected override IEnumerable<GraphElementPresenter> GetControlData()
{
var instance = CreateInstance<ScatterContolPresenter>();
instance.Initialize(node);
return new List<GraphElementPresenter> { instance };
}
}
}

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


fileFormatVersion: 2
guid: 324b6873762a09544a3cebd0f0c7721d
timeCreated: 1495713547
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

68
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Input/Matrix/MatrixCommonNode.cs


using System.ComponentModel;
using UnityEngine.Graphing;
using System.Collections.Generic;
namespace UnityEngine.MaterialGraph
{
[Title("Input/Matrix/CommonMatrix")]
public class MatrixCommonNode : AbstractMaterialNode
{
static Dictionary<CommonMatrixType, string> m_matrixList = new Dictionary<CommonMatrixType, string>
{
{CommonMatrixType.ModelView, "UNITY_MATRIX_MV"},
{CommonMatrixType.View, "UNITY_MATRIX_V"},
{CommonMatrixType.Projection, "UNITY_MATRIX_P"},
{CommonMatrixType.ViewProjection, "UNITY_MATRIX_VP"},
{CommonMatrixType.TransposeModelView, "UNITY_MATRIX_T_MV"},
{CommonMatrixType.InverseTransposeModelView, "UNITY_MATRIX_IT_MV"},
{CommonMatrixType.ObjectToWorld, "unity_ObjectToWorld"},
{CommonMatrixType.WorldToObject, "unity_WorldToObject"},
};
[SerializeField]
private CommonMatrixType m_matrix = CommonMatrixType.ModelView;
private const int kOutputSlotId = 0;
private const string kOutputSlotName = "Output";
public override bool hasPreview { get { return false; } }
public CommonMatrixType matrix
{
get { return m_matrix; }
set
{
if (m_matrix == value)
return;
m_matrix = value;
if (onModified != null)
{
onModified(this, ModificationScope.Graph);
}
}
}
public MatrixCommonNode()
{
name = "CommonMatrix";
UpdateNodeAfterDeserialization();
}
public sealed override void UpdateNodeAfterDeserialization()
{
AddSlot(new MaterialSlot(kOutputSlotId, kOutputSlotName, kOutputSlotName, SlotType.Output, SlotValueType.Matrix4, Vector4.zero));
RemoveSlotsNameNotMatching(new[] { kOutputSlotId });
}
public override string GetVariableNameForSlot(int slotId)
{
return m_matrixList[matrix];
}
public bool RequiresVertexColor()
{
return true;
}
}
}

12
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Input/Matrix/MatrixCommonNode.cs.meta


fileFormatVersion: 2
guid: 080829bc2938e23489292a936367364d
timeCreated: 1481123160
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

9
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Math/Matrix.meta


fileFormatVersion: 2
guid: bfc8dbcaa9711c945b8fd983b819335d
folderAsset: yes
timeCreated: 1495700996
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

55
MaterialGraphProject/Assets/_MingWai/ColorBalanceNode.cs


namespace UnityEngine.MaterialGraph
{
[Title("ColorBalance")]
public class ColorBalanceNode : FunctionNInNOut, IGeneratesFunction
{
public ColorBalanceNode()
{
name = "ColorBalance";
AddSlot("Color", "inputColor", Graphing.SlotType.Input, SlotValueType.Vector4, Vector4.one);
AddSlot("AdjustRGB", "adjustRGB", Graphing.SlotType.Input, SlotValueType.Vector3, Vector3.zero);
AddSlot("RGBA", "finalColor", Graphing.SlotType.Output, SlotValueType.Vector4, Vector4.zero);
UpdateNodeAfterDeserialization();
}
protected override string GetFunctionName()
{
return "unity_colorbalance_" + precision;
}
public override bool hasPreview
{
get { return true; }
}
public void GenerateNodeFunction(ShaderGenerator visitor, GenerationMode generationMode)
{
var outputString = new ShaderGenerator();
outputString.AddShaderChunk(GetFunctionPrototype(), false);
outputString.AddShaderChunk("{", false);
outputString.Indent();
outputString.AddShaderChunk("float red = 0;", false);
outputString.AddShaderChunk("float green = 0;", false);
outputString.AddShaderChunk("float blue = 0;", false);
outputString.AddShaderChunk("red = 1.00f / (1-adjustRGB.r) * inputColor.r;", false);
outputString.AddShaderChunk("green = 1.00f / (1-adjustRGB.g) * inputColor.g;", false);
outputString.AddShaderChunk("blue = 1.00f / (1-adjustRGB.b) * inputColor.b;", false);
outputString.AddShaderChunk("red = clamp(red,0.00f,1.00f);", false);
outputString.AddShaderChunk("green = clamp(green,0.00f,1.00f);", false);
outputString.AddShaderChunk("blue = clamp(blue,0.00f,1.00f);", false);
outputString.AddShaderChunk("finalColor.r = red;", false);
outputString.AddShaderChunk("finalColor.g = green;", false);
outputString.AddShaderChunk("finalColor.b = blue;", false);
outputString.AddShaderChunk("finalColor.a = inputColor.a;", false);
outputString.Deindent();
outputString.AddShaderChunk("}", false);
visitor.AddShaderChunk(outputString.GetShaderString(0), true);
}
}
}

12
MaterialGraphProject/Assets/_MingWai/ColorBalanceNode.cs.meta


fileFormatVersion: 2
guid: 1e71a86c3ae7610479697effc1e8b703
timeCreated: 1495705851
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

67
MaterialGraphProject/Assets/_MingWai/RandomRangeNode.cs


namespace UnityEngine.MaterialGraph
{
[Title("Math/Range/RandomRange")]
public class RandomRangeNode : Function3Input, IGeneratesFunction
{
public RandomRangeNode()
{
name = "RandomRange";
}
protected override string GetFunctionName()
{
return "unity_randomrange_" + precision;
}
protected override string GetInputSlot1Name()
{
return "Seed";
}
protected override MaterialSlot GetInputSlot1()
{
return new MaterialSlot(InputSlot1Id, GetInputSlot1Name(), kInputSlot1ShaderName, UnityEngine.Graphing.SlotType.Input, SlotValueType.Vector2, Vector2.zero);
}
protected override string GetInputSlot2Name()
{
return "Min";
}
protected override MaterialSlot GetInputSlot2()
{
return new MaterialSlot(InputSlot2Id, GetInputSlot2Name(), kInputSlot2ShaderName, UnityEngine.Graphing.SlotType.Input, SlotValueType.Vector1, Vector2.zero);
}
protected override string GetInputSlot3Name()
{
return "Max";
}
protected override MaterialSlot GetInputSlot3()
{
return new MaterialSlot(InputSlot3Id, GetInputSlot3Name(), kInputSlot3ShaderName, UnityEngine.Graphing.SlotType.Input, SlotValueType.Vector1, Vector3.zero);
}
protected override MaterialSlot GetOutputSlot()
{
return new MaterialSlot(OutputSlotId, GetOutputSlotName(), kOutputSlotShaderName, UnityEngine.Graphing.SlotType.Output, SlotValueType.Vector1, Vector2.zero);
}
public void GenerateNodeFunction(ShaderGenerator visitor, GenerationMode generationMode)
{
var outputString = new ShaderGenerator();
outputString.AddShaderChunk(GetFunctionPrototype("seed", "min", "max"), false);
outputString.AddShaderChunk("{", false);
outputString.Indent();
outputString.AddShaderChunk("float randomno = frac(sin(dot(seed, float2(12.9898, 78.233)))*43758.5453);", false);
outputString.AddShaderChunk("return floor(randomno * (max - min + 1)) + min;", false);
outputString.Deindent();
outputString.AddShaderChunk("}", false);
visitor.AddShaderChunk(outputString.GetShaderString(0), true);
}
}
}

12
MaterialGraphProject/Assets/_MingWai/RandomRangeNode.cs.meta


fileFormatVersion: 2
guid: 5e7048f6323341547955eab30f96151f
timeCreated: 1495703851
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

121
MaterialGraphProject/Assets/_MingWai/ScatterNode.cs


using UnityEngine.Graphing;
namespace UnityEngine.MaterialGraph
{
[Title("Procedural/Scatter")]
public class ScatterNode : FunctionNInNOut, IGeneratesFunction
{
[SerializeField]
private int m_num = 1 ;
public int num
{
get { return m_num; }
set
{
if (m_num == value)
{
return;
}
m_num = value;
if (onModified != null)
{
onModified(this, ModificationScope.Graph);
}
}
}
public ScatterNode()
{
name = "Scatter";
AddSlot("Texture", "inputTex", Graphing.SlotType.Input, SlotValueType.sampler2D, Vector4.zero);
AddSlot("UV", "inputUV", Graphing.SlotType.Input, SlotValueType.Vector2, Vector2.one);
AddSlot("Seed", "seed", Graphing.SlotType.Input, SlotValueType.Vector2, Vector2.one);
AddSlot("PositionRange", "p_range", Graphing.SlotType.Input, SlotValueType.Vector2, Vector2.zero);
AddSlot("RotationRange", "r_range", Graphing.SlotType.Input, SlotValueType.Vector2, Vector2.zero);
AddSlot("ScaleRange", "s_range", Graphing.SlotType.Input, SlotValueType.Vector2, Vector2.zero);
AddSlot("RGBA", "finalColor", Graphing.SlotType.Output, SlotValueType.Vector4, Vector4.zero);
UpdateNodeAfterDeserialization();
}
protected override string GetFunctionName()
{
return "unity_scatter_" + precision;
}
public override bool hasPreview
{
get { return true; }
}
public void GenerateNodeFunction(ShaderGenerator visitor, GenerationMode generationMode)
{
var outputString = new ShaderGenerator();
//RotateUVFunction ===================================================================
outputString.AddShaderChunk("inline float2 rotateUV( float2 arg1, float arg2 )", false);
outputString.AddShaderChunk("{", false);
outputString.Indent();
//center texture's pivot
outputString.AddShaderChunk("arg1.xy -= 0.5;", false);
//rotation matrix
outputString.AddShaderChunk(precision + " s = sin(arg2);", false);
outputString.AddShaderChunk(precision + " c = cos(arg2);", false);
outputString.AddShaderChunk(precision + "2x2 rMatrix = float2x2(c, -s, s, c);", false);
//center rotation matrix
outputString.AddShaderChunk("rMatrix *= 0.5;", false);
outputString.AddShaderChunk("rMatrix += 0.5;", false);
outputString.AddShaderChunk("rMatrix = rMatrix*2 - 1;", false);
//multiply the UVs by the rotation matrix
outputString.AddShaderChunk("arg1.xy = mul(arg1.xy, rMatrix);", false);
outputString.AddShaderChunk("arg1.xy += 0.5;", false);
outputString.AddShaderChunk("return " + "arg1;", false);
outputString.Deindent();
outputString.AddShaderChunk("}", false);
//RamdomFunction ===================================================================
outputString.AddShaderChunk("inline float randomrange(float2 randomseed, float min, float max)", false);
outputString.AddShaderChunk("{", false);
outputString.Indent();
outputString.AddShaderChunk("float randomno = frac(sin(dot(randomseed, float2(12.9898, 78.233)))*43758.5453);", false);
outputString.AddShaderChunk("return floor(randomno * (max - min + 1)) + min;", false);
outputString.Deindent();
outputString.AddShaderChunk("}", false);
//ScatterFunction ===================================================================
outputString.AddShaderChunk(GetFunctionPrototype(), false);
outputString.AddShaderChunk("{", false);
outputString.Indent();
outputString.AddShaderChunk("finalColor = float4(0,0,0,0);", false);
outputString.AddShaderChunk("float2 newuv = inputUV;", false);
outputString.AddShaderChunk("float4 tex = tex2D(inputTex,newuv);", false);
for (int i=0; i<m_num; i++)
{
//random UV
outputString.AddShaderChunk("newuv *= randomrange(seed,s_range.x,s_range.y);", false); //Scale
outputString.AddShaderChunk("newuv = rotateUV(newuv,randomrange(seed,r_range.x,r_range.y));", false); //Rotate
outputString.AddShaderChunk("newuv += randomrange(seed,p_range.x,p_range.y));", false); //Position
//seamless
//sample
outputString.AddShaderChunk("tex = tex2D(inputTex,newuv);", false);
//blend together
outputString.AddShaderChunk("finalColor += tex/"+m_num+";", false);
}
outputString.Deindent();
outputString.AddShaderChunk("}", false);
visitor.AddShaderChunk(outputString.GetShaderString(0), true);
}
}
}

12
MaterialGraphProject/Assets/_MingWai/ScatterNode.cs.meta


fileFormatVersion: 2
guid: 7726e0a353d4a53499b58140956b2c9b
timeCreated: 1495709638
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

1
MaterialGraphProject/Assets/Matt/Examples/HueStrip.ShaderGraph
文件差异内容过多而无法显示
查看文件

9
MaterialGraphProject/Assets/Matt/Examples/HueStrip.ShaderGraph.meta


fileFormatVersion: 2
guid: ef4863cc0eaedba4d8ab1d6de73caabf
timeCreated: 1495713916
licenseType: Pro
ScriptedImporter:
userData:
assetBundleName:
assetBundleVariant:
script: {fileID: 11500000, guid: 625f186215c104763be7675aa2d941aa, type: 3}

1
MaterialGraphProject/Assets/Matt/Examples/Swirl.ShaderGraph
文件差异内容过多而无法显示
查看文件

9
MaterialGraphProject/Assets/Matt/Examples/Swirl.ShaderGraph.meta


fileFormatVersion: 2
guid: c4bdf1ebef2b7aa4f8683354d16b64a1
timeCreated: 1495715410
licenseType: Pro
ScriptedImporter:
userData:
assetBundleName:
assetBundleVariant:
script: {fileID: 11500000, guid: 625f186215c104763be7675aa2d941aa, type: 3}

123
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Math/Matrix/MatrixMultiplyByVectorNode.cs


using UnityEngine.Graphing;
namespace UnityEngine.MaterialGraph
{
[Title("Math/Matrix/MultiplyMatrixByVector")]
public class MatrixMultiplyByVectorNode : AbstractMaterialNode, IGeneratesBodyCode, IGeneratesFunction
{
protected const string kInputSlot1ShaderName = "Input1";
protected const string kInputSlot2ShaderName = "Input2";
protected const string kOutputSlotShaderName = "Output";
public const int InputSlot1Id = 0;
public const int InputSlot2Id = 1;
public const int OutputSlotId = 2;
public override bool hasPreview
{
get { return false; }
}
public MatrixMultiplyByVectorNode()
{
name = "MultiplyMatrixByVector";
UpdateNodeAfterDeserialization();
}
protected string GetFunctionName()
{
return "unity_matrix_multiplybyvector_" + precision;
}
public sealed override void UpdateNodeAfterDeserialization()
{
AddSlot(GetInputSlot1());
AddSlot(GetInputSlot2());
AddSlot(GetOutputSlot());
RemoveSlotsNameNotMatching(validSlots);
}
protected int[] validSlots
{
get { return new[] { InputSlot1Id, InputSlot2Id, OutputSlotId }; }
}
protected MaterialSlot GetInputSlot1()
{
return new MaterialSlot(InputSlot1Id, GetInputSlot1Name(), kInputSlot1ShaderName, SlotType.Input, SlotValueType.Matrix4, Vector4.zero);
}
protected MaterialSlot GetInputSlot2()
{
return new MaterialSlot(InputSlot2Id, GetInputSlot2Name(), kInputSlot2ShaderName, SlotType.Input, SlotValueType.Vector4, Vector4.zero);
}
protected MaterialSlot GetOutputSlot()
{
return new MaterialSlot(OutputSlotId, GetOutputSlotName(), kOutputSlotShaderName, SlotType.Output, SlotValueType.Vector4, Vector4.zero);
}
protected virtual string GetInputSlot1Name()
{
return "Input1";
}
protected virtual string GetInputSlot2Name()
{
return "Input2";
}
protected string GetOutputSlotName()
{
return "Output";
}
protected string GetFunctionPrototype(string arg1Name, string arg2Name)
{
return "inline " + precision + outputDimension + " " + GetFunctionName() + " ("
+ precision + input1Dimension + " " + arg1Name + ", "
+ precision + input2Dimension + " " + arg2Name + ")";
}
public void GenerateNodeCode(ShaderGenerator visitor, GenerationMode generationMode)
{
NodeUtils.SlotConfigurationExceptionIfBadConfiguration(this, new[] { InputSlot1Id, InputSlot2Id }, new[] { OutputSlotId });
string input1Value = GetSlotValue(InputSlot1Id, generationMode);
string input2Value = GetSlotValue(InputSlot2Id, generationMode);
visitor.AddShaderChunk(precision + outputDimension + " " + GetVariableNameForSlot(OutputSlotId) + " = " + GetFunctionCallBody(input1Value, input2Value) + ";", true);
}
protected string GetFunctionCallBody(string input1Value, string input2Value)
{
return GetFunctionName() + " (" + input1Value + ", " + input2Value + ")";
}
public string outputDimension
{
get { return ConvertConcreteSlotValueTypeToString(FindInputSlot<MaterialSlot>(InputSlot2Id).concreteValueType); }
}
private string input1Dimension
{
get { return ConvertConcreteSlotValueTypeToString(FindInputSlot<MaterialSlot>(InputSlot1Id).concreteValueType); }
}
private string input2Dimension
{
get { return ConvertConcreteSlotValueTypeToString(FindInputSlot<MaterialSlot>(InputSlot2Id).concreteValueType); }
}
public void GenerateNodeFunction(ShaderGenerator visitor, GenerationMode generationMode)
{
var outputString = new ShaderGenerator();
outputString.AddShaderChunk(GetFunctionPrototype("arg1", "arg2"), false);
outputString.AddShaderChunk("{", false);
outputString.Indent();
outputString.AddShaderChunk("return mul(arg1, arg2);", false);
outputString.Deindent();
outputString.AddShaderChunk("}", false);
visitor.AddShaderChunk(outputString.GetShaderString(0), true);
}
}
}

12
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Math/Matrix/MatrixMultiplyByVectorNode.cs.meta


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

/MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/MatrixMultiplyNode.cs → /MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Math/Matrix/MatrixMultiplyNode.cs

/MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/MatrixMultiplyNode.cs.meta → /MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Math/Matrix/MatrixMultiplyNode.cs.meta

/MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/MatrixTransposeNode.cs → /MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Math/Matrix/MatrixTransposeNode.cs

/MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/MatrixTransposeNode.cs.meta → /MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Math/Matrix/MatrixTransposeNode.cs.meta

正在加载...
取消
保存