From c01a2aa4bbfe77feb5b2cc94fa0442aea5f34ad4 Mon Sep 17 00:00:00 2001 From: Antony Riakiotakis Date: Fri, 13 Feb 2015 11:52:27 +0100 Subject: [PATCH] Alleviate grid creating shadows in Ambient Occlusion effect. Draw the grid last with depth masking disabled. That should have no ill effects otherwise as far as I can tell except from some exceptional cases (axis lines over grid) but this is hardly annoying. Generally to properly solve such issues we need to have a better render pipeline with wire objects/materials being drawn after compositing. This is not impossible but for now doing it the simple way. --- .../editors/space_view3d/view3d_draw.c | 47 ++++++++++--------- 1 file changed, 24 insertions(+), 23 deletions(-) diff --git a/source/blender/editors/space_view3d/view3d_draw.c b/source/blender/editors/space_view3d/view3d_draw.c index 94d0ffcc9ee..28ba87f0397 100644 --- a/source/blender/editors/space_view3d/view3d_draw.c +++ b/source/blender/editors/space_view3d/view3d_draw.c @@ -295,7 +295,7 @@ static void drawgrid(UnitSettings *unit, ARegion *ar, View3D *v3d, const char ** dx = fabs(x - (wx) * fx / fw); if (dx == 0) dx = fabs(y - (wy) * fy / fw); - glDepthMask(0); /* disable write in zbuffer */ + glDepthMask(GL_FALSE); /* disable write in zbuffer */ /* check zoom out */ UI_ThemeColor(TH_GRID); @@ -434,7 +434,7 @@ static void drawgrid(UnitSettings *unit, ARegion *ar, View3D *v3d, const char ** fdrawline(x, 0.0, x, (float)ar->winy); - glDepthMask(1); /* enable write in zbuffer */ + glDepthMask(GL_TRUE); /* enable write in zbuffer */ } #undef GRID_MIN_PX @@ -476,8 +476,7 @@ static void drawfloor(Scene *scene, View3D *v3d, const char **grid_unit) grid_scale = ED_view3d_grid_scale(scene, v3d, grid_unit); grid = gridlines * grid_scale; - if (v3d->zbuf && scene->obedit) - glDepthMask(0); /* for zbuffer-select */ + glDepthMask(GL_FALSE); UI_GetThemeColor3ubv(TH_GRID, col_grid); @@ -546,7 +545,7 @@ static void drawfloor(Scene *scene, View3D *v3d, const char **grid_unit) } } - if (v3d->zbuf && scene->obedit) glDepthMask(1); + glDepthMask(GL_TRUE); } @@ -2668,6 +2667,8 @@ static void view3d_draw_objects( RegionView3D *rv3d = ar->regiondata; Base *base; const bool do_camera_frame = !draw_offscreen; + const bool draw_floor = (rv3d->view == RV3D_VIEW_USER) || (rv3d->persp != RV3D_ORTHO); + const bool draw_grids = !draw_offscreen && (v3d->flag2 & V3D_RENDER_OVERRIDE) == 0; if (!draw_offscreen) { ED_region_draw_cb_draw(C, ar, REGION_DRAW_PRE_VIEW); @@ -2698,26 +2699,21 @@ static void view3d_draw_objects( glEnable(GL_DEPTH_TEST); } - if (!draw_offscreen) { + /* ortho grid goes first, does not write to depth buffer and doesn't need depth test so it will override + * objects if done last */ + if (draw_grids) { /* needs to be done always, gridview is adjusted in drawgrid() now, but only for ortho views. */ rv3d->gridview = ED_view3d_grid_scale(scene, v3d, grid_unit); - if ((rv3d->view == RV3D_VIEW_USER) || (rv3d->persp != RV3D_ORTHO)) { - if ((v3d->flag2 & V3D_RENDER_OVERRIDE) == 0) { - drawfloor(scene, v3d, grid_unit); - } - } - else { - if ((v3d->flag2 & V3D_RENDER_OVERRIDE) == 0) { - ED_region_pixelspace(ar); - *grid_unit = NULL; /* drawgrid need this to detect/affect smallest valid unit... */ - drawgrid(&scene->unit, ar, v3d, grid_unit); - /* XXX make function? replaces persp(1) */ - glMatrixMode(GL_PROJECTION); - glLoadMatrixf(rv3d->winmat); - glMatrixMode(GL_MODELVIEW); - glLoadMatrixf(rv3d->viewmat); - } + if (!draw_floor) { + ED_region_pixelspace(ar); + *grid_unit = NULL; /* drawgrid need this to detect/affect smallest valid unit... */ + drawgrid(&scene->unit, ar, v3d, grid_unit); + /* XXX make function? replaces persp(1) */ + glMatrixMode(GL_PROJECTION); + glLoadMatrixf(rv3d->winmat); + glMatrixMode(GL_MODELVIEW); + glLoadMatrixf(rv3d->viewmat); } } @@ -2806,6 +2802,11 @@ static void view3d_draw_objects( if (v3d->afterdraw_xray.first) view3d_draw_xray(scene, ar, v3d, true); if (v3d->afterdraw_xraytransp.first) view3d_draw_xraytransp(scene, ar, v3d, true); + /* perspective floor goes last to use scene depth and avoid writing to depth buffer */ + if (draw_grids && draw_floor) { + drawfloor(scene, v3d, grid_unit); + } + if (!draw_offscreen) { ED_region_draw_cb_draw(C, ar, REGION_DRAW_POST_VIEW); } @@ -3546,7 +3547,7 @@ static void view3d_main_area_draw_objects(const bContext *C, Scene *scene, View3 if (do_compositing) { GPU_fx_do_composite_pass(rv3d->compositor, rv3d->winmat, rv3d->is_persp, scene, NULL); } - + /* Disable back anti-aliasing */ if (U.ogl_multisamples != USER_MULTISAMPLE_NONE) { glDisable(GL_MULTISAMPLE_ARB);