[Bf-blender-cvs] [e148f6d6972] tmp-eevee-glsl-cleanup: Cleanup: EEVEE: Remove own viewvecs

Clément Foucault noreply at git.blender.org
Sat Jul 11 14:42:17 CEST 2020


Commit: e148f6d69729573a18b36fb6712d48e5a40439da
Author: Clément Foucault
Date:   Thu Jul 9 16:56:55 2020 +0200
Branches: tmp-eevee-glsl-cleanup
https://developer.blender.org/rBe148f6d69729573a18b36fb6712d48e5a40439da

Cleanup: EEVEE: Remove own viewvecs

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

M	source/blender/draw/engines/eevee/eevee_materials.c
M	source/blender/draw/engines/eevee/eevee_mist.c
M	source/blender/draw/engines/eevee/eevee_private.h
M	source/blender/draw/engines/eevee/eevee_volumes.c
M	source/blender/draw/engines/eevee/shaders/common_uniforms_lib.glsl

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

diff --git a/source/blender/draw/engines/eevee/eevee_materials.c b/source/blender/draw/engines/eevee/eevee_materials.c
index ab2ed691c63..7e30431b88d 100644
--- a/source/blender/draw/engines/eevee/eevee_materials.c
+++ b/source/blender/draw/engines/eevee/eevee_materials.c
@@ -207,46 +207,6 @@ void EEVEE_update_noise(EEVEE_PassList *psl, EEVEE_FramebufferList *fbl, const d
   DRW_draw_pass(psl->update_noise_pass);
 }
 
