0

Here's a picture of the graphical glitch. It essentially creates concentric rings of discoloration around the camera, including the player camera or the scene editor camera.

I ran into this problem in a larger project of mine, but after playing around with the editor for a while, I figured out how to recreate the problem easily.

To recreate:

  1. Create a new unity project (I tried this on both the 3d (URP) and 3d (hdrp) templates and found the issue on both)
  2. Create a new empty Game Object and add a mesh filter and mesh renderer component.
  3. Apply the attached script to the Game Object
  4. Import the attached texture image, set the filter mode to "Point (no filter)", and drag it onto the Game Object
  5. Run the game
  6. Move the scene editor camera around and you should see the graphical glitch. You can also point the Main Camera object at the generated meshes to see the glitch in the Game screen.

The graphical glitch goes away as soon as I set the filter mode off "Point", but filtering the asset makes the pixel art look blurry, so I'm not really willing to consider that as a fix. Does anyone have any idea what's happening here and/or how to go about fixing it?

Here's the art asset.

Here's my code:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class TerrainGenerator : MonoBehaviour
{
    public int width = 100;
    public int height = 100;

    Mesh mesh;

    List<Vector3> vertices = new List<Vector3> ();
    List<int> triangles = new List<int>();
    List<Vector2> uvs = new List<Vector2>();

    int vertexCounter = 0;

    // Start is called before the first frame update
    void Start() {
        mesh = gameObject.GetComponent<MeshFilter>().mesh;

        mesh.Clear();
        vertices.Clear ();
        triangles.Clear ();
        uvs.Clear ();

        for (int i = 0; i < width; i++) {
            for (int j = 0; j < height; j++) {
                addFace(i, j, 1, 1);
            }
        }

        mesh.vertices = vertices.ToArray();
        mesh.triangles = triangles.ToArray();
        mesh.uv = uvs.ToArray();

        mesh.RecalculateNormals();
    }

    private void addFace(int x, int y, int width, int height) {
        vertices.Add(new Vector3(x, 0, y));
        vertices.Add(new Vector3(x, 0, y + height));
        vertices.Add(new Vector3(x + width, 0, y));
        vertices.Add(new Vector3(x + width, 0, y + height));
        vertices.Add(new Vector3(x + width, 0, y));
        vertices.Add(new Vector3(x, 0, y + height));

        triangles.Add(vertexCounter++);
        triangles.Add(vertexCounter++);
        triangles.Add(vertexCounter++);
        triangles.Add(vertexCounter++);
        triangles.Add(vertexCounter++);
        triangles.Add(vertexCounter++);

        uvs.Add(new Vector2(0, 0));
        uvs.Add(new Vector2(0, 1));
        uvs.Add(new Vector2(1, 0));
        uvs.Add(new Vector2(1, 1));
        uvs.Add(new Vector2(1, 0));
        uvs.Add(new Vector2(0, 1));
    }
}

1 Answer 1

0

On the texture settings for the asset, under advanced > disable 'generate mip maps'. Wikipedia article on mipmaps. See below screenshots for before and after. Good luck with the project :)

mip maps disabled mip maps enabled

Not the answer you're looking for? Browse other questions tagged or ask your own question.