1
\$\begingroup\$

Assume I have a model and I don't map the UV for this model and I just apply a texture for the model. I see that Unity will apply a single color to the model, something like this (I took the img from this topic): model without uv

I guess the default pixel color it uses maybe at UV (0, 0) or UV (1, 1), but after I test it, I see that my guess is wrong, the colors doesn't match.

color uv

color 1: the color of the model when I apply the texture to a non-UV model

color 2: the color of pixel at UV (0, 0) of the texture (color = myTexture2D.GetPixelBilinear(0.0f, 0.0f);)

I see color 1 is lighter than color 2.

So how get get the color from the texture that matches color 1?

Edit I have tried another test:

Here is the texture (4 pixels with 4 different colors):

UV Test

And I got this color when I apply this texture to a non-UV mapping model:

non-UV mapping

It seems like they use an algorithm to make the non-UV color (like blend some colors of the texture together)

\$\endgroup\$
0
\$\begingroup\$

I figure it out, they blend 4 corner pixel of the texture to make the non-UV color.

I have a 16x16 texture (4 corners is: red, green, blue & black, the rest are yellow)

16x16 Texture

And when I apply the texture on a non-UV model, I get this color:

Non-UV color

But notice that the non-UV color is lighter than the blend color of 4 corners, so here I propose this code to make the non-UV color, it's not perfect but good enough for me:

color = (myTexture2D.GetPixelBilinear(0.0f, 0.0f) +
                myTexture2D.GetPixelBilinear(1.0f, 0.0f) +
                myTexture2D.GetPixelBilinear(1.0f, 1.0f) +
                myTexture2D.GetPixelBilinear(0.0f, 1.0f) + 
                Color.white) / 5.0f;
\$\endgroup\$
  • 1
    \$\begingroup\$ Just ot curiousity, why are you doing this? are you trying to emulate what Unity is doing in an home-brew game engine? \$\endgroup\$ – Gabriele Vierti Feb 12 at 8:33
  • \$\begingroup\$ @GabrieleVierti - No, I just need to get this color for a specific feature of my game. \$\endgroup\$ – 123iamking Feb 13 at 3:15

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.