Eevee: Use DRW_view_* API instead of DRW_viewport_matrix_*
[blender.git] / source / blender / draw / engines / eevee / eevee_render.c
index 8e3857a..e083d16 100644 (file)
@@ -105,25 +105,20 @@ void EEVEE_render_init(EEVEE_Data *ved, RenderEngine *engine, struct Depsgraph *
   }
 
   /* Set the pers & view matrix. */
+  float winmat[4][4], viewmat[4][4], viewinv[4][4];
   /* TODO(sergey): Shall render hold pointer to an evaluated camera instead? */
   struct Object *ob_camera_eval = DEG_get_evaluated_object(depsgraph, RE_GetCamera(engine->re));
   float frame = BKE_scene_frame_get(scene);
-  RE_GetCameraWindow(engine->re, ob_camera_eval, frame, g_data->winmat);
-  RE_GetCameraModelMatrix(engine->re, ob_camera_eval, g_data->viewinv);
 
-  RE_GetCameraWindowWithOverscan(engine->re, g_data->winmat, g_data->overscan);
+  RE_GetCameraWindow(engine->re, ob_camera_eval, frame, winmat);
+  RE_GetCameraWindowWithOverscan(engine->re, winmat, g_data->overscan);
+  RE_GetCameraModelMatrix(engine->re, ob_camera_eval, viewinv);
 
-  invert_m4_m4(g_data->viewmat, g_data->viewinv);
-  mul_m4_m4m4(g_data->persmat, g_data->winmat, g_data->viewmat);
-  invert_m4_m4(g_data->persinv, g_data->persmat);
-  invert_m4_m4(g_data->wininv, g_data->winmat);
+  invert_m4_m4(viewmat, viewinv);
 
-  DRW_viewport_matrix_override_set(g_data->persmat, DRW_MAT_PERS);
-  DRW_viewport_matrix_override_set(g_data->persinv, DRW_MAT_PERSINV);
-  DRW_viewport_matrix_override_set(g_data->winmat, DRW_MAT_WIN);
-  DRW_viewport_matrix_override_set(g_data->wininv, DRW_MAT_WININV);
-  DRW_viewport_matrix_override_set(g_data->viewmat, DRW_MAT_VIEW);
-  DRW_viewport_matrix_override_set(g_data->viewinv, DRW_MAT_VIEWINV);
+  DRWView *view = DRW_view_create(viewmat, winmat, NULL, NULL, NULL);
+  DRW_view_default_set(view);
+  DRW_view_set_active(view);
 
   /* EEVEE_effects_init needs to go first for TAA */
   EEVEE_effects_init(sldata, vedata, ob_camera_eval, false);
@@ -304,6 +299,9 @@ static void eevee_render_result_normal(RenderLayer *rl,
                                1,
                                rp->rect);
 
+    float viewinv[4][4];
+    DRW_view_viewmat_get(NULL, viewinv, true);
+
     /* Convert Eevee encoded normals to Blender normals. */
     for (int i = 0; i < rp->rectx * rp->recty * 3; i += 3) {
       if (rp->rect[i] == 0.0f && rp->rect[i + 1] == 0.0f) {
@@ -322,7 +320,7 @@ static void eevee_render_result_normal(RenderLayer *rl,
       rp->rect[i + 1] = fenc[1] * g;
       rp->rect[i + 2] = 1.0f - f / 2.0f;
 
-      mul_mat3_m4_v3(g_data->viewinv, &rp->rect[i]);
+      mul_mat3_m4_v3(viewinv, &rp->rect[i]);
     }
   }
 }
@@ -357,6 +355,9 @@ static void eevee_render_result_z(RenderLayer *rl,
 
     bool is_persp = DRW_viewport_is_persp_get();
 
+    float viewmat[4][4];
+    DRW_view_viewmat_get(NULL, viewmat, false);
+
     /* Convert ogl depth [0..1] to view Z [near..far] */
     for (int i = 0; i < rp->rectx * rp->recty; ++i) {
       if (rp->rect[i] == 1.0f) {
@@ -365,7 +366,7 @@ static void eevee_render_result_z(RenderLayer *rl,
       else {
         if (is_persp) {
           rp->rect[i] = rp->rect[i] * 2.0f - 1.0f;
-          rp->rect[i] = g_data->winmat[3][2] / (rp->rect[i] + g_data->winmat[2][2]);
+          rp->rect[i] = viewmat[3][2] / (rp->rect[i] + viewmat[2][2]);
         }
         else {
           rp->rect[i] = -common_data->view_vecs[0][2] +
@@ -533,24 +534,17 @@ void EEVEE_render_draw(EEVEE_Data *vedata, RenderEngine *engine, RenderLayer *rl
     double offset[3] = {0.0, 0.0, 0.0};
     double r[3];
 
-    /* Restore winmat before jittering again. */
-    copy_m4_m4(stl->effects->overide_winmat, g_data->winmat);
     /* Copy previous persmat to UBO data */
     copy_m4_m4(sldata->common_data.prev_persmat, stl->effects->prev_persmat);
 
     BLI_halton_3d(primes, offset, stl->effects->taa_current_sample, r);
     EEVEE_update_noise(psl, fbl, r);
-    EEVEE_temporal_sampling_matrices_calc(stl->effects, g_data->viewmat, g_data->persmat, r);
+    EEVEE_temporal_sampling_matrices_calc(stl->effects, r);
     EEVEE_volumes_set_jitter(sldata, stl->effects->taa_current_sample - 1);
     EEVEE_materials_init(sldata, stl, fbl);
 
     /* Set matrices. */
-    DRW_viewport_matrix_override_set(stl->effects->overide_persmat, DRW_MAT_PERS);
-    DRW_viewport_matrix_override_set(stl->effects->overide_persinv, DRW_MAT_PERSINV);
-    DRW_viewport_matrix_override_set(stl->effects->overide_winmat, DRW_MAT_WIN);
-    DRW_viewport_matrix_override_set(stl->effects->overide_wininv, DRW_MAT_WININV);
-    DRW_viewport_matrix_override_set(g_data->viewmat, DRW_MAT_VIEW);
-    DRW_viewport_matrix_override_set(g_data->viewinv, DRW_MAT_VIEWINV);
+    DRW_view_set_active(stl->effects->taa_view);
 
     /* Refresh Probes */
     EEVEE_lightprobes_refresh(sldata, vedata);
@@ -566,7 +560,7 @@ void EEVEE_render_draw(EEVEE_Data *vedata, RenderEngine *engine, RenderLayer *rl
 
     /* Refresh Shadows */
     EEVEE_lights_update(sldata, vedata);
-    EEVEE_draw_shadows(sldata, vedata);
+    EEVEE_draw_shadows(sldata, vedata, stl->effects->taa_view);
 
     /* Set ray type. */
     sldata->common_data.ray_type = EEVEE_RAY_CAMERA;