Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEditor.ShaderGraph;
- using System.Reflection;
- [Title("Wunderwunsch", "HexNode")]
- public class HexNode : CodeFunctionNode
- {
- public HexNode()
- {
- name = "HexNode";
- }
- protected override MethodInfo GetFunctionToConvert()
- {
- return GetType().GetMethod("HexNodeFunction", BindingFlags.Static | BindingFlags.NonPublic);
- }
- static string HexNodeFunction
- (
- [Slot(0, Binding.None)] Vector3 WorldPosition,
- [Slot(1, Binding.None)] Vector2 gridSize,
- [Slot(2, Binding.None)] Vector1 borderWidth,
- [Slot(3, Binding.None)] out Vector1 value
- )
- {
- return @"
- {
- float2 g = gridSize;
- float2 p = abs(WorldPosition.xz);
- p = p * g;
- float2 q = float2( p.x*1.1547006, p.y + p.x*0.5773503 );
- float2 pi = floor(q);
- float2 pf = frac(q);
- float v = fmod(pi.x + pi.y, 3.0);
- float ca = step(1.0,v), cb = step(2.0,v);
- float2 ma = step(pf.xy,pf.yx);
- float e = dot( ma, 1.0-pf.yx + ca*(pf.x+pf.y-1.0) + cb*(pf.yx-2.0*pf.xy) );
- value = step(borderWidth,e);
- }
- ";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement