From 53396816e499d7dea00ec114813474cc25c70e80 Mon Sep 17 00:00:00 2001 From: Jeroen Bakker Date: Thu, 17 Aug 2023 11:31:10 +0200 Subject: [PATCH] Vulkan: Make Polyline Shaders Vulkan Compatible Splitting interface stages based on the interpolation of its attributes. Then naming convention that have been used: * use `interp` as instance name when using smooth interpolation * use `interp_noperspective` when using no perpective interpolation * use `interp_flat` when using flat interpolation The same suffix will be added to the struct names. The naming convention will be added to the GLSL code style and applied to other shaders as well. Pull Request: https://projects.blender.org/blender/blender/pulls/111210 --- .../blender/gpu/shaders/gpu_shader_3D_polyline_frag.glsl | 3 ++- .../blender/gpu/shaders/gpu_shader_3D_polyline_geom.glsl | 4 ++-- .../gpu/shaders/gpu_shader_3D_polyline_vert_no_geom.glsl | 2 +- .../gpu/shaders/infos/gpu_shader_3D_polyline_info.hh | 7 ++++++- 4 files changed, 11 insertions(+), 5 deletions(-) diff --git a/source/blender/gpu/shaders/gpu_shader_3D_polyline_frag.glsl b/source/blender/gpu/shaders/gpu_shader_3D_polyline_frag.glsl index f912bad8a14..f177e5f35fa 100644 --- a/source/blender/gpu/shaders/gpu_shader_3D_polyline_frag.glsl +++ b/source/blender/gpu/shaders/gpu_shader_3D_polyline_frag.glsl @@ -9,7 +9,8 @@ void main() #endif fragColor = interp.final_color; if (lineSmooth) { - fragColor.a *= clamp((lineWidth + SMOOTH_WIDTH) * 0.5 - abs(interp.smoothline), 0.0, 1.0); + fragColor.a *= clamp( + (lineWidth + SMOOTH_WIDTH) * 0.5 - abs(interp_noperspective.smoothline), 0.0, 1.0); } fragColor = blender_srgb_to_framebuffer_space(fragColor); } diff --git a/source/blender/gpu/shaders/gpu_shader_3D_polyline_geom.glsl b/source/blender/gpu/shaders/gpu_shader_3D_polyline_geom.glsl index 6d23e03c835..719215e73b1 100644 --- a/source/blender/gpu/shaders/gpu_shader_3D_polyline_geom.glsl +++ b/source/blender/gpu/shaders/gpu_shader_3D_polyline_geom.glsl @@ -32,12 +32,12 @@ void do_vertex(const int i, vec4 pos, vec2 ofs) interp_out.clip = interp_in[i].clip; #endif - interp_out.smoothline = (lineWidth + SMOOTH_WIDTH * float(lineSmooth)) * 0.5; + interp_noperspective_out.smoothline = (lineWidth + SMOOTH_WIDTH * float(lineSmooth)) * 0.5; gl_Position = pos; gl_Position.xy += ofs * pos.w; EmitVertex(); - interp_out.smoothline = -(lineWidth + SMOOTH_WIDTH * float(lineSmooth)) * 0.5; + interp_noperspective_out.smoothline = -(lineWidth + SMOOTH_WIDTH * float(lineSmooth)) * 0.5; gl_Position = pos; gl_Position.xy -= ofs * pos.w; EmitVertex(); diff --git a/source/blender/gpu/shaders/gpu_shader_3D_polyline_vert_no_geom.glsl b/source/blender/gpu/shaders/gpu_shader_3D_polyline_vert_no_geom.glsl index d546f98d165..2adab6f7a35 100644 --- a/source/blender/gpu/shaders/gpu_shader_3D_polyline_vert_no_geom.glsl +++ b/source/blender/gpu/shaders/gpu_shader_3D_polyline_vert_no_geom.glsl @@ -45,7 +45,7 @@ void do_vertex(int index, vec4 pos, vec2 ofs, float flip) interp.clip = clip_g[index]; #endif - interp.smoothline = flip * (lineWidth + SMOOTH_WIDTH * float(lineSmooth)) * 0.5; + interp_noperspective.smoothline = flip * (lineWidth + SMOOTH_WIDTH * float(lineSmooth)) * 0.5; gl_Position = pos; gl_Position.xy += flip * ofs * pos.w; } diff --git a/source/blender/gpu/shaders/infos/gpu_shader_3D_polyline_info.hh b/source/blender/gpu/shaders/infos/gpu_shader_3D_polyline_info.hh index 17b34edaf5e..4e80ccfde2f 100644 --- a/source/blender/gpu/shaders/infos/gpu_shader_3D_polyline_info.hh +++ b/source/blender/gpu/shaders/infos/gpu_shader_3D_polyline_info.hh @@ -11,7 +11,9 @@ GPU_SHADER_INTERFACE_INFO(gpu_shader_3D_polyline_iface, "interp") .smooth(Type::VEC4, "final_color") - .smooth(Type::FLOAT, "clip") + .smooth(Type::FLOAT, "clip"); + +GPU_SHADER_INTERFACE_INFO(gpu_shader_3D_polyline_noperspective_iface, "interp_noperspective") .no_perspective(Type::FLOAT, "smoothline"); GPU_SHADER_CREATE_INFO(gpu_shader_3D_polyline) @@ -22,8 +24,10 @@ GPU_SHADER_CREATE_INFO(gpu_shader_3D_polyline) .push_constant(Type::BOOL, "lineSmooth") .vertex_in(0, Type::VEC3, "pos") .vertex_out(gpu_shader_3D_polyline_iface) + .vertex_out(gpu_shader_3D_polyline_noperspective_iface) .geometry_layout(PrimitiveIn::LINES, PrimitiveOut::TRIANGLE_STRIP, 4) .geometry_out(gpu_shader_3D_polyline_iface) + .geometry_out(gpu_shader_3D_polyline_noperspective_iface) .fragment_out(0, Type::VEC4, "fragColor") .vertex_source("gpu_shader_3D_polyline_vert.glsl") .geometry_source("gpu_shader_3D_polyline_geom.glsl") @@ -38,6 +42,7 @@ GPU_SHADER_CREATE_INFO(gpu_shader_3D_polyline_no_geom) .push_constant(Type::BOOL, "lineSmooth") .vertex_in(0, Type::VEC3, "pos") .vertex_out(gpu_shader_3D_polyline_iface) + .vertex_out(gpu_shader_3D_polyline_noperspective_iface) .fragment_out(0, Type::VEC4, "fragColor") .vertex_source("gpu_shader_3D_polyline_vert_no_geom.glsl") .fragment_source("gpu_shader_3D_polyline_frag.glsl")