diff options
author | Clément Foucault <foucault.clem@gmail.com> | 2019-05-08 20:30:03 +0300 |
---|---|---|
committer | Clément Foucault <foucault.clem@gmail.com> | 2019-05-08 21:13:32 +0300 |
commit | 24aeb479be2b87d406196240c1a4c20e1688514e (patch) | |
tree | 2dc416e42ca0368317c2475ba91c46bfa8a928d5 /source/blender | |
parent | c358da6b21158792bc05fa17fa00440675d0e76e (diff) |
Overlay Mode: Use common_view_lib
This is in order to centralize all matrices transformations.
Diffstat (limited to 'source/blender')
-rw-r--r-- | source/blender/draw/modes/overlay_mode.c | 17 | ||||
-rw-r--r-- | source/blender/draw/modes/shaders/common_view_lib.glsl | 6 | ||||
-rw-r--r-- | source/blender/draw/modes/shaders/overlay_face_wireframe_vert.glsl | 8 |
3 files changed, 21 insertions, 10 deletions
diff --git a/source/blender/draw/modes/overlay_mode.c b/source/blender/draw/modes/overlay_mode.c index fe4bb2db18e..ce49eb0e688 100644 --- a/source/blender/draw/modes/overlay_mode.c +++ b/source/blender/draw/modes/overlay_mode.c @@ -100,6 +100,8 @@ extern char datatoc_overlay_face_wireframe_geom_glsl[]; extern char datatoc_overlay_face_wireframe_frag_glsl[]; extern char datatoc_gpu_shader_depth_only_frag_glsl[]; +extern char datatoc_common_view_lib_glsl[]; + /* Functions */ static void overlay_engine_init(void *vedata) { @@ -133,7 +135,10 @@ static void overlay_engine_init(void *vedata) if (!sh_data->face_wireframe) { sh_data->select_wireframe = GPU_shader_create_from_arrays({ - .vert = (const char *[]){sh_cfg_data->lib, datatoc_overlay_face_wireframe_vert_glsl, NULL}, + .vert = (const char *[]){sh_cfg_data->lib, + datatoc_common_view_lib_glsl, + datatoc_overlay_face_wireframe_vert_glsl, + NULL}, .geom = (const char *[]){sh_cfg_data->lib, datatoc_overlay_face_wireframe_geom_glsl, NULL}, .frag = (const char *[]){datatoc_gpu_shader_depth_only_frag_glsl, NULL}, .defs = (const char *[]){sh_cfg_data->def, "#define SELECT_EDGES\n", NULL}, @@ -141,14 +146,20 @@ static void overlay_engine_init(void *vedata) #if USE_GEOM_SHADER_WORKAROUND /* Apple drivers does not support wide wires. Use geometry shader as a workaround. */ sh_data->face_wireframe = GPU_shader_create_from_arrays({ - .vert = (const char *[]){sh_cfg_data->lib, datatoc_overlay_face_wireframe_vert_glsl, NULL}, + .vert = (const char *[]){sh_cfg_data->lib, + datatoc_common_view_lib_glsl, + datatoc_overlay_face_wireframe_vert_glsl, + NULL}, .geom = (const char *[]){sh_cfg_data->lib, datatoc_overlay_face_wireframe_geom_glsl, NULL}, .frag = (const char *[]){datatoc_overlay_face_wireframe_frag_glsl, NULL}, .defs = (const char *[]){sh_cfg_data->def, "#define USE_GEOM\n", NULL}, }); #else sh_data->face_wireframe = GPU_shader_create_from_arrays({ - .vert = (const char *[]){sh_cfg_data->lib, datatoc_overlay_face_wireframe_vert_glsl, NULL}, + .vert = (const char *[]){sh_cfg_data->lib, + datatoc_common_view_lib_glsl, + datatoc_overlay_face_wireframe_vert_glsl, + NULL}, .frag = (const char *[]){datatoc_overlay_face_wireframe_frag_glsl, NULL}, .defs = (const char *[]){sh_cfg_data->def, NULL}, }); diff --git a/source/blender/draw/modes/shaders/common_view_lib.glsl b/source/blender/draw/modes/shaders/common_view_lib.glsl index de9c4e2a96e..25aa8e19474 100644 --- a/source/blender/draw/modes/shaders/common_view_lib.glsl +++ b/source/blender/draw/modes/shaders/common_view_lib.glsl @@ -13,3 +13,9 @@ layout(std140) uniform viewBlock vec4 clipPlanes[2]; }; + +/* Transform shortcuts. */ +#define transform_normal_object_to_world(nor) (transpose(mat3(ModelMatrixInverse)) * nor) +#define transform_normal_world_to_object(nor) (transpose(mat3(ModelMatrix)) * nor) +#define transform_point_view_to_object(point) \ + ((ModelMatrixInverse * (ViewMatrixInverse * vec4(point, 1.0))).xyz) diff --git a/source/blender/draw/modes/shaders/overlay_face_wireframe_vert.glsl b/source/blender/draw/modes/shaders/overlay_face_wireframe_vert.glsl index d73f0bdb609..0d5b4390402 100644 --- a/source/blender/draw/modes/shaders/overlay_face_wireframe_vert.glsl +++ b/source/blender/draw/modes/shaders/overlay_face_wireframe_vert.glsl @@ -1,8 +1,4 @@ -uniform mat4 ProjectionMatrix; -uniform mat4 ViewMatrix; -uniform mat4 ViewMatrixInverse; - uniform mat4 ModelMatrix; uniform mat4 ModelMatrixInverse; @@ -22,8 +18,6 @@ float get_edge_sharpness(float wd) #endif } -#define transform_normal_to_world(nor) (transpose(mat3(ModelMatrixInverse)) * nor) - /* Geometry shader version */ #if defined(SELECT_EDGES) || defined(USE_GEOM) out float facing_g; @@ -45,7 +39,7 @@ void main() vec4 wpos = ModelMatrix * vec4(pos, 1.0); gl_Position = projmat * (ViewMatrix * wpos); - vec3 wnor = normalize(transform_normal_to_world(nor)); + vec3 wnor = normalize(transform_normal_object_to_world(nor)); facing_g = dot(wnor, ViewMatrixInverse[2].xyz); edgeSharpness_g = get_edge_sharpness(wd); |