Data Transfer modifier works inconsistently when dealing with Vertex Color Alpha #81914

Closed
opened 2020-10-21 11:10:09 +02:00 by Teemu · 14 comments

System Information
Operating system: Windows-10-10.0.18362-SP0 64 Bits
Graphics card: GeForce GTX 1060 6GB/PCIe/SSE2 NVIDIA Corporation 4.5.0 NVIDIA 456.71

Blender Version
Broken: version: 2.90.1, branch: master, commit date: 2020-09-23 06:43, hash: 3e85bb34d0
Worked: -

Short description of error
When using DataTransfer modifier to transfer vertex colors from object to another, vertex color alpha interferes with color transfer. Vertex color alpha seems to work as a mask which is not expected.

Exact steps for others to reproduce the error

image.png (See attached blend file for ready-made setup)

  1. Create a cube. Give it a vertex color layer.
  2. Create another cube or plane. Give it fully red, blue or green coloring and erase some parts of its vertex color alpha.
  3. Add Data transfer modifier to the first cube. Copy vertex colors from the other object. Only 'Above' and 'Below threshold' Mix mode settings seems to fully transfer RGB without alpha affecting the transfer.
  4. Create material for the cube that has copied values. Create emissive shader and attach vertex color input node into it.
  5. Check with different mix modes and see how result varies.
  6. Optionally: Apply data transfer and inspect vertex colors. Alpha causes issue with RGB channels.

DataTransfer_Vertex-Color-Alpha.blend

**System Information** Operating system: Windows-10-10.0.18362-SP0 64 Bits Graphics card: GeForce GTX 1060 6GB/PCIe/SSE2 NVIDIA Corporation 4.5.0 NVIDIA 456.71 **Blender Version** Broken: version: 2.90.1, branch: master, commit date: 2020-09-23 06:43, hash: `3e85bb34d0` Worked: - **Short description of error** When using DataTransfer modifier to transfer vertex colors from object to another, vertex color alpha interferes with color transfer. Vertex color alpha seems to work as a mask which is not expected. **Exact steps for others to reproduce the error** ![image.png](https://archive.blender.org/developer/F9027011/image.png) (See attached blend file for ready-made setup) 1. Create a cube. Give it a vertex color layer. 2. Create another cube or plane. Give it fully red, blue or green coloring and erase some parts of its vertex color alpha. 3. Add Data transfer modifier to the first cube. Copy vertex colors from the other object. Only 'Above' and 'Below threshold' Mix mode settings seems to fully transfer RGB without alpha affecting the transfer. 5. Create material for the cube that has copied values. Create emissive shader and attach vertex color input node into it. 6. Check with different mix modes and see how result varies. 7. Optionally: Apply data transfer and inspect vertex colors. Alpha causes issue with RGB channels. [DataTransfer_Vertex-Color-Alpha.blend](https://archive.blender.org/developer/F9026996/DataTransfer_Vertex-Color-Alpha.blend)
Author

Added subscriber: @TMug

Added subscriber: @TMug

#81996 was marked as duplicate of this issue

#81996 was marked as duplicate of this issue

Added subscriber: @mano-wii

Added subscriber: @mano-wii

Changed status from 'Needs Triage' to: 'Confirmed'

Changed status from 'Needs Triage' to: 'Confirmed'

I can confirm.
This occurs in older versions like 2.79 as well.
Apparently the alpha value replaces the original color with white.
I don't know why that happens, it seems to be a bug.

I can confirm. This occurs in older versions like 2.79 as well. Apparently the alpha value replaces the original color with white. I don't know why that happens, it seems to be a bug.
Robert Guetzkow changed title from Data Tranfer works inconsistently when dealing with Vertex Color Alpha to Data Transfer modifier works inconsistently when dealing with Vertex Color Alpha 2020-10-23 12:33:19 +02:00
Member

Added subscribers: @mont29, @brecht, @lichtwerk

Added subscribers: @mont29, @brecht, @lichtwerk
Member

Apparently the alpha value replaces the original color with white.

White is the original vertex color on the destination object - which is not being replaced by red because the source layer has alpha = 0 there.

I don't know why that happens, it seems to be a bug.

This is because modes other than Above Threshold and Below Threshold do real Mixing (btw. I guess it would be good to gray out the Mix factor for the threshold ones).
Mixing is done premultiplied, see layerCopyValue_mloopcol / blend_color_interpolate_byte and the comment in blend_color_interpolate_byte:

  /* do color interpolation, but in premultiplied space so that RGB colors
   * from zero alpha regions have no influence */

Doing color interpolation premultiplied is probably usually the right thing to do (it might be different in the context of DataTransfer modifier?), not sure this is a bug, @mont29 or @brecht might know?

> Apparently the alpha value replaces the original color with white. White is the original vertex color on the destination object - which is not being replaced by red because the source layer has alpha = 0 there. > I don't know why that happens, it seems to be a bug. This is because modes other than `Above Threshold` and `Below Threshold` do real Mixing (btw. I guess it would be good to gray out the Mix factor for the threshold ones). Mixing is done premultiplied, see `layerCopyValue_mloopcol` / `blend_color_interpolate_byte` and the comment in blend_color_interpolate_byte: ``` /* do color interpolation, but in premultiplied space so that RGB colors * from zero alpha regions have no influence */ ``` Doing color interpolation premultiplied is probably usually the right thing to do (it might be different in the context of DataTransfer modifier?), not sure this is a bug, @mont29 or @brecht might know?
Member

Added subscriber: @FrankieHobbins

Added subscriber: @FrankieHobbins

To me this looks like what happens when you don't interpolate premultiplied. So I would check if the code is calling this function and that the function is working correctly.

Also, layerCopyValue_mloopcol copying alpha from m1 to m2 rather than using the interpolated alpha is wrong, though I'm not sure that would cause this issue.

To me this looks like what happens when you don't interpolate premultiplied. So I would check if the code is calling this function and that the function is working correctly. Also, layerCopyValue_mloopcol copying alpha from m1 to m2 rather than using the interpolated alpha is wrong, though I'm not sure that would cause this issue.
Member

In #81914#1040197, @brecht wrote:
To me this looks like what happens when you don't interpolate premultiplied. So I would check if the code is calling this function and that the function is working correctly.

Also, layerCopyValue_mloopcol copying alpha from m1 to m2 rather than using the interpolated alpha is wrong, though I'm not sure that would cause this issue.

Code is called, and I think it does what it advertises: it takes straight input, premultiplies colors with the alpha internally before blending, so you get no color change in the target if the source has another color (but no alpha there).
This is the right thing to do, no? At least this is how layer blending in Gimp etc works afaict.
I think the reason this actually looks "off" in this file is that interpolation of alpha in the viewport on this lowpoly is just not "enough".
It already looks a lot better if you subdivide a bit:
DataTransfer_Vertex-Color-Alpha_subdivided.blend

However, I think there is also something wrong with blend_color_interpolate_byte: if the combined alpha (after applying the mix factor) is zero, it would just copy the whole color, but alpha should be zero here?
P1730: T81914_snippet_one



diff --git a/source/blender/blenlib/intern/math_color_blend_inline.c b/source/blender/blenlib/intern/math_color_blend_inline.c
index eb82bb81a89..7ad4f0d9585 100644
--- a/source/blender/blenlib/intern/math_color_blend_inline.c
+++ b/source/blender/blenlib/intern/math_color_blend_inline.c
@@ -606,6 +606,7 @@ MINLINE void blend_color_interpolate_byte(uchar dst[4],
   }
   else {
     copy_v4_v4_uchar(dst, src1);
+    dst- [x] = 0;
   }
 }
 

