浏览代码
Merge branch 'hackweek2017' of https://github.com/stramit/MaterialGraph into hackweek2017
/main
Merge branch 'hackweek2017' of https://github.com/stramit/MaterialGraph into hackweek2017
/main
bfogerty
7 年前
当前提交
995a95bc
共有 42 个文件被更改,包括 919 次插入 和 67 次删除
-
1MaterialGraphProject/Assets/Eduardo/ConstantsNode.cs
-
2MaterialGraphProject/Assets/Eduardo/EduardoTestGraph.ShaderGraph
-
4MaterialGraphProject/Assets/Eduardo/EduardoTestMat.mat
-
2MaterialGraphProject/Assets/Matt/Test.ShaderGraph
-
4MaterialGraphProject/Assets/Matt/Test.ShaderGraph.meta
-
3MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/MaterialGraphPresenter.cs
-
16MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/Vector1NodePresenter.cs
-
42MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Procedural/VoronoiNoise.cs
-
116MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Math/Matrix/MatrixMultiplyNode.cs
-
21MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Math/Matrix/MatrixTransposeNode.cs
-
41MaterialGraphProject/Assets/Andre/Nodes/Editor/TransformNodePresenter.cs
-
12MaterialGraphProject/Assets/Andre/Nodes/Editor/TransformNodePresenter.cs.meta
-
34MaterialGraphProject/Assets/Andre/Nodes/TransformNode.cs
-
12MaterialGraphProject/Assets/Andre/Nodes/TransformNode.cs.meta
-
14MaterialGraphProject/Assets/Matt/CommonMatrixType.cs
-
12MaterialGraphProject/Assets/Matt/CommonMatrixType.cs.meta
-
9MaterialGraphProject/Assets/Matt/Examples.meta
-
51MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/MatrixCommonNodePresenter.cs
-
12MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/MatrixCommonNodePresenter.cs.meta
-
43MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/ScatterNodePresenter.cs
-
12MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/ScatterNodePresenter.cs.meta
-
68MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Input/Matrix/MatrixCommonNode.cs
-
12MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Input/Matrix/MatrixCommonNode.cs.meta
-
9MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Math/Matrix.meta
-
55MaterialGraphProject/Assets/_MingWai/ColorBalanceNode.cs
-
12MaterialGraphProject/Assets/_MingWai/ColorBalanceNode.cs.meta
-
67MaterialGraphProject/Assets/_MingWai/RandomRangeNode.cs
-
12MaterialGraphProject/Assets/_MingWai/RandomRangeNode.cs.meta
-
121MaterialGraphProject/Assets/_MingWai/ScatterNode.cs
-
12MaterialGraphProject/Assets/_MingWai/ScatterNode.cs.meta
-
1MaterialGraphProject/Assets/Matt/Examples/HueStrip.ShaderGraph
-
9MaterialGraphProject/Assets/Matt/Examples/HueStrip.ShaderGraph.meta
-
1MaterialGraphProject/Assets/Matt/Examples/Swirl.ShaderGraph
-
9MaterialGraphProject/Assets/Matt/Examples/Swirl.ShaderGraph.meta
-
123MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Math/Matrix/MatrixMultiplyByVectorNode.cs
-
12MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Math/Matrix/MatrixMultiplyByVectorNode.cs.meta
-
0/MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Math/Matrix/MatrixMultiplyNode.cs
-
0/MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Math/Matrix/MatrixMultiplyNode.cs.meta
-
0/MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Math/Matrix/MatrixTransposeNode.cs
-
0/MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Math/Matrix/MatrixTransposeNode.cs.meta
2
MaterialGraphProject/Assets/Eduardo/EduardoTestGraph.ShaderGraph
文件差异内容过多而无法显示
查看文件
文件差异内容过多而无法显示
查看文件
2
MaterialGraphProject/Assets/Matt/Test.ShaderGraph
文件差异内容过多而无法显示
查看文件
文件差异内容过多而无法显示
查看文件
|
|||
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 }; |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 01ea0408c41734e0b8b28e0983f7a700 |
|||
timeCreated: 1476732809 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
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"; |
|||
} |
|||
} |
|||
} |
|||
|
|
|||
fileFormatVersion: 2 |
|||
guid: 1d252394349e74b278276a6e0857635e |
|||
timeCreated: 1490745697 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
namespace UnityEngine.MaterialGraph |
|||
{ |
|||
public enum CommonMatrixType |
|||
{ |
|||
ModelView, |
|||
View, |
|||
Projection, |
|||
ViewProjection, |
|||
TransposeModelView, |
|||
InverseTransposeModelView, |
|||
ObjectToWorld, |
|||
WorldToObject |
|||
}; |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: e466cff33b1ebe64eb2b897b9534a4a4 |
|||
timeCreated: 1495703998 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: 6a5311f2c2db6e34f8da2333309aab50 |
|||
folderAsset: yes |
|||
timeCreated: 1495713891 |
|||
licenseType: Pro |
|||
DefaultImporter: |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
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 }; |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: b7283eb87c37e4a43b5eddbf2d4360d1 |
|||
timeCreated: 1495448531 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
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 }; |
|||
} |
|||
} |
|||
|
|||
|
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 324b6873762a09544a3cebd0f0c7721d |
|||
timeCreated: 1495713547 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
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; |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 080829bc2938e23489292a936367364d |
|||
timeCreated: 1481123160 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: bfc8dbcaa9711c945b8fd983b819335d |
|||
folderAsset: yes |
|||
timeCreated: 1495700996 |
|||
licenseType: Pro |
|||
DefaultImporter: |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
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); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 1e71a86c3ae7610479697effc1e8b703 |
|||
timeCreated: 1495705851 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
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); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 5e7048f6323341547955eab30f96151f |
|||
timeCreated: 1495703851 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
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); |
|||
} |
|||
} |
|||
} |
|
|||
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
文件差异内容过多而无法显示
查看文件
文件差异内容过多而无法显示
查看文件
|
|||
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
文件差异内容过多而无法显示
查看文件
文件差异内容过多而无法显示
查看文件
|
|||
fileFormatVersion: 2 |
|||
guid: c4bdf1ebef2b7aa4f8683354d16b64a1 |
|||
timeCreated: 1495715410 |
|||
licenseType: Pro |
|||
ScriptedImporter: |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|||
script: {fileID: 11500000, guid: 625f186215c104763be7675aa2d941aa, type: 3} |
|
|||
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); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: ad9cec4b346abf749b3eb1730875ee5d |
|||
timeCreated: 1495542985 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
撰写
预览
正在加载...
取消
保存
Reference in new issue