|
|
|
|
|
|
namespace UnityEngine.MaterialGraph |
|
|
|
{ |
|
|
|
[Title("Procedural/Voronoi Noise")] |
|
|
|
public class VoronoiNoiseNode : Function1Input, IGeneratesFunction |
|
|
|
public class VoronoiNoiseNode : Function2Input, IGeneratesFunction |
|
|
|
{ |
|
|
|
public VoronoiNoiseNode() |
|
|
|
{ |
|
|
|
|
|
|
return "unity_voronoinoise_" + precision; |
|
|
|
} |
|
|
|
|
|
|
|
protected override string GetInputSlotName() |
|
|
|
protected override string GetInputSlot1Name() |
|
|
|
protected override MaterialSlot GetInputSlot() |
|
|
|
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() |
|
|
|
return new MaterialSlot(InputSlotId, GetInputSlotName(), kInputSlotShaderName, UnityEngine.Graphing.SlotType.Input, SlotValueType.Vector2, Vector2.zero); |
|
|
|
return new MaterialSlot(InputSlot2Id, GetInputSlot2Name(), kInputSlot2ShaderName, UnityEngine.Graphing.SlotType.Input, SlotValueType.Vector1, Vector2.zero); |
|
|
|
} |
|
|
|
|
|
|
|
protected override MaterialSlot GetOutputSlot() |
|
|
|
|
|
|
{ |
|
|
|
var outputString = new ShaderGenerator(); |
|
|
|
|
|
|
|
outputString.AddShaderChunk("inline float unity_voronoi_noise_randomVector (float2 uv)", false); |
|
|
|
outputString.AddShaderChunk("inline float2 unity_voronoi_noise_randomVector (float2 uv, float offset)", false); |
|
|
|
outputString.AddShaderChunk("return frac(sin(mul(uv, m)) * 46839.32);", false); |
|
|
|
outputString.AddShaderChunk("uv = frac(sin(mul(uv, m)) * 46839.32);", false); |
|
|
|
outputString.AddShaderChunk("return float2(sin(uv.y*+offset)*0.5+0.5, cos(uv.x*offset)*0.5+0.5);", false); |
|
|
|
outputString.AddShaderChunk(GetFunctionPrototype("uv"), false); |
|
|
|
outputString.AddShaderChunk(GetFunctionPrototype("uv", "angleOffset"), false); |
|
|
|
outputString.AddShaderChunk("{", false); |
|
|
|
outputString.Indent(); |
|
|
|
|
|
|
|
|
|
|
outputString.Indent(); |
|
|
|
|
|
|
|
outputString.AddShaderChunk("float2 lattice = float2(x,y);", false); |
|
|
|
outputString.AddShaderChunk("float2 offset = unity_voronoi_noise_randomVector(lattice + g);", false); |
|
|
|
outputString.AddShaderChunk("float2 offset = unity_voronoi_noise_randomVector(lattice + g, angleOffset);", false); |
|
|
|
outputString.AddShaderChunk("float d = distance(lattice + offset, f);", false); |
|
|
|
outputString.AddShaderChunk("if(d < res.x)", false); |
|
|
|
outputString.AddShaderChunk("{", false); |
|
|
|