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:
authorClément Foucault <foucault.clem@gmail.com>2019-12-02 03:40:58 +0300
committerClément Foucault <foucault.clem@gmail.com>2019-12-02 15:15:52 +0300
commit9516921c05bd9fee5c94942eb8e38f47ba7e4351 (patch)
treeda007fc17bc6a02f849dae2e8f76f5ab304fe4dc /source/blender/gpu/shaders
parent1f6c3699a836d485ed37f443cd0fcd19e978dbb6 (diff)
Overlay Engine: Refactor & Cleanup
This is the unification of all overlays into one overlay engine as described in T65347. I went over all the code making it more future proof with less hacks and removing old / not relevent parts. Goals / Acheivements: - Remove internal shader usage (only drw shaders) - Remove viewportSize and viewportSizeInv and put them in gloabl ubo - Fixed some drawing issues: Missing probe option and Missing Alt+B clipping of some shader - Remove old (legacy) shaders dependancy (not using view UBO). - Less shader variation (less compilation time at first load and less patching needed for vulkan) - removed some geom shaders when I could - Remove static e_data (except shaders storage where it is OK) - Clear the way to fix some anoying limitations (dithered transparency, background image compositing etc...) - Wireframe drawing now uses the same batching capabilities as workbench & eevee (indirect drawing). - Reduced complexity, removed ~3000 Lines of code in draw (also removed a lot of unused shader in GPU). - Post AA to avoid complexity and cost of MSAA. Remaining issues: - ~~Armature edits, overlay toggles, (... others?) are not refreshing viewport after AA is complete~~ - FXAA is not the best for wires, maybe investigate SMAA - Maybe do something more temporally stable for AA. - ~~Paint overlays are not working with AA.~~ - ~~infront objects are difficult to select.~~ - ~~the infront wires sometimes goes through they solid counterpart (missing clear maybe?) (toggle overlays on-off when using infront+wireframe overlay in solid shading)~~ Note: I made some decision to change slightly the appearance of some objects to simplify their drawing. Namely the empty arrows end (which is now hollow/wire) and distance points of the cameras/spots being done by lines. Reviewed By: jbakker Differential Revision: https://developer.blender.org/D6296
Diffstat (limited to 'source/blender/gpu/shaders')
-rw-r--r--source/blender/gpu/shaders/gpu_shader_2D_line_dashed_frag.glsl11
-rw-r--r--source/blender/gpu/shaders/gpu_shader_2D_line_dashed_geom.glsl65
-rw-r--r--source/blender/gpu/shaders/gpu_shader_2D_line_dashed_uniform_color_vert.glsl8
-rw-r--r--source/blender/gpu/shaders/gpu_shader_2D_line_dashed_width_geom.glsl60
-rw-r--r--source/blender/gpu/shaders/gpu_shader_3D_groundline_geom.glsl25
-rw-r--r--source/blender/gpu/shaders/gpu_shader_3D_groundpoint_vert.glsl16
-rw-r--r--source/blender/gpu/shaders/gpu_shader_3D_line_dashed_uniform_color_legacy_vert.glsl27
-rw-r--r--source/blender/gpu/shaders/gpu_shader_3D_line_dashed_uniform_color_vert.glsl8
-rw-r--r--source/blender/gpu/shaders/gpu_shader_instance_camera_vert.glsl55
-rw-r--r--source/blender/gpu/shaders/gpu_shader_instance_distance_line_vert.glsl31
-rw-r--r--source/blender/gpu/shaders/gpu_shader_instance_edges_variying_color_geom.glsl68
-rw-r--r--source/blender/gpu/shaders/gpu_shader_instance_edges_variying_color_vert.glsl71
-rw-r--r--source/blender/gpu/shaders/gpu_shader_instance_objectspace_variying_color_vert.glsl26
-rw-r--r--source/blender/gpu/shaders/gpu_shader_instance_screen_aligned_vert.glsl43
-rw-r--r--source/blender/gpu/shaders/gpu_shader_instance_screenspace_variying_color_vert.glsl32
-rw-r--r--source/blender/gpu/shaders/gpu_shader_instance_variying_size_variying_id_vert.glsl29
-rw-r--r--source/blender/gpu/shaders/gpu_shader_instance_vert.glsl13
-rw-r--r--source/blender/gpu/shaders/gpu_shader_text_frag.glsl7
-rw-r--r--source/blender/gpu/shaders/gpu_shader_text_geom.glsl37
-rw-r--r--source/blender/gpu/shaders/gpu_shader_text_simple_geom.glsl36
-rw-r--r--source/blender/gpu/shaders/gpu_shader_text_simple_vert.glsl22
-rw-r--r--source/blender/gpu/shaders/gpu_shader_text_vert.glsl16
-rw-r--r--source/blender/gpu/shaders/material/gpu_shader_material_normal_map.glsl2
23 files changed, 35 insertions, 673 deletions
diff --git a/source/blender/gpu/shaders/gpu_shader_2D_line_dashed_frag.glsl b/source/blender/gpu/shaders/gpu_shader_2D_line_dashed_frag.glsl
index a29335046f2..44a9db76834 100644
--- a/source/blender/gpu/shaders/gpu_shader_2D_line_dashed_frag.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_2D_line_dashed_frag.glsl
@@ -17,13 +17,16 @@ uniform float dash_factor; /* if > 1.0, solid line. */
uniform int colors_len; /* Enabled if > 0, 1 for solid line. */
uniform vec4 colors[32];
-noperspective in float distance_along_line;
-noperspective in vec4 color_geom;
+flat in vec4 color_vert;
+
+noperspective in vec2 stipple_pos;
+flat in vec2 stipple_start;
out vec4 fragColor;
void main()
{
+ float distance_along_line = distance(stipple_pos, stipple_start);
/* Multi-color option. */
if (colors_len > 0) {
/* Solid line case, simple. */
@@ -40,13 +43,13 @@ void main()
else {
/* Solid line case, simple. */
if (dash_factor >= 1.0f) {
- fragColor = color_geom;
+ fragColor = color_vert;
}
/* Actually dashed line... */
else {
float normalized_distance = fract(distance_along_line / dash_width);
if (normalized_distance <= dash_factor) {
- fragColor = color_geom;
+ fragColor = color_vert;
}
else {
discard;
diff --git a/source/blender/gpu/shaders/gpu_shader_2D_line_dashed_geom.glsl b/source/blender/gpu/shaders/gpu_shader_2D_line_dashed_geom.glsl
deleted file mode 100644
index 584a179a9ac..00000000000
--- a/source/blender/gpu/shaders/gpu_shader_2D_line_dashed_geom.glsl
+++ /dev/null
@@ -1,65 +0,0 @@
-
-/*
- * Geometry Shader for dashed lines, with uniform multi-color(s),
- * or any single-color, and unary thickness.
- *
- * Dashed is performed in screen space.
- */
-
-/* Make to be used with dynamic batching so no Model Matrix needed */
-uniform mat4 ModelViewProjectionMatrix;
-uniform vec2 viewport_size;
-
-/* Uniforms from fragment shader,
- * used here to optimize out useless computation in case of solid line. */
-uniform float dash_factor; /* if > 1.0, solid line. */
-uniform int colors_len; /* Enabled if > 0, 1 for solid line. */
-
-layout(lines) in;
-
-in vec4 color_vert[];
-
-layout(line_strip, max_vertices = 2) out;
-noperspective out float distance_along_line;
-noperspective out vec4 color_geom;
-
-void main()
-{
- vec4 v1 = gl_in[0].gl_Position;
- vec4 v2 = gl_in[1].gl_Position;
-
- gl_Position = v1;
- color_geom = color_vert[0];
- distance_along_line = 0.0f;
-
-#ifdef USE_WORLD_CLIP_PLANES
- world_clip_planes_set_clip_distance(gl_in[0].gl_ClipDistance);
-#endif
- EmitVertex();
-
- gl_Position = v2;
- color_geom = color_vert[1];
- if ((colors_len == 1) || (dash_factor >= 1.0f)) {
- /* Solid line, optimize out distance computation! */
- distance_along_line = 0.0f;
- }
- else {
- vec2 p1 = (v1.xy / v1.w) * 0.5 + 0.5; // <- device coordinates in [0..1] range.
- p1 = p1 * viewport_size; // <- 'virtual' screen coordinates.
-
- vec2 p2 = (v2.xy / v2.w) * 0.5 + 0.5; // <- device coordinates in [0..1] range.
- p2 = p2 * viewport_size; // <- 'virtual' screen coordinates.
-
- distance_along_line = distance(p1, p2);
- }
-
-#ifdef USE_WORLD_CLIP_PLANES
- world_clip_planes_set_clip_distance(gl_in[1].gl_ClipDistance);
-#endif
- EmitVertex();
-
- EndPrimitive();
-
- /* Note: we could also use similar approach as diag_stripes_frag,
- * but this would give us dashed 'anchored' to the screen, and not to one end of the line... */
-}
diff --git a/source/blender/gpu/shaders/gpu_shader_2D_line_dashed_uniform_color_vert.glsl b/source/blender/gpu/shaders/gpu_shader_2D_line_dashed_uniform_color_vert.glsl
index 8b5a5cd8c9a..15362d020e4 100644
--- a/source/blender/gpu/shaders/gpu_shader_2D_line_dashed_uniform_color_vert.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_2D_line_dashed_uniform_color_vert.glsl
@@ -9,13 +9,19 @@
uniform mat4 ModelViewProjectionMatrix;
uniform vec4 color;
+uniform vec2 viewport_size;
in vec2 pos;
-out vec4 color_vert;
+flat out vec4 color_vert;
+
+/* We leverage hardware interpolation to compute distance along the line. */
+noperspective out vec2 stipple_pos; /* In screen space */
+flat out vec2 stipple_start; /* In screen space */
void main()
{
gl_Position = ModelViewProjectionMatrix * vec4(pos, 0.0, 1.0);
+ stipple_start = stipple_pos = viewport_size * 0.5 * (gl_Position.xy / gl_Position.w);
color_vert = color;
}
diff --git a/source/blender/gpu/shaders/gpu_shader_2D_line_dashed_width_geom.glsl b/source/blender/gpu/shaders/gpu_shader_2D_line_dashed_width_geom.glsl
deleted file mode 100644
index 336f310837e..00000000000
--- a/source/blender/gpu/shaders/gpu_shader_2D_line_dashed_width_geom.glsl
+++ /dev/null
@@ -1,60 +0,0 @@
-
-// Draw dashed lines, perforated in screen space, with non-unary width.
-
-/* Make to be used with dynamic batching so no Model Matrix needed */
-uniform mat4 ModelViewProjectionMatrix;
-uniform vec2 viewport_size;
-
-/* Width of the generated 'line'. */
-uniform float width; /* in pixels, screen space. */
-
-/* Uniforms from fragment shader,
- * used here to optimize out useless computation in case of solid line. */
-uniform float dash_factor; /* if > 1.0, solid line. */
-uniform int colors_len; /* Enabled if > 0, 1 for solid line. */
-
-layout(lines) in;
-
-layout(triangle_strip, max_vertices = 4) out;
-noperspective out float distance_along_line;
-
-void main()
-{
- vec4 v1 = gl_in[0].gl_Position;
- vec4 v2 = gl_in[1].gl_Position;
-
- /* Width, from 2D screen space in pixels, to ModelViewProjection space of each input vertices. */
- float w1 = (width / viewport_size) * v1.w * 2.0;
- float w2 = (width / viewport_size) * v2.w * 2.0;
-
- /* Normalized vector parallel to screen and orthogonal to line. */
- vec4 wdir = normalize(vec4(v1.y - v2.y, v2.x - v1.x, 0.0, 0.0))
-
- distance_along_line = 0.0f;
- gl_Position = v1 + (wdir * w1);
- EmitVertex();
-
- gl_Position = v1 - (wdir * w1);
- EmitVertex();
-
- if ((colors_len == 1) || (dash_factor >= 1.0f)) {
- /* Solid line, optimize out distance computation! */
- distance_along_line = 0.0f;
- }
- else {
- vec2 p1 = (v1.xy / v1.w) * 0.5 + 0.5; // <- device coordinates in [0..1] range.
- p1 = p1 * viewport_size; // <- 'virtual' screen coordinates.
-
- vec2 p2 = (v2.xy / v2.w) * 0.5 + 0.5; // <- device coordinates in [0..1] range.
- p2 = p2 * viewport_size; // <- 'virtual' screen coordinates.
-
- distance_along_line = distance(p1, p2);
- }
- gl_Position = v2 + (wdir * w2);
- EmitVertex();
-
- gl_Position = v2 - (wdir * w2);
- EmitVertex();
-
- EndPrimitive();
-}
diff --git a/source/blender/gpu/shaders/gpu_shader_3D_groundline_geom.glsl b/source/blender/gpu/shaders/gpu_shader_3D_groundline_geom.glsl
deleted file mode 100644
index 03bee1b4e06..00000000000
--- a/source/blender/gpu/shaders/gpu_shader_3D_groundline_geom.glsl
+++ /dev/null
@@ -1,25 +0,0 @@
-
-/* Make to be used with dynamic batching so no Model Matrix needed */
-uniform mat4 ViewProjectionMatrix;
-
-layout(points) in;
-layout(line_strip, max_vertices = 2) out;
-
-void main()
-{
- vec3 vert = gl_in[0].gl_Position.xyz;
-
- gl_Position = ViewProjectionMatrix * vec4(vert.xyz, 1.0);
-#ifdef USE_WORLD_CLIP_PLANES
- world_clip_planes_set_clip_distance(gl_in[0].gl_ClipDistance);
-#endif
- EmitVertex();
-
- gl_Position = ViewProjectionMatrix * vec4(vert.xy, 0.0, 1.0);
-#ifdef USE_WORLD_CLIP_PLANES
- world_clip_planes_calc_clip_distance(vec3(vert.xy, 0.0));
-#endif
- EmitVertex();
-
- EndPrimitive();
-}
diff --git a/source/blender/gpu/shaders/gpu_shader_3D_groundpoint_vert.glsl b/source/blender/gpu/shaders/gpu_shader_3D_groundpoint_vert.glsl
deleted file mode 100644
index 6786b7b7405..00000000000
--- a/source/blender/gpu/shaders/gpu_shader_3D_groundpoint_vert.glsl
+++ /dev/null
@@ -1,16 +0,0 @@
-
-/* Made to be used with dynamic batching so no Model Matrix needed */
-uniform mat4 ViewProjectionMatrix;
-
-in vec3 pos;
-
-void main()
-{
- vec4 pos_4d = vec4(pos.xy, 0.0, 1.0);
- gl_Position = ViewProjectionMatrix * pos_4d;
- gl_PointSize = 2.0;
-
-#ifdef USE_WORLD_CLIP_PLANES
- world_clip_planes_calc_clip_distance(pos_4d.xyz);
-#endif
-}
diff --git a/source/blender/gpu/shaders/gpu_shader_3D_line_dashed_uniform_color_legacy_vert.glsl b/source/blender/gpu/shaders/gpu_shader_3D_line_dashed_uniform_color_legacy_vert.glsl
deleted file mode 100644
index 28c91343771..00000000000
--- a/source/blender/gpu/shaders/gpu_shader_3D_line_dashed_uniform_color_legacy_vert.glsl
+++ /dev/null
@@ -1,27 +0,0 @@
-
-/*
- * Vertex Shader for dashed lines with 3D coordinates,
- * with uniform multi-colors or uniform single-color, and unary thickness.
- *
- * Legacy version, without geometry shader support, always produce solid lines!
- */
-
-uniform mat4 ModelViewProjectionMatrix;
-uniform vec2 viewport_size;
-
-uniform vec4 color;
-
-in vec3 pos;
-noperspective out float distance_along_line;
-noperspective out vec4 color_geom;
-
-void main()
-{
- gl_Position = ModelViewProjectionMatrix * vec4(pos, 1.0);
-
- /* Hack - prevent stupid GLSL compiler to optimize out unused viewport_size uniform,
- * which gives crash! */
- distance_along_line = viewport_size.x * 0.000001f - viewport_size.x * 0.0000009f;
-
- color_geom = color;
-}
diff --git a/source/blender/gpu/shaders/gpu_shader_3D_line_dashed_uniform_color_vert.glsl b/source/blender/gpu/shaders/gpu_shader_3D_line_dashed_uniform_color_vert.glsl
index 7c317ecfb8c..aefa47275f5 100644
--- a/source/blender/gpu/shaders/gpu_shader_3D_line_dashed_uniform_color_vert.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_3D_line_dashed_uniform_color_vert.glsl
@@ -13,15 +13,21 @@ uniform mat4 ModelMatrix;
#endif
uniform vec4 color;
+uniform vec2 viewport_size;
in vec3 pos;
-out vec4 color_vert;
+flat out vec4 color_vert;
+
+/* We leverage hardware interpolation to compute distance along the line. */
+noperspective out vec2 stipple_pos; /* In screen space */
+flat out vec2 stipple_start; /* In screen space */
void main()
{
vec4 pos_4d = vec4(pos, 1.0);
gl_Position = ModelViewProjectionMatrix * pos_4d;
+ stipple_start = stipple_pos = viewport_size * 0.5 * (gl_Position.xy / gl_Position.w);
color_vert = color;
#ifdef USE_WORLD_CLIP_PLANES
world_clip_planes_calc_clip_distance((ModelMatrix * pos_4d).xyz);
diff --git a/source/blender/gpu/shaders/gpu_shader_instance_camera_vert.glsl b/source/blender/gpu/shaders/gpu_shader_instance_camera_vert.glsl
deleted file mode 100644
index f32c47bcec3..00000000000
--- a/source/blender/gpu/shaders/gpu_shader_instance_camera_vert.glsl
+++ /dev/null
@@ -1,55 +0,0 @@
-
-uniform mat4 ViewProjectionMatrix;
-
-/* ---- Instantiated Attrs ---- */
-in float pos;
-
-/* ---- Per instance Attrs ---- */
-in vec3 color;
-in vec4 corners[2]; /* trouble fetching vec2 */
-in float depth;
-in vec4 tria;
-in mat4 InstanceModelMatrix;
-
-flat out vec4 finalColor;
-
-void main()
-{
- vec3 pPos;
-
- if (pos == 1.0) {
- pPos = vec3(corners[0].xy, depth);
- }
- else if (pos == 2.0) {
- pPos = vec3(corners[0].zw, depth);
- }
- else if (pos == 3.0) {
- pPos = vec3(corners[1].xy, depth);
- }
- else if (pos == 4.0) {
- pPos = vec3(corners[1].zw, depth);
- }
- else if (pos == 5.0) {
- pPos = vec3(tria.xy, depth);
- }
- else if (pos == 6.0) {
- vec2 ofs = tria.xy - corners[0].xy;
- ofs.x = -ofs.x;
- pPos = vec3(corners[1].zw + ofs, depth);
- }
- else if (pos == 7.0) {
- pPos = vec3(tria.zw, depth);
- }
- else {
- pPos = vec3(0.0);
- }
-
- vec4 wPos = InstanceModelMatrix * vec4(pPos, 1.0);
- gl_Position = ViewProjectionMatrix * wPos;
-
- finalColor = vec4(color, 1.0);
-
-#ifdef USE_WORLD_CLIP_PLANES
- world_clip_planes_calc_clip_distance(wPos.xyz);
-#endif
-}
diff --git a/source/blender/gpu/shaders/gpu_shader_instance_distance_line_vert.glsl b/source/blender/gpu/shaders/gpu_shader_instance_distance_line_vert.glsl
deleted file mode 100644
index 5bd29c55e42..00000000000
--- a/source/blender/gpu/shaders/gpu_shader_instance_distance_line_vert.glsl
+++ /dev/null
@@ -1,31 +0,0 @@
-
-uniform mat4 ViewProjectionMatrix;
-
-/* ---- Instantiated Attrs ---- */
-in vec3 pos;
-
-/* ---- Per instance Attrs ---- */
-in vec3 color;
-in float start;
-in float end;
-in mat4 InstanceModelMatrix;
-
-uniform float size;
-
-flat out vec4 finalColor;
-
-void main()
-{
- float len = end - start;
- vec3 sta = vec3(0.0, 0.0, -start);
-
- vec4 wPos = InstanceModelMatrix * vec4(pos * -len + sta, 1.0);
-
- gl_Position = ViewProjectionMatrix * wPos;
- gl_PointSize = size;
- finalColor = vec4(color, 1.0);
-
-#ifdef USE_WORLD_CLIP_PLANES
- world_clip_planes_calc_clip_distance(wPos.xyz);
-#endif
-}
diff --git a/source/blender/gpu/shaders/gpu_shader_instance_edges_variying_color_geom.glsl b/source/blender/gpu/shaders/gpu_shader_instance_edges_variying_color_geom.glsl
deleted file mode 100644
index 1193e1b5b9c..00000000000
--- a/source/blender/gpu/shaders/gpu_shader_instance_edges_variying_color_geom.glsl
+++ /dev/null
@@ -1,68 +0,0 @@
-
-// Draw "fancy" wireframe, displaying front-facing, back-facing and
-// silhouette lines differently.
-// Mike Erwin, April 2015
-
-// After working with this shader a while, convinced we should make
-// separate shaders for perpective & ortho. (Oct 2016)
-
-// Due to perspective, the line segment's endpoints might disagree on
-// whether the adjacent faces are front facing. This geometry shader
-// decides which edge type to use if endpoints disagree.
-
-uniform mat4 ProjectionMatrix;
-
-uniform bool drawFront = true;
-uniform bool drawBack = true;
-uniform bool drawSilhouette = true;
-
-layout(lines) in;
-layout(line_strip, max_vertices = 2) out;
-
-in vec4 MV_pos[];
-in float edgeClass[];
-in vec3 fCol[];
-
-flat out vec4 finalColor;
-
-void emitLine(vec4 color)
-{
- gl_Position = ProjectionMatrix * MV_pos[0];
-#ifdef USE_WORLD_CLIP_PLANES
- world_clip_planes_set_clip_distance(gl_in[0].gl_ClipDistance);
-#endif
- EmitVertex();
-
- gl_Position = ProjectionMatrix * MV_pos[1];
-#ifdef USE_WORLD_CLIP_PLANES
- world_clip_planes_set_clip_distance(gl_in[1].gl_ClipDistance);
-#endif
- finalColor = color;
- EmitVertex();
-
- EndPrimitive();
-}
-
-void main()
-{
- float finalEdgeClass = max(edgeClass[0], edgeClass[1]);
-
- if (finalEdgeClass > 0.0f) {
- // front-facing edge
- if (drawFront) {
- emitLine(vec4(fCol[0], 0.75));
- }
- }
- else if (finalEdgeClass < 0.0f) {
- // back-facing edge
- if (drawBack) {
- emitLine(vec4(fCol[0], 0.5));
- }
- }
- else {
- // exactly one face is front-facing, silhouette edge
- if (drawSilhouette) {
- emitLine(vec4(fCol[0], 1.0));
- }
- }
-}
diff --git a/source/blender/gpu/shaders/gpu_shader_instance_edges_variying_color_vert.glsl b/source/blender/gpu/shaders/gpu_shader_instance_edges_variying_color_vert.glsl
deleted file mode 100644
index 543497e890b..00000000000
--- a/source/blender/gpu/shaders/gpu_shader_instance_edges_variying_color_vert.glsl
+++ /dev/null
@@ -1,71 +0,0 @@
-
-// Draw "fancy" wireframe, displaying front-facing, back-facing and
-// silhouette lines differently.
-// Mike Erwin, April 2015
-
-// After working with this shader a while, convinced we should make
-// separate shaders for perpective & ortho. (Oct 2016)
-
-// Due to perspective, the line segment's endpoints might disagree on
-// whether the adjacent faces are front facing. We use a geometry
-// shader to resolve this properly.
-
-uniform mat4 ViewMatrix;
-uniform mat4 ProjectionMatrix;
-
-in vec3 pos;
-in vec3 N1, N2; // normals of faces this edge joins (object coords)
-
-/* Instance attrs */
-in vec3 color;
-in mat4 InstanceModelMatrix;
-
-out vec4 MV_pos;
-out float edgeClass;
-out vec3 fCol;
-
-// TODO: in float angle; // [-pi .. +pi], + peak, 0 flat, - valley
-
-bool front(mat3 normal_matrix, vec3 N, vec3 eye)
-{
- return dot(normal_matrix * N, eye) > 0.0;
-}
-
-void main()
-{
- vec3 eye;
-
- mat4 model_view_matrix = ViewMatrix * InstanceModelMatrix;
-
- vec4 pos_4d = vec4(pos, 1.0);
- MV_pos = model_view_matrix * pos_4d;
-
- mat3 normal_matrix = transpose(inverse(mat3(model_view_matrix)));
-
- /* if persp */
- if (ProjectionMatrix[3][3] == 0.0) {
- eye = normalize(-MV_pos.xyz);
- }
- else {
- eye = vec3(0.0, 0.0, 1.0);
- }
-
- bool face_1_front = front(normal_matrix, N1, eye);
- bool face_2_front = front(normal_matrix, N2, eye);
-
- if (face_1_front && face_2_front) {
- edgeClass = 1.0; // front-facing edge
- }
- else if (face_1_front || face_2_front) {
- edgeClass = 0.0; // exactly one face is front-facing, silhouette edge
- }
- else {
- edgeClass = -1.0; // back-facing edge
- }
-
- fCol = color;
-
-#ifdef USE_WORLD_CLIP_PLANES
- world_clip_planes_calc_clip_distance((InstanceModelMatrix * vec4(pos, 1.0)).xyz);
-#endif
-}
diff --git a/source/blender/gpu/shaders/gpu_shader_instance_objectspace_variying_color_vert.glsl b/source/blender/gpu/shaders/gpu_shader_instance_objectspace_variying_color_vert.glsl
deleted file mode 100644
index 5b3922d7a72..00000000000
--- a/source/blender/gpu/shaders/gpu_shader_instance_objectspace_variying_color_vert.glsl
+++ /dev/null
@@ -1,26 +0,0 @@
-
-uniform mat4 ViewMatrixInverse;
-uniform mat4 ViewProjectionMatrix;
-
-/* ---- Instantiated Attrs ---- */
-in vec3 pos;
-in vec3 nor;
-
-/* ---- Per instance Attrs ---- */
-in mat4 InstanceModelMatrix;
-in vec4 color;
-
-out vec3 normal;
-flat out vec4 finalColor;
-
-void main()
-{
- gl_Position = ViewProjectionMatrix * (InstanceModelMatrix * vec4(pos, 1.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. */
- mat3 normal_mat = transpose(inverse(mat3(InstanceModelMatrix)));
- normal = normalize((transpose(mat3(ViewMatrixInverse)) * (normal_mat * nor)));
-
- finalColor = color;
-}
diff --git a/source/blender/gpu/shaders/gpu_shader_instance_screen_aligned_vert.glsl b/source/blender/gpu/shaders/gpu_shader_instance_screen_aligned_vert.glsl
deleted file mode 100644
index 374dcab2415..00000000000
--- a/source/blender/gpu/shaders/gpu_shader_instance_screen_aligned_vert.glsl
+++ /dev/null
@@ -1,43 +0,0 @@
-
-uniform mat4 ViewProjectionMatrix;
-#ifdef USE_WORLD_CLIP_PLANES
-uniform mat4 ModelMatrix;
-#endif
-uniform vec3 screen_vecs[2];
-
-/* ---- Instantiated Attrs ---- */
-in vec3 pos; /* using Z as axis id */
-
-/* ---- Per instance Attrs ---- */
-in mat4 InstanceModelMatrix;
-in vec3 color;
-in float size;
-
-flat out vec4 finalColor;
-
-void main()
-{
- vec3 offset = vec3(0.0);
-
-#ifdef AXIS_NAME
- if (pos.z == 0.0) {
- offset = vec3(1.125, 0.0, 0.0);
- }
- else if (pos.z == 1.0) {
- offset = vec3(0.0, 1.125, 0.0);
- }
- else {
- offset = vec3(0.0, 0.0, 1.125);
- }
- offset *= size;
-#endif
-
- vec3 screen_pos = screen_vecs[0].xyz * pos.x + screen_vecs[1].xyz * pos.y;
- vec4 pos_4d = InstanceModelMatrix * vec4(offset, 1.0) + vec4(screen_pos * size, 0.0);
- gl_Position = ViewProjectionMatrix * pos_4d;
- finalColor = vec4(color, 1.0);
-
-#ifdef USE_WORLD_CLIP_PLANES
- world_clip_planes_calc_clip_distance((ModelMatrix * pos_4d).xyz);
-#endif
-}
diff --git a/source/blender/gpu/shaders/gpu_shader_instance_screenspace_variying_color_vert.glsl b/source/blender/gpu/shaders/gpu_shader_instance_screenspace_variying_color_vert.glsl
deleted file mode 100644
index c7368f78890..00000000000
--- a/source/blender/gpu/shaders/gpu_shader_instance_screenspace_variying_color_vert.glsl
+++ /dev/null
@@ -1,32 +0,0 @@
-
-uniform mat4 ViewProjectionMatrix;
-uniform vec3 screen_vecs[2];
-uniform float size;
-uniform float pixel_size;
-
-/* ---- Instantiated Attrs ---- */
-in vec2 pos;
-
-/* ---- Per instance Attrs ---- */
-in vec3 world_pos;
-in vec3 color;
-
-flat out vec4 finalColor;
-
-float mul_project_m4_v3_zfac(in vec3 co)
-{
- return (ViewProjectionMatrix[0][3] * co.x) + (ViewProjectionMatrix[1][3] * co.y) +
- (ViewProjectionMatrix[2][3] * co.z) + ViewProjectionMatrix[3][3];
-}
-
-void main()
-{
- float pix_size = mul_project_m4_v3_zfac(world_pos) * pixel_size;
- vec3 screen_pos = screen_vecs[0].xyz * pos.x + screen_vecs[1].xyz * pos.y;
- gl_Position = ViewProjectionMatrix * vec4(world_pos + screen_pos * size * pix_size, 1.0);
- finalColor = vec4(color, 1.0);
-
-#ifdef USE_WORLD_CLIP_PLANES
- world_clip_planes_calc_clip_distance(world_pos);
-#endif
-}
diff --git a/source/blender/gpu/shaders/gpu_shader_instance_variying_size_variying_id_vert.glsl b/source/blender/gpu/shaders/gpu_shader_instance_variying_size_variying_id_vert.glsl
deleted file mode 100644
index 32db8d17572..00000000000
--- a/source/blender/gpu/shaders/gpu_shader_instance_variying_size_variying_id_vert.glsl
+++ /dev/null
@@ -1,29 +0,0 @@
-
-uniform mat4 ViewProjectionMatrix;
-
-uniform int baseId;
-
-/* ---- Instantiated Attrs ---- */
-in vec3 pos;
-
-/* ---- Per instance Attrs ---- */
-in mat4 InstanceModelMatrix;
-#ifdef UNIFORM_SCALE
-in float size;
-#else
-in vec3 size;
-#endif
-in int callId;
-
-flat out uint finalId;
-
-void main()
-{
- vec4 wPos = InstanceModelMatrix * vec4(pos * size, 1.0);
- gl_Position = ViewProjectionMatrix * wPos;
- finalId = uint(baseId + callId);
-
-#ifdef USE_WORLD_CLIP_PLANES
- world_clip_planes_calc_clip_distance(wPos.xyz);
-#endif
-}
diff --git a/source/blender/gpu/shaders/gpu_shader_instance_vert.glsl b/source/blender/gpu/shaders/gpu_shader_instance_vert.glsl
deleted file mode 100644
index b8d31f5540a..00000000000
--- a/source/blender/gpu/shaders/gpu_shader_instance_vert.glsl
+++ /dev/null
@@ -1,13 +0,0 @@
-
-uniform mat4 ViewProjectionMatrix;
-
-/* ---- Instantiated Attrs ---- */
-in vec3 pos;
-
-/* ---- Per instance Attrs ---- */
-in mat4 InstanceModelMatrix;
-
-void main()
-{
- gl_Position = ViewProjectionMatrix * (InstanceModelMatrix * vec4(pos, 1.0));
-}
diff --git a/source/blender/gpu/shaders/gpu_shader_text_frag.glsl b/source/blender/gpu/shaders/gpu_shader_text_frag.glsl
index 4a6ce4fd3ac..f9f195c31d6 100644
--- a/source/blender/gpu/shaders/gpu_shader_text_frag.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_text_frag.glsl
@@ -1,6 +1,5 @@
flat in vec4 color_flat;
-flat in vec4 texCoord_rect;
noperspective in vec2 texCoord_interp;
out vec4 fragColor;
@@ -34,16 +33,16 @@ void main()
fragColor.rgb = color_flat.rgb;
vec2 texel = 1.0 / vec2(textureSize(glyph, 0));
- vec2 texco = mix(abs(texCoord_rect.xy), abs(texCoord_rect.zw), texCoord_interp);
+ vec2 texco = abs(texCoord_interp);
// modulate input alpha & texture alpha
- if (texCoord_rect.x > 0) {
+ if (texCoord_interp.x > 0) {
fragColor.a = texture(glyph, texco).r;
}
else {
fragColor.a = 0.0;
- if (texCoord_rect.w > 0) {
+ if (texCoord_interp.y > 0) {
/* 3x3 blur */
/* Manual unroll for perf. (stupid glsl compiler) */
fragColor.a += sample_glyph_offset(texco, texel, offsets4[0]);
diff --git a/source/blender/gpu/shaders/gpu_shader_text_geom.glsl b/source/blender/gpu/shaders/gpu_shader_text_geom.glsl
deleted file mode 100644
index 12ccbf00130..00000000000
--- a/source/blender/gpu/shaders/gpu_shader_text_geom.glsl
+++ /dev/null
@@ -1,37 +0,0 @@
-
-uniform mat4 ModelViewProjectionMatrix;
-
-layout(points) in;
-layout(triangle_strip, max_vertices = 4) out;
-
-in vec4 pos_rect[];
-in vec4 tex_rect[];
-in vec4 color[];
-
-flat out vec4 color_flat;
-flat out vec4 texCoord_rect;
-noperspective out vec2 texCoord_interp;
-
-void main()
-{
- color_flat = color[0];
- texCoord_rect = tex_rect[0];
-
- gl_Position = (ModelViewProjectionMatrix * vec4(pos_rect[0].xy, 0.0, 1.0));
- texCoord_interp = vec2(0.0, 0.0);
- EmitVertex();
-
- gl_Position = (ModelViewProjectionMatrix * vec4(pos_rect[0].zy, 0.0, 1.0));
- texCoord_interp = vec2(1.0, 0.0);
- EmitVertex();
-
- gl_Position = (ModelViewProjectionMatrix * vec4(pos_rect[0].xw, 0.0, 1.0));
- texCoord_interp = vec2(0.0, 1.0);
- EmitVertex();
-
- gl_Position = (ModelViewProjectionMatrix * vec4(pos_rect[0].zw, 0.0, 1.0));
- texCoord_interp = vec2(1.0, 1.0);
- EmitVertex();
-
- EndPrimitive();
-}
diff --git a/source/blender/gpu/shaders/gpu_shader_text_simple_geom.glsl b/source/blender/gpu/shaders/gpu_shader_text_simple_geom.glsl
deleted file mode 100644
index 7a8a872f919..00000000000
--- a/source/blender/gpu/shaders/gpu_shader_text_simple_geom.glsl
+++ /dev/null
@@ -1,36 +0,0 @@
-
-layout(points) in;
-layout(triangle_strip, max_vertices = 4) out;
-
-in vec4 pos_rect[];
-in vec4 tex_rect[];
-in vec4 color[];
-
-flat out vec4 color_flat;
-flat out vec4 texCoord_rect;
-noperspective out vec2 texCoord_interp;
-
-void main()
-{
- color_flat = color[0];
- texCoord_rect = tex_rect[0];
- gl_Position.zw = vec2(0.0, 1.0);
-
- gl_Position.xy = pos_rect[0].xy;
- texCoord_interp = vec2(0.0, 0.0);
- EmitVertex();
-
- gl_Position.xy = pos_rect[0].zy;
- texCoord_interp = vec2(1.0, 0.0);
- EmitVertex();
-
- gl_Position.xy = pos_rect[0].xw;
- texCoord_interp = vec2(0.0, 1.0);
- EmitVertex();
-
- gl_Position.xy = pos_rect[0].zw;
- texCoord_interp = vec2(1.0, 1.0);
- EmitVertex();
-
- EndPrimitive();
-}
diff --git a/source/blender/gpu/shaders/gpu_shader_text_simple_vert.glsl b/source/blender/gpu/shaders/gpu_shader_text_simple_vert.glsl
deleted file mode 100644
index a8a79ffe6c9..00000000000
--- a/source/blender/gpu/shaders/gpu_shader_text_simple_vert.glsl
+++ /dev/null
@@ -1,22 +0,0 @@
-
-/* Simpler version of gpu_shader_text_vert that supports only 2D translation. */
-
-uniform mat4 ModelViewProjectionMatrix;
-
-in vec4 pos; /* rect */
-in vec4 tex; /* rect */
-in vec4 col;
-
-out vec4 pos_rect;
-out vec4 tex_rect;
-out vec4 color;
-
-void main()
-{
- /* Manual mat4*vec2 */
- pos_rect = ModelViewProjectionMatrix[0].xyxy * pos.xxzz;
- pos_rect += ModelViewProjectionMatrix[1].xyxy * pos.yyww;
- pos_rect += ModelViewProjectionMatrix[3].xyxy;
- tex_rect = tex;
- color = col;
-}
diff --git a/source/blender/gpu/shaders/gpu_shader_text_vert.glsl b/source/blender/gpu/shaders/gpu_shader_text_vert.glsl
index d8e4b2bc986..28437208e91 100644
--- a/source/blender/gpu/shaders/gpu_shader_text_vert.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_text_vert.glsl
@@ -5,13 +5,17 @@ in vec4 pos; /* rect */
in vec4 tex; /* rect */
in vec4 col;
-out vec4 pos_rect;
-out vec4 tex_rect;
-out vec4 color;
+flat out vec4 color_flat;
+noperspective out vec2 texCoord_interp;
void main()
{
- pos_rect = pos;
- tex_rect = tex;
- color = col;
+ /* Quad expension using instanced rendering. */
+ float x = float(gl_VertexID % 2);
+ float y = float(gl_VertexID / 2);
+ vec2 quad = vec2(x, y);
+
+ gl_Position = ModelViewProjectionMatrix * vec4(mix(pos.xy, pos.zw, quad), 0.0, 1.0);
+ texCoord_interp = mix(abs(tex.xy), abs(tex.zw), quad) * sign(tex.xw);
+ color_flat = col;
}
diff --git a/source/blender/gpu/shaders/material/gpu_shader_material_normal_map.glsl b/source/blender/gpu/shaders/material/gpu_shader_material_normal_map.glsl
index 6930e0c5dad..a9be6bfa0ff 100644
--- a/source/blender/gpu/shaders/material/gpu_shader_material_normal_map.glsl
+++ b/source/blender/gpu/shaders/material/gpu_shader_material_normal_map.glsl
@@ -5,7 +5,7 @@ void node_normal_map(vec4 info, vec4 tangent, vec3 normal, vec3 texnormal, out v
return;
}
tangent *= (gl_FrontFacing ? 1.0 : -1.0);
- vec3 B = tangent.w * cross(normal, tangent.xyz) * info.w;
+ vec3 B = tangent.w * cross(normal, tangent.xyz) * sign(info.w);
outnormal = texnormal.x * tangent.xyz + texnormal.y * B + texnormal.z * normal;
outnormal = normalize(outnormal);