Overlays: Use common_view_lib.glsl
authorClément Foucault <foucault.clem@gmail.com>
Thu, 9 May 2019 23:57:42 +0000 (01:57 +0200)
committerClément Foucault <foucault.clem@gmail.com>
Fri, 10 May 2019 10:25:16 +0000 (12:25 +0200)
This removes ModelViewProjectionMatrix usage

29 files changed:
source/blender/draw/intern/draw_common.c
source/blender/draw/modes/edit_curve_mode.c
source/blender/draw/modes/edit_lattice_mode.c
source/blender/draw/modes/edit_mesh_mode.c
source/blender/draw/modes/object_mode.c
source/blender/draw/modes/overlay_mode.c
source/blender/draw/modes/paint_texture_mode.c
source/blender/draw/modes/paint_vertex_mode.c
source/blender/draw/modes/particle_mode.c
source/blender/draw/modes/sculpt_mode.c
source/blender/draw/modes/shaders/edit_curve_overlay_handle_vert.glsl
source/blender/draw/modes/shaders/edit_curve_overlay_loosevert_vert.glsl
source/blender/draw/modes/shaders/edit_curve_overlay_normals_vert.glsl
source/blender/draw/modes/shaders/edit_lattice_overlay_loosevert_vert.glsl
source/blender/draw/modes/shaders/edit_mesh_overlay_facefill_vert.glsl
source/blender/draw/modes/shaders/edit_mesh_overlay_mesh_analysis_vert.glsl
source/blender/draw/modes/shaders/edit_normals_vert.glsl
source/blender/draw/modes/shaders/object_empty_image_vert.glsl
source/blender/draw/modes/shaders/object_outline_prepass_vert.glsl
source/blender/draw/modes/shaders/overlay_face_orientation_vert.glsl
source/blender/draw/modes/shaders/paint_face_vert.glsl
source/blender/draw/modes/shaders/paint_texture_vert.glsl
source/blender/draw/modes/shaders/paint_vertex_vert.glsl
source/blender/draw/modes/shaders/paint_weight_vert.glsl
source/blender/draw/modes/shaders/paint_wire_vert.glsl
source/blender/draw/modes/shaders/particle_strand_frag.glsl
source/blender/draw/modes/shaders/particle_strand_vert.glsl
source/blender/draw/modes/shaders/sculpt_mask_vert.glsl
source/blender/draw/modes/shaders/volume_velocity_vert.glsl

index 76fca6fc72d900c505f84b601cf8c9ecf6118809..9abc7ec6c6ee75b6a590f7dea3bcc1384d9536e2 100644 (file)
@@ -1038,18 +1038,23 @@ struct GPUShader *volume_velocity_shader_get(bool use_needle)
   COMMON_Shaders *sh_data = &g_shaders[GPU_SHADER_CFG_DEFAULT];
   if (use_needle) {
     if (sh_data->volume_velocity_needle_sh == NULL) {
-      sh_data->volume_velocity_needle_sh = DRW_shader_create(
+      sh_data->volume_velocity_needle_sh = DRW_shader_create_with_lib(
           datatoc_volume_velocity_vert_glsl,
           NULL,
           datatoc_gpu_shader_flat_color_frag_glsl,
+          datatoc_common_view_lib_glsl,
           "#define USE_NEEDLE");
     }
     return sh_data->volume_velocity_needle_sh;
   }
   else {
     if (sh_data->volume_velocity_sh == NULL) {
-      sh_data->volume_velocity_sh = DRW_shader_create(
-          datatoc_volume_velocity_vert_glsl, NULL, datatoc_gpu_shader_flat_color_frag_glsl, NULL);
+      sh_data->volume_velocity_sh = DRW_shader_create_with_lib(
+          datatoc_volume_velocity_vert_glsl,
+          NULL,
+          datatoc_gpu_shader_flat_color_frag_glsl,
+          datatoc_common_view_lib_glsl,
+          NULL);
     }
     return sh_data->volume_velocity_sh;
   }
index e47393c88c425ac6bd638f0a6e79fe72273f31dd..f1aa4d20a7e354466c11e07652b3b5c2731d5eda 100644 (file)
@@ -39,6 +39,7 @@
  * Not needed for constant color. */
 
 extern char datatoc_common_globals_lib_glsl[];
+extern char datatoc_common_view_lib_glsl[];
 extern char datatoc_edit_curve_overlay_loosevert_vert_glsl[];
 extern char datatoc_edit_curve_overlay_normals_vert_glsl[];
 extern char datatoc_edit_curve_overlay_handle_vert_glsl[];
@@ -124,8 +125,10 @@ static void EDIT_CURVE_engine_init(void *UNUSED(vedata))
 
   if (!sh_data->wire_normals_sh) {
     sh_data->wire_normals_sh = GPU_shader_create_from_arrays({
-        .vert =
-            (const char *[]){sh_cfg_data->lib, datatoc_edit_curve_overlay_normals_vert_glsl, NULL},
+        .vert = (const char *[]){sh_cfg_data->lib,
+                                 datatoc_common_view_lib_glsl,
+                                 datatoc_edit_curve_overlay_normals_vert_glsl,
+                                 NULL},
         .frag = (const char *[]){datatoc_gpu_shader_uniform_color_frag_glsl, NULL},
         .defs = (const char *[]){sh_cfg_data->def, NULL},
     });
@@ -133,8 +136,10 @@ static void EDIT_CURVE_engine_init(void *UNUSED(vedata))
 
   if (!sh_data->overlay_edge_sh) {
     sh_data->overlay_edge_sh = GPU_shader_create_from_arrays({
-        .vert =
-            (const char *[]){sh_cfg_data->lib, datatoc_edit_curve_overlay_handle_vert_glsl, NULL},
+        .vert = (const char *[]){sh_cfg_data->lib,
+                                 datatoc_common_view_lib_glsl,
+                                 datatoc_edit_curve_overlay_handle_vert_glsl,
+                                 NULL},
         .geom = (const char *[]){sh_cfg_data->lib,
                                  datatoc_common_globals_lib_glsl,
                                  datatoc_edit_curve_overlay_handle_geom_glsl,
@@ -148,6 +153,7 @@ static void EDIT_CURVE_engine_init(void *UNUSED(vedata))
     sh_data->overlay_vert_sh = GPU_shader_create_from_arrays({
         .vert = (const char *[]){sh_cfg_data->lib,
                                  datatoc_common_globals_lib_glsl,
+                                 datatoc_common_view_lib_glsl,
                                  datatoc_edit_curve_overlay_loosevert_vert_glsl,
                                  NULL},
         .frag = (const char *[]){datatoc_gpu_shader_point_varying_color_frag_glsl, NULL},
index 273480b8127c3396f430784169dfb43b5240a756..52893e5f54d3dcb2917010b9a560ae26020e8e4b 100644 (file)
@@ -32,6 +32,7 @@
 #include "draw_mode_engines.h"
 
 extern char datatoc_common_globals_lib_glsl[];
+extern char datatoc_common_view_lib_glsl[];
 
 extern char datatoc_edit_lattice_overlay_loosevert_vert_glsl[];
 extern char datatoc_edit_lattice_overlay_frag_glsl[];
@@ -152,6 +153,7 @@ static void EDIT_LATTICE_engine_init(void *vedata)
     sh_data->overlay_vert = GPU_shader_create_from_arrays({
         .vert = (const char *[]){sh_cfg_data->lib,
                                  datatoc_common_globals_lib_glsl,
+                                 datatoc_common_view_lib_glsl,
                                  datatoc_edit_lattice_overlay_loosevert_vert_glsl,
                                  NULL},
         .frag = (const char *[]){datatoc_common_globals_lib_glsl,
index 655b042874357d7e86cab49c0e6288e8a7a180a1..c68a3cb604d5544dda773a7d004bc7eb14ba78a9 100644 (file)
@@ -198,6 +198,7 @@ static void EDIT_MESH_engine_init(void *vedata)
     sh_data->weight_face = GPU_shader_create_from_arrays({
         .vert = (const char *[]){sh_cfg_data->lib,
                                  datatoc_common_globals_lib_glsl,
+                                 datatoc_common_view_lib_glsl,
                                  datatoc_paint_weight_vert_glsl,
                                  NULL},
         .frag = (const char *[]){datatoc_common_globals_lib_glsl,
@@ -290,24 +291,20 @@ static void EDIT_MESH_engine_init(void *vedata)
         .defs = (const char *[]){sh_cfg_data->def, NULL},
     });
 
-    MEM_freeN(lib);
-
     /* Mesh Analysis */
     sh_data->mesh_analysis_face = GPU_shader_create_from_arrays({
-        .vert = (const char *[]){sh_cfg_data->lib,
-                                 datatoc_edit_mesh_overlay_mesh_analysis_vert_glsl,
-                                 NULL},
+        .vert = (const char *[]){lib, datatoc_edit_mesh_overlay_mesh_analysis_vert_glsl, NULL},
         .frag = (const char *[]){datatoc_edit_mesh_overlay_mesh_analysis_frag_glsl, NULL},
         .defs = (const char *[]){sh_cfg_data->def, "#define FACE_COLOR\n", NULL},
     });
     sh_data->mesh_analysis_vertex = GPU_shader_create_from_arrays({
-        .vert = (const char *[]){sh_cfg_data->lib,
-                                 datatoc_edit_mesh_overlay_mesh_analysis_vert_glsl,
-                                 NULL},
+        .vert = (const char *[]){lib, datatoc_edit_mesh_overlay_mesh_analysis_vert_glsl, NULL},
         .frag = (const char *[]){datatoc_edit_mesh_overlay_mesh_analysis_frag_glsl, NULL},
         .defs = (const char *[]){sh_cfg_data->def, "#define VERTEX_COLOR\n", NULL},
     });
 
+    MEM_freeN(lib);
+
     sh_data->depth = DRW_shader_create_3d_depth_only(draw_ctx->sh_cfg);
   }
 }
index 7e5586f1b10c7e224fa4a95e49e4d5d364031eff..cc313620a11f0cba208e3ada351e8e742fc06705 100644 (file)
@@ -468,12 +468,18 @@ static void OBJECT_engine_init(void *vedata)
               "#define DEPTH_BACK " STRINGIFY(OB_EMPTY_IMAGE_DEPTH_BACK) "\n");
 
       sh_data->object_empty_image = GPU_shader_create_from_arrays({
-          .vert = (const char *[]){sh_cfg_data->lib, datatoc_object_empty_image_vert_glsl, NULL},
+          .vert = (const char *[]){sh_cfg_data->lib,
+                                   datatoc_common_view_lib_glsl,
+                                   datatoc_object_empty_image_vert_glsl,
+                                   NULL},
           .frag = (const char *[]){datatoc_object_empty_image_frag_glsl, NULL},
           .defs = (const char *[]){sh_cfg_data->def, empty_image_defs, NULL},
       });
       sh_data->object_empty_image_wire = GPU_shader_create_from_arrays({
-          .vert = (const char *[]){sh_cfg_data->lib, datatoc_object_empty_image_vert_glsl, NULL},
+          .vert = (const char *[]){sh_cfg_data->lib,
+                                   datatoc_common_view_lib_glsl,
+                                   datatoc_object_empty_image_vert_glsl,
+                                   NULL},
           .frag = (const char *[]){datatoc_object_empty_image_frag_glsl, NULL},
           .defs = (const char *[]){sh_cfg_data->def, "#define USE_WIRE\n", empty_image_defs, NULL},
       });
index 99ab842b3bf78f600ad690ef7271a120c81eb2cd..ceb114673d05626c2c4abf004d4db94b6b3cbe8f 100644 (file)
@@ -126,8 +126,10 @@ static void overlay_engine_init(void *vedata)
   if (!sh_data->face_orientation) {
     /* Face orientation */
     sh_data->face_orientation = GPU_shader_create_from_arrays({
-        .vert =
-            (const char *[]){sh_cfg_data->lib, datatoc_overlay_face_orientation_vert_glsl, NULL},
+        .vert = (const char *[]){sh_cfg_data->lib,
+                                 datatoc_common_view_lib_glsl,
+                                 datatoc_overlay_face_orientation_vert_glsl,
+                                 NULL},
         .frag = (const char *[]){datatoc_overlay_face_orientation_frag_glsl, NULL},
         .defs = (const char *[]){sh_cfg_data->def, NULL},
     });
index 3e292f4e4bccb86eac42f5fe21e9119ba52811a8..123dc7fca881ca872dcb2cc9cad69a01f349320b 100644 (file)
@@ -27,6 +27,8 @@
 
 #include "BKE_node.h"
 
+#include "BLI_string_utils.h"
+
 /* If builtin shaders are needed */
 #include "GPU_shader.h"
 #include "GPU_texture.h"
@@ -39,6 +41,7 @@
 #include "DEG_depsgraph_query.h"
 
 extern char datatoc_common_globals_lib_glsl[];
+extern char datatoc_common_view_lib_glsl[];
 extern char datatoc_paint_texture_vert_glsl[];
 extern char datatoc_paint_texture_frag_glsl[];
 extern char datatoc_paint_wire_vert_glsl[];
@@ -132,26 +135,31 @@ static void PAINT_TEXTURE_engine_init(void *UNUSED(vedata))
   if (!e_data.fallback_sh) {
     e_data.fallback_sh = GPU_shader_get_builtin_shader(GPU_SHADER_3D_UNIFORM_COLOR);
 
-    e_data.image_sh = DRW_shader_create_with_lib(datatoc_paint_texture_vert_glsl,
-                                                 NULL,
-                                                 datatoc_paint_texture_frag_glsl,
-                                                 datatoc_common_globals_lib_glsl,
-                                                 NULL);
+    char *lib = BLI_string_joinN(datatoc_common_globals_lib_glsl, datatoc_common_view_lib_glsl);
+
+    e_data.image_sh = DRW_shader_create_with_lib(
+        datatoc_paint_texture_vert_glsl, NULL, datatoc_paint_texture_frag_glsl, lib, NULL);
 
     e_data.image_masking_sh = DRW_shader_create_with_lib(datatoc_paint_texture_vert_glsl,
                                                          NULL,
                                                          datatoc_paint_texture_frag_glsl,
-                                                         datatoc_common_globals_lib_glsl,
+                                                         lib,
                                                          "#define TEXTURE_PAINT_MASK\n");
 
     e_data.wire_overlay_shader = DRW_shader_create_with_lib(datatoc_paint_wire_vert_glsl,
                                                             NULL,
                                                             datatoc_paint_wire_frag_glsl,
-                                                            datatoc_common_globals_lib_glsl,
+                                                            lib,
                                                             "#define VERTEX_MODE\n");
 
-    e_data.face_overlay_shader = DRW_shader_create(
-        datatoc_paint_face_vert_glsl, NULL, datatoc_gpu_shader_uniform_color_frag_glsl, NULL);
+    e_data.face_overlay_shader = DRW_shader_create_with_lib(
+        datatoc_paint_face_vert_glsl,
+        NULL,
+        datatoc_gpu_shader_uniform_color_frag_glsl,
+        datatoc_common_view_lib_glsl,
+        NULL);
+
+    MEM_freeN(lib);
   }
 }
 
index ef3af1255eb9c46a967f0b24de036e824144b145..caf7a5fb18413f6589de8f03ff78eadace14298a 100644 (file)
@@ -42,6 +42,7 @@ extern char datatoc_paint_wire_vert_glsl[];
 extern char datatoc_paint_wire_frag_glsl[];
 extern char datatoc_paint_vert_frag_glsl[];
 extern char datatoc_common_globals_lib_glsl[];
+extern char datatoc_common_view_lib_glsl[];
 
 extern char datatoc_gpu_shader_uniform_color_frag_glsl[];
 
@@ -115,12 +116,16 @@ static void PAINT_VERTEX_engine_init(void *UNUSED(vedata))
 
   if (!sh_data->face_select_overlay) {
     sh_data->by_mode[VERTEX_MODE].color_face = GPU_shader_create_from_arrays({
-        .vert = (const char *[]){sh_cfg_data->lib, datatoc_paint_vertex_vert_glsl, NULL},
+        .vert = (const char *[]){sh_cfg_data->lib,
+                                 datatoc_common_view_lib_glsl,
+                                 datatoc_paint_vertex_vert_glsl,
+                                 NULL},
         .frag = (const char *[]){datatoc_paint_vertex_frag_glsl, NULL},
         .defs = (const char *[]){sh_cfg_data->def, NULL},
     });
     sh_data->by_mode[WEIGHT_MODE].color_face = GPU_shader_create_from_arrays({
         .vert = (const char *[]){sh_cfg_data->lib,
+                                 datatoc_common_view_lib_glsl,
                                  datatoc_common_globals_lib_glsl,
                                  datatoc_paint_weight_vert_glsl,
                                  NULL},
@@ -131,13 +136,17 @@ static void PAINT_VERTEX_engine_init(void *UNUSED(vedata))
     });
 
     sh_data->face_select_overlay = GPU_shader_create_from_arrays({
-        .vert = (const char *[]){sh_cfg_data->lib, datatoc_paint_face_vert_glsl, NULL},
+        .vert = (const char *[]){sh_cfg_data->lib,
+                                 datatoc_common_view_lib_glsl,
+                                 datatoc_paint_face_vert_glsl,
+                                 NULL},
         .frag = (const char *[]){datatoc_gpu_shader_uniform_color_frag_glsl, NULL},
         .defs = (const char *[]){sh_cfg_data->def, NULL},
     });
     sh_data->vert_select_overlay = GPU_shader_create_from_arrays({
         .vert = (const char *[]){sh_cfg_data->lib,
                                  datatoc_common_globals_lib_glsl,
+                                 datatoc_common_view_lib_glsl,
                                  datatoc_paint_wire_vert_glsl,
                                  NULL},
         .frag = (const char *[]){datatoc_paint_vert_frag_glsl, NULL},
@@ -152,6 +161,7 @@ static void PAINT_VERTEX_engine_init(void *UNUSED(vedata))
       sh_data->by_mode[i].wire_overlay = GPU_shader_create_from_arrays({
           .vert = (const char *[]){sh_cfg_data->lib,
                                    datatoc_common_globals_lib_glsl,
+                                   datatoc_common_view_lib_glsl,
                                    datatoc_paint_wire_vert_glsl,
                                    NULL},
           .frag = (const char *[]){datatoc_paint_wire_frag_glsl, NULL},
@@ -160,6 +170,7 @@ static void PAINT_VERTEX_engine_init(void *UNUSED(vedata))
       sh_data->by_mode[i].wire_select_overlay = GPU_shader_create_from_arrays({
           .vert = (const char *[]){sh_cfg_data->lib,
                                    datatoc_common_globals_lib_glsl,
+                                   datatoc_common_view_lib_glsl,
                                    datatoc_paint_wire_vert_glsl,
                                    NULL},
           .frag = (const char *[]){datatoc_paint_wire_frag_glsl, NULL},
index 600a29fecb4127a3db7aee2b698a3d40a8f30a21..60cc95dac4cf7344ef8bfa8016035c4ca37e8b6d 100644 (file)
@@ -27,6 +27,8 @@
 
 #include "BKE_pointcache.h"
 
+#include "BLI_string_utils.h"
+
 #include "GPU_shader.h"
 
 #include "draw_common.h"
@@ -39,6 +41,7 @@
 extern char datatoc_particle_strand_vert_glsl[];
 extern char datatoc_particle_strand_frag_glsl[];
 extern char datatoc_common_globals_lib_glsl[];
+extern char datatoc_common_view_lib_glsl[];
 
 /* *********** LISTS *********** */
 
@@ -86,23 +89,23 @@ typedef struct PARTICLE_PrivateData {
 static void particle_engine_init(void *UNUSED(vedata))
 {
   if (!e_data.strands_shader) {
-    e_data.strands_shader = DRW_shader_create_with_lib(datatoc_particle_strand_vert_glsl,
-                                                       NULL,
-                                                       datatoc_particle_strand_frag_glsl,
-                                                       datatoc_common_globals_lib_glsl,
-                                                       "");
+    char *lib = BLI_string_joinN(datatoc_common_globals_lib_glsl, datatoc_common_view_lib_glsl);
+
+    e_data.strands_shader = DRW_shader_create_with_lib(
+        datatoc_particle_strand_vert_glsl, NULL, datatoc_particle_strand_frag_glsl, lib, "");
 
     e_data.strands_weight_shader = DRW_shader_create_with_lib(datatoc_particle_strand_vert_glsl,
                                                               NULL,
                                                               datatoc_particle_strand_frag_glsl,
-                                                              datatoc_common_globals_lib_glsl,
+                                                              lib,
                                                               "#define USE_WEIGHT");
 
     e_data.points_shader = DRW_shader_create_with_lib(datatoc_particle_strand_vert_glsl,
                                                       NULL,
                                                       datatoc_particle_strand_frag_glsl,
-                                                      datatoc_common_globals_lib_glsl,
+                                                      lib,
                                                       "#define USE_POINTS");
+    MEM_freeN(lib);
   }
 }
 
index 053e73e406815d52c738a5bc75988c09d9d1a1b7..df18e91a8b18e6e0376f8cefddf25599c3c007b0 100644 (file)
@@ -37,6 +37,7 @@
 #include "draw_common.h"
 #include "draw_mode_engines.h"
 
+extern char datatoc_common_view_lib_glsl[];
 extern char datatoc_sculpt_mask_vert_glsl[];
 extern char datatoc_gpu_shader_3D_smooth_color_frag_glsl[];
 
@@ -111,8 +112,11 @@ static void SCULPT_engine_init(void *vedata)
   UNUSED_VARS(txl, fbl, stl);
 
   if (!e_data.shader_mask) {
-    e_data.shader_mask = DRW_shader_create(
-        datatoc_sculpt_mask_vert_glsl, NULL, datatoc_gpu_shader_3D_smooth_color_frag_glsl, NULL);
+    e_data.shader_mask = DRW_shader_create_with_lib(datatoc_sculpt_mask_vert_glsl,
+                                                    NULL,
+                                                    datatoc_gpu_shader_3D_smooth_color_frag_glsl,
+                                                    datatoc_common_view_lib_glsl,
+                                                    NULL);
   }
 }
 
index b7166382b1998bb302b1187b2bc8e2e97b772e95..1773414a3fcf37e59fc63be4a9b4e502a40d729e 100644 (file)
@@ -1,5 +1,4 @@
 /* Draw Curve Handles */
-uniform mat4 ModelViewProjectionMatrix;
 uniform mat4 ModelMatrix;
 
 in vec3 pos;
@@ -9,11 +8,11 @@ flat out int vertFlag;
 
 void main()
 {
-  vec4 pos_4d = vec4(pos, 1.0);
-  gl_Position = ModelViewProjectionMatrix * pos_4d;
+  vec3 world_pos = point_object_to_world(pos);
+  gl_Position = point_world_to_ndc(world_pos);
   vertFlag = data;
 
 #ifdef USE_WORLD_CLIP_PLANES
-  world_clip_planes_calc_clip_distance((ModelMatrix * pos_4d).xyz);
+  world_clip_planes_calc_clip_distance(world_pos);
 #endif
 }
index 4718f11db65c454ad717aa0f427f960127413dc4..169751871761553b165035203338a6965977902e 100644 (file)
@@ -1,6 +1,6 @@
 /* Draw Curve Vertices */
-uniform mat4 ModelViewProjectionMatrix;
 uniform mat4 ModelMatrix;
+
 uniform vec2 viewportSize;
 
 in vec3 pos;
@@ -22,10 +22,10 @@ void main()
     finalColor = colorVertex;
   }
 
-  vec4 pos_4d = vec4(pos, 1.0);
-  gl_Position = ModelViewProjectionMatrix * pos_4d;
+  vec3 world_pos = point_object_to_world(pos);
+  gl_Position = point_world_to_ndc(world_pos);
   gl_PointSize = sizeVertex * 2.0;
 #ifdef USE_WORLD_CLIP_PLANES
-  world_clip_planes_calc_clip_distance((ModelMatrix * pos_4d).xyz);
+  world_clip_planes_calc_clip_distance(world_pos);
 #endif
 }
index 02244086711af06e3e09bb04a0034786b6afda2f..b746c8d0a74badb60e16a121ebf1376990823fa7 100644 (file)
@@ -1,6 +1,6 @@
 /* Draw Curve Normals */
-uniform mat4 ModelViewProjectionMatrix;
 uniform mat4 ModelMatrix;
+
 uniform float normalSize;
 
 in vec3 pos;
@@ -18,10 +18,10 @@ void main()
     final_pos += normalSize * rad * (flip * nor - tan);
   }
 
-  vec4 final_pos_4d = vec4(final_pos, 1.0);
-  gl_Position = ModelViewProjectionMatrix * final_pos_4d;
+  vec3 world_pos = point_object_to_world(final_pos);
+  gl_Position = point_world_to_ndc(world_pos);
 
 #ifdef USE_WORLD_CLIP_PLANES
-  world_clip_planes_calc_clip_distance((ModelMatrix * final_pos_4d).xyz);
+  world_clip_planes_calc_clip_distance(world_pos);
 #endif
 }
index 3cf808f3c5279b55f06f6579520a2f0578f3baeb..a4773f31977d5ae22b9235c4a4e2fdae4c77cde1 100644 (file)
@@ -1,8 +1,8 @@
 
 /* Draw Lattice Vertices */
 
-uniform mat4 ModelViewProjectionMatrix;
 uniform mat4 ModelMatrix;
+
 uniform vec2 viewportSize;
 
 in vec3 pos;
@@ -27,7 +27,8 @@ void main()
 {
   clipCase = 0;
 
-  vec4 pPos = ModelViewProjectionMatrix * vec4(pos, 1.0);
+  vec3 world_pos = point_object_to_world(pos);
+  vec4 pPos = point_world_to_ndc(world_pos);
 
   /* only vertex position 0 is used */
   eData1 = eData2 = vec4(1e10);
@@ -39,6 +40,6 @@ void main()
   gl_Position = pPos;
 
 #ifdef USE_WORLD_CLIP_PLANES
-  world_clip_planes_calc_clip_distance((ModelMatrix * vec4(pos, 1.0)).xyz);
+  world_clip_planes_calc_clip_distance(world_pos);
 #endif
 }
index c84d97fa1c5174ffef05f7ee08ebfeac3355b07c..f81da2ff0e810847935ff32bb1a4b3a049c51ea3 100644 (file)
@@ -1,6 +1,6 @@
 
-uniform mat4 ModelViewProjectionMatrix;
 uniform mat4 ModelMatrix;
+
 uniform ivec4 dataMask = ivec4(0xFF);
 
 in vec3 pos;
@@ -10,13 +10,14 @@ flat out vec4 faceColor;
 
 void main()
 {
-  gl_Position = ModelViewProjectionMatrix * vec4(pos, 1.0);
+  vec3 world_pos = point_object_to_world(pos);
+  gl_Position = point_world_to_ndc(world_pos);
 
   ivec4 data_m = data & dataMask;
 
   faceColor = EDIT_MESH_face_color(data_m.x);
 
 #ifdef USE_WORLD_CLIP_PLANES
-  world_clip_planes_calc_clip_distance((ModelMatrix * vec4(pos, 1.0)).xyz);
+  world_clip_planes_calc_clip_distance(world_pos);
 #endif
 }
index 94d8d2e701c716937347a5a6c4a3c8777998bdc4..98cb788b75da8efbd86b88e1aaf5a501275b6aa9 100644 (file)
@@ -1,4 +1,3 @@
-uniform mat4 ModelViewProjectionMatrix;
 uniform mat4 ModelMatrix;
 
 in vec3 pos;
@@ -14,10 +13,11 @@ out vec4 weightColor;
 
 void main()
 {
-  gl_Position = ModelViewProjectionMatrix * vec4(pos, 1.0);
+  vec3 world_pos = point_object_to_world(pos);
+  gl_Position = point_world_to_ndc(world_pos);
   weightColor = vec4(weight_color.rgb, 1.0);
 
 #ifdef USE_WORLD_CLIP_PLANES
-  world_clip_planes_calc_clip_distance((ModelMatrix * vec4(pos, 1.0)).xyz);
+  world_clip_planes_calc_clip_distance(world_pos);
 #endif
 }
index 648577cc08093023e4179a2f46182a6878633a09..31b2faa76673c2571370160dc4efdcf3d6445c3a 100644 (file)
@@ -1,5 +1,4 @@
 
-uniform mat4 ModelViewProjectionMatrix;
 uniform mat4 ModelMatrix;
 uniform mat4 ModelMatrixInverse;
 
@@ -25,10 +24,14 @@ flat out vec4 v2;
 
 void main()
 {
-  v1 = ModelViewProjectionMatrix * vec4(pos, 1.0);
-  vec3 n = normalize(normal_object_to_view(nor));
-  v2 = v1 + ProjectionMatrix * vec4(n * normalSize, 0.0);
+  vec3 n = normalize(normal_object_to_world(nor));
+
+  vec3 world_pos = point_object_to_world(pos);
+
+  v1 = point_world_to_ndc(world_pos);
+  v2 = point_world_to_ndc(world_pos + n * normalSize);
+
 #ifdef USE_WORLD_CLIP_PLANES
-  world_clip_planes_calc_clip_distance((ModelMatrix * vec4(pos, 1.0)).xyz);
+  world_clip_planes_calc_clip_distance(world_pos);
 #endif
 }
index 9694c63fef172a702db37dffe3e7af0bdd37ac79..881d7aa750e2b9b9350c476ca7e6be38571cf268 100644 (file)
@@ -1,5 +1,5 @@
-uniform mat4 ModelViewProjectionMatrix;
 uniform mat4 ModelMatrix;
+
 uniform float aspectX;
 uniform float aspectY;
 uniform float size;
@@ -21,8 +21,9 @@ out vec2 texCoord_interp;
 
 void main()
 {
-  vec4 pos_4d = vec4((pos + offset) * (size * vec2(aspectX, aspectY)), 0.0, 1.0);
-  gl_Position = ModelViewProjectionMatrix * pos_4d;
+  vec3 pos = vec3((pos + offset) * (size * vec2(aspectX, aspectY)), 0.0);
+  vec3 world_pos = point_object_to_world(pos);
+  gl_Position = point_world_to_ndc(world_pos);
 #ifdef USE_WIRE
   gl_Position.z -= 1e-5;
   finalColor = vec4(color, 1.0);
@@ -32,6 +33,6 @@ void main()
 #endif
 
 #ifdef USE_WORLD_CLIP_PLANES
-  world_clip_planes_calc_clip_distance((ModelMatrix * pos_4d).xyz);
+  world_clip_planes_calc_clip_distance(world_pos);
 #endif
 }
index 5928d60b311130b2d5c6657cbf1cdccbd52b33aa..fcffc7a8ae04377ac60bac354fae254e1b5da80d 100644 (file)
@@ -15,6 +15,6 @@ void main()
   pPos.z -= 1e-3;
 
 #ifdef USE_WORLD_CLIP_PLANES
-  world_clip_planes_calc_clip_distance(world_pos).xyz);
+  world_clip_planes_calc_clip_distance(world_pos);
 #endif
 }
index 659e3cbd5f5611de853edffad0a65e514f5ef99c..5025d054048a8635cc73699a6708596601caa711 100644 (file)
@@ -1,13 +1,13 @@
-uniform mat4 ModelViewProjectionMatrix;
 uniform mat4 ModelMatrix;
 
 in vec3 pos;
 
 void main()
 {
-  gl_Position = ModelViewProjectionMatrix * vec4(pos, 1.0);
+  vec3 world_pos = point_object_to_world(pos);
+  gl_Position = point_world_to_ndc(world_pos);
 
 #ifdef USE_WORLD_CLIP_PLANES
-  world_clip_planes_calc_clip_distance((ModelMatrix * vec4(pos, 1.0)).xyz);
+  world_clip_planes_calc_clip_distance(world_pos);
 #endif
 }
index 59b88d8d3a785fcad0972995a58980838c60dd63..7ea2390dd3f212873560dceab6a24006b8b25d2f 100644 (file)
@@ -1,5 +1,4 @@
 
-uniform mat4 ModelViewProjectionMatrix;
 uniform mat4 ModelMatrix;
 
 in vec3 pos;
@@ -7,14 +6,16 @@ in vec4 nor; /* select flag on the 4th component */
 
 void main()
 {
-  gl_Position = ModelViewProjectionMatrix * vec4(pos, 1.0);
+  vec3 world_pos = point_object_to_world(pos);
+  gl_Position = point_world_to_ndc(world_pos);
+
   /* Don't draw faces that are selected. */
   if (nor.w > 0.0) {
     gl_Position = vec4(0.0, 0.0, 0.0, 1.0);
   }
   else {
 #ifdef USE_WORLD_CLIP_PLANES
-    world_clip_planes_calc_clip_distance((ModelMatrix * vec4(pos, 1.0)).xyz);
+    world_clip_planes_calc_clip_distance(world_pos);
 #endif
   }
 }
index 03d933b91968e6de3fa351f964214acd00642d38..14d3afd62721701819dc83de3630ca8adcf8bc54 100644 (file)
@@ -1,5 +1,4 @@
 
-uniform mat4 ModelViewProjectionMatrix;
 uniform mat4 ModelMatrix;
 
 in vec2 u; /* active uv map */
@@ -17,7 +16,8 @@ out vec2 masking_uv_interp;
 
 void main()
 {
-  gl_Position = ModelViewProjectionMatrix * vec4(pos, 1.0);
+  vec3 world_pos = point_object_to_world(pos);
+  gl_Position = point_world_to_ndc(world_pos);
 
   uv_interp = u;
 
@@ -26,6 +26,6 @@ void main()
 #endif
 
 #ifdef USE_WORLD_CLIP_PLANES
-  world_clip_planes_calc_clip_distance((ModelMatrix * vec4(pos, 1.0)).xyz);
+  world_clip_planes_calc_clip_distance(world_pos);
 #endif
 }
index 54f6d1a4aea563ce9dcd1f365af1976d58d0dba4..871f52b9df3980c45e081fa1aa0190a219ad1b94 100644 (file)
@@ -1,5 +1,4 @@
 
-uniform mat4 ModelViewProjectionMatrix;
 uniform mat4 ModelMatrix;
 
 in vec3 pos;
@@ -17,11 +16,12 @@ vec3 srgb_to_linear_attr(vec3 c)
 
 void main()
 {
-  gl_Position = ModelViewProjectionMatrix * vec4(pos, 1.0);
+  vec3 world_pos = point_object_to_world(pos);
+  gl_Position = point_world_to_ndc(world_pos);
 
   finalColor = srgb_to_linear_attr(c);
 
 #ifdef USE_WORLD_CLIP_PLANES
-  world_clip_planes_calc_clip_distance((ModelMatrix * vec4(pos, 1.0)).xyz);
+  world_clip_planes_calc_clip_distance(world_pos);
 #endif
 }
index e95b116df797d66ac031c97f86a100adbd6406eb..fb0e6c535d13bccacb7881ed1dfe4606dcb40ce3 100644 (file)
@@ -1,5 +1,4 @@
 
-uniform mat4 ModelViewProjectionMatrix;
 uniform mat4 ModelMatrix;
 
 in float weight;
@@ -9,12 +8,13 @@ out vec2 weight_interp; /* (weight, alert) */
 
 void main()
 {
-  gl_Position = ModelViewProjectionMatrix * vec4(pos, 1.0);
+  vec3 world_pos = point_object_to_world(pos);
+  gl_Position = point_world_to_ndc(world_pos);
 
   /* Separate actual weight and alerts for independent interpolation */
   weight_interp = max(vec2(weight, -weight), 0.0);
 
 #ifdef USE_WORLD_CLIP_PLANES
-  world_clip_planes_calc_clip_distance((ModelMatrix * vec4(pos, 1.0)).xyz);
+  world_clip_planes_calc_clip_distance(world_pos);
 #endif
 }
index a163fd7e8b3bb4792592a2b0beb4ccbb52bde6ea..7e9a5b9bfe632bbdc7ffce89f94a7afa8645cd25 100644 (file)
@@ -1,5 +1,4 @@
 
-uniform mat4 ModelViewProjectionMatrix;
 uniform mat4 ModelMatrix;
 
 in vec3 pos;
@@ -16,7 +15,8 @@ void main()
   bool is_select = false;
   bool is_hidden = false;
 #endif
-  gl_Position = ModelViewProjectionMatrix * vec4(pos, 1.0);
+  vec3 world_pos = point_object_to_world(pos);
+  gl_Position = point_world_to_ndc(world_pos);
   /* Add offset in Z to avoid zfighting and render selected wires on top. */
   /* TODO scale this bias using znear and zfar range. */
   gl_Position.z -= (is_select ? 2e-4 : 1e-4);
@@ -46,6 +46,6 @@ void main()
   finalColor.a = nor.w;
 
 #ifdef USE_WORLD_CLIP_PLANES
-  world_clip_planes_calc_clip_distance((ModelMatrix * vec4(pos, 1.0)).xyz);
+  world_clip_planes_calc_clip_distance(world_pos);
 #endif
 }
index 578a4935b37cbe8ea6c1ae4b4fcc2faee098d7fb..49d843b7e0e6ce00702d5533a23537ef099f9639 100644 (file)
@@ -1,4 +1,3 @@
-uniform mat4 ModelViewProjectionMatrix;
 
 in vec4 finalColor;
 #ifdef USE_POINTS
index 6dac6d6b98016129b693999ad82f2cbe3a38bf23..14f9050f9df1d11aa03725c6042ddab01348a947 100644 (file)
@@ -1,5 +1,5 @@
 
-uniform mat4 ModelViewProjectionMatrix;
+uniform mat4 ModelMatrix;
 
 in vec3 pos;
 in float color;
@@ -47,7 +47,8 @@ vec3 weight_to_rgb(float weight)
 
 void main()
 {
-  gl_Position = ModelViewProjectionMatrix * vec4(pos, 1.0);
+  vec3 world_pos = point_object_to_world(pos);
+  gl_Position = point_world_to_ndc(world_pos);
 
 #ifdef USE_WEIGHT
   finalColor = vec4(weight_to_rgb(color), 1.0);
index e5e34fee57e0270a68849e0e35a6bbc98d4983af..ee05844d8f6d2dfe4656eff5bc05d5f3fe88b445 100644 (file)
@@ -1,5 +1,6 @@
 
-uniform mat4 ModelViewProjectionMatrix;
+uniform mat4 ModelMatrix;
+
 uniform float maskOpacity;
 
 in vec3 pos;
@@ -9,7 +10,8 @@ out vec4 finalColor;
 
 void main()
 {
-  gl_Position = ModelViewProjectionMatrix * vec4(pos, 1.0);
+  vec3 world_pos = point_object_to_world(pos);
+  gl_Position = point_world_to_ndc(world_pos);
 
   float mask = 1.0 - (msk * maskOpacity);
   finalColor = vec4(mask, mask, mask, 1.0);
index 32207afa0b1a9c735072f099ff18ed704dce139a..87fa3519da1865a1016931d7bf0ee921ed3e194d 100644 (file)
@@ -1,5 +1,5 @@
 
-uniform mat4 ModelViewProjectionMatrix;
+uniform mat4 ModelMatrix;
 
 uniform sampler3D velocityX;
 uniform sampler3D velocityY;
@@ -109,5 +109,6 @@ void main()
   pos += (((gl_VertexID % 2) == 1) ? velocity : vec3(0.0)) * displaySize * voxel_size;
 #endif
 
-  gl_Position = ModelViewProjectionMatrix * vec4(pos, 1.0);
+  vec3 world_pos = point_object_to_world(pos);
+  gl_Position = point_world_to_ndc(world_pos);
 }