Author Topic: Write Masks to Alpha Channel  (Read 5485 times)

2020-02-13, 02:23:12

cjwidd

  • Active Users
  • **
  • Posts: 1077
    • View Profile
    • Artstation
Is there already a way to store all rendered masks into the alpha channel of 32-bit .EXR (or 16-bit .TIFF) automatically in Corona / 3ds Max?

It sounds like this user is requesting something similar for Corona in C4D(?)

EDIT: if not, does anyone have a tasty PS script they could share(?)
« Last Edit: 2020-02-13, 02:35:18 by cjwidd »

2020-02-13, 09:47:54
Reply #1

sprayer

  • Active Users
  • **
  • Posts: 794
    • View Profile
I am using wirecolor mask, and randomize wire color script for objects

2020-02-13, 09:50:26
Reply #2

cjwidd

  • Active Users
  • **
  • Posts: 1077
    • View Profile
    • Artstation
Link to resources?

2020-02-13, 09:59:12
Reply #3

GeorgeK

  • Corona Team
  • Active Users
  • ****
  • Posts: 838
  • George
    • View Profile
George Karampelas | chaos-corona.com
Chaos Corona QA Specialist | contact us

2020-02-13, 11:11:18
Reply #4

maru

  • Corona Team
  • Active Users
  • ****
  • Posts: 12768
  • Marcin
    • View Profile
Isn't every RGB mask saved with its own alpha channel? For example if you save to EXR and open it in PS with the EX-io plugin?
Marcin Miodek | chaos-corona.com
3D Support Team Lead - Corona | contact us

2020-02-14, 00:38:04
Reply #5

cjwidd

  • Active Users
  • **
  • Posts: 1077
    • View Profile
    • Artstation
@GeorgeK I read over the scripts description, but it sounds like what this script is doing is essentially *generating* masks based on wire color. However, my question is about how to compile all masks that are included as render elements (in Corona) in the alpha channel of the beauty pass of an .EXR.

@Maru Yes I think this is true, for example if you have three objects, you can assign each one to the R,G, and B channels of a mask, but I think you are limited to only those three channels - only three objects or sets of objects.

It's definitely not as sophisticated, but my current workflow is to just generate one mask per object (or object set) that requires one and then save everything into an .EXR, e.g. beauty, translucency, shadows, alphas, etc. The issue is that I have to copy / paste all the masks into the alpha channel individually.

2020-02-14, 08:21:23
Reply #6

Frood

  • Active Users
  • **
  • Posts: 1922
    • View Profile
    • Rakete GmbH
The issue is that I have to copy / paste all the masks into the alpha channel individually.

The question is: why would you like to have them there? Is it about the convenient Ctrl-Click to get a selection? Or to keep the document tidy? I have recorded myself a simple ps action for that purpose, all I need to do is to select a (b&w) mask layer and press a hotkey.

