浏览代码

Adding Mandelbrot fractal node. Not perfect, but it's there

/main
Eduardo Chaves 8 年前
当前提交
56672837
共有 6 个文件被更改,包括 80 次插入1 次删除
  1. 2
      MaterialGraphProject/Assets/Eduardo/FunctionNAddNode.cs
  2. 1
      MaterialGraphProject/Assets/Eduardo/FunctionNInNOut.cs
  3. 1
      MaterialGraphProject/Assets/Eduardo/EduardoTestGraph.ShaderGraph
  4. 9
      MaterialGraphProject/Assets/Eduardo/EduardoTestGraph.ShaderGraph.meta
  5. 56
      MaterialGraphProject/Assets/Rinaldo/FractalNode.cs
  6. 12
      MaterialGraphProject/Assets/Rinaldo/FractalNode.cs.meta

2
MaterialGraphProject/Assets/Eduardo/FunctionNAddNode.cs


public void AddInputSlot()
{
string inputName = "Input" + GetInputSlots<ISlot>().Count().ToString();
string inputName = "Input" + GetInputSlots<MaterialSlot>().Count().ToString();
AddSlot(inputName, inputName, Graphing.SlotType.Input, SlotValueType.Dynamic);
}

1
MaterialGraphProject/Assets/Eduardo/FunctionNInNOut.cs


public FunctionNInNOut()
{
name = "FunctionNInNOut";
UpdateNodeAfterDeserialization();
}
public override void UpdateNodeAfterDeserialization()

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

9
MaterialGraphProject/Assets/Eduardo/EduardoTestGraph.ShaderGraph.meta


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

56
MaterialGraphProject/Assets/Rinaldo/FractalNode.cs


using UnityEngine.Graphing;
using System.Linq;
using System.Collections;
namespace UnityEngine.MaterialGraph
{
[Title("Procedural/Fractal")]
public class FractalNode : FunctionNInNOut, IGeneratesFunction
{
public FractalNode()
{
name = "Fractal";
AddSlot("UV", "texCoord", Graphing.SlotType.Input, SlotValueType.Vector2);
AddSlot("Pan", "Pan", Graphing.SlotType.Input, SlotValueType.Vector2);
AddSlot("Zoom", "Zoom", Graphing.SlotType.Input, SlotValueType.Vector1);
AddSlot("Aspect", "Aspect", Graphing.SlotType.Input, SlotValueType.Vector1);
AddSlot("FracResult", "fractalRes", Graphing.SlotType.Output, SlotValueType.Dynamic);
UpdateNodeAfterDeserialization();
}
protected override string GetFunctionName()
{
return "unity_Fractal";
}
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.AddShaderChunk("const int Iterations = 128;", false);
outputString.Indent();
outputString.AddShaderChunk("float2 c = (texCoord - 0.5) * Zoom * float2(1, Aspect) - Pan;", false);
outputString.AddShaderChunk("float2 v = 0;", false);
outputString.AddShaderChunk("for (int n = 0; n < Iterations && dot(v,v) < 4; n++)", false);
outputString.AddShaderChunk("{", false);
outputString.Indent();
outputString.AddShaderChunk("v = float2(v.x * v.x - v.y * v.y, v.x * v.y * 2) + c;", false);
outputString.Deindent();
outputString.AddShaderChunk("}", false);
outputString.Deindent();
outputString.AddShaderChunk("fractalRes = (dot(v, v) > 4) ? (float)n / (float)Iterations : 0;", false);
outputString.AddShaderChunk("}", false);
visitor.AddShaderChunk(outputString.GetShaderString(0), true);
}
}
}

12
MaterialGraphProject/Assets/Rinaldo/FractalNode.cs.meta


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