Re: Noesis 2 png transparency
If that can help people, here's a small Unity Editor script to automatically pre-multiply alpha at import time:
https://gist.github.com/MrJul/1042aa754 ... a7d7d039c3
It doesn't change the original file, only the imported Unity asset, which is useful since the PNG display stays "correct" in non-Unity editors (Blend, etc).
https://gist.github.com/MrJul/1042aa754 ... a7d7d039c3
It doesn't change the original file, only the imported Unity asset, which is useful since the PNG display stays "correct" in non-Unity editors (Blend, etc).
Re: Noesis 2 png transparency
Thanks for this! We will include it in our documentation!
Re: Noesis 2 png transparency
Sometimes you (or rather the user) is bringing in a texture at runtime that you have no control over the authoring up. In which case, if the image has alpha you are going to have to get it in the right format so it looks correct. To wit, I submit the following extension to the Texture2D class which handles this:
Given Noesis' insistence on pre-multiplied Alpha, and Unity's insistence on not having pre-multiplied Alpha... might be good to have this in the Noesis API somewhere (if such a thing doesn't already exist).
David
Code: Select all
public static class Texture2DExtensions
{
public static void PreMultiplyAlpha(this Texture2D texture)
{
// Check if the texture has an alpha channel
if (texture.format == TextureFormat.Alpha8 ||
texture.format == TextureFormat.ARGB4444 ||
texture.format == TextureFormat.RGBA32 ||
texture.format == TextureFormat.RGBA4444 ||
texture.format == TextureFormat.RGBAFloat ||
texture.format == TextureFormat.RGBAHalf)
{
// Get the pixel data of the texture
Color[] pixels = texture.GetPixels();
// Pre-multiply the alpha values of the pixels
for (int i = 0; i < pixels.Length; i++)
{
pixels[i] = new Color(
pixels[i].r * pixels[i].a,
pixels[i].g * pixels[i].a,
pixels[i].b * pixels[i].a,
pixels[i].a
);
}
// Set the pixel data of the texture
texture.SetPixels(pixels);
texture.Apply();
}
}
}
David
Re: Noesis 2 png transparency
It is impossible to get the right result without using pre-multiplied alpha, but we could do this internally in the shader. Slightly more inefficient but probably worth it. We have plans to implement support for premultiplied and non-premultiplied textures in the long-term.Given Noesis' insistence on pre-multiplied Alpha, and Unity's insistence on not having pre-multiplied Alpha... might be good to have this in the Noesis API somewhere (if such a thing doesn't already exist).
Thanks for the contribution.
Re: Noesis 2 png transparency
Yeah, I'm not complaining ... (that much)... but thought this would be useful.
Making this fact more obvious would help too. Noesis suffers from information overload trying to get started with it. And is saddled with all the complexities of xaml, which is a world of hurt all by itself.
As the saying goes:
Xaml makes the difficult easy, and the easy impossible.
Making this fact more obvious would help too. Noesis suffers from information overload trying to get started with it. And is saddled with all the complexities of xaml, which is a world of hurt all by itself.
As the saying goes:
Xaml makes the difficult easy, and the easy impossible.
Re: Noesis 2 png transparency
Thanks for the feedback! There are also plans to automatically apply the "noesis" label to textures used by Noesis in Unity.
Who is online
Users browsing this forum: Bing [Bot], Google [Bot] and 21 guests