[Bf-blender-cvs] [2bae11d5c08] master: EEVEE: Arbitrary Output Variables

Jeroen Bakker noreply at git.blender.org
Fri Dec 4 08:16:12 CET 2020


Commit: 2bae11d5c08a9095f2c8ec5e465e73ada9840ed1
Author: Jeroen Bakker
Date:   Fri Dec 4 08:13:54 2020 +0100
Branches: master
https://developer.blender.org/rB2bae11d5c08a9095f2c8ec5e465e73ada9840ed1

EEVEE: Arbitrary Output Variables

This patch adds support for AOVs in EEVEE. AOV Outputs can be defined in the
render pass tab and used in shader materials. Both Object and World based
shaders are supported. The AOV can be previewed in the viewport using the
renderpass selector in the shading popover.

AOV names that conflict with other AOVs are automatically corrected. AOV
conflicts with render passes get a warning icon. The reason behind this is that
changing render engines/passes can change the conflict, but you might not notice
it. Changing this automatically would also make the materials incorrect, so best
to leave this to the user.

**Implementation**

The patch adds a copies the AOV structures of Cycles into Blender. The goal is
that the Cycles will use Blenders AOV defintions. In the Blender kernel
(`layer.c`) the logic of these structures are implemented.

The GLSL shader of any GPUMaterial can hold multiple outputs (the main output
and the AOV outputs) based on the renderPassUBO the right output is selected.
This selection uses an hash that encodes the AOV structure. The full AOV needed
to be encoded when actually drawing the material pass as the AOV type changes
the behavior of the AOV. This isn't known yet when the GLSL is compiled.

**Future Developments**

* The AOV definitions in the render layer panel isn't shared with Cycles.
  Cycles should be migrated to use the same viewlayer aovs. During a previous
  attempt this failed as the AOV validation in cycles and in Blender have
  implementation differences what made it crash when an aov name was invalid.
  This could be fixed by extending the external render engine API.
* Add support to Cycles to render AOVs in the 3d viewport.
* Use a drop down list for selecting AOVs in the AOV Output node.
* Give user feedback when multiple AOV output nodes with the same AOV name
  exists in the same shader.
* Fix viewing single channel images in the image editor [T83314]
* Reduce viewport render time by only render needed draw passes. [T83316]

Reviewed By: Brecht van Lommel, Clément Foucault

Differential Revision: https://developer.blender.org/D7010

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

M	release/datafiles/locale
M	release/scripts/addons
M	release/scripts/startup/bl_ui/properties_view_layer.py
M	release/scripts/startup/nodeitems_builtins.py
M	source/blender/blenkernel/BKE_appdir.h
M	source/blender/blenkernel/BKE_layer.h
M	source/blender/blenkernel/CMakeLists.txt
M	source/blender/blenkernel/intern/appdir.c
M	source/blender/blenkernel/intern/layer.c
A	source/blender/blenkernel/intern/layer_test.cc
M	source/blender/blenloader/tests/blendfile_loading_base_test.cc
M	source/blender/draw/engines/eevee/eevee_data.c
M	source/blender/draw/engines/eevee/eevee_materials.c
M	source/blender/draw/engines/eevee/eevee_private.h
M	source/blender/draw/engines/eevee/eevee_render.c
M	source/blender/draw/engines/eevee/eevee_renderpasses.c
M	source/blender/draw/engines/eevee/shaders/renderpass_lib.glsl
M	source/blender/draw/engines/eevee/shaders/renderpass_postprocess_frag.glsl
M	source/blender/editors/render/render_intern.h
M	source/blender/editors/render/render_ops.c
M	source/blender/editors/render/render_shading.c
M	source/blender/gpu/CMakeLists.txt
M	source/blender/gpu/GPU_material.h
M	source/blender/gpu/intern/gpu_codegen.c
M	source/blender/gpu/intern/gpu_material.c
M	source/blender/gpu/intern/gpu_material_library.c
M	source/blender/gpu/intern/gpu_node_graph.c
M	source/blender/gpu/intern/gpu_node_graph.h
A	source/blender/gpu/shaders/material/gpu_shader_material_output_aov.glsl
M	source/blender/makesdna/DNA_layer_types.h
M	source/blender/makesdna/DNA_view3d_types.h
M	source/blender/makesrna/RNA_access.h
M	source/blender/makesrna/intern/rna_internal.h
M	source/blender/makesrna/intern/rna_layer.c
M	source/blender/makesrna/intern/rna_scene.c
M	source/blender/makesrna/intern/rna_space.c
M	source/blender/nodes/shader/node_shader_tree.c
M	source/blender/nodes/shader/nodes/node_shader_output_aov.c
M	source/blender/windowmanager/WM_api.h
M	source/blender/windowmanager/intern/wm_init_exit.c
M	source/blender/windowmanager/intern/wm_window.c
M	source/tools

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