-void EEVEE_update_viewvecs(float invproj[4][4], float winmat[4][4], float (*r_viewvecs)[4])
-{
-  /* view vectors for the corners of the view frustum.
-   * Can be used to recreate the world space position easily */
-  float view_vecs[4][4] = {
-      {-1.0f, -1.0f, -1.0f, 1.0f},
-      {1.0f, -1.0f, -1.0f, 1.0f},
-      {-1.0f, 1.0f, -1.0f, 1.0f},
-      {-1.0f, -1.0f, 1.0f, 1.0f},
-  };
-
-  /* convert the view vectors to view space */
-  const bool is_persp = (winmat[3][3] == 0.0f);
-  for (int i = 0; i < 4; i++) {
-    mul_project_m4_v3(invproj, view_vecs[i]);
-    /* normalized trick see:
-     * http://www.derschmale.com/2014/01/26/reconstructing-positions-from-the-depth-buffer */
-    if (is_persp) {
-      /* Divide XY by Z. */
-      mul_v2_fl(view_vecs[i], 1.0f / view_vecs[i][2]);
-    }
-  }
-
-  /**
-   * If ortho : view_vecs[0] is the near-bottom-left corner of the frustum and
-   *            view_vecs[1] is the vector going from the near-bottom-left corner to
-   *            the far-top-right corner.
-   * If Persp : view_vecs[0].xy and view_vecs[1].xy are respectively the bottom-left corner
-   *            when Z = 1, and top-left corner if Z = 1.
-   *            view_vecs[0].z the near clip distance and view_vecs[1].z is the (signed)
-   *            distance from the near plane to the far clip plane.
-   */
-  copy_v4_v4(r_viewvecs[0], view_vecs[0]);
-
-  /* we need to store the differences */
-  r_viewvecs[1][0] = view_vecs[1][0] - view_vecs[0][0];
-  r_viewvecs[1][1] = view_vecs[2][1] - view_vecs[0][1];
-  r_viewvecs[1][2] = view_vecs[3][2] - view_vecs[0][2];
-}
-
 void EEVEE_materials_init(EEVEE_ViewLayerData *sldata,
                           EEVEE_Data *vedata,
                           EEVEE_StorageList *stl,
@@ -273,15 +233,6 @@ void EEVEE_materials_init(EEVEE_ViewLayerData *sldata,
     sldata->common_data.alpha_hash_scale = 0.01f;
   }
 
-  {
-    /* Update view_vecs */
-    float invproj[4][4], winmat[4][4];
-    DRW_view_winmat_get(NULL, winmat, false);
-    DRW_view_winmat_get(NULL, invproj, true);
-
-    EEVEE_update_viewvecs(invproj, winmat, sldata->common_data.view_vecs);
-  }
-
   {
     /* Update noise Framebuffer. */
     GPU_framebuffer_ensure_config(
diff --git a/source/blender/draw/engines/eevee/eevee_mist.c b/source/blender/draw/engines/eevee/eevee_mist.c
index 1f27ed706a8..d2f3a13eb7c 100644
--- a/source/blender/draw/engines/eevee/eevee_mist.c
+++ b/source/blender/draw/engines/eevee/eevee_mist.c
@@ -94,11 +94,11 @@ void EEVEE_mist_output_init(EEVEE_ViewLayerData *sldata, EEVEE_Data *vedata)
     }
   }
   else {
-    float near = -sldata->common_data.view_vecs[0][2];
-    float range = sldata->common_data.view_vecs[1][2];
+    float near = DRW_view_near_distance_get(NULL);
+    float far = DRW_view_far_distance_get(NULL);
     /* Fallback */
     g_data->mist_start = near;
-    g_data->mist_inv_dist = 1.0f / fabsf(range);
+    g_data->mist_inv_dist = 1.0f / fabsf(far - near);
     g_data->mist_falloff = 1.0f;
   }
 
diff --git a/source/blender/draw/engines/eevee/eevee_private.h b/source/blender/draw/engines/eevee/eevee_private.h
index 96d262d2390..5ef58557840 100644
--- a/source/blender/draw/engines/eevee/eevee_private.h
+++ b/source/blender/draw/engines/eevee/eevee_private.h
@@ -747,7 +747,6 @@ typedef struct EEVEE_EffectsInfo {
  * - sizeof(bool) == sizeof(int) in GLSL so use int in C */
 typedef struct EEVEE_CommonUniformBuffer {
   float prev_persmat[4][4]; /* mat4 */
-  float view_vecs[2][4];    /* vec4[2] */
   float mip_ratio[10][4];   /* vec2[10] */
   /* Ambient Occlusion */
   /* -- 16 byte aligned -- */
@@ -1001,7 +1000,6 @@ void EEVEE_object_hair_cache_populate(EEVEE_Data *vedata,
 void EEVEE_materials_cache_finish(EEVEE_ViewLayerData *sldata, EEVEE_Data *vedata);
 void EEVEE_materials_free(void);
 void EEVEE_update_noise(EEVEE_PassList *psl, EEVEE_FramebufferList *fbl, const double offsets[3]);
-void EEVEE_update_viewvecs(float invproj[4][4], float winmat[4][4], float (*r_viewvecs)[4]);
 void EEVEE_material_renderpasses_init(EEVEE_Data *vedata);
 void EEVEE_material_output_init(EEVEE_ViewLayerData *sldata, EEVEE_Data *vedata, uint tot_samples);
 void EEVEE_material_output_accumulate(EEVEE_ViewLayerData *sldata, EEVEE_Data *vedata);
diff --git a/source/blender/draw/engines/eevee/eevee_volumes.c b/source/blender/draw/engines/eevee/eevee_volumes.c
index b59e9a0bf67..c9276ee6e6a 100644
--- a/source/blender/draw/engines/eevee/eevee_volumes.c
+++ b/source/blender/draw/engines/eevee/eevee_volumes.c
@@ -247,17 +247,11 @@ void EEVEE_volumes_init(EEVEE_ViewLayerData *sldata, EEVEE_Data *vedata)
     common_data->vol_shadow_steps = 0;
   }
 
-  /* Update view_vecs */
-  float invproj[4][4], winmat[4][4];
-  DRW_view_winmat_get(NULL, winmat, false);
-  DRW_view_winmat_get(NULL, invproj, true);
-  EEVEE_update_viewvecs(invproj, winmat, sldata->common_data.view_vecs);
-
   if (DRW_view_is_persp_get(NULL)) {
     float sample_distribution = scene_eval->eevee.volumetric_sample_distribution;
     sample_distribution = 4.0f * (max_ff(1.0f - sample_distribution, 1e-2f));
 
-    const float clip_start = common_data->view_vecs[0][2];
+    const float clip_start = DRW_view_near_distance_get(NULL);
     /* Negate */
     float near = integration_start = min_ff(-integration_start, clip_start - 1e-4f);
     float far = integration_end = min_ff(-integration_end, near - 1e-4f);
@@ -268,8 +262,8 @@ void EEVEE_volumes_init(EEVEE_ViewLayerData *sldata, EEVEE_Data *vedata)
     common_data->vol_depth_param[2] = sample_distribution;
   }
   else {
-    const float clip_start = common_data->view_vecs[0][2];
-    const float clip_end = clip_start + common_data->view_vecs[1][2];
+    const float clip_start = DRW_view_near_distance_get(NULL);
+    const float clip_end = DRW_view_far_distance_get(NULL);
     integration_start = min_ff(integration_end, clip_start);
     integration_end = max_ff(-integration_end, clip_end);
 
diff --git a/source/blender/draw/engines/eevee/shaders/common_uniforms_lib.glsl b/source/blender/draw/engines/eevee/shaders/common_uniforms_lib.glsl
index 7068b256111..a6c9eebaff2 100644
--- a/source/blender/draw/engines/eevee/shaders/common_uniforms_lib.glsl
+++ b/source/blender/draw/engines/eevee/shaders/common_uniforms_lib.glsl
@@ -2,7 +2,6 @@
 layout(std140) uniform common_block
 {
   mat4 pastViewProjectionMatrix;
-  vec4 viewVecs[2];
   vec2 mipRatio[10]; /* To correct mip level texel misalignment */
   /* Ambient Occlusion */
   vec4 aoParameters[2];



More information about the Bf-blender-cvs mailing list