2
\$\begingroup\$

I am trying create a glow effect on a background, to do this I am using shaders, when I use the main texture everything is okay, but when I put the emission map the texture corrupts This is happend

Here's the original image for those trying to replicate the problem:

enter image description here

I am beginner about shaders and Unity

\$\endgroup\$
3
  • \$\begingroup\$ Can you share your input image so we can try to reproduce the problem with the exact image data you're using? \$\endgroup\$ – DMGregory Jan 2 at 16:24
  • \$\begingroup\$ imgur.com/pAn6GZc This the image in imigur \$\endgroup\$ – Luis Schmitt Jan 2 at 16:38
  • \$\begingroup\$ Interestingly, when I took the image that was linked in the comment above & pasted the link into the question directly, it doesn't display as expected. Maybe some sort of alpha or encoding problem? \$\endgroup\$ – Pikalek Jan 4 at 14:59
2
\$\begingroup\$

It looks like you've imported this texture with the flag "Alpha is Transparency" ticked.

This tells Unity that the colour values of texels in zero-alpha areas will never be seen (because they're transparent), so it's free to modify them to help avoid ugly fringes at the edges of sprites, or to make the texture compress better.

So here it's bled the white of your windows out into the zero-alpha regions of the texture, on the assumption that you will keep the promise you made and only ever treat those texels as transparent.

You can see the correct shapes of the windows are still preserved in the alpha channel. And if we multiply the RGB channels by the alpha (like we would if rendering the image with transparency), we get the same result as your original image:

Multiplied Result

So there's no "corruption" here at all. Unity is applying a safe, information-preserving transformation to help your image render correctly in the way you promised you were going to render it.

The problem here is you broke your promise. You're not using it like a transparent sprite. You're discarding the alpha channel and using the RGB channels alone for emission.

Because you're using the texture in a way that's different from what you promised by ticking "Alpha is Transparency", the transformation Unity applied is no longer safe for that use case.

So, three solutions:

  1. Uncheck "Alpha is Transparency" so you're not making promises that you don't plan to keep.

  2. Pre-multiply the RGB channels by the Alpha channel as shown above, and pass the multiplied result to the emission pin. That way you emulate the transparent blending that's assumed by the "Alpha is Transparency" checkbox. This will also work for colour images.

  3. If you only want white emission, wire just the texture's Alpha pin to the material emission pin. That way you can discard the unused RGB information entirely, and store your texture in an Alpha-only format.

\$\endgroup\$
1
  • \$\begingroup\$ Oh thank you, it worked !! \$\endgroup\$ – Luis Schmitt Jan 3 at 20:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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