@@ -99,79 +99,6 @@ RTCScene initializeScene(RTCDevice device)
99
99
return scene;
100
100
}
101
101
102
- bool castRay (RTCScene scene,
103
- float ox, float oy, float oz,
104
- float dx, float dy, float dz, float maxDist)
105
- {
106
- /*
107
- * The intersect context can be used to set intersection
108
- * filters or flags, and it also contains the instance ID stack
109
- * used in multi-level instancing.
110
- */
111
- struct RTCIntersectContext context;
112
- rtcInitIntersectContext (&context);
113
-
114
- /*
115
- * The ray hit structure holds both the ray and the hit.
116
- * The user must initialize it properly -- see API documentation
117
- * for rtcIntersect1() for details.
118
- */
119
- // struct RTCRayHit rayhit;
120
- // rayhit.ray.org_x = ox;
121
- // rayhit.ray.org_y = oy;
122
- // rayhit.ray.org_z = oz;
123
- // rayhit.ray.dir_x = dx;
124
- // rayhit.ray.dir_y = dy;
125
- // rayhit.ray.dir_z = dz;
126
- // rayhit.ray.tnear = 0;
127
- // rayhit.ray.tfar = maxDist;
128
- // rayhit.ray.mask = 0;
129
- // rayhit.ray.flags = 0;
130
- // rayhit.hit.geomID = RTC_INVALID_GEOMETRY_ID;
131
- // rayhit.hit.instID[0] = RTC_INVALID_GEOMETRY_ID;
132
-
133
-
134
- struct RTCRay rayhit;
135
- rayhit.org_x = ox;
136
- rayhit.org_y = oy;
137
- rayhit.org_z = oz;
138
- rayhit.dir_x = dx;
139
- rayhit.dir_y = dy;
140
- rayhit.dir_z = dz;
141
- rayhit.tnear = 0 .01f ;
142
- rayhit.tfar = maxDist;
143
- rayhit.mask = 0 ;
144
- rayhit.flags = 0 ;
145
-
146
- /*
147
- * There are multiple variants of rtcIntersect. This one
148
- * intersects a single ray with the scene.
149
- */
150
- rtcOccluded1 (scene, &context, &rayhit);
151
-
152
- // printf("%f, %f, %f: ", ox, oy, oz);
153
- // if (rayhit.hit.geomID != RTC_INVALID_GEOMETRY_ID)
154
- if (rayhit.tfar < 0 .0f )
155
- {
156
- /* Note how geomID and primID identify the geometry we just hit.
157
- * We could use them here to interpolate geometry information,
158
- * compute shading, etc.
159
- * Since there is only a single triangle in this scene, we will
160
- * get geomID=0 / primID=0 for all hits.
161
- * There is also instID, used for instancing. See
162
- * the instancing tutorials for more information */
163
- // printf("Found intersection on geometry %d, primitive %d at tfar=%f\n",
164
- // rayhit.hit.geomID,
165
- // rayhit.hit.primID,
166
- // rayhit.ray.tfar);
167
- return true ;
168
- }
169
- return false ;
170
- // else
171
- // printf("Did not find any intersection.\n");
172
- }
173
-
174
-
175
102
void rotate_vector_by_quaternion (const vec3& v, const quat& q, vec3& vprime)
176
103
{
177
104
// Extract the vector part of the quaternion
@@ -199,7 +126,6 @@ void computeAOPerVert(float *verts, float *norms, int *tris, float *result,
199
126
200
127
RTCGeometry geom = rtcNewGeometry (device, RTC_GEOMETRY_TYPE_TRIANGLE);
201
128
202
-
203
129
float * vertices = (float *) rtcSetNewGeometryBuffer (geom,
204
130
RTC_BUFFER_TYPE_VERTEX,
205
131
0 ,
@@ -254,14 +180,12 @@ void computeAOPerVert(float *verts, float *norms, int *tris, float *result,
254
180
struct RTCIntersectContext context;
255
181
rtcInitIntersectContext (&context);
256
182
257
- // struct RTCRay rayhit;
258
- RTCRay *rays = new RTCRay[rayDir.size ()];
183
+ tbb::parallel_for ( tbb::blocked_range<int >(0 , vcount),
184
+ [&](tbb::blocked_range<int > r)
185
+ {
186
+ RTCRay *rays = new RTCRay[rayDir.size ()];
259
187
260
- // tbb::parallel_for( tbb::blocked_range<int>(0, vcount),
261
- // [&](tbb::blocked_range<int> r)
262
- // {
263
- // for (int i = r.begin(); i < r.end(); ++i)
264
- for (int i = 0 ; i < vcount; ++i)
188
+ for (int i = r.begin (); i < r.end (); ++i)
265
189
{
266
190
vec3 oriVec (0 , 1 , 0 );
267
191
@@ -286,15 +210,10 @@ void computeAOPerVert(float *verts, float *norms, int *tris, float *result,
286
210
rays[s].mask = 0 ;
287
211
rays[s].flags = 0 ;
288
212
289
- // bool inter = castRay(scene, vertices[i * 3], vertices[i * 3 + 1], vertices[i * 3 + 2],
290
- // rotatedDir.x, rotatedDir.y, rotatedDir.z, maxDist);
291
-
292
- // if (inter) {
293
- // totalAO += 1.0f;
294
213
}
295
214
296
215
rtcOccluded1M (scene, &context, &rays[0 ], rayDir.size (), sizeof (RTCRay));
297
- // rtcOccluded1(scene, &context, &rayhit);
216
+
298
217
float totalAO = 0 .0f ;
299
218
300
219
for (int s = 0 ; s < rayDir.size (); s++) {
@@ -305,7 +224,7 @@ void computeAOPerVert(float *verts, float *norms, int *tris, float *result,
305
224
306
225
result[i] = 1 .0f - (totalAO / samplesAO);
307
226
}
308
- // });
227
+ });
309
228
310
229
/* Though not strictly necessary in this example, you should
311
230
* always make sure to release resources allocated through Embree. */
@@ -314,15 +233,14 @@ void computeAOPerVert(float *verts, float *norms, int *tris, float *result,
314
233
315
234
auto timerstop = high_resolution_clock::now ();
316
235
auto duration = duration_cast<milliseconds>(timerstop - timerstart).count ();
317
- // fprintf(stderr, "%.6f ms\n", duration;
318
236
std::cerr << duration << " ms" << std::endl;
319
237
}
320
238
321
239
322
240
int main (int argc, char **argv) {
323
241
324
242
int samplesAO = 128 ;
325
- float maxDist = 100 .0f ;
243
+ float maxDist = 20 .0f ;
326
244
327
245
tinyobj::attrib_t attrib;
328
246
std::vector<tinyobj::shape_t > shapes;
@@ -355,7 +273,6 @@ int main(int argc, char **argv) {
355
273
for (size_t v = 0 ; v < fv; v++) {
356
274
tinyobj::index_t idx = shapes[s].mesh .indices [index_offset + v];
357
275
ids.push_back (idx.vertex_index );
358
- // std::cout << idx.vertex_index << std::endl;
359
276
}
360
277
index_offset += fv;
361
278
}
@@ -370,6 +287,8 @@ int main(int argc, char **argv) {
370
287
for (int i = 0 ; i < verts.size () / 3 ; i++) {
371
288
printf (" v %.6f %.6f %.6f %.3f %.3f %.3f\n " ,
372
289
verts[i * 3 ], verts[i * 3 + 1 ], verts[i * 3 + 2 ], result[i], result[i], result[i]);
290
+ printf (" vn %.6f %.6f %.6f\n " , norms[i * 3 ], norms[i * 3 + 1 ], norms[i * 3 + 2 ]);
291
+
373
292
}
374
293
375
294
for (int i = 0 ; i < ids.size () / 3 ; i++) {
0 commit comments