~ubuntu-branches/ubuntu/trusty/blender/trusty

« back to all changes in this revision

Viewing changes to source/blender/render/intern/raytrace/bvh.h

  • Committer: Package Import Robot
  • Author(s): Jeremy Bicha
  • Date: 2013-03-06 12:08:47 UTC
  • mfrom: (1.5.1) (14.1.8 experimental)
  • Revision ID: package-import@ubuntu.com-20130306120847-frjfaryb2zrotwcg
Tags: 2.66a-1ubuntu1
* Resynchronize with Debian (LP: #1076930, #1089256, #1052743, #999024,
  #1122888, #1147084)
* debian/control:
  - Lower build-depends on libavcodec-dev since we're not
    doing the libav9 transition in Ubuntu yet

Show diffs side-by-side

added added

removed removed

Lines of Context:
59
59
        copy_v3_v3(start, isec->start);
60
60
        copy_v3_v3(idot_axis, isec->idot_axis);
61
61
 
62
 
        const __m128 tmin1 = _mm_max_ps(tmin0, _mm_mul_ps( _mm_sub_ps( bb_group[isec->bv_index[0]], _mm_set_ps1(start[0]) ), _mm_set_ps1(idot_axis[0])) );
63
 
        const __m128 tmax1 = _mm_min_ps(tmax0, _mm_mul_ps( _mm_sub_ps( bb_group[isec->bv_index[1]], _mm_set_ps1(start[0]) ), _mm_set_ps1(idot_axis[0])) );
64
 
        const __m128 tmin2 = _mm_max_ps(tmin1, _mm_mul_ps( _mm_sub_ps( bb_group[isec->bv_index[2]], _mm_set_ps1(start[1]) ), _mm_set_ps1(idot_axis[1])) );
65
 
        const __m128 tmax2 = _mm_min_ps(tmax1, _mm_mul_ps( _mm_sub_ps( bb_group[isec->bv_index[3]], _mm_set_ps1(start[1]) ), _mm_set_ps1(idot_axis[1])) );
66
 
        const __m128 tmin3 = _mm_max_ps(tmin2, _mm_mul_ps( _mm_sub_ps( bb_group[isec->bv_index[4]], _mm_set_ps1(start[2]) ), _mm_set_ps1(idot_axis[2])) );
67
 
        const __m128 tmax3 = _mm_min_ps(tmax2, _mm_mul_ps( _mm_sub_ps( bb_group[isec->bv_index[5]], _mm_set_ps1(start[2]) ), _mm_set_ps1(idot_axis[2])) );
 
62
        const __m128 tmin1 = _mm_max_ps(tmin0, _mm_mul_ps(_mm_sub_ps(bb_group[isec->bv_index[0]], _mm_set_ps1(start[0]) ), _mm_set_ps1(idot_axis[0])) );
 
63
        const __m128 tmax1 = _mm_min_ps(tmax0, _mm_mul_ps(_mm_sub_ps(bb_group[isec->bv_index[1]], _mm_set_ps1(start[0]) ), _mm_set_ps1(idot_axis[0])) );
 
64
        const __m128 tmin2 = _mm_max_ps(tmin1, _mm_mul_ps(_mm_sub_ps(bb_group[isec->bv_index[2]], _mm_set_ps1(start[1]) ), _mm_set_ps1(idot_axis[1])) );
 
65
        const __m128 tmax2 = _mm_min_ps(tmax1, _mm_mul_ps(_mm_sub_ps(bb_group[isec->bv_index[3]], _mm_set_ps1(start[1]) ), _mm_set_ps1(idot_axis[1])) );
 
66
        const __m128 tmin3 = _mm_max_ps(tmin2, _mm_mul_ps(_mm_sub_ps(bb_group[isec->bv_index[4]], _mm_set_ps1(start[2]) ), _mm_set_ps1(idot_axis[2])) );
 
67
        const __m128 tmax3 = _mm_min_ps(tmax2, _mm_mul_ps(_mm_sub_ps(bb_group[isec->bv_index[5]], _mm_set_ps1(start[2]) ), _mm_set_ps1(idot_axis[2])) );
68
68
        
69
69
        return _mm_movemask_ps(_mm_cmpge_ps(tmax3, tmin3));
70
70
}
75
75
 * Based on Tactical Optimization of Ray/Box Intersection, by Graham Fyffe
