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
This commit is contained in:
@@ -226,6 +226,18 @@ ccl_device float curve_thickness(KernelGlobals kg, ccl_private const ShaderData
|
||||
return r * 2.0f;
|
||||
}
|
||||
|
||||
/* Curve random */
|
||||
|
||||
ccl_device float curve_random(KernelGlobals kg, ccl_private const ShaderData *sd)
|
||||
{
|
||||
if (sd->type & PRIMITIVE_CURVE) {
|
||||
const AttributeDescriptor desc = find_attribute(kg, sd, ATTR_STD_CURVE_RANDOM);
|
||||
return (desc.offset != ATTR_STD_NOT_FOUND) ? curve_attribute_float(kg, sd, desc, NULL, NULL) :
|
||||
0.0f;
|
||||
}
|
||||
return 0.0f;
|
||||
}
|
||||
|
||||
/* Curve location for motion pass, linear interpolation between keys and
|
||||
* ignoring radius because we do the same for the motion keys */
|
||||
|
||||
|
@@ -109,17 +109,59 @@ ccl_device float4 point_attribute_float4(KernelGlobals kg,
|
||||
}
|
||||
}
|
||||
|
||||
/* Point position */
|
||||
|
||||
ccl_device float3 point_position(KernelGlobals kg, ccl_private const ShaderData *sd)
|
||||
{
|
||||
if (sd->type & PRIMITIVE_POINT) {
|
||||
/* World space center. */
|
||||
float3 P = (sd->type & PRIMITIVE_MOTION) ?
|
||||
float4_to_float3(motion_point(kg, sd->object, sd->prim, sd->time)) :
|
||||
float4_to_float3(kernel_tex_fetch(__points, sd->prim));
|
||||
|
||||
if (!(sd->object_flag & SD_OBJECT_TRANSFORM_APPLIED)) {
|
||||
object_position_transform(kg, sd, &P);
|
||||
}
|
||||
|
||||
return P;
|
||||
}
|
||||
|
||||
return zero_float3();
|
||||
}
|
||||
|
||||
/* Point radius */
|
||||
|
||||
ccl_device float point_radius(KernelGlobals kg, ccl_private const ShaderData *sd)
|
||||
{
|
||||
if (sd->type & PRIMITIVE_POINT) {
|
||||
return kernel_tex_fetch(__points, sd->prim).w;
|
||||
/* World space radius. */
|
||||
const float r = kernel_tex_fetch(__points, sd->prim).w;
|
||||
|
||||
if (sd->object_flag & SD_OBJECT_TRANSFORM_APPLIED) {
|
||||
return r;
|
||||
}
|
||||
else {
|
||||
float3 dir = make_float3(r, r, r);
|
||||
object_dir_transform(kg, sd, &dir);
|
||||
return average(dir);
|
||||
}
|
||||
}
|
||||
|
||||
return 0.0f;
|
||||
}
|
||||
|
||||
/* Point random */
|
||||
|
||||
ccl_device float point_random(KernelGlobals kg, ccl_private const ShaderData *sd)
|
||||
{
|
||||
if (sd->type & PRIMITIVE_POINT) {
|
||||
const AttributeDescriptor desc = find_attribute(kg, sd, ATTR_STD_POINT_RANDOM);
|
||||
return (desc.offset != ATTR_STD_NOT_FOUND) ? point_attribute_float(kg, sd, desc, NULL, NULL) :
|
||||
0.0f;
|
||||
}
|
||||
return 0.0f;
|
||||
}
|
||||
|
||||
/* Point location for motion pass, linear interpolation between keys and
|
||||
* ignoring radius because we do the same for the motion keys */
|
||||
|
||||
|
@@ -116,6 +116,8 @@ ustring OSLRenderServices::u_curve_tangent_normal("geom:curve_tangent_normal");
|
||||
ustring OSLRenderServices::u_curve_random("geom:curve_random");
|
||||
ustring OSLRenderServices::u_is_point("geom:is_point");
|
||||
ustring OSLRenderServices::u_point_radius("geom:point_radius");
|
||||
ustring OSLRenderServices::u_point_position("geom:point_position");
|
||||
ustring OSLRenderServices::u_point_random("geom:point_random");
|
||||
ustring OSLRenderServices::u_normal_map_normal("geom:normal_map_normal");
|
||||
ustring OSLRenderServices::u_path_ray_length("path:ray_length");
|
||||
ustring OSLRenderServices::u_path_ray_depth("path:ray_depth");
|
||||
@@ -999,6 +1001,10 @@ bool OSLRenderServices::get_object_standard_attribute(const KernelGlobalsCPU *kg
|
||||
float3 f = curve_tangent_normal(kg, sd);
|
||||
return set_attribute_float3(f, type, derivatives, val);
|
||||
}
|
||||
else if (name == u_curve_random) {
|
||||
float f = curve_random(kg, sd);
|
||||
return set_attribute_float(f, type, derivatives, val);
|
||||
}
|
||||
/* point attributes */
|
||||
else if (name == u_is_point) {
|
||||
float f = (sd->type & PRIMITIVE_POINT) != 0;
|
||||
@@ -1008,6 +1014,14 @@ bool OSLRenderServices::get_object_standard_attribute(const KernelGlobalsCPU *kg
|
||||
float f = point_radius(kg, sd);
|
||||
return set_attribute_float(f, type, derivatives, val);
|
||||
}
|
||||
else if (name == u_point_position) {
|
||||
float3 f = point_position(kg, sd);
|
||||
return set_attribute_float3(f, type, derivatives, val);
|
||||
}
|
||||
else if (name == u_point_random) {
|
||||
float f = point_random(kg, sd);
|
||||
return set_attribute_float(f, type, derivatives, val);
|
||||
}
|
||||
else if (name == u_normal_map_normal) {
|
||||
if (sd->type & PRIMITIVE_TRIANGLE) {
|
||||
float3 f = triangle_smooth_normal_unnormalized(kg, sd, sd->Ng, sd->prim, sd->u, sd->v);
|
||||
|
@@ -298,7 +298,9 @@ class OSLRenderServices : public OSL::RendererServices {
|
||||
static ustring u_curve_tangent_normal;
|
||||
static ustring u_curve_random;
|
||||
static ustring u_is_point;
|
||||
static ustring u_point_position;
|
||||
static ustring u_point_radius;
|
||||
static ustring u_point_random;
|
||||
static ustring u_normal_map_normal;
|
||||
static ustring u_path_ray_length;
|
||||
static ustring u_path_ray_depth;
|
||||
|
@@ -49,6 +49,7 @@ set(SRC_OSL
|
||||
node_glossy_bsdf.osl
|
||||
node_gradient_texture.osl
|
||||
node_hair_info.osl
|
||||
node_point_info.osl
|
||||
node_scatter_volume.osl
|
||||
node_absorption_volume.osl
|
||||
node_principled_volume.osl
|
||||
|
26
intern/cycles/kernel/osl/shaders/node_point_info.osl
Normal file
26
intern/cycles/kernel/osl/shaders/node_point_info.osl
Normal file
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
* Copyright 2011-2022 Blender Foundation
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "stdcycles.h"
|
||||
|
||||
shader node_point_info(output point Position = point(0.0, 0.0, 0.0),
|
||||
output float Radius = 0.0,
|
||||
output float Random = 0.0)
|
||||
{
|
||||
getattribute("geom:point_position", Position);
|
||||
getattribute("geom:point_radius", Radius);
|
||||
getattribute("geom:point_random", Random);
|
||||
}
|
@@ -242,13 +242,6 @@ ccl_device_noinline void svm_node_hair_info(KernelGlobals kg,
|
||||
stack_store_float(stack, out_offset, data);
|
||||
break;
|
||||
}
|
||||
# if 0
|
||||
case NODE_INFO_CURVE_FADE: {
|
||||
data = sd->curve_transparency;
|
||||
stack_store_float(stack, out_offset, data);
|
||||
break;
|
||||
}
|
||||
# endif
|
||||
case NODE_INFO_CURVE_TANGENT_NORMAL: {
|
||||
data3 = curve_tangent_normal(kg, sd);
|
||||
stack_store_float3(stack, out_offset, data3);
|
||||
@@ -258,4 +251,28 @@ ccl_device_noinline void svm_node_hair_info(KernelGlobals kg,
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef __POINTCLOUD__
|
||||
|
||||
/* Point Info */
|
||||
|
||||
ccl_device_noinline void svm_node_point_info(KernelGlobals kg,
|
||||
ccl_private ShaderData *sd,
|
||||
ccl_private float *stack,
|
||||
uint type,
|
||||
uint out_offset)
|
||||
{
|
||||
switch (type) {
|
||||
case NODE_INFO_POINT_POSITION:
|
||||
stack_store_float3(stack, out_offset, point_position(kg, sd));
|
||||
break;
|
||||
case NODE_INFO_POINT_RADIUS:
|
||||
stack_store_float(stack, out_offset, point_radius(kg, sd));
|
||||
break;
|
||||
case NODE_INFO_POINT_RANDOM:
|
||||
break; /* handled as attribute */
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
CCL_NAMESPACE_END
|
||||
|
@@ -454,13 +454,14 @@ ccl_device void svm_eval_nodes(KernelGlobals kg,
|
||||
break;
|
||||
#if defined(__HAIR__)
|
||||
case NODE_HAIR_INFO:
|
||||
IF_KERNEL_NODES_FEATURE(HAIR)
|
||||
{
|
||||
svm_node_hair_info(kg, sd, stack, node.y, node.z);
|
||||
}
|
||||
svm_node_hair_info(kg, sd, stack, node.y, node.z);
|
||||
break;
|
||||
#endif
|
||||
#if defined(__POINTCLOUD__)
|
||||
case NODE_POINT_INFO:
|
||||
svm_node_point_info(kg, sd, stack, node.y, node.z);
|
||||
break;
|
||||
#endif
|
||||
|
||||
case NODE_TEXTURE_MAPPING:
|
||||
offset = svm_node_texture_mapping(kg, sd, stack, node.y, node.z, offset);
|
||||
break;
|
||||
|
@@ -81,6 +81,7 @@ typedef enum ShaderNodeType {
|
||||
NODE_OBJECT_INFO,
|
||||
NODE_PARTICLE_INFO,
|
||||
NODE_HAIR_INFO,
|
||||
NODE_POINT_INFO,
|
||||
NODE_TEXTURE_MAPPING,
|
||||
NODE_MAPPING,
|
||||
NODE_MIN_MAX,
|
||||
@@ -176,12 +177,16 @@ typedef enum NodeHairInfo {
|
||||
NODE_INFO_CURVE_INTERCEPT,
|
||||
NODE_INFO_CURVE_LENGTH,
|
||||
NODE_INFO_CURVE_THICKNESS,
|
||||
/* Fade for minimum hair width transiency. */
|
||||
// NODE_INFO_CURVE_FADE,
|
||||
NODE_INFO_CURVE_TANGENT_NORMAL,
|
||||
NODE_INFO_CURVE_RANDOM,
|
||||
} NodeHairInfo;
|
||||
|
||||
typedef enum NodePointInfo {
|
||||
NODE_INFO_POINT_POSITION,
|
||||
NODE_INFO_POINT_RADIUS,
|
||||
NODE_INFO_POINT_RANDOM,
|
||||
} NodePointInfo;
|
||||
|
||||
typedef enum NodeLightPath {
|
||||
NODE_LP_camera = 0,
|
||||
NODE_LP_shadow,
|
||||
|
@@ -1565,21 +1565,21 @@ enum KernelFeatureFlag : uint32_t {
|
||||
KERNEL_FEATURE_NODE_BSDF = (1U << 0U),
|
||||
KERNEL_FEATURE_NODE_EMISSION = (1U << 1U),
|
||||
KERNEL_FEATURE_NODE_VOLUME = (1U << 2U),
|
||||
KERNEL_FEATURE_NODE_HAIR = (1U << 3U),
|
||||
KERNEL_FEATURE_NODE_BUMP = (1U << 4U),
|
||||
KERNEL_FEATURE_NODE_BUMP_STATE = (1U << 5U),
|
||||
KERNEL_FEATURE_NODE_VORONOI_EXTRA = (1U << 6U),
|
||||
KERNEL_FEATURE_NODE_RAYTRACE = (1U << 7U),
|
||||
KERNEL_FEATURE_NODE_AOV = (1U << 8U),
|
||||
KERNEL_FEATURE_NODE_LIGHT_PATH = (1U << 9U),
|
||||
KERNEL_FEATURE_NODE_BUMP = (1U << 3U),
|
||||
KERNEL_FEATURE_NODE_BUMP_STATE = (1U << 4U),
|
||||
KERNEL_FEATURE_NODE_VORONOI_EXTRA = (1U << 5U),
|
||||
KERNEL_FEATURE_NODE_RAYTRACE = (1U << 6U),
|
||||
KERNEL_FEATURE_NODE_AOV = (1U << 7U),
|
||||
KERNEL_FEATURE_NODE_LIGHT_PATH = (1U << 8U),
|
||||
|
||||
/* Use denoising kernels and output denoising passes. */
|
||||
KERNEL_FEATURE_DENOISING = (1U << 10U),
|
||||
KERNEL_FEATURE_DENOISING = (1U << 9U),
|
||||
|
||||
/* Use path tracing kernels. */
|
||||
KERNEL_FEATURE_PATH_TRACING = (1U << 11U),
|
||||
KERNEL_FEATURE_PATH_TRACING = (1U << 10U),
|
||||
|
||||
/* BVH/sampling kernel features. */
|
||||
KERNEL_FEATURE_POINTCLOUD = (1U << 11U),
|
||||
KERNEL_FEATURE_HAIR = (1U << 12U),
|
||||
KERNEL_FEATURE_HAIR_THICK = (1U << 13U),
|
||||
KERNEL_FEATURE_OBJECT_MOTION = (1U << 14U),
|
||||
@@ -1616,9 +1616,6 @@ enum KernelFeatureFlag : uint32_t {
|
||||
KERNEL_FEATURE_AO_PASS = (1U << 25U),
|
||||
KERNEL_FEATURE_AO_ADDITIVE = (1U << 26U),
|
||||
KERNEL_FEATURE_AO = (KERNEL_FEATURE_AO_PASS | KERNEL_FEATURE_AO_ADDITIVE),
|
||||
|
||||
/* Point clouds. */
|
||||
KERNEL_FEATURE_POINTCLOUD = (1U << 27U),
|
||||
};
|
||||
|
||||
/* Shader node feature mask, to specialize shader evaluation for kernels. */
|
||||
@@ -1628,7 +1625,7 @@ enum KernelFeatureFlag : uint32_t {
|
||||
KERNEL_FEATURE_NODE_LIGHT_PATH)
|
||||
#define KERNEL_FEATURE_NODE_MASK_SURFACE_SHADOW \
|
||||
(KERNEL_FEATURE_NODE_BSDF | KERNEL_FEATURE_NODE_EMISSION | KERNEL_FEATURE_NODE_VOLUME | \
|
||||
KERNEL_FEATURE_NODE_HAIR | KERNEL_FEATURE_NODE_BUMP | KERNEL_FEATURE_NODE_BUMP_STATE | \
|
||||
KERNEL_FEATURE_NODE_BUMP | KERNEL_FEATURE_NODE_BUMP_STATE | \
|
||||
KERNEL_FEATURE_NODE_VORONOI_EXTRA | KERNEL_FEATURE_NODE_LIGHT_PATH)
|
||||
#define KERNEL_FEATURE_NODE_MASK_SURFACE \
|
||||
(KERNEL_FEATURE_NODE_MASK_SURFACE_SHADOW | KERNEL_FEATURE_NODE_RAYTRACE | \
|
||||
|
Reference in New Issue
Block a user