Author Topic: Transparent pixel rendering...  (Read 11108 times)

2017-04-24, 18:45:06

Naxos

  • Primary Certified Instructor
  • Active Users
  • ***
  • Posts: 201
    • View Profile
Hello there,

As some may know i'm a lot involved in "configurators" projects, where i render a lot of PNG rgba files to let the final user choose colors for a product
http://configurateur.billard-toulet.com/

As you may have noticed, in some color cases, dark on dark, or light on light, for ex. we get an awfull contour, due to the arbitrary 128grey choice for the background (best fit for all-case solution)...
Let me show you some quick tests :

dark on dark effect - 128grey background


light on light effect - 128grey background

What would be great is to be able to "render" transparent pixels... Sort of premultiplied alpha, but not during the saving picture process (it already exists when PNG is used for ex.),
but the Photoshop-way :


Screenshot of the photoshop "draw - onto - transparent pixels"...


... and pasted onto my background picture...

Now let's speak about coding this one : i'm not a coder guy, but my logical think about it would be :
I'm the CPU, i'm rendering the picture... For that pixel being rendering, what's about alpha : is it black or is it white ? (or grey)...
If the alpha is white, ok then i go on rendering it...
If the alpha is 100% black, ok i ignore it and set this pixel to transparent... Really transparent, not letting the 3D background / direct visibility override color...
If the alpha is somewhere in between, ok i write the premultiplied alpha value onto it, again not on the background / direct visibility color, but on transparent way...
Just like Photoshop does when we draw on empty layer...

That would prevent contour, and more than that, that would maybe speed up the rendering of the scene, because black-alpha-ed pixels would be ignored...

What do you think of that ? Is it possible ?

2017-04-25, 13:03:05
Reply #1

Fluss

  • Active Users
  • **
  • Posts: 553
    • View Profile
This is a premultiplication/unpremultiplication issue. For compositing purpose, you should always render on a black background. Then, unpremult -> grade -> premult.

Look at this :

http://www.schoolofmotion.com/premultiplication-demystified/

AND

« Last Edit: 2017-04-25, 13:09:41 by Fluss »

2017-04-25, 17:39:44
Reply #2

Naxos

  • Primary Certified Instructor
  • Active Users
  • ***
  • Posts: 201
    • View Profile
Very interesting tuto, thanks...

But it is not really what i need, since i don't grade anything, just i'd like to get rid of contour right outside the box after render...

Here is a test within a black background, and we still see dark contour, no grade, no change : just render and apply onto back picture...

3dsmax / Corona premultiply the alpha with PNG output, but i can't find the "Straighten alpha" the tuto is talking about...



« Last Edit: 2017-04-25, 17:48:35 by Naxos »

2017-04-26, 12:44:30
Reply #3

Fluss

  • Active Users
  • **
  • Posts: 553
    • View Profile
PNG automatically premultiply alpha, so you get part of the background in the antialiased areas. If you want to get rid of this, you HAVE TO comp your render over your background in post and tell your compositing package you have rendered a premultiplied image over a solid background (and specify that background color for removing the premultiplication from the color channels).

2017-04-26, 13:06:10
Reply #4

Naxos

  • Primary Certified Instructor
  • Active Users
  • ***
  • Posts: 201
    • View Profile
problem is that i manage several png layers, containing from dark to light objects...

That is why the Photoshop-like transparent background is needed, i can't use any arbitrary background except a 128grey as a medium-range one...

2017-04-26, 14:11:39
Reply #5

sebastian___

  • Active Users
  • **
  • Posts: 200
    • View Profile
I discovered a long time a go, I think in 3ds max 3 or 4 times, that you cannot composite anything without using TGA and unchecking the premultiplied checkbox. It will look ugly everywhere like in picture viewers, but it will work right in after effects, premiere, and I think in 3ds max too. Without any lines and contours.
 I don;t understand why no one uses this simple workflow.
But I think people use instead the unmult/premult and stuff in Nuke and so on.





