Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeroen Bakker <jeroen@blender.org>2020-09-11 08:59:48 +0300
committerJeroen Bakker <jeroen@blender.org>2020-09-11 09:08:46 +0300
commitd6525e8d133b787655bdb2c2fcef218591a457c3 (patch)
treeb4dbb06b75005deee918d7816c074a5735be930c /source/blender/draw/engines/overlay/shaders
parentd023c4104cb642c839d5868411a3b719f3528421 (diff)
Use DrawManager for Image/UV Editor
This project moves the current UV/Image editor drawing to the draw manager. Why would we do this: **Performance**: Current implementation would draw each texel per time. Multiple texels could be drawn per pixel what would overwrite the previous result. You can notice this when working with large textures. Repeat image drawing made this visible by drawing for a small period of time and stop drawing the rest. Now the rendering is fast and all repeated images are drawn. **Alpha drawing**: Current implementation would draw directly in display space. Giving incorrect results when displaying alpha transparent images. This addresses {T52680}, {T74709}, {T79518} The image editor now can show emission only colors. See {D8234} for examples. **Current Limitations** Using images that are larger than supported by your GPU are resized (eg larger than 16000x16000 are resized to 8k). This leaves some blurring artifacts. It is a low priority to add support back of displaying individual pixels of huge images. There is a design task {T80113} with more detail. **Implementation overview** Introduced an Image Engine in the draw module. this engine is responsible for drawing the texture in the main area of the UV/Image editor. The overlay engine has a edit_uv overlay which is responsible to draw the UV's, shadows and overlays specifically for the UV Image editor. The background + checker pattern is drawn by the overlay_background. The patch will allow us to share overlays between the 3d viewport and UV/Image editor more easily. In most cases we just need to switch the `pos` with the `u` attribute in the vertex shader. The project can be activated in the user preferences as experimental features. In a later commit this will be reversed. Reviewed By: Clément Foucault Differential Revision: https://developer.blender.org/D8234
Diffstat (limited to 'source/blender/draw/engines/overlay/shaders')
-rw-r--r--source/blender/draw/engines/overlay/shaders/background_frag.glsl7
-rw-r--r--source/blender/draw/engines/overlay/shaders/common_overlay_lib.glsl5
-rw-r--r--source/blender/draw/engines/overlay/shaders/edit_uv_edges_frag.glsl77
-rw-r--r--source/blender/draw/engines/overlay/shaders/edit_uv_edges_geom.glsl63
-rw-r--r--source/blender/draw/engines/overlay/shaders/edit_uv_edges_vert.glsl32
-rw-r--r--source/blender/draw/engines/overlay/shaders/edit_uv_face_dots_vert.glsl18
-rw-r--r--source/blender/draw/engines/overlay/shaders/edit_uv_faces_vert.glsl22
-rw-r--r--source/blender/draw/engines/overlay/shaders/edit_uv_stretching_vert.glsl98
-rw-r--r--source/blender/draw/engines/overlay/shaders/edit_uv_tiled_image_borders_vert.glsl12
-rw-r--r--source/blender/draw/engines/overlay/shaders/edit_uv_verts_frag.glsl33
-rw-r--r--source/blender/draw/engines/overlay/shaders/edit_uv_verts_vert.glsl44
-rw-r--r--source/blender/draw/engines/overlay/shaders/grid_vert.glsl7
12 files changed, 415 insertions, 3 deletions
diff --git a/source/blender/draw/engines/overlay/shaders/background_frag.glsl b/source/blender/draw/engines/overlay/shaders/background_frag.glsl
index d5aaaf75b79..71bfd2f8e73 100644
--- a/source/blender/draw/engines/overlay/shaders/background_frag.glsl
+++ b/source/blender/draw/engines/overlay/shaders/background_frag.glsl
@@ -13,6 +13,7 @@ out vec4 fragColor;
#define BG_GRADIENT 1
#define BG_CHECKER 2
#define BG_RADIAL 3
+#define BG_SOLID_CHECKER 4
#define SQRT2 1.4142135623730950488
/* 4x4 bayer matrix prepared for 8bit UNORM precision error. */
@@ -43,7 +44,11 @@ void main()
vec3 col_high;
vec3 col_low;
- switch (bgType) {
+ /* BG_SOLID_CHECKER selects BG_SOLID when no pixel has been drawn otherwise use the BG_CHERKER.
+ */
+ int bg_type = bgType == BG_SOLID_CHECKER ? (depth == 1.0 ? BG_SOLID : BG_CHECKER) : bgType;
+
+ switch (bg_type) {
case BG_SOLID:
bg_col = colorBackground.rgb;
break;
diff --git a/source/blender/draw/engines/overlay/shaders/common_overlay_lib.glsl b/source/blender/draw/engines/overlay/shaders/common_overlay_lib.glsl
new file mode 100644
index 00000000000..65aeb81a4ef
--- /dev/null
+++ b/source/blender/draw/engines/overlay/shaders/common_overlay_lib.glsl
@@ -0,0 +1,5 @@
+#define OVERLAY_UV_LINE_STYLE_OUTLINE 0
+#define OVERLAY_UV_LINE_STYLE_DASH 1
+#define OVERLAY_UV_LINE_STYLE_BLACK 2
+#define OVERLAY_UV_LINE_STYLE_WHITE 3
+#define OVERLAY_UV_LINE_STYLE_SHADOW 4
diff --git a/source/blender/draw/engines/overlay/shaders/edit_uv_edges_frag.glsl b/source/blender/draw/engines/overlay/shaders/edit_uv_edges_frag.glsl
new file mode 100644
index 00000000000..b81fdd2c712
--- /dev/null
+++ b/source/blender/draw/engines/overlay/shaders/edit_uv_edges_frag.glsl
@@ -0,0 +1,77 @@
+#pragma BLENDER_REQUIRE(common_globals_lib.glsl)
+#pragma BLENDER_REQUIRE(common_overlay_lib.glsl)
+
+uniform int lineStyle;
+uniform bool doSmoothWire;
+uniform float alpha;
+uniform float dashLength;
+
+in float selectionFac_f;
+noperspective in float edgeCoord_f;
+noperspective in vec2 stipplePos_f;
+flat in vec2 stippleStart_f;
+
+layout(location = 0) out vec4 fragColor;
+
+#define M_1_SQRTPI 0.5641895835477563 /* 1/sqrt(pi) */
+
+/**
+ * We want to know how much a pixel is covered by a line.
+ * We replace the square pixel with acircle of the same area and try to find the intersection area.
+ * The area we search is the circular segment. https://en.wikipedia.org/wiki/Circular_segment
+ * The formula for the area uses inverse trig function and is quite complexe. Instead,
+ * we approximate it by using the smoothstep function and a 1.05 factor to the disc radius.
+ */
+#define DISC_RADIUS (M_1_SQRTPI * 1.05)
+#define GRID_LINE_SMOOTH_START (0.5 - DISC_RADIUS)
+#define GRID_LINE_SMOOTH_END (0.5 + DISC_RADIUS)
+
+void main()
+{
+ vec4 inner_color = vec4(vec3(0.0), 1.0);
+ vec4 outer_color = vec4(0.0);
+
+ vec2 dd = fwidth(stipplePos_f);
+ float line_distance = distance(stipplePos_f, stippleStart_f) / max(dd.x, dd.y);
+
+ if (lineStyle == OVERLAY_UV_LINE_STYLE_OUTLINE) {
+ inner_color = mix(colorWireEdit, colorEdgeSelect, selectionFac_f);
+ outer_color = vec4(vec3(0.0), 1.0);
+ }
+ else if (lineStyle == OVERLAY_UV_LINE_STYLE_DASH) {
+ if (fract(line_distance / dashLength) < 0.5) {
+ inner_color = mix(vec4(1.0), colorEdgeSelect, selectionFac_f);
+ }
+ }
+ else if (lineStyle == OVERLAY_UV_LINE_STYLE_BLACK) {
+ vec4 base_color = vec4(vec3(0.0), 1.0);
+ inner_color = mix(base_color, colorEdgeSelect, selectionFac_f);
+ }
+ else if (lineStyle == OVERLAY_UV_LINE_STYLE_WHITE) {
+ vec4 base_color = vec4(1.0);
+ inner_color = mix(base_color, colorEdgeSelect, selectionFac_f);
+ }
+ else if (lineStyle == OVERLAY_UV_LINE_STYLE_SHADOW) {
+ inner_color = colorUVShadow;
+ }
+
+ float dist = abs(edgeCoord_f) - max(sizeEdge - 0.5, 0.0);
+ float dist_outer = dist - max(sizeEdge, 1.0);
+ float mix_w;
+ float mix_w_outer;
+
+ if (doSmoothWire) {
+ mix_w = smoothstep(GRID_LINE_SMOOTH_START, GRID_LINE_SMOOTH_END, dist);
+ mix_w_outer = smoothstep(GRID_LINE_SMOOTH_START, GRID_LINE_SMOOTH_END, dist_outer);
+ }
+ else {
+ mix_w = step(0.5, dist);
+ mix_w_outer = step(0.5, dist_outer);
+ }
+
+ vec4 final_color = mix(outer_color, inner_color, 1.0 - mix_w * outer_color.a);
+ final_color.a *= 1.0 - (outer_color.a > 0.0 ? mix_w_outer : mix_w);
+ final_color.a *= alpha;
+
+ fragColor = final_color;
+} \ No newline at end of file
diff --git a/source/blender/draw/engines/overlay/shaders/edit_uv_edges_geom.glsl b/source/blender/draw/engines/overlay/shaders/edit_uv_edges_geom.glsl
new file mode 100644
index 00000000000..4f8d553a220
--- /dev/null
+++ b/source/blender/draw/engines/overlay/shaders/edit_uv_edges_geom.glsl
@@ -0,0 +1,63 @@
+#pragma BLENDER_REQUIRE(common_globals_lib.glsl)
+#pragma BLENDER_REQUIRE(common_overlay_lib.glsl)
+
+layout(lines) in;
+layout(triangle_strip, max_vertices = 4) out;
+
+in float selectionFac[2];
+flat in vec2 stippleStart[2];
+noperspective in vec2 stipplePos[2];
+
+uniform int lineStyle;
+uniform bool doSmoothWire;
+
+out float selectionFac_f;
+noperspective out float edgeCoord_f;
+noperspective out vec2 stipplePos_f;
+flat out vec2 stippleStart_f;
+
+void do_vertex(
+ vec4 pos, float selection_fac, vec2 stipple_start, vec2 stipple_pos, float coord, vec2 offset)
+{
+ selectionFac_f = selection_fac;
+ edgeCoord_f = coord;
+ stippleStart_f = stipple_start;
+ stipplePos_f = stipple_pos;
+
+ gl_Position = pos;
+ /* Multiply offset by 2 because gl_Position range is [-1..1]. */
+ gl_Position.xy += offset * 2.0;
+ EmitVertex();
+}
+
+void main()
+{
+ vec2 ss_pos[2];
+ vec4 pos0 = gl_in[0].gl_Position;
+ vec4 pos1 = gl_in[1].gl_Position;
+ ss_pos[0] = pos0.xy / pos0.w;
+ ss_pos[1] = pos1.xy / pos1.w;
+
+ float half_size = sizeEdge;
+ /* Enlarge edge for outline drawing. */
+ /* Factor of 3.0 out of nowhere! Seems to fix issues with float imprecision. */
+ half_size += (lineStyle == OVERLAY_UV_LINE_STYLE_OUTLINE) ?
+ max(sizeEdge * (doSmoothWire ? 1.0 : 3.0), 1.0) :
+ 0.0;
+ /* Add 1 px for AA */
+ if (doSmoothWire) {
+ half_size += 0.5;
+ }
+
+ 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 * sizeViewportInv * ceil(half_size);
+
+ do_vertex(pos0, selectionFac[0], stippleStart[0], stipplePos[0], half_size, edge_ofs.xy);
+ do_vertex(pos0, selectionFac[0], stippleStart[0], stipplePos[0], -half_size, -edge_ofs.xy);
+ do_vertex(pos1, selectionFac[1], stippleStart[1], stipplePos[1], half_size, edge_ofs.xy);
+ do_vertex(pos1, selectionFac[1], stippleStart[1], stipplePos[1], -half_size, -edge_ofs.xy);
+
+ EndPrimitive();
+}
diff --git a/source/blender/draw/engines/overlay/shaders/edit_uv_edges_vert.glsl b/source/blender/draw/engines/overlay/shaders/edit_uv_edges_vert.glsl
new file mode 100644
index 00000000000..3db6cc1d3c1
--- /dev/null
+++ b/source/blender/draw/engines/overlay/shaders/edit_uv_edges_vert.glsl
@@ -0,0 +1,32 @@
+#pragma BLENDER_REQUIRE(common_globals_lib.glsl)
+#pragma BLENDER_REQUIRE(common_view_lib.glsl)
+
+in vec3 pos;
+in vec2 u;
+in int flag;
+
+out float selectionFac;
+noperspective out vec2 stipplePos;
+flat out vec2 stippleStart;
+
+void main()
+{
+ vec3 world_pos = point_object_to_world(vec3(u, 0.0));
+ gl_Position = point_world_to_ndc(world_pos);
+ /* Snap vertices to the pixel grid to reduce artifacts. */
+ vec2 half_viewport_res = sizeViewport.xy * 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;
+
+ bool is_select = (flag & VERT_UV_SELECT) != 0;
+ selectionFac = is_select ? 1.0 : 0.0;
+ /* Move selected edges to the top
+ * Vertices are between 0.0 and 0.2, Edges between 0.2 and 0.4
+ * actual pixels are at 0.75, 1.0 is used for the background. */
+ float depth = is_select ? 0.25 : 0.35;
+ gl_Position.z = depth;
+
+ /* Avoid precision loss. */
+ stippleStart = stipplePos = 500.0 + 500.0 * (gl_Position.xy / gl_Position.w);
+}
diff --git a/source/blender/draw/engines/overlay/shaders/edit_uv_face_dots_vert.glsl b/source/blender/draw/engines/overlay/shaders/edit_uv_face_dots_vert.glsl
new file mode 100644
index 00000000000..61152c83a29
--- /dev/null
+++ b/source/blender/draw/engines/overlay/shaders/edit_uv_face_dots_vert.glsl
@@ -0,0 +1,18 @@
+#pragma BLENDER_REQUIRE(common_globals_lib.glsl)
+#pragma BLENDER_REQUIRE(common_view_lib.glsl)
+
+uniform float pointSize;
+
+in vec2 u;
+in int flag;
+
+flat out vec4 finalColor;
+
+void main()
+{
+ vec3 world_pos = point_object_to_world(vec3(u, 0.0));
+ gl_Position = point_world_to_ndc(world_pos);
+
+ finalColor = ((flag & FACE_UV_SELECT) != 0) ? colorVertexSelect : vec4(colorWire.rgb, 1.0);
+ gl_PointSize = pointSize;
+}
diff --git a/source/blender/draw/engines/overlay/shaders/edit_uv_faces_vert.glsl b/source/blender/draw/engines/overlay/shaders/edit_uv_faces_vert.glsl
new file mode 100644
index 00000000000..cf1018ae5f9
--- /dev/null
+++ b/source/blender/draw/engines/overlay/shaders/edit_uv_faces_vert.glsl
@@ -0,0 +1,22 @@
+#pragma BLENDER_REQUIRE(common_globals_lib.glsl)
+#pragma BLENDER_REQUIRE(common_view_lib.glsl)
+
+uniform float uvOpacity;
+
+in vec2 u;
+in int flag;
+
+flat out vec4 finalColor;
+
+void main()
+{
+ vec3 world_pos = point_object_to_world(vec3(u, 0.0));
+ gl_Position = point_world_to_ndc(world_pos);
+
+ bool is_selected = (flag & FACE_UV_SELECT) != 0;
+ bool is_active = (flag & FACE_UV_ACTIVE) != 0;
+
+ finalColor = (is_selected) ? colorFaceSelect : colorFace;
+ finalColor = (is_active) ? colorEditMeshActive : finalColor;
+ finalColor.a *= uvOpacity;
+}
diff --git a/source/blender/draw/engines/overlay/shaders/edit_uv_stretching_vert.glsl b/source/blender/draw/engines/overlay/shaders/edit_uv_stretching_vert.glsl
new file mode 100644
index 00000000000..ce97f1e27ac
--- /dev/null
+++ b/source/blender/draw/engines/overlay/shaders/edit_uv_stretching_vert.glsl
@@ -0,0 +1,98 @@
+#pragma BLENDER_REQUIRE(common_view_lib.glsl)
+
+uniform vec2 aspect;
+in vec2 pos;
+
+#ifdef STRETCH_ANGLE
+in vec2 uv_angles;
+in float angle;
+
+#else
+in float ratio;
+uniform float totalAreaRatio;
+uniform float totalAreaRatioInv;
+
+#endif
+
+noperspective out vec4 finalColor;
+
+vec3 weight_to_rgb(float weight)
+{
+ vec3 r_rgb;
+ float blend = ((weight / 2.0) + 0.5);
+
+ if (weight <= 0.25) { /* blue->cyan */
+ r_rgb[0] = 0.0;
+ r_rgb[1] = blend * weight * 4.0;
+ r_rgb[2] = blend;
+ }
+ else if (weight <= 0.50) { /* cyan->green */
+ r_rgb[0] = 0.0;
+ r_rgb[1] = blend;
+ r_rgb[2] = blend * (1.0 - ((weight - 0.25) * 4.0));
+ }
+ else if (weight <= 0.75) { /* green->yellow */
+ r_rgb[0] = blend * ((weight - 0.50) * 4.0);
+ r_rgb[1] = blend;
+ r_rgb[2] = 0.0;
+ }
+ else if (weight <= 1.0) { /* yellow->red */
+ r_rgb[0] = blend;
+ r_rgb[1] = blend * (1.0 - ((weight - 0.75) * 4.0));
+ r_rgb[2] = 0.0;
+ }
+ else {
+ /* exceptional value, unclamped or nan,
+ * avoid uninitialized memory use */
+ r_rgb[0] = 1.0;
+ r_rgb[1] = 0.0;
+ r_rgb[2] = 1.0;
+ }
+
+ return r_rgb;
+}
+
+#define M_PI 3.1415926535897932
+
+vec2 angle_to_v2(float angle)
+{
+ return vec2(cos(angle), sin(angle));
+}
+
+/* Adapted from BLI_math_vector.h */
+float angle_normalized_v2v2(vec2 v1, vec2 v2)
+{
+ v1 = normalize(v1 * aspect);
+ v2 = normalize(v2 * aspect);
+ /* this is the same as acos(dot_v3v3(v1, v2)), but more accurate */
+ bool q = (dot(v1, v2) >= 0.0);
+ vec2 v = (q) ? (v1 - v2) : (v1 + v2);
+ float a = 2.0 * asin(length(v) / 2.0);
+ return (q) ? a : M_PI - a;
+}
+
+float area_ratio_to_stretch(float ratio, float tot_ratio, float inv_tot_ratio)
+{
+ ratio *= (ratio > 0.0f) ? tot_ratio : -inv_tot_ratio;
+ return (ratio > 1.0f) ? (1.0f / ratio) : ratio;
+}
+
+void main()
+{
+ vec3 world_pos = point_object_to_world(vec3(pos, 0.0));
+ gl_Position = point_world_to_ndc(world_pos);
+
+#ifdef STRETCH_ANGLE
+ vec2 v1 = angle_to_v2(uv_angles.x * M_PI);
+ vec2 v2 = angle_to_v2(uv_angles.y * M_PI);
+ float uv_angle = angle_normalized_v2v2(v1, v2) / M_PI;
+ float stretch = 1.0 - abs(uv_angle - angle);
+ stretch = stretch;
+ stretch = 1.0 - stretch * stretch;
+#else
+ float stretch = 1.0 - area_ratio_to_stretch(ratio, totalAreaRatio, totalAreaRatioInv);
+
+#endif
+
+ finalColor = vec4(weight_to_rgb(stretch), 1.0);
+}
diff --git a/source/blender/draw/engines/overlay/shaders/edit_uv_tiled_image_borders_vert.glsl b/source/blender/draw/engines/overlay/shaders/edit_uv_tiled_image_borders_vert.glsl
new file mode 100644
index 00000000000..c762858a910
--- /dev/null
+++ b/source/blender/draw/engines/overlay/shaders/edit_uv_tiled_image_borders_vert.glsl
@@ -0,0 +1,12 @@
+#pragma BLENDER_REQUIRE(common_view_lib.glsl)
+
+in vec3 pos;
+
+void main()
+{
+ /* `pos` contains the coordinates of a quad (-1..1). but we need the coordinates of an image
+ * plane (0..1) */
+ vec3 image_pos = pos * 0.5 + 0.5;
+ vec4 position = point_object_to_ndc(image_pos);
+ gl_Position = position;
+}
diff --git a/source/blender/draw/engines/overlay/shaders/edit_uv_verts_frag.glsl b/source/blender/draw/engines/overlay/shaders/edit_uv_verts_frag.glsl
new file mode 100644
index 00000000000..11694de38ca
--- /dev/null
+++ b/source/blender/draw/engines/overlay/shaders/edit_uv_verts_frag.glsl
@@ -0,0 +1,33 @@
+
+uniform vec4 outlineColor;
+
+in vec4 radii;
+in vec4 fillColor;
+out vec4 fragColor;
+
+void main()
+{
+ float dist = length(gl_PointCoord - vec2(0.5));
+
+ // transparent outside of point
+ // --- 0 ---
+ // smooth transition
+ // --- 1 ---
+ // pure outline color
+ // --- 2 ---
+ // smooth transition
+ // --- 3 ---
+ // pure fill color
+ // ...
+ // dist = 0 at center of point
+
+ float midStroke = 0.5 * (radii[1] + radii[2]);
+
+ if (dist > midStroke) {
+ fragColor.rgb = outlineColor.rgb;
+ fragColor.a = mix(outlineColor.a, 0.0, smoothstep(radii[1], radii[0], dist));
+ }
+ else {
+ fragColor = mix(fillColor, outlineColor, smoothstep(radii[3], radii[2], dist));
+ }
+}
diff --git a/source/blender/draw/engines/overlay/shaders/edit_uv_verts_vert.glsl b/source/blender/draw/engines/overlay/shaders/edit_uv_verts_vert.glsl
new file mode 100644
index 00000000000..327a35ce6b2
--- /dev/null
+++ b/source/blender/draw/engines/overlay/shaders/edit_uv_verts_vert.glsl
@@ -0,0 +1,44 @@
+#pragma BLENDER_REQUIRE(common_globals_lib.glsl)
+#pragma BLENDER_REQUIRE(common_view_lib.glsl)
+
+uniform float pointSize;
+uniform float outlineWidth;
+
+in vec2 u;
+in int flag;
+
+out vec4 fillColor;
+out vec4 outlineColor;
+out vec4 radii;
+
+/* TODO Theme? */
+const vec4 pinned_col = vec4(1.0, 0.0, 0.0, 1.0);
+
+void main()
+{
+ bool is_selected = (flag & (VERT_UV_SELECT | FACE_UV_SELECT)) != 0;
+ bool is_pinned = (flag & VERT_UV_PINNED) != 0;
+ vec4 deselect_col = (is_pinned) ? pinned_col : vec4(colorWire.rgb, 1.0);
+ fillColor = (is_selected) ? colorVertexSelect : deselect_col;
+ outlineColor = (is_pinned) ? pinned_col : vec4(fillColor.rgb, 0.0);
+
+ vec3 world_pos = point_object_to_world(vec3(u, 0.0));
+ /* Move selected vertices to the top
+ * Vertices are between 0.0 and 0.2, Edges between 0.2 and 0.4
+ * actual pixels are at 0.75, 1.0 is used for the background. */
+ float depth = is_selected ? 0.05 : 0.15;
+ gl_Position = vec4(point_world_to_ndc(world_pos).xy, depth, 1.0);
+ gl_PointSize = pointSize;
+
+ // calculate concentric radii in pixels
+ float radius = 0.5 * pointSize;
+
+ // start at the outside and progress toward the center
+ radii[0] = radius;
+ radii[1] = radius - 1.0;
+ radii[2] = radius - outlineWidth;
+ radii[3] = radius - outlineWidth - 1.0;
+
+ // convert to PointCoord units
+ radii /= pointSize;
+}
diff --git a/source/blender/draw/engines/overlay/shaders/grid_vert.glsl b/source/blender/draw/engines/overlay/shaders/grid_vert.glsl
index dd0e771ad93..6df4ead9f2a 100644
--- a/source/blender/draw/engines/overlay/shaders/grid_vert.glsl
+++ b/source/blender/draw/engines/overlay/shaders/grid_vert.glsl
@@ -12,7 +12,7 @@ uniform int gridFlag;
#define PLANE_YZ (1 << 6)
#define CLIP_Z_POS (1 << 7)
#define CLIP_Z_NEG (1 << 8)
-
+#define PLANE_IMAGE (1 << 11)
in vec3 pos;
out vec3 local_pos;
@@ -28,9 +28,12 @@ void main()
else if ((gridFlag & PLANE_XZ) != 0) {
vert_pos = vec3(pos.x, 0.0, pos.y);
}
- else {
+ else if ((gridFlag & PLANE_YZ) != 0) {
vert_pos = vec3(0.0, pos.x, pos.y);
}
+ else /* PLANE_IMAGE */ {
+ vert_pos = vec3(pos.xy * 0.5 + 0.5, 0.0);
+ }
local_pos = vert_pos;