Skip to content

Feature highlight object - #706

Open
PILIPALA030 wants to merge 7 commits into
Snapmaker:feature_object_highlightfrom
PILIPALA030:feature_highlight_object
Open

Feature highlight object#706
PILIPALA030 wants to merge 7 commits into
Snapmaker:feature_object_highlightfrom
PILIPALA030:feature_highlight_object

Conversation

@PILIPALA030

Copy link
Copy Markdown
Collaborator

Description

Screenshots/Recordings/Graphs

Tests

…mask and stencil fallback

Replace the per-GLVolume depth-texture outline with a unified screen-space
approach that renders all selected volumes into a shared multisampled mask,
then composites a coverage-aware fill and a 2 px hard outline over the
finished scene without Gaussian blur.

Key changes:

- Add 4 new fragment shaders (110/140): selection_mask.fs and
  selection_composite.fs. The mask shader outputs flat coverage with
  alpha=1.0; the composite shader reads the resolved mask texture and
  emits anti-aliased fill (coverage × fillAlpha) plus a binary 2 px
  circular-neighbourhood outline to the default framebuffer.

- GLCanvas3D: introduce SelectionHighlightResources (dual FBO:
  4× MSAA RGBA8 color renderbuffer + RGBA8 resolve texture, no
  depth/stencil) and ESelectionHighlightMode (Disabled /
  UnifiedFramebuffer / StencilFallback).

- Implement Save/Restore helpers for the Mask, Composite, and Stencil
  passes, each capturing and restoring the full set of persistent GL
  state affected by that pass. Both ARB and EXT framebuffer paths are
  supported.

- EnsureSelectionHighlightResources(): lazily creates cross-API FBO
  resources and re-creates them only on canvas resize. Validates
  GL_RENDERBUFFER_SAMPLES and glCheckFramebufferStatus for both APIs.

- RenderSelectionHighlightMask(): binds the MSAA FBO, clears to
  transparent, draws selected opaque and transparent volumes through
  the mask shader, then resolves to the resolve texture with
  glBlitFramebuffer / glBlitFramebufferEXT.

- CompositeSelectionHighlight(): disables depth test, enables alpha
  blend, binds the resolve texture, and draws the background fullscreen
  quad with the composite shader to overlay fill and outline onto the
  finished scene.

- RenderSelectionStencilFallback(): when the unified framebuffer path
  is unavailable, uses the default framebuffer stencil attachment with
  a model-space 1.02× scale to draw an occlusion-dependent outline.

- ResolveSelectionHighlightMode(): selects UnifiedFramebuffer when FBO
  support, 4× MSAA capability, and both shaders are present; falls back
  to StencilFallback when GL_STENCIL_BITS > 0 and the mask shader is
  available; degrades to Disabled otherwise.

- Runtime capability checks: queries GL_MAX_SAMPLES (ARB or EXT),
  validates GL_STENCIL_BITS, and logs degradation paths once.

- Register selection_mask (flat.vs + selection_mask.fs) and
  selection_composite (background.vs + selection_composite.fs) in
  GLShadersManager.

Design constraints:
- Mask FBO has no depth/stencil attachment — only a color buffer.
- Fill preserves continuous MSAA-resolved coverage (no sign/step).
- Outline is a hard 2 px edge in framebuffer space (no DPI scaling).
- Both fill and outline composite after the main scene and are always
  visible (no depth testing), matching the requirement for
  see-through-occlusion behaviour.
- Old render_with_outline() and Gouraud depth-texture outline code
  are preserved but no longer used as the fallback; they will be
  removed in a follow-up cleanup.
Replace the single-pass radius-2 circular dilation in the selection
composite shader with a two-pass separable max dilation (horizontal
radius 4 into a dedicated band, then vertical radius 4), producing a
~4px-wide outline at ~18 taps/pixel instead of the ~49 taps a radius-4
circular kernel would need; corners are squarer (Chebyshev kernel).

- Add selection_dilate.fs (110/140): horizontal max dilation over the
  resolved mask into a reusable dilation texture.
- selection_composite.fs (110/140): vertical max dilation over the
  dilated band with early-out once the band is hit.
- GLCanvas3D: add a dilation FBO/texture to the selection highlight
  resources, wire its lifecycle for both ARB and EXT framebuffers, gate
  the Unified path on the new shader, and run the horizontal pass inside
  CompositeSelectionHighlight.
- GLShadersManager: register the selection_dilate shader.
…at reduced resolution

Replace the single-pass circular-dilation outline with a multi-pass
edge-detection and blurred-glow pipeline to get a soft ~4px outline.

Mask pass:
- Render selected volumes into a full-resolution mask texture, then
  downsample it to half resolution with the gaussian shader (radius 0).

Outline/glow passes (replaces DilateSelectionMaskHorizontal):
- selection_edge.fs: Sobel-style gradient magnitude on the half-res mask
  produces a thin edge band.
- selection_gaussian.fs: two-pass separable Gaussian blur; edge is blurred
  at half resolution, glow is downsampled to quarter resolution first for
  a wide soft falloff.
- selection_composite.fs: separate fill / outline / additive-glow passes;
  outline uses smoothstep exclusion to keep the band outside the fill and
  renders a fixed orange color instead of the canvas-type color.

Resources:
- Add six texture-backed FBOs (full-res mask, mask, edge temp/final,
  glow temp/final) with shared ARB/EXT framebuffer helpers and viewport
  save/restore.

Remove the previous selection_dilate shader and its registration.
Merge the fill, edge, and glow passes of the selection highlight into
one draw call by precomposing normal-alpha fill and edge followed by
additive glow inside the shader, removing the render_fill/render_glow
branches and the extra blend-mode switches.
Merge the fill, edge, and glow passes of the selection highlight into a
single draw call. The shader now precomposes normal-alpha fill and edge
followed by additive glow, removing the render_fill/render_glow branches
and the extra blend-mode switches in GLCanvas3D.
Remove the deprecated "Show Selected Outline (beta)" feature, including
the depth-texture silhouette detection in the gouraud shader,
GLVolume::render_with_outline, the show_outline app-config flag, and the
corresponding menu entry. It is superseded by the new selection
highlight pipeline based on mask/edge/glow textures.
…s optional

- Save/restore texture unit 0 binding and active texture in mask render state
- Use GL_FRAMEBUFFER(_EXT) instead of split draw/read framebuffer bindings
- Load selection highlight shaders as optional with warning instead of failing init
- Ignore local planning docs in .gitignore
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant