Fix mipmap artifacts for an image with widely-varying color?

Here’s a UV-mapped model, and its texture. Mipmap artifacts from the white portion are showing up at grazing angles, as shown below. Now, in the final version of the texture, the eyeball isn’t going to be quite as stark white and uniform, but I’m sure it will still be quite different than the eyestalk color.

How would you solve this problem?

My best idea so far is to use two UV maps and two textures. I’d prefer a solution that didn’t require those additional resources, though.

230216--8262--$eyeball_170.jpg
230216--8263--$screen_shot_2009_11_25_at_41847_pm_108.png

This looks surprisingly close to the issue detailed in this thread: http://forum.unity3d.com/viewtopic.php?t=37562 .

Are you just guessing that its a mipmap artifact or are you talking from experience/knowledge? Can you offer some insight?

To be honest ive never seen anything like it outside of Unity, so i was assuming its a glitch in the rendering pipeline.

Well, turning mipmaps off solves the problem, so I don’t think I’m guessing. :wink: But I suppose it’s possible that it might be a coincidence.

I also don’t think it has anything to do with antialiasing, considering I’m using Unity iPhone with graphics emulation on.

You should give that a shot for your own model and then post your results.

I would, but its not my model :slight_smile:

Hah! Completely missed the fact that it wasn’t your thread!

:x

I don’t know if this would help the other person out, but what I’ve ended up doing only requires one UV map. I still need to use two textures, but I can switch them on and off with pure white or black vertex colors. It’s kind of like having two models, only at least a little better for performance, I imagine. It’s a good solution for this case, anyway.

Shader "Separated by Vertex Alpha" {

Properties {
	_MainTex ("Texture 1  (white vertex A)", 2D) = ""
	_Texture2 ("Texture 2  (black vertex A)", 2D) = ""
}

SubShader {
	BindChannels {
		Bind "vertex", vertex
		Bind "color", color
		Bind "texcoord", texcoord
	}
	
	Pass {
		SetTexture [_MainTex]		
		SetTexture [_Texture2] {Combine previous Lerp(primary) texture}
	}
}

}

In relation to your problem above, you might be better off separating the two parts into individual images anyway, the reasoning behind doing that would be so you could use several different eyeballs for varity without the expense of using a repeating texture asset.

Thanks for the reply on my issue, will take a look at your shader in relation to that blending problem ;o)

No, that wouldn’t be helpful to me, because I only use Unity iPhone, and everything I do is built around dynamic batching. Every new material is a new draw call.

Typically, people resolve this situation by leaving a 2 (or so) pixel border around any areas where this sort of color bleeding might happen. There’s not much avoiding color bleeding inside a texture. You can clamp your UV coordinates to stop it happening on texture edges, but elsewhere, it’s going to happen.

Disabling mip-maps or (texture filtering) is a bad idea because it has an adverse effect on performance. With a border of a couple of pixels, it won’t bleed far enough to show the color you’re avoiding.

Yes, it will. Where the problem happens, the mipmap is at 4x4 pixels or less. I logged a bug about this, where PVRTC compression flips areas of light and dark at low resolutions, but I don’t know if that’s something that can be fixed by Unity. And even still, the two lowest-res mipmaps are going to be lighter-colored.

You could potentially work around that by setting the mipmaps directly using SetPixels (which allows setting individual mip levels), except then you wouldn’t have texture compression.

–Eric

That’s why I didn’t do it.

Now, there is supposedly a file format that Unity reads in which you can create your own mipmaps. I saw that in some thread, but forgot how I found it. That might work, but I’d never heard of it before. I believe it mentioned that NVIDIA had a tool to create these files.

DDS, that’s it. Know anything about it?

Yep, in fact I was just thinking about that. :wink: A couple problems with DDS: 1) Windows-only tools AFAIK, 2) seems to be mostly relevant with DXT, unclear as to whether PVRTC support is available or common. Also it doesn’t import on Unity with PPC Macs, only Intel Macs, not that this affects most people (or Unity iPhone at all).

–Eric

Oh, this is IPhone specific? Then I’m afraid I can’t help you, as I’ve never developed on that platform. As you say, it could well be a by-product of working with that specific brand of texture compression.

I would have also suggested going with DDS and manually creating the mipmaps, but again, I only have experience with that on Windows.

The model looks simple enought to use some more polygons if needed, even if the goal is dynamic batching (300 verts.). I would try to use geometry to define the iris zone (a circle aproximation), and then give it its own UV island, apart of the white zone. This way you could use a green background for the iris texture, and the mipmapping would not mix the 2 zones.