Vulkan: Convert Overlay Stage Interfaces

Convert overlay stage interfaces to be compatible with vulkan.

Pull Request: https://projects.blender.org/blender/blender/pulls/111218
This commit is contained in:
Jeroen Bakker
2023-08-17 15:47:36 +02:00
parent d0dcfb8159
commit 667be8c49d
13 changed files with 80 additions and 45 deletions

View File

@@ -69,7 +69,8 @@ GPU_SHADER_INTERFACE_INFO(overlay_armature_shape_outline_iface, "geom_in")
.smooth(Type::VEC3, "vPos")
.smooth(Type::VEC2, "ssPos")
.smooth(Type::VEC2, "ssNor")
.smooth(Type::VEC4, "vColSize")
.smooth(Type::VEC4, "vColSize");
GPU_SHADER_INTERFACE_INFO(overlay_armature_shape_outline_flat_iface, "geom_flat_in")
.flat(Type::INT, "inverted");
GPU_SHADER_INTERFACE_INFO(overlay_armature_shape_outline_no_geom_iface, "")
@@ -85,6 +86,7 @@ GPU_SHADER_CREATE_INFO(overlay_armature_shape_outline)
.vertex_in(2, Type::VEC4, "color")
.vertex_in(3, Type::MAT4, "inst_obmat")
.vertex_out(overlay_armature_shape_outline_iface)
.vertex_out(overlay_armature_shape_outline_flat_iface)
.geometry_layout(PrimitiveIn::LINES_ADJACENCY, PrimitiveOut::LINE_STRIP, 2)
.geometry_out(overlay_armature_wire_iface)
.vertex_source("overlay_armature_shape_outline_vert.glsl")

View File

@@ -73,8 +73,11 @@ GPU_SHADER_INTERFACE_INFO(overlay_edit_mesh_edge_iface, "geometry_in")
.smooth(Type::UINT, "selectOverride_");
GPU_SHADER_INTERFACE_INFO(overlay_edit_mesh_edge_geom_iface, "geometry_out")
.smooth(Type::VEC4, "finalColor")
.flat(Type::VEC4, "finalColorOuter")
.smooth(Type::VEC4, "finalColor");
GPU_SHADER_INTERFACE_INFO(overlay_edit_mesh_edge_geom_flat_iface, "geometry_flat_out")
.flat(Type::VEC4, "finalColorOuter");
GPU_SHADER_INTERFACE_INFO(overlay_edit_mesh_edge_geom_noperspective_iface,
"geometry_noperspective_out")
.no_perspective(Type::FLOAT, "edgeCoord");
GPU_SHADER_CREATE_INFO(overlay_edit_mesh_edge)
@@ -86,6 +89,8 @@ GPU_SHADER_CREATE_INFO(overlay_edit_mesh_edge)
.push_constant(Type::BOOL, "do_smooth_wire")
.vertex_out(overlay_edit_mesh_edge_iface)
.geometry_out(overlay_edit_mesh_edge_geom_iface)
.geometry_out(overlay_edit_mesh_edge_geom_flat_iface)
.geometry_out(overlay_edit_mesh_edge_geom_noperspective_iface)
.geometry_layout(PrimitiveIn::LINES, PrimitiveOut::TRIANGLE_STRIP, 4)
.geometry_source("overlay_edit_mesh_geom.glsl")
.fragment_source("overlay_edit_mesh_frag.glsl")
@@ -102,6 +107,8 @@ GPU_SHADER_CREATE_INFO(overlay_edit_mesh_edge_no_geom)
.vertex_in(2, Type::VEC3_101010I2, "vnor")
.push_constant(Type::BOOL, "do_smooth_wire")
.vertex_out(overlay_edit_mesh_edge_geom_iface)
.vertex_out(overlay_edit_mesh_edge_geom_flat_iface)
.vertex_out(overlay_edit_mesh_edge_geom_noperspective_iface)
.fragment_source("overlay_edit_mesh_frag.glsl")
.additional_info("overlay_edit_mesh_common_no_geom");
#endif
@@ -233,16 +240,19 @@ GPU_SHADER_CREATE_INFO(overlay_edit_mesh_skin_root_clipped)
/** \name Edit UV
* \{ */
GPU_SHADER_INTERFACE_INFO(overlay_edit_uv_iface, "geom_in")
.smooth(Type::FLOAT, "selectionFac")
.no_perspective(Type::VEC2, "stipplePos")
GPU_SHADER_INTERFACE_INFO(overlay_edit_uv_iface, "geom_in").smooth(Type::FLOAT, "selectionFac");
GPU_SHADER_INTERFACE_INFO(overlay_edit_uv_flat_iface, "geom_flat_in")
.flat(Type::VEC2, "stippleStart");
GPU_SHADER_INTERFACE_INFO(overlay_edit_uv_noperspective_iface, "geom_noperspective_in")
.no_perspective(Type::VEC2, "stipplePos");
GPU_SHADER_INTERFACE_INFO(overlay_edit_uv_geom_iface, "geom_out")
.smooth(Type::FLOAT, "selectionFac")
.no_perspective(Type::FLOAT, "edgeCoord")
.no_perspective(Type::VEC2, "stipplePos")
.smooth(Type::FLOAT, "selectionFac");
GPU_SHADER_INTERFACE_INFO(overlay_edit_uv_geom_flat_iface, "geom_flat_out")
.flat(Type::VEC2, "stippleStart");
GPU_SHADER_INTERFACE_INFO(overlay_edit_uv_geom_noperspective_iface, "geom_noperspective_out")
.no_perspective(Type::FLOAT, "edgeCoord")
.no_perspective(Type::VEC2, "stipplePos");
GPU_SHADER_CREATE_INFO(overlay_edit_uv_edges_common)
.vertex_in(0, Type::VEC2, "au")
@@ -259,8 +269,12 @@ GPU_SHADER_CREATE_INFO(overlay_edit_uv_edges)
.additional_info("overlay_edit_uv_edges_common")
.do_static_compilation(true)
.vertex_out(overlay_edit_uv_iface)
.vertex_out(overlay_edit_uv_flat_iface)
.vertex_out(overlay_edit_uv_noperspective_iface)
.geometry_layout(PrimitiveIn::LINES, PrimitiveOut::TRIANGLE_STRIP, 4)
.geometry_out(overlay_edit_uv_geom_iface)
.geometry_out(overlay_edit_uv_geom_flat_iface)
.geometry_out(overlay_edit_uv_geom_noperspective_iface)
.vertex_source("overlay_edit_uv_edges_vert.glsl")
.geometry_source("overlay_edit_uv_edges_geom.glsl");
@@ -270,6 +284,8 @@ GPU_SHADER_CREATE_INFO(overlay_edit_uv_edges_no_geom)
.additional_info("overlay_edit_uv_edges_common")
.do_static_compilation(true)
.vertex_out(overlay_edit_uv_geom_iface)
.vertex_out(overlay_edit_uv_geom_flat_iface)
.vertex_out(overlay_edit_uv_geom_noperspective_iface)
.vertex_source("overlay_edit_uv_edges_vert_no_geom.glsl");
#endif

