- Home /
A Shader to Duplicate and Flip a texture
I have a half of a symmetrical texture like this here:
I intend to use shader to duplicate and flip it horizontally with the end result like so:
I have written a shader that accomplishes the flipping part. But I'm not sure how to duplicate the effect before flipping.
Shader "Custom/CustomShader"
{
Properties
{
_Color ("Color", Color) = (1,1,1,1)
_MainTex ("Albedo (RGB)", 2D) = "white" {}
_Glossiness ("Smoothness", Range(0,1)) = 0.5
_Metallic ("Metallic", Range(0,1)) = 0.0
}
SubShader
{
Tags { "RenderType"="Opaque" }
LOD 200
CGPROGRAM
#pragma surface surf Standard fullforwardshadows
#pragma target 3.0
sampler2D _MainTex;
struct Input
{
float2 uv_MainTex;
};
half _Glossiness;
half _Metallic;
fixed4 _Color;
void surf (Input IN, inout SurfaceOutputStandard o)
{
float2 flippedUVs = IN.uv_MainTex;
flippedUVs.x = flippedUVs.x;
flippedUVs.y = 1.0 - flippedUVs.y;
fixed4 c = tex2D (_MainTex, flippedUVs) * _Color;
o.Albedo = c.rgb;
o.Metallic = _Metallic;
o.Smoothness = _Glossiness;
o.Alpha = c.a;
}
ENDCG
}
FallBack "Diffuse"
}
I'm sorry, I don't have much to add. I'd say if you are dealing with pngs then just use a photo editor (i.e. Photoshop) to flip one and paste them together beforehand. I was searching for a way to mirror a RenderTexture and your code helped me a lot, so thank you.
Also, the closest thing I could find to achieve what you want would be to just use the standard shader. Set your Base (RGB) tiling to something like 1 & -1. Then the offset to 0.5 & 1. You may have to mess with those values to get what you are looking for. This may also only repeat the image and now no mirroring.