From cd4123e1db8a40836fa04813ef7dc440ef7feeb0 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Sun, 22 Jan 2012 17:20:37 +0000 Subject: use inline BLI_math functions for dot product and length calculation. --- .../blender/render/intern/source/convertblender.c | 30 +++++++++++----------- source/blender/render/intern/source/occlusion.c | 2 +- source/blender/render/intern/source/pixelshading.c | 6 ++--- source/blender/render/intern/source/rayshade.c | 14 +++++----- source/blender/render/intern/source/shadbuf.c | 4 +-- source/blender/render/intern/source/shadeinput.c | 4 +-- source/blender/render/intern/source/volumetric.c | 2 +- 7 files changed, 31 insertions(+), 31 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 1ec400138a7..fa8540b352d 100644 --- a/source/blender/render/intern/source/convertblender.c +++ b/source/blender/render/intern/source/convertblender.c @@ -671,7 +671,7 @@ static void calc_vertexnormals(Render *UNUSED(re), ObjectRen *obr, int do_tangen float *tav= RE_vertren_get_tangent(obr, ver, 0); if (tav) { /* orthonorm. */ - float tdn = tav[0]*ver->n[0] + tav[1]*ver->n[1] + tav[2]*ver->n[2]; + const float tdn = dot_v3v3(tav, ver->n); tav[0] -= ver->n[0]*tdn; tav[1] -= ver->n[1]*tdn; tav[2] -= ver->n[2]*tdn; @@ -767,7 +767,7 @@ static int as_testvertex(VlakRen *vlr, VertRen *UNUSED(ver), ASvert *asv, float while(asf) { for(a=0; a<4; a++) { if(asf->vlr[a] && asf->vlr[a]!=vlr) { - inp= fabs( vlr->n[0]*asf->vlr[a]->n[0] + vlr->n[1]*asf->vlr[a]->n[1] + vlr->n[2]*asf->vlr[a]->n[2] ); + inp = fabsf(dot_v3v3(vlr->n, asf->vlr[a]->n)); if(inp < thresh) return 1; } } @@ -790,7 +790,7 @@ static VertRen *as_findvertex(VlakRen *vlr, VertRen *UNUSED(ver), ASvert *asv, f if(asf->vlr[a] && asf->vlr[a]!=vlr) { /* this face already made a copy for this vertex! */ if(asf->nver[a]) { - inp= fabs( vlr->n[0]*asf->vlr[a]->n[0] + vlr->n[1]*asf->vlr[a]->n[1] + vlr->n[2]*asf->vlr[a]->n[2] ); + inp = fabsf(dot_v3v3(vlr->n, asf->vlr[a]->n)); if(inp >= thresh) { return asf->nver[a]; } @@ -2158,7 +2158,7 @@ static void make_render_halos(Render *re, ObjectRen *obr, Mesh *UNUSED(me), int copy_v3_v3(view, vec); normalize_v3(view); - zn= nor[0]*view[0]+nor[1]*view[1]+nor[2]*view[2]; + zn = dot_v3v3(nor, view); if(zn>=0.0f) hasize= 0.0f; else hasize*= zn*zn*zn*zn; } @@ -2240,9 +2240,9 @@ static void displace_render_vert(Render *re, ObjectRen *obr, ShadeInput *shi, Ve mul_m4_v3(mat, shi->co); if(imat) { - shi->vn[0]= imat[0][0]*vr->n[0]+imat[0][1]*vr->n[1]+imat[0][2]*vr->n[2]; - shi->vn[1]= imat[1][0]*vr->n[0]+imat[1][1]*vr->n[1]+imat[1][2]*vr->n[2]; - shi->vn[2]= imat[2][0]*vr->n[0]+imat[2][1]*vr->n[1]+imat[2][2]*vr->n[2]; + shi->vn[0] = dot_v3v3(imat[0], vr->n); + shi->vn[1] = dot_v3v3(imat[1], vr->n); + shi->vn[2] = dot_v3v3(imat[2], vr->n); } if (texco & TEXCO_UV) { @@ -4241,7 +4241,7 @@ static void check_non_flat_quads(ObjectRen *obr) flen= normal_tri_v3( nor,vlr->v4->co, vlr->v3->co, vlr->v1->co); if(flen==0.0f) normal_tri_v3( nor,vlr->v4->co, vlr->v2->co, vlr->v1->co); - xn= nor[0]*vlr->n[0] + nor[1]*vlr->n[1] + nor[2]*vlr->n[2]; + xn = dot_v3v3(nor, vlr->n); if(ABS(xn) < 0.999995f ) { // checked on noisy fractal grid @@ -4252,11 +4252,11 @@ static void check_non_flat_quads(ObjectRen *obr) /* split direction based on vnorms */ normal_tri_v3( nor,vlr->v1->co, vlr->v2->co, vlr->v3->co); - d1= nor[0]*vlr->v1->n[0] + nor[1]*vlr->v1->n[1] + nor[2]*vlr->v1->n[2]; + d1 = dot_v3v3(nor, vlr->v1->n); normal_tri_v3( nor,vlr->v2->co, vlr->v3->co, vlr->v4->co); - d2= nor[0]*vlr->v2->n[0] + nor[1]*vlr->v2->n[1] + nor[2]*vlr->v2->n[2]; - + d2 = dot_v3v3(nor, vlr->v2->n); + if( fabs(d1) < fabs(d2) ) vlr->flag |= R_DIVIDE_24; else vlr->flag &= ~R_DIVIDE_24; @@ -5267,7 +5267,7 @@ static void speedvector_project(Render *re, float zco[2], const float co[3], con if(vec[0]<0.0f) ang= -ang; zco[0]= ang/pixelphix + zmulx; - ang= 0.5f*(float)M_PI - saacos(vec[1]/sqrtf(vec[0]*vec[0] + vec[1]*vec[1] + vec[2]*vec[2])); + ang= 0.5f*(float)M_PI - saacos(vec[1] / len_v3(vec)); zco[1]= ang/pixelphiy + zmuly; } @@ -5487,9 +5487,9 @@ static int load_fluidsimspeedvectors(Render *re, ObjectInstanceRen *obi, float * } // transform (=rotate) to cam space - camco[0]= imat[0][0]*fsvec[0] + imat[0][1]*fsvec[1] + imat[0][2]*fsvec[2]; - camco[1]= imat[1][0]*fsvec[0] + imat[1][1]*fsvec[1] + imat[1][2]*fsvec[2]; - camco[2]= imat[2][0]*fsvec[0] + imat[2][1]*fsvec[1] + imat[2][2]*fsvec[2]; + camco[0] = dot_v3v3(imat[0], fsvec); + camco[1] = dot_v3v3(imat[1], fsvec); + camco[2] = dot_v3v3(imat[2], fsvec); // get homogenous coordinates projectvert(camco, winmat, hoco); diff --git a/source/blender/render/intern/source/occlusion.c b/source/blender/render/intern/source/occlusion.c index e20fd85d0f0..782e0b59388 100644 --- a/source/blender/render/intern/source/occlusion.c +++ b/source/blender/render/intern/source/occlusion.c @@ -1413,7 +1413,7 @@ static void sample_occ_tree(Render *re, OcclusionTree *tree, OccFace *exclude, f if(env) { /* sky shading using bent normal */ if(ELEM(envcolor, WO_AOSKYCOL, WO_AOSKYTEX)) { - fac= 0.5f*(1.0f+bn[0]*re->grvec[0]+ bn[1]*re->grvec[1]+ bn[2]*re->grvec[2]); + fac= 0.5f * (1.0f + dot_v3v3(bn, re->grvec)); env[0]= (1.0f-fac)*re->wrld.horr + fac*re->wrld.zenr; env[1]= (1.0f-fac)*re->wrld.horg + fac*re->wrld.zeng; env[2]= (1.0f-fac)*re->wrld.horb + fac*re->wrld.zenb; diff --git a/source/blender/render/intern/source/pixelshading.c b/source/blender/render/intern/source/pixelshading.c index f261ec41746..24683ec57f7 100644 --- a/source/blender/render/intern/source/pixelshading.c +++ b/source/blender/render/intern/source/pixelshading.c @@ -104,7 +104,7 @@ static void render_lighting_halo(HaloRen *har, float col_r[3]) lv[0]= rco[0]-lar->co[0]; lv[1]= rco[1]-lar->co[1]; lv[2]= rco[2]-lar->co[2]; - ld= sqrt(lv[0]*lv[0]+lv[1]*lv[1]+lv[2]*lv[2]); + ld = len_v3(lv); lv[0]/= ld; lv[1]/= ld; lv[2]/= ld; @@ -210,7 +210,7 @@ static void render_lighting_halo(HaloRen *har, float col_r[3]) /* dot product and reflectivity*/ - inp= 1.0-fabs(vn[0]*lv[0] + vn[1]*lv[1] + vn[2]*lv[2]); + inp = 1.0 - fabs(dot_v3v3(vn, lv)); /* inp= cos(0.5*M_PI-acos(inp)); */ @@ -511,7 +511,7 @@ void shadeSkyView(float col_r[3], const float rco[3], const float view[3], const /* Some view vector stuff. */ if(R.wrld.skytype & WO_SKYREAL) { - blend= view[0]*R.grvec[0]+ view[1]*R.grvec[1]+ view[2]*R.grvec[2]; + blend = dot_v3v3(view, R.grvec); if(blend<0.0f) skyflag= 0; diff --git a/source/blender/render/intern/source/rayshade.c b/source/blender/render/intern/source/rayshade.c index f9ffc2532eb..6c0386cc8b1 100644 --- a/source/blender/render/intern/source/rayshade.c +++ b/source/blender/render/intern/source/rayshade.c @@ -471,7 +471,7 @@ void makeraytree(Render *re) sub[i] = max[i]-min[i]; } - re->maxdist= sub[0]*sub[0] + sub[1]*sub[1] + sub[2]*sub[2]; + re->maxdist = dot_v3v3(sub, sub); if(re->maxdist > 0.0f) re->maxdist= sqrt(re->maxdist); re->i.infostr= "Raytree finished"; @@ -598,7 +598,7 @@ static int refraction(float refract[3], const float n[3], const float view[3], f copy_v3_v3(refract, view); - dot= view[0]*n[0] + view[1]*n[1] + view[2]*n[2]; + dot = dot_v3v3(view, n); if(dot>0.0f) { index = 1.0f/index; @@ -1708,7 +1708,7 @@ static int UNUSED_FUNCTION(ray_trace_shadow_rad)(ShadeInput *ship, ShadeResult * counter+=3; counter %= 768; copy_v3_v3(vec, hashvectf+counter); - if(ship->vn[0]*vec[0]+ship->vn[1]*vec[1]+ship->vn[2]*vec[2]>0.0f) { + if (dot_v3v3(ship->vn, vec) > 0.0f) { vec[0]-= vec[0]; vec[1]-= vec[1]; vec[2]-= vec[2]; @@ -1771,7 +1771,7 @@ static void DS_energy(float *sphere, int tot, float vec[3]) for(a=0, fp=sphere; a bias) { + if (dot_v3v3(vec, nrm) > bias) { /* only ao samples for mask */ if(R.r.mode & R_OSA) { j++; @@ -2135,7 +2135,7 @@ static void ray_ao_spheresamp(ShadeInput *shi, float ao[3], float env[3]) normalize_v3(view); if(envcolor==WO_AOSKYCOL) { - const float fac= 0.5f*(1.0f+view[0]*R.grvec[0]+ view[1]*R.grvec[1]+ view[2]*R.grvec[2]); + const float fac = 0.5f * (1.0f + dot_v3v3(view, R.grvec)); env[0]+= (1.0f-fac)*R.wrld.horr + fac*R.wrld.zenr; env[1]+= (1.0f-fac)*R.wrld.horg + fac*R.wrld.zeng; env[2]+= (1.0f-fac)*R.wrld.horb + fac*R.wrld.zenb; diff --git a/source/blender/render/intern/source/shadbuf.c b/source/blender/render/intern/source/shadbuf.c index c14a768d1ce..88d86d5bd43 100644 --- a/source/blender/render/intern/source/shadbuf.c +++ b/source/blender/render/intern/source/shadbuf.c @@ -2068,7 +2068,7 @@ static int viewpixel_to_lampbuf(ShadBuf *shb, ObjectInstanceRen *obi, VlakRen *v mul_m4_v3(obi->mat, v1); /* from shadepixel() */ - dface= v1[0]*nor[0] + v1[1]*nor[1] + v1[2]*nor[2]; + dface = dot_v3v3(v1, nor); hoco[3]= 1.0f; /* ortho viewplane cannot intersect using view vector originating in (0,0,0) */ @@ -2091,7 +2091,7 @@ static int viewpixel_to_lampbuf(ShadBuf *shb, ObjectInstanceRen *obi, VlakRen *v calc_view_vector(view, x, y); - div= nor[0]*view[0] + nor[1]*view[1] + nor[2]*view[2]; + div = dot_v3v3(nor, view); if (div==0.0f) return 0; diff --git a/source/blender/render/intern/source/shadeinput.c b/source/blender/render/intern/source/shadeinput.c index 580a09d5050..e0b5da817cb 100644 --- a/source/blender/render/intern/source/shadeinput.c +++ b/source/blender/render/intern/source/shadeinput.c @@ -608,7 +608,7 @@ void shade_input_calc_viewco(ShadeInput *shi, float x, float y, float z, float v if(shi->obi->flag & R_TRANSFORMED) mul_m4_v3(shi->obi->mat, v1); - dface= v1[0]*shi->facenor[0]+v1[1]*shi->facenor[1]+v1[2]*shi->facenor[2]; + dface = dot_v3v3(v1, shi->facenor); /* ortho viewplane cannot intersect using view vector originating in (0,0,0) */ if(R.r.mode & R_ORTHO) { @@ -650,7 +650,7 @@ void shade_input_calc_viewco(ShadeInput *shi, float x, float y, float z, float v else { float div; - div= shi->facenor[0]*view[0] + shi->facenor[1]*view[1] + shi->facenor[2]*view[2]; + div = dot_v3v3(shi->facenor, view); if (div!=0.0f) fac= dface/div; else fac= 0.0f; diff --git a/source/blender/render/intern/source/volumetric.c b/source/blender/render/intern/source/volumetric.c index 3637c2de1fb..66cbb18bc57 100644 --- a/source/blender/render/intern/source/volumetric.c +++ b/source/blender/render/intern/source/volumetric.c @@ -274,7 +274,7 @@ static float metadensity(Object* ob, const float co[3]) } /* ml->rad2 is not set */ - dist2 = 1.f - ((tp[0]*tp[0] + tp[1]*tp[1] + tp[2]*tp[2]) / (ml->rad*ml->rad)); + dist2 = 1.0f - (dot_v3v3(tp, tp) / (ml->rad * ml->rad)); if (dist2 > 0.f) dens += (ml->flag & MB_NEGATIVE) ? -ml->s*dist2*dist2*dist2 : ml->s*dist2*dist2*dist2; } -- cgit v1.2.3