Last active
April 18, 2020 07:01
-
-
Save rkandas/d4bcb70612d602cdf068d54ed9657630 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 UnityEngine; | |
using UnityEditor.ShaderGraph; | |
[Title("Custom", "Mirror Texture Node")] | |
public class MirrorTextureNode : CodeFunctionNode | |
{ | |
public MirrorTextureNode() | |
{ | |
name = "Mirror Texture"; | |
} | |
protected override MethodInfo GetFunctionToConvert() | |
{ | |
return GetType().GetMethod("MirrorTextureFunction", | |
BindingFlags.Static | BindingFlags.NonPublic); | |
} | |
static string MirrorTextureFunction( | |
[Slot(0, Binding.None)] Boolean mirrorX, | |
[Slot(1, Binding.None)] Boolean mirrorY, | |
[Slot(2, Binding.MeshUV0)] Vector2 UV, | |
[Slot(3, Binding.None)] Texture2D Texture, | |
[Slot(4, Binding.None)] SamplerState SS, | |
[Slot(5, Binding.None)] out Vector4 RGBA | |
) | |
{ | |
RGBA = Vector4.zero; | |
return @" | |
{ | |
float2 mirroredUV = float2(lerp(UV.x, 1.0f - UV.x, mirrorX),lerp(UV.y, 1.0f - UV.y, mirrorY)); | |
RGBA = Texture.Sample(SS,mirroredUV); | |
} | |
"; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment