Compositor: Fallback to a black color for invalid outputs #118340

Merged
Omar Emara merged 3 commits from OmarEmaraDev/blender:fix-empty-buffer-case into main 2024-02-16 15:33:10 +01:00
Member

Currently, some compositor operations produce en empty output buffer by
specifying a COM_AREA_NONE canvas to indicate an invalid output, for
instance, when the Mask operation references an invalid mask. The
intention is that this buffer would signal that a fallback value should
fill the canvas of consumer operations.

The aforementioned behavior is currently implemented in a rather hacky
way, where it is implemented using the Translate operation as part of
canvas conversion in COM_convert_canvas, where the operation would clear
the entire buffer with zeros since out of bounds checking would always
take the out of bound case due to the empty buffer.

This behavior is problematic because we can't control the fallback
value, which would ideally be an opaque black color. Moreover, since
implicit type conversion happen before canvas conversion by design,
value typed buffers would eventually become transparent, which is rather
unexpected to the end user since float/value outputs can't have
transparency.

This is not a good design or implementation, but a redesign will be too
complex for now. So to fix this, we workaround it by handling the empty
buffer case explicitly in the Translate operation and fill the output
using a fallback black color, which works for both value and color typed
buffers, since this would also be the output of the value to color
implicit conversion.

Currently, some compositor operations produce en empty output buffer by specifying a COM_AREA_NONE canvas to indicate an invalid output, for instance, when the Mask operation references an invalid mask. The intention is that this buffer would signal that a fallback value should fill the canvas of consumer operations. The aforementioned behavior is currently implemented in a rather hacky way, where it is implemented using the Translate operation as part of canvas conversion in COM_convert_canvas, where the operation would clear the entire buffer with zeros since out of bounds checking would always take the out of bound case due to the empty buffer. This behavior is problematic because we can't control the fallback value, which would ideally be an opaque black color. Moreover, since implicit type conversion happen before canvas conversion by design, value typed buffers would eventually become transparent, which is rather unexpected to the end user since float/value outputs can't have transparency. This is not a good design or implementation, but a redesign will be too complex for now. So to fix this, we workaround it by handling the empty buffer case explicitly in the Translate operation and fill the output using a fallback black color, which works for both value and color typed buffers, since this would also be the output of the value to color implicit conversion.
Omar Emara added the
Interest
Compositing
Module
VFX & Video
labels 2024-02-15 19:02:39 +01:00
Omar Emara added 1 commit 2024-02-15 19:02:48 +01:00
53c8003b2a Compositor: Fallback to a black color for invalid outputs
Currently, some compositor operations produce en empty output buffer by
specifying a COM_AREA_NONE canvas to indicate an invalid output, for
instance, when the Mask operation references an invalid mask. The
intention is that this buffer would signal that a fallback value should
fill the canvas of consumer operations.

The aforementioned behavior is currently implemented in a rather hacky
way, where it is implemented using the Translate operation as part of
canvas conversion in COM_convert_canvas, where the operation would clear
the entire buffer with zeros since out of bounds checking would always
take the out of bound case due to the empty buffer.

This behavior is problematic because we can't control the fallback
value, which would ideally be an opaque black color. Moreover, since
implicit type conversion happen before canvas conversion by design,
value typed buffers would eventually become transparent, which is rather
unexpected to the end user since float/value outputs can't have
transparency.

This is not a good design or implementation, but a redesign will be too
complex for now. So to fix this, we workaround it by handling the empty
buffer case explicitly in the Translate operation and fill the output
using a fallback black color, which works for both value and color typed
buffers, since this would also be the output of the value to color
implicit conversion.
Omar Emara requested review from Sergey Sharybin 2024-02-15 19:03:07 +01:00

I am not really sure what is the user-level setup this change has affect on. Was kind of expecting that Mask Node without mask ID specified will trigger the changed behavior, but it does not seem to.

It is also a bit strange its only done for translate node. Wouldn't it also needed for scale and toration?