To record: have a layer visible and selected, start recording, Alt-Click on the layer visibility icon (so that it's the only layer which is visible now), change to channels, Ctrl-click on the RGB channel, go back to layers, Alt-Click on the visibility icon again, stop recording. Then assign the action to any hotkey.

Now you can just select a layer, press the hotkey and you have a selection to use as mask. No more Ctrl-A, Ctrl-C, Q, Ctrl-V, Q  which would be another option to be recorded - for some reason I've chosen the above one, don't know why anymore.


Good Luck



Never underestimate the power of a well placed level one spell.

2020-02-14, 09:48:40
Reply #7

cjwidd

  • Active Users
  • **
  • Posts: 1077
    • View Profile
    • Artstation
@Frood Yes, it is 100% about the convenience of performing different selections on the masks, e.g. Ctrl+click, Ctrl+shift+click, Ctrl+shift+alt+click.

2020-02-14, 10:53:41
Reply #8

Frood

  • Active Users
  • **
  • Posts: 1922
    • View Profile
    • Rakete GmbH
Yes, reason enough. Especially when it comes to shift/alt clicks. Personally I would have a look at these

https://www.adobe.com/content/dam/acom/en/devnet/photoshop/pdfs/photoshop-cc-scripting-guide-2019.pdf

https://www.adobe.com/content/dam/acom/en/devnet/photoshop/pdfs/photoshop-cc-javascript-ref-2019.pdf

and would try to write a script which converts the currently selected layers to channels of the same name. I think this is what you were asking for in your 'Edit' in the OP. Would be useful for sure...


Good Luck


Never underestimate the power of a well placed level one spell.

2020-02-14, 19:58:06
Reply #9

cjwidd

  • Active Users
  • **
  • Posts: 1077
    • View Profile
    • Artstation
Yeah I'm working on a .js script that will basically take all the open documents after the focused document, copy the document (i.e. mask), close the document, paste into alpha channel, write the pasted document name to the alpha channel label, then iterate through that loop for all open documents.

2020-02-20, 10:15:26
Reply #10

Frood

  • Active Users
  • **
  • Posts: 1922
    • View Profile
    • Rakete GmbH
So you are working with multiple files usually? We use layered exr/cxr almost exclusively. I could not resist to try myself now (because yes, it's something to streamline) and I made "Layers to Channels" which you can find as a menu item in "File" -> "Automate" after throwing it into the scripts folder. It detects if RGB channels are equal or not for a layer and splits it into different channels if necessary. No masterpiece (never js-scripted PS before), but despite the fact that the api hmm. "surprised" me a bit with it's "simplicity" it works ok for me :)


Good Luck


Edit: corrected typo in archive


« Last Edit: 2020-02-21, 12:35:42 by Frood »
Never underestimate the power of a well placed level one spell.

2020-02-20, 19:27:15
Reply #11

cjwidd

  • Active Users
  • **
  • Posts: 1077
    • View Profile
    • Artstation
Hey Frood, this looks like exactly what I was trying to do. I will check this out and report back in a bit.

2020-02-21, 01:39:09
Reply #12

cjwidd

  • Active Users
  • **
  • Posts: 1077
    • View Profile
    • Artstation
@Frood

Your script is fantastic and it so happens that it is exactly what I was trying to achieve. Thank you so much for sharing, I really, really appreciate it :)

In your case, you are loading packed RGB masks - not mono masks - into the layered .EXR and then running the script on a single layer, i.e. the script does not loop through all layers, only the selected layer?

@GeorgeK

The Random Wire Color Tools script is really great for its intended use case, i.e. assigning wire colors to objects in the scene. How are you using it in conjunction with masking in your workflow? For example, are you using packed RGB masks or mono masks? In the case of the former, obviously you can use CMasking_WireColor, but this produces a single RGB mask that would have to be color selected in PS, which may require additional clean-up to generate a clean mask.

There is another script on the forums (2015) that will generate mono masks based on ALL scene materials, which when used in conjunction with @Frood's script, basically implements the workflow I had imagined. However, unless you keep a VERY tidy scene you are going to generate a bunch of masks you don't need (i.e. materials that are on hidden objects, HDRIs, rayswitch, etc.).

I'm looking through the script (.ms) now to see if there is a way to condition the mask generation loop on only selected objects or based on wire color instead of material.
« Last Edit: 2020-02-21, 01:47:54 by cjwidd »

2020-02-21, 08:51:48
Reply #13

Frood

  • Active Users
  • **
  • Posts: 1922
    • View Profile
    • Rakete GmbH
In your case, you are loading packed RGB masks - not mono masks - into the layered .EXR and then running the script on a single layer, i.e. the script does not loop through all layers, only the selected layer?

Those RGB masks or "packed" ones as you call them are just CMasking_Mask render elements from Corona with RGB mode activated - they are already in the EXR ("Automatically Add/Remove Render Elements from Render Dialog" ticked in the OpenEXR Configuration). I do not manually load anything into the document in the first place. The layers you can see in the screenshot are those written by Corona, it's just a random output of a Backburner job I opened in Photoshop.

But as stated, if it's a "mono" layer (R=G=B), "Layers to Channels" creates a single channel (in the example image, the standard beauty alpha is nothing else but a mono mask). And yes, it processes only selected layers, I don't want my beauty or lightmix layers to disappear :)


Good Luck



Never underestimate the power of a well placed level one spell.

2020-02-21, 09:06:24
Reply #14

cjwidd

  • Active Users
  • **
  • Posts: 1077
    • View Profile
    • Artstation
Yeah I just recorded an action to run the script on the selected layer and it works beautifully - thanks again for sharing it (!)