diff --git a/release/datafiles/locale b/release/datafiles/locale
index ae7e6c215c9..1c0e9c29fd3 160000
--- a/release/datafiles/locale
+++ b/release/datafiles/locale
@@ -1 +1 @@
-Subproject commit ae7e6c215c9fc715cdedbc1c1e33e946fc90b496
+Subproject commit 1c0e9c29fd33963ff42ff9252a64016abda8d2a7
diff --git a/release/scripts/addons b/release/scripts/addons
index ca741974401..672cfe9c85e 160000
--- a/release/scripts/addons
+++ b/release/scripts/addons
@@ -1 +1 @@
-Subproject commit ca74197440127e56c9f6f2a277c30957f34fd07c
+Subproject commit 672cfe9c85e2ac71b97b5331d9034d23c9723d71
diff --git a/release/scripts/startup/bl_ui/properties_view_layer.py b/release/scripts/startup/bl_ui/properties_view_layer.py
index afa00bb50c2..35cd7ae5ab9 100644
--- a/release/scripts/startup/bl_ui/properties_view_layer.py
+++ b/release/scripts/startup/bl_ui/properties_view_layer.py
@@ -17,7 +17,16 @@
 # ##### END GPL LICENSE BLOCK #####
 
 # <pep8 compliant>
-from bpy.types import Panel
+from bpy.types import Panel, UIList
+
+
+class VIEWLAYER_UL_aov(UIList):
+    def draw_item(self, context, layout, data, item, icon, active_data, active_propname):
+        row = layout.row()
+        split = row.split(factor=0.65)
+        icon = 'NONE' if item.is_valid else 'ERROR'
+        split.row().prop(item, "name", text="", icon=icon, emboss=False)
+        split.row().prop(item, "type", text="", emboss=False)
 
 
 class ViewLayerButtonsPanel:
@@ -49,7 +58,7 @@ class VIEWLAYER_PT_layer(ViewLayerButtonsPanel, Panel):
         col.prop(rd, "use_single_layer", text="Render Single Layer")
 
 
-class VIEWLAYER_PT_eevee_layer_passes(ViewLayerButtonsPanel, Panel):
+class VIEWLAYER_PT_layer_passes(ViewLayerButtonsPanel, Panel):
     bl_label = "Passes"
     COMPAT_ENGINES = {'BLENDER_EEVEE'}
 
@@ -59,7 +68,7 @@ class VIEWLAYER_PT_eevee_layer_passes(ViewLayerButtonsPanel, Panel):
 
 class VIEWLAYER_PT_eevee_layer_passes_data(ViewLayerButtonsPanel, Panel):
     bl_label = "Data"
-    bl_parent_id = "VIEWLAYER_PT_eevee_layer_passes"
+    bl_parent_id = "VIEWLAYER_PT_layer_passes"
 
     COMPAT_ENGINES = {'BLENDER_EEVEE'}
 
@@ -81,7 +90,7 @@ class VIEWLAYER_PT_eevee_layer_passes_data(ViewLayerButtonsPanel, Panel):
 
 class VIEWLAYER_PT_eevee_layer_passes_light(ViewLayerButtonsPanel, Panel):
     bl_label = "Light"
-    bl_parent_id = "VIEWLAYER_PT_eevee_layer_passes"
+    bl_parent_id = "VIEWLAYER_PT_layer_passes"
     COMPAT_ENGINES = {'BLENDER_EEVEE'}
 
     def draw(self, context):
@@ -116,7 +125,7 @@ class VIEWLAYER_PT_eevee_layer_passes_light(ViewLayerButtonsPanel, Panel):
 
 class VIEWLAYER_PT_eevee_layer_passes_effects(ViewLayerButtonsPanel, Panel):
     bl_label = "Effects"
-    bl_parent_id = "VIEWLAYER_PT_eevee_layer_passes"
+    bl_parent_id = "VIEWLAYER_PT_layer_passes"
     COMPAT_ENGINES = {'BLENDER_EEVEE'}
 
     def draw(self, context):
@@ -135,12 +144,41 @@ class VIEWLAYER_PT_eevee_layer_passes_effects(ViewLayerButtonsPanel, Panel):
         col.active = scene_eevee.use_bloom
 
 
