diff options
7 files changed, 114 insertions, 104 deletions
diff --git a/source/blender/draw/engines/overlay/overlay_shader.c b/source/blender/draw/engines/overlay/overlay_shader.c index 9d180f7fb8d..a38055063dc 100644 --- a/source/blender/draw/engines/overlay/overlay_shader.c +++ b/source/blender/draw/engines/overlay/overlay_shader.c @@ -423,23 +423,10 @@ GPUShader *OVERLAY_shader_armature_wire(void) GPUShader *OVERLAY_shader_edit_curve_handle(void) { const DRWContextState *draw_ctx = DRW_context_state_get(); - const GPUShaderConfigData *sh_cfg = &GPU_shader_cfg_data[draw_ctx->sh_cfg]; OVERLAY_Shaders *sh_data = &e_data.sh_data[draw_ctx->sh_cfg]; if (!sh_data->edit_curve_handle) { - sh_data->edit_curve_handle = GPU_shader_create_from_arrays({ - .vert = (const char *[]){sh_cfg->lib, - datatoc_common_globals_lib_glsl, - datatoc_common_view_lib_glsl, - datatoc_edit_curve_handle_vert_glsl, - NULL}, - .geom = (const char *[]){sh_cfg->lib, - datatoc_common_globals_lib_glsl, - datatoc_common_view_lib_glsl, - datatoc_edit_curve_handle_geom_glsl, - NULL}, - .frag = (const char *[]){datatoc_gpu_shader_3D_smooth_color_frag_glsl, NULL}, - .defs = (const char *[]){sh_cfg->def, NULL}, - }); + sh_data->edit_curve_handle = GPU_shader_create_from_info_name( + draw_ctx->sh_cfg ? "overlay_edit_curve_handle_clipped" : "overlay_edit_curve_handle"); } return sh_data->edit_curve_handle; } @@ -447,18 +434,10 @@ GPUShader *OVERLAY_shader_edit_curve_handle(void) GPUShader *OVERLAY_shader_edit_curve_point(void) { const DRWContextState *draw_ctx = DRW_context_state_get(); - const GPUShaderConfigData *sh_cfg = &GPU_shader_cfg_data[draw_ctx->sh_cfg]; OVERLAY_Shaders *sh_data = &e_data.sh_data[draw_ctx->sh_cfg]; if (!sh_data->edit_curve_point) { - sh_data->edit_curve_point = GPU_shader_create_from_arrays({ - .vert = (const char *[]){sh_cfg->lib, - datatoc_common_globals_lib_glsl, - datatoc_common_view_lib_glsl, - datatoc_edit_curve_point_vert_glsl, - NULL}, - .frag = (const char *[]){datatoc_gpu_shader_point_varying_color_frag_glsl, NULL}, - .defs = (const char *[]){sh_cfg->def, NULL}, - }); + sh_data->edit_curve_point = GPU_shader_create_from_info_name( + draw_ctx->sh_cfg ? "overlay_edit_curve_point_clipped" : "overlay_edit_curve_point"); } return sh_data->edit_curve_point; } @@ -466,18 +445,10 @@ GPUShader *OVERLAY_shader_edit_curve_point(void) GPUShader *OVERLAY_shader_edit_curve_wire(void) { const DRWContextState *draw_ctx = DRW_context_state_get(); - const GPUShaderConfigData *sh_cfg = &GPU_shader_cfg_data[draw_ctx->sh_cfg]; OVERLAY_Shaders *sh_data = &e_data.sh_data[draw_ctx->sh_cfg]; if (!sh_data->edit_curve_wire) { - sh_data->edit_curve_wire = GPU_shader_create_from_arrays({ - .vert = (const char *[]){sh_cfg->lib, - datatoc_common_globals_lib_glsl, - datatoc_common_view_lib_glsl, - datatoc_edit_curve_wire_vert_glsl, - NULL}, - .frag = (const char *[]){datatoc_gpu_shader_flat_color_frag_glsl, NULL}, - .defs = (const char *[]){sh_cfg->def, "#define IN_PLACE_INSTANCES\n", NULL}, - }); + sh_data->edit_curve_wire = GPU_shader_create_from_info_name( + draw_ctx->sh_cfg ? "overlay_edit_curve_wire_clipped" : "overlay_edit_curve_wire"); } return sh_data->edit_curve_wire; } diff --git a/source/blender/draw/engines/overlay/overlay_shader_shared.h b/source/blender/draw/engines/overlay/overlay_shader_shared.h index 4b1d4eea69a..860560e1026 100644 --- a/source/blender/draw/engines/overlay/overlay_shader_shared.h +++ b/source/blender/draw/engines/overlay/overlay_shader_shared.h @@ -40,6 +40,22 @@ struct OVERLAY_GridData { }; BLI_STATIC_ASSERT_ALIGN(OVERLAY_GridData, 16) +#ifdef GPU_SHADER +/* Keep the same values as in `draw_cache_imp_curve.c` */ +# define ACTIVE_NURB (1 << 2) +# define BEZIER_HANDLE (1 << 3) +# define EVEN_U_BIT (1 << 4) +# define COLOR_SHIFT 5 + +/* Keep the same value in `handle_display` in `DNA_view3d_types.h` */ +# define CURVE_HANDLE_SELECTED 0 +# define CURVE_HANDLE_ALL 1 +#else +/* TODO(fclem): Find a better way to share enums/defines from DNA files with GLSL. */ +BLI_STATIC_ASSERT(CURVE_HANDLE_SELECTED == 0, "Ensure value is sync"); +BLI_STATIC_ASSERT(CURVE_HANDLE_ALL == 1, "Ensure value is sync"); +#endif + #ifndef GPU_SHADER # ifdef __cplusplus } diff --git a/source/blender/draw/engines/overlay/shaders/edit_curve_handle_geom.glsl b/source/blender/draw/engines/overlay/shaders/edit_curve_handle_geom.glsl index 036efa41555..7d92baea595 100644 --- a/source/blender/draw/engines/overlay/shaders/edit_curve_handle_geom.glsl +++ b/source/blender/draw/engines/overlay/shaders/edit_curve_handle_geom.glsl @@ -1,22 +1,6 @@ -/* Keep the same value of `ACTIVE_NURB` in `draw_cache_imp_curve.c` */ -#define ACTIVE_NURB (1 << 2) -#define EVEN_U_BIT (1 << 4) -#define COLOR_SHIFT 5 - -/* Keep the same value in `handle_display` in `DNA_view3d_types.h` */ -#define CURVE_HANDLE_SELECTED 0 -#define CURVE_HANDLE_ALL 1 - -layout(lines) in; -layout(triangle_strip, max_vertices = 10) out; - -uniform bool showCurveHandles; -uniform int curveHandleDisplay; - -flat in int vertFlag[]; - -out vec4 finalColor; +#pragma BLENDER_REQUIRE(common_view_clipping_lib.glsl) +#pragma BLENDER_REQUIRE(common_view_lib.glsl) void output_line(vec2 offset, vec4 color) { @@ -24,16 +8,12 @@ void output_line(vec2 offset, vec4 color) gl_Position = gl_in[0].gl_Position; gl_Position.xy += offset * gl_in[0].gl_Position.w; -#ifdef USE_WORLD_CLIP_PLANES - world_clip_planes_set_clip_distance(gl_in[0].gl_ClipDistance); -#endif + view_clipping_distances_set(gl_in[0]); EmitVertex(); gl_Position = gl_in[1].gl_Position; gl_Position.xy += offset * gl_in[1].gl_Position.w; -#ifdef USE_WORLD_CLIP_PLANES - world_clip_planes_set_clip_distance(gl_in[1].gl_ClipDistance); -#endif + view_clipping_distances_set(gl_in[1]); EmitVertex(); } @@ -42,24 +22,24 @@ void main() vec4 v1 = gl_in[0].gl_Position; vec4 v2 = gl_in[1].gl_Position; - int is_active_nurb = (vertFlag[1] & ACTIVE_NURB); - int color_id = (vertFlag[1] >> COLOR_SHIFT); + int is_active_nurb = (vert[1].flag & ACTIVE_NURB); + int color_id = (vert[1].flag >> COLOR_SHIFT); /* Don't output any edges if we don't show handles */ if (!showCurveHandles && (color_id < 5)) { return; } - bool edge_selected = (((vertFlag[1] | vertFlag[0]) & VERT_SELECTED) != 0); + bool edge_selected = (((vert[1].flag | vert[0].flag) & VERT_SELECTED) != 0); bool handle_selected = (showCurveHandles && - (((vertFlag[1] | vertFlag[0]) & VERT_SELECTED_BEZT_HANDLE) != 0)); + (((vert[1].flag | vert[0].flag) & VERT_SELECTED_BEZT_HANDLE) != 0)); - bool is_gpencil = ((vertFlag[1] & VERT_GPENCIL_BEZT_HANDLE) != 0); + bool is_gpencil = ((vert[1].flag & VERT_GPENCIL_BEZT_HANDLE) != 0); /* If handle type is only selected and the edge is not selected, don't show. */ if ((curveHandleDisplay != CURVE_HANDLE_ALL) && (!handle_selected)) { /* Nurbs must show the handles always. */ - bool is_u_segment = (((vertFlag[1] ^ vertFlag[0]) & EVEN_U_BIT) != 0); + bool is_u_segment = (((vert[1].flag ^ vert[0].flag) & EVEN_U_BIT) != 0); if ((!is_u_segment) && (color_id <= 4)) { return; } @@ -85,8 +65,8 @@ void main() inner_color = (edge_selected) ? colorHandleSelAutoclamp : colorHandleAutoclamp; } else { - bool is_selected = (((vertFlag[1] & vertFlag[0]) & VERT_SELECTED) != 0); - bool is_u_segment = (((vertFlag[1] ^ vertFlag[0]) & EVEN_U_BIT) != 0); + bool is_selected = (((vert[1].flag & vert[0].flag) & VERT_SELECTED) != 0); + bool is_u_segment = (((vert[1].flag ^ vert[0].flag) & EVEN_U_BIT) != 0); if (is_u_segment) { inner_color = (is_selected) ? colorNurbSelUline : colorNurbUline; } @@ -103,7 +83,7 @@ void main() vec4(inner_color.rgb, 0.0); vec2 v1_2 = (v2.xy / v2.w - v1.xy / v1.w); - vec2 offset = sizeEdge * 4.0 * sizeViewportInv.xy; /* 4.0 is eyeballed */ + vec2 offset = sizeEdge * 4.0 * drw_view.viewport_size_inverse; /* 4.0 is eyeballed */ if (abs(v1_2.x * sizeViewport.x) < abs(v1_2.y * sizeViewport.y)) { offset.y = 0.0; diff --git a/source/blender/draw/engines/overlay/shaders/edit_curve_handle_vert.glsl b/source/blender/draw/engines/overlay/shaders/edit_curve_handle_vert.glsl index a2b0d072719..186cc010f45 100644 --- a/source/blender/draw/engines/overlay/shaders/edit_curve_handle_vert.glsl +++ b/source/blender/draw/engines/overlay/shaders/edit_curve_handle_vert.glsl @@ -1,8 +1,6 @@ -in vec3 pos; -in int data; - -flat out int vertFlag; +#pragma BLENDER_REQUIRE(common_view_clipping_lib.glsl) +#pragma BLENDER_REQUIRE(common_view_lib.glsl) void main() { @@ -10,9 +8,7 @@ void main() vec3 world_pos = point_object_to_world(pos); gl_Position = point_world_to_ndc(world_pos); - vertFlag = data; + vert.flag = data; -#ifdef USE_WORLD_CLIP_PLANES - world_clip_planes_calc_clip_distance(world_pos); -#endif + view_clipping_distances(world_pos); } diff --git a/source/blender/draw/engines/overlay/shaders/edit_curve_point_vert.glsl b/source/blender/draw/engines/overlay/shaders/edit_curve_point_vert.glsl index 5f2154f00b8..a30496177c3 100644 --- a/source/blender/draw/engines/overlay/shaders/edit_curve_point_vert.glsl +++ b/source/blender/draw/engines/overlay/shaders/edit_curve_point_vert.glsl @@ -1,17 +1,6 @@ -/* Keep the same value of `BEZIER_HANDLE` in `draw_cache_imp_curve.c` */ -#define BEZIER_HANDLE (1 << 3) - -/* Keep the same value in `handle_display` in `DNA_view3d_types.h` */ -#define CURVE_HANDLE_SELECTED 0 - -uniform bool showCurveHandles; -uniform int curveHandleDisplay; - -in vec3 pos; -in int data; - -out vec4 finalColor; +#pragma BLENDER_REQUIRE(common_view_clipping_lib.glsl) +#pragma BLENDER_REQUIRE(common_view_lib.glsl) void main() { @@ -34,9 +23,7 @@ void main() vec3 world_pos = point_object_to_world(pos); gl_Position = point_world_to_ndc(world_pos); gl_PointSize = (!is_gpencil) ? sizeVertex * 2.0 : sizeVertexGpencil * 2.0; -#ifdef USE_WORLD_CLIP_PLANES - world_clip_planes_calc_clip_distance(world_pos); -#endif + view_clipping_distances(world_pos); bool show_handle = showCurveHandles; if ((curveHandleDisplay == CURVE_HANDLE_SELECTED) && ((data & VERT_SELECTED_BEZT_HANDLE) == 0)) { diff --git a/source/blender/draw/engines/overlay/shaders/edit_curve_wire_vert.glsl b/source/blender/draw/engines/overlay/shaders/edit_curve_wire_vert.glsl index 5dd8e579db3..183df7e5450 100644 --- a/source/blender/draw/engines/overlay/shaders/edit_curve_wire_vert.glsl +++ b/source/blender/draw/engines/overlay/shaders/edit_curve_wire_vert.glsl @@ -1,12 +1,6 @@ -uniform float normalSize; - -in vec3 pos; -in vec3 nor; -in vec3 tan; -in float rad; - -flat out vec4 finalColor; +#pragma BLENDER_REQUIRE(common_view_clipping_lib.glsl) +#pragma BLENDER_REQUIRE(common_view_lib.glsl) void main() { @@ -25,7 +19,5 @@ void main() finalColor = colorWireEdit; -#ifdef USE_WORLD_CLIP_PLANES - world_clip_planes_calc_clip_distance(world_pos); -#endif + view_clipping_distances(world_pos); } diff --git a/source/blender/draw/engines/overlay/shaders/infos/edit_mode_info.hh b/source/blender/draw/engines/overlay/shaders/infos/edit_mode_info.hh index 188cb3dcd10..ffdbf1b3e89 100644 --- a/source/blender/draw/engines/overlay/shaders/infos/edit_mode_info.hh +++ b/source/blender/draw/engines/overlay/shaders/infos/edit_mode_info.hh @@ -3,7 +3,7 @@ #include "gpu_shader_create_info.hh" GPU_SHADER_INTERFACE_INFO(overlay_edit_flat_color_iface, "").flat(Type::VEC4, "finalColor"); - +GPU_SHADER_INTERFACE_INFO(overlay_edit_smooth_color_iface, "").smooth(Type::VEC4, "finalColor"); GPU_SHADER_INTERFACE_INFO(overlay_edit_nopersp_color_iface, "") .no_perspective(Type::VEC4, "finalColor"); @@ -292,3 +292,71 @@ GPU_SHADER_CREATE_INFO(overlay_edit_uv_stretching_angle) .additional_info("overlay_edit_uv_stretching"); /** \} */ + +/* -------------------------------------------------------------------- */ +/** \name Edit Curve + * \{ */ + +GPU_SHADER_INTERFACE_INFO(overlay_edit_curve_handle_iface, "vert").flat(Type::INT, "flag"); + +GPU_SHADER_CREATE_INFO(overlay_edit_curve_handle) + .do_static_compilation(true) + .typedef_source("overlay_shader_shared.h") + /* NOTE: Color already in Linear space. Which is what we want. */ + .define("srgbTarget", "false") + .vertex_in(0, Type::VEC3, "pos") + .vertex_in(1, Type::INT, "data") + .vertex_out(overlay_edit_curve_handle_iface) + .geometry_layout(PrimitiveIn::LINES, PrimitiveOut::TRIANGLE_STRIP, 10) + .geometry_out(overlay_edit_smooth_color_iface) + .push_constant(Type::BOOL, "showCurveHandles") + .push_constant(Type::INT, "curveHandleDisplay") + .fragment_out(0, Type::VEC4, "fragColor") + .vertex_source("edit_curve_handle_vert.glsl") + .geometry_source("edit_curve_handle_geom.glsl") + .fragment_source("gpu_shader_3D_smooth_color_frag.glsl") + .additional_info("draw_mesh", "draw_globals"); + +GPU_SHADER_CREATE_INFO(overlay_edit_curve_handle_clipped) + .do_static_compilation(true) + .additional_info("overlay_edit_curve_handle", "drw_clipped"); + +GPU_SHADER_CREATE_INFO(overlay_edit_curve_point) + .do_static_compilation(true) + .typedef_source("overlay_shader_shared.h") + /* NOTE: Color already in Linear space. Which is what we want. */ + .define("srgbTarget", "false") + .vertex_in(0, Type::VEC3, "pos") + .vertex_in(1, Type::INT, "data") + .vertex_out(overlay_edit_flat_color_iface) + .push_constant(Type::BOOL, "showCurveHandles") + .push_constant(Type::INT, "curveHandleDisplay") + .fragment_out(0, Type::VEC4, "fragColor") + .vertex_source("edit_curve_point_vert.glsl") + .fragment_source("gpu_shader_point_varying_color_frag.glsl") + .additional_info("draw_mesh", "draw_globals"); + +GPU_SHADER_CREATE_INFO(overlay_edit_curve_point_clipped) + .do_static_compilation(true) + .additional_info("overlay_edit_curve_point", "drw_clipped"); + +GPU_SHADER_CREATE_INFO(overlay_edit_curve_wire) + .do_static_compilation(true) + /* NOTE: Color already in Linear space. Which is what we want. */ + .define("srgbTarget", "false") + .vertex_in(0, Type::VEC3, "pos") + .vertex_in(1, Type::VEC3, "nor") + .vertex_in(2, Type::VEC3, "tan") + .vertex_in(3, Type::FLOAT, "rad") + .push_constant(Type::FLOAT, "normalSize") + .vertex_out(overlay_edit_flat_color_iface) + .fragment_out(0, Type::VEC4, "fragColor") + .vertex_source("edit_curve_wire_vert.glsl") + .fragment_source("gpu_shader_flat_color_frag.glsl") + .additional_info("draw_modelmat", "draw_resource_id_uniform", "draw_globals"); + +GPU_SHADER_CREATE_INFO(overlay_edit_curve_wire_clipped) + .do_static_compilation(true) + .additional_info("overlay_edit_curve_wire", "drw_clipped"); + +/** \} */ |