- Home /
How to use enlarged, pixelated textures without texel bleeding
I'm trying to create a game using low-res textures blown up to appear pixelated. Unfortunately, whenever I zoom in on the texture, it appears that the color from one texel has bled into others. n.b. This is not a bilinear filtering issue - I have set the filtering the Point filtering, which makes the image nice and blocky, but still has color bleed issues.
Things I have tried: I have tried changing the texture format (RGB24) to reduce any artifacts from compression. I have disabled mipmaps. I have disabled anisotropic filtering I have toggled the linear parameter in the Texture2D constructor I have set the camera to orthographic I have offset the camera by half-pixel amounts.
Nothing seems to work. I have output the texture directly from unity to a file, and verified that it is texel-perfect, but when viewed inside Unity, the texels bleed.
Raw Texture (enlarged):
Screenshot:
Testing is easy, attach the script to a Plane and point the camera at it (or view it in the scene viewer). It will also output the texture as a png in your project directory.
here is the code:
using UnityEngine;
using System.Collections;
public class TextureTest : MonoBehaviour {
private Texture2D texture;
public void Start() {
int width = 20;
int height = 20;
texture = new Texture2D(width, height);
texture.filterMode = FilterMode.Point;
for (int row=0; row<height; ++row) {
for (int column=0; column<width; ++column) {
Color color = new Color(row % 3 == 0 && column % 3 == 0 ? 1 : 0, 0, 0);
texture.SetPixel(column, row, color);
}
}
texture.Apply();
this.renderer.material.mainTexture = texture;
byte[] bytes = texture.EncodeToPNG();
System.IO.FileStream stream = new System.IO.FileStream("Texture.png", System.IO.FileMode.Create);
System.IO.BinaryWriter writer = new System.IO.BinaryWriter(stream);
writer.Write(bytes);
writer.Close();
stream.Close();
}
}
Is the generated texture a power-of-two size? If not, Unity will automatically upscale it to the nearest power-of-two size which might be the cause of your problem.
Your answer
Follow this Question
Related Questions
Blurred Textures 1 Answer
Controlling Subsampling on textures in Unity 1 Answer
How to Apply a Texture to an Object in Unity 4 1 Answer
Textures and transparency 1 Answer
Import Texture with good quality... 2 Answers