diff options
author | Clément Foucault <foucault.clem@gmail.com> | 2019-05-10 02:57:42 +0300 |
---|---|---|
committer | Clément Foucault <foucault.clem@gmail.com> | 2019-05-10 13:25:16 +0300 |
commit | 632e0725d27271f95073f668a24bcf06f603f001 (patch) | |
tree | 6980992db3d05f25aff27646bad1e3a01827153b /source | |
parent | 6006f86e07c5732f72015d500ce3e066464e2baa (diff) |
Overlays: Use common_view_lib.glsl
This removes ModelViewProjectionMatrix usage
Diffstat (limited to 'source')
29 files changed, 148 insertions, 95 deletions
diff --git a/source/blender/draw/intern/draw_common.c b/source/blender/draw/intern/draw_common.c index 76fca6fc72d..9abc7ec6c6e 100644 --- a/source/blender/draw/intern/draw_common.c +++ b/source/blender/draw/intern/draw_common.c @@ -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; } diff --git a/source/blender/draw/modes/edit_curve_mode.c b/source/blender/draw/modes/edit_curve_mode.c index e47393c88c4..f1aa4d20a7e 100644 --- a/source/blender/draw/modes/edit_curve_mode.c +++ b/source/blender/draw/modes/edit_curve_mode.c @@ -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}, diff --git a/source/blender/draw/modes/edit_lattice_mode.c b/source/blender/draw/modes/edit_lattice_mode.c index 273480b8127..52893e5f54d 100644 --- a/source/blender/draw/modes/edit_lattice_mode.c +++ b/source/blender/draw/modes/edit_lattice_mode.c @@ -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, diff --git a/source/blender/draw/modes/edit_mesh_mode.c b/source/blender/draw/modes/edit_mesh_mode.c index 655b0428743..c68a3cb604d 100644 --- a/source/blender/draw/modes/edit_mesh_mode.c +++ b/source/blender/draw/modes/edit_mesh_mode.c @@ -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); } } diff --git a/source/blender/draw/modes/object_mode.c b/source/blender/draw/modes/object_mode.c index 7e5586f1b10..cc313620a11 100644 --- a/source/blender/draw/modes/object_mode.c +++ b/source/blender/draw/modes/object_mode.c @@ -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}, }); diff --git a/source/blender/draw/modes/overlay_mode.c b/source/blender/draw/modes/overlay_mode.c index 99ab842b3bf..ceb114673d0 100644 --- a/source/blender/draw/modes/overlay_mode.c +++ b/source/blender/draw/modes/overlay_mode.c @@ -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}, }); diff --git a/source/blender/draw/modes/paint_texture_mode.c b/source/blender/draw/modes/paint_texture_mode.c index 3e292f4e4bc..123dc7fca88 100644 --- a/source/blender/draw/modes/paint_texture_mode.c +++ b/source/blender/draw/modes/paint_texture_mode.c @@ -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); } } diff --git a/source/blender/draw/modes/paint_vertex_mode.c b/source/blender/draw/modes/paint_vertex_mode.c index ef3af1255eb..caf7a5fb184 100644 --- a/source/blender/draw/modes/paint_vertex_mode.c +++ b/source/blender/draw/modes/paint_vertex_mode.c @@ -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}, diff --git a/source/blender/draw/modes/particle_mode.c b/source/blender/draw/modes/particle_mode.c index 600a29fecb4..60cc95dac4c 100644 --- a/source/blender/draw/modes/particle_mode.c +++ b/source/blender/draw/modes/particle_mode.c @@ -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); } } diff --git a/source/blender/draw/modes/sculpt_mode.c b/source/blender/draw/modes/sculpt_mode.c index 053e73e4068..df18e91a8b1 100644 --- a/source/blender/draw/modes/sculpt_mode.c +++ b/source/blender/draw/modes/sculpt_mode.c @@ -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); } } diff --git a/source/blender/draw/modes/shaders/edit_curve_overlay_handle_vert.glsl b/source/blender/draw/modes/shaders/edit_curve_overlay_handle_vert.glsl index b7166382b19..1773414a3fc 100644 --- a/source/blender/draw/modes/shaders/edit_curve_overlay_handle_vert.glsl +++ b/source/blender/draw/modes/shaders/edit_curve_overlay_handle_vert.glsl @@ -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 } diff --git a/source/blender/draw/modes/shaders/edit_curve_overlay_loosevert_vert.glsl b/source/blender/draw/modes/shaders/edit_curve_overlay_loosevert_vert.glsl index 4718f11db65..16975187176 100644 --- a/source/blender/draw/modes/shaders/edit_curve_overlay_loosevert_vert.glsl +++ b/source/blender/draw/modes/shaders/edit_curve_overlay_loosevert_vert.glsl @@ -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 } diff --git a/source/blender/draw/modes/shaders/edit_curve_overlay_normals_vert.glsl b/source/blender/draw/modes/shaders/edit_curve_overlay_normals_vert.glsl index 02244086711..b746c8d0a74 100644 --- a/source/blender/draw/modes/shaders/edit_curve_overlay_normals_vert.glsl +++ b/source/blender/draw/modes/shaders/edit_curve_overlay_normals_vert.glsl @@ -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 } diff --git a/source/blender/draw/modes/shaders/edit_lattice_overlay_loosevert_vert.glsl b/source/blender/draw/modes/shaders/edit_lattice_overlay_loosevert_vert.glsl index 3cf808f3c52..a4773f31977 100644 --- a/source/blender/draw/modes/shaders/edit_lattice_overlay_loosevert_vert.glsl +++ b/source/blender/draw/modes/shaders/edit_lattice_overlay_loosevert_vert.glsl @@ -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 } diff --git a/source/blender/draw/modes/shaders/edit_mesh_overlay_facefill_vert.glsl b/source/blender/draw/modes/shaders/edit_mesh_overlay_facefill_vert.glsl index c84d97fa1c5..f81da2ff0e8 100644 --- a/source/blender/draw/modes/shaders/edit_mesh_overlay_facefill_vert.glsl +++ b/source/blender/draw/modes/shaders/edit_mesh_overlay_facefill_vert.glsl @@ -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 } diff --git a/source/blender/draw/modes/shaders/edit_mesh_overlay_mesh_analysis_vert.glsl b/source/blender/draw/modes/shaders/edit_mesh_overlay_mesh_analysis_vert.glsl index 94d8d2e701c..98cb788b75d 100644 --- a/source/blender/draw/modes/shaders/edit_mesh_overlay_mesh_analysis_vert.glsl +++ b/source/blender/draw/modes/shaders/edit_mesh_overlay_mesh_analysis_vert.glsl @@ -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 } diff --git a/source/blender/draw/modes/shaders/edit_normals_vert.glsl b/source/blender/draw/modes/shaders/edit_normals_vert.glsl index 648577cc080..31b2faa7667 100644 --- a/source/blender/draw/modes/shaders/edit_normals_vert.glsl +++ b/source/blender/draw/modes/shaders/edit_normals_vert.glsl @@ -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 } diff --git a/source/blender/draw/modes/shaders/object_empty_image_vert.glsl b/source/blender/draw/modes/shaders/object_empty_image_vert.glsl index 9694c63fef1..881d7aa750e 100644 --- a/source/blender/draw/modes/shaders/object_empty_image_vert.glsl +++ b/source/blender/draw/modes/shaders/object_empty_image_vert.glsl @@ -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 } diff --git a/source/blender/draw/modes/shaders/object_outline_prepass_vert.glsl b/source/blender/draw/modes/shaders/object_outline_prepass_vert.glsl index 5928d60b311..fcffc7a8ae0 100644 --- a/source/blender/draw/modes/shaders/object_outline_prepass_vert.glsl +++ b/source/blender/draw/modes/shaders/object_outline_prepass_vert.glsl @@ -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 } diff --git a/source/blender/draw/modes/shaders/overlay_face_orientation_vert.glsl b/source/blender/draw/modes/shaders/overlay_face_orientation_vert.glsl index 659e3cbd5f5..5025d054048 100644 --- a/source/blender/draw/modes/shaders/overlay_face_orientation_vert.glsl +++ b/source/blender/draw/modes/shaders/overlay_face_orientation_vert.glsl @@ -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 } diff --git a/source/blender/draw/modes/shaders/paint_face_vert.glsl b/source/blender/draw/modes/shaders/paint_face_vert.glsl index 59b88d8d3a7..7ea2390dd3f 100644 --- a/source/blender/draw/modes/shaders/paint_face_vert.glsl +++ b/source/blender/draw/modes/shaders/paint_face_vert.glsl @@ -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 } } diff --git a/source/blender/draw/modes/shaders/paint_texture_vert.glsl b/source/blender/draw/modes/shaders/paint_texture_vert.glsl index 03d933b9196..14d3afd6272 100644 --- a/source/blender/draw/modes/shaders/paint_texture_vert.glsl +++ b/source/blender/draw/modes/shaders/paint_texture_vert.glsl @@ -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 } diff --git a/source/blender/draw/modes/shaders/paint_vertex_vert.glsl b/source/blender/draw/modes/shaders/paint_vertex_vert.glsl index 54f6d1a4aea..871f52b9df3 100644 --- a/source/blender/draw/modes/shaders/paint_vertex_vert.glsl +++ b/source/blender/draw/modes/shaders/paint_vertex_vert.glsl @@ -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 } diff --git a/source/blender/draw/modes/shaders/paint_weight_vert.glsl b/source/blender/draw/modes/shaders/paint_weight_vert.glsl index e95b116df79..fb0e6c535d1 100644 --- a/source/blender/draw/modes/shaders/paint_weight_vert.glsl +++ b/source/blender/draw/modes/shaders/paint_weight_vert.glsl @@ -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 } diff --git a/source/blender/draw/modes/shaders/paint_wire_vert.glsl b/source/blender/draw/modes/shaders/paint_wire_vert.glsl index a163fd7e8b3..7e9a5b9bfe6 100644 --- a/source/blender/draw/modes/shaders/paint_wire_vert.glsl +++ b/source/blender/draw/modes/shaders/paint_wire_vert.glsl @@ -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 } diff --git a/source/blender/draw/modes/shaders/particle_strand_frag.glsl b/source/blender/draw/modes/shaders/particle_strand_frag.glsl index 578a4935b37..49d843b7e0e 100644 --- a/source/blender/draw/modes/shaders/particle_strand_frag.glsl +++ b/source/blender/draw/modes/shaders/particle_strand_frag.glsl @@ -1,4 +1,3 @@ -uniform mat4 ModelViewProjectionMatrix; in vec4 finalColor; #ifdef USE_POINTS diff --git a/source/blender/draw/modes/shaders/particle_strand_vert.glsl b/source/blender/draw/modes/shaders/particle_strand_vert.glsl index 6dac6d6b980..14f9050f9df 100644 --- a/source/blender/draw/modes/shaders/particle_strand_vert.glsl +++ b/source/blender/draw/modes/shaders/particle_strand_vert.glsl @@ -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); diff --git a/source/blender/draw/modes/shaders/sculpt_mask_vert.glsl b/source/blender/draw/modes/shaders/sculpt_mask_vert.glsl index e5e34fee57e..ee05844d8f6 100644 --- a/source/blender/draw/modes/shaders/sculpt_mask_vert.glsl +++ b/source/blender/draw/modes/shaders/sculpt_mask_vert.glsl @@ -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); diff --git a/source/blender/draw/modes/shaders/volume_velocity_vert.glsl b/source/blender/draw/modes/shaders/volume_velocity_vert.glsl index 32207afa0b1..87fa3519da1 100644 --- a/source/blender/draw/modes/shaders/volume_velocity_vert.glsl +++ b/source/blender/draw/modes/shaders/volume_velocity_vert.glsl @@ -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); } |