#70267 Retopology Overlay #104599

Merged
Clément Foucault merged 30 commits from bonj/blender:retopology-overlay into main 2023-03-03 00:35:56 +01:00

30 Commits

Author SHA1 Message Date
Clément Foucault 58dd91423d Merge branch 'main' into retopology-overlay 2023-03-03 00:29:19 +01:00
Jorijn de Graaf 113dc37272 Remove unused variable rv3d
This was necessary when the clip distances were used to calculate offset, but that's done inside the shader now, so it's no longer needed.
2023-03-01 00:25:55 +01:00
Clément Foucault 46171c5d8f Merge branch 'main' into retopology-overlay 2023-02-28 18:32:17 +01:00
Clément Foucault 81ad3e6866 Merge branch 'main' into retopology-overlay 2023-02-28 18:17:17 +01:00
Jorijn de Graaf 2e92bcdae6 Clamp retopology offset for perspective projection
This way it can't offset a vertex to behind the camera, and by keeping the ratio between Z and offset large enough, it avoids floating point precision errors.
2023-02-28 18:13:49 +01:00
Jorijn de Graaf 40a930e13c Reuse view_pos for facing based color blend
I'm already calculating the view position earlier in the function, so might as well reuse it here instead of calculating it again.
2023-02-28 13:56:03 +01:00
Jorijn de Graaf 3a90751a0b Rename parameter for get_homogenous_z_offset
Apparently offset is already used, and you can't overwrite it on Metal, so I'm renaming it to vs_offset.
Also I'm adjusting the comment a little.
2023-02-28 13:38:43 +01:00
Jorijn de Graaf bae2564702 Merge branch 'main' into retopology-overlay
buildbot/vexp-code-patch-coordinator Build done. Details
2023-02-28 04:27:08 +01:00
Jorijn de Graaf e7d2e05fa1 Use max instead of plus for retopology epsilon
Jeroen Bakker requested this, and it makes sense to me.
He also asked me to get rid of the comment.
2023-02-28 04:16:38 +01:00
Jorijn de Graaf 9240dd0e13 Merge branch 'main' into retopology-overlay
buildbot/vexp-code-patch-coordinator Build done. Details
2023-02-28 00:48:52 +01:00
Jorijn de Graaf 7e5202cc18 Merge branch 'main' into retopology-overlay 2023-02-28 00:14:56 +01:00
Jorijn de Graaf c11b43952f Merge branch 'main' into retopology-overlay
buildbot/vexp-code-patch-coordinator Build done. Details
2023-02-27 17:38:13 +01:00
Jorijn de Graaf 2762fd7b8d Implement retopology overlay requests
The bias property is now called offset, not just in the UI but everywhere, because I like consistency.
get_homogenous_z_offset no longer negates its output, and has some more documentation.
The offset property is now of distance type, because it is a viewspace offset.
To make this more clear the soft max is increased to 10.
Because there's no point in arbitrarily limiting the values users can input, the hard max is FLT_MAX now.
I kept step the same, because it good the way it is.
2023-02-26 22:51:24 +01:00
Jorijn de Graaf 152dcb969a Merge branch 'main' into retopology-overlay 2023-02-26 18:25:50 +01:00
Jorijn de Graaf ad07bd6931 Use new and improved math for retopology offset
The clip distances no longer need to be factored in on the C++ side, so that simplifies how bias is calculated.
I've added a new function to the common_view_lib, which uses math I found in a neat PDF for perspective, and math I came up with through a little trial and error for orthographic.
The shaders that use retopology bias now have an extra step to get the view position, but that was being calculated to get the homogenous position anyway so it's just an extra variable.
The offset is done at the start of the vertex shader now instead of the end; I think it makes sense because the offset it does is usually much larger than anything that comes after.
2023-02-26 17:03:41 +01:00
Jorijn de Graaf 7aa7153b72 Fix overlay_edit_mesh_depth bug
This is what happens when you copy paste without reading carefully.
This shader was sharing a variable with the regular overlay_depth_only shader, so whichever was used first during a session would be used for both.
Now it has its own variable, so the shaders don't interfere with each other anymore.
2023-02-26 17:03:41 +01:00
Jorijn de Graaf 6f3ed2f125 Fix shader name mess
Oh boy, this is about to get confusing, so I recommend just looking at the PR's final changes instead.
overlay_uniform_color_vert.glsl is renamed back to overlay_depth_only.glsl, like it was originally.
overlay_uniform_color uses this vertex shader again.
overlay_depth_only no longer has retopologyBias.
For edit mesh I've added a new shader, overlay_edit_mesh_depth, with its own vertex shader, overlay_edit_mesh_depth_vert.glsl.
I've added the necessary function, OVERLAY_shader_edit_mesh_depth, in hopefully the right places.
It builds and runs fine at least.
2023-02-26 17:03:41 +01:00
Jorijn de Graaf d08be75414 Use epsilon for retopology bias
Now the shader can tell whether the effect is enabled or not by comparing against zero.
No longer using negative values for that means that I can remove the max calls from vertex shaders.
2023-02-26 17:03:41 +01:00
Jorijn de Graaf ee3ed2c15a Don't update View3D Shading on bias change
Because setting the value to 0 no longer disables the effect, this is no longer, necessary.
I forgot to do it in the last commit.
2023-02-26 17:03:41 +01:00
Jorijn de Graaf a4124b667e Adjust retopology bias property
Setting the value to 0.0 no longer disables the effect, so I removed that part of the tooltip.
Very large meshes require very large bias values, so I'm upping the hard maximum to 100000, and adding a soft maximum.
2023-02-26 17:03:41 +01:00
Jorijn de Graaf 0e0bf18f4d Lower opacity of default retopology color
Since we're not changing the opacity by selection mode, this value was too opaque compared to selected / active / freestyle faces when in vertex select mode.
2023-02-26 17:03:41 +01:00
Jorijn de Graaf a9a8878767 Use back face culling for retopology overlay
It's simple and gives you a decent way to check if your faces are the right way around.
2023-02-26 17:03:41 +01:00
Jorijn de Graaf 2ddb9b599f Fix ThemeSpace struct padding
I messed this up while fixing merge conflicts.
2023-02-26 17:03:41 +01:00
Jorijn de Graaf fbc35f68c4 Fix depth pass for retopology overlay
When in retopology mode, the depth pass now uses the edit cage mesh, and no longer does back face culling.
I've also removed the unnecessary DRW_shgroup_uniform_block line, which I previously added via careless copy pasting.
2023-02-26 17:03:41 +01:00
Jorijn de Graaf b20eae1d95 Allow retopology bias to be 0
A value of 0 no longer disables the effect, and the face color code now checks for a value of -1 instead.
The shaders that use the bias for math have to clamp it to positive values.
2023-02-26 17:03:41 +01:00
Jorijn de Graaf 8a13e2e9db Fix retopology overlay in orthographic view
After a few hours of trial and error, I managed to figure out the right way to calculate the bias value for orthographic view.
Also it turns out bias should divided by W instead of Z in the shaders; this fixes orthographic view, and some minor artifacts in perspective view.
2023-02-26 17:03:41 +01:00
Jorijn de Graaf 63f58db6ae Replace Hidden Wire with Retopology
These features are functionally the same.
2023-02-26 17:03:41 +01:00
Jorijn de Graaf db70eae118 Add retopology bias to shaders
This value will be set in the next commits; when 0 it just does nothing.
2023-02-26 17:03:41 +01:00
Jorijn de Graaf f9738791a4 Give overlay_uniform_color its own vertex shader
This is necessary because I'm making changes to the overlay_depth_only shader, which don't need to propagate to this shader.
2023-02-26 17:03:41 +01:00
Jorijn de Graaf 47f146af0c Add theme color for retopology overlay
I went with the blue from pose mode bones, with half the alpha of selected edit mode faces.
2023-02-26 17:03:40 +01:00