From b9f6d033beecd75398be14419d37d8aab0609812 Mon Sep 17 00:00:00 2001 From: Brecht Van Lommel Date: Wed, 11 Mar 2020 14:58:19 +0100 Subject: Eevee: internal support for arbitrary number of volume grids This has no user visible impact yet since smoke volumes only support a fixed set of attributes, but will become important with the new volume object. For GPU shader compilation, volume grids are now handled separately from image textures. They are somewhere between a vertex attribute and an image texture, basically an attribute that is stored as a texture. Differential Revision: https://developer.blender.org/D6952 --- .../nodes/shader/nodes/node_shader_attribute.c | 34 ++++++---------- .../nodes/shader/nodes/node_shader_volume_info.c | 26 +++++++----- .../shader/nodes/node_shader_volume_principled.c | 47 ++++------------------ 3 files changed, 34 insertions(+), 73 deletions(-) (limited to 'source/blender/nodes') diff --git a/source/blender/nodes/shader/nodes/node_shader_attribute.c b/source/blender/nodes/shader/nodes/node_shader_attribute.c index fa0b8955c58..6b5d46e250b 100644 --- a/source/blender/nodes/shader/nodes/node_shader_attribute.c +++ b/source/blender/nodes/shader/nodes/node_shader_attribute.c @@ -42,28 +42,18 @@ static int node_shader_gpu_attribute(GPUMaterial *mat, { NodeShaderAttribute *attr = node->storage; - /* FIXME : if an attribute layer (like vertex color) has one of these names, - * it will not work as expected. */ - if (strcmp(attr->name, "density") == 0) { - return GPU_stack_link( - mat, node, "node_attribute_volume_density", in, out, GPU_builtin(GPU_VOLUME_DENSITY)); - } - else if (strcmp(attr->name, "color") == 0) { - return GPU_stack_link( - mat, node, "node_attribute_volume_color", in, out, GPU_builtin(GPU_VOLUME_COLOR)); - } - else if (strcmp(attr->name, "flame") == 0) { - return GPU_stack_link( - mat, node, "node_attribute_volume_flame", in, out, GPU_builtin(GPU_VOLUME_FLAME)); - } - else if (strcmp(attr->name, "temperature") == 0) { - return GPU_stack_link(mat, - node, - "node_attribute_volume_temperature", - in, - out, - GPU_builtin(GPU_VOLUME_FLAME), - GPU_builtin(GPU_VOLUME_TEMPERATURE)); + if (GPU_material_is_volume_shader(mat)) { + if (out[0].hasoutput) { + out[0].link = GPU_volume_grid(mat, attr->name); + } + if (out[1].hasoutput) { + out[1].link = GPU_volume_grid(mat, attr->name); + } + if (out[2].hasoutput) { + out[2].link = GPU_volume_grid(mat, attr->name); + } + + return 1; } else { GPUNodeLink *cd_attr = GPU_attribute(mat, CD_AUTO_FROM_NAME, attr->name); diff --git a/source/blender/nodes/shader/nodes/node_shader_volume_info.c b/source/blender/nodes/shader/nodes/node_shader_volume_info.c index c91c82eee6c..7ccc00f1af3 100644 --- a/source/blender/nodes/shader/nodes/node_shader_volume_info.c +++ b/source/blender/nodes/shader/nodes/node_shader_volume_info.c @@ -28,21 +28,25 @@ static bNodeSocketTemplate sh_node_volume_info_out[] = { }; static int node_shader_gpu_volume_info(GPUMaterial *mat, - bNode *node, + bNode *UNUSED(node), bNodeExecData *UNUSED(execdata), - GPUNodeStack *in, + GPUNodeStack *UNUSED(in), GPUNodeStack *out) { + if (out[0].hasoutput) { + out[0].link = GPU_volume_grid(mat, "color"); + } + if (out[1].hasoutput) { + out[1].link = GPU_volume_grid(mat, "density"); + } + if (out[2].hasoutput) { + out[2].link = GPU_volume_grid(mat, "flame"); + } + if (out[3].hasoutput) { + out[3].link = GPU_volume_grid(mat, "temperature"); + } - return GPU_stack_link(mat, - node, - "node_volume_info", - in, - out, - GPU_builtin(GPU_VOLUME_DENSITY), - GPU_builtin(GPU_VOLUME_COLOR), - GPU_builtin(GPU_VOLUME_FLAME), - GPU_builtin(GPU_VOLUME_TEMPERATURE)); + return true; } void register_node_type_sh_volume_info(void) diff --git a/source/blender/nodes/shader/nodes/node_shader_volume_principled.c b/source/blender/nodes/shader/nodes/node_shader_volume_principled.c index d82ef1a03e9..92e1b3435c8 100644 --- a/source/blender/nodes/shader/nodes/node_shader_volume_principled.c +++ b/source/blender/nodes/shader/nodes/node_shader_volume_principled.c @@ -54,42 +54,6 @@ static void node_shader_init_volume_principled(bNodeTree *UNUSED(ntree), bNode * } } -static void node_shader_gpu_volume_attribute(GPUMaterial *mat, - const char *name, - GPUNodeLink **outcol, - GPUNodeLink **outvec, - GPUNodeLink **outf) -{ - if (strcmp(name, "density") == 0) { - GPU_link(mat, - "node_attribute_volume_density", - GPU_builtin(GPU_VOLUME_DENSITY), - outcol, - outvec, - outf); - } - else if (strcmp(name, "color") == 0) { - GPU_link( - mat, "node_attribute_volume_color", GPU_builtin(GPU_VOLUME_COLOR), outcol, outvec, outf); - } - else if (strcmp(name, "flame") == 0) { - GPU_link( - mat, "node_attribute_volume_flame", GPU_builtin(GPU_VOLUME_FLAME), outcol, outvec, outf); - } - else if (strcmp(name, "temperature") == 0) { - GPU_link(mat, - "node_attribute_volume_temperature", - GPU_builtin(GPU_VOLUME_FLAME), - GPU_builtin(GPU_VOLUME_TEMPERATURE), - outcol, - outvec, - outf); - } - else { - *outcol = *outvec = *outf = NULL; - } -} - static int node_shader_gpu_volume_principled(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), @@ -108,16 +72,19 @@ static int node_shader_gpu_volume_principled(GPUMaterial *mat, } bNodeSocketValueString *value = sock->default_value; - GPUNodeLink *outcol, *outvec, *outf; + const char *attribute_name = value->value; + if (attribute_name[0] == '\0') { + continue; + } if (STREQ(sock->name, "Density Attribute")) { - node_shader_gpu_volume_attribute(mat, value->value, &outcol, &outvec, &density); + density = GPU_volume_grid(mat, attribute_name); } else if (STREQ(sock->name, "Color Attribute")) { - node_shader_gpu_volume_attribute(mat, value->value, &color, &outvec, &outf); + color = GPU_volume_grid(mat, attribute_name); } else if (use_blackbody && STREQ(sock->name, "Temperature Attribute")) { - node_shader_gpu_volume_attribute(mat, value->value, &outcol, &outvec, &temperature); + temperature = GPU_volume_grid(mat, attribute_name); } } -- cgit v1.2.3