Page MenuHome

Add mask blending factor to mask editor
ClosedPublic

Authored by Simon Lenz (Amudtogal) on Nov 19 2021, 10:54 AM.

Details

Summary

This adds a new parameter to the "Combined" overlay mode of the mask editor.
The "blending factor" allows users to blend the mask exterior with the original footage to visualise the content of the mask in a more intuitive way.
The "Alpha" overlay is unaffected by this change.

The existing "Combined" overlay is used like before (covering everything outside the mask in black), but can be blended with the slider in the mask overlay to look at the exterior.

Click me, I am a GIF:

Coding details
In the draw function of masks several adjustments were made:

  • the "Combined" overlay mode now uses the GPU_BLEND_ALPHA method, and the blending factor as alpha value
  • for this to work, the mask has to be inverted, which is currently done in a for loop over the drawing buffer (Reviewers: this is definitely not the most performant/nice way to do this, but I could not find a utility function/macro to do this... I was thinking of adding an inversion flag to the rasterisation, or maybe use some GPU computation to do this simple calculation. Any suggestions?)

This is part of an effort to make mask editing more intuitive & easy to use: https://developer.blender.org/T93097

Diff Detail

Repository
rB Blender

Event Timeline

Simon Lenz (Amudtogal) requested review of this revision.Nov 19 2021, 10:54 AM
Simon Lenz (Amudtogal) created this revision.

I fail to keep the python files consistent. Apologies!

  • Restore original formatting of bl_ui python

Thanks for moving this to a dedicated patch!

Think it is useful feature to have, but I share the same question as you: how to setup blending in a way that we don't need a manual CPU-side inversion. Something I hope @Jeroen Bakker (jbakker) will help us with :)

release/scripts/startup/bl_ui/properties_mask_common.py
242

Are the changes above this one caused by some auto-formatter? If those are not intentional, please exclude them from the patch.

242

Nevermind, you did fix it already.

I am not able to get the same results as in the animated gif. Might be that I am using the image editor for masking and its masking is implemented in the overlay engine. See overlay_edit_uv here it would be easier to implement as there is a uses a custom fragment shader (edit_uv_image_mask_frag.glsl). Here the blending logic should be added and is fairly straight forward as you have access to the mask. and can calculate the invert mask in the fragment as well.

The plan is eventually to migrate the image drawing of the movie clip editor to the overlay engine. But that is still an over issue T82153: Use draw manager for clip editor drawing. If that is done there is no need to have store the invert of the mask. But I don't think that we should add this as a prerequisite of this patch.

