diff options
author | Clément Foucault <foucault.clem@gmail.com> | 2022-04-19 13:01:16 +0300 |
---|---|---|
committer | Clément Foucault <foucault.clem@gmail.com> | 2022-04-19 13:09:18 +0300 |
commit | fa3bd17ae87301ca198d16d2dc7d2432548f34f9 (patch) | |
tree | c08eb8740784799dd3bf9517f4eb4380bc4e6cab /source/blender/nodes | |
parent | 1e3f4c70ab56578b8b0e0056870bd17cc118982a (diff) |
GPU: Replace `GPUMaterialVolumeGrid` by `GPUMaterialAttribute`
This is to make the codegen and shading nodes object type agnostic. This
is essential for flexibility of the engine to use the nodetree as it see
fits.
The essential volume attributes struct properties are moved to the
`GPUMaterialAttribute` which see its final input name set on creation.
The binding process is centralized into `draw_volume.cc` to avoid
duplicating the code between multiple engines. It mimics the hair attributes
process.
Volume object grid transforms and other per object uniforms are packed into
one UBO per object. The grid transform is now based on object which simplify
the matrix preparations.
This also gets rid of the double transforms and use object info orco factors
for volume objects.
Tagging @brecht because he did the initial implementation of Volume Grids.
Diffstat (limited to 'source/blender/nodes')
3 files changed, 31 insertions, 25 deletions
diff --git a/source/blender/nodes/shader/nodes/node_shader_attribute.cc b/source/blender/nodes/shader/nodes/node_shader_attribute.cc index bb01818e734..d01271c15d3 100644 --- a/source/blender/nodes/shader/nodes/node_shader_attribute.cc +++ b/source/blender/nodes/shader/nodes/node_shader_attribute.cc @@ -37,24 +37,6 @@ static int node_shader_gpu_attribute(GPUMaterial *mat, NodeShaderAttribute *attr = static_cast<NodeShaderAttribute *>(node->storage); bool is_varying = attr->type == SHD_ATTRIBUTE_GEOMETRY; - if (GPU_material_is_volume_shader(mat) && is_varying) { - if (out[0].hasoutput) { - out[0].link = GPU_volume_grid(mat, attr->name, GPU_VOLUME_DEFAULT_0); - } - if (out[1].hasoutput) { - out[1].link = GPU_volume_grid(mat, attr->name, GPU_VOLUME_DEFAULT_0); - } - if (out[2].hasoutput) { - out[2].link = GPU_volume_grid(mat, attr->name, GPU_VOLUME_DEFAULT_0); - } - if (out[3].hasoutput) { - static const float default_alpha = 1.0f; - out[3].link = GPU_constant(&default_alpha); - } - - return 1; - } - GPUNodeLink *cd_attr; if (is_varying) { @@ -64,6 +46,13 @@ static int node_shader_gpu_attribute(GPUMaterial *mat, cd_attr = GPU_uniform_attribute(mat, attr->name, attr->type == SHD_ATTRIBUTE_INSTANCER); } + if (STREQ(attr->name, "color")) { + GPU_link(mat, "node_attribute_color", cd_attr, &cd_attr); + } + else if (STREQ(attr->name, "temperature")) { + GPU_link(mat, "node_attribute_temperature", cd_attr, &cd_attr); + } + GPU_stack_link(mat, node, "node_attribute", in, out, cd_attr); int i; diff --git a/source/blender/nodes/shader/nodes/node_shader_volume_info.cc b/source/blender/nodes/shader/nodes/node_shader_volume_info.cc index 6676a7653fe..a202312f8d8 100644 --- a/source/blender/nodes/shader/nodes/node_shader_volume_info.cc +++ b/source/blender/nodes/shader/nodes/node_shader_volume_info.cc @@ -20,16 +20,18 @@ static int node_shader_gpu_volume_info(GPUMaterial *mat, GPUNodeStack *out) { if (out[0].hasoutput) { - out[0].link = GPU_volume_grid(mat, "color", GPU_VOLUME_DEFAULT_0); + out[0].link = GPU_attribute(mat, CD_AUTO_FROM_NAME, "color"); + GPU_link(mat, "node_attribute_color", out[0].link, &out[0].link); } if (out[1].hasoutput) { - out[1].link = GPU_volume_grid(mat, "density", GPU_VOLUME_DEFAULT_0); + out[1].link = GPU_attribute(mat, CD_AUTO_FROM_NAME, "density"); } if (out[2].hasoutput) { - out[2].link = GPU_volume_grid(mat, "flame", GPU_VOLUME_DEFAULT_0); + out[2].link = GPU_attribute(mat, CD_AUTO_FROM_NAME, "flame"); } if (out[3].hasoutput) { - out[3].link = GPU_volume_grid(mat, "temperature", GPU_VOLUME_DEFAULT_0); + out[3].link = GPU_attribute(mat, CD_AUTO_FROM_NAME, "temperature"); + GPU_link(mat, "node_attribute_temperature", out[3].link, &out[3].link); } return true; diff --git a/source/blender/nodes/shader/nodes/node_shader_volume_principled.cc b/source/blender/nodes/shader/nodes/node_shader_volume_principled.cc index d414b4b2ef7..d4d5c4789ed 100644 --- a/source/blender/nodes/shader/nodes/node_shader_volume_principled.cc +++ b/source/blender/nodes/shader/nodes/node_shader_volume_principled.cc @@ -43,6 +43,18 @@ static void node_shader_init_volume_principled(bNodeTree *UNUSED(ntree), bNode * } } +static void attribute_post_process(GPUMaterial *mat, + const char *attribute_name, + GPUNodeLink **attribute_link) +{ + if (STREQ(attribute_name, "color")) { + GPU_link(mat, "node_attribute_color", *attribute_link, attribute_link); + } + else if (STREQ(attribute_name, "temperature")) { + GPU_link(mat, "node_attribute_temperature", *attribute_link, attribute_link); + } +} + static int node_shader_gpu_volume_principled(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), @@ -67,13 +79,16 @@ static int node_shader_gpu_volume_principled(GPUMaterial *mat, } if (STREQ(sock->name, "Density Attribute")) { - density = GPU_volume_grid(mat, attribute_name, GPU_VOLUME_DEFAULT_1); + density = GPU_attribute_with_default(mat, CD_AUTO_FROM_NAME, attribute_name, GPU_DEFAULT_1); + attribute_post_process(mat, attribute_name, &density); } else if (STREQ(sock->name, "Color Attribute")) { - color = GPU_volume_grid(mat, attribute_name, GPU_VOLUME_DEFAULT_1); + color = GPU_attribute_with_default(mat, CD_AUTO_FROM_NAME, attribute_name, GPU_DEFAULT_1); + attribute_post_process(mat, attribute_name, &color); } else if (use_blackbody && STREQ(sock->name, "Temperature Attribute")) { - temperature = GPU_volume_grid(mat, attribute_name, GPU_VOLUME_DEFAULT_0); + temperature = GPU_attribute(mat, CD_AUTO_FROM_NAME, attribute_name); + attribute_post_process(mat, attribute_name, &temperature); } } |