From b340f930ec5639f24e7e2d47fab221fb752b61dd Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Sat, 28 Apr 2012 06:31:57 +0000 Subject: style cleanup: changes to brace placement / newlines - for/while/if/switch --- source/blender/render/intern/raytrace/bvh.h | 121 ++++++------- .../blender/render/intern/raytrace/rayobject.cpp | 78 +++------ .../render/intern/raytrace/rayobject_blibvh.cpp | 3 +- .../render/intern/raytrace/rayobject_hint.h | 2 +- .../render/intern/raytrace/rayobject_instance.cpp | 18 +- .../render/intern/raytrace/rayobject_octree.cpp | 72 ++++---- .../render/intern/raytrace/rayobject_qbvh.cpp | 3 +- .../render/intern/raytrace/rayobject_rtbuild.cpp | 53 ++---- .../render/intern/raytrace/rayobject_svbvh.cpp | 12 +- .../render/intern/raytrace/rayobject_vbvh.cpp | 12 +- source/blender/render/intern/raytrace/reorganize.h | 188 ++++++++------------- source/blender/render/intern/raytrace/svbvh.h | 89 +++++----- source/blender/render/intern/raytrace/vbvh.h | 35 ++-- .../blender/render/intern/source/convertblender.c | 13 +- source/blender/render/intern/source/initrender.c | 4 +- source/blender/render/intern/source/pointdensity.c | 2 +- source/blender/render/intern/source/rayshade.c | 102 ++++------- .../blender/render/intern/source/render_texture.c | 10 +- source/blender/render/intern/source/rendercore.c | 4 +- .../blender/render/intern/source/renderdatabase.c | 6 +- source/blender/render/intern/source/shadeoutput.c | 7 +- source/blender/render/intern/source/sunsky.c | 6 +- .../blender/render/intern/source/volume_precache.c | 33 ++-- source/blender/render/intern/source/volumetric.c | 3 +- source/blender/render/intern/source/voxeldata.c | 17 +- source/blender/render/intern/source/zbuf.c | 4 +- 26 files changed, 350 insertions(+), 547 deletions(-) (limited to 'source/blender/render') diff --git a/source/blender/render/intern/raytrace/bvh.h b/source/blender/render/intern/raytrace/bvh.h index ac86a65ff0b..946b64e98e5 100644 --- a/source/blender/render/intern/raytrace/bvh.h +++ b/source/blender/render/intern/raytrace/bvh.h @@ -88,9 +88,9 @@ static int rayobject_bb_intersect_test(const Isect *isec, const float *_bb) RE_RC_COUNT(isec->raycounter->bb.test); - if(t1x > t2y || t2x < t1y || t1x > t2z || t2x < t1z || t1y > t2z || t2y < t1z) return 0; - if(t2x < 0.0 || t2y < 0.0 || t2z < 0.0) return 0; - if(t1x > isec->dist || t1y > isec->dist || t1z > isec->dist) return 0; + if (t1x > t2y || t2x < t1y || t1x > t2z || t2x < t1z || t1y > t2z || t2y < t1z) return 0; + if (t2x < 0.0 || t2y < 0.0 || t2z < 0.0) return 0; + if (t1x > isec->dist || t1y > isec->dist || t1z > isec->dist) return 0; RE_RC_COUNT(isec->raycounter->bb.hit); return 1; @@ -113,10 +113,10 @@ template static void bvh_done(Tree *obj); template static void bvh_free(Tree *obj) { - if(obj->builder) + if (obj->builder) rtbuild_free(obj->builder); - if(obj->node_arena) + if (obj->node_arena) BLI_memarena_free(obj->node_arena); MEM_freeN(obj); @@ -125,7 +125,7 @@ static void bvh_free(Tree *obj) template static void bvh_bb(Tree *obj, float *min, float *max) { - if(obj->root) + if (obj->root) bvh_node_merge_bb(obj->root, min, max); } @@ -149,12 +149,10 @@ template static inline int bvh_node_hit_test(Node *node, Isect *isec template static inline void bvh_node_merge_bb(Node *node, float *min, float *max) { - if(is_leaf(node)) - { + if (is_leaf(node)) { RE_rayobject_merge_bb( (RayObject*)node, min, max); } - else - { + else { DO_MIN(node->bb , min); DO_MAX(node->bb+3, max); } @@ -173,26 +171,22 @@ static int bvh_node_stack_raycast(Node *root, Isect *isec) Node *stack[MAX_STACK_SIZE]; int hit = 0, stack_pos = 0; - if(!TEST_ROOT && !is_leaf(root)) + if (!TEST_ROOT && !is_leaf(root)) bvh_node_push_childs(root, isec, stack, stack_pos); else stack[stack_pos++] = root; - while(stack_pos) - { + while (stack_pos) { Node *node = stack[--stack_pos]; - if(!is_leaf(node)) - { - if(bvh_node_hit_test(node,isec)) - { + if (!is_leaf(node)) { + if (bvh_node_hit_test(node,isec)) { bvh_node_push_childs(node, isec, stack, stack_pos); assert(stack_pos <= MAX_STACK_SIZE); } } - else - { + else { hit |= RE_rayobject_intersect( (RayObject*)node, isec); - if(SHADOW && hit) return hit; + if (SHADOW && hit) return hit; } } return hit; @@ -212,11 +206,9 @@ static int bvh_node_stack_raycast_simd(Node *root, Isect *isec) int hit = 0, stack_pos = 0; - if(!TEST_ROOT) - { - if(!is_leaf(root)) - { - if(!is_leaf(root->child)) + if (!TEST_ROOT) { + if (!is_leaf(root)) { + if (!is_leaf(root->child)) bvh_node_push_childs(root, isec, stack, stack_pos); else return RE_rayobject_intersect( (RayObject*)root->child, isec); @@ -224,19 +216,16 @@ static int bvh_node_stack_raycast_simd(Node *root, Isect *isec) else return RE_rayobject_intersect( (RayObject*)root, isec); } - else - { - if(!is_leaf(root)) + else { + if (!is_leaf(root)) stack[stack_pos++] = root; else return RE_rayobject_intersect( (RayObject*)root, isec); } - while(true) - { + while (true) { //Use SIMD 4 - if(stack_pos >= 4) - { + if (stack_pos >= 4) { __m128 t_bb[6]; Node * t_node[4]; @@ -286,41 +275,33 @@ static int bvh_node_stack_raycast_simd(Node *root, Isect *isec) RE_RC_COUNT(isec->raycounter->simd_bb.test); int res = test_bb_group4( t_bb, isec ); - for(int i=0; i<4; i++) - if(res & (1<raycounter->simd_bb.hit); - if(!is_leaf(t_node[i])) - { - for(Node *t=t_node[i]; t; t=t->sibling) - { + if (!is_leaf(t_node[i])) { + for (Node *t = t_node[i]; t; t = t->sibling) { assert(stack_pos < MAX_STACK_SIZE); stack[stack_pos++] = t; } } - else - { + else { hit |= RE_rayobject_intersect( (RayObject*)t_node[i], isec); - if(hit && isec->mode == RE_RAY_SHADOW) return hit; + if (hit && isec->mode == RE_RAY_SHADOW) return hit; } } } - else if(stack_pos > 0) - { + else if (stack_pos > 0) { Node *node = stack[--stack_pos]; assert(!is_leaf(node)); - if(bvh_node_hit_test(node,isec)) - { - if(!is_leaf(node->child)) - { + if (bvh_node_hit_test(node,isec)) { + if (!is_leaf(node->child)) { bvh_node_push_childs(node, isec, stack, stack_pos); assert(stack_pos <= MAX_STACK_SIZE); } - else - { + else { hit |= RE_rayobject_intersect( (RayObject*)node->child, isec); - if(hit && isec->mode == RE_RAY_SHADOW) return hit; + if (hit && isec->mode == RE_RAY_SHADOW) return hit; } } } @@ -338,41 +319,41 @@ template static int bvh_node_raycast(Node *node, Isect *isec) { int hit = 0; - if(bvh_test_node(node, isec)) + if (bvh_test_node(node, isec)) { - if(isec->idot_axis[node->split_axis] > 0.0f) + if (isec->idot_axis[node->split_axis] > 0.0f) { int i; for(i=0; ichild[i])) + if (!is_leaf(node->child[i])) { - if(node->child[i] == 0) break; + if (node->child[i] == 0) break; hit |= bvh_node_raycast(node->child[i], isec); - if(hit && isec->mode == RE_RAY_SHADOW) return hit; + if (hit && isec->mode == RE_RAY_SHADOW) return hit; } else { hit |= RE_rayobject_intersect( (RayObject*)node->child[i], isec); - if(hit && isec->mode == RE_RAY_SHADOW) return hit; + if (hit && isec->mode == RE_RAY_SHADOW) return hit; } } else { int i; for(i=BVH_NCHILDS-1; i>=0; i--) - if(!is_leaf(node->child[i])) + if (!is_leaf(node->child[i])) { - if(node->child[i]) + if (node->child[i]) { hit |= dfs_raycast(node->child[i], isec); - if(hit && isec->mode == RE_RAY_SHADOW) return hit; + if (hit && isec->mode == RE_RAY_SHADOW) return hit; } } else { hit |= RE_rayobject_intersect( (RayObject*)node->child[i], isec); - if(hit && isec->mode == RE_RAY_SHADOW) return hit; + if (hit && isec->mode == RE_RAY_SHADOW) return hit; } } } @@ -385,28 +366,22 @@ void bvh_dfs_make_hint(Node *node, LCTSHint *hint, int reserve_space, HintObject { assert( hint->size + reserve_space + 1 <= RE_RAY_LCTS_MAX_SIZE ); - if(is_leaf(node)) - { + if (is_leaf(node)) { hint->stack[hint->size++] = (RayObject*)node; } - else - { + else { int childs = count_childs(node); - if(hint->size + reserve_space + childs <= RE_RAY_LCTS_MAX_SIZE) - { + if (hint->size + reserve_space + childs <= RE_RAY_LCTS_MAX_SIZE) { int result = hint_test_bb(hintObject, node->bb, node->bb+3); - if(result == HINT_RECURSE) - { + if (result == HINT_RECURSE) { /* We are 100% sure the ray will be pass inside this node */ bvh_dfs_make_hint_push_siblings(node->child, hint, reserve_space, hintObject); } - else if(result == HINT_ACCEPT) - { + else if (result == HINT_ACCEPT) { hint->stack[hint->size++] = (RayObject*)node; } } - else - { + else { hint->stack[hint->size++] = (RayObject*)node; } } diff --git a/source/blender/render/intern/raytrace/rayobject.cpp b/source/blender/render/intern/raytrace/rayobject.cpp index b2f85e8429d..a2773ba218d 100644 --- a/source/blender/render/intern/raytrace/rayobject.cpp +++ b/source/blender/render/intern/raytrace/rayobject.cpp @@ -60,13 +60,11 @@ MALWAYS_INLINE RayObject* rayface_from_coords(RayFace *rayface, void *ob, void * copy_v3_v3(rayface->v2, v2); copy_v3_v3(rayface->v3, v3); - if (v4) - { + if (v4) { copy_v3_v3(rayface->v4, v4); rayface->quad = 1; } - else - { + else { rayface->quad = 0; } @@ -77,8 +75,7 @@ MALWAYS_INLINE void rayface_from_vlak(RayFace *rayface, ObjectInstanceRen *obi, { rayface_from_coords(rayface, obi, vlr, vlr->v1->co, vlr->v2->co, vlr->v3->co, vlr->v4 ? vlr->v4->co : NULL); - if (obi->transform_primitives) - { + if (obi->transform_primitives) { mul_m4_v3(obi->mat, rayface->v1); mul_m4_v3(obi->mat, rayface->v2); mul_m4_v3(obi->mat, rayface->v3); @@ -295,13 +292,11 @@ MALWAYS_INLINE int intersect_rayface(RayObject *hit_obj, RayFace *face, Isect *i return 0; /* check if we should intersect this face */ - if (is->check == RE_CHECK_VLR_RENDER) - { + if (is->check == RE_CHECK_VLR_RENDER) { if (vlr_check_intersect(is, (ObjectInstanceRen*)face->ob, (VlakRen*)face->face) == 0) return 0; } - else if (is->check == RE_CHECK_VLR_NON_SOLID_MATERIAL) - { + else if (is->check == RE_CHECK_VLR_NON_SOLID_MATERIAL) { if (vlr_check_intersect(is, (ObjectInstanceRen*)face->ob, (VlakRen*)face->face) == 0) return 0; if (vlr_check_intersect_solid(is, (ObjectInstanceRen*)face->ob, (VlakRen*)face->face) == 0) @@ -322,27 +317,25 @@ MALWAYS_INLINE int intersect_rayface(RayObject *hit_obj, RayFace *face, Isect *i /* when a shadow ray leaves a face, it can be little outside the edges * of it, causing intersection to be detected in its neighbor face */ - if (is->skip & RE_SKIP_VLR_NEIGHBOUR) - { - if (dist < 0.1f && is->orig.ob == face->ob) - { + if (is->skip & RE_SKIP_VLR_NEIGHBOUR) { + if (dist < 0.1f && is->orig.ob == face->ob) { VlakRen * a = (VlakRen*)is->orig.face; VlakRen * b = (VlakRen*)face->face; /* so there's a shared edge or vertex, let's intersect ray with * face itself, if that's true we can safely return 1, otherwise * we assume the intersection is invalid, 0 */ - if (a->v1==b->v1 || a->v2==b->v1 || a->v3==b->v1 || a->v4==b->v1 - || a->v1==b->v2 || a->v2==b->v2 || a->v3==b->v2 || a->v4==b->v2 - || a->v1==b->v3 || a->v2==b->v3 || a->v3==b->v3 || a->v4==b->v3 - || (b->v4 && (a->v1==b->v4 || a->v2==b->v4 || a->v3==b->v4 || a->v4==b->v4))) { + if (a->v1==b->v1 || a->v2==b->v1 || a->v3==b->v1 || a->v4==b->v1 || + a->v1==b->v2 || a->v2==b->v2 || a->v3==b->v2 || a->v4==b->v2 || + a->v1==b->v3 || a->v2==b->v3 || a->v3==b->v3 || a->v4==b->v3 || + (b->v4 && (a->v1==b->v4 || a->v2==b->v4 || a->v3==b->v4 || a->v4==b->v4))) + { /* create RayFace from original face, transformed if necessary */ RayFace origface; ObjectInstanceRen *ob= (ObjectInstanceRen*)is->orig.ob; rayface_from_vlak(&origface, ob, (VlakRen*)is->orig.face); - if (!isec_tri_quad_neighbour(is->start, is->dir, &origface)) - { + if (!isec_tri_quad_neighbour(is->start, is->dir, &origface)) { return 0; } } @@ -375,8 +368,7 @@ int RE_rayobject_raycast(RayObject *r, Isect *isec) RE_RC_COUNT(isec->raycounter->raycast.test); /* setup vars used on raycast */ - for (i=0; i<3; i++) - { + for (i=0; i<3; i++) { isec->idot_axis[i] = 1.0f / isec->dir[i]; isec->bv_index[2*i] = isec->idot_axis[i] < 0.0 ? 1 : 0; @@ -388,12 +380,10 @@ int RE_rayobject_raycast(RayObject *r, Isect *isec) #ifdef RT_USE_LAST_HIT /* last hit heuristic */ - if (isec->mode==RE_RAY_SHADOW && isec->last_hit) - { + if (isec->mode==RE_RAY_SHADOW && isec->last_hit) { RE_RC_COUNT(isec->raycounter->rayshadow_last_hit.test); - if (RE_rayobject_intersect(isec->last_hit, isec)) - { + if (RE_rayobject_intersect(isec->last_hit, isec)) { RE_RC_COUNT(isec->raycounter->raycast.hit); RE_RC_COUNT(isec->raycounter->rayshadow_last_hit.hit); return 1; @@ -405,8 +395,7 @@ int RE_rayobject_raycast(RayObject *r, Isect *isec) isec->hit_hint = 0; #endif - if (RE_rayobject_intersect(r, isec)) - { + if (RE_rayobject_intersect(r, isec)) { RE_RC_COUNT(isec->raycounter->raycast.hit); #ifdef RT_USE_HINT @@ -420,12 +409,10 @@ int RE_rayobject_raycast(RayObject *r, Isect *isec) int RE_rayobject_intersect(RayObject *r, Isect *i) { - if (RE_rayobject_isRayFace(r)) - { + if (RE_rayobject_isRayFace(r)) { return intersect_rayface(r, (RayFace*) RE_rayobject_align(r), i); } - else if (RE_rayobject_isVlakPrimitive(r)) - { + else if (RE_rayobject_isVlakPrimitive(r)) { //TODO optimize (useless copy to RayFace to avoid duplicate code) VlakPrimitive *face = (VlakPrimitive*) RE_rayobject_align(r); RayFace nface; @@ -433,8 +420,7 @@ int RE_rayobject_intersect(RayObject *r, Isect *i) return intersect_rayface(r, &nface, i); } - else if (RE_rayobject_isRayAPI(r)) - { + else if (RE_rayobject_isRayAPI(r)) { r = RE_rayobject_align(r); return r->api->raycast(r, i); } @@ -466,12 +452,10 @@ void RE_rayobject_free(RayObject *r) float RE_rayobject_cost(RayObject *r) { - if (RE_rayobject_isRayFace(r) || RE_rayobject_isVlakPrimitive(r)) - { + if (RE_rayobject_isRayFace(r) || RE_rayobject_isVlakPrimitive(r)) { return 1.0f; } - else if (RE_rayobject_isRayAPI(r)) - { + else if (RE_rayobject_isRayAPI(r)) { r = RE_rayobject_align(r); return r->api->cost(r); } @@ -485,8 +469,7 @@ float RE_rayobject_cost(RayObject *r) void RE_rayobject_merge_bb(RayObject *r, float *min, float *max) { - if (RE_rayobject_isRayFace(r)) - { + if (RE_rayobject_isRayFace(r)) { RayFace *face = (RayFace*) RE_rayobject_align(r); DO_MINMAX(face->v1, min, max); @@ -494,8 +477,7 @@ void RE_rayobject_merge_bb(RayObject *r, float *min, float *max) DO_MINMAX(face->v3, min, max); if (RE_rayface_isQuad(face)) DO_MINMAX(face->v4, min, max); } - else if (RE_rayobject_isVlakPrimitive(r)) - { + else if (RE_rayobject_isVlakPrimitive(r)) { VlakPrimitive *face = (VlakPrimitive*) RE_rayobject_align(r); RayFace nface; rayface_from_vlak(&nface, face->ob, face->face); @@ -505,8 +487,7 @@ void RE_rayobject_merge_bb(RayObject *r, float *min, float *max) DO_MINMAX(nface.v3, min, max); if (RE_rayface_isQuad(&nface)) DO_MINMAX(nface.v4, min, max); } - else if (RE_rayobject_isRayAPI(r)) - { + else if (RE_rayobject_isRayAPI(r)) { r = RE_rayobject_align(r); r->api->bb(r, min, max); } @@ -518,12 +499,10 @@ void RE_rayobject_merge_bb(RayObject *r, float *min, float *max) void RE_rayobject_hint_bb(RayObject *r, RayHint *hint, float *min, float *max) { - if (RE_rayobject_isRayFace(r) || RE_rayobject_isVlakPrimitive(r)) - { + if (RE_rayobject_isRayFace(r) || RE_rayobject_isVlakPrimitive(r)) { return; } - else if (RE_rayobject_isRayAPI(r)) - { + else if (RE_rayobject_isRayAPI(r)) { r = RE_rayobject_align(r); return r->api->hint_bb(r, hint, min, max); } @@ -543,8 +522,7 @@ int RE_rayobjectcontrol_test_break(RayObjectControl *control) void RE_rayobject_set_control(RayObject *r, void *data, RE_rayobjectcontrol_test_break_callback test_break) { - if (RE_rayobject_isRayAPI(r)) - { + if (RE_rayobject_isRayAPI(r)) { r = RE_rayobject_align(r); r->control.data = data; r->control.test_break = test_break; diff --git a/source/blender/render/intern/raytrace/rayobject_blibvh.cpp b/source/blender/render/intern/raytrace/rayobject_blibvh.cpp index 165b62cfbe4..d0036fd8556 100644 --- a/source/blender/render/intern/raytrace/rayobject_blibvh.cpp +++ b/source/blender/render/intern/raytrace/rayobject_blibvh.cpp @@ -102,8 +102,7 @@ static void bvh_callback(void *userdata, int index, const BVHTreeRay *UNUSED(ray Isect *isec = data->isec; RayObject *face = data->leafs[index]; - if (RE_rayobject_intersect(face,isec)) - { + if (RE_rayobject_intersect(face, isec)) { hit->index = index; if (isec->mode == RE_RAY_SHADOW) diff --git a/source/blender/render/intern/raytrace/rayobject_hint.h b/source/blender/render/intern/raytrace/rayobject_hint.h index 3689aa8ac17..37d9edb035d 100644 --- a/source/blender/render/intern/raytrace/rayobject_hint.h +++ b/source/blender/render/intern/raytrace/rayobject_hint.h @@ -44,7 +44,7 @@ struct HintBB inline int hint_test_bb(HintBB *obj, float *Nmin, float *Nmax) { - if(bb_fits_inside( Nmin, Nmax, obj->bb, obj->bb+3 ) ) + if (bb_fits_inside( Nmin, Nmax, obj->bb, obj->bb+3 ) ) return HINT_RECURSE; else return HINT_ACCEPT; diff --git a/source/blender/render/intern/raytrace/rayobject_instance.cpp b/source/blender/render/intern/raytrace/rayobject_instance.cpp index 2e803ce0fd3..ce88bac1587 100644 --- a/source/blender/render/intern/raytrace/rayobject_instance.cpp +++ b/source/blender/render/intern/raytrace/rayobject_instance.cpp @@ -99,8 +99,7 @@ static int RE_rayobject_instance_intersect(RayObject *o, Isect *isec) int changed = 0, i, res; // TODO - this is disabling self intersection on instances - if (isec->orig.ob == obj->ob && obj->ob) - { + if (isec->orig.ob == obj->ob && obj->ob) { changed = 1; isec->orig.ob = obj->target_ob; } @@ -117,8 +116,7 @@ static int RE_rayobject_instance_intersect(RayObject *o, Isect *isec) isec->dist *= normalize_v3(isec->dir); // update idot_axis and bv_index - for (i=0; i<3; i++) - { + for (i=0; i<3; i++) { isec->idot_axis[i] = 1.0f / isec->dir[i]; isec->bv_index[2*i] = isec->idot_axis[i] < 0.0 ? 1 : 0; @@ -132,12 +130,10 @@ static int RE_rayobject_instance_intersect(RayObject *o, Isect *isec) res = RE_rayobject_intersect(obj->target, isec); // map dist into original coordinate space - if (res == 0) - { + if (res == 0) { isec->dist = dist; } - else - { + else { // note we don't just multiply dist, because of possible // non-uniform scaling in the transform matrix float vec[3]; @@ -165,8 +161,7 @@ static int RE_rayobject_instance_intersect(RayObject *o, Isect *isec) isec->orig.ob = obj->ob; // restore bv_index - for (i=0; i<3; i++) - { + for (i=0; i<3; i++) { isec->bv_index[2*i] = isec->idot_axis[i] < 0.0 ? 1 : 0; isec->bv_index[2*i+1] = 1 - isec->bv_index[2*i]; @@ -202,8 +197,7 @@ static void RE_rayobject_instance_bb(RayObject *o, float *min, float *max) RE_rayobject_merge_bb(obj->target, m, M); //There must be a faster way than rotating all the 8 vertexs of the BB - for (i=0; i<8; i++) - { + for (i=0; i<8; i++) { for (j=0; j<3; j++) t[j] = i&(1<target2global, t); DO_MINMAX(t, min, max); diff --git a/source/blender/render/intern/raytrace/rayobject_octree.cpp b/source/blender/render/intern/raytrace/rayobject_octree.cpp index ea1d5c2573c..eef2fcc51c9 100644 --- a/source/blender/render/intern/raytrace/rayobject_octree.cpp +++ b/source/blender/render/intern/raytrace/rayobject_octree.cpp @@ -305,7 +305,7 @@ static void ocwrite(Octree *oc, RayFace *face, int quad, short x, short y, short no= (Node *)br->b[oc5]; if (no==NULL) br->b[oc5]= (Branch *)(no= addnode(oc)); - while(no->next) no= no->next; + while (no->next) no = no->next; a= 0; if (no->v[7]) { /* node full */ @@ -313,7 +313,7 @@ static void ocwrite(Octree *oc, RayFace *face, int quad, short x, short y, short no= no->next; } else { - while(no->v[a]!=NULL) a++; + while (no->v[a] != NULL) a++; } no->v[a]= (RayFace*) RE_rayobject_align(face); @@ -383,7 +383,7 @@ static void d2dda(Octree *oc, short b1, short b2, short c1, short c2, char *ocfa x=ocx1; y=ocy1; labda= MIN2(labdax, labday); - while(TRUE) { + while (TRUE) { if (x<0 || y<0 || x>=oc->ocres || y>=oc->ocres); else ocface[oc->ocres*x+y]= 1; @@ -421,7 +421,7 @@ static void filltriangle(Octree *oc, short c1, short c2, char *ocface, short *oc for (y=ocmin[c2];y<=ocmax[c2];y++) { if (ocface[a+y]) { y++; - while(ocface[a+y] && y!=ocmax[c2]) y++; + while (ocface[a+y] && y!=ocmax[c2]) y++; for (y1=ocmax[c2];y1>y;y1--) { if (ocface[a+y1]) { for (y2=y;y2<=y1;y2++) ocface[a+y2]=1; @@ -449,7 +449,7 @@ static void RE_rayobject_octree_free(RayObject *tree) if (oc->adrbranch) { int a= 0; - while(oc->adrbranch[a]) { + while (oc->adrbranch[a]) { MEM_freeN(oc->adrbranch[a]); oc->adrbranch[a]= NULL; a++; @@ -461,7 +461,7 @@ static void RE_rayobject_octree_free(RayObject *tree) if (oc->adrnode) { int a= 0; - while(oc->adrnode[a]) { + while (oc->adrnode[a]) { MEM_freeN(oc->adrnode[a]); oc->adrnode[a]= NULL; a++; @@ -658,8 +658,7 @@ static void RE_rayobject_octree_done(RayObject *tree) oc->ocsize= sqrt(t00*t00+t01*t01+t02*t02); /* global, max size octree */ - for (c=0; cro_nodes_used; c++) - { + for (c=0; cro_nodes_used; c++) { octree_fill_rayface(oc, oc->ro_nodes[c]); } @@ -683,42 +682,41 @@ static void RE_rayobject_octree_bb(RayObject *tree, float *min, float *max) /* check all faces in this node */ static int testnode(Octree *UNUSED(oc), Isect *is, Node *no, OcVal ocval) { - short nr=0; + short nr = 0; /* return on any first hit */ - if (is->mode==RE_RAY_SHADOW) { + if (is->mode == RE_RAY_SHADOW) { - for (; no; no = no->next) - for (nr=0; nr<8; nr++) - { - RayFace *face = no->v[nr]; - OcVal *ov = no->ov+nr; - - if (!face) break; - - if ( (ov->ocx & ocval.ocx) && (ov->ocy & ocval.ocy) && (ov->ocz & ocval.ocz) ) - { - if ( RE_rayobject_intersect( RE_rayobject_unalignRayFace(face),is) ) - return 1; + for ( ; no; no = no->next) { + for (nr = 0; nr < 8; nr++) { + RayFace *face = no->v[nr]; + OcVal *ov = no->ov + nr; + + if (!face) break; + + if ( (ov->ocx & ocval.ocx) && (ov->ocy & ocval.ocy) && (ov->ocz & ocval.ocz) ) { + if ( RE_rayobject_intersect( RE_rayobject_unalignRayFace(face),is) ) + return 1; + } } } } - else - { /* else mirror or glass or shadowtra, return closest face */ + else { + /* else mirror or glass or shadowtra, return closest face */ int found= 0; - for (; no; no = no->next) - for (nr=0; nr<8; nr++) - { - RayFace *face = no->v[nr]; - OcVal *ov = no->ov+nr; - - if (!face) break; - - if ( (ov->ocx & ocval.ocx) && (ov->ocy & ocval.ocy) && (ov->ocz & ocval.ocz) ) - { - if ( RE_rayobject_intersect( RE_rayobject_unalignRayFace(face),is) ) - found= 1; + for ( ; no; no = no->next) { + for (nr = 0; nr < 8; nr++) { + RayFace *face = no->v[nr]; + OcVal *ov = no->ov + nr; + + if (!face) break; + + if ( (ov->ocx & ocval.ocx) && (ov->ocy & ocval.ocy) && (ov->ocz & ocval.ocz) ) { + if ( RE_rayobject_intersect( RE_rayobject_unalignRayFace(face),is) ) { + found = 1; + } + } } } @@ -1003,7 +1001,7 @@ static int RE_rayobject_octree_intersect(RayObject *tree, Isect *is) /* this loop has been constructed to make sure the first and last node of ray * are always included, even when ddalabda==1.0f or larger */ - while(TRUE) { + while (TRUE) { no= ocread(oc, xo, yo, zo); if (no) { diff --git a/source/blender/render/intern/raytrace/rayobject_qbvh.cpp b/source/blender/render/intern/raytrace/rayobject_qbvh.cpp index 2edf1593e99..2d0abba9a75 100644 --- a/source/blender/render/intern/raytrace/rayobject_qbvh.cpp +++ b/source/blender/render/intern/raytrace/rayobject_qbvh.cpp @@ -71,8 +71,7 @@ void bvh_done(QBVHTree *obj) //TODO do this in 1 pass (half memory usage during building) VBVHNode *root = BuildBinaryVBVH(arena1, &obj->rayobj.control).transform(obj->builder); - if (RE_rayobjectcontrol_test_break(&obj->rayobj.control)) - { + if (RE_rayobjectcontrol_test_break(&obj->rayobj.control)) { BLI_memarena_free(arena1); BLI_memarena_free(arena2); return; diff --git a/source/blender/render/intern/raytrace/rayobject_rtbuild.cpp b/source/blender/render/intern/raytrace/rayobject_rtbuild.cpp index 54901db8bdd..ad74159fd3b 100644 --- a/source/blender/render/intern/raytrace/rayobject_rtbuild.cpp +++ b/source/blender/render/intern/raytrace/rayobject_rtbuild.cpp @@ -74,8 +74,7 @@ RTBuilder* rtbuild_create(int size) builder->primitives.begin = builder->primitives.end = memblock; builder->primitives.maxsize = size; - for (int i=0; i<3; i++) - { + for (int i=0; i<3; i++) { builder->sorted_begin[i] = (RTBuilder::Object**)MEM_mallocN( sizeof(RTBuilder::Object*)*size,"RTBuilder.sorted_objects"); builder->sorted_end[i] = builder->sorted_begin[i]; } @@ -124,8 +123,7 @@ void rtbuild_add(RTBuilder *b, RayObject *o) b->primitives.end->obj = o; b->primitives.end->cost = RE_rayobject_cost(o); - for (int i=0; i<3; i++) - { + for (int i=0; i<3; i++) { *(b->sorted_end[i]) = b->primitives.end; b->sorted_end[i]++; } @@ -158,8 +156,7 @@ static void object_sort(Item *begin, Item *end, int axis) void rtbuild_done(RTBuilder *b, RayObjectControl* ctrl) { for (int i=0; i<3; i++) - if (b->sorted_begin[i]) - { + if (b->sorted_begin[i]) { if (RE_rayobjectcontrol_test_break(ctrl)) break; object_sort( b->sorted_begin[i], b->sorted_end[i], i ); } @@ -175,13 +172,11 @@ RTBuilder* rtbuild_get_child(RTBuilder *b, int child, RTBuilder *tmp) rtbuild_init( tmp ); for (int i=0; i<3; i++) - if (b->sorted_begin[i]) - { + if (b->sorted_begin[i]) { tmp->sorted_begin[i] = b->sorted_begin[i] + b->child_offset[child ]; tmp->sorted_end [i] = b->sorted_begin[i] + b->child_offset[child+1]; } - else - { + else { tmp->sorted_begin[i] = 0; tmp->sorted_end [i] = 0; } @@ -191,8 +186,7 @@ RTBuilder* rtbuild_get_child(RTBuilder *b, int child, RTBuilder *tmp) void rtbuild_calc_bb(RTBuilder *b) { - if (b->bb[0] == 1.0e30f) - { + if (b->bb[0] == 1.0e30f) { for (RTBuilder::Object **index = b->sorted_begin[0]; index != b->sorted_end[0]; index++) RE_rayobject_merge_bb( (*index)->obj , b->bb, b->bb+3); } @@ -337,30 +331,25 @@ int rtbuild_heuristic_object_split(RTBuilder *b, int nchilds) assert(size > 1); int baxis = -1, boffset = 0; - if (size > nchilds) - { + if (size > nchilds) { float bcost = FLT_MAX; baxis = -1, boffset = size/2; SweepCost *sweep = (SweepCost*)MEM_mallocN( sizeof(SweepCost)*size, "RTBuilder.HeuristicSweep" ); - for (int axis=0; axis<3; axis++) - { + for (int axis=0; axis<3; axis++) { SweepCost sweep_left; RTBuilder::Object **obj = b->sorted_begin[axis]; // float right_cost = 0; - for (int i=size-1; i>=0; i--) - { - if (i == size-1) - { + for (int i=size-1; i>=0; i--) { + if (i == size-1) { copy_v3_v3(sweep[i].bb, obj[i]->bb); copy_v3_v3(sweep[i].bb+3, obj[i]->bb+3); sweep[i].cost = obj[i]->cost; } - else - { + else { sweep[i].bb[0] = MIN2(obj[i]->bb[0], sweep[i+1].bb[0]); sweep[i].bb[1] = MIN2(obj[i]->bb[1], sweep[i+1].bb[1]); sweep[i].bb[2] = MIN2(obj[i]->bb[2], sweep[i+1].bb[2]); @@ -382,8 +371,7 @@ int rtbuild_heuristic_object_split(RTBuilder *b, int nchilds) // right_cost -= obj[0]->cost; if (right_cost < 0) right_cost = 0; - for (int i=1; i bcost) break; //No way we can find a better heuristic in this axis assert(hcost >= 0); - if ( hcost < bcost - || (hcost == bcost && axis < baxis)) //this makes sure the tree built is the same whatever is the order of the sorting axis - { + // this makes sure the tree built is the same whatever is the order of the sorting axis + if ( hcost < bcost || (hcost == bcost && axis < baxis)) { bcost = hcost; baxis = axis; boffset = i; @@ -423,13 +410,11 @@ int rtbuild_heuristic_object_split(RTBuilder *b, int nchilds) MEM_freeN(sweep); } - else if (size == 2) - { + else if (size == 2) { baxis = 0; boffset = 1; } - else if (size == 1) - { + else if (size == 1) { b->child_offset[0] = 0; b->child_offset[1] = 1; return 1; @@ -500,15 +485,13 @@ int bb_largest_axis(float *min, float *max) sub[0] = max[0]-min[0]; sub[1] = max[1]-min[1]; sub[2] = max[2]-min[2]; - if (sub[0] > sub[1]) - { + if (sub[0] > sub[1]) { if (sub[0] > sub[2]) return 0; else return 2; } - else - { + else { if (sub[1] > sub[2]) return 1; else diff --git a/source/blender/render/intern/raytrace/rayobject_svbvh.cpp b/source/blender/render/intern/raytrace/rayobject_svbvh.cpp index 4c2099eb1e3..cbec02ab798 100644 --- a/source/blender/render/intern/raytrace/rayobject_svbvh.cpp +++ b/source/blender/render/intern/raytrace/rayobject_svbvh.cpp @@ -79,12 +79,10 @@ void bvh_done(SVBVHTree *obj) BLI_memarena_use_align(arena2, 16); //Build and optimize the tree - if (0) - { + if (0) { VBVHNode *root = BuildBinaryVBVH(arena1, &obj->rayobj.control).transform(obj->builder); - if (RE_rayobjectcontrol_test_break(&obj->rayobj.control)) - { + if (RE_rayobjectcontrol_test_break(&obj->rayobj.control)) { BLI_memarena_free(arena1); BLI_memarena_free(arena2); return; @@ -100,14 +98,12 @@ void bvh_done(SVBVHTree *obj) obj->root = Reorganize_SVBVH(arena2).transform(root); } - else - { + else { //Finds the optimal packing of this tree using a given cost model //TODO this uses quite a lot of memory, find ways to reduce memory usage during building OVBVHNode *root = BuildBinaryVBVH(arena1,&obj->rayobj.control).transform(obj->builder); - if (RE_rayobjectcontrol_test_break(&obj->rayobj.control)) - { + if (RE_rayobjectcontrol_test_break(&obj->rayobj.control)) { BLI_memarena_free(arena1); BLI_memarena_free(arena2); return; diff --git a/source/blender/render/intern/raytrace/rayobject_vbvh.cpp b/source/blender/render/intern/raytrace/rayobject_vbvh.cpp index e82623f1da9..26a99794362 100644 --- a/source/blender/render/intern/raytrace/rayobject_vbvh.cpp +++ b/source/blender/render/intern/raytrace/rayobject_vbvh.cpp @@ -87,11 +87,9 @@ void bvh_done(VBVHTree *obj) BLI_memarena_use_malloc(arena1); //Build and optimize the tree - if (1) - { + if (1) { VBVHNode *root = BuildBinaryVBVH(arena1,&obj->rayobj.control).transform(obj->builder); - if (RE_rayobjectcontrol_test_break(&obj->rayobj.control)) - { + if (RE_rayobjectcontrol_test_break(&obj->rayobj.control)) { BLI_memarena_free(arena1); return; } @@ -108,8 +106,7 @@ void bvh_done(VBVHTree *obj) else obj->root = NULL; } - else - { + else { /* TODO MemArena *arena2 = BLI_memarena_new(BLI_MEMARENA_STD_BUFSIZE, "vbvh arena2"); @@ -159,8 +156,7 @@ void bvh_hint_bb(Tree *tree, LCTSHint *hint, float *UNUSED(min), float *UNUSED(m void bfree(VBVHTree *tree) { - if (tot_pushup + tot_pushdown + tot_hints + tot_moves) - { + if (tot_pushup + tot_pushdown + tot_hints + tot_moves) { if (G.debug & G_DEBUG) { printf("tot pushups: %d\n", tot_pushup); printf("tot pushdowns: %d\n", tot_pushdown); diff --git a/source/blender/render/intern/raytrace/reorganize.h b/source/blender/render/intern/raytrace/reorganize.h index 68b2b22ecdd..1930e5bb32b 100644 --- a/source/blender/render/intern/raytrace/reorganize.h +++ b/source/blender/render/intern/raytrace/reorganize.h @@ -66,17 +66,15 @@ void reorganize_find_fittest_parent(Node *tree, Node *node, std::pair q; q.push(tree); - while(!q.empty()) - { + while (!q.empty()) { Node *parent = q.front(); q.pop(); - if(parent == node) continue; - if(node_fits_inside(node, parent) && RE_rayobject_isAligned(parent->child) ) - { + if (parent == node) continue; + if (node_fits_inside(node, parent) && RE_rayobject_isAligned(parent->child) ) { float pcost = bb_area(parent->bb, parent->bb+3); cost = std::min( cost, std::make_pair(pcost,parent) ); - for(Node *child = parent->child; child; child = child->sibling) + for (Node *child = parent->child; child; child = child->sibling) q.push(child); } } @@ -89,28 +87,23 @@ void reorganize(Node *root) std::queue q; q.push(root); - while(!q.empty()) - { + while (!q.empty()) { Node * node = q.front(); q.pop(); - if( RE_rayobject_isAligned(node->child) ) - { - for(Node **prev = &node->child; *prev; ) - { + if (RE_rayobject_isAligned(node->child)) { + for (Node **prev = &node->child; *prev; ) { assert( RE_rayobject_isAligned(*prev) ); q.push(*prev); std::pair best(FLT_MAX, root); reorganize_find_fittest_parent( root, *prev, best ); - if(best.second == node) - { + if (best.second == node) { //Already inside the fitnest BB prev = &(*prev)->sibling; } - else - { + else { Node *tmp = *prev; *prev = (*prev)->sibling; @@ -123,8 +116,7 @@ void reorganize(Node *root) } } - if(node != root) - { + if (node != root) { } } } @@ -137,29 +129,24 @@ void reorganize(Node *root) template void remove_useless(Node *node, Node **new_node) { - if( RE_rayobject_isAligned(node->child) ) - { + if ( RE_rayobject_isAligned(node->child) ) { - for(Node **prev = &node->child; *prev; ) - { + for (Node **prev = &node->child; *prev; ) { Node *next = (*prev)->sibling; remove_useless(*prev, prev); - if(*prev == NULL) + if (*prev == NULL) *prev = next; - else - { + else { (*prev)->sibling = next; prev = &((*prev)->sibling); } } } - if(node->child) - { - if(RE_rayobject_isAligned(node->child) && node->child->sibling == 0) + if (node->child) { + if (RE_rayobject_isAligned(node->child) && node->child->sibling == 0) *new_node = node->child; } - else if(node->child == NULL) - { + else if (node->child == NULL) { *new_node = NULL; } } @@ -171,18 +158,16 @@ void remove_useless(Node *node, Node **new_node) template void pushup(Node *parent) { - if(is_leaf(parent)) return; + if (is_leaf(parent)) return; float p_area = bb_area(parent->bb, parent->bb+3); Node **prev = &parent->child; - for(Node *child = parent->child; RE_rayobject_isAligned(child) && child; ) - { + for (Node *child = parent->child; RE_rayobject_isAligned(child) && child; ) { const float c_area = bb_area(child->bb, child->bb + 3); const int nchilds = count_childs(child); float original_cost = ((p_area != 0.0f)? (c_area / p_area)*nchilds: 1.0f) + 1; float flatten_cost = nchilds; - if(flatten_cost < original_cost && nchilds >= 2) - { + if (flatten_cost < original_cost && nchilds >= 2) { append_sibling(child, child->child); child = child->sibling; *prev = child; @@ -192,15 +177,14 @@ void pushup(Node *parent) // child = *prev; tot_pushup++; } - else - { + else { *prev = child; prev = &(*prev)->sibling; child = *prev; } } - for(Node *child = parent->child; RE_rayobject_isAligned(child) && child; child = child->sibling) + for (Node *child = parent->child; RE_rayobject_isAligned(child) && child; child = child->sibling) pushup(child); } @@ -210,30 +194,27 @@ void pushup(Node *parent) template void pushup_simd(Node *parent) { - if(is_leaf(parent)) return; + if (is_leaf(parent)) return; int n = count_childs(parent); Node **prev = &parent->child; - for(Node *child = parent->child; RE_rayobject_isAligned(child) && child; ) - { + for (Node *child = parent->child; RE_rayobject_isAligned(child) && child; ) { int cn = count_childs(child); - if(cn-1 <= (SSize - (n%SSize) ) % SSize && RE_rayobject_isAligned(child->child) ) - { + if (cn-1 <= (SSize - (n%SSize) ) % SSize && RE_rayobject_isAligned(child->child) ) { n += (cn - 1); append_sibling(child, child->child); child = child->sibling; *prev = child; } - else - { + else { *prev = child; prev = &(*prev)->sibling; child = *prev; } } - for(Node *child = parent->child; RE_rayobject_isAligned(child) && child; child = child->sibling) + for (Node *child = parent->child; RE_rayobject_isAligned(child) && child; child = child->sibling) pushup_simd(child); } @@ -248,19 +229,17 @@ void pushdown(Node *parent) Node **s_child = &parent->child; Node * child = parent->child; - while(child && RE_rayobject_isAligned(child)) - { + while (child && RE_rayobject_isAligned(child)) { Node *next = child->sibling; Node **next_s_child = &child->sibling; //assert(bb_fits_inside(parent->bb, parent->bb+3, child->bb, child->bb+3)); - for(Node *i = parent->child; RE_rayobject_isAligned(i) && i; i = i->sibling) - if(child != i && bb_fits_inside(i->bb, i->bb+3, child->bb, child->bb+3) && RE_rayobject_isAligned(i->child)) - { + for (Node *i = parent->child; RE_rayobject_isAligned(i) && i; i = i->sibling) + if (child != i && bb_fits_inside(i->bb, i->bb+3, child->bb, child->bb+3) && RE_rayobject_isAligned(i->child)) { // todo optimize (should the one with the smallest area?) // float ia = bb_area(i->bb, i->bb+3) -// if(child->i) +// if (child->i) *s_child = child->sibling; child->sibling = i->child; i->child = child; @@ -286,18 +265,17 @@ void pushdown(Node *parent) template float bvh_refit(Node *node) { - if(is_leaf(node)) return 0; - if(is_leaf(node->child)) return 0; + if (is_leaf(node)) return 0; + if (is_leaf(node->child)) return 0; float total = 0; - for(Node *child = node->child; child; child = child->sibling) + for (Node *child = node->child; child; child = child->sibling) total += bvh_refit(child); float old_area = bb_area(node->bb, node->bb+3); INIT_MINMAX(node->bb, node->bb+3); - for(Node *child = node->child; child; child = child->sibling) - { + for (Node *child = node->child; child; child = child->sibling) { DO_MIN(child->bb, node->bb); DO_MAX(child->bb+3, node->bb+3); } @@ -347,32 +325,27 @@ struct OVBVHNode int best_cutsize; void set_cut(int cutsize, OVBVHNode ***cut) { - if(cutsize == 1) - { + if (cutsize == 1) { **cut = this; *cut = &(**cut)->sibling; } - else - { - if(cutsize > MAX_CUT_SIZE) - { - for(OVBVHNode *child = this->child; child && RE_rayobject_isAligned(child); child = child->sibling) - { + else { + if (cutsize > MAX_CUT_SIZE) { + for (OVBVHNode *child = this->child; child && RE_rayobject_isAligned(child); child = child->sibling) { child->set_cut( 1, cut ); cutsize--; } assert(cutsize == 0); } else - for(OVBVHNode *child = this->child; child && RE_rayobject_isAligned(child); child = child->sibling) + for (OVBVHNode *child = this->child; child && RE_rayobject_isAligned(child); child = child->sibling) child->set_cut( child->get_cut_size( cutsize ), cut ); } } void optimize() { - if(RE_rayobject_isAligned(this->child)) - { + if (RE_rayobject_isAligned(this->child)) { //Calc new childs { OVBVHNode **cut = &(this->child); @@ -381,7 +354,7 @@ struct OVBVHNode } //Optimize new childs - for(OVBVHNode *child = this->child; child && RE_rayobject_isAligned(child); child = child->sibling) + for (OVBVHNode *child = this->child; child && RE_rayobject_isAligned(child); child = child->sibling) child->optimize(); } } @@ -415,8 +388,7 @@ struct VBVH_optimalPackSIMD //Fetch childs and needed data { float parent_area = bb_area(node->bb, node->bb+3); - for(Node *child = node->child; child && RE_rayobject_isAligned(child); child = child->sibling) - { + for (Node *child = node->child; child && RE_rayobject_isAligned(child); child = child->sibling) { this->child[nchilds] = child; this->child_hit_prob[nchilds] = (parent_area != 0.0f)? bb_area(child->bb, child->bb+3) / parent_area: 1.0f; nchilds++; @@ -427,36 +399,35 @@ struct VBVH_optimalPackSIMD //Build DP table to find minimum cost to represent this node with a given cutsize - int bt [MAX_OPTIMIZE_CHILDS+1][MAX_CUT_SIZE+1]; //backtrace table - float cost[MAX_OPTIMIZE_CHILDS+1][MAX_CUT_SIZE+1]; //cost table (can be reduced to float[2][MAX_CUT_COST]) + int bt [MAX_OPTIMIZE_CHILDS + 1][MAX_CUT_SIZE + 1]; //backtrace table + float cost[MAX_OPTIMIZE_CHILDS + 1][MAX_CUT_SIZE + 1]; //cost table (can be reduced to float[2][MAX_CUT_COST]) - for(int i=0; i<=nchilds; i++) - for(int j=0; j<=MAX_CUT_SIZE; j++) - cost[i][j] = INFINITY; + for (int i = 0; i <= nchilds; i++) { + for (int j = 0; j <= MAX_CUT_SIZE; j++) { + cost[i][j] = INFINITY; + } + } cost[0][0] = 0; - for(int i=1; i<=nchilds; i++) - for(int size=i-1; size/*+(nchilds-i)*/<=MAX_CUT_SIZE; size++) - for(int cut=1; cut+size/*+(nchilds-i)*/<=MAX_CUT_SIZE; cut++) - { - float new_cost = cost[i-1][size] + child_hit_prob[i-1]*child[i-1]->get_cost(cut); - if(new_cost < cost[i][size+cut]) - { - cost[i][size+cut] = new_cost; - bt[i][size+cut] = cut; + for (int i = 1; i<=nchilds; i++) { + for (int size = i - 1; size/*+(nchilds-i)*/<=MAX_CUT_SIZE; size++) { + for (int cut = 1; cut+size/*+(nchilds-i)*/<=MAX_CUT_SIZE; cut++) { + float new_cost = cost[i - 1][size] + child_hit_prob[i - 1] * child[i - 1]->get_cost(cut); + if (new_cost < cost[i][size+cut]) { + cost[i][size+cut] = new_cost; + bt[i][size+cut] = cut; + } + } } } //Save the ways to archieve the minimum cost with a given cutsize - for(int i = nchilds; i <= MAX_CUT_SIZE; i++) - { + for (int i = nchilds; i <= MAX_CUT_SIZE; i++) { node->cut_cost[i-1] = cost[nchilds][i]; - if(cost[nchilds][i] < INFINITY) - { + if (cost[nchilds][i] < INFINITY) { int current_size = i; - for(int j=nchilds; j>0; j--) - { + for (int j=nchilds; j>0; j--) { child[j-1]->cut_size[i-1] = bt[j][current_size]; current_size -= bt[j][current_size]; } @@ -468,26 +439,22 @@ struct VBVH_optimalPackSIMD void calc_costs(Node *node) { - if( RE_rayobject_isAligned(node->child) ) - { + if ( RE_rayobject_isAligned(node->child) ) { int nchilds = 0; - for(Node *child = node->child; child && RE_rayobject_isAligned(child); child = child->sibling) - { + for (Node *child = node->child; child && RE_rayobject_isAligned(child); child = child->sibling) { calc_costs(child); nchilds++; } - for(int i=0; icut_cost[i] = INFINITY; //We are not allowed to look on nodes with with so many childs - if(nchilds > MAX_CUT_SIZE) - { + if (nchilds > MAX_CUT_SIZE) { float cost = 0; float parent_area = bb_area(node->bb, node->bb+3); - for(Node *child = node->child; child && RE_rayobject_isAligned(child); child = child->sibling) - { + for (Node *child = node->child; child && RE_rayobject_isAligned(child); child = child->sibling) { cost += ((parent_area != 0.0f)? ( bb_area(child->bb, child->bb+3) / parent_area ): 1.0f) * child->get_cost(1); } @@ -495,16 +462,13 @@ struct VBVH_optimalPackSIMD node->cut_cost[0] = cost; node->best_cutsize = nchilds; } - else - { + else { calc_best calc(node); //calc expected cost if we optimaly pack this node - for(int cutsize=nchilds; cutsize<=MAX_CUT_SIZE; cutsize++) - { + for (int cutsize=nchilds; cutsize<=MAX_CUT_SIZE; cutsize++) { float m = node->get_cost(cutsize) + testcost(cutsize); - if(m < node->cut_cost[0]) - { + if (m < node->cut_cost[0]) { node->cut_cost[0] = m; node->best_cutsize = cutsize; } @@ -512,24 +476,22 @@ struct VBVH_optimalPackSIMD } assert(node->cut_cost[0] != INFINITY); } - else - { + else { node->cut_cost[0] = 1.0f; - for(int i=1; icut_cost[i] = INFINITY; } } Node *transform(Node *node) { - if(RE_rayobject_isAligned(node->child)) - { + if (RE_rayobject_isAligned(node->child)) { static int num = 0; bool first = false; - if(num == 0) { num++; first = true; } + if (num == 0) { num++; first = true; } calc_costs(node); - if((G.debug & G_DEBUG) && first) printf("expected cost = %f (%d)\n", node->cut_cost[0], node->best_cutsize ); + if ((G.debug & G_DEBUG) && first) printf("expected cost = %f (%d)\n", node->cut_cost[0], node->best_cutsize ); node->optimize(); } return node; diff --git a/source/blender/render/intern/raytrace/svbvh.h b/source/blender/render/intern/raytrace/svbvh.h index e0e96781f36..a4044db8208 100644 --- a/source/blender/render/intern/raytrace/svbvh.h +++ b/source/blender/render/intern/raytrace/svbvh.h @@ -94,9 +94,9 @@ static int svbvh_bb_intersect_test(const Isect *isec, const float *_bb) RE_RC_COUNT(isec->raycounter->bb.test); - if(t1x > t2y || t2x < t1y || t1x > t2z || t2x < t1z || t1y > t2z || t2y < t1z) return 0; - if(t2x < 0.0 || t2y < 0.0 || t2z < 0.0) return 0; - if(t1x > isec->dist || t1y > isec->dist || t1z > isec->dist) return 0; + if (t1x > t2y || t2x < t1y || t1x > t2z || t2x < t1z || t1y > t2z || t2y < t1z) return 0; + if (t2x < 0.0 || t2y < 0.0 || t2z < 0.0) return 0; + if (t1x > isec->dist || t1y > isec->dist || t1z > isec->dist) return 0; RE_RC_COUNT(isec->raycounter->bb.hit); @@ -116,40 +116,39 @@ static int svbvh_node_stack_raycast(SVBVHNode *root, Isect *isec) stack[stack_pos++] = root; - while(stack_pos) - { + while (stack_pos) { node = stack[--stack_pos]; - if(!svbvh_node_is_leaf(node)) - { + if (!svbvh_node_is_leaf(node)) { int nchilds= node->nchilds; - if(nchilds == 4) { + if (nchilds == 4) { float *child_bb= node->child_bb; int res = svbvh_bb_intersect_test_simd4(isec, ((__m128*) (child_bb))); SVBVHNode **child= node->child; RE_RC_COUNT(isec->raycounter->simd_bb.test); - if(res & 1) { stack[stack_pos++] = child[0]; RE_RC_COUNT(isec->raycounter->simd_bb.hit); } - if(res & 2) { stack[stack_pos++] = child[1]; RE_RC_COUNT(isec->raycounter->simd_bb.hit); } - if(res & 4) { stack[stack_pos++] = child[2]; RE_RC_COUNT(isec->raycounter->simd_bb.hit); } - if(res & 8) { stack[stack_pos++] = child[3]; RE_RC_COUNT(isec->raycounter->simd_bb.hit); } + if (res & 1) { stack[stack_pos++] = child[0]; RE_RC_COUNT(isec->raycounter->simd_bb.hit); } + if (res & 2) { stack[stack_pos++] = child[1]; RE_RC_COUNT(isec->raycounter->simd_bb.hit); } + if (res & 4) { stack[stack_pos++] = child[2]; RE_RC_COUNT(isec->raycounter->simd_bb.hit); } + if (res & 8) { stack[stack_pos++] = child[3]; RE_RC_COUNT(isec->raycounter->simd_bb.hit); } } else { float *child_bb= node->child_bb; SVBVHNode **child= node->child; int i; - for(i=0; i inline void bvh_node_merge_bb(SVBVHNode *node, float *min, float *max) { - if(is_leaf(node)) - { + if (is_leaf(node)) { RE_rayobject_merge_bb((RayObject*)node, min, max); } - else - { + else { int i=0; - while(i+4 <= node->nchilds) - { + while (i+4 <= node->nchilds) { float *res = node->child_bb + 6*i; - for(int j=0; j<3; j++) - { + for (int j = 0; j < 3; j++) { min[j] = MIN2(min[j], res[4*j+0]); min[j] = MIN2(min[j], res[4*j+1]); min[j] = MIN2(min[j], res[4*j+2]); min[j] = MIN2(min[j], res[4*j+3]); } - for(int j=0; j<3; j++) - { + for (int j = 0; j < 3; j++) { max[j] = MAX2(max[j], res[4*(j+3)+0]); max[j] = MAX2(max[j], res[4*(j+3)+1]); max[j] = MAX2(max[j], res[4*(j+3)+2]); @@ -188,10 +182,9 @@ inline void bvh_node_merge_bb(SVBVHNode *node, float *min, float *max i += 4; } - for(; inchilds; i++) - { - DO_MIN(node->child_bb+6*i , min); - DO_MAX(node->child_bb+3+6*i, max); + for ( ; i < node->nchilds; i++) { + DO_MIN(node->child_bb + 6 * i, min); + DO_MAX(node->child_bb + 3 + 6 * i, max); } } } @@ -218,17 +211,19 @@ struct Reorganize_SVBVH childs_per_node = 0; useless_bb = 0; - for(int i=0; i<16; i++) + for (int i = 0; i < 16; i++) { nodes_with_childs[i] = 0; + } } ~Reorganize_SVBVH() { - if(G.debug & G_DEBUG) { + if (G.debug & G_DEBUG) { printf("%f childs per node\n", childs_per_node / nodes); printf("%d childs BB are useless\n", useless_bb); - for(int i=0; i<16; i++) + for (int i = 0; i < 16; i++) { printf("%i childs per node: %d/%d = %f\n", i, nodes_with_childs[i], nodes, nodes_with_childs[i]/float(nodes)); + } } } @@ -248,14 +243,12 @@ struct Reorganize_SVBVH void prepare_for_simd(SVBVHNode *node) { int i=0; - while(i+4 <= node->nchilds) - { + while (i + 4 <= node->nchilds) { float vec_tmp[4*6]; float *res = node->child_bb+6*i; std::copy(res, res+6*4, vec_tmp); - for(int j=0; j<6; j++) - { + for (int j=0; j<6; j++) { res[4*j+0] = vec_tmp[6*0+j]; res[4*j+1] = vec_tmp[6*1+j]; res[4*j+2] = vec_tmp[6*2+j]; @@ -274,26 +267,25 @@ struct Reorganize_SVBVH SVBVHNode *transform(OldNode *old) { - if(is_leaf(old)) + if (is_leaf(old)) return (SVBVHNode*)old; - if(is_leaf(old->child)) + if (is_leaf(old->child)) return (SVBVHNode*)old->child; int nchilds = count_childs(old); int alloc_childs = nchilds; - if(nchilds % 4 > 2) + if (nchilds % 4 > 2) alloc_childs = padup(nchilds, 4); SVBVHNode *node = create_node(alloc_childs); childs_per_node += nchilds; nodes++; - if(nchilds < 16) + if (nchilds < 16) nodes_with_childs[nchilds]++; useless_bb += alloc_childs-nchilds; - while(alloc_childs > nchilds) - { + while (alloc_childs > nchilds) { const static float def_bb[6] = { FLT_MAX, FLT_MAX, FLT_MAX, FLT_MIN, FLT_MIN, FLT_MIN }; alloc_childs--; node->child[alloc_childs] = NULL; @@ -301,20 +293,17 @@ struct Reorganize_SVBVH } int i=nchilds; - for(OldNode *o_child = old->child; o_child; o_child = o_child->sibling) - { + for (OldNode *o_child = old->child; o_child; o_child = o_child->sibling) { i--; node->child[i] = transform(o_child); - if(is_leaf(o_child)) - { + if (is_leaf(o_child)) { float bb[6]; INIT_MINMAX(bb, bb+3); RE_rayobject_merge_bb((RayObject*)o_child, bb, bb+3); copy_bb(node->child_bb+i*6, bb); break; } - else - { + else { copy_bb(node->child_bb+i*6, o_child->bb); } } diff --git a/source/blender/render/intern/raytrace/vbvh.h b/source/blender/render/intern/raytrace/vbvh.h index 1c84cd23510..f916dd412f7 100644 --- a/source/blender/render/intern/raytrace/vbvh.h +++ b/source/blender/render/intern/raytrace/vbvh.h @@ -57,17 +57,14 @@ inline static void bvh_node_push_childs(Node *node, Isect *UNUSED(isec), Node ** { Node *child = node->child; - if(is_leaf(child)) - { + if (is_leaf(child)) { stack[stack_pos++] = child; } - else - { - while(child) - { + else { + while (child) { /* Skips BB tests on primitives */ #if 0 - if(is_leaf(child->child)) { + if (is_leaf(child->child)) { stack[stack_pos++] = child->child; } else @@ -86,10 +83,9 @@ template int count_childs(Node *parent) { int n = 0; - for(Node *i = parent->child; i; i = i->sibling) - { + for (Node *i = parent->child; i; i = i->sibling) { n++; - if(is_leaf(i)) + if (is_leaf(i)) break; } @@ -100,7 +96,7 @@ int count_childs(Node *parent) template void append_sibling(Node *node, Node *sibling) { - while(node->sibling) + while (node->sibling) node = node->sibling; node->sibling = sibling; @@ -118,7 +114,7 @@ struct BuildBinaryVBVH void test_break() { - if(RE_rayobjectcontrol_test_break(control)) + if (RE_rayobjectcontrol_test_break(control)) throw "Stop"; } @@ -160,19 +156,17 @@ struct BuildBinaryVBVH { int size = rtbuild_size(builder); - if(size == 0) { + if (size == 0) { return NULL; } - else if(size == 1) - { + else if (size == 1) { Node *node = create_node(); INIT_MINMAX(node->bb, node->bb+3); rtbuild_merge_bb(builder, node->bb, node->bb+3); node->child = (Node *) rtbuild_get_primitive(builder, 0); return node; } - else - { + else { test_break(); Node *node = create_node(); @@ -183,8 +177,7 @@ struct BuildBinaryVBVH INIT_MINMAX(node->bb, node->bb+3); assert(nc == 2); - for(int i=0; isibling; } *child_ptr = 0; diff --git a/source/blender/render/intern/source/convertblender.c b/source/blender/render/intern/source/convertblender.c index 66ed0bd85a9..404901f2bb7 100644 --- a/source/blender/render/intern/source/convertblender.c +++ b/source/blender/render/intern/source/convertblender.c @@ -1472,7 +1472,7 @@ static void particle_normal_ren(short ren_as, ParticleSettings *part, Render *re if (ren_as != PART_DRAW_BB) mul_m4_v3(re->viewmat, loc); - switch(ren_as) { + switch (ren_as) { case PART_DRAW_LINE: sd->line = 1; sd->time = 0.0f; @@ -2630,8 +2630,7 @@ static int dl_surf_to_renderdata(ObjectRen *obr, DispList *dl, Material **matar, sizeu--; sizev--; /* dec size for face array */ if (dl->flag & DL_CYCL_V) { - for (v = 0; v < sizev; v++) - { + for (v = 0; v < sizev; v++) { /* optimize! :*/ vlr= RE_findOrAddVlak(obr, UVTOINDEX(sizeu - 1, v)); vlr1= RE_findOrAddVlak(obr, UVTOINDEX(0, v)); @@ -2643,8 +2642,7 @@ static int dl_surf_to_renderdata(ObjectRen *obr, DispList *dl, Material **matar, } if (dl->flag & DL_CYCL_U) { - for (u = 0; u < sizeu; u++) - { + for (u = 0; u < sizeu; u++) { /* optimize! :*/ vlr= RE_findOrAddVlak(obr, UVTOINDEX(u, 0)); vlr1= RE_findOrAddVlak(obr, UVTOINDEX(u, sizev-1)); @@ -3486,8 +3484,7 @@ static void init_render_mesh(Render *re, ObjectRen *obr, int timeoffset) if (need_nmap_tangent != 0) { const float * tangent = (const float *) layer->data; float * ftang = RE_vlakren_get_nmap_tangent(obr, vlr, 1); - for (vindex=0; vindexarea_sizey= lar->area_size; } else if (lar->type==LA_AREA) { - switch(lar->area_shape) { + switch (lar->area_shape) { case LA_AREA_SQUARE: lar->ray_totsamp= lar->ray_samp*lar->ray_samp; lar->ray_sampy= lar->ray_samp; diff --git a/source/blender/render/intern/source/initrender.c b/source/blender/render/intern/source/initrender.c index f7f592c9407..3e82bec7e52 100644 --- a/source/blender/render/intern/source/initrender.c +++ b/source/blender/render/intern/source/initrender.c @@ -167,7 +167,7 @@ float RE_filter_value(int type, float x) x= ABS(x); - switch(type) { + switch (type) { case R_FILTER_BOX: if (x>1.0f) return 0.0f; return 1.0f; @@ -208,7 +208,7 @@ static float calc_weight(Render *re, float *weight, int i, int j) weight[a]= 0.0; /* Weighting choices */ - switch(re->r.filtertype) { + switch (re->r.filtertype) { case R_FILTER_BOX: if (i==0 && j==0) weight[a]= 1.0; break; diff --git a/source/blender/render/intern/source/pointdensity.c b/source/blender/render/intern/source/pointdensity.c index 5d4f9db9a02..54474891810 100644 --- a/source/blender/render/intern/source/pointdensity.c +++ b/source/blender/render/intern/source/pointdensity.c @@ -221,7 +221,7 @@ static void pointdensity_cache_object(Render *re, PointDensity *pd, Object *ob) copy_v3_v3(co, mvert->co); - switch(pd->ob_cache_space) { + switch (pd->ob_cache_space) { case TEX_PD_OBJECTSPACE: break; case TEX_PD_OBJECTLOC: diff --git a/source/blender/render/intern/source/rayshade.c b/source/blender/render/intern/source/rayshade.c index 0c735c18c57..bb08911a1eb 100644 --- a/source/blender/render/intern/source/rayshade.c +++ b/source/blender/render/intern/source/rayshade.c @@ -87,8 +87,7 @@ static int test_break(void *data) static void RE_rayobject_config_control(RayObject *r, Render *re) { - if (RE_rayobject_isRayAPI(r)) - { + if (RE_rayobject_isRayAPI(r)) { r = RE_rayobject_align( r ); r->control.data = re; r->control.test_break = test_break; @@ -99,8 +98,7 @@ static RayObject* RE_rayobject_create(Render *re, int type, int size) { RayObject * res = NULL; - if (type == R_RAYSTRUCTURE_AUTO) - { + if (type == R_RAYSTRUCTURE_AUTO) { //TODO //if (detect_simd()) #ifdef __SSE__ @@ -111,8 +109,7 @@ static RayObject* RE_rayobject_create(Render *re, int type, int size) } #ifndef __SSE__ - if (type == R_RAYSTRUCTURE_SIMD_SVBVH || type == R_RAYSTRUCTURE_SIMD_QBVH) - { + if (type == R_RAYSTRUCTURE_SIMD_SVBVH || type == R_RAYSTRUCTURE_SIMD_QBVH) { puts("Warning: Using VBVH (SSE was disabled at compile time)"); type = R_RAYSTRUCTURE_VBVH; } @@ -148,37 +145,30 @@ void freeraytree(Render *re) { ObjectInstanceRen *obi; - if (re->raytree) - { + if (re->raytree) { RE_rayobject_free(re->raytree); re->raytree = NULL; } - if (re->rayfaces) - { + if (re->rayfaces) { MEM_freeN(re->rayfaces); re->rayfaces = NULL; } - if (re->rayprimitives) - { + if (re->rayprimitives) { MEM_freeN(re->rayprimitives); re->rayprimitives = NULL; } - for (obi=re->instancetable.first; obi; obi=obi->next) - { + for (obi=re->instancetable.first; obi; obi=obi->next) { ObjectRen *obr = obi->obr; - if (obr->raytree) - { + if (obr->raytree) { RE_rayobject_free(obr->raytree); obr->raytree = NULL; } - if (obr->rayfaces) - { + if (obr->rayfaces) { MEM_freeN(obr->rayfaces); obr->rayfaces = NULL; } - if (obi->raytree) - { + if (obi->raytree) { RE_rayobject_free(obi->raytree); obi->raytree = NULL; } @@ -232,8 +222,7 @@ RayObject* makeraytree_object(Render *re, ObjectInstanceRen *obi) // update render stats ObjectRen *obr = obi->obr; - if (obr->raytree == NULL) - { + if (obr->raytree == NULL) { RayObject *raytree; RayFace *face = NULL; VlakPrimitive *vlakprimitive = NULL; @@ -241,8 +230,7 @@ RayObject* makeraytree_object(Render *re, ObjectInstanceRen *obi) //Count faces int faces = 0; - for (v=0;vtotvlak;v++) - { + for (v=0;vtotvlak;v++) { VlakRen *vlr = obr->vlaknodes[v>>8].vlak + (v&255); if (is_raytraceable_vlr(re, vlr)) faces++; @@ -260,11 +248,9 @@ RayObject* makeraytree_object(Render *re, ObjectInstanceRen *obi) obr->rayobi = obi; - for (v=0;vtotvlak;v++) - { + for (v=0;vtotvlak;v++) { VlakRen *vlr = obr->vlaknodes[v>>8].vlak + (v&255); - if (is_raytraceable_vlr(re, vlr)) - { + if (is_raytraceable_vlr(re, vlr)) { if ((re->r.raytrace_options & R_RAYTRACE_USE_LOCAL_COORDS)) { RE_rayobject_add( raytree, RE_vlakprimitive_from_vlak( vlakprimitive, obi, vlr ) ); vlakprimitive++; @@ -286,8 +272,7 @@ RayObject* makeraytree_object(Render *re, ObjectInstanceRen *obi) } if (obr->raytree) { - if ((obi->flag & R_TRANSFORMED) && obi->raytree == NULL) - { + if ((obi->flag & R_TRANSFORMED) && obi->raytree == NULL) { obi->transform_primitives = 0; obi->raytree = RE_rayobject_instance_create( obr->raytree, obi->mat, obi, obi->obr->rayobi ); } @@ -299,16 +284,13 @@ RayObject* makeraytree_object(Render *re, ObjectInstanceRen *obi) static int has_special_rayobject(Render *re, ObjectInstanceRen *obi) { - if ( (obi->flag & R_TRANSFORMED) && (re->r.raytrace_options & R_RAYTRACE_USE_INSTANCES) ) - { + if ( (obi->flag & R_TRANSFORMED) && (re->r.raytrace_options & R_RAYTRACE_USE_INSTANCES) ) { ObjectRen *obr = obi->obr; int v, faces = 0; - for (v=0;vtotvlak;v++) - { + for (v=0;vtotvlak;v++) { VlakRen *vlr = obr->vlaknodes[v>>8].vlak + (v&255); - if (is_raytraceable_vlr(re, vlr)) - { + if (is_raytraceable_vlr(re, vlr)) { faces++; if (faces > 4) return 1; @@ -329,8 +311,7 @@ static void makeraytree_single(Render *re) int faces = 0, obs = 0, special = 0; for (obi=re->instancetable.first; obi; obi=obi->next) - if (is_raytraceable(re, obi)) - { + if (is_raytraceable(re, obi)) { ObjectRen *obr = obi->obr; obs++; @@ -339,8 +320,7 @@ static void makeraytree_single(Render *re) } else { int v; - for (v=0;vtotvlak;v++) - { + for (v=0;vtotvlak;v++) { VlakRen *vlr = obr->vlaknodes[v>>8].vlak + (v&255); if (is_raytraceable_vlr(re, vlr)) faces++; @@ -348,8 +328,7 @@ static void makeraytree_single(Render *re) } } - if (faces + special == 0) - { + if (faces + special == 0) { re->raytree = RE_rayobject_empty_create(); return; } @@ -357,8 +336,7 @@ static void makeraytree_single(Render *re) //Create raytree raytree = re->raytree = RE_rayobject_create( re, re->r.raytrace_structure, faces+special ); - if ( (re->r.raytrace_options & R_RAYTRACE_USE_LOCAL_COORDS) ) - { + if ( (re->r.raytrace_options & R_RAYTRACE_USE_LOCAL_COORDS) ) { vlakprimitive = re->rayprimitives = (VlakPrimitive*)MEM_callocN(faces*sizeof(VlakPrimitive), "Raytrace vlak-primitives"); } else { @@ -366,8 +344,7 @@ static void makeraytree_single(Render *re) } for (obi=re->instancetable.first; obi; obi=obi->next) - if (is_raytraceable(re, obi)) - { + if (is_raytraceable(re, obi)) { if (test_break(re)) break; @@ -384,13 +361,11 @@ static void makeraytree_single(Render *re) int v; ObjectRen *obr = obi->obr; - if (obi->flag & R_TRANSFORMED) - { + if (obi->flag & R_TRANSFORMED) { obi->transform_primitives = 1; } - for (v=0;vtotvlak;v++) - { + for (v=0;vtotvlak;v++) { VlakRen *vlr = obr->vlaknodes[v>>8].vlak + (v&255); if (is_raytraceable_vlr(re, vlr)) { if ((re->r.raytrace_options & R_RAYTRACE_USE_LOCAL_COORDS)) { @@ -400,8 +375,7 @@ static void makeraytree_single(Render *re) } else { RE_rayface_from_vlak(face, obi, vlr); - if ((obi->flag & R_TRANSFORMED)) - { + if ((obi->flag & R_TRANSFORMED)) { mul_m4_v3(obi->mat, face->v1); mul_m4_v3(obi->mat, face->v2); mul_m4_v3(obi->mat, face->v3); @@ -417,8 +391,7 @@ static void makeraytree_single(Render *re) } } - if (!test_break(re)) - { + if (!test_break(re)) { re->i.infostr= "Raytree.. building"; re->stats_draw(re->sdh, &re->i); @@ -452,8 +425,7 @@ void makeraytree(Render *re) //This is ONLY needed to kept a bogus behavior of SUN and HEMI lights INIT_MINMAX(min, max); RE_rayobject_merge_bb( re->raytree, min, max ); - for (i=0; i<3; i++) - { + for (i=0; i<3; i++) { min[i] += 0.01f; max[i] += 0.01f; sub[i] = max[i]-min[i]; @@ -1006,12 +978,10 @@ static void halton_sample(double *ht_invprimes, double *ht_nums, double *v) // "Instant Radiosity", Keller A. unsigned int i; - for (i = 0; i < 2; i++) - { + for (i = 0; i < 2; i++) { double r = fabs((1.0 - ht_nums[i]) - 1e-10); - if (ht_invprimes[i] >= r) - { + if (ht_invprimes[i] >= r) { double lasth; double h = ht_invprimes[i]; @@ -1065,8 +1035,7 @@ static struct QMCSampler *QMC_initSampler(int type, int tot) static void QMC_initPixel(QMCSampler *qsa, int thread) { - if (qsa->type==SAMP_TYPE_HAMMERSLEY) - { + if (qsa->type==SAMP_TYPE_HAMMERSLEY) { /* hammersley sequence is fixed, already created in QMCSampler init. * per pixel, gets a random offset. We create separate offsets per thread, for write-safety */ qsa->offs[thread][0] = 0.5f * BLI_thread_frand(thread); @@ -1377,8 +1346,7 @@ static void trace_refract(float col[4], ShadeInput *shi, ShadeResult *shr) samples++; /* adaptive sampling */ - if (adapt_thresh < 1.0f && samples > max_samples/2) - { + if (adapt_thresh < 1.0f && samples > max_samples/2) { if (adaptive_sample_variance(samples, col, colsq, adapt_thresh)) break; @@ -1479,8 +1447,7 @@ static void trace_reflect(float col[3], ShadeInput *shi, ShadeResult *shr, float samples++; /* adaptive sampling */ - if (adapt_thresh > 0.0f && samples > max_samples/3) - { + if (adapt_thresh > 0.0f && samples > max_samples/3) { if (adaptive_sample_variance(samples, col, colsq, adapt_thresh)) break; @@ -2267,8 +2234,7 @@ static void ray_shadow_qmc(ShadeInput *shi, LampRen *lar, const float lampco[3], QMC_initPixel(qsa, shi->thread); INIT_MINMAX(min, max); - for (i=0; itype) { + switch (tex->type) { case 0: texres->tin= 0.0f; @@ -1231,7 +1231,7 @@ static int multitex(Tex *tex, float *texvec, float *dxt, float *dyt, int osatex, copy_v3_v3(tmpvec, texvec); mul_v3_fl(tmpvec, 1.0f/tex->noisesize); - switch(tex->stype) { + switch (tex->stype) { case TEX_MFRACTAL: case TEX_FBM: retval= mg_mFractalOrfBmTex(tex, tmpvec, texres); @@ -1389,7 +1389,7 @@ void texture_rgb_blend(float in[3], const float tex[3], const float out[3], floa { float facm, col; - switch(blendtype) { + switch (blendtype) { case MTEX_BLEND: fact*= facg; facm= 1.0f-fact; @@ -1530,7 +1530,7 @@ float texture_value_blend(float tex, float out, float fact, float facg, int blen facm= 1.0f-fact; if (flip) SWAP(float, fact, facm); - switch(blendtype) { + switch (blendtype) { case MTEX_BLEND: in= fact*tex + facm*out; break; @@ -3054,7 +3054,7 @@ void do_sky_tex(const float rco[3], float lo[3], const float dxyview[2], float h } /* Grab the mapping settings for this texture */ - switch(mtex->texco) { + switch (mtex->texco) { case TEXCO_ANGMAP: /* only works with texture being "real" */ /* use saacos(), fixes bug [#22398], float precision caused lo[2] to be slightly less then -1.0 */ diff --git a/source/blender/render/intern/source/rendercore.c b/source/blender/render/intern/source/rendercore.c index f5e36125299..c0267a3b44d 100644 --- a/source/blender/render/intern/source/rendercore.c +++ b/source/blender/render/intern/source/rendercore.c @@ -457,7 +457,7 @@ static void add_filt_passes(RenderLayer *rl, int curmask, int rectx, int offset, float *fp, *col= NULL; int pixsize= 3; - switch(rpass->passtype) { + switch (rpass->passtype) { case SCE_PASS_Z: fp= rpass->rect + offset; *fp= shr->z; @@ -569,7 +569,7 @@ static void add_passes(RenderLayer *rl, int offset, ShadeInput *shi, ShadeResult float *col= NULL, uvcol[3]; int a, pixsize= 3; - switch(rpass->passtype) { + switch (rpass->passtype) { case SCE_PASS_Z: fp= rpass->rect + offset; *fp= shr->z; diff --git a/source/blender/render/intern/source/renderdatabase.c b/source/blender/render/intern/source/renderdatabase.c index 6a0c8e3526f..f3b6bfb80ea 100644 --- a/source/blender/render/intern/source/renderdatabase.c +++ b/source/blender/render/intern/source/renderdatabase.c @@ -871,8 +871,7 @@ void free_renderdata_tables(Render *re) } if (re->objectinstance) { - for (obi=re->instancetable.first; obi; obi=obi->next) - { + for (obi=re->instancetable.first; obi; obi=obi->next) { if (obi->vectors) MEM_freeN(obi->vectors); @@ -1274,8 +1273,7 @@ void project_renderdata(Render *re, void (*projectfunc)(const float *, float mat else if (hoco[3]<0.0f) { har->miny= har->maxy= -10000; /* render clips it */ } - else /* do the projection...*/ - { + else { /* do the projection...*/ /* bring back hocos */ hoco[0]*= 2.0f; hoco[1]*= 2.0f; diff --git a/source/blender/render/intern/source/shadeoutput.c b/source/blender/render/intern/source/shadeoutput.c index cf688982eda..e74041c9006 100644 --- a/source/blender/render/intern/source/shadeoutput.c +++ b/source/blender/render/intern/source/shadeoutput.c @@ -931,7 +931,7 @@ static void add_to_diffuse(float *diff, ShadeInput *shi, float is, float r, floa float fac; /* input */ - switch(ma->rampin_col) { + switch (ma->rampin_col) { case MA_RAMP_IN_ENERGY: /* should use 'rgb_to_grayscale' but we only have a vector version */ fac= 0.3f*r + 0.58f*g + 0.12f*b; @@ -1003,7 +1003,7 @@ static void do_specular_ramp(ShadeInput *shi, float is, float t, float spec[3]) float col[4]; /* input */ - switch(ma->rampin_spec) { + switch (ma->rampin_spec) { case MA_RAMP_IN_ENERGY: fac= t; break; @@ -1158,8 +1158,7 @@ float lamp_get_visibility(LampRen *lar, const float co[3], float lv[3], float *d // visifac= 0.0f; } else { - switch(lar->falloff_type) - { + switch (lar->falloff_type) { case LA_FALLOFF_CONSTANT: visifac = 1.0f; break; diff --git a/source/blender/render/intern/source/sunsky.c b/source/blender/render/intern/source/sunsky.c index 8097628e575..8aabfbfed09 100644 --- a/source/blender/render/intern/source/sunsky.c +++ b/source/blender/render/intern/source/sunsky.c @@ -338,8 +338,7 @@ static void ComputeAttenuatedSunlight(float theta, int turbidity, float fTau[3]) m = 1.0f/(cosf(theta) + 0.15f*powf(93.885f-theta/(float)M_PI*180.0f,-1.253f)); - for (i = 0; i < 3; i++) - { + for (i = 0; i < 3; i++) { // Rayleigh Scattering fTauR = expf( -m * 0.008735f * powf(fLambda[i], (float)(-4.08f))); @@ -393,8 +392,7 @@ void InitAtmosphere(struct SunSky *sunSky, float sun_intens, float mief, float r fLambda[0] = 1/650e-9f; fLambda[1] = 1/570e-9f; fLambda[2] = 1/475e-9f; - for (i=0; i < 3; i++) - { + for (i=0; i < 3; i++) { fLambda2[i] = fLambda[i]*fLambda[i]; fLambda4[i] = fLambda2[i]*fLambda2[i]; } diff --git a/source/blender/render/intern/source/volume_precache.c b/source/blender/render/intern/source/volume_precache.c index 8b059d4a564..1f5ada9b113 100644 --- a/source/blender/render/intern/source/volume_precache.c +++ b/source/blender/render/intern/source/volume_precache.c @@ -334,14 +334,10 @@ static void ms_diffuse(Render *re, int do_test_break, float *x0, float *x, float size_t size = n[0]*n[1]*n[2]; const float a = dt*diff*size; - for (l=0; l<20; l++) - { - for (k=1; k<=n[2]; k++) - { - for (j=1; j<=n[1]; j++) - { - for (i=1; i<=n[0]; i++) - { + for (l=0; l<20; l++) { + for (k=1; k<=n[2]; k++) { + for (j=1; j<=n[1]; j++) { + for (i=1; i<=n[0]; i++) { x[v_I_pad(i,j,k,n)] = (x0[v_I_pad(i,j,k,n)]) + a*( x0[v_I_pad(i-1,j,k,n)]+ x0[v_I_pad(i+1,j,k,n)]+ x0[v_I_pad(i,j-1,k,n)]+ x0[v_I_pad(i,j+1,k,n)]+ x0[v_I_pad(i,j,k-1,n)]+x0[v_I_pad(i,j,k+1,n)] ) / (1+6*a); @@ -384,15 +380,11 @@ static void multiple_scattering_diffusion(Render *re, VolumePrecache *vp, Materi energy_ss = total_ss_energy(re, do_test_break, vp); /* Scattering as diffusion pass */ - for (m=0; mfirst; go; go= go->next) - { + for (go=lights->first; go; go= go->next) { float lacol[3] = {0.f, 0.f, 0.f}; lar= go->lampren; diff --git a/source/blender/render/intern/source/voxeldata.c b/source/blender/render/intern/source/voxeldata.c index 1f49b654ef8..817e51f2020 100644 --- a/source/blender/render/intern/source/voxeldata.c +++ b/source/blender/render/intern/source/voxeldata.c @@ -171,8 +171,7 @@ static void load_frame_image_sequence(VoxelData *vd, Tex *tex) vd->resol[2] = iuser.frames; vd->dataset = MEM_mapallocN(sizeof(float)*vd_resol_size(vd), "voxel dataset"); - for (z=0; z < iuser.frames; z++) - { + for (z=0; z < iuser.frames; z++) { /* get a new ibuf for each frame */ if (z > 0) { iuser.framenr++; @@ -182,10 +181,8 @@ static void load_frame_image_sequence(VoxelData *vd, Tex *tex) } rf = ibuf->rect_float; - for (y=0; y < ibuf->y; y++) - { - for (x=0; x < ibuf->x; x++) - { + for (y=0; y < ibuf->y; y++) { + for (x=0; x < ibuf->x; x++) { /* currently averaged to monchrome */ vd->dataset[ V_I(x, y, z, vd->resol) ] = (rf[0] + rf[1] + rf[2])*0.333f; rf +=4; @@ -249,8 +246,7 @@ static void init_frame_smoke(VoxelData *vd, float cfra) heat = smoke_get_heat(smd->domain->fluid); - for (i=0; idataset[i] = (heat[i]+2.0f)/4.0f; } @@ -271,8 +267,7 @@ static void init_frame_smoke(VoxelData *vd, float cfra) yvel = smoke_get_velocity_y(smd->domain->fluid); zvel = smoke_get_velocity_z(smd->domain->fluid); - for (i=0; idataset[i] = sqrt(xvel[i]*xvel[i] + yvel[i]*yvel[i] + zvel[i]*zvel[i])*3.0f; } @@ -333,7 +328,7 @@ void cache_voxeldata(Tex *tex, int scene_frame) BLI_strncpy(path, vd->source_path, sizeof(path)); - switch(vd->file_format) { + switch (vd->file_format) { case TEX_VD_IMAGE_SEQUENCE: load_frame_image_sequence(vd, tex); return; diff --git a/source/blender/render/intern/source/zbuf.c b/source/blender/render/intern/source/zbuf.c index 74c4bf19faf..06fc323e8d7 100644 --- a/source/blender/render/intern/source/zbuf.c +++ b/source/blender/render/intern/source/zbuf.c @@ -3529,7 +3529,7 @@ void merge_transp_passes(RenderLayer *rl, ShadeResult *shr) float *col= NULL; int pixsize= 3; - switch(rpass->passtype) { + switch (rpass->passtype) { case SCE_PASS_RGBA: col= shr->col; pixsize= 4; @@ -3629,7 +3629,7 @@ void add_transp_passes(RenderLayer *rl, int offset, ShadeResult *shr, float alph float *fp, *col= NULL; int pixsize= 3; - switch(rpass->passtype) { + switch (rpass->passtype) { case SCE_PASS_Z: fp= rpass->rect + offset; if (shr->z < *fp) -- cgit v1.2.3 From 07b2241fb12db6731ae1a54c6f98f4743e35fd2d Mon Sep 17 00:00:00 2001 From: Brecht Van Lommel Date: Sat, 28 Apr 2012 08:53:59 +0000 Subject: Cycles: merging features from tomato branch. === BVH build time optimizations === * BVH building was multithreaded. Not all building is multithreaded, packing and the initial bounding/splitting is still single threaded, but recursive splitting is, which was the main bottleneck. * Object splitting now uses binning rather than sorting of all elements, using code from the Embree raytracer from Intel. http://software.intel.com/en-us/articles/embree-photo-realistic-ray-tracing-kernels/ * Other small changes to avoid allocations, pack memory more tightly, avoid some unnecessary operations, ... These optimizations do not work yet when Spatial Splits are enabled, for that more work is needed. There's also other optimizations still needed, in particular for the case of many low poly objects, the packing step and node memory allocation. BVH raytracing time should remain about the same, but BVH build time should be significantly reduced, test here show speedup of about 5x to 10x on a dual core and 5x to 25x on an 8-core machine, depending on the scene. === Threads === Centralized task scheduler for multithreading, which is basically the CPU device threading code wrapped into something reusable. Basic idea is that there is a single TaskScheduler that keeps a pool of threads, one for each core. Other places in the code can then create a TaskPool that they can drop Tasks in to be executed by the scheduler, and wait for them to complete or cancel them early. === Normal ==== Added a Normal output to the texture coordinate node. This currently gives the object space normal, which is the same under object animation. In the future this might become a "generated" normal so it's also stable for deforming objects, but for now it's already useful for non-deforming objects. === Render Layers === Per render layer Samples control, leaving it to 0 will use the common scene setting. Environment pass will now render environment even if film is set to transparent. Exclude Layers" added. Scene layers (all object that influence the render, directly or indirectly) are shared between all render layers. However sometimes it's useful to leave out some object influence for a particular render layer. That's what this option allows you to do. === Filter Glossy === When using a value higher than 0.0, this will blur glossy reflections after blurry bounces, to reduce noise at the cost of accuracy. 1.0 is a good starting value to tweak. Some light paths have a low probability of being found while contributing much light to the pixel. As a result these light paths will be found in some pixels and not in others, causing fireflies. An example of such a difficult path might be a small light that is causing a small specular highlight on a sharp glossy material, which we are seeing through a rough glossy material. With path tracing it is difficult to find the specular highlight, but if we increase the roughness on the material the highlight gets bigger and softer, and so easier to find. Often this blurring will be hardly noticeable, because we are seeing it through a blurry material anyway, but there are also cases where this will lead to a loss of detail in lighting. --- source/blender/render/extern/include/RE_pipeline.h | 2 +- source/blender/render/intern/source/render_result.c | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) (limited to 'source/blender/render') diff --git a/source/blender/render/extern/include/RE_pipeline.h b/source/blender/render/extern/include/RE_pipeline.h index 315995475e9..2a3c8e60638 100644 --- a/source/blender/render/extern/include/RE_pipeline.h +++ b/source/blender/render/extern/include/RE_pipeline.h @@ -82,7 +82,7 @@ typedef struct RenderLayer { /* copy of RenderData */ char name[RE_MAXNAME]; - unsigned int lay, lay_zmask; + unsigned int lay, lay_zmask, lay_exclude; int layflag, passflag, pass_xor; struct Material *mat_override; diff --git a/source/blender/render/intern/source/render_result.c b/source/blender/render/intern/source/render_result.c index 37d6479e7bc..162fc160915 100644 --- a/source/blender/render/intern/source/render_result.c +++ b/source/blender/render/intern/source/render_result.c @@ -458,6 +458,7 @@ RenderResult *render_result_new(Render *re, rcti *partrct, int crop, int savebuf BLI_strncpy(rl->name, srl->name, sizeof(rl->name)); rl->lay= srl->lay; rl->lay_zmask= srl->lay_zmask; + rl->lay_exclude= srl->lay_exclude; rl->layflag= srl->layflag; rl->passflag= srl->passflag; // for debugging: srl->passflag|SCE_PASS_RAYHITS; rl->pass_xor= srl->pass_xor; -- cgit v1.2.3 From f88cfd9168c2977fc4acc414d8709da6484e23e7 Mon Sep 17 00:00:00 2001 From: Sergey Sharybin Date: Sat, 28 Apr 2012 16:49:00 +0000 Subject: Code and style cleanup in own modules in BKE and also mball module - Make sure functions are named in way BKE__ (same way as RNA callbacks) - Make functions which are used by mball.c only static and remove their prototypes from public header file. Further cleanup is coming. --- source/blender/render/intern/source/convertblender.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'source/blender/render') diff --git a/source/blender/render/intern/source/convertblender.c b/source/blender/render/intern/source/convertblender.c index 404901f2bb7..7fe1fab1681 100644 --- a/source/blender/render/intern/source/convertblender.c +++ b/source/blender/render/intern/source/convertblender.c @@ -908,10 +908,10 @@ static float *get_object_orco(Render *re, Object *ob) if (!orco) { if (ELEM(ob->type, OB_CURVE, OB_FONT)) { - orco = make_orco_curve(re->scene, ob); + orco = BKE_curve_make_orco(re->scene, ob); } else if (ob->type==OB_SURF) { - orco = make_orco_surf(ob); + orco = BKE_curve_surf_make_orco(ob); } if (orco) @@ -2437,7 +2437,7 @@ static void init_render_mball(Render *re, ObjectRen *obr) int a, need_orco, vlakindex, *index, negative_scale; ListBase dispbase= {NULL, NULL}; - if (ob!=find_basis_mball(re->scene, ob)) + if (ob!=BKE_metaball_basis_find(re->scene, ob)) return; mult_m4_m4m4(mat, re->viewmat, ob->obmat); @@ -2463,7 +2463,7 @@ static void init_render_mball(Render *re, ObjectRen *obr) if (!orco) { /* orco hasn't been found in cache - create new one and add to cache */ - orco= make_orco_mball(ob, &dispbase); + orco= BKE_metaball_make_orco(ob, &dispbase); set_object_orco(re, ob, orco); } } @@ -4725,7 +4725,7 @@ static int allow_render_object(Render *re, Object *ob, int nolamps, int onlysele return 0; /* don't add non-basic meta objects, ends up having renderobjects with no geometry */ - if (ob->type == OB_MBALL && ob!=find_basis_mball(re->scene, ob)) + if (ob->type == OB_MBALL && ob!=BKE_metaball_basis_find(re->scene, ob)) return 0; if (nolamps && (ob->type==OB_LAMP)) -- cgit v1.2.3