From 0dfb6eddc001828058b84979699269a55c9bdfcb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Foucault?= Date: Sun, 1 May 2022 15:35:54 +0200 Subject: Overlay: Port motion path shaders to use shaderCreateInfo This should have no functional changes. --- source/blender/draw/CMakeLists.txt | 1 + .../blender/draw/engines/overlay/overlay_shader.c | 29 ++----------- .../draw/engines/overlay/overlay_shader_shared.h | 8 ++++ .../engines/overlay/shaders/infos/extra_info.hh | 50 ++++++++++++++++++++++ .../overlay/shaders/motion_path_line_frag.glsl | 5 +++ .../overlay/shaders/motion_path_line_geom.glsl | 26 ++++------- .../overlay/shaders/motion_path_line_vert.glsl | 30 +++++-------- .../overlay/shaders/motion_path_point_vert.glsl | 17 ++------ 8 files changed, 90 insertions(+), 76 deletions(-) create mode 100644 source/blender/draw/engines/overlay/shaders/motion_path_line_frag.glsl (limited to 'source') diff --git a/source/blender/draw/CMakeLists.txt b/source/blender/draw/CMakeLists.txt index 63405e5fa75..58a7d6f31da 100644 --- a/source/blender/draw/CMakeLists.txt +++ b/source/blender/draw/CMakeLists.txt @@ -494,6 +494,7 @@ set(GLSL_SRC engines/overlay/shaders/grid_vert.glsl engines/overlay/shaders/image_vert.glsl engines/overlay/shaders/image_frag.glsl + engines/overlay/shaders/motion_path_line_frag.glsl engines/overlay/shaders/motion_path_line_geom.glsl engines/overlay/shaders/motion_path_line_vert.glsl engines/overlay/shaders/motion_path_point_vert.glsl diff --git a/source/blender/draw/engines/overlay/overlay_shader.c b/source/blender/draw/engines/overlay/overlay_shader.c index e23c34e1051..701b03bf8b1 100644 --- a/source/blender/draw/engines/overlay/overlay_shader.c +++ b/source/blender/draw/engines/overlay/overlay_shader.c @@ -765,23 +765,10 @@ GPUShader *OVERLAY_shader_image(void) GPUShader *OVERLAY_shader_motion_path_line(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->motion_path_line) { - sh_data->motion_path_line = GPU_shader_create_from_arrays({ - .vert = (const char *[]){sh_cfg->lib, - datatoc_common_globals_lib_glsl, - datatoc_common_view_lib_glsl, - datatoc_motion_path_line_vert_glsl, - NULL}, - .geom = (const char *[]){sh_cfg->lib, - datatoc_common_globals_lib_glsl, - datatoc_common_view_lib_glsl, - datatoc_motion_path_line_geom_glsl, - NULL}, - .frag = (const char *[]){datatoc_gpu_shader_3D_smooth_color_frag_glsl, NULL}, - .defs = (const char *[]){sh_cfg->def, NULL}, - }); + sh_data->motion_path_line = GPU_shader_create_from_info_name( + draw_ctx->sh_cfg ? "overlay_motion_path_line_clipped" : "overlay_motion_path_line"); } return sh_data->motion_path_line; } @@ -789,18 +776,10 @@ GPUShader *OVERLAY_shader_motion_path_line(void) GPUShader *OVERLAY_shader_motion_path_vert(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->motion_path_vert) { - sh_data->motion_path_vert = GPU_shader_create_from_arrays({ - .vert = (const char *[]){sh_cfg->lib, - datatoc_common_globals_lib_glsl, - datatoc_common_view_lib_glsl, - datatoc_motion_path_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->motion_path_vert = GPU_shader_create_from_info_name( + draw_ctx->sh_cfg ? "overlay_motion_path_point_clipped" : "overlay_motion_path_point"); } return sh_data->motion_path_vert; } diff --git a/source/blender/draw/engines/overlay/overlay_shader_shared.h b/source/blender/draw/engines/overlay/overlay_shader_shared.h index 268346d8355..99700cdcec4 100644 --- a/source/blender/draw/engines/overlay/overlay_shader_shared.h +++ b/source/blender/draw/engines/overlay/overlay_shader_shared.h @@ -3,6 +3,9 @@ #ifndef GPU_SHADER # include "GPU_shader_shared_utils.h" +# include "DNA_action_types.h" +# include "DNA_view3d_types.h" + # ifdef __cplusplus extern "C" { # else @@ -67,10 +70,15 @@ BLI_STATIC_ASSERT_ALIGN(OVERLAY_GridData, 16) # define GP_EDIT_STROKE_END 16u /* 1 << 4 */ # define GP_EDIT_POINT_DIMMED 32u /* 1 << 5 */ +# define MOTIONPATH_VERT_SEL (1 << 0) +# define MOTIONPATH_VERT_KEY (1 << 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"); +BLI_STATIC_ASSERT(MOTIONPATH_VERT_SEL == (1 << 0), "Ensure value is sync"); +BLI_STATIC_ASSERT(MOTIONPATH_VERT_KEY == (1 << 1), "Ensure value is sync"); #endif #ifndef GPU_SHADER diff --git a/source/blender/draw/engines/overlay/shaders/infos/extra_info.hh b/source/blender/draw/engines/overlay/shaders/infos/extra_info.hh index d80db60748d..e2ce4329bd7 100644 --- a/source/blender/draw/engines/overlay/shaders/infos/extra_info.hh +++ b/source/blender/draw/engines/overlay/shaders/infos/extra_info.hh @@ -174,3 +174,53 @@ GPU_SHADER_CREATE_INFO(overlay_extra_loose_point_clipped) .additional_info("overlay_extra_loose_point", "drw_clipped"); /** \} */ + +/* -------------------------------------------------------------------- */ +/** \name Motion Path + * \{ */ + +GPU_SHADER_INTERFACE_INFO(overlay_motion_path_line_iface, "interp") + .flat(Type::VEC2, "ss_pos") + .smooth(Type::VEC4, "color"); + +GPU_SHADER_CREATE_INFO(overlay_motion_path_line) + .do_static_compilation(true) + .vertex_in(0, Type::VEC3, "pos") + .push_constant(Type::IVEC4, "mpathLineSettings") + .push_constant(Type::BOOL, "selected") + .push_constant(Type::VEC3, "customColor") + .push_constant(Type::INT, "lineThickness") /* In pixels. */ + .vertex_out(overlay_motion_path_line_iface) + .geometry_out(overlay_motion_path_line_iface) + .geometry_layout(PrimitiveIn::LINES, PrimitiveOut::TRIANGLE_STRIP, 4) + .fragment_out(0, Type::VEC4, "fragColor") + .vertex_source("motion_path_line_vert.glsl") + .geometry_source("motion_path_line_geom.glsl") + .fragment_source("motion_path_line_frag.glsl") + .additional_info("draw_view", "draw_globals"); + +GPU_SHADER_CREATE_INFO(overlay_motion_path_line_clipped) + .do_static_compilation(true) + .additional_info("overlay_motion_path_line", "drw_clipped"); + +GPU_SHADER_INTERFACE_INFO(overlay_motion_path_point_iface, "").flat(Type::VEC4, "finalColor"); + +GPU_SHADER_CREATE_INFO(overlay_motion_path_point) + .do_static_compilation(true) + .typedef_source("overlay_shader_shared.h") + .vertex_in(0, Type::VEC3, "pos") + .vertex_in(1, Type::INT, "flag") + .push_constant(Type::IVEC4, "mpathPointSettings") + .push_constant(Type::BOOL, "showKeyFrames") + .push_constant(Type::VEC3, "customColor") + .vertex_out(overlay_motion_path_point_iface) + .fragment_out(0, Type::VEC4, "fragColor") + .vertex_source("motion_path_point_vert.glsl") + .fragment_source("gpu_shader_point_varying_color_frag.glsl") + .additional_info("draw_view", "draw_globals"); + +GPU_SHADER_CREATE_INFO(overlay_motion_path_point_clipped) + .do_static_compilation(true) + .additional_info("overlay_motion_path_point", "drw_clipped"); + +/** \} */ diff --git a/source/blender/draw/engines/overlay/shaders/motion_path_line_frag.glsl b/source/blender/draw/engines/overlay/shaders/motion_path_line_frag.glsl new file mode 100644 index 00000000000..324d22501f9 --- /dev/null +++ b/source/blender/draw/engines/overlay/shaders/motion_path_line_frag.glsl @@ -0,0 +1,5 @@ + +void main() +{ + fragColor = interp.color; +} diff --git a/source/blender/draw/engines/overlay/shaders/motion_path_line_geom.glsl b/source/blender/draw/engines/overlay/shaders/motion_path_line_geom.glsl index 95e5b08049e..29346a44863 100644 --- a/source/blender/draw/engines/overlay/shaders/motion_path_line_geom.glsl +++ b/source/blender/draw/engines/overlay/shaders/motion_path_line_geom.glsl @@ -1,13 +1,6 @@ -layout(lines) in; -layout(triangle_strip, max_vertices = 4) out; - -uniform int lineThickness = 2; - -in vec4 finalColor_geom[]; -in vec2 ssPos[]; - -out vec4 finalColor; +#pragma BLENDER_REQUIRE(common_view_clipping_lib.glsl) +#pragma BLENDER_REQUIRE(common_view_lib.glsl) vec2 compute_dir(vec2 v0, vec2 v1) { @@ -19,25 +12,22 @@ vec2 compute_dir(vec2 v0, vec2 v1) void main(void) { vec2 t; - vec2 edge_dir = compute_dir(ssPos[0], ssPos[1]) * sizeViewportInv.xy; + vec2 edge_dir = compute_dir(interp_in[0].ss_pos, interp_in[1].ss_pos) * + drw_view.viewport_size_inverse; bool is_persp = (ProjectionMatrix[3][3] == 0.0); float line_size = float(lineThickness) * sizePixel; -#ifdef USE_WORLD_CLIP_PLANES - world_clip_planes_set_clip_distance(gl_in[0].gl_ClipDistance); -#endif - finalColor = finalColor_geom[0]; + view_clipping_distances_set(gl_in[0]); + interp_out.color = interp_in[0].color; t = edge_dir * (line_size * (is_persp ? gl_in[0].gl_Position.w : 1.0)); gl_Position = gl_in[0].gl_Position + vec4(t, 0.0, 0.0); EmitVertex(); gl_Position = gl_in[0].gl_Position - vec4(t, 0.0, 0.0); EmitVertex(); -#ifdef USE_WORLD_CLIP_PLANES - world_clip_planes_set_clip_distance(gl_in[1].gl_ClipDistance); -#endif - finalColor = finalColor_geom[1]; + view_clipping_distances_set(gl_in[1]); + interp_out.color = interp_in[1].color; t = edge_dir * (line_size * (is_persp ? gl_in[1].gl_Position.w : 1.0)); gl_Position = gl_in[1].gl_Position + vec4(t, 0.0, 0.0); EmitVertex(); diff --git a/source/blender/draw/engines/overlay/shaders/motion_path_line_vert.glsl b/source/blender/draw/engines/overlay/shaders/motion_path_line_vert.glsl index 7486f287a79..bc74a436f5e 100644 --- a/source/blender/draw/engines/overlay/shaders/motion_path_line_vert.glsl +++ b/source/blender/draw/engines/overlay/shaders/motion_path_line_vert.glsl @@ -1,18 +1,12 @@ -uniform ivec4 mpathLineSettings; -uniform bool selected; -uniform vec3 customColor; +#pragma BLENDER_REQUIRE(common_view_clipping_lib.glsl) +#pragma BLENDER_REQUIRE(common_view_lib.glsl) #define frameCurrent mpathLineSettings.x #define frameStart mpathLineSettings.y #define frameEnd mpathLineSettings.z #define cacheStart mpathLineSettings.w -in vec3 pos; - -out vec2 ssPos; -out vec4 finalColor_geom; - /* project to screen space */ vec2 proj(vec4 pos) { @@ -26,7 +20,7 @@ void main() { gl_Position = ViewProjectionMatrix * vec4(pos, 1.0); - ssPos = proj(gl_Position); + interp.ss_pos = proj(gl_Position); int frame = gl_VertexID + cacheStart; @@ -40,7 +34,7 @@ void main() if (frame < frameCurrent) { if (use_custom_color) { /* Custom color: previous frames color is darker than current frame */ - finalColor_geom.rgb = customColor * 0.25; + interp.color.rgb = customColor * 0.25; } else { /* black - before frameCurrent */ @@ -50,13 +44,13 @@ void main() else { intensity = SET_INTENSITY(frameStart, frame, frameCurrent, 0.68, 0.92); } - finalColor_geom.rgb = mix(colorWire.rgb, blend_base, intensity); + interp.color.rgb = mix(colorWire.rgb, blend_base, intensity); } } else if (frame > frameCurrent) { if (use_custom_color) { /* Custom color: next frames color is equal to user selected color */ - finalColor_geom.rgb = customColor; + interp.color.rgb = customColor; } else { /* blue - after frameCurrent */ @@ -67,13 +61,13 @@ void main() intensity = SET_INTENSITY(frameCurrent, frame, frameEnd, 0.68, 0.92); } - finalColor_geom.rgb = mix(colorBonePose.rgb, blend_base, intensity); + interp.color.rgb = mix(colorBonePose.rgb, blend_base, intensity); } } else { if (use_custom_color) { /* Custom color: current frame color is slightly darker than user selected color */ - finalColor_geom.rgb = customColor * 0.5; + interp.color.rgb = customColor * 0.5; } else { /* green - on frameCurrent */ @@ -83,13 +77,11 @@ void main() else { intensity = 0.75f; } - finalColor_geom.rgb = mix(colorBackground.rgb, blend_base, intensity); + interp.color.rgb = mix(colorBackground.rgb, blend_base, intensity); } } - finalColor_geom.a = 1.0; + interp.color.a = 1.0; -#ifdef USE_WORLD_CLIP_PLANES - world_clip_planes_calc_clip_distance(pos); -#endif + view_clipping_distances(pos); } diff --git a/source/blender/draw/engines/overlay/shaders/motion_path_point_vert.glsl b/source/blender/draw/engines/overlay/shaders/motion_path_point_vert.glsl index 14335eb1b99..5027525b9b3 100644 --- a/source/blender/draw/engines/overlay/shaders/motion_path_point_vert.glsl +++ b/source/blender/draw/engines/overlay/shaders/motion_path_point_vert.glsl @@ -1,21 +1,12 @@ -uniform ivec4 mpathPointSettings; -uniform bool showKeyFrames = true; -uniform vec3 customColor; +#pragma BLENDER_REQUIRE(common_view_clipping_lib.glsl) +#pragma BLENDER_REQUIRE(common_view_lib.glsl) #define pointSize mpathPointSettings.x #define frameCurrent mpathPointSettings.y #define cacheStart mpathPointSettings.z #define stepSize mpathPointSettings.w -in vec3 pos; -in int flag; - -#define MOTIONPATH_VERT_SEL (1 << 0) -#define MOTIONPATH_VERT_KEY (1 << 1) - -out vec4 finalColor; - void main() { gl_Position = ViewProjectionMatrix * vec4(pos, 1.0); @@ -52,7 +43,5 @@ void main() gl_PointSize *= sizePixel; -#ifdef USE_WORLD_CLIP_PLANES - world_clip_planes_calc_clip_distance(pos); -#endif + view_clipping_distances(pos); } -- cgit v1.2.3