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
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')
-rw-r--r--source/blender/gpu/CMakeLists.txt16
-rw-r--r--source/blender/gpu/GPU_batch.h4
-rw-r--r--source/blender/gpu/GPU_shader.h19
-rw-r--r--source/blender/gpu/GPU_vertex_buffer.h2
-rw-r--r--source/blender/gpu/intern/gpu_batch.c57
-rw-r--r--source/blender/gpu/intern/gpu_shader.c112
-rw-r--r--source/blender/gpu/intern/gpu_vertex_buffer.c13
-rw-r--r--source/blender/gpu/intern/gpu_viewport.c1
-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
31 files changed, 104 insertions, 828 deletions
diff --git a/source/blender/gpu/CMakeLists.txt b/source/blender/gpu/CMakeLists.txt
index 9320e849194..bcdc1550fd2 100644
--- a/source/blender/gpu/CMakeLists.txt
+++ b/source/blender/gpu/CMakeLists.txt
@@ -158,7 +158,6 @@ data_to_c_simple(shaders/gpu_shader_2D_nodelink_vert.glsl SRC)
data_to_c_simple(shaders/gpu_shader_2D_flat_color_vert.glsl SRC)
data_to_c_simple(shaders/gpu_shader_2D_line_dashed_uniform_color_vert.glsl SRC)
data_to_c_simple(shaders/gpu_shader_2D_line_dashed_frag.glsl SRC)
-data_to_c_simple(shaders/gpu_shader_2D_line_dashed_geom.glsl SRC)
data_to_c_simple(shaders/gpu_shader_2D_smooth_color_vert.glsl SRC)
data_to_c_simple(shaders/gpu_shader_2D_smooth_color_frag.glsl SRC)
data_to_c_simple(shaders/gpu_shader_2D_smooth_color_dithered_frag.glsl SRC)
@@ -189,19 +188,7 @@ data_to_c_simple(shaders/gpu_shader_3D_smooth_color_frag.glsl SRC)
data_to_c_simple(shaders/gpu_shader_3D_passthrough_vert.glsl SRC)
data_to_c_simple(shaders/gpu_shader_3D_clipped_uniform_color_vert.glsl SRC)
-data_to_c_simple(shaders/gpu_shader_instance_vert.glsl SRC)
data_to_c_simple(shaders/gpu_shader_instance_variying_size_variying_color_vert.glsl SRC)
-data_to_c_simple(shaders/gpu_shader_instance_variying_size_variying_id_vert.glsl SRC)
-data_to_c_simple(shaders/gpu_shader_instance_objectspace_variying_color_vert.glsl SRC)
-data_to_c_simple(shaders/gpu_shader_instance_screenspace_variying_color_vert.glsl SRC)
-data_to_c_simple(shaders/gpu_shader_instance_screen_aligned_vert.glsl SRC)
-data_to_c_simple(shaders/gpu_shader_instance_camera_vert.glsl SRC)
-data_to_c_simple(shaders/gpu_shader_instance_distance_line_vert.glsl SRC)
-data_to_c_simple(shaders/gpu_shader_instance_edges_variying_color_geom.glsl SRC)
-data_to_c_simple(shaders/gpu_shader_instance_edges_variying_color_vert.glsl SRC)
-
-data_to_c_simple(shaders/gpu_shader_3D_groundline_geom.glsl SRC)
-data_to_c_simple(shaders/gpu_shader_3D_groundpoint_vert.glsl SRC)
data_to_c_simple(shaders/gpu_shader_point_uniform_color_frag.glsl SRC)
data_to_c_simple(shaders/gpu_shader_point_uniform_color_aa_frag.glsl SRC)
@@ -225,10 +212,7 @@ data_to_c_simple(shaders/gpu_shader_2D_edituvs_edges_vert.glsl SRC)
data_to_c_simple(shaders/gpu_shader_2D_edituvs_faces_vert.glsl SRC)
data_to_c_simple(shaders/gpu_shader_2D_edituvs_stretch_vert.glsl SRC)
-data_to_c_simple(shaders/gpu_shader_text_simple_vert.glsl SRC)
-data_to_c_simple(shaders/gpu_shader_text_simple_geom.glsl SRC)
data_to_c_simple(shaders/gpu_shader_text_vert.glsl SRC)
-data_to_c_simple(shaders/gpu_shader_text_geom.glsl SRC)
data_to_c_simple(shaders/gpu_shader_text_frag.glsl SRC)
data_to_c_simple(shaders/gpu_shader_keyframe_diamond_vert.glsl SRC)
data_to_c_simple(shaders/gpu_shader_keyframe_diamond_frag.glsl SRC)
diff --git a/source/blender/gpu/GPU_batch.h b/source/blender/gpu/GPU_batch.h
index d7218e97bf0..3616189e673 100644
--- a/source/blender/gpu/GPU_batch.h
+++ b/source/blender/gpu/GPU_batch.h
@@ -41,6 +41,7 @@ typedef enum {
} GPUBatchPhase;
#define GPU_BATCH_VBO_MAX_LEN 6
+#define GPU_BATCH_INST_VBO_MAX_LEN 2
#define GPU_BATCH_VAO_STATIC_LEN 3
#define GPU_BATCH_VAO_DYN_ALLOC_COUNT 16
@@ -50,7 +51,7 @@ typedef struct GPUBatch {
/** verts[0] is required, others can be NULL */
GPUVertBuf *verts[GPU_BATCH_VBO_MAX_LEN];
/** Instance attributes. */
- GPUVertBuf *inst;
+ GPUVertBuf *inst[GPU_BATCH_INST_VBO_MAX_LEN];
/** NULL if element list not needed */
GPUIndexBuf *elem;
uint32_t gl_prim_type;
@@ -117,6 +118,7 @@ void GPU_batch_callback_free_set(GPUBatch *, void (*callback)(GPUBatch *, void *
void GPU_batch_instbuf_set(GPUBatch *, GPUVertBuf *, bool own_vbo); /* Instancing */
void GPU_batch_elembuf_set(GPUBatch *batch, GPUIndexBuf *elem, bool own_ibo);
+int GPU_batch_instbuf_add_ex(GPUBatch *, GPUVertBuf *, bool own_vbo);
int GPU_batch_vertbuf_add_ex(GPUBatch *, GPUVertBuf *, bool own_vbo);
#define GPU_batch_vertbuf_add(batch, verts) GPU_batch_vertbuf_add_ex(batch, verts, false)
diff --git a/source/blender/gpu/GPU_shader.h b/source/blender/gpu/GPU_shader.h
index b169b84c5b8..e877646310b 100644
--- a/source/blender/gpu/GPU_shader.h
+++ b/source/blender/gpu/GPU_shader.h
@@ -105,7 +105,6 @@ char *GPU_shader_get_binary(GPUShader *shader, uint *r_binary_format, int *r_bin
typedef enum eGPUBuiltinShader {
/* specialized drawing */
GPU_SHADER_TEXT,
- GPU_SHADER_TEXT_SIMPLE,
GPU_SHADER_KEYFRAME_DIAMOND,
GPU_SHADER_SIMPLE_LIGHTING,
GPU_SHADER_SIMPLE_LIGHTING_FLAT_COLOR,
@@ -316,26 +315,8 @@ typedef enum eGPUBuiltinShader {
/* lines */
GPU_SHADER_2D_LINE_DASHED_UNIFORM_COLOR,
GPU_SHADER_3D_LINE_DASHED_UNIFORM_COLOR,
- /* light drawing */
- GPU_SHADER_3D_GROUNDPOINT,
- GPU_SHADER_3D_GROUNDLINE,
- GPU_SHADER_3D_SCREENSPACE_VARIYING_COLOR,
- /* bone drawing */
- GPU_SHADER_3D_OBJECTSPACE_VARIYING_COLOR,
- GPU_SHADER_3D_OBJECTSPACE_SIMPLE_LIGHTING_VARIYING_COLOR,
- /* camera drawing */
- GPU_SHADER_CAMERA,
- /* distance in front of objects */
- GPU_SHADER_DISTANCE_LINES,
- /* axis name */
- GPU_SHADER_3D_INSTANCE_SCREEN_ALIGNED_AXIS,
- GPU_SHADER_3D_INSTANCE_SCREEN_ALIGNED,
/* instance */
- GPU_SHADER_INSTANCE_UNIFORM_COLOR,
- GPU_SHADER_INSTANCE_VARIYING_ID_VARIYING_SIZE, /* Uniformly scaled */
GPU_SHADER_INSTANCE_VARIYING_COLOR_VARIYING_SIZE, /* Uniformly scaled */
- GPU_SHADER_INSTANCE_VARIYING_COLOR_VARIYING_SCALE,
- GPU_SHADER_INSTANCE_EDGES_VARIYING_COLOR,
/* grease pencil drawing */
GPU_SHADER_GPENCIL_STROKE,
GPU_SHADER_GPENCIL_FILL,
diff --git a/source/blender/gpu/GPU_vertex_buffer.h b/source/blender/gpu/GPU_vertex_buffer.h
index 2d728422c42..99d32f24cc3 100644
--- a/source/blender/gpu/GPU_vertex_buffer.h
+++ b/source/blender/gpu/GPU_vertex_buffer.h
@@ -88,6 +88,8 @@ void GPU_vertbuf_data_len_set(GPUVertBuf *, uint v_len);
void GPU_vertbuf_attr_set(GPUVertBuf *, uint a_idx, uint v_idx, const void *data);
+void GPU_vertbuf_vert_set(GPUVertBuf *verts, uint v_idx, const void *data);
+
/* Tightly packed, non interleaved input data. */
void GPU_vertbuf_attr_fill(GPUVertBuf *, uint a_idx, const void *data);
diff --git a/source/blender/gpu/intern/gpu_batch.c b/source/blender/gpu/intern/gpu_batch.c
index 23692cb20ec..717983f94d8 100644
--- a/source/blender/gpu/intern/gpu_batch.c
+++ b/source/blender/gpu/intern/gpu_batch.c
@@ -103,7 +103,9 @@ void GPU_batch_init_ex(
for (int v = 1; v < GPU_BATCH_VBO_MAX_LEN; v++) {
batch->verts[v] = NULL;
}
- batch->inst = NULL;
+ for (int v = 0; v < GPU_BATCH_INST_VBO_MAX_LEN; v++) {
+ batch->inst[v] = NULL;
+ }
batch->elem = elem;
batch->gl_prim_type = convert_prim_type_to_gl(prim_type);
batch->phase = GPU_BATCH_READY_TO_DRAW;
@@ -129,7 +131,8 @@ void GPU_batch_clear(GPUBatch *batch)
GPU_indexbuf_discard(batch->elem);
}
if (batch->owns_flag & GPU_BATCH_OWNS_INSTANCES) {
- GPU_vertbuf_discard(batch->inst);
+ GPU_vertbuf_discard(batch->inst[0]);
+ GPU_VERTBUF_DISCARD_SAFE(batch->inst[1]);
}
if ((batch->owns_flag & ~GPU_BATCH_OWNS_INDEX) != 0) {
for (int v = 0; v < GPU_BATCH_VBO_MAX_LEN; v++) {
@@ -171,10 +174,11 @@ void GPU_batch_instbuf_set(GPUBatch *batch, GPUVertBuf *inst, bool own_vbo)
/* redo the bindings */
GPU_batch_vao_cache_clear(batch);
- if (batch->inst != NULL && (batch->owns_flag & GPU_BATCH_OWNS_INSTANCES)) {
- GPU_vertbuf_discard(batch->inst);
+ if (batch->inst[0] != NULL && (batch->owns_flag & GPU_BATCH_OWNS_INSTANCES)) {
+ GPU_vertbuf_discard(batch->inst[0]);
+ GPU_VERTBUF_DISCARD_SAFE(batch->inst[1]);
}
- batch->inst = inst;
+ batch->inst[0] = inst;
if (own_vbo) {
batch->owns_flag |= GPU_BATCH_OWNS_INSTANCES;
@@ -203,6 +207,37 @@ void GPU_batch_elembuf_set(GPUBatch *batch, GPUIndexBuf *elem, bool own_ibo)
}
}
+/* A bit of a quick hack. Should be streamlined as the vbos handling */
+int GPU_batch_instbuf_add_ex(GPUBatch *batch, GPUVertBuf *insts, bool own_vbo)
+{
+ /* redo the bindings */
+ GPU_batch_vao_cache_clear(batch);
+
+ for (uint v = 0; v < GPU_BATCH_INST_VBO_MAX_LEN; v++) {
+ if (batch->inst[v] == NULL) {
+#if TRUST_NO_ONE
+ /* for now all VertexBuffers must have same vertex_len */
+ if (batch->inst[0] != NULL) {
+ /* Allow for different size of vertex buf (will choose the smallest number of verts). */
+ // assert(insts->vertex_len == batch->inst[0]->vertex_len);
+ assert(own_vbo == ((batch->owns_flag & GPU_BATCH_OWNS_INSTANCES) != 0));
+ }
+#endif
+ batch->inst[v] = insts;
+ if (own_vbo) {
+ batch->owns_flag |= GPU_BATCH_OWNS_INSTANCES;
+ }
+ return v;
+ }
+ }
+
+ /* we only make it this far if there is no room for another GPUVertBuf */
+#if TRUST_NO_ONE
+ assert(false);
+#endif
+ return -1;
+}
+
/* Returns the index of verts in the batch. */
int GPU_batch_vertbuf_add_ex(GPUBatch *batch, GPUVertBuf *verts, bool own_vbo)
{
@@ -458,8 +493,10 @@ static void batch_update_program_bindings(GPUBatch *batch, uint i_first)
create_bindings(batch->verts[v], batch->interface, 0, false);
}
}
- if (batch->inst) {
- create_bindings(batch->inst, batch->interface, i_first, true);
+ for (int v = GPU_BATCH_INST_VBO_MAX_LEN - 1; v > -1; v--) {
+ if (batch->inst[v]) {
+ create_bindings(batch->inst[v], batch->interface, i_first, true);
+ }
}
if (batch->elem) {
GPU_indexbuf_use(batch->elem);
@@ -639,7 +676,11 @@ void GPU_batch_draw_advanced(GPUBatch *batch, int v_first, int v_count, int i_fi
v_count = (batch->elem) ? batch->elem->index_len : batch->verts[0]->vertex_len;
}
if (i_count == 0) {
- i_count = (batch->inst) ? batch->inst->vertex_len : 1;
+ i_count = (batch->inst[0]) ? batch->inst[0]->vertex_len : 1;
+ /* Meh. This is to be able to use different numbers of verts in instance vbos. */
+ if (batch->inst[1] && i_count > batch->inst[1]->vertex_len) {
+ i_count = batch->inst[1]->vertex_len;
+ }
}
if (v_count == 0 || i_count == 0) {
diff --git a/source/blender/gpu/intern/gpu_shader.c b/source/blender/gpu/intern/gpu_shader.c
index 5df73d1a0c6..ae2c7864e36 100644
--- a/source/blender/gpu/intern/gpu_shader.c
+++ b/source/blender/gpu/intern/gpu_shader.c
@@ -102,20 +102,7 @@ extern char datatoc_gpu_shader_3D_smooth_color_frag_glsl[];
extern char datatoc_gpu_shader_3D_passthrough_vert_glsl[];
extern char datatoc_gpu_shader_3D_clipped_uniform_color_vert_glsl[];
-extern char datatoc_gpu_shader_instance_vert_glsl[];
extern char datatoc_gpu_shader_instance_variying_size_variying_color_vert_glsl[];
-extern char datatoc_gpu_shader_instance_variying_size_variying_id_vert_glsl[];
-extern char datatoc_gpu_shader_instance_objectspace_variying_color_vert_glsl[];
-extern char datatoc_gpu_shader_instance_screenspace_variying_color_vert_glsl[];
-extern char datatoc_gpu_shader_instance_screen_aligned_vert_glsl[];
-extern char datatoc_gpu_shader_instance_camera_vert_glsl[];
-extern char datatoc_gpu_shader_instance_distance_line_vert_glsl[];
-extern char datatoc_gpu_shader_instance_edges_variying_color_geom_glsl[];
-extern char datatoc_gpu_shader_instance_edges_variying_color_vert_glsl[];
-extern char datatoc_gpu_shader_instance_mball_handles_vert_glsl[];
-
-extern char datatoc_gpu_shader_3D_groundpoint_vert_glsl[];
-extern char datatoc_gpu_shader_3D_groundline_geom_glsl[];
extern char datatoc_gpu_shader_point_uniform_color_frag_glsl[];
extern char datatoc_gpu_shader_point_uniform_color_aa_frag_glsl[];
@@ -141,14 +128,10 @@ extern char datatoc_gpu_shader_2D_edituvs_stretch_vert_glsl[];
extern char datatoc_gpu_shader_2D_line_dashed_uniform_color_vert_glsl[];
extern char datatoc_gpu_shader_2D_line_dashed_frag_glsl[];
-extern char datatoc_gpu_shader_2D_line_dashed_geom_glsl[];
extern char datatoc_gpu_shader_3D_line_dashed_uniform_color_vert_glsl[];
extern char datatoc_gpu_shader_text_vert_glsl[];
-extern char datatoc_gpu_shader_text_geom_glsl[];
extern char datatoc_gpu_shader_text_frag_glsl[];
-extern char datatoc_gpu_shader_text_simple_vert_glsl[];
-extern char datatoc_gpu_shader_text_simple_geom_glsl[];
extern char datatoc_gpu_shader_keyframe_diamond_vert_glsl[];
extern char datatoc_gpu_shader_keyframe_diamond_frag_glsl[];
@@ -885,13 +868,6 @@ static const GPUShaderStages builtin_shader_stages[GPU_SHADER_BUILTIN_LEN] = {
[GPU_SHADER_TEXT] =
{
.vert = datatoc_gpu_shader_text_vert_glsl,
- .geom = datatoc_gpu_shader_text_geom_glsl,
- .frag = datatoc_gpu_shader_text_frag_glsl,
- },
- [GPU_SHADER_TEXT_SIMPLE] =
- {
- .vert = datatoc_gpu_shader_text_simple_vert_glsl,
- .geom = datatoc_gpu_shader_text_simple_geom_glsl,
.frag = datatoc_gpu_shader_text_frag_glsl,
},
[GPU_SHADER_KEYFRAME_DIAMOND] =
@@ -1105,70 +1081,17 @@ static const GPUShaderStages builtin_shader_stages[GPU_SHADER_BUILTIN_LEN] = {
.frag = datatoc_gpu_shader_uniform_color_frag_glsl,
},
- [GPU_SHADER_3D_GROUNDPOINT] =
- {
- .vert = datatoc_gpu_shader_3D_groundpoint_vert_glsl,
- .frag = datatoc_gpu_shader_point_uniform_color_frag_glsl,
- },
- [GPU_SHADER_3D_GROUNDLINE] =
- {
- .vert = datatoc_gpu_shader_3D_passthrough_vert_glsl,
- .geom = datatoc_gpu_shader_3D_groundline_geom_glsl,
- .frag = datatoc_gpu_shader_uniform_color_frag_glsl,
- },
-
[GPU_SHADER_2D_LINE_DASHED_UNIFORM_COLOR] =
{
.vert = datatoc_gpu_shader_2D_line_dashed_uniform_color_vert_glsl,
- .geom = datatoc_gpu_shader_2D_line_dashed_geom_glsl,
.frag = datatoc_gpu_shader_2D_line_dashed_frag_glsl,
},
[GPU_SHADER_3D_LINE_DASHED_UNIFORM_COLOR] =
{
.vert = datatoc_gpu_shader_3D_line_dashed_uniform_color_vert_glsl,
- .geom = datatoc_gpu_shader_2D_line_dashed_geom_glsl,
.frag = datatoc_gpu_shader_2D_line_dashed_frag_glsl,
},
- [GPU_SHADER_3D_OBJECTSPACE_SIMPLE_LIGHTING_VARIYING_COLOR] =
- {
- .vert = datatoc_gpu_shader_instance_objectspace_variying_color_vert_glsl,
- .frag = datatoc_gpu_shader_simple_lighting_frag_glsl,
- .defs = "#define USE_INSTANCE_COLOR\n",
- },
- [GPU_SHADER_3D_OBJECTSPACE_VARIYING_COLOR] =
- {
- .vert = datatoc_gpu_shader_instance_objectspace_variying_color_vert_glsl,
- .frag = datatoc_gpu_shader_flat_color_frag_glsl,
- },
- [GPU_SHADER_3D_SCREENSPACE_VARIYING_COLOR] =
- {
- .vert = datatoc_gpu_shader_instance_screenspace_variying_color_vert_glsl,
- .frag = datatoc_gpu_shader_flat_color_frag_glsl,
- },
- [GPU_SHADER_3D_INSTANCE_SCREEN_ALIGNED_AXIS] =
- {
- .vert = datatoc_gpu_shader_instance_screen_aligned_vert_glsl,
- .frag = datatoc_gpu_shader_flat_color_frag_glsl,
- .defs = "#define AXIS_NAME\n",
- },
- [GPU_SHADER_3D_INSTANCE_SCREEN_ALIGNED] =
- {
- .vert = datatoc_gpu_shader_instance_screen_aligned_vert_glsl,
- .frag = datatoc_gpu_shader_flat_color_frag_glsl,
- },
-
- [GPU_SHADER_CAMERA] =
- {
- .vert = datatoc_gpu_shader_instance_camera_vert_glsl,
- .frag = datatoc_gpu_shader_flat_color_frag_glsl,
- },
- [GPU_SHADER_DISTANCE_LINES] =
- {
- .vert = datatoc_gpu_shader_instance_distance_line_vert_glsl,
- .frag = datatoc_gpu_shader_flat_color_frag_glsl,
- },
-
[GPU_SHADER_2D_POINT_FIXED_SIZE_UNIFORM_COLOR] =
{
.vert = datatoc_gpu_shader_2D_vert_glsl,
@@ -1225,34 +1148,12 @@ static const GPUShaderStages builtin_shader_stages[GPU_SHADER_BUILTIN_LEN] = {
.frag = datatoc_gpu_shader_point_uniform_color_outline_aa_frag_glsl,
},
- [GPU_SHADER_INSTANCE_UNIFORM_COLOR] =
- {
- .vert = datatoc_gpu_shader_instance_vert_glsl,
- .frag = datatoc_gpu_shader_uniform_color_frag_glsl,
- },
- [GPU_SHADER_INSTANCE_VARIYING_ID_VARIYING_SIZE] =
- {
- .vert = datatoc_gpu_shader_instance_variying_size_variying_id_vert_glsl,
- .frag = datatoc_gpu_shader_flat_id_frag_glsl,
- .defs = "#define UNIFORM_SCALE\n",
- },
[GPU_SHADER_INSTANCE_VARIYING_COLOR_VARIYING_SIZE] =
{
.vert = datatoc_gpu_shader_instance_variying_size_variying_color_vert_glsl,
.frag = datatoc_gpu_shader_flat_color_frag_glsl,
.defs = "#define UNIFORM_SCALE\n",
},
- [GPU_SHADER_INSTANCE_VARIYING_COLOR_VARIYING_SCALE] =
- {
- .vert = datatoc_gpu_shader_instance_variying_size_variying_color_vert_glsl,
- .frag = datatoc_gpu_shader_flat_color_frag_glsl,
- },
- [GPU_SHADER_INSTANCE_EDGES_VARIYING_COLOR] =
- {
- .vert = datatoc_gpu_shader_instance_edges_variying_color_vert_glsl,
- .geom = datatoc_gpu_shader_instance_edges_variying_color_geom_glsl,
- .frag = datatoc_gpu_shader_flat_color_frag_glsl,
- },
[GPU_SHADER_2D_AREA_EDGES] =
{
@@ -1366,22 +1267,11 @@ GPUShader *GPU_shader_get_builtin_shader_with_config(eGPUBuiltinShader shader,
GPU_SHADER_3D_UNIFORM_COLOR,
GPU_SHADER_3D_SMOOTH_COLOR,
GPU_SHADER_3D_DEPTH_ONLY,
- GPU_SHADER_CAMERA,
GPU_SHADER_INSTANCE_VARIYING_COLOR_VARIYING_SIZE,
- GPU_SHADER_INSTANCE_VARIYING_COLOR_VARIYING_SCALE,
GPU_SHADER_3D_POINT_UNIFORM_SIZE_UNIFORM_COLOR_OUTLINE_AA,
GPU_SHADER_3D_POINT_UNIFORM_SIZE_UNIFORM_COLOR_AA,
- GPU_SHADER_3D_SCREENSPACE_VARIYING_COLOR,
- GPU_SHADER_3D_INSTANCE_SCREEN_ALIGNED,
-
- GPU_SHADER_3D_GROUNDLINE,
- GPU_SHADER_3D_GROUNDPOINT,
- GPU_SHADER_DISTANCE_LINES,
- GPU_SHADER_INSTANCE_EDGES_VARIYING_COLOR) ||
- ELEM(shader,
GPU_SHADER_3D_FLAT_COLOR,
- GPU_SHADER_3D_LINE_DASHED_UNIFORM_COLOR,
- GPU_SHADER_INSTANCE_VARIYING_ID_VARIYING_SIZE));
+ GPU_SHADER_3D_LINE_DASHED_UNIFORM_COLOR));
const char *world_clip_lib = datatoc_gpu_shader_cfg_world_clip_lib_glsl;
const char *world_clip_def = "#define USE_WORLD_CLIP_PLANES\n";
/* In rare cases geometry shaders calculate clipping themselves. */
diff --git a/source/blender/gpu/intern/gpu_vertex_buffer.c b/source/blender/gpu/intern/gpu_vertex_buffer.c
index eecbcb9ec94..1df7e68e08b 100644
--- a/source/blender/gpu/intern/gpu_vertex_buffer.c
+++ b/source/blender/gpu/intern/gpu_vertex_buffer.c
@@ -196,6 +196,19 @@ void GPU_vertbuf_attr_fill(GPUVertBuf *verts, uint a_idx, const void *data)
GPU_vertbuf_attr_fill_stride(verts, a_idx, stride, data);
}
+/** Fills a whole vertex (all attribs). Data must match packed layout. */
+void GPU_vertbuf_vert_set(GPUVertBuf *verts, uint v_idx, const void *data)
+{
+ const GPUVertFormat *format = &verts->format;
+
+#if TRUST_NO_ONE
+ assert(v_idx < verts->vertex_alloc);
+ assert(verts->data != NULL);
+#endif
+ verts->dirty = true;
+ memcpy((GLubyte *)verts->data + v_idx * format->stride, data, format->stride);
+}
+
void GPU_vertbuf_attr_fill_stride(GPUVertBuf *verts, uint a_idx, uint stride, const void *data)
{
const GPUVertFormat *format = &verts->format;
diff --git a/source/blender/gpu/intern/gpu_viewport.c b/source/blender/gpu/intern/gpu_viewport.c
index 519cd918b53..972ff87ebcf 100644
--- a/source/blender/gpu/intern/gpu_viewport.c
+++ b/source/blender/gpu/intern/gpu_viewport.c
@@ -145,6 +145,7 @@ GPUViewport *GPU_viewport_create_from_offscreen(struct GPUOffScreen *ofs)
GPU_framebuffer_ensure_config(
&viewport->fbl->depth_only_fb,
{GPU_ATTACHMENT_TEXTURE(viewport->txl->depth), GPU_ATTACHMENT_NONE});
+ /* TODO infront buffer */
}
return viewport;
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);