Commit: 7ea7eae41f0b2d751a557a01b900705689733a5a
Author: Clément Foucault
Date:   Mon Jun 25 00:15:30 2018 +0200
Branches: temp-eeveelightcache
https://developer.blender.org/rB7ea7eae41f0b2d751a557a01b900705689733a5a

Eevee: Lookdev: Use own lightcache

This makes possible to have different lookdev settings per viewport without
rendering the environment constantly.

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

M       source/blender/draw/engines/eevee/eevee_lightprobes.c
M       source/blender/draw/engines/eevee/eevee_lookdev.c
M       source/blender/draw/engines/eevee/eevee_private.h

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

diff --git a/source/blender/draw/engines/eevee/eevee_lightprobes.c 
b/source/blender/draw/engines/eevee/eevee_lightprobes.c
index bfb20a86733..e10bdfb26b8 100644
--- a/source/blender/draw/engines/eevee/eevee_lightprobes.c
+++ b/source/blender/draw/engines/eevee/eevee_lightprobes.c
@@ -905,7 +905,10 @@ void EEVEE_lightprobes_refresh(EEVEE_ViewLayerData 
*sldata, EEVEE_Data *vedata)
        EEVEE_LightCache *light_cache = vedata->stl->g_data->light_cache;
 
        if (light_cache->flag & LIGHTCACHE_UPDATE_WORLD) {
+               DRWMatrixState saved_mats;
+               DRW_viewport_matrix_get_all(&saved_mats);
                EEVEE_lightbake_update_world_quick(sldata, vedata, scene_eval);
+               DRW_viewport_matrix_override_set_all(&saved_mats);
        }
 }
 
diff --git a/source/blender/draw/engines/eevee/eevee_lookdev.c 
b/source/blender/draw/engines/eevee/eevee_lookdev.c
index 2e2fb4de798..5437b75facc 100644
--- a/source/blender/draw/engines/eevee/eevee_lookdev.c
+++ b/source/blender/draw/engines/eevee/eevee_lookdev.c
@@ -30,15 +30,31 @@
 #include "DNA_screen_types.h"
 #include "DNA_world_types.h"
 
+#include "DEG_depsgraph_query.h"
+
 #include "ED_screen.h"
 
 #include "eevee_private.h"
+#include "eevee_lightcache.h"
+
+static void eevee_lookdev_lightcache_delete(EEVEE_Data *vedata)
+{
+       EEVEE_StorageList *stl = vedata->stl;
+       EEVEE_TextureList *txl = vedata->txl;
+
+       MEM_SAFE_FREE(stl->lookdev_lightcache);
+       MEM_SAFE_FREE(stl->lookdev_grid_data);
+       MEM_SAFE_FREE(stl->lookdev_cube_data);
+       DRW_TEXTURE_FREE_SAFE(txl->lookdev_grid_tx);
+       DRW_TEXTURE_FREE_SAFE(txl->lookdev_cube_tx);
+}
 
 void EEVEE_lookdev_cache_init(
         EEVEE_Data *vedata, DRWShadingGroup **grp, GPUShader *shader, DRWPass 
*pass,
         World *world, EEVEE_LightProbesInfo *pinfo)
 {
        EEVEE_StorageList *stl = vedata->stl;
+       EEVEE_TextureList *txl = vedata->txl;
        const DRWContextState *draw_ctx = DRW_context_state_get();
        View3D *v3d = draw_ctx->v3d;
        if (LOOK_DEV_MODE_ENABLED(v3d)) {
@@ -47,6 +63,41 @@ void EEVEE_lookdev_cache_init(
                        struct Gwn_Batch *geom = 
DRW_cache_fullscreen_quad_get();
                        GPUTexture *tex = NULL;
 
+                       /* If one of the component is missing we start from 
scratch. */
+                       if ((stl->lookdev_grid_data == NULL) ||
+                           (stl->lookdev_cube_data == NULL) ||
+                           (txl->lookdev_grid_tx == NULL) ||
+                           (txl->lookdev_cube_tx == NULL))
+                       {
+                               eevee_lookdev_lightcache_delete(vedata);
+                       }
+
+                       if (stl->lookdev_lightcache == NULL) {
+                               const Scene *scene_eval = 
DEG_get_evaluated_scene(draw_ctx->depsgraph);
+#if defined(IRRADIANCE_SH_L2)
+                               int grid_res = 4;
+#elif defined(IRRADIANCE_CUBEMAP)
+                               int grid_res = 8;
+#elif defined(IRRADIANCE_HL2)
+                               int grid_res = 4;
+#endif
+                               int cube_res = 
scene_eval->eevee.gi_cubemap_resolution;
+
+                               stl->lookdev_lightcache = 
EEVEE_lightcache_create(1, 1, cube_res, (int[3]){grid_res, grid_res, 1});
+
+                               /* We do this to use a special light cache for 
lookdev.
+                                * This lightcache needs to be per viewport. 
But we need to
+                                * have correct freeing when the viewport is 
closed. So we
+                                * need to reference all textures to the txl 
and the memblocks
+                                * to the stl. */
+                               stl->lookdev_grid_data = 
stl->lookdev_lightcache->grid_data;
+                               stl->lookdev_cube_data = 
stl->lookdev_lightcache->cube_data;
+                               txl->lookdev_grid_tx = 
stl->lookdev_lightcache->grid_tx;
+                               txl->lookdev_cube_tx = 
stl->lookdev_lightcache->cube_tx;
+                       }
+
+                       stl->g_data->light_cache = stl->lookdev_lightcache;
+
                        *grp = DRW_shgroup_create(shader, pass);
                        
axis_angle_to_mat3_single(stl->g_data->studiolight_matrix, 'Z', 
v3d->shading.studiolight_rot_z);
                        DRW_shgroup_uniform_mat3(*grp, "StudioLightMatrix", 
stl->g_data->studiolight_matrix);
@@ -77,11 +128,9 @@ void EEVEE_lookdev_cache_init(
                            ((pinfo->studiolight_index != sl->index) ||
                             (pinfo->studiolight_rot_z != 
v3d->shading.studiolight_rot_z)))
                        {
-                               // pinfo->update_world |= PROBE_UPDATE_ALL;
-                               // pinfo->studiolight_index = sl->index;
-                               // pinfo->studiolight_rot_z = 
v3d->shading.studiolight_rot_z;
-                               // pinfo->prev_wo_sh_compiled = false;
-                               // pinfo->prev_world = NULL;
+                               stl->lookdev_lightcache->flag |= 
LIGHTCACHE_UPDATE_WORLD;
+                               pinfo->studiolight_index = sl->index;
+                               pinfo->studiolight_rot_z = 
v3d->shading.studiolight_rot_z;
                        }
                }
        }
diff --git a/source/blender/draw/engines/eevee/eevee_private.h 
b/source/blender/draw/engines/eevee/eevee_private.h
index 441e13b3acb..07a4612f420 100644
--- a/source/blender/draw/engines/eevee/eevee_private.h
+++ b/source/blender/draw/engines/eevee/eevee_private.h
@@ -275,6 +275,9 @@ typedef struct EEVEE_TextureList {
        struct GPUTexture *volume_scatter_history;
        struct GPUTexture *volume_transmittance_history;
 
+       struct GPUTexture *lookdev_grid_tx;
+       struct GPUTexture *lookdev_cube_tx;
+
        struct GPUTexture *planar_pool;
        struct GPUTexture *planar_depth;
 
@@ -291,6 +294,9 @@ typedef struct EEVEE_StorageList {
 
        struct EEVEE_PrivateData *g_data;
 
+       struct EEVEE_LightCache *lookdev_lightcache;
+       struct EEVEE_LightProbe *lookdev_cube_data;
+       struct EEVEE_LightGrid  *lookdev_grid_data;
 } EEVEE_StorageList;
 
 /* ************ LIGHT UBO ************* */

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to