0
\$\begingroup\$

I have a material with a spritesheet texture (albedo) and an emission map. The spritesheet has 32x32 squares. The emission has a 32x32 square that is an emission for the magma-looking square.

Material on quad

It works well on the magma, however, the glow also spreads to the sand, grass, planks, and snow_grass textures. You can clearly see it spread on the sand (bottom-rightmost opaque texture) in the right because it isn't directly touching the magma. Here is another picture where it is attached

Material on sphere

You can still see the spreading of glow if you look closely. Now, you can definitely see it glow here

enter image description here

How do you stop that from happening? That artifact is really weird and i really need it to go away. I've tried decreasing the size of the square in the emission map but it still was there. Please help.

Thanks.

EDIT 1 Here is how I apply uv

` public static Dictionary textureMap = new Dictionary();

public static void Initialize(string texturePath, Texture texture)
{
    Sprite[] sprites = Resources.LoadAll<Sprite>(texturePath);

    foreach (Sprite s in sprites)
    {
        Vector2[] uvs = new Vector2[4];
        uvs[0] = new Vector2(s.rect.xMin / texture.width, s.rect.yMin / texture.height);
        uvs[1] = new Vector2(s.rect.xMax / texture.width, s.rect.yMin / texture.height);
        uvs[2] = new Vector2(s.rect.xMin / texture.width, s.rect.yMax / texture.height);
        uvs[3] = new Vector2(s.rect.xMax / texture.width, s.rect.yMax / texture.height);
        //Debug.Log(s.name);

        if (!textureMap.ContainsKey(s.name))
        {
            textureMap.Add(s.name, uvs);
        }
    }

}

public static bool AddTextures (Block block, Direction direction, int index, Vector2[] uvs)
{
    string key = FastGetKey(block, direction);

    Vector2[] text;
    if (textureMap.TryGetValue(key, out text))
    {
        //Debug.Log(key);
        uvs[index] = text[0];
        uvs[index + 1] = text[1];
        uvs[index + 2] = text[2];
        uvs[index + 3] = text[3];
        return true;

    }

    text = textureMap["Default"];

    uvs[index] = text[0];
    uvs[index + 1] = text[1];
    uvs[index + 2] = text[2];
    uvs[index + 3] = text[3];

    return false;
}

`

Where Direction is a direction (example north) and Block is a short. Index is the vertex index of the mesh. Texture is the sprite texture (.png)

\$\endgroup\$
8
  • \$\begingroup\$ How big is your spritesheet, and how have you set the UVs on your meshes? Do you have mipmapping enabled? \$\endgroup\$
    – DMGregory
    Commented Dec 30, 2018 at 16:50
  • \$\begingroup\$ Mipmaps are not enabled, sprite sheet is 160x128 \$\endgroup\$ Commented Dec 30, 2018 at 16:56
  • \$\begingroup\$ That could be a factor. Have you tried making your sprite sheet a power of two in both dimensions? \$\endgroup\$
    – DMGregory
    Commented Dec 30, 2018 at 16:57
  • 1
    \$\begingroup\$ I suspect its due to the bilinear filtering done on the emission map. Try changing it to point filtering. \$\endgroup\$
    – DarkDestry
    Commented Dec 30, 2018 at 16:58
  • \$\begingroup\$ @DMGregory no, but I presume that it will still spread \$\endgroup\$ Commented Dec 30, 2018 at 17:02

1 Answer 1

1
\$\begingroup\$

So I figured out a solution. (I "disobeyed" DMGregory) If ever you have an emission map that can become a power-of-two image due to transparency, you need to check if unity made it one. Check it under Advanced > None Power of 2. Set it to none. I did this to mine and it worked. Also just change it to point filter.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .