Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

In an Android game, I have a gradient background that changes color over time. This was achieved by creating a 1x2 pixel texture in code, and stretching it over a large quad with bilinear filtering.

This all works fine in the editor, but as soon as it is viewed on an Android device, the banding is ridiculously noticeable and annoying.

Since this texture is generated in code, I cannot set the compression to "truecolor" like most other post suggest, nor can I tick the "Generate Mipmap" option.

Here is how the gradient look on the phone : enter image description here

Code to generate gradient (stripped of unimportant stuff):

Texture2D gradient;
MeshRenderer render;
Color HSV1, HSV2;
Color primaryColor, secondaryColor;

render = GetComponent<MeshRenderer>();

Update() {
    HSV1.x += 0.01F * Time.deltaTime;
    HSV2.x = HSV1.x;

    if (HSV1.x > 1)
        HSV1.x = HSV1.x - 1;

    if (HSV2.x > 1)
        HSV2.x = HSV2.x - 1;

    primaryColor = Color.HSVToRGB(HSV1.r, HSV1.g, HSV1.b + HSVdifferece);
    secondaryColor = Color.HSVToRGB(HSV2.r, HSV1.g - HSVdifferece, HSV1.b - HSVdifferece);

    gradient.SetPixel(0, 0, primaryColor);
    gradient.SetPixel(0, 1, secondaryColor);
    gradient.filterMode = FilterMode.Bilinear;
    gradient.Apply();

    render.material.SetTexture("_MainTex", rainbow);

}

The color banding is really obvious and annoying. How can I fix this?

share|improve this question
    
can you please add some code so it'll be easier to help and work from there. thanks. – Daniel Netzer Jul 2 at 8:44
    
Sure thing, added code. – Samuel Ng Jul 2 at 9:23

Texture2D constructor has textureFormat and mipMap arguments. So create texture with options needed and set your pixels you want.

share|improve this answer
    
The constructor of Texture2D takes in a type of TextureFormat. To my knowledge, TextureFormat only contains compressed formats (ie: there is no TextureFormat.Truecolor). – Samuel Ng Jul 5 at 13:41
1  
you should try to look at the documentation on that enum and search a bit on that topic RGBA32 is what you need or some other truecolor textureformat – bobenko Jul 9 at 15:42

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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