I have a texture that I have created that looks something like this:
This is a very low texture map, but it helps me in a shader that I'm making that distinguishes between land and ocean, the ocean tiles do different things than the land. To try and figure out what was going on, I used the shader to turn the ocean, as defined by the mask, black. Note that this image doesn't match the ocean texture example from above, but it's the best I had...
The ocean is a binary color, either it is ocean or isn't, and is set appropriately. But what I'm actually seeing is that if the 2x2 tile area has mixed land/ ocean, the value is averaged.
What I've noticed is that the pixels were combining together, a 2x2 pixel area was averaged. After tracing through this for some time, I discovered that the issue was a quality setting that reduced the resolution of certain images.
There are some images that I don't mind lowering the resolution of, but images such as this one I absolutely don't want to lower the resolution. Is there a setting that I can add to a runtime generated texture to tell it not to reduce it's resolution if requested to by the quality settings?
EDIT: Code fragments to produce the results above. It's kind of hard to pull just the fragments that produce this code and not produce an overwhelming bit, but hopefully this will do.
Code to generate textures:
Color32[] windMask=new Color32[world.width*world.height];
for (int x = 0; x < world.width; x++)
{
for (int y = 0; y < world.height; y++)
{
windMask[x + world.width * y] = world.Tiles(x, y).baseType == Tile.BaseType.Ocean?new Color32(255,255,255,255):new Color32(0,0,0,255);
}
}
sharedMaterial.SetTexture("_WindMask", TextureUtilities.TextureFromColors(world.width, world.height, windMask, FilterMode.Point));
public static Texture2D TextureFromColors(int width, int height, Color[] colors, FilterMode filterMode = FilterMode.Trilinear)
{
Texture2D texture = new Texture2D(width, height);
texture.SetPixels(colors);
texture.filterMode = filterMode;
texture.Apply();
return texture;
}
The Shader code:
o.Albedo *= 1 - tex2D(_WindMask, IN.uv_MainTex).r;
The "Fastest" quality settings that show the issue:
The "Fantastic" quality, which correctly isolates the ocean.
Image of the correctly isolated ocean:
The issue is the "Texture Quality", which you will note for the fastest setting is half resolution. I would really like to keep the ability to use lower resolution in the game, but have a few textures that do not use the lower resolution if the quality settings change.