diff options
author | Brecht Van Lommel <brecht@blender.org> | 2022-01-25 15:25:33 +0300 |
---|---|---|
committer | Fabian Schempp <fabianschempp@googlemail.com> | 2022-04-11 01:28:39 +0300 |
commit | 0f5044245d681df06879831a5b5436fde9dca972 (patch) | |
tree | 85d18ec10a4eb02e196355e507f30cfd58e6a666 /source | |
parent | e250d65db7fd2f2613b9c29a95f8034fafee25e2 (diff) |
Cycles: add Point Info node
With (center) position, radius and random value outputs.
Eevee does not yet support rendering point clouds, but an untested
implementation of this node was added for when it does.
Ref T92573
Diffstat (limited to 'source')
17 files changed, 123 insertions, 16 deletions
diff --git a/source/blender/blenkernel/BKE_node.h b/source/blender/blenkernel/BKE_node.h index cd6d58f563a..b2c91fafe97 100644 --- a/source/blender/blenkernel/BKE_node.h +++ b/source/blender/blenkernel/BKE_node.h @@ -1178,6 +1178,7 @@ void BKE_nodetree_remove_layer_n(struct bNodeTree *ntree, struct Scene *scene, i #define SH_NODE_OUTPUT_AOV 707 #define SH_NODE_VECTOR_ROTATE 708 #define SH_NODE_CURVE_FLOAT 709 +#define SH_NODE_POINT_INFO 710 /** \} */ diff --git a/source/blender/blenkernel/intern/node.cc b/source/blender/blenkernel/intern/node.cc index 8c58f3bcfc8..626aa503f42 100644 --- a/source/blender/blenkernel/intern/node.cc +++ b/source/blender/blenkernel/intern/node.cc @@ -4668,6 +4668,7 @@ static void registerTextureNodes() register_node_type_sh_tangent(); register_node_type_sh_normal_map(); register_node_type_sh_hair_info(); + register_node_type_sh_point_info(); register_node_type_sh_volume_info(); register_node_type_tex_checker(); diff --git a/source/blender/draw/engines/eevee/eevee_private.h b/source/blender/draw/engines/eevee/eevee_private.h index 996716d6def..766e721b1b8 100644 --- a/source/blender/draw/engines/eevee/eevee_private.h +++ b/source/blender/draw/engines/eevee/eevee_private.h @@ -176,7 +176,7 @@ enum { VAR_MAT_MESH = (1 << 0), VAR_MAT_VOLUME = (1 << 1), VAR_MAT_HAIR = (1 << 2), - /* VAR_MAT_PROBE = (1 << 3), UNUSED */ + VAR_MAT_POINTCLOUD = (1 << 3), VAR_MAT_BLEND = (1 << 4), VAR_MAT_LOOKDEV = (1 << 5), VAR_MAT_HOLDOUT = (1 << 6), diff --git a/source/blender/draw/engines/eevee/eevee_shaders.c b/source/blender/draw/engines/eevee/eevee_shaders.c index adede7676d5..e56097df6b7 100644 --- a/source/blender/draw/engines/eevee/eevee_shaders.c +++ b/source/blender/draw/engines/eevee/eevee_shaders.c @@ -1357,6 +1357,9 @@ static char *eevee_get_defines(int options) if ((options & VAR_MAT_HAIR) != 0) { BLI_dynstr_append(ds, "#define HAIR_SHADER\n"); } + if ((options & VAR_MAT_POINTCLOUD) != 0) { + BLI_dynstr_append(ds, "#define POINTCLOUD_SHADER\n"); + } if ((options & VAR_WORLD_PROBE) != 0) { BLI_dynstr_append(ds, "#define PROBE_CAPTURE\n"); } diff --git a/source/blender/draw/engines/eevee/shaders/shadow_vert.glsl b/source/blender/draw/engines/eevee/shaders/shadow_vert.glsl index 0e342938396..cbfa9737a84 100644 --- a/source/blender/draw/engines/eevee/shaders/shadow_vert.glsl +++ b/source/blender/draw/engines/eevee/shaders/shadow_vert.glsl @@ -26,6 +26,9 @@ void main() worldNormal = cross(hairTangent, binor); vec3 world_pos = pos; +#elif defined(POINTCLOUD_SHADER) + pointcloud_get_pos_and_radius(pointPosition, pointRadius); + pointID = gl_VertexID; #else vec3 world_pos = point_object_to_world(pos); #endif diff --git a/source/blender/draw/engines/eevee/shaders/surface_lib.glsl b/source/blender/draw/engines/eevee/shaders/surface_lib.glsl index 7d016d57c46..d7fc5e0b52a 100644 --- a/source/blender/draw/engines/eevee/shaders/surface_lib.glsl +++ b/source/blender/draw/engines/eevee/shaders/surface_lib.glsl @@ -42,3 +42,13 @@ IN_OUT ShaderHairInterface flat int hairStrandID; }; #endif + +#ifdef POINTCLOUD_SHADER +IN_OUT ShaderPointCloudInterface +{ + /* world space */ + float pointRadius; + float pointPosition; + flat int pointID; +}; +#endif diff --git a/source/blender/draw/engines/eevee/shaders/surface_vert.glsl b/source/blender/draw/engines/eevee/shaders/surface_vert.glsl index 0ad1393dd70..51e9eda6cc2 100644 --- a/source/blender/draw/engines/eevee/shaders/surface_vert.glsl +++ b/source/blender/draw/engines/eevee/shaders/surface_vert.glsl @@ -31,6 +31,9 @@ void main() hairThickTime); worldNormal = cross(hairTangent, binor); vec3 world_pos = pos; +#elif defined(POINTCLOUD_SHADER) + pointcloud_get_pos_and_radius(pointPosition, pointRadius); + pointID = gl_VertexID; #else vec3 world_pos = point_object_to_world(pos); #endif diff --git a/source/blender/draw/intern/shaders/common_pointcloud_lib.glsl b/source/blender/draw/intern/shaders/common_pointcloud_lib.glsl index 2da16d3f6a9..dd725ad327f 100644 --- a/source/blender/draw/intern/shaders/common_pointcloud_lib.glsl +++ b/source/blender/draw/intern/shaders/common_pointcloud_lib.glsl @@ -22,13 +22,22 @@ mat3 pointcloud_get_facing_matrix(vec3 p) return facing_mat; } +/* Returns world center position and radius. */ +void pointcloud_get_pos_and_radius(out vec3 outpos, out float outradius) +{ + outpos = point_object_to_world(pos.xyz); + outradius = dot(abs(mat3(ModelMatrix) * pos.www), vec3(1.0 / 3.0)); +} + /* Return world position and normal. */ void pointcloud_get_pos_and_nor(out vec3 outpos, out vec3 outnor) { - vec3 p = point_object_to_world(pos.xyz); + vec3 p; + float radius; + pointcloud_get_pos_and_radius(p, radius); + mat3 facing_mat = pointcloud_get_facing_matrix(p); - float radius = dot(abs(mat3(ModelMatrix) * pos.www), vec3(1.0 / 3.0)); /* TODO(fclem): remove multiplication here. Here only for keeping the size correct for now. */ radius *= 0.01; outpos = p + (facing_mat * pos_inst) * radius; diff --git a/source/blender/gpu/CMakeLists.txt b/source/blender/gpu/CMakeLists.txt index 3e811caa14b..5be4352cffd 100644 --- a/source/blender/gpu/CMakeLists.txt +++ b/source/blender/gpu/CMakeLists.txt @@ -323,6 +323,7 @@ set(GLSL_SRC shaders/material/gpu_shader_material_output_material.glsl shaders/material/gpu_shader_material_output_world.glsl shaders/material/gpu_shader_material_particle_info.glsl + shaders/material/gpu_shader_material_point_info.glsl shaders/material/gpu_shader_material_principled.glsl shaders/material/gpu_shader_material_refraction.glsl shaders/material/gpu_shader_material_rgb_curves.glsl diff --git a/source/blender/gpu/intern/gpu_material_library.c b/source/blender/gpu/intern/gpu_material_library.c index 74e0270c42a..712ab44adb3 100644 --- a/source/blender/gpu/intern/gpu_material_library.c +++ b/source/blender/gpu/intern/gpu_material_library.c @@ -91,6 +91,7 @@ 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[]; +extern char datatoc_gpu_shader_material_point_info_glsl[]; extern char datatoc_gpu_shader_material_principled_glsl[]; extern char datatoc_gpu_shader_material_refraction_glsl[]; extern char datatoc_gpu_shader_material_rgb_curves_glsl[]; @@ -295,7 +296,7 @@ static GPUMaterialLibrary gpu_shader_material_glass_library = { static GPUMaterialLibrary gpu_shader_material_hair_info_library = { .code = datatoc_gpu_shader_material_hair_info_glsl, - .dependencies = {NULL}, + .dependencies = {&gpu_shader_material_hash_library, NULL}, }; static GPUMaterialLibrary gpu_shader_material_holdout_library = { @@ -388,6 +389,11 @@ static GPUMaterialLibrary gpu_shader_material_particle_info_library = { .dependencies = {NULL}, }; +static GPUMaterialLibrary gpu_shader_material_point_info_library = { + .code = datatoc_gpu_shader_material_point_info_glsl, + .dependencies = {&gpu_shader_material_hash_library, NULL}, +}; + static GPUMaterialLibrary gpu_shader_material_principled_library = { .code = datatoc_gpu_shader_material_principled_glsl, .dependencies = {NULL}, @@ -644,6 +650,7 @@ static GPUMaterialLibrary *gpu_material_libraries[] = { &gpu_shader_material_output_material_library, &gpu_shader_material_output_world_library, &gpu_shader_material_particle_info_library, + &gpu_shader_material_point_info_library, &gpu_shader_material_principled_library, &gpu_shader_material_refraction_library, &gpu_shader_material_rgb_curves_library, diff --git a/source/blender/gpu/shaders/material/gpu_shader_material_hair_info.glsl b/source/blender/gpu/shaders/material/gpu_shader_material_hair_info.glsl index 6ffa6b59572..59f0377869b 100644 --- a/source/blender/gpu/shaders/material/gpu_shader_material_hair_info.glsl +++ b/source/blender/gpu/shaders/material/gpu_shader_material_hair_info.glsl @@ -1,15 +1,4 @@ -float wang_hash_noise(uint s) -{ - s = (s ^ 61u) ^ (s >> 16u); - s *= 9u; - s = s ^ (s >> 4u); - s *= 0x27d4eb2du; - s = s ^ (s >> 15u); - - return fract(float(s) / 4294967296.0); -} - void node_hair_info(float hair_length, out float is_strand, out float intercept, diff --git a/source/blender/gpu/shaders/material/gpu_shader_material_hash.glsl b/source/blender/gpu/shaders/material/gpu_shader_material_hash.glsl index 86191451e5f..cb798047791 100644 --- a/source/blender/gpu/shaders/material/gpu_shader_material_hash.glsl +++ b/source/blender/gpu/shaders/material/gpu_shader_material_hash.glsl @@ -215,3 +215,14 @@ float integer_noise(int n) nn = (n * (n * n * 60493 + 19990303) + 1376312589) & 0x7fffffff; return 0.5 * (float(nn) / 1073741824.0); } + +float wang_hash_noise(uint s) +{ + s = (s ^ 61u) ^ (s >> 16u); + s *= 9u; + s = s ^ (s >> 4u); + s *= 0x27d4eb2du; + s = s ^ (s >> 15u); + + return fract(float(s) / 4294967296.0); +} diff --git a/source/blender/gpu/shaders/material/gpu_shader_material_point_info.glsl b/source/blender/gpu/shaders/material/gpu_shader_material_point_info.glsl new file mode 100644 index 00000000000..d717ac97b28 --- /dev/null +++ b/source/blender/gpu/shaders/material/gpu_shader_material_point_info.glsl @@ -0,0 +1,13 @@ + +void node_point_info(out vec3 position, out float radius, out float random) +{ +#ifdef POINTCLOUD_SHADER + position = pointPosition; + radius = pointRadius; + random = wang_hash_noise(uint(pointID)); +#else + position = vec3(0.0, 0.0, 0.0); + radius = 0.0; + random = 0.0; +#endif +} diff --git a/source/blender/nodes/NOD_shader.h b/source/blender/nodes/NOD_shader.h index 65720fc119b..57740ce3ad9 100644 --- a/source/blender/nodes/NOD_shader.h +++ b/source/blender/nodes/NOD_shader.h @@ -85,6 +85,7 @@ void register_node_type_sh_layer_weight(void); void register_node_type_sh_tex_coord(void); void register_node_type_sh_particle_info(void); void register_node_type_sh_hair_info(void); +void register_node_type_sh_point_info(void); void register_node_type_sh_volume_info(void); void register_node_type_sh_script(void); void register_node_type_sh_normal_map(void); @@ -146,7 +147,6 @@ void register_node_type_sh_custom_group(bNodeType *ntype); struct bNodeTreeExec *ntreeShaderBeginExecTree(struct bNodeTree *ntree); void ntreeShaderEndExecTree(struct bNodeTreeExec *exec); - /** * Find an output node of the shader tree. * diff --git a/source/blender/nodes/NOD_static_types.h b/source/blender/nodes/NOD_static_types.h index a819aa87dab..34e37b6bd1f 100644 --- a/source/blender/nodes/NOD_static_types.h +++ b/source/blender/nodes/NOD_static_types.h @@ -96,6 +96,7 @@ DefNode(ShaderNode, SH_NODE_LIGHT_FALLOFF, 0, "LIG DefNode(ShaderNode, SH_NODE_OBJECT_INFO, 0, "OBJECT_INFO", ObjectInfo, "Object Info", "" ) DefNode(ShaderNode, SH_NODE_PARTICLE_INFO, 0, "PARTICLE_INFO", ParticleInfo, "Particle Info", "" ) DefNode(ShaderNode, SH_NODE_HAIR_INFO, 0, "HAIR_INFO", HairInfo, "Hair Info", "" ) +DefNode(ShaderNode, SH_NODE_POINT_INFO, 0, "POINT_INFO", PointInfo, "Point Info", "" ) DefNode(ShaderNode, SH_NODE_VOLUME_INFO, 0, "VOLUME_INFO", VolumeInfo, "Volume Info", "" ) DefNode(ShaderNode, SH_NODE_WIREFRAME, def_sh_tex_wireframe, "WIREFRAME", Wireframe, "Wireframe", "" ) DefNode(ShaderNode, SH_NODE_WAVELENGTH, 0, "WAVELENGTH", Wavelength, "Wavelength", "" ) diff --git a/source/blender/nodes/shader/CMakeLists.txt b/source/blender/nodes/shader/CMakeLists.txt index 4cf18429e0d..c8eb0b8d570 100644 --- a/source/blender/nodes/shader/CMakeLists.txt +++ b/source/blender/nodes/shader/CMakeLists.txt @@ -93,6 +93,7 @@ set(SRC nodes/node_shader_output_material.cc nodes/node_shader_output_world.cc nodes/node_shader_particle_info.cc + nodes/node_shader_point_info.cc nodes/node_shader_rgb.cc nodes/node_shader_rgb_to_bw.cc nodes/node_shader_script.cc diff --git a/source/blender/nodes/shader/nodes/node_shader_point_info.cc b/source/blender/nodes/shader/nodes/node_shader_point_info.cc new file mode 100644 index 00000000000..adc58ca065a --- /dev/null +++ b/source/blender/nodes/shader/nodes/node_shader_point_info.cc @@ -0,0 +1,54 @@ +/* + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2005 Blender Foundation. + * All rights reserved. + */ + +#include "node_shader_util.hh" + +namespace blender::nodes::node_shader_point_info_cc { + +static void node_declare(NodeDeclarationBuilder &b) +{ + b.add_output<decl::Vector>(N_("Position")); + b.add_output<decl::Float>(N_("Radius")); + b.add_output<decl::Float>(N_("Random")); +} + +static int node_shader_gpu_point_info(GPUMaterial *mat, + bNode *node, + bNodeExecData *UNUSED(execdata), + GPUNodeStack *in, + GPUNodeStack *out) +{ + return GPU_stack_link(mat, node, "node_point_info", in, out); +} + +} // namespace blender::nodes::node_shader_point_info_cc + +/* node type definition */ +void register_node_type_sh_point_info() +{ + namespace file_ns = blender::nodes::node_shader_point_info_cc; + + static bNodeType ntype; + + sh_node_type_base(&ntype, SH_NODE_POINT_INFO, "Point Info", NODE_CLASS_INPUT); + ntype.declare = file_ns::node_declare; + node_type_gpu(&ntype, file_ns::node_shader_gpu_point_info); + + nodeRegisterType(&ntype); +} |