Skip to content

Instantly share code, notes, and snippets.

@rngtm
Created October 22, 2018 11:48
Show Gist options
  • Save rngtm/77fb9334ed1f176217a4d16e45b7e78d to your computer and use it in GitHub Desktop.
Save rngtm/77fb9334ed1f176217a4d16e45b7e78d to your computer and use it in GitHub Desktop.
ShaderGraph - GraphPreviewNode
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;
}";
}
}
@rngtm
Copy link
Author

rngtm commented Oct 22, 2018

シェーダーグラフのVector1をグラフで表示できるカスタムノード
graph_preview_node

@rngtm
Copy link
Author

rngtm commented Oct 22, 2018

使い方

Utility/Graph Previewを選ぶと使えます.

image

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment