Page MenuHome

Curves: Visualize sculpt selection in overlay
ClosedPublic

Authored by Hans Goudey (HooglyBoogly) on Jun 16 2022, 9:49 PM.

Details

Summary

This patch adds visualization to the selection in curves sculpt mode.
Previously it was only possible to see the selection when it was connected
to a shader.

In order to obstruct the users vision as little as possible, the selected areas
of the curve are left as is, but a dark overlay is drawn over unselected areas.

To make it work, the overlay requests the selection attribute and then ensures
that the evaluation is complete for curves. Then it retrieves the evaluated
selection GPU texture and passes that to the shader. This reuses the existing
generic attribute extraction system because there currently wouldn't be any
benefits to dealing with selection separately, and because it avoids duplication
of the logic that extracts attributes from curves and evaluates them if necessary.


In the future we could tag specific attributes as dirty when editing in order to
only re-evaluate data as necessary. We may also end up using a separate system
for selection if the optimizations don't fit with the generic attributes, but my
thinking is that we should first optimize the generic process before doing specifics
for selection.

Diff Detail

Repository
rB Blender

Event Timeline

Hans Goudey (HooglyBoogly) requested review of this revision.Jun 16 2022, 9:49 PM
Hans Goudey (HooglyBoogly) planned changes to this revision.
Hans Goudey (HooglyBoogly) created this revision.
Clément Foucault (fclem) added inline comments.
source/blender/draw/engines/overlay/shaders/infos/overlay_sculpt_curves_info.hh
19

Use draw_hair. You do not need vertex_ins and draw_object_infos is only if you need object color which I assume don't need for sculpt selection.

A bit more progress, maybe

See some changes to make the drawing part working.

The position of the actual vertices aren't part of the vertex buffer, but of a texture. This might give you a jumping start.

source/blender/draw/engines/overlay/overlay_shader.c
800

should be sculpt_curves_selection

  • Changes from Jeroen (so it draws something)
Hans Goudey (HooglyBoogly) retitled this revision from Curves: Vizualize sculpt selection in overlay (WIP) to Curves: Vizualize sculpt selection in overlay.
Hans Goudey (HooglyBoogly) edited the summary of this revision. (Show Details)
  • Working drawing based on discussion with Clément on blender.chat
  • Add back optimization to avoid storing selection attributes when everything is selected
Hans Goudey (HooglyBoogly) edited the summary of this revision. (Show Details)
  • Use the generic attribute request system
  • Use more generic functions to request selection attribute and retrieve texture
source/blender/draw/engines/overlay/shaders/infos/overlay_sculpt_curves_info.hh
13

no need for a vertex input.

18

This is going to be written in a document at some point, but use out_color for color output, and _tx suffix for texture resources (i.e: selection_tx)

source/blender/draw/engines/overlay/shaders/overlay_sculpt_curves_selection_vert.glsl
7

do not put uniforms in shader code. this is a legacy practice. Declare all uniforms and resources in GPU_SHADER_CREATE_INFO(overlay_sculpt_curves_selection) . Here it is a sampler of type ImageType::FLOAT_BUFFER.

Great job Hans.

Bug report :) It is missing a redraw/flush/recalculate something ...

  • Go to sculpt mode
  • Paint some selection
  • Switch to object mode

The hair is still partially painted. It only goes fully back when I toggle edit mode twice.

  1. Selection Opacity overlay doesn't work when the overlays are disabled, however the property is not disabled when that happens:

  1. There is also a drawing refresh missing at the end of painting the selection.

This is a bit harder to explain. But EEVEE has a cheap AA (used during 3d orbit), and a more expensive one once the view settles. While painting the selection it is using the cheap one, but it never triggers the expensive one. But as soon as I press the MMB it then refreshes.

Hans Goudey (HooglyBoogly) marked 5 inline comments as done.Jun 29 2022, 4:54 PM
  • Gray out opacity option if overlays are disabled (turns out I accidentally committed the overlay panel in a cleanup commit earlier, oops!)
  • Address review comments
  • Switch to multiplication blending

I'm still not sure about the AA/sampling issue.

If the AA issue happens in other modes (like sculpt) I would ignore it.

About the AA issue: This fixes the problem: https://developer.blender.org/P3048

BTW 1: By the way, DRW_state_is_navigating() is checking for both RV3D_NAVIGATING and RV3D_PAINTING flags. It would be nicer if the function name was more accurate.

BTW 2: I wonder if we even need the cheap AA during paint select. But anyways.

Jeroen Bakker (jbakker) requested changes to this revision.Jul 5 2022, 2:23 PM
Jeroen Bakker (jbakker) added inline comments.
source/blender/draw/engines/overlay/overlay_sculpt_curves.cc
3

Should be 2022

76

Can we perform this before creating the sub group. The subgroup creation would already add a draw call what would then still draw, On AMD cards this could lead to drawing artifacts as all samplers must be bound, otherwise it can read from uninitialized memory.

We often load a dummy texture in this case.

90

This will draw on the linear buffer. Normally for overlays we select the overlay framebuffers this will apply the effect in sRGB space what is more what the user expects (perceptual color spaces)
Might need some tweak in the fragment shader as well.

This revision now requires changes to proceed.Jul 5 2022, 2:23 PM
Hans Goudey (HooglyBoogly) marked 2 inline comments as done.Jul 5 2022, 3:11 PM
Hans Goudey (HooglyBoogly) added inline comments.
source/blender/draw/engines/overlay/overlay_sculpt_curves.cc
76

I switched the order. It required using a GPUTexture ** because the texture isn't created until DRW_shgroup_curves_create_sub runs. But hopefully this still accomplishes what you're talking about.

90

Here I just copied the mesh sculpt mode overlay. Shouldn't they be consistent?
I'm not sure which other buffer to choose from DefaultFramebufferList. Do you mean overlay_fb?

Hans Goudey (HooglyBoogly) marked an inline comment as done.
  • Switch order of texture retrieval and shader group creation
source/blender/draw/engines/overlay/overlay_sculpt_curves.cc
67

Why would you split the request and the actual texture getter? You can make DRW_curves_request_attribute a static and not expose it.

90

Actually this problem is also present in the sculpt overlay which was duplicated here. I think we need to use fbl->overlay_in_front_fb / fbl->overlay_default_fb. The reason sculpt overlay did not use them is because it needed the color to be overlay color to be multiplied on top of the render. But here, in this case, since we only use grey scale, we can use black alpha blending on top of the overlay fb to make the selection visible.

Simplify functions for requesting attribute texture

Use alpha blending and different frame buffer

Hans Goudey (HooglyBoogly) marked 3 inline comments as done.Jul 5 2022, 3:47 PM
Hans Goudey (HooglyBoogly) retitled this revision from Curves: Vizualize sculpt selection in overlay to Curves: Visualize sculpt selection in overlay.Jul 6 2022, 2:59 PM
This revision is now accepted and ready to land.Jul 7 2022, 8:43 AM
This revision was automatically updated to reflect the committed changes.