Every year and every 3ds Max Version I try again to understand why this is never fixed and how to find a better fix to this annoying issue. That thing is simple (or should be simple),  if you have an image with transparency info (alpha channel) you want it to show nice no matter the background. In the image above you see a dark halo in the borders that looks horrible. The same happens if the background is white in the render and later you composite it over a black background then you see white borders.

This also affect anti-aliasing, that depends on transparency. So even you don't use translucent materials your object could have issues on its borders when you composite the image in any 2D editing program or game engine.

 The following is the correct way,  how you want to behave a PNG with transparency :

Then when I google about it, is like only a few people have this concern and the forums discussion you find many different opinions, complex solutions and fights about if 3ds Max fault or Photoshop fault; or my fault for being so dump that I never found that secret super-hidden configuration that makes 3ds Max save .PNG right.
 A simple test says who is guilty. Open your 3ds Max .PNG on Gimp 2, or drag it to a new gmail message, try anywhere else and you will see that it will show wrong with the black or white background borders.

Why this happen?

When your image have and alpha channel then the color channel must be pure colors, NOT blended with the background color, have to be totally independent. But 3ds Max thinks in a different way, they always use pre-multiplied alpha and make things difficult for those that want to composite images outside of Max. (Tested with all versions until Max 2014, later versions I don't know yet, but I bet is still there)

Solution 1

Use another file format, like OpenEXR or TGA. Yes, it may work, but I want to use .PNG. Others makes things more complex. PNG is popular and sexy.

Solution 2

Fix with photoshop "Remove White|Black Matte". It works perfectly well fixing the mixed RGB channel.
Go to Layer > Matting > Remove White|Black Matte 

Done! But I'm not happy yet. I need to fix a whole animation sequence of many PNG images.
Ok. Create a new Photoshop action that applies "Remove White|Black Matte".  Go to Files > Scripts > Image processor and apply your new action to a whole folder of *.PNG images!
Wait... No.
I'm using Photoshop CS4 (I'm vintage guy) and the Image Proccessor doen't have a save to .PNG option! grrrrr.... Google time.
Yay! Found a modified script of Image Proccessor that adds PNG-24 support.
(NOTE: At the moment of writing this post the old links for the scrips are broken. So I going to share my copy of the  script here. Copy and replace the old one here: C:\Program Files\Adobe\Adobe Photoshop CS4 (64 Bit)\Presets\Scripts )

Well, I was happy for a while, but now I needed more speed, because Photoshop is too slow doing this, and you have wait for it to process all images to use Photoshop again.

"Solution" 3 

All that long story and you know what? I know how to do it myself, coding in Delphi, I even have my own graphics units with calculations to fix this by pixel, but I'm lazy to write a tool, that need to open and Save PNG and parse the files... brr.. better keep googling...

ImageMagick! I was already using ImageMagick tools for a while and now wanted to find a solution to my dirty PNGs. Wasn't easy, maybe is there, but the only thing I found was the command -FX, is great allows you to use mathematical expressions to convert the images pixel by pixel if you need it... but the happiness was over when I read that for every pixel you process the expression string is parsed and evaluated again, so after spending many hours figuring out how to use the -FX command maybe the processing would be mush slower than Photshop :(

So, finally let's do it myself:

Solution 4, Final!

I have my own graphics Unit developed over many years since Delphi 7 that makes many small efficient useful things, playing with pixels directly.

So now with  Delphi XE3 that supports Load/Saving of PNG, I made this console tool, that fix my PNGs like 10 times faster than Photoshop just with this line in the windows cmd:
dpxtool fixalpha *.png black   
And it works. :D
You can download the *.EXE and Delphi source here: [Download dpxTool]
Copy it anywhere and add to your Windows PATH environment variable.
If your PNG background is white just ommit the color:
dpxtool fixalpha *.png
Use wildcards:
dpxtool fixalpha frame????.png

Tell me in the comments if  any of this solutions works for you or if you have better one! ;)

Original Images (Right click to download  PNG):

Image rendered with 3ds Max 2014. See how it shows the black borders on your browser:
This is the image result after fixing with dpxTool. Now it is blending nicely with the white background:

Share To:
Denys Almaral

Denys Almaral

Denys is a 3D artist with an old passion for game development

Post a Comment