Viewport normal drawing with constant length

Patch for: T37878

{F10169694}

Reviewed By: fclem

Differential Revision: https://developer.blender.org/D11487
This commit is contained in:
Jeroen Bakker 2021-08-04 10:52:51 +02:00
parent 218df99410
commit cb67bfdba2
17 changed files with 81 additions and 4 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 24 KiB

After

Width:  |  Height:  |  Size: 25 KiB

@ -17301,6 +17301,11 @@
d="m 1800,348 h 3 v 14 h -3 z m -4,7 h 16 v 3 h -16 z"
inkscape:connector-curvature="0" />
</g>
<path
style="color:#000000;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:medium;line-height:normal;font-family:sans-serif;font-variant-ligatures:normal;font-variant-position:normal;font-variant-caps:normal;font-variant-numeric:normal;font-variant-alternates:normal;font-feature-settings:normal;text-indent:0;text-align:start;text-decoration:none;text-decoration-line:none;text-decoration-style:solid;text-decoration-color:#000000;letter-spacing:normal;word-spacing:normal;text-transform:none;writing-mode:lr-tb;direction:ltr;text-orientation:mixed;dominant-baseline:auto;baseline-shift:baseline;text-anchor:start;white-space:normal;shape-padding:0;clip-rule:nonzero;display:inline;overflow:visible;visibility:visible;opacity:0.98999999;isolation:auto;mix-blend-mode:normal;color-interpolation:sRGB;color-interpolation-filters:linearRGB;solid-color:#000000;solid-opacity:1;vector-effect:none;fill:#ffffff;fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:1;stroke-linecap:round;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;color-rendering:auto;image-rendering:auto;shape-rendering:auto;text-rendering:auto;enable-background:new"
d="m 418.85321,140.04954 -2.82,-2.82 a 0.62,0.62 0 0 0 -0.4,-0.18 0.6,0.6 0 0 0 -0.6,0.6 0.62,0.62 0 0 0 0.18,0.43 l 1,1 -9.18,9.12 -1,-1 a 0.62,0.62 0 0 0 -0.4,-0.15 0.6,0.6 0 0 0 -0.6,0.6 0.62,0.62 0 0 0 0.18,0.4 l 2.82,2.82 a 0.6,0.6 0 0 0 0.82,-0.82 l -1,-1 9.18,-9.15 1,1 a 0.6,0.6 0 0 0 0.82,-0.85 z"
id="path3261"
inkscape:connector-curvature="0" />
</g>
<g
inkscape:groupmode="layer"

Before

Width:  |  Height:  |  Size: 2.5 MiB

After

Width:  |  Height:  |  Size: 2.5 MiB

@ -6386,7 +6386,13 @@ class VIEW3D_PT_overlay_edit_mesh_normals(Panel):
sub = row.row(align=True)
sub.active = overlay.show_vertex_normals or overlay.show_face_normals or overlay.show_split_normals
sub.prop(overlay, "normals_length", text="Size")
if overlay.use_normals_constant_screen_size:
sub.prop(overlay, "normals_constant_screen_size", text="Size")
else:
sub.prop(overlay, "normals_length", text="Size")
row.prop(overlay, "use_normals_constant_screen_size", text="", icon='FIXED_SIZE')
class VIEW3D_PT_overlay_edit_mesh_freestyle(Panel):

@ -708,5 +708,19 @@ void blo_do_versions_300(FileData *fd, Library *UNUSED(lib), Main *bmain)
*/
{
/* Keep this block, even when empty. */
if (!DNA_struct_elem_find(
fd->filesdna, "View3DOverlay", "float", "normals_constant_screen_size")) {
LISTBASE_FOREACH (bScreen *, screen, &bmain->screens) {
LISTBASE_FOREACH (ScrArea *, area, &screen->areabase) {
LISTBASE_FOREACH (SpaceLink *, sl, &area->spacedata) {
if (sl->spacetype == SPACE_VIEW3D) {
View3D *v3d = (View3D *)sl;
v3d->overlay.normals_constant_screen_size = 7.0f;
}
}
}
}
}
}
}