I'll do some testing later
(and always leave the "compress" check box on, because it's lossless and actually faster in some cases.)

The pics are just examples from google, but not sure if the settings are correct in the pic.

2017-04-26, 17:14:21
Reply #6

Naxos

  • Primary Certified Instructor
  • Active Users
  • ***
  • Posts: 201
    • View Profile
Good to know : i'll give a test rendering in TGA without premult, then open in photoshop to save PNG with real transparent background...

Many thanks.

2017-04-28, 07:20:35
Reply #7

sebastian___

  • Active Users
  • **
  • Posts: 200
    • View Profile
I did some quick testing and the results were inconclusive.
I rendered a plane with a gradient ramp in the opacity channel and saved the image with a variety of settings with PNG and TGA. Using a gray background and black background.

And composited the render in AE over a gray background.
And the only conclusion so far, without further tests, if you have some weird contour - you need to do some quick tests with a simple scene and change settings until the rendered object looks right. Try with a black background, and with a PNG and with TGA with and without "Pre-Multiplied Alpha" on.
And also don't forget if you compose in after effects to right click on the render file, and chose "interpret footage"

2017-04-28, 16:58:22
Reply #8

mraw

  • Active Users
  • **
  • Posts: 162
    • View Profile
Quote
What would be great is to be able to "render" transparent pixels... Sort of premultiplied alpha, but not during the saving picture process (it already exists when PNG is used for ex.),
but the Photoshop-way :

Quote
That is why the Photoshop-like transparent background is needed, i can't use any arbitrary background except a 128grey as a medium-range one...

the 'Photoshop-like transparent bg needed' is only a visual interpretation of a black alpha channel. That's all.
asking for transparent pixel rendering shows a misconception of the premultiply thing.

https://limnu.com/premultiplied-alpha-primer-artists/
I only had a brief look into it, but it seems ok.

I had a very hard and long time myself fully understanding the concept of premultiplied/unpremultiplied. But after I got it I never complained about 'fringes' or 'contours'.

Key is to know what you've got: Pre or unpremultiplied images.
When you will need to know what the software getting the images expect to get:  Pre or unpremultiplied images.
And if this mismatches you'll either have to to tell the software otherwise or use a premultiply/unpremultiply operation.
Hope this helps a bit...

2017-04-28, 17:56:03
Reply #9

Naxos

  • Primary Certified Instructor
  • Active Users
  • ***
  • Posts: 201
    • View Profile
Did you visit the configurator i've made ?
This is quite easy to create : DIVs on top of each others, with PNG rgba in them...
So it is meant to be shown with Chrome, IE, Edge, Safari, Firefox etc...

None of those softwares are managing pre or unpremultiplied alphas, just they put the PNG as it is written on HDD...

Also, for this project, i've rendered more than 150 000 PNG files, it has to be strait out-of-the-renderBox, far too many files to be post-processed to manage alpha premultiplication...

I'll give a look at the link you've gave us (thank you for that), but i'm affraid that this will not change for my specific problem...

2017-04-28, 21:08:05
Reply #10

lmikkelb

  • Active Users
  • **
  • Posts: 86
    • View Profile
Naxos
 
- Render 16bit exr with black background in Max.
- batch import all the exr`s to Photoshop. If it`s even possible:)   
- batch save all layers to png.

In my tests i got no black edge and straight rgb out from photohop.
I really dont think you should render the background in anything other than black, if that`s still an option.
I also think you need to make sure (Blend rgb colors using gamma: 1,00) is on in
photoshop color settings, you probably have done that:)     

I guess your problem is the amount of frames,  you need to find a way to batch this process through Photoshop :) Good luck!


Btw, i looked at all my pngs out from Photoshop in Nuke, so you might get different results, I guess it depends on how it is implemented in the browser. but i think it will work.
« Last Edit: 2017-04-28, 21:23:38 by lmikkelb »

2017-04-29, 11:20:56
Reply #11

Naxos

  • Primary Certified Instructor
  • Active Users
  • ***
  • Posts: 201
    • View Profile
i'll give a try, thank you

2017-04-29, 15:45:10
Reply #12

mraw

  • Active Users
  • **
  • Posts: 162
    • View Profile
Quote
- Render 16bit exr with black background in Max.

You're rendering on a non-black bg?

2017-05-18, 15:38:56
Reply #13

raumtaucher

  • Active Users
  • **
  • Posts: 8
  • Call me Ray :-)
    • View Profile
    • My Website
My suggestion: get the render only selection as a render element instead of using cmasking_mask to cut objects from Beauty-Pass.
The problem always is, that in these cases the background has not a single color for comping with clear borders.
if you render a selection, then the selection has borders which are premultiplied to black. Aftereffects or Photoshop has no problems to paste them perfect on backplates.
In my examples you can see the difference of using cmasking-mask or render selection.
In case of render selection are no need to tweak the mask. Its perfect. With cmasking.mask you need to tweak the masks a lot. If you make color correction or comping new parts together.
For big print resolutions you can disregard the small borders, but in 1080P or 4k they have to be clean. espacially for motion blur or transparent materials.

2017-05-18, 16:28:37
Reply #14

Naxos

  • Primary Certified Instructor
  • Active Users
  • ***
  • Posts: 201
    • View Profile
Render selection.... great idea : i'll test that !