Advertisement
Guest User

Untitled

a guest
Apr 26th, 2019
228
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.30 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEditor.ShaderGraph;
  5. using System.Reflection;
  6.  
  7. [Title("Wunderwunsch", "HexNode")]
  8. public class HexNode : CodeFunctionNode
  9. {
  10.     public HexNode()
  11.     {
  12.         name = "HexNode";
  13.     }
  14.  
  15.     protected override MethodInfo GetFunctionToConvert()
  16.     {
  17.         return GetType().GetMethod("HexNodeFunction", BindingFlags.Static | BindingFlags.NonPublic);
  18.  
  19.     }
  20.  
  21.     static string HexNodeFunction
  22.         (
  23.         [Slot(0, Binding.None)] Vector3 WorldPosition,
  24.         [Slot(1, Binding.None)] Vector2 gridSize,
  25.         [Slot(2, Binding.None)] Vector1 borderWidth,
  26.         [Slot(3, Binding.None)] out Vector1 value
  27.         )
  28.     {
  29.         return @"
  30.        {
  31.            float2 g = gridSize;
  32.            float2 p = abs(WorldPosition.xz);
  33.            p = p * g;
  34.            float2 q = float2( p.x*1.1547006, p.y + p.x*0.5773503 );
  35.            float2 pi = floor(q);
  36.            float2 pf = frac(q);
  37.            float v = fmod(pi.x + pi.y, 3.0);
  38.            float ca = step(1.0,v), cb = step(2.0,v);
  39.            float2 ma = step(pf.xy,pf.yx);
  40.            float e = dot( ma, 1.0-pf.yx + ca*(pf.x+pf.y-1.0) + cb*(pf.yx-2.0*pf.xy) );
  41.            value = step(borderWidth,e);            
  42.        }
  43.        ";
  44.     }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement