Color Picker in texture mode sampling incorrect values (sample merged OFF, sampling from another object) #88300

Open
opened 2021-05-15 00:40:24 +02:00 by Jonas Meyer · 11 comments

System Information
Operating system: Windows-10-10.0.19041-SP0 64 Bits
Graphics card: GeForce RTX 3080/PCIe/SSE2 NVIDIA Corporation 4.5.0 NVIDIA 462.31

Blender Version
Broken: version: 2.92.0, branch: master, commit date: 2021-02-24 16:25, hash: 02948a2cab
Worked: ?

Short description of error
The color picker in "Texture Painting" mode seems to only sample the correct color when the look is set to Noneunder the ColorManagement->Look->"None" and if the Viewport Shading->RenderPass is set to DiffuseColor.
Otherwise, the color values are simply wrong, they are either too bright or too dark.
In the provided scene the issue is quite clear, but in more complex scenes with more complex lighting and post-processing the sampling becomes completely broken giving values that aren't even close to what is shown on screen.

Expected Behaviour
The way I would expect the color picker to work is that it either samples the color as I as a user see it on my viewport.
Or that it samples the source texture at the pixel I am sampling without any extra lighting applied to it. ( This should be easily toggleable behavior but that is more of a feature request )ColorPicker_WrongSampling.blend
Right now it seems to do neither.

Exact steps for others to reproduce the error

  • Open attached .blend file.
  • Select the black cube and enter Texture Paint Mode.

Sample the color from the other cube ( I recommend sampling the green since the meshes are close to each other making it easy to see the color difference ).

**System Information** Operating system: Windows-10-10.0.19041-SP0 64 Bits Graphics card: GeForce RTX 3080/PCIe/SSE2 NVIDIA Corporation 4.5.0 NVIDIA 462.31 **Blender Version** Broken: version: 2.92.0, branch: master, commit date: 2021-02-24 16:25, hash: `02948a2cab` Worked: ? **Short description of error** The color picker in "Texture Painting" mode seems to only sample the correct color when the look is set to **None**under the **ColorManagement->Look->"None"** and if the Viewport **Shading->RenderPass** is set to **DiffuseColor**. Otherwise, the color values are simply wrong, they are either too bright or too dark. *In the provided scene the issue is quite clear, but in more complex scenes with more complex lighting and post-processing the sampling becomes **completely** broken giving values that aren't even close to what is shown on screen.* **Expected Behaviour** The way I would expect the color picker to work is that it either samples the color as **I** as a user see it on my viewport. Or that it samples the source texture at the pixel I am sampling without any extra lighting applied to it. *( This should be easily toggleable behavior but that is more of a feature request )*[ColorPicker_WrongSampling.blend](https://archive.blender.org/developer/F10104107/ColorPicker_WrongSampling.blend) Right now it seems to do neither. **Exact steps for others to reproduce the error** - Open attached .blend file. - Select the black cube and enter Texture Paint Mode. # Sample the color from the other cube *( I recommend sampling the green since the meshes are close to each other making it easy to see the color difference )*.
Author

Added subscriber: @JJG

Added subscriber: @JJG
Author

Here is a video I recorded of the problem to show to some friends where you can see the color picker doing all sorts of nonsense. That was before I made the reproduction steps.
#86196 seems related in so far that its talking about sampling in general behaving strangely, not specific to the 3D texture painting.There also appears to be an issue with the color picker sampling textures linearly despite what interpolation method is actually being used, in the videos case the texture interpolation is set to "Closest" but its using "Linear" instead. Should I make another ticket for this?{F10104126}*There also doesn't appear to be a way to make the embed display smaller, sorry for that.//

