diff options
author | Campbell Barton <ideasman42@gmail.com> | 2019-03-25 03:55:36 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2019-03-25 03:55:36 +0300 |
commit | 07f6be87a97ed952c82804abc7f647c488c8ed3a (patch) | |
tree | e6bcf556d03245ce203bdf86ca73f5945a1b7779 /source/blender/render/intern | |
parent | abd18f6ec0631b0a03bc7730e3241c5e2b61a788 (diff) |
Cleanup: style (render module)
Diffstat (limited to 'source/blender/render/intern')
-rw-r--r-- | source/blender/render/intern/source/bake_api.c | 10 | ||||
-rw-r--r-- | source/blender/render/intern/source/external_engine.c | 4 | ||||
-rw-r--r-- | source/blender/render/intern/source/imagetexture.c | 884 | ||||
-rw-r--r-- | source/blender/render/intern/source/initrender.c | 2 | ||||
-rw-r--r-- | source/blender/render/intern/source/multires_bake.c | 42 | ||||
-rw-r--r-- | source/blender/render/intern/source/pipeline.c | 16 | ||||
-rw-r--r-- | source/blender/render/intern/source/pointdensity.c | 25 | ||||
-rw-r--r-- | source/blender/render/intern/source/render_result.c | 30 | ||||
-rw-r--r-- | source/blender/render/intern/source/render_texture.c | 800 | ||||
-rw-r--r-- | source/blender/render/intern/source/zbuf.c | 142 |
10 files changed, 979 insertions, 976 deletions
diff --git a/source/blender/render/intern/source/bake_api.c b/source/blender/render/intern/source/bake_api.c index a658a0e1138..5e63f76ca80 100644 --- a/source/blender/render/intern/source/bake_api.c +++ b/source/blender/render/intern/source/bake_api.c @@ -362,7 +362,7 @@ static bool cast_ray_highpoly( /* transfer position differentials */ float tmp[3]; - mul_v3_v3fl(tmp, dir_high, 1.0f/dot_v3v3(dir_high, triangle_high->normal)); + mul_v3_v3fl(tmp, dir_high, 1.0f / dot_v3v3(dir_high, triangle_high->normal)); madd_v3_v3fl(dxco, tmp, -dot_v3v3(dxco, triangle_high->normal)); madd_v3_v3fl(dyco, tmp, -dot_v3v3(dyco, triangle_high->normal)); @@ -421,10 +421,10 @@ static TriTessFace *mesh_calc_tri_tessface( } BKE_mesh_recalc_looptri( - me->mloop, me->mpoly, - me->mvert, - me->totloop, me->totpoly, - looptri); + me->mloop, me->mpoly, + me->mvert, + me->totloop, me->totpoly, + looptri); const float *precomputed_normals = CustomData_get_layer(&me->pdata, CD_NORMAL); const bool calculate_normal = precomputed_normals ? false : true; diff --git a/source/blender/render/intern/source/external_engine.c b/source/blender/render/intern/source/external_engine.c index b29d504c21f..a9bf80a6aa0 100644 --- a/source/blender/render/intern/source/external_engine.c +++ b/source/blender/render/intern/source/external_engine.c @@ -273,7 +273,7 @@ void RE_engine_end_result(RenderEngine *engine, RenderResult *result, bool cance RenderPart *pa = get_part_from_result(re, result); if (pa) { - pa->status = (!cancel && merge_results)? PART_STATUS_MERGED: PART_STATUS_RENDERED; + pa->status = (!cancel && merge_results) ? PART_STATUS_MERGED : PART_STATUS_RENDERED; } else if (re->result->do_exr_tile) { /* if written result does not match any tile and we are using save @@ -505,7 +505,7 @@ static void engine_depsgraph_free(RenderEngine *engine) void RE_engine_frame_set(RenderEngine *engine, int frame, float subframe) { - if(!engine->depsgraph) { + if (!engine->depsgraph) { return; } diff --git a/source/blender/render/intern/source/imagetexture.c b/source/blender/render/intern/source/imagetexture.c index e246592f24e..e67a07e791e 100644 --- a/source/blender/render/intern/source/imagetexture.c +++ b/source/blender/render/intern/source/imagetexture.c @@ -63,27 +63,27 @@ static void ibuf_get_color(float col[4], struct ImBuf *ibuf, int x, int y) int ofs = y * ibuf->x + x; if (ibuf->rect_float) { - if (ibuf->channels==4) { - const float *fp= ibuf->rect_float + 4*ofs; + if (ibuf->channels == 4) { + const float *fp = ibuf->rect_float + 4 * ofs; copy_v4_v4(col, fp); } - else if (ibuf->channels==3) { - const float *fp= ibuf->rect_float + 3*ofs; + else if (ibuf->channels == 3) { + const float *fp = ibuf->rect_float + 3 * ofs; copy_v3_v3(col, fp); - col[3]= 1.0f; + col[3] = 1.0f; } else { - const float *fp= ibuf->rect_float + ofs; - col[0]= col[1]= col[2]= col[3]= *fp; + const float *fp = ibuf->rect_float + ofs; + col[0] = col[1] = col[2] = col[3] = *fp; } } else { - const char *rect = (char *)( ibuf->rect+ ofs); + const char *rect = (char *)(ibuf->rect + ofs); - col[0] = ((float)rect[0])*(1.0f/255.0f); - col[1] = ((float)rect[1])*(1.0f/255.0f); - col[2] = ((float)rect[2])*(1.0f/255.0f); - col[3] = ((float)rect[3])*(1.0f/255.0f); + col[0] = ((float)rect[0]) * (1.0f / 255.0f); + col[1] = ((float)rect[1]) * (1.0f / 255.0f); + col[2] = ((float)rect[2]) * (1.0f / 255.0f); + col[3] = ((float)rect[3]) * (1.0f / 255.0f); /* bytes are internally straight, however render pipeline seems to expect premul */ col[0] *= col[3]; @@ -98,13 +98,13 @@ int imagewrap(Tex *tex, Image *ima, ImBuf *ibuf, const float texvec[3], TexResul int x, y, retval; int xi, yi; /* original values */ - texres->tin= texres->ta= texres->tr= texres->tg= texres->tb= 0.0f; + texres->tin = texres->ta = texres->tr = texres->tg = texres->tb = 0.0f; /* we need to set retval OK, otherwise texture code generates normals itself... */ - retval= texres->nor ? 3 : 1; + retval = texres->nor ? 3 : 1; /* quick tests */ - if (ibuf==NULL && ima==NULL) + if (ibuf == NULL && ima == NULL) return retval; if (ima) { @@ -114,9 +114,9 @@ int imagewrap(Tex *tex, Image *ima, ImBuf *ibuf, const float texvec[3], TexResul ibuf = BKE_image_pool_acquire_ibuf(ima, &tex->iuser, pool); - ima->flag|= IMA_USED_FOR_RENDER; + ima->flag |= IMA_USED_FOR_RENDER; } - if (ibuf==NULL || (ibuf->rect==NULL && ibuf->rect_float==NULL)) { + if (ibuf == NULL || (ibuf->rect == NULL && ibuf->rect_float == NULL)) { if (ima) BKE_image_pool_release_ibuf(ima, ibuf, pool); return retval; @@ -124,21 +124,21 @@ int imagewrap(Tex *tex, Image *ima, ImBuf *ibuf, const float texvec[3], TexResul /* setup mapping */ if (tex->imaflag & TEX_IMAROT) { - fy= texvec[0]; - fx= texvec[1]; + fy = texvec[0]; + fx = texvec[1]; } else { - fx= texvec[0]; - fy= texvec[1]; + fx = texvec[0]; + fy = texvec[1]; } if (tex->extend == TEX_CHECKER) { int xs, ys; - xs= (int)floor(fx); - ys= (int)floor(fy); - fx-= xs; - fy-= ys; + xs = (int)floor(fx); + ys = (int)floor(fy); + fx -= xs; + fy -= ys; if ( (tex->flag & TEX_CHECKER_ODD) == 0) { if ((xs + ys) & 1) { @@ -150,53 +150,53 @@ int imagewrap(Tex *tex, Image *ima, ImBuf *ibuf, const float texvec[3], TexResul return retval; } } - if ( (tex->flag & TEX_CHECKER_EVEN)==0) { - if ((xs+ys) & 1) { + if ( (tex->flag & TEX_CHECKER_EVEN) == 0) { + if ((xs + ys) & 1) { if (ima) BKE_image_pool_release_ibuf(ima, ibuf, pool); return retval; } } /* scale around center, (0.5, 0.5) */ - if (tex->checkerdist<1.0f) { - fx= (fx-0.5f)/(1.0f-tex->checkerdist) +0.5f; - fy= (fy-0.5f)/(1.0f-tex->checkerdist) +0.5f; + if (tex->checkerdist < 1.0f) { + fx = (fx - 0.5f) / (1.0f - tex->checkerdist) + 0.5f; + fy = (fy - 0.5f) / (1.0f - tex->checkerdist) + 0.5f; } } - x= xi= (int)floorf(fx*ibuf->x); - y= yi= (int)floorf(fy*ibuf->y); + x = xi = (int)floorf(fx * ibuf->x); + y = yi = (int)floorf(fy * ibuf->y); if (tex->extend == TEX_CLIPCUBE) { - if (x<0 || y<0 || x>=ibuf->x || y>=ibuf->y || texvec[2]<-1.0f || texvec[2]>1.0f) { + if (x < 0 || y < 0 || x >= ibuf->x || y >= ibuf->y || texvec[2] < -1.0f || texvec[2] > 1.0f) { if (ima) BKE_image_pool_release_ibuf(ima, ibuf, pool); return retval; } } - else if ( tex->extend==TEX_CLIP || tex->extend==TEX_CHECKER) { - if (x<0 || y<0 || x>=ibuf->x || y>=ibuf->y) { + else if (tex->extend == TEX_CLIP || tex->extend == TEX_CHECKER) { + if (x < 0 || y < 0 || x >= ibuf->x || y >= ibuf->y) { if (ima) BKE_image_pool_release_ibuf(ima, ibuf, pool); return retval; } } else { - if (tex->extend==TEX_EXTEND) { - if (x>=ibuf->x) x = ibuf->x-1; - else if (x<0) x= 0; + if (tex->extend == TEX_EXTEND) { + if (x >= ibuf->x) x = ibuf->x - 1; + else if (x < 0) x = 0; } else { - x= x % ibuf->x; - if (x<0) x+= ibuf->x; + x = x % ibuf->x; + if (x < 0) x += ibuf->x; } - if (tex->extend==TEX_EXTEND) { - if (y>=ibuf->y) y = ibuf->y-1; - else if (y<0) y= 0; + if (tex->extend == TEX_EXTEND) { + if (y >= ibuf->y) y = ibuf->y - 1; + else if (y < 0) y = 0; } else { - y= y % ibuf->y; - if (y<0) y+= ibuf->y; + y = y % ibuf->y; + if (y < 0) y += ibuf->y; } } @@ -221,7 +221,7 @@ int imagewrap(Tex *tex, Image *ima, ImBuf *ibuf, const float texvec[3], TexResul fx -= (float)(xi - x) / (float)ibuf->x; fy -= (float)(yi - y) / (float)ibuf->y; - boxsample(ibuf, fx-filterx, fy-filtery, fx+filterx, fy+filtery, texres, (tex->extend==TEX_REPEAT), (tex->extend==TEX_EXTEND)); + boxsample(ibuf, fx - filterx, fy - filtery, fx + filterx, fy + filtery, texres, (tex->extend == TEX_REPEAT), (tex->extend == TEX_EXTEND)); } else { /* no filtering */ ibuf_get_color(&texres->tr, ibuf, x, y); @@ -236,35 +236,35 @@ int imagewrap(Tex *tex, Image *ima, ImBuf *ibuf, const float texvec[3], TexResul * the normal used in the renderer points inward. It is generated * this way in calc_vertexnormals(). Should this ever change * this negate must be removed. */ - texres->nor[0] = -2.f*(texres->tr - 0.5f); - texres->nor[1] = 2.f*(texres->tg - 0.5f); - texres->nor[2] = 2.f*(texres->tb - 0.5f); + texres->nor[0] = -2.f * (texres->tr - 0.5f); + texres->nor[1] = 2.f * (texres->tg - 0.5f); + texres->nor[2] = 2.f * (texres->tb - 0.5f); } else { /* bump: take three samples */ - val1= texres->tr+texres->tg+texres->tb; + val1 = texres->tr + texres->tg + texres->tb; - if (x<ibuf->x-1) { + if (x < ibuf->x - 1) { float col[4]; - ibuf_get_color(col, ibuf, x+1, y); - val2= (col[0]+col[1]+col[2]); + ibuf_get_color(col, ibuf, x + 1, y); + val2 = (col[0] + col[1] + col[2]); } else { - val2= val1; + val2 = val1; } - if (y<ibuf->y-1) { + if (y < ibuf->y - 1) { float col[4]; - ibuf_get_color(col, ibuf, x, y+1); - val3 = (col[0]+col[1]+col[2]); + ibuf_get_color(col, ibuf, x, y + 1); + val3 = (col[0] + col[1] + col[2]); } else { val3 = val1; } /* do not mix up x and y here! */ - texres->nor[0]= (val1-val2); - texres->nor[1]= (val1-val3); + texres->nor[0] = (val1 - val2); + texres->nor[1] = (val1 - val3); } } @@ -284,11 +284,11 @@ int imagewrap(Tex *tex, Image *ima, ImBuf *ibuf, const float texvec[3], TexResul /* de-premul, this is being premulled in shade_input_do_shade() * do not de-premul for generated alpha, it is already in straight */ - if (texres->ta!=1.0f && texres->ta>1e-4f && !(tex->imaflag & TEX_CALCALPHA)) { - fx= 1.0f/texres->ta; - texres->tr*= fx; - texres->tg*= fx; - texres->tb*= fx; + if (texres->ta != 1.0f && texres->ta > 1e-4f && !(tex->imaflag & TEX_CALCALPHA)) { + fx = 1.0f / texres->ta; + texres->tr *= fx; + texres->tg *= fx; + texres->tb *= fx; } if (ima) @@ -304,45 +304,45 @@ static void clipx_rctf_swap(rctf *stack, short *count, float x1, float x2) rctf *rf, *newrct; short a; - a= *count; - rf= stack; - for (;a>0;a--) { - if (rf->xmin<x1) { - if (rf->xmax<x1) { - rf->xmin+= (x2-x1); - rf->xmax+= (x2-x1); + a = *count; + rf = stack; + for (; a > 0; a--) { + if (rf->xmin < x1) { + if (rf->xmax < x1) { + rf->xmin += (x2 - x1); + rf->xmax += (x2 - x1); } else { - if (rf->xmax>x2) rf->xmax = x2; - newrct= stack+ *count; + if (rf->xmax > x2) rf->xmax = x2; + newrct = stack + *count; (*count)++; newrct->xmax = x2; - newrct->xmin = rf->xmin+(x2-x1); + newrct->xmin = rf->xmin + (x2 - x1); newrct->ymin = rf->ymin; newrct->ymax = rf->ymax; - if (newrct->xmin ==newrct->xmax) (*count)--; + if (newrct->xmin == newrct->xmax) (*count)--; rf->xmin = x1; } } - else if (rf->xmax>x2) { - if (rf->xmin>x2) { - rf->xmin-= (x2-x1); - rf->xmax-= (x2-x1); + else if (rf->xmax > x2) { + if (rf->xmin > x2) { + rf->xmin -= (x2 - x1); + rf->xmax -= (x2 - x1); } else { - if (rf->xmin<x1) rf->xmin = x1; - newrct= stack+ *count; + if (rf->xmin < x1) rf->xmin = x1; + newrct = stack + *count; (*count)++; newrct->xmin = x1; - newrct->xmax = rf->xmax-(x2-x1); + newrct->xmax = rf->xmax - (x2 - x1); newrct->ymin = rf->ymin; newrct->ymax = rf->ymax; - if (newrct->xmin ==newrct->xmax) (*count)--; + if (newrct->xmin == newrct->xmax) (*count)--; rf->xmax = x2; } @@ -357,45 +357,45 @@ static void clipy_rctf_swap(rctf *stack, short *count, float y1, float y2) rctf *rf, *newrct; short a; - a= *count; - rf= stack; - for (;a>0;a--) { - if (rf->ymin<y1) { - if (rf->ymax<y1) { - rf->ymin+= (y2-y1); - rf->ymax+= (y2-y1); + a = *count; + rf = stack; + for (; a > 0; a--) { + if (rf->ymin < y1) { + if (rf->ymax < y1) { + rf->ymin += (y2 - y1); + rf->ymax += (y2 - y1); } else { - if (rf->ymax>y2) rf->ymax = y2; - newrct= stack+ *count; + if (rf->ymax > y2) rf->ymax = y2; + newrct = stack + *count; (*count)++; newrct->ymax = y2; - newrct->ymin = rf->ymin+(y2-y1); + newrct->ymin = rf->ymin + (y2 - y1); newrct->xmin = rf->xmin; newrct->xmax = rf->xmax; - if (newrct->ymin==newrct->ymax) (*count)--; + if (newrct->ymin == newrct->ymax) (*count)--; rf->ymin = y1; } } - else if (rf->ymax>y2) { - if (rf->ymin>y2) { - rf->ymin-= (y2-y1); - rf->ymax-= (y2-y1); + else if (rf->ymax > y2) { + if (rf->ymin > y2) { + rf->ymin -= (y2 - y1); + rf->ymax -= (y2 - y1); } else { - if (rf->ymin<y1) rf->ymin = y1; - newrct= stack+ *count; + if (rf->ymin < y1) rf->ymin = y1; + newrct = stack + *count; (*count)++; newrct->ymin = y1; - newrct->ymax = rf->ymax-(y2-y1); + newrct->ymax = rf->ymax - (y2 - y1); newrct->xmin = rf->xmin; newrct->xmax = rf->xmax; - if (newrct->ymin==newrct->ymax) (*count)--; + if (newrct->ymin == newrct->ymax) (*count)--; rf->ymax = y2; } @@ -419,10 +419,10 @@ static float clipx_rctf(rctf *rf, float x1, float x2) size = BLI_rctf_size_x(rf); - if (rf->xmin<x1) { + if (rf->xmin < x1) { rf->xmin = x1; } - if (rf->xmax>x2) { + if (rf->xmax > x2) { rf->xmax = x2; } if (rf->xmin > rf->xmax) { @@ -441,10 +441,10 @@ static float clipy_rctf(rctf *rf, float y1, float y2) size = BLI_rctf_size_y(rf); - if (rf->ymin<y1) { + if (rf->ymin < y1) { rf->ymin = y1; } - if (rf->ymax>y2) { + if (rf->ymax > y2) { rf->ymax = y2; } @@ -467,79 +467,79 @@ static void boxsampleclip(struct ImBuf *ibuf, rctf *rf, TexResult *texres) float muly, mulx, div, col[4]; int x, y, startx, endx, starty, endy; - startx= (int)floor(rf->xmin); - endx= (int)floor(rf->xmax); - starty= (int)floor(rf->ymin); - endy= (int)floor(rf->ymax); + startx = (int)floor(rf->xmin); + endx = (int)floor(rf->xmax); + starty = (int)floor(rf->ymin); + endy = (int)floor(rf->ymax); - if (startx < 0) startx= 0; - if (starty < 0) starty= 0; - if (endx>=ibuf->x) endx= ibuf->x-1; - if (endy>=ibuf->y) endy= ibuf->y-1; + if (startx < 0) startx = 0; + if (starty < 0) starty = 0; + if (endx >= ibuf->x) endx = ibuf->x - 1; + if (endy >= ibuf->y) endy = ibuf->y - 1; - if (starty==endy && startx==endx) { + if (starty == endy && startx == endx) { ibuf_get_color(&texres->tr, ibuf, startx, starty); } else { - div= texres->tr= texres->tg= texres->tb= texres->ta= 0.0; - for (y=starty; y<=endy; y++) { + div = texres->tr = texres->tg = texres->tb = texres->ta = 0.0; + for (y = starty; y <= endy; y++) { - muly= 1.0; + muly = 1.0; - if (starty==endy) { + if (starty == endy) { /* pass */ } else { - if (y==starty) muly= 1.0f-(rf->ymin - y); - if (y==endy) muly= (rf->ymax - y); + if (y == starty) muly = 1.0f - (rf->ymin - y); + if (y == endy) muly = (rf->ymax - y); } - if (startx==endx) { - mulx= muly; + if (startx == endx) { + mulx = muly; ibuf_get_color(col, ibuf, startx, y); - texres->ta+= mulx*col[3]; - texres->tr+= mulx*col[0]; - texres->tg+= mulx*col[1]; - texres->tb+= mulx*col[2]; - div+= mulx; + texres->ta += mulx * col[3]; + texres->tr += mulx * col[0]; + texres->tg += mulx * col[1]; + texres->tb += mulx * col[2]; + div += mulx; } else { - for (x=startx; x<=endx; x++) { - mulx= muly; - if (x==startx) mulx*= 1.0f-(rf->xmin - x); - if (x==endx) mulx*= (rf->xmax - x); + for (x = startx; x <= endx; x++) { + mulx = muly; + if (x == startx) mulx *= 1.0f - (rf->xmin - x); + if (x == endx) mulx *= (rf->xmax - x); ibuf_get_color(col, ibuf, x, y); - if (mulx==1.0f) { - texres->ta+= col[3]; - texres->tr+= col[0]; - texres->tg+= col[1]; - texres->tb+= col[2]; - div+= 1.0f; + if (mulx == 1.0f) { + texres->ta += col[3]; + texres->tr += col[0]; + texres->tg += col[1]; + texres->tb += col[2]; + div += 1.0f; } else { - texres->ta+= mulx*col[3]; - texres->tr+= mulx*col[0]; - texres->tg+= mulx*col[1]; - texres->tb+= mulx*col[2]; - div+= mulx; + texres->ta += mulx * col[3]; + texres->tr += mulx * col[0]; + texres->tg += mulx * col[1]; + texres->tb += mulx * col[2]; + div += mulx; } } } } - if (div!=0.0f) { - div= 1.0f/div; - texres->tb*= div; - texres->tg*= div; - texres->tr*= div; - texres->ta*= div; + if (div != 0.0f) { + div = 1.0f / div; + texres->tb *= div; + texres->tg *= div; + texres->tr *= div; + texres->ta *= div; } else { - texres->tr= texres->tg= texres->tb= texres->ta= 0.0f; + texres->tr = texres->tg = texres->tb = texres->ta = 0.0f; } } } @@ -557,79 +557,79 @@ static void boxsample(ImBuf *ibuf, float minx, float miny, float maxx, float max * the point which min/max is derived from is assumed to be wrapped */ TexResult texr; rctf *rf, stack[8]; - float opp, tot, alphaclip= 1.0; - short count=1; + float opp, tot, alphaclip = 1.0; + short count = 1; - rf= stack; - rf->xmin = minx*(ibuf->x); - rf->xmax = maxx*(ibuf->x); - rf->ymin = miny*(ibuf->y); - rf->ymax = maxy*(ibuf->y); + rf = stack; + rf->xmin = minx * (ibuf->x); + rf->xmax = maxx * (ibuf->x); + rf->ymin = miny * (ibuf->y); + rf->ymax = maxy * (ibuf->y); - texr.talpha= texres->talpha; /* is read by boxsample_clip */ + texr.talpha = texres->talpha; /* is read by boxsample_clip */ if (imapextend) { - CLAMP(rf->xmin, 0.0f, ibuf->x-1); - CLAMP(rf->xmax, 0.0f, ibuf->x-1); + CLAMP(rf->xmin, 0.0f, ibuf->x - 1); + CLAMP(rf->xmax, 0.0f, ibuf->x - 1); } else if (imaprepeat) clipx_rctf_swap(stack, &count, 0.0, (float)(ibuf->x)); else { - alphaclip= clipx_rctf(rf, 0.0, (float)(ibuf->x)); + alphaclip = clipx_rctf(rf, 0.0, (float)(ibuf->x)); - if (alphaclip<=0.0f) { - texres->tr= texres->tb= texres->tg= texres->ta= 0.0; + if (alphaclip <= 0.0f) { + texres->tr = texres->tb = texres->tg = texres->ta = 0.0; return; } } if (imapextend) { - CLAMP(rf->ymin, 0.0f, ibuf->y-1); - CLAMP(rf->ymax, 0.0f, ibuf->y-1); + CLAMP(rf->ymin, 0.0f, ibuf->y - 1); + CLAMP(rf->ymax, 0.0f, ibuf->y - 1); } else if (imaprepeat) clipy_rctf_swap(stack, &count, 0.0, (float)(ibuf->y)); else { - alphaclip*= clipy_rctf(rf, 0.0, (float)(ibuf->y)); + alphaclip *= clipy_rctf(rf, 0.0, (float)(ibuf->y)); - if (alphaclip<=0.0f) { - texres->tr= texres->tb= texres->tg= texres->ta= 0.0; + if (alphaclip <= 0.0f) { + texres->tr = texres->tb = texres->tg = texres->ta = 0.0; return; } } - if (count>1) { - tot= texres->tr= texres->tb= texres->tg= texres->ta= 0.0; + if (count > 1) { + tot = texres->tr = texres->tb = texres->tg = texres->ta = 0.0; while (count--) { boxsampleclip(ibuf, rf, &texr); - opp= square_rctf(rf); - tot+= opp; + opp = square_rctf(rf); + tot += opp; - texres->tr+= opp*texr.tr; - texres->tg+= opp*texr.tg; - texres->tb+= opp*texr.tb; - if (texres->talpha) texres->ta+= opp*texr.ta; + texres->tr += opp * texr.tr; + texres->tg += opp * texr.tg; + texres->tb += opp * texr.tb; + if (texres->talpha) texres->ta += opp * texr.ta; rf++; } - if (tot!= 0.0f) { - texres->tr/= tot; - texres->tg/= tot; - texres->tb/= tot; - if (texres->talpha) texres->ta/= tot; + if (tot != 0.0f) { + texres->tr /= tot; + texres->tg /= tot; + texres->tb /= tot; + if (texres->talpha) texres->ta /= tot; } } else boxsampleclip(ibuf, rf, texres); - if (texres->talpha==0) texres->ta= 1.0; + if (texres->talpha == 0) texres->ta = 1.0; - if (alphaclip!=1.0f) { + if (alphaclip != 1.0f) { /* premul it all */ - texres->tr*= alphaclip; - texres->tg*= alphaclip; - texres->tb*= alphaclip; - texres->ta*= alphaclip; + texres->tr *= alphaclip; + texres->tg *= alphaclip; + texres->tb *= alphaclip; + texres->ta *= alphaclip; } } @@ -655,19 +655,19 @@ static int ibuf_get_color_clip(float col[4], ImBuf *ibuf, int x, int y, int extf { int clip = 0; switch (extflag) { - case TXC_XMIR: /* y rep */ - x %= 2*ibuf->x; - x += x < 0 ? 2*ibuf->x : 0; - x = x >= ibuf->x ? 2*ibuf->x - x - 1 : x; + case TXC_XMIR: /* y rep */ + x %= 2 * ibuf->x; + x += x < 0 ? 2 * ibuf->x : 0; + x = x >= ibuf->x ? 2 * ibuf->x - x - 1 : x; y %= ibuf->y; y += y < 0 ? ibuf->y : 0; break; - case TXC_YMIR: /* x rep */ + case TXC_YMIR: /* x rep */ x %= ibuf->x; x += x < 0 ? ibuf->x : 0; - y %= 2*ibuf->y; - y += y < 0 ? 2*ibuf->y : 0; - y = y >= ibuf->y ? 2*ibuf->y - y - 1 : y; + y %= 2 * ibuf->y; + y += y < 0 ? 2 * ibuf->y : 0; + y = y >= ibuf->y ? 2 * ibuf->y - y - 1 : y; break; case TXC_EXTD: x = (x < 0) ? 0 : ((x >= ibuf->x) ? (ibuf->x - 1) : x); @@ -680,7 +680,7 @@ static int ibuf_get_color_clip(float col[4], ImBuf *ibuf, int x, int y, int extf y += (y < 0) ? ibuf->y : 0; break; default: - { /* as extend, if clipped, set alpha to 0.0 */ + { /* as extend, if clipped, set alpha to 0.0 */ if (x < 0) { x = 0; } /* TXF alpha: clip = 1; } */ if (x >= ibuf->x) { x = ibuf->x - 1; } /* TXF alpha: clip = 1; } */ if (y < 0) { y = 0; } /* TXF alpha: clip = 1; } */ @@ -700,12 +700,12 @@ static int ibuf_get_color_clip(float col[4], ImBuf *ibuf, int x, int y, int extf } } else { - const char *rect = (char *)(ibuf->rect + x + y*ibuf->x); + const char *rect = (char *)(ibuf->rect + x + y * ibuf->x); float inv_alpha_fac = (1.0f / 255.0f) * rect[3] * (1.0f / 255.0f); col[0] = rect[0] * inv_alpha_fac; col[1] = rect[1] * inv_alpha_fac; col[2] = rect[2] * inv_alpha_fac; - col[3] = clip ? 0.f : rect[3]*(1.f/255.f); + col[3] = clip ? 0.f : rect[3] * (1.f / 255.f); } return clip; } @@ -717,16 +717,16 @@ static int ibuf_get_color_clip_bilerp(float col[4], ImBuf *ibuf, float u, float float c00[4], c01[4], c10[4], c11[4]; const float ufl = floorf(u -= 0.5f), vfl = floorf(v -= 0.5f); const float uf = u - ufl, vf = v - vfl; - const float w00=(1.f-uf)*(1.f-vf), w10=uf*(1.f-vf), w01=(1.f-uf)*vf, w11=uf*vf; + const float w00 = (1.f - uf) * (1.f - vf), w10 = uf * (1.f - vf), w01 = (1.f - uf) * vf, w11 = uf * vf; const int x1 = (int)ufl, y1 = (int)vfl, x2 = x1 + 1, y2 = y1 + 1; int clip = ibuf_get_color_clip(c00, ibuf, x1, y1, extflag); clip |= ibuf_get_color_clip(c10, ibuf, x2, y1, extflag); clip |= ibuf_get_color_clip(c01, ibuf, x1, y2, extflag); clip |= ibuf_get_color_clip(c11, ibuf, x2, y2, extflag); - col[0] = w00*c00[0] + w10*c10[0] + w01*c01[0] + w11*c11[0]; - col[1] = w00*c00[1] + w10*c10[1] + w01*c01[1] + w11*c11[1]; - col[2] = w00*c00[2] + w10*c10[2] + w01*c01[2] + w11*c11[2]; - col[3] = clip ? 0.f : w00*c00[3] + w10*c10[3] + w01*c01[3] + w11*c11[3]; + col[0] = w00 * c00[0] + w10 * c10[0] + w01 * c01[0] + w11 * c11[0]; + col[1] = w00 * c00[1] + w10 * c10[1] + w01 * c01[1] + w11 * c11[1]; + col[2] = w00 * c00[2] + w10 * c10[2] + w01 * c01[2] + w11 * c11[2]; + col[3] = clip ? 0.f : w00 * c00[3] + w10 * c10[3] + w01 * c01[3] + w11 * c11[3]; return clip; } return ibuf_get_color_clip(col, ibuf, (int)u, (int)v, extflag); @@ -736,23 +736,23 @@ static void area_sample(TexResult *texr, ImBuf *ibuf, float fx, float fy, afdata { int xs, ys, clip = 0; float tc[4], xsd, ysd, cw = 0.f; - const float ux = ibuf->x*AFD->dxt[0], uy = ibuf->y*AFD->dxt[1]; - const float vx = ibuf->x*AFD->dyt[0], vy = ibuf->y*AFD->dyt[1]; - int xsam = (int)(0.5f*sqrtf(ux*ux + uy*uy) + 0.5f); - int ysam = (int)(0.5f*sqrtf(vx*vx + vy*vy) + 0.5f); + const float ux = ibuf->x * AFD->dxt[0], uy = ibuf->y * AFD->dxt[1]; + const float vx = ibuf->x * AFD->dyt[0], vy = ibuf->y * AFD->dyt[1]; + int xsam = (int)(0.5f * sqrtf(ux * ux + uy * uy) + 0.5f); + int ysam = (int)(0.5f * sqrtf(vx * vx + vy * vy) + 0.5f); const int minsam = AFD->intpol ? 2 : 4; - xsam = CLAMPIS(xsam, minsam, ibuf->x*2); - ysam = CLAMPIS(ysam, minsam, ibuf->y*2); + xsam = CLAMPIS(xsam, minsam, ibuf->x * 2); + ysam = CLAMPIS(ysam, minsam, ibuf->y * 2); xsd = 1.f / xsam; ysd = 1.f / ysam; texr->tr = texr->tg = texr->tb = texr->ta = 0.f; - for (ys=0; ys<ysam; ++ys) { - for (xs=0; xs<xsam; ++xs) { - const float su = (xs + ((ys & 1) + 0.5f)*0.5f)*xsd - 0.5f; - const float sv = (ys + ((xs & 1) + 0.5f)*0.5f)*ysd - 0.5f; - const float pu = fx + su*AFD->dxt[0] + sv*AFD->dyt[0]; - const float pv = fy + su*AFD->dxt[1] + sv*AFD->dyt[1]; - const int out = ibuf_get_color_clip_bilerp(tc, ibuf, pu*ibuf->x, pv*ibuf->y, AFD->intpol, AFD->extflag); + for (ys = 0; ys < ysam; ++ys) { + for (xs = 0; xs < xsam; ++xs) { + const float su = (xs + ((ys & 1) + 0.5f) * 0.5f) * xsd - 0.5f; + const float sv = (ys + ((xs & 1) + 0.5f) * 0.5f) * ysd - 0.5f; + const float pu = fx + su * AFD->dxt[0] + sv * AFD->dyt[0]; + const float pv = fy + su * AFD->dxt[1] + sv * AFD->dyt[1]; + const int out = ibuf_get_color_clip_bilerp(tc, ibuf, pu * ibuf->x, pv * ibuf->y, AFD->intpol, AFD->extflag); clip |= out; cw += out ? 0.f : 1.f; texr->tr += tc[0]; @@ -766,7 +766,7 @@ static void area_sample(TexResult *texr, ImBuf *ibuf, float fx, float fy, afdata texr->tg *= xsd; texr->tb *= xsd; /* clipping can be ignored if alpha used, texr->ta already includes filtered edge */ - texr->ta = texr->talpha ? texr->ta*xsd : (clip ? cw*xsd : 1.f); + texr->ta = texr->talpha ? texr->ta * xsd : (clip ? cw * xsd : 1.f); } typedef struct ReadEWAData { @@ -776,7 +776,7 @@ typedef struct ReadEWAData { static void ewa_read_pixel_cb(void *userdata, int x, int y, float result[4]) { - ReadEWAData *data = (ReadEWAData *) userdata; + ReadEWAData *data = (ReadEWAData *)userdata; ibuf_get_color_clip(result, data->ibuf, x, y, data->AFD->extflag); } @@ -799,40 +799,40 @@ static void ewa_eval(TexResult *texr, ImBuf *ibuf, float fx, float fy, afdata_t static void feline_eval(TexResult *texr, ImBuf *ibuf, float fx, float fy, afdata_t *AFD) { const int maxn = AFD->iProbes - 1; - const float ll = ((AFD->majrad == AFD->minrad) ? 2.f*AFD->majrad : 2.f*(AFD->majrad - AFD->minrad)) / (maxn ? (float)maxn : 1.f); - float du = maxn ? cosf(AFD->theta)*ll : 0.f; - float dv = maxn ? sinf(AFD->theta)*ll : 0.f; + const float ll = ((AFD->majrad == AFD->minrad) ? 2.f * AFD->majrad : 2.f * (AFD->majrad - AFD->minrad)) / (maxn ? (float)maxn : 1.f); + float du = maxn ? cosf(AFD->theta) * ll : 0.f; + float dv = maxn ? sinf(AFD->theta) * ll : 0.f; /* const float D = -0.5f*(du*du + dv*dv) / (AFD->majrad*AFD->majrad); */ - const float D = (EWA_MAXIDX + 1)*0.25f*(du*du + dv*dv) / (AFD->majrad*AFD->majrad); + const float D = (EWA_MAXIDX + 1) * 0.25f * (du * du + dv * dv) / (AFD->majrad * AFD->majrad); float d; /* TXF alpha: cw = 0.f; */ int n; /* TXF alpha: clip = 0; */ /* have to use same scaling for du/dv here as for Ux/Vx/Uy/Vy (*after* D calc.) */ du *= AFD->dusc; dv *= AFD->dvsc; d = texr->tr = texr->tb = texr->tg = texr->ta = 0.f; - for (n=-maxn; n<=maxn; n+=2) { + for (n = -maxn; n <= maxn; n += 2) { float tc[4]; - const float hn = n*0.5f; - const float u = fx + hn*du, v = fy + hn*dv; + const float hn = n * 0.5f; + const float u = fx + hn * du, v = fy + hn * dv; /*const float wt = expf(n*n*D); - * can use ewa table here too */ - const float wt = EWA_WTS[(int)(n*n*D)]; - /*const int out =*/ ibuf_get_color_clip_bilerp(tc, ibuf, ibuf->x*u, ibuf->y*v, AFD->intpol, AFD->extflag); + * can use ewa table here too */ + const float wt = EWA_WTS[(int)(n * n * D)]; + /*const int out =*/ ibuf_get_color_clip_bilerp(tc, ibuf, ibuf->x * u, ibuf->y * v, AFD->intpol, AFD->extflag); /* TXF alpha: clip |= out; * TXF alpha: cw += out ? 0.f : wt; */ - texr->tr += tc[0]*wt; - texr->tg += tc[1]*wt; - texr->tb += tc[2]*wt; - texr->ta += texr->talpha ? tc[3]*wt : 0.f; + texr->tr += tc[0] * wt; + texr->tg += tc[1] * wt; + texr->tb += tc[2] * wt; + texr->ta += texr->talpha ? tc[3] * wt : 0.f; d += wt; } - d = 1.f/d; + d = 1.f / d; texr->tr *= d; texr->tg *= d; texr->tb *= d; /* clipping can be ignored if alpha used, texr->ta already includes filtered edge */ - texr->ta = texr->talpha ? texr->ta*d : 1.f; // TXF alpha: (clip ? cw*d : 1.f); + texr->ta = texr->talpha ? texr->ta * d : 1.f; // TXF alpha: (clip ? cw*d : 1.f); } #undef EWA_MAXIDX @@ -845,21 +845,21 @@ static void alpha_clip_aniso(ImBuf *ibuf, float minx, float miny, float maxx, fl * if this is actually correct for the all the filtering algorithms .. */ if (!(extflag == TXC_REPT || extflag == TXC_EXTD)) { - rf.xmin = minx*(ibuf->x); - rf.xmax = maxx*(ibuf->x); - rf.ymin = miny*(ibuf->y); - rf.ymax = maxy*(ibuf->y); + rf.xmin = minx * (ibuf->x); + rf.xmax = maxx * (ibuf->x); + rf.ymin = miny * (ibuf->y); + rf.ymax = maxy * (ibuf->y); alphaclip = clipx_rctf(&rf, 0.0, (float)(ibuf->x)); alphaclip *= clipy_rctf(&rf, 0.0, (float)(ibuf->y)); alphaclip = max_ff(alphaclip, 0.0f); - if (alphaclip!=1.0f) { + if (alphaclip != 1.0f) { /* premul it all */ - texres->tr*= alphaclip; - texres->tg*= alphaclip; - texres->tb*= alphaclip; - texres->ta*= alphaclip; + texres->tr *= alphaclip; + texres->tg *= alphaclip; + texres->tb *= alphaclip; + texres->ta *= alphaclip; } } } @@ -896,7 +896,7 @@ static int imagewraposa_aniso(Tex *tex, Image *ima, ImBuf *ibuf, const float tex int curmap, retval, intpol, extflag = 0; afdata_t AFD; - void (*filterfunc)(TexResult*, ImBuf*, float, float, afdata_t*); + void (*filterfunc)(TexResult *, ImBuf *, float, float, afdata_t *); switch (tex->texfilter) { case TXF_EWA: filterfunc = ewa_eval; @@ -915,9 +915,9 @@ static int imagewraposa_aniso(Tex *tex, Image *ima, ImBuf *ibuf, const float tex retval = texres->nor ? 3 : 1; /* quick tests */ - if (ibuf==NULL && ima==NULL) return retval; + if (ibuf == NULL && ima == NULL) return retval; - if (ima) { /* hack for icon render */ + if (ima) { /* hack for icon render */ if (skip_load_image && !BKE_image_has_loaded_ibuf(ima)) { return retval; } @@ -962,8 +962,8 @@ static int imagewraposa_aniso(Tex *tex, Image *ima, ImBuf *ibuf, const float tex maxy = max_fff(dxt[1], dyt[1], dxt[1] + dyt[1]); /* tex_sharper has been removed */ - minx = (maxx - minx)*0.5f; - miny = (maxy - miny)*0.5f; + minx = (maxx - minx) * 0.5f; + miny = (maxy - miny) * 0.5f; if (tex->imaflag & TEX_FILTER_MIN) { /* make sure the filtersize is minimal in pixels (normal, ref map can have miniature pixel dx/dy) */ @@ -1060,8 +1060,8 @@ static int imagewraposa_aniso(Tex *tex, Image *ima, ImBuf *ibuf, const float tex /* scale around center, (0.5, 0.5) */ if (tex->checkerdist < 1.f) { const float omcd = 1.f / (1.f - tex->checkerdist); - fx = (fx - 0.5f)*omcd + 0.5f; - fy = (fy - 0.5f)*omcd + 0.5f; + fx = (fx - 0.5f) * omcd + 0.5f; + fy = (fy - 0.5f) * omcd + 0.5f; minx *= omcd; miny *= omcd; } @@ -1103,10 +1103,10 @@ static int imagewraposa_aniso(Tex *tex, Image *ima, ImBuf *ibuf, const float tex /* brecht: added stupid clamping here, large dx/dy can give very large * filter sizes which take ages to render, it may be better to do this * more intelligently later in the code .. probably it's not noticeable */ - if (AFD.dxt[0]*AFD.dxt[0] + AFD.dxt[1]*AFD.dxt[1] > 2.0f*2.0f) - mul_v2_fl(AFD.dxt, 2.0f/len_v2(AFD.dxt)); - if (AFD.dyt[0]*AFD.dyt[0] + AFD.dyt[1]*AFD.dyt[1] > 2.0f*2.0f) - mul_v2_fl(AFD.dyt, 2.0f/len_v2(AFD.dyt)); + if (AFD.dxt[0] * AFD.dxt[0] + AFD.dxt[1] * AFD.dxt[1] > 2.0f * 2.0f) + mul_v2_fl(AFD.dxt, 2.0f / len_v2(AFD.dxt)); + if (AFD.dyt[0] * AFD.dyt[0] + AFD.dyt[1] * AFD.dyt[1] > 2.0f * 2.0f) + mul_v2_fl(AFD.dyt, 2.0f / len_v2(AFD.dyt)); /* choice: */ if (tex->imaflag & TEX_MIPMAP) { @@ -1118,12 +1118,12 @@ static int imagewraposa_aniso(Tex *tex, Image *ima, ImBuf *ibuf, const float tex /* modify ellipse minor axis if too eccentric, use for area sampling as well * scaling dxt/dyt as done in pbrt is not the same * (as in ewa_eval(), scale by sqrt(ibuf->x) to maximize precision) */ - const float ff = sqrtf(ibuf->x), q = ibuf->y/ff; - const float Ux = dxt[0]*ff, Vx = dxt[1]*q, Uy = dyt[0]*ff, Vy = dyt[1]*q; - const float A = Vx*Vx + Vy*Vy; - const float B = -2.f*(Ux*Vx + Uy*Vy); - const float C = Ux*Ux + Uy*Uy; - const float F = A*C - B*B*0.25f; + const float ff = sqrtf(ibuf->x), q = ibuf->y / ff; + const float Ux = dxt[0] * ff, Vx = dxt[1] * q, Uy = dyt[0] * ff, Vy = dyt[1] * q; + const float A = Vx * Vx + Vy * Vy; + const float B = -2.f * (Ux * Vx + Uy * Vy); + const float C = Ux * Ux + Uy * Uy; + const float F = A * C - B * B * 0.25f; float a, b, th, ecc; BLI_ewa_imp2radangle(A, B, C, F, &a, &b, &th, &ecc); if (tex->texfilter == TXF_FELINE) { @@ -1132,18 +1132,18 @@ static int imagewraposa_aniso(Tex *tex, Image *ima, ImBuf *ibuf, const float tex b *= ff; a = max_ff(a, 1.0f); b = max_ff(b, 1.0f); - fProbes = 2.f*(a / b) - 1.f; + fProbes = 2.f * (a / b) - 1.f; AFD.iProbes = round_fl_to_int(fProbes); AFD.iProbes = MIN2(AFD.iProbes, tex->afmax); if (AFD.iProbes < fProbes) - b = 2.f*a / (float)(AFD.iProbes + 1); - AFD.majrad = a/ff; - AFD.minrad = b/ff; + b = 2.f * a / (float)(AFD.iProbes + 1); + AFD.majrad = a / ff; + AFD.minrad = b / ff; AFD.theta = th; - AFD.dusc = 1.f/ff; + AFD.dusc = 1.f / ff; AFD.dvsc = ff / (float)ibuf->y; } - else { /* EWA & area */ + else { /* EWA & area */ if (ecc > (float)tex->afmax) b = a / (float)tex->afmax; b *= ff; } @@ -1192,16 +1192,16 @@ static int imagewraposa_aniso(Tex *tex, Image *ima, ImBuf *ibuf, const float tex if (previbuf != curibuf) { /* interpolate */ filterfunc(&texr, previbuf, fx, fy, &AFD); /* rgb */ - texres->tr += levf*(texr.tr - texres->tr); - texres->tg += levf*(texr.tg - texres->tg); - texres->tb += levf*(texr.tb - texres->tb); - texres->ta += levf*(texr.ta - texres->ta); + texres->tr += levf * (texr.tr - texres->tr); + texres->tg += levf * (texr.tg - texres->tg); + texres->tb += levf * (texr.tb - texres->tb); + texres->ta += levf * (texr.ta - texres->ta); /* normal */ - val1 += levf*((texr.tr + texr.tg + texr.tb) - val1); + val1 += levf * ((texr.tr + texr.tg + texr.tb) - val1); filterfunc(&texr, previbuf, fx + dxt[0], fy + dxt[1], &AFD); - val2 += levf*((texr.tr + texr.tg + texr.tb) - val2); + val2 += levf * ((texr.tr + texr.tg + texr.tb) - val2); filterfunc(&texr, previbuf, fx + dyt[0], fy + dyt[1], &AFD); - val3 += levf*((texr.tr + texr.tg + texr.tb) - val3); + val3 += levf * ((texr.tr + texr.tg + texr.tb) - val3); texres->nor[0] = val1 - val2; /* vals have been interpolated above! */ texres->nor[1] = val1 - val3; } @@ -1210,40 +1210,40 @@ static int imagewraposa_aniso(Tex *tex, Image *ima, ImBuf *ibuf, const float tex filterfunc(texres, curibuf, fx, fy, &AFD); if (previbuf != curibuf) { /* interpolate */ filterfunc(&texr, previbuf, fx, fy, &AFD); - texres->tr += levf*(texr.tr - texres->tr); - texres->tg += levf*(texr.tg - texres->tg); - texres->tb += levf*(texr.tb - texres->tb); - texres->ta += levf*(texr.ta - texres->ta); + texres->tr += levf * (texr.tr - texres->tr); + texres->tg += levf * (texr.tg - texres->tg); + texres->tb += levf * (texr.tb - texres->tb); + texres->ta += levf * (texr.ta - texres->ta); } if (tex->texfilter != TXF_EWA) { - alpha_clip_aniso(ibuf, fx-minx, fy-miny, fx+minx, fy+miny, extflag, texres); + alpha_clip_aniso(ibuf, fx - minx, fy - miny, fx + minx, fy + miny, extflag, texres); } } } - else { /* no mipmap */ + else { /* no mipmap */ /* filter functions take care of interpolation themselves, no need to modify dxt/dyt here */ if (tex->texfilter == TXF_FELINE) { - const float ff = sqrtf(ibuf->x), q = ibuf->y/ff; - const float Ux = dxt[0]*ff, Vx = dxt[1]*q, Uy = dyt[0]*ff, Vy = dyt[1]*q; - const float A = Vx*Vx + Vy*Vy; - const float B = -2.f*(Ux*Vx + Uy*Vy); - const float C = Ux*Ux + Uy*Uy; - const float F = A*C - B*B*0.25f; + const float ff = sqrtf(ibuf->x), q = ibuf->y / ff; + const float Ux = dxt[0] * ff, Vx = dxt[1] * q, Uy = dyt[0] * ff, Vy = dyt[1] * q; + const float A = Vx * Vx + Vy * Vy; + const float B = -2.f * (Ux * Vx + Uy * Vy); + const float C = Ux * Ux + Uy * Uy; + const float F = A * C - B * B * 0.25f; float a, b, th, ecc, fProbes; BLI_ewa_imp2radangle(A, B, C, F, &a, &b, &th, &ecc); a *= ff; b *= ff; a = max_ff(a, 1.0f); b = max_ff(b, 1.0f); - fProbes = 2.f*(a / b) - 1.f; + fProbes = 2.f * (a / b) - 1.f; /* no limit to number of Probes here */ AFD.iProbes = round_fl_to_int(fProbes); - if (AFD.iProbes < fProbes) b = 2.f*a / (float)(AFD.iProbes + 1); - AFD.majrad = a/ff; - AFD.minrad = b/ff; + if (AFD.iProbes < fProbes) b = 2.f * a / (float)(AFD.iProbes + 1); + AFD.majrad = a / ff; + AFD.minrad = b / ff; AFD.theta = th; - AFD.dusc = 1.f/ff; + AFD.dusc = 1.f / ff; AFD.dvsc = ff / (float)ibuf->y; } if (texres->nor && ((tex->imaflag & TEX_NORMALMAP) == 0)) { @@ -1261,7 +1261,7 @@ static int imagewraposa_aniso(Tex *tex, Image *ima, ImBuf *ibuf, const float tex else { filterfunc(texres, ibuf, fx, fy, &AFD); if (tex->texfilter != TXF_EWA) { - alpha_clip_aniso(ibuf, fx-minx, fy-miny, fx+minx, fy+miny, extflag, texres); + alpha_clip_aniso(ibuf, fx - minx, fy - miny, fx + minx, fy + miny, extflag, texres); } } } @@ -1272,16 +1272,16 @@ static int imagewraposa_aniso(Tex *tex, Image *ima, ImBuf *ibuf, const float tex texres->tin = texres->ta; if (tex->flag & TEX_NEGALPHA) texres->ta = 1.f - texres->ta; - if (texres->nor && (tex->imaflag & TEX_NORMALMAP)) { /* normal from color */ + if (texres->nor && (tex->imaflag & TEX_NORMALMAP)) { /* normal from color */ /* The invert of the red channel is to make * the normal map compliant with the outside world. * It needs to be done because in Blender * the normal used in the renderer points inward. It is generated * this way in calc_vertexnormals(). Should this ever change * this negate must be removed. */ - texres->nor[0] = -2.f*(texres->tr - 0.5f); - texres->nor[1] = 2.f*(texres->tg - 0.5f); - texres->nor[2] = 2.f*(texres->tb - 0.5f); + texres->nor[0] = -2.f * (texres->tr - 0.5f); + texres->nor[1] = 2.f * (texres->tg - 0.5f); + texres->nor[2] = 2.f * (texres->tb - 0.5f); } /* de-premul, this is being premulled in shade_input_do_shade() @@ -1291,8 +1291,8 @@ static int imagewraposa_aniso(Tex *tex, Image *ima, ImBuf *ibuf, const float tex /* brecht: tried to fix this, see "TXF alpha" comments */ /* do not de-premul for generated alpha, it is already in straight */ - if (texres->ta!=1.0f && texres->ta>1e-4f && !(tex->imaflag & TEX_CALCALPHA)) { - fx = 1.f/texres->ta; + if (texres->ta != 1.0f && texres->ta > 1e-4f && !(tex->imaflag & TEX_CALCALPHA)) { + fx = 1.f / texres->ta; texres->tr *= fx; texres->tg *= fx; texres->tb *= fx; @@ -1323,13 +1323,13 @@ int imagewraposa(Tex *tex, Image *ima, ImBuf *ibuf, const float texvec[3], const if (tex->texfilter != TXF_BOX) return imagewraposa_aniso(tex, ima, ibuf, texvec, dxt, dyt, texres, pool, skip_load_image); - texres->tin= texres->ta= texres->tr= texres->tg= texres->tb= 0.0f; + texres->tin = texres->ta = texres->tr = texres->tg = texres->tb = 0.0f; /* we need to set retval OK, otherwise texture code generates normals itself... */ retval = texres->nor ? 3 : 1; /* quick tests */ - if (ibuf==NULL && ima==NULL) + if (ibuf == NULL && ima == NULL) return retval; if (ima) { @@ -1339,9 +1339,9 @@ int imagewraposa(Tex *tex, Image *ima, ImBuf *ibuf, const float texvec[3], const ibuf = BKE_image_pool_acquire_ibuf(ima, &tex->iuser, pool); - ima->flag|= IMA_USED_FOR_RENDER; + ima->flag |= IMA_USED_FOR_RENDER; } - if (ibuf==NULL || (ibuf->rect==NULL && ibuf->rect_float==NULL)) { + if (ibuf == NULL || (ibuf->rect == NULL && ibuf->rect_float == NULL)) { if (ima) BKE_image_pool_release_ibuf(ima, ibuf, pool); return retval; @@ -1358,15 +1358,15 @@ int imagewraposa(Tex *tex, Image *ima, ImBuf *ibuf, const float texvec[3], const } } - texr.talpha= texres->talpha; + texr.talpha = texres->talpha; if (tex->imaflag & TEX_IMAROT) { - fy= texvec[0]; - fx= texvec[1]; + fy = texvec[0]; + fx = texvec[1]; } else { - fx= texvec[0]; - fy= texvec[1]; + fx = texvec[0]; + fy = texvec[1]; } /* pixel coordinates */ @@ -1377,57 +1377,57 @@ int imagewraposa(Tex *tex, Image *ima, ImBuf *ibuf, const float texvec[3], const maxy = max_fff(dxt[1], dyt[1], dxt[1] + dyt[1]); /* tex_sharper has been removed */ - minx= (maxx-minx)/2.0f; - miny= (maxy-miny)/2.0f; + minx = (maxx - minx) / 2.0f; + miny = (maxy - miny) / 2.0f; if (tex->imaflag & TEX_FILTER_MIN) { /* make sure the filtersize is minimal in pixels (normal, ref map can have miniature pixel dx/dy) */ - float addval= (0.5f * tex->filtersize) / (float) MIN2(ibuf->x, ibuf->y); + float addval = (0.5f * tex->filtersize) / (float)MIN2(ibuf->x, ibuf->y); if (addval > minx) - minx= addval; + minx = addval; if (addval > miny) - miny= addval; + miny = addval; } - else if (tex->filtersize!=1.0f) { - minx*= tex->filtersize; - miny*= tex->filtersize; + else if (tex->filtersize != 1.0f) { + minx *= tex->filtersize; + miny *= tex->filtersize; - dxt[0]*= tex->filtersize; - dxt[1]*= tex->filtersize; - dyt[0]*= tex->filtersize; - dyt[1]*= tex->filtersize; + dxt[0] *= tex->filtersize; + dxt[1] *= tex->filtersize; + dyt[0] *= tex->filtersize; + dyt[1] *= tex->filtersize; } if (tex->imaflag & TEX_IMAROT) SWAP(float, minx, miny); - if (minx>0.25f) minx= 0.25f; - else if (minx<0.00001f) minx= 0.00001f; /* side faces of unit-cube */ - if (miny>0.25f) miny= 0.25f; - else if (miny<0.00001f) miny= 0.00001f; + if (minx > 0.25f) minx = 0.25f; + else if (minx < 0.00001f) minx = 0.00001f; /* side faces of unit-cube */ + if (miny > 0.25f) miny = 0.25f; + else if (miny < 0.00001f) miny = 0.00001f; /* repeat and clip */ - imaprepeat= (tex->extend==TEX_REPEAT); - imapextend= (tex->extend==TEX_EXTEND); + imaprepeat = (tex->extend == TEX_REPEAT); + imapextend = (tex->extend == TEX_EXTEND); if (tex->extend == TEX_REPEAT) { - if (tex->flag & (TEX_REPEAT_XMIR|TEX_REPEAT_YMIR)) { - imaprepeat= 0; - imapextend= 1; + if (tex->flag & (TEX_REPEAT_XMIR | TEX_REPEAT_YMIR)) { + imaprepeat = 0; + imapextend = 1; } } if (tex->extend == TEX_CHECKER) { int xs, ys, xs1, ys1, xs2, ys2, boundary; - xs= (int)floor(fx); - ys= (int)floor(fy); + xs = (int)floor(fx); + ys = (int)floor(fy); /* both checkers available, no boundary exceptions, checkerdist will eat aliasing */ if ( (tex->flag & TEX_CHECKER_ODD) && (tex->flag & TEX_CHECKER_EVEN) ) { - fx-= xs; - fy-= ys; + fx -= xs; + fy -= ys; } else if ((tex->flag & TEX_CHECKER_ODD) == 0 && (tex->flag & TEX_CHECKER_EVEN) == 0) @@ -1438,14 +1438,14 @@ int imagewraposa(Tex *tex, Image *ima, ImBuf *ibuf, const float texvec[3], const } else { - xs1= (int)floor(fx-minx); - ys1= (int)floor(fy-miny); - xs2= (int)floor(fx+minx); - ys2= (int)floor(fy+miny); - boundary= (xs1!=xs2) || (ys1!=ys2); + xs1 = (int)floor(fx - minx); + ys1 = (int)floor(fy - miny); + xs2 = (int)floor(fx + minx); + ys2 = (int)floor(fy + miny); + boundary = (xs1 != xs2) || (ys1 != ys2); - if (boundary==0) { - if ( (tex->flag & TEX_CHECKER_ODD)==0) { + if (boundary == 0) { + if ( (tex->flag & TEX_CHECKER_ODD) == 0) { if ((xs + ys) & 1) { /* pass */ } @@ -1455,52 +1455,52 @@ int imagewraposa(Tex *tex, Image *ima, ImBuf *ibuf, const float texvec[3], const return retval; } } - if ( (tex->flag & TEX_CHECKER_EVEN)==0) { + if ( (tex->flag & TEX_CHECKER_EVEN) == 0) { if ((xs + ys) & 1) { if (ima) BKE_image_pool_release_ibuf(ima, ibuf, pool); return retval; } } - fx-= xs; - fy-= ys; + fx -= xs; + fy -= ys; } else { if (tex->flag & TEX_CHECKER_ODD) { - if ((xs1+ys) & 1) fx-= xs2; - else fx-= xs1; + if ((xs1 + ys) & 1) fx -= xs2; + else fx -= xs1; - if ((ys1+xs) & 1) fy-= ys2; - else fy-= ys1; + if ((ys1 + xs) & 1) fy -= ys2; + else fy -= ys1; } if (tex->flag & TEX_CHECKER_EVEN) { - if ((xs1+ys) & 1) fx-= xs1; - else fx-= xs2; + if ((xs1 + ys) & 1) fx -= xs1; + else fx -= xs2; - if ((ys1+xs) & 1) fy-= ys1; - else fy-= ys2; + if ((ys1 + xs) & 1) fy -= ys1; + else fy -= ys2; } } } /* scale around center, (0.5, 0.5) */ - if (tex->checkerdist<1.0f) { - fx= (fx-0.5f)/(1.0f-tex->checkerdist) +0.5f; - fy= (fy-0.5f)/(1.0f-tex->checkerdist) +0.5f; - minx/= (1.0f-tex->checkerdist); - miny/= (1.0f-tex->checkerdist); + if (tex->checkerdist < 1.0f) { + fx = (fx - 0.5f) / (1.0f - tex->checkerdist) + 0.5f; + fy = (fy - 0.5f) / (1.0f - tex->checkerdist) + 0.5f; + minx /= (1.0f - tex->checkerdist); + miny /= (1.0f - tex->checkerdist); } } if (tex->extend == TEX_CLIPCUBE) { - if (fx+minx<0.0f || fy+miny<0.0f || fx-minx>1.0f || fy-miny>1.0f || texvec[2]<-1.0f || texvec[2]>1.0f) { + if (fx + minx < 0.0f || fy + miny < 0.0f || fx - minx > 1.0f || fy - miny > 1.0f || texvec[2] < -1.0f || texvec[2] > 1.0f) { if (ima) BKE_image_pool_release_ibuf(ima, ibuf, pool); return retval; } } - else if (tex->extend==TEX_CLIP || tex->extend==TEX_CHECKER) { - if (fx+minx<0.0f || fy+miny<0.0f || fx-minx>1.0f || fy-miny>1.0f) { + else if (tex->extend == TEX_CLIP || tex->extend == TEX_CHECKER) { + if (fx + minx < 0.0f || fy + miny < 0.0f || fx - minx > 1.0f || fy - miny > 1.0f) { if (ima) BKE_image_pool_release_ibuf(ima, ibuf, pool); return retval; @@ -1508,21 +1508,21 @@ int imagewraposa(Tex *tex, Image *ima, ImBuf *ibuf, const float texvec[3], const } else { if (imapextend) { - if (fx>1.0f) fx = 1.0f; - else if (fx<0.0f) fx= 0.0f; + if (fx > 1.0f) fx = 1.0f; + else if (fx < 0.0f) fx = 0.0f; } else { - if (fx>1.0f) fx -= (int)(fx); - else if (fx<0.0f) fx+= 1-(int)(fx); + if (fx > 1.0f) fx -= (int)(fx); + else if (fx < 0.0f) fx += 1 - (int)(fx); } if (imapextend) { - if (fy>1.0f) fy = 1.0f; - else if (fy<0.0f) fy= 0.0f; + if (fy > 1.0f) fy = 1.0f; + else if (fy < 0.0f) fy = 0.0f; } else { - if (fy>1.0f) fy -= (int)(fy); - else if (fy<0.0f) fy+= 1-(int)(fy); + if (fy > 1.0f) fy -= (int)(fy); + else if (fy < 0.0f) fy += 1 - (int)(fy); } } @@ -1536,105 +1536,105 @@ int imagewraposa(Tex *tex, Image *ima, ImBuf *ibuf, const float texvec[3], const maxd = max_ff(dx, dy); if (maxd > 0.5f) maxd = 0.5f; - pixsize = 1.0f / (float) MIN2(ibuf->x, ibuf->y); + pixsize = 1.0f / (float)MIN2(ibuf->x, ibuf->y); - bumpscale= pixsize/maxd; - if (bumpscale>1.0f) bumpscale= 1.0f; - else bumpscale*=bumpscale; + bumpscale = pixsize / maxd; + if (bumpscale > 1.0f) bumpscale = 1.0f; + else bumpscale *= bumpscale; - curmap= 0; - previbuf= curibuf= ibuf; + curmap = 0; + previbuf = curibuf = ibuf; while (curmap < IMB_MIPMAP_LEVELS && ibuf->mipmap[curmap]) { if (maxd < pixsize) break; - previbuf= curibuf; - curibuf= ibuf->mipmap[curmap]; - pixsize= 1.0f / (float)MIN2(curibuf->x, curibuf->y); + previbuf = curibuf; + curibuf = ibuf->mipmap[curmap]; + pixsize = 1.0f / (float)MIN2(curibuf->x, curibuf->y); curmap++; } - if (previbuf!=curibuf || (tex->imaflag & TEX_INTERPOL)) { + if (previbuf != curibuf || (tex->imaflag & TEX_INTERPOL)) { /* sample at least 1 pixel */ if (minx < 0.5f / ibuf->x) minx = 0.5f / ibuf->x; if (miny < 0.5f / ibuf->y) miny = 0.5f / ibuf->y; } - if (texres->nor && (tex->imaflag & TEX_NORMALMAP)==0) { + if (texres->nor && (tex->imaflag & TEX_NORMALMAP) == 0) { /* a bit extra filter */ //minx*= 1.35f; //miny*= 1.35f; - boxsample(curibuf, fx-minx, fy-miny, fx+minx, fy+miny, texres, imaprepeat, imapextend); - val1= texres->tr+texres->tg+texres->tb; - boxsample(curibuf, fx-minx+dxt[0], fy-miny+dxt[1], fx+minx+dxt[0], fy+miny+dxt[1], &texr, imaprepeat, imapextend); - val2= texr.tr + texr.tg + texr.tb; - boxsample(curibuf, fx-minx+dyt[0], fy-miny+dyt[1], fx+minx+dyt[0], fy+miny+dyt[1], &texr, imaprepeat, imapextend); - val3= texr.tr + texr.tg + texr.tb; + boxsample(curibuf, fx - minx, fy - miny, fx + minx, fy + miny, texres, imaprepeat, imapextend); + val1 = texres->tr + texres->tg + texres->tb; + boxsample(curibuf, fx - minx + dxt[0], fy - miny + dxt[1], fx + minx + dxt[0], fy + miny + dxt[1], &texr, imaprepeat, imapextend); + val2 = texr.tr + texr.tg + texr.tb; + boxsample(curibuf, fx - minx + dyt[0], fy - miny + dyt[1], fx + minx + dyt[0], fy + miny + dyt[1], &texr, imaprepeat, imapextend); + val3 = texr.tr + texr.tg + texr.tb; /* don't switch x or y! */ - texres->nor[0]= (val1-val2); - texres->nor[1]= (val1-val3); + texres->nor[0] = (val1 - val2); + texres->nor[1] = (val1 - val3); - if (previbuf!=curibuf) { /* interpolate */ + if (previbuf != curibuf) { /* interpolate */ - boxsample(previbuf, fx-minx, fy-miny, fx+minx, fy+miny, &texr, imaprepeat, imapextend); + boxsample(previbuf, fx - minx, fy - miny, fx + minx, fy + miny, &texr, imaprepeat, imapextend); /* calc rgb */ - dx= 2.0f*(pixsize-maxd)/pixsize; - if (dx>=1.0f) { - texres->ta= texr.ta; texres->tb= texr.tb; - texres->tg= texr.tg; texres->tr= texr.tr; + dx = 2.0f * (pixsize - maxd) / pixsize; + if (dx >= 1.0f) { + texres->ta = texr.ta; texres->tb = texr.tb; + texres->tg = texr.tg; texres->tr = texr.tr; } else { - dy= 1.0f-dx; - texres->tb= dy*texres->tb+ dx*texr.tb; - texres->tg= dy*texres->tg+ dx*texr.tg; - texres->tr= dy*texres->tr+ dx*texr.tr; - texres->ta= dy*texres->ta+ dx*texr.ta; + dy = 1.0f - dx; + texres->tb = dy * texres->tb + dx * texr.tb; + texres->tg = dy * texres->tg + dx * texr.tg; + texres->tr = dy * texres->tr + dx * texr.tr; + texres->ta = dy * texres->ta + dx * texr.ta; } - val1= dy*val1+ dx*(texr.tr + texr.tg + texr.tb); - boxsample(previbuf, fx-minx+dxt[0], fy-miny+dxt[1], fx+minx+dxt[0], fy+miny+dxt[1], &texr, imaprepeat, imapextend); - val2= dy*val2+ dx*(texr.tr + texr.tg + texr.tb); - boxsample(previbuf, fx-minx+dyt[0], fy-miny+dyt[1], fx+minx+dyt[0], fy+miny+dyt[1], &texr, imaprepeat, imapextend); - val3= dy*val3+ dx*(texr.tr + texr.tg + texr.tb); - - texres->nor[0]= (val1-val2); /* vals have been interpolated above! */ - texres->nor[1]= (val1-val3); - - if (dx<1.0f) { - dy= 1.0f-dx; - texres->tb= dy*texres->tb+ dx*texr.tb; - texres->tg= dy*texres->tg+ dx*texr.tg; - texres->tr= dy*texres->tr+ dx*texr.tr; - texres->ta= dy*texres->ta+ dx*texr.ta; + val1 = dy * val1 + dx * (texr.tr + texr.tg + texr.tb); + boxsample(previbuf, fx - minx + dxt[0], fy - miny + dxt[1], fx + minx + dxt[0], fy + miny + dxt[1], &texr, imaprepeat, imapextend); + val2 = dy * val2 + dx * (texr.tr + texr.tg + texr.tb); + boxsample(previbuf, fx - minx + dyt[0], fy - miny + dyt[1], fx + minx + dyt[0], fy + miny + dyt[1], &texr, imaprepeat, imapextend); + val3 = dy * val3 + dx * (texr.tr + texr.tg + texr.tb); + + texres->nor[0] = (val1 - val2); /* vals have been interpolated above! */ + texres->nor[1] = (val1 - val3); + + if (dx < 1.0f) { + dy = 1.0f - dx; + texres->tb = dy * texres->tb + dx * texr.tb; + texres->tg = dy * texres->tg + dx * texr.tg; + texres->tr = dy * texres->tr + dx * texr.tr; + texres->ta = dy * texres->ta + dx * texr.ta; } } - texres->nor[0]*= bumpscale; - texres->nor[1]*= bumpscale; + texres->nor[0] *= bumpscale; + texres->nor[1] *= bumpscale; } else { - maxx= fx+minx; - minx= fx-minx; - maxy= fy+miny; - miny= fy-miny; + maxx = fx + minx; + minx = fx - minx; + maxy = fy + miny; + miny = fy - miny; boxsample(curibuf, minx, miny, maxx, maxy, texres, imaprepeat, imapextend); - if (previbuf!=curibuf) { /* interpolate */ + if (previbuf != curibuf) { /* interpolate */ boxsample(previbuf, minx, miny, maxx, maxy, &texr, imaprepeat, imapextend); - fx= 2.0f*(pixsize-maxd)/pixsize; + fx = 2.0f * (pixsize - maxd) / pixsize; - if (fx>=1.0f) { - texres->ta= texr.ta; texres->tb= texr.tb; - texres->tg= texr.tg; texres->tr= texr.tr; + if (fx >= 1.0f) { + texres->ta = texr.ta; texres->tb = texr.tb; + texres->tg = texr.tg; texres->tr = texr.tr; } else { - fy= 1.0f-fx; - texres->tb= fy*texres->tb+ fx*texr.tb; - texres->tg= fy*texres->tg+ fx*texr.tg; - texres->tr= fy*texres->tr+ fx*texr.tr; - texres->ta= fy*texres->ta+ fx*texr.ta; + fy = 1.0f - fx; + texres->tb = fy * texres->tb + fx * texr.tb; + texres->tg = fy * texres->tg + fx * texr.tg; + texres->tr = fy * texres->tr + fx * texr.tr; + texres->ta = fy * texres->ta + fx * texr.ta; } } } @@ -1647,20 +1647,20 @@ int imagewraposa(Tex *tex, Image *ima, ImBuf *ibuf, const float texvec[3], const if (miny < 0.5f / ibuf->y) miny = 0.5f / ibuf->y; } - if (texres->nor && (tex->imaflag & TEX_NORMALMAP)==0) { - boxsample(ibuf, fx-minx, fy-miny, fx+minx, fy+miny, texres, imaprepeat, imapextend); - val1= texres->tr+texres->tg+texres->tb; - boxsample(ibuf, fx-minx+dxt[0], fy-miny+dxt[1], fx+minx+dxt[0], fy+miny+dxt[1], &texr, imaprepeat, imapextend); - val2= texr.tr + texr.tg + texr.tb; - boxsample(ibuf, fx-minx+dyt[0], fy-miny+dyt[1], fx+minx+dyt[0], fy+miny+dyt[1], &texr, imaprepeat, imapextend); - val3= texr.tr + texr.tg + texr.tb; + if (texres->nor && (tex->imaflag & TEX_NORMALMAP) == 0) { + boxsample(ibuf, fx - minx, fy - miny, fx + minx, fy + miny, texres, imaprepeat, imapextend); + val1 = texres->tr + texres->tg + texres->tb; + boxsample(ibuf, fx - minx + dxt[0], fy - miny + dxt[1], fx + minx + dxt[0], fy + miny + dxt[1], &texr, imaprepeat, imapextend); + val2 = texr.tr + texr.tg + texr.tb; + boxsample(ibuf, fx - minx + dyt[0], fy - miny + dyt[1], fx + minx + dyt[0], fy + miny + dyt[1], &texr, imaprepeat, imapextend); + val3 = texr.tr + texr.tg + texr.tb; /* don't switch x or y! */ - texres->nor[0]= (val1-val2); - texres->nor[1]= (val1-val3); + texres->nor[0] = (val1 - val2); + texres->nor[1] = (val1 - val3); } else - boxsample(ibuf, fx-minx, fy-miny, fx+minx, fy+miny, texres, imaprepeat, imapextend); + boxsample(ibuf, fx - minx, fy - miny, fx + minx, fy + miny, texres, imaprepeat, imapextend); } if (tex->imaflag & TEX_CALCALPHA) { @@ -1670,7 +1670,7 @@ int imagewraposa(Tex *tex, Image *ima, ImBuf *ibuf, const float texvec[3], const texres->tin = texres->ta; } - if (tex->flag & TEX_NEGALPHA) texres->ta= 1.0f-texres->ta; + if (tex->flag & TEX_NEGALPHA) texres->ta = 1.0f - texres->ta; if (texres->nor && (tex->imaflag & TEX_NORMALMAP)) { /* qdn: normal from color @@ -1680,14 +1680,14 @@ int imagewraposa(Tex *tex, Image *ima, ImBuf *ibuf, const float texvec[3], const * the normal used in the renderer points inward. It is generated * this way in calc_vertexnormals(). Should this ever change * this negate must be removed. */ - texres->nor[0] = -2.f*(texres->tr - 0.5f); - texres->nor[1] = 2.f*(texres->tg - 0.5f); - texres->nor[2] = 2.f*(texres->tb - 0.5f); + texres->nor[0] = -2.f * (texres->tr - 0.5f); + texres->nor[1] = 2.f * (texres->tg - 0.5f); + texres->nor[2] = 2.f * (texres->tb - 0.5f); } /* de-premul, this is being premulled in shade_input_do_shade() */ /* do not de-premul for generated alpha, it is already in straight */ - if (texres->ta!=1.0f && texres->ta>1e-4f && !(tex->imaflag & TEX_CALCALPHA)) { + if (texres->ta != 1.0f && texres->ta > 1e-4f && !(tex->imaflag & TEX_CALCALPHA)) { mul_v3_fl(&texres->tr, 1.0f / texres->ta); } @@ -1713,7 +1713,7 @@ void image_sample(Image *ima, float fx, float fy, float dx, float dy, float resu boxsample(ibuf, fx, fy, fx + dx, fy + dy, &texres, 0, 1); copy_v4_v4(result, &texres.tr); - ima->flag|= IMA_USED_FOR_RENDER; + ima->flag |= IMA_USED_FOR_RENDER; BKE_image_pool_release_ibuf(ima, ibuf, pool); } diff --git a/source/blender/render/intern/source/initrender.c b/source/blender/render/intern/source/initrender.c index 7b0b1bed0ef..ff0d2867426 100644 --- a/source/blender/render/intern/source/initrender.c +++ b/source/blender/render/intern/source/initrender.c @@ -118,7 +118,7 @@ float RE_filter_value(int type, float x) { const float two_gaussfac2 = 2.0f * gaussfac * gaussfac; x *= 3.0f * gaussfac; - return 1.0f / sqrtf((float)M_PI * two_gaussfac2) * expf(-x*x / two_gaussfac2); + return 1.0f / sqrtf((float)M_PI * two_gaussfac2) * expf(-x * x / two_gaussfac2); } case R_FILTER_MITCH: diff --git a/source/blender/render/intern/source/multires_bake.c b/source/blender/render/intern/source/multires_bake.c index f20434969db..632c501c54c 100644 --- a/source/blender/render/intern/source/multires_bake.c +++ b/source/blender/render/intern/source/multires_bake.c @@ -103,7 +103,7 @@ typedef struct { const int *orig_index_mp_to_orig; } MNormalBakeData; -static void multiresbake_get_normal(const MResolvePixelData *data, float norm[],const int tri_num, const int vert_index) +static void multiresbake_get_normal(const MResolvePixelData *data, float norm[], const int tri_num, const int vert_index) { const int poly_index = data->mlooptri[tri_num].poly; const MPoly *mp = &data->mpoly[poly_index]; @@ -129,7 +129,7 @@ static void multiresbake_get_normal(const MResolvePixelData *data, float norm[], static void init_bake_rast(MBakeRast *bake_rast, const ImBuf *ibuf, const MResolvePixelData *data, MFlushPixel flush_pixel, short *do_update) { - BakeImBufuserData *userdata = (BakeImBufuserData *) ibuf->userdata; + BakeImBufuserData *userdata = (BakeImBufuserData *)ibuf->userdata; memset(bake_rast, 0, sizeof(MBakeRast)); @@ -281,9 +281,9 @@ static void bake_rasterize(const MBakeRast *bake_rast, const float st0_in[2], co /* check if mid point is to the left or to the right of the lo-hi edge */ is_mid_right = (-(shi - slo) * (tmi - thi) + (thi - tlo) * (smi - shi)) > 0 ? 1 : 0; - ylo = (int) ceilf(tlo); - yhi_beg = (int) ceilf(tmi); - yhi = (int) ceilf(thi); + ylo = (int)ceilf(tlo); + yhi_beg = (int)ceilf(tmi); + yhi = (int)ceilf(thi); /*if (fTmi>ceilf(fTlo))*/ rasterize_half(bake_rast, slo, tlo, smi, tmi, slo, tlo, shi, thi, ylo, yhi_beg, is_mid_right); @@ -343,7 +343,7 @@ static int multires_bake_queue_next_tri(MultiresBakeQueue *queue) static void *do_multires_bake_thread(void *data_v) { - MultiresBakeThread *handle = (MultiresBakeThread *) data_v; + MultiresBakeThread *handle = (MultiresBakeThread *)data_v; MResolvePixelData *data = &handle->data; MBakeRast *bake_rast = &handle->bake_rast; MultiresBakeRender *bkr = handle->bkr; @@ -403,9 +403,9 @@ static void init_ccgdm_arrays(DerivedMesh *dm) grid_offset = dm->getGridOffset(dm); dm->getGridKey(dm, &key); - (void) grid_size; - (void) grid_data; - (void) grid_offset; + (void)grid_size; + (void)grid_data; + (void)grid_offset; } static void do_multires_bake(MultiresBakeRender *bkr, Image *ima, bool require_tangent, MPassKnownData passKnownData, @@ -525,10 +525,10 @@ static void interp_bilinear_grid(CCGKey *key, CCGElem *grid, float crn_x, float float u, v; float data[4][3]; - x0 = (int) crn_x; + x0 = (int)crn_x; x1 = x0 >= (key->grid_size - 1) ? (key->grid_size - 1) : (x0 + 1); - y0 = (int) crn_y; + y0 = (int)crn_y; y1 = y0 >= (key->grid_size - 1) ? (key->grid_size - 1) : (y0 + 1); u = crn_x - x0; @@ -717,7 +717,7 @@ static void apply_heights_callback(DerivedMesh *lores_dm, DerivedMesh *hires_dm, MPoly *mpoly = lores_dm->getPolyArray(lores_dm) + lt->poly; MLoopUV *mloopuv = lores_dm->getLoopDataArray(lores_dm, CD_MLOOPUV); MHeightBakeData *height_data = (MHeightBakeData *)bake_data; - MultiresBakeThread *thread_data = (MultiresBakeThread *) thread_data_v; + MultiresBakeThread *thread_data = (MultiresBakeThread *)thread_data_v; float uv[2], *st0, *st1, *st2, *st3; int pixel = ibuf->x * y + x; float vec[3], p0[3], p1[3], n[3], len; @@ -941,7 +941,7 @@ static void create_ao_raytree(MultiresBakeRender *bkr, MAOBakeData *ao_data) num_faces = num_grids * (grid_size - 1) * (grid_size - 1); raytree = ao_data->raytree = RE_rayobject_create(bkr->raytrace_structure, num_faces, bkr->octree_resolution); - face = ao_data->rayfaces = (RayFace *) MEM_callocN(num_faces * sizeof(RayFace), "ObjectRen faces"); + face = ao_data->rayfaces = (RayFace *)MEM_callocN(num_faces * sizeof(RayFace), "ObjectRen faces"); for (i = 0; i < num_grids; i++) { int x, y; @@ -999,7 +999,7 @@ static void *init_ao_data(MultiresBakeRender *bkr, Image *UNUSED(ima)) static void free_ao_data(void *bake_data) { - MAOBakeData *ao_data = (MAOBakeData *) bake_data; + MAOBakeData *ao_data = (MAOBakeData *)bake_data; RE_rayobject_free(ao_data->raytree); MEM_freeN(ao_data->rayfaces); @@ -1056,7 +1056,7 @@ static void apply_ao_callback(DerivedMesh *lores_dm, DerivedMesh *hires_dm, void const MLoopTri *lt = lores_dm->getLoopTriArray(lores_dm) + tri_index; MPoly *mpoly = lores_dm->getPolyArray(lores_dm) + lt->poly; MLoopUV *mloopuv = lores_dm->getLoopDataArray(lores_dm, CD_MLOOPUV); - MAOBakeData *ao_data = (MAOBakeData *) bake_data; + MAOBakeData *ao_data = (MAOBakeData *)bake_data; int i, k, perm_offs; float pos[3], nrm[3]; @@ -1113,8 +1113,8 @@ static void apply_ao_callback(DerivedMesh *lores_dm, DerivedMesh *hires_dm, void const unsigned short I = ao_data->permutation_table_1[(i + perm_offs) % ao_data->number_of_rays]; const unsigned short J = ao_data->permutation_table_2[i]; - const float JitPh = (get_ao_random2(I + perm_offs) & (MAX_NUMBER_OF_AO_RAYS-1))/((float) MAX_NUMBER_OF_AO_RAYS); - const float JitTh = (get_ao_random1(J + perm_offs) & (MAX_NUMBER_OF_AO_RAYS-1))/((float) MAX_NUMBER_OF_AO_RAYS); + const float JitPh = (get_ao_random2(I + perm_offs) & (MAX_NUMBER_OF_AO_RAYS - 1)) / ((float)MAX_NUMBER_OF_AO_RAYS); + const float JitTh = (get_ao_random1(J + perm_offs) & (MAX_NUMBER_OF_AO_RAYS - 1)) / ((float)MAX_NUMBER_OF_AO_RAYS); const float SiSqPhi = (I + JitPh) / ao_data->number_of_rays; const float Theta = (float)(2 * M_PI) * ((J + JitTh) / ao_data->number_of_rays); @@ -1149,7 +1149,7 @@ static void apply_ao_callback(DerivedMesh *lores_dm, DerivedMesh *hires_dm, void rrgbf[3] = 1.0f; } else { - unsigned char *rrgb = (unsigned char *) ibuf->rect + pixel * 4; + unsigned char *rrgb = (unsigned char *)ibuf->rect + pixel * 4; rrgb[0] = rrgb[1] = rrgb[2] = unit_float_to_uchar_clamp(value); rrgb[3] = 255; } @@ -1206,7 +1206,7 @@ static void bake_ibuf_normalize_displacement(ImBuf *ibuf, float *displacement, c } if (ibuf->rect) { - unsigned char *cp = (unsigned char *) (ibuf->rect + i); + unsigned char *cp = (unsigned char *)(ibuf->rect + i); cp[0] = cp[1] = cp[2] = unit_float_to_uchar_clamp(normalized_displacement); cp[3] = 255; } @@ -1294,14 +1294,14 @@ static void finish_images(MultiresBakeRender *bkr, MultiresBakeResult *result) for (link = bkr->image.first; link; link = link->next) { Image *ima = (Image *)link->data; ImBuf *ibuf = BKE_image_acquire_ibuf(ima, NULL, NULL); - BakeImBufuserData *userdata = (BakeImBufuserData *) ibuf->userdata; + BakeImBufuserData *userdata = (BakeImBufuserData *)ibuf->userdata; if (ibuf->x <= 0 || ibuf->y <= 0) continue; if (use_displacement_buffer) { bake_ibuf_normalize_displacement(ibuf, userdata->displacement_buffer, userdata->mask_buffer, - result->height_min, result->height_max); + result->height_min, result->height_max); } bake_ibuf_filter(ibuf, userdata->mask_buffer, bkr->bake_filter); diff --git a/source/blender/render/intern/source/pipeline.c b/source/blender/render/intern/source/pipeline.c index f5346a6c315..021abe89105 100644 --- a/source/blender/render/intern/source/pipeline.c +++ b/source/blender/render/intern/source/pipeline.c @@ -863,8 +863,8 @@ static void render_result_rescale(Render *re) } } - scale_x = (float) result->rectx / re->result->rectx; - scale_y = (float) result->recty / re->result->recty; + scale_x = (float)result->rectx / re->result->rectx; + scale_y = (float)result->recty / re->result->recty; for (x = 0; x < re->result->rectx; ++x) { for (y = 0; y < re->result->recty; ++y) { int src_x = x * scale_x; @@ -1261,7 +1261,7 @@ static void ntree_render_scenes(Render *re) /* bad call... need to think over proper method still */ static void render_composit_stats(void *arg, const char *str) { - Render *re = (Render*)arg; + Render *re = (Render *)arg; RenderStats i; memcpy(&i, &re->i, sizeof(i)); @@ -1319,7 +1319,7 @@ static void free_all_freestyle_renders(void) Render *re1; LinkData *link; - for (re1= RenderGlobal.renderlist.first; re1; re1= re1->next) { + for (re1 = RenderGlobal.renderlist.first; re1; re1 = re1->next) { for (link = (LinkData *)re1->freestyle_renders.first; link; link = link->next) { Render *freestyle_render = (Render *)link->data; @@ -1445,7 +1445,7 @@ static void renderresult_stampinfo(Render *re) /* this is the basic trick to get the displayed float or char rect from render result */ nr = 0; - for (rv = re->result->views.first;rv;rv = rv->next, nr++) { + for (rv = re->result->views.first; rv; rv = rv->next, nr++) { RE_SetActiveRenderView(re, rv->name); RE_AcquireResultImage(re, &rres, nr); BKE_image_stamp_buf(re->scene, @@ -2019,7 +2019,7 @@ void RE_BlenderFrame(Render *re, Main *bmain, Scene *scene, ViewLayer *single_la #ifdef WITH_FREESTYLE void RE_RenderFreestyleStrokes(Render *re, Main *bmain, Scene *scene, int render) { - re->result_ok= 0; + re->result_ok = 0; if (render_initialize_from_main(re, &scene->r, bmain, scene, NULL, NULL, 0, 0)) { if (render) do_render_3d(re); @@ -2181,7 +2181,7 @@ bool RE_WriteRenderViewsMovie( &scene->display_settings, &scene->r.im_format); ok &= mh->append_movie(movie_ctx_arr[view_id], rd, preview ? scene->r.psfra : scene->r.sfra, scene->r.cfra, - (int *) ibuf->rect, ibuf->x, ibuf->y, suffix, reports); + (int *)ibuf->rect, ibuf->x, ibuf->y, suffix, reports); /* imbuf knows which rects are not part of ibuf */ IMB_freeImBuf(ibuf); @@ -2205,7 +2205,7 @@ bool RE_WriteRenderViewsMovie( ibuf_arr[2] = IMB_stereo3d_ImBuf(&scene->r.im_format, ibuf_arr[0], ibuf_arr[1]); - ok = mh->append_movie(movie_ctx_arr[0], rd, preview ? scene->r.psfra : scene->r.sfra, scene->r.cfra, (int *) ibuf_arr[2]->rect, + ok = mh->append_movie(movie_ctx_arr[0], rd, preview ? scene->r.psfra : scene->r.sfra, scene->r.cfra, (int *)ibuf_arr[2]->rect, ibuf_arr[2]->x, ibuf_arr[2]->y, "", reports); for (i = 0; i < 3; i++) { diff --git a/source/blender/render/intern/source/pointdensity.c b/source/blender/render/intern/source/pointdensity.c index 06d51fb161d..d3e6b6c6c51 100644 --- a/source/blender/render/intern/source/pointdensity.c +++ b/source/blender/render/intern/source/pointdensity.c @@ -251,9 +251,9 @@ static void pointdensity_cache_psys(Depsgraph *depsgraph, Scene *scene, BLI_bvhtree_insert(pd->point_tree, i, partco, 1); if (data_vel) { - data_vel[i*3 + 0] = state.vel[0]; - data_vel[i*3 + 1] = state.vel[1]; - data_vel[i*3 + 2] = state.vel[2]; + data_vel[i * 3 + 0] = state.vel[0]; + data_vel[i * 3 + 1] = state.vel[1]; + data_vel[i * 3 + 2] = state.vel[2]; } if (data_life) { data_life[i] = state.time; @@ -309,7 +309,7 @@ static void pointdensity_cache_vertex_color(PointDensity *pd, Object *UNUSED(ob) */ for (i = 0; i < pd->totpoints; i++) { if (mcorners[i] > 0) - mul_v3_fl(&data_color[i*3], 1.0f / mcorners[i]); + mul_v3_fl(&data_color[i * 3], 1.0f / mcorners[i]); } MEM_freeN(mcorners); @@ -566,8 +566,9 @@ static void accum_density(void *userdata, int index, const float co[3], float sq } -static void init_pointdensityrangedata(PointDensity *pd, PointDensityRangeData *pdr, - float *density, float *vec, float *age, float *col, struct CurveMapping *density_curve, float velscale) +static void init_pointdensityrangedata( + PointDensity *pd, PointDensityRangeData *pdr, + float *density, float *vec, float *age, float *col, struct CurveMapping *density_curve, float velscale) { pdr->squared_radius = pd->radius * pd->radius; pdr->density = density; @@ -600,9 +601,9 @@ static int pointdensity(PointDensity *pd, texres->tin = 0.0f; init_pointdensityrangedata(pd, &pdr, &density, vec, &age, col, - (pd->flag & TEX_PD_FALLOFF_CURVE ? pd->falloff_curve : NULL), - pd->falloff_speed_scale * 0.001f); - noise_fac = pd->noise_fac * 0.5f; /* better default */ + (pd->flag & TEX_PD_FALLOFF_CURVE ? pd->falloff_curve : NULL), + pd->falloff_speed_scale * 0.001f); + noise_fac = pd->noise_fac * 0.5f; /* better default */ copy_v3_v3(co, texvec); @@ -626,7 +627,7 @@ static int pointdensity(PointDensity *pd, turb = BLI_gTurbulence(pd->noise_size, texvec[0] + vec[0], texvec[1] + vec[1], texvec[2] + vec[2], pd->noise_depth, 0, pd->noise_basis); - turb -= 0.5f; /* re-center 0.0-1.0 range around 0 to prevent offsetting result */ + turb -= 0.5f; /* re-center 0.0-1.0 range around 0 to prevent offsetting result */ /* now we have an offset coordinate to use for the density lookup */ co[0] = texvec[0] + noise_fac * turb; @@ -894,8 +895,8 @@ static void point_density_sample_func( pointdensity(pd, texvec, &texres, vec, &age, col); pointdensity_color(pd, &texres, age, vec, col); - copy_v3_v3(&values[index*4 + 0], &texres.tr); - values[index*4 + 3] = texres.tin; + copy_v3_v3(&values[index * 4 + 0], &texres.tr); + values[index * 4 + 3] = texres.tin; } } } diff --git a/source/blender/render/intern/source/render_result.c b/source/blender/render/intern/source/render_result.c index 103a6782b7f..c00fc48bcd0 100644 --- a/source/blender/render/intern/source/render_result.c +++ b/source/blender/render/intern/source/render_result.c @@ -325,12 +325,12 @@ RenderResult *render_result_new(Render *re, rcti *partrct, int crop, int savebuf IMB_exr_add_view(rl->exrhandle, view); #define RENDER_LAYER_ADD_PASS_SAFE(rr, rl, channels, name, viewname, chan_id) \ - do { \ - if (render_layer_add_pass(rr, rl, channels, name, viewname, chan_id) == NULL) { \ - render_result_free(rr); \ - return NULL; \ - } \ - } while (false) + do { \ + if (render_layer_add_pass(rr, rl, channels, name, viewname, chan_id) == NULL) { \ + render_result_free(rr); \ + return NULL; \ + } \ + } while (false) /* a renderlayer should always have a Combined pass*/ render_layer_add_pass(rr, rl, 4, "Combined", view, "RGBA"); @@ -598,8 +598,8 @@ static void *ml_addview_cb(void *base, const char *str) static int order_render_passes(const void *a, const void *b) { // 1 if a is after b - RenderPass *rpa = (RenderPass *) a; - RenderPass *rpb = (RenderPass *) b; + RenderPass *rpa = (RenderPass *)a; + RenderPass *rpb = (RenderPass *)b; unsigned int passtype_a = passtype_from_name(rpa->name); unsigned int passtype_b = passtype_from_name(rpb->name); @@ -838,7 +838,7 @@ bool RE_WriteRenderResult(ReportList *reports, RenderResult *rr, const char *fil } if (write_z && rview->rectz) { - const char *layname = (multi_layer)? "Composite": ""; + const char *layname = (multi_layer) ? "Composite" : ""; IMB_exr_add_channel(exrhandle, layname, "Z", viewname, 1, rr->rectx, rview->rectz, false); } @@ -846,7 +846,7 @@ bool RE_WriteRenderResult(ReportList *reports, RenderResult *rr, const char *fil } /* Other render layers. */ - int nr = (rr->have_combined)? 1: 0; + int nr = (rr->have_combined) ? 1 : 0; for (RenderLayer *rl = rr->layers.first; rl; rl = rl->next, nr++) { /* Skip other render layers if requested. */ if (!multi_layer && nr != layer) { @@ -1304,7 +1304,7 @@ ImBuf *render_result_rect_to_ibuf(RenderResult *rr, RenderData *rd, const int vi RenderView *rv = RE_RenderViewGetById(rr, view_id); /* if not exists, BKE_imbuf_write makes one */ - ibuf->rect = (unsigned int *) rv->rect32; + ibuf->rect = (unsigned int *)rv->rect32; ibuf->rect_float = rv->rectf; ibuf->zbuf_float = rv->rectz; @@ -1392,7 +1392,7 @@ void render_result_rect_get_pixels(RenderResult *rr, unsigned int *rect, int rec if (rv->rect32) memcpy(rect, rv->rect32, sizeof(int) * rr->rectx * rr->recty); else if (rv->rectf) - IMB_display_buffer_transform_apply((unsigned char *) rect, rv->rectf, rr->rectx, rr->recty, 4, + IMB_display_buffer_transform_apply((unsigned char *)rect, rv->rectf, rr->rectx, rr->recty, 4, view_settings, display_settings, true); else /* else fill with black */ @@ -1431,11 +1431,13 @@ bool RE_HasFloatPixels(RenderResult *res) bool RE_RenderResult_is_stereo(RenderResult *res) { - if (! BLI_findstring(&res->views, STEREO_LEFT_NAME, offsetof(RenderView, name))) + if (!BLI_findstring(&res->views, STEREO_LEFT_NAME, offsetof(RenderView, name))) { return false; + } - if (! BLI_findstring(&res->views, STEREO_RIGHT_NAME, offsetof(RenderView, name))) + if (!BLI_findstring(&res->views, STEREO_RIGHT_NAME, offsetof(RenderView, name))) { return false; + } return true; } diff --git a/source/blender/render/intern/source/render_texture.c b/source/blender/render/intern/source/render_texture.c index 4e38f8d569a..7678e69caad 100644 --- a/source/blender/render/intern/source/render_texture.c +++ b/source/blender/render/intern/source/render_texture.c @@ -87,24 +87,24 @@ static void tex_normal_derivate(Tex *tex, TexResult *texres) if (BKE_colorband_evaluate(tex->coba, texres->tin, col)) { float fac0, fac1, fac2, fac3; - fac0= (col[0]+col[1]+col[2]); + fac0 = (col[0] + col[1] + col[2]); BKE_colorband_evaluate(tex->coba, texres->nor[0], col); - fac1= (col[0]+col[1]+col[2]); + fac1 = (col[0] + col[1] + col[2]); BKE_colorband_evaluate(tex->coba, texres->nor[1], col); - fac2= (col[0]+col[1]+col[2]); + fac2 = (col[0] + col[1] + col[2]); BKE_colorband_evaluate(tex->coba, texres->nor[2], col); - fac3= (col[0]+col[1]+col[2]); + fac3 = (col[0] + col[1] + col[2]); - texres->nor[0]= (fac0 - fac1) / 3.0f; - texres->nor[1]= (fac0 - fac2) / 3.0f; - texres->nor[2]= (fac0 - fac3) / 3.0f; + texres->nor[0] = (fac0 - fac1) / 3.0f; + texres->nor[1] = (fac0 - fac2) / 3.0f; + texres->nor[2] = (fac0 - fac3) / 3.0f; return; } } - texres->nor[0]= texres->tin - texres->nor[0]; - texres->nor[1]= texres->tin - texres->nor[1]; - texres->nor[2]= texres->tin - texres->nor[2]; + texres->nor[0] = texres->tin - texres->nor[0]; + texres->nor[1] = texres->tin - texres->nor[1]; + texres->nor[2] = texres->tin - texres->nor[2]; } @@ -114,41 +114,41 @@ static int blend(Tex *tex, const float texvec[3], TexResult *texres) float x, y, t; if (tex->flag & TEX_FLIPBLEND) { - x= texvec[1]; - y= texvec[0]; + x = texvec[1]; + y = texvec[0]; } else { - x= texvec[0]; - y= texvec[1]; + x = texvec[0]; + y = texvec[1]; } - if (tex->stype==TEX_LIN) { /* lin */ - texres->tin= (1.0f+x)/2.0f; + if (tex->stype == TEX_LIN) { /* lin */ + texres->tin = (1.0f + x) / 2.0f; } - else if (tex->stype==TEX_QUAD) { /* quad */ - texres->tin= (1.0f+x)/2.0f; - if (texres->tin<0.0f) texres->tin= 0.0f; - else texres->tin*= texres->tin; + else if (tex->stype == TEX_QUAD) { /* quad */ + texres->tin = (1.0f + x) / 2.0f; + if (texres->tin < 0.0f) texres->tin = 0.0f; + else texres->tin *= texres->tin; } - else if (tex->stype==TEX_EASE) { /* ease */ - texres->tin= (1.0f+x)/2.0f; - if (texres->tin<=0.0f) texres->tin= 0.0f; - else if (texres->tin>=1.0f) texres->tin= 1.0f; + else if (tex->stype == TEX_EASE) { /* ease */ + texres->tin = (1.0f + x) / 2.0f; + if (texres->tin <= 0.0f) texres->tin = 0.0f; + else if (texres->tin >= 1.0f) texres->tin = 1.0f; else { - t= texres->tin*texres->tin; - texres->tin= (3.0f*t-2.0f*t*texres->tin); + t = texres->tin * texres->tin; + texres->tin = (3.0f * t - 2.0f * t * texres->tin); } } - else if (tex->stype==TEX_DIAG) { /* diag */ - texres->tin= (2.0f+x+y)/4.0f; + else if (tex->stype == TEX_DIAG) { /* diag */ + texres->tin = (2.0f + x + y) / 4.0f; } - else if (tex->stype==TEX_RAD) { /* radial */ + else if (tex->stype == TEX_RAD) { /* radial */ texres->tin = (atan2f(y, x) / (float)(2 * M_PI) + 0.5f); } else { /* sphere TEX_SPHERE */ texres->tin = 1.0f - sqrtf(x * x + y * y + texvec[2] * texvec[2]); - if (texres->tin<0.0f) texres->tin= 0.0f; - if (tex->stype==TEX_HALO) texres->tin*= texres->tin; /* halo */ + if (texres->tin < 0.0f) texres->tin = 0.0f; + if (tex->stype == TEX_HALO) texres->tin *= texres->tin; /* halo */ } BRICONT; @@ -165,24 +165,24 @@ static int clouds(Tex *tex, const float texvec[3], TexResult *texres) { int rv = TEX_INT; - texres->tin = BLI_gTurbulence(tex->noisesize, texvec[0], texvec[1], texvec[2], tex->noisedepth, (tex->noisetype!=TEX_NOISESOFT), tex->noisebasis); + texres->tin = BLI_gTurbulence(tex->noisesize, texvec[0], texvec[1], texvec[2], tex->noisedepth, (tex->noisetype != TEX_NOISESOFT), tex->noisebasis); - if (texres->nor!=NULL) { + if (texres->nor != NULL) { /* calculate bumpnormal */ - texres->nor[0] = BLI_gTurbulence(tex->noisesize, texvec[0] + tex->nabla, texvec[1], texvec[2], tex->noisedepth, (tex->noisetype!=TEX_NOISESOFT), tex->noisebasis); - texres->nor[1] = BLI_gTurbulence(tex->noisesize, texvec[0], texvec[1] + tex->nabla, texvec[2], tex->noisedepth, (tex->noisetype!=TEX_NOISESOFT), tex->noisebasis); - texres->nor[2] = BLI_gTurbulence(tex->noisesize, texvec[0], texvec[1], texvec[2] + tex->nabla, tex->noisedepth, (tex->noisetype!=TEX_NOISESOFT), tex->noisebasis); + texres->nor[0] = BLI_gTurbulence(tex->noisesize, texvec[0] + tex->nabla, texvec[1], texvec[2], tex->noisedepth, (tex->noisetype != TEX_NOISESOFT), tex->noisebasis); + texres->nor[1] = BLI_gTurbulence(tex->noisesize, texvec[0], texvec[1] + tex->nabla, texvec[2], tex->noisedepth, (tex->noisetype != TEX_NOISESOFT), tex->noisebasis); + texres->nor[2] = BLI_gTurbulence(tex->noisesize, texvec[0], texvec[1], texvec[2] + tex->nabla, tex->noisedepth, (tex->noisetype != TEX_NOISESOFT), tex->noisebasis); tex_normal_derivate(tex, texres); rv |= TEX_NOR; } - if (tex->stype==TEX_COLOR) { + if (tex->stype == TEX_COLOR) { /* in this case, int. value should really be computed from color, * and bumpnormal from that, would be too slow, looks ok as is */ texres->tr = texres->tin; - texres->tg = BLI_gTurbulence(tex->noisesize, texvec[1], texvec[0], texvec[2], tex->noisedepth, (tex->noisetype!=TEX_NOISESOFT), tex->noisebasis); - texres->tb = BLI_gTurbulence(tex->noisesize, texvec[1], texvec[2], texvec[0], tex->noisedepth, (tex->noisetype!=TEX_NOISESOFT), tex->noisebasis); + texres->tg = BLI_gTurbulence(tex->noisesize, texvec[1], texvec[0], texvec[2], tex->noisedepth, (tex->noisetype != TEX_NOISESOFT), tex->noisebasis); + texres->tb = BLI_gTurbulence(tex->noisesize, texvec[1], texvec[2], texvec[0], tex->noisedepth, (tex->noisetype != TEX_NOISESOFT), tex->noisebasis); BRICONTRGB; texres->ta = 1.0; return (rv | TEX_RGB); @@ -205,10 +205,10 @@ static float tex_sin(float a) /* creates a saw wave */ static float tex_saw(float a) { - const float b = 2*M_PI; + const float b = 2 * M_PI; int n = (int)(a / b); - a -= n*b; + a -= n * b; if (a < 0) a += b; return a / b; } @@ -216,10 +216,10 @@ static float tex_saw(float a) /* creates a triangle wave */ static float tex_tri(float a) { - const float b = 2*M_PI; + const float b = 2 * M_PI; const float rmax = 1.0; - a = rmax - 2.0f*fabsf(floorf((a*(1.0f/b))+0.5f) - (a*(1.0f/b))); + a = rmax - 2.0f * fabsf(floorf((a * (1.0f / b)) + 0.5f) - (a * (1.0f / b))); return a; } @@ -228,29 +228,29 @@ static float tex_tri(float a) static float wood_int(Tex *tex, float x, float y, float z) { float wi = 0; - short wf = tex->noisebasis2; /* wave form: TEX_SIN=0, TEX_SAW=1, TEX_TRI=2 */ - short wt = tex->stype; /* wood type: TEX_BAND=0, TEX_RING=1, TEX_BANDNOISE=2, TEX_RINGNOISE=3 */ + short wf = tex->noisebasis2; /* wave form: TEX_SIN=0, TEX_SAW=1, TEX_TRI=2 */ + short wt = tex->stype; /* wood type: TEX_BAND=0, TEX_RING=1, TEX_BANDNOISE=2, TEX_RINGNOISE=3 */ - float (*waveform[3])(float); /* create array of pointers to waveform functions */ - waveform[0] = tex_sin; /* assign address of tex_sin() function to pointer array */ + float (*waveform[3])(float); /* create array of pointers to waveform functions */ + waveform[0] = tex_sin; /* assign address of tex_sin() function to pointer array */ waveform[1] = tex_saw; waveform[2] = tex_tri; - if ((wf>TEX_TRI) || (wf<TEX_SIN)) wf=0; /* check to be sure noisebasis2 is initialized ahead of time */ + if ((wf > TEX_TRI) || (wf < TEX_SIN)) wf = 0; /* check to be sure noisebasis2 is initialized ahead of time */ - if (wt==TEX_BAND) { - wi = waveform[wf]((x + y + z)*10.0f); + if (wt == TEX_BAND) { + wi = waveform[wf]((x + y + z) * 10.0f); } - else if (wt==TEX_RING) { - wi = waveform[wf](sqrtf(x*x + y*y + z*z)*20.0f); + else if (wt == TEX_RING) { + wi = waveform[wf](sqrtf(x * x + y * y + z * z) * 20.0f); } - else if (wt==TEX_BANDNOISE) { - wi = tex->turbul*BLI_gNoise(tex->noisesize, x, y, z, (tex->noisetype!=TEX_NOISESOFT), tex->noisebasis); - wi = waveform[wf]((x + y + z)*10.0f + wi); + else if (wt == TEX_BANDNOISE) { + wi = tex->turbul * BLI_gNoise(tex->noisesize, x, y, z, (tex->noisetype != TEX_NOISESOFT), tex->noisebasis); + wi = waveform[wf]((x + y + z) * 10.0f + wi); } - else if (wt==TEX_RINGNOISE) { - wi = tex->turbul*BLI_gNoise(tex->noisesize, x, y, z, (tex->noisetype!=TEX_NOISESOFT), tex->noisebasis); - wi = waveform[wf](sqrtf(x*x + y*y + z*z)*20.0f + wi); + else if (wt == TEX_RINGNOISE) { + wi = tex->turbul * BLI_gNoise(tex->noisesize, x, y, z, (tex->noisetype != TEX_NOISESOFT), tex->noisebasis); + wi = waveform[wf](sqrtf(x * x + y * y + z * z) * 20.0f + wi); } return wi; @@ -258,10 +258,10 @@ static float wood_int(Tex *tex, float x, float y, float z) static int wood(Tex *tex, const float texvec[3], TexResult *texres) { - int rv=TEX_INT; + int rv = TEX_INT; texres->tin = wood_int(tex, texvec[0], texvec[1], texvec[2]); - if (texres->nor!=NULL) { + if (texres->nor != NULL) { /* calculate bumpnormal */ texres->nor[0] = wood_int(tex, texvec[0] + tex->nabla, texvec[1], texvec[2]); texres->nor[1] = wood_int(tex, texvec[0], texvec[1] + tex->nabla, texvec[2]); @@ -280,26 +280,26 @@ static int wood(Tex *tex, const float texvec[3], TexResult *texres) static float marble_int(Tex *tex, float x, float y, float z) { float n, mi; - short wf = tex->noisebasis2; /* wave form: TEX_SIN=0, TEX_SAW=1, TEX_TRI=2 */ - short mt = tex->stype; /* marble type: TEX_SOFT=0, TEX_SHARP=1, TEX_SHAPER=2 */ + short wf = tex->noisebasis2; /* wave form: TEX_SIN=0, TEX_SAW=1, TEX_TRI=2 */ + short mt = tex->stype; /* marble type: TEX_SOFT=0, TEX_SHARP=1, TEX_SHAPER=2 */ - float (*waveform[3])(float); /* create array of pointers to waveform functions */ - waveform[0] = tex_sin; /* assign address of tex_sin() function to pointer array */ + float (*waveform[3])(float); /* create array of pointers to waveform functions */ + waveform[0] = tex_sin; /* assign address of tex_sin() function to pointer array */ waveform[1] = tex_saw; waveform[2] = tex_tri; - if ((wf>TEX_TRI) || (wf<TEX_SIN)) wf=0; /* check to be sure noisebasis2 isn't initialized ahead of time */ + if ((wf > TEX_TRI) || (wf < TEX_SIN)) wf = 0; /* check to be sure noisebasis2 isn't initialized ahead of time */ n = 5.0f * (x + y + z); - mi = n + tex->turbul * BLI_gTurbulence(tex->noisesize, x, y, z, tex->noisedepth, (tex->noisetype!=TEX_NOISESOFT), tex->noisebasis); + mi = n + tex->turbul * BLI_gTurbulence(tex->noisesize, x, y, z, tex->noisedepth, (tex->noisetype != TEX_NOISESOFT), tex->noisebasis); - if (mt>=TEX_SOFT) { /* TEX_SOFT always true */ + if (mt >= TEX_SOFT) { /* TEX_SOFT always true */ mi = waveform[wf](mi); - if (mt==TEX_SHARP) { + if (mt == TEX_SHARP) { mi = sqrtf(mi); } - else if (mt==TEX_SHARPER) { + else if (mt == TEX_SHARPER) { mi = sqrtf(sqrtf(mi)); } } @@ -309,11 +309,11 @@ static float marble_int(Tex *tex, float x, float y, float z) static int marble(Tex *tex, const float texvec[3], TexResult *texres) { - int rv=TEX_INT; + int rv = TEX_INT; texres->tin = marble_int(tex, texvec[0], texvec[1], texvec[2]); - if (texres->nor!=NULL) { + if (texres->nor != NULL) { /* calculate bumpnormal */ texres->nor[0] = marble_int(tex, texvec[0] + tex->nabla, texvec[1], texvec[2]); texres->nor[1] = marble_int(tex, texvec[0], texvec[1] + tex->nabla, texvec[2]); @@ -336,45 +336,45 @@ static int magic(Tex *tex, const float texvec[3], TexResult *texres) float x, y, z, turb; int n; - n= tex->noisedepth; - turb= tex->turbul/5.0f; + n = tex->noisedepth; + turb = tex->turbul / 5.0f; - x = sinf(( texvec[0] + texvec[1] + texvec[2]) * 5.0f); + x = sinf((texvec[0] + texvec[1] + texvec[2]) * 5.0f); y = cosf((-texvec[0] + texvec[1] - texvec[2]) * 5.0f); z = -cosf((-texvec[0] - texvec[1] + texvec[2]) * 5.0f); - if (n>0) { - x*= turb; - y*= turb; - z*= turb; - y= -cosf(x-y+z); - y*= turb; - if (n>1) { - x= cosf(x-y-z); - x*= turb; - if (n>2) { - z= sinf(-x-y-z); - z*= turb; - if (n>3) { - x= -cosf(-x+y-z); - x*= turb; - if (n>4) { - y= -sinf(-x+y+z); - y*= turb; - if (n>5) { - y= -cosf(-x+y+z); - y*= turb; - if (n>6) { - x= cosf(x+y+z); - x*= turb; - if (n>7) { - z= sinf(x+y-z); - z*= turb; - if (n>8) { - x= -cosf(-x-y+z); - x*= turb; - if (n>9) { - y= -sinf(x-y+z); - y*= turb; + if (n > 0) { + x *= turb; + y *= turb; + z *= turb; + y = -cosf(x - y + z); + y *= turb; + if (n > 1) { + x = cosf(x - y - z); + x *= turb; + if (n > 2) { + z = sinf(-x - y - z); + z *= turb; + if (n > 3) { + x = -cosf(-x + y - z); + x *= turb; + if (n > 4) { + y = -sinf(-x + y + z); + y *= turb; + if (n > 5) { + y = -cosf(-x + y + z); + y *= turb; + if (n > 6) { + x = cosf(x + y + z); + x *= turb; + if (n > 7) { + z = sinf(x + y - z); + z *= turb; + if (n > 8) { + x = -cosf(-x - y + z); + x *= turb; + if (n > 9) { + y = -sinf(x - y + z); + y *= turb; } } } @@ -386,17 +386,17 @@ static int magic(Tex *tex, const float texvec[3], TexResult *texres) } } - if (turb!=0.0f) { - turb*= 2.0f; - x/= turb; - y/= turb; - z/= turb; + if (turb != 0.0f) { + turb *= 2.0f; + x /= turb; + y /= turb; + z /= turb; } texres->tr = 0.5f - x; texres->tg = 0.5f - y; texres->tb = 0.5f - z; - texres->tin= (1.0f / 3.0f) * (texres->tr + texres->tg + texres->tb); + texres->tin = (1.0f / 3.0f) * (texres->tr + texres->tg + texres->tb); BRICONTRGB; texres->ta = 1.0f; @@ -410,38 +410,38 @@ static int magic(Tex *tex, const float texvec[3], TexResult *texres) static int stucci(Tex *tex, const float texvec[3], TexResult *texres) { float nor[3], b2, ofs; - int retval= TEX_INT; + int retval = TEX_INT; - b2= BLI_gNoise(tex->noisesize, texvec[0], texvec[1], texvec[2], (tex->noisetype!=TEX_NOISESOFT), tex->noisebasis); + b2 = BLI_gNoise(tex->noisesize, texvec[0], texvec[1], texvec[2], (tex->noisetype != TEX_NOISESOFT), tex->noisebasis); - ofs= tex->turbul/200.0f; + ofs = tex->turbul / 200.0f; - if (tex->stype) ofs*=(b2*b2); - nor[0] = BLI_gNoise(tex->noisesize, texvec[0]+ofs, texvec[1], texvec[2], (tex->noisetype!=TEX_NOISESOFT), tex->noisebasis); - nor[1] = BLI_gNoise(tex->noisesize, texvec[0], texvec[1]+ofs, texvec[2], (tex->noisetype!=TEX_NOISESOFT), tex->noisebasis); - nor[2] = BLI_gNoise(tex->noisesize, texvec[0], texvec[1], texvec[2]+ofs, (tex->noisetype!=TEX_NOISESOFT), tex->noisebasis); + if (tex->stype) ofs *= (b2 * b2); + nor[0] = BLI_gNoise(tex->noisesize, texvec[0] + ofs, texvec[1], texvec[2], (tex->noisetype != TEX_NOISESOFT), tex->noisebasis); + nor[1] = BLI_gNoise(tex->noisesize, texvec[0], texvec[1] + ofs, texvec[2], (tex->noisetype != TEX_NOISESOFT), tex->noisebasis); + nor[2] = BLI_gNoise(tex->noisesize, texvec[0], texvec[1], texvec[2] + ofs, (tex->noisetype != TEX_NOISESOFT), tex->noisebasis); - texres->tin= nor[2]; + texres->tin = nor[2]; if (texres->nor) { copy_v3_v3(texres->nor, nor); tex_normal_derivate(tex, texres); - if (tex->stype==TEX_WALLOUT) { - texres->nor[0]= -texres->nor[0]; - texres->nor[1]= -texres->nor[1]; - texres->nor[2]= -texres->nor[2]; + if (tex->stype == TEX_WALLOUT) { + texres->nor[0] = -texres->nor[0]; + texres->nor[1] = -texres->nor[1]; + texres->nor[2] = -texres->nor[2]; } retval |= TEX_NOR; } - if (tex->stype==TEX_WALLOUT) - texres->tin= 1.0f-texres->tin; + if (tex->stype == TEX_WALLOUT) + texres->tin = 1.0f - texres->tin; - if (texres->tin<0.0f) - texres->tin= 0.0f; + if (texres->tin < 0.0f) + texres->tin = 0.0f; return retval; } @@ -454,20 +454,20 @@ static float mg_mFractalOrfBmTex(Tex *tex, const float texvec[3], TexResult *tex int rv = TEX_INT; float (*mgravefunc)(float, float, float, float, float, float, int); - if (tex->stype==TEX_MFRACTAL) + if (tex->stype == TEX_MFRACTAL) mgravefunc = mg_MultiFractal; else mgravefunc = mg_fBm; - texres->tin = tex->ns_outscale*mgravefunc(texvec[0], texvec[1], texvec[2], tex->mg_H, tex->mg_lacunarity, tex->mg_octaves, tex->noisebasis); + texres->tin = tex->ns_outscale * mgravefunc(texvec[0], texvec[1], texvec[2], tex->mg_H, tex->mg_lacunarity, tex->mg_octaves, tex->noisebasis); - if (texres->nor!=NULL) { - float offs= tex->nabla/tex->noisesize; /* also scaling of texvec */ + if (texres->nor != NULL) { + float offs = tex->nabla / tex->noisesize; /* also scaling of texvec */ /* calculate bumpnormal */ - texres->nor[0] = tex->ns_outscale*mgravefunc(texvec[0] + offs, texvec[1], texvec[2], tex->mg_H, tex->mg_lacunarity, tex->mg_octaves, tex->noisebasis); - texres->nor[1] = tex->ns_outscale*mgravefunc(texvec[0], texvec[1] + offs, texvec[2], tex->mg_H, tex->mg_lacunarity, tex->mg_octaves, tex->noisebasis); - texres->nor[2] = tex->ns_outscale*mgravefunc(texvec[0], texvec[1], texvec[2] + offs, tex->mg_H, tex->mg_lacunarity, tex->mg_octaves, tex->noisebasis); + texres->nor[0] = tex->ns_outscale * mgravefunc(texvec[0] + offs, texvec[1], texvec[2], tex->mg_H, tex->mg_lacunarity, tex->mg_octaves, tex->noisebasis); + texres->nor[1] = tex->ns_outscale * mgravefunc(texvec[0], texvec[1] + offs, texvec[2], tex->mg_H, tex->mg_lacunarity, tex->mg_octaves, tex->noisebasis); + texres->nor[2] = tex->ns_outscale * mgravefunc(texvec[0], texvec[1], texvec[2] + offs, tex->mg_H, tex->mg_lacunarity, tex->mg_octaves, tex->noisebasis); tex_normal_derivate(tex, texres); rv |= TEX_NOR; @@ -484,20 +484,20 @@ static float mg_ridgedOrHybridMFTex(Tex *tex, const float texvec[3], TexResult * int rv = TEX_INT; float (*mgravefunc)(float, float, float, float, float, float, float, float, int); - if (tex->stype==TEX_RIDGEDMF) + if (tex->stype == TEX_RIDGEDMF) mgravefunc = mg_RidgedMultiFractal; else mgravefunc = mg_HybridMultiFractal; - texres->tin = tex->ns_outscale*mgravefunc(texvec[0], texvec[1], texvec[2], tex->mg_H, tex->mg_lacunarity, tex->mg_octaves, tex->mg_offset, tex->mg_gain, tex->noisebasis); + texres->tin = tex->ns_outscale * mgravefunc(texvec[0], texvec[1], texvec[2], tex->mg_H, tex->mg_lacunarity, tex->mg_octaves, tex->mg_offset, tex->mg_gain, tex->noisebasis); - if (texres->nor!=NULL) { - float offs= tex->nabla/tex->noisesize; /* also scaling of texvec */ + if (texres->nor != NULL) { + float offs = tex->nabla / tex->noisesize; /* also scaling of texvec */ /* calculate bumpnormal */ - texres->nor[0] = tex->ns_outscale*mgravefunc(texvec[0] + offs, texvec[1], texvec[2], tex->mg_H, tex->mg_lacunarity, tex->mg_octaves, tex->mg_offset, tex->mg_gain, tex->noisebasis); - texres->nor[1] = tex->ns_outscale*mgravefunc(texvec[0], texvec[1] + offs, texvec[2], tex->mg_H, tex->mg_lacunarity, tex->mg_octaves, tex->mg_offset, tex->mg_gain, tex->noisebasis); - texres->nor[2] = tex->ns_outscale*mgravefunc(texvec[0], texvec[1], texvec[2] + offs, tex->mg_H, tex->mg_lacunarity, tex->mg_octaves, tex->mg_offset, tex->mg_gain, tex->noisebasis); + texres->nor[0] = tex->ns_outscale * mgravefunc(texvec[0] + offs, texvec[1], texvec[2], tex->mg_H, tex->mg_lacunarity, tex->mg_octaves, tex->mg_offset, tex->mg_gain, tex->noisebasis); + texres->nor[1] = tex->ns_outscale * mgravefunc(texvec[0], texvec[1] + offs, texvec[2], tex->mg_H, tex->mg_lacunarity, tex->mg_octaves, tex->mg_offset, tex->mg_gain, tex->noisebasis); + texres->nor[2] = tex->ns_outscale * mgravefunc(texvec[0], texvec[1], texvec[2] + offs, tex->mg_H, tex->mg_lacunarity, tex->mg_octaves, tex->mg_offset, tex->mg_gain, tex->noisebasis); tex_normal_derivate(tex, texres); rv |= TEX_NOR; @@ -514,15 +514,15 @@ static float mg_HTerrainTex(Tex *tex, const float texvec[3], TexResult *texres) { int rv = TEX_INT; - texres->tin = tex->ns_outscale*mg_HeteroTerrain(texvec[0], texvec[1], texvec[2], tex->mg_H, tex->mg_lacunarity, tex->mg_octaves, tex->mg_offset, tex->noisebasis); + texres->tin = tex->ns_outscale * mg_HeteroTerrain(texvec[0], texvec[1], texvec[2], tex->mg_H, tex->mg_lacunarity, tex->mg_octaves, tex->mg_offset, tex->noisebasis); - if (texres->nor!=NULL) { - float offs= tex->nabla/tex->noisesize; /* also scaling of texvec */ + if (texres->nor != NULL) { + float offs = tex->nabla / tex->noisesize; /* also scaling of texvec */ /* calculate bumpnormal */ - texres->nor[0] = tex->ns_outscale*mg_HeteroTerrain(texvec[0] + offs, texvec[1], texvec[2], tex->mg_H, tex->mg_lacunarity, tex->mg_octaves, tex->mg_offset, tex->noisebasis); - texres->nor[1] = tex->ns_outscale*mg_HeteroTerrain(texvec[0], texvec[1] + offs, texvec[2], tex->mg_H, tex->mg_lacunarity, tex->mg_octaves, tex->mg_offset, tex->noisebasis); - texres->nor[2] = tex->ns_outscale*mg_HeteroTerrain(texvec[0], texvec[1], texvec[2] + offs, tex->mg_H, tex->mg_lacunarity, tex->mg_octaves, tex->mg_offset, tex->noisebasis); + texres->nor[0] = tex->ns_outscale * mg_HeteroTerrain(texvec[0] + offs, texvec[1], texvec[2], tex->mg_H, tex->mg_lacunarity, tex->mg_octaves, tex->mg_offset, tex->noisebasis); + texres->nor[1] = tex->ns_outscale * mg_HeteroTerrain(texvec[0], texvec[1] + offs, texvec[2], tex->mg_H, tex->mg_lacunarity, tex->mg_octaves, tex->mg_offset, tex->noisebasis); + texres->nor[2] = tex->ns_outscale * mg_HeteroTerrain(texvec[0], texvec[1], texvec[2] + offs, tex->mg_H, tex->mg_lacunarity, tex->mg_octaves, tex->mg_offset, tex->noisebasis); tex_normal_derivate(tex, texres); rv |= TEX_NOR; @@ -541,8 +541,8 @@ static float mg_distNoiseTex(Tex *tex, const float texvec[3], TexResult *texres) texres->tin = mg_VLNoise(texvec[0], texvec[1], texvec[2], tex->dist_amount, tex->noisebasis, tex->noisebasis2); - if (texres->nor!=NULL) { - float offs= tex->nabla/tex->noisesize; /* also scaling of texvec */ + if (texres->nor != NULL) { + float offs = tex->nabla / tex->noisesize; /* also scaling of texvec */ /* calculate bumpnormal */ texres->nor[0] = mg_VLNoise(texvec[0] + offs, texvec[1], texvec[2], tex->dist_amount, tex->noisebasis, tex->noisebasis2); @@ -567,39 +567,39 @@ static float mg_distNoiseTex(Tex *tex, const float texvec[3], TexResult *texres) static float voronoiTex(Tex *tex, const float texvec[3], TexResult *texres) { int rv = TEX_INT; - float da[4], pa[12]; /* distance and point coordinate arrays of 4 nearest neighbors */ + float da[4], pa[12]; /* distance and point coordinate arrays of 4 nearest neighbors */ float aw1 = fabsf(tex->vn_w1); float aw2 = fabsf(tex->vn_w2); float aw3 = fabsf(tex->vn_w3); float aw4 = fabsf(tex->vn_w4); float sc = (aw1 + aw2 + aw3 + aw4); - if (sc!=0.f) sc = tex->ns_outscale/sc; + if (sc != 0.f) sc = tex->ns_outscale / sc; voronoi(texvec[0], texvec[1], texvec[2], da, pa, tex->vn_mexp, tex->vn_distm); - texres->tin = sc * fabsf(tex->vn_w1*da[0] + tex->vn_w2*da[1] + tex->vn_w3*da[2] + tex->vn_w4*da[3]); + texres->tin = sc * fabsf(tex->vn_w1 * da[0] + tex->vn_w2 * da[1] + tex->vn_w3 * da[2] + tex->vn_w4 * da[3]); if (tex->vn_coltype) { - float ca[3]; /* cell color */ + float ca[3]; /* cell color */ cellNoiseV(pa[0], pa[1], pa[2], ca); - texres->tr = aw1*ca[0]; - texres->tg = aw1*ca[1]; - texres->tb = aw1*ca[2]; + texres->tr = aw1 * ca[0]; + texres->tg = aw1 * ca[1]; + texres->tb = aw1 * ca[2]; cellNoiseV(pa[3], pa[4], pa[5], ca); - texres->tr += aw2*ca[0]; - texres->tg += aw2*ca[1]; - texres->tb += aw2*ca[2]; + texres->tr += aw2 * ca[0]; + texres->tg += aw2 * ca[1]; + texres->tb += aw2 * ca[2]; cellNoiseV(pa[6], pa[7], pa[8], ca); - texres->tr += aw3*ca[0]; - texres->tg += aw3*ca[1]; - texres->tb += aw3*ca[2]; + texres->tr += aw3 * ca[0]; + texres->tg += aw3 * ca[1]; + texres->tb += aw3 * ca[2]; cellNoiseV(pa[9], pa[10], pa[11], ca); - texres->tr += aw4*ca[0]; - texres->tg += aw4*ca[1]; - texres->tb += aw4*ca[2]; - if (tex->vn_coltype>=2) { - float t1 = (da[1]-da[0])*10; - if (t1>1) t1=1; - if (tex->vn_coltype==3) t1*=texres->tin; else t1*=sc; + texres->tr += aw4 * ca[0]; + texres->tg += aw4 * ca[1]; + texres->tb += aw4 * ca[2]; + if (tex->vn_coltype >= 2) { + float t1 = (da[1] - da[0]) * 10; + if (t1 > 1) t1 = 1; + if (tex->vn_coltype == 3) t1 *= texres->tin; else t1 *= sc; texres->tr *= t1; texres->tg *= t1; texres->tb *= t1; @@ -611,16 +611,16 @@ static float voronoiTex(Tex *tex, const float texvec[3], TexResult *texres) } } - if (texres->nor!=NULL) { - float offs= tex->nabla/tex->noisesize; /* also scaling of texvec */ + if (texres->nor != NULL) { + float offs = tex->nabla / tex->noisesize; /* also scaling of texvec */ /* calculate bumpnormal */ voronoi(texvec[0] + offs, texvec[1], texvec[2], da, pa, tex->vn_mexp, tex->vn_distm); - texres->nor[0] = sc * fabsf(tex->vn_w1*da[0] + tex->vn_w2*da[1] + tex->vn_w3*da[2] + tex->vn_w4*da[3]); + texres->nor[0] = sc * fabsf(tex->vn_w1 * da[0] + tex->vn_w2 * da[1] + tex->vn_w3 * da[2] + tex->vn_w4 * da[3]); voronoi(texvec[0], texvec[1] + offs, texvec[2], da, pa, tex->vn_mexp, tex->vn_distm); - texres->nor[1] = sc * fabsf(tex->vn_w1*da[0] + tex->vn_w2*da[1] + tex->vn_w3*da[2] + tex->vn_w4*da[3]); + texres->nor[1] = sc * fabsf(tex->vn_w1 * da[0] + tex->vn_w2 * da[1] + tex->vn_w3 * da[2] + tex->vn_w4 * da[3]); voronoi(texvec[0], texvec[1], texvec[2] + offs, da, pa, tex->vn_mexp, tex->vn_distm); - texres->nor[2] = sc * fabsf(tex->vn_w1*da[0] + tex->vn_w2*da[1] + tex->vn_w3*da[2] + tex->vn_w4*da[3]); + texres->nor[2] = sc * fabsf(tex->vn_w1 * da[0] + tex->vn_w2 * da[1] + tex->vn_w3 * da[2] + tex->vn_w4 * da[3]); tex_normal_derivate(tex, texres); rv |= TEX_NOR; @@ -642,15 +642,15 @@ static float voronoiTex(Tex *tex, const float texvec[3], TexResult *texres) static int texnoise(Tex *tex, TexResult *texres, int thread) { - float div=3.0; + float div = 3.0; int val, ran, loop, shift = 29; - ran= BLI_rng_thread_rand(random_tex_array, thread); + ran = BLI_rng_thread_rand(random_tex_array, thread); - loop= tex->noisedepth; + loop = tex->noisedepth; /* start from top bits since they have more variance */ - val= ((ran >> shift) & 3); + val = ((ran >> shift) & 3); while (loop--) { shift -= 2; @@ -658,7 +658,7 @@ static int texnoise(Tex *tex, TexResult *texres, int thread) div *= 3.0f; } - texres->tin= ((float)val)/div; + texres->tin = ((float)val) / div; BRICONT; return TEX_INT; @@ -671,8 +671,8 @@ static int cubemap_glob(const float n[3], float x, float y, float z, float *adr1 float x1, y1, z1, nor[3]; int ret; - if (n==NULL) { - nor[0]= x; nor[1]= y; nor[2]= z; /* use local render coord */ + if (n == NULL) { + nor[0] = x; nor[1] = y; nor[2] = z; /* use local render coord */ } else { copy_v3_v3(nor, n); @@ -682,20 +682,20 @@ static int cubemap_glob(const float n[3], float x, float y, float z, float *adr1 y1 = fabsf(nor[1]); z1 = fabsf(nor[2]); - if (z1>=x1 && z1>=y1) { + if (z1 >= x1 && z1 >= y1) { *adr1 = (x + 1.0f) / 2.0f; *adr2 = (y + 1.0f) / 2.0f; - ret= 0; + ret = 0; } - else if (y1>=x1 && y1>=z1) { + else if (y1 >= x1 && y1 >= z1) { *adr1 = (x + 1.0f) / 2.0f; *adr2 = (z + 1.0f) / 2.0f; - ret= 1; + ret = 1; } else { *adr1 = (y + 1.0f) / 2.0f; *adr2 = (z + 1.0f) / 2.0f; - ret= 2; + ret = 2; } return ret; } @@ -705,90 +705,90 @@ static int cubemap_glob(const float n[3], float x, float y, float z, float *adr1 /* ------------------------------------------------------------------------- */ static void do_2d_mapping( - const MTex *mtex, float texvec[3], const float n[3], float dxt[3], float dyt[3]) + const MTex *mtex, float texvec[3], const float n[3], float dxt[3], float dyt[3]) { Tex *tex; float fx, fy, fac1, area[8]; - int ok, proj, areaflag= 0, wrap; + int ok, proj, areaflag = 0, wrap; /* mtex variables localized, only cubemap doesn't cooperate yet... */ - wrap= mtex->mapping; - tex= mtex->tex; + wrap = mtex->mapping; + tex = mtex->tex; if (!(dxt && dyt)) { - if (wrap==MTEX_FLAT) { + if (wrap == MTEX_FLAT) { fx = (texvec[0] + 1.0f) / 2.0f; fy = (texvec[1] + 1.0f) / 2.0f; } - else if (wrap == MTEX_TUBE) map_to_tube( &fx, &fy, texvec[0], texvec[1], texvec[2]); + else if (wrap == MTEX_TUBE) map_to_tube(&fx, &fy, texvec[0], texvec[1], texvec[2]); else if (wrap == MTEX_SPHERE) map_to_sphere(&fx, &fy, texvec[0], texvec[1], texvec[2]); else { cubemap_glob(n, texvec[0], texvec[1], texvec[2], &fx, &fy); } /* repeat */ - if (tex->extend==TEX_REPEAT) { - if (tex->xrepeat>1) { - float origf= fx *= tex->xrepeat; + if (tex->extend == TEX_REPEAT) { + if (tex->xrepeat > 1) { + float origf = fx *= tex->xrepeat; - if (fx>1.0f) fx -= (int)(fx); - else if (fx<0.0f) fx+= 1-(int)(fx); + if (fx > 1.0f) fx -= (int)(fx); + else if (fx < 0.0f) fx += 1 - (int)(fx); if (tex->flag & TEX_REPEAT_XMIR) { - int orig= (int)floor(origf); + int orig = (int)floor(origf); if (orig & 1) - fx= 1.0f-fx; + fx = 1.0f - fx; } } - if (tex->yrepeat>1) { - float origf= fy *= tex->yrepeat; + if (tex->yrepeat > 1) { + float origf = fy *= tex->yrepeat; - if (fy>1.0f) fy -= (int)(fy); - else if (fy<0.0f) fy+= 1-(int)(fy); + if (fy > 1.0f) fy -= (int)(fy); + else if (fy < 0.0f) fy += 1 - (int)(fy); if (tex->flag & TEX_REPEAT_YMIR) { - int orig= (int)floor(origf); + int orig = (int)floor(origf); if (orig & 1) - fy= 1.0f-fy; + fy = 1.0f - fy; } } } /* crop */ - if (tex->cropxmin!=0.0f || tex->cropxmax!=1.0f) { - fac1= tex->cropxmax - tex->cropxmin; - fx= tex->cropxmin+ fx*fac1; + if (tex->cropxmin != 0.0f || tex->cropxmax != 1.0f) { + fac1 = tex->cropxmax - tex->cropxmin; + fx = tex->cropxmin + fx * fac1; } - if (tex->cropymin!=0.0f || tex->cropymax!=1.0f) { - fac1= tex->cropymax - tex->cropymin; - fy= tex->cropymin+ fy*fac1; + if (tex->cropymin != 0.0f || tex->cropymax != 1.0f) { + fac1 = tex->cropymax - tex->cropymin; + fy = tex->cropymin + fy * fac1; } - texvec[0]= fx; - texvec[1]= fy; + texvec[0] = fx; + texvec[1] = fy; } else { - if (wrap==MTEX_FLAT) { - fx= (texvec[0] + 1.0f) / 2.0f; - fy= (texvec[1] + 1.0f) / 2.0f; - dxt[0]/= 2.0f; - dxt[1]/= 2.0f; - dxt[2]/= 2.0f; - dyt[0]/= 2.0f; - dyt[1]/= 2.0f; - dyt[2]/= 2.0f; + if (wrap == MTEX_FLAT) { + fx = (texvec[0] + 1.0f) / 2.0f; + fy = (texvec[1] + 1.0f) / 2.0f; + dxt[0] /= 2.0f; + dxt[1] /= 2.0f; + dxt[2] /= 2.0f; + dyt[0] /= 2.0f; + dyt[1] /= 2.0f; + dyt[2] /= 2.0f; } else if (ELEM(wrap, MTEX_TUBE, MTEX_SPHERE)) { /* exception: the seam behind (y<0.0) */ - ok= 1; - if (texvec[1]<=0.0f) { - fx= texvec[0]+dxt[0]; - fy= texvec[0]+dyt[0]; - if (fx>=0.0f && fy>=0.0f && texvec[0]>=0.0f) { + ok = 1; + if (texvec[1] <= 0.0f) { + fx = texvec[0] + dxt[0]; + fy = texvec[0] + dyt[0]; + if (fx >= 0.0f && fy >= 0.0f && texvec[0] >= 0.0f) { /* pass */ } - else if (fx<=0.0f && fy<=0.0f && texvec[0]<=0.0f) { + else if (fx <= 0.0f && fy <= 0.0f && texvec[0] <= 0.0f) { /* pass */ } else { @@ -797,43 +797,43 @@ static void do_2d_mapping( } if (ok) { - if (wrap==MTEX_TUBE) { - map_to_tube(area, area+1, texvec[0], texvec[1], texvec[2]); + if (wrap == MTEX_TUBE) { + map_to_tube(area, area + 1, texvec[0], texvec[1], texvec[2]); map_to_tube(area + 2, area + 3, texvec[0] + dxt[0], texvec[1] + dxt[1], texvec[2] + dxt[2]); map_to_tube(area + 4, area + 5, texvec[0] + dyt[0], texvec[1] + dyt[1], texvec[2] + dyt[2]); } else { - map_to_sphere(area, area+1, texvec[0], texvec[1], texvec[2]); + map_to_sphere(area, area + 1, texvec[0], texvec[1], texvec[2]); map_to_sphere(area + 2, area + 3, texvec[0] + dxt[0], texvec[1] + dxt[1], texvec[2] + dxt[2]); map_to_sphere(area + 4, area + 5, texvec[0] + dyt[0], texvec[1] + dyt[1], texvec[2] + dyt[2]); } - areaflag= 1; + areaflag = 1; } else { - if (wrap==MTEX_TUBE) map_to_tube( &fx, &fy, texvec[0], texvec[1], texvec[2]); + if (wrap == MTEX_TUBE) map_to_tube(&fx, &fy, texvec[0], texvec[1], texvec[2]); else map_to_sphere(&fx, &fy, texvec[0], texvec[1], texvec[2]); - dxt[0]/= 2.0f; - dxt[1]/= 2.0f; - dyt[0]/= 2.0f; - dyt[1]/= 2.0f; + dxt[0] /= 2.0f; + dxt[1] /= 2.0f; + dyt[0] /= 2.0f; + dyt[1] /= 2.0f; } } else { proj = cubemap_glob(n, texvec[0], texvec[1], texvec[2], &fx, &fy); - if (proj==1) { + if (proj == 1) { SWAP(float, dxt[1], dxt[2]); SWAP(float, dyt[1], dyt[2]); } - else if (proj==2) { - float f1= dxt[0], f2= dyt[0]; - dxt[0]= dxt[1]; - dyt[0]= dyt[1]; - dxt[1]= dxt[2]; - dyt[1]= dyt[2]; - dxt[2]= f1; - dyt[2]= f2; + else if (proj == 2) { + float f1 = dxt[0], f2 = dyt[0]; + dxt[0] = dxt[1]; + dyt[0] = dyt[1]; + dxt[1] = dxt[2]; + dyt[1] = dyt[2]; + dxt[2] = f1; + dyt[2] = f2; } dxt[0] *= 0.5f; @@ -848,80 +848,80 @@ static void do_2d_mapping( /* if area, then reacalculate dxt[] and dyt[] */ if (areaflag) { - fx= area[0]; - fy= area[1]; - dxt[0]= area[2]-fx; - dxt[1]= area[3]-fy; - dyt[0]= area[4]-fx; - dyt[1]= area[5]-fy; + fx = area[0]; + fy = area[1]; + dxt[0] = area[2] - fx; + dxt[1] = area[3] - fy; + dyt[0] = area[4] - fx; + dyt[1] = area[5] - fy; } /* repeat */ - if (tex->extend==TEX_REPEAT) { - float max= 1.0f; - if (tex->xrepeat>1) { - float origf= fx *= tex->xrepeat; + if (tex->extend == TEX_REPEAT) { + float max = 1.0f; + if (tex->xrepeat > 1) { + float origf = fx *= tex->xrepeat; /* TXF: omit mirror here, see comments in do_material_tex() after do_2d_mapping() call */ if (tex->texfilter == TXF_BOX) { - if (fx>1.0f) fx -= (int)(fx); - else if (fx<0.0f) fx+= 1-(int)(fx); + if (fx > 1.0f) fx -= (int)(fx); + else if (fx < 0.0f) fx += 1 - (int)(fx); if (tex->flag & TEX_REPEAT_XMIR) { - int orig= (int)floor(origf); + int orig = (int)floor(origf); if (orig & 1) - fx= 1.0f-fx; + fx = 1.0f - fx; } } - max= tex->xrepeat; + max = tex->xrepeat; - dxt[0]*= tex->xrepeat; - dyt[0]*= tex->xrepeat; + dxt[0] *= tex->xrepeat; + dyt[0] *= tex->xrepeat; } - if (tex->yrepeat>1) { - float origf= fy *= tex->yrepeat; + if (tex->yrepeat > 1) { + float origf = fy *= tex->yrepeat; /* TXF: omit mirror here, see comments in do_material_tex() after do_2d_mapping() call */ if (tex->texfilter == TXF_BOX) { - if (fy>1.0f) fy -= (int)(fy); - else if (fy<0.0f) fy+= 1-(int)(fy); + if (fy > 1.0f) fy -= (int)(fy); + else if (fy < 0.0f) fy += 1 - (int)(fy); if (tex->flag & TEX_REPEAT_YMIR) { - int orig= (int)floor(origf); + int orig = (int)floor(origf); if (orig & 1) - fy= 1.0f-fy; + fy = 1.0f - fy; } } - if (max<tex->yrepeat) - max= tex->yrepeat; + if (max < tex->yrepeat) + max = tex->yrepeat; - dxt[1]*= tex->yrepeat; - dyt[1]*= tex->yrepeat; + dxt[1] *= tex->yrepeat; + dyt[1] *= tex->yrepeat; } - if (max!=1.0f) { - dxt[2]*= max; - dyt[2]*= max; + if (max != 1.0f) { + dxt[2] *= max; + dyt[2] *= max; } } /* crop */ - if (tex->cropxmin!=0.0f || tex->cropxmax!=1.0f) { - fac1= tex->cropxmax - tex->cropxmin; - fx= tex->cropxmin+ fx*fac1; - dxt[0]*= fac1; - dyt[0]*= fac1; + if (tex->cropxmin != 0.0f || tex->cropxmax != 1.0f) { + fac1 = tex->cropxmax - tex->cropxmin; + fx = tex->cropxmin + fx * fac1; + dxt[0] *= fac1; + dyt[0] *= fac1; } - if (tex->cropymin!=0.0f || tex->cropymax!=1.0f) { - fac1= tex->cropymax - tex->cropymin; - fy= tex->cropymin+ fy*fac1; - dxt[1]*= fac1; - dyt[1]*= fac1; + if (tex->cropymin != 0.0f || tex->cropymax != 1.0f) { + fac1 = tex->cropymax - tex->cropymin; + fy = tex->cropymin + fy * fac1; + dxt[1] *= fac1; + dyt[1] *= fac1; } - texvec[0]= fx; - texvec[1]= fy; + texvec[0] = fx; + texvec[1] = fy; } } @@ -953,7 +953,7 @@ static int multitex(Tex *tex, else { switch (tex->type) { case 0: - texres->tin= 0.0f; + texres->tin = 0.0f; return 0; case TEX_CLOUDS: retval = clouds(tex, texvec, texres); @@ -978,7 +978,7 @@ static int multitex(Tex *tex, break; case TEX_IMAGE: if (osatex) retval = imagewraposa(tex, tex->ima, NULL, texvec, dxt, dyt, texres, pool, skip_load_image); - else retval = imagewrap(tex, tex->ima, NULL, texvec, texres, pool, skip_load_image); + else retval = imagewrap(tex, tex->ima, NULL, texvec, texres, pool, skip_load_image); if (tex->ima) { BKE_image_tag_time(tex->ima); } @@ -1006,7 +1006,7 @@ static int multitex(Tex *tex, break; } break; - /* newnoise: voronoi type */ + /* newnoise: voronoi type */ case TEX_VORONOI: /* ton: added this, for Blender convention reason. * artificer: added the use of tmpvec to avoid scaling texvec @@ -1032,10 +1032,10 @@ static int multitex(Tex *tex, float col[4]; if (BKE_colorband_evaluate(tex->coba, texres->tin, col)) { texres->talpha = true; - texres->tr= col[0]; - texres->tg= col[1]; - texres->tb= col[2]; - texres->ta= col[3]; + texres->tr = col[0]; + texres->tg = col[1]; + texres->tb = col[2]; + texres->ta = col[3]; retval |= TEX_RGB; } } @@ -1056,15 +1056,15 @@ static int multitex_nodes_intern(Tex *tex, const bool texnode_preview, const bool use_nodes) { - if (tex==NULL) { + if (tex == NULL) { memset(texres, 0, sizeof(TexResult)); return 0; } if (mtex) - which_output= mtex->which_output; + which_output = mtex->which_output; - if (tex->type==TEX_IMAGE) { + if (tex->type == TEX_IMAGE) { int rgbnor; if (mtex) { @@ -1102,10 +1102,10 @@ static int multitex_nodes_intern(Tex *tex, MTex localmtex; float texvec_l[3], dxt_l[3], dyt_l[3]; - localmtex.mapping= MTEX_FLAT; - localmtex.tex= tex; - localmtex.object= NULL; - localmtex.texco= TEXCO_ORCO; + localmtex.mapping = MTEX_FLAT; + localmtex.tex = tex; + localmtex.object = NULL; + localmtex.texco = TEXCO_ORCO; copy_v3_v3(texvec_l, texvec); if (dxt && dyt) { @@ -1238,90 +1238,90 @@ void texture_rgb_blend(float in[3], const float tex[3], const float out[3], floa switch (blendtype) { case MTEX_BLEND: - fact*= facg; - facm= 1.0f-fact; + fact *= facg; + facm = 1.0f - fact; - in[0]= (fact*tex[0] + facm*out[0]); - in[1]= (fact*tex[1] + facm*out[1]); - in[2]= (fact*tex[2] + facm*out[2]); + in[0] = (fact * tex[0] + facm * out[0]); + in[1] = (fact * tex[1] + facm * out[1]); + in[2] = (fact * tex[2] + facm * out[2]); break; case MTEX_MUL: - fact*= facg; - facm= 1.0f-fact; - in[0]= (facm+fact*tex[0])*out[0]; - in[1]= (facm+fact*tex[1])*out[1]; - in[2]= (facm+fact*tex[2])*out[2]; + fact *= facg; + facm = 1.0f - fact; + in[0] = (facm + fact * tex[0]) * out[0]; + in[1] = (facm + fact * tex[1]) * out[1]; + in[2] = (facm + fact * tex[2]) * out[2]; break; case MTEX_SCREEN: - fact*= facg; - facm= 1.0f-fact; - in[0]= 1.0f - (facm+fact*(1.0f-tex[0])) * (1.0f-out[0]); - in[1]= 1.0f - (facm+fact*(1.0f-tex[1])) * (1.0f-out[1]); - in[2]= 1.0f - (facm+fact*(1.0f-tex[2])) * (1.0f-out[2]); + fact *= facg; + facm = 1.0f - fact; + in[0] = 1.0f - (facm + fact * (1.0f - tex[0])) * (1.0f - out[0]); + in[1] = 1.0f - (facm + fact * (1.0f - tex[1])) * (1.0f - out[1]); + in[2] = 1.0f - (facm + fact * (1.0f - tex[2])) * (1.0f - out[2]); break; case MTEX_OVERLAY: - fact*= facg; - facm= 1.0f-fact; + fact *= facg; + facm = 1.0f - fact; if (out[0] < 0.5f) - in[0] = out[0] * (facm + 2.0f*fact*tex[0]); + in[0] = out[0] * (facm + 2.0f * fact * tex[0]); else - in[0] = 1.0f - (facm + 2.0f*fact*(1.0f - tex[0])) * (1.0f - out[0]); + in[0] = 1.0f - (facm + 2.0f * fact * (1.0f - tex[0])) * (1.0f - out[0]); if (out[1] < 0.5f) - in[1] = out[1] * (facm + 2.0f*fact*tex[1]); + in[1] = out[1] * (facm + 2.0f * fact * tex[1]); else - in[1] = 1.0f - (facm + 2.0f*fact*(1.0f - tex[1])) * (1.0f - out[1]); + in[1] = 1.0f - (facm + 2.0f * fact * (1.0f - tex[1])) * (1.0f - out[1]); if (out[2] < 0.5f) - in[2] = out[2] * (facm + 2.0f*fact*tex[2]); + in[2] = out[2] * (facm + 2.0f * fact * tex[2]); else - in[2] = 1.0f - (facm + 2.0f*fact*(1.0f - tex[2])) * (1.0f - out[2]); + in[2] = 1.0f - (facm + 2.0f * fact * (1.0f - tex[2])) * (1.0f - out[2]); break; case MTEX_SUB: - fact= -fact; + fact = -fact; ATTR_FALLTHROUGH; case MTEX_ADD: - fact*= facg; - in[0]= (fact*tex[0] + out[0]); - in[1]= (fact*tex[1] + out[1]); - in[2]= (fact*tex[2] + out[2]); + fact *= facg; + in[0] = (fact * tex[0] + out[0]); + in[1] = (fact * tex[1] + out[1]); + in[2] = (fact * tex[2] + out[2]); break; case MTEX_DIV: - fact*= facg; - facm= 1.0f-fact; + fact *= facg; + facm = 1.0f - fact; - if (tex[0]!=0.0f) - in[0]= facm*out[0] + fact*out[0]/tex[0]; - if (tex[1]!=0.0f) - in[1]= facm*out[1] + fact*out[1]/tex[1]; - if (tex[2]!=0.0f) - in[2]= facm*out[2] + fact*out[2]/tex[2]; + if (tex[0] != 0.0f) + in[0] = facm * out[0] + fact * out[0] / tex[0]; + if (tex[1] != 0.0f) + in[1] = facm * out[1] + fact * out[1] / tex[1]; + if (tex[2] != 0.0f) + in[2] = facm * out[2] + fact * out[2] / tex[2]; break; case MTEX_DIFF: - fact*= facg; - facm= 1.0f-fact; - in[0]= facm*out[0] + fact*fabsf(tex[0]-out[0]); - in[1]= facm*out[1] + fact*fabsf(tex[1]-out[1]); - in[2]= facm*out[2] + fact*fabsf(tex[2]-out[2]); + fact *= facg; + facm = 1.0f - fact; + in[0] = facm * out[0] + fact * fabsf(tex[0] - out[0]); + in[1] = facm * out[1] + fact * fabsf(tex[1] - out[1]); + in[2] = facm * out[2] + fact * fabsf(tex[2] - out[2]); break; case MTEX_DARK: - fact*= facg; - facm= 1.0f-fact; + fact *= facg; + facm = 1.0f - fact; - in[0] = min_ff(out[0], tex[0])*fact + out[0]*facm; - in[1] = min_ff(out[1], tex[1])*fact + out[1]*facm; - in[2] = min_ff(out[2], tex[2])*fact + out[2]*facm; + in[0] = min_ff(out[0], tex[0]) * fact + out[0] * facm; + in[1] = min_ff(out[1], tex[1]) * fact + out[1] * facm; + in[2] = min_ff(out[2], tex[2]) * fact + out[2] * facm; break; case MTEX_LIGHT: - fact*= facg; + fact *= facg; in[0] = max_ff(fact * tex[0], out[0]); in[1] = max_ff(fact * tex[1], out[1]); @@ -1329,32 +1329,32 @@ void texture_rgb_blend(float in[3], const float tex[3], const float out[3], floa break; case MTEX_BLEND_HUE: - fact*= facg; + fact *= facg; copy_v3_v3(in, out); ramp_blend(MA_RAMP_HUE, in, fact, tex); break; case MTEX_BLEND_SAT: - fact*= facg; + fact *= facg; copy_v3_v3(in, out); ramp_blend(MA_RAMP_SAT, in, fact, tex); break; case MTEX_BLEND_VAL: - fact*= facg; + fact *= facg; copy_v3_v3(in, out); ramp_blend(MA_RAMP_VAL, in, fact, tex); break; case MTEX_BLEND_COLOR: - fact*= facg; + fact *= facg; copy_v3_v3(in, out); ramp_blend(MA_RAMP_COLOR, in, fact, tex); break; case MTEX_SOFT_LIGHT: - fact*= facg; + fact *= facg; copy_v3_v3(in, out); ramp_blend(MA_RAMP_SOFT, in, fact, tex); break; case MTEX_LIN_LIGHT: - fact*= facg; + fact *= facg; copy_v3_v3(in, out); ramp_blend(MA_RAMP_LINEAR, in, fact, tex); break; @@ -1363,73 +1363,73 @@ void texture_rgb_blend(float in[3], const float tex[3], const float out[3], floa float texture_value_blend(float tex, float out, float fact, float facg, int blendtype) { - float in=0.0, facm, col, scf; - int flip= (facg < 0.0f); + float in = 0.0, facm, col, scf; + int flip = (facg < 0.0f); - facg= fabsf(facg); + facg = fabsf(facg); - fact*= facg; - facm= 1.0f-fact; + fact *= facg; + facm = 1.0f - fact; if (flip) SWAP(float, fact, facm); switch (blendtype) { case MTEX_BLEND: - in= fact*tex + facm*out; + in = fact * tex + facm * out; break; case MTEX_MUL: - facm= 1.0f-facg; - in= (facm+fact*tex)*out; + facm = 1.0f - facg; + in = (facm + fact * tex) * out; break; case MTEX_SCREEN: - facm= 1.0f-facg; - in= 1.0f-(facm+fact*(1.0f-tex))*(1.0f-out); + facm = 1.0f - facg; + in = 1.0f - (facm + fact * (1.0f - tex)) * (1.0f - out); break; case MTEX_OVERLAY: - facm= 1.0f-facg; + facm = 1.0f - facg; if (out < 0.5f) - in = out * (facm + 2.0f*fact*tex); + in = out * (facm + 2.0f * fact * tex); else - in = 1.0f - (facm + 2.0f*fact*(1.0f - tex)) * (1.0f - out); + in = 1.0f - (facm + 2.0f * fact * (1.0f - tex)) * (1.0f - out); break; case MTEX_SUB: - fact= -fact; + fact = -fact; ATTR_FALLTHROUGH; case MTEX_ADD: - in= fact*tex + out; + in = fact * tex + out; break; case MTEX_DIV: - if (tex!=0.0f) - in= facm*out + fact*out/tex; + if (tex != 0.0f) + in = facm * out + fact * out / tex; break; case MTEX_DIFF: - in= facm*out + fact*fabsf(tex-out); + in = facm * out + fact * fabsf(tex - out); break; case MTEX_DARK: - in = min_ff(out, tex)*fact + out*facm; + in = min_ff(out, tex) * fact + out * facm; break; case MTEX_LIGHT: - col= fact*tex; - if (col > out) in= col; else in= out; + col = fact * tex; + if (col > out) in = col; else in = out; break; case MTEX_SOFT_LIGHT: - scf=1.0f - (1.0f - tex) * (1.0f - out); - in= facm*out + fact * ((1.0f - out) * tex * out) + (out * scf); + scf = 1.0f - (1.0f - tex) * (1.0f - out); + in = facm * out + fact * ((1.0f - out) * tex * out) + (out * scf); break; case MTEX_LIN_LIGHT: if (tex > 0.5f) - in = out + fact*(2.0f*(tex - 0.5f)); + in = out + fact * (2.0f * (tex - 0.5f)); else - in = out + fact*(2.0f*tex - 1.0f); + in = out + fact * (2.0f * tex - 1.0f); break; } @@ -1451,22 +1451,22 @@ int externtex(const MTex *mtex, float dxt[3], dyt[3], texvec[3]; int rgb; - tex= mtex->tex; - if (tex==NULL) return 0; - texr.nor= NULL; + tex = mtex->tex; + if (tex == NULL) return 0; + texr.nor = NULL; /* placement */ - if (mtex->projx) texvec[0]= mtex->size[0]*(vec[mtex->projx-1]+mtex->ofs[0]); - else texvec[0]= mtex->size[0]*(mtex->ofs[0]); + if (mtex->projx) texvec[0] = mtex->size[0] * (vec[mtex->projx - 1] + mtex->ofs[0]); + else texvec[0] = mtex->size[0] * (mtex->ofs[0]); - if (mtex->projy) texvec[1]= mtex->size[1]*(vec[mtex->projy-1]+mtex->ofs[1]); - else texvec[1]= mtex->size[1]*(mtex->ofs[1]); + if (mtex->projy) texvec[1] = mtex->size[1] * (vec[mtex->projy - 1] + mtex->ofs[1]); + else texvec[1] = mtex->size[1] * (mtex->ofs[1]); - if (mtex->projz) texvec[2]= mtex->size[2]*(vec[mtex->projz-1]+mtex->ofs[2]); - else texvec[2]= mtex->size[2]*(mtex->ofs[2]); + if (mtex->projz) texvec[2] = mtex->size[2] * (vec[mtex->projz - 1] + mtex->ofs[2]); + else texvec[2] = mtex->size[2] * (mtex->ofs[2]); /* texture */ - if (tex->type==TEX_IMAGE) { + if (tex->type == TEX_IMAGE) { do_2d_mapping(mtex, texvec, NULL, dxt, dyt); } @@ -1485,16 +1485,16 @@ int externtex(const MTex *mtex, texr.tin = IMB_colormanagement_get_luminance(&texr.tr); } else { - texr.tr= mtex->r; - texr.tg= mtex->g; - texr.tb= mtex->b; + texr.tr = mtex->r; + texr.tg = mtex->g; + texr.tb = mtex->b; } - *tin= texr.tin; - *tr= texr.tr; - *tg= texr.tg; - *tb= texr.tb; - *ta= texr.ta; + *tin = texr.tin; + *tr = texr.tr; + *tg = texr.tg; + *tb = texr.tb; + *ta = texr.ta; return (rgb != 0); } diff --git a/source/blender/render/intern/source/zbuf.c b/source/blender/render/intern/source/zbuf.c index 51104714a99..05944df770a 100644 --- a/source/blender/render/intern/source/zbuf.c +++ b/source/blender/render/intern/source/zbuf.c @@ -48,11 +48,11 @@ void zbuf_alloc_span(ZSpan *zspan, int rectx, int recty) { memset(zspan, 0, sizeof(ZSpan)); - zspan->rectx= rectx; - zspan->recty= recty; + zspan->rectx = rectx; + zspan->recty = recty; - zspan->span1= MEM_mallocN(recty*sizeof(float), "zspan"); - zspan->span2= MEM_mallocN(recty*sizeof(float), "zspan"); + zspan->span1 = MEM_mallocN(recty * sizeof(float), "zspan"); + zspan->span2 = MEM_mallocN(recty * sizeof(float), "zspan"); } void zbuf_free_span(ZSpan *zspan) @@ -60,16 +60,16 @@ void zbuf_free_span(ZSpan *zspan) if (zspan) { if (zspan->span1) MEM_freeN(zspan->span1); if (zspan->span2) MEM_freeN(zspan->span2); - zspan->span1= zspan->span2= NULL; + zspan->span1 = zspan->span2 = NULL; } } /* reset range for clipping */ static void zbuf_init_span(ZSpan *zspan) { - zspan->miny1= zspan->miny2= zspan->recty+1; - zspan->maxy1= zspan->maxy2= -1; - zspan->minp1= zspan->maxp1= zspan->minp2= zspan->maxp2= NULL; + zspan->miny1 = zspan->miny2 = zspan->recty + 1; + zspan->maxy1 = zspan->maxy2 = -1; + zspan->minp1 = zspan->maxp1 = zspan->minp2 = zspan->maxp2 = NULL; } static void zbuf_add_to_span(ZSpan *zspan, const float v1[2], const float v2[2]) @@ -79,30 +79,30 @@ static void zbuf_add_to_span(ZSpan *zspan, const float v1[2], const float v2[2]) float xx1, dx0, xs0; int y, my0, my2; - if (v1[1]<v2[1]) { - minv= v1; maxv= v2; + if (v1[1] < v2[1]) { + minv = v1; maxv = v2; } else { - minv= v2; maxv= v1; + minv = v2; maxv = v1; } - my0= ceil(minv[1]); - my2= floor(maxv[1]); + my0 = ceil(minv[1]); + my2 = floor(maxv[1]); - if (my2<0 || my0>= zspan->recty) return; + if (my2 < 0 || my0 >= zspan->recty) return; /* clip top */ - if (my2>=zspan->recty) my2= zspan->recty-1; + if (my2 >= zspan->recty) my2 = zspan->recty - 1; /* clip bottom */ - if (my0<0) my0= 0; + if (my0 < 0) my0 = 0; - if (my0>my2) return; + if (my0 > my2) return; /* if (my0>my2) should still fill in, that way we get spans that skip nicely */ - xx1= maxv[1]-minv[1]; - if (xx1>FLT_EPSILON) { - dx0= (minv[0]-maxv[0])/xx1; - xs0= dx0*(minv[1]-my2) + minv[0]; + xx1 = maxv[1] - minv[1]; + if (xx1 > FLT_EPSILON) { + dx0 = (minv[0] - maxv[0]) / xx1; + xs0 = dx0 * (minv[1] - my2) + minv[0]; } else { dx0 = 0.0f; @@ -111,43 +111,43 @@ static void zbuf_add_to_span(ZSpan *zspan, const float v1[2], const float v2[2]) /* empty span */ if (zspan->maxp1 == NULL) { - span= zspan->span1; + span = zspan->span1; } - else { /* does it complete left span? */ - if ( maxv == zspan->minp1 || minv==zspan->maxp1) { - span= zspan->span1; + else { /* does it complete left span? */ + if (maxv == zspan->minp1 || minv == zspan->maxp1) { + span = zspan->span1; } else { - span= zspan->span2; + span = zspan->span2; } } - if (span==zspan->span1) { + if (span == zspan->span1) { // printf("left span my0 %d my2 %d\n", my0, my2); - if (zspan->minp1==NULL || zspan->minp1[1] > minv[1] ) { - zspan->minp1= minv; + if (zspan->minp1 == NULL || zspan->minp1[1] > minv[1]) { + zspan->minp1 = minv; } - if (zspan->maxp1==NULL || zspan->maxp1[1] < maxv[1] ) { - zspan->maxp1= maxv; + if (zspan->maxp1 == NULL || zspan->maxp1[1] < maxv[1]) { + zspan->maxp1 = maxv; } - if (my0<zspan->miny1) zspan->miny1= my0; - if (my2>zspan->maxy1) zspan->maxy1= my2; + if (my0 < zspan->miny1) zspan->miny1 = my0; + if (my2 > zspan->maxy1) zspan->maxy1 = my2; } else { // printf("right span my0 %d my2 %d\n", my0, my2); - if (zspan->minp2==NULL || zspan->minp2[1] > minv[1] ) { - zspan->minp2= minv; + if (zspan->minp2 == NULL || zspan->minp2[1] > minv[1]) { + zspan->minp2 = minv; } - if (zspan->maxp2==NULL || zspan->maxp2[1] < maxv[1] ) { - zspan->maxp2= maxv; + if (zspan->maxp2 == NULL || zspan->maxp2[1] < maxv[1]) { + zspan->maxp2 = maxv; } - if (my0<zspan->miny2) zspan->miny2= my0; - if (my2>zspan->maxy2) zspan->maxy2= my2; + if (my0 < zspan->miny2) zspan->miny2 = my0; + if (my2 > zspan->maxy2) zspan->maxy2 = my2; } - for (y=my2; y>=my0; y--, xs0+= dx0) { + for (y = my2; y >= my0; y--, xs0 += dx0) { /* xs0 is the xcoord! */ - span[y]= xs0; + span[y] = xs0; } } @@ -173,57 +173,57 @@ void zspan_scanconvert(ZSpan *zspan, void *handle, float *v1, float *v2, float * zbuf_add_to_span(zspan, v3, v1); /* clipped */ - if (zspan->minp2==NULL || zspan->maxp2==NULL) return; + if (zspan->minp2 == NULL || zspan->maxp2 == NULL) return; my0 = max_ii(zspan->miny1, zspan->miny2); my2 = min_ii(zspan->maxy1, zspan->maxy2); // printf("my %d %d\n", my0, my2); - if (my2<my0) return; + if (my2 < my0) return; /* ZBUF DX DY, in floats still */ - x1= v1[0]- v2[0]; - x2= v2[0]- v3[0]; - y1= v1[1]- v2[1]; - y2= v2[1]- v3[1]; + x1 = v1[0] - v2[0]; + x2 = v2[0] - v3[0]; + y1 = v1[1] - v2[1]; + y2 = v2[1] - v3[1]; - z1= 1.0f; /* (u1 - u2) */ - z2= 0.0f; /* (u2 - u3) */ + z1 = 1.0f; /* (u1 - u2) */ + z2 = 0.0f; /* (u2 - u3) */ - x0= y1*z2-z1*y2; - y0= z1*x2-x1*z2; - z0= x1*y2-y1*x2; + x0 = y1 * z2 - z1 * y2; + y0 = z1 * x2 - x1 * z2; + z0 = x1 * y2 - y1 * x2; - if (z0==0.0f) return; + if (z0 == 0.0f) return; - xx1= (x0*v1[0] + y0*v1[1])/z0 + 1.0f; - uxd= -(double)x0/(double)z0; - uyd= -(double)y0/(double)z0; - uy0= ((double)my2)*uyd + (double)xx1; + xx1 = (x0 * v1[0] + y0 * v1[1]) / z0 + 1.0f; + uxd = -(double)x0 / (double)z0; + uyd = -(double)y0 / (double)z0; + uy0 = ((double)my2) * uyd + (double)xx1; - z1= -1.0f; /* (v1 - v2) */ - z2= 1.0f; /* (v2 - v3) */ + z1 = -1.0f; /* (v1 - v2) */ + z2 = 1.0f; /* (v2 - v3) */ - x0= y1*z2-z1*y2; - y0= z1*x2-x1*z2; + x0 = y1 * z2 - z1 * y2; + y0 = z1 * x2 - x1 * z2; - xx1= (x0*v1[0] + y0*v1[1])/z0; - vxd= -(double)x0/(double)z0; - vyd= -(double)y0/(double)z0; - vy0= ((double)my2)*vyd + (double)xx1; + xx1 = (x0 * v1[0] + y0 * v1[1]) / z0; + vxd = -(double)x0 / (double)z0; + vyd = -(double)y0 / (double)z0; + vy0 = ((double)my2) * vyd + (double)xx1; /* correct span */ - span1= zspan->span1+my2; - span2= zspan->span2+my2; + span1 = zspan->span1 + my2; + span2 = zspan->span2 + my2; for (i = 0, y = my2; y >= my0; i++, y--, span1--, span2--) { - sn1= floor(min_ff(*span1, *span2)); - sn2= floor(max_ff(*span1, *span2)); + sn1 = floor(min_ff(*span1, *span2)); + sn2 = floor(max_ff(*span1, *span2)); sn1++; - if (sn2>=rectx) sn2= rectx-1; - if (sn1<0) sn1= 0; + if (sn2 >= rectx) sn2 = rectx - 1; + if (sn1 < 0) sn1 = 0; u = (((double)sn1 * uxd) + uy0) - (i * uyd); v = (((double)sn1 * vxd) + vy0) - (i * vyd); |