If that is corrected (otherwise you get popping if a mix factor of one is used), you are right, interpolated alpha should be used:
P1731: T81914_snippet_two



diff --git a/source/blender/blenkernel/intern/customdata.c b/source/blender/blenkernel/intern/customdata.c
index 466a0115a9d..8b903b98173 100644
--- a/source/blender/blenkernel/intern/customdata.c
+++ b/source/blender/blenkernel/intern/customdata.c
@@ -751,6 +751,7 @@ static void layerCopyValue_mloopcol(const void *source,
     m2->r = m1->r;
     m2->g = m1->g;
     m2->b = m1->b;
+    m2->a = m1->a;
   }
   else { /* Modes that support 'real' mix factor. */
     unsigned char src- [x] = {m1->r, m1->g, m1->b, m1->a};
@@ -776,8 +777,8 @@ static void layerCopyValue_mloopcol(const void *source,
     m2->r = (char)dst[0];
     m2->g = (char)dst[1];
     m2->b = (char)dst[2];
+    m2->a = (char)dst[3];
   }
-  m2->a = m1->a;
 }
 
 static bool layerEqual_mloopcol(const void *data1, const void *data2)
diff --git a/source/blender/blenlib/intern/math_color_blend_inline.c b/source/blender/blenlib/intern/math_color_blend_inline.c
index eb82bb81a89..7ad4f0d9585 100644
--- a/source/blender/blenlib/intern/math_color_blend_inline.c
+++ b/source/blender/blenlib/intern/math_color_blend_inline.c
@@ -606,6 +606,7 @@ MINLINE void blend_color_interpolate_byte(uchar dst[4],
   }
   else {
     copy_v4_v4_uchar(dst, src1);
+    dst- [x] = 0;
   }
 }
 
