- Home /
2D procedural texture looks buggy with certain resolutions
Hi there,
I am procedurally generating textures, each of which are bound to an unlit texture Material with Offset 0, 0 and Tiling 1, 1. When I generate the textures, they work great with many resolutions and very poorly with others.
Here is what it looks like when it works:
And here is what it looks like when it doesn't:
I have messed around with Texture2D() mipchain, the Apply() updateMipmaps argument, and filterModes. None have been to any avail. Here is my code below:
// GENERATE AND APPLY TEXTURE
Texture2D texture = new Texture2D(width, height, TextureFormat.ARGB32, false); // width and height are integers
texture.filterMode = FilterMode.Point;
// 0 -> width/height
for (int x = 0; x < width; x++) {
for (int y = 0; y < height; y++) {
// 0 -> 1
float i = ((float)x / (float)width) * (float)width / (float)height;
float j = (float)y / (float)height;
bool open = ((Mathf.PerlinNoise((offset.x + i) * stretch, (offset.y + j) * stretch)) < clamp); // offset is a Vector2Int; stretch is a float; and clamp is a float
Color col = open ? empty : full; // empty and full are white and black, respectively
texture.SetPixel(x, y, col);
}
}
texture.Apply();
mat.SetTexture("_MainTex", texture);
What am I missing? Surely there's a way to make the sprite look normal. Another note is sometimes after initially generating the texture, the first time I regenerate the same texture after, it fixes some minor horizontal rendering issues. Any help would be greatly appreciated—thank you!
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Combine Array of Sprites to Form One Sprite 0 Answers
How can I change the sprite using an image URL? 1 Answer
Aligning planes thin gap? c# 0 Answers