[Bf-blender-cvs] [e425e984751] master: OffscreenRendering: Fix Incorrect Window Coordinates

Jeroen Bakker noreply at git.blender.org
Tue May 21 16:07:17 CEST 2019


Commit: e425e98475139733dbfb1da71a39edbad60ed8e1
Author: Jeroen Bakker
Date:   Wed May 15 09:47:22 2019 +0200
Branches: master
https://developer.blender.org/rBe425e98475139733dbfb1da71a39edbad60ed8e1

OffscreenRendering: Fix Incorrect Window Coordinates

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

===================================================================

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

===================================================================

diff --git a/source/blender/editors/gpencil/gpencil_fill.c b/source/blender/editors/gpencil/gpencil_fill.c
index 96f405fab2f..bf15b846bb6 100644
--- a/source/blender/editors/gpencil/gpencil_fill.c
+++ b/source/blender/editors/gpencil/gpencil_fill.c
@@ -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);
diff --git a/source/blender/editors/include/ED_view3d.h b/source/blender/editors/include/ED_view3d.h
index 1c5fc3340eb..055bd3643b6 100644
--- a/source/blender/editors/include/ED_view3d.h
+++ b/source/blender/editors/include/ED_view3d.h
@@ -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);
diff --git a/source/blender/editors/space_view3d/view3d_draw.c b/source/blender/editors/space_view3d/view3d_draw.c
index afc3b80fe3e..54955c83ad9 100644
--- a/source/blender/editors/space_view3d/view3d_draw.c
+++ b/source/blender/editors/space_view3d/view3d_draw.c
@@ -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 */
diff --git a/source/blender/editors/space_view3d/view3d_view.c b/source/blender/editors/space_view3d/view3d_view.c
index 2454358b687..5865efa0ffa 100644
--- a/source/blender/editors/space_view3d/view3d_view.c
+++ b/source/blender/editors/space_view3d/view3d_view.c
@@ -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);
   }
 }
 
diff --git a/source/blender/makesrna/intern/rna_space_api.c b/source/blender/makesrna/intern/rna_space_api.c
index 58a9429e528..52a197240da 100644
--- a/source/blender/makesrna/intern/rna_space_api.c
+++ b/source/blender/makesrna/intern/rna_space_api.c
@@ -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;
       }
     }



More information about the Bf-blender-cvs mailing list