diff options
author | Clément Foucault <foucault.clem@gmail.com> | 2022-10-07 12:01:55 +0300 |
---|---|---|
committer | Clément Foucault <foucault.clem@gmail.com> | 2022-10-07 13:43:10 +0300 |
commit | 70b35c7ad037ba0b97f7892ca286fe5db267cfd8 (patch) | |
tree | 72ebdee99650d78dfa78a9db64287b2dfbc9dc3d | |
parent | 126d485b837d317ead313c46bcd6545d03391020 (diff) |
Overlay: Use global viewport size instead of DRWView one
This is part of the effor to simplify the View struct in order to implement
multiview rendering.
27 files changed, 43 insertions, 193 deletions
diff --git a/source/blender/draw/CMakeLists.txt b/source/blender/draw/CMakeLists.txt index 01268509200..d82ae4cd32c 100644 --- a/source/blender/draw/CMakeLists.txt +++ b/source/blender/draw/CMakeLists.txt @@ -490,7 +490,6 @@ set(GLSL_SRC intern/shaders/common_debug_shape_lib.glsl intern/shaders/common_fullscreen_vert.glsl intern/shaders/common_fxaa_lib.glsl - intern/shaders/common_globals_lib.glsl intern/shaders/common_gpencil_lib.glsl intern/shaders/common_hair_lib.glsl intern/shaders/common_hair_refine_comp.glsl diff --git a/source/blender/draw/engines/overlay/overlay_outline.cc b/source/blender/draw/engines/overlay/overlay_outline.cc index 00ceb930ba5..5ea02376b67 100644 --- a/source/blender/draw/engines/overlay/overlay_outline.cc +++ b/source/blender/draw/engines/overlay/overlay_outline.cc @@ -122,21 +122,25 @@ void OVERLAY_outline_cache_init(OVERLAY_Data *vedata) pd->outlines_grp = grp = DRW_shgroup_create(sh_geom, psl->outlines_prepass_ps); DRW_shgroup_uniform_bool_copy(grp, "isTransform", (G.moving & G_TRANSFORM_OBJ) != 0); + DRW_shgroup_uniform_block(grp, "globalsBlock", G_draw.block_ubo); GPUShader *sh_geom_ptcloud = OVERLAY_shader_outline_prepass_pointcloud(); pd->outlines_ptcloud_grp = grp = DRW_shgroup_create(sh_geom_ptcloud, psl->outlines_prepass_ps); DRW_shgroup_uniform_bool_copy(grp, "isTransform", (G.moving & G_TRANSFORM_OBJ) != 0); + DRW_shgroup_uniform_block(grp, "globalsBlock", G_draw.block_ubo); GPUShader *sh_gpencil = OVERLAY_shader_outline_prepass_gpencil(); pd->outlines_gpencil_grp = grp = DRW_shgroup_create(sh_gpencil, psl->outlines_prepass_ps); DRW_shgroup_uniform_bool_copy(grp, "isTransform", (G.moving & G_TRANSFORM_OBJ) != 0); DRW_shgroup_uniform_float_copy(grp, "gpStrokeIndexOffset", 0.0); + DRW_shgroup_uniform_block(grp, "globalsBlock", G_draw.block_ubo); GPUShader *sh_curves = OVERLAY_shader_outline_prepass_curves(); pd->outlines_curves_grp = grp = DRW_shgroup_create(sh_curves, psl->outlines_prepass_ps); DRW_shgroup_uniform_bool_copy(grp, "isTransform", (G.moving & G_TRANSFORM_OBJ) != 0); + DRW_shgroup_uniform_block(grp, "globalsBlock", G_draw.block_ubo); } /* outlines_prepass_ps is still needed for selection of probes. */ diff --git a/source/blender/draw/engines/overlay/shaders/infos/overlay_outline_info.hh b/source/blender/draw/engines/overlay/shaders/infos/overlay_outline_info.hh index 288fb3b3cbd..abf9e873b29 100644 --- a/source/blender/draw/engines/overlay/shaders/infos/overlay_outline_info.hh +++ b/source/blender/draw/engines/overlay/shaders/infos/overlay_outline_info.hh @@ -14,7 +14,7 @@ GPU_SHADER_CREATE_INFO(overlay_outline_prepass) /* Using uint because 16bit uint can contain more ids than int. */ .fragment_out(0, Type::UINT, "out_object_id") .fragment_source("overlay_outline_prepass_frag.glsl") - .additional_info("draw_resource_handle"); + .additional_info("draw_resource_handle", "draw_globals"); GPU_SHADER_CREATE_INFO(overlay_outline_prepass_mesh) .do_static_compilation(true) @@ -72,7 +72,7 @@ GPU_SHADER_CREATE_INFO(overlay_outline_prepass_gpencil) /* Using uint because 16bit uint can contain more ids than int. */ .fragment_out(0, Type::UINT, "out_object_id") .fragment_source("overlay_outline_prepass_gpencil_frag.glsl") - .additional_info("draw_gpencil", "draw_resource_handle"); + .additional_info("draw_gpencil", "draw_resource_handle", "draw_globals"); GPU_SHADER_CREATE_INFO(overlay_outline_prepass_gpencil_clipped) .do_static_compilation(true) diff --git a/source/blender/draw/engines/overlay/shaders/overlay_armature_envelope_outline_vert.glsl b/source/blender/draw/engines/overlay/shaders/overlay_armature_envelope_outline_vert.glsl index ca5a6aff2ca..c13698728ef 100644 --- a/source/blender/draw/engines/overlay/shaders/overlay_armature_envelope_outline_vert.glsl +++ b/source/blender/draw/engines/overlay/shaders/overlay_armature_envelope_outline_vert.glsl @@ -137,7 +137,7 @@ void main() vec2 ofs_dir = compute_dir(ss0, ss1, ss2); /* Offset away from the center to avoid overlap with solid shape. */ - gl_Position.xy += ofs_dir * drw_view.viewport_size_inverse * gl_Position.w; + gl_Position.xy += ofs_dir * sizeViewportInv * gl_Position.w; edgeStart = edgePos = proj(gl_Position); diff --git a/source/blender/draw/engines/overlay/shaders/overlay_armature_shape_outline_geom.glsl b/source/blender/draw/engines/overlay/shaders/overlay_armature_shape_outline_geom.glsl index b485b0a7807..65a2fcc1977 100644 --- a/source/blender/draw/engines/overlay/shaders/overlay_armature_shape_outline_geom.glsl +++ b/source/blender/draw/engines/overlay/shaders/overlay_armature_shape_outline_geom.glsl @@ -56,7 +56,7 @@ void main(void) gl_Position = geom_in[1].pPos; /* Offset away from the center to avoid overlap with solid shape. */ - gl_Position.xy += (edge_dir - perp) * drw_view.viewport_size_inverse * gl_Position.w; + gl_Position.xy += (edge_dir - perp) * sizeViewportInv * gl_Position.w; /* Improve AA bleeding inside bone silhouette. */ gl_Position.z -= (is_persp) ? 1e-4 : 1e-6; edgeStart = edgePos = ((gl_Position.xy / gl_Position.w) * 0.5 + 0.5) * sizeViewport; @@ -65,7 +65,7 @@ void main(void) gl_Position = geom_in[2].pPos; /* Offset away from the center to avoid overlap with solid shape. */ - gl_Position.xy += (edge_dir + perp) * drw_view.viewport_size_inverse * gl_Position.w; + gl_Position.xy += (edge_dir + perp) * sizeViewportInv * gl_Position.w; /* Improve AA bleeding inside bone silhouette. */ gl_Position.z -= (is_persp) ? 1e-4 : 1e-6; edgeStart = edgePos = ((gl_Position.xy / gl_Position.w) * 0.5 + 0.5) * sizeViewport.xy; diff --git a/source/blender/draw/engines/overlay/shaders/overlay_armature_shape_outline_vert_no_geom.glsl b/source/blender/draw/engines/overlay/shaders/overlay_armature_shape_outline_vert_no_geom.glsl index 87447b9d7ea..57c0ecb0b9b 100644 --- a/source/blender/draw/engines/overlay/shaders/overlay_armature_shape_outline_vert_no_geom.glsl +++ b/source/blender/draw/engines/overlay/shaders/overlay_armature_shape_outline_vert_no_geom.glsl @@ -160,7 +160,7 @@ void main() if (line_vertex_id == 0) { gl_Position = pPos[1]; /* Offset away from the center to avoid overlap with solid shape. */ - gl_Position.xy += (edge_dir - perp) * drw_view.viewport_size_inverse * gl_Position.w; + gl_Position.xy += (edge_dir - perp) * sizeViewportInv * gl_Position.w; /* Improve AA bleeding inside bone silhouette. */ gl_Position.z -= (is_persp) ? 1e-4 : 1e-6; edgeStart = edgePos = ((gl_Position.xy / gl_Position.w) * 0.5 + 0.5) * sizeViewport.xy; @@ -169,7 +169,7 @@ void main() else { gl_Position = pPos[2]; /* Offset away from the center to avoid overlap with solid shape. */ - gl_Position.xy += (edge_dir + perp) * drw_view.viewport_size_inverse * gl_Position.w; + gl_Position.xy += (edge_dir + perp) * sizeViewportInv * gl_Position.w; /* Improve AA bleeding inside bone silhouette. */ gl_Position.z -= (is_persp) ? 1e-4 : 1e-6; edgeStart = edgePos = ((gl_Position.xy / gl_Position.w) * 0.5 + 0.5) * sizeViewport.xy; diff --git a/source/blender/draw/engines/overlay/shaders/overlay_armature_sphere_outline_vert.glsl b/source/blender/draw/engines/overlay/shaders/overlay_armature_sphere_outline_vert.glsl index 4d79fab718f..ef9a0b7bdd6 100644 --- a/source/blender/draw/engines/overlay/shaders/overlay_armature_sphere_outline_vert.glsl +++ b/source/blender/draw/engines/overlay/shaders/overlay_armature_sphere_outline_vert.glsl @@ -63,7 +63,7 @@ void main() /* Offset away from the center to avoid overlap with solid shape. */ vec2 ofs_dir = normalize(proj(gl_Position) - proj(center)); - gl_Position.xy += ofs_dir * drw_view.viewport_size_inverse * gl_Position.w; + gl_Position.xy += ofs_dir * sizeViewportInv * gl_Position.w; edgeStart = edgePos = proj(gl_Position); diff --git a/source/blender/draw/engines/overlay/shaders/overlay_armature_stick_vert.glsl b/source/blender/draw/engines/overlay/shaders/overlay_armature_stick_vert.glsl index e7917a46312..c10a221ef08 100644 --- a/source/blender/draw/engines/overlay/shaders/overlay_armature_stick_vert.glsl +++ b/source/blender/draw/engines/overlay/shaders/overlay_armature_stick_vert.glsl @@ -64,7 +64,7 @@ void main() if (finalInnerColor.a > 0.0) { float stick_size = sizePixel * 5.0; gl_Position = (is_head) ? p0 : p1; - gl_Position.xy += stick_size * (vpos * drw_view.viewport_size_inverse); + gl_Position.xy += stick_size * (vpos * sizeViewportInv); gl_Position.z += (is_bone) ? 0.0 : 1e-6; /* Avoid Z fighting of head/tails. */ view_clipping_distances((is_head ? boneStart_4d : boneEnd_4d).xyz); } diff --git a/source/blender/draw/engines/overlay/shaders/overlay_edit_curve_handle_geom.glsl b/source/blender/draw/engines/overlay/shaders/overlay_edit_curve_handle_geom.glsl index 7d92baea595..c1726f00d66 100644 --- a/source/blender/draw/engines/overlay/shaders/overlay_edit_curve_handle_geom.glsl +++ b/source/blender/draw/engines/overlay/shaders/overlay_edit_curve_handle_geom.glsl @@ -83,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 * drw_view.viewport_size_inverse; /* 4.0 is eyeballed */ + vec2 offset = sizeEdge * 4.0 * sizeViewportInv; /* 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/overlay_edit_mesh_geom.glsl b/source/blender/draw/engines/overlay/shaders/overlay_edit_mesh_geom.glsl index 82f957b2071..257058d7029 100644 --- a/source/blender/draw/engines/overlay/shaders/overlay_edit_mesh_geom.glsl +++ b/source/blender/draw/engines/overlay/shaders/overlay_edit_mesh_geom.glsl @@ -56,7 +56,7 @@ void main() half_size += 0.5; } - vec3 edge_ofs = vec3(half_size * drw_view.viewport_size_inverse, 0.0); + vec3 edge_ofs = vec3(half_size * sizeViewportInv, 0.0); bool horizontal = line.x > line.y; edge_ofs = (horizontal) ? edge_ofs.zyz : edge_ofs.xzz; diff --git a/source/blender/draw/engines/overlay/shaders/overlay_edit_mesh_vert_no_geom.glsl b/source/blender/draw/engines/overlay/shaders/overlay_edit_mesh_vert_no_geom.glsl index 64fad1c449e..fb18b95ccc5 100644 --- a/source/blender/draw/engines/overlay/shaders/overlay_edit_mesh_vert_no_geom.glsl +++ b/source/blender/draw/engines/overlay/shaders/overlay_edit_mesh_vert_no_geom.glsl @@ -181,7 +181,7 @@ void main() half_size += 0.5; #endif - vec3 edge_ofs = vec3(half_size * drw_view.viewport_size_inverse, 0.0); + vec3 edge_ofs = vec3(half_size * sizeViewportInv, 0.0); bool horizontal = line.x > line.y; edge_ofs = (horizontal) ? edge_ofs.zyz : edge_ofs.xzz; diff --git a/source/blender/draw/engines/overlay/shaders/overlay_edit_uv_edges_geom.glsl b/source/blender/draw/engines/overlay/shaders/overlay_edit_uv_edges_geom.glsl index f31ebffd8b8..8038c68476a 100644 --- a/source/blender/draw/engines/overlay/shaders/overlay_edit_uv_edges_geom.glsl +++ b/source/blender/draw/engines/overlay/shaders/overlay_edit_uv_edges_geom.glsl @@ -36,7 +36,7 @@ void main() vec2 line = ss_pos[0] - ss_pos[1]; vec2 line_dir = normalize(line); vec2 line_perp = vec2(-line_dir.y, line_dir.x); - vec2 edge_ofs = line_perp * drw_view.viewport_size_inverse * ceil(half_size); + vec2 edge_ofs = line_perp * sizeViewportInv * ceil(half_size); float selectFac0 = geom_in[0].selectionFac; float selectFac1 = geom_in[1].selectionFac; #ifdef USE_EDGE_SELECT diff --git a/source/blender/draw/engines/overlay/shaders/overlay_edit_uv_edges_vert.glsl b/source/blender/draw/engines/overlay/shaders/overlay_edit_uv_edges_vert.glsl index 23f1a44c321..b7bcfbeb0d4 100644 --- a/source/blender/draw/engines/overlay/shaders/overlay_edit_uv_edges_vert.glsl +++ b/source/blender/draw/engines/overlay/shaders/overlay_edit_uv_edges_vert.glsl @@ -5,8 +5,8 @@ void main() vec3 world_pos = point_object_to_world(vec3(au, 0.0)); gl_Position = point_world_to_ndc(world_pos); /* Snap vertices to the pixel grid to reduce artifacts. */ - vec2 half_viewport_res = drw_view.viewport_size * 0.5; - vec2 half_pixel_offset = drw_view.viewport_size_inverse * 0.5; + vec2 half_viewport_res = sizeViewport * 0.5; + vec2 half_pixel_offset = sizeViewportInv * 0.5; gl_Position.xy = floor(gl_Position.xy * half_viewport_res) / half_viewport_res + half_pixel_offset; diff --git a/source/blender/draw/engines/overlay/shaders/overlay_extra_vert.glsl b/source/blender/draw/engines/overlay/shaders/overlay_extra_vert.glsl index 269da0fd196..7b1e29525e9 100644 --- a/source/blender/draw/engines/overlay/shaders/overlay_extra_vert.glsl +++ b/source/blender/draw/engines/overlay/shaders/overlay_extra_vert.glsl @@ -218,8 +218,7 @@ void main() /* HACK: to avoid losing sub-pixel object in selections, we add a bit of randomness to the * wire to at least create one fragment that will pass the occlusion query. */ /* TODO(fclem): Limit this workaround to selection. It's not very noticeable but still... */ - gl_Position.xy += drw_view.viewport_size_inverse * gl_Position.w * - ((gl_VertexID % 2 == 0) ? -1.0 : 1.0); + gl_Position.xy += sizeViewportInv * gl_Position.w * ((gl_VertexID % 2 == 0) ? -1.0 : 1.0); #endif view_clipping_distances(world_pos); diff --git a/source/blender/draw/engines/overlay/shaders/overlay_extra_wire_vert.glsl b/source/blender/draw/engines/overlay/shaders/overlay_extra_wire_vert.glsl index cd217021e8f..efa4e4706f3 100644 --- a/source/blender/draw/engines/overlay/shaders/overlay_extra_wire_vert.glsl +++ b/source/blender/draw/engines/overlay/shaders/overlay_extra_wire_vert.glsl @@ -16,8 +16,7 @@ void main() /* HACK: to avoid losing sub-pixel object in selections, we add a bit of randomness to the * wire to at least create one fragment that will pass the occlusion query. */ /* TODO(fclem): Limit this workaround to selection. It's not very noticeable but still... */ - gl_Position.xy += drw_view.viewport_size_inverse * gl_Position.w * - ((gl_VertexID % 2 == 0) ? -1.0 : 1.0); + gl_Position.xy += sizeViewportInv * gl_Position.w * ((gl_VertexID % 2 == 0) ? -1.0 : 1.0); #endif stipple_coord = stipple_start = screen_position(gl_Position); diff --git a/source/blender/draw/engines/overlay/shaders/overlay_motion_path_line_geom.glsl b/source/blender/draw/engines/overlay/shaders/overlay_motion_path_line_geom.glsl index 25e13e7c212..32a38db140a 100644 --- a/source/blender/draw/engines/overlay/shaders/overlay_motion_path_line_geom.glsl +++ b/source/blender/draw/engines/overlay/shaders/overlay_motion_path_line_geom.glsl @@ -12,8 +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) * - drw_view.viewport_size_inverse; + vec2 edge_dir = compute_dir(interp_in[0].ss_pos, interp_in[1].ss_pos) * sizeViewportInv; bool is_persp = (drw_view.winmat[3][3] == 0.0); float line_size = float(lineThickness) * sizePixel; diff --git a/source/blender/draw/engines/overlay/shaders/overlay_motion_path_line_vert_no_geom.glsl b/source/blender/draw/engines/overlay/shaders/overlay_motion_path_line_vert_no_geom.glsl index 9b6591cc543..e3ddeb5c6a4 100644 --- a/source/blender/draw/engines/overlay/shaders/overlay_motion_path_line_vert_no_geom.glsl +++ b/source/blender/draw/engines/overlay/shaders/overlay_motion_path_line_vert_no_geom.glsl @@ -124,7 +124,7 @@ void main() * Each vertex shader invocation is one vertex in the output primitive, so outptut * required ID. */ vec2 t; - vec2 edge_dir = compute_dir(ssPos[0], ssPos[1]) * drw_view.viewport_size_inverse; + vec2 edge_dir = compute_dir(ssPos[0], ssPos[1]) * sizeViewportInv; bool is_persp = (ProjectionMatrix[3][3] == 0.0); float line_size = float(lineThickness) * sizePixel; diff --git a/source/blender/draw/engines/overlay/shaders/overlay_outline_detect_frag.glsl b/source/blender/draw/engines/overlay/shaders/overlay_outline_detect_frag.glsl index 472a589f441..18914b0276f 100644 --- a/source/blender/draw/engines/overlay/shaders/overlay_outline_detect_frag.glsl +++ b/source/blender/draw/engines/overlay/shaders/overlay_outline_detect_frag.glsl @@ -36,7 +36,7 @@ bvec4 gather_edges(vec2 uv, uint ref) #ifdef GPU_ARB_texture_gather ids = textureGather(outlineId, uv); #else - vec3 ofs = vec3(0.5, 0.5, -0.5) * drw_view.viewport_size_inverse.xyy; + vec3 ofs = vec3(0.5, 0.5, -0.5) * sizeViewportInv.xyy; ids.x = textureLod(outlineId, uv - ofs.xz, 0.0).r; ids.y = textureLod(outlineId, uv + ofs.xy, 0.0).r; ids.z = textureLod(outlineId, uv + ofs.xz, 0.0).r; @@ -161,8 +161,8 @@ void main() uint ref = textureLod(outlineId, uvcoordsvar.xy, 0.0).r; uint ref_col = ref; - vec2 uvs = gl_FragCoord.xy * drw_view.viewport_size_inverse; - vec3 ofs = vec3(drw_view.viewport_size_inverse.xy, 0.0); + vec2 uvs = gl_FragCoord.xy * sizeViewportInv; + vec3 ofs = vec3(sizeViewportInv.xy, 0.0); vec2 depth_uv = uvs; @@ -269,13 +269,13 @@ void main() switch (edge_case) { /* Straight lines. */ case YPOS: - extra_edges = gather_edges(uvs + drw_view.viewport_size_inverse * vec2(2.5, 0.5), ref); - extra_edges2 = gather_edges(uvs + drw_view.viewport_size_inverse * vec2(-2.5, 0.5), ref); + extra_edges = gather_edges(uvs + sizeViewportInv * vec2(2.5, 0.5), ref); + extra_edges2 = gather_edges(uvs + sizeViewportInv * vec2(-2.5, 0.5), ref); straight_line_dir(extra_edges, extra_edges2, line_start, line_end); break; case YNEG: - extra_edges = gather_edges(uvs + drw_view.viewport_size_inverse * vec2(-2.5, -0.5), ref); - extra_edges2 = gather_edges(uvs + drw_view.viewport_size_inverse * vec2(2.5, -0.5), ref); + extra_edges = gather_edges(uvs + sizeViewportInv * vec2(-2.5, -0.5), ref); + extra_edges2 = gather_edges(uvs + sizeViewportInv * vec2(2.5, -0.5), ref); extra_edges = rotate_180(extra_edges); extra_edges2 = rotate_180(extra_edges2); straight_line_dir(extra_edges, extra_edges2, line_start, line_end); @@ -283,8 +283,8 @@ void main() line_end = rotate_180(line_end); break; case XPOS: - extra_edges = gather_edges(uvs + drw_view.viewport_size_inverse * vec2(0.5, 2.5), ref); - extra_edges2 = gather_edges(uvs + drw_view.viewport_size_inverse * vec2(0.5, -2.5), ref); + extra_edges = gather_edges(uvs + sizeViewportInv * vec2(0.5, 2.5), ref); + extra_edges2 = gather_edges(uvs + sizeViewportInv * vec2(0.5, -2.5), ref); extra_edges = rotate_90(extra_edges); extra_edges2 = rotate_90(extra_edges2); straight_line_dir(extra_edges, extra_edges2, line_start, line_end); @@ -292,8 +292,8 @@ void main() line_end = rotate_90(line_end); break; case XNEG: - extra_edges = gather_edges(uvs + drw_view.viewport_size_inverse * vec2(-0.5, 2.5), ref); - extra_edges2 = gather_edges(uvs + drw_view.viewport_size_inverse * vec2(-0.5, -2.5), ref); + extra_edges = gather_edges(uvs + sizeViewportInv * vec2(-0.5, 2.5), ref); + extra_edges2 = gather_edges(uvs + sizeViewportInv * vec2(-0.5, -2.5), ref); extra_edges = rotate_270(extra_edges); extra_edges2 = rotate_270(extra_edges2); straight_line_dir(extra_edges, extra_edges2, line_start, line_end); diff --git a/source/blender/draw/engines/overlay/shaders/overlay_outline_prepass_curves_vert.glsl b/source/blender/draw/engines/overlay/shaders/overlay_outline_prepass_curves_vert.glsl index f9ec475d21f..27150d1cb3d 100644 --- a/source/blender/draw/engines/overlay/shaders/overlay_outline_prepass_curves_vert.glsl +++ b/source/blender/draw/engines/overlay/shaders/overlay_outline_prepass_curves_vert.glsl @@ -45,8 +45,8 @@ void main() vec3 world_pos; if (hairThicknessRes > 1) { /* Calculate the thickness, thicktime, worldpos taken into account the outline. */ - float outline_width = point_world_to_ndc(center_wpos).w * 1.25 * - drw_view.viewport_size_inverse.y * drw_view.wininv[1][1]; + float outline_width = point_world_to_ndc(center_wpos).w * 1.25 * sizeViewportInv.y * + drw_view.wininv[1][1]; thickness += outline_width; float thick_time = float(gl_VertexID % hairThicknessRes) / float(hairThicknessRes - 1); thick_time = thickness * (thick_time * 2.0 - 1.0); diff --git a/source/blender/draw/engines/overlay/shaders/overlay_outline_prepass_gpencil_frag.glsl b/source/blender/draw/engines/overlay/shaders/overlay_outline_prepass_gpencil_frag.glsl index a575d42231e..2b7c3f06769 100644 --- a/source/blender/draw/engines/overlay/shaders/overlay_outline_prepass_gpencil_frag.glsl +++ b/source/blender/draw/engines/overlay/shaders/overlay_outline_prepass_gpencil_frag.glsl @@ -23,7 +23,7 @@ void main() if (!gpStrokeOrder3d) { /* Stroke order 2D. Project to gpDepthPlane. */ bool is_persp = drw_view.winmat[3][3] == 0.0; - vec2 uvs = vec2(gl_FragCoord.xy) * drw_view.viewport_size_inverse; + vec2 uvs = vec2(gl_FragCoord.xy) * sizeViewportInv; vec3 pos_ndc = vec3(uvs, gl_FragCoord.z) * 2.0 - 1.0; vec4 pos_world = drw_view.viewinv * (drw_view.wininv * vec4(pos_ndc, 1.0)); vec3 pos = pos_world.xyz / pos_world.w; diff --git a/source/blender/draw/engines/overlay/shaders/overlay_outline_prepass_gpencil_vert.glsl b/source/blender/draw/engines/overlay/shaders/overlay_outline_prepass_gpencil_vert.glsl index 4b1470e5723..7d8fb0c2cb8 100644 --- a/source/blender/draw/engines/overlay/shaders/overlay_outline_prepass_gpencil_vert.glsl +++ b/source/blender/draw/engines/overlay/shaders/overlay_outline_prepass_gpencil_vert.glsl @@ -47,7 +47,7 @@ void main() col1, col2, fcol1, - vec4(drw_view.viewport_size, drw_view.viewport_size_inverse), + vec4(sizeViewport, sizeViewportInv), world_pos, unused_N, unused_color, diff --git a/source/blender/draw/engines/overlay/shaders/overlay_wireframe_frag.glsl b/source/blender/draw/engines/overlay/shaders/overlay_wireframe_frag.glsl index bc28d7a8a36..d3eb1a500ba 100644 --- a/source/blender/draw/engines/overlay/shaders/overlay_wireframe_frag.glsl +++ b/source/blender/draw/engines/overlay/shaders/overlay_wireframe_frag.glsl @@ -17,10 +17,10 @@ void main() vec2 dir = lineOutput.xy * 2.0 - 1.0; bool dir_horiz = abs(dir.x) > abs(dir.y); - vec2 uv = gl_FragCoord.xy * drw_view.viewport_size_inverse; + vec2 uv = gl_FragCoord.xy * sizeViewportInv; float depth_occluder = texture(depthTex, uv).r; float depth_min = depth_occluder; - vec2 texel_uv_size = drw_view.viewport_size_inverse; + vec2 texel_uv_size = sizeViewportInv; if (dir_horiz) { depth_min = min(depth_min, texture(depthTex, uv + vec2(-texel_uv_size.x, 0.0)).r); diff --git a/source/blender/draw/engines/overlay/shaders/overlay_wireframe_vert.glsl b/source/blender/draw/engines/overlay/shaders/overlay_wireframe_vert.glsl index d189ab1b72c..7af2e0b3427 100644 --- a/source/blender/draw/engines/overlay/shaders/overlay_wireframe_vert.glsl +++ b/source/blender/draw/engines/overlay/shaders/overlay_wireframe_vert.glsl @@ -96,7 +96,7 @@ void main() wofs = normal_world_to_view(wofs); /* Push vertex half a pixel (maximum) in normal direction. */ - gl_Position.xy += wofs.xy * drw_view.viewport_size_inverse * gl_Position.w; + gl_Position.xy += wofs.xy * sizeViewportInv * gl_Position.w; /* Push the vertex towards the camera. Helps a bit. */ gl_Position.z -= facing_ratio * curvature * 1.0e-6 * gl_Position.w; @@ -136,8 +136,7 @@ void main() #ifdef SELECT_EDGES /* HACK: to avoid losing sub-pixel object in selections, we add a bit of randomness to the * wire to at least create one fragment that will pass the occlusion query. */ - gl_Position.xy += drw_view.viewport_size_inverse * gl_Position.w * - ((gl_VertexID % 2 == 0) ? -1.0 : 1.0); + gl_Position.xy += sizeViewportInv * gl_Position.w * ((gl_VertexID % 2 == 0) ? -1.0 : 1.0); #endif view_clipping_distances(wpos); diff --git a/source/blender/draw/intern/draw_cache_impl.h b/source/blender/draw/intern/draw_cache_impl.h index e49b37b451f..c6e8539121f 100644 --- a/source/blender/draw/intern/draw_cache_impl.h +++ b/source/blender/draw/intern/draw_cache_impl.h @@ -279,8 +279,6 @@ struct GPUVertBuf *DRW_mesh_batch_cache_pos_vertbuf_get(struct Mesh *me); int DRW_mesh_material_count_get(const struct Object *object, const struct Mesh *me); -/* See 'common_globals_lib.glsl' for duplicate defines. */ - /* Edit mesh bitflags (is this the right place?) */ enum { VFLAG_VERT_ACTIVE = 1 << 0, diff --git a/source/blender/draw/intern/draw_common.c b/source/blender/draw/intern/draw_common.c index 73a93a10582..a63c26f70f2 100644 --- a/source/blender/draw/intern/draw_common.c +++ b/source/blender/draw/intern/draw_common.c @@ -180,7 +180,6 @@ void DRW_globals_update(void) gb->pixel_fac = *DRW_viewport_pixelsize_get(); - /* Deprecated, use drw_view.viewport_size instead */ copy_v2_v2(&gb->size_viewport[0], DRW_viewport_size_get()); copy_v2_v2(&gb->size_viewport[2], &gb->size_viewport[0]); invert_v2(&gb->size_viewport[2]); diff --git a/source/blender/draw/intern/draw_common_shader_shared.h b/source/blender/draw/intern/draw_common_shader_shared.h index 8d412fadd82..9a5fce52c1e 100644 --- a/source/blender/draw/intern/draw_common_shader_shared.h +++ b/source/blender/draw/intern/draw_common_shader_shared.h @@ -228,6 +228,7 @@ BLI_STATIC_ASSERT_ALIGN(GlobalsUboStorage, 16) # define colorFaceFront globalsBlock.color_face_front # define colorUVShadow globalsBlock.color_uv_shadow # define sizeViewport globalsBlock.size_viewport.xy +# define sizeViewportInv globalsBlock.size_viewport.zw # define sizePixel globalsBlock.size_pixel # define pixelFac globalsBlock.pixel_fac # define sizeObjectCenter globalsBlock.size_object_center diff --git a/source/blender/draw/intern/shaders/common_globals_lib.glsl b/source/blender/draw/intern/shaders/common_globals_lib.glsl deleted file mode 100644 index 495a2e2c3d4..00000000000 --- a/source/blender/draw/intern/shaders/common_globals_lib.glsl +++ /dev/null @@ -1,147 +0,0 @@ -#define COMMON_GLOBALS_LIB - -#ifdef USE_GPU_SHADER_CREATE_INFO -# error Use draw_globals as additional_info instead of common_globals_lib.glsl -#endif - -/* keep in sync with GlobalsUboStorage */ -layout(std140) uniform globalsBlock -{ - vec4 colorWire; - vec4 colorWireEdit; - vec4 colorActive; - vec4 colorSelect; - vec4 colorLibrarySelect; - vec4 colorLibrary; - vec4 colorTransform; - vec4 colorLight; - vec4 colorSpeaker; - vec4 colorCamera; - vec4 colorCameraPath; - vec4 colorEmpty; - vec4 colorVertex; - vec4 colorVertexSelect; - vec4 colorVertexUnreferenced; - vec4 colorVertexMissingData; - vec4 colorEditMeshActive; - vec4 colorEdgeSelect; - vec4 colorEdgeSeam; - vec4 colorEdgeSharp; - vec4 colorEdgeCrease; - vec4 colorEdgeBWeight; - vec4 colorEdgeFaceSelect; - vec4 colorEdgeFreestyle; - vec4 colorFace; - vec4 colorFaceSelect; - vec4 colorFaceFreestyle; - vec4 colorGpencilVertex; - vec4 colorGpencilVertexSelect; - vec4 colorNormal; - vec4 colorVNormal; - vec4 colorLNormal; - vec4 colorFaceDot; - vec4 colorSkinRoot; - vec4 colorDeselect; - vec4 colorOutline; - vec4 colorLightNoAlpha; - - vec4 colorBackground; - vec4 colorBackgroundGradient; - vec4 colorCheckerPrimary; - vec4 colorCheckerSecondary; - vec4 colorClippingBorder; - vec4 colorEditMeshMiddle; - - vec4 colorHandleFree; - vec4 colorHandleAuto; - vec4 colorHandleVect; - vec4 colorHandleAlign; - vec4 colorHandleAutoclamp; - vec4 colorHandleSelFree; - vec4 colorHandleSelAuto; - vec4 colorHandleSelVect; - vec4 colorHandleSelAlign; - vec4 colorHandleSelAutoclamp; - vec4 colorNurbUline; - vec4 colorNurbVline; - vec4 colorNurbSelUline; - vec4 colorNurbSelVline; - vec4 colorActiveSpline; - - vec4 colorBonePose; - vec4 colorBonePoseActive; - vec4 colorBonePoseActiveUnsel; - vec4 colorBonePoseConstraint; - vec4 colorBonePoseIK; - vec4 colorBonePoseSplineIK; - vec4 colorBonePoseTarget; - vec4 colorBoneSolid; - vec4 colorBoneLocked; - vec4 colorBoneActive; - vec4 colorBoneActiveUnsel; - vec4 colorBoneSelect; - vec4 colorBoneIKLine; - vec4 colorBoneIKLineNoTarget; - vec4 colorBoneIKLineSpline; - - vec4 colorText; - vec4 colorTextHi; - - vec4 colorBundleSolid; - - vec4 colorMballRadius; - vec4 colorMballRadiusSelect; - vec4 colorMballStiffness; - vec4 colorMballStiffnessSelect; - - vec4 colorCurrentFrame; - - vec4 colorGrid; - vec4 colorGridEmphasis; - vec4 colorGridAxisX; - vec4 colorGridAxisY; - vec4 colorGridAxisZ; - - vec4 colorFaceBack; - vec4 colorFaceFront; - - vec4 colorUVShadow; - - vec4 sizeViewport; /* Inverted size in zw. */ - - float sizePixel; /* This one is for DPI scaling. */ - float pixelFac; /* To use with mul_project_m4_v3_zfac() */ - float sizeObjectCenter; - float sizeLightCenter; - float sizeLightCircle; - float sizeLightCircleShadow; - float sizeVertex; - float sizeEdge; - float sizeEdgeFix; - float sizeFaceDot; - float sizeChecker; - float sizeVertexGpencil; -}; - -#define sizeViewportInv (sizeViewport.zw) - -/* See: 'draw_cache_impl.h' for matching includes. */ -#define VERT_GPENCIL_BEZT_HANDLE (1 << 30) -/* data[0] (1st byte flags) */ -#define FACE_ACTIVE (1 << 0) -#define FACE_SELECTED (1 << 1) -#define FACE_FREESTYLE (1 << 2) -#define VERT_UV_SELECT (1 << 3) -#define VERT_UV_PINNED (1 << 4) -#define EDGE_UV_SELECT (1 << 5) -#define FACE_UV_ACTIVE (1 << 6) -#define FACE_UV_SELECT (1 << 7) -/* data[1] (2st byte flags) */ -#define VERT_ACTIVE (1 << 0) -#define VERT_SELECTED (1 << 1) -#define VERT_SELECTED_BEZT_HANDLE (1 << 2) -#define EDGE_ACTIVE (1 << 3) -#define EDGE_SELECTED (1 << 4) -#define EDGE_SEAM (1 << 5) -#define EDGE_SHARP (1 << 6) -#define EDGE_FREESTYLE (1 << 7) |