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/gpu
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/gpu')
-rw-r--r--source/blender/gpu/CMakeLists.txt1
-rw-r--r--source/blender/gpu/GPU_material.h1
-rw-r--r--source/blender/gpu/intern/gpu_codegen.c37
-rw-r--r--source/blender/gpu/intern/gpu_material.c8
-rw-r--r--source/blender/gpu/intern/gpu_material_library.c7
-rw-r--r--source/blender/gpu/intern/gpu_node_graph.c4
-rw-r--r--source/blender/gpu/intern/gpu_node_graph.h10
-rw-r--r--source/blender/gpu/shaders/material/gpu_shader_material_output_aov.glsl13
8 files changed, 77 insertions, 4 deletions
diff --git a/source/blender/gpu/CMakeLists.txt b/source/blender/gpu/CMakeLists.txt
index 7e2fe753b7b..69a79e2f2ce 100644
--- a/source/blender/gpu/CMakeLists.txt
+++ b/source/blender/gpu/CMakeLists.txt
@@ -313,6 +313,7 @@ data_to_c_simple(shaders/material/gpu_shader_material_noise.glsl SRC)
data_to_c_simple(shaders/material/gpu_shader_material_normal.glsl SRC)
data_to_c_simple(shaders/material/gpu_shader_material_normal_map.glsl SRC)
data_to_c_simple(shaders/material/gpu_shader_material_object_info.glsl SRC)
+data_to_c_simple(shaders/material/gpu_shader_material_output_aov.glsl SRC)
data_to_c_simple(shaders/material/gpu_shader_material_output_material.glsl SRC)
data_to_c_simple(shaders/material/gpu_shader_material_output_world.glsl SRC)
data_to_c_simple(shaders/material/gpu_shader_material_particle_info.glsl SRC)
diff --git a/source/blender/gpu/GPU_material.h b/source/blender/gpu/GPU_material.h
index 67cd1a61aed..312da491a36 100644
--- a/source/blender/gpu/GPU_material.h
+++ b/source/blender/gpu/GPU_material.h
@@ -173,6 +173,7 @@ GPUNodeLink *GPU_uniformbuf_link_out(struct GPUMaterial *mat,
const int index);
void GPU_material_output_link(GPUMaterial *material, GPUNodeLink *link);
+void GPU_material_add_output_link_aov(GPUMaterial *material, GPUNodeLink *link, int hash);
void GPU_material_sss_profile_create(GPUMaterial *material,
float radii[3],
diff --git a/source/blender/gpu/intern/gpu_codegen.c b/source/blender/gpu/intern/gpu_codegen.c
index 3ebe2edc89e..84da95f6fee 100644
--- a/source/blender/gpu/intern/gpu_codegen.c
+++ b/source/blender/gpu/intern/gpu_codegen.c
@@ -411,7 +411,7 @@ static void codegen_declare_tmps(DynStr *ds, GPUNodeGraph *graph)
BLI_dynstr_append(ds, "\n");
}
-static void codegen_call_functions(DynStr *ds, GPUNodeGraph *graph, GPUOutput *finaloutput)
+static void codegen_call_functions(DynStr *ds, GPUNodeGraph *graph)
{
LISTBASE_FOREACH (GPUNode *, node, &graph->nodes) {
BLI_dynstr_appendf(ds, " %s(", node->name);
@@ -509,8 +509,11 @@ static void codegen_call_functions(DynStr *ds, GPUNodeGraph *graph, GPUOutput *f
BLI_dynstr_append(ds, ");\n");
}
+}
- BLI_dynstr_appendf(ds, "\n return tmp%d;\n", finaloutput->id);
+static void codegen_final_output(DynStr *ds, GPUOutput *finaloutput)
+{
+ BLI_dynstr_appendf(ds, "return tmp%d;\n", finaloutput->id);
}
static char *code_generate_fragment(GPUMaterial *material,
@@ -593,7 +596,35 @@ static char *code_generate_fragment(GPUMaterial *material,
}
codegen_declare_tmps(ds, graph);
- codegen_call_functions(ds, graph, graph->outlink->output);
+ codegen_call_functions(ds, graph);
+
+ BLI_dynstr_append(ds, " #ifndef VOLUMETRICS\n");
+ BLI_dynstr_append(ds, " if (renderPassAOV) {\n");
+ BLI_dynstr_append(ds, " switch (render_pass_aov_hash()) {\n");
+ GSet *aovhashes_added = BLI_gset_int_new(__func__);
+ LISTBASE_FOREACH (GPUNodeGraphOutputLink *, aovlink, &graph->outlink_aovs) {
+ void *aov_key = POINTER_FROM_INT(aovlink->hash);
+ if (BLI_gset_haskey(aovhashes_added, aov_key)) {
+ continue;
+ }
+ BLI_dynstr_appendf(ds, " case %d: {\n ", aovlink->hash);
+ codegen_final_output(ds, aovlink->outlink->output);
+ BLI_dynstr_append(ds, " }\n");
+ BLI_gset_add(aovhashes_added, aov_key);
+ }
+ BLI_gset_free(aovhashes_added, NULL);
+ BLI_dynstr_append(ds, " default: {\n");
+ BLI_dynstr_append(ds, " Closure no_aov = CLOSURE_DEFAULT;\n");
+ BLI_dynstr_append(ds, " no_aov.holdout = 1.0;\n");
+ BLI_dynstr_append(ds, " return no_aov;\n");
+ BLI_dynstr_append(ds, " }\n");
+ BLI_dynstr_append(ds, " }\n");
+ BLI_dynstr_append(ds, " } else {\n");
+ BLI_dynstr_append(ds, " #else /* VOLUMETRICS */\n");
+ BLI_dynstr_append(ds, " {\n");
+ BLI_dynstr_append(ds, " #endif /* VOLUMETRICS */\n ");
+ codegen_final_output(ds, graph->outlink->output);
+ BLI_dynstr_append(ds, " }\n");
BLI_dynstr_append(ds, "}\n");
diff --git a/source/blender/gpu/intern/gpu_material.c b/source/blender/gpu/intern/gpu_material.c
index a0fe77598f2..3f22424c7c9 100644
--- a/source/blender/gpu/intern/gpu_material.c
+++ b/source/blender/gpu/intern/gpu_material.c
@@ -597,6 +597,14 @@ void GPU_material_output_link(GPUMaterial *material, GPUNodeLink *link)
}
}
+void GPU_material_add_output_link_aov(GPUMaterial *material, GPUNodeLink *link, int hash)
+{
+ GPUNodeGraphOutputLink *aov_link = MEM_callocN(sizeof(GPUNodeGraphOutputLink), __func__);
+ aov_link->outlink = link;
+ aov_link->hash = hash;
+ BLI_addtail(&material->graph.outlink_aovs, aov_link);
+}
+
GPUNodeGraph *gpu_material_node_graph(GPUMaterial *material)
{
return &material->graph;
diff --git a/source/blender/gpu/intern/gpu_material_library.c b/source/blender/gpu/intern/gpu_material_library.c
index e0165e1fa83..496988c4ba9 100644
--- a/source/blender/gpu/intern/gpu_material_library.c
+++ b/source/blender/gpu/intern/gpu_material_library.c
@@ -84,6 +84,7 @@ extern char datatoc_gpu_shader_material_noise_glsl[];
extern char datatoc_gpu_shader_material_normal_glsl[];
extern char datatoc_gpu_shader_material_normal_map_glsl[];
extern char datatoc_gpu_shader_material_object_info_glsl[];
+extern char datatoc_gpu_shader_material_output_aov_glsl[];
extern char datatoc_gpu_shader_material_output_material_glsl[];
extern char datatoc_gpu_shader_material_output_world_glsl[];
extern char datatoc_gpu_shader_material_particle_info_glsl[];
@@ -354,6 +355,11 @@ static GPUMaterialLibrary gpu_shader_material_object_info_library = {
.dependencies = {NULL},
};
+static GPUMaterialLibrary gpu_shader_material_output_aov_library = {
+ .code = datatoc_gpu_shader_material_output_aov_glsl,
+ .dependencies = {NULL},
+};
+
static GPUMaterialLibrary gpu_shader_material_output_material_library = {
.code = datatoc_gpu_shader_material_output_material_glsl,
.dependencies = {NULL},
@@ -619,6 +625,7 @@ static GPUMaterialLibrary *gpu_material_libraries[] = {
&gpu_shader_material_normal_library,
&gpu_shader_material_normal_map_library,
&gpu_shader_material_object_info_library,
+ &gpu_shader_material_output_aov_library,
&gpu_shader_material_output_material_library,
&gpu_shader_material_output_world_library,
&gpu_shader_material_particle_info_library,
diff --git a/source/blender/gpu/intern/gpu_node_graph.c b/source/blender/gpu/intern/gpu_node_graph.c
index 2a2a51e32b3..08da49c3475 100644
--- a/source/blender/gpu/intern/gpu_node_graph.c
+++ b/source/blender/gpu/intern/gpu_node_graph.c
@@ -805,6 +805,7 @@ void gpu_node_graph_free_nodes(GPUNodeGraph *graph)
/* Free both node graph and requested attributes and textures. */
void gpu_node_graph_free(GPUNodeGraph *graph)
{
+ BLI_freelistN(&graph->outlink_aovs);
gpu_node_graph_free_nodes(graph);
LISTBASE_FOREACH (GPUMaterialVolumeGrid *, grid, &graph->volume_grids) {
@@ -847,6 +848,9 @@ void gpu_node_graph_prune_unused(GPUNodeGraph *graph)
}
gpu_nodes_tag(graph->outlink);
+ LISTBASE_FOREACH (GPUNodeGraphOutputLink *, aovlink, &graph->outlink_aovs) {
+ gpu_nodes_tag(aovlink->outlink);
+ }
for (GPUNode *node = graph->nodes.first, *next = NULL; node; node = next) {
next = node->next;
diff --git a/source/blender/gpu/intern/gpu_node_graph.h b/source/blender/gpu/intern/gpu_node_graph.h
index a0e6298cd92..0ef95d94c0d 100644
--- a/source/blender/gpu/intern/gpu_node_graph.h
+++ b/source/blender/gpu/intern/gpu_node_graph.h
@@ -141,12 +141,20 @@ typedef struct GPUInput {
};
} GPUInput;
+typedef struct GPUNodeGraphOutputLink {
+ struct GPUNodeGraphOutputLink *next, *prev;
+ int hash;
+ GPUNodeLink *outlink;
+} GPUNodeGraphOutputLink;
+
typedef struct GPUNodeGraph {
/* Nodes */
ListBase nodes;
- /* Output. */
+ /* Main Output. */
GPUNodeLink *outlink;
+ /* List of GPUNodeGraphOutputLink */
+ ListBase outlink_aovs;
/* Requested attributes and textures. */
ListBase attributes;
diff --git a/source/blender/gpu/shaders/material/gpu_shader_material_output_aov.glsl b/source/blender/gpu/shaders/material/gpu_shader_material_output_aov.glsl
new file mode 100644
index 00000000000..648994739bf
--- /dev/null
+++ b/source/blender/gpu/shaders/material/gpu_shader_material_output_aov.glsl
@@ -0,0 +1,13 @@
+
+void node_output_aov(vec4 color, float value, out Closure result)
+{
+ result = CLOSURE_DEFAULT;
+#ifndef VOLUMETRICS
+ if (render_pass_aov_is_color()) {
+ result.radiance = color.rgb;
+ }
+ else {
+ result.radiance = vec3(value);
+ }
+#endif
+}