Overlay: Edit Mesh: Add anti-alising on normal lines #119146

Open
sac.aiden wants to merge 7 commits from sac.aiden/blender:normal-antialiasing into main

When changing the target branch, be careful to rebase the branch in your fork to match. See documentation.
First-time contributor

Related issue: #107534

Now normals display with anti-alising

This is how it looks now:
image

I use almost the same shader as gpu_shader_3D_polyline_geom.glsl, which transforms a line to two triangles making up a square, and do some necessary modifications to fit the overlay_edit_mesh_normal.

Related issue: https://projects.blender.org/blender/blender/issues/107534 Now normals display with anti-alising This is how it looks now: ![image](/attachments/15e9d581-b22b-4908-8f67-76c11f8558f0) I use almost the same shader as `gpu_shader_3D_polyline_geom.glsl`, which transforms a line to two triangles making up a square, and do some necessary modifications to fit the `overlay_edit_mesh_normal`.
647 KiB
sac.aiden added 1 commit 2024-03-07 09:19:37 +01:00
Iliya Katushenock added this to the EEVEE & Viewport project 2024-03-07 09:29:50 +01:00
Member

Hi,

the trick is that geometry shaders aren't supported on Metal and would require a similar work-around. I expect that this change will crash on macOs currently. Will ask the Michael to help you out with this.

Hi, the trick is that geometry shaders aren't supported on Metal and would require a similar work-around. I expect that this change will crash on macOs currently. Will ask the Michael to help you out with this.
First-time contributor

Yes, as Jeroen has highlighted, unfortunately geometry shaders are unsupported by the Metal backend. Instead, an alternative implementation is required utilizing a vertex-pull solution. The same pattern already exists for a number of shaders e.g. 3D polyline.

The general idea is that the fragment shader and vertex interface can remain exactly the same, but instead, multiple instances of the vertex shader are invoked per input vertex to allow a greater number of outputs. The backend implementation here effectively binds the source vertex/index buffers as SSBOs with full range access, and then invokes the vertex shader with a vertex count which is expected to match the total maximum output.

The shader implementation itself can then use vertex-pull to read the required data to output the required primitives.

One such example which is perhaps similar is: source/blender/draw/engines/overlay/shaders/overlay_armature_shape_outline_vert_no_geom.glsl

Metal will require an implementation of this which utilises a non-geometry shader vertex pass. I am happy to look into implementing this, but to prevent crashing, the shader system will need a fall back which avoids the geometry shader path, while keeping the interface consistent.

To make this fallback seamless, we currently define GPUShaderCreateInfo overrides in gpu_shader_create_info_init.

e.g: For 3D polyline, we override the geometry shader variants of the create info with ones which do not use geometry shaders.

/* 3D polyline. */
    gpu_shader_3D_polyline_uniform_color = gpu_shader_3D_polyline_uniform_color_no_geom;
    gpu_shader_3D_polyline_flat_color = gpu_shader_3D_polyline_flat_color_no_geom;
    gpu_shader_3D_polyline_smooth_color = gpu_shader_3D_polyline_smooth_color_no_geom;
    gpu_shader_3D_polyline_uniform_color_clipped =
        gpu_shader_3D_polyline_uniform_color_clipped_no_geom;

Thanks!

Yes, as Jeroen has highlighted, unfortunately geometry shaders are unsupported by the Metal backend. Instead, an alternative implementation is required utilizing a vertex-pull solution. The same pattern already exists for a number of shaders e.g. 3D polyline. The general idea is that the fragment shader and vertex interface can remain exactly the same, but instead, multiple instances of the vertex shader are invoked per input vertex to allow a greater number of outputs. The backend implementation here effectively binds the source vertex/index buffers as SSBOs with full range access, and then invokes the vertex shader with a vertex count which is expected to match the total maximum output. The shader implementation itself can then use vertex-pull to read the required data to output the required primitives. One such example which is perhaps similar is: `source/blender/draw/engines/overlay/shaders/overlay_armature_shape_outline_vert_no_geom.glsl` Metal will require an implementation of this which utilises a non-geometry shader vertex pass. I am happy to look into implementing this, but to prevent crashing, the shader system will need a fall back which avoids the geometry shader path, while keeping the interface consistent. To make this fallback seamless, we currently define GPUShaderCreateInfo overrides in `gpu_shader_create_info_init`. e.g: For 3D polyline, we override the geometry shader variants of the create info with ones which do not use geometry shaders. ``` /* 3D polyline. */ gpu_shader_3D_polyline_uniform_color = gpu_shader_3D_polyline_uniform_color_no_geom; gpu_shader_3D_polyline_flat_color = gpu_shader_3D_polyline_flat_color_no_geom; gpu_shader_3D_polyline_smooth_color = gpu_shader_3D_polyline_smooth_color_no_geom; gpu_shader_3D_polyline_uniform_color_clipped = gpu_shader_3D_polyline_uniform_color_clipped_no_geom; ``` Thanks!
Clément Foucault added the
Module
EEVEE & Viewport
Interest
Overlay
labels 2024-03-07 10:45:14 +01:00
Clément Foucault changed title from add anti-alising on normal lines to Overlay: Edit Mesh: Add anti-alising on normal lines 2024-03-07 10:45:33 +01:00
sac.aiden added 3 commits 2024-03-08 09:36:25 +01:00
Author
First-time contributor

image
now it can run on mac, but cannot render correctly, have no idea why it looks like this

![image](/attachments/da325597-763f-4a2a-a242-64984b7d0e00) now it can run on mac, but cannot render correctly, have no idea why it looks like this
923 KiB
Author
First-time contributor

6187dd9d7c1fbca858877dbfe281f35f
It may work on mac now

![6187dd9d7c1fbca858877dbfe281f35f](/attachments/fb67dded-c611-43fe-83ce-de0528325432) It may work on mac now
sac.aiden force-pushed normal-antialiasing from 5748959741 to fa4043fa82 2024-03-09 04:10:24 +01:00 Compare
sac.aiden added 1 commit 2024-03-09 04:21:49 +01:00
sac.aiden added 1 commit 2024-03-11 04:18:51 +01:00
Author
First-time contributor

Really thanks @Michael-Parkin-White-Apple for teaching me patient.

Really thanks @Michael-Parkin-White-Apple for teaching me patient.
Jeroen Bakker added this to the 4.2 LTS milestone 2024-03-11 07:59:05 +01:00
Jeroen Bakker requested review from Jeroen Bakker 2024-03-11 07:59:25 +01:00
Merge conflict checking is in progress. Try again in few moments.

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u normal-antialiasing:sac.aiden-normal-antialiasing
git checkout sac.aiden-normal-antialiasing
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 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#119146
No description provided.