Calculating uv texture coordinates for a procedurally generated circular mesh

I am trying to calculate uv for a grid that I am generating in code. This is a very simple circle (2d)

enter image description here

and I want to texture it like this

enter image description here

and using this code for uvs

uvs[i] = new Vector2((verts[i].x+radius)/(radius), (verts[i].y+radius)/(2*radius));

      

and the center vertex is (0.5f, 0.5f)

but I am getting a distorted image. (EDIT PHOTO after answer from answer but still stretched out)

enter image description here

Can anyone help here? thanks in advance

+3


source to share


1 answer


How about this:

Suppose the coordinates of the center vertex (center X, center Y)



uvs[i] = new Vector2(0.5f +(verts[i].x-centerX)/(2*radius), 
                             0.5f + (verts[i].y-centerY)/(2*radius));

      

+3


source







All Articles