- Home /
How can I turn off texture filtering on procedurally generated textures?
Hi everyone, I'm using the script below to generate a terrain texture onto a plane using perlin noise. The problem is, I'm going for a pixel art look and all of the pixels are smoothed into eachother, which looks especially bad if the image is small, for example 16x16. Is there a way to turn off texture filtering in code for the generated texture so that I can get sharp pixels?
using UnityEngine;
using System.Collections;
public class PerlinExample : MonoBehaviour {
public int pixWidth;
public int pixHeight;
public float xOrg;
public float yOrg;
public float scale = 1.0f;
private Texture2D noiseTex;
private Color[]pix;
void Start(){
noiseTex = new Texture2D(pixWidth, pixHeight);
pix = new Color[noiseTex.width * noiseTex.height];
renderer.material.mainTexture = noiseTex;
CalcNoise();
}
void CalcNoise(){
float y = 0.0f;
while (y < noiseTex.height){
float x = 0.0f;
while (x < noiseTex.width){
float xCoord = xOrg + x / noiseTex.width * scale;
float yCoord = yOrg + y / noiseTex.width * scale;
float sample = Mathf.PerlinNoise(xCoord, yCoord);
pix[(int)y * (int)noiseTex.width + (int)x] = new Color(sample, sample, sample);
x++;
}
y++;
}
noiseTex.SetPixels(pix);
noiseTex.Apply();
}
}
Answer by ratking · Jan 16, 2014 at 11:00 AM
http://docs.unity3d.com/Documentation/ScriptReference/Texture-filterMode.html
http://docs.unity3d.com/Documentation/ScriptReference/FilterMode.Point.html
noiseTex.filterMode = FilterMode.Point;
Your answer
Follow this Question
Related Questions
is there a way to make a gradient material, white to black, in Unity3D? 2 Answers
Texture2D: pixel Specific alpha not working? 4 Answers
Change Material settings through script 1 Answer
How to avoid Texture.Apply() 1 Answer
Making Unity textures/materials look as good as they did in Blender 2 Answers