> In #81914#1040197, @brecht wrote: > To me this looks like what happens when you don't interpolate premultiplied. So I would check if the code is calling this function and that the function is working correctly. > > Also, layerCopyValue_mloopcol copying alpha from m1 to m2 rather than using the interpolated alpha is wrong, though I'm not sure that would cause this issue. Code is called, and I think it does what it advertises: it takes straight input, premultiplies colors with the alpha internally before blending, so you get no color change in the target if the source has another color (but no alpha there). This is the right thing to do, no? At least this is how layer blending in Gimp etc works afaict. I think the reason this actually looks "off" in this file is that interpolation of alpha in the viewport on this lowpoly is just not "enough". It already looks a lot better if you subdivide a bit: [DataTransfer_Vertex-Color-Alpha_subdivided.blend](https://archive.blender.org/developer/F9052941/DataTransfer_Vertex-Color-Alpha_subdivided.blend) However, I think there is also something wrong with `blend_color_interpolate_byte`: if the combined alpha (after applying the mix factor) is zero, it would just copy the whole color, but alpha should be zero here? [P1730: T81914_snippet_one](https://archive.blender.org/developer/P1730.txt) ``` diff --git a/source/blender/blenlib/intern/math_color_blend_inline.c b/source/blender/blenlib/intern/math_color_blend_inline.c index eb82bb81a89..7ad4f0d9585 100644 --- a/source/blender/blenlib/intern/math_color_blend_inline.c +++ b/source/blender/blenlib/intern/math_color_blend_inline.c @@ -606,6 +606,7 @@ MINLINE void blend_color_interpolate_byte(uchar dst[4], } else { copy_v4_v4_uchar(dst, src1); + dst- [x] = 0; } } ``` If that is corrected (otherwise you get popping if a mix factor of one is used), you are right, interpolated alpha should be used: [P1731: T81914_snippet_two](https://archive.blender.org/developer/P1731.txt) ``` diff --git a/source/blender/blenkernel/intern/customdata.c b/source/blender/blenkernel/intern/customdata.c index 466a0115a9d..8b903b98173 100644 --- a/source/blender/blenkernel/intern/customdata.c +++ b/source/blender/blenkernel/intern/customdata.c @@ -751,6 +751,7 @@ static void layerCopyValue_mloopcol(const void *source, m2->r = m1->r; m2->g = m1->g; m2->b = m1->b; + m2->a = m1->a; } else { /* Modes that support 'real' mix factor. */ unsigned char src- [x] = {m1->r, m1->g, m1->b, m1->a}; @@ -776,8 +777,8 @@ static void layerCopyValue_mloopcol(const void *source, m2->r = (char)dst[0]; m2->g = (char)dst[1]; m2->b = (char)dst[2]; + m2->a = (char)dst[3]; } - m2->a = m1->a; } static bool layerEqual_mloopcol(const void *data1, const void *data2) diff --git a/source/blender/blenlib/intern/math_color_blend_inline.c b/source/blender/blenlib/intern/math_color_blend_inline.c index eb82bb81a89..7ad4f0d9585 100644 --- a/source/blender/blenlib/intern/math_color_blend_inline.c +++ b/source/blender/blenlib/intern/math_color_blend_inline.c @@ -606,6 +606,7 @@ MINLINE void blend_color_interpolate_byte(uchar dst[4], } else { copy_v4_v4_uchar(dst, src1); + dst- [x] = 0; } } ```

This issue was referenced by 6a5d2f4ea2

This issue was referenced by 6a5d2f4ea2261528ae9d15c66852635b05743d97

This issue was referenced by 3fc97727df

This issue was referenced by 3fc97727df6d09636072ca884ab90cb3d9bca6f6
Member

Changed status from 'Confirmed' to: 'Resolved'

Changed status from 'Confirmed' to: 'Resolved'
Philipp Oeser self-assigned this 2020-11-04 12:43:41 +01:00
Member

Since 6a5d2f4ea2 and 3fc97727df have been committed, I think the alpha handling is now actually correct.

For the viewport interpolation being "off" on lowres [highres works better - see my example file above], I think this deserves to be a separate report.

Will close this one (feel free to comment again though if issues persist - we can always reopen in that case)

Since 6a5d2f4ea2 and 3fc97727df have been committed, I think the alpha handling is now actually correct. For the viewport interpolation being "off" on lowres [highres works better - see my example file above], I think this deserves to be a separate report. Will close this one (feel free to comment again though if issues persist - we can always reopen in that case)
Sign in to join this conversation.
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
5 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#81914
No description provided.