diff options
author | Clément Foucault <foucault.clem@gmail.com> | 2017-09-22 03:42:57 +0300 |
---|---|---|
committer | Clément Foucault <foucault.clem@gmail.com> | 2017-09-22 03:44:40 +0300 |
commit | 1a4a1447b728082939e7b0f033602f27c0269937 (patch) | |
tree | 9060d9ff3762a5bd9709dca267c458c8fd8222d9 | |
parent | 406427bd4eac038491e69156a1b344d21a5289fd (diff) |
Edit Mesh Mode: Add a facing falloff effect
This let the user keep track of the shape by fading the center of the object.
An Opacity parameter is yet to be added.
7 files changed, 84 insertions, 8 deletions
diff --git a/source/blender/draw/modes/edit_mesh_mode.c b/source/blender/draw/modes/edit_mesh_mode.c index c06a2976ac7..c723d6e2d2d 100644 --- a/source/blender/draw/modes/edit_mesh_mode.c +++ b/source/blender/draw/modes/edit_mesh_mode.c @@ -152,14 +152,17 @@ static void EDIT_MESH_engine_init(void *vedata) datatoc_edit_mesh_overlay_vert_glsl, datatoc_edit_mesh_overlay_geom_tri_glsl, datatoc_edit_mesh_overlay_frag_glsl, - datatoc_common_globals_lib_glsl, "#define EDGE_FIX\n"); + datatoc_common_globals_lib_glsl, + "#define EDGE_FIX\n" + "#define VERTEX_FACING"); } if (!e_data.overlay_tri_fast_sh) { e_data.overlay_tri_fast_sh = DRW_shader_create_with_lib( datatoc_edit_mesh_overlay_vert_glsl, datatoc_edit_mesh_overlay_geom_tri_glsl, datatoc_edit_mesh_overlay_frag_glsl, - datatoc_common_globals_lib_glsl, NULL); + datatoc_common_globals_lib_glsl, + "#define VERTEX_FACING"); } if (!e_data.overlay_tri_vcol_sh) { e_data.overlay_tri_vcol_sh = DRW_shader_create_with_lib( @@ -168,7 +171,8 @@ static void EDIT_MESH_engine_init(void *vedata) datatoc_edit_mesh_overlay_frag_glsl, datatoc_common_globals_lib_glsl, "#define EDGE_FIX\n" - "#define VERTEX_SELECTION\n"); + "#define VERTEX_SELECTION\n" + "#define VERTEX_FACING"); } if (!e_data.overlay_tri_vcol_fast_sh) { e_data.overlay_tri_vcol_fast_sh = DRW_shader_create_with_lib( @@ -176,14 +180,16 @@ static void EDIT_MESH_engine_init(void *vedata) datatoc_edit_mesh_overlay_geom_tri_glsl, datatoc_edit_mesh_overlay_frag_glsl, datatoc_common_globals_lib_glsl, - "#define VERTEX_SELECTION\n"); + "#define VERTEX_SELECTION\n" + "#define VERTEX_FACING"); } if (!e_data.overlay_edge_sh) { e_data.overlay_edge_sh = DRW_shader_create_with_lib( datatoc_edit_mesh_overlay_vert_glsl, datatoc_edit_mesh_overlay_geom_edge_glsl, datatoc_edit_mesh_overlay_frag_glsl, - datatoc_common_globals_lib_glsl, NULL); + datatoc_common_globals_lib_glsl, + "#define VERTEX_FACING"); } if (!e_data.overlay_edge_vcol_sh) { e_data.overlay_edge_vcol_sh = DRW_shader_create_with_lib( @@ -191,20 +197,23 @@ static void EDIT_MESH_engine_init(void *vedata) datatoc_edit_mesh_overlay_geom_edge_glsl, datatoc_edit_mesh_overlay_frag_glsl, datatoc_common_globals_lib_glsl, - "#define VERTEX_SELECTION\n"); + "#define VERTEX_SELECTION\n" + "#define VERTEX_FACING"); } if (!e_data.overlay_vert_sh) { e_data.overlay_vert_sh = DRW_shader_create_with_lib( datatoc_edit_mesh_overlay_loosevert_vert_glsl, NULL, datatoc_edit_mesh_overlay_frag_glsl, datatoc_common_globals_lib_glsl, - "#define VERTEX_SELECTION\n"); + "#define VERTEX_SELECTION\n" + "#define VERTEX_FACING"); } if (!e_data.overlay_facedot_sh) { e_data.overlay_facedot_sh = DRW_shader_create_with_lib( datatoc_edit_mesh_overlay_facedot_vert_glsl, NULL, datatoc_edit_mesh_overlay_facedot_frag_glsl, - datatoc_common_globals_lib_glsl, NULL); + datatoc_common_globals_lib_glsl, + "#define VERTEX_FACING"); } if (!e_data.overlay_mix_sh) { e_data.overlay_mix_sh = DRW_shader_create_fullscreen(datatoc_edit_mesh_overlay_mix_frag_glsl, NULL); diff --git a/source/blender/draw/modes/shaders/edit_mesh_overlay_facedot_frag.glsl b/source/blender/draw/modes/shaders/edit_mesh_overlay_facedot_frag.glsl index 9b3fe6286e8..6dcbc097468 100644 --- a/source/blender/draw/modes/shaders/edit_mesh_overlay_facedot_frag.glsl +++ b/source/blender/draw/modes/shaders/edit_mesh_overlay_facedot_frag.glsl @@ -1,5 +1,8 @@ flat in int isSelected; +#ifdef VERTEX_FACING +in float facing; +#endif out vec4 FragColor; @@ -9,4 +12,8 @@ void main() FragColor = colorFaceDot; else FragColor = colorWireEdit; + +#ifdef VERTEX_FACING + FragColor.a *= 1.0 - abs(facing) * 0.4; +#endif } diff --git a/source/blender/draw/modes/shaders/edit_mesh_overlay_facedot_vert.glsl b/source/blender/draw/modes/shaders/edit_mesh_overlay_facedot_vert.glsl index 3e6f0ead04c..b27a4bba4ca 100644 --- a/source/blender/draw/modes/shaders/edit_mesh_overlay_facedot_vert.glsl +++ b/source/blender/draw/modes/shaders/edit_mesh_overlay_facedot_vert.glsl @@ -6,6 +6,16 @@ in vec4 norAndFlag; flat out int isSelected; +#ifdef VERTEX_FACING +uniform mat4 ProjectionMatrix; +uniform mat4 ModelViewMatrix; +uniform mat3 NormalMatrix; +uniform vec3 eye; + +in vec3 vnor; +out float facing; +#endif + void main() { gl_Position = ModelViewProjectionMatrix * vec4(pos, 1.0); @@ -13,4 +23,11 @@ void main() gl_Position.z -= 0.0002; gl_PointSize = sizeFaceDot; isSelected = int(norAndFlag.w); +#ifdef VERTEX_FACING + vec3 view_normal = normalize(NormalMatrix * norAndFlag.xyz); + vec3 view_vec = (ProjectionMatrix[3][3] == 0.0) + ? normalize((ModelViewMatrix * vec4(pos, 1.0)).xyz) + : vec3(0.0, 0.0, 1.0); + facing = dot(view_vec, view_normal); +#endif } diff --git a/source/blender/draw/modes/shaders/edit_mesh_overlay_frag.glsl b/source/blender/draw/modes/shaders/edit_mesh_overlay_frag.glsl index 8ae7a9e3ab5..d7f96695d0e 100644 --- a/source/blender/draw/modes/shaders/edit_mesh_overlay_frag.glsl +++ b/source/blender/draw/modes/shaders/edit_mesh_overlay_frag.glsl @@ -15,6 +15,9 @@ flat in int clipCase; #ifdef VERTEX_SELECTION in vec3 vertexColor; #endif +#ifdef VERTEX_FACING +in float facing; +#endif /* We use a vec4[2] interface to pass edge data * (without fragmenting memory accesses) @@ -198,6 +201,10 @@ void main() } #endif +#ifdef VERTEX_FACING + FragColor.a *= 1.0 - abs(facing) * 0.4; +#endif + /* don't write depth if not opaque */ if (FragColor.a == 0.0) discard; } diff --git a/source/blender/draw/modes/shaders/edit_mesh_overlay_geom_edge.glsl b/source/blender/draw/modes/shaders/edit_mesh_overlay_geom_edge.glsl index 5e3ecd59cb4..7d71e1540d5 100644 --- a/source/blender/draw/modes/shaders/edit_mesh_overlay_geom_edge.glsl +++ b/source/blender/draw/modes/shaders/edit_mesh_overlay_geom_edge.glsl @@ -14,6 +14,9 @@ uniform vec2 viewportSize; in vec4 vPos[]; in vec4 pPos[]; in ivec4 vData[]; +#ifdef VERTEX_FACING +in float vFacing[]; +#endif /* these are the same for all vertices * and does not need interpolation */ @@ -25,6 +28,9 @@ flat out int clipCase; #ifdef VERTEX_SELECTION out vec3 vertexColor; #endif +#ifdef VERTEX_FACING +out float facing; +#endif /* See fragment shader */ noperspective out vec4 eData1; @@ -79,6 +85,10 @@ void doVertex(int v, vec4 pos) vertexColor = getVertexColor(v); #endif +#ifdef VERTEX_FACING + facing = vFacing[v]; +#endif + gl_Position = pos; EmitVertex(); diff --git a/source/blender/draw/modes/shaders/edit_mesh_overlay_geom_tri.glsl b/source/blender/draw/modes/shaders/edit_mesh_overlay_geom_tri.glsl index afd1e5a74a8..f83402e3869 100644 --- a/source/blender/draw/modes/shaders/edit_mesh_overlay_geom_tri.glsl +++ b/source/blender/draw/modes/shaders/edit_mesh_overlay_geom_tri.glsl @@ -29,6 +29,9 @@ uniform vec2 viewportSize; in vec4 vPos[]; in vec4 pPos[]; in ivec4 vData[]; +#ifdef VERTEX_FACING +in float vFacing[]; +#endif /* these are the same for all vertices * and does not need interpolation */ @@ -40,6 +43,9 @@ flat out int clipCase; #ifdef VERTEX_SELECTION out vec3 vertexColor; #endif +#ifdef VERTEX_FACING +out float facing; +#endif /* See fragment shader */ noperspective out vec4 eData1; @@ -103,6 +109,10 @@ void doVertex(int v, vec4 pos) vertexColor = getVertexColor(v); #endif +#ifdef VERTEX_FACING + facing = vFacing[v]; +#endif + gl_Position = pos; EmitVertex(); diff --git a/source/blender/draw/modes/shaders/edit_mesh_overlay_vert.glsl b/source/blender/draw/modes/shaders/edit_mesh_overlay_vert.glsl index 5bc9a8bef85..6da9b0a0e86 100644 --- a/source/blender/draw/modes/shaders/edit_mesh_overlay_vert.glsl +++ b/source/blender/draw/modes/shaders/edit_mesh_overlay_vert.glsl @@ -15,9 +15,25 @@ out vec4 vPos; out vec4 pPos; out ivec4 vData; +#ifdef VERTEX_FACING +uniform mat4 ProjectionMatrix; +uniform mat3 NormalMatrix; +uniform vec3 eye; + +in vec3 vnor; +out float vFacing; +#endif + void main() { vPos = ModelViewMatrix * vec4(pos, 1.0); pPos = ModelViewProjectionMatrix * vec4(pos, 1.0); vData = data; +#ifdef VERTEX_FACING + vec3 view_normal = normalize(NormalMatrix * vnor); + vec3 view_vec = (ProjectionMatrix[3][3] == 0.0) + ? normalize(vPos.xyz) + : vec3(0.0, 0.0, 1.0); + vFacing = dot(view_vec, view_normal); +#endif } |