Created
October 22, 2018 11:48
-
-
Save rngtm/77fb9334ed1f176217a4d16e45b7e78d to your computer and use it in GitHub Desktop.
ShaderGraph - GraphPreviewNode
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using UnityEditor.ShaderGraph; | |
using System.Reflection; | |
[Title("Utility", "Graph Preview")] | |
public class GraphPreviewNode : CodeFunctionNode | |
{ | |
protected override MethodInfo GetFunctionToConvert() | |
{ | |
return GetType().GetMethod("MyCustomFunction", | |
BindingFlags.Static | BindingFlags.NonPublic); | |
} | |
static string MyCustomFunction( | |
[Slot(0, Binding.MeshUV0)] Vector2 UV, | |
[Slot(1, Binding.None)] Vector1 Input, | |
[Slot(2, Binding.None, 0.018f, 0f, 0f, 0f)] Vector1 LineWidth, | |
[Slot(3, Binding.None, true)] out ColorRGB OutColor, | |
[Slot(4, Binding.None)] out Vector1 OutFloat | |
) | |
{ | |
return @"{ | |
#define LINE_SIZE LineWidth | |
#define LINE_COLOR float4(1,1,1,1) | |
#define BRIGHTNESS 5.0 | |
#define X (Input) | |
#define Y (UV.y) | |
#define InvX (1.0 - X) | |
#define InvY (1.0 - Y) | |
OutColor = BRIGHTNESS * LINE_COLOR * ( | |
smoothstep(Y - LINE_SIZE, Y + LINE_SIZE, X) | |
* smoothstep(InvY - LINE_SIZE, InvY + LINE_SIZE, InvX) | |
); | |
OutFloat = Input; | |
}"; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
シェーダーグラフのVector1をグラフで表示できるカスタムノード