So the question still remains how can we setup a blend mode to do an inversion of the color/alpha.
Possible short term solutions:

  • Add an own GPU_BLEND_INVERT_ALPHA blending mode. Not really in favor of adding a custom mode for this case. Changing blend modes requires a flush of the GPU pipeline.
  • We could use GPU_BLEND_CUSTOM that requires a custom fragment shader to output the madd (multiply/add) components of the blend. Doable but makes the code less readable.
  • GPU_SHADER_2D_IMAGE_SHUFFLE_COLOR add an additive part to the shader. (invert is the same as (*-1 + 1)

as the shader is only used in two places I would prefer the last option. gpu_shader_image_shuffle_color_frag.glsl shuffle uniform would also get an shuffleAdd vec4 uniform.
When setting up the shader we should set shuffle to (-1, 0, 0, 0) and set the shuffleAdd to (1.0, 1.0, 1.0, 1.0).
If I am not mistaken this would solve the issue.

Note that the shader also needs to be adjusted in draw_filled_lasso. Shader states can be shared so it needs to be set everywhere where the shader is used.

If you need any assistance I will be online until 16h CEST.

  • Merge branch 'master' into mask_blend_factor
  • Add shuffleAdd to shader
  • Remove raw inversion loop in favour of GLSL
  • Remove addShuffle from shader

This fixed the remaining issue with the "brute-force" inversion of the mask.

One last thing needs to be done: I want to add a default value for the blending factor to the default VFX screen.

In a separate patch (https://developer.blender.org/D13367) I have added default DNA initialisation for the SpaceClip struct (which I will patch with a default of 1.0 as well),
but how can I update the Blender defaults in the shipped "example" scenes?

Catching up with the changes since taking time off..

Is the drawing part is aligned with what Jeroen was proposing?

but how can I update the Blender defaults in the shipped "example" scenes?

Think you'd need to edit release/scripts/startup/bl_app_templates_system/VFX/startup.blend.

I don't see any changes to the overlay engine so would expect that the image editor/compositor doesn't have this feature implemented yet.
If there needs some back and forth needed for that I am happy to help out.

I just recompiled this against master, still working.

So what do you want me to do?
Adding the same blending factor to the image editor?

I am not entirely sure how to edit the startup blend in a git-able way. Is that something we do last, just before committing?

Are you sure you only want to change startup file settings? What about other .blend files containing open mask editors, they should have the value initialized properly too. This can be done in versioning_300.c.
(And startup files can be modified programmatically in versioning_defaults.c, including the application template startup files.)

Julian Eisel (Severin) requested changes to this revision.Jan 11 2022, 7:05 PM

Requesting changes since this is missing versioning.

This revision now requires changes to proceed.Jan 11 2022, 7:05 PM
  • Merge branch 'master' into mask_blend_factor
  • Masking: add mask blend factor to versioning
  • merge master
  • Masking: add blend factor to DNA defaults

It's been a long time (sorry), but here is an update. have added defaults for the blend factor to:

  • DNA_space_defaults.h
  • versioning_300.c: I added it under the most recent version bump (is that alright?)
  • versioning_defaults.c: added to the blo_update_defaults_screen(), are there other parts that it needs to be added to?

I chose a value of 0.7, because the effect becomes visible in the combined display right away, once a mask is added.

On top of that, I have merged the current master (which required some small changes with renaming and removing the const for the blend factor), I hope I haven't messed up the merge 😄

  • Masking: Remove duplicate default in versioning_300

Some minor feedback on the code.

But the versioning would be nice to hear from @Sebastian Koenig (sebastian_k): would it make more sense in the versioning code to use the new default blending factor of 0.7, or would it make more sense to set the factor to 1, preserving the interface look exactly the same as it was when the file was created?

source/blender/editors/mask/mask_draw.c
725

It is not correct to call it rad now.

source/blender/gpu/shaders/gpu_shader_image_shuffle_color_frag.glsl
8 ↗(On Diff #48615)

Is this used somewhere?

Talked to Sebastian. Lets use factor 0.7 for the new files and 1.0 for the old files.

The rest I can not really review as it is drawing. Would be cool if Jeroen reviews the drawing part.

Simon Lenz (Amudtogal) marked an inline comment as done.

Hi @Sergey Sharybin (sergey) & @Sebastian Koenig (sebastian_k) ,
thanks for checking in!

I have updated the diff with the new default values.

Looking forward to see this happen 😄

Changed:

  • Change default blend factor for old files to 1.0
  • Remove obsolete shader bit
  • Rename mask buffer color variable
Simon Lenz (Amudtogal) marked 3 inline comments as done.Apr 10 2022, 9:54 PM

Thanks for the updates! Getting close, at least from my side!

source/blender/blenloader/intern/versioning_300.c
2664

This needs to be inside of the Versioning code until next subversion bump goes here. block below., Otherwise the files which are saved with the current master branch will not be properly do-versioned.

source/blender/blenloader/intern/versioning_defaults.c
187

Use f suffix to indicate single floating point precision, avoiding double floating point precision downcast (is probably harmless here due to compiler being smart enough, but warning could still be generated. Also good practice to be explicit in the precision anyway :).

source/blender/makesdna/DNA_space_defaults.h
21

Same as above.

source/blender/makesdna/DNA_space_types.h
735–737

Keep padding at the end.

source/blender/makesrna/intern/rna_space.c
3500

Don't omit decimal digits and be explicit w.r.t single floating point precision.

Wait. Think there is no way to properly do-version in this case without subversion bump.

So would need to set subverison to 13 (BLENDER_FILE_SUBVERSION in BKE_blender_version.h) and put code in the if (!MAIN_VERSION_ATLEAST(bmain, 302, 13)) {.

  • Rebase on top of latest master branch
  • Address own inlined comments

@Julian Eisel (Severin) Is there any outstanding concerns from yuor side?

This revision is now accepted and ready to land.Jun 16 2022, 7:50 PM