View File

@@ -182,12 +182,9 @@ GPU_SHADER_CREATE_INFO(overlay_extra_loose_point_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_INTERFACE_INFO(overlay_motion_path_line_no_geom_iface, "interp")
.smooth(Type::VEC4, "color");
GPU_SHADER_INTERFACE_INFO(overlay_motion_path_line_iface, "interp").smooth(Type::VEC4, "color");
GPU_SHADER_INTERFACE_INFO(overlay_motion_path_line_flat_iface, "interp_flat")
.flat(Type::VEC2, "ss_pos");
GPU_SHADER_CREATE_INFO(overlay_motion_path_line)
.do_static_compilation(true)
@@ -197,6 +194,7 @@ GPU_SHADER_CREATE_INFO(overlay_motion_path_line)
.push_constant(Type::VEC3, "customColor")
.push_constant(Type::INT, "lineThickness") /* In pixels. */
.vertex_out(overlay_motion_path_line_iface)
.vertex_out(overlay_motion_path_line_flat_iface)
.geometry_out(overlay_motion_path_line_iface)
.geometry_layout(PrimitiveIn::LINES, PrimitiveOut::TRIANGLE_STRIP, 4)
.fragment_out(0, Type::VEC4, "fragColor")
@@ -213,7 +211,7 @@ GPU_SHADER_CREATE_INFO(overlay_motion_path_line_no_geom)
.push_constant(Type::BOOL, "selected")
.push_constant(Type::VEC3, "customColor")
.push_constant(Type::INT, "lineThickness") /* In pixels. */
.vertex_out(overlay_motion_path_line_no_geom_iface)
.vertex_out(overlay_motion_path_line_iface)
.fragment_out(0, Type::VEC4, "fragColor")
.vertex_source("overlay_motion_path_line_vert_no_geom.glsl")
.fragment_source("overlay_motion_path_line_frag.glsl")

View File

@@ -66,13 +66,13 @@ GPU_SHADER_CREATE_INFO(overlay_outline_prepass_wire_clipped)
.do_static_compilation(true)
.additional_info("overlay_outline_prepass_wire", "drw_clipped");
GPU_SHADER_INTERFACE_INFO(overlay_outline_prepass_gpencil_flat_iface, "gp_interp_flat")
.flat(Type::VEC2, "aspect")
.flat(Type::VEC4, "sspos");
GPU_SHADER_INTERFACE_INFO(overlay_outline_prepass_gpencil_noperspective_iface,
"gp_interp_noperspective")
.no_perspective(Type::VEC2, "thickness")
.no_perspective(Type::FLOAT, "hardness");
GPU_SHADER_INTERFACE_INFO(overlay_outline_prepass_gpencil_flat_iface, "gp_interp_flat")
.flat(Type::VEC2, "aspect")
.flat(Type::VEC4, "sspos");
GPU_SHADER_CREATE_INFO(overlay_outline_prepass_gpencil)
.do_static_compilation(true)

View File

@@ -28,7 +28,7 @@ void main(void)
}
}
n0 = (geom_in[0].inverted == 1) ? -n0 : n0;
n0 = (geom_flat_in[0].inverted == 1) ? -n0 : n0;
/* Don't outline if concave edge. */
if (dot(n0, v13) > 0.0001) {
return;

View File

@@ -19,7 +19,8 @@ void main()
geom_in.vPos = view_pos.xyz;
geom_in.pPos = drw_view.winmat * view_pos;
geom_in.inverted = int(dot(cross(model_mat[0].xyz, model_mat[1].xyz), model_mat[2].xyz) < 0.0);
geom_flat_in.inverted = int(dot(cross(model_mat[0].xyz, model_mat[1].xyz), model_mat[2].xyz) <
0.0);
/* This is slow and run per vertex, but it's still faster than
* doing it per instance on CPU and sending it on via instance attribute. */

View File

@@ -29,16 +29,16 @@ float edge_step(float dist)
void main()
{
float dist = abs(geometry_out.edgeCoord) - max(sizeEdge - 0.5, 0.0);
float dist = abs(geometry_noperspective_out.edgeCoord) - max(sizeEdge - 0.5, 0.0);
float dist_outer = dist - max(sizeEdge, 1.0);
float mix_w = edge_step(dist);
float mix_w_outer = edge_step(dist_outer);
/* Line color & alpha. */
fragColor = mix(geometry_out.finalColorOuter,
fragColor = mix(geometry_flat_out.finalColorOuter,
geometry_out.finalColor,
1.0 - mix_w * geometry_out.finalColorOuter.a);
1.0 - mix_w * geometry_flat_out.finalColorOuter.a);
/* Line edges shape. */
fragColor.a *= 1.0 - (geometry_out.finalColorOuter.a > 0.0 ? mix_w_outer : mix_w);
fragColor.a *= 1.0 - (geometry_flat_out.finalColorOuter.a > 0.0 ? mix_w_outer : mix_w);
fragColor.a *= test_occlusion() ? alpha : 1.0;
}

View File

@@ -5,7 +5,7 @@
void do_vertex(vec4 color, vec4 pos, float coord, vec2 offset)
{
geometry_out.finalColor = color;
geometry_out.edgeCoord = coord;
geometry_noperspective_out.edgeCoord = coord;
gl_Position = pos;
/* Multiply offset by 2 because gl_Position range is [-1..1]. */
gl_Position.xy += offset * 2.0 * pos.w;
@@ -46,10 +46,10 @@ void main()
vec2 line = ss_pos[0] - ss_pos[1];
line = abs(line) * sizeViewport.xy;
geometry_out.finalColorOuter = geometry_in[0].finalColorOuter_;
geometry_flat_out.finalColorOuter = geometry_in[0].finalColorOuter_;
float half_size = sizeEdge;
/* Enlarge edge for flag display. */
half_size += (geometry_out.finalColorOuter.a > 0.0) ? max(sizeEdge, 1.0) : 0.0;
half_size += (geometry_flat_out.finalColorOuter.a > 0.0) ? max(sizeEdge, 1.0) : 0.0;
if (do_smooth_wire) {
/* Add 1 px for AA */

View File

@@ -17,8 +17,9 @@ void main()
vec4 inner_color = vec4(vec3(0.0), 1.0);
vec4 outer_color = vec4(0.0);
vec2 dd = fwidth(geom_out.stipplePos);
float line_distance = distance(geom_out.stipplePos, geom_out.stippleStart) / max(dd.x, dd.y);
vec2 dd = fwidth(geom_noperspective_out.stipplePos);
float line_distance = distance(geom_noperspective_out.stipplePos, geom_flat_out.stippleStart) /
max(dd.x, dd.y);
if (lineStyle == OVERLAY_UV_LINE_STYLE_OUTLINE) {
#ifdef USE_EDGE_SELECT
@@ -47,7 +48,7 @@ void main()
inner_color = colorUVShadow;
}
float dist = abs(geom_out.edgeCoord) - max(sizeEdge - 0.5, 0.0);
float dist = abs(geom_noperspective_out.edgeCoord) - max(sizeEdge - 0.5, 0.0);
float dist_outer = dist - max(sizeEdge, 1.0);
float mix_w;
float mix_w_outer;

View File

@@ -4,9 +4,9 @@ void do_vertex(
vec4 pos, float selection_fac, vec2 stipple_start, vec2 stipple_pos, float coord, vec2 offset)
{
geom_out.selectionFac = selection_fac;
geom_out.edgeCoord = coord;
geom_out.stippleStart = stipple_start;
geom_out.stipplePos = stipple_pos;
geom_noperspective_out.edgeCoord = coord;
geom_flat_out.stippleStart = stipple_start;
geom_noperspective_out.stipplePos = stipple_pos;
gl_Position = pos;
/* Multiply offset by 2 because gl_Position range is [-1..1]. */
@@ -44,14 +44,30 @@ void main()
selectFac1 = selectFac0;
#endif
do_vertex(
pos0, selectFac0, geom_in[0].stippleStart, geom_in[0].stipplePos, half_size, edge_ofs.xy);
do_vertex(
pos0, selectFac0, geom_in[0].stippleStart, geom_in[0].stipplePos, -half_size, -edge_ofs.xy);
do_vertex(
pos1, selectFac1, geom_in[1].stippleStart, geom_in[1].stipplePos, half_size, edge_ofs.xy);
do_vertex(
pos1, selectFac1, geom_in[1].stippleStart, geom_in[1].stipplePos, -half_size, -edge_ofs.xy);
do_vertex(pos0,
selectFac0,
geom_flat_in[0].stippleStart,
geom_noperspective_in[0].stipplePos,
half_size,
edge_ofs.xy);
do_vertex(pos0,
selectFac0,
geom_flat_in[0].stippleStart,
geom_noperspective_in[0].stipplePos,
-half_size,
-edge_ofs.xy);
do_vertex(pos1,
selectFac1,
geom_flat_in[1].stippleStart,
geom_noperspective_in[1].stipplePos,
half_size,
edge_ofs.xy);
do_vertex(pos1,
selectFac1,
geom_flat_in[1].stippleStart,
geom_noperspective_in[1].stipplePos,
-half_size,
-edge_ofs.xy);
EndPrimitive();
}

View File

@@ -23,5 +23,6 @@ void main()
gl_Position.z = depth;
/* Avoid precision loss. */
geom_in.stippleStart = geom_in.stipplePos = 500.0 + 500.0 * (gl_Position.xy / gl_Position.w);
geom_flat_in.stippleStart = geom_noperspective_in.stipplePos = 500.0 + 500.0 * (gl_Position.xy /
gl_Position.w);
}

View File

@@ -12,7 +12,7 @@ vec2 compute_dir(vec2 v0, vec2 v1)
void main(void)
{
vec2 t;
vec2 edge_dir = compute_dir(interp_in[0].ss_pos, interp_in[1].ss_pos) * sizeViewportInv;
vec2 edge_dir = compute_dir(interp_flat[0].ss_pos, interp_flat[1].ss_pos) * sizeViewportInv;
bool is_persp = (drw_view.winmat[3][3] == 0.0);
float line_size = float(lineThickness) * sizePixel;

View File

@@ -24,7 +24,7 @@ void main()
{
gl_Position = drw_view.winmat * (drw_view.viewmat * vec4(pos, 1.0));
interp.ss_pos = proj(gl_Position);
interp_flat.ss_pos = proj(gl_Position);
int frame = gl_VertexID + cacheStart;