@ -190,6 +190,7 @@ static void blo_update_defaults_screen(bScreen *screen,
}
/* Disable Curve Normals. */
v3d->overlay.edit_flag &= ~V3D_OVERLAY_EDIT_CU_NORMALS;
v3d->overlay.normals_constant_screen_size = 7.0f;
}
else if (area->spacetype == SPACE_CLIP) {
SpaceClip *sclip = area->spacedata.first;

@ -132,6 +132,11 @@ void OVERLAY_edit_mesh_cache_init(OVERLAY_Data *vedata)
DRW_shgroup_uniform_float_copy(grp, "normalSize", v3d->overlay.normals_length);
DRW_shgroup_uniform_float_copy(grp, "alpha", backwire_opacity);
DRW_shgroup_uniform_texture_ref(grp, "depthTex", depth_tex);
DRW_shgroup_uniform_bool_copy(grp,
"isConstantScreenSizeNormals",
(flag & V3D_OVERLAY_EDIT_CONSTANT_SCREEN_SIZE_NORMALS) != 0);
DRW_shgroup_uniform_float_copy(
grp, "normalScreenSize", v3d->overlay.normals_constant_screen_size);
}
{
/* Mesh Analysis Pass */

@ -1,5 +1,7 @@
uniform float normalSize;
uniform float normalScreenSize;
uniform bool isConstantScreenSizeNormals;
uniform sampler2D depthTex;
uniform float alpha = 1.0;
@ -49,11 +51,25 @@ void main()
}
vec3 n = normalize(normal_object_to_world(nor));
vec3 world_pos = point_object_to_world(pos);
if (gl_VertexID == 0) {
world_pos += n * normalSize;
if (isConstantScreenSizeNormals) {
bool is_persp = (ProjectionMatrix[3][3] == 0.0);
if (is_persp)
{
float dist_fac = length(cameraPos - world_pos);
float cos_fac = dot(cameraForward, cameraVec(world_pos));
world_pos += n * normalScreenSize * dist_fac * cos_fac * pixelFac * sizePixel;
}
else {
float frustrum_fac = mul_project_m4_v3_zfac(n) * sizePixel;
world_pos += n * normalScreenSize * frustrum_fac;
}
}
else {
world_pos += n * normalSize;
}
}
gl_Position = point_world_to_ndc(world_pos);

@ -583,6 +583,7 @@ set(ICON_NAMES
uv_facesel
uv_islandsel
uv_sync_select
fixed_size
transform_origins
gizmo
orientation_cursor

@ -715,7 +715,7 @@ DEF_ICON(UV_ISLANDSEL)
DEF_ICON(UV_SYNC_SELECT)
DEF_ICON_BLANK(240)
DEF_ICON_BLANK(241)
DEF_ICON_BLANK(242)
DEF_ICON(FIXED_SIZE)
DEF_ICON(TRANSFORM_ORIGINS)
DEF_ICON(GIZMO)
DEF_ICON(ORIENTATION_CURSOR)

@ -71,6 +71,7 @@
.gpencil_paper_opacity = 0.5f, \
.gpencil_grid_opacity = 0.9f, \
.gpencil_vertex_paint_opacity = 1.0f, \
.normals_constant_screen_size = 7.0f, \
}
#define _DNA_DEFAULT_View3DCursor \

@ -204,6 +204,7 @@ typedef struct View3DOverlay {
/** Edit mode settings. */
int edit_flag;
float normals_length;
float normals_constant_screen_size;
float backwire_opacity;
/** Paint mode settings. */
@ -238,6 +239,8 @@ typedef struct View3DOverlay {
float gpencil_vertex_paint_opacity;
/** Handles display type for curves. */
int handle_display;
char _pad[4];
} View3DOverlay;
/* View3DOverlay->handle_display */
@ -551,6 +554,7 @@ enum {
// V3D_OVERLAY_EDIT_CU_HANDLES = (1 << 20),
V3D_OVERLAY_EDIT_CU_NORMALS = (1 << 21),
V3D_OVERLAY_EDIT_CONSTANT_SCREEN_SIZE_NORMALS = (1 << 22),
};
/** #View3DOverlay.paint_flag */

@ -0,0 +1,9 @@
diff a/source/blender/makesdna/DNA_view3d_types.h b/source/blender/makesdna/DNA_view3d_types.h (rejected hunks)
@@ -550,6 +553,7 @@
/* V3D_OVERLAY_EDIT_CU_HANDLES = (1 << 20), */
V3D_OVERLAY_EDIT_CU_NORMALS = (1 << 21),
+ V3D_OVERLAY_EDIT_CONSTANT_SCREEN_SIZE_NORMALS = (1 << 22),
};
/** #View3DOverlay.paint_flag */

@ -4363,6 +4363,21 @@ static void rna_def_space_view3d_overlay(BlenderRNA *brna)
RNA_def_property_float_default(prop, 0.02);
RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL);
prop = RNA_def_property(srna, "normals_constant_screen_size", PROP_FLOAT, PROP_PIXEL);
RNA_def_property_float_sdna(prop, NULL, "overlay.normals_constant_screen_size");
RNA_def_property_ui_text(prop, "Normal Screen Size", "Screen size for normals in the 3D view");
RNA_def_property_range(prop, 0.0, 100000.0);
RNA_def_property_ui_range(prop, 1.0, 100.0, 50, 0);
RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL);
prop = RNA_def_property(srna, "use_normals_constant_screen_size", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(
prop, NULL, "overlay.edit_flag", V3D_OVERLAY_EDIT_CONSTANT_SCREEN_SIZE_NORMALS);
RNA_def_property_ui_text(prop,
"Constant Screen Size Normals",
"Keep size of normals constant in relation to 3D view");
RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL);
prop = RNA_def_property(srna, "backwire_opacity", PROP_FLOAT, PROP_FACTOR);
RNA_def_property_float_sdna(prop, NULL, "overlay.backwire_opacity");
RNA_def_property_ui_text(prop, "Backwire Opacity", "Opacity when rendering transparent wires");