1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
|
// Copyright 2009-2020 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
#pragma once
#include "subgrid_intersector.h"
namespace embree
{
namespace isa
{
template<int N, bool filter>
struct SubGridMBIntersector1Pluecker
{
typedef SubGridMBQBVHN<N> Primitive;
typedef SubGridQuadMIntersector1Pluecker<4,filter> Precalculations;
static __forceinline void intersect(const Precalculations& pre, RayHit& ray, IntersectContext* context, const SubGrid& subgrid)
{
STAT3(normal.trav_prims,1,1,1);
const GridMesh* mesh = context->scene->get<GridMesh>(subgrid.geomID());
const GridMesh::Grid &g = mesh->grid(subgrid.primID());
float ftime;
const int itime = mesh->timeSegment(ray.time(), ftime);
Vec3vf4 v0,v1,v2,v3; subgrid.gatherMB(v0,v1,v2,v3,context->scene,itime,ftime);
pre.intersect(ray,context,v0,v1,v2,v3,g,subgrid);
}
static __forceinline bool occluded(const Precalculations& pre, Ray& ray, IntersectContext* context, const SubGrid& subgrid)
{
STAT3(shadow.trav_prims,1,1,1);
const GridMesh* mesh = context->scene->get<GridMesh>(subgrid.geomID());
const GridMesh::Grid &g = mesh->grid(subgrid.primID());
float ftime;
const int itime = mesh->timeSegment(ray.time(), ftime);
Vec3vf4 v0,v1,v2,v3; subgrid.gatherMB(v0,v1,v2,v3,context->scene,itime,ftime);
return pre.occluded(ray,context,v0,v1,v2,v3,g,subgrid);
}
static __forceinline bool pointQuery(PointQuery* query, PointQueryContext* context, const SubGrid& subgrid)
{
return PrimitivePointQuery1<Primitive>::pointQuery(query, context, subgrid);
}
template<int Nx, bool robust>
static __forceinline void intersect(const Accel::Intersectors* This, Precalculations& pre, RayHit& ray, IntersectContext* context, const Primitive* prim, size_t num, const TravRay<N,Nx,robust> &tray, size_t& lazy_node)
{
BVHNQuantizedBaseNodeIntersector1<N,Nx,robust> isec1;
for (size_t i=0;i<num;i++)
{
vfloat<Nx> dist;
const float time = prim[i].adjustTime(ray.time());
assert(time <= 1.0f);
size_t mask = isec1.intersect(&prim[i].qnode,tray,time,dist);
#if defined(__AVX__)
STAT3(normal.trav_hit_boxes[popcnt(mask)],1,1,1);
#endif
while(mask != 0)
{
const size_t ID = bscf(mask);
if (unlikely(dist[ID] > ray.tfar)) continue;
intersect(pre,ray,context,prim[i].subgrid(ID));
}
}
}
template<int Nx, bool robust>
static __forceinline bool occluded(const Accel::Intersectors* This, Precalculations& pre, Ray& ray, IntersectContext* context, const Primitive* prim, size_t num, const TravRay<N,Nx,robust> &tray, size_t& lazy_node)
{
BVHNQuantizedBaseNodeIntersector1<N,Nx,robust> isec1;
for (size_t i=0;i<num;i++)
{
const float time = prim[i].adjustTime(ray.time());
assert(time <= 1.0f);
vfloat<Nx> dist;
size_t mask = isec1.intersect(&prim[i].qnode,tray,time,dist);
while(mask != 0)
{
const size_t ID = bscf(mask);
if (occluded(pre,ray,context,prim[i].subgrid(ID)))
return true;
}
}
return false;
}
static __forceinline bool pointQuery(const Accel::Intersectors* This, PointQuery* query, PointQueryContext* context, const Primitive* prim, size_t num, const TravPointQuery<N> &tquery, size_t& lazy_node)
{
assert(false && "not implemented");
return false;
}
};
template<int N, int K, bool filter>
struct SubGridMBIntersectorKPluecker
{
typedef SubGridMBQBVHN<N> Primitive;
typedef SubGridQuadMIntersectorKPluecker<4,K,filter> Precalculations;
static __forceinline void intersect(const vbool<K>& valid_i, Precalculations& pre, RayHitK<K>& ray, IntersectContext* context, const SubGrid& subgrid)
{
size_t m_valid = movemask(valid_i);
while(m_valid)
{
size_t ID = bscf(m_valid);
intersect(pre,ray,ID,context,subgrid);
}
}
static __forceinline vbool<K> occluded(const vbool<K>& valid_i, Precalculations& pre, RayK<K>& ray, IntersectContext* context, const SubGrid& subgrid)
{
vbool<K> valid0 = valid_i;
size_t m_valid = movemask(valid_i);
while(m_valid)
{
size_t ID = bscf(m_valid);
if (occluded(pre,ray,ID,context,subgrid))
clear(valid0,ID);
}
return !valid0;
}
static __forceinline void intersect(Precalculations& pre, RayHitK<K>& ray, size_t k, IntersectContext* context, const SubGrid& subgrid)
{
STAT3(normal.trav_prims,1,1,1);
const GridMesh* mesh = context->scene->get<GridMesh>(subgrid.geomID());
const GridMesh::Grid &g = mesh->grid(subgrid.primID());
vfloat<K> ftime;
const vint<K> itime = mesh->timeSegment(ray.time(), ftime);
Vec3vf4 v0,v1,v2,v3; subgrid.gatherMB(v0,v1,v2,v3,context->scene,itime[k],ftime[k]);
pre.intersect1(ray,k,context,v0,v1,v2,v3,g,subgrid);
}
static __forceinline bool occluded(Precalculations& pre, RayK<K>& ray, size_t k, IntersectContext* context, const SubGrid& subgrid)
{
STAT3(shadow.trav_prims,1,1,1);
const GridMesh* mesh = context->scene->get<GridMesh>(subgrid.geomID());
const GridMesh::Grid &g = mesh->grid(subgrid.primID());
vfloat<K> ftime;
const vint<K> itime = mesh->timeSegment(ray.time(), ftime);
Vec3vf4 v0,v1,v2,v3; subgrid.gatherMB(v0,v1,v2,v3,context->scene,itime[k],ftime[k]);
return pre.occluded1(ray,k,context,v0,v1,v2,v3,g,subgrid);
}
template<bool robust>
static __forceinline void intersect(const vbool<K>& valid, const Accel::Intersectors* This, Precalculations& pre, RayHitK<K>& ray, IntersectContext* context, const Primitive* prim, size_t num, const TravRayK<K, robust> &tray, size_t& lazy_node)
{
BVHNQuantizedBaseNodeIntersectorK<N,K,robust> isecK;
for (size_t j=0;j<num;j++)
{
size_t m_valid = movemask(prim[j].qnode.validMask());
const vfloat<K> time = prim[j].adjustTime(ray.time());
vfloat<K> dist;
while(m_valid)
{
const size_t i = bscf(m_valid);
if (none(valid & isecK.intersectK(&prim[j].qnode,i,tray,time,dist))) continue;
intersect(valid,pre,ray,context,prim[j].subgrid(i));
}
}
}
template<bool robust>
static __forceinline vbool<K> occluded(const vbool<K>& valid, const Accel::Intersectors* This, Precalculations& pre, RayK<K>& ray, IntersectContext* context, const Primitive* prim, size_t num, const TravRayK<K, robust> &tray, size_t& lazy_node)
{
BVHNQuantizedBaseNodeIntersectorK<N,K,robust> isecK;
vbool<K> valid0 = valid;
for (size_t j=0;j<num;j++)
{
size_t m_valid = movemask(prim[j].qnode.validMask());
const vfloat<K> time = prim[j].adjustTime(ray.time());
vfloat<K> dist;
while(m_valid)
{
const size_t i = bscf(m_valid);
if (none(valid0 & isecK.intersectK(&prim[j].qnode,i,tray,time,dist))) continue;
valid0 &= !occluded(valid0,pre,ray,context,prim[j].subgrid(i));
if (none(valid0)) break;
}
}
return !valid0;
}
template<int Nx, bool robust>
static __forceinline void intersect(const Accel::Intersectors* This, Precalculations& pre, RayHitK<K>& ray, size_t k, IntersectContext* context, const Primitive* prim, size_t num, const TravRay<N,Nx,robust> &tray, size_t& lazy_node)
{
BVHNQuantizedBaseNodeIntersector1<N,Nx,robust> isec1;
for (size_t i=0;i<num;i++)
{
vfloat<N> dist;
const float time = prim[i].adjustTime(ray.time()[k]);
assert(time <= 1.0f);
size_t mask = isec1.intersect(&prim[i].qnode,tray,time,dist);
while(mask != 0)
{
const size_t ID = bscf(mask);
if (unlikely(dist[ID] > ray.tfar[k])) continue;
intersect(pre,ray,k,context,prim[i].subgrid(ID));
}
}
}
template<int Nx, bool robust>
static __forceinline bool occluded(const Accel::Intersectors* This, Precalculations& pre, RayK<K>& ray, size_t k, IntersectContext* context, const Primitive* prim, size_t num, const TravRay<N,Nx,robust> &tray, size_t& lazy_node)
{
BVHNQuantizedBaseNodeIntersector1<N,Nx,robust> isec1;
for (size_t i=0;i<num;i++)
{
vfloat<N> dist;
const float time = prim[i].adjustTime(ray.time()[k]);
assert(time <= 1.0f);
size_t mask = isec1.intersect(&prim[i].qnode,tray,time,dist);
while(mask != 0)
{
const size_t ID = bscf(mask);
if (occluded(pre,ray,k,context,prim[i].subgrid(ID)))
return true;
}
}
return false;
}
};
}
}
|