Search code examples
c#meshtexture-mappingprocedural-generation

Calculating uv texture coords for a procedurally generated circle mesh


I am trying to calculate the uv's for a mesh I generate in code. It's a very simple circle (2d)

enter image description here

and I want to texture it like follows

enter image description here

and using this code for the 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 help from answer but still stretched)

enter image description here

could anyone help here? Thanks in advance


Solution

  • How about this:

    Lets assume that the coordinates of the center vertex are (centerX, centerY)

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