Blender V4.3
point_intersect.h
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2011-2022 Blender Foundation
2 *
3 * SPDX-License-Identifier: Apache-2.0 */
4
5#pragma once
6
8
9/* Point primitive intersection functions. */
10
11#ifdef __POINTCLOUD__
12
13ccl_device_forceinline bool point_intersect_test(const float4 point,
14 const float3 ray_P,
15 const float3 ray_D,
16 const float ray_tmin,
17 const float ray_tmax,
18 ccl_private float *t)
19{
20 const float3 center = float4_to_float3(point);
21 const float radius = point.w;
22
23 const float rd2 = 1.0f / dot(ray_D, ray_D);
24
25 const float3 c0 = center - ray_P;
26 const float projC0 = dot(c0, ray_D) * rd2;
27 const float3 perp = c0 - projC0 * ray_D;
28 const float l2 = dot(perp, perp);
29 const float r2 = radius * radius;
30 if (!(l2 <= r2)) {
31 return false;
32 }
33
34 const float td = sqrt((r2 - l2) * rd2);
35 const float t_front = projC0 - td;
36 const bool valid_front = (ray_tmin <= t_front) & (t_front <= ray_tmax);
37
38 /* Always back-face culling for now. */
39# if 0
40 const float t_back = projC0 + td;
41 const bool valid_back = (ray_tmin <= t_back) & (t_back <= ray_tmax);
42
43 /* check if there is a first hit */
44 const bool valid_first = valid_front | valid_back;
45 if (!valid_first) {
46 return false;
47 }
48
49 *t = (valid_front) ? t_front : t_back;
50 return true;
51# else
52 if (!valid_front) {
53 return false;
54 }
55 *t = t_front;
56 return true;
57# endif
58}
59
60ccl_device_forceinline bool point_intersect(KernelGlobals kg,
62 const float3 ray_P,
63 const float3 ray_D,
64 const float ray_tmin,
65 const float ray_tmax,
66 const int object,
67 const int prim,
68 const float time,
69 const int type)
70{
71 const float4 point = (type & PRIMITIVE_MOTION) ? motion_point(kg, object, prim, time) :
72 kernel_data_fetch(points, prim);
73
74 if (!point_intersect_test(point, ray_P, ray_D, ray_tmin, ray_tmax, &isect->t)) {
75 return false;
76 }
77
78 isect->prim = prim;
79 isect->object = object;
80 isect->type = type;
81 isect->u = 0.0f;
82 isect->v = 0.0f;
83 return true;
84}
85
86ccl_device_inline void point_shader_setup(KernelGlobals kg,
88 ccl_private const Intersection *isect,
89 ccl_private const Ray *ray)
90{
91 sd->shader = kernel_data_fetch(points_shader, isect->prim);
92 sd->P = ray->P + ray->D * isect->t;
93
94 /* Texture coordinates, zero for now. */
95# ifdef __UV__
96 sd->u = isect->u;
97 sd->v = isect->v;
98# endif
99
100 /* Compute point center for normal. */
101 float3 center = float4_to_float3((isect->type & PRIMITIVE_MOTION) ?
102 motion_point(kg, sd->object, sd->prim, sd->time) :
103 kernel_data_fetch(points, sd->prim));
104 if (!(sd->object_flag & SD_OBJECT_TRANSFORM_APPLIED)) {
105 object_position_transform_auto(kg, sd, &center);
106 }
107
108 /* Normal */
109 sd->Ng = normalize(sd->P - center);
110 sd->N = sd->Ng;
111
112# ifdef __DPDU__
113 /* dPdu/dPdv */
114 sd->dPdu = make_float3(0.0f, 0.0f, 0.0f);
115 sd->dPdv = make_float3(0.0f, 0.0f, 0.0f);
116# endif
117}
118
119#endif
120
sqrt(x)+1/max(0
SIMD_FORCE_INLINE btVector3 & normalize()
Normalize this vector x^2 + y^2 + z^2 = 1.
Definition btVector3.h:303
additional_info("compositor_sum_squared_difference_float_shared") .push_constant(Type output_img float dot(value.rgb, luminance_coefficients)") .define("LOAD(value)"
const KernelGlobalsCPU *ccl_restrict KernelGlobals
#define kernel_data_fetch(name, index)
#define ccl_device_forceinline
#define ccl_private
#define ccl_device_inline
#define CCL_NAMESPACE_END
ccl_device_forceinline float3 make_float3(const float x, const float y, const float z)
#define object_position_transform_auto
@ PRIMITIVE_MOTION
ShaderData
@ SD_OBJECT_TRANSFORM_APPLIED
VecBase< float, 4 > float4
ccl_device_inline float3 float4_to_float3(const float4 a)
Definition util/math.h:535