Merge branch 'master' into blender2.8
authorBrecht Van Lommel <brechtvanlommel@gmail.com>
Fri, 15 Jun 2018 21:04:35 +0000 (23:04 +0200)
committerBrecht Van Lommel <brechtvanlommel@gmail.com>
Fri, 15 Jun 2018 21:16:49 +0000 (23:16 +0200)
The Eevee AO node supports the new Normal socket, but ignores Distance,
Samples, Inside and Only Local settings.

15 files changed:
1  2 
intern/cycles/blender/addon/version_update.py
intern/cycles/blender/blender_shader.cpp
intern/cycles/render/nodes.cpp
intern/cycles/render/nodes.h
release/scripts/startup/nodeitems_builtins.py
source/blender/blenkernel/BKE_blender_version.h
source/blender/blenloader/intern/versioning_270.c
source/blender/blenloader/intern/versioning_280.c
source/blender/draw/engines/eevee/shaders/lit_surface_frag.glsl
source/blender/editors/space_node/drawnode.c
source/blender/gpu/shaders/gpu_shader_material.glsl
source/blender/makesdna/DNA_node_types.h
source/blender/makesrna/intern/rna_nodetree.c
source/blender/nodes/NOD_static_types.h
source/blender/nodes/shader/nodes/node_shader_ambient_occlusion.c

@@@ -430,22 -462,14 +464,26 @@@ def do_versions(self)
          # Switch to squared roughness convention
          square_roughness_nodes_insert()
  
 -    if bpy.data.version <= (2, 79, 4):
 +    if bpy.data.version <= (2, 80, 15):
 +        # Copy cycles hair settings to internal settings
 +        for part in bpy.data.particles:
 +            cpart = part.get("cycles", None)
 +            if cpart:
 +                part.shape = cpart.get("shape", 0.0)
 +                part.root_radius = cpart.get("root_width", 1.0)
 +                part.tip_radius = cpart.get("tip_width", 0.0)
 +                part.radius_scale = cpart.get("radius_scale", 0.01)
 +                part.use_close_tip = cpart.get("use_closetip", True)
 +
-     for world in bpy.data.worlds:
-         cworld = world.cycles
-         # World MIS
-         if not cworld.is_property_set("sampling_method"):
-             if cworld.get("sample_as_light", False):
-                 cworld.sampling_method = 'MANUAL'
-             else:
-                 cworld.sampling_method = 'NONE'
++    if bpy.data.version <= (2, 79, 4) or \
++       (bpy.data.version >= (2, 80, 0) and bpy.data.version <= (2, 80, 18)):
+         for world in bpy.data.worlds:
+             cworld = world.cycles
+             # World MIS
+             if not cworld.is_property_set("sampling_method"):
+                 if cworld.get("sample_as_light", False):
+                     cworld.sampling_method = 'MANUAL'
+                 else:
+                     cworld.sampling_method = 'NONE'
+         ambient_occlusion_nodes_relink()
Simple merge
Simple merge
@@@ -192,31 -224,29 +193,30 @@@ shader_node_categories = 
          NodeItem("ShaderNodeOutputLineStyle", poll=line_style_shader_nodes_poll),
          NodeItem("NodeGroupOutput", poll=group_input_output_item_poll),
          ]),
 -    ShaderNewNodeCategory("SH_NEW_SHADER", "Shader", items=[
 -        NodeItem("ShaderNodeMixShader"),
 -        NodeItem("ShaderNodeAddShader"),
 -        NodeItem("ShaderNodeBsdfDiffuse", poll=object_shader_nodes_poll),
 -        NodeItem("ShaderNodeBsdfPrincipled", poll=object_shader_nodes_poll),
 -        NodeItem("ShaderNodeBsdfGlossy", poll=object_shader_nodes_poll),
 -        NodeItem("ShaderNodeBsdfTransparent", poll=object_shader_nodes_poll),
 -        NodeItem("ShaderNodeBsdfRefraction", poll=object_shader_nodes_poll),
 -        NodeItem("ShaderNodeBsdfGlass", poll=object_shader_nodes_poll),
 -        NodeItem("ShaderNodeBsdfTranslucent", poll=object_shader_nodes_poll),
 -        NodeItem("ShaderNodeBsdfAnisotropic", poll=object_shader_nodes_poll),
 -        NodeItem("ShaderNodeBsdfVelvet", poll=object_shader_nodes_poll),
 -        NodeItem("ShaderNodeBsdfToon", poll=object_shader_nodes_poll),
 -        NodeItem("ShaderNodeSubsurfaceScattering", poll=object_shader_nodes_poll),
 -        NodeItem("ShaderNodeEmission", poll=object_shader_nodes_poll),
 -        NodeItem("ShaderNodeBsdfHair", poll=object_shader_nodes_poll),
 +    ShaderNodeCategory("SH_NEW_SHADER", "Shader", items=[
 +        NodeItem("ShaderNodeMixShader", poll=eevee_cycles_shader_nodes_poll),
 +        NodeItem("ShaderNodeAddShader", poll=eevee_cycles_shader_nodes_poll),
 +        NodeItem("ShaderNodeBsdfDiffuse", poll=object_eevee_cycles_shader_nodes_poll),
 +        NodeItem("ShaderNodeBsdfPrincipled", poll=object_eevee_cycles_shader_nodes_poll),
 +        NodeItem("ShaderNodeBsdfGlossy", poll=object_eevee_cycles_shader_nodes_poll),
 +        NodeItem("ShaderNodeBsdfTransparent", poll=object_eevee_cycles_shader_nodes_poll),
 +        NodeItem("ShaderNodeBsdfRefraction", poll=object_eevee_cycles_shader_nodes_poll),
 +        NodeItem("ShaderNodeBsdfGlass", poll=object_eevee_cycles_shader_nodes_poll),
 +        NodeItem("ShaderNodeBsdfTranslucent", poll=object_cycles_shader_nodes_poll),
 +        NodeItem("ShaderNodeBsdfAnisotropic", poll=object_cycles_shader_nodes_poll),
 +        NodeItem("ShaderNodeBsdfVelvet", poll=object_cycles_shader_nodes_poll),
 +        NodeItem("ShaderNodeBsdfToon", poll=object_cycles_shader_nodes_poll),
 +        NodeItem("ShaderNodeSubsurfaceScattering", poll=object_eevee_cycles_shader_nodes_poll),
 +        NodeItem("ShaderNodeEmission", poll=object_eevee_cycles_shader_nodes_poll),
 +        NodeItem("ShaderNodeBsdfHair", poll=object_cycles_shader_nodes_poll),
          NodeItem("ShaderNodeBackground", poll=world_shader_nodes_poll),
-         NodeItem("ShaderNodeAmbientOcclusion", poll=object_eevee_cycles_shader_nodes_poll),
 -        NodeItem("ShaderNodeHoldout", poll=object_shader_nodes_poll),
 -        NodeItem("ShaderNodeVolumeAbsorption"),
 -        NodeItem("ShaderNodeVolumeScatter"),
 +        NodeItem("ShaderNodeHoldout", poll=object_cycles_shader_nodes_poll),
 +        NodeItem("ShaderNodeVolumeAbsorption", poll=eevee_cycles_shader_nodes_poll),
 +        NodeItem("ShaderNodeVolumeScatter", poll=eevee_cycles_shader_nodes_poll),
          NodeItem("ShaderNodeVolumePrincipled"),
 +        NodeItem("ShaderNodeEeveeSpecular", poll=object_eevee_shader_nodes_poll),
          ]),
 -    ShaderNewNodeCategory("SH_NEW_TEXTURE", "Texture", items=[
 +    ShaderNodeCategory("SH_NEW_TEXTURE", "Texture", items=[
          NodeItem("ShaderNodeTexImage"),
          NodeItem("ShaderNodeTexEnvironment"),
          NodeItem("ShaderNodeTexSky"),
  /* these lines are grep'd, watch out for our not-so-awesome regex
   * and keep comment above the defines.
   * Use STRINGIFY() rather than defining with quotes */
 -#define BLENDER_VERSION         279
 -#define BLENDER_SUBVERSION      5
 -/* Several breakages with 270, e.g. constraint deg vs rad */
 -#define BLENDER_MINVERSION      270
 -#define BLENDER_MINSUBVERSION   6
 +#define BLENDER_VERSION         280
- #define BLENDER_SUBVERSION      17
++#define BLENDER_SUBVERSION      18
 +/* Several breakages with 280, e.g. collections vs layers */
 +#define BLENDER_MINVERSION      280
 +#define BLENDER_MINSUBVERSION   0
  
  /* used by packaging tools */
  /* can be left blank, otherwise a,b,c... etc with no quotes */
index e7d4e4f,0000000..0324161
mode 100644,000000..100644
--- /dev/null
@@@ -1,1602 -1,0 +1,1603 @@@
-       {
 +/*
 + * ***** 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.
 + *
 + * Contributor(s): Dalai Felinto
 + *
 + * ***** END GPL LICENSE BLOCK *****
 + *
 + */
 +
 +/** \file blender/blenloader/intern/versioning_280.c
 + *  \ingroup blenloader
 + */
 +
 +/* allow readfile to use deprecated functionality */
 +#define DNA_DEPRECATED_ALLOW
 +
 +#include <string.h>
 +#include <float.h>
 +
 +#include "BLI_listbase.h"
 +#include "BLI_math.h"
 +#include "BLI_mempool.h"
 +#include "BLI_string.h"
 +#include "BLI_string_utf8.h"
 +#include "BLI_utildefines.h"
 +
 +#include "DNA_object_types.h"
 +#include "DNA_camera_types.h"
 +#include "DNA_constraint_types.h"
 +#include "DNA_gpu_types.h"
 +#include "DNA_group_types.h"
 +#include "DNA_lamp_types.h"
 +#include "DNA_layer_types.h"
 +#include "DNA_lightprobe_types.h"
 +#include "DNA_material_types.h"
 +#include "DNA_mesh_types.h"
 +#include "DNA_particle_types.h"
 +#include "DNA_scene_types.h"
 +#include "DNA_screen_types.h"
 +#include "DNA_view3d_types.h"
 +#include "DNA_genfile.h"
 +#include "DNA_workspace_types.h"
 +
 +#include "BKE_collection.h"
 +#include "BKE_constraint.h"
 +#include "BKE_customdata.h"
 +#include "BKE_freestyle.h"
 +#include "BKE_idprop.h"
 +#include "BKE_image.h"
 +#include "BKE_layer.h"
 +#include "BKE_main.h"
 +#include "BKE_mesh.h"
 +#include "BKE_node.h"
 +#include "BKE_report.h"
 +#include "BKE_scene.h"
 +#include "BKE_screen.h"
 +#include "BKE_studiolight.h"
 +#include "BKE_workspace.h"
 +
 +#include "BLO_readfile.h"
 +#include "readfile.h"
 +
 +#include "MEM_guardedalloc.h"
 +
 +static bScreen *screen_parent_find(const bScreen *screen)
 +{
 +      /* can avoid lookup if screen state isn't maximized/full (parent and child store the same state) */
 +      if (ELEM(screen->state, SCREENMAXIMIZED, SCREENFULL)) {
 +              for (const ScrArea *sa = screen->areabase.first; sa; sa = sa->next) {
 +                      if (sa->full && sa->full != screen) {
 +                              BLI_assert(sa->full->state == screen->state);
 +                              return sa->full;
 +                      }
 +              }
 +      }
 +
 +      return NULL;
 +}
 +
 +static void do_version_workspaces_create_from_screens(Main *bmain)
 +{
 +      for (bScreen *screen = bmain->screen.first; screen; screen = screen->id.next) {
 +              const bScreen *screen_parent = screen_parent_find(screen);
 +              Scene *scene = screen->scene;
 +              WorkSpace *workspace;
 +              ViewLayer *layer = BLI_findlink(&scene->view_layers, scene->r.actlay);
 +              if (screen->temp) {
 +                      continue;
 +              }
 +              if (!layer) {
 +                      layer = BKE_view_layer_default_view(scene);
 +              }
 +
 +              if (screen_parent) {
 +                      /* fullscreen with "Back to Previous" option, don't create
 +                       * a new workspace, add layout workspace containing parent */
 +                      workspace = BLI_findstring(
 +                              &bmain->workspaces, screen_parent->id.name + 2, offsetof(ID, name) + 2);
 +              }
 +              else {
 +                      workspace = BKE_workspace_add(bmain, screen->id.name + 2);
 +              }
 +              BKE_workspace_layout_add(bmain, workspace, screen, screen->id.name + 2);
 +              BKE_workspace_view_layer_set(workspace, layer, scene);
 +      }
 +}
 +
 +static void do_version_area_change_space_to_space_action(ScrArea *area, const Scene *scene)
 +{
 +      SpaceType *stype = BKE_spacetype_from_id(SPACE_ACTION);
 +      SpaceAction *saction = (SpaceAction *)stype->new(area, scene);
 +      ARegion *region_channels;
 +
 +      /* Properly free current regions */
 +      for (ARegion *region = area->regionbase.first; region; region = region->next) {
 +              BKE_area_region_free(area->type, region);
 +      }
 +      BLI_freelistN(&area->regionbase);
 +
 +      area->type = stype;
 +      area->spacetype = stype->spaceid;
 +
 +      BLI_addhead(&area->spacedata, saction);
 +      area->regionbase = saction->regionbase;
 +      BLI_listbase_clear(&saction->regionbase);
 +
 +      /* Different defaults for timeline */
 +      region_channels = BKE_area_find_region_type(area, RGN_TYPE_CHANNELS);
 +      region_channels->flag |= RGN_FLAG_HIDDEN;
 +
 +      saction->mode = SACTCONT_TIMELINE;
 +      saction->ads.flag |= ADS_FLAG_SUMMARY_COLLAPSED;
 +}
 +
 +/**
 + * \brief After lib-link versioning for new workspace design.
 + *
 + * - Adds a workspace for (almost) each screen of the old file
 + *   and adds the needed workspace-layout to wrap the screen.
 + * - Active screen isn't stored directly in window anymore, but in the active workspace.
 + * - Active scene isn't stored in screen anymore, but in window.
 + * - Create workspace instance hook for each window.
 + *
 + * \note Some of the created workspaces might be deleted again in case of reading the default startup.blend.
 + */
 +static void do_version_workspaces_after_lib_link(Main *bmain)
 +{
 +      BLI_assert(BLI_listbase_is_empty(&bmain->workspaces));
 +
 +      do_version_workspaces_create_from_screens(bmain);
 +
 +      for (wmWindowManager *wm = bmain->wm.first; wm; wm = wm->id.next) {
 +              for (wmWindow *win = wm->windows.first; win; win = win->next) {
 +                      bScreen *screen_parent = screen_parent_find(win->screen);
 +                      bScreen *screen = screen_parent ? screen_parent : win->screen;
 +                      WorkSpace *workspace = BLI_findstring(&bmain->workspaces, screen->id.name + 2, offsetof(ID, name) + 2);
 +                      ListBase *layouts = BKE_workspace_layouts_get(workspace);
 +
 +                      win->workspace_hook = BKE_workspace_instance_hook_create(bmain);
 +
 +                      BKE_workspace_active_set(win->workspace_hook, workspace);
 +                      BKE_workspace_active_layout_set(win->workspace_hook, layouts->first);
 +
 +                      win->scene = screen->scene;
 +                      /* Deprecated from now on! */
 +                      win->screen = NULL;
 +              }
 +      }
 +
 +      for (bScreen *screen = bmain->screen.first; screen; screen = screen->id.next) {
 +              /* Deprecated from now on! */
 +              BLI_freelistN(&screen->scene->transform_spaces);
 +              screen->scene = NULL;
 +      }
 +}
 +
 +#ifdef USE_COLLECTION_COMPAT_28
 +enum {
 +      COLLECTION_DEPRECATED_VISIBLE    = (1 << 0),
 +      COLLECTION_DEPRECATED_VIEWPORT   = (1 << 0),
 +      COLLECTION_DEPRECATED_SELECTABLE = (1 << 1),
 +      COLLECTION_DEPRECATED_DISABLED   = (1 << 2),
 +      COLLECTION_DEPRECATED_RENDER     = (1 << 3),
 +};
 +
 +static void do_version_view_layer_visibility(ViewLayer *view_layer)
 +{
 +      /* Convert from deprecated VISIBLE flag to DISABLED */
 +      LayerCollection *lc;
 +      for (lc = view_layer->layer_collections.first;
 +           lc;
 +           lc = lc->next)
 +      {
 +              if (lc->flag & COLLECTION_DEPRECATED_DISABLED) {
 +                      lc->flag &= ~COLLECTION_DEPRECATED_DISABLED;
 +              }
 +
 +              if ((lc->flag & COLLECTION_DEPRECATED_VISIBLE) == 0) {
 +                      lc->flag |= COLLECTION_DEPRECATED_DISABLED;
 +              }
 +
 +              lc->flag |= COLLECTION_DEPRECATED_VIEWPORT | COLLECTION_DEPRECATED_RENDER;
 +      }
 +}
 +
 +static void do_version_layer_collection_pre(
 +        ViewLayer *view_layer,
 +        ListBase *lb,
 +        GSet *enabled_set,
 +        GSet *selectable_set)
 +{
 +      /* Convert from deprecated DISABLED to new layer collection and collection flags */
 +      for (LayerCollection *lc = lb->first; lc; lc = lc->next) {
 +              if (lc->scene_collection) {
 +                      if (!(lc->flag & COLLECTION_DEPRECATED_DISABLED)) {
 +                              BLI_gset_insert(enabled_set, lc->scene_collection);
 +                      }
 +                      if (lc->flag & COLLECTION_DEPRECATED_SELECTABLE) {
 +                              BLI_gset_insert(selectable_set, lc->scene_collection);
 +                      }
 +              }
 +
 +              do_version_layer_collection_pre(view_layer, &lc->layer_collections, enabled_set, selectable_set);
 +      }
 +}
 +
 +static void do_version_layer_collection_post(
 +        ViewLayer *view_layer,
 +        ListBase *lb,
 +        GSet *enabled_set,
 +        GSet *selectable_set,
 +        GHash *collection_map)
 +{
 +      /* Apply layer collection exclude flags. */
 +      for (LayerCollection *lc = lb->first; lc; lc = lc->next) {
 +              if (!(lc->collection->flag & COLLECTION_IS_MASTER)) {
 +                      SceneCollection *sc = BLI_ghash_lookup(collection_map, lc->collection);
 +                      const bool enabled = (sc && BLI_gset_haskey(enabled_set, sc));
 +                      const bool selectable = (sc && BLI_gset_haskey(selectable_set, sc));
 +
 +                      if (!enabled) {
 +                              lc->flag |= LAYER_COLLECTION_EXCLUDE;
 +                      }
 +                      if (enabled && !selectable) {
 +                              lc->collection->flag |= COLLECTION_RESTRICT_SELECT;
 +                      }
 +              }
 +
 +              do_version_layer_collection_post(
 +                      view_layer, &lc->layer_collections, enabled_set, selectable_set, collection_map);
 +      }
 +}
 +
 +static void do_version_scene_collection_convert(
 +        Main *bmain,
 +        ID *id,
 +        SceneCollection *sc,
 +        Collection *collection,
 +        GHash *collection_map)
 +{
 +      if (collection_map) {
 +              BLI_ghash_insert(collection_map, collection, sc);
 +      }
 +
 +      for (SceneCollection *nsc = sc->scene_collections.first; nsc;) {
 +              SceneCollection *nsc_next = nsc->next;
 +              Collection *ncollection = BKE_collection_add(bmain, collection, nsc->name);
 +              ncollection->id.lib = id->lib;
 +              do_version_scene_collection_convert(bmain, id, nsc, ncollection, collection_map);
 +              nsc = nsc_next;
 +      }
 +
 +      for (LinkData *link = sc->objects.first; link; link = link->next) {
 +              Object *ob = link->data;
 +              if (ob) {
 +                      BKE_collection_object_add(bmain, collection, ob);
 +                      id_us_min(&ob->id);
 +              }
 +      }
 +
 +      BLI_freelistN(&sc->objects);
 +      MEM_freeN(sc);
 +}
 +
 +static void do_version_group_collection_to_collection(Main *bmain, Collection *group)
 +{
 +      /* Convert old 2.8 group collections to new unified collections. */
 +      if (group->collection) {
 +              do_version_scene_collection_convert(bmain, &group->id, group->collection, group, NULL);
 +      }
 +
 +      group->collection = NULL;
 +      group->view_layer = NULL;
 +      id_fake_user_set(&group->id);
 +}
 +
 +static void do_version_scene_collection_to_collection(Main *bmain, Scene *scene)
 +{
 +      /* Convert old 2.8 scene collections to new unified collections. */
 +
 +      /* Temporarily clear view layers so we don't do any layer collection syncing
 +       * and destroy old flags that we want to restore. */
 +      ListBase view_layers = scene->view_layers;
 +      BLI_listbase_clear(&scene->view_layers);
 +
 +      if (!scene->master_collection) {
 +              scene->master_collection = BKE_collection_master_add();
 +      }
 +
 +      /* Convert scene collections. */
 +      GHash *collection_map = BLI_ghash_new(BLI_ghashutil_ptrhash, BLI_ghashutil_ptrcmp, __func__);
 +      if (scene->collection) {
 +              do_version_scene_collection_convert(bmain, &scene->id, scene->collection, scene->master_collection, collection_map);
 +              scene->collection = NULL;
 +      }
 +
 +      scene->view_layers = view_layers;
 +
 +      /* Convert layer collections. */
 +      ViewLayer *view_layer;
 +      for (view_layer = scene->view_layers.first; view_layer; view_layer = view_layer->next) {
 +              GSet *enabled_set = BLI_gset_new(BLI_ghashutil_ptrhash, BLI_ghashutil_ptrcmp, __func__);
 +              GSet *selectable_set = BLI_gset_new(BLI_ghashutil_ptrhash, BLI_ghashutil_ptrcmp, __func__);
 +
 +              do_version_layer_collection_pre(
 +                      view_layer, &view_layer->layer_collections, enabled_set, selectable_set);
 +
 +              BKE_layer_collection_sync(scene, view_layer);
 +
 +              do_version_layer_collection_post(
 +                      view_layer, &view_layer->layer_collections, enabled_set, selectable_set, collection_map);
 +
 +              BLI_gset_free(enabled_set, NULL);
 +              BLI_gset_free(selectable_set, NULL);
 +
 +              BKE_layer_collection_sync(scene, view_layer);
 +      }
 +
 +      BLI_ghash_free(collection_map, NULL, NULL);
 +}
 +#endif
 +
 +
 +enum {
 +      DO_VERSION_COLLECTION_VISIBLE     = 0,
 +      DO_VERSION_COLLECTION_HIDE        = 1,
 +      DO_VERSION_COLLECTION_HIDE_RENDER = 2,
 +      DO_VERSION_COLLECTION_HIDE_ALL    = 3,
 +};
 +
 +static void do_version_layers_to_collections(Main *bmain, Scene *scene)
 +{
 +      /* Since we don't have access to FileData we check the (always valid) first
 +       * render layer instead. */
 +      if (!scene->master_collection) {
 +              scene->master_collection = BKE_collection_master_add();
 +      }
 +
 +      if (scene->view_layers.first) {
 +              return;
 +      }
 +
 +      /* Create collections from layers. */
 +      Collection *collection_master = BKE_collection_master(scene);
 +
 +      struct DoVersionSceneCollections {
 +              Collection *collections[20];
 +              int created;
 +              const char *suffix;
 +              int flag;
 +      } collections[] =
 +      {
 +              {
 +                      .collections = {NULL},
 +                      .created = 0,
 +                      .suffix = "",
 +                      .flag = 0,
 +              },
 +              {
 +                      .collections = {NULL},
 +                      .created = 0,
 +                      .suffix = " - Hide Viewport",
 +                      .flag = COLLECTION_RESTRICT_VIEW,
 +              },
 +              {
 +                      .collections = {NULL},
 +                      .created = 0,
 +                      .suffix = " - Hide Render",
 +                      .flag = COLLECTION_RESTRICT_RENDER,
 +              },
 +              {
 +                      .collections = {NULL},
 +                      .created = 0,
 +                      .suffix = " - Hide Render All",
 +                      .flag = COLLECTION_RESTRICT_VIEW | COLLECTION_RESTRICT_RENDER,
 +              }
 +      };
 +
 +      for (int layer = 0; layer < 20; layer++) {
 +              for (Base *base = scene->base.first; base; base = base->next) {
 +                      if (base->lay & (1 << layer)) {
 +                              int collection_index = -1;
 +                              if ((base->object->restrictflag & OB_RESTRICT_VIEW) &&
 +                                  (base->object->restrictflag & OB_RESTRICT_RENDER))
 +                              {
 +                                      collection_index = DO_VERSION_COLLECTION_HIDE_ALL;
 +                              }
 +                              else if (base->object->restrictflag & OB_RESTRICT_VIEW) {
 +                                      collection_index = DO_VERSION_COLLECTION_HIDE;
 +                              }
 +                              else if (base->object->restrictflag & OB_RESTRICT_RENDER) {
 +                                      collection_index = DO_VERSION_COLLECTION_HIDE_RENDER;
 +                              }
 +                              else {
 +                                      collection_index = DO_VERSION_COLLECTION_VISIBLE;
 +                              }
 +
 +                              /* Create collections when needed only. */
 +                              if ((collections[collection_index].created & (1 << layer)) == 0) {
 +                                      char name[MAX_NAME];
 +
 +                                      if ((collections[DO_VERSION_COLLECTION_VISIBLE].created & (1 << layer)) == 0) {
 +                                              BLI_snprintf(name,
 +                                                           sizeof(collection_master->id.name),
 +                                                           "Collection %d%s",
 +                                                           layer + 1,
 +                                                           collections[DO_VERSION_COLLECTION_VISIBLE].suffix);
 +
 +                                              Collection *collection = BKE_collection_add(bmain, collection_master, name);
 +                                              collection->id.lib = scene->id.lib;
 +                                              collection->flag |= collections[DO_VERSION_COLLECTION_VISIBLE].flag;
 +                                              collections[DO_VERSION_COLLECTION_VISIBLE].collections[layer] = collection;
 +                                              collections[DO_VERSION_COLLECTION_VISIBLE].created |= (1 << layer);
 +
 +                                              if (!(scene->lay & (1 << layer))) {
 +                                                      collection->flag |= COLLECTION_RESTRICT_VIEW | COLLECTION_RESTRICT_RENDER;
 +                                              }
 +                                      }
 +
 +                                      if (collection_index != DO_VERSION_COLLECTION_VISIBLE) {
 +                                              Collection *collection_parent;
 +                                              collection_parent = collections[DO_VERSION_COLLECTION_VISIBLE].collections[layer];
 +                                              BLI_snprintf(name,
 +                                                           sizeof(collection_master->id.name),
 +                                                           "Collection %d%s",
 +                                                           layer + 1,
 +                                                           collections[collection_index].suffix);
 +
 +                                              Collection *collection = BKE_collection_add(bmain, collection_parent, name);
 +                                              collection->id.lib = scene->id.lib;
 +                                              collection->flag |= collections[collection_index].flag;
 +                                              collections[collection_index].collections[layer] = collection;
 +                                              collections[collection_index].created |= (1 << layer);
 +
 +                                              if (!(scene->lay & (1 << layer))) {
 +                                                      collection->flag |= COLLECTION_RESTRICT_VIEW | COLLECTION_RESTRICT_RENDER;
 +                                              }
 +                                      }
 +                              }
 +
 +                              /* Note usually this would do slow collection syncing for view layers,
 +                               * but since no view layers exists yet at this point it's fast. */
 +                              BKE_collection_object_add(
 +                                      bmain,
 +                                      collections[collection_index].collections[layer], base->object);
 +                      }
 +
 +                      if (base->flag & SELECT) {
 +                              base->object->flag |= SELECT;
 +                      }
 +                      else {
 +                              base->object->flag &= ~SELECT;
 +                      }
 +              }
 +      }
 +
 +      /* Re-order the nested hidden collections. */
 +      CollectionChild *child_parent = collection_master->children.first;
 +      Collection *collection_parent = (child_parent) ? child_parent->collection : NULL;
 +
 +      for (int layer = 0; layer < 20; layer++) {
 +              if (collections[DO_VERSION_COLLECTION_VISIBLE].created & (1 << layer)) {
 +                      CollectionChild *hide_child = BLI_findptr(
 +                              &collection_parent->children,
 +                              collections[DO_VERSION_COLLECTION_HIDE].collections[layer],
 +                              offsetof(CollectionChild, collection));
 +
 +                      if ((collections[DO_VERSION_COLLECTION_HIDE].created & (1 << layer)) &&
 +                          (hide_child != collection_parent->children.first))
 +                      {
 +                              BLI_listbase_swaplinks(
 +                                      &collection_parent->children,
 +                                      hide_child,
 +                                      collection_parent->children.first);
 +                      }
 +
 +                      CollectionChild *hide_all_child = BLI_findptr(
 +                              &collection_parent->children,
 +                              collections[DO_VERSION_COLLECTION_HIDE_ALL].collections[layer],
 +                              offsetof(CollectionChild, collection));
 +
 +                      if ((collections[DO_VERSION_COLLECTION_HIDE_ALL].created & (1 << layer)) &&
 +                          (hide_all_child != collection_parent->children.last))
 +                      {
 +                              BLI_listbase_swaplinks(
 +                                      &collection_parent->children,
 +                                      hide_all_child,
 +                                      collection_parent->children.last);
 +                      }
 +
 +                      child_parent = child_parent->next;
 +                      collection_parent = (child_parent) ? child_parent->collection : NULL;
 +              }
 +      }
 +      BLI_assert(collection_parent == NULL);
 +
 +      /* Handle legacy render layers. */
 +      bool have_override = false;
 +
 +      for (SceneRenderLayer *srl = scene->r.layers.first; srl; srl = srl->next) {
 +              ViewLayer *view_layer = BKE_view_layer_add(scene, srl->name);
 +
 +              if (srl->samples != 0) {
 +                      have_override = true;
 +
 +                      /* It is up to the external engine to handle
 +                       * its own doversion in this case. */
 +                      BKE_override_view_layer_int_add(
 +                              view_layer,
 +                              ID_SCE,
 +                              "samples",
 +                              srl->samples);
 +              }
 +
 +              if (srl->mat_override) {
 +                      have_override = true;
 +
 +                      BKE_override_view_layer_datablock_add(
 +                              view_layer,
 +                              ID_MA,
 +                              "self",
 +                              (ID *)srl->mat_override);
 +              }
 +
 +              if (srl->layflag & SCE_LAY_DISABLE) {
 +                      view_layer->flag &= ~VIEW_LAYER_RENDER;
 +              }
 +
 +              if ((srl->layflag & SCE_LAY_FRS) == 0) {
 +                      view_layer->flag &= ~VIEW_LAYER_FREESTYLE;
 +              }
 +
 +              /* XXX If we are to keep layflag it should be merged with flag (dfelinto). */
 +              view_layer->layflag = srl->layflag;
 +              /* XXX Not sure if we should keep the passes (dfelinto). */
 +              view_layer->passflag = srl->passflag;
 +              view_layer->pass_xor = srl->pass_xor;
 +              view_layer->pass_alpha_threshold = srl->pass_alpha_threshold;
 +
 +              BKE_freestyle_config_free(&view_layer->freestyle_config, true);
 +              view_layer->freestyle_config = srl->freestyleConfig;
 +              view_layer->id_properties = srl->prop;
 +
 +              /* Set exclusion and overrides. */
 +              for (int layer = 0; layer < 20; layer++) {
 +                      if (collections[DO_VERSION_COLLECTION_VISIBLE].created & (1 << layer)) {
 +                              Collection *collection = collections[DO_VERSION_COLLECTION_VISIBLE].collections[layer];
 +                              LayerCollection *lc = BKE_layer_collection_first_from_scene_collection(view_layer, collection);
 +
 +                              if (srl->lay_exclude & (1 << layer)) {
 +                                      /* Disable excluded layer. */
 +                                      have_override = true;
 +                                      lc->flag |= LAYER_COLLECTION_EXCLUDE;
 +                                      for (LayerCollection *nlc = lc->layer_collections.first; nlc; nlc = nlc->next) {
 +                                              nlc->flag |= LAYER_COLLECTION_EXCLUDE;
 +                                      }
 +                              }
 +                              else if ((scene->lay & srl->lay & ~(srl->lay_exclude) & (1 << layer)) ||
 +                                       (srl->lay_zmask & (scene->lay | srl->lay_exclude) & (1 << layer)))
 +                              {
 +                                      if (srl->lay_zmask & (1 << layer)) {
 +                                              have_override = true;
 +
 +                                              BKE_override_layer_collection_boolean_add(
 +                                                      lc,
 +                                                      ID_OB,
 +                                                      "cycles.is_holdout",
 +                                                      true);
 +                                      }
 +
 +                                      if ((srl->lay & (1 << layer)) == 0) {
 +                                              have_override = true;
 +
 +                                              BKE_override_layer_collection_boolean_add(
 +                                                      lc,
 +                                                      ID_OB,
 +                                                      "cycles_visibility.camera",
 +                                                      false);
 +                                      }
 +                              }
 +
 +                              LayerCollection *nlc = lc->layer_collections.first;
 +                              for (int j = 1; j < 4; j++) {
 +                                      if (collections[j].created & (1 << layer)) {
 +                                              nlc = nlc->next;
 +                                      }
 +                              }
 +                              BLI_assert(nlc == NULL);
 +                      }
 +              }
 +
 +              /* for convenience set the same active object in all the layers */
 +              if (scene->basact) {
 +                      view_layer->basact = BKE_view_layer_base_find(view_layer, scene->basact->object);
 +              }
 +
 +              for (Base *base = view_layer->object_bases.first; base; base = base->next) {
 +                      if ((base->flag & BASE_SELECTABLED) && (base->object->flag & SELECT)) {
 +                              base->flag |= BASE_SELECTED;
 +                      }
 +              }
 +      }
 +
 +      BLI_freelistN(&scene->r.layers);
 +
 +      /* If render layers included overrides, we also create a vanilla
 +       * viewport layer without them. */
 +      if (have_override) {
 +              ViewLayer *view_layer = BKE_view_layer_add(scene, "Viewport");
 +
 +              /* Make it first in the list. */
 +              BLI_remlink(&scene->view_layers, view_layer);
 +              BLI_addhead(&scene->view_layers, view_layer);
 +
 +              /* If we ported all the original render layers, we don't need to make the viewport layer renderable. */
 +              if (!BLI_listbase_is_single(&scene->view_layers)) {
 +                      view_layer->flag &= ~VIEW_LAYER_RENDER;
 +              }
 +
 +              /* convert active base */
 +              if (scene->basact) {
 +                      view_layer->basact = BKE_view_layer_base_find(view_layer, scene->basact->object);
 +              }
 +
 +              /* convert selected bases */
 +              for (Base *base = view_layer->object_bases.first; base; base = base->next) {
 +                      if ((base->flag & BASE_SELECTABLED) && (base->object->flag & SELECT)) {
 +                              base->flag |= BASE_SELECTED;
 +                      }
 +
 +                      /* keep lay around for forward compatibility (open those files in 2.79) */
 +                      base->lay = base->object->lay;
 +              }
 +      }
 +
 +      /* remove bases once and for all */
 +      for (Base *base = scene->base.first; base; base = base->next) {
 +              id_us_min(&base->object->id);
 +      }
 +
 +      BLI_freelistN(&scene->base);
 +      scene->basact = NULL;
 +}
 +
 +void do_versions_after_linking_280(Main *bmain)
 +{
 +      bool use_collection_compat_28 = true;
 +
 +      if (!MAIN_VERSION_ATLEAST(bmain, 280, 0)) {
 +              use_collection_compat_28 = false;
 +
 +              /* Convert group layer visibility flags to hidden nested collection. */
 +              for (Collection *collection = bmain->collection.first; collection; collection = collection->id.next) {
 +                      /* Add fake user for all existing groups. */
 +                      id_fake_user_set(&collection->id);
 +
 +                      if (collection->flag & (COLLECTION_RESTRICT_VIEW | COLLECTION_RESTRICT_RENDER)) {
 +                              continue;
 +                      }
 +
 +                      Collection *collection_hidden = NULL;
 +                      for (CollectionObject *cob = collection->gobject.first, *cob_next = NULL; cob; cob = cob_next) {
 +                              cob_next = cob->next;
 +                              Object *ob = cob->ob;
 +
 +                              if (!(ob->lay & collection->layer)) {
 +                                      if (collection_hidden == NULL) {
 +                                              collection_hidden = BKE_collection_add(bmain, collection, "Hidden");
 +                                              collection_hidden->id.lib = collection->id.lib;
 +                                              collection_hidden->flag |= COLLECTION_RESTRICT_VIEW | COLLECTION_RESTRICT_RENDER;
 +                                      }
 +
 +                                      BKE_collection_object_add(bmain, collection_hidden, ob);
 +                                      BKE_collection_object_remove(bmain, collection, ob, true);
 +                              }
 +                      }
 +              }
 +
 +              /* Convert layers to collections. */
 +              for (Scene *scene = bmain->scene.first; scene; scene = scene->id.next) {
 +                      do_version_layers_to_collections(bmain, scene);
 +              }
 +      }
 +
 +      if (!MAIN_VERSION_ATLEAST(bmain, 280, 0)) {
 +              for (bScreen *screen = bmain->screen.first; screen; screen = screen->id.next) {
 +                      /* same render-layer as do_version_workspaces_after_lib_link will activate,
 +                       * so same layer as BKE_view_layer_from_workspace_get would return */
 +                      ViewLayer *layer = screen->scene->view_layers.first;
 +
 +                      for (ScrArea *sa = screen->areabase.first; sa; sa = sa->next) {
 +                              for (SpaceLink *space = sa->spacedata.first; space; space = space->next) {
 +                                      if (space->spacetype == SPACE_OUTLINER) {
 +                                              SpaceOops *soutliner = (SpaceOops *)space;
 +
 +                                              soutliner->outlinevis = SO_VIEW_LAYER;
 +
 +                                              if (BLI_listbase_count_at_most(&layer->layer_collections, 2) == 1) {
 +                                                      if (soutliner->treestore == NULL) {
 +                                                              soutliner->treestore = BLI_mempool_create(
 +                                                                      sizeof(TreeStoreElem), 1, 512, BLI_MEMPOOL_ALLOW_ITER);
 +                                                      }
 +
 +                                                      /* Create a tree store element for the collection. This is normally
 +                                                       * done in check_persistent (outliner_tree.c), but we need to access
 +                                                       * it here :/ (expand element if it's the only one) */
 +                                                      TreeStoreElem *tselem = BLI_mempool_calloc(soutliner->treestore);
 +                                                      tselem->type = TSE_LAYER_COLLECTION;
 +                                                      tselem->id = layer->layer_collections.first;
 +                                                      tselem->nr = tselem->used = 0;
 +                                                      tselem->flag &= ~TSE_CLOSED;
 +                                              }
 +                                      }
 +                              }
 +                      }
 +              }
 +      }
 +
 +      /* New workspace design */
 +      if (!MAIN_VERSION_ATLEAST(bmain, 280, 1)) {
 +              do_version_workspaces_after_lib_link(bmain);
 +      }
 +
 +      if (!MAIN_VERSION_ATLEAST(bmain, 280, 2)) {
 +              /* Cleanup any remaining SceneRenderLayer data for files that were created
 +               * with Blender 2.8 before the SceneRenderLayer > RenderLayer refactor. */
 +              for (Scene *scene = bmain->scene.first; scene; scene = scene->id.next) {
 +                      for (SceneRenderLayer *srl = scene->r.layers.first; srl; srl = srl->next) {
 +                              if (srl->prop) {
 +                                      IDP_FreeProperty(srl->prop);
 +                                      MEM_freeN(srl->prop);
 +                              }
 +                              BKE_freestyle_config_free(&srl->freestyleConfig, true);
 +                      }
 +                      BLI_freelistN(&scene->r.layers);
 +              }
 +      }
 +
 +      if (!MAIN_VERSION_ATLEAST(bmain, 280, 3)) {
 +              /* Due to several changes to particle RNA and draw code particles from older files may no longer
 +               * be visible. Here we correct this by setting a default draw size for those files. */
 +              for (Object *object = bmain->object.first; object; object = object->id.next) {
 +                      for (ParticleSystem *psys = object->particlesystem.first; psys; psys = psys->next) {
 +                              if (psys->part->draw_size == 0.0f) {
 +                                      psys->part->draw_size = 0.1f;
 +                              }
 +                      }
 +              }
 +      }
 +
 +      if (!MAIN_VERSION_ATLEAST(bmain, 280, 4)) {
 +              for (Object *object = bmain->object.first; object; object = object->id.next) {
 +#ifndef VERSION_280_SUBVERSION_4
 +                      /* If any object already has an initialized value for
 +                       * duplicator_visibility_flag it means we've already doversioned it.
 +                       * TODO(all) remove the VERSION_280_SUBVERSION_4 code once the subversion was bumped. */
 +                      if (object->duplicator_visibility_flag != 0) {
 +                              break;
 +                      }
 +#endif
 +                      if (object->particlesystem.first) {
 +                              object->duplicator_visibility_flag = OB_DUPLI_FLAG_VIEWPORT;
 +                              for (ParticleSystem *psys = object->particlesystem.first; psys; psys = psys->next) {
 +                                      if (psys->part->draw & PART_DRAW_EMITTER) {
 +                                              object->duplicator_visibility_flag |= OB_DUPLI_FLAG_RENDER;
 +#ifndef VERSION_280_SUBVERSION_4
 +                                              psys->part->draw &= ~PART_DRAW_EMITTER;
 +#else
 +                                              break;
 +#endif
 +                                      }
 +                              }
 +                      }
 +                      else if (object->transflag & OB_DUPLI) {
 +                              object->duplicator_visibility_flag = OB_DUPLI_FLAG_VIEWPORT;
 +                      }
 +                      else {
 +                              object->duplicator_visibility_flag = OB_DUPLI_FLAG_VIEWPORT | OB_DUPLI_FLAG_RENDER;
 +                      }
 +              }
 +      }
 +
 +      /* SpaceTime & SpaceLogic removal/replacing */
 +      if (!MAIN_VERSION_ATLEAST(bmain, 280, 9)) {
 +              const wmWindowManager *wm = bmain->wm.first;
 +              const Scene *scene = bmain->scene.first;
 +
 +              if (wm != NULL) {
 +                      /* Action editors need a scene for creation. First, update active
 +                       * screens using the active scene of the window they're displayed in.
 +                       * Next, update remaining screens using first scene in main listbase. */
 +
 +                      for (wmWindow *win = wm->windows.first; win; win = win->next) {
 +                              const bScreen *screen = BKE_workspace_active_screen_get(win->workspace_hook);
 +                              for (ScrArea *area = screen->areabase.first; area; area = area->next) {
 +                                      if (ELEM(area->butspacetype, SPACE_TIME, SPACE_LOGIC)) {
 +                                              do_version_area_change_space_to_space_action(area, win->scene);
 +
 +                                              /* Don't forget to unset! */
 +                                              area->butspacetype = SPACE_EMPTY;
 +                                      }
 +                              }
 +                      }
 +              }
 +              if (scene != NULL) {
 +                      for (bScreen *screen = bmain->screen.first; screen; screen = screen->id.next) {
 +                              for (ScrArea *area = screen->areabase.first; area; area = area->next) {
 +                                      if (ELEM(area->butspacetype, SPACE_TIME, SPACE_LOGIC)) {
 +                                              /* Areas that were already handled won't be handled again */
 +                                              do_version_area_change_space_to_space_action(area, scene);
 +
 +                                              /* Don't forget to unset! */
 +                                              area->butspacetype = SPACE_EMPTY;
 +                                      }
 +                              }
 +                      }
 +              }
 +      }
 +
 +#ifdef USE_COLLECTION_COMPAT_28
 +      if (use_collection_compat_28 && !MAIN_VERSION_ATLEAST(bmain, 280, 14)) {
 +              for (Collection *group = bmain->collection.first; group; group = group->id.next) {
 +                      do_version_group_collection_to_collection(bmain, group);
 +              }
 +
 +              for (Scene *scene = bmain->scene.first; scene; scene = scene->id.next) {
 +                      do_version_scene_collection_to_collection(bmain, scene);
 +              }
 +      }
 +#endif
 +}
 +
 +void blo_do_versions_280(FileData *fd, Library *UNUSED(lib), Main *bmain)
 +{
 +      bool use_collection_compat_28 = true;
 +
 +      if (!MAIN_VERSION_ATLEAST(bmain, 280, 0)) {
 +              use_collection_compat_28 = false;
 +
 +              for (Scene *scene = bmain->scene.first; scene; scene = scene->id.next) {
 +                      scene->r.gauss = 1.5f;
 +              }
 +      }
 +
 +      if (!MAIN_VERSION_ATLEAST(bmain, 280, 1)) {
 +              if (!DNA_struct_elem_find(fd->filesdna, "Lamp", "float", "bleedexp")) {
 +                      for (Lamp *la = bmain->lamp.first; la; la = la->id.next) {
 +                              la->bleedexp = 2.5f;
 +                      }
 +              }
 +
 +              if (!DNA_struct_elem_find(fd->filesdna, "GPUDOFSettings", "float", "ratio")) {
 +                      for (Camera *ca = bmain->camera.first; ca; ca = ca->id.next) {
 +                              ca->gpu_dof.ratio = 1.0f;
 +                      }
 +              }
 +
 +              /* MTexPoly now removed. */
 +              if (DNA_struct_find(fd->filesdna, "MTexPoly")) {
 +                      const int cd_mtexpoly = 15;  /* CD_MTEXPOLY, deprecated */
 +                      for (Mesh *me = bmain->mesh.first; me; me = me->id.next) {
 +                              /* If we have UV's, so this file will have MTexPoly layers too! */
 +                              if (me->mloopuv != NULL) {
 +                                      CustomData_update_typemap(&me->pdata);
 +                                      CustomData_free_layers(&me->pdata, cd_mtexpoly, me->totpoly);
 +                                      BKE_mesh_update_customdata_pointers(me, false);
 +                              }
 +                      }
 +              }
 +      }
 +
 +      if (!MAIN_VERSION_ATLEAST(bmain, 280, 2)) {
 +              if (!DNA_struct_elem_find(fd->filesdna, "Lamp", "float", "cascade_max_dist")) {
 +                      for (Lamp *la = bmain->lamp.first; la; la = la->id.next) {
 +                              la->cascade_max_dist = 1000.0f;
 +                              la->cascade_count = 4;
 +                              la->cascade_exponent = 0.8f;
 +                              la->cascade_fade = 0.1f;
 +                      }
 +              }
 +
 +              if (!DNA_struct_elem_find(fd->filesdna, "Lamp", "float", "contact_dist")) {
 +                      for (Lamp *la = bmain->lamp.first; la; la = la->id.next) {
 +                              la->contact_dist = 1.0f;
 +                              la->contact_bias = 0.03f;
 +                              la->contact_spread = 0.2f;
 +                              la->contact_thickness = 0.5f;
 +                      }
 +              }
 +
 +              if (!DNA_struct_elem_find(fd->filesdna, "LightProbe", "float", "vis_bias")) {
 +                      for (LightProbe *probe = bmain->lightprobe.first; probe; probe = probe->id.next) {
 +                              probe->vis_bias = 1.0f;
 +                              probe->vis_blur = 0.2f;
 +                      }
 +              }
 +
 +              typedef enum eNTreeDoVersionErrors {
 +                      NTREE_DOVERSION_NO_ERROR = 0,
 +                      NTREE_DOVERSION_NEED_OUTPUT = (1 << 0),
 +                      NTREE_DOVERSION_TRANSPARENCY_EMISSION = (1 << 1),
 +              } eNTreeDoVersionErrors;
 +
 +              /* Eevee shader nodes renamed because of the output node system.
 +               * Note that a new output node is not being added here, because it would be overkill
 +               * to handle this case in lib_verify_nodetree.
 +               *
 +               * Also, metallic node is now unified into the principled node. */
 +              eNTreeDoVersionErrors error = NTREE_DOVERSION_NO_ERROR;
 +
 +              FOREACH_NODETREE(bmain, ntree, id) {
 +                      if (ntree->type == NTREE_SHADER) {
 +                              for (bNode *node = ntree->nodes.first; node; node = node->next) {
 +                                      if (node->type == 194 /* SH_NODE_EEVEE_METALLIC */ &&
 +                                          STREQ(node->idname, "ShaderNodeOutputMetallic"))
 +                                      {
 +                                              BLI_strncpy(node->idname, "ShaderNodeEeveeMetallic", sizeof(node->idname));
 +                                              error |= NTREE_DOVERSION_NEED_OUTPUT;
 +                                      }
 +
 +                                      else if (node->type == SH_NODE_EEVEE_SPECULAR && STREQ(node->idname, "ShaderNodeOutputSpecular")) {
 +                                              BLI_strncpy(node->idname, "ShaderNodeEeveeSpecular", sizeof(node->idname));
 +                                              error |= NTREE_DOVERSION_NEED_OUTPUT;
 +                                      }
 +
 +                                      else if (node->type == 196 /* SH_NODE_OUTPUT_EEVEE_MATERIAL */ &&
 +                                               STREQ(node->idname, "ShaderNodeOutputEeveeMaterial"))
 +                                      {
 +                                              node->type = SH_NODE_OUTPUT_MATERIAL;
 +                                              BLI_strncpy(node->idname, "ShaderNodeOutputMaterial", sizeof(node->idname));
 +                                      }
 +
 +                                      else if (node->type == 194 /* SH_NODE_EEVEE_METALLIC */ &&
 +                                               STREQ(node->idname, "ShaderNodeEeveeMetallic"))
 +                                      {
 +                                              node->type = SH_NODE_BSDF_PRINCIPLED;
 +                                              BLI_strncpy(node->idname, "ShaderNodeBsdfPrincipled", sizeof(node->idname));
 +                                              node->custom1 = SHD_GLOSSY_MULTI_GGX;
 +                                              error |= NTREE_DOVERSION_TRANSPARENCY_EMISSION;
 +                                      }
 +                              }
 +                      }
 +              } FOREACH_NODETREE_END
 +
 +              if (error & NTREE_DOVERSION_NEED_OUTPUT) {
 +                      BKE_report(fd->reports, RPT_ERROR, "Eevee material conversion problem. Error in console");
 +                      printf("You need to connect Principled and Eevee Specular shader nodes to new material output nodes.\n");
 +              }
 +
 +              if (error & NTREE_DOVERSION_TRANSPARENCY_EMISSION) {
 +                      BKE_report(fd->reports, RPT_ERROR, "Eevee material conversion problem. Error in console");
 +                      printf("You need to combine transparency and emission shaders to the converted Principled shader nodes.\n");
 +              }
 +
 +#ifdef USE_COLLECTION_COMPAT_28
 +              if (use_collection_compat_28 &&
 +                  (DNA_struct_elem_find(fd->filesdna, "ViewLayer", "FreestyleConfig", "freestyle_config") == false) &&
 +                  DNA_struct_elem_find(fd->filesdna, "Scene", "ListBase", "view_layers"))
 +              {
 +                      for (Scene *scene = bmain->scene.first; scene; scene = scene->id.next) {
 +                              ViewLayer *view_layer;
 +                              for (view_layer = scene->view_layers.first; view_layer; view_layer = view_layer->next) {
 +                                      view_layer->flag |= VIEW_LAYER_FREESTYLE;
 +                                      view_layer->layflag = 0x7FFF;   /* solid ztra halo edge strand */
 +                                      view_layer->passflag = SCE_PASS_COMBINED | SCE_PASS_Z;
 +                                      view_layer->pass_alpha_threshold = 0.5f;
 +                                      BKE_freestyle_config_init(&view_layer->freestyle_config);
 +                              }
 +                      }
 +              }
 +#endif
 +      }
 +
 +#ifdef USE_COLLECTION_COMPAT_28
 +      if (use_collection_compat_28 && !MAIN_VERSION_ATLEAST(bmain, 280, 3)) {
 +              for (Scene *scene = bmain->scene.first; scene; scene = scene->id.next) {
 +                      ViewLayer *view_layer;
 +                      for (view_layer = scene->view_layers.first; view_layer; view_layer = view_layer->next) {
 +                              do_version_view_layer_visibility(view_layer);
 +                      }
 +              }
 +
 +              for (Collection *group = bmain->collection.first; group; group = group->id.next) {
 +                      if (group->view_layer != NULL) {
 +                              do_version_view_layer_visibility(group->view_layer);
 +                      }
 +              }
 +      }
 +#endif
 +
 +      if (!MAIN_VERSION_ATLEAST(bmain, 280, 6)) {
 +              if (DNA_struct_elem_find(fd->filesdna, "SpaceOops", "int", "filter") == false) {
 +                      bScreen *sc;
 +                      ScrArea *sa;
 +                      SpaceLink *sl;
 +
 +                      /* Update files using invalid (outdated) outlinevis Outliner values. */
 +                      for (sc = bmain->screen.first; sc; sc = sc->id.next) {
 +                              for (sa = sc->areabase.first; sa; sa = sa->next) {
 +                                      for (sl = sa->spacedata.first; sl; sl = sl->next) {
 +                                              if (sl->spacetype == SPACE_OUTLINER) {
 +                                                      SpaceOops *so = (SpaceOops *)sl;
 +
 +                                                      if (!ELEM(so->outlinevis,
 +                                                                SO_SCENES,
 +                                                                SO_LIBRARIES,
 +                                                                SO_SEQUENCE,
 +                                                                SO_DATA_API,
 +                                                                SO_ID_ORPHANS))
 +                                                      {
 +                                                              so->outlinevis = SO_VIEW_LAYER;
 +                                                      }
 +                                              }
 +                                      }
 +                              }
 +                      }
 +              }
 +
 +              if (!DNA_struct_elem_find(fd->filesdna, "LightProbe", "float", "intensity")) {
 +                      for (LightProbe *probe = bmain->lightprobe.first; probe; probe = probe->id.next) {
 +                              probe->intensity = 1.0f;
 +                      }
 +              }
 +
 +              for (Object *ob = bmain->object.first; ob; ob = ob->id.next) {
 +                      bConstraint *con, *con_next;
 +                      con = ob->constraints.first;
 +                      while (con) {
 +                              con_next = con->next;
 +                              if (con->type == 17) { /* CONSTRAINT_TYPE_RIGIDBODYJOINT */
 +                                      BLI_remlink(&ob->constraints, con);
 +                                      BKE_constraint_free_data(con);
 +                                      MEM_freeN(con);
 +                              }
 +                              con = con_next;
 +                      }
 +              }
 +
 +              if (!DNA_struct_elem_find(fd->filesdna, "Scene", "int", "orientation_index_custom")) {
 +                      for (Scene *scene = bmain->scene.first; scene; scene = scene->id.next) {
 +                              scene->orientation_index_custom = -1;
 +                      }
 +              }
 +
 +              for (bScreen *sc = bmain->screen.first; sc; sc = sc->id.next) {
 +                      for (ScrArea *sa = sc->areabase.first; sa; sa = sa->next) {
 +                              for (SpaceLink *sl = sa->spacedata.first; sl; sl = sl->next) {
 +                                      if (sl->spacetype == SPACE_VIEW3D) {
 +                                              View3D *v3d = (View3D *)sl;
 +                                              v3d->shading.light = V3D_LIGHTING_STUDIO;
 +                                              v3d->shading.flag |= V3D_SHADING_OBJECT_OUTLINE;
 +
 +                                              /* Assume (demo) files written with 2.8 want to show
 +                                               * Eevee renders in the viewport. */
 +                                              if (MAIN_VERSION_ATLEAST(bmain, 280, 0)) {
 +                                                      v3d->drawtype = OB_MATERIAL;
 +                                              }
 +                                      }
 +                              }
 +                      }
 +              }
 +      }
 +
 +      if (!MAIN_VERSION_ATLEAST(bmain, 280, 7)) {
 +              /* Render engine storage moved elsewhere and back during 2.8
 +               * development, we assume any files saved in 2.8 had Eevee set
 +               * as scene render engine. */
 +              if (MAIN_VERSION_ATLEAST(bmain, 280, 0)) {
 +                      for (Scene *scene = bmain->scene.first; scene; scene = scene->id.next) {
 +                              BLI_strncpy(scene->r.engine, RE_engine_id_BLENDER_EEVEE, sizeof(scene->r.engine));
 +                      }
 +              }
 +      }
 +
 +      if (!MAIN_VERSION_ATLEAST(bmain, 280, 8)) {
 +              /* Blender Internal removal */
 +              for (Scene *scene = bmain->scene.first; scene; scene = scene->id.next) {
 +                      if (STREQ(scene->r.engine, "BLENDER_RENDER") ||
 +                          STREQ(scene->r.engine, "BLENDER_GAME"))
 +                      {
 +                              BLI_strncpy(scene->r.engine, RE_engine_id_BLENDER_EEVEE, sizeof(scene->r.engine));
 +                      }
 +
 +                      scene->r.bake_mode = 0;
 +              }
 +
 +              for (Tex *tex = bmain->tex.first; tex; tex = tex->id.next) {
 +                      /* Removed envmap, pointdensity, voxeldata, ocean textures. */
 +                      if (ELEM(tex->type, 10, 14, 15, 16)) {
 +                              tex->type = 0;
 +                      }
 +              }
 +      }
 +
 +      if (!MAIN_VERSION_ATLEAST(bmain, 280, 11)) {
 +
 +              /* Remove info editor, but only if at the top of the window. */
 +              for (bScreen *screen = bmain->screen.first; screen; screen = screen->id.next) {
 +                      /* Calculate window width/height from screen vertices */
 +                      int win_width = 0, win_height = 0;
 +                      for (ScrVert *vert = screen->vertbase.first; vert; vert = vert->next) {
 +                              win_width  = MAX2(win_width, vert->vec.x);
 +                              win_height = MAX2(win_height, vert->vec.y);
 +                      }
 +
 +                      for (ScrArea *area = screen->areabase.first, *area_next; area; area = area_next) {
 +                              area_next = area->next;
 +
 +                              if (area->spacetype == SPACE_INFO) {
 +                                      if ((area->v2->vec.y == win_height) && (area->v1->vec.x == 0) && (area->v4->vec.x == win_width)) {
 +                                              BKE_screen_area_free(area);
 +
 +                                              BLI_remlink(&screen->areabase, area);
 +
 +                                              BKE_screen_remove_double_scredges(screen);
 +                                              BKE_screen_remove_unused_scredges(screen);
 +                                              BKE_screen_remove_unused_scrverts(screen);
 +
 +                                              MEM_freeN(area);
 +                                      }
 +                              }
 +                              /* AREA_TEMP_INFO is deprecated from now on, it should only be set for info areas
 +                               * which are deleted above, so don't need to unset it. Its slot/bit can be reused */
 +                      }
 +              }
 +      }
 +
 +      if (!MAIN_VERSION_ATLEAST(bmain, 280, 11)) {
 +              for (Lamp *lamp = bmain->lamp.first; lamp; lamp = lamp->id.next) {
 +                      if (lamp->mode & (1 << 13)) { /* LA_SHAD_RAY */
 +                              lamp->mode |= LA_SHADOW;
 +                              lamp->mode &= ~(1 << 13);
 +                      }
 +              }
 +      }
 +
 +      if (!MAIN_VERSION_ATLEAST(bmain, 280, 12)) {
 +              /* Remove tool property regions. */
 +              for (bScreen *screen = bmain->screen.first; screen; screen = screen->id.next) {
 +                      for (ScrArea *sa = screen->areabase.first; sa; sa = sa->next) {
 +                              for (SpaceLink *sl = sa->spacedata.first; sl; sl = sl->next) {
 +                                      if (ELEM(sl->spacetype, SPACE_VIEW3D, SPACE_CLIP)) {
 +                                              ListBase *regionbase = (sl == sa->spacedata.first) ? &sa->regionbase : &sl->regionbase;
 +
 +                                              for (ARegion *region = regionbase->first, *region_next; region; region = region_next) {
 +                                                      region_next = region->next;
 +
 +                                                      if (region->regiontype == RGN_TYPE_TOOL_PROPS) {
 +                                                              BKE_area_region_free(NULL, region);
 +                                                              BLI_freelinkN(regionbase, region);
 +                                                      }
 +                                              }
 +                                      }
 +                              }
 +                      }
 +              }
 +      }
 +
 +      if (!MAIN_VERSION_ATLEAST(bmain, 280, 13)) {
 +              /* Initialize specular factor. */
 +              if (!DNA_struct_elem_find(fd->filesdna, "Lamp", "float", "spec_fac")) {
 +                      for (Lamp *la = bmain->lamp.first; la; la = la->id.next) {
 +                              la->spec_fac = 1.0f;
 +                      }
 +              }
 +
 +              /* Initialize new view3D options. */
 +              for (bScreen *screen = bmain->screen.first; screen; screen = screen->id.next) {
 +                      for (ScrArea *sa = screen->areabase.first; sa; sa = sa->next) {
 +                              for (SpaceLink *sl = sa->spacedata.first; sl; sl = sl->next) {
 +                                      if (sl->spacetype == SPACE_VIEW3D) {
 +                                              View3D *v3d = (View3D *)sl;
 +                                              v3d->shading.light = V3D_LIGHTING_STUDIO;
 +                                              v3d->shading.color_type = V3D_SHADING_MATERIAL_COLOR;
 +                                              copy_v3_fl(v3d->shading.single_color, 0.8f);
 +                                              v3d->shading.shadow_intensity = 0.5;
 +
 +                                              v3d->overlay.backwire_opacity = 0.5f;
 +                                              v3d->overlay.normals_length = 0.1f;
 +                                              v3d->overlay.flag = V3D_OVERLAY_LOOK_DEV;
 +                                      }
 +                              }
 +                      }
 +              }
 +
 +              if (!DNA_struct_find(fd->filesdna, "View3DCursor")) {
 +                      for (Scene *scene = bmain->scene.first; scene; scene = scene->id.next) {
 +                              unit_qt(scene->cursor.rotation);
 +                      }
 +                      for (bScreen *screen = bmain->screen.first; screen; screen = screen->id.next) {
 +                              for (ScrArea *sa = screen->areabase.first; sa; sa = sa->next) {
 +                                      for (SpaceLink *sl = sa->spacedata.first; sl; sl = sl->next) {
 +                                              if (sl->spacetype == SPACE_VIEW3D) {
 +                                                      View3D *v3d = (View3D *)sl;
 +                                                      unit_qt(v3d->cursor.rotation);
 +                                              }
 +                                      }
 +                              }
 +                      }
 +              }
 +      }
 +
 +      if (!MAIN_VERSION_ATLEAST(bmain, 280, 14)) {
 +              if (!DNA_struct_elem_find(fd->filesdna, "Scene", "SceneDisplay", "display")) {
 +                      /* Initialize new scene.SceneDisplay */
 +                      for (Scene *scene = bmain->scene.first; scene; scene = scene->id.next) {
 +                              copy_v3_v3(scene->display.light_direction, (float[3]){-M_SQRT1_3, -M_SQRT1_3, M_SQRT1_3});
 +                      }
 +              }
 +              if (!DNA_struct_elem_find(fd->filesdna, "SceneDisplay", "float", "shadow_shift")) {
 +                      for (Scene *scene = bmain->scene.first; scene; scene = scene->id.next) {
 +                              scene->display.shadow_shift = 0.1;
 +                      }
 +              }
 +
 +              if (!DNA_struct_elem_find(fd->filesdna, "Object", "ObjectDisplay", "display")) {
 +                      /* Initialize new object.ObjectDisplay */
 +                      for (Object *ob = bmain->object.first; ob; ob = ob->id.next) {
 +                              ob->display.flag = OB_SHOW_SHADOW;
 +                      }
 +              }
 +
 +              if (!DNA_struct_elem_find(fd->filesdna, "ToolSettings", "char", "transform_pivot_point")) {
 +                      for (Scene *scene = bmain->scene.first; scene; scene = scene->id.next) {
 +                              scene->toolsettings->transform_pivot_point = V3D_AROUND_CENTER_MEAN;
 +                      }
 +              }
 +
 +              if (!DNA_struct_find(fd->filesdna, "SceneEEVEE")) {
 +                      for (Scene *scene = bmain->scene.first; scene; scene = scene->id.next) {
 +                              /* First set the default for all the properties. */
 +
 +                              scene->eevee.gi_diffuse_bounces = 3;
 +                              scene->eevee.gi_cubemap_resolution = 512;
 +                              scene->eevee.gi_visibility_resolution = 32;
 +
 +                              scene->eevee.taa_samples = 16;
 +                              scene->eevee.taa_render_samples = 64;
 +
 +                              scene->eevee.sss_samples = 7;
 +                              scene->eevee.sss_jitter_threshold = 0.3f;
 +
 +                              scene->eevee.ssr_quality = 0.25f;
 +                              scene->eevee.ssr_max_roughness = 0.5f;
 +                              scene->eevee.ssr_thickness = 0.2f;
 +                              scene->eevee.ssr_border_fade = 0.075f;
 +                              scene->eevee.ssr_firefly_fac = 10.0f;
 +
 +                              scene->eevee.volumetric_start = 0.1f;
 +                              scene->eevee.volumetric_end = 100.0f;
 +                              scene->eevee.volumetric_tile_size = 8;
 +                              scene->eevee.volumetric_samples = 64;
 +                              scene->eevee.volumetric_sample_distribution = 0.8f;
 +                              scene->eevee.volumetric_light_clamp = 0.0f;
 +                              scene->eevee.volumetric_shadow_samples = 16;
 +
 +                              scene->eevee.gtao_distance = 0.2f;
 +                              scene->eevee.gtao_factor = 1.0f;
 +                              scene->eevee.gtao_quality = 0.25f;
 +
 +                              scene->eevee.bokeh_max_size = 100.0f;
 +                              scene->eevee.bokeh_threshold = 1.0f;
 +
 +                              copy_v3_fl(scene->eevee.bloom_color, 1.0f);
 +                              scene->eevee.bloom_threshold = 0.8f;
 +                              scene->eevee.bloom_knee = 0.5f;
 +                              scene->eevee.bloom_intensity = 0.8f;
 +                              scene->eevee.bloom_radius = 6.5f;
 +                              scene->eevee.bloom_clamp = 1.0f;
 +
 +                              scene->eevee.motion_blur_samples = 8;
 +                              scene->eevee.motion_blur_shutter = 1.0f;
 +
 +                              scene->eevee.shadow_method = SHADOW_ESM;
 +                              scene->eevee.shadow_cube_size = 512;
 +                              scene->eevee.shadow_cascade_size = 1024;
 +
 +                              scene->eevee.flag =
 +                                      SCE_EEVEE_VOLUMETRIC_LIGHTS |
 +                                      SCE_EEVEE_VOLUMETRIC_COLORED |
 +                                      SCE_EEVEE_GTAO_BENT_NORMALS |
 +                                      SCE_EEVEE_GTAO_BOUNCE |
 +                                      SCE_EEVEE_TAA_REPROJECTION |
 +                                      SCE_EEVEE_SSR_HALF_RESOLUTION;
 +
 +
 +                              /* If the file is pre-2.80 move on. */
 +                              if (scene->layer_properties == NULL) {
 +                                      continue;
 +                              }
 +
 +                              /* Now we handle eventual properties that may be set in the file. */
 +#define EEVEE_GET_BOOL(_props, _name, _flag) \
 +                              { \
 +                                      IDProperty *_idprop = IDP_GetPropertyFromGroup(_props, #_name); \
 +                                      if (_idprop != NULL) { \
 +                                              const int _value = IDP_Int(_idprop); \
 +                                              if (_value) { \
 +                                                      scene->eevee.flag |= _flag; \
 +                                              } \
 +                                              else { \
 +                                                      scene->eevee.flag &= ~_flag; \
 +                                              } \
 +                                      } \
 +                              }
 +
 +#define EEVEE_GET_INT(_props, _name) \
 +                              { \
 +                                      IDProperty *_idprop = IDP_GetPropertyFromGroup(_props, #_name); \
 +                                      if (_idprop != NULL) { \
 +                                              scene->eevee._name = IDP_Int(_idprop); \
 +                                      } \
 +                              }
 +
 +#define EEVEE_GET_FLOAT(_props, _name) \
 +                              { \
 +                                      IDProperty *_idprop = IDP_GetPropertyFromGroup(_props, #_name); \
 +                                      if (_idprop != NULL) { \
 +                                              scene->eevee._name = IDP_Float(_idprop); \
 +                                      } \
 +                              }
 +
 +#define EEVEE_GET_FLOAT_ARRAY(_props, _name, _length) \
 +                              { \
 +                                      IDProperty *_idprop = IDP_GetPropertyFromGroup(_props, #_name); \
 +                                      if (_idprop != NULL) { \
 +                                              const float *_values = IDP_Array(_idprop); \
 +                                              for (int _i = 0; _i < _length; _i++) { \
 +                                                      scene->eevee._name [_i] = _values[_i]; \
 +                                              } \
 +                                      } \
 +                              }
 +
 +                              IDProperty *props = IDP_GetPropertyFromGroup(scene->layer_properties, RE_engine_id_BLENDER_EEVEE);
 +                              EEVEE_GET_BOOL(props, volumetric_enable, SCE_EEVEE_VOLUMETRIC_ENABLED);
 +                              EEVEE_GET_BOOL(props, volumetric_lights, SCE_EEVEE_VOLUMETRIC_LIGHTS);
 +                              EEVEE_GET_BOOL(props, volumetric_shadows, SCE_EEVEE_VOLUMETRIC_SHADOWS);
 +                              EEVEE_GET_BOOL(props, volumetric_colored_transmittance, SCE_EEVEE_VOLUMETRIC_COLORED);
 +                              EEVEE_GET_BOOL(props, gtao_enable, SCE_EEVEE_GTAO_ENABLED);
 +                              EEVEE_GET_BOOL(props, gtao_use_bent_normals, SCE_EEVEE_GTAO_BENT_NORMALS);
 +                              EEVEE_GET_BOOL(props, gtao_bounce, SCE_EEVEE_GTAO_BOUNCE);
 +                              EEVEE_GET_BOOL(props, dof_enable, SCE_EEVEE_DOF_ENABLED);
 +                              EEVEE_GET_BOOL(props, bloom_enable, SCE_EEVEE_BLOOM_ENABLED);
 +                              EEVEE_GET_BOOL(props, motion_blur_enable, SCE_EEVEE_MOTION_BLUR_ENABLED);
 +                              EEVEE_GET_BOOL(props, shadow_high_bitdepth, SCE_EEVEE_SHADOW_HIGH_BITDEPTH);
 +                              EEVEE_GET_BOOL(props, taa_reprojection, SCE_EEVEE_TAA_REPROJECTION);
 +                              EEVEE_GET_BOOL(props, sss_enable, SCE_EEVEE_SSS_ENABLED);
 +                              EEVEE_GET_BOOL(props, sss_separate_albedo, SCE_EEVEE_SSS_SEPARATE_ALBEDO);
 +                              EEVEE_GET_BOOL(props, ssr_enable, SCE_EEVEE_SSR_ENABLED);
 +                              EEVEE_GET_BOOL(props, ssr_refraction, SCE_EEVEE_SSR_REFRACTION);
 +                              EEVEE_GET_BOOL(props, ssr_halfres, SCE_EEVEE_SSR_HALF_RESOLUTION);
 +
 +                              EEVEE_GET_INT(props, gi_diffuse_bounces);
 +                              EEVEE_GET_INT(props, gi_diffuse_bounces);
 +                              EEVEE_GET_INT(props, gi_cubemap_resolution);
 +                              EEVEE_GET_INT(props, gi_visibility_resolution);
 +
 +                              EEVEE_GET_INT(props, taa_samples);
 +                              EEVEE_GET_INT(props, taa_render_samples);
 +
 +                              EEVEE_GET_INT(props, sss_samples);
 +                              EEVEE_GET_FLOAT(props, sss_jitter_threshold);
 +
 +                              EEVEE_GET_FLOAT(props, ssr_quality);
 +                              EEVEE_GET_FLOAT(props, ssr_max_roughness);
 +                              EEVEE_GET_FLOAT(props, ssr_thickness);
 +                              EEVEE_GET_FLOAT(props, ssr_border_fade);
 +                              EEVEE_GET_FLOAT(props, ssr_firefly_fac);
 +
 +                              EEVEE_GET_FLOAT(props, volumetric_start);
 +                              EEVEE_GET_FLOAT(props, volumetric_end);
 +                              EEVEE_GET_INT(props, volumetric_tile_size);
 +                              EEVEE_GET_INT(props, volumetric_samples);
 +                              EEVEE_GET_FLOAT(props, volumetric_sample_distribution);
 +                              EEVEE_GET_FLOAT(props, volumetric_light_clamp);
 +                              EEVEE_GET_INT(props, volumetric_shadow_samples);
 +
 +                              EEVEE_GET_FLOAT(props, gtao_distance);
 +                              EEVEE_GET_FLOAT(props, gtao_factor);
 +                              EEVEE_GET_FLOAT(props, gtao_quality);
 +
 +                              EEVEE_GET_FLOAT(props, bokeh_max_size);
 +                              EEVEE_GET_FLOAT(props, bokeh_threshold);
 +
 +                              EEVEE_GET_FLOAT_ARRAY(props, bloom_color, 3);
 +                              EEVEE_GET_FLOAT(props, bloom_threshold);
 +                              EEVEE_GET_FLOAT(props, bloom_knee);
 +                              EEVEE_GET_FLOAT(props, bloom_intensity);
 +                              EEVEE_GET_FLOAT(props, bloom_radius);
 +                              EEVEE_GET_FLOAT(props, bloom_clamp);
 +
 +                              EEVEE_GET_INT(props, motion_blur_samples);
 +                              EEVEE_GET_FLOAT(props, motion_blur_shutter);
 +
 +                              EEVEE_GET_INT(props, shadow_method);
 +                              EEVEE_GET_INT(props, shadow_cube_size);
 +                              EEVEE_GET_INT(props, shadow_cascade_size);
 +
 +                              /* Cleanup. */
 +                              IDP_FreeProperty(scene->layer_properties);
 +                              MEM_freeN(scene->layer_properties);
 +                              scene->layer_properties = NULL;
 +
 +#undef EEVEE_GET_FLOAT_ARRAY
 +#undef EEVEE_GET_FLOAT
 +#undef EEVEE_GET_INT
 +#undef EEVEE_GET_BOOL
 +                      }
 +              }
 +
 +
 +              if (!MAIN_VERSION_ATLEAST(bmain, 280, 15)) {
 +                      for (Scene *scene = bmain->scene.first; scene; scene = scene->id.next) {
 +                              scene->display.matcap_ssao_distance = 0.2f;
 +                              scene->display.matcap_ssao_attenuation = 1.0f;
 +                              scene->display.matcap_ssao_samples = 16;
 +                      }
 +
 +                      for (bScreen *screen = bmain->screen.first; screen; screen = screen->id.next) {
 +                              for (ScrArea *sa = screen->areabase.first; sa; sa = sa->next) {
 +                                      for (SpaceLink *sl = sa->spacedata.first; sl; sl = sl->next) {
 +                                              if (sl->spacetype == SPACE_OUTLINER) {
 +                                                      SpaceOops *soops = (SpaceOops *)sl;
 +                                                      soops->filter_id_type = ID_GR;
 +                                                      soops->outlinevis = SO_VIEW_LAYER;
 +                                              }
 +                                      }
 +                              }
 +                      }
 +
 +                      for (Scene *scene = bmain->scene.first; scene; scene = scene->id.next) {
 +                              switch (scene->toolsettings->snap_mode) {
 +                                      case 0: scene->toolsettings->snap_mode = SCE_SNAP_MODE_INCREMENT; break;
 +                                      case 1: scene->toolsettings->snap_mode = SCE_SNAP_MODE_VERTEX   ; break;
 +                                      case 2: scene->toolsettings->snap_mode = SCE_SNAP_MODE_EDGE     ; break;
 +                                      case 3: scene->toolsettings->snap_mode = SCE_SNAP_MODE_FACE     ; break;
 +                                      case 4: scene->toolsettings->snap_mode = SCE_SNAP_MODE_VOLUME   ; break;
 +                              }
 +                              switch (scene->toolsettings->snap_node_mode) {
 +                                      case 5: scene->toolsettings->snap_node_mode = SCE_SNAP_MODE_NODE_X; break;
 +                                      case 6: scene->toolsettings->snap_node_mode = SCE_SNAP_MODE_NODE_Y; break;
 +                                      case 7: scene->toolsettings->snap_node_mode = SCE_SNAP_MODE_NODE_X | SCE_SNAP_MODE_NODE_Y; break;
 +                                      case 8: scene->toolsettings->snap_node_mode = SCE_SNAP_MODE_GRID  ; break;
 +                              }
 +                              switch (scene->toolsettings->snap_uv_mode) {
 +                                      case 0: scene->toolsettings->snap_uv_mode = SCE_SNAP_MODE_INCREMENT; break;
 +                                      case 1: scene->toolsettings->snap_uv_mode = SCE_SNAP_MODE_VERTEX   ; break;
 +                              }
 +                      }
 +
 +                      ParticleSettings *part;
 +                      for (part = bmain->particle.first; part; part = part->id.next) {
 +                              part->shape_flag = PART_SHAPE_CLOSE_TIP;
 +                              part->shape = 0.0f;
 +                              part->rad_root = 1.0f;
 +                              part->rad_tip = 0.0f;
 +                              part->rad_scale = 0.01f;
 +                      }
 +              }
 +
 +      }
++
++      if (!MAIN_VERSION_ATLEAST(bmain, 280, 18)) {
 +              if (!DNA_struct_elem_find(fd->filesdna, "Material", "float", "roughness")) {
 +                      for (Material *mat = bmain->mat.first; mat; mat = mat->id.next) {
 +                              if (mat->use_nodes) {
 +                                      if (MAIN_VERSION_ATLEAST(bmain, 280, 0)) {
 +                                              mat->roughness = mat->gloss_mir;
 +                                      }
 +                                      else {
 +                                              mat->roughness = 0.25f;
 +                                      }
 +                              }
 +                              else {
 +                                      mat->roughness = 1.0f - mat->gloss_mir;
 +                              }
 +                              mat->metallic = mat->ray_mirror;
 +                      }
 +
 +                      for (bScreen *screen = bmain->screen.first; screen; screen = screen->id.next) {
 +                              for (ScrArea *sa = screen->areabase.first; sa; sa = sa->next) {
 +                                      for (SpaceLink *sl = sa->spacedata.first; sl; sl = sl->next) {
 +                                              if (sl->spacetype == SPACE_VIEW3D) {
 +                                                      View3D *v3d = (View3D *)sl;
 +                                                      v3d->shading.flag |= V3D_SHADING_SPECULAR_HIGHLIGHT;
 +                                              }
 +                                      }
 +                              }
 +                      }
 +              }
 +
 +              if (!DNA_struct_elem_find(fd->filesdna, "View3DShading", "float", "xray_alpha")) {
 +                      for (bScreen *screen = bmain->screen.first; screen; screen = screen->id.next) {
 +                              for (ScrArea *sa = screen->areabase.first; sa; sa = sa->next) {
 +                                      for (SpaceLink *sl = sa->spacedata.first; sl; sl = sl->next) {
 +                                              if (sl->spacetype == SPACE_VIEW3D) {
 +                                                      View3D *v3d = (View3D *)sl;
 +                                                      v3d->shading.xray_alpha = 0.5f;
 +                                              }
 +                                      }
 +                              }
 +                      }
 +              }
 +              if (!DNA_struct_elem_find(fd->filesdna, "View3DShading", "char", "matcap[256]")) {
 +                      StudioLight *default_matcap = BKE_studiolight_find_first(STUDIOLIGHT_ORIENTATION_VIEWNORMAL);
 +                      /* when loading the internal file is loaded before the matcaps */
 +                      if (default_matcap) {
 +                              for (bScreen *screen = bmain->screen.first; screen; screen = screen->id.next) {
 +                                      for (ScrArea *sa = screen->areabase.first; sa; sa = sa->next) {
 +                                              for (SpaceLink *sl = sa->spacedata.first; sl; sl = sl->next) {
 +                                                      if (sl->spacetype == SPACE_VIEW3D) {
 +                                                              View3D *v3d = (View3D *)sl;
 +                                                              BLI_strncpy(v3d->shading.matcap, default_matcap->name, FILE_MAXFILE);
 +                                                      }
 +                                              }
 +                                      }
 +                              }
 +                      }
 +              }
 +              if (!DNA_struct_elem_find(fd->filesdna, "View3DOverlay", "float", "wireframe_threshold")) {
 +                      for (bScreen *screen = bmain->screen.first; screen; screen = screen->id.next) {
 +                              for (ScrArea *sa = screen->areabase.first; sa; sa = sa->next) {
 +                                      for (SpaceLink *sl = sa->spacedata.first; sl; sl = sl->next) {
 +                                              if (sl->spacetype == SPACE_VIEW3D) {
 +                                                      View3D *v3d = (View3D *)sl;
 +                                                      v3d->overlay.wireframe_threshold = 0.5f;
 +                                              }
 +                                      }
 +                              }
 +                      }
 +              }
 +              if (!DNA_struct_elem_find(fd->filesdna, "View3DShading", "float", "cavity_valley_factor")) {
 +                      for (bScreen *screen = bmain->screen.first; screen; screen = screen->id.next) {
 +                              for (ScrArea *sa = screen->areabase.first; sa; sa = sa->next) {
 +                                      for (SpaceLink *sl = sa->spacedata.first; sl; sl = sl->next) {
 +                                              if (sl->spacetype == SPACE_VIEW3D) {
 +                                                      View3D *v3d = (View3D *)sl;
 +                                                      v3d->shading.cavity_valley_factor = 1.0f;
 +                                                      v3d->shading.cavity_ridge_factor = 1.0f;
 +                                              }
 +                                      }
 +                              }
 +                      }
 +              }
 +              if (!DNA_struct_elem_find(fd->filesdna, "View3DOverlay", "float", "bone_selection_alpha")) {
 +                      for (bScreen *screen = bmain->screen.first; screen; screen = screen->id.next) {
 +                              for (ScrArea *sa = screen->areabase.first; sa; sa = sa->next) {
 +                                      for (SpaceLink *sl = sa->spacedata.first; sl; sl = sl->next) {
 +                                              if (sl->spacetype == SPACE_VIEW3D) {
 +                                                      View3D *v3d = (View3D *)sl;
 +                                                      v3d->overlay.bone_selection_alpha = 0.5f;
 +                                              }
 +                                      }
 +                              }
 +                      }
 +              }
 +              if (!DNA_struct_elem_find(fd->filesdna, "Image", "ListBase", "renderslot")) {
 +                      for (Image *ima = bmain->image.first; ima; ima = ima->id.next) {
 +                              if (ima->type == IMA_TYPE_R_RESULT) {
 +                                      for (int i = 0; i < 8; i++) {
 +                                              RenderSlot *slot = MEM_callocN(sizeof(RenderSlot), "Image Render Slot Init");
 +                                              BLI_snprintf(slot->name, sizeof(slot->name), "Slot %d", i + 1);
 +                                              BLI_addtail(&ima->renderslots, slot);
 +                                      }
 +                              }
 +                      }
 +              }
 +      }
 +}
index ac1dd07,0000000..69c96ee
mode 100644,000000..100644
--- /dev/null
@@@ -1,482 -1,0 +1,482 @@@
- #endif
 +
 +#ifndef LIT_SURFACE_UNIFORM
 +#define LIT_SURFACE_UNIFORM
 +
 +uniform float refractionDepth;
 +
 +#ifndef UTIL_TEX
 +#define UTIL_TEX
 +uniform sampler2DArray utilTex;
 +#define texelfetch_noise_tex(coord) texelFetch(utilTex, ivec3(ivec2(coord) % LUT_SIZE, 2.0), 0)
 +#endif /* UTIL_TEX */
 +
 +in vec3 worldPosition;
 +in vec3 viewPosition;
 +
 +#ifdef USE_FLAT_NORMAL
 +flat in vec3 worldNormal;
 +flat in vec3 viewNormal;
 +#else
 +in vec3 worldNormal;
 +in vec3 viewNormal;
 +#endif
 +
 +#ifdef HAIR_SHADER
 +in vec3 hairTangent; /* world space */
 +in float hairThickTime;
 +in float hairThickness;
 +in float hairTime;
 +flat in int hairStrandID;
 +
 +uniform int hairThicknessRes = 1;
 +#endif
 +
 +#endif /* LIT_SURFACE_UNIFORM */
 +
 +/** AUTO CONFIG
 + * We include the file multiple times each time with a different configuration.
 + * This leads to a lot of deadcode. Better idea would be to only generate the one needed.
 + */
 +#if !defined(SURFACE_DEFAULT)
 +      #define SURFACE_DEFAULT
 +      #define CLOSURE_NAME eevee_closure_default
 +      #define CLOSURE_DIFFUSE
 +      #define CLOSURE_GLOSSY
 +#endif /* SURFACE_DEFAULT */
 +
 +#if !defined(SURFACE_PRINCIPLED) && !defined(CLOSURE_NAME)
 +      #define SURFACE_PRINCIPLED
 +      #define CLOSURE_NAME eevee_closure_principled
 +      #define CLOSURE_DIFFUSE
 +      #define CLOSURE_GLOSSY
 +      #define CLOSURE_CLEARCOAT
 +      #define CLOSURE_REFRACTION
 +      #define CLOSURE_SUBSURFACE
 +#endif /* SURFACE_PRINCIPLED */
 +
 +#if !defined(SURFACE_DIFFUSE) && !defined(CLOSURE_NAME)
 +      #define SURFACE_DIFFUSE
 +      #define CLOSURE_NAME eevee_closure_diffuse
 +      #define CLOSURE_DIFFUSE
 +#endif /* SURFACE_DIFFUSE */
 +
 +#if !defined(SURFACE_SUBSURFACE) && !defined(CLOSURE_NAME)
 +      #define SURFACE_SUBSURFACE
 +      #define CLOSURE_NAME eevee_closure_subsurface
 +      #define CLOSURE_DIFFUSE
 +      #define CLOSURE_SUBSURFACE
 +#endif /* SURFACE_SUBSURFACE */
 +
 +#if !defined(SURFACE_GLOSSY) && !defined(CLOSURE_NAME)
 +      #define SURFACE_GLOSSY
 +      #define CLOSURE_NAME eevee_closure_glossy
 +      #define CLOSURE_GLOSSY
 +#endif /* SURFACE_GLOSSY */
 +
 +#if !defined(SURFACE_REFRACT) && !defined(CLOSURE_NAME)
 +      #define SURFACE_REFRACT
 +      #define CLOSURE_NAME eevee_closure_refraction
 +      #define CLOSURE_REFRACTION
 +#endif /* SURFACE_REFRACT */
 +
 +#if !defined(SURFACE_GLASS) && !defined(CLOSURE_NAME)
 +      #define SURFACE_GLASS
 +      #define CLOSURE_NAME eevee_closure_glass
 +      #define CLOSURE_GLOSSY
 +      #define CLOSURE_REFRACTION
 +#endif /* SURFACE_GLASS */
 +
 +/* Safety : CLOSURE_CLEARCOAT implies CLOSURE_GLOSSY */
 +#ifdef CLOSURE_CLEARCOAT
 +      #ifndef CLOSURE_GLOSSY
 +              #define CLOSURE_GLOSSY
 +      #endif
 +#endif /* CLOSURE_CLEARCOAT */
 +
 +void CLOSURE_NAME(
 +        vec3 N
 +#ifdef CLOSURE_DIFFUSE
 +        , vec3 albedo
 +#endif
 +#ifdef CLOSURE_GLOSSY
 +        , vec3 f0, int ssr_id
 +#endif
 +#if defined(CLOSURE_GLOSSY) || defined(CLOSURE_REFRACTION)
 +        , float roughness
 +#endif
 +#ifdef CLOSURE_CLEARCOAT
 +        , vec3 C_N, float C_intensity, float C_roughness
 +#endif
 +#if defined(CLOSURE_GLOSSY) || defined(CLOSURE_DIFFUSE)
 +        , float ao
 +#endif
 +#ifdef CLOSURE_SUBSURFACE
 +        , float sss_scale
 +#endif
 +#ifdef CLOSURE_REFRACTION
 +        , float ior
 +#endif
 +#ifdef CLOSURE_DIFFUSE
 +        , out vec3 out_diff
 +#endif
 +#ifdef CLOSURE_SUBSURFACE
 +        , out vec3 out_trans
 +#endif
 +#ifdef CLOSURE_GLOSSY
 +        , out vec3 out_spec
 +#endif
 +#ifdef CLOSURE_REFRACTION
 +        , out vec3 out_refr
 +#endif
 +#ifdef CLOSURE_GLOSSY
 +        , out vec3 ssr_spec
 +#endif
 +        )
 +{
 +#ifdef CLOSURE_DIFFUSE
 +      out_diff = vec3(0.0);
 +#endif
 +
 +#ifdef CLOSURE_SUBSURFACE
 +      out_trans = vec3(0.0);
 +#endif
 +
 +#ifdef CLOSURE_GLOSSY
 +      out_spec = vec3(0.0);
 +#endif
 +
 +#ifdef CLOSURE_REFRACTION
 +      out_refr = vec3(0.0);
 +#endif
 +
 +      /* Zero length vectors cause issues, see: T51979. */
 +      float len = length(N);
 +      if (isnan(len)) {
 +              return;
 +      }
 +      N /= len;
 +
 +#ifdef CLOSURE_CLEARCOAT
 +      len = length(C_N);
 +      if (isnan(len)) {
 +              return;
 +      }
 +      C_N /= len;
 +#endif
 +
 +#if defined(CLOSURE_GLOSSY) || defined(CLOSURE_REFRACTION)
 +      roughness = clamp(roughness, 1e-8, 0.9999);
 +      float roughnessSquared = roughness * roughness;
 +#endif
 +
 +#ifdef CLOSURE_CLEARCOAT
 +      C_roughness = clamp(C_roughness, 1e-8, 0.9999);
 +      float C_roughnessSquared = C_roughness * C_roughness;
 +#endif
 +
 +      vec3 V = cameraVec;
 +
 +      vec4 rand = texelFetch(utilTex, ivec3(ivec2(gl_FragCoord.xy) % LUT_SIZE, 2.0), 0);
 +
 +      /* ---------------------------------------------------------------- */
 +      /* -------------------- SCENE LAMPS LIGHTING ---------------------- */
 +      /* ---------------------------------------------------------------- */
 +
 +#ifdef CLOSURE_GLOSSY
 +      vec2 lut_uv = lut_coords(dot(N, V), roughness);
 +      vec4 ltc_mat = texture(utilTex, vec3(lut_uv, 0.0)).rgba;
 +#endif
 +
 +#ifdef CLOSURE_CLEARCOAT
 +      vec2 lut_uv_clear = lut_coords(dot(C_N, V), C_roughness);
 +      vec4 ltc_mat_clear = texture(utilTex, vec3(lut_uv_clear, 0.0)).rgba;
 +      vec3 out_spec_clear = vec3(0.0);
 +#endif
 +
 +      for (int i = 0; i < MAX_LIGHT && i < laNumLight; ++i) {
 +              LightData ld = lights_data[i];
 +
 +              vec4 l_vector; /* Non-Normalized Light Vector with length in last component. */
 +              l_vector.xyz = ld.l_position - worldPosition;
 +              l_vector.w = length(l_vector.xyz);
 +
 +              vec3 l_color_vis = ld.l_color * light_visibility(ld, worldPosition, viewPosition, viewNormal, l_vector);
 +
 +      #ifdef CLOSURE_DIFFUSE
 +              out_diff += l_color_vis * light_diffuse(ld, N, V, l_vector);
 +      #endif
 +
 +      #ifdef CLOSURE_SUBSURFACE
 +              out_trans += ld.l_color * light_translucent(ld, worldPosition, -N, l_vector, sss_scale);
 +      #endif
 +
 +      #ifdef CLOSURE_GLOSSY
 +              out_spec += l_color_vis * light_specular(ld, ltc_mat, N, V, l_vector) * ld.l_spec;
 +      #endif
 +
 +      #ifdef CLOSURE_CLEARCOAT
 +              out_spec_clear += l_color_vis * light_specular(ld, ltc_mat_clear, C_N, V, l_vector) * C_intensity * ld.l_spec;
 +      #endif
 +      }
 +
 +#ifdef CLOSURE_GLOSSY
 +      vec3 brdf_lut_lamps = texture(utilTex, vec3(lut_uv, 1.0)).rgb;
 +      out_spec *= F_area(f0, brdf_lut_lamps.xy) * brdf_lut_lamps.z;
 +#endif
 +
 +#ifdef CLOSURE_CLEARCOAT
 +      vec3 brdf_lut_lamps_clear = texture(utilTex, vec3(lut_uv_clear, 1.0)).rgb;
 +      out_spec_clear *= F_area(f0, brdf_lut_lamps_clear.xy) * brdf_lut_lamps_clear.z;
 +      out_spec += out_spec_clear;
 +#endif
 +
 +      /* ---------------------------------------------------------------- */
 +      /* ---------------- SPECULAR ENVIRONMENT LIGHTING ----------------- */
 +      /* ---------------------------------------------------------------- */
 +
 +      /* Accumulate incomming light from all sources until accumulator is full. Then apply Occlusion and BRDF. */
 +#ifdef CLOSURE_GLOSSY
 +      vec4 spec_accum = vec4(0.0);
 +#endif
 +
 +#ifdef CLOSURE_CLEARCOAT
 +      vec4 C_spec_accum = vec4(0.0);
 +#endif
 +
 +#ifdef CLOSURE_REFRACTION
 +      vec4 refr_accum = vec4(0.0);
 +#endif
 +
 +#ifdef CLOSURE_GLOSSY
 +      /* ---------------------------- */
 +      /*      Planar Reflections      */
 +      /* ---------------------------- */
 +
 +      for (int i = 0; i < MAX_PLANAR && i < prbNumPlanar && spec_accum.a < 0.999; ++i) {
 +              PlanarData pd = planars_data[i];
 +
 +              /* Fade on geometric normal. */
 +              float fade = probe_attenuation_planar(pd, worldPosition, worldNormal, roughness);
 +
 +              if (fade > 0.0) {
 +                      if (!(ssrToggle && ssr_id == outputSsrId)) {
 +                              vec3 spec = probe_evaluate_planar(float(i), pd, worldPosition, N, V, roughness, fade);
 +                              accumulate_light(spec, fade, spec_accum);
 +                      }
 +
 +      #ifdef CLOSURE_CLEARCOAT
 +                      vec3 C_spec = probe_evaluate_planar(float(i), pd, worldPosition, C_N, V, C_roughness, fade);
 +                      accumulate_light(C_spec, fade, C_spec_accum);
 +      #endif
 +
 +              }
 +      }
 +#endif
 +
 +
 +#ifdef CLOSURE_GLOSSY
 +      vec3 spec_dir = get_specular_reflection_dominant_dir(N, V, roughnessSquared);
 +#endif
 +
 +#ifdef CLOSURE_CLEARCOAT
 +      vec3 C_spec_dir = get_specular_reflection_dominant_dir(C_N, V, C_roughnessSquared);
 +#endif
 +
 +#ifdef CLOSURE_REFRACTION
 +      /* Refract the view vector using the depth heuristic.
 +       * Then later Refract a second time the already refracted
 +       * ray using the inverse ior. */
 +      float final_ior = (refractionDepth > 0.0) ? 1.0 / ior : ior;
 +      vec3 refr_V = (refractionDepth > 0.0) ? -refract(-V, N, final_ior) : V;
 +      vec3 refr_pos = (refractionDepth > 0.0) ? line_plane_intersect(worldPosition, refr_V, worldPosition - N * refractionDepth, N) : worldPosition;
 +      vec3 refr_dir = get_specular_refraction_dominant_dir(N, refr_V, roughness, final_ior);
 +#endif
 +
 +
 +#ifdef CLOSURE_REFRACTION
 +      /* ---------------------------- */
 +      /*   Screen Space Refraction    */
 +      /* ---------------------------- */
 +      #ifdef USE_REFRACTION
 +      if (ssrToggle && roughness < ssrMaxRoughness + 0.2) {
 +              /* Find approximated position of the 2nd refraction event. */
 +              vec3 refr_vpos = (refractionDepth > 0.0) ? transform_point(ViewMatrix, refr_pos) : viewPosition;
 +              vec4 trans = screen_space_refraction(refr_vpos, N, refr_V, final_ior, roughnessSquared, rand);
 +              trans.a *= smoothstep(ssrMaxRoughness + 0.2, ssrMaxRoughness, roughness);
 +              accumulate_light(trans.rgb, trans.a, refr_accum);
 +      }
 +      #endif
 +
 +#endif
 +
 +
 +      /* ---------------------------- */
 +      /*       Specular probes        */
 +      /* ---------------------------- */
 +#if defined(CLOSURE_GLOSSY) || defined(CLOSURE_REFRACTION)
 +
 +      #ifdef CLOSURE_REFRACTION
 +              #define ACCUM refr_accum
 +      #else
 +              #define ACCUM spec_accum
 +      #endif
 +
 +      /* Starts at 1 because 0 is world probe */
 +      for (int i = 1; ACCUM.a < 0.999 && i < prbNumRenderCube && i < MAX_PROBE; ++i) {
 +              CubeData cd = probes_data[i];
 +
 +              float fade = probe_attenuation_cube(cd, worldPosition);
 +
 +              if (fade > 0.0) {
 +
 +      #ifdef CLOSURE_GLOSSY
 +                      if (!(ssrToggle && ssr_id == outputSsrId)) {
 +                              vec3 spec = probe_evaluate_cube(float(i), cd, worldPosition, spec_dir, roughness);
 +                              accumulate_light(spec, fade, spec_accum);
 +                      }
 +      #endif
 +
 +      #ifdef CLOSURE_CLEARCOAT
 +                      vec3 C_spec = probe_evaluate_cube(float(i), cd, worldPosition, C_spec_dir, C_roughness);
 +                      accumulate_light(C_spec, fade, C_spec_accum);
 +      #endif
 +
 +      #ifdef CLOSURE_REFRACTION
 +                      vec3 trans = probe_evaluate_cube(float(i), cd, refr_pos, refr_dir, roughnessSquared);
 +                      accumulate_light(trans, fade, refr_accum);
 +      #endif
 +              }
 +      }
 +
 +      #undef ACCUM
 +
 +      /* ---------------------------- */
 +      /*          World Probe         */
 +      /* ---------------------------- */
 +      #ifdef CLOSURE_GLOSSY
 +      if (spec_accum.a < 0.999) {
 +              if (!(ssrToggle && ssr_id == outputSsrId)) {
 +                      vec3 spec = probe_evaluate_world_spec(spec_dir, roughness);
 +                      accumulate_light(spec, 1.0, spec_accum);
 +              }
 +
 +              #ifdef CLOSURE_CLEARCOAT
 +              vec3 C_spec = probe_evaluate_world_spec(C_spec_dir, C_roughness);
 +              accumulate_light(C_spec, 1.0, C_spec_accum);
 +              #endif
 +
 +      }
 +      #endif
 +
 +      #ifdef CLOSURE_REFRACTION
 +      if (refr_accum.a < 0.999) {
 +              vec3 trans = probe_evaluate_world_spec(refr_dir, roughnessSquared);
 +              accumulate_light(trans, 1.0, refr_accum);
 +      }
 +      #endif
 +#endif /* Specular probes */ 
 +
 +
 +      /* ---------------------------- */
 +      /*       Ambient Occlusion      */
 +      /* ---------------------------- */
 +#if defined(CLOSURE_GLOSSY) || defined(CLOSURE_DIFFUSE)
 +      vec3 bent_normal;
 +      float final_ao = occlusion_compute(N, viewPosition, ao, rand, bent_normal);
 +#endif
 +
 +
 +      /* ---------------------------- */
 +      /*        Specular Output       */
 +      /* ---------------------------- */
 +      float NV = dot(N, V);
 +#ifdef CLOSURE_GLOSSY
 +      vec2 uv = lut_coords(NV, roughness);
 +      vec2 brdf_lut = texture(utilTex, vec3(uv, 1.0)).rg;
 +
 +      /* This factor is outputed to be used by SSR in order
 +       * to match the intensity of the regular reflections. */
 +      ssr_spec = F_ibl(f0, brdf_lut);
 +      float spec_occlu = specular_occlusion(NV, final_ao, roughness);
 +
 +      /* The SSR pass recompute the occlusion to not apply it to the SSR */
 +      if (ssrToggle && ssr_id == outputSsrId) {
 +              spec_occlu = 1.0;
 +      }
 +
 +      out_spec += spec_accum.rgb * ssr_spec * spec_occlu * float(specToggle);
 +#endif
 +
 +#ifdef CLOSURE_REFRACTION
 +      float btdf = get_btdf_lut(utilTex, NV, roughness, ior);
 +
 +      out_refr += refr_accum.rgb * btdf;
 +#endif
 +
 +#ifdef CLOSURE_CLEARCOAT
 +      NV = dot(C_N, V);
 +      vec2 C_uv = lut_coords(NV, C_roughness);
 +      vec2 C_brdf_lut = texture(utilTex, vec3(C_uv, 1.0)).rg;
 +      vec3 C_fresnel = F_ibl(vec3(0.04), brdf_lut) * specular_occlusion(NV, final_ao, C_roughness);
 +
 +      out_spec += C_spec_accum.rgb * C_fresnel * float(specToggle) * C_intensity;
 +#endif
 +
 +      /* ---------------------------------------------------------------- */
 +      /* ---------------- DIFFUSE ENVIRONMENT LIGHTING ------------------ */
 +      /* ---------------------------------------------------------------- */
 +
 +      /* Accumulate light from all sources until accumulator is full. Then apply Occlusion and BRDF. */
 +#ifdef CLOSURE_DIFFUSE
 +      vec4 diff_accum = vec4(0.0);
 +
 +      /* ---------------------------- */
 +      /*       Irradiance Grids       */
 +      /* ---------------------------- */
 +      /* Start at 1 because 0 is world irradiance */
 +      for (int i = 1; i < MAX_GRID && i < prbNumRenderGrid && diff_accum.a < 0.999; ++i) {
 +              GridData gd = grids_data[i];
 +
 +              vec3 localpos;
 +              float fade = probe_attenuation_grid(gd, worldPosition, localpos);
 +
 +              if (fade > 0.0) {
 +                      vec3 diff = probe_evaluate_grid(gd, worldPosition, bent_normal, localpos);
 +                      accumulate_light(diff, fade, diff_accum);
 +              }
 +      }
 +
 +      /* ---------------------------- */
 +      /*        World Diffuse         */
 +      /* ---------------------------- */
 +      if (diff_accum.a < 0.999 && prbNumRenderGrid > 0) {
 +              vec3 diff = probe_evaluate_world_diff(bent_normal);
 +              accumulate_light(diff, 1.0, diff_accum);
 +      }
 +
 +      out_diff += diff_accum.rgb * gtao_multibounce(final_ao, albedo);
 +#endif
 +}
 +
 +/* Cleanup for next configuration */
 +#undef CLOSURE_NAME
 +
 +#ifdef CLOSURE_DIFFUSE
 +      #undef CLOSURE_DIFFUSE
 +#endif
 +
 +#ifdef CLOSURE_GLOSSY
 +      #undef CLOSURE_GLOSSY
 +#endif
 +
 +#ifdef CLOSURE_CLEARCOAT
 +      #undef CLOSURE_CLEARCOAT
 +#endif
 +
 +#ifdef CLOSURE_REFRACTION
 +      #undef CLOSURE_REFRACTION
 +#endif
 +
 +#ifdef CLOSURE_SUBSURFACE
 +      #undef CLOSURE_SUBSURFACE
++#endif
@@@ -1165,196 -2620,198 +1165,194 @@@ void node_bsdf_velvet(vec4 color, floa
        node_bsdf_diffuse(color, 0.0, N, result);
  }
  
 -void node_bsdf_glass(vec4 color, float roughness, float ior, vec3 N, out vec4 result)
 -{
 +void node_subsurface_scattering(
 +        vec4 color, float scale, vec3 radius, float sharpen, float texture_blur, vec3 N, float sss_id,
 +        out Closure result)
 +{
 +#if defined(USE_SSS)
 +      vec3 out_diff, out_trans;
 +      vec3 vN = normalize(mat3(ViewMatrix) * N);
 +      result = CLOSURE_DEFAULT;
 +      result.ssr_data = vec4(0.0);
 +      result.ssr_normal = normal_encode(vN, viewCameraVec);
 +      result.ssr_id = -1;
 +      result.sss_data.a = scale;
 +      eevee_closure_subsurface(N, color.rgb, 1.0, scale, out_diff, out_trans);
 +      result.sss_data.rgb = out_diff + out_trans;
 +#ifdef USE_SSS_ALBEDO
 +      /* Not perfect for texture_blur not exaclty equal to 0.0 or 1.0. */
 +      result.sss_albedo.rgb = mix(color.rgb, vec3(1.0), texture_blur);
 +      result.sss_data.rgb *= mix(vec3(1.0), color.rgb, texture_blur);
 +#else
 +      result.sss_data.rgb *= color.rgb;
 +#endif
 +#else
        node_bsdf_diffuse(color, 0.0, N, result);
 +#endif
  }
  
 -void node_bsdf_toon(vec4 color, float size, float tsmooth, vec3 N, out vec4 result)
 +void node_bsdf_refraction(vec4 color, float roughness, float ior, vec3 N, out Closure result)
  {
 -      node_bsdf_diffuse(color, 0.0, N, result);
 +      vec3 out_refr;
 +      color.rgb *= (refractionDepth > 0.0) ? color.rgb : vec3(1.0); /* Simulate 2 absorption event. */
 +      eevee_closure_refraction(N, roughness, ior, out_refr);
 +      vec3 vN = normalize(mat3(ViewMatrix) * N);
 +      result = CLOSURE_DEFAULT;
 +      result.ssr_normal = normal_encode(vN, viewCameraVec);
 +      result.radiance = out_refr * color.rgb;
 +      result.ssr_id = REFRACT_CLOSURE_FLAG;
  }
  
- void node_ambient_occlusion(vec4 color, vec3 vN, out Closure result)
 -void node_bsdf_principled(vec4 base_color, float subsurface, vec3 subsurface_radius, vec4 subsurface_color, float metallic, float specular,
 -      float specular_tint, float roughness, float anisotropic, float anisotropic_rotation, float sheen, float sheen_tint, float clearcoat,
 -      float clearcoat_roughness, float ior, float transmission, float transmission_roughness, vec3 N, vec3 CN, vec3 T, vec3 I, out vec4 result)
++void node_ambient_occlusion(vec4 color, float distance, vec3 normal, out vec4 result_color, out float result_ao)
  {
 -      /* ambient light */
 -      // TODO: set ambient light to an appropriate value
 -      vec3 L = mix(0.1, 0.03, metallic) * mix(base_color.rgb, subsurface_color.rgb, subsurface * (1.0 - metallic));
 -
 -      float eta = (2.0 / (1.0 - sqrt(0.08 * specular))) - 1.0;
 -
 -      /* set the viewing vector */
 -      vec3 V = (gl_ProjectionMatrix[3][3] == 0.0) ? -normalize(I) : vec3(0.0, 0.0, 1.0);
 -
 -      /* get the tangent */
 -      vec3 Tangent = T;
 -      if (T == vec3(0.0)) {
 -              // if no tangent is set, use a default tangent
 -              if(N.x != N.y || N.x != N.z) {
 -                      Tangent = vec3(N.z-N.y, N.x-N.z, N.y-N.x);  // (1,1,1) x N
 -              }
 -              else {
 -                      Tangent = vec3(N.z-N.y, N.x+N.z, -N.y-N.x);  // (-1,1,1) x N
 -              }
 -      }
 -
 -      /* rotate tangent */
 -      if (anisotropic_rotation != 0.0) {
 -              Tangent = rotate_vector(Tangent, N, anisotropic_rotation * 2.0 * M_PI);
 -      }
 -
 -      /* calculate the tangent and bitangent */
 -      vec3 Y = normalize(cross(N, Tangent));
 -      vec3 X = cross(Y, N);
 -
 -      /* fresnel normalization parameters */
 -      float F0 = fresnel_dielectric_0(eta);
 -      float F0_norm = 1.0 / (1.0 - F0);
 -
 -      /* directional lights */
 -      for (int i = 0; i < NUM_LIGHTS; i++) {
 -              vec3 light_position_world = gl_LightSource[i].position.xyz;
 -              vec3 light_position = normalize(light_position_world);
 -
 -              vec3 H = normalize(light_position + V);
 -
 -              vec3 light_diffuse = gl_LightSource[i].diffuse.rgb;
 -              vec3 light_specular = gl_LightSource[i].specular.rgb;
 -
 -              float NdotL = dot(N, light_position);
 -              float NdotV = dot(N, V);
 -              float LdotH = dot(light_position, H);
 -
 -              vec3 diffuse_and_specular_bsdf = vec3(0.0);
 -              if (NdotL >= 0.0 && NdotV >= 0.0) {
 -                      float NdotH = dot(N, H);
 -
 -                      float Cdlum = 0.3 * base_color.r + 0.6 * base_color.g + 0.1 * base_color.b; // luminance approx.
 -
 -                      vec3 Ctint = Cdlum > 0 ? base_color.rgb / Cdlum : vec3(1.0); // normalize lum. to isolate hue+sat
 -                      vec3 Cspec0 = mix(specular * 0.08 * mix(vec3(1.0), Ctint, specular_tint), base_color.rgb, metallic);
 -                      vec3 Csheen = mix(vec3(1.0), Ctint, sheen_tint);
 -
 -                      // Diffuse fresnel - go from 1 at normal incidence to .5 at grazing
 -                      // and mix in diffuse retro-reflection based on roughness
 -
 -                      float FL = schlick_fresnel(NdotL), FV = schlick_fresnel(NdotV);
 -                      float Fd90 = 0.5 + 2.0 * LdotH*LdotH * roughness;
 -                      float Fd = mix(1.0, Fd90, FL) * mix(1.0, Fd90, FV);
 -
 -                      // Based on Hanrahan-Krueger brdf approximation of isotropic bssrdf
 -                      // 1.25 scale is used to (roughly) preserve albedo
 -                      // Fss90 used to "flatten" retroreflection based on roughness
 -                      float Fss90 = LdotH*LdotH * roughness;
 -                      float Fss = mix(1.0, Fss90, FL) * mix(1.0, Fss90, FV);
 -                      float ss = 1.25 * (Fss * (1.0 / (NdotL + NdotV) - 0.5) + 0.5);
 -
 -                      // specular
 -                      float aspect = sqrt(1.0 - anisotropic * 0.9);
 -                      float a = sqr(roughness);
 -                      float ax = max(0.001, a / aspect);
 -                      float ay = max(0.001, a * aspect);
 -                      float Ds = GTR2_aniso(NdotH, dot(H, X), dot(H, Y), ax, ay); //GTR2(NdotH, a);
 -                      float FH = (fresnel_dielectric_cos(LdotH, eta) - F0) * F0_norm;
 -                      vec3 Fs = mix(Cspec0, vec3(1.0), FH);
 -                      float roughg = sqr(roughness * 0.5 + 0.5);
 -                      float Gs = smithG_GGX(NdotL, roughg) * smithG_GGX(NdotV, roughg);
 -
 -                      // sheen
 -                      vec3 Fsheen = schlick_fresnel(LdotH) * sheen * Csheen;
 -
 -                      vec3 diffuse_bsdf = (mix(Fd * base_color.rgb, ss * subsurface_color.rgb, subsurface) + Fsheen) * light_diffuse;
 -                      vec3 specular_bsdf = Gs * Fs * Ds * light_specular;
 -                      diffuse_and_specular_bsdf = diffuse_bsdf * (1.0 - metallic) + specular_bsdf;
 -              }
 -              diffuse_and_specular_bsdf *= max(NdotL, 0.0);
 +      vec3 bent_normal;
 +      vec4 rand = texelFetch(utilTex, ivec3(ivec2(gl_FragCoord.xy) % LUT_SIZE, 2.0), 0);
-       float final_ao = occlusion_compute(normalize(worldNormal), viewPosition, 1.0, rand, bent_normal);
-       result = CLOSURE_DEFAULT;
-       result.ssr_normal = normal_encode(vN, viewCameraVec);
-       result.radiance = final_ao * color.rgb;
++      result_ao = occlusion_compute(normalize(normal), viewPosition, 1.0, rand, bent_normal);
++      result_color = result_ao * color;
 +}
  
 -              float CNdotL = dot(CN, light_position);
 -              float CNdotV = dot(CN, V);
 +#endif /* VOLUMETRICS */
  
 -              vec3 clearcoat_bsdf = vec3(0.0);
 -              if (CNdotL >= 0.0 && CNdotV >= 0.0 && clearcoat > 0.0) {
 -                      float CNdotH = dot(CN, H);
 -                      //float FH = schlick_fresnel(LdotH);
 +/* emission */
  
 -                      // clearcoat (ior = 1.5 -> F0 = 0.04)
 -                      float Dr = GTR1(CNdotH, sqr(clearcoat_roughness));
 -                      float Fr = fresnel_dielectric_cos(LdotH, 1.5); //mix(0.04, 1.0, FH);
 -                      float Gr = smithG_GGX(CNdotL, 0.25) * smithG_GGX(CNdotV, 0.25);
 +void node_emission(vec4 color, float strength, vec3 vN, out Closure result)
 +{
 +#ifndef VOLUMETRICS
 +      color *= strength;
 +      result = CLOSURE_DEFAULT;
 +      result.radiance = color.rgb;
 +      result.opacity = color.a;
 +      result.ssr_normal = normal_encode(vN, viewCameraVec);
 +#else
 +      result = Closure(vec3(0.0), vec3(0.0), color.rgb * strength, 0.0);
 +#endif
 +}
  
 -                      clearcoat_bsdf = clearcoat * Gr * Fr * Dr * vec3(0.25) * light_specular;
 -              }
 -              clearcoat_bsdf *= max(CNdotL, 0.0);
 +/* background */
  
 -              L += diffuse_and_specular_bsdf + clearcoat_bsdf;
 -      }
 +void background_transform_to_world(vec3 viewvec, out vec3 worldvec)
 +{
 +      vec4 v = (ProjectionMatrix[3][3] == 0.0) ? vec4(viewvec, 1.0) : vec4(0.0, 0.0, 1.0, 1.0);
 +      vec4 co_homogenous = (ProjectionMatrixInverse * v);
  
 -      result = vec4(L, 1.0);
 +      vec4 co = vec4(co_homogenous.xyz / co_homogenous.w, 0.0);
 +#if defined(WORLD_BACKGROUND) || defined(PROBE_CAPTURE)
 +      worldvec = (ViewMatrixInverse * co).xyz;
 +#else
 +      worldvec = (ModelViewMatrixInverse * co).xyz;
 +#endif
  }
  
 -void node_bsdf_translucent(vec4 color, vec3 N, out vec4 result)
 +void node_background(vec4 color, float strength, out Closure result)
  {
 -      node_bsdf_diffuse(color, 0.0, N, result);
 +#ifndef VOLUMETRICS
 +      color *= strength;
 +      result = CLOSURE_DEFAULT;
 +      result.radiance = color.rgb;
 +      result.opacity = color.a;
 +#else
 +      result = CLOSURE_DEFAULT;
 +#endif
  }
  
 -void node_bsdf_transparent(vec4 color, out vec4 result)
 -{
 -      /* this isn't right */
 -      result.r = color.r;
 -      result.g = color.g;
 -      result.b = color.b;
 -      result.a = 0.0;
 -}
 +/* volumes */
  
 -void node_bsdf_velvet(vec4 color, float sigma, vec3 N, out vec4 result)
 +void node_volume_scatter(vec4 color, float density, float anisotropy, out Closure result)
  {
 -      node_bsdf_diffuse(color, 0.0, N, result);
 +#ifdef VOLUMETRICS
 +      result = Closure(vec3(0.0), color.rgb * density, vec3(0.0), anisotropy);
 +#else
 +      result = CLOSURE_DEFAULT;
 +#endif
  }
  
 -void node_subsurface_scattering(
 -        vec4 color, float scale, vec3 radius, float sharpen, float texture_blur, vec3 N,
 -        out vec4 result)
 +void node_volume_absorption(vec4 color, float density, out Closure result)
  {
 -      node_bsdf_diffuse(color, 0.0, N, result);
 +#ifdef VOLUMETRICS
 +      result = Closure((1.0 - color.rgb) * density, vec3(0.0), vec3(0.0), 0.0);
 +#else
 +      result = CLOSURE_DEFAULT;
 +#endif
  }
  
 -void node_bsdf_hair(vec4 color, float offset, float roughnessu, float roughnessv, vec3 tangent, out vec4 result)
 +void node_blackbody(float temperature, sampler2D spectrummap, out vec4 color)
  {
 -      result = color;
 +    if(temperature >= 12000.0) {
 +        color = vec4(0.826270103, 0.994478524, 1.56626022, 1.0);
 +    }
 +    else if(temperature < 965.0) {
 +        color = vec4(4.70366907, 0.0, 0.0, 1.0);
 +    }
 +      else {
 +              float t = (temperature - 965.0) / (12000.0 - 965.0);
 +              color = vec4(texture(spectrummap, vec2(t, 0.0)).rgb, 1.0);
 +      }
  }
  
 -void node_bsdf_refraction(vec4 color, float roughness, float ior, vec3 N, out vec4 result)
 +void node_volume_principled(
 +      vec4 color,
 +      float density,
 +      float anisotropy,
 +      vec4 absorption_color,
 +      float emission_strength,
 +      vec4 emission_color,
 +      float blackbody_intensity,
 +      vec4 blackbody_tint,
 +      float temperature,
 +      float density_attribute,
 +      vec4 color_attribute,
 +      float temperature_attribute,
 +      sampler2D spectrummap,
 +      out Closure result)
  {
 -      node_bsdf_diffuse(color, 0.0, N, result);
 -}
 +#ifdef VOLUMETRICS
 +      vec3 absorption_coeff = vec3(0.0);
 +      vec3 scatter_coeff = vec3(0.0);
 +      vec3 emission_coeff = vec3(0.0);
  
 -void node_ambient_occlusion(vec4 color, float distance, vec3 normal, out vec4 result_color, out float result_ao)
 -{
 -      result_color = color;
 -      result_ao = 1.0;
 -}
 +      /* Compute density. */
 +      density = max(density, 0.0);
  
 -/* emission */
 +      if(density > 1e-5) {
 +              density = max(density * density_attribute, 0.0);
 +      }
  
 -void node_emission(vec4 color, float strength, vec3 N, out vec4 result)
 -{
 -      result = color * strength;
 -}
 +      if(density > 1e-5) {
 +              /* Compute scattering and absorption coefficients. */
 +              vec3 scatter_color = color.rgb * color_attribute.rgb;
  
 -/* background */
 +              scatter_coeff = scatter_color * density;
 +              absorption_color.rgb = sqrt(max(absorption_color.rgb, 0.0));
 +              absorption_coeff = max(1.0 - scatter_color, 0.0) * max(1.0 - absorption_color.rgb, 0.0) * density;
 +      }
  
 -void background_transform_to_world(vec3 viewvec, out vec3 worldvec)
 -{
 -      vec4 v = (gl_ProjectionMatrix[3][3] == 0.0) ? vec4(viewvec, 1.0) : vec4(0.0, 0.0, 1.0, 1.0);
 -      vec4 co_homogenous = (gl_ProjectionMatrixInverse * v);
 +      /* Compute emission. */
 +      emission_strength = max(emission_strength, 0.0);
  
 -      vec4 co = vec4(co_homogenous.xyz / co_homogenous.w, 0.0);
 -      worldvec = (gl_ModelViewMatrixInverse * co).xyz;
 -}
 +      if(emission_strength > 1e-5) {
 +              emission_coeff += emission_strength * emission_color.rgb;
 +      }
  
 -void node_background(vec4 color, float strength, vec3 N, out vec4 result)
 -{
 -      result = color * strength;
 +      if(blackbody_intensity > 1e-3) {
 +              /* Add temperature from attribute. */
 +              float T = max(temperature * max(temperature_attribute, 0.0), 0.0);
 +
 +              /* Stefan-Boltzman law. */
 +              float T4 = (T * T) * (T * T);
 +              float sigma = 5.670373e-8 * 1e-6 / M_PI;
 +              float intensity = sigma * mix(1.0, T4, blackbody_intensity);
 +
 +              if(intensity > 1e-5) {
 +                      vec4 bb;
 +                      node_blackbody(T, spectrummap, bb);
 +                      emission_coeff += bb.rgb * blackbody_tint.rgb * intensity;
 +              }
 +      }
 +
 +      result = Closure(absorption_coeff, scatter_coeff, emission_coeff, anisotropy);
 +#else
 +      result = CLOSURE_DEFAULT;
 +#endif
  }
  
  /* closures */
@@@ -39,9 -42,15 +42,18 @@@ static bNodeSocketTemplate sh_node_ambi
        {       -1, 0, ""       }
  };
  
 -static int node_shader_gpu_ambient_occlusion(GPUMaterial *mat, bNode *UNUSED(node), bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
 +static int node_shader_gpu_ambient_occlusion(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
  {
-       return GPU_stack_link(mat, node, "node_ambient_occlusion", in, out, GPU_builtin(GPU_VIEW_NORMAL));
 -      return GPU_stack_link(mat, "node_ambient_occlusion", in, out, GPU_builtin(GPU_VIEW_NORMAL));
++      if (!in[2].link)
++              GPU_link(mat, "world_normals_get", &in[2].link);
++
++      return GPU_stack_link(mat, node, "node_ambient_occlusion", in, out);
+ }
+ static void node_shader_init_ambient_occlusion(bNodeTree *UNUSED(ntree), bNode *node)
+ {
+       node->custom1 = 8; /* samples */
+       node->custom2 = SHD_AO_LOCAL;
  }
  
  /* node type definition */