mirror of
https://github.com/blender/blender
synced 2026-11-22 03:45:13 +03:00
Based on the "Stochastic ray tracing of transparent 3D Gaussians" paper by Xin Sun et. al. The basic idea: perform stochastic intersection with the Gaussian splat based on its transparency. Gaussian splats are implemented as a dedicated primitive type, but it shares the same layout for position and radius as points, so a lot of existing functions (positions, attributes, etc) work for both points and splats. For the Embree and hardware intersection it is implemented as a custom primitive type. The choice of using bounding spheres mainly comes from a balance between performance and memory usage. More ideal would be to use OBB, but it is not supported for custom primitive types in Embree and GPU HW-RT on all backends. There is a known limitation that comes from the fact that the datasets are trained in sRGB space and Cycles work in Linear space: areas with low opacity and high radiance render noticeably differently from the ground-truth implementation. Ref #159470 Pull Request: https://projects.blender.org/blender/blender/pulls/163103
100 lines
2.8 KiB
C++
100 lines
2.8 KiB
C++
/* SPDX-FileCopyrightText: 2021-2022 Blender Foundation
|
|
*
|
|
* SPDX-License-Identifier: Apache-2.0 */
|
|
|
|
#pragma once
|
|
|
|
#include "kernel/globals.h"
|
|
|
|
#include "kernel/geom/attribute.h"
|
|
#include "kernel/geom/motion_point.h"
|
|
#include "kernel/geom/object.h"
|
|
|
|
CCL_NAMESPACE_BEGIN
|
|
|
|
/* Point Primitive
|
|
*
|
|
* Point primitive for rendering point clouds.
|
|
*/
|
|
|
|
#ifdef __POINTCLOUD__
|
|
|
|
/* Reading attributes on various point elements */
|
|
|
|
template<typename T>
|
|
ccl_device T point_attribute(KernelGlobals kg,
|
|
const ccl_private ShaderData *sd,
|
|
const AttributeDescriptor desc)
|
|
{
|
|
if (desc.element & ATTR_ELEMENT_VERTEX) {
|
|
return T(attribute_data_fetch<dual_base_t<T>>(kg, desc.element, desc.offset + sd->prim));
|
|
}
|
|
return make_zero<T>();
|
|
}
|
|
|
|
/* Point position */
|
|
|
|
ccl_device float3 point_position(KernelGlobals kg, const ccl_private ShaderData *sd)
|
|
{
|
|
if (sd->type & PRIMITIVE_ANY_POINT) {
|
|
/* World space center. */
|
|
const int position_offset = kernel_data_fetch(objects, sd->object).position_offset;
|
|
float3 P = (sd->type & PRIMITIVE_MOTION) ?
|
|
make_float3(motion_point(kg, sd->object, sd->prim, sd->time)) :
|
|
make_float3(kernel_data_fetch(points, position_offset + 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, const ccl_private ShaderData *sd)
|
|
{
|
|
if (sd->type & PRIMITIVE_ANY_POINT) {
|
|
/* World space radius. */
|
|
const int position_offset = kernel_data_fetch(objects, sd->object).position_offset;
|
|
const float r = kernel_data_fetch(points, position_offset + sd->prim).w;
|
|
|
|
if (sd->object_flag & SD_OBJECT_TRANSFORM_APPLIED) {
|
|
return r;
|
|
}
|
|
|
|
const float normalized_r = r * (1.0f / M_SQRT3_F);
|
|
float3 dir = make_float3(normalized_r, normalized_r, normalized_r);
|
|
object_dir_transform(kg, sd, &dir);
|
|
return len(dir);
|
|
}
|
|
|
|
return 0.0f;
|
|
}
|
|
|
|
/* Point random */
|
|
|
|
ccl_device float point_random(KernelGlobals kg, const ccl_private ShaderData *sd)
|
|
{
|
|
if (sd->type & PRIMITIVE_ANY_POINT) {
|
|
const AttributeDescriptor desc = find_attribute(kg, sd, ATTR_STD_POINT_RANDOM);
|
|
return is_attribute_found(desc) ? point_attribute<float>(kg, sd, desc) : 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 */
|
|
|
|
ccl_device float3 point_motion_center_location(KernelGlobals kg, const ccl_private ShaderData *sd)
|
|
{
|
|
const int position_offset = kernel_data_fetch(objects, sd->object).position_offset;
|
|
return make_float3(kernel_data_fetch(points, position_offset + sd->prim));
|
|
}
|
|
|
|
#endif /* __POINTCLOUD__ */
|
|
|
|
CCL_NAMESPACE_END
|