浏览代码

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

/main
Matt Dean 8 年前
当前提交
423d104b
共有 3 个文件被更改,包括 121 次插入29 次删除
  1. 34
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/UV/CartesianToPolarNode.cs
  2. 104
      MaterialGraphProject/Assets/Brandon/NoiseNode.cs
  3. 12
      MaterialGraphProject/Assets/Brandon/NoiseNode.cs.meta

34
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/UV/CartesianToPolarNode.cs


namespace UnityEngine.MaterialGraph
{
[Title("UV/Cartesian To Polar")]
public class CartesianToPolarNode : Function3Input, IGeneratesFunction
public class CartesianToPolarNode : Function1Input, IGeneratesFunction
{
public CartesianToPolarNode()
{

return "unity_cartesiantopolar_" + precision;
}
protected override string GetInputSlot1Name()
protected override string GetInputSlotName()
protected override string GetInputSlot2Name()
{
return "HorizontalTileScale";
}
protected override string GetInputSlot3Name()
{
return "VerticalTileScale";
}
protected override MaterialSlot GetInputSlot1()
{
return new MaterialSlot(InputSlot1Id, GetInputSlot1Name(), kInputSlot1ShaderName, UnityEngine.Graphing.SlotType.Input, SlotValueType.Vector2, Vector2.zero);
}
protected override MaterialSlot GetInputSlot2()
protected override MaterialSlot GetInputSlot()
return new MaterialSlot(InputSlot2Id, GetInputSlot2Name(), kInputSlot2ShaderName, UnityEngine.Graphing.SlotType.Input, SlotValueType.Vector1, Vector4.zero);
}
protected override MaterialSlot GetInputSlot3()
{
return new MaterialSlot(InputSlot3Id, GetInputSlot3Name(), kInputSlot3ShaderName, UnityEngine.Graphing.SlotType.Input, SlotValueType.Vector1, Vector4.zero);
}
protected override MaterialSlot GetOutputSlot()
{
return new MaterialSlot(OutputSlotId, GetOutputSlotName(), kOutputSlotShaderName, UnityEngine.Graphing.SlotType.Output, SlotValueType.Vector2, Vector2.zero);
return new MaterialSlot(InputSlotId, GetInputSlotName(), kInputSlotShaderName, UnityEngine.Graphing.SlotType.Input, SlotValueType.Vector2, Vector2.zero);
outputString.AddShaderChunk(GetFunctionPrototype("uv", "horizontalTileScale", "verticalTileScale"), false);
outputString.AddShaderChunk(GetFunctionPrototype("uv"), false);
outputString.AddShaderChunk("{", false);
outputString.Indent();
outputString.AddShaderChunk("float radius = length(uv);", false);

104
MaterialGraphProject/Assets/Brandon/NoiseNode.cs


namespace UnityEngine.MaterialGraph
{
[Title("Input/Procedural/Noise Node")]
public class NoiseNode : Function1Input, IGeneratesFunction
{
public NoiseNode()
{
name = "NoiseNode";
}
protected override string GetFunctionName()
{
return "unity_noise_" + precision;
}
protected override string GetInputSlotName()
{
return "UV";
}
protected override MaterialSlot GetInputSlot()
{
return new MaterialSlot(InputSlotId, GetInputSlotName(), kInputSlotShaderName, UnityEngine.Graphing.SlotType.Input, SlotValueType.Vector2, Vector2.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("inline float unity_randomValue (float2 uv)", false);
outputString.AddShaderChunk("{", false);
outputString.Indent();
outputString.AddShaderChunk("return frac(sin(dot(uv, float2(12.9898, 78.233)))*43758.5453);", false);
outputString.Deindent();
outputString.AddShaderChunk("}", false);
outputString.AddShaderChunk("inline float unity_interpolate (float a, float b, float t)", false);
outputString.AddShaderChunk("{", false);
outputString.Indent();
outputString.AddShaderChunk("return (1.0-t)*a + (t*b);", false);
outputString.Deindent();
outputString.AddShaderChunk("}", false);
outputString.AddShaderChunk("inline float unity_valueNoise (float2 uv)", false);
outputString.AddShaderChunk("{", false);
outputString.Indent();
outputString.AddShaderChunk("float2 i = floor(uv);", false);
outputString.AddShaderChunk("float2 f = frac(uv);", false);
outputString.AddShaderChunk("f = f * f * (3.0 - 2.0 * f);", false);
outputString.AddShaderChunk("uv = abs(frac(uv) - 0.5);", false);
outputString.AddShaderChunk("float2 c0 = i + float2(0.0, 0.0);", false);
outputString.AddShaderChunk("float2 c1 = i + float2(1.0, 0.0);", false);
outputString.AddShaderChunk("float2 c2 = i + float2(0.0, 1.0);", false);
outputString.AddShaderChunk("float2 c3 = i + float2(1.0, 1.0);", false);
outputString.AddShaderChunk("float r0 = unity_randomValue(c0);", false);
outputString.AddShaderChunk("float r1 = unity_randomValue(c1);", false);
outputString.AddShaderChunk("float r2 = unity_randomValue(c2);", false);
outputString.AddShaderChunk("float r3 = unity_randomValue(c3);", false);
outputString.AddShaderChunk("float bottomOfGrid = unity_interpolate(r0, r1, f.x);", false);
outputString.AddShaderChunk("float topOfGrid = unity_interpolate(r2, r3, f.x);", false);
outputString.AddShaderChunk("float t = unity_interpolate(bottomOfGrid, topOfGrid, f.y);", false);
outputString.AddShaderChunk("return t;", false);
outputString.Deindent();
outputString.AddShaderChunk("}", false);
outputString.AddShaderChunk(GetFunctionPrototype("uv"), false);
outputString.AddShaderChunk("{", false);
outputString.Indent();
outputString.AddShaderChunk("float t = 0.0;", false);
outputString.AddShaderChunk("for(int i = 0; i < 3; i++)", false);
outputString.AddShaderChunk("{", false);
outputString.Indent();
outputString.AddShaderChunk("float freq = pow(2.0, float(i));", false);
outputString.AddShaderChunk("float amp = pow(0.5, float(3-i));", false);
outputString.AddShaderChunk("t += unity_valueNoise(float2(uv.x/freq, uv.y/freq))*amp;", false);
outputString.Deindent();
outputString.AddShaderChunk("}", false);
outputString.AddShaderChunk("return t;", false);
outputString.Deindent();
outputString.AddShaderChunk("}", false);
visitor.AddShaderChunk(outputString.GetShaderString(0), true);
}
}
}

12
MaterialGraphProject/Assets/Brandon/NoiseNode.cs.meta


fileFormatVersion: 2
guid: 6e05bd4324babff4498e856ab63b993c
timeCreated: 1495526233
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
正在加载...
取消
保存