Skip to content

Instantly share code, notes, and snippets.

@rkandas
Last active April 18, 2020 07:01
Show Gist options
  • Save rkandas/d4bcb70612d602cdf068d54ed9657630 to your computer and use it in GitHub Desktop.
Save rkandas/d4bcb70612d602cdf068d54ed9657630 to your computer and use it in GitHub Desktop.
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