Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeroen Bakker <jbakker>2020-12-04 10:13:54 +0300
committerJeroen Bakker <jeroen@blender.org>2020-12-04 10:14:07 +0300
commit2bae11d5c08a9095f2c8ec5e465e73ada9840ed1 (patch)
tree1b256d7acff23d763758daa33282b9238ba72f5b /source/blender/makesrna
parent2bd0263fbf2175c672d46c9df9eff7fd3ceecbce (diff)
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
Diffstat (limited to 'source/blender/makesrna')
-rw-r--r--source/blender/makesrna/RNA_access.h1
-rw-r--r--source/blender/makesrna/intern/rna_internal.h4
-rw-r--r--source/blender/makesrna/intern/rna_layer.c13
-rw-r--r--source/blender/makesrna/intern/rna_scene.c95
-rw-r--r--source/blender/makesrna/intern/rna_space.c96
5 files changed, 203 insertions, 6 deletions
diff --git a/source/blender/makesrna/RNA_access.h b/source/blender/makesrna/RNA_access.h
index f51202348b5..a581edcb04b 100644
--- a/source/blender/makesrna/RNA_access.h
+++ b/source/blender/makesrna/RNA_access.h
@@ -60,6 +60,7 @@ extern StructRNA RNA_AnimData;
extern StructRNA RNA_AnimViz;
extern StructRNA RNA_AnimVizMotionPaths;
extern StructRNA RNA_AnyType;
+extern StructRNA RNA_AOV;
extern StructRNA RNA_Area;
extern StructRNA RNA_AreaLight;
extern StructRNA RNA_Armature;
diff --git a/source/blender/makesrna/intern/rna_internal.h b/source/blender/makesrna/intern/rna_internal.h
index 31e920a6799..1c6f83efd65 100644
--- a/source/blender/makesrna/intern/rna_internal.h
+++ b/source/blender/makesrna/intern/rna_internal.h
@@ -345,6 +345,10 @@ void rna_ViewLayer_material_override_update(struct Main *bmain,
void rna_ViewLayer_pass_update(struct Main *bmain,
struct Scene *activescene,
struct PointerRNA *ptr);
+void rna_ViewLayer_active_aov_index_range(
+ PointerRNA *ptr, int *min, int *max, int *softmin, int *softmax);
+int rna_ViewLayer_active_aov_index_get(PointerRNA *ptr);
+void rna_ViewLayer_active_aov_index_set(PointerRNA *ptr, int value);
/* named internal so as not to conflict with obj.update() rna func */
void rna_Object_internal_update_data(struct Main *bmain,
diff --git a/source/blender/makesrna/intern/rna_layer.c b/source/blender/makesrna/intern/rna_layer.c
index c7a53757296..0dcbd8a070b 100644
--- a/source/blender/makesrna/intern/rna_layer.c
+++ b/source/blender/makesrna/intern/rna_layer.c
@@ -152,7 +152,18 @@ static void rna_ViewLayer_update_render_passes(ID *id)
if (scene->nodetree) {
ntreeCompositUpdateRLayers(scene->nodetree);
}
-}
+
+ RenderEngineType *engine_type = RE_engines_find(scene->r.engine);
+ if (engine_type->update_render_passes) {
+ RenderEngine *engine = RE_engine_create(engine_type);
+ if (engine) {
+ LISTBASE_FOREACH (ViewLayer *, view_layer, &scene->view_layers) {
+ BKE_view_layer_verify_aov(engine, scene, view_layer);
+ }
+ }
+ RE_engine_free(engine);
+ engine = NULL;
+ }}
static PointerRNA rna_ViewLayer_objects_get(CollectionPropertyIterator *iter)
{
diff --git a/source/blender/makesrna/intern/rna_scene.c b/source/blender/makesrna/intern/rna_scene.c
index 235042122e6..0f13ba29d3b 100644
--- a/source/blender/makesrna/intern/rna_scene.c
+++ b/source/blender/makesrna/intern/rna_scene.c
@@ -529,6 +529,12 @@ const EnumPropertyItem rna_enum_bake_pass_filter_type_items[] = {
{0, NULL, 0, NULL, NULL},
};
+const EnumPropertyItem rna_enum_view_layer_aov_type_items[] = {
+ {AOV_TYPE_COLOR, "COLOR", 0, "Color", ""},
+ {AOV_TYPE_VALUE, "VALUE", 0, "Value", ""},
+ {0, NULL, 0, NULL, NULL},
+};
+
#ifndef RNA_RUNTIME
static const EnumPropertyItem rna_enum_gpencil_interpolation_mode_items[] = {
/* interpolation */
@@ -1779,6 +1785,27 @@ void rna_ViewLayer_pass_update(Main *bmain, Scene *activescene, PointerRNA *ptr)
ntreeCompositUpdateRLayers(scene->nodetree);
}
+ ViewLayer *view_layer = NULL;
+ if (ptr->type == &RNA_ViewLayer) {
+ view_layer = (ViewLayer *)ptr->data;
+ }
+ else if (ptr->type == &RNA_AOV) {
+ ViewLayerAOV *aov = (ViewLayerAOV *)ptr->data;
+ view_layer = BKE_view_layer_find_with_aov(scene, aov);
+ }
+
+ if (view_layer) {
+ RenderEngineType *engine_type = RE_engines_find(scene->r.engine);
+ if (engine_type->update_render_passes) {
+ RenderEngine *engine = RE_engine_create(engine_type);
+ if (engine) {
+ BKE_view_layer_verify_aov(engine, scene, view_layer);
+ }
+ RE_engine_free(engine);
+ engine = NULL;
+ }
+ }
+
rna_Scene_glsl_update(bmain, activescene, ptr);
}
@@ -2397,6 +2424,28 @@ static void rna_ViewLayer_remove(
}
}
+void rna_ViewLayer_active_aov_index_range(
+ PointerRNA *ptr, int *min, int *max, int *UNUSED(softmin), int *UNUSED(softmax))
+{
+ ViewLayer *view_layer = (ViewLayer *)ptr->data;
+
+ *min = 0;
+ *max = max_ii(0, BLI_listbase_count(&view_layer->aovs) - 1);
+}
+
+int rna_ViewLayer_active_aov_index_get(PointerRNA *ptr)
+{
+ ViewLayer *view_layer = (ViewLayer *)ptr->data;
+ return BLI_findindex(&view_layer->aovs, view_layer->active_aov);
+}
+
+void rna_ViewLayer_active_aov_index_set(PointerRNA *ptr, int value)
+{
+ ViewLayer *view_layer = (ViewLayer *)ptr->data;
+ ViewLayerAOV *aov = BLI_findlink(&view_layer->aovs, value);
+ view_layer->active_aov = aov;
+}
+
/* Fake value, used internally (not saved to DNA). */
# define V3D_ORIENT_DEFAULT -1
@@ -3963,6 +4012,33 @@ static void rna_def_view_layer_eevee(BlenderRNA *brna)
RNA_def_property_update(prop, NC_SCENE | ND_RENDER_OPTIONS, "rna_ViewLayer_pass_update");
}
+static void rna_def_view_layer_aov(BlenderRNA *brna)
+{
+ StructRNA *srna;
+ PropertyRNA *prop;
+ srna = RNA_def_struct(brna, "AOV", NULL);
+ RNA_def_struct_sdna(srna, "ViewLayerAOV");
+ RNA_def_struct_ui_text(srna, "Shader AOV", "");
+
+ prop = RNA_def_property(srna, "name", PROP_STRING, PROP_NONE);
+ RNA_def_property_string_sdna(prop, NULL, "name");
+ RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
+ RNA_def_property_ui_text(prop, "Name", "Name of the AOV");
+ RNA_def_property_update(prop, NC_SCENE | ND_RENDER_OPTIONS, "rna_ViewLayer_pass_update");
+ RNA_def_struct_name_property(srna, prop);
+
+ prop = RNA_def_property(srna, "is_valid", PROP_BOOLEAN, PROP_NONE);
+ RNA_def_property_boolean_negative_sdna(prop, NULL, "flag", AOV_CONFLICT);
+ RNA_def_property_ui_text(prop, "Valid", "Is the name of the AOV conflicting");
+
+ prop = RNA_def_property(srna, "type", PROP_ENUM, PROP_NONE);
+ RNA_def_property_enum_sdna(prop, NULL, "type");
+ RNA_def_property_enum_items(prop, rna_enum_view_layer_aov_type_items);
+ RNA_def_property_enum_default(prop, AOV_TYPE_COLOR);
+ RNA_def_property_ui_text(prop, "Type", "Data type of the AOV");
+ RNA_def_property_update(prop, NC_SCENE | ND_RENDER_OPTIONS, "rna_ViewLayer_pass_update");
+}
+
void rna_def_view_layer_common(StructRNA *srna, const bool scene)
{
PropertyRNA *prop;
@@ -4013,6 +4089,24 @@ void rna_def_view_layer_common(StructRNA *srna, const bool scene)
RNA_def_property_flag(prop, PROP_NEVER_NULL);
RNA_def_property_struct_type(prop, "ViewLayerEEVEE");
RNA_def_property_ui_text(prop, "EEVEE Settings", "View layer settings for EEVEE");
+
+ prop = RNA_def_property(srna, "aovs", PROP_COLLECTION, PROP_NONE);
+ RNA_def_property_collection_sdna(prop, NULL, "aovs", NULL);
+ RNA_def_property_struct_type(prop, "AOV");
+ RNA_def_property_ui_text(prop, "Shader AOV", "");
+
+ prop = RNA_def_property(srna, "active_aov", PROP_POINTER, PROP_NONE);
+ RNA_def_property_struct_type(prop, "AOV");
+ RNA_def_property_clear_flag(prop, PROP_EDITABLE);
+ RNA_def_property_ui_text(prop, "Shader AOV", "Active AOV");
+
+ prop = RNA_def_property(srna, "active_aov_index", PROP_INT, PROP_UNSIGNED);
+ RNA_def_property_int_funcs(prop,
+ "rna_ViewLayer_active_aov_index_get",
+ "rna_ViewLayer_active_aov_index_set",
+ "rna_ViewLayer_active_aov_index_range");
+ RNA_def_property_ui_text(prop, "Active AOV Index", "Index of active aov");
+ RNA_def_property_update(prop, NC_SCENE | ND_RENDER_OPTIONS, NULL);
}
/* layer options */
@@ -7848,6 +7942,7 @@ void RNA_def_scene(BlenderRNA *brna)
rna_def_display_safe_areas(brna);
rna_def_scene_display(brna);
rna_def_scene_eevee(brna);
+ rna_def_view_layer_aov(brna);
rna_def_view_layer_eevee(brna);
rna_def_scene_gpencil(brna);
RNA_define_animate_sdna(true);
diff --git a/source/blender/makesrna/intern/rna_space.c b/source/blender/makesrna/intern/rna_space.c
index 8ff4336ba83..eabb71c79d3 100644
--- a/source/blender/makesrna/intern/rna_space.c
+++ b/source/blender/makesrna/intern/rna_space.c
@@ -426,6 +426,9 @@ static const EnumPropertyItem rna_enum_view3dshading_render_pass_type_items[] =
{EEVEE_RENDER_PASS_NORMAL, "NORMAL", 0, "Normal", ""},
{EEVEE_RENDER_PASS_MIST, "MIST", 0, "Mist", ""},
+ {0, "", ICON_NONE, "Shader AOV", ""},
+ {EEVEE_RENDER_PASS_AOV, "AOV", 0, "AOV", ""},
+
{0, NULL, 0, NULL, NULL},
};
@@ -1065,6 +1068,19 @@ static Scene *rna_3DViewShading_scene(PointerRNA *ptr)
}
}
+static ViewLayer *rna_3DViewShading_view_layer(PointerRNA *ptr)
+{
+ /* Get scene, depends if using 3D view or OpenGL render settings. */
+ ID *id = ptr->owner_id;
+ if (GS(id->name) == ID_SCE) {
+ return NULL;
+ }
+ else {
+ bScreen *screen = (bScreen *)ptr->owner_id;
+ return WM_windows_view_layer_get_from_screen(G_MAIN->wm.first, screen);
+ }
+}
+
static int rna_3DViewShading_type_get(PointerRNA *ptr)
{
/* Available shading types depend on render engine. */
@@ -1292,15 +1308,33 @@ static const EnumPropertyItem *rna_3DViewShading_render_pass_itemf(bContext *C,
bool *r_free)
{
Scene *scene = CTX_data_scene(C);
+ ViewLayer *view_layer = CTX_data_view_layer(C);
const bool bloom_enabled = scene->eevee.flag & SCE_EEVEE_BLOOM_ENABLED;
+ const bool aov_available = BKE_view_layer_has_valid_aov(view_layer);
int totitem = 0;
EnumPropertyItem *result = NULL;
+ EnumPropertyItem aov_template;
for (int i = 0; rna_enum_view3dshading_render_pass_type_items[i].identifier != NULL; i++) {
const EnumPropertyItem *item = &rna_enum_view3dshading_render_pass_type_items[i];
- if (!((!bloom_enabled &&
- (item->value == EEVEE_RENDER_PASS_BLOOM || STREQ(item->name, "Effects"))))) {
+ if (item->value == EEVEE_RENDER_PASS_AOV) {
+ aov_template.value = item->value;
+ aov_template.icon = 0;
+ aov_template.description = item->description;
+ LISTBASE_FOREACH (ViewLayerAOV *, aov, &view_layer->aovs) {
+ if ((aov->flag & AOV_CONFLICT) != 0) {
+ continue;
+ }
+ aov_template.name = aov->name;
+ aov_template.identifier = aov->name;
+ RNA_enum_item_add(&result, &totitem, &aov_template);
+ aov_template.value++;
+ }
+ }
+ else if (!((!bloom_enabled &&
+ (item->value == EEVEE_RENDER_PASS_BLOOM || STREQ(item->name, "Effects"))) ||
+ (!aov_available && STREQ(item->name, "Shader AOV")))) {
RNA_enum_item_add(&result, &totitem, item);
}
}
@@ -1314,14 +1348,58 @@ static int rna_3DViewShading_render_pass_get(PointerRNA *ptr)
View3DShading *shading = (View3DShading *)ptr->data;
eViewLayerEEVEEPassType result = shading->render_pass;
Scene *scene = rna_3DViewShading_scene(ptr);
+ ViewLayer *view_layer = rna_3DViewShading_view_layer(ptr);
if (result == EEVEE_RENDER_PASS_BLOOM && ((scene->eevee.flag & SCE_EEVEE_BLOOM_ENABLED) == 0)) {
- result = EEVEE_RENDER_PASS_COMBINED;
+ return EEVEE_RENDER_PASS_COMBINED;
+ }
+ else if (result == EEVEE_RENDER_PASS_AOV) {
+ if (!view_layer) {
+ return EEVEE_RENDER_PASS_COMBINED;
+ }
+ const int aov_index = BLI_findstringindex(
+ &view_layer->aovs, shading->aov_name, offsetof(ViewLayerAOV, name));
+ if (aov_index == -1) {
+ return EEVEE_RENDER_PASS_COMBINED;
+ }
+ return result + aov_index;
}
return result;
}
+static void rna_3DViewShading_render_pass_set(PointerRNA *ptr, int value)
+{
+ View3DShading *shading = (View3DShading *)ptr->data;
+ Scene *scene = rna_3DViewShading_scene(ptr);
+ ViewLayer *view_layer = rna_3DViewShading_view_layer(ptr);
+ shading->aov_name[0] = 0;
+
+ if ((value & EEVEE_RENDER_PASS_AOV) != 0) {
+ if (!view_layer) {
+ shading->render_pass = EEVEE_RENDER_PASS_COMBINED;
+ return;
+ }
+ const int aov_index = value & ~EEVEE_RENDER_PASS_AOV;
+ ViewLayerAOV *aov = BLI_findlink(&view_layer->aovs, aov_index);
+ if (!aov) {
+ /* AOV not found, cannot select AOV. */
+ shading->render_pass = EEVEE_RENDER_PASS_COMBINED;
+ return;
+ }
+
+ shading->render_pass = EEVEE_RENDER_PASS_AOV;
+ BLI_strncpy(shading->aov_name, aov->name, sizeof(aov->name));
+ }
+ else if (value == EEVEE_RENDER_PASS_BLOOM &&
+ ((scene->eevee.flag & SCE_EEVEE_BLOOM_ENABLED) == 0)) {
+ shading->render_pass = EEVEE_RENDER_PASS_COMBINED;
+ }
+ else {
+ shading->render_pass = value;
+ }
+}
+
static void rna_SpaceView3D_use_local_collections_update(bContext *C, PointerRNA *ptr)
{
Main *bmain = CTX_data_main(C);
@@ -3488,9 +3566,17 @@ static void rna_def_space_view3d_shading(BlenderRNA *brna)
RNA_def_property_enum_sdna(prop, NULL, "render_pass");
RNA_def_property_enum_items(prop, rna_enum_view3dshading_render_pass_type_items);
RNA_def_property_ui_text(prop, "Render Pass", "Render Pass to show in the viewport");
- RNA_def_property_enum_funcs(
- prop, "rna_3DViewShading_render_pass_get", NULL, "rna_3DViewShading_render_pass_itemf");
+ RNA_def_property_enum_funcs(prop,
+ "rna_3DViewShading_render_pass_get",
+ "rna_3DViewShading_render_pass_set",
+ "rna_3DViewShading_render_pass_itemf");
RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D | NS_VIEW3D_SHADING, NULL);
+
+ prop = RNA_def_property(srna, "aov_name", PROP_STRING, PROP_NONE);
+ RNA_def_property_string_sdna(prop, NULL, "aov_name");
+ RNA_def_property_ui_text(prop, "Shader AOV Name", "Name of the active Shader AOV");
+ RNA_def_property_flag(prop, PROP_HIDDEN);
+ RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL);
}
static void rna_def_space_view3d_overlay(BlenderRNA *brna)