Shaders are not my strong point but I’ve usually managed to adapt existing examples to suit my needs, until now.
I found the following ‘UVRotation’ shader on this forum and it’s almost perfect for my needs apart from the lack of a colour picker which as yet, I’ve failed to address.
Could a shader guru could point me in the right direction ?
Shader "Custom/UVRotation"
{
Properties
{
_MainTex ("Texture", 2D) = "white" {}
_Angle ("Angle", Range(-5.0, 5.0)) = 0.0
}
SubShader
{
Tags { "RenderType"="Opaque" }
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
struct v2f {
float4 pos : SV_POSITION;
float2 uv : TEXCOORD0;
};
float _Angle;
v2f vert(appdata_base v)
{
v2f o;
o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
// Pivot
float2 pivot = float2(0.5, 0.5);
// Rotation Matrix
float cosAngle = cos(_Angle);
float sinAngle = sin(_Angle);
float2x2 rot = float2x2(cosAngle, -sinAngle, sinAngle, cosAngle);
// Rotation consedering pivot
float2 uv = v.texcoord.xy - pivot;
o.uv = mul(rot, uv);
o.uv += pivot;
return o;
}
sampler2D _MainTex;
fixed4 frag(v2f i) : SV_Target
{
// Texel sampling
return tex2D(_MainTex, i.uv);
}
ENDCG
}
}
}