I tried to make border using rectangular sdf but with different scale it gets distorted.
I was thinking about object scale but can't figure how to do this myself
Object scales: (1, 1), (1, 0.125)
Desired result (Made in photoshop, slightly out of proportion)
There is vertex, fragment shader and rectangle function
float rectangle(float2 position, float2 size){
float2 component_wise_edge_distance = abs(position) - size;
float outside_distance = length(max(component_wise_edge_distance, 0));
float inside_distance = min(max(component_wise_edge_distance.x, component_wise_edge_distance.y), 0);
return outside_distance + inside_distance;
}
v2f vert(appdata v){
v2f o;
o.position = UnityObjectToClipPos(v.vertex);
o.uv = v.uv;
return o;
}
float4 frag(v2f i) : SV_TARGET
{
half3x3 m = UNITY_MATRIX_M;
half3 objectScale = half3(
length( half3( m[0][0], m[1][0], m[2][0] ) ),
length( half3( m[0][1], m[1][1], m[2][1] ) ),
length( half3( m[0][2], m[1][2], m[2][2] ) )
);
float4 coords = i.uv;
coords *= 8;
float2 position = float2(coords.x - 4, coords.y - 4);
float sdf = step(0, rectangle(position, float2(3, 3)));
float4 col = float4(sdf.xxx, 1);
return col;
}