I am not really sure what is the user-level setup this change has affect on. Was kind of expecting that Mask Node without mask ID specified will trigger the changed behavior, but it does not seem to. It is also a bit strange its only done for translate node. Wouldn't it also needed for scale and toration?
Author
Member

@Sergey A Mask node with no mask selected should reproduce the changed behavior indeed, it should produce black instead of a transparent color. I will double check.

Rotation needn't be handled, because rotation is not used in canvas conversion. Scaling could be handled, but I couldn't find a code path where it was necessary to handle it.

@Sergey A Mask node with no mask selected should reproduce the changed behavior indeed, it should produce black instead of a transparent color. I will double check. Rotation needn't be handled, because rotation is not used in canvas conversion. Scaling could be handled, but I couldn't find a code path where it was necessary to handle it.
Author
Member

@Sergey There is also a test case for that in the tests. The Input Mask one.

@Sergey There is also a test case for that in the tests. The Input Mask one.

@OmarEmaraDev Ah, i finally see difference. The change only affects F12 render, but not the backdrop (and i was looking at the changes in backdrop all this time). Do you also have such difference in behavior backdrop vs. F12 render result?

@OmarEmaraDev Ah, i finally see difference. The change only affects F12 render, but not the backdrop (and i was looking at the changes in backdrop all this time). Do you also have such difference in behavior backdrop vs. F12 render result?
Author
Member

@Sergey Ah, I also get that difference. But it seems to be an issue with the viewer operation, probably because it doesn't have a preferred canvas. So that's another thing to look at.

@Sergey Ah, I also get that difference. But it seems to be an issue with the viewer operation, probably because it doesn't have a preferred canvas. So that's another thing to look at.
Sergey Sharybin approved these changes 2024-02-16 14:47:12 +01:00
Sergey Sharybin left a comment
Owner

Good, now things are clarified and we're all aligned. Lets start with fixing the F12 behavior!

There is a typo in comment, would be nice to fix it, but no need to wait for an extra review.

Good, now things are clarified and we're all aligned. Lets start with fixing the F12 behavior! There is a typo in comment, would be nice to fix it, but no need to wait for an extra review.
@ -117,6 +117,18 @@ void TranslateOperation::update_memory_buffer_partial(MemoryBuffer *output,
return;
}
/* Some compositor operations produce en empty output buffer by specifying a COM_AREA_NONE canvas

en empty -> an empty

`en empty` -> `an empty`
OmarEmaraDev marked this conversation as resolved
Omar Emara added 2 commits 2024-02-16 15:31:50 +01:00
Omar Emara merged commit 0906201a4c into main 2024-02-16 15:33:10 +01:00
Omar Emara deleted branch fix-empty-buffer-case 2024-02-16 15:33:12 +01:00
Sign in to join this conversation.
No reviewers
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset Browser
Interest
Asset Browser Project Overview
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
EEVEE & Viewport
Interest
Freestyle
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
ID Management
Interest
Images & Movies
Interest
Import Export
Interest
Line Art
Interest
Masking
Interest
Metal
Interest
Modeling
Interest
Modifiers
Interest
Motion Tracking
Interest
Nodes & Physics
Interest
OpenGL
Interest
Overlay
Interest
Overrides
Interest
Performance
Interest
Physics
Interest
Pipeline, Assets & IO
Interest
Platforms, Builds & Tests
Interest
Python API
Interest
Render & Cycles
Interest
Render Pipeline
Interest
Sculpt, Paint & Texture
Interest
Text Editor
Interest
Translations
Interest
Triaging
Interest
Undo
Interest
USD
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Interest
Video Sequencer
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Blender 2.8 Project
Legacy
Milestone 1: Basic, Local Asset Browser
Legacy
OpenGL Error
Meta
Good First Issue
Meta
Papercut
Meta
Retrospective
Meta
Security
Module
Animation & Rigging
Module
Core
Module
Development Management
Module
EEVEE & Viewport
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline, Assets & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Priority
High
Priority
Low
Priority
Normal
Priority
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No project
No Assignees
2 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender#118340
No description provided.