diff options
author | Clément Foucault <foucault.clem@gmail.com> | 2017-04-03 22:37:40 +0300 |
---|---|---|
committer | Clément Foucault <foucault.clem@gmail.com> | 2017-04-03 22:52:42 +0300 |
commit | ccaa21df6d53f08f3ebf2fcc93807d041970e5c3 (patch) | |
tree | 9784ebbc841516f5f54dcfe50a351a60198b60ba /source/blender/draw/modes | |
parent | 4a8aaab0b2ab84455450fcdd1e39e190862b0bb6 (diff) |
Infinite Grid: View angle fade
and show Z axis in special persp views
Diffstat (limited to 'source/blender/draw/modes')
-rw-r--r-- | source/blender/draw/modes/object_mode.c | 18 | ||||
-rw-r--r-- | source/blender/draw/modes/shaders/object_grid_frag.glsl | 24 |
2 files changed, 32 insertions, 10 deletions
diff --git a/source/blender/draw/modes/object_mode.c b/source/blender/draw/modes/object_mode.c index 0656485f792..5a9582bd319 100644 --- a/source/blender/draw/modes/object_mode.c +++ b/source/blender/draw/modes/object_mode.c @@ -315,7 +315,7 @@ static void OBJECT_engine_init(void *vedata) } /* Z axis if needed */ - if ((rv3d->view == RV3D_VIEW_USER) && show_axis_z) { + if (((rv3d->view == RV3D_VIEW_USER) || (rv3d->persp != RV3D_ORTHO)) && show_axis_z) { e_data.zpos_flag = SHOW_AXIS_Z; float zvec[4] = {0.0f, 0.0f, -1.0f, 0.0f}; @@ -323,10 +323,10 @@ static void OBJECT_engine_init(void *vedata) /* z axis : chose the most facing plane */ if (fabsf(zvec[0]) < fabsf(zvec[1])) { - e_data.zpos_flag |= (PLANE_XZ | SHOW_AXIS_X); + e_data.zpos_flag |= PLANE_XZ; } else { - e_data.zpos_flag |= (PLANE_YZ | SHOW_AXIS_Y); + e_data.zpos_flag |= PLANE_YZ; } e_data.zneg_flag = e_data.zpos_flag; @@ -502,6 +502,8 @@ static void OBJECT_cache_init(void *vedata) psl->grid = DRW_pass_create("Infinite Grid Pass", state); struct Batch *quad = DRW_cache_fullscreen_quad_get(); + static float mat[4][4]; + unit_m4(mat); /* Create 3 quads to render ordered transparency Z axis */ DRWShadingGroup *grp = DRW_shgroup_create(e_data.grid_sh, psl->grid); @@ -511,15 +513,15 @@ static void OBJECT_cache_init(void *vedata) DRW_shgroup_uniform_vec4(grp, "gridSettings", e_data.grid_settings, 1); DRW_shgroup_uniform_float(grp, "gridOneOverLogSubdiv", &e_data.grid_settings[4], 1); DRW_shgroup_uniform_block(grp, "globalsBlock", globals_ubo, 0); - DRW_shgroup_call_add(grp, quad, NULL); + DRW_shgroup_call_add(grp, quad, mat); grp = DRW_shgroup_create(e_data.grid_sh, psl->grid); DRW_shgroup_uniform_int(grp, "gridFlag", &e_data.grid_flag, 1); - DRW_shgroup_call_add(grp, quad, NULL); + DRW_shgroup_call_add(grp, quad, mat); grp = DRW_shgroup_create(e_data.grid_sh, psl->grid); DRW_shgroup_uniform_int(grp, "gridFlag", &e_data.zpos_flag, 1); - DRW_shgroup_call_add(grp, quad, NULL); + DRW_shgroup_call_add(grp, quad, mat); } { @@ -690,8 +692,8 @@ static void DRW_shgroup_lamp(OBJECT_StorageList *stl, Object *ob, SceneLayer *sl } float (*shapemat)[4], (*spotblendmat)[4]; - shapemat = (float (*)[4])*la_mats; - spotblendmat = (float (*)[4])*la_mats + 16; + shapemat = (float (*)[4])(*la_mats); + spotblendmat = (float (*)[4])(*la_mats + 16); /* Don't draw the center if it's selected or active */ if (theme_id == TH_GROUP) diff --git a/source/blender/draw/modes/shaders/object_grid_frag.glsl b/source/blender/draw/modes/shaders/object_grid_frag.glsl index 0c5a1175052..9b1283e46af 100644 --- a/source/blender/draw/modes/shaders/object_grid_frag.glsl +++ b/source/blender/draw/modes/shaders/object_grid_frag.glsl @@ -8,6 +8,7 @@ out vec4 FragColor; uniform mat4 ProjectionMatrix; uniform vec3 cameraPos; +uniform vec3 eye; uniform vec4 gridSettings; uniform float gridOneOverLogSubdiv; @@ -60,13 +61,32 @@ void main() float dist, fade; /* if persp */ if (ProjectionMatrix[3][3] == 0.0) { - dist = distance(cameraPos, wPos); - fade = 1.0 - smoothstep(0.0, gridDistance, dist - gridDistance); + vec3 viewvec = cameraPos - wPos; + dist = length(viewvec); + viewvec /= dist; + + float angle; + if ((gridFlag & PLANE_XZ) > 0) + angle = viewvec.y; + else if ((gridFlag & PLANE_YZ) > 0) + angle = viewvec.x; + else + angle = viewvec.z; + + angle = 1.0 - abs(angle); + fade = 1.0 - angle * angle; + fade *= 1.0 - smoothstep(0.0, gridDistance, dist - gridDistance); } else { dist = abs(gl_FragCoord.z * 2.0 - 1.0); fade = 1.0 - smoothstep(0.0, 0.5, dist - 0.5); dist = 1.0; /* avoid branch after */ + + if ((gridFlag & PLANE_XY) > 0) { + float angle = 1.0 - abs(eye.z); + fade *= 1.0 - angle * angle * angle; + dist = 1.0 + angle * 2.0; + } } if ((gridFlag & GRID) > 0) { |