1

As seen from the figure, assuming a model has two UV unfolding ways, i.e., UV-1 and UV-1. Then I ask an artist to paint the model based on UV-1 and get the texture map 1. How can I transfer colors from UV-1 to UV-2 programmatically (e.g., python)? One method I know is mapping the texture map 1 into vertex colors and then rendering the vertex colors to UV-2. But this method would lose some color details. So how can I do it?

enter image description here

XiaoJin
  • 67
  • 1
  • 6
  • Programmatically? I suppose you could loop through all the pixels in Texture Map 2, find which part of the model they map to, then look up the same part of the model in UV-1, then get the corresponding pixel in Texture Map 1. There might be a more efficient way to do it such as iterating over all the triangles instead. – user253751 Sep 27 '22 at 15:32
  • In this way, I can find the triangle's vertices mapping between UV-1 and UV-2. But what about those pixels inside triangles? – XiaoJin Sep 28 '22 at 04:20

1 Answers1

0

Render your model on Texture Map 2 using UV-2 coordinates for vertex positions and UV-1 coordinates interpolated across the triangles. In the fragment shader use the interpolated UV-1 coordinates to sample Texture Map 1. This way you're limited only by the resolution of the texture maps, not by the resolution of the model.

EDIT: Vertex shader:

in vec2 UV1;
in vec2 UV2;
out vec2 fUV1;
void main() {
    gl_Position = vec4(UV2, 0, 1);
    fUV1 = UV1;
}

Fragment shader:

in vec2 fUV1;
uniform sampler2D TEX1;
out vec4 OUT;
void main() {
    OUT = texture(TEX1, fUV1);
}
Yakov Galka
  • 70,775
  • 16
  • 139
  • 220
  • I understand it should establish the face-to-face mapping between UV-1 and UV-2. But how to do the interpolation across the UV-1's triangles and map to UV-2's triangles? I know how to establish the vertex mapping between UV-1 and UV-2. I am confusing how to establish the mapping inside triangles between UV-1 and UV-2. – XiaoJin Sep 28 '22 at 04:23
  • @XiaoJin i don't understand what isn't clear; you already have UV-1 values at the vertices. You pass that as a vertex attribute. The GPU interpolates it across the triangle. You use the interpolated UV-1 value directly as the coordinate in the `texture(...)` call. – Yakov Galka Sep 28 '22 at 04:55
  • So you mean I can use OpenGL/GPU's rendering pipeline to do the interpolation, instead of interpolating by myself? – XiaoJin Sep 28 '22 at 06:19
  • @XiaoJin that is what I said, yes; of course you can do the same calculations manually without OpenGL, but that's a PITA for no good reason. – Yakov Galka Sep 28 '22 at 13:02
  • @XiaoJin when you draw the model onto the screen how do you establish the mapping inside triangles onto the screen? you don't - it interpolates automatically – user253751 Jan 17 '23 at 18:14