76
76
 *  [http://tog.acm.org/resources/RTNews/html/rtnv21n1.html#art9]
77
77
 */
78
 
static int rayobject_bb_intersect_test(const Isect *isec, const float *_bb)
 
78
static inline int rayobject_bb_intersect_test(const Isect *isec, const float *_bb)
79
79
{
80
80
        const float *bb = _bb;
81
81
        
88
88
 
89
89
        RE_RC_COUNT(isec->raycounter->bb.test);
90
90
        
91
 
        if(t1x > t2y || t2x < t1y || t1x > t2z || t2x < t1z || t1y > t2z || t2y < t1z) return 0;
92
 
        if(t2x < 0.0 || t2y < 0.0 || t2z < 0.0) return 0;
93
 
        if(t1x > isec->dist || t1y > isec->dist || t1z > isec->dist) return 0;
94
 
        RE_RC_COUNT(isec->raycounter->bb.hit);  
 
91
        if (t1x > t2y  || t2x < t1y  || t1x > t2z || t2x < t1z || t1y > t2z || t2y < t1z) return 0;
 
92
        if (t2x < 0.0f || t2y < 0.0f || t2z < 0.0f) return 0;
 
93
        if (t1x > isec->dist || t1y > isec->dist || t1z > isec->dist) return 0;
 
94
        RE_RC_COUNT(isec->raycounter->bb.hit);
95
95
 
96
96
        return 1;
97
97
}
99
99
/* bvh tree generics */
100
100
template<class Tree> static void bvh_add(Tree *obj, RayObject *ob)
101
101
{
102
 
        rtbuild_add( obj->builder, ob );
 
102
        rtbuild_add(obj->builder, ob);
103
103
}
104
104
 
105
105
template<class Node>
113
113
template<class Tree>
114
114
static void bvh_free(Tree *obj)
115
115
{
116
 
        if(obj->builder)
 
116
        if (obj->builder)
117
117
                rtbuild_free(obj->builder);
118
118
 
119
 
        if(obj->node_arena)
 
119
        if (obj->node_arena)
120
120
                BLI_memarena_free(obj->node_arena);
121
121
 
122
122
        MEM_freeN(obj);
125
125
template<class Tree>
126
126
static void bvh_bb(Tree *obj, float *min, float *max)
127
127
{
128
 
        if(obj->root)
 
128
        if (obj->root)
129
129
                bvh_node_merge_bb(obj->root, min, max);
130
130
}
131
131
 
133
133
template<class Tree>
134
134
static float bvh_cost(Tree *obj)
135
135
{
136
 
        assert(obj->cost >= 0.0);
 
136
        assert(obj->cost >= 0.0f);
137
137
        return obj->cost;
138
138
}
139
139
 
142
142
/* bvh tree nodes generics */
143
143
template<class Node> static inline int bvh_node_hit_test(Node *node, Isect *isec)
144
144
{
145
 
        return rayobject_bb_intersect_test(isec, (const float*)node->bb);
 
145
        return rayobject_bb_intersect_test(isec, (const float *)node->bb);
146
146
}
147
147
 
148
148
 
149
149
template<class Node>
150
 
static inline void bvh_node_merge_bb(Node *node, float *min, float *max)
 
150
static inline void bvh_node_merge_bb(Node *node, float min[3], float max[3])
151
151
{
152
 
        if(is_leaf(node))
153
 
        {
154
 
                RE_rayobject_merge_bb( (RayObject*)node, min, max);
 
152
        if (is_leaf(node)) {
 
153
                RE_rayobject_merge_bb((RayObject *)node, min, max);
155
154
        }
156
 
        else
157
 
        {
158
 
                DO_MIN(node->bb  , min);
159
 
                DO_MAX(node->bb+3, max);
 
155
        else {
 
156
                DO_MIN(node->bb,     min);
 
157
                DO_MAX(node->bb + 3, max);
160
158
        }
161
159
}
162
160
 
167
165
 */
168
166
template<class Node> static inline void bvh_node_push_childs(Node *node, Isect *isec, Node **stack, int &stack_pos);
169
167
 
170
 
template<class Node,int MAX_STACK_SIZE,bool TEST_ROOT,bool SHADOW>
 
168
template<class Node, int MAX_STACK_SIZE, bool TEST_ROOT, bool SHADOW>
171
169
static int bvh_node_stack_raycast(Node *root, Isect *isec)
172
170
{
173
171
        Node *stack[MAX_STACK_SIZE];
174
172
        int hit = 0, stack_pos = 0;
175
173
                
176
 
        if(!TEST_ROOT && !is_leaf(root))
 
174
        if (!TEST_ROOT && !is_leaf(root))
177
175
                bvh_node_push_childs(root, isec, stack, stack_pos);
178
176
        else
179
177
                stack[stack_pos++] = root;
180
178
 
181
 
        while(stack_pos)
182
 
        {
 
179
        while (stack_pos) {
183
180
                Node *node = stack[--stack_pos];
184
 
                if(!is_leaf(node))
185
 
                {
186
 
                        if(bvh_node_hit_test(node,isec))
187
 
                        {
 
181
                if (!is_leaf(node)) {
 
182
                        if (bvh_node_hit_test(node, isec)) {
188
183
                                bvh_node_push_childs(node, isec, stack, stack_pos);
189
184
                                assert(stack_pos <= MAX_STACK_SIZE);
190
185
                        }
191
186
                }
192
 
                else
193
 
                {
194
 
                        hit |= RE_rayobject_intersect( (RayObject*)node, isec);
195
 
                        if(SHADOW && hit) return hit;
 
187
                else {
 
188
                        hit |= RE_rayobject_intersect( (RayObject *)node, isec);
 
189
                        if (SHADOW && hit) return hit;
196
190
                }
197
191
        }
198
192
        return hit;
205
199
 * this was created to be able to use any simd (with the cost of some memmoves)
206
200
 * it can take advantage of any SIMD width and doens't needs any special tree care
207
201
 */
208
 
template<class Node,int MAX_STACK_SIZE,bool TEST_ROOT>
 
202
template<class Node, int MAX_STACK_SIZE, bool TEST_ROOT>
209
203
static int bvh_node_stack_raycast_simd(Node *root, Isect *isec)
210
204
{
211
205
        Node *stack[MAX_STACK_SIZE];
212
206
 
213
207
        int hit = 0, stack_pos = 0;
214
208
                
215
 
        if(!TEST_ROOT)
216
 
        {
217
 
                if(!is_leaf(root))
218
 
                {
219
 
                        if(!is_leaf(root->child))
 
209
        if (!TEST_ROOT) {
 
210
                if (!is_leaf(root)) {
 
211
                        if (!is_leaf(root->child))
220
212
                                bvh_node_push_childs(root, isec, stack, stack_pos);
221
213
                        else
222
 
                                return RE_rayobject_intersect( (RayObject*)root->child, isec);
 
214
                                return RE_rayobject_intersect( (RayObject *)root->child, isec);
223
215
                }
224
216
                else
225
 
                        return RE_rayobject_intersect( (RayObject*)root, isec);
 
217
                        return RE_rayobject_intersect( (RayObject *)root, isec);
226
218
        }
227
 
        else
228
 
        {
229
 
                if(!is_leaf(root))
 
219
        else {
 
220
                if (!is_leaf(root))
230
221
                        stack[stack_pos++] = root;
231
222
                else
232
 
                        return RE_rayobject_intersect( (RayObject*)root, isec);
 
223
                        return RE_rayobject_intersect( (RayObject *)root, isec);
233
224
        }
234
225
 
235
 
        while(true)
236
 
        {
 
226
        while (true) {
237
227
                //Use SIMD 4
238
 
                if(stack_pos >= 4)
239
 
                {
 
228
                if (stack_pos >= 4) {
240
229
                        __m128 t_bb[6];
241
 
                        Node * t_node[4];
 
230
                        Node *t_node[4];
242
231
                        
243
232
                        stack_pos -= 4;
244
233
 
245
234
                        /* prepare the 4BB for SIMD */
246
 
                        t_node[0] = stack[stack_pos+0]->child;
247
 
                        t_node[1] = stack[stack_pos+1]->child;
248
 
                        t_node[2] = stack[stack_pos+2]->child;
249
 
                        t_node[3] = stack[stack_pos+3]->child;
250
 
                        
251
 
                        const float *bb0 = stack[stack_pos+0]->bb;
252
 
                        const float *bb1 = stack[stack_pos+1]->bb;
253
 
                        const float *bb2 = stack[stack_pos+2]->bb;
254
 
                        const float *bb3 = stack[stack_pos+3]->bb;
255
 
                        
256
 
                        const __m128 x0y0x1y1 = _mm_shuffle_ps( _mm_load_ps(bb0), _mm_load_ps(bb1), _MM_SHUFFLE(1,0,1,0) );
257
 
                        const __m128 x2y2x3y3 = _mm_shuffle_ps( _mm_load_ps(bb2), _mm_load_ps(bb3), _MM_SHUFFLE(1,0,1,0) );
258
 
                        t_bb[0] = _mm_shuffle_ps( x0y0x1y1, x2y2x3y3, _MM_SHUFFLE(2,0,2,0) );
259
 
                        t_bb[1] = _mm_shuffle_ps( x0y0x1y1, x2y2x3y3, _MM_SHUFFLE(3,1,3,1) );
260
 
 
261
 
                        const __m128 z0X0z1X1 = _mm_shuffle_ps( _mm_load_ps(bb0), _mm_load_ps(bb1), _MM_SHUFFLE(3,2,3,2) );
262
 
                        const __m128 z2X2z3X3 = _mm_shuffle_ps( _mm_load_ps(bb2), _mm_load_ps(bb3), _MM_SHUFFLE(3,2,3,2) );
263
 
                        t_bb[2] = _mm_shuffle_ps( z0X0z1X1, z2X2z3X3, _MM_SHUFFLE(2,0,2,0) );
264
 
                        t_bb[3] = _mm_shuffle_ps( z0X0z1X1, z2X2z3X3, _MM_SHUFFLE(3,1,3,1) );
265
 
 
266
 
                        const __m128 Y0Z0Y1Z1 = _mm_shuffle_ps( _mm_load_ps(bb0+4), _mm_load_ps(bb1+4), _MM_SHUFFLE(1,0,1,0) );
267
 
                        const __m128 Y2Z2Y3Z3 = _mm_shuffle_ps( _mm_load_ps(bb2+4), _mm_load_ps(bb3+4), _MM_SHUFFLE(1,0,1,0) );
268
 
                        t_bb[4] = _mm_shuffle_ps( Y0Z0Y1Z1, Y2Z2Y3Z3, _MM_SHUFFLE(2,0,2,0) );
269
 
                        t_bb[5] = _mm_shuffle_ps( Y0Z0Y1Z1, Y2Z2Y3Z3, _MM_SHUFFLE(3,1,3,1) );
 
235
                        t_node[0] = stack[stack_pos + 0]->child;
 
236
                        t_node[1] = stack[stack_pos + 1]->child;
 
237
                        t_node[2] = stack[stack_pos + 2]->child;
 
238
                        t_node[3] = stack[stack_pos + 3]->child;
 
239
 
 
240
                        const float *bb0 = stack[stack_pos + 0]->bb;
 
241
                        const float *bb1 = stack[stack_pos + 1]->bb;
 
242
                        const float *bb2 = stack[stack_pos + 2]->bb;
 
243
                        const float *bb3 = stack[stack_pos + 3]->bb;
 
244
 
 
245
                        const __m128 x0y0x1y1 = _mm_shuffle_ps(_mm_load_ps(bb0), _mm_load_ps(bb1), _MM_SHUFFLE(1, 0, 1, 0) );
 
246
                        const __m128 x2y2x3y3 = _mm_shuffle_ps(_mm_load_ps(bb2), _mm_load_ps(bb3), _MM_SHUFFLE(1, 0, 1, 0) );
 
247
                        t_bb[0] = _mm_shuffle_ps(x0y0x1y1, x2y2x3y3, _MM_SHUFFLE(2, 0, 2, 0) );
 
248
                        t_bb[1] = _mm_shuffle_ps(x0y0x1y1, x2y2x3y3, _MM_SHUFFLE(3, 1, 3, 1) );
 
249
 
 
250
                        const __m128 z0X0z1X1 = _mm_shuffle_ps(_mm_load_ps(bb0), _mm_load_ps(bb1), _MM_SHUFFLE(3, 2, 3, 2) );
 
251
                        const __m128 z2X2z3X3 = _mm_shuffle_ps(_mm_load_ps(bb2), _mm_load_ps(bb3), _MM_SHUFFLE(3, 2, 3, 2) );
 
252
                        t_bb[2] = _mm_shuffle_ps(z0X0z1X1, z2X2z3X3, _MM_SHUFFLE(2, 0, 2, 0) );
 
253
                        t_bb[3] = _mm_shuffle_ps(z0X0z1X1, z2X2z3X3, _MM_SHUFFLE(3, 1, 3, 1) );
 
254
 
 
255
                        const __m128 Y0Z0Y1Z1 = _mm_shuffle_ps(_mm_load_ps(bb0 + 4), _mm_load_ps(bb1 + 4), _MM_SHUFFLE(1, 0, 1, 0) );
 
256
                        const __m128 Y2Z2Y3Z3 = _mm_shuffle_ps(_mm_load_ps(bb2 + 4), _mm_load_ps(bb3 + 4), _MM_SHUFFLE(1, 0, 1, 0) );
 
257
                        t_bb[4] = _mm_shuffle_ps(Y0Z0Y1Z1, Y2Z2Y3Z3, _MM_SHUFFLE(2, 0, 2, 0) );
 
258
                        t_bb[5] = _mm_shuffle_ps(Y0Z0Y1Z1, Y2Z2Y3Z3, _MM_SHUFFLE(3, 1, 3, 1) );
270
259
#if 0
271
 
                        for(int i=0; i<4; i++)
 
260
                        for (int i = 0; i < 4; i++)
272
261
                        {
273
 
                                Node *t = stack[stack_pos+i];
 
262
                                Node *t = stack[stack_pos + i];
274
263
                                assert(!is_leaf(t));
275
264
                                
276
 
                                float *bb = ((float*)t_bb)+i;
277
 
                                bb[4*0] = t->bb[0];
278
 
                                bb[4*1] = t->bb[1];
279
 
                                bb[4*2] = t->bb[2];
280
 
                                bb[4*3] = t->bb[3];
281
 
                                bb[4*4] = t->bb[4];
282
 
                                bb[4*5] = t->bb[5];
 
265
                                float *bb = ((float *)t_bb) + i;
 
266
                                bb[4 * 0] = t->bb[0];
 
267
                                bb[4 * 1] = t->bb[1];
 
268
                                bb[4 * 2] = t->bb[2];
 
269
                                bb[4 * 3] = t->bb[3];
 
270
                                bb[4 * 4] = t->bb[4];
 
271
                                bb[4 * 5] = t->bb[5];
283
272
                                t_node[i] = t->child;
284
273
                        }
285
274
#endif
286
275
                        RE_RC_COUNT(isec->raycounter->simd_bb.test);
287
 
                        int res = test_bb_group4( t_bb, isec );
 
276
                        int res = test_bb_group4(t_bb, isec);
288
277
 
289
 
                        for(int i=0; i<4; i++)
290
 
                        if(res & (1<<i))
291
 
                        {
292
 
                                RE_RC_COUNT(isec->raycounter->simd_bb.hit);
293
 
                                if(!is_leaf(t_node[i]))
294
 
                                {
295
 
                                        for(Node *t=t_node[i]; t; t=t->sibling)
296
 
                                        {
297
 
                                                assert(stack_pos < MAX_STACK_SIZE);
298
 
                                                stack[stack_pos++] = t;
 
278
                        for (int i = 0; i < 4; i++)
 
279
                                if (res & (1 << i)) {
 
280
                                        RE_RC_COUNT(isec->raycounter->simd_bb.hit);
 
281
                                        if (!is_leaf(t_node[i])) {
 
282
                                                for (Node *t = t_node[i]; t; t = t->sibling) {
 
283
                                                        assert(stack_pos < MAX_STACK_SIZE);
 
284
                                                        stack[stack_pos++] = t;
 
285
                                                }
 
286
                                        }
 
287
                                        else {
 
288
                                                hit |= RE_rayobject_intersect( (RayObject *)t_node[i], isec);
 
289
                                                if (hit && isec->mode == RE_RAY_SHADOW) return hit;
299
290
                                        }
300
291
                                }
301
 
                                else
302
 
                                {
303
 
                                        hit |= RE_rayobject_intersect( (RayObject*)t_node[i], isec);
304
 
                                        if(hit && isec->mode == RE_RAY_SHADOW) return hit;                              
305
 
                                }       
306
 
                        }
307
292
                }
308
 
                else if(stack_pos > 0)
309
 
                {       
 
293
                else if (stack_pos > 0) {
310
294
                        Node *node = stack[--stack_pos];
311
295
                        assert(!is_leaf(node));
312
296
                        
313
 
                        if(bvh_node_hit_test(node,isec))
314
 
                        {
315
 
                                if(!is_leaf(node->child))
316
 
                                {
 
297
                        if (bvh_node_hit_test(node, isec)) {
 
298
                                if (!is_leaf(node->child)) {
317
299
                                        bvh_node_push_childs(node, isec, stack, stack_pos);
318
300
                                        assert(stack_pos <= MAX_STACK_SIZE);
319
301
                                }
320
 
                                else
321
 
                                {
322
 
                                        hit |= RE_rayobject_intersect( (RayObject*)node->child, isec);
323
 
                                        if(hit && isec->mode == RE_RAY_SHADOW) return hit;
 
302
                                else {
 
303
                                        hit |= RE_rayobject_intersect( (RayObject *)node->child, isec);
 
304
                                        if (hit && isec->mode == RE_RAY_SHADOW) return hit;
324
305
                                }
325
306
                        }
326
307
                }
338
319
static int bvh_node_raycast(Node *node, Isect *isec)
339
320
{
340
321
        int hit = 0;
341
 
        if(bvh_test_node(node, isec))
 
322
        if (bvh_test_node(node, isec))
342
323
        {
343
 
                if(isec->idot_axis[node->split_axis] > 0.0f)
 
324
                if (isec->idot_axis[node->split_axis] > 0.0f)
344
325
                {
345
326
                        int i;
346
 
                        for(i=0; i<BVH_NCHILDS; i++)
347
 
                                if(!is_leaf(node->child[i]))
 
327
                        for (i = 0; i < BVH_NCHILDS; i++)
 
328
                                if (!is_leaf(node->child[i]))
348
329
                                {
349
 
                                        if(node->child[i] == 0) break;
 
330
                                        if (node->child[i] == 0) break;
350
331
                                        
351
332
                                        hit |= bvh_node_raycast(node->child[i], isec);
352
 
                                        if(hit && isec->mode == RE_RAY_SHADOW) return hit;
 
333
                                        if (hit && isec->mode == RE_RAY_SHADOW) return hit;
353
334
                                }
354
 
                                else
355
 
                                {
356
 
                                        hit |= RE_rayobject_intersect( (RayObject*)node->child[i], isec);
357
 
                                        if(hit && isec->mode == RE_RAY_SHADOW) return hit;
 
335
                                else {
 
336
                                        hit |= RE_rayobject_intersect( (RayObject *)node->child[i], isec);
 
337
                                        if (hit && isec->mode == RE_RAY_SHADOW) return hit;
358
338
                                }
359
339
                }
360
 
                else
361
 
                {
 
340
                else {
362
341
                        int i;
363
 
                        for(i=BVH_NCHILDS-1; i>=0; i--)
364
 
                                if(!is_leaf(node->child[i]))
 
342
                        for (i = BVH_NCHILDS - 1; i >= 0; i--)
 
343
                                if (!is_leaf(node->child[i]))
365
344
                                {
366
 
                                        if(node->child[i])
 
345
                                        if (node->child[i])
367
346
                                        {
368
347
                                                hit |= dfs_raycast(node->child[i], isec);
369
 
                                                if(hit && isec->mode == RE_RAY_SHADOW) return hit;
 
348
                                                if (hit && isec->mode == RE_RAY_SHADOW) return hit;
370
349
                                        }
371
350
                                }
372
 
                                else
373
 
                                {
374
 
                                        hit |= RE_rayobject_intersect( (RayObject*)node->child[i], isec);
375
 
                                        if(hit && isec->mode == RE_RAY_SHADOW) return hit;
 
351
                                else {
 
352
                                        hit |= RE_rayobject_intersect( (RayObject *)node->child[i], isec);
 
353
                                        if (hit && isec->mode == RE_RAY_SHADOW) return hit;
376
354
                                }
377
355
                }
378
356
        }
380
358
}
381
359
#endif
382
360
 
383
 
template<class Node,class HintObject>
 
361
template<class Node, class HintObject>
384
362
void bvh_dfs_make_hint(Node *node, LCTSHint *hint, int reserve_space, HintObject *hintObject)
385
363
{
386
 
        assert( hint->size + reserve_space + 1 <= RE_RAY_LCTS_MAX_SIZE );
 
364
        assert(hint->size + reserve_space + 1 <= RE_RAY_LCTS_MAX_SIZE);
387
365
        
388
 
        if(is_leaf(node))
389
 
        {
390
 
                hint->stack[hint->size++] = (RayObject*)node;
 
366
        if (is_leaf(node)) {
 
367
                hint->stack[hint->size++] = (RayObject *)node;
391
368
        }
392
 
        else
393
 
        {
 
369
        else {
394
370
                int childs = count_childs(node);
395
 
                if(hint->size + reserve_space + childs <= RE_RAY_LCTS_MAX_SIZE)
396
 
                {
397
 
                        int result = hint_test_bb(hintObject, node->bb, node->bb+3);
398
 
                        if(result == HINT_RECURSE)
399
 
                        {
 
371
                if (hint->size + reserve_space + childs <= RE_RAY_LCTS_MAX_SIZE) {
 
372
                        int result = hint_test_bb(hintObject, node->bb, node->bb + 3);
 
373
                        if (result == HINT_RECURSE) {
400
374
                                /* We are 100% sure the ray will be pass inside this node */
401
375
                                bvh_dfs_make_hint_push_siblings(node->child, hint, reserve_space, hintObject);
402
376
                        }
403
 
                        else if(result == HINT_ACCEPT)
404
 
                        {
405
 
                                hint->stack[hint->size++] = (RayObject*)node;
 
377
                        else if (result == HINT_ACCEPT) {
 
378
                                hint->stack[hint->size++] = (RayObject *)node;
406
379
                        }
407
380
                }
408
 
                else
409
 
                {
410
 
                        hint->stack[hint->size++] = (RayObject*)node;
 
381
                else {
 
382
                        hint->stack[hint->size++] = (RayObject *)node;
411
383
                }
412
384
        }
413
385
}
414
386
 
415
387
 
416
388
template<class Tree>
417
 
static RayObjectAPI* bvh_get_api(int maxstacksize);
 
389
static RayObjectAPI *bvh_get_api(int maxstacksize);
418
390
 
419
391
 
420
392
template<class Tree, int DFS_STACK_SIZE>
421
393
static inline RayObject *bvh_create_tree(int size)
422
394
{
423
 
        Tree *obj= (Tree*)MEM_callocN(sizeof(Tree), "BVHTree" );
424
 
        assert( RE_rayobject_isAligned(obj) ); /* RayObject API assumes real data to be 4-byte aligned */       
 
395
        Tree *obj = (Tree *)MEM_callocN(sizeof(Tree), "BVHTree");
 
396
        assert(RE_rayobject_isAligned(obj)); /* RayObject API assumes real data to be 4-byte aligned */
425
397
        
426
398
        obj->rayobj.api = bvh_get_api<Tree>(DFS_STACK_SIZE);
427
399
        obj->root = NULL;
428
400
        
429
401
        obj->node_arena = NULL;
430
 
        obj->builder    = rtbuild_create( size );
 
402
        obj->builder    = rtbuild_create(size);
431
403
        
432
 
        return RE_rayobject_unalignRayAPI((RayObject*) obj);
 
404
        return RE_rayobject_unalignRayAPI((RayObject *) obj);
433
405
}
434
406
 
435
407
#endif