diff --git a/source/blender/draw/engines/gpencil/gpencil_cache_utils.cc b/source/blender/draw/engines/gpencil/gpencil_cache_utils.cc index f00fb4bd92b..820e8c5185b 100644 --- a/source/blender/draw/engines/gpencil/gpencil_cache_utils.cc +++ b/source/blender/draw/engines/gpencil/gpencil_cache_utils.cc @@ -50,7 +50,6 @@ GPENCIL_tObject *gpencil_object_cache_add(GPENCIL_Instance *inst, tgp_ob->vfx.first = tgp_ob->vfx.last = nullptr; tgp_ob->camera_z = dot_v3v3(inst->camera_z_axis, ob->object_to_world().location()); tgp_ob->is_drawmode3d = is_stroke_order_3d; - tgp_ob->object_scale = mat4_to_scale(ob->object_to_world().ptr()); /* Check if any material with holdout flag enabled. */ tgp_ob->do_mat_holdout = false; @@ -317,9 +316,6 @@ GPENCIL_tLayer *grease_pencil_layer_cache_add(GPENCIL_Instance *inst, const float vert_col_opacity = (override_vertcol) ? (is_vert_col_mode ? inst->vertex_paint_opacity : 0.0f) : (inst->is_render ? 1.0f : inst->vertex_paint_opacity); - /* Negate thickness sign to tag that strokes are in screen space (this is no longer used in - * GPv3). Convert to world units (by default, 1 meter = 1000 pixels). */ - const float thickness_scale = blender::bke::greasepencil::LEGACY_RADIUS_CONVERSION_FACTOR; /* If the layer is used as a mask (but is otherwise not visible in the render), render it with a * opacity of 0 so that it can still mask other layers. */ const float layer_opacity = !is_used_as_mask ? grease_pencil_layer_final_opacity_get( @@ -454,10 +450,6 @@ GPENCIL_tLayer *grease_pencil_layer_cache_add(GPENCIL_Instance *inst, pass.bind_texture("gpMaskTexture", mask_tex); pass.push_constant("gpNormal", tgp_ob->plane_normal); pass.push_constant("gpStrokeOrder3d", tgp_ob->is_drawmode3d); - pass.push_constant("gpThicknessScale", tgp_ob->object_scale); - /* Replaced by a modifier in GPv3. */ - pass.push_constant("gpThicknessOffset", 0.0f); - pass.push_constant("gpThicknessWorldScale", thickness_scale); pass.push_constant("gpVertexColorOpacity", vert_col_opacity); pass.bind_texture("gpFillTexture", inst->dummy_tx); diff --git a/source/blender/draw/engines/gpencil/gpencil_engine.h b/source/blender/draw/engines/gpencil/gpencil_engine.h index 1a393bf42ce..974d1af3f07 100644 --- a/source/blender/draw/engines/gpencil/gpencil_engine.h +++ b/source/blender/draw/engines/gpencil/gpencil_engine.h @@ -136,8 +136,6 @@ typedef struct GPENCIL_tObject { /* Distance to camera. Used for sorting. */ float camera_z; - /* Used for stroke thickness scaling. */ - float object_scale; /* Normal used for shading. Based on view angle. */ float3 plane_normal; /* Used for drawing depth merge pass. */ diff --git a/source/blender/draw/engines/overlay/overlay_next_grease_pencil.hh b/source/blender/draw/engines/overlay/overlay_next_grease_pencil.hh index d7fd0bfc207..32cbcab23e6 100644 --- a/source/blender/draw/engines/overlay/overlay_next_grease_pencil.hh +++ b/source/blender/draw/engines/overlay/overlay_next_grease_pencil.hh @@ -310,16 +310,10 @@ class GreasePencil : Overlay { const Vector drawings = retrieve_visible_drawings(*scene, grease_pencil, true); for (const DrawingInfo info : drawings) { - const float object_scale = mat4_to_scale(ob->object_to_world().ptr()); - const float thickness_scale = bke::greasepencil::LEGACY_RADIUS_CONVERSION_FACTOR; - gpu::VertBuf *position_tx = draw::DRW_cache_grease_pencil_position_buffer_get(scene, ob); gpu::VertBuf *color_tx = draw::DRW_cache_grease_pencil_color_buffer_get(scene, ob); pass.push_constant("gpStrokeOrder3d", is_stroke_order_3d); - pass.push_constant("gpThicknessScale", object_scale); - pass.push_constant("gpThicknessOffset", 0.0f); - pass.push_constant("gpThicknessWorldScale", thickness_scale); pass.bind_texture("gp_pos_tx", position_tx); pass.bind_texture("gp_col_tx", color_tx); diff --git a/source/blender/draw/intern/draw_cache_impl_grease_pencil.cc b/source/blender/draw/intern/draw_cache_impl_grease_pencil.cc index f6187ca1b27..37ee1b7c2d0 100644 --- a/source/blender/draw/intern/draw_cache_impl_grease_pencil.cc +++ b/source/blender/draw/intern/draw_cache_impl_grease_pencil.cc @@ -1212,9 +1212,6 @@ static void grease_pencil_geom_batch_ensure(Object &object, * use negative values as a special 'flag' to get rounded caps. */ s_vert.radius = math::max(radii[point_i], 0.0f) * ((end_cap == GP_STROKE_CAP_TYPE_ROUND) ? 1.0f : -1.0f); - /* Convert to legacy "pixel" space. We divide here, because the shader expects the values to - * be in the `px` space rather than world space. Otherwise the values will get clamped. */ - s_vert.radius /= bke::greasepencil::LEGACY_RADIUS_CONVERSION_FACTOR; s_vert.opacity = opacities[point_i] * ((start_cap == GP_STROKE_CAP_TYPE_ROUND) ? 1.0f : -1.0f); s_vert.point_id = verts_range[idx]; diff --git a/source/blender/draw/intern/shaders/draw_grease_pencil_lib.glsl b/source/blender/draw/intern/shaders/draw_grease_pencil_lib.glsl index 312060f1d74..86c5fdc99d8 100644 --- a/source/blender/draw/intern/shaders/draw_grease_pencil_lib.glsl +++ b/source/blender/draw/intern/shaders/draw_grease_pencil_lib.glsl @@ -75,18 +75,20 @@ vec2 gpencil_project_to_screenspace(vec4 v, vec4 viewport_size) float gpencil_stroke_thickness_modulate(float thickness, vec4 ndc_pos, vec4 viewport_size) { - /* Modify stroke thickness by object and layer factors. */ - thickness = max(1.0, thickness * gpThicknessScale + gpThicknessOffset); + /* Modify stroke thickness by object scale. */ + thickness = length(to_float3x3(drw_modelmat()) * vec3(thickness * M_SQRT1_3)); + + /* For compatibility, thickness has to be clamped after being multiplied by this factor. + * This clamping was introduced to reduce aliasing issue by instead fading the lines alpha at + * smaller radii. This can be removed in major release if compatibility is not a concern. */ + const float legacy_radius_conversion_factor = 2000.0; + thickness *= legacy_radius_conversion_factor; + thickness = max(1.0, thickness); + thickness /= legacy_radius_conversion_factor; + + /* World space point size. */ + thickness *= drw_view().winmat[1][1] * viewport_size.y; - if (gpThicknessIsScreenSpace) { - /* Multiply offset by view Z so that offset is constant in screen-space. - * (e.i: does not change with the distance to camera) */ - thickness *= ndc_pos.w; - } - else { - /* World space point size. */ - thickness *= gpThicknessWorldScale * drw_view().winmat[1][1] * viewport_size.y; - } return thickness; } diff --git a/source/blender/draw/intern/shaders/draw_object_infos_info.hh b/source/blender/draw/intern/shaders/draw_object_infos_info.hh index f85b4091614..dce5e84fc6e 100644 --- a/source/blender/draw/intern/shaders/draw_object_infos_info.hh +++ b/source/blender/draw/intern/shaders/draw_object_infos_info.hh @@ -103,12 +103,6 @@ TYPEDEF_SOURCE("gpencil_shader_shared.h") DEFINE("DRW_GPENCIL_INFO") SAMPLER(0, FLOAT_BUFFER, gp_pos_tx) SAMPLER(1, FLOAT_BUFFER, gp_col_tx) -/* Per Object */ -PUSH_CONSTANT(FLOAT, gpThicknessScale) /* TODO(fclem): Replace with object info. */ -PUSH_CONSTANT(FLOAT, gpThicknessWorldScale) /* TODO(fclem): Same as above. */ -DEFINE_VALUE("gpThicknessIsScreenSpace", "(gpThicknessWorldScale < 0.0)") -/* Per Layer */ -PUSH_CONSTANT(FLOAT, gpThicknessOffset) ADDITIONAL_INFO(draw_resource_id_varying) ADDITIONAL_INFO(draw_view) ADDITIONAL_INFO(draw_object_infos) diff --git a/source/blender/draw/intern/shaders/draw_view_info.hh b/source/blender/draw/intern/shaders/draw_view_info.hh index 9ce395eaa0b..91e197ef3fc 100644 --- a/source/blender/draw/intern/shaders/draw_view_info.hh +++ b/source/blender/draw/intern/shaders/draw_view_info.hh @@ -18,7 +18,6 @@ # define USE_WORLD_CLIP_PLANES # define DRW_VIEW_LEN DRW_VIEW_MAX -# define gpThicknessIsScreenSpace (gpThicknessWorldScale < 0.0) #endif #include "gpu_shader_create_info.hh"