- Home /
How to prevent RenderTexture colour blending
I'm using Simple Pixelator (code to follow) to pixelate a scene to give it a proper pixel density relative to the rest of my game and I've run into a problem.
In spite of this texture being solid black and white, it interprets certain angles as being grey. I would like my textures to maintain their exact colour depth. Is there a way this can be accomplished? Right now, this is the code I'm using:
//SimplePixelizer
//Copyright © The Breemans Lounge Company
//This script should be available for free in the Asset Store. if you found this script, or bought this script, from a third party seller please contact us
//contact@breemanslounge.com
using UnityEngine;
using System.Collections;
[ExecuteInEditMode]
[AddComponentMenu("Image Effects/Pixelizer")]
public class SimplePixelizer : MonoBehaviour {
public int pixelize = 1;
protected void Start() {
if (!SystemInfo.supportsImageEffects) {
enabled = false;
return;
}
}
void OnRenderImage (RenderTexture source, RenderTexture destination) {
RenderTexture buffer = RenderTexture.GetTemporary(source.width/pixelize, source.height/pixelize, 0);
buffer.filterMode = FilterMode.Point;
Graphics.Blit(source, buffer);
Graphics.Blit(buffer, destination);
RenderTexture.ReleaseTemporary(buffer);
}
}
For the checkerboard texture, what is the resolution shown at the bottom of the Inspector? Also, is it a power-of-two texture?
I am wondering, were you able to solve it? I ran into the same problem.
Answer by Bunny83 · Jan 10, 2013 at 11:27 PM
Uhm a white surface that is only lit partly will be gray. If you talk about the gray linesat the edge between a white and a black square, that's due to mipmapping. You can turn of mipmap generation, but you will have heavy aliasing. You can also try to just turn off anisotropic filtering but that makes it even worse since it's there to reduce this effect from mipmapping.
RenderTexture doesn't have mipmaps enabled by default and none are generated in the code sample I provided. Anisotropic filtering only applies if you use bilinear or trilinear filtering, which I am not. I am using point filtering.