diff options
Diffstat (limited to 'source/blender/render/intern/raytrace/rayobject.cpp')
-rw-r--r-- | source/blender/render/intern/raytrace/rayobject.cpp | 144 |
1 files changed, 72 insertions, 72 deletions
diff --git a/source/blender/render/intern/raytrace/rayobject.cpp b/source/blender/render/intern/raytrace/rayobject.cpp index ac29d9e78ee..ca74367dd37 100644 --- a/source/blender/render/intern/raytrace/rayobject.cpp +++ b/source/blender/render/intern/raytrace/rayobject.cpp @@ -50,7 +50,7 @@ * because function is too long. Since this is code that is called billions * of times we really do want to inline. */ -MALWAYS_INLINE RayObject* rayface_from_coords(RayFace *rayface, void *ob, void *face, +MALWAYS_INLINE RayObject *rayface_from_coords(RayFace *rayface, void *ob, void *face, float *v1, float *v2, float *v3, float *v4) { rayface->ob = ob; @@ -85,14 +85,14 @@ MALWAYS_INLINE void rayface_from_vlak(RayFace *rayface, ObjectInstanceRen *obi, } } -RayObject* RE_rayface_from_vlak(RayFace *rayface, ObjectInstanceRen *obi, VlakRen *vlr) +RayObject *RE_rayface_from_vlak(RayFace *rayface, ObjectInstanceRen *obi, VlakRen *vlr) { return rayface_from_coords(rayface, obi, vlr, vlr->v1->co, vlr->v2->co, vlr->v3->co, vlr->v4 ? vlr->v4->co : 0); } /* VlakPrimitive */ -RayObject* RE_vlakprimitive_from_vlak(VlakPrimitive *face, struct ObjectInstanceRen *obi, struct VlakRen *vlr) +RayObject *RE_vlakprimitive_from_vlak(VlakPrimitive *face, struct ObjectInstanceRen *obi, struct VlakRen *vlr) { face->ob = obi; face->face = vlr; @@ -110,13 +110,13 @@ MALWAYS_INLINE int vlr_check_intersect(Isect *is, ObjectInstanceRen *obi, VlakRe return 0; /* I know... cpu cycle waste, might do smarter once */ - if (is->mode==RE_RAY_MIRROR) + if (is->mode == RE_RAY_MIRROR) return !(vlr->mat->mode & MA_ONLYCAST); else return (is->lay & obi->lay); } -MALWAYS_INLINE int vlr_check_intersect_solid(Isect *UNUSED(is), ObjectInstanceRen* UNUSED(obi), VlakRen *vlr) +MALWAYS_INLINE int vlr_check_intersect_solid(Isect *UNUSED(is), ObjectInstanceRen *UNUSED(obi), VlakRen *vlr) { /* solid material types only */ if (vlr->mat->material_type == MA_TYPE_SURFACE) @@ -125,7 +125,7 @@ MALWAYS_INLINE int vlr_check_intersect_solid(Isect *UNUSED(is), ObjectInstanceRe return 0; } -MALWAYS_INLINE int vlr_check_bake(Isect *is, ObjectInstanceRen* obi, VlakRen *UNUSED(vlr)) +MALWAYS_INLINE int vlr_check_bake(Isect *is, ObjectInstanceRen *obi, VlakRen *UNUSED(vlr)) { return (obi->obr->ob != is->userdata) && (obi->obr->ob->flag & SELECT); } @@ -138,7 +138,7 @@ MALWAYS_INLINE int isec_tri_quad(float start[3], float dir[3], RayFace *face, fl float t0[3], t1[3], x[3], r[3], m[3], u, v, divdet, det1, l; int quad; - quad= RE_rayface_isQuad(face); + quad = RE_rayface_isQuad(face); copy_v3_v3(co1, face->v1); copy_v3_v3(co2, face->v2); @@ -151,29 +151,29 @@ MALWAYS_INLINE int isec_tri_quad(float start[3], float dir[3], RayFace *face, fl sub_v3_v3v3(t1, co3, co1); cross_v3_v3v3(x, r, t1); - divdet= dot_v3v3(t0, x); + divdet = dot_v3v3(t0, x); sub_v3_v3v3(m, start, co3); - det1= dot_v3v3(m, x); + det1 = dot_v3v3(m, x); if (divdet != 0.0f) { - divdet= 1.0f/divdet; - v= det1*divdet; + divdet = 1.0f / divdet; + v = det1 * divdet; - if (v < RE_RAYTRACE_EPSILON && v > -(1.0f+RE_RAYTRACE_EPSILON)) { + if (v < RE_RAYTRACE_EPSILON && v > -(1.0f + RE_RAYTRACE_EPSILON)) { float cros[3]; cross_v3_v3v3(cros, m, t0); - u= divdet*dot_v3v3(cros, r); + u = divdet * dot_v3v3(cros, r); - if (u < RE_RAYTRACE_EPSILON && (v + u) > -(1.0f+RE_RAYTRACE_EPSILON)) { - l= divdet*dot_v3v3(cros, t1); + if (u < RE_RAYTRACE_EPSILON && (v + u) > -(1.0f + RE_RAYTRACE_EPSILON)) { + l = divdet * dot_v3v3(cros, t1); /* check if intersection is within ray length */ if (l > -RE_RAYTRACE_EPSILON && l < *lambda) { - uv[0]= u; - uv[1]= v; - *lambda= l; + uv[0] = u; + uv[1] = v; + *lambda = l; return 1; } } @@ -184,25 +184,25 @@ MALWAYS_INLINE int isec_tri_quad(float start[3], float dir[3], RayFace *face, fl if (quad) { copy_v3_v3(co4, face->v4); sub_v3_v3v3(t0, co3, co4); - divdet= dot_v3v3(t0, x); + divdet = dot_v3v3(t0, x); if (divdet != 0.0f) { - divdet= 1.0f/divdet; - v = det1*divdet; + divdet = 1.0f / divdet; + v = det1 * divdet; - if (v < RE_RAYTRACE_EPSILON && v > -(1.0f+RE_RAYTRACE_EPSILON)) { + if (v < RE_RAYTRACE_EPSILON && v > -(1.0f + RE_RAYTRACE_EPSILON)) { float cros[3]; cross_v3_v3v3(cros, m, t0); - u= divdet*dot_v3v3(cros, r); + u = divdet * dot_v3v3(cros, r); - if (u < RE_RAYTRACE_EPSILON && (v + u) > -(1.0f+RE_RAYTRACE_EPSILON)) { - l= divdet*dot_v3v3(cros, t1); + if (u < RE_RAYTRACE_EPSILON && (v + u) > -(1.0f + RE_RAYTRACE_EPSILON)) { + l = divdet * dot_v3v3(cros, t1); - if (l >- RE_RAYTRACE_EPSILON && l < *lambda) { - uv[0]= u; - uv[1]= -(1.0f + v + u); - *lambda= l; + if (l > -RE_RAYTRACE_EPSILON && l < *lambda) { + uv[0] = u; + uv[1] = -(1.0f + v + u); + *lambda = l; return 2; } } @@ -221,7 +221,7 @@ MALWAYS_INLINE int isec_tri_quad_neighbour(float start[3], float dir[3], RayFace float t0[3], t1[3], x[3], r[3], m[3], u, v, divdet, det1; int quad; - quad= RE_rayface_isQuad(face); + quad = RE_rayface_isQuad(face); copy_v3_v3(co1, face->v1); copy_v3_v3(co2, face->v2); @@ -234,22 +234,22 @@ MALWAYS_INLINE int isec_tri_quad_neighbour(float start[3], float dir[3], RayFace sub_v3_v3v3(t1, co3, co1); cross_v3_v3v3(x, r, t1); - divdet= dot_v3v3(t0, x); + divdet = dot_v3v3(t0, x); sub_v3_v3v3(m, start, co3); - det1= dot_v3v3(m, x); + det1 = dot_v3v3(m, x); if (divdet != 0.0f) { - divdet= 1.0f/divdet; - v= det1*divdet; + divdet = 1.0f / divdet; + v = det1 * divdet; - if (v < RE_RAYTRACE_EPSILON && v > -(1.0f+RE_RAYTRACE_EPSILON)) { + if (v < RE_RAYTRACE_EPSILON && v > -(1.0f + RE_RAYTRACE_EPSILON)) { float cros[3]; cross_v3_v3v3(cros, m, t0); - u= divdet*dot_v3v3(cros, r); + u = divdet * dot_v3v3(cros, r); - if (u < RE_RAYTRACE_EPSILON && (v + u) > -(1.0f+RE_RAYTRACE_EPSILON)) + if (u < RE_RAYTRACE_EPSILON && (v + u) > -(1.0f + RE_RAYTRACE_EPSILON)) return 1; } } @@ -258,19 +258,19 @@ MALWAYS_INLINE int isec_tri_quad_neighbour(float start[3], float dir[3], RayFace if (quad) { copy_v3_v3(co4, face->v4); sub_v3_v3v3(t0, co3, co4); - divdet= dot_v3v3(t0, x); + divdet = dot_v3v3(t0, x); if (divdet != 0.0f) { - divdet= 1.0f/divdet; - v = det1*divdet; + divdet = 1.0f / divdet; + v = det1 * divdet; - if (v < RE_RAYTRACE_EPSILON && v > -(1.0f+RE_RAYTRACE_EPSILON)) { + if (v < RE_RAYTRACE_EPSILON && v > -(1.0f + RE_RAYTRACE_EPSILON)) { float cros[3]; cross_v3_v3v3(cros, m, t0); - u= divdet*dot_v3v3(cros, r); + u = divdet * dot_v3v3(cros, r); - if (u < RE_RAYTRACE_EPSILON && (v + u) > -(1.0f+RE_RAYTRACE_EPSILON)) + if (u < RE_RAYTRACE_EPSILON && (v + u) > -(1.0f + RE_RAYTRACE_EPSILON)) return 2; } } @@ -285,7 +285,7 @@ MALWAYS_INLINE int isec_tri_quad_neighbour(float start[3], float dir[3], RayFace MALWAYS_INLINE int intersect_rayface(RayObject *hit_obj, RayFace *face, Isect *is) { float dist, uv[2]; - int ok= 0; + int ok = 0; /* avoid self-intersection */ if (is->orig.ob == face->ob && is->orig.face == face->face) @@ -293,25 +293,25 @@ MALWAYS_INLINE int intersect_rayface(RayObject *hit_obj, RayFace *face, Isect *i /* check if we should intersect this face */ if (is->check == RE_CHECK_VLR_RENDER) { - if (vlr_check_intersect(is, (ObjectInstanceRen*)face->ob, (VlakRen*)face->face) == 0) + if (vlr_check_intersect(is, (ObjectInstanceRen *)face->ob, (VlakRen *)face->face) == 0) return 0; } else if (is->check == RE_CHECK_VLR_NON_SOLID_MATERIAL) { - if (vlr_check_intersect(is, (ObjectInstanceRen*)face->ob, (VlakRen*)face->face) == 0) + 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) + if (vlr_check_intersect_solid(is, (ObjectInstanceRen *)face->ob, (VlakRen *)face->face) == 0) return 0; } else if (is->check == RE_CHECK_VLR_BAKE) { - if (vlr_check_bake(is, (ObjectInstanceRen*)face->ob, (VlakRen*)face->face) == 0) + if (vlr_check_bake(is, (ObjectInstanceRen *)face->ob, (VlakRen *)face->face) == 0) return 0; } /* ray counter */ RE_RC_COUNT(is->raycounter->faces.test); - dist= is->dist; - ok= isec_tri_quad(is->start, is->dir, face, uv, &dist); + dist = is->dist; + ok = isec_tri_quad(is->start, is->dir, face, uv, &dist); if (ok) { @@ -319,21 +319,21 @@ MALWAYS_INLINE int intersect_rayface(RayObject *hit_obj, RayFace *face, Isect *i * 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) { - VlakRen * a = (VlakRen*)is->orig.face; - VlakRen * b = (VlakRen*)face->face; + 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); + 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)) { return 0; @@ -344,9 +344,9 @@ MALWAYS_INLINE int intersect_rayface(RayObject *hit_obj, RayFace *face, Isect *i RE_RC_COUNT(is->raycounter->faces.hit); - is->isect= ok; // which half of the quad - is->dist= dist; - is->u= uv[0]; is->v= uv[1]; + is->isect = ok; // which half of the quad + is->dist = dist; + is->u = uv[0]; is->v = uv[1]; is->hit.ob = face->ob; is->hit.face = face->face; @@ -368,19 +368,19 @@ 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++) { - isec->idot_axis[i] = 1.0f / isec->dir[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; - isec->bv_index[2*i+1] = 1 - isec->bv_index[2*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]; - isec->bv_index[2*i] = i+3*isec->bv_index[2*i]; - isec->bv_index[2*i+1] = i+3*isec->bv_index[2*i+1]; + isec->bv_index[2 * i] = i + 3 * isec->bv_index[2 * i]; + isec->bv_index[2 * i + 1] = i + 3 * isec->bv_index[2 * i + 1]; } #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)) { @@ -410,11 +410,11 @@ int RE_rayobject_raycast(RayObject *r, Isect *isec) int RE_rayobject_intersect(RayObject *r, Isect *i) { if (RE_rayobject_isRayFace(r)) { - return intersect_rayface(r, (RayFace*) RE_rayobject_align(r), i); + return intersect_rayface(r, (RayFace *) RE_rayobject_align(r), i); } else if (RE_rayobject_isVlakPrimitive(r)) { //TODO optimize (useless copy to RayFace to avoid duplicate code) - VlakPrimitive *face = (VlakPrimitive*) RE_rayobject_align(r); + VlakPrimitive *face = (VlakPrimitive *) RE_rayobject_align(r); RayFace nface; rayface_from_vlak(&nface, face->ob, face->face); @@ -470,7 +470,7 @@ float RE_rayobject_cost(RayObject *r) void RE_rayobject_merge_bb(RayObject *r, float *min, float *max) { if (RE_rayobject_isRayFace(r)) { - RayFace *face = (RayFace*) RE_rayobject_align(r); + RayFace *face = (RayFace *) RE_rayobject_align(r); DO_MINMAX(face->v1, min, max); DO_MINMAX(face->v2, min, max); @@ -478,7 +478,7 @@ void RE_rayobject_merge_bb(RayObject *r, float *min, float *max) if (RE_rayface_isQuad(face)) DO_MINMAX(face->v4, min, max); } else if (RE_rayobject_isVlakPrimitive(r)) { - VlakPrimitive *face = (VlakPrimitive*) RE_rayobject_align(r); + VlakPrimitive *face = (VlakPrimitive *) RE_rayobject_align(r); RayFace nface; rayface_from_vlak(&nface, face->ob, face->face); |