Here is a video I recorded of the problem to show to some friends where you can see the color picker doing all sorts of nonsense. That was before I made the reproduction steps. [#86196](https:*developer.blender.org/T86196) seems related in so far that its talking about sampling in general behaving strangely, not specific to the 3D texture painting.*There also appears to be an issue with the color picker sampling textures linearly despite what interpolation method is actually being used, in the videos case the texture interpolation is set to "Closest" but its using "Linear" instead. Should I make another ticket for this?*{[F10104126](https://archive.blender.org/developer/F10104126/colorPicker_wonkiness.mp4)}*There also doesn't appear to be a way to make the embed display smaller, sorry for that.//
Member

Added subscriber: @lichtwerk

Added subscriber: @lichtwerk
Member

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

Changed status from 'Needs Triage' to: 'Confirmed'
Philipp Oeser self-assigned this 2021-05-20 10:02:30 +02:00
Member

I can sort of confirm.

But first of all, here is the scenario that actually works as intended:

  • use the {key S} Sample Color operator (not the eyedropper from the brush color), this operator has the Sample Merged option.
    • with the option of, shading information is discarded and only the texture value is sampled

However, this only seems to work correctly when sampling from the same object, when picking from another object, behavior seems to be as if the Sample Merged option is ON (meaning it will just sample the OpneGL pixel value -- including all shading on top).

Will check on the case where we are picking from another object than is currently being painted on.
But @JJG: could you confirm that Sample Color works correctly for you when sampling from the same object?

There also appears to be an issue with the color picker sampling textures linearly despite what interpolation method is actually being used, in the videos case the texture interpolation is set to "Closest" but its using "Linear" instead. Should I make another ticket for this?

Yes, please

I can sort of confirm. But first of all, here is the scenario that actually works as intended: - use the {key S} `Sample Color` operator (not the eyedropper from the brush color), this operator has the `Sample Merged` option. - with the option of, shading information is discarded and only the texture value is sampled However, this only seems to work correctly when sampling from the **same object**, when picking from another object, behavior seems to be as if the `Sample Merged` option is ON (meaning it will just sample the OpneGL pixel value -- including all shading on top). Will check on the case where we are picking **from another object** than is currently being painted on. But @JJG: could you confirm that Sample Color works correctly for you when sampling **from the same object**? > There also appears to be an issue with the color picker sampling textures linearly despite what interpolation method is actually being used, in the videos case the texture interpolation is set to "Closest" but its using "Linear" instead. Should I make another ticket for this? > Yes, please
Philipp Oeser changed title from Color Picker in texture mode sampling incorrect values to Color Picker in texture mode sampling incorrect values (sample merged OFF, sampling from another object) 2021-05-20 10:03:02 +02:00
Author

Added subscriber: @jonas-19

Added subscriber: @jonas-19
Author

But @jonas-19 Meyer (JJG): could you confirm that Sample Color works correctly for you when sampling from the same object?

Will do later in the evening today.

> But @jonas-19 Meyer (JJG): could you confirm that Sample Color works correctly for you when sampling from the same object? Will do later in the evening today.
Member

Added subscribers: @mano-wii, @ideasman42

Added subscribers: @mano-wii, @ideasman42
Member

So here is a bit of code that would enable picking colors directly from the textures of other objects.
Has rough edges though, not sure if this would really be the way to go:

P2128: T88300_snippet



diff --git a/source/blender/editors/sculpt_paint/paint_utils.c b/source/blender/editors/sculpt_paint/paint_utils.c
index 2484f382ed4..5f04c74f92e 100644
--- a/source/blender/editors/sculpt_paint/paint_utils.c
+++ b/source/blender/editors/sculpt_paint/paint_utils.c
@@ -478,26 +478,33 @@ void paint_sample_color(
 
   if (v3d && texpaint_proj) {
     /* first try getting a color directly from the mesh faces if possible */
-    ViewLayer *view_layer = CTX_data_view_layer(C);
-    Object *ob = OBACT(view_layer);
-    Object *ob_eval = DEG_get_evaluated_object(depsgraph, ob);
-    ImagePaintSettings *imapaint = &scene->toolsettings->imapaint;
-    bool use_material = (imapaint->mode == IMAGEPAINT_MODE_MATERIAL);
+    const int mval- [x] = {x, y};
+    Base *base = ED_view3d_give_base_under_cursor(C, mval);
+
+    if (base != NULL) {
+      Object *ob = base->object;
+      Object *ob_eval = DEG_get_evaluated_object(depsgraph, ob);
+
+      /* Cheat for picking from another than the active object
+       * imapaint_face_image() needs these initalized. */
+      BKE_texpaint_slots_refresh_object(scene, ob);
+
+      ImagePaintSettings *imapaint = &scene->toolsettings->imapaint;
+      bool use_material = (imapaint->mode == IMAGEPAINT_MODE_MATERIAL);
 
-    if (ob) {
       CustomData_MeshMasks cddata_masks = CD_MASK_BAREMESH;
       cddata_masks.pmask |= CD_MASK_ORIGINDEX;
       Mesh *me = (Mesh *)ob->data;
       Mesh *me_eval = mesh_get_eval_final(depsgraph, scene, ob_eval, &cddata_masks);
 
       ViewContext vc;
-      const int mval- [x] = {x, y};
       uint faceindex;
       uint totpoly = me->totpoly;
 
       if (CustomData_has_layer(&me_eval->ldata, CD_MLOOPUV)) {
         ED_view3d_viewcontext_init(C, &vc, depsgraph);
-
+        /* Cheat for picking from another than the active object. */
+        vc.obact = ob;
         view3d_operator_needs_opengl(C);
 
         if (imapaint_pick_face(&vc, mval, &faceindex, totpoly)) {
diff --git a/source/blender/editors/space_view3d/view3d_draw.c b/source/blender/editors/space_view3d/view3d_draw.c
index 0a89b7d0292..58e9a25db6e 100644
--- a/source/blender/editors/space_view3d/view3d_draw.c
+++ b/source/blender/editors/space_view3d/view3d_draw.c
@@ -2161,7 +2161,9 @@ static void validate_object_select_id(struct Depsgraph *depsgraph,
   else if ((obact_eval && (obact_eval->mode & OB_MODE_PARTICLE_EDIT)) && !XRAY_ENABLED(v3d)) {
     /* do nothing */
   }
-  else {
+  /* #88300: in case of sampling from another object, we dont want to return here
+   * DRW_select_buffer_context_create stuff below is still needed. */
+  else if (OBACT(view_layer) == obact){
     v3d->runtime.flag |= V3D_RUNTIME_DEPTHBUF_OVERRIDDEN;
     return;
   }

Will change this to TODO, current code was not really expecting this to work on objects other than the active.
(Of course, from the user perspective, this is totally unexpected)

Might be interesting to
CC @ideasman42
CC @mano-wii

So here is a bit of code that would enable picking colors directly from the textures of **other objects**. Has rough edges though, not sure if this would really be the way to go: [P2128: T88300_snippet](https://archive.blender.org/developer/P2128.txt) ``` diff --git a/source/blender/editors/sculpt_paint/paint_utils.c b/source/blender/editors/sculpt_paint/paint_utils.c index 2484f382ed4..5f04c74f92e 100644 --- a/source/blender/editors/sculpt_paint/paint_utils.c +++ b/source/blender/editors/sculpt_paint/paint_utils.c @@ -478,26 +478,33 @@ void paint_sample_color( if (v3d && texpaint_proj) { /* first try getting a color directly from the mesh faces if possible */ - ViewLayer *view_layer = CTX_data_view_layer(C); - Object *ob = OBACT(view_layer); - Object *ob_eval = DEG_get_evaluated_object(depsgraph, ob); - ImagePaintSettings *imapaint = &scene->toolsettings->imapaint; - bool use_material = (imapaint->mode == IMAGEPAINT_MODE_MATERIAL); + const int mval- [x] = {x, y}; + Base *base = ED_view3d_give_base_under_cursor(C, mval); + + if (base != NULL) { + Object *ob = base->object; + Object *ob_eval = DEG_get_evaluated_object(depsgraph, ob); + + /* Cheat for picking from another than the active object + * imapaint_face_image() needs these initalized. */ + BKE_texpaint_slots_refresh_object(scene, ob); + + ImagePaintSettings *imapaint = &scene->toolsettings->imapaint; + bool use_material = (imapaint->mode == IMAGEPAINT_MODE_MATERIAL); - if (ob) { CustomData_MeshMasks cddata_masks = CD_MASK_BAREMESH; cddata_masks.pmask |= CD_MASK_ORIGINDEX; Mesh *me = (Mesh *)ob->data; Mesh *me_eval = mesh_get_eval_final(depsgraph, scene, ob_eval, &cddata_masks); ViewContext vc; - const int mval- [x] = {x, y}; uint faceindex; uint totpoly = me->totpoly; if (CustomData_has_layer(&me_eval->ldata, CD_MLOOPUV)) { ED_view3d_viewcontext_init(C, &vc, depsgraph); - + /* Cheat for picking from another than the active object. */ + vc.obact = ob; view3d_operator_needs_opengl(C); if (imapaint_pick_face(&vc, mval, &faceindex, totpoly)) { diff --git a/source/blender/editors/space_view3d/view3d_draw.c b/source/blender/editors/space_view3d/view3d_draw.c index 0a89b7d0292..58e9a25db6e 100644 --- a/source/blender/editors/space_view3d/view3d_draw.c +++ b/source/blender/editors/space_view3d/view3d_draw.c @@ -2161,7 +2161,9 @@ static void validate_object_select_id(struct Depsgraph *depsgraph, else if ((obact_eval && (obact_eval->mode & OB_MODE_PARTICLE_EDIT)) && !XRAY_ENABLED(v3d)) { /* do nothing */ } - else { + /* #88300: in case of sampling from another object, we dont want to return here + * DRW_select_buffer_context_create stuff below is still needed. */ + else if (OBACT(view_layer) == obact){ v3d->runtime.flag |= V3D_RUNTIME_DEPTHBUF_OVERRIDDEN; return; } ``` Will change this to TODO, current code was not really expecting this to work on objects other than the active. (Of course, from the user perspective, this is totally unexpected) Might be interesting to CC @ideasman42 CC @mano-wii
Author

@lichtwerk I can confirm that the sampling works as long as it is the same object but gives incorrect values when trying to sample another object.

@lichtwerk I can confirm that the sampling works as long as it is the same object but gives incorrect values when trying to sample another object.
Philipp Oeser removed their assignment 2021-06-02 10:48:42 +02:00

Added subscriber: @KennethThomas

Added subscriber: @KennethThomas
Julien Kaspar added this to the Sculpt, Paint & Texture project 2023-02-08 10:48:53 +01:00
Philipp Oeser removed the
Interest
Sculpt, Paint & Texture
label 2023-02-10 09:11:50 +01:00
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 Assignees
3 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#88300
No description provided.