浏览代码

Added a spherize node and fixed a bug in the checkerboatd node.

/main
bfogerty 8 年前
当前提交
ee8f0ea6
共有 3 个文件被更改,包括 90 次插入1 次删除
  1. 2
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Procedural/CheckerboardNode.cs
  2. 77
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/UV/SpherizeNode.cs
  3. 12
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/UV/SpherizeNode.cs.meta

2
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Procedural/CheckerboardNode.cs


outputString.AddShaderChunk(GetFunctionPrototype("uv", "horizontalTileScale", "verticalTileScale"), false);
outputString.AddShaderChunk("{", false);
outputString.Indent();
outputString.AddShaderChunk("return floor(fmod(floor(uv.x * horizontalTileScale) + floor(uv.y * verticalTileScale), 2.0)) * float4(1.0, 1.0, 1.0, 1.0);", false);
outputString.AddShaderChunk("return abs(floor(fmod(floor(uv.x * horizontalTileScale) + floor(uv.y * verticalTileScale), 2.0)));", false);
outputString.Deindent();
outputString.AddShaderChunk("}", false);

77
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/UV/SpherizeNode.cs


namespace UnityEngine.MaterialGraph
{
[Title("UV/Spherize")]
public class SpherizeNode : Function3Input, IGeneratesFunction
{
public SpherizeNode()
{
name = "Spherize";
}
protected override string GetFunctionName()
{
return "unity_spherize_" + precision;
}
protected override string GetInputSlot1Name()
{
return "UV";
}
protected override MaterialSlot GetInputSlot1()
{
return new MaterialSlot(InputSlot1Id, GetInputSlot1Name(), kInputSlot1ShaderName, UnityEngine.Graphing.SlotType.Input, SlotValueType.Vector2, Vector2.zero);
}
protected override string GetInputSlot2Name()
{
return "Position";
}
protected override MaterialSlot GetInputSlot2()
{
return new MaterialSlot(InputSlot2Id, GetInputSlot2Name(), kInputSlot2ShaderName, UnityEngine.Graphing.SlotType.Input, SlotValueType.Vector2, Vector2.zero);
}
protected override string GetInputSlot3Name()
{
return "RadiusAndStrength";
}
protected override MaterialSlot GetInputSlot3()
{
return new MaterialSlot(InputSlot3Id, GetInputSlot3Name(), kInputSlot3ShaderName, UnityEngine.Graphing.SlotType.Input, SlotValueType.Vector2, Vector3.zero);
}
protected override MaterialSlot GetOutputSlot()
{
return new MaterialSlot(OutputSlotId, GetOutputSlotName(), kOutputSlotShaderName, UnityEngine.Graphing.SlotType.Output, SlotValueType.Vector2, Vector2.zero);
}
public void GenerateNodeFunction(ShaderGenerator visitor, GenerationMode generationMode)
{
var outputString = new ShaderGenerator();
outputString.AddShaderChunk(GetFunctionPrototype("uv", "position", "radiusAndStrength"), false);
outputString.AddShaderChunk("{", false);
outputString.Indent();
//vec2 fromUVToPoint = pos - uv;
//dist = length(fromUVToPoint);
//float mag = (1.0 - (dist / radius)) * strength;
//mag *= step(dist, radius);
//return uv + (mag * fromUVToPoint);
outputString.AddShaderChunk("float2 fromUVToPoint = position - uv;", false);
outputString.AddShaderChunk("float dist = length(fromUVToPoint);", false);
outputString.AddShaderChunk("float mag = (1.0 - (dist / radiusAndStrength.x)) * radiusAndStrength.y * step(dist, radiusAndStrength.x);", false);
outputString.AddShaderChunk("return uv + (mag * fromUVToPoint);", false);
outputString.Deindent();
outputString.AddShaderChunk("}", false);
visitor.AddShaderChunk(outputString.GetShaderString(0), true);
}
}
}

12
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/UV/SpherizeNode.cs.meta


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