浏览代码

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

/main
RinaldoTjan 8 年前
当前提交
180f53e2
共有 5 个文件被更改,包括 115 次插入1 次删除
  1. 7
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/NodePreviewPresenter.cs
  2. 2
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Interfaces/IMasterNode.cs
  3. 5
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/AbstractMasterNode.cs
  4. 90
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Procedural/VoronoiNoise.cs
  5. 12
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Procedural/VoronoiNoise.cs.meta

7
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/NodePreviewPresenter.cs


List<PropertyGenerator.TextureInfo> defaultTextures;
var resultShader = ((IMasterNode) m_Node).GetFullShader(GenerationMode.Preview, out defaultTextures);
m_GeneratedShaderMode = PreviewMode.Preview3D;
if (((IMasterNode)m_Node).has3DPreview())
{
m_GeneratedShaderMode = PreviewMode.Preview3D;
}
return resultShader;
}
return ShaderGenerator.GeneratePreviewShader(m_Node, out m_GeneratedShaderMode);

2
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Interfaces/IMasterNode.cs


string GetSubShader(GenerationMode mode, PropertyGenerator shaderPropertiesVisitor);
string GetVariableNameForNode();
bool has3DPreview();
}
}

5
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/AbstractMasterNode.cs


public abstract string GetFullShader(GenerationMode mode, out List<PropertyGenerator.TextureInfo> configuredTextures);
public abstract string GetSubShader(GenerationMode mode, PropertyGenerator shaderPropertiesVisitor);
public virtual bool has3DPreview()
{
return true;
}
}
}

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


namespace UnityEngine.MaterialGraph
{
[Title("Procedural/Voronoi Noise")]
public class VoronoiNoiseNode : Function1Input, IGeneratesFunction
{
public VoronoiNoiseNode()
{
name = "VoronoiNoise";
}
protected override string GetFunctionName()
{
return "unity_voronoinoise_" + 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_voronoi_noise_randomVector (float2 uv)", false);
outputString.AddShaderChunk("{", false);
outputString.Indent();
outputString.AddShaderChunk("float2x2 m = float2x2(15.27, 47.63, 99.41, 89.98);", false);
outputString.AddShaderChunk("return frac(sin(mul(uv, m)) * 46839.32);", false);
outputString.Deindent();
outputString.AddShaderChunk("}", false);
outputString.AddShaderChunk(GetFunctionPrototype("uv"), false);
outputString.AddShaderChunk("{", false);
outputString.Indent();
outputString.AddShaderChunk("float2 g = floor(uv);", false);
outputString.AddShaderChunk("float2 f = frac(uv);", false);
outputString.AddShaderChunk("float t = 8.0;", false);
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("for(int x=-1; x<=1; x++)", false);
outputString.AddShaderChunk("{", false);
outputString.Indent();
outputString.AddShaderChunk("float2 lattice = float2(x,y);", false);
outputString.AddShaderChunk("float2 offset = unity_voronoi_noise_randomVector(lattice + g);", false);
outputString.AddShaderChunk("float d = distance(lattice + offset, f);", false);
outputString.AddShaderChunk("if(d < res.x)", false);
outputString.AddShaderChunk("{", false);
outputString.Indent();
outputString.AddShaderChunk("res = float3(d, offset.x, offset.y);", false);
outputString.Deindent();
outputString.AddShaderChunk("}", false);
outputString.Deindent();
outputString.AddShaderChunk("}", false);
outputString.Deindent();
outputString.AddShaderChunk("}", false);
outputString.AddShaderChunk("return res.x;", false);
outputString.Deindent();
outputString.AddShaderChunk("}", false);
visitor.AddShaderChunk(outputString.GetShaderString(0), true);
}
}
}

12
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Procedural/VoronoiNoise.cs.meta


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