3
\$\begingroup\$

I am using Unity3d (free) to make a game with user-defined content (i.e., load in a map, it'll build the level for you).

Everything is working as expected, except for the rendering.

enter image description here

Note the artifact / seam along the edge of the two cubes.

I am not entirely sure what is causing this, other than, perhaps a rounding error?

At any rate, every mesh in my scene shares the same texture, with specific UV offsets generated at 1/8 intervals for each corresponding texture:

enter image description here

Playing around with the assigned UVs moves the artifacts around. For instance, the red brick texture has the issue between the top faces:

enter image description here

So clearly, I'm doing this in a suboptimal way. Is there something specific I'm doing wrong? Or is there a better way to build meshes with texture atlases?

\$\endgroup\$
8
  • \$\begingroup\$ Doesn't look like z-fighting (which you shouldn't get with shared vertices anyway, since there's no overlapping geometry), it looks more like the texture coordinates are off. \$\endgroup\$ – MichaelHouse Sep 20 '13 at 17:30
  • \$\begingroup\$ @Byte56 You were correct. I changed the texture to something else and the problem vanished (which doesn't solve the problem, because I'm using the texture as a sprite sheet). \$\endgroup\$ – Raven Dreamer Sep 22 '13 at 4:09
  • \$\begingroup\$ Neat. Sounds like it's a new problem now, but at least it's clear(er) what's happening. \$\endgroup\$ – MichaelHouse Sep 22 '13 at 4:31
  • \$\begingroup\$ @Byte56 Yeah, I played around with it, and it proved as infuriating as ever. Question vastly updated to account for newly understood problem. \$\endgroup\$ – Raven Dreamer Sep 22 '13 at 14:55
  • \$\begingroup\$ Just as an experiment, you might want to convert your texture to a .tiff or .jpg, just to see what happens. Unity interpolates the colors differently for each. \$\endgroup\$ – Kirbinator Sep 23 '13 at 1:55
2
\$\begingroup\$

I would recommend using Sprite Textures.

You will need to do the following:

  1. Set your texture type to Sprite (2D and UI).
  2. Set Sprite mode to Multiple.
  3. Access the Sprite editor and use the Slice tool (sneakily hidden in the upper left corner)

Sprite editor

From here, slice up the single image and get multiple sprites to your heart's content. Then you can use these sprites in your gameobject (might need some custom shaders).

If you want to avoid using sprites, I believe you can access this feature by selecting Advanced import setting.

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

Here's how I wound up doing it. (This is probably sub-optimal)

The problem originally arose due to a combination of a shared texture and UVs being specified as a float from 0 to 1. That's a recipe for niggling rounding issues.

On the other hand, there is a way to make each texture have the "regular" UVs -- submeshes! I discovered that the "SetTriangles" method already has a "Submesh" parameter, so I split my single texture into individual "blocks", and am able to generate artifact-free objects with each submesh using the full range of UVs.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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