Hi Uniteers, I am struggling with the current.
I wish to add a glow to my sprite using the UV coordinates, but problem is, if the sprite originates from an atlas created by Unity’s sprite packer, then the UV aren’t normalized from 0 to 1, but from and to two arbitrary values. How do I normalize UV data for a single sprite that resides in an atlas?
float4 uvs = ExtractUVs(IN.texcoord); // Extract both UV and normalised UV from a single float2
OUT.texcoord = uvs.xy; // pass on the atlased UV to the pixel shader
OUT.normalisedtexcoord = uvs.zw; // pass on the normalised UV to the pixel shader
OUT.color = IN.color * _Color;
return OUT;
}
// Extract UV and Normalised UVs into a float4…
float4 ExtractUVs(float2 uv0)
{
uv0 -= float2(1.0,1.0);
float4 uv1 = uv0.xyxy;
if (uv1.x > 1.0)
uv1.x -= 1.0;
if (uv1.y > 1.0)
uv1.y -= 1.0;
uv1.zw -= uv1.xy;
return uv1; // uv1.xy = UV and uv1.zw = NormalisedUVs
}