Search Unity

How can I manipulate only one group of vertexes in my model?

Discussion in 'General Graphics' started by Reverend-Speed, Oct 17, 2019.

  1. Reverend-Speed

    Reverend-Speed

    Joined:
    Mar 28, 2011
    Posts:
    284
    Hey folks. I'm currently looking into doing some eyes similar to that found in Twilight Princess. However, I was wondering if it would be possible to just isolate and change the UVs of one specific island on my texture - allowing the pupil to move around independantly of the rest of the face.

    In the link above, they're using a separate layer of geometry, and I also know I could do this with multiple materials... but it would actually be really handy for me to just grab the island that I need and scroll that around independently of the model.

    An example of the texture I'm looking at follows - note how clean the eye area is, how easily it would be to turn this into a separate island.
    LeonGreyscale01003RS.png
    Lemme know if you've any ideas on this - or if you can explain why I can't (or shouldn't!) do this! (Or if I should have put this thread into 'shaders'!)

    Many thanks in advance,

    --Rev
     
  2. neoshaman

    neoshaman

    Joined:
    Feb 11, 2011
    Posts:
    6,493
    v.uv = v.uv + offset.xy in vertex (pseudo code)
     
  3. Reverend-Speed

    Reverend-Speed

    Joined:
    Mar 28, 2011
    Posts:
    284
    Ah, sorry @neoshaman , I'm not sure if I was being sufficiently clear there. I know how to offset UVs in both C# and shader, I'm just trying to isolate one particular island of UVs to apply that offset to.
    upload_2019-10-17_23-25-49.png
    Basically, imagine if I just wanted to translate the one highlighted island / face over the character's eye in the image above. How could I identify that particular face for translation?

    Again, thank you for any help!
     
  4. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,352
    1. Split the model so those triangles are a separate mesh.
    2. Set a vertex color on that triangle in an external application. Check for that color in the vertex shader.
    3. Move the UVs to outside of the usual 0.0 to 1.0 range (ie: if the UV is at (0.2, 0.5), set it to (-0.8, -0.5) by subtracting 1 from both.
    4. Find the triangle indices for those triangles and test them against the SV_PrimitiveID in the fragment shader.

    Lots of ways. Most of those make it easy to find in C# too, though the 4th method alone won't work well there as unlike the first 3 methods it won't ensure the wanted triangles have unique vertices meaning any manipulation will also cause the rest of the face around it to move too.
     
    Reverend-Speed likes this.
  5. Reverend-Speed

    Reverend-Speed

    Joined:
    Mar 28, 2011
    Posts:
    284
    That's a fantastic answer, @bgolus ...! Hmm.

    1) Trying not to split the model if I can - it'd be nice to do most of my work within a single material on a skinned renderer.
    2) Hm. I have a feeling that might be the easiest, but I'd worry about that colour bleeding onto nearby vertexes. Of course, I should just detach those vertexes... which is probably your intention. Gotcha.
    3) Ha, excellent idea! Unsure of how I'd talk directly to those vertexes in the shader, but you've set me on a useful path there.
    4) I understand - as you point out, that'll affect neighbouring triangles, which is not the intended outcome.

    Righto. I'll take a look into #3. Thank you muchly, bGolus!
     
  6. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,352
    re #3
    Code (csharp):
    1. if (i.uv.x < 0.0 && i.uv.y < 0.0) {
    2.     i.uv += _EyeUVOffset;
    3. }
    It also automatically detaches those vertices when you import a mesh with disconnected UVs.
     
    Reverend-Speed likes this.
  7. Reverend-Speed

    Reverend-Speed

    Joined:
    Mar 28, 2011
    Posts:
    284
    Goddamnit, yes, perfect. I should have thought of that...

    Interesting to hear about the detached verts on disconnected UVs. That's convenient...!

    Thanks again, bgolus!
     
    neoshaman likes this.