So close… I’ve been trying to steve jobs my rectangle instances so they can have perfect rounded corners (non stretched)

Finally got it working but still getting artifacts at certain scales. I’m guessing it has to do with the texture coordinate falling between pixels or something. Hoping somebody might know.

glsl_rounded_corners.tox (1.7 KB)

**vertex**

```
out vec2 texCoord;
out vec2 dimensions;
void main()
{
dimensions.x = TDInstanceMat3()[0].x;
dimensions.y = TDInstanceMat3()[1].y;
texCoord = uv[0].st;
vec4 worldSpacePos = TDDeform(P);
gl_Position = TDWorldToProj(worldSpacePos);
}
```

**pixel**

```
in vec2 texCoord;
in vec2 dimensions;
uniform sampler2D sColorMap;
out vec4 fragColor;
void main()
{
// scale texture coordinates by instance scale
vec2 scaleCoord = texCoord * dimensions;
// define boarder width that will not be stretched
float edge = 0.25;
// initialize default coordinate to grab from texture
vec2 remap = vec2(edge);
if (scaleCoord.x < edge)
{remap.x = scaleCoord.x;}
if (scaleCoord.x > dimensions.x - edge)
{remap.x = scaleCoord.x - (dimensions.x-1.0);}
if (scaleCoord.y < edge)
{remap.y = scaleCoord.y;}
if (scaleCoord.y > dimensions.y - edge)
{remap.y = scaleCoord.y - (dimensions.y-1.0);}
vec4 color = texture(sColorMap, remap.st);
TDCheckDiscard();
TDAlphaTest(color.a);
fragColor = TDOutputSwizzle(color);
}
```