- Home /
UV mapping tiles on mesh bleeds texture when camera is at certain angle
Hi there!
So I generate meshes with tiles on them and I want to make each tile have a texture. Each tile has 4 unique verticies and each mesh / chunk is 100x100 tiles. I read that it is best to use UV mapping with a texture atlas when using tiles like this, rather than using SetPixels() to create a unique texture for every mesh. So in the images below I set the UV mapping for each tile to the grass part of the texture shown in the first image. (0.4, 0.4) (0.6, 0.4) (0.4, 0.6) (0.6, 0.6). So I was just wondering why the entire texture shows when I tilt the camera in the distance? It starts at a certain distance from camera and has a half-circle shape. It would work fine if it was a 2D game, but it is a top down 3D. The only "solution" I found is to set the padding to 3x the tile width, so if the tile takes a 32x32 texture, then I need 96px of padding around it in each direction with a similar color to make it not look ugly. Also this limits the amount of texture tiles I can use.
Tilted camera view:
Tilted camera view with "generate mip maps" set on":
Top down view:
Answer by EvanTune · Aug 17, 2018 at 10:45 AM
So I turned off anti aliasing in quality settings and this fixed the issue with the magenta color showing up in the distance as shown in the first image. I am now using the free Post Processing Stack asset to add it back to the camera and it doesn't have the weird effects as before.
Answer by Bunny83 · Aug 15, 2018 at 11:34 AM
Because you use mipmaps. Mipmaps are down sampled versions of the same texture which are used when the sampled area on the screen is very small.
Your options are
Either disable mipmapping or if you really need mipmapping you might need to generate the mipmap levels manually and make sure the tiles are aligned to power-of-two position and scale.
When you generate mipmaps your self it wouldn't make any sense to go further down when you reach the tile size. So one tile is one pixel in the highest mipmap level. Apart from that to avoid bleeding each tile should have a one pixel border if possible. That means you would shift your UV coordinates inwards by one pixel. Though this depends on your texture filtering method
Thanks for the reply! So when I disable "generate mip maps" in the texture, the pink part of the texture still shows as in the first image in my post far in the distance. So turning it off still gives me trouble.
This is with mip maps off
For your second option, do you know how to apply them to a texture? If I have a 1024x1024 px texture atlas with 32x32 px tiles, then I assume I would need 512x 256x 128x 64x and 32x mip map textures. So I would then need to apply 5 mip map textures to the texture atlas? I also noticed that the bigger I make the texture atlas the more mip map "levels" unity generates for it.
Hmm, that really looks strange. Usually when you turn off mipmaps this shouldn't happen. $$anonymous$$eep in $$anonymous$$d that if coordinates are normalized coordinates. However the actual pixels used depends on the filtering mode. You should generally avoid sampling positions between two pixels(texels). You image is a non power-of-two image so it is stretched to the nearest power-of-two size.
To create the mipmaps levels manually you would just use the SetPixels overload that takes the mipmap index as additional parameter. Level0 is the whole image. Though if disabling doesn't work, setting the mipmaps manually will not help either. Also this will only make sense if the tiles are properly aligned inside the image.
Are you sure your UVs are correct? Without mipmapping you may see some bleeding of the cyan area but the magenta region shouldn't be visible at all
Your answer
Follow this Question
Related Questions
More materials smaller texture size vs less materials bigger texture size 0 Answers
Why would my texture split across the triangle at runtime? 0 Answers
Texture grid displayed oddly when width =/= height 1 Answer
Texture Atlas for sprites/particles: Wasting Texture Memory? 1 Answer
good program for uv texturing 2 Answers