How do I set point sampling when magnifying a texture.
The following script (attached to Plane object) seems to use linear sampling, even though the filterMode is set to point:
using UnityEngine;
using System.Collections;
public class CreateSimpleTexture : MonoBehaviour {
void Start () {
Texture2D texture = new Texture2D(30,30,TextureFormat.ARGB32,false);
Color[] colors = new Color[texture.width*texture.height];
for (int x=0;x<texture.width;x++){
for (int y=0;y<texture.height;y++){
if (y%2==0 && x%2==0){
colors[y*texture.width+x] = new Color(1,0,0,1);
} else {
colors[y*texture.width+x] = new Color(1,1,1,1);
}
}
}
texture.filterMode = FilterMode.Point;
texture.wrapMode = TextureWrapMode.Clamp;
texture.SetPixels(colors);
texture.Apply();
GetComponent<MeshRenderer>().sharedMaterial.mainTexture = texture;
}
}
Result:
[698-Screen+Shot+2012-04-20+at+1.32.01+PM.png|698]
(I’m running OS/X - I don’t know if this problem is platform related)