Created
April 18, 2020 13:24
-
-
Save rkandas/e7057eae3888c4c8cc8ad9011713736a to your computer and use it in GitHub Desktop.
This file contains hidden or 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 System.Reflection; | |
using UnityEditor.ShaderGraph; | |
using UnityEngine; | |
[Title("Custom", "Gray Scale Node")] | |
public class GrayScaleNode : CodeFunctionNode | |
{ | |
public GrayScaleNode() | |
{ | |
name = "Gray Scale"; | |
} | |
protected override MethodInfo GetFunctionToConvert() | |
{ | |
return GetType().GetMethod("GrayScaleFunction", | |
BindingFlags.Static | BindingFlags.NonPublic); | |
} | |
static string GrayScaleFunction( | |
[Slot(2, Binding.MeshUV0)] Vector2 UV, | |
[Slot(3, Binding.None)] SamplerState SS, | |
[Slot(4, Binding.None)] out Vector4 RGBA | |
) | |
{ | |
RGBA = Vector4.zero; | |
return @" | |
{ | |
const float3 W = float3( 0.2125, 0.7154, 0.0721 ); | |
float3 irgb = _MainTex.Sample( SS, UV ).rgb; | |
float luminance = dot( irgb, W ); | |
RGBA = float4(luminance,luminance,luminance,1.0); | |
} | |
"; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment