Merge branch 'master' into blender2.8
authorCampbell Barton <ideasman42@gmail.com>
Wed, 7 Feb 2018 00:18:50 +0000 (11:18 +1100)
committerCampbell Barton <ideasman42@gmail.com>
Wed, 7 Feb 2018 00:19:01 +0000 (11:19 +1100)
47 files changed:
1  2 
source/blender/CMakeLists.txt
source/blender/alembic/intern/abc_mesh.cc
source/blender/blenkernel/BKE_pointcache.h
source/blender/blenkernel/intern/boids.c
source/blender/blenkernel/intern/collision.c
source/blender/blenkernel/intern/effect.c
source/blender/blenkernel/intern/fluidsim.c
source/blender/blenkernel/intern/library_query.c
source/blender/blenkernel/intern/object_deform.c
source/blender/blenkernel/intern/particle_system.c
source/blender/blenkernel/intern/pointcache.c
source/blender/blenkernel/intern/rigidbody.c
source/blender/blenloader/intern/readfile.c
source/blender/blenloader/intern/versioning_250.c
source/blender/blenloader/intern/versioning_260.c
source/blender/blenloader/intern/versioning_270.c
source/blender/blenloader/intern/versioning_legacy.c
source/blender/blenloader/intern/writefile.c
source/blender/depsgraph/intern/builder/deg_builder_relations.cc
source/blender/depsgraph/intern/depsgraph_build.cc
source/blender/draw/engines/eevee/eevee_depth_of_field.c
source/blender/draw/engines/eevee/eevee_volumes.c
source/blender/draw/modes/object_mode.c
source/blender/editors/interface/interface_templates.c
source/blender/editors/object/object_add.c
source/blender/editors/object/object_edit.c
source/blender/editors/object/object_modifier.c
source/blender/editors/physics/physics_fluid.c
source/blender/editors/space_buttons/buttons_texture.c
source/blender/editors/space_view3d/view3d_manipulator_forcefield.c
source/blender/makesdna/DNA_modifier_types.h
source/blender/makesdna/DNA_object_force_types.h
source/blender/makesdna/intern/makesdna.c
source/blender/makesrna/intern/rna_dynamicpaint.c
source/blender/makesrna/intern/rna_fluidsim.c
source/blender/makesrna/intern/rna_modifier.c
source/blender/makesrna/intern/rna_object.c
source/blender/makesrna/intern/rna_object_force.c
source/blender/makesrna/intern/rna_particle.c
source/blender/makesrna/intern/rna_smoke.c
source/blender/modifiers/intern/MOD_dynamicpaint.c
source/blender/modifiers/intern/MOD_fluidsim.c
source/blender/modifiers/intern/MOD_smoke.c
source/blender/modifiers/intern/MOD_softbody.c
source/blender/render/intern/source/convertblender.c
source/blender/render/intern/source/pipeline.c
source/gameengine/Converter/BL_BlenderDataConversion.cpp

Simple merge
index 6c5931263d8be1219e513dd50ad7f912749e7623,8d92ddcb053b21deeb04d759eec9cb01da5bd26a..0f83dfe7ecfc9989e5679eb89148fa191e071620
@@@ -51,8 -51,7 +51,8 @@@
  #include "DNA_movieclip_types.h"
  #include "DNA_mask_types.h"
  #include "DNA_node_types.h"
- #include "DNA_object_force.h"
+ #include "DNA_object_force_types.h"
 +#include "DNA_lightprobe_types.h"
  #include "DNA_rigidbody_types.h"
  #include "DNA_scene_types.h"
  #include "DNA_sensor_types.h"
index 228dc4cf377c325dcc654406f344aa97c43c6f6f,ceb1233596a05444b440c980fcdb841dd497749f..712ce3340024ccaa8b599f987b2a14ffb7313dcc
  #include "DNA_material_types.h"
  #include "DNA_node_types.h"
  #include "DNA_object_types.h"
- #include "DNA_object_force.h"
+ #include "DNA_object_force_types.h"
  #include "DNA_packedFile_types.h"
  #include "DNA_particle_types.h"
 +#include "DNA_lightprobe_types.h"
  #include "DNA_property_types.h"
  #include "DNA_rigidbody_types.h"
  #include "DNA_scene_types.h"
index f5fc79aba4f24afa1e3d4b1c5ce980fc68ed7267,0000000000000000000000000000000000000000..dcd45e27337d8eb118ad01da7d5d9480d314a024
mode 100644,000000..100644
--- /dev/null
@@@ -1,297 -1,0 +1,297 @@@
- #include "DNA_object_force.h"
 +/*
 + * Copyright 2016, Blender Foundation.
 + *
 + * This program is free software; you can redistribute it and/or
 + * modify it under the terms of the GNU General Public License
 + * as published by the Free Software Foundation; either version 2
 + * of the License, or (at your option) any later version.
 + *
 + * This program is distributed in the hope that it will be useful,
 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 + * GNU General Public License for more details.
 + *
 + * You should have received a copy of the GNU General Public License
 + * along with this program; if not, write to the Free Software Foundation,
 + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 + *
 + * Contributor(s): Blender Institute
 + *
 + */
 +
 +/** \file eevee_depth_of_field.c
 + *  \ingroup draw_engine
 + *
 + * Depth of field post process effect.
 + */
 +
 +#include "DRW_render.h"
 +
 +#include "BLI_dynstr.h"
 +#include "BLI_rand.h"
 +
 +#include "DNA_anim_types.h"
 +#include "DNA_camera_types.h"
++#include "DNA_object_force_types.h"
 +#include "DNA_screen_types.h"
 +#include "DNA_view3d_types.h"
 +#include "DNA_world_types.h"
 +
 +#include "BKE_global.h" /* for G.debug_value */
 +#include "BKE_camera.h"
 +#include "BKE_mesh.h"
 +#include "BKE_object.h"
 +#include "BKE_animsys.h"
 +#include "BKE_screen.h"
 +
 +#include "DEG_depsgraph.h"
 +#include "DEG_depsgraph_query.h"
 +
 +#include "eevee_private.h"
 +#include "GPU_extensions.h"
 +#include "GPU_framebuffer.h"
 +#include "GPU_texture.h"
 +
 +#include "ED_screen.h"
 +
 +static struct {
 +      /* Depth Of Field */
 +      struct GPUShader *dof_downsample_sh;
 +      struct GPUShader *dof_scatter_sh;
 +      struct GPUShader *dof_resolve_sh;
 +} e_data = {NULL}; /* Engine data */
 +
 +extern char datatoc_effect_dof_vert_glsl[];
 +extern char datatoc_effect_dof_geom_glsl[];
 +extern char datatoc_effect_dof_frag_glsl[];
 +
 +static void eevee_create_shader_depth_of_field(void)
 +{
 +      e_data.dof_downsample_sh = DRW_shader_create(datatoc_effect_dof_vert_glsl, NULL,
 +                                                   datatoc_effect_dof_frag_glsl, "#define STEP_DOWNSAMPLE\n");
 +      e_data.dof_scatter_sh = DRW_shader_create(datatoc_effect_dof_vert_glsl, NULL,
 +                                                datatoc_effect_dof_frag_glsl, "#define STEP_SCATTER\n");
 +      e_data.dof_resolve_sh = DRW_shader_create(datatoc_effect_dof_vert_glsl, NULL,
 +                                                datatoc_effect_dof_frag_glsl, "#define STEP_RESOLVE\n");
 +}
 +
 +int EEVEE_depth_of_field_init(EEVEE_ViewLayerData *UNUSED(sldata), EEVEE_Data *vedata, Object *camera)
 +{
 +      EEVEE_StorageList *stl = vedata->stl;
 +      EEVEE_FramebufferList *fbl = vedata->fbl;
 +      EEVEE_TextureList *txl = vedata->txl;
 +      EEVEE_EffectsInfo *effects = stl->effects;
 +
 +      const DRWContextState *draw_ctx = DRW_context_state_get();
 +      ViewLayer *view_layer = draw_ctx->view_layer;
 +      IDProperty *props = BKE_view_layer_engine_evaluated_get(view_layer, COLLECTION_MODE_NONE, RE_engine_id_BLENDER_EEVEE);
 +
 +      if (BKE_collection_engine_property_value_get_bool(props, "dof_enable")) {
 +              Scene *scene = draw_ctx->scene;
 +              RegionView3D *rv3d = draw_ctx->rv3d;
 +
 +              if (!e_data.dof_downsample_sh) {
 +                      eevee_create_shader_depth_of_field();
 +              }
 +
 +              if (camera) {
 +                      const float *viewport_size = DRW_viewport_size_get();
 +                      Camera *cam = (Camera *)camera->data;
 +
 +                      /* Retreive Near and Far distance */
 +                      effects->dof_near_far[0] = -cam->clipsta;
 +                      effects->dof_near_far[1] = -cam->clipend;
 +
 +                      int buffer_size[2] = {(int)viewport_size[0] / 2, (int)viewport_size[1] / 2};
 +
 +                      /* Reuse buffer from Bloom if available */
 +                      /* WATCH IT : must have the same size */
 +                      struct GPUTexture **dof_down_near;
 +
 +                      if ((effects->enabled_effects & EFFECT_BLOOM) != 0) {
 +                              dof_down_near = &txl->bloom_downsample[0];
 +                      }
 +                      else {
 +                              dof_down_near = &txl->dof_down_near;
 +                      }
 +
 +                      /* Setup buffers */
 +                      DRWFboTexture tex_down[3] = {
 +                              {dof_down_near, DRW_TEX_RGB_11_11_10, DRW_TEX_FILTER}, /* filter to not interfeer with bloom */
 +                              {&txl->dof_down_far, DRW_TEX_RGB_11_11_10, 0},
 +                              {&txl->dof_coc, DRW_TEX_RG_16, 0},
 +                      };
 +                      DRW_framebuffer_init(
 +                              &fbl->dof_down_fb, &draw_engine_eevee_type,
 +                              buffer_size[0], buffer_size[1], tex_down, 3);
 +
 +                      /* Go full 32bits for rendering and reduce the color artifacts. */
 +                      DRWTextureFormat fb_format = DRW_state_is_image_render() ? DRW_TEX_RGBA_32 : DRW_TEX_RGBA_16;
 +
 +                      DRWFboTexture tex_scatter_far = {&txl->dof_far_blur, fb_format, DRW_TEX_FILTER};
 +                      DRW_framebuffer_init(
 +                              &fbl->dof_scatter_far_fb, &draw_engine_eevee_type,
 +                              buffer_size[0], buffer_size[1], &tex_scatter_far, 1);
 +
 +                      DRWFboTexture tex_scatter_near = {&txl->dof_near_blur, fb_format, DRW_TEX_FILTER};
 +                      DRW_framebuffer_init(
 +                              &fbl->dof_scatter_near_fb, &draw_engine_eevee_type,
 +                              buffer_size[0], buffer_size[1], &tex_scatter_near, 1);
 +
 +                      /* Parameters */
 +                      /* TODO UI Options */
 +                      float fstop = cam->gpu_dof.fstop;
 +                      float blades = cam->gpu_dof.num_blades;
 +                      float rotation = cam->gpu_dof.rotation;
 +                      float ratio = 1.0f / cam->gpu_dof.ratio;
 +                      float sensor = BKE_camera_sensor_size(cam->sensor_fit, cam->sensor_x, cam->sensor_y);
 +                      float focus_dist = BKE_camera_object_dof_distance(camera);
 +                      float focal_len = cam->lens;
 +
 +                      UNUSED_VARS(rotation, ratio);
 +
 +                      /* this is factor that converts to the scene scale. focal length and sensor are expressed in mm
 +                       * unit.scale_length is how many meters per blender unit we have. We want to convert to blender units though
 +                       * because the shader reads coordinates in world space, which is in blender units.
 +                       * Note however that focus_distance is already in blender units and shall not be scaled here (see T48157). */
 +                      float scale = (scene->unit.system) ? scene->unit.scale_length : 1.0f;
 +                      float scale_camera = 0.001f / scale;
 +                      /* we want radius here for the aperture number  */
 +                      float aperture = 0.5f * scale_camera * focal_len / fstop;
 +                      float focal_len_scaled = scale_camera * focal_len;
 +                      float sensor_scaled = scale_camera * sensor;
 +
 +                      if (rv3d != NULL) {
 +                              sensor_scaled *= rv3d->viewcamtexcofac[0];
 +                      }
 +
 +                      effects->dof_params[0] = aperture * fabsf(focal_len_scaled / (focus_dist - focal_len_scaled));
 +                      effects->dof_params[1] = -focus_dist;
 +                      effects->dof_params[2] = viewport_size[0] / sensor_scaled;
 +                      effects->dof_bokeh[0] = blades;
 +                      effects->dof_bokeh[1] = rotation;
 +                      effects->dof_bokeh[2] = ratio;
 +                      effects->dof_bokeh[3] = BKE_collection_engine_property_value_get_float(props, "bokeh_max_size");
 +
 +                      return EFFECT_DOF | EFFECT_POST_BUFFER;
 +              }
 +      }
 +
 +      /* Cleanup to release memory */
 +      DRW_TEXTURE_FREE_SAFE(txl->dof_down_near);
 +      DRW_TEXTURE_FREE_SAFE(txl->dof_down_far);
 +      DRW_TEXTURE_FREE_SAFE(txl->dof_coc);
 +      DRW_TEXTURE_FREE_SAFE(txl->dof_far_blur);
 +      DRW_TEXTURE_FREE_SAFE(txl->dof_near_blur);
 +      DRW_FRAMEBUFFER_FREE_SAFE(fbl->dof_down_fb);
 +      DRW_FRAMEBUFFER_FREE_SAFE(fbl->dof_scatter_far_fb);
 +      DRW_FRAMEBUFFER_FREE_SAFE(fbl->dof_scatter_near_fb);
 +
 +      return 0;
 +}
 +
 +void EEVEE_depth_of_field_cache_init(EEVEE_ViewLayerData *UNUSED(sldata), EEVEE_Data *vedata)
 +{
 +      EEVEE_PassList *psl = vedata->psl;
 +      EEVEE_StorageList *stl = vedata->stl;
 +      EEVEE_TextureList *txl = vedata->txl;
 +      EEVEE_EffectsInfo *effects = stl->effects;
 +      DefaultTextureList *dtxl = DRW_viewport_texture_list_get();
 +
 +      if ((effects->enabled_effects & EFFECT_DOF) != 0) {
 +              /**  Depth of Field algorithm
 +               *
 +               * Overview :
 +               * - Downsample the color buffer into 2 buffers weighted with
 +               *   CoC values. Also output CoC into a texture.
 +               * - Shoot quads for every pixel and expand it depending on the CoC.
 +               *   Do one pass for near Dof and one pass for far Dof.
 +               * - Finally composite the 2 blurred buffers with the original render.
 +               **/
 +              DRWShadingGroup *grp;
 +              struct Gwn_Batch *quad = DRW_cache_fullscreen_quad_get();
 +
 +              psl->dof_down = DRW_pass_create("DoF Downsample", DRW_STATE_WRITE_COLOR);
 +
 +              grp = DRW_shgroup_create(e_data.dof_downsample_sh, psl->dof_down);
 +              DRW_shgroup_uniform_buffer(grp, "colorBuffer", &effects->source_buffer);
 +              DRW_shgroup_uniform_buffer(grp, "depthBuffer", &dtxl->depth);
 +              DRW_shgroup_uniform_vec2(grp, "nearFar", effects->dof_near_far, 1);
 +              DRW_shgroup_uniform_vec3(grp, "dofParams", effects->dof_params, 1);
 +              DRW_shgroup_call_add(grp, quad, NULL);
 +
 +              psl->dof_scatter = DRW_pass_create("DoF Scatter", DRW_STATE_WRITE_COLOR | DRW_STATE_ADDITIVE_FULL);
 +
 +              /* This create an empty batch of N triangles to be positioned
 +               * by the vertex shader 0.4ms against 6ms with instancing */
 +              const float *viewport_size = DRW_viewport_size_get();
 +              const int sprite_ct = ((int)viewport_size[0] / 2) * ((int)viewport_size[1] / 2); /* brackets matters */
 +              grp = DRW_shgroup_empty_tri_batch_create(e_data.dof_scatter_sh, psl->dof_scatter, sprite_ct);
 +
 +              DRW_shgroup_uniform_buffer(grp, "colorBuffer", &effects->unf_source_buffer);
 +              DRW_shgroup_uniform_buffer(grp, "cocBuffer", &txl->dof_coc);
 +              DRW_shgroup_uniform_vec2(grp, "layerSelection", effects->dof_layer_select, 1);
 +              DRW_shgroup_uniform_vec4(grp, "bokehParams", effects->dof_bokeh, 1);
 +
 +              psl->dof_resolve = DRW_pass_create("DoF Resolve", DRW_STATE_WRITE_COLOR);
 +
 +              grp = DRW_shgroup_create(e_data.dof_resolve_sh, psl->dof_resolve);
 +              DRW_shgroup_uniform_buffer(grp, "colorBuffer", &effects->source_buffer);
 +              DRW_shgroup_uniform_buffer(grp, "nearBuffer", &txl->dof_near_blur);
 +              DRW_shgroup_uniform_buffer(grp, "farBuffer", &txl->dof_far_blur);
 +              DRW_shgroup_uniform_buffer(grp, "depthBuffer", &dtxl->depth);
 +              DRW_shgroup_uniform_vec2(grp, "nearFar", effects->dof_near_far, 1);
 +              DRW_shgroup_uniform_vec3(grp, "dofParams", effects->dof_params, 1);
 +              DRW_shgroup_call_add(grp, quad, NULL);
 +      }
 +}
 +
 +void EEVEE_depth_of_field_draw(EEVEE_Data *vedata)
 +{
 +      EEVEE_PassList *psl = vedata->psl;
 +      EEVEE_TextureList *txl = vedata->txl;
 +      EEVEE_FramebufferList *fbl = vedata->fbl;
 +      EEVEE_StorageList *stl = vedata->stl;
 +      EEVEE_EffectsInfo *effects = stl->effects;
 +
 +      /* Depth Of Field */
 +      if ((effects->enabled_effects & EFFECT_DOF) != 0) {
 +              float clear_col[4] = {0.0f, 0.0f, 0.0f, 0.0f};
 +
 +              /* Downsample */
 +              DRW_framebuffer_bind(fbl->dof_down_fb);
 +              DRW_draw_pass(psl->dof_down);
 +
 +              /* Scatter Far */
 +              effects->unf_source_buffer = txl->dof_down_far;
 +              copy_v2_fl2(effects->dof_layer_select, 0.0f, 1.0f);
 +              DRW_framebuffer_bind(fbl->dof_scatter_far_fb);
 +              DRW_framebuffer_clear(true, false, false, clear_col, 0.0f);
 +              DRW_draw_pass(psl->dof_scatter);
 +
 +              /* Scatter Near */
 +              if ((effects->enabled_effects & EFFECT_BLOOM) != 0) {
 +                      /* Reuse bloom half res buffer */
 +                      effects->unf_source_buffer = txl->bloom_downsample[0];
 +              }
 +              else {
 +                      effects->unf_source_buffer = txl->dof_down_near;
 +              }
 +              copy_v2_fl2(effects->dof_layer_select, 1.0f, 0.0f);
 +              DRW_framebuffer_bind(fbl->dof_scatter_near_fb);
 +              DRW_framebuffer_clear(true, false, false, clear_col, 0.0f);
 +              DRW_draw_pass(psl->dof_scatter);
 +
 +              /* Resolve */
 +              DRW_framebuffer_bind(effects->target_buffer);
 +              DRW_draw_pass(psl->dof_resolve);
 +              SWAP_BUFFERS();
 +      }
 +}
 +
 +void EEVEE_depth_of_field_free(void)
 +{
 +      DRW_SHADER_FREE_SAFE(e_data.dof_downsample_sh);
 +      DRW_SHADER_FREE_SAFE(e_data.dof_scatter_sh);
 +      DRW_SHADER_FREE_SAFE(e_data.dof_resolve_sh);
 +}
index 3c538c945e89fd74f76ca5cc35d240a897fbc200,0000000000000000000000000000000000000000..2c5b90728379f91f100edb15e1a30f9b63858e95
mode 100644,000000..100644
--- /dev/null
@@@ -1,593 -1,0 +1,593 @@@
- #include "DNA_object_force.h"
 +/*
 + * Copyright 2016, Blender Foundation.
 + *
 + * This program is free software; you can redistribute it and/or
 + * modify it under the terms of the GNU General Public License
 + * as published by the Free Software Foundation; either version 2
 + * of the License, or (at your option) any later version.
 + *
 + * This program is distributed in the hope that it will be useful,
 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 + * GNU General Public License for more details.
 + *
 + * You should have received a copy of the GNU General Public License
 + * along with this program; if not, write to the Free Software Foundation,
 + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 + *
 + * Contributor(s): Blender Institute
 + *
 + */
 +
 +/** \file eevee_volumes.c
 + *  \ingroup draw_engine
 + *
 + * Volumetric effects rendering using frostbite approach.
 + */
 +
 +#include "DRW_render.h"
 +
 +#include "BLI_rand.h"
 +#include "BLI_string_utils.h"
 +
++#include "DNA_object_force_types.h"
 +#include "DNA_smoke_types.h"
 +#include "DNA_world_types.h"
 +
 +#include "BKE_global.h" /* for G.debug_value */
 +#include "BKE_modifier.h"
 +#include "BKE_mesh.h"
 +#include "BKE_object.h"
 +
 +#include "ED_screen.h"
 +
 +#include "eevee_private.h"
 +#include "GPU_draw.h"
 +#include "GPU_texture.h"
 +
 +static struct {
 +      char *volumetric_common_lib;
 +      char *volumetric_common_lamps_lib;
 +
 +      struct GPUShader *volumetric_clear_sh;
 +      struct GPUShader *volumetric_scatter_sh;
 +      struct GPUShader *volumetric_scatter_with_lamps_sh;
 +      struct GPUShader *volumetric_integration_sh;
 +      struct GPUShader *volumetric_resolve_sh;
 +
 +      GPUTexture *color_src;
 +      GPUTexture *depth_src;
 +
 +      /* List of all smoke domains rendered within this frame. */
 +      ListBase smoke_domains;
 +} e_data = {NULL}; /* Engine data */
 +
 +extern char datatoc_bsdf_common_lib_glsl[];
 +extern char datatoc_bsdf_direct_lib_glsl[];
 +extern char datatoc_common_uniforms_lib_glsl[];
 +extern char datatoc_octahedron_lib_glsl[];
 +extern char datatoc_irradiance_lib_glsl[];
 +extern char datatoc_lamps_lib_glsl[];
 +extern char datatoc_volumetric_frag_glsl[];
 +extern char datatoc_volumetric_geom_glsl[];
 +extern char datatoc_volumetric_vert_glsl[];
 +extern char datatoc_volumetric_resolve_frag_glsl[];
 +extern char datatoc_volumetric_scatter_frag_glsl[];
 +extern char datatoc_volumetric_integration_frag_glsl[];
 +extern char datatoc_volumetric_lib_glsl[];
 +extern char datatoc_gpu_shader_fullscreen_vert_glsl[];
 +
 +static void eevee_create_shader_volumes(void)
 +{
 +      e_data.volumetric_common_lib = BLI_string_joinN(
 +              datatoc_common_uniforms_lib_glsl,
 +              datatoc_bsdf_common_lib_glsl,
 +              datatoc_volumetric_lib_glsl);
 +
 +      e_data.volumetric_common_lamps_lib = BLI_string_joinN(
 +              datatoc_common_uniforms_lib_glsl,
 +              datatoc_bsdf_common_lib_glsl,
 +              datatoc_bsdf_direct_lib_glsl,
 +              datatoc_octahedron_lib_glsl,
 +              datatoc_irradiance_lib_glsl,
 +              datatoc_lamps_lib_glsl,
 +              datatoc_volumetric_lib_glsl);
 +
 +      e_data.volumetric_clear_sh = DRW_shader_create_with_lib(
 +              datatoc_volumetric_vert_glsl,
 +              datatoc_volumetric_geom_glsl,
 +              datatoc_volumetric_frag_glsl,
 +              e_data.volumetric_common_lib,
 +              "#define VOLUMETRICS\n"
 +              "#define CLEAR\n");
 +      e_data.volumetric_scatter_sh = DRW_shader_create_with_lib(
 +              datatoc_volumetric_vert_glsl,
 +              datatoc_volumetric_geom_glsl,
 +              datatoc_volumetric_scatter_frag_glsl,
 +              e_data.volumetric_common_lamps_lib,
 +              SHADER_DEFINES
 +              "#define VOLUMETRICS\n"
 +              "#define VOLUME_SHADOW\n");
 +      e_data.volumetric_scatter_with_lamps_sh = DRW_shader_create_with_lib(
 +              datatoc_volumetric_vert_glsl,
 +              datatoc_volumetric_geom_glsl,
 +              datatoc_volumetric_scatter_frag_glsl,
 +              e_data.volumetric_common_lamps_lib,
 +              SHADER_DEFINES
 +              "#define VOLUMETRICS\n"
 +              "#define VOLUME_LIGHTING\n"
 +              "#define VOLUME_SHADOW\n");
 +      e_data.volumetric_integration_sh = DRW_shader_create_with_lib(
 +              datatoc_volumetric_vert_glsl,
 +              datatoc_volumetric_geom_glsl,
 +              datatoc_volumetric_integration_frag_glsl,
 +              e_data.volumetric_common_lib, NULL);
 +      e_data.volumetric_resolve_sh = DRW_shader_create_with_lib(
 +              datatoc_gpu_shader_fullscreen_vert_glsl, NULL,
 +              datatoc_volumetric_resolve_frag_glsl,
 +              e_data.volumetric_common_lib, NULL);
 +}
 +
 +void EEVEE_volumes_set_jitter(EEVEE_ViewLayerData *sldata, unsigned int current_sample)
 +{
 +      EEVEE_CommonUniformBuffer *common_data = &sldata->common_data;
 +
 +      double ht_point[3];
 +      double ht_offset[3] = {0.0, 0.0};
 +      unsigned int ht_primes[3] = {3, 7, 2};
 +
 +      BLI_halton_3D(ht_primes, ht_offset, current_sample, ht_point);
 +
 +      common_data->vol_jitter[0] = (float)ht_point[0];
 +      common_data->vol_jitter[1] = (float)ht_point[1];
 +      common_data->vol_jitter[2] = (float)ht_point[2];
 +}
 +
 +int EEVEE_volumes_init(EEVEE_ViewLayerData *sldata, EEVEE_Data *vedata)
 +{
 +      EEVEE_StorageList *stl = vedata->stl;
 +      EEVEE_FramebufferList *fbl = vedata->fbl;
 +      EEVEE_TextureList *txl = vedata->txl;
 +      EEVEE_EffectsInfo *effects = stl->effects;
 +      EEVEE_CommonUniformBuffer *common_data = &sldata->common_data;
 +
 +      const DRWContextState *draw_ctx = DRW_context_state_get();
 +      ViewLayer *view_layer = draw_ctx->view_layer;
 +      IDProperty *props = BKE_view_layer_engine_evaluated_get(view_layer, COLLECTION_MODE_NONE, RE_engine_id_BLENDER_EEVEE);
 +
 +      const float *viewport_size = DRW_viewport_size_get();
 +
 +      BLI_listbase_clear(&e_data.smoke_domains);
 +
 +      if (BKE_collection_engine_property_value_get_bool(props, "volumetric_enable")) {
 +
 +              /* Shaders */
 +              if (!e_data.volumetric_scatter_sh) {
 +                      eevee_create_shader_volumes();
 +              }
 +
 +              int tile_size = BKE_collection_engine_property_value_get_int(props, "volumetric_tile_size");
 +
 +              /* Find Froxel Texture resolution. */
 +              int tex_size[3];
 +
 +              tex_size[0] = (int)ceilf(fmaxf(1.0f, viewport_size[0] / (float)tile_size));
 +              tex_size[1] = (int)ceilf(fmaxf(1.0f, viewport_size[1] / (float)tile_size));
 +              tex_size[2] = max_ii(BKE_collection_engine_property_value_get_int(props, "volumetric_samples"), 1);
 +
 +              common_data->vol_coord_scale[0] = viewport_size[0] / (float)(tile_size * tex_size[0]);
 +              common_data->vol_coord_scale[1] = viewport_size[1] / (float)(tile_size * tex_size[1]);
 +
 +              /* TODO compute snap to maxZBuffer for clustered rendering */
 +
 +              if ((common_data->vol_tex_size[0] != tex_size[0]) ||
 +                  (common_data->vol_tex_size[1] != tex_size[1]) ||
 +                  (common_data->vol_tex_size[2] != tex_size[2]))
 +              {
 +                      DRW_TEXTURE_FREE_SAFE(txl->volume_prop_scattering);
 +                      DRW_TEXTURE_FREE_SAFE(txl->volume_prop_extinction);
 +                      DRW_TEXTURE_FREE_SAFE(txl->volume_prop_emission);
 +                      DRW_TEXTURE_FREE_SAFE(txl->volume_prop_phase);
 +                      DRW_TEXTURE_FREE_SAFE(txl->volume_scatter);
 +                      DRW_TEXTURE_FREE_SAFE(txl->volume_transmittance);
 +                      DRW_TEXTURE_FREE_SAFE(txl->volume_scatter_history);
 +                      DRW_TEXTURE_FREE_SAFE(txl->volume_transmittance_history);
 +                      DRW_FRAMEBUFFER_FREE_SAFE(fbl->volumetric_fb);
 +                      DRW_FRAMEBUFFER_FREE_SAFE(fbl->volumetric_scat_fb);
 +                      DRW_FRAMEBUFFER_FREE_SAFE(fbl->volumetric_integ_fb);
 +                      common_data->vol_tex_size[0] = tex_size[0];
 +                      common_data->vol_tex_size[1] = tex_size[1];
 +                      common_data->vol_tex_size[2] = tex_size[2];
 +
 +                      common_data->vol_inv_tex_size[0] = 1.0f / (float)(tex_size[0]);
 +                      common_data->vol_inv_tex_size[1] = 1.0f / (float)(tex_size[1]);
 +                      common_data->vol_inv_tex_size[2] = 1.0f / (float)(tex_size[2]);
 +              }
 +
 +              /* Like frostbite's paper, 5% blend of the new frame. */
 +              common_data->vol_history_alpha = (txl->volume_prop_scattering == NULL) ? 0.0f : 0.95f;
 +
 +              if (txl->volume_prop_scattering == NULL) {
 +                      /* Volume properties: We evaluate all volumetric objects
 +                       * and store their final properties into each froxel */
 +                      txl->volume_prop_scattering = DRW_texture_create_3D(tex_size[0], tex_size[1], tex_size[2],
 +                                                                          DRW_TEX_RGB_11_11_10, DRW_TEX_FILTER, NULL);
 +                      txl->volume_prop_extinction = DRW_texture_create_3D(tex_size[0], tex_size[1], tex_size[2],
 +                                                                          DRW_TEX_RGB_11_11_10, DRW_TEX_FILTER, NULL);
 +                      txl->volume_prop_emission = DRW_texture_create_3D(tex_size[0], tex_size[1], tex_size[2],
 +                                                                        DRW_TEX_RGB_11_11_10, DRW_TEX_FILTER, NULL);
 +                      txl->volume_prop_phase = DRW_texture_create_3D(tex_size[0], tex_size[1], tex_size[2],
 +                                                                     DRW_TEX_RG_16, DRW_TEX_FILTER, NULL);
 +
 +                      /* Volume scattering: We compute for each froxel the
 +                       * Scattered light towards the view. We also resolve temporal
 +                       * super sampling during this stage. */
 +                      txl->volume_scatter = DRW_texture_create_3D(tex_size[0], tex_size[1], tex_size[2],
 +                                                                  DRW_TEX_RGB_11_11_10, DRW_TEX_FILTER, NULL);
 +                      txl->volume_transmittance = DRW_texture_create_3D(tex_size[0], tex_size[1], tex_size[2],
 +                                                                        DRW_TEX_RGB_11_11_10, DRW_TEX_FILTER, NULL);
 +
 +                      /* Final integration: We compute for each froxel the
 +                       * amount of scattered light and extinction coef at this
 +                       * given depth. We use theses textures as double buffer
 +                       * for the volumetric history. */
 +                      txl->volume_scatter_history = DRW_texture_create_3D(tex_size[0], tex_size[1], tex_size[2],
 +                                                                          DRW_TEX_RGB_11_11_10, DRW_TEX_FILTER, NULL);
 +                      txl->volume_transmittance_history = DRW_texture_create_3D(tex_size[0], tex_size[1], tex_size[2],
 +                                                                                DRW_TEX_RGB_11_11_10, DRW_TEX_FILTER, NULL);
 +              }
 +
 +              /* Temporal Super sampling jitter */
 +              unsigned int ht_primes[3] = {3, 7, 2};
 +              unsigned int current_sample = 0;
 +
 +              /* If TAA is in use do not use the history buffer. */
 +              bool do_taa = ((effects->enabled_effects & EFFECT_TAA) != 0);
 +
 +              if (draw_ctx->evil_C != NULL) {
 +                      struct wmWindowManager *wm = CTX_wm_manager(draw_ctx->evil_C);
 +                      do_taa = do_taa && (ED_screen_animation_no_scrub(wm) == NULL);
 +              }
 +
 +              if (do_taa) {
 +                      common_data->vol_history_alpha = 0.0f;
 +                      current_sample = effects->taa_current_sample - 1;
 +                      effects->volume_current_sample = -1;
 +              }
 +              else {
 +                      const unsigned int max_sample = (ht_primes[0] * ht_primes[1] * ht_primes[2]);
 +                      current_sample = effects->volume_current_sample = (effects->volume_current_sample + 1) % max_sample;
 +                      if (current_sample != max_sample - 1) {
 +                              DRW_viewport_request_redraw();
 +                      }
 +              }
 +
 +              EEVEE_volumes_set_jitter(sldata, current_sample);
 +
 +              /* Framebuffer setup */
 +              DRWFboTexture tex_vol[4] = {{&txl->volume_prop_scattering, DRW_TEX_RGB_11_11_10, DRW_TEX_FILTER},
 +                                          {&txl->volume_prop_extinction, DRW_TEX_RGB_11_11_10, DRW_TEX_FILTER},
 +                                          {&txl->volume_prop_emission, DRW_TEX_RGB_11_11_10, DRW_TEX_FILTER},
 +                                          {&txl->volume_prop_phase, DRW_TEX_RG_16, DRW_TEX_FILTER}};
 +
 +              DRW_framebuffer_init(&fbl->volumetric_fb, &draw_engine_eevee_type,
 +                                   (int)tex_size[0], (int)tex_size[1],
 +                                   tex_vol, 4);
 +
 +              DRWFboTexture tex_vol_scat[2] = {{&txl->volume_scatter, DRW_TEX_RGB_11_11_10, DRW_TEX_FILTER},
 +                                               {&txl->volume_transmittance, DRW_TEX_RGB_11_11_10, DRW_TEX_FILTER}};
 +
 +              DRW_framebuffer_init(&fbl->volumetric_scat_fb, &draw_engine_eevee_type,
 +                                   (int)tex_size[0], (int)tex_size[1],
 +                                   tex_vol_scat, 2);
 +
 +              DRWFboTexture tex_vol_integ[2] = {{&txl->volume_scatter_history, DRW_TEX_RGB_11_11_10, DRW_TEX_FILTER},
 +                                                {&txl->volume_transmittance_history, DRW_TEX_RGB_11_11_10, DRW_TEX_FILTER}};
 +
 +              DRW_framebuffer_init(&fbl->volumetric_integ_fb, &draw_engine_eevee_type,
 +                                   (int)tex_size[0], (int)tex_size[1],
 +                                   tex_vol_integ, 2);
 +
 +              float integration_start = BKE_collection_engine_property_value_get_float(props, "volumetric_start");
 +              float integration_end = BKE_collection_engine_property_value_get_float(props, "volumetric_end");
 +              common_data->vol_light_clamp = BKE_collection_engine_property_value_get_float(props, "volumetric_light_clamp");
 +
 +              common_data->vol_shadow_steps = (float)BKE_collection_engine_property_value_get_int(props, "volumetric_shadow_samples");
 +              if (BKE_collection_engine_property_value_get_bool(props, "volumetric_shadows")) {
 +              }
 +              else {
 +                      common_data->vol_shadow_steps = 0;
 +              }
 +
 +              if (DRW_viewport_is_persp_get()) {
 +                      float sample_distribution = BKE_collection_engine_property_value_get_float(props, "volumetric_sample_distribution");
 +                      sample_distribution = 4.0f * (1.00001f - sample_distribution);
 +
 +                      const float clip_start = common_data->view_vecs[0][2];
 +                      /* Negate */
 +                      float near = integration_start = min_ff(-integration_start, clip_start - 1e-4f);
 +                      float far = integration_end = min_ff(-integration_end, near - 1e-4f);
 +
 +                      common_data->vol_depth_param[0] = (far - near * exp2(1.0f / sample_distribution)) / (far - near);
 +                      common_data->vol_depth_param[1] = (1.0f - common_data->vol_depth_param[0]) / near;
 +                      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];
 +                      integration_start = min_ff(integration_end, clip_start);
 +                      integration_end = max_ff(-integration_end, clip_end);
 +
 +                      common_data->vol_depth_param[0] = integration_start;
 +                      common_data->vol_depth_param[1] = integration_end;
 +                      common_data->vol_depth_param[2] = 1.0f / (integration_end - integration_start);
 +              }
 +
 +              /* Disable clamp if equal to 0. */
 +              if (common_data->vol_light_clamp == 0.0) {
 +                      common_data->vol_light_clamp = FLT_MAX;
 +              }
 +
 +              common_data->vol_use_lights = BKE_collection_engine_property_value_get_bool(props, "volumetric_lights");
 +
 +              return EFFECT_VOLUMETRIC | EFFECT_POST_BUFFER;
 +      }
 +
 +      /* Cleanup to release memory */
 +      DRW_TEXTURE_FREE_SAFE(txl->volume_prop_scattering);
 +      DRW_TEXTURE_FREE_SAFE(txl->volume_prop_extinction);
 +      DRW_TEXTURE_FREE_SAFE(txl->volume_prop_emission);
 +      DRW_TEXTURE_FREE_SAFE(txl->volume_prop_phase);
 +      DRW_TEXTURE_FREE_SAFE(txl->volume_scatter);
 +      DRW_TEXTURE_FREE_SAFE(txl->volume_transmittance);
 +      DRW_TEXTURE_FREE_SAFE(txl->volume_scatter_history);
 +      DRW_TEXTURE_FREE_SAFE(txl->volume_transmittance_history);
 +      DRW_FRAMEBUFFER_FREE_SAFE(fbl->volumetric_fb);
 +      DRW_FRAMEBUFFER_FREE_SAFE(fbl->volumetric_scat_fb);
 +      DRW_FRAMEBUFFER_FREE_SAFE(fbl->volumetric_integ_fb);
 +
 +      return 0;
 +}
 +
 +void EEVEE_volumes_cache_init(EEVEE_ViewLayerData *sldata, EEVEE_Data *vedata)
 +{
 +      EEVEE_PassList *psl = vedata->psl;
 +      EEVEE_StorageList *stl = vedata->stl;
 +      EEVEE_TextureList *txl = vedata->txl;
 +      EEVEE_EffectsInfo *effects = stl->effects;
 +      EEVEE_CommonUniformBuffer *common_data = &sldata->common_data;
 +
 +      if ((effects->enabled_effects & EFFECT_VOLUMETRIC) != 0) {
 +              const DRWContextState *draw_ctx = DRW_context_state_get();
 +              Scene *scene = draw_ctx->scene;
 +              DRWShadingGroup *grp;
 +
 +              /* Quick breakdown of the Volumetric rendering:
 +               *
 +               * The rendering is separated in 4 stages:
 +               *
 +               * - Material Parameters : we collect volume properties of
 +               *   all participating media in the scene and store them in
 +               *   a 3D texture aligned with the 3D frustum.
 +               *   This is done in 2 passes, one that clear the texture
 +               *   and/or evaluate the world volumes, and the 2nd one that
 +               *   additively render object volumes.
 +               *
 +               * - Light Scattering : the volume properties then are sampled
 +               *   and light scattering is evaluated for each cell of the
 +               *   volume texture. Temporal supersampling (if enabled) occurs here.
 +               *
 +               * - Volume Integration : the scattered light and extinction is
 +               *   integrated (accumulated) along the viewrays. The result is stored
 +               *   for every cell in another texture.
 +               *
 +               * - Fullscreen Resolve : From the previous stage, we get two
 +               *   3D textures that contains integrated scatered light and extinction
 +               *   for "every" positions in the frustum. We only need to sample
 +               *   them and blend the scene color with thoses factors. This also
 +               *   work for alpha blended materials.
 +               **/
 +
 +              /* World pass is not additive as it also clear the buffer. */
 +              psl->volumetric_world_ps = DRW_pass_create("Volumetric World", DRW_STATE_WRITE_COLOR);
 +
 +              /* World Volumetric */
 +              struct World *wo = scene->world;
 +              if (wo != NULL && wo->use_nodes && wo->nodetree) {
 +                      struct GPUMaterial *mat = EEVEE_material_world_volume_get(scene, wo);
 +
 +                      grp = DRW_shgroup_material_empty_tri_batch_create(mat,
 +                                                                        psl->volumetric_world_ps,
 +                                                                        common_data->vol_tex_size[2]);
 +
 +                      if (grp) {
 +                              DRW_shgroup_uniform_block(grp, "common_block", sldata->common_ubo);
 +                      }
 +              }
 +              else {
 +                      /* If no world or volume material is present just clear the buffer with this drawcall */
 +                      grp = DRW_shgroup_empty_tri_batch_create(e_data.volumetric_clear_sh,
 +                                                                   psl->volumetric_world_ps,
 +                                                                   common_data->vol_tex_size[2]);
 +
 +                      DRW_shgroup_uniform_block(grp, "common_block", sldata->common_ubo);
 +              }
 +
 +              /* Volumetric Objects */
 +              psl->volumetric_objects_ps = DRW_pass_create("Volumetric Properties", DRW_STATE_WRITE_COLOR |
 +                                                                                    DRW_STATE_ADDITIVE);
 +
 +              struct GPUShader *scatter_sh = (common_data->vol_use_lights) ? e_data.volumetric_scatter_with_lamps_sh
 +                                                                    : e_data.volumetric_scatter_sh;
 +              psl->volumetric_scatter_ps = DRW_pass_create("Volumetric Scattering", DRW_STATE_WRITE_COLOR);
 +              grp = DRW_shgroup_empty_tri_batch_create(scatter_sh, psl->volumetric_scatter_ps,
 +                                                       common_data->vol_tex_size[2]);
 +              DRW_shgroup_uniform_buffer(grp, "irradianceGrid", &sldata->irradiance_pool);
 +              DRW_shgroup_uniform_buffer(grp, "shadowTexture", &sldata->shadow_pool);
 +              DRW_shgroup_uniform_buffer(grp, "volumeScattering", &txl->volume_prop_scattering);
 +              DRW_shgroup_uniform_buffer(grp, "volumeExtinction", &txl->volume_prop_extinction);
 +              DRW_shgroup_uniform_buffer(grp, "volumeEmission", &txl->volume_prop_emission);
 +              DRW_shgroup_uniform_buffer(grp, "volumePhase", &txl->volume_prop_phase);
 +              DRW_shgroup_uniform_buffer(grp, "historyScattering", &txl->volume_scatter_history);
 +              DRW_shgroup_uniform_buffer(grp, "historyTransmittance", &txl->volume_transmittance_history);
 +              DRW_shgroup_uniform_block(grp, "light_block", sldata->light_ubo);
 +              DRW_shgroup_uniform_block(grp, "shadow_block", sldata->shadow_ubo);
 +              DRW_shgroup_uniform_block(grp, "common_block", sldata->common_ubo);
 +
 +              psl->volumetric_integration_ps = DRW_pass_create("Volumetric Integration", DRW_STATE_WRITE_COLOR);
 +              grp = DRW_shgroup_empty_tri_batch_create(e_data.volumetric_integration_sh,
 +                                                       psl->volumetric_integration_ps,
 +                                                       common_data->vol_tex_size[2]);
 +              DRW_shgroup_uniform_buffer(grp, "volumeScattering", &txl->volume_scatter);
 +              DRW_shgroup_uniform_buffer(grp, "volumeExtinction", &txl->volume_transmittance);
 +              DRW_shgroup_uniform_block(grp, "common_block", sldata->common_ubo);
 +
 +              psl->volumetric_resolve_ps = DRW_pass_create("Volumetric Resolve", DRW_STATE_WRITE_COLOR);
 +              grp = DRW_shgroup_create(e_data.volumetric_resolve_sh, psl->volumetric_resolve_ps);
 +              DRW_shgroup_uniform_buffer(grp, "inScattering", &txl->volume_scatter);
 +              DRW_shgroup_uniform_buffer(grp, "inTransmittance", &txl->volume_transmittance);
 +              DRW_shgroup_uniform_buffer(grp, "inSceneColor", &e_data.color_src);
 +              DRW_shgroup_uniform_buffer(grp, "inSceneDepth", &e_data.depth_src);
 +              DRW_shgroup_uniform_block(grp, "common_block", sldata->common_ubo);
 +              DRW_shgroup_call_add(grp, DRW_cache_fullscreen_quad_get(), NULL);
 +      }
 +}
 +
 +void EEVEE_volumes_cache_object_add(EEVEE_ViewLayerData *sldata, EEVEE_Data *vedata, Scene *scene, Object *ob)
 +{
 +      float *texcoloc = NULL;
 +      float *texcosize = NULL;
 +      struct ModifierData *md = NULL;
 +      Material *ma = give_current_material(ob, 1);
 +
 +      if (ma == NULL) {
 +              return;
 +      }
 +
 +      struct GPUMaterial *mat = EEVEE_material_mesh_volume_get(scene, ma);
 +
 +      DRWShadingGroup *grp = DRW_shgroup_material_empty_tri_batch_create(mat, vedata->psl->volumetric_objects_ps, sldata->common_data.vol_tex_size[2]);
 +
 +      /* Making sure it's updated. */
 +      invert_m4_m4(ob->imat, ob->obmat);
 +
 +      BKE_mesh_texspace_get_reference((struct Mesh *)ob->data, NULL, &texcoloc, NULL, &texcosize);
 +
 +      if (grp) {
 +              DRW_shgroup_uniform_block(grp, "common_block", sldata->common_ubo);
 +              DRW_shgroup_uniform_mat4(grp, "volumeObjectMatrix", (float *)ob->imat);
 +              DRW_shgroup_uniform_vec3(grp, "volumeOrcoLoc", texcoloc, 1);
 +              DRW_shgroup_uniform_vec3(grp, "volumeOrcoSize", texcosize, 1);
 +      }
 +
 +      /* Smoke Simulation */
 +      if (((ob->base_flag & BASE_FROMDUPLI) == 0) &&
 +          (md = modifiers_findByType(ob, eModifierType_Smoke)) &&
 +          (modifier_isEnabled(scene, md, eModifierMode_Realtime)))
 +      {
 +              SmokeModifierData *smd = (SmokeModifierData *)md;
 +              SmokeDomainSettings *sds = smd->domain;
 +              /* Don't show smoke before simulation starts, this could be made an option in the future. */
 +              const bool show_smoke = (CFRA >= sds->point_cache[0]->startframe);
 +
 +              if (sds->fluid && show_smoke) {
 +                      if (!sds->wt || !(sds->viewsettings & MOD_SMOKE_VIEW_SHOWBIG)) {
 +                              GPU_create_smoke(smd, 0);
 +                      }
 +                      else if (sds->wt && (sds->viewsettings & MOD_SMOKE_VIEW_SHOWBIG)) {
 +                              GPU_create_smoke(smd, 1);
 +                      }
 +                      BLI_addtail(&e_data.smoke_domains, BLI_genericNodeN(smd));
 +              }
 +
 +              if (sds->tex != NULL) {
 +                      DRW_shgroup_uniform_buffer(grp, "sampdensity", &sds->tex);
 +              }
 +              if (sds->tex_flame != NULL) {
 +                      DRW_shgroup_uniform_buffer(grp, "sampflame", &sds->tex_flame);
 +              }
 +      }
 +}
 +
 +void EEVEE_volumes_compute(EEVEE_ViewLayerData *UNUSED(sldata), EEVEE_Data *vedata)
 +{
 +      EEVEE_PassList *psl = vedata->psl;
 +      EEVEE_TextureList *txl = vedata->txl;
 +      EEVEE_FramebufferList *fbl = vedata->fbl;
 +      EEVEE_StorageList *stl = vedata->stl;
 +      EEVEE_EffectsInfo *effects = stl->effects;
 +      if ((effects->enabled_effects & EFFECT_VOLUMETRIC) != 0) {
 +              DRW_stats_group_start("Volumetrics");
 +
 +              /* Step 1: Participating Media Properties */
 +              DRW_framebuffer_bind(fbl->volumetric_fb);
 +              DRW_draw_pass(psl->volumetric_world_ps);
 +              DRW_draw_pass(psl->volumetric_objects_ps);
 +
 +              /* Step 2: Scatter Light */
 +              DRW_framebuffer_bind(fbl->volumetric_scat_fb);
 +              DRW_draw_pass(psl->volumetric_scatter_ps);
 +
 +              /* Step 3: Integration */
 +              DRW_framebuffer_bind(fbl->volumetric_integ_fb);
 +              DRW_draw_pass(psl->volumetric_integration_ps);
 +
 +              /* Swap volume history buffers */
 +              SWAP(struct GPUFrameBuffer *, fbl->volumetric_scat_fb, fbl->volumetric_integ_fb);
 +              SWAP(GPUTexture *, txl->volume_scatter, txl->volume_scatter_history);
 +              SWAP(GPUTexture *, txl->volume_transmittance, txl->volume_transmittance_history);
 +
 +              /* Restore */
 +              DRW_framebuffer_bind(fbl->main);
 +
 +              DRW_stats_group_end();
 +      }
 +}
 +
 +void EEVEE_volumes_resolve(EEVEE_ViewLayerData *UNUSED(sldata), EEVEE_Data *vedata)
 +{
 +      EEVEE_PassList *psl = vedata->psl;
 +      EEVEE_TextureList *txl = vedata->txl;
 +      EEVEE_FramebufferList *fbl = vedata->fbl;
 +      EEVEE_StorageList *stl = vedata->stl;
 +      EEVEE_EffectsInfo *effects = stl->effects;
 +
 +      if ((effects->enabled_effects & EFFECT_VOLUMETRIC) != 0) {
 +              DefaultTextureList *dtxl = DRW_viewport_texture_list_get();
 +
 +              e_data.color_src = txl->color;
 +              e_data.depth_src = dtxl->depth;
 +
 +              /* Step 4: Apply for opaque */
 +              DRW_framebuffer_bind(fbl->effect_fb);
 +              DRW_draw_pass(psl->volumetric_resolve_ps);
 +
 +              /* Swap the buffers and rebind depth to the current buffer */
 +              DRW_framebuffer_texture_detach(dtxl->depth);
 +              SWAP(struct GPUFrameBuffer *, fbl->main, fbl->effect_fb);
 +              SWAP(GPUTexture *, txl->color, txl->color_post);
 +              DRW_framebuffer_texture_attach(fbl->main, dtxl->depth, 0, 0);
 +      }
 +}
 +
 +void EEVEE_volumes_free_smoke_textures(void)
 +{
 +      /* Free Smoke Textures after rendering */
 +      for (LinkData *link = e_data.smoke_domains.first; link; link = link->next) {
 +              SmokeModifierData *smd = (SmokeModifierData *)link->data;
 +              GPU_free_smoke(smd);
 +      }
 +      BLI_freelistN(&e_data.smoke_domains);
 +}
 +
 +void EEVEE_volumes_free(void)
 +{
 +      MEM_SAFE_FREE(e_data.volumetric_common_lib);
 +      MEM_SAFE_FREE(e_data.volumetric_common_lamps_lib);
 +
 +      DRW_SHADER_FREE_SAFE(e_data.volumetric_clear_sh);
 +      DRW_SHADER_FREE_SAFE(e_data.volumetric_scatter_sh);
 +      DRW_SHADER_FREE_SAFE(e_data.volumetric_scatter_with_lamps_sh);
 +      DRW_SHADER_FREE_SAFE(e_data.volumetric_integration_sh);
 +      DRW_SHADER_FREE_SAFE(e_data.volumetric_resolve_sh);
 +}
index b1e0eddfc467b0fae7a80d7abc20fc13913e0d97,0000000000000000000000000000000000000000..e807be34633789531bfd36d26ffbb5fe187c2726
mode 100644,000000..100644
--- /dev/null
@@@ -1,2050 -1,0 +1,2050 @@@
- #include "DNA_object_force.h"
 +/*
 + * Copyright 2016, Blender Foundation.
 + *
 + * This program is free software; you can redistribute it and/or
 + * modify it under the terms of the GNU General Public License
 + * as published by the Free Software Foundation; either version 2
 + * of the License, or (at your option) any later version.
 + *
 + * This program is distributed in the hope that it will be useful,
 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 + * GNU General Public License for more details.
 + *
 + * You should have received a copy of the GNU General Public License
 + * along with this program; if not, write to the Free Software Foundation,
 + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 + *
 + * Contributor(s): Blender Institute
 + *
 + */
 +
 +/** \file blender/draw/modes/object_mode.c
 + *  \ingroup draw
 + */
 +
 +#include "DRW_engine.h"
 +#include "DRW_render.h"
 +
 +#include "DNA_userdef_types.h"
 +#include "DNA_armature_types.h"
 +#include "DNA_camera_types.h"
 +#include "DNA_curve_types.h"
 +#include "DNA_mesh_types.h"
 +#include "DNA_meta_types.h"
++#include "DNA_object_force_types.h"
 +#include "DNA_lightprobe_types.h"
 +#include "DNA_particle_types.h"
 +#include "DNA_view3d_types.h"
 +#include "DNA_world_types.h"
 +
 +#include "BIF_gl.h"
 +
 +#include "BKE_anim.h"
 +#include "BKE_camera.h"
 +#include "BKE_curve.h"
 +#include "BKE_global.h"
 +#include "BKE_mball.h"
 +#include "BKE_object.h"
 +#include "BKE_particle.h"
 +#include "BKE_image.h"
 +#include "BKE_texture.h"
 +
 +#include "ED_view3d.h"
 +
 +#include "GPU_shader.h"
 +#include "GPU_texture.h"
 +
 +#include "UI_resources.h"
 +
 +#include "draw_mode_engines.h"
 +#include "draw_manager_text.h"
 +#include "draw_common.h"
 +
 +#include "DEG_depsgraph_query.h"
 +
 +extern struct GPUUniformBuffer *globals_ubo; /* draw_common.c */
 +extern struct GPUTexture *globals_ramp; /* draw_common.c */
 +extern GlobalsUboStorage ts;
 +
 +extern char datatoc_object_outline_resolve_frag_glsl[];
 +extern char datatoc_object_outline_detect_frag_glsl[];
 +extern char datatoc_object_outline_expand_frag_glsl[];
 +extern char datatoc_object_grid_frag_glsl[];
 +extern char datatoc_object_grid_vert_glsl[];
 +extern char datatoc_object_empty_image_frag_glsl[];
 +extern char datatoc_object_empty_image_vert_glsl[];
 +extern char datatoc_object_lightprobe_grid_vert_glsl[];
 +extern char datatoc_object_particle_prim_vert_glsl[];
 +extern char datatoc_object_particle_dot_vert_glsl[];
 +extern char datatoc_object_particle_dot_frag_glsl[];
 +extern char datatoc_common_globals_lib_glsl[];
 +extern char datatoc_common_fxaa_lib_glsl[];
 +extern char datatoc_gpu_shader_flat_color_frag_glsl[];
 +extern char datatoc_gpu_shader_fullscreen_vert_glsl[];
 +extern char datatoc_gpu_shader_uniform_color_frag_glsl[];
 +
 +/* *********** LISTS *********** */
 +typedef struct OBJECT_PassList {
 +      struct DRWPass *non_meshes;
 +      struct DRWPass *ob_center;
 +      struct DRWPass *outlines;
 +      struct DRWPass *outlines_search;
 +      struct DRWPass *outlines_expand;
 +      struct DRWPass *outlines_bleed;
 +      struct DRWPass *outlines_resolve;
 +      struct DRWPass *grid;
 +      struct DRWPass *bone_solid;
 +      struct DRWPass *bone_wire;
 +      struct DRWPass *bone_envelope;
 +      struct DRWPass *particle;
 +      struct DRWPass *lightprobes;
 +      /* use for empty/background images */
 +      struct DRWPass *reference_image;
 +} OBJECT_PassList;
 +
 +typedef struct OBJECT_FramebufferList {
 +      struct GPUFrameBuffer *outlines;
 +      struct GPUFrameBuffer *blur;
 +} OBJECT_FramebufferList;
 +
 +typedef struct OBJECT_StorageList {
 +      struct OBJECT_PrivateData *g_data;
 +} OBJECT_StorageList;
 +
 +typedef struct OBJECT_Data {
 +      void *engine_type;
 +      OBJECT_FramebufferList *fbl;
 +      DRWViewportEmptyList *txl;
 +      OBJECT_PassList *psl;
 +      OBJECT_StorageList *stl;
 +} OBJECT_Data;
 +
 +/* *********** STATIC *********** */
 +
 +typedef struct OBJECT_PrivateData {
 +      /* Empties */
 +      DRWShadingGroup *plain_axes;
 +      DRWShadingGroup *cube;
 +      DRWShadingGroup *circle;
 +      DRWShadingGroup *sphere;
 +      DRWShadingGroup *cone;
 +      DRWShadingGroup *single_arrow;
 +      DRWShadingGroup *single_arrow_line;
 +      DRWShadingGroup *arrows;
 +      DRWShadingGroup *axis_names;
 +      /* GPUTexture -> EmptyImageShadingGroupData */
 +      GHash *image_plane_map;
 +
 +      /* Force Field */
 +      DRWShadingGroup *field_wind;
 +      DRWShadingGroup *field_force;
 +      DRWShadingGroup *field_vortex;
 +      DRWShadingGroup *field_curve_sta;
 +      DRWShadingGroup *field_curve_end;
 +      DRWShadingGroup *field_tube_limit;
 +      DRWShadingGroup *field_cone_limit;
 +
 +      /* Speaker */
 +      DRWShadingGroup *speaker;
 +
 +      /* Probe */
 +      DRWShadingGroup *probe_cube;
 +      DRWShadingGroup *probe_planar;
 +      DRWShadingGroup *probe_grid;
 +
 +      /* MetaBalls */
 +      DRWShadingGroup *mball_circle;
 +
 +      /* Lamps */
 +      DRWShadingGroup *lamp_center;
 +      DRWShadingGroup *lamp_center_group;
 +      DRWShadingGroup *lamp_groundpoint;
 +      DRWShadingGroup *lamp_groundline;
 +      DRWShadingGroup *lamp_circle;
 +      DRWShadingGroup *lamp_circle_shadow;
 +      DRWShadingGroup *lamp_sunrays;
 +      DRWShadingGroup *lamp_distance;
 +      DRWShadingGroup *lamp_buflimit;
 +      DRWShadingGroup *lamp_buflimit_points;
 +      DRWShadingGroup *lamp_area;
 +      DRWShadingGroup *lamp_hemi;
 +      DRWShadingGroup *lamp_spot_cone;
 +      DRWShadingGroup *lamp_spot_blend;
 +      DRWShadingGroup *lamp_spot_pyramid;
 +      DRWShadingGroup *lamp_spot_blend_rect;
 +
 +      /* Helpers */
 +      DRWShadingGroup *relationship_lines;
 +
 +      /* Objects Centers */
 +      DRWShadingGroup *center_active;
 +      DRWShadingGroup *center_selected;
 +      DRWShadingGroup *center_deselected;
 +      DRWShadingGroup *center_selected_lib;
 +      DRWShadingGroup *center_deselected_lib;
 +
 +      /* Camera */
 +      DRWShadingGroup *camera;
 +      DRWShadingGroup *camera_frame;
 +      DRWShadingGroup *camera_tria;
 +      DRWShadingGroup *camera_focus;
 +      DRWShadingGroup *camera_clip;
 +      DRWShadingGroup *camera_clip_points;
 +      DRWShadingGroup *camera_mist;
 +      DRWShadingGroup *camera_mist_points;
 +
 +      /* Outlines */
 +      DRWShadingGroup *outlines_active;
 +      DRWShadingGroup *outlines_active_group;
 +      DRWShadingGroup *outlines_select;
 +      DRWShadingGroup *outlines_select_group;
 +      DRWShadingGroup *outlines_transform;
 +
 +      /* Lightprobes */
 +      DRWShadingGroup *lightprobes_cube;
 +      DRWShadingGroup *lightprobes_planar;
 +
 +      /* Wire */
 +      DRWShadingGroup *wire;
 +      DRWShadingGroup *wire_active;
 +      DRWShadingGroup *wire_active_group;
 +      DRWShadingGroup *wire_select;
 +      DRWShadingGroup *wire_select_group;
 +      DRWShadingGroup *wire_transform;
 +} OBJECT_PrivateData; /* Transient data */
 +
 +static struct {
 +      /* fullscreen shaders */
 +      GPUShader *outline_resolve_sh;
 +      GPUShader *outline_resolve_aa_sh;
 +      GPUShader *outline_detect_sh;
 +      GPUShader *outline_fade_sh;
 +
 +      /* regular shaders */
 +      GPUShader *object_empty_image_sh;
 +      GPUShader *object_empty_image_wire_sh;
 +      GPUShader *grid_sh;
 +      GPUShader *part_dot_sh;
 +      GPUShader *part_prim_sh;
 +      GPUShader *part_axis_sh;
 +      GPUShader *lightprobe_grid_sh;
 +      float camera_pos[3];
 +      float screenvecs[3][4];
 +      float grid_settings[5];
 +      int grid_flag;
 +      float grid_normal[3];
 +      float grid_axes[3];
 +      int zpos_flag;
 +      int zneg_flag;
 +      float zplane_normal[3];
 +      float zplane_axes[3];
 +      float inv_viewport_size[2];
 +      bool draw_grid;
 +      /* Temp buffer textures */
 +      struct GPUTexture *outlines_depth_tx;
 +      struct GPUTexture *outlines_color_tx;
 +      struct GPUTexture *outlines_blur_tx;
 +} e_data = {NULL}; /* Engine data */
 +
 +
 +enum {
 +      SHOW_AXIS_X  = (1 << 0),
 +      SHOW_AXIS_Y  = (1 << 1),
 +      SHOW_AXIS_Z  = (1 << 2),
 +      SHOW_GRID    = (1 << 3),
 +      PLANE_XY     = (1 << 4),
 +      PLANE_XZ     = (1 << 5),
 +      PLANE_YZ     = (1 << 6),
 +      CLIP_ZPOS    = (1 << 7),
 +      CLIP_ZNEG    = (1 << 8),
 +};
 +
 +/* *********** FUNCTIONS *********** */
 +
 +static void OBJECT_engine_init(void *vedata)
 +{
 +      OBJECT_FramebufferList *fbl = ((OBJECT_Data *)vedata)->fbl;
 +
 +      const float *viewport_size = DRW_viewport_size_get();
 +
 +      if (DRW_state_is_fbo()) {
 +              DRWFboTexture tex[2] = {
 +                      {&e_data.outlines_depth_tx, DRW_TEX_DEPTH_24, DRW_TEX_TEMP},
 +                      {&e_data.outlines_color_tx, DRW_TEX_RGBA_8, DRW_TEX_FILTER | DRW_TEX_TEMP},
 +              };
 +
 +              DRW_framebuffer_init(
 +                      &fbl->outlines, &draw_engine_object_type,
 +                      (int)viewport_size[0], (int)viewport_size[1],
 +                      tex, 2);
 +
 +              DRWFboTexture blur_tex = {&e_data.outlines_blur_tx, DRW_TEX_RGBA_8, DRW_TEX_FILTER | DRW_TEX_TEMP};
 +              DRW_framebuffer_init(
 +                      &fbl->blur, &draw_engine_object_type,
 +                      (int)viewport_size[0], (int)viewport_size[1],
 +                      &blur_tex, 1);
 +      }
 +
 +      if (!e_data.outline_resolve_sh) {
 +              e_data.outline_resolve_sh = DRW_shader_create_fullscreen(datatoc_object_outline_resolve_frag_glsl, NULL);
 +      }
 +
 +      if (!e_data.outline_resolve_aa_sh) {
 +              e_data.outline_resolve_aa_sh = DRW_shader_create_with_lib(
 +                          datatoc_gpu_shader_fullscreen_vert_glsl, NULL,
 +                          datatoc_object_outline_resolve_frag_glsl,
 +                          datatoc_common_fxaa_lib_glsl,
 +                          "#define FXAA_ALPHA\n"
 +                          "#define USE_FXAA\n");
 +      }
 +
 +      if (!e_data.outline_detect_sh) {
 +              e_data.outline_detect_sh = DRW_shader_create_fullscreen(datatoc_object_outline_detect_frag_glsl, NULL);
 +      }
 +
 +      if (!e_data.outline_fade_sh) {
 +              e_data.outline_fade_sh = DRW_shader_create_fullscreen(datatoc_object_outline_expand_frag_glsl, NULL);
 +      }
 +
 +      if (!e_data.object_empty_image_sh) {
 +              e_data.object_empty_image_sh = DRW_shader_create_with_lib(
 +                         datatoc_object_empty_image_vert_glsl, NULL,
 +                         datatoc_object_empty_image_frag_glsl,
 +                         datatoc_common_globals_lib_glsl, NULL);
 +      }
 +
 +      if (!e_data.object_empty_image_wire_sh) {
 +              e_data.object_empty_image_wire_sh = DRW_shader_create_with_lib(
 +                         datatoc_object_empty_image_vert_glsl, NULL,
 +                         datatoc_object_empty_image_frag_glsl,
 +                         datatoc_common_globals_lib_glsl,
 +                         "#define USE_WIRE\n");
 +      }
 +
 +      if (!e_data.grid_sh) {
 +              e_data.grid_sh = DRW_shader_create_with_lib(
 +                      datatoc_object_grid_vert_glsl, NULL,
 +                      datatoc_object_grid_frag_glsl,
 +                      datatoc_common_globals_lib_glsl, NULL);
 +      }
 +
 +      if (!e_data.part_prim_sh) {
 +              e_data.part_prim_sh = DRW_shader_create(
 +                      datatoc_object_particle_prim_vert_glsl, NULL, datatoc_gpu_shader_flat_color_frag_glsl, NULL);
 +      }
 +
 +      if (!e_data.part_axis_sh) {
 +              e_data.part_axis_sh = DRW_shader_create(
 +                      datatoc_object_particle_prim_vert_glsl, NULL, datatoc_gpu_shader_flat_color_frag_glsl,
 +                      "#define USE_AXIS\n");
 +      }
 +
 +      if (!e_data.part_dot_sh) {
 +              e_data.part_dot_sh = DRW_shader_create(
 +                      datatoc_object_particle_dot_vert_glsl, NULL, datatoc_object_particle_dot_frag_glsl, NULL);
 +      }
 +
 +      if (!e_data.lightprobe_grid_sh) {
 +              e_data.lightprobe_grid_sh = DRW_shader_create(
 +                      datatoc_object_lightprobe_grid_vert_glsl, NULL, datatoc_gpu_shader_uniform_color_frag_glsl, NULL);
 +      }
 +
 +      {
 +              /* Grid precompute */
 +              float invviewmat[4][4], invwinmat[4][4];
 +              float viewmat[4][4], winmat[4][4];
 +              const DRWContextState *draw_ctx = DRW_context_state_get();
 +              View3D *v3d = draw_ctx->v3d;
 +              Scene *scene = draw_ctx->scene;
 +              RegionView3D *rv3d = draw_ctx->rv3d;
 +              float grid_scale = ED_view3d_grid_scale(scene, v3d, NULL);
 +              float grid_res;
 +
 +              const bool show_axis_x = (v3d->gridflag & V3D_SHOW_X) != 0;
 +              const bool show_axis_y = (v3d->gridflag & V3D_SHOW_Y) != 0;
 +              const bool show_axis_z = (v3d->gridflag & V3D_SHOW_Z) != 0;
 +              const bool show_floor = (v3d->gridflag & V3D_SHOW_FLOOR) != 0;
 +              e_data.draw_grid = show_axis_x || show_axis_y || show_axis_z || show_floor;
 +
 +              DRW_viewport_matrix_get(winmat, DRW_MAT_WIN);
 +              DRW_viewport_matrix_get(viewmat, DRW_MAT_VIEW);
 +              DRW_viewport_matrix_get(invwinmat, DRW_MAT_WININV);
 +              DRW_viewport_matrix_get(invviewmat, DRW_MAT_VIEWINV);
 +
 +              /* Setup camera pos */
 +              copy_v3_v3(e_data.camera_pos, invviewmat[3]);
 +
 +              /* if perps */
 +              if (winmat[3][3] == 0.0f) {
 +                      float fov;
 +                      float viewvecs[2][4] = {
 +                          {1.0f, -1.0f, -1.0f, 1.0f},
 +                          {-1.0f, 1.0f, -1.0f, 1.0f}
 +                      };
 +
 +                      /* convert the view vectors to view space */
 +                      for (int i = 0; i < 2; i++) {
 +                              mul_m4_v4(invwinmat, viewvecs[i]);
 +                              mul_v3_fl(viewvecs[i], 1.0f / viewvecs[i][2]); /* perspective divide */
 +                      }
 +
 +                      fov = angle_v3v3(viewvecs[0], viewvecs[1]) / 2.0f;
 +                      grid_res = fabsf(tanf(fov)) / grid_scale;
 +
 +                      e_data.grid_flag = (1 << 4); /* XY plane */
 +                      if (show_axis_x)
 +                              e_data.grid_flag |= SHOW_AXIS_X;
 +                      if (show_axis_y)
 +                              e_data.grid_flag |= SHOW_AXIS_Y;
 +                      if (show_floor)
 +                              e_data.grid_flag |= SHOW_GRID;
 +
 +              }
 +              else {
 +                      float viewdist = 1.0f / max_ff(fabsf(winmat[0][0]), fabsf(winmat[1][1]));
 +                      grid_res = viewdist / grid_scale;
 +
 +                      if (ELEM(rv3d->view, RV3D_VIEW_RIGHT, RV3D_VIEW_LEFT)) {
 +                              e_data.grid_flag = PLANE_YZ;
 +                              e_data.grid_flag |= SHOW_AXIS_Y;
 +                              e_data.grid_flag |= SHOW_AXIS_Z;
 +                              e_data.grid_flag |= SHOW_GRID;
 +                      }
 +                      else if (ELEM(rv3d->view, RV3D_VIEW_TOP, RV3D_VIEW_BOTTOM)) {
 +                              e_data.grid_flag = PLANE_XY;
 +                              e_data.grid_flag |= SHOW_AXIS_X;
 +                              e_data.grid_flag |= SHOW_AXIS_Y;
 +                              e_data.grid_flag |= SHOW_GRID;
 +                      }
 +                      else if (ELEM(rv3d->view, RV3D_VIEW_FRONT, RV3D_VIEW_BACK)) {
 +                              e_data.grid_flag = PLANE_XZ;
 +                              e_data.grid_flag |= SHOW_AXIS_X;
 +                              e_data.grid_flag |= SHOW_AXIS_Z;
 +                              e_data.grid_flag |= SHOW_GRID;
 +                      }
 +                      else { /* RV3D_VIEW_USER */
 +                              e_data.grid_flag = PLANE_XY;
 +                              if (show_axis_x)
 +                                      e_data.grid_flag |= SHOW_AXIS_X;
 +                              if (show_axis_y)
 +                                      e_data.grid_flag |= SHOW_AXIS_Y;
 +                              if (show_floor)
 +                                      e_data.grid_flag |= SHOW_GRID;
 +                      }
 +              }
 +
 +              e_data.grid_normal[0] = (float)((e_data.grid_flag & PLANE_YZ) != 0);
 +              e_data.grid_normal[1] = (float)((e_data.grid_flag & PLANE_XZ) != 0);
 +              e_data.grid_normal[2] = (float)((e_data.grid_flag & PLANE_XY) != 0);
 +
 +              e_data.grid_axes[0] = (float)((e_data.grid_flag & (PLANE_XZ | PLANE_XY)) != 0);
 +              e_data.grid_axes[1] = (float)((e_data.grid_flag & (PLANE_YZ | PLANE_XY)) != 0);
 +              e_data.grid_axes[2] = (float)((e_data.grid_flag & (PLANE_YZ | PLANE_XZ)) != 0);
 +
 +              /* Vectors to recover pixel world position. Fix grid precision issue. */
 +              /* Using pixel at z = 0.0f in ndc space : gives average precision between
 +               * near and far plane. Note that it might not be the best choice. */
 +              copy_v4_fl4(e_data.screenvecs[0],  1.0f, -1.0f, 0.0f, 1.0f);
 +              copy_v4_fl4(e_data.screenvecs[1], -1.0f,  1.0f, 0.0f, 1.0f);
 +              copy_v4_fl4(e_data.screenvecs[2], -1.0f, -1.0f, 0.0f, 1.0f);
 +
 +              for (int i = 0; i < 3; i++) {
 +                      /* Doing 2 steps to recover world position of the corners of the frustum.
 +                       * Using the inverse perspective matrix is giving very low precision output. */
 +                      mul_m4_v4(invwinmat, e_data.screenvecs[i]);
 +                      e_data.screenvecs[i][0] /= e_data.screenvecs[i][3]; /* perspective divide */
 +                      e_data.screenvecs[i][1] /= e_data.screenvecs[i][3]; /* perspective divide */
 +                      e_data.screenvecs[i][2] /= e_data.screenvecs[i][3]; /* perspective divide */
 +                      e_data.screenvecs[i][3] = 1.0f;
 +                      /* main instability come from this one */
 +                      /* TODO : to make things even more stable, don't use
 +                       * invviewmat and derive vectors from camera properties */
 +                      mul_m4_v4(invviewmat, e_data.screenvecs[i]);
 +              }
 +
 +              sub_v3_v3(e_data.screenvecs[0], e_data.screenvecs[2]);
 +              sub_v3_v3(e_data.screenvecs[1], e_data.screenvecs[2]);
 +
 +              /* Z axis if needed */
 +              if (((rv3d->view == RV3D_VIEW_USER) || (rv3d->persp != RV3D_ORTHO)) && show_axis_z) {
 +                      e_data.zpos_flag = SHOW_AXIS_Z;
 +
 +                      float zvec[4] = {0.0f, 0.0f, -1.0f, 0.0f};
 +                      mul_m4_v4(invviewmat, zvec);
 +
 +                      /* z axis : chose the most facing plane */
 +                      if (fabsf(zvec[0]) < fabsf(zvec[1])) {
 +                              e_data.zpos_flag |= PLANE_XZ;
 +                      }
 +                      else {
 +                              e_data.zpos_flag |= PLANE_YZ;
 +                      }
 +
 +                      e_data.zneg_flag = e_data.zpos_flag;
 +
 +                      /* Persp : If camera is below floor plane, we switch clipping
 +                       * Ortho : If eye vector is looking up, we switch clipping */
 +                      if (((winmat[3][3] == 0.0f) && (e_data.camera_pos[2] > 0.0f)) ||
 +                          ((winmat[3][3] != 0.0f) && (zvec[2] < 0.0f)))
 +                      {
 +                              e_data.zpos_flag |= CLIP_ZPOS;
 +                              e_data.zneg_flag |= CLIP_ZNEG;
 +                      }
 +                      else {
 +                              e_data.zpos_flag |= CLIP_ZNEG;
 +                              e_data.zneg_flag |= CLIP_ZPOS;
 +                      }
 +
 +                      e_data.zplane_normal[0] = (float)((e_data.zpos_flag & PLANE_YZ) != 0);
 +                      e_data.zplane_normal[1] = (float)((e_data.zpos_flag & PLANE_XZ) != 0);
 +                      e_data.zplane_normal[2] = (float)((e_data.zpos_flag & PLANE_XY) != 0);
 +
 +                      e_data.zplane_axes[0] = (float)((e_data.zpos_flag & (PLANE_XZ | PLANE_XY)) != 0);
 +                      e_data.zplane_axes[1] = (float)((e_data.zpos_flag & (PLANE_YZ | PLANE_XY)) != 0);
 +                      e_data.zplane_axes[2] = (float)((e_data.zpos_flag & (PLANE_YZ | PLANE_XZ)) != 0);
 +
 +              }
 +              else {
 +                      e_data.zneg_flag = e_data.zpos_flag = CLIP_ZNEG | CLIP_ZPOS;
 +              }
 +
 +              float dist;
 +              if (rv3d->persp == RV3D_CAMOB && v3d->camera) {
 +                      Object *camera_object = DEG_get_evaluated_object(draw_ctx->depsgraph, v3d->camera);
 +                      dist = ((Camera *)camera_object)->clipend;
 +              }
 +              else {
 +                      dist = v3d->far;
 +              }
 +
 +              e_data.grid_settings[0] = dist / 2.0f; /* gridDistance */
 +              e_data.grid_settings[1] = grid_res; /* gridResolution */
 +              e_data.grid_settings[2] = grid_scale; /* gridScale */
 +              e_data.grid_settings[3] = v3d->gridsubdiv; /* gridSubdiv */
 +              e_data.grid_settings[4] = (v3d->gridsubdiv > 1) ? 1.0f / logf(v3d->gridsubdiv) : 0.0f; /* 1/log(gridSubdiv) */
 +      }
 +
 +      copy_v2_v2(e_data.inv_viewport_size, DRW_viewport_size_get());
 +      invert_v2(e_data.inv_viewport_size);
 +}
 +
 +static void OBJECT_engine_free(void)
 +{
 +      DRW_SHADER_FREE_SAFE(e_data.outline_resolve_sh);
 +      DRW_SHADER_FREE_SAFE(e_data.outline_resolve_aa_sh);
 +      DRW_SHADER_FREE_SAFE(e_data.outline_detect_sh);
 +      DRW_SHADER_FREE_SAFE(e_data.outline_fade_sh);
 +      DRW_SHADER_FREE_SAFE(e_data.object_empty_image_sh);
 +      DRW_SHADER_FREE_SAFE(e_data.object_empty_image_wire_sh);
 +      DRW_SHADER_FREE_SAFE(e_data.grid_sh);
 +      DRW_SHADER_FREE_SAFE(e_data.part_prim_sh);
 +      DRW_SHADER_FREE_SAFE(e_data.part_axis_sh);
 +      DRW_SHADER_FREE_SAFE(e_data.part_dot_sh);
 +      DRW_SHADER_FREE_SAFE(e_data.lightprobe_grid_sh);
 +}
 +
 +static DRWShadingGroup *shgroup_outline(DRWPass *pass, const float col[4], GPUShader *sh)
 +{
 +      DRWShadingGroup *grp = DRW_shgroup_create(sh, pass);
 +      DRW_shgroup_uniform_vec4(grp, "color", col, 1);
 +
 +      return grp;
 +}
 +
 +/* currently same as 'shgroup_outline', new function to avoid confustion */
 +static DRWShadingGroup *shgroup_wire(DRWPass *pass, const float col[4], GPUShader *sh)
 +{
 +      DRWShadingGroup *grp = DRW_shgroup_create(sh, pass);
 +      DRW_shgroup_uniform_vec4(grp, "color", col, 1);
 +
 +      return grp;
 +}
 +
 +static DRWShadingGroup *shgroup_theme_id_to_outline_or(
 +        OBJECT_StorageList *stl, int theme_id, DRWShadingGroup *fallback)
 +{
 +      switch (theme_id) {
 +              case TH_ACTIVE:
 +                      return stl->g_data->outlines_active;
 +              case TH_SELECT:
 +                      return stl->g_data->outlines_select;
 +              case TH_GROUP_ACTIVE:
 +                      return stl->g_data->outlines_select_group;
 +              case TH_TRANSFORM:
 +                      return stl->g_data->outlines_transform;
 +              default:
 +                      return fallback;
 +      }
 +}
 +
 +static DRWShadingGroup *shgroup_theme_id_to_wire_or(
 +        OBJECT_StorageList *stl, int theme_id, DRWShadingGroup *fallback)
 +{
 +      switch (theme_id) {
 +              case TH_ACTIVE:
 +                      return stl->g_data->wire_active;
 +              case TH_SELECT:
 +                      return stl->g_data->wire_select;
 +              case TH_GROUP_ACTIVE:
 +                      return stl->g_data->wire_select_group;
 +              case TH_TRANSFORM:
 +                      return stl->g_data->wire_transform;
 +              default:
 +                      return fallback;
 +      }
 +}
 +
 +static void image_calc_aspect(Image *ima, ImageUser *iuser, float r_image_aspect[2])
 +{
 +      float ima_x, ima_y;
 +      if (ima) {
 +              int w, h;
 +              BKE_image_get_size(ima, iuser, &w, &h);
 +              ima_x = w;
 +              ima_y = h;
 +      }
 +      else {
 +              /* if no image, make it a 1x1 empty square, honor scale & offset */
 +              ima_x = ima_y = 1.0f;
 +      }
 +      /* Get the image aspect even if the buffer is invalid */
 +      float sca_x = 1.0f, sca_y = 1.0f;
 +      if (ima) {
 +              if (ima->aspx > ima->aspy) {
 +                      sca_y = ima->aspy / ima->aspx;
 +              }
 +              else if (ima->aspx < ima->aspy) {
 +                      sca_x = ima->aspx / ima->aspy;
 +              }
 +      }
 +
 +      const float scale_x_inv = ima_x * sca_x;
 +      const float scale_y_inv = ima_y * sca_y;
 +      if (scale_x_inv > scale_y_inv) {
 +              r_image_aspect[0] = 1.0f;
 +              r_image_aspect[1] = scale_y_inv / scale_x_inv;
 +      }
 +      else {
 +              r_image_aspect[0] = scale_x_inv / scale_y_inv;
 +              r_image_aspect[1] = 1.0f;
 +      }
 +}
 +
 +/* per-image shading groups for image-type empty objects */
 +struct EmptyImageShadingGroupData {
 +      DRWShadingGroup *shgrp_image;
 +      DRWShadingGroup *shgrp_wire;
 +      float image_aspect[2];
 +};
 +
 +static void DRW_shgroup_empty_image(
 +        OBJECT_StorageList *stl, OBJECT_PassList *psl, Object *ob, const float color[3])
 +{
 +      /* TODO: 'StereoViews', see draw_empty_image. */
 +
 +      if (stl->g_data->image_plane_map == NULL) {
 +              stl->g_data->image_plane_map = BLI_ghash_ptr_new(__func__);
 +      }
 +
 +      struct EmptyImageShadingGroupData *empty_image_data;
 +
 +      GPUTexture *tex = ob->data ?
 +              GPU_texture_from_blender(ob->data, ob->iuser, GL_TEXTURE_2D, false, false, false) : NULL;
 +      void **val_p;
 +
 +      /* Create on demand, 'tex' may be NULL. */
 +      if (BLI_ghash_ensure_p(stl->g_data->image_plane_map, tex, &val_p)) {
 +              empty_image_data = *val_p;
 +      }
 +      else {
 +              empty_image_data = MEM_mallocN(sizeof(*empty_image_data), __func__);
 +
 +              image_calc_aspect(ob->data, ob->iuser, empty_image_data->image_aspect);
 +
 +              if (tex) {
 +                      struct Gwn_Batch *geom = DRW_cache_image_plane_get();
 +                      DRWShadingGroup *grp = DRW_shgroup_instance_create(
 +                              e_data.object_empty_image_sh, psl->non_meshes, geom);
 +                      DRW_shgroup_attrib_float(grp, "objectColor", 4);
 +                      DRW_shgroup_attrib_float(grp, "size", 1);
 +                      DRW_shgroup_attrib_float(grp, "offset", 2);
 +                      DRW_shgroup_attrib_float(grp, "InstanceModelMatrix", 16);
 +
 +                      DRW_shgroup_uniform_texture(grp, "image", tex);
 +                      DRW_shgroup_uniform_vec2(grp, "aspect", empty_image_data->image_aspect, 1);
 +
 +                      empty_image_data->shgrp_image = grp;
 +              }
 +              else {
 +                      empty_image_data->shgrp_image = NULL;
 +              }
 +
 +              {
 +                      struct Gwn_Batch *geom = DRW_cache_image_plane_wire_get();
 +                      DRWShadingGroup *grp = DRW_shgroup_instance_create(
 +                              e_data.object_empty_image_wire_sh, psl->non_meshes, geom);
 +                      DRW_shgroup_attrib_float(grp, "color", 3);
 +                      DRW_shgroup_attrib_float(grp, "size", 1);
 +                      DRW_shgroup_attrib_float(grp, "offset", 2);
 +                      DRW_shgroup_attrib_float(grp, "InstanceModelMatrix", 16);
 +
 +                      DRW_shgroup_uniform_vec2(grp, "aspect", empty_image_data->image_aspect, 1);
 +
 +                      empty_image_data->shgrp_wire = grp;
 +              }
 +
 +              *val_p = empty_image_data;
 +      }
 +
 +      if (empty_image_data->shgrp_image != NULL) {
 +              DRW_shgroup_call_dynamic_add(
 +                      empty_image_data->shgrp_image,
 +                      ob->col,
 +                      &ob->empty_drawsize,
 +                      ob->ima_ofs,
 +                      ob->obmat);
 +      }
 +
 +      DRW_shgroup_call_dynamic_add(
 +              empty_image_data->shgrp_wire,
 +              color,
 +              &ob->empty_drawsize,
 +              ob->ima_ofs,
 +              ob->obmat);
 +}
 +
 +static void OBJECT_cache_init(void *vedata)
 +{
 +      OBJECT_PassList *psl = ((OBJECT_Data *)vedata)->psl;
 +      OBJECT_StorageList *stl = ((OBJECT_Data *)vedata)->stl;
 +      DefaultTextureList *dtxl = DRW_viewport_texture_list_get();
 +
 +      if (!stl->g_data) {
 +              /* Alloc transient pointers */
 +              stl->g_data = MEM_mallocN(sizeof(*stl->g_data), __func__);
 +      }
 +
 +      {
 +              DRWState state = DRW_STATE_WRITE_COLOR | DRW_STATE_WRITE_DEPTH | DRW_STATE_DEPTH_LESS | DRW_STATE_WIRE;
 +              psl->outlines = DRW_pass_create("Outlines Depth Pass", state);
 +
 +              GPUShader *sh = GPU_shader_get_builtin_shader(GPU_SHADER_3D_UNIFORM_COLOR);
 +
 +              /* Select */
 +              stl->g_data->outlines_select = shgroup_outline(psl->outlines, ts.colorSelect, sh);
 +              stl->g_data->outlines_select_group = shgroup_outline(psl->outlines, ts.colorGroupActive, sh);
 +
 +              /* Transform */
 +              stl->g_data->outlines_transform = shgroup_outline(psl->outlines, ts.colorTransform, sh);
 +
 +              /* Active */
 +              stl->g_data->outlines_active = shgroup_outline(psl->outlines, ts.colorActive, sh);
 +              stl->g_data->outlines_active_group = shgroup_outline(psl->outlines, ts.colorGroupActive, sh);
 +      }
 +
 +      {
 +              DRWState state = DRW_STATE_WRITE_COLOR | DRW_STATE_WRITE_DEPTH | DRW_STATE_DEPTH_LESS;
 +              psl->lightprobes = DRW_pass_create("Object Probe Pass", state);
 +
 +              /* Cubemap */
 +              stl->g_data->lightprobes_cube = shgroup_instance(psl->lightprobes, DRW_cache_sphere_get());
 +
 +              /* Planar */
 +              stl->g_data->lightprobes_planar = shgroup_instance(psl->lightprobes, DRW_cache_quad_get());
 +      }
 +
 +      {
 +              DRWState state = DRW_STATE_WRITE_COLOR;
 +              struct Gwn_Batch *quad = DRW_cache_fullscreen_quad_get();
 +              static float alphaOcclu = 0.35f;
 +              /* Reminder : bool uniforms need to be 4 bytes. */
 +              static const int bTrue = true;
 +              static const int bFalse = false;
 +
 +              psl->outlines_search = DRW_pass_create("Outlines Detect Pass", state);
 +
 +              DRWShadingGroup *grp = DRW_shgroup_create(e_data.outline_detect_sh, psl->outlines_search);
 +              DRW_shgroup_uniform_buffer(grp, "outlineColor", &e_data.outlines_color_tx);
 +              DRW_shgroup_uniform_buffer(grp, "outlineDepth", &e_data.outlines_depth_tx);
 +              DRW_shgroup_uniform_buffer(grp, "sceneDepth", &dtxl->depth);
 +              DRW_shgroup_uniform_float(grp, "alphaOcclu", &alphaOcclu, 1);
 +              DRW_shgroup_call_add(grp, quad, NULL);
 +
 +              psl->outlines_expand = DRW_pass_create("Outlines Expand Pass", state);
 +
 +              grp = DRW_shgroup_create(e_data.outline_fade_sh, psl->outlines_expand);
 +              DRW_shgroup_uniform_buffer(grp, "outlineColor", &e_data.outlines_blur_tx);
 +              DRW_shgroup_uniform_bool(grp, "doExpand", &bTrue, 1);
 +              DRW_shgroup_call_add(grp, quad, NULL);
 +
 +              psl->outlines_bleed = DRW_pass_create("Outlines Bleed Pass", state);
 +
 +              grp = DRW_shgroup_create(e_data.outline_fade_sh, psl->outlines_bleed);
 +              DRW_shgroup_uniform_buffer(grp, "outlineColor", &e_data.outlines_color_tx);
 +              DRW_shgroup_uniform_bool(grp, "doExpand", &bFalse, 1);
 +              DRW_shgroup_call_add(grp, quad, NULL);
 +      }
 +
 +      {
 +              DRWState state = DRW_STATE_WRITE_COLOR | DRW_STATE_BLEND;
 +              psl->outlines_resolve = DRW_pass_create("Outlines Resolve Pass", state);
 +
 +              struct Gwn_Batch *quad = DRW_cache_fullscreen_quad_get();
 +
 +              DRWShadingGroup *grp = DRW_shgroup_create(e_data.outline_resolve_aa_sh, psl->outlines_resolve);
 +              DRW_shgroup_uniform_buffer(grp, "outlineBluredColor", &e_data.outlines_blur_tx);
 +              DRW_shgroup_uniform_vec2(grp, "rcpDimensions", e_data.inv_viewport_size, 1);
 +              DRW_shgroup_call_add(grp, quad, NULL);
 +      }
 +
 +      {
 +              /* Grid pass */
 +              DRWState state = DRW_STATE_WRITE_COLOR | DRW_STATE_BLEND;
 +              psl->grid = DRW_pass_create("Infinite Grid Pass", state);
 +
 +              struct Gwn_Batch *quad = DRW_cache_fullscreen_quad_get();
 +              static float mat[4][4];
 +              unit_m4(mat);
 +
 +              /* Create 3 quads to render ordered transparency Z axis */
 +              DRWShadingGroup *grp = DRW_shgroup_create(e_data.grid_sh, psl->grid);
 +              DRW_shgroup_uniform_int(grp, "gridFlag", &e_data.zneg_flag, 1);
 +              DRW_shgroup_uniform_vec3(grp, "planeNormal", e_data.zplane_normal, 1);
 +              DRW_shgroup_uniform_vec3(grp, "planeAxes", e_data.zplane_axes, 1);
 +              DRW_shgroup_uniform_vec3(grp, "cameraPos", e_data.camera_pos, 1);
 +              DRW_shgroup_uniform_vec4(grp, "screenvecs[0]", e_data.screenvecs[0], 3);
 +              DRW_shgroup_uniform_vec4(grp, "gridSettings", e_data.grid_settings, 1);
 +              DRW_shgroup_uniform_float(grp, "gridOneOverLogSubdiv", &e_data.grid_settings[4], 1);
 +              DRW_shgroup_uniform_block(grp, "globalsBlock", globals_ubo);
 +              DRW_shgroup_uniform_vec2(grp, "viewportSize", DRW_viewport_size_get(), 1);
 +              DRW_shgroup_uniform_buffer(grp, "depthBuffer", &dtxl->depth);
 +              DRW_shgroup_call_add(grp, quad, mat);
 +
 +              grp = DRW_shgroup_create(e_data.grid_sh, psl->grid);
 +              DRW_shgroup_uniform_int(grp, "gridFlag", &e_data.grid_flag, 1);
 +              DRW_shgroup_uniform_vec3(grp, "planeNormal", e_data.grid_normal, 1);
 +              DRW_shgroup_uniform_vec3(grp, "planeAxes", e_data.grid_axes, 1);
 +              DRW_shgroup_uniform_block(grp, "globalsBlock", globals_ubo);
 +              DRW_shgroup_uniform_buffer(grp, "depthBuffer", &dtxl->depth);
 +              DRW_shgroup_call_add(grp, quad, mat);
 +
 +              grp = DRW_shgroup_create(e_data.grid_sh, psl->grid);
 +              DRW_shgroup_uniform_int(grp, "gridFlag", &e_data.zpos_flag, 1);
 +              DRW_shgroup_uniform_vec3(grp, "planeNormal", e_data.zplane_normal, 1);
 +              DRW_shgroup_uniform_vec3(grp, "planeAxes", e_data.zplane_axes, 1);
 +              DRW_shgroup_uniform_block(grp, "globalsBlock", globals_ubo);
 +              DRW_shgroup_uniform_buffer(grp, "depthBuffer", &dtxl->depth);
 +              DRW_shgroup_call_add(grp, quad, mat);
 +      }
 +
 +      {
 +              /* Solid bones */
 +              DRWState state = DRW_STATE_WRITE_COLOR | DRW_STATE_WRITE_DEPTH | DRW_STATE_DEPTH_LESS;
 +              psl->bone_solid = DRW_pass_create("Bone Solid Pass", state);
 +      }
 +
 +      {
 +              /* Wire bones */
 +              DRWState state = DRW_STATE_WRITE_COLOR | DRW_STATE_WRITE_DEPTH | DRW_STATE_DEPTH_LESS | DRW_STATE_BLEND;
 +              psl->bone_wire = DRW_pass_create("Bone Wire Pass", state);
 +      }
 +
 +      {
 +              /* distance outline around envelope bones */
 +              DRWState state = DRW_STATE_ADDITIVE | DRW_STATE_WRITE_COLOR | DRW_STATE_DEPTH_LESS | DRW_STATE_BLEND;
 +              psl->bone_envelope = DRW_pass_create("Bone Envelope Outline Pass", state);
 +      }
 +
 +      {
 +              /* Non Meshes Pass (Camera, empties, lamps ...) */
 +              struct Gwn_Batch *geom;
 +
 +              DRWState state =
 +                      DRW_STATE_WRITE_COLOR | DRW_STATE_WRITE_DEPTH |
 +                      DRW_STATE_DEPTH_LESS | DRW_STATE_BLEND | DRW_STATE_POINT;
 +              state |= DRW_STATE_WIRE;
 +              psl->non_meshes = DRW_pass_create("Non Meshes Pass", state);
 +
 +              /* Empties */
 +              geom = DRW_cache_plain_axes_get();
 +              stl->g_data->plain_axes = shgroup_instance(psl->non_meshes, geom);
 +
 +              geom = DRW_cache_cube_get();
 +              stl->g_data->cube = shgroup_instance(psl->non_meshes, geom);
 +
 +              geom = DRW_cache_circle_get();
 +              stl->g_data->circle = shgroup_instance(psl->non_meshes, geom);
 +
 +              geom = DRW_cache_empty_sphere_get();
 +              stl->g_data->sphere = shgroup_instance(psl->non_meshes, geom);
 +
 +              geom = DRW_cache_empty_cone_get();
 +              stl->g_data->cone = shgroup_instance(psl->non_meshes, geom);
 +
 +              geom = DRW_cache_single_arrow_get();
 +              stl->g_data->single_arrow = shgroup_instance(psl->non_meshes, geom);
 +
 +              geom = DRW_cache_single_line_get();
 +              stl->g_data->single_arrow_line = shgroup_instance(psl->non_meshes, geom);
 +
 +              geom = DRW_cache_arrows_get();
 +              stl->g_data->arrows = shgroup_instance(psl->non_meshes, geom);
 +
 +              geom = DRW_cache_axis_names_get();
 +              stl->g_data->axis_names = shgroup_instance_axis_names(psl->non_meshes, geom);
 +
 +              /* initialize on first use */
 +              stl->g_data->image_plane_map = NULL;
 +
 +              /* Force Field */
 +              geom = DRW_cache_field_wind_get();
 +              stl->g_data->field_wind = shgroup_instance_scaled(psl->non_meshes, geom);
 +
 +              geom = DRW_cache_field_force_get();
 +              stl->g_data->field_force = shgroup_instance_screen_aligned(psl->non_meshes, geom);
 +
 +              geom = DRW_cache_field_vortex_get();
 +              stl->g_data->field_vortex = shgroup_instance_scaled(psl->non_meshes, geom);
 +
 +              geom = DRW_cache_screenspace_circle_get();
 +              stl->g_data->field_curve_sta = shgroup_instance_screen_aligned(psl->non_meshes, geom);
 +
 +              /* Speaker */
 +              geom = DRW_cache_speaker_get();
 +              stl->g_data->speaker = shgroup_instance(psl->non_meshes, geom);
 +
 +              /* Probe */
 +              static float probeSize = 14.0f;
 +              geom = DRW_cache_lightprobe_cube_get();
 +              stl->g_data->probe_cube = shgroup_instance_screenspace(psl->non_meshes, geom, &probeSize);
 +
 +              geom = DRW_cache_lightprobe_grid_get();
 +              stl->g_data->probe_grid = shgroup_instance_screenspace(psl->non_meshes, geom, &probeSize);
 +
 +              static float probePlanarSize = 20.0f;
 +              geom = DRW_cache_lightprobe_planar_get();
 +              stl->g_data->probe_planar = shgroup_instance_screenspace(psl->non_meshes, geom, &probePlanarSize);
 +
 +              /* Camera */
 +              geom = DRW_cache_camera_get();
 +              stl->g_data->camera = shgroup_camera_instance(psl->non_meshes, geom);
 +
 +              geom = DRW_cache_camera_frame_get();
 +              stl->g_data->camera_frame = shgroup_camera_instance(psl->non_meshes, geom);
 +
 +              geom = DRW_cache_camera_tria_get();
 +              stl->g_data->camera_tria = shgroup_camera_instance(psl->non_meshes, geom);
 +
 +              geom = DRW_cache_plain_axes_get();
 +              stl->g_data->camera_focus = shgroup_instance(psl->non_meshes, geom);
 +
 +              geom = DRW_cache_single_line_get();
 +              stl->g_data->camera_clip = shgroup_distance_lines_instance(psl->non_meshes, geom);
 +              stl->g_data->camera_mist = shgroup_distance_lines_instance(psl->non_meshes, geom);
 +
 +              geom = DRW_cache_single_line_endpoints_get();
 +              stl->g_data->camera_clip_points = shgroup_distance_lines_instance(psl->non_meshes, geom);
 +              stl->g_data->camera_mist_points = shgroup_distance_lines_instance(psl->non_meshes, geom);
 +
 +      }
 +
 +      {
 +              GPUShader *sh = GPU_shader_get_builtin_shader(GPU_SHADER_3D_UNIFORM_COLOR);
 +
 +              /* Unselected */
 +              stl->g_data->wire = shgroup_wire(psl->non_meshes, ts.colorWire, sh);
 +
 +              /* Select */
 +              stl->g_data->wire_select = shgroup_wire(psl->non_meshes, ts.colorSelect, sh);
 +              stl->g_data->wire_select_group = shgroup_wire(psl->non_meshes, ts.colorGroupActive, sh);
 +
 +              /* Transform */
 +              stl->g_data->wire_transform = shgroup_wire(psl->non_meshes, ts.colorTransform, sh);
 +
 +              /* Active */
 +              stl->g_data->wire_active = shgroup_wire(psl->non_meshes, ts.colorActive, sh);
 +              stl->g_data->wire_active_group = shgroup_wire(psl->non_meshes, ts.colorGroupActive, sh);
 +      }
 +
 +      {
 +              /* Metaballs Helpers */
 +              struct Gwn_Batch *geom;
 +              geom = DRW_cache_screenspace_circle_get();
 +              stl->g_data->mball_circle = shgroup_instance_mball_helpers(psl->non_meshes, geom);
 +      }
 +
 +      {
 +              /* Lamps */
 +              /* TODO
 +               * for now we create multiple times the same VBO with only lamp center coordinates
 +               * but ideally we would only create it once */
 +              struct Gwn_Batch *geom;
 +
 +              /* start with buflimit because we don't want stipples */
 +              geom = DRW_cache_single_line_get();
 +              stl->g_data->lamp_buflimit = shgroup_distance_lines_instance(psl->non_meshes, geom);
 +
 +              stl->g_data->lamp_center = shgroup_dynpoints_uniform_color(psl->non_meshes, ts.colorLampNoAlpha, &ts.sizeLampCenter);
 +              stl->g_data->lamp_center_group = shgroup_dynpoints_uniform_color(psl->non_meshes, ts.colorGroup, &ts.sizeLampCenter);
 +
 +              geom = DRW_cache_lamp_get();
 +              stl->g_data->lamp_circle = shgroup_instance_screenspace(psl->non_meshes, geom, &ts.sizeLampCircle);
 +              geom = DRW_cache_lamp_shadows_get();
 +              stl->g_data->lamp_circle_shadow = shgroup_instance_screenspace(psl->non_meshes, geom, &ts.sizeLampCircleShadow);
 +
 +              geom = DRW_cache_lamp_sunrays_get();
 +              stl->g_data->lamp_sunrays = shgroup_instance_screenspace(psl->non_meshes, geom, &ts.sizeLampCircle);
 +
 +              stl->g_data->lamp_groundline = shgroup_groundlines_uniform_color(psl->non_meshes, ts.colorLamp);
 +              stl->g_data->lamp_groundpoint = shgroup_groundpoints_uniform_color(psl->non_meshes, ts.colorLamp);
 +
 +              geom = DRW_cache_lamp_area_get();
 +              stl->g_data->lamp_area = shgroup_instance(psl->non_meshes, geom);
 +
 +              geom = DRW_cache_lamp_hemi_get();
 +              stl->g_data->lamp_hemi = shgroup_instance(psl->non_meshes, geom);
 +
 +              geom = DRW_cache_single_line_get();
 +              stl->g_data->lamp_distance = shgroup_distance_lines_instance(psl->non_meshes, geom);
 +
 +              geom = DRW_cache_single_line_endpoints_get();
 +              stl->g_data->lamp_buflimit_points = shgroup_distance_lines_instance(psl->non_meshes, geom);
 +
 +              geom = DRW_cache_lamp_spot_get();
 +              stl->g_data->lamp_spot_cone = shgroup_spot_instance(psl->non_meshes, geom);
 +
 +              geom = DRW_cache_circle_get();
 +              stl->g_data->lamp_spot_blend = shgroup_instance(psl->non_meshes, geom);
 +
 +              geom = DRW_cache_lamp_spot_square_get();
 +              stl->g_data->lamp_spot_pyramid = shgroup_instance(psl->non_meshes, geom);
 +
 +              geom = DRW_cache_square_get();
 +              stl->g_data->lamp_spot_blend_rect = shgroup_instance(psl->non_meshes, geom);
 +      }
 +
 +      {
 +              /* -------- STIPPLES ------- */
 +              /* TODO port to shader stipple */
 +              struct Gwn_Batch *geom;
 +
 +              /* Relationship Lines */
 +              stl->g_data->relationship_lines = shgroup_dynlines_uniform_color(psl->non_meshes, ts.colorWire);
 +              DRW_shgroup_state_enable(stl->g_data->relationship_lines, DRW_STATE_STIPPLE_3);
 +
 +              /* Force Field Curve Guide End (here because of stipple) */
 +              geom = DRW_cache_screenspace_circle_get();
 +              stl->g_data->field_curve_end = shgroup_instance_screen_aligned(psl->non_meshes, geom);
 +
 +              /* Force Field Limits */
 +              geom = DRW_cache_field_tube_limit_get();
 +              stl->g_data->field_tube_limit = shgroup_instance_scaled(psl->non_meshes, geom);
 +
 +              geom = DRW_cache_field_cone_limit_get();
 +              stl->g_data->field_cone_limit = shgroup_instance_scaled(psl->non_meshes, geom);
 +      }
 +
 +      {
 +              /* Object Center pass grouped by State */
 +              DRWShadingGroup *grp;
 +              static float outlineWidth, size;
 +
 +              DRWState state = DRW_STATE_WRITE_COLOR | DRW_STATE_BLEND | DRW_STATE_POINT;
 +              psl->ob_center = DRW_pass_create("Obj Center Pass", state);
 +
 +              outlineWidth = 1.0f * U.pixelsize;
 +              size = U.obcenter_dia * U.pixelsize + outlineWidth;
 +
 +              GPUShader *sh = GPU_shader_get_builtin_shader(GPU_SHADER_3D_POINT_UNIFORM_SIZE_UNIFORM_COLOR_OUTLINE_AA);
 +
 +              /* Active */
 +              grp = DRW_shgroup_point_batch_create(sh, psl->ob_center);
 +              DRW_shgroup_uniform_float(grp, "size", &size, 1);
 +              DRW_shgroup_uniform_float(grp, "outlineWidth", &outlineWidth, 1);
 +              DRW_shgroup_uniform_vec4(grp, "color", ts.colorActive, 1);
 +              DRW_shgroup_uniform_vec4(grp, "outlineColor", ts.colorOutline, 1);
 +              stl->g_data->center_active = grp;
 +
 +              /* Select */
 +              grp = DRW_shgroup_point_batch_create(sh, psl->ob_center);
 +              DRW_shgroup_uniform_vec4(grp, "color", ts.colorSelect, 1);
 +              stl->g_data->center_selected = grp;
 +
 +              /* Deselect */
 +              grp = DRW_shgroup_point_batch_create(sh, psl->ob_center);
 +              DRW_shgroup_uniform_vec4(grp, "color", ts.colorDeselect, 1);
 +              stl->g_data->center_deselected = grp;
 +
 +              /* Select (library) */
 +              grp = DRW_shgroup_point_batch_create(sh, psl->ob_center);
 +              DRW_shgroup_uniform_vec4(grp, "color", ts.colorLibrarySelect, 1);
 +              stl->g_data->center_selected_lib = grp;
 +
 +              /* Deselect (library) */
 +              grp = DRW_shgroup_point_batch_create(sh, psl->ob_center);
 +              DRW_shgroup_uniform_vec4(grp, "color", ts.colorLibrary, 1);
 +              stl->g_data->center_deselected_lib = grp;
 +      }
 +
 +      {
 +              /* Particle Pass */
 +              psl->particle = DRW_pass_create(
 +                      "Particle Pass",
 +                      DRW_STATE_WRITE_COLOR | DRW_STATE_WRITE_DEPTH | DRW_STATE_DEPTH_LESS |
 +                      DRW_STATE_POINT | DRW_STATE_BLEND);
 +      }
 +
 +      {
 +              /* Empty/Background Image Pass */
 +              psl->reference_image = DRW_pass_create(
 +                      "Refrence Image Pass",
 +                      DRW_STATE_WRITE_COLOR | DRW_STATE_WRITE_DEPTH | DRW_STATE_DEPTH_LESS | DRW_STATE_BLEND);
 +      }
 +}
 +
 +static void DRW_shgroup_mball_helpers(OBJECT_StorageList *stl, Object *ob, ViewLayer *view_layer)
 +{
 +      MetaBall *mb = ob->data;
 +
 +      float *color;
 +      DRW_object_wire_theme_get(ob, view_layer, &color);
 +
 +      for (MetaElem *ml = mb->elems.first; ml != NULL; ml = ml->next) {
 +              /* draw radius */
 +              BKE_mball_element_calc_display_m3x4(ml->draw_scale_xform, ob->obmat, &ml->x);
 +              DRW_shgroup_call_dynamic_add(stl->g_data->mball_circle, ml->draw_scale_xform, &ml->rad, color);
 +      }
 +}
 +
 +static void DRW_shgroup_lamp(OBJECT_StorageList *stl, Object *ob, ViewLayer *view_layer)
 +{
 +      Lamp *la = ob->data;
 +      float *color;
 +      int theme_id = DRW_object_wire_theme_get(ob, view_layer, &color);
 +      static float zero = 0.0f;
 +
 +      typedef struct LampEngineData {
 +              ObjectEngineData engine_data;
 +              float shape_mat[4][4];
 +              float spot_blend_mat[4][4];
 +      } LampEngineData;
 +
 +      LampEngineData *lamp_engine_data =
 +              (LampEngineData *)DRW_object_engine_data_ensure(
 +                      ob,
 +                      &draw_engine_object_type,
 +                      sizeof(LampEngineData),
 +                      NULL,
 +                      NULL);
 +
 +      float (*shapemat)[4] = lamp_engine_data->shape_mat;
 +      float (*spotblendmat)[4] = lamp_engine_data->spot_blend_mat;
 +
 +      /* Don't draw the center if it's selected or active */
 +      if (theme_id == TH_GROUP)
 +              DRW_shgroup_call_dynamic_add(stl->g_data->lamp_center_group, ob->obmat[3]);
 +      else if (theme_id == TH_LAMP)
 +              DRW_shgroup_call_dynamic_add(stl->g_data->lamp_center, ob->obmat[3]);
 +
 +      /* First circle */
 +      DRW_shgroup_call_dynamic_add(stl->g_data->lamp_circle, ob->obmat[3], color);
 +
 +      /* draw dashed outer circle if shadow is on. remember some lamps can't have certain shadows! */
 +      if (la->type != LA_HEMI) {
 +              if ((la->mode & LA_SHAD_RAY) || ((la->mode & LA_SHAD_BUF) && (la->type == LA_SPOT))) {
 +                      DRW_shgroup_call_dynamic_add(stl->g_data->lamp_circle_shadow, ob->obmat[3], color);
 +              }
 +      }
 +
 +      /* Distance */
 +      if (ELEM(la->type, LA_HEMI, LA_SUN, LA_AREA)) {
 +              DRW_shgroup_call_dynamic_add(stl->g_data->lamp_distance, color, &zero, &la->dist, ob->obmat);
 +      }
 +
 +      copy_m4_m4(shapemat, ob->obmat);
 +
 +      if (la->type == LA_SUN) {
 +              DRW_shgroup_call_dynamic_add(stl->g_data->lamp_sunrays, ob->obmat[3], color);
 +      }
 +      else if (la->type == LA_SPOT) {
 +              float size[3], sizemat[4][4];
 +              static float one = 1.0f;
 +              float blend = 1.0f - pow2f(la->spotblend);
 +
 +              size[0] = size[1] = sinf(la->spotsize * 0.5f) * la->dist;
 +              size[2] = cosf(la->spotsize * 0.5f) * la->dist;
 +
 +              size_to_mat4(sizemat, size);
 +              mul_m4_m4m4(shapemat, ob->obmat, sizemat);
 +
 +              size[0] = size[1] = blend; size[2] = 1.0f;
 +              size_to_mat4(sizemat, size);
 +              translate_m4(sizemat, 0.0f, 0.0f, -1.0f);
 +              rotate_m4(sizemat, 'X', (float)(M_PI / 2));
 +              mul_m4_m4m4(spotblendmat, shapemat, sizemat);
 +
 +              if (la->mode & LA_SQUARE) {
 +                      DRW_shgroup_call_dynamic_add(stl->g_data->lamp_spot_pyramid, color, &one, shapemat);
 +
 +                      /* hide line if it is zero size or overlaps with outer border,
 +                       * previously it adjusted to always to show it but that seems
 +                       * confusing because it doesn't show the actual blend size */
 +                      if (blend != 0.0f && blend != 1.0f) {
 +                              DRW_shgroup_call_dynamic_add(stl->g_data->lamp_spot_blend_rect, color, &one, spotblendmat);
 +                      }
 +              }
 +              else {
 +                      DRW_shgroup_call_dynamic_add(stl->g_data->lamp_spot_cone, color, shapemat);
 +
 +                      /* hide line if it is zero size or overlaps with outer border,
 +                       * previously it adjusted to always to show it but that seems
 +                       * confusing because it doesn't show the actual blend size */
 +                      if (blend != 0.0f && blend != 1.0f) {
 +                              DRW_shgroup_call_dynamic_add(stl->g_data->lamp_spot_blend, color, &one, spotblendmat);
 +                      }
 +              }
 +
 +              DRW_shgroup_call_dynamic_add(stl->g_data->lamp_buflimit, color, &la->clipsta, &la->clipend, ob->obmat);
 +              DRW_shgroup_call_dynamic_add(stl->g_data->lamp_buflimit_points, color, &la->clipsta, &la->clipend, ob->obmat);
 +      }
 +      else if (la->type == LA_HEMI) {
 +              static float hemisize = 2.0f;
 +              DRW_shgroup_call_dynamic_add(stl->g_data->lamp_hemi, color, &hemisize, shapemat);
 +      }
 +      else if (la->type == LA_AREA) {
 +              float size[3] = {1.0f, 1.0f, 1.0f}, sizemat[4][4];
 +
 +              if (la->area_shape == LA_AREA_RECT) {
 +                      size[1] = la->area_sizey / la->area_size;
 +                      size_to_mat4(sizemat, size);
 +                      mul_m4_m4m4(shapemat, shapemat, sizemat);
 +              }
 +
 +              DRW_shgroup_call_dynamic_add(stl->g_data->lamp_area, color, &la->area_size, shapemat);
 +      }
 +
 +      /* Line and point going to the ground */
 +      DRW_shgroup_call_dynamic_add(stl->g_data->lamp_groundline, ob->obmat[3]);
 +      DRW_shgroup_call_dynamic_add(stl->g_data->lamp_groundpoint, ob->obmat[3]);
 +}
 +
 +static void DRW_shgroup_camera(OBJECT_StorageList *stl, Object *ob, ViewLayer *view_layer)
 +{
 +      const DRWContextState *draw_ctx = DRW_context_state_get();
 +      View3D *v3d = draw_ctx->v3d;
 +      Scene *scene = draw_ctx->scene;
 +      RegionView3D *rv3d = draw_ctx->rv3d;
 +
 +      Camera *cam = ob->data;
 +      const bool is_active = (ob == v3d->camera);
 +      const bool look_through = (is_active && (rv3d->persp == RV3D_CAMOB));
 +      float *color;
 +      DRW_object_wire_theme_get(ob, view_layer, &color);
 +
 +      float vec[4][3], asp[2], shift[2], scale[3], drawsize;
 +
 +      scale[0] = 1.0f / len_v3(ob->obmat[0]);
 +      scale[1] = 1.0f / len_v3(ob->obmat[1]);
 +      scale[2] = 1.0f / len_v3(ob->obmat[2]);
 +
 +      BKE_camera_view_frame_ex(scene, cam, cam->drawsize, false, scale,
 +                               asp, shift, &drawsize, vec);
 +
 +      /* Frame coords */
 +      copy_v2_v2(cam->drwcorners[0], vec[0]);
 +      copy_v2_v2(cam->drwcorners[1], vec[1]);
 +      copy_v2_v2(cam->drwcorners[2], vec[2]);
 +      copy_v2_v2(cam->drwcorners[3], vec[3]);
 +
 +      /* depth */
 +      cam->drwdepth = vec[0][2];
 +
 +      /* tria */
 +      cam->drwtria[0][0] = shift[0] + ((0.7f * drawsize) * scale[0]);
 +      cam->drwtria[0][1] = shift[1] + ((drawsize * (asp[1] + 0.1f)) * scale[1]);
 +      cam->drwtria[1][0] = shift[0];
 +      cam->drwtria[1][1] = shift[1] + ((1.1f * drawsize * (asp[1] + 0.7f)) * scale[1]);
 +
 +      if (look_through) {
 +              /* Only draw the frame. */
 +              DRW_shgroup_call_dynamic_add(
 +                      stl->g_data->camera_frame, color, cam->drwcorners,
 +                      &cam->drwdepth, cam->drwtria, ob->obmat);
 +      }
 +      else {
 +              DRW_shgroup_call_dynamic_add(
 +                      stl->g_data->camera, color, cam->drwcorners,
 +                      &cam->drwdepth, cam->drwtria, ob->obmat);
 +
 +              /* Active cam */
 +              if (is_active) {
 +                      DRW_shgroup_call_dynamic_add(
 +                              stl->g_data->camera_tria, color,
 +                              cam->drwcorners, &cam->drwdepth, cam->drwtria, ob->obmat);
 +              }
 +      }
 +
 +      /* draw the rest in normalize object space */
 +      copy_m4_m4(cam->drwnormalmat, ob->obmat);
 +      normalize_m4(cam->drwnormalmat);
 +
 +      if (cam->flag & CAM_SHOWLIMITS) {
 +              static float col[3] = {0.5f, 0.5f, 0.25f}, col_hi[3] = {1.0f, 1.0f, 0.5f};
 +              float sizemat[4][4], size[3] = {1.0f, 1.0f, 0.0f};
 +              float focusdist = BKE_camera_object_dof_distance(ob);
 +
 +              copy_m4_m4(cam->drwfocusmat, cam->drwnormalmat);
 +              translate_m4(cam->drwfocusmat, 0.0f, 0.0f, -focusdist);
 +              size_to_mat4(sizemat, size);
 +              mul_m4_m4m4(cam->drwfocusmat, cam->drwfocusmat, sizemat);
 +
 +              DRW_shgroup_call_dynamic_add(
 +                      stl->g_data->camera_focus, (is_active ? col_hi : col),
 +                      &cam->drawsize, cam->drwfocusmat);
 +
 +              DRW_shgroup_call_dynamic_add(
 +                      stl->g_data->camera_clip, color,
 +                      &cam->clipsta, &cam->clipend, cam->drwnormalmat);
 +              DRW_shgroup_call_dynamic_add(
 +                      stl->g_data->camera_clip_points, (is_active ? col_hi : col),
 +                      &cam->clipsta, &cam->clipend, cam->drwnormalmat);
 +      }
 +
 +      if (cam->flag & CAM_SHOWMIST) {
 +              World *world = scene->world;
 +
 +              if (world) {
 +                      static float col[3] = {0.5f, 0.5f, 0.5f}, col_hi[3] = {1.0f, 1.0f, 1.0f};
 +                      world->mistend = world->miststa + world->mistdist;
 +                      DRW_shgroup_call_dynamic_add(
 +                              stl->g_data->camera_mist, color,
 +                              &world->miststa, &world->mistend, cam->drwnormalmat);
 +                      DRW_shgroup_call_dynamic_add(
 +                              stl->g_data->camera_mist_points, (is_active ? col_hi : col),
 +                              &world->miststa, &world->mistend, cam->drwnormalmat);
 +              }
 +      }
 +}
 +
 +static void DRW_shgroup_empty(OBJECT_StorageList *stl, OBJECT_PassList *psl, Object *ob, ViewLayer *view_layer)
 +{
 +      float *color;
 +      DRW_object_wire_theme_get(ob, view_layer, &color);
 +
 +      switch (ob->empty_drawtype) {
 +              case OB_PLAINAXES:
 +                      DRW_shgroup_call_dynamic_add(stl->g_data->plain_axes, color, &ob->empty_drawsize, ob->obmat);
 +                      break;
 +              case OB_SINGLE_ARROW:
 +                      DRW_shgroup_call_dynamic_add(stl->g_data->single_arrow, color, &ob->empty_drawsize, ob->obmat);
 +                      DRW_shgroup_call_dynamic_add(stl->g_data->single_arrow_line, color, &ob->empty_drawsize, ob->obmat);
 +                      break;
 +              case OB_CUBE:
 +                      DRW_shgroup_call_dynamic_add(stl->g_data->cube, color, &ob->empty_drawsize, ob->obmat);
 +                      break;
 +              case OB_CIRCLE:
 +                      DRW_shgroup_call_dynamic_add(stl->g_data->circle, color, &ob->empty_drawsize, ob->obmat);
 +                      break;
 +              case OB_EMPTY_SPHERE:
 +                      DRW_shgroup_call_dynamic_add(stl->g_data->sphere, color, &ob->empty_drawsize, ob->obmat);
 +                      break;
 +              case OB_EMPTY_CONE:
 +                      DRW_shgroup_call_dynamic_add(stl->g_data->cone, color, &ob->empty_drawsize, ob->obmat);
 +                      break;
 +              case OB_ARROWS:
 +                      DRW_shgroup_call_dynamic_add(stl->g_data->arrows, color, &ob->empty_drawsize, ob->obmat);
 +                      DRW_shgroup_call_dynamic_add(stl->g_data->axis_names, color, &ob->empty_drawsize, ob->obmat);
 +                      break;
 +              case OB_EMPTY_IMAGE:
 +                      DRW_shgroup_empty_image(stl, psl, ob, color);
 +                      break;
 +      }
 +}
 +
 +static void DRW_shgroup_forcefield(OBJECT_StorageList *stl, Object *ob, ViewLayer *view_layer)
 +{
 +      int theme_id = DRW_object_wire_theme_get(ob, view_layer, NULL);
 +      float *color = DRW_color_background_blend_get(theme_id);
 +      PartDeflect *pd = ob->pd;
 +      Curve *cu = (ob->type == OB_CURVE) ? ob->data : NULL;
 +
 +      /* TODO Move this to depsgraph */
 +      float tmp[3];
 +      copy_v3_fl(pd->drawvec1, ob->empty_drawsize);
 +
 +      switch (pd->forcefield) {
 +              case PFIELD_WIND:
 +                      pd->drawvec1[2] = pd->f_strength;
 +                      break;
 +              case PFIELD_VORTEX:
 +                      if (pd->f_strength < 0.0f) {
 +                              pd->drawvec1[1] = -pd->drawvec1[1];
 +                      }
 +                      break;
 +              case PFIELD_GUIDE:
 +                      if (cu && (cu->flag & CU_PATH) && ob->curve_cache->path && ob->curve_cache->path->data) {
 +                              where_on_path(ob, 0.0f, pd->drawvec1, tmp, NULL, NULL, NULL);
 +                              where_on_path(ob, 1.0f, pd->drawvec2, tmp, NULL, NULL, NULL);
 +                      }
 +                      break;
 +      }
 +
 +      if (pd->falloff == PFIELD_FALL_TUBE) {
 +              pd->drawvec_falloff_max[0] = pd->drawvec_falloff_max[1] = (pd->flag & PFIELD_USEMAXR) ? pd->maxrad : 1.0f;
 +              pd->drawvec_falloff_max[2] = (pd->flag & PFIELD_USEMAX) ? pd->maxdist : 0.0f;
 +
 +              pd->drawvec_falloff_min[0] = pd->drawvec_falloff_min[1] = (pd->flag & PFIELD_USEMINR) ? pd->minrad : 1.0f;
 +              pd->drawvec_falloff_min[2] = (pd->flag & PFIELD_USEMIN) ? pd->mindist : 0.0f;
 +      }
 +      else if (pd->falloff == PFIELD_FALL_CONE) {
 +              float radius, distance;
 +
 +              radius = DEG2RADF((pd->flag & PFIELD_USEMAXR) ? pd->maxrad : 1.0f);
 +              distance = (pd->flag & PFIELD_USEMAX) ? pd->maxdist : 0.0f;
 +              pd->drawvec_falloff_max[0] = pd->drawvec_falloff_max[1] = distance * sinf(radius);
 +              pd->drawvec_falloff_max[2] = distance * cosf(radius);
 +
 +              radius = DEG2RADF((pd->flag & PFIELD_USEMINR) ? pd->minrad : 1.0f);
 +              distance = (pd->flag & PFIELD_USEMIN) ? pd->mindist : 0.0f;
 +
 +              pd->drawvec_falloff_min[0] = pd->drawvec_falloff_min[1] = distance * sinf(radius);
 +              pd->drawvec_falloff_min[2] = distance * cosf(radius);
 +      }
 +      /* End of things that should go to depthgraph */
 +
 +      switch (pd->forcefield) {
 +              case PFIELD_WIND:
 +                      DRW_shgroup_call_dynamic_add(stl->g_data->field_wind, color, &pd->drawvec1, ob->obmat);
 +                      break;
 +              case PFIELD_FORCE:
 +                      DRW_shgroup_call_dynamic_add(stl->g_data->field_force, color, &pd->drawvec1, ob->obmat);
 +                      break;
 +              case PFIELD_VORTEX:
 +                      DRW_shgroup_call_dynamic_add(stl->g_data->field_vortex, color, &pd->drawvec1, ob->obmat);
 +                      break;
 +              case PFIELD_GUIDE:
 +                      if (cu && (cu->flag & CU_PATH) && ob->curve_cache->path && ob->curve_cache->path->data) {
 +                              DRW_shgroup_call_dynamic_add(stl->g_data->field_curve_sta, color, &pd->f_strength, ob->obmat);
 +                              DRW_shgroup_call_dynamic_add(stl->g_data->field_curve_end, color, &pd->f_strength, ob->obmat);
 +                      }
 +                      break;
 +      }
 +
 +      if (pd->falloff == PFIELD_FALL_SPHERE) {
 +              /* as last, guide curve alters it */
 +              if ((pd->flag & PFIELD_USEMAX) != 0) {
 +                      DRW_shgroup_call_dynamic_add(stl->g_data->field_curve_end, color, &pd->maxdist, ob->obmat);
 +              }
 +
 +              if ((pd->flag & PFIELD_USEMIN) != 0) {
 +                      DRW_shgroup_call_dynamic_add(stl->g_data->field_curve_end, color, &pd->mindist, ob->obmat);
 +              }
 +      }
 +      else if (pd->falloff == PFIELD_FALL_TUBE) {
 +              if (pd->flag & (PFIELD_USEMAX | PFIELD_USEMAXR)) {
 +                      DRW_shgroup_call_dynamic_add(stl->g_data->field_tube_limit, color, &pd->drawvec_falloff_max, ob->obmat);
 +              }
 +
 +              if (pd->flag & (PFIELD_USEMIN | PFIELD_USEMINR)) {
 +                      DRW_shgroup_call_dynamic_add(stl->g_data->field_tube_limit, color, &pd->drawvec_falloff_min, ob->obmat);
 +              }
 +      }
 +      else if (pd->falloff == PFIELD_FALL_CONE) {
 +              if (pd->flag & (PFIELD_USEMAX | PFIELD_USEMAXR)) {
 +                      DRW_shgroup_call_dynamic_add(stl->g_data->field_cone_limit, color, &pd->drawvec_falloff_max, ob->obmat);
 +              }
 +
 +              if (pd->flag & (PFIELD_USEMIN | PFIELD_USEMINR)) {
 +                      DRW_shgroup_call_dynamic_add(stl->g_data->field_cone_limit, color, &pd->drawvec_falloff_min, ob->obmat);
 +              }
 +      }
 +}
 +
 +static void DRW_shgroup_speaker(OBJECT_StorageList *stl, Object *ob, ViewLayer *view_layer)
 +{
 +      float *color;
 +      static float one = 1.0f;
 +      DRW_object_wire_theme_get(ob, view_layer, &color);
 +
 +      DRW_shgroup_call_dynamic_add(stl->g_data->speaker, color, &one, ob->obmat);
 +}
 +
 +typedef struct OBJECT_LightProbeEngineData {
 +      ObjectEngineData engine_data;
 +
 +      float prb_mats[6][4][4];
 +      float probe_cube_mat[4][4];
 +      float draw_size;
 +      float increment_x[3];
 +      float increment_y[3];
 +      float increment_z[3];
 +      float corner[3];
 +} OBJECT_LightProbeEngineData;
 +
 +static void DRW_shgroup_lightprobe(OBJECT_StorageList *stl, OBJECT_PassList *psl, Object *ob, ViewLayer *view_layer)
 +{
 +      float *color;
 +      static float one = 1.0f;
 +      LightProbe *prb = (LightProbe *)ob->data;
 +      bool do_outlines = ((ob->base_flag & BASE_SELECTED) != 0);
 +      DRW_object_wire_theme_get(ob, view_layer, &color);
 +
 +      OBJECT_LightProbeEngineData *prb_data =
 +              (OBJECT_LightProbeEngineData *)DRW_object_engine_data_ensure(
 +                      ob,
 +                      &draw_engine_object_type,
 +                      sizeof(OBJECT_LightProbeEngineData),
 +                      NULL,
 +                      NULL);
 +
 +      if ((DRW_state_is_select() || do_outlines) && ((prb->flag & LIGHTPROBE_FLAG_SHOW_DATA) != 0)) {
 +
 +              if (prb->type == LIGHTPROBE_TYPE_GRID) {
 +                      /* Update transforms */
 +                      float cell_dim[3], half_cell_dim[3];
 +                      cell_dim[0] = 2.0f / (float)(prb->grid_resolution_x);
 +                      cell_dim[1] = 2.0f / (float)(prb->grid_resolution_y);
 +                      cell_dim[2] = 2.0f / (float)(prb->grid_resolution_z);
 +
 +                      mul_v3_v3fl(half_cell_dim, cell_dim, 0.5f);
 +
 +                      /* First cell. */
 +                      copy_v3_fl(prb_data->corner, -1.0f);
 +                      add_v3_v3(prb_data->corner, half_cell_dim);
 +                      mul_m4_v3(ob->obmat, prb_data->corner);
 +
 +                      /* Opposite neighbor cell. */
 +                      copy_v3_fl3(prb_data->increment_x, cell_dim[0], 0.0f, 0.0f);
 +                      add_v3_v3(prb_data->increment_x, half_cell_dim);
 +                      add_v3_fl(prb_data->increment_x, -1.0f);
 +                      mul_m4_v3(ob->obmat, prb_data->increment_x);
 +                      sub_v3_v3(prb_data->increment_x, prb_data->corner);
 +
 +                      copy_v3_fl3(prb_data->increment_y, 0.0f, cell_dim[1], 0.0f);
 +                      add_v3_v3(prb_data->increment_y, half_cell_dim);
 +                      add_v3_fl(prb_data->increment_y, -1.0f);
 +                      mul_m4_v3(ob->obmat, prb_data->increment_y);
 +                      sub_v3_v3(prb_data->increment_y, prb_data->corner);
 +
 +                      copy_v3_fl3(prb_data->increment_z, 0.0f, 0.0f, cell_dim[2]);
 +                      add_v3_v3(prb_data->increment_z, half_cell_dim);
 +                      add_v3_fl(prb_data->increment_z, -1.0f);
 +                      mul_m4_v3(ob->obmat, prb_data->increment_z);
 +                      sub_v3_v3(prb_data->increment_z, prb_data->corner);
 +
 +                      DRWShadingGroup *grp = DRW_shgroup_instance_create(e_data.lightprobe_grid_sh, psl->lightprobes, DRW_cache_sphere_get());
 +                      DRW_shgroup_set_instance_count(grp, prb->grid_resolution_x * prb->grid_resolution_y * prb->grid_resolution_z);
 +                      DRW_shgroup_uniform_vec4(grp, "color", color, 1);
 +                      DRW_shgroup_uniform_vec3(grp, "corner", prb_data->corner, 1);
 +                      DRW_shgroup_uniform_vec3(grp, "increment_x", prb_data->increment_x, 1);
 +                      DRW_shgroup_uniform_vec3(grp, "increment_y", prb_data->increment_y, 1);
 +                      DRW_shgroup_uniform_vec3(grp, "increment_z", prb_data->increment_z, 1);
 +                      DRW_shgroup_uniform_ivec3(grp, "grid_resolution", &prb->grid_resolution_x, 1);
 +                      DRW_shgroup_uniform_float(grp, "sphere_size", &prb->data_draw_size, 1);
 +              }
 +              else if (prb->type == LIGHTPROBE_TYPE_CUBE) {
 +                      prb_data->draw_size = prb->data_draw_size * 0.1f;
 +                      unit_m4(prb_data->probe_cube_mat);
 +                      copy_v3_v3(prb_data->probe_cube_mat[3], ob->obmat[3]);
 +                      DRW_shgroup_call_dynamic_add(stl->g_data->lightprobes_cube, color, &prb_data->draw_size, prb_data->probe_cube_mat);
 +              }
 +              else {
 +                      prb_data->draw_size = 1.0f;
 +                      DRW_shgroup_call_dynamic_add(stl->g_data->lightprobes_planar, color, &prb_data->draw_size, ob->obmat);
 +              }
 +      }
 +
 +      switch (prb->type) {
 +              case LIGHTPROBE_TYPE_PLANAR:
 +                      DRW_shgroup_call_dynamic_add(stl->g_data->probe_planar, ob->obmat[3], color);
 +                      break;
 +              case LIGHTPROBE_TYPE_GRID:
 +                      DRW_shgroup_call_dynamic_add(stl->g_data->probe_grid, ob->obmat[3], color);
 +                      break;
 +              case LIGHTPROBE_TYPE_CUBE:
 +              default:
 +                      DRW_shgroup_call_dynamic_add(stl->g_data->probe_cube, ob->obmat[3], color);
 +                      break;
 +      }
 +
 +
 +
 +      if (prb->type == LIGHTPROBE_TYPE_PLANAR) {
 +              float (*mat)[4];
 +              mat = (float (*)[4])(prb_data->prb_mats[0]);
 +              copy_m4_m4(mat, ob->obmat);
 +              normalize_m4(mat);
 +
 +              DRW_shgroup_call_dynamic_add(stl->g_data->single_arrow, color, &ob->empty_drawsize, mat);
 +              DRW_shgroup_call_dynamic_add(stl->g_data->single_arrow_line, color, &ob->empty_drawsize, mat);
 +
 +              mat = (float (*)[4])(prb_data->prb_mats[1]);
 +              copy_m4_m4(mat, ob->obmat);
 +              zero_v3(mat[2]);
 +
 +              DRW_shgroup_call_dynamic_add(stl->g_data->cube, color, &one, mat);
 +      }
 +
 +      if ((prb->flag & LIGHTPROBE_FLAG_SHOW_INFLUENCE) != 0) {
 +
 +              prb->distfalloff = (1.0f - prb->falloff) * prb->distinf;
 +              prb->distgridinf = prb->distinf;
 +
 +              if (prb->type == LIGHTPROBE_TYPE_GRID) {
 +                      prb->distfalloff += 1.0f;
 +                      prb->distgridinf += 1.0f;
 +              }
 +
 +              if (prb->type == LIGHTPROBE_TYPE_GRID ||
 +                  prb->attenuation_type == LIGHTPROBE_SHAPE_BOX)
 +              {
 +                      DRW_shgroup_call_dynamic_add(stl->g_data->cube, color, &prb->distgridinf, ob->obmat);
 +                      DRW_shgroup_call_dynamic_add(stl->g_data->cube, color, &prb->distfalloff, ob->obmat);
 +              }
 +              else if (prb->type == LIGHTPROBE_TYPE_PLANAR) {
 +                      float (*rangemat)[4];
 +                      rangemat = (float (*)[4])(prb_data->prb_mats[2]);
 +                      copy_m4_m4(rangemat, ob->obmat);
 +                      normalize_v3(rangemat[2]);
 +                      mul_v3_fl(rangemat[2], prb->distinf);
 +
 +                      DRW_shgroup_call_dynamic_add(stl->g_data->cube, color, &one, rangemat);
 +
 +                      rangemat = (float (*)[4])(prb_data->prb_mats[3]);
 +                      copy_m4_m4(rangemat, ob->obmat);
 +                      normalize_v3(rangemat[2]);
 +                      mul_v3_fl(rangemat[2], prb->distfalloff);
 +
 +                      DRW_shgroup_call_dynamic_add(stl->g_data->cube, color, &one, rangemat);
 +              }
 +              else {
 +                      DRW_shgroup_call_dynamic_add(stl->g_data->sphere, color, &prb->distgridinf, ob->obmat);
 +                      DRW_shgroup_call_dynamic_add(stl->g_data->sphere, color, &prb->distfalloff, ob->obmat);
 +              }
 +      }
 +
 +      if ((prb->flag & LIGHTPROBE_FLAG_SHOW_PARALLAX) != 0) {
 +              if (prb->type != LIGHTPROBE_TYPE_PLANAR) {
 +                      float (*obmat)[4], *dist;
 +
 +                      if ((prb->flag & LIGHTPROBE_FLAG_CUSTOM_PARALLAX) != 0) {
 +                              dist = &prb->distpar;
 +                              /* TODO object parallax */
 +                              obmat = ob->obmat;
 +                      }
 +                      else {
 +                              dist = &prb->distinf;
 +                              obmat = ob->obmat;
 +                      }
 +
 +                      if (prb->parallax_type == LIGHTPROBE_SHAPE_BOX) {
 +                              DRW_shgroup_call_dynamic_add(stl->g_data->cube, color, dist, obmat);
 +                      }
 +                      else {
 +                              DRW_shgroup_call_dynamic_add(stl->g_data->sphere, color, dist, obmat);
 +                      }
 +              }
 +      }
 +
 +      if ((prb->flag & LIGHTPROBE_FLAG_SHOW_CLIP_DIST) != 0) {
 +              if (prb->type != LIGHTPROBE_TYPE_PLANAR) {
 +                      static const float cubefacemat[6][4][4] = {
 +                              {{0.0, 0.0, -1.0, 0.0}, {0.0, -1.0, 0.0, 0.0}, {-1.0, 0.0, 0.0, 0.0}, {0.0, 0.0, 0.0, 1.0}},
 +                              {{0.0, 0.0, 1.0, 0.0}, {0.0, -1.0, 0.0, 0.0}, {1.0, 0.0, 0.0, 0.0}, {0.0, 0.0, 0.0, 1.0}},
 +                              {{1.0, 0.0, 0.0, 0.0}, {0.0, 0.0, -1.0, 0.0}, {0.0, 1.0, 0.0, 0.0}, {0.0, 0.0, 0.0, 1.0}},
 +                              {{1.0, 0.0, 0.0, 0.0}, {0.0, 0.0, 1.0, 0.0}, {0.0, -1.0, 0.0, 0.0}, {0.0, 0.0, 0.0, 1.0}},
 +                              {{1.0, 0.0, 0.0, 0.0}, {0.0, -1.0, 0.0, 0.0}, {0.0, 0.0, -1.0, 0.0}, {0.0, 0.0, 0.0, 1.0}},
 +                              {{-1.0, 0.0, 0.0, 0.0}, {0.0, -1.0, 0.0, 0.0}, {0.0, 0.0, 1.0, 0.0}, {0.0, 0.0, 0.0, 1.0}},
 +                      };
 +
 +                      for (int i = 0; i < 6; ++i) {
 +                              float (*clipmat)[4];
 +                              clipmat = (float (*)[4])(prb_data->prb_mats[i]);
 +
 +                              normalize_m4_m4(clipmat, ob->obmat);
 +                              mul_m4_m4m4(clipmat, clipmat, cubefacemat[i]);
 +
 +                              DRW_shgroup_call_dynamic_add(stl->g_data->lamp_buflimit, color, &prb->clipsta, &prb->clipend, clipmat);
 +                              DRW_shgroup_call_dynamic_add(stl->g_data->lamp_buflimit_points, color, &prb->clipsta, &prb->clipend, clipmat);
 +                      }
 +              }
 +      }
 +
 +      /* Line and point going to the ground */
 +      if (prb->type == LIGHTPROBE_TYPE_CUBE) {
 +              DRW_shgroup_call_dynamic_add(stl->g_data->lamp_groundline, ob->obmat[3]);
 +              DRW_shgroup_call_dynamic_add(stl->g_data->lamp_groundpoint, ob->obmat[3]);
 +      }
 +}
 +
 +static void DRW_shgroup_relationship_lines(OBJECT_StorageList *stl, Object *ob)
 +{
 +      if (ob->parent && DRW_check_object_visible_within_active_context(ob->parent)) {
 +              DRW_shgroup_call_dynamic_add(stl->g_data->relationship_lines, ob->obmat[3]);
 +              DRW_shgroup_call_dynamic_add(stl->g_data->relationship_lines, ob->parent->obmat[3]);
 +      }
 +}
 +
 +static void DRW_shgroup_object_center(OBJECT_StorageList *stl, Object *ob, ViewLayer *view_layer, View3D *v3d)
 +{
 +      const bool is_library = ob->id.us > 1 || ID_IS_LINKED(ob);
 +      DRWShadingGroup *shgroup;
 +
 +      if (ob == OBACT(view_layer)) {
 +              shgroup = stl->g_data->center_active;
 +      }
 +      else if (ob->base_flag & BASE_SELECTED) {
 +              if (is_library) {
 +                      shgroup = stl->g_data->center_selected_lib;
 +              }
 +              else {
 +                      shgroup = stl->g_data->center_selected;
 +              }
 +      }
 +      else if (v3d->flag & V3D_DRAW_CENTERS) {
 +              if (is_library) {
 +                      shgroup = stl->g_data->center_deselected_lib;
 +              }
 +              else {
 +                      shgroup = stl->g_data->center_deselected;
 +              }
 +      }
 +      else {
 +              return;
 +      }
 +
 +      DRW_shgroup_call_dynamic_add(shgroup, ob->obmat[3]);
 +}
 +
 +static void OBJECT_cache_populate_particles(Object *ob,
 +                                            OBJECT_PassList *psl)
 +{
 +      for (ParticleSystem *psys = ob->particlesystem.first; psys; psys = psys->next) {
 +              if (psys_check_enabled(ob, psys, false)) {
 +                      ParticleSettings *part = psys->part;
 +                      int draw_as = (part->draw_as == PART_DRAW_REND) ? part->ren_as : part->draw_as;
 +
 +                      if (draw_as == PART_DRAW_PATH && !psys->pathcache && !psys->childcache) {
 +                              draw_as = PART_DRAW_DOT;
 +                      }
 +
 +                      static float mat[4][4];
 +                      unit_m4(mat);
 +
 +                      if (draw_as != PART_DRAW_PATH) {
 +                              struct Gwn_Batch *geom = DRW_cache_particles_get_dots(psys);
 +                              DRWShadingGroup *shgrp = NULL;
 +                              static int screen_space[2] = {0, 1};
 +                              static float def_prim_col[3] = {0.5f, 0.5f, 0.5f};
 +                              static float def_sec_col[3] = {1.0f, 1.0f, 1.0f};
 +
 +                              Material *ma = give_current_material(ob, part->omat);
 +
 +                              switch (draw_as) {
 +                                      case PART_DRAW_DOT:
 +                                              shgrp = DRW_shgroup_create(e_data.part_dot_sh, psl->particle);
 +                                              DRW_shgroup_uniform_vec3(shgrp, "color", ma ? &ma->r : def_prim_col, 1);
 +                                              DRW_shgroup_uniform_vec3(shgrp, "outlineColor", ma ? &ma->specr : def_sec_col, 1);
 +                                              DRW_shgroup_uniform_float(shgrp, "pixel_size", DRW_viewport_pixelsize_get(), 1);
 +                                              DRW_shgroup_uniform_float(shgrp, "size", &part->draw_size, 1);
 +                                              DRW_shgroup_uniform_texture(shgrp, "ramp", globals_ramp);
 +                                              DRW_shgroup_call_add(shgrp, geom, mat);
 +                                              break;
 +                                      case PART_DRAW_CROSS:
 +                                              shgrp = DRW_shgroup_instance_create(
 +                                                      e_data.part_prim_sh, psl->particle, DRW_cache_particles_get_prim(PART_DRAW_CROSS));
 +                                              DRW_shgroup_uniform_texture(shgrp, "ramp", globals_ramp);
 +                                              DRW_shgroup_uniform_vec3(shgrp, "color", ma ? &ma->r : def_prim_col, 1);
 +                                              DRW_shgroup_uniform_int(shgrp, "screen_space", &screen_space[0], 1);
 +                                              break;
 +                                      case PART_DRAW_CIRC:
 +                                              shgrp = DRW_shgroup_instance_create(
 +                                                      e_data.part_prim_sh, psl->particle, DRW_cache_particles_get_prim(PART_DRAW_CIRC));
 +                                              DRW_shgroup_uniform_texture(shgrp, "ramp", globals_ramp);
 +                                              DRW_shgroup_uniform_vec3(shgrp, "color", ma ? &ma->r : def_prim_col, 1);
 +                                              DRW_shgroup_uniform_int(shgrp, "screen_space", &screen_space[1], 1);
 +                                              break;
 +                                      case PART_DRAW_AXIS:
 +                                              shgrp = DRW_shgroup_instance_create(
 +                                                      e_data.part_axis_sh, psl->particle, DRW_cache_particles_get_prim(PART_DRAW_AXIS));
 +                                              DRW_shgroup_uniform_int(shgrp, "screen_space", &screen_space[0], 1);
 +                                              break;
 +                                      default:
 +                                              break;
 +                              }
 +
 +                              if (shgrp) {
 +                                      if (draw_as != PART_DRAW_DOT) {
 +                                              DRW_shgroup_uniform_float(shgrp, "draw_size", &part->draw_size, 1);
 +                                              DRW_shgroup_instance_batch(shgrp, geom);
 +                                      }
 +                              }
 +                      }
 +              }
 +      }
 +}
 +
 +static void OBJECT_cache_populate(void *vedata, Object *ob)
 +{
 +      OBJECT_PassList *psl = ((OBJECT_Data *)vedata)->psl;
 +      OBJECT_StorageList *stl = ((OBJECT_Data *)vedata)->stl;
 +      const DRWContextState *draw_ctx = DRW_context_state_get();
 +      Scene *scene = draw_ctx->scene;
 +      ViewLayer *view_layer = draw_ctx->view_layer;
 +      View3D *v3d = draw_ctx->v3d;
 +      int theme_id = TH_UNDEFINED;
 +
 +      /* Handle particles first in case the emitter itself shouldn't be rendered. */
 +      if (ob->type == OB_MESH) {
 +              OBJECT_cache_populate_particles(ob, psl);
 +      }
 +
 +      if (DRW_check_object_visible_within_active_context(ob) == false) {
 +              return;
 +      }
 +
 +      //CollectionEngineSettings *ces_mode_ob = BKE_layer_collection_engine_evaluated_get(ob, COLLECTION_MODE_OBJECT, "");
 +
 +      //bool do_wire = BKE_collection_engine_property_value_get_bool(ces_mode_ob, "show_wire");
 +      bool do_outlines = ((ob->base_flag & BASE_SELECTED) != 0);
 +
 +      if (do_outlines) {
 +              Object *obedit = scene->obedit;
 +              if (ob != obedit && !((ob == draw_ctx->obact) && (draw_ctx->object_mode & OB_MODE_ALL_PAINT))) {
 +                      struct Gwn_Batch *geom = DRW_cache_object_surface_get(ob);
 +                      if (geom) {
 +                              theme_id = DRW_object_wire_theme_get(ob, view_layer, NULL);
 +                              DRWShadingGroup *shgroup = shgroup_theme_id_to_outline_or(stl, theme_id, NULL);
 +                              if (shgroup != NULL) {
 +                                      DRW_shgroup_call_add(shgroup, geom, ob->obmat);
 +                              }
 +                      }
 +              }
 +      }
 +
 +      switch (ob->type) {
 +              case OB_MESH:
 +              {
 +                      Mesh *me = ob->data;
 +                      if (me->totpoly == 0) {
 +                              Object *obedit = scene->obedit;
 +                              if (ob != obedit) {
 +                                      struct Gwn_Batch *geom = DRW_cache_mesh_edges_get(ob);
 +                                      if (geom) {
 +                                              if (theme_id == TH_UNDEFINED) {
 +                                                      theme_id = DRW_object_wire_theme_get(ob, view_layer, NULL);
 +                                              }
 +
 +                                              DRWShadingGroup *shgroup = shgroup_theme_id_to_wire_or(stl, theme_id, stl->g_data->wire);
 +                                              DRW_shgroup_call_add(shgroup, geom, ob->obmat);
 +                                      }
 +                              }
 +                      }
 +                      break;
 +              }
 +              case OB_SURF:
 +                      break;
 +              case OB_LATTICE:
 +              {
 +                      Object *obedit = scene->obedit;
 +                      if (ob != obedit) {
 +                              struct Gwn_Batch *geom = DRW_cache_lattice_wire_get(ob, false);
 +                              if (theme_id == TH_UNDEFINED) {
 +                                      theme_id = DRW_object_wire_theme_get(ob, view_layer, NULL);
 +                              }
 +
 +                              DRWShadingGroup *shgroup = shgroup_theme_id_to_wire_or(stl, theme_id, stl->g_data->wire);
 +                              DRW_shgroup_call_add(shgroup, geom, ob->obmat);
 +                      }
 +                      break;
 +              }
 +
 +              case OB_CURVE:
 +              {
 +                      Object *obedit = scene->obedit;
 +                      if (ob != obedit) {
 +                              struct Gwn_Batch *geom = DRW_cache_curve_edge_wire_get(ob);
 +                              if (theme_id == TH_UNDEFINED) {
 +                                      theme_id = DRW_object_wire_theme_get(ob, view_layer, NULL);
 +                              }
 +                              DRWShadingGroup *shgroup = shgroup_theme_id_to_wire_or(stl, theme_id, stl->g_data->wire);
 +                              DRW_shgroup_call_add(shgroup, geom, ob->obmat);
 +                      }
 +                      break;
 +              }
 +              case OB_MBALL:
 +              {
 +                      Object *obedit = scene->obedit;
 +                      if (ob != obedit) {
 +                              DRW_shgroup_mball_helpers(stl, ob, view_layer);
 +                      }
 +                      break;
 +              }
 +              case OB_LAMP:
 +                      DRW_shgroup_lamp(stl, ob, view_layer);
 +                      break;
 +              case OB_CAMERA:
 +                      DRW_shgroup_camera(stl, ob, view_layer);
 +                      break;
 +              case OB_EMPTY:
 +                      DRW_shgroup_empty(stl, psl, ob, view_layer);
 +                      break;
 +              case OB_SPEAKER:
 +                      DRW_shgroup_speaker(stl, ob, view_layer);
 +                      break;
 +              case OB_LIGHTPROBE:
 +                      DRW_shgroup_lightprobe(stl, psl, ob, view_layer);
 +                      break;
 +              case OB_ARMATURE:
 +              {
 +                      bArmature *arm = ob->data;
 +                      if (arm->edbo == NULL) {
 +                              if (DRW_state_is_select() || !DRW_pose_mode_armature(ob, draw_ctx->obact)) {
 +                                      DRW_shgroup_armature_object(
 +                                              ob, view_layer, psl->bone_solid, psl->bone_wire, psl->bone_envelope,
 +                                              stl->g_data->relationship_lines);
 +                              }
 +                      }
 +                      break;
 +              }
 +              default:
 +                      break;
 +      }
 +
 +      if (ob->pd && ob->pd->forcefield) {
 +              DRW_shgroup_forcefield(stl, ob, view_layer);
 +      }
 +
 +      /* don't show object extras in set's */
 +      if ((ob->base_flag & (BASE_FROM_SET | BASE_FROMDUPLI)) == 0) {
 +
 +              DRW_shgroup_object_center(stl, ob, view_layer, v3d);
 +
 +              DRW_shgroup_relationship_lines(stl, ob);
 +
 +              if ((ob->dtx & OB_DRAWNAME) && DRW_state_show_text()) {
 +                      struct DRWTextStore *dt = DRW_text_cache_ensure();
 +                      if (theme_id == TH_UNDEFINED) {
 +                              theme_id = DRW_object_wire_theme_get(ob, view_layer, NULL);
 +                      }
 +
 +                      unsigned char color[4];
 +                      UI_GetThemeColor4ubv(theme_id, color);
 +
 +                      DRW_text_cache_add(
 +                              dt, ob->obmat[3],
 +                              ob->id.name + 2, strlen(ob->id.name + 2),
 +                              10, DRW_TEXT_CACHE_GLOBALSPACE | DRW_TEXT_CACHE_STRING_PTR, color);
 +              }
 +      }
 +}
 +
 +static void OBJECT_draw_scene(void *vedata)
 +{
 +
 +      OBJECT_PassList *psl = ((OBJECT_Data *)vedata)->psl;
 +      OBJECT_StorageList *stl = ((OBJECT_Data *)vedata)->stl;
 +      OBJECT_FramebufferList *fbl = ((OBJECT_Data *)vedata)->fbl;
 +      DefaultFramebufferList *dfbl = DRW_viewport_framebuffer_list_get();
 +      DefaultTextureList *dtxl = DRW_viewport_texture_list_get();
 +
 +      float clearcol[4] = {0.0f, 0.0f, 0.0f, 0.0f};
 +
 +      if (DRW_state_is_fbo()) {
 +              DRW_stats_group_start("Outlines");
 +              /* attach temp textures */
 +              DRW_framebuffer_texture_attach(fbl->outlines, e_data.outlines_depth_tx, 0, 0);
 +              DRW_framebuffer_texture_attach(fbl->outlines, e_data.outlines_color_tx, 0, 0);
 +              DRW_framebuffer_texture_attach(fbl->blur, e_data.outlines_blur_tx, 0, 0);
 +              
 +              /* Render filled polygon on a separate framebuffer */
 +              DRW_framebuffer_bind(fbl->outlines);
 +              DRW_framebuffer_clear(true, true, false, clearcol, 1.0f);
 +              DRW_draw_pass(psl->outlines);
 +              DRW_draw_pass(psl->lightprobes);
 +
 +              /* detach textures */
 +              DRW_framebuffer_texture_detach(e_data.outlines_depth_tx);
 +
 +              /* Search outline pixels */
 +              DRW_framebuffer_bind(fbl->blur);
 +              DRW_draw_pass(psl->outlines_search);
 +
 +              /* Expand outline to form a 3px wide line */
 +              DRW_framebuffer_bind(fbl->outlines);
 +              DRW_draw_pass(psl->outlines_expand);
 +
 +              /* Bleed color so the AA can do it's stuff */
 +              DRW_framebuffer_bind(fbl->blur);
 +              DRW_draw_pass(psl->outlines_bleed);
 +
 +              /* detach temp textures */
 +              DRW_framebuffer_texture_detach(e_data.outlines_color_tx);
 +              DRW_framebuffer_texture_detach(e_data.outlines_blur_tx);
 +
 +              /* restore main framebuffer */
 +              DRW_framebuffer_bind(dfbl->default_fb);
 +              DRW_stats_group_end();
 +      }
 +      else if (DRW_state_is_select()) {
 +              /* Render probes spheres/planes so we can select them. */
 +              DRW_draw_pass(psl->lightprobes);
 +      }
 +
 +      MULTISAMPLE_SYNC_ENABLE(dfbl)
 +
 +      /* This needs to be drawn after the oultine */
 +//    DRW_draw_pass(psl->bone_envelope);  /* Never drawn in Object mode currently. */
 +      DRW_draw_pass(psl->bone_wire);
 +      DRW_draw_pass(psl->bone_solid);
 +      DRW_draw_pass(psl->non_meshes);
 +      DRW_draw_pass(psl->particle);
 +      DRW_draw_pass(psl->reference_image);
 +
 +      MULTISAMPLE_SYNC_DISABLE(dfbl)
 +
 +      DRW_draw_pass(psl->ob_center);
 +
 +      if (DRW_state_is_fbo()) {
 +              if (e_data.draw_grid) {
 +                      DRW_framebuffer_texture_detach(dtxl->depth);
 +                      DRW_draw_pass(psl->grid);
 +                      DRW_framebuffer_texture_attach(dfbl->default_fb, dtxl->depth, 0, 0);
 +              }
 +
 +              /* Combine with scene buffer last */
 +              DRW_draw_pass(psl->outlines_resolve);
 +      }
 +
 +      /* This has to be freed only after drawing empties! */
 +      if (stl->g_data->image_plane_map) {
 +              BLI_ghash_free(stl->g_data->image_plane_map, NULL, MEM_freeN);
 +      }
 +}
 +
 +void OBJECT_collection_settings_create(IDProperty *props)
 +{
 +      BLI_assert(props &&
 +                 props->type == IDP_GROUP &&
 +                 props->subtype == IDP_GROUP_SUB_MODE_OBJECT);
 +      BKE_collection_engine_property_add_int(props, "show_wire", false);
 +      BKE_collection_engine_property_add_int(props, "show_backface_culling", false);
 +}
 +
 +static const DrawEngineDataSize OBJECT_data_size = DRW_VIEWPORT_DATA_SIZE(OBJECT_Data);
 +
 +DrawEngineType draw_engine_object_type = {
 +      NULL, NULL,
 +      N_("ObjectMode"),
 +      &OBJECT_data_size,
 +      &OBJECT_engine_init,
 +      &OBJECT_engine_free,
 +      &OBJECT_cache_init,
 +      &OBJECT_cache_populate,
 +      NULL,
 +      NULL,
 +      &OBJECT_draw_scene,
 +      NULL,
 +      NULL,
 +};
index 5c96c13ebedeb749522b6a5b1eded4d065163a6c,8d5c4684c2b92b070b11da12f2cae394cb070418..56279522c8826fb91755bad09f68b6744d7bb2e7
  #include "DNA_material_types.h"
  #include "DNA_mesh_types.h"
  #include "DNA_meta_types.h"
- #include "DNA_object_fluidsim.h"
- #include "DNA_object_force.h"
+ #include "DNA_object_fluidsim_types.h"
+ #include "DNA_object_force_types.h"
  #include "DNA_object_types.h"
 +#include "DNA_lightprobe_types.h"
  #include "DNA_scene_types.h"
  #include "DNA_vfont_types.h"
  #include "DNA_actuator_types.h"
index 6a34f493caf9b7d5ebb76c01ebfd91b82e1ab0b7,0000000000000000000000000000000000000000..e76be448be42ffeb1acda533ba100bc4d0c0db5c
mode 100644,000000..100644
--- /dev/null
@@@ -1,118 -1,0 +1,118 @@@
- #include "DNA_object_force.h"
 +/*
 + * ***** BEGIN GPL LICENSE BLOCK *****
 + *
 + * This program is free software; you can redistribute it and/or
 + * modify it under the terms of the GNU General Public License
 + * as published by the Free Software Foundation; either version 2
 + * of the License, or (at your option) any later version.
 + *
 + * This program is distributed in the hope that it will be useful,
 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 + * GNU General Public License for more details.
 + *
 + * You should have received a copy of the GNU General Public License
 + * along with this program; if not, write to the Free Software Foundation,
 + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 + *
 + * ***** END GPL LICENSE BLOCK *****
 + */
 +
 +/** \file blender/editors/space_view3d/view3d_manipulator_forcefield.c
 + *  \ingroup spview3d
 + */
 +
 +
 +#include "BLI_blenlib.h"
 +#include "BLI_math.h"
 +#include "BLI_utildefines.h"
 +
 +#include "BKE_context.h"
 +#include "BKE_object.h"
 +
 +#include "DNA_object_types.h"
++#include "DNA_object_force_types.h"
 +
 +#include "ED_screen.h"
 +#include "ED_manipulator_library.h"
 +
 +#include "UI_resources.h"
 +
 +#include "MEM_guardedalloc.h"
 +
 +#include "RNA_access.h"
 +
 +#include "WM_api.h"
 +#include "WM_types.h"
 +
 +#include "view3d_intern.h"  /* own include */
 +
 +/* -------------------------------------------------------------------- */
 +
 +/** \name Force Field Manipulators
 + * \{ */
 +
 +static bool WIDGETGROUP_forcefield_poll(const bContext *C, wmManipulatorGroupType *UNUSED(wgt))
 +{
 +      Object *ob = CTX_data_active_object(C);
 +
 +      return (ob && ob->pd && ob->pd->forcefield);
 +}
 +
 +static void WIDGETGROUP_forcefield_setup(const bContext *UNUSED(C), wmManipulatorGroup *mgroup)
 +{
 +      /* only wind effector for now */
 +      wmManipulatorWrapper *wwrapper = MEM_mallocN(sizeof(wmManipulatorWrapper), __func__);
 +      mgroup->customdata = wwrapper;
 +
 +      wwrapper->manipulator = WM_manipulator_new("MANIPULATOR_WT_arrow_3d", mgroup, NULL);
 +      wmManipulator *mpr = wwrapper->manipulator;
 +      RNA_enum_set(mpr->ptr, "draw_options",  ED_MANIPULATOR_ARROW_STYLE_CONSTRAINED);
 +      ED_manipulator_arrow3d_set_ui_range(mpr, -200.0f, 200.0f);
 +      ED_manipulator_arrow3d_set_range_fac(mpr, 6.0f);
 +
 +      UI_GetThemeColor3fv(TH_MANIPULATOR_PRIMARY, mpr->color);
 +      UI_GetThemeColor3fv(TH_MANIPULATOR_HI, mpr->color_hi);
 +}
 +
 +static void WIDGETGROUP_forcefield_refresh(const bContext *C, wmManipulatorGroup *mgroup)
 +{
 +      wmManipulatorWrapper *wwrapper = mgroup->customdata;
 +      wmManipulator *mpr = wwrapper->manipulator;
 +      Object *ob = CTX_data_active_object(C);
 +      PartDeflect *pd = ob->pd;
 +
 +      if (pd->forcefield == PFIELD_WIND) {
 +              const float size = (ob->type == OB_EMPTY) ? ob->empty_drawsize : 1.0f;
 +              const float ofs[3] = {0.0f, -size, 0.0f};
 +              PointerRNA field_ptr;
 +
 +              RNA_pointer_create(&ob->id, &RNA_FieldSettings, pd, &field_ptr);
 +              WM_manipulator_set_matrix_location(mpr, ob->obmat[3]);
 +              WM_manipulator_set_matrix_rotation_from_z_axis(mpr, ob->obmat[2]);
 +              WM_manipulator_set_matrix_offset_location(mpr, ofs);
 +              WM_manipulator_set_flag(mpr, WM_MANIPULATOR_HIDDEN, false);
 +              WM_manipulator_target_property_def_rna(mpr, "offset", &field_ptr, "strength", -1);
 +      }
 +      else {
 +              WM_manipulator_set_flag(mpr, WM_MANIPULATOR_HIDDEN, true);
 +      }
 +}
 +
 +void VIEW3D_WGT_force_field(wmManipulatorGroupType *wgt)
 +{
 +      wgt->name = "Force Field Widgets";
 +      wgt->idname = "VIEW3D_WGT_force_field";
 +
 +      wgt->flag |= (WM_MANIPULATORGROUPTYPE_PERSISTENT |
 +                    WM_MANIPULATORGROUPTYPE_3D |
 +                    WM_MANIPULATORGROUPTYPE_SCALE |
 +                    WM_MANIPULATORGROUPTYPE_DEPTH_3D);
 +
 +      wgt->poll = WIDGETGROUP_forcefield_poll;
 +      wgt->setup = WIDGETGROUP_forcefield_setup;
 +      wgt->refresh = WIDGETGROUP_forcefield_refresh;
 +}
 +
 +/** \} */
 +
index 5a5c99724fe3409d29902e7b8b5ff1f67047a008,6ed2534f1522527a899480385e5be569073ca6e2..29a5c2c3dd6953a9431093c913ae41822780162b
@@@ -2101,9 -2087,31 +2102,31 @@@ static void tag_dependend_objects_for_r
                                        else if (md->type == eModifierType_Shrinkwrap) {
                                                ShrinkwrapModifierData *smd = (ShrinkwrapModifierData *)md;
                                                if (smd->target  && smd->target->type == OB_MESH) {
 -                                                      DAG_id_tag_update(&smd->target->id, OB_RECALC_DATA);
 +                                                      DEG_id_tag_update(&smd->target->id, OB_RECALC_DATA);
                                                }
                                        }
 -                                                                      DAG_id_tag_update(&part->dup_ob->id, OB_RECALC_DATA);
+                                       else if (md->type == eModifierType_ParticleSystem) {
+                                               ParticleSystemModifierData *psmd = (ParticleSystemModifierData *)md;
+                                               ParticleSystem *psys = psmd->psys;
+                                               ParticleSettings *part = psys->part;
+                                               switch (part->ren_as) {
+                                                       case PART_DRAW_OB:
+                                                               if (part->dup_ob != NULL) {
 -                                                                              DAG_id_tag_update(&go->ob->id, OB_RECALC_DATA);
++                                                                      DEG_id_tag_update(&part->dup_ob->id, OB_RECALC_DATA);
+                                                               }
+                                                               break;
+                                                       case PART_DRAW_GR:
+                                                               if (part->dup_group != NULL) {
+                                                                       for (GroupObject *go = part->dup_group->gobject.first;
+                                                                            go != NULL;
+                                                                            go = go->next)
+                                                                       {
++                                                                              DEG_id_tag_update(&go->ob->id, OB_RECALC_DATA);
+                                                                       }
+                                                               }
+                                                               break;
+                                               }
+                                       }
                                }
                        }
                }