Blender V5.0
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
7#include "kernel/globals.h"
8#include "kernel/types.h"
9
11#include "kernel/geom/object.h"
12
14
15/* Point primitive intersection functions. */
16
17#ifdef __POINTCLOUD__
18
19ccl_device_forceinline bool point_intersect_test(const float4 point,
20 const float3 ray_P,
21 const float3 ray_D,
22 const float ray_tmin,
23 const float ray_tmax,
24 ccl_private float *t)
25{
26 const float3 center = make_float3(point);
27 const float radius = point.w;
28
29 const float rd2 = 1.0f / dot(ray_D, ray_D);
30
31 const float3 c0 = center - ray_P;
32 const float projC0 = dot(c0, ray_D) * rd2;
33 const float3 perp = c0 - projC0 * ray_D;
34 const float l2 = dot(perp, perp);
35 const float r2 = radius * radius;
36 if (!(l2 <= r2)) {
37 return false;
38 }
39
40 const float td = sqrt((r2 - l2) * rd2);
41 const float t_front = projC0 - td;
42 const bool valid_front = (ray_tmin <= t_front) & (t_front <= ray_tmax);
43
44 /* Always back-face culling for now. */
45# if 0
46 const float t_back = projC0 + td;
47 const bool valid_back = (ray_tmin <= t_back) & (t_back <= ray_tmax);
48
49 /* check if there is a first hit */
50 const bool valid_first = valid_front | valid_back;
51 if (!valid_first) {
52 return false;
53 }
54
55 *t = (valid_front) ? t_front : t_back;
56 return true;
57# else
58 if (!valid_front) {
59 return false;
60 }
61 *t = t_front;
62 return true;
63# endif
64}
65
66ccl_device_forceinline bool point_intersect(KernelGlobals kg,
68 const float3 ray_P,
69 const float3 ray_D,
70 const float ray_tmin,
71 const float ray_tmax,
72 const int object,
73 const int prim,
74 const float time,
75 const int type)
76{
77 const float4 point = (type & PRIMITIVE_MOTION) ? motion_point(kg, object, prim, time) :
78 kernel_data_fetch(points, prim);
79
80 if (!point_intersect_test(point, ray_P, ray_D, ray_tmin, ray_tmax, &isect->t)) {
81 return false;
82 }
83
84 isect->prim = prim;
85 isect->object = object;
86 isect->type = type;
87 isect->u = 0.0f;
88 isect->v = 0.0f;
89 return true;
90}
91
92ccl_device_inline void point_shader_setup(KernelGlobals kg,
93 ccl_private ShaderData *sd,
94 const ccl_private Intersection *isect,
95 const ccl_private Ray *ray)
96{
97 sd->shader = kernel_data_fetch(points_shader, isect->prim);
98 sd->P = ray->P + ray->D * isect->t;
99
100 /* Texture coordinates, zero for now. */
101# ifdef __UV__
102 sd->u = isect->u;
103 sd->v = isect->v;
104# endif
105
106 /* Compute point center for normal. */
107 float3 center = make_float3((isect->type & PRIMITIVE_MOTION) ?
108 motion_point(kg, sd->object, sd->prim, sd->time) :
109 kernel_data_fetch(points, sd->prim));
110 if (!(sd->object_flag & SD_OBJECT_TRANSFORM_APPLIED)) {
111 object_position_transform_auto(kg, sd, &center);
112 }
113
114 /* Normal */
115 sd->Ng = normalize(sd->P - center);
116 sd->N = sd->Ng;
117
118# ifdef __DPDU__
119 /* dPdu/dPdv */
120 sd->dPdu = make_float3(0.0f, 0.0f, 0.0f);
121 sd->dPdv = make_float3(0.0f, 0.0f, 0.0f);
122# endif
123}
124
125#endif
126
dot(value.rgb, luminance_coefficients)") DEFINE_VALUE("REDUCE(lhs
#define ccl_device_forceinline
#define kernel_data_fetch(name, index)
#define ccl_private
const ThreadKernelGlobalsCPU * KernelGlobals
#define ccl_device_inline
#define CCL_NAMESPACE_END
ccl_device_forceinline float3 make_float3(const float x, const float y, const float z)
VecBase< float, D > normalize(VecOp< float, D >) RET
#define sqrt
#define object_position_transform_auto
@ PRIMITIVE_MOTION
@ SD_OBJECT_TRANSFORM_APPLIED
float w
Definition sky_math.h:225