I wanted to create a shader without texture tiling. And i created a simple shader which contains dividing the UV into blocks and rotating them. But i cannot figure out how to create a blend between the edges of the UV blocks...
Here is my code:
Shader "Custom/Blend_4_test"
{
Properties
{
_MainTex ("Texture", 2D) = "white" {}
_TileCount("Tile Count", Range(2.0, 100.0)) = 4
_TileCountInside("Tile Count Inside", Range(1.0, 10.0)) = 1
_RotateAngle("Rotate Angle", Float) = 45.0
_RotateNoise("Rotate Noise", Float) = 20.0
[Enum(Texture,0,Checker,1)] _ViewMode("View Mode", Int) = 1
}
SubShader {
Pass {
CGPROGRAM
#pragma vertex vert_img
#pragma fragment frag
#include "UnityCG.cginc"
#include "../Libraries/Helper.cginc"
sampler2D _MainTex;
half _TileCount;
half _TileCountInside;
half _RotateAngle;
half _RotateNoise;
half _Mitigation;
int _ViewMode;
half Hash21(half2 p) {
p = frac(p*half2(123.34, 456.21));
p += dot(p, p+45.32);
return frac(p.x*p.y);
}
half2 getNoise(half2 uv) {
half2 st = uv * max(_TileCount, 1);
half2 ipos = floor(st);
return rand2(ipos, _RotateNoise);
}
int getChecker(half2 uv) {
half2 ipos = sin(uv * _TileCountInside * 6.2831);
return ipos.x * ipos.y > 0.;
}
half4 frag(v2f_img i) : SV_Target
{
half2 noise = getNoise(i.uv);
i.uv *= _TileCount;
half2 uvRotationPivot = (half2)0.5;
i.uv -= floor(i.uv);
i.uv -= uvRotationPivot;
i.uv = mul(rot(radians(_RotateAngle * Hash21(noise))), i.uv);
i.uv += uvRotationPivot;
return _ViewMode ? getChecker(i.uv) : tex2D( _MainTex, i.uv * _TileCountInside );
}
ENDCG
}
}
}
Here is an example output: https://i.stack.imgur.com/J8ruT.png