+class VIEWLAYER_PT_layer_passes_aov(ViewLayerButtonsPanel, Panel):
+    bl_label = "Shader AOV"
+    bl_parent_id = "VIEWLAYER_PT_layer_passes"
+    COMPAT_ENGINES = {'BLENDER_EEVEE'}
+
+    def draw(self, context):
+        layout = self.layout
+
+        layout.use_property_split = True
+        layout.use_property_decorate = False
+
+        view_layer = context.view_layer
+
+        row = layout.row()
+        col = row.column()
+        col.template_list("VIEWLAYER_UL_aov", "aovs", view_layer, "aovs", view_layer, "active_aov_index", rows=2)
+
+        col = row.column()
+        sub = col.column(align=True)
+        sub.operator("scene.view_layer_add_aov", icon='ADD', text="")
+        sub.operator("scene.view_layer_remove_aov", icon='REMOVE', text="")
+
+        aov = view_layer.active_aov
+        if aov and not aov.is_valid:
+            layout.label(text="Conflicts with another render pass with the same name", icon='ERROR')
+
+
 classes = (
     VIEWLAYER_PT_layer,
-    VIEWLAYER_PT_eevee_layer_passes,
+    VIEWLAYER_PT_layer_passes,
     VIEWLAYER_PT_eevee_layer_passes_data,
     VIEWLAYER_PT_eevee_layer_passes_light,
     VIEWLAYER_PT_eevee_layer_passes_effects,
+    VIEWLAYER_PT_layer_passes_aov,
+    VIEWLAYER_UL_aov,
 )
 
 if __name__ == "__main__":  # only for live edit.
diff --git a/release/scripts/startup/nodeitems_builtins.py b/release/scripts/startup/nodeitems_builtins.py
index b1789776728..abab50b95a2 100644
--- a/release/scripts/startup/nodeitems_builtins.py
+++ b/release/scripts/startup/nodeitems_builtins.py
@@ -165,11 +165,6 @@ def object_cycles_shader_nodes_poll(context):
             cycles_shader_nodes_poll(context))
 
 
-def cycles_aov_node_poll(context):
-    return (object_cycles_shader_nodes_poll(context) or
-            world_shader_nodes_poll(context))
-
-
 def object_eevee_shader_nodes_poll(context):
     return (object_shader_nodes_poll(context) and
             eevee_shader_nodes_poll(context))
@@ -210,7 +205,7 @@ shader_node_categories = [
     ShaderNodeCategory("SH_NEW_OUTPUT", "Output", items=[
         NodeItem("ShaderNodeOutputMaterial", poll=object_eevee_cycles_shader_nodes_poll),
         NodeItem("ShaderNodeOutputLight", poll=object_cycles_shader_nodes_poll),
-        NodeItem("ShaderNodeOutputAOV", poll=cycles_aov_node_poll),
+        NodeItem("ShaderNodeOutputAOV"),
         NodeItem("ShaderNodeOutputWorld", poll=world_shader_nodes_poll),
         NodeItem("ShaderNodeOutputLineStyle", poll=line_style_shader_nodes_poll),
         NodeItem("NodeGroupOutput", poll=group_input_output_item_poll),
diff --git a/source/blender/blenkernel/BKE_appdir.h b/source/blender/blenkernel/BKE_appdir.h
index 3e52d7f3301..6da6079ea2a 100644
--- a/source/blender/blenkernel/BKE_appdir.h
+++ b/source/blender/blenkernel/BKE_appdir.h
@@ -26,6 +26,7 @@ extern "C" {
 struct ListBase;
 
 void BKE_appdir_init(void);
+void BKE_appdir_exit(void);
 
 /* note on naming: typical _get() suffix is omitted here,
  * since its the main purpose of the API. */
diff --git a/source/blender/blenkernel/BKE_layer.h b/source/blender/blenkernel/BKE_layer.h
index 7091a060243..e5fab35891c 100644
--- a/source/blender/blenkernel/BKE_layer.h
+++ b/source/blender/blenkernel/BKE_layer.h
@@ -42,6 +42,7 @@ struct Depsgraph;
 struct LayerCollection;
 struct Main;
 struct Object;
+struct RenderEngine;
 struct Scene;
 struct View3D;
 struct ViewLayer;
@@ -444,6 +445,15 @@ bool BKE_view_layer_filter_edit_mesh_has_edges(struct Object *ob, void *user_dat
   BKE_view_layer_array_from_objects_in_mode( \
       view_layer, v3d, r_len, {.object_mode = mode, .no_dup_data = true})
 
+struct ViewLayerAOV *BKE_view_layer_add_aov(struct ViewLayer *view_layer);
+void BKE_view_layer_remove_aov(struct ViewLayer *view_layer, struct ViewLayerAOV *aov);
+void BKE_view_layer_set_active_aov(struct ViewLayer *view_layer, struct ViewLayerAOV *aov);
+void BKE_view_layer_verify_aov(struct RenderEngine *engine,
+                               struct Scene *scene,
+                               struct ViewLayer *view_layer);
+bool BKE_view_layer_has_valid_aov(struct ViewLayer *view_layer);
+ViewLayer *BKE_view_layer_find_with_aov(struct Scene *scene, struct ViewLayerAOV *view_layer_aov);
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/source/blender/blenkernel/CMakeLists.txt b/source/blender/blenkernel/CMakeLists.txt
index 1a90d6fadd3..a328c600eac 100644
--- a/source/blender/blenkernel/CMakeLists.txt
+++ b/source/blender/blenkernel/CMakeLists.txt
@@ -726,6 +726,7 @@ if(WITH_GTESTS)
     intern/fcurve_test.cc
     intern/lattice_deform_test.cc
     intern/tracking_test.cc
+    intern/layer_test.cc
   )
   set(TEST_INC
     ../editors/include
diff --git a/source/blender/blenkernel/intern/appdir.c b/source/blender/blenkernel/intern/appdir.c
index 2038079744d..b1462167edd 100644
--- a/source/blender/blenkernel/intern/appdir.c
+++ b/source/blender/blenkernel/intern/appdir.c
@@ -114,6 +114,14 @@ void BKE_appdir_init(void)
 #endif
 }
 
+void BKE_appdir_exit(void)
+{
+#ifndef NDEBUG
+  BLI_assert(is_appdir_init == true);
+  is_appdir_init = false;
+#endif
+}
+
 /** \} */
 
 /* -------------------------------------------------------------------- */
diff --git a/source/blender/blenkernel/intern/layer.c b/source/blender/blenkernel/intern/layer.c
index 73b330bc0de..6b346d7a337 100644
--- a/source/blender/blenkernel/intern/layer.c
+++ b/source/blender/blenkernel/intern/layer.c
@@ -57,6 +57,8 @@
 
 #include "DRW_engine.h"
 
+#include "RE_engine.h"
+
 #include "MEM_guardedalloc.h"
 
 #include "BLO_read_write.h"
@@ -279,6 +281,8 @@ void BKE_view_layer_free_ex(ViewLayer *view_layer, const bool do_id_user)
     }
   }
   BLI_freelistN(&view_layer->drawdata);
+  BLI_freelistN(&view_layer->aovs);
+  view_layer->active_aov = NULL;
 
   MEM_SAFE_FREE(view_layer->stats);
 
@@ -412,6 +416,28 @@ void BKE_view_layer_base_select_and_set_active(struct ViewLayer *view_layer, Bas
 }
 
 /**************************** Copy View Layer and Layer Collections ***********************/
+static void layer_aov_copy_data(ViewLayer *view_layer_dst,
+                                const ViewLayer *view_layer_src,
+                                ListBase *aovs_dst,
+                                const ListBase *aovs_src)
+{
+  if (aovs_src != NULL) {
+    BLI_duplicatelist(aovs_dst, aovs_src);
+  }
+
+  ViewLayerAOV *aov_dst = aovs_dst->first;
+  const ViewLayerAOV *aov_src = aovs_src->first;
+
+  while (aov_dst != NULL) {
+    BLI_assert(aov_src);
+    if (aov_src == view_layer_src->active_aov) {
+      view_layer_dst->active_aov = aov_dst;
+    }
+
+    aov_dst = aov_dst->next;
+    aov_src = aov_src->next;
+  }
+}
 
 static void layer_collections_copy_data(ViewLayer *view_layer_dst,
                                         const ViewLayer *view_layer_src,
@@ -482,6 +508,10 @@ void BKE_view_layer_copy_data(Scene *scene_dst,
   LayerCollection *lc_scene_dst = view_layer_dst->layer_collections.first;
   lc_scene_dst->collection = scene_dst->master_collection;
 
+  BLI_listbase_clear(&view_layer_dst->aovs);
+  layer_aov_copy_data(
+      view_layer_dst, view_layer_src, &view_layer_dst->aovs, &view_layer_src->aovs);
+
   if ((flag & LIB_ID_CREATE_NO_USER_REFCOUNT) == 0) {
     

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list