OffscreenRendering: Fix Incorrect Window Coordinates
authorJeroen Bakker <j.bakker@atmind.nl>
Wed, 15 May 2019 07:47:22 +0000 (09:47 +0200)
committerJeroen Bakker <j.bakker@atmind.nl>
Tue, 21 May 2019 14:06:18 +0000 (16:06 +0200)
When doing offscreen rendering (Viewport Render or Sequencer Scene
strip) EEVEE and workbench used the wrong window coordinates. These
coordinates included the border that was not drawn.

Reviewed By: brecht

Maniphest Tasks: T64505

Differential Revision: https://developer.blender.org/D4864

source/blender/editors/gpencil/gpencil_fill.c
source/blender/editors/include/ED_view3d.h
source/blender/editors/space_view3d/view3d_draw.c
source/blender/editors/space_view3d/view3d_view.c
source/blender/makesrna/intern/rna_space_api.c

index 96f405f..bf15b84 100644 (file)
@@ -401,7 +401,8 @@ static bool gp_render_offscreen(tGPDfill *tgpf)
   glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
   glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
 
-  ED_view3d_update_viewmat(tgpf->depsgraph, tgpf->scene, tgpf->v3d, tgpf->ar, NULL, winmat, NULL);
+  ED_view3d_update_viewmat(
+      tgpf->depsgraph, tgpf->scene, tgpf->v3d, tgpf->ar, NULL, winmat, NULL, true);
   /* set for opengl */
   GPU_matrix_projection_set(tgpf->rv3d->winmat);
   GPU_matrix_set(tgpf->rv3d->viewmat);
index 1c5fc33..055bd36 100644 (file)
@@ -615,7 +615,8 @@ void ED_view3d_update_viewmat(struct Depsgraph *depsgraph,
                               struct ARegion *ar,
                               float viewmat[4][4],
                               float winmat[4][4],
-                              const struct rcti *rect);
+                              const struct rcti *rect,
+                              bool offscreen);
 bool ED_view3d_quat_from_axis_view(const char view, float quat[4]);
 char ED_view3d_quat_to_axis_view(const float quat[4], const float epsilon);
 char ED_view3d_lock_view_from_index(int index);
index afc3b80..54955c8 100644 (file)
@@ -105,7 +105,8 @@ void ED_view3d_update_viewmat(Depsgraph *depsgraph,
                               ARegion *ar,
                               float viewmat[4][4],
                               float winmat[4][4],
-                              const rcti *rect)
+                              const rcti *rect,
+                              bool offscreen)
 {
   RegionView3D *rv3d = ar->regiondata;
 
@@ -138,7 +139,7 @@ void ED_view3d_update_viewmat(Depsgraph *depsgraph,
   /* calculate GLSL view dependent values */
 
   /* store window coordinates scaling/offset */
-  if (rv3d->persp == RV3D_CAMOB && v3d->camera) {
+  if (!offscreen && rv3d->persp == RV3D_CAMOB && v3d->camera) {
     rctf cameraborder;
     ED_view3d_calc_camera_border(scene, depsgraph, ar, v3d, rv3d, &cameraborder, false);
     rv3d->viewcamtexcofac[0] = (float)ar->winx / BLI_rctf_size_x(&cameraborder);
@@ -184,7 +185,22 @@ static void view3d_main_region_setup_view(Depsgraph *depsgraph,
 {
   RegionView3D *rv3d = ar->regiondata;
 
-  ED_view3d_update_viewmat(depsgraph, scene, v3d, ar, viewmat, winmat, rect);
+  ED_view3d_update_viewmat(depsgraph, scene, v3d, ar, viewmat, winmat, rect, false);
+
+  /* set for opengl */
+  GPU_matrix_projection_set(rv3d->winmat);
+  GPU_matrix_set(rv3d->viewmat);
+}
+
+static void view3d_main_region_setup_offscreen(Depsgraph *depsgraph,
+                                               Scene *scene,
+                                               View3D *v3d,
+                                               ARegion *ar,
+                                               float viewmat[4][4],
+                                               float winmat[4][4])
+{
+  RegionView3D *rv3d = ar->regiondata;
+  ED_view3d_update_viewmat(depsgraph, scene, v3d, ar, viewmat, winmat, NULL, true);
 
   /* set for opengl */
   GPU_matrix_projection_set(rv3d->winmat);
@@ -1480,14 +1496,14 @@ static void view3d_stereo3d_setup_offscreen(Depsgraph *depsgraph,
     const bool is_left = STREQ(viewname, STEREO_LEFT_NAME);
 
     BKE_camera_multiview_view_matrix(&scene->r, v3d->camera, is_left, viewmat);
-    view3d_main_region_setup_view(depsgraph, scene, v3d, ar, viewmat, winmat, NULL);
+    view3d_main_region_setup_offscreen(depsgraph, scene, v3d, ar, viewmat, winmat);
   }
   else { /* SCE_VIEWS_FORMAT_MULTIVIEW */
     float viewmat[4][4];
     Object *camera = BKE_camera_multiview_render(scene, v3d->camera, viewname);
 
     BKE_camera_multiview_view_matrix(&scene->r, camera, false, viewmat);
-    view3d_main_region_setup_view(depsgraph, scene, v3d, ar, viewmat, winmat, NULL);
+    view3d_main_region_setup_offscreen(depsgraph, scene, v3d, ar, viewmat, winmat);
   }
 }
 
@@ -1545,7 +1561,7 @@ void ED_view3d_draw_offscreen(Depsgraph *depsgraph,
     view3d_stereo3d_setup_offscreen(depsgraph, scene, v3d, ar, winmat, viewname);
   }
   else {
-    view3d_main_region_setup_view(depsgraph, scene, v3d, ar, viewmat, winmat, NULL);
+    view3d_main_region_setup_offscreen(depsgraph, scene, v3d, ar, viewmat, winmat);
   }
 
   /* main drawing call */
index 2454358..5865efa 100644 (file)
@@ -428,7 +428,7 @@ void ED_view3d_smooth_view_force_finish(bContext *C, View3D *v3d, ARegion *ar)
      * can use them without redrawing first */
     Depsgraph *depsgraph = CTX_data_depsgraph(C);
     Scene *scene = CTX_data_scene(C);
-    ED_view3d_update_viewmat(depsgraph, scene, v3d, ar, NULL, NULL, NULL);
+    ED_view3d_update_viewmat(depsgraph, scene, v3d, ar, NULL, NULL, NULL, false);
   }
 }
 
index 58a9429..52a1972 100644 (file)
@@ -50,7 +50,7 @@ static void rna_RegionView3D_update(ID *id, RegionView3D *rv3d, bContext *C)
         ViewLayer *view_layer = WM_window_get_active_view_layer(win);
         Depsgraph *depsgraph = BKE_scene_get_depsgraph(scene, view_layer, true);
 
-        ED_view3d_update_viewmat(depsgraph, scene, v3d, ar, NULL, NULL, NULL);
+        ED_view3d_update_viewmat(depsgraph, scene, v3d, ar, NULL, NULL, NULL, false);
         break;
       }
     }