diff options
Diffstat (limited to 'source/blender/render/intern')
26 files changed, 4809 insertions, 4711 deletions
diff --git a/source/blender/render/intern/raytrace/rayobject_octree.cpp b/source/blender/render/intern/raytrace/rayobject_octree.cpp index 3e2c60cfcc0..0411173f07f 100644 --- a/source/blender/render/intern/raytrace/rayobject_octree.cpp +++ b/source/blender/render/intern/raytrace/rayobject_octree.cpp @@ -158,7 +158,8 @@ static void calc_ocval_ray(OcVal *ov, float xo, float yo, float zo, float *vec1, if(vec1[0]<vec2[0]) { ocmin= OCVALRES*(vec1[0] - xo); ocmax= OCVALRES*(vec2[0] - xo); - } else { + } + else { ocmin= OCVALRES*(vec2[0] - xo); ocmax= OCVALRES*(vec1[0] - xo); } @@ -167,7 +168,8 @@ static void calc_ocval_ray(OcVal *ov, float xo, float yo, float zo, float *vec1, if(vec1[1]<vec2[1]) { ocmin= OCVALRES*(vec1[1] - yo); ocmax= OCVALRES*(vec2[1] - yo); - } else { + } + else { ocmin= OCVALRES*(vec2[1] - yo); ocmax= OCVALRES*(vec1[1] - yo); } @@ -176,7 +178,8 @@ static void calc_ocval_ray(OcVal *ov, float xo, float yo, float zo, float *vec1, if(vec1[2]<vec2[2]) { ocmin= OCVALRES*(vec1[2] - zo); ocmax= OCVALRES*(vec2[2] - zo); - } else { + } + else { ocmin= OCVALRES*(vec2[2] - zo); ocmax= OCVALRES*(vec1[2] - zo); } @@ -348,12 +351,14 @@ static void d2dda(Octree *oc, short b1, short b2, short c1, short c2, char *ocfa labdax= (ox1-ocx1-1.0f)/(ox1-ox2); ldx= -1.0f/(ox1-ox2); dx= 1; - } else { + } + else { labdax= (ox1-ocx1)/(ox1-ox2); ldx= 1.0f/(ox1-ox2); dx= -1; } - } else { + } + else { labdax=1.0f; ldx=0; } @@ -363,12 +368,14 @@ static void d2dda(Octree *oc, short b1, short b2, short c1, short c2, char *ocfa labday= (oy1-ocy1-1.0f)/(oy1-oy2); ldy= -1.0f/(oy1-oy2); dy= 1; - } else { + } + else { labday= (oy1-ocy1)/(oy1-oy2); ldy= 1.0f/(oy1-oy2); dy= -1; } - } else { + } + else { labday=1.0f; ldy=0; } @@ -387,11 +394,13 @@ static void d2dda(Octree *oc, short b1, short b2, short c1, short c2, char *ocfa x+=dx; labday+=ldy; y+=dy; - } else { + } + else { if(labdax<labday) { labdax+=ldx; x+=dx; - } else { + } + else { labday+=ldy; y+=dy; } @@ -940,11 +949,13 @@ static int RE_rayobject_octree_intersect(RayObject *tree, Isect *is) ldx= -1.0f/dox; labdax= (ocx1-ox1+1.0f)*ldx; dx= 1; - } else if(dox>FLT_EPSILON) { + } + else if(dox>FLT_EPSILON) { ldx= 1.0f/dox; labdax= (ox1-ocx1)*ldx; dx= -1; - } else { + } + else { labdax=1.0f; ldx=0; dx= 0; @@ -954,11 +965,13 @@ static int RE_rayobject_octree_intersect(RayObject *tree, Isect *is) ldy= -1.0f/doy; labday= (ocy1-oy1+1.0f)*ldy; dy= 1; - } else if(doy>FLT_EPSILON) { + } + else if(doy>FLT_EPSILON) { ldy= 1.0f/doy; labday= (oy1-ocy1)*ldy; dy= -1; - } else { + } + else { labday=1.0f; ldy=0; dy= 0; @@ -968,11 +981,13 @@ static int RE_rayobject_octree_intersect(RayObject *tree, Isect *is) ldz= -1.0f/doz; labdaz= (ocz1-oz1+1.0f)*ldz; dz= 1; - } else if(doz>FLT_EPSILON) { + } + else if(doz>FLT_EPSILON) { ldz= 1.0f/doz; labdaz= (oz1-ocz1)*ldz; dz= -1; - } else { + } + else { labdaz=1.0f; ldz=0; dz= 0; diff --git a/source/blender/render/intern/source/convertblender.c b/source/blender/render/intern/source/convertblender.c index a4c5adda721..7dd11dd1fe0 100644 --- a/source/blender/render/intern/source/convertblender.c +++ b/source/blender/render/intern/source/convertblender.c @@ -171,7 +171,7 @@ void RE_make_stars(Render *re, Scene *scenev3d, void (*initfunc)(void), int x, y, z, sx, sy, sz, ex, ey, ez, done = 0; unsigned int totstar= 0; - if(initfunc) { + if (initfunc) { scene= scenev3d; wrld= scene->world; } @@ -195,7 +195,7 @@ void RE_make_stars(Render *re, Scene *scenev3d, void (*initfunc)(void), if (re) re->flag |= R_HALO; else stargrid *= 1.0f; /* then it draws fewer */ - if(re) invert_m4_m4(mat, re->viewmat); + if (re) invert_m4_m4(mat, re->viewmat); else unit_m4(mat); /* BOUNDING BOX CALCULATION @@ -206,7 +206,7 @@ void RE_make_stars(Render *re, Scene *scenev3d, void (*initfunc)(void), camera= re ? RE_GetCamera(re) : scene->camera; - if(camera==NULL || camera->type != OB_CAMERA) + if (camera==NULL || camera->type != OB_CAMERA) return; cam = camera->data; @@ -229,7 +229,7 @@ void RE_make_stars(Render *re, Scene *scenev3d, void (*initfunc)(void), initfunc(); } - if(re) /* add render object for stars */ + if (re) /* add render object for stars */ obr= RE_addRenderObject(re, NULL, NULL, 0, 0, 0); for (x = sx, fx = sx * stargrid; x <= ex; x++, fx += stargrid) { @@ -243,7 +243,7 @@ void RE_make_stars(Render *re, Scene *scenev3d, void (*initfunc)(void), vec[3] = 1.0; if (vertexfunc) { - if(done & 1) vertexfunc(vec); + if (done & 1) vertexfunc(vec); done++; } else { @@ -267,7 +267,8 @@ void RE_make_stars(Render *re, Scene *scenev3d, void (*initfunc)(void), else if (alpha <= starmindist) alpha = 0.0; else if (alpha <= 2.0f * starmindist) { alpha = (alpha - starmindist) / starmindist; - } else { + } + else { alpha -= 2.0f * starmindist; alpha /= (clipend - 2.0f * starmindist); alpha = 1.0f - alpha; @@ -298,8 +299,8 @@ void RE_make_stars(Render *re, Scene *scenev3d, void (*initfunc)(void), } /* break out of the loop if generating stars takes too long */ - if(re && !(totstar % 1000000)) { - if(re->test_break(re->tbh)) { + if (re && !(totstar % 1000000)) { + if (re->test_break(re->tbh)) { x= ex + 1; y= ey + 1; z= ez + 1; @@ -314,7 +315,7 @@ void RE_make_stars(Render *re, Scene *scenev3d, void (*initfunc)(void), } if (termfunc) termfunc(); - if(obr) + if (obr) re->tothalo += obr->tothalo; } @@ -354,11 +355,13 @@ static void split_v_renderfaces(ObjectRen *obr, int startvlak, int UNUSED(startv if (v==vLen-1) { VlakRen *vlr = RE_findOrAddVlak(obr, startvlak + vLen*uIndex + 0); vlr->v1 = vert; - } else { + } + else { VlakRen *vlr = RE_findOrAddVlak(obr, startvlak + vLen*uIndex + v+1); vlr->v1 = vert; } - } else { + } + else { vlr->v2 = vert; if (v<vLen-1) { @@ -396,16 +399,16 @@ static void calc_edge_stress(Render *UNUSED(re), ObjectRen *obr, Mesh *me) float loc[3], size[3], *accum, *acc, *accumoffs, *stress; int a; - if(obr->totvert==0) return; + if (obr->totvert==0) return; mesh_get_texspace(me, loc, NULL, size); accum= MEM_callocN(2*sizeof(float)*obr->totvert, "temp accum for stress"); /* de-normalize orco */ - for(a=0; a<obr->totvert; a++) { + for (a=0; a<obr->totvert; a++) { VertRen *ver= RE_findOrAddVert(obr, a); - if(ver->orco) { + if (ver->orco) { ver->orco[0]= ver->orco[0]*size[0] +loc[0]; ver->orco[1]= ver->orco[1]*size[1] +loc[1]; ver->orco[2]= ver->orco[2]*size[2] +loc[2]; @@ -414,14 +417,14 @@ static void calc_edge_stress(Render *UNUSED(re), ObjectRen *obr, Mesh *me) /* add stress values */ accumoffs= accum; /* so we can use vertex index */ - for(a=0; a<obr->totvlak; a++) { + for (a=0; a<obr->totvlak; a++) { VlakRen *vlr= RE_findOrAddVlak(obr, a); - if(vlr->v1->orco && vlr->v4) { + if (vlr->v1->orco && vlr->v4) { calc_edge_stress_add(accumoffs, vlr->v1, vlr->v2); calc_edge_stress_add(accumoffs, vlr->v2, vlr->v3); calc_edge_stress_add(accumoffs, vlr->v3, vlr->v1); - if(vlr->v4) { + if (vlr->v4) { calc_edge_stress_add(accumoffs, vlr->v3, vlr->v4); calc_edge_stress_add(accumoffs, vlr->v4, vlr->v1); calc_edge_stress_add(accumoffs, vlr->v2, vlr->v4); @@ -429,12 +432,12 @@ static void calc_edge_stress(Render *UNUSED(re), ObjectRen *obr, Mesh *me) } } - for(a=0; a<obr->totvert; a++) { + for (a=0; a<obr->totvert; a++) { VertRen *ver= RE_findOrAddVert(obr, a); - if(ver->orco) { + if (ver->orco) { /* find stress value */ acc= accumoffs + 2*ver->index; - if(acc[1]!=0.0f) + if (acc[1]!=0.0f) acc[0]/= acc[1]; stress= RE_vertren_get_stress(obr, ver, 1); *stress= *acc; @@ -458,25 +461,25 @@ static void calc_tangent_vector(ObjectRen *obr, VertexTangent **vtangents, MemAr float *uv1, *uv2, *uv3, *uv4; float uv[4][2]; - if(tface) { + if (tface) { uv1= tface->uv[0]; uv2= tface->uv[1]; uv3= tface->uv[2]; uv4= tface->uv[3]; } - else if(v1->orco) { + else if (v1->orco) { uv1= uv[0]; uv2= uv[1]; uv3= uv[2]; uv4= uv[3]; map_to_sphere( &uv[0][0], &uv[0][1],v1->orco[0], v1->orco[1], v1->orco[2]); map_to_sphere( &uv[1][0], &uv[1][1],v2->orco[0], v2->orco[1], v2->orco[2]); map_to_sphere( &uv[2][0], &uv[2][1],v3->orco[0], v3->orco[1], v3->orco[2]); - if(v4) + if (v4) map_to_sphere( &uv[3][0], &uv[3][1],v4->orco[0], v4->orco[1], v4->orco[2]); } else return; tangent_from_uv(uv1, uv2, uv3, v1->co, v2->co, v3->co, vlr->n, tang); - if(do_tangent) { + if (do_tangent) { tav= RE_vertren_get_tangent(obr, v1, 1); add_v3_v3(tav, tang); tav= RE_vertren_get_tangent(obr, v2, 1); @@ -485,16 +488,16 @@ static void calc_tangent_vector(ObjectRen *obr, VertexTangent **vtangents, MemAr add_v3_v3(tav, tang); } - if(do_nmap_tangent) { + if (do_nmap_tangent) { sum_or_add_vertex_tangent(arena, &vtangents[v1->index], tang, uv1); sum_or_add_vertex_tangent(arena, &vtangents[v2->index], tang, uv2); sum_or_add_vertex_tangent(arena, &vtangents[v3->index], tang, uv3); } - if(v4) { + if (v4) { tangent_from_uv(uv1, uv3, uv4, v1->co, v3->co, v4->co, vlr->n, tang); - if(do_tangent) { + if (do_tangent) { tav= RE_vertren_get_tangent(obr, v1, 1); add_v3_v3(tav, tang); tav= RE_vertren_get_tangent(obr, v3, 1); @@ -503,7 +506,7 @@ static void calc_tangent_vector(ObjectRen *obr, VertexTangent **vtangents, MemAr add_v3_v3(tav, tang); } - if(do_nmap_tangent) { + if (do_nmap_tangent) { sum_or_add_vertex_tangent(arena, &vtangents[v1->index], tang, uv1); sum_or_add_vertex_tangent(arena, &vtangents[v3->index], tang, uv3); sum_or_add_vertex_tangent(arena, &vtangents[v4->index], tang, uv4); @@ -556,11 +559,11 @@ static void GetTextureCoordinate(const SMikkTSpaceContext * pContext, float fUV[ MTFace *tface= RE_vlakren_get_tface(pMesh->obr, vlr, pMesh->obr->actmtface, NULL, 0); const float *coord; - if(tface != NULL) { + if (tface != NULL) { coord= tface->uv[vert_index]; fUV[0]= coord[0]; fUV[1]= coord[1]; } - else if((coord= (&vlr->v1)[vert_index]->orco)) { + else if ((coord= (&vlr->v1)[vert_index]->orco)) { map_to_sphere(&fUV[0], &fUV[1], coord[0], coord[1], coord[2]); } else { /* else we get un-initialized value, 0.0 ok default? */ @@ -582,7 +585,7 @@ static void SetTSpace(const SMikkTSpaceContext * pContext, const float fvTangent SRenderMeshToTangent * pMesh = (SRenderMeshToTangent *) pContext->m_pUserData; VlakRen *vlr= RE_findOrAddVlak(pMesh->obr, face_num); float * ftang= RE_vlakren_get_nmap_tangent(pMesh->obr, vlr, 1); - if(ftang!=NULL) { + if (ftang!=NULL) { copy_v3_v3(&ftang[iVert*4+0], fvTangent); ftang[iVert*4+3]=fSign; } @@ -594,7 +597,7 @@ static void calc_vertexnormals(Render *UNUSED(re), ObjectRen *obr, int do_tangen VertexTangent **vtangents= NULL; int a; - if(do_nmap_tangent) { + if (do_nmap_tangent) { arena= BLI_memarena_new(BLI_MEMARENA_STD_BUFSIZE, "nmap tangent arena"); BLI_memarena_use_calloc(arena); @@ -602,23 +605,23 @@ static void calc_vertexnormals(Render *UNUSED(re), ObjectRen *obr, int do_tangen } /* clear all vertex normals */ - for(a=0; a<obr->totvert; a++) { + for (a=0; a<obr->totvert; a++) { VertRen *ver= RE_findOrAddVert(obr, a); ver->n[0]=ver->n[1]=ver->n[2]= 0.0f; } /* calculate cos of angles and point-masses, use as weight factor to * add face normal to vertex */ - for(a=0; a<obr->totvlak; a++) { + for (a=0; a<obr->totvlak; a++) { VlakRen *vlr= RE_findOrAddVlak(obr, a); - if(vlr->flag & ME_SMOOTH) { + if (vlr->flag & ME_SMOOTH) { float *n4= (vlr->v4)? vlr->v4->n: NULL; float *c4= (vlr->v4)? vlr->v4->co: NULL; accumulate_vertex_normals(vlr->v1->n, vlr->v2->n, vlr->v3->n, n4, vlr->n, vlr->v1->co, vlr->v2->co, vlr->v3->co, c4); } - if(do_nmap_tangent || do_tangent) { + if (do_nmap_tangent || do_tangent) { /* tangents still need to be calculated for flat faces too */ /* weighting removed, they are not vertexnormals */ calc_tangent_vector(obr, vtangents, arena, vlr, do_nmap_tangent, do_tangent); @@ -626,21 +629,21 @@ static void calc_vertexnormals(Render *UNUSED(re), ObjectRen *obr, int do_tangen } /* do solid faces */ - for(a=0; a<obr->totvlak; a++) { + for (a=0; a<obr->totvlak; a++) { VlakRen *vlr= RE_findOrAddVlak(obr, a); - if((vlr->flag & ME_SMOOTH)==0) { - if(is_zero_v3(vlr->v1->n)) copy_v3_v3(vlr->v1->n, vlr->n); - if(is_zero_v3(vlr->v2->n)) copy_v3_v3(vlr->v2->n, vlr->n); - if(is_zero_v3(vlr->v3->n)) copy_v3_v3(vlr->v3->n, vlr->n); - if(vlr->v4 && is_zero_v3(vlr->v4->n)) copy_v3_v3(vlr->v4->n, vlr->n); + if ((vlr->flag & ME_SMOOTH)==0) { + if (is_zero_v3(vlr->v1->n)) copy_v3_v3(vlr->v1->n, vlr->n); + if (is_zero_v3(vlr->v2->n)) copy_v3_v3(vlr->v2->n, vlr->n); + if (is_zero_v3(vlr->v3->n)) copy_v3_v3(vlr->v3->n, vlr->n); + if (vlr->v4 && is_zero_v3(vlr->v4->n)) copy_v3_v3(vlr->v4->n, vlr->n); } - if(do_nmap_tangent) { + if (do_nmap_tangent) { VertRen *v1=vlr->v1, *v2=vlr->v2, *v3=vlr->v3, *v4=vlr->v4; MTFace *tface= RE_vlakren_get_tface(obr, vlr, obr->actmtface, NULL, 0); - if(tface) { + if (tface) { int k=0; float *vtang, *ftang= RE_vlakren_get_nmap_tangent(obr, vlr, 1); @@ -653,12 +656,12 @@ static void calc_vertexnormals(Render *UNUSED(re), ObjectRen *obr, int do_tangen vtang= find_vertex_tangent(vtangents[v3->index], tface->uv[2]); copy_v3_v3(ftang+8, vtang); normalize_v3(ftang+8); - if(v4) { + if (v4) { vtang= find_vertex_tangent(vtangents[v4->index], tface->uv[3]); copy_v3_v3(ftang+12, vtang); normalize_v3(ftang+12); } - for(k=0; k<4; k++) ftang[4*k+3]=1; + for (k=0; k<4; k++) ftang[4*k+3]=1; } } } @@ -667,7 +670,7 @@ static void calc_vertexnormals(Render *UNUSED(re), ObjectRen *obr, int do_tangen for (a=0; a<obr->totvert; a++) { VertRen *ver= RE_findOrAddVert(obr, a); normalize_v3(ver->n); - if(do_tangent) { + if (do_tangent) { float *tav= RE_vertren_get_tangent(obr, ver, 0); if (tav) { /* orthonorm. */ @@ -702,9 +705,9 @@ static void calc_vertexnormals(Render *UNUSED(re), ObjectRen *obr, int do_tangen genTangSpaceDefault(&sContext); } - if(arena) + if (arena) BLI_memarena_free(arena); - if(vtangents) + if (vtangents) MEM_freeN(vtangents); } @@ -728,16 +731,16 @@ static void as_addvert(ASvert *asv, VertRen *v1, VlakRen *vlr) ASface *asf; int a; - if(v1 == NULL) return; + if (v1 == NULL) return; - if(asv->faces.first==NULL) { + if (asv->faces.first==NULL) { asf= MEM_callocN(sizeof(ASface), "asface"); BLI_addtail(&asv->faces, asf); } asf= asv->faces.last; - for(a=0; a<4; a++) { - if(asf->vlr[a]==NULL) { + for (a=0; a<4; a++) { + if (asf->vlr[a]==NULL) { asf->vlr[a]= vlr; asv->totface++; break; @@ -745,7 +748,7 @@ static void as_addvert(ASvert *asv, VertRen *v1, VlakRen *vlr) } /* new face struct */ - if(a==4) { + if (a==4) { asf= MEM_callocN(sizeof(ASface), "asface"); BLI_addtail(&asv->faces, asf); asf->vlr[0]= vlr; @@ -760,14 +763,14 @@ static int as_testvertex(VlakRen *vlr, VertRen *UNUSED(ver), ASvert *asv, float float inp; int a; - if(vlr==0) return 0; + if (vlr==0) return 0; asf= asv->faces.first; while(asf) { - for(a=0; a<4; a++) { - if(asf->vlr[a] && asf->vlr[a]!=vlr) { + for (a=0; a<4; a++) { + if (asf->vlr[a] && asf->vlr[a]!=vlr) { inp = fabsf(dot_v3v3(vlr->n, asf->vlr[a]->n)); - if(inp < thresh) return 1; + if (inp < thresh) return 1; } } asf= asf->next; @@ -785,12 +788,12 @@ static VertRen *as_findvertex(VlakRen *vlr, VertRen *UNUSED(ver), ASvert *asv, f asf= asv->faces.first; while(asf) { - for(a=0; a<4; a++) { - if(asf->vlr[a] && asf->vlr[a]!=vlr) { + for (a=0; a<4; a++) { + if (asf->vlr[a] && asf->vlr[a]!=vlr) { /* this face already made a copy for this vertex! */ - if(asf->nver[a]) { + if (asf->nver[a]) { inp = fabsf(dot_v3v3(vlr->n, asf->vlr[a]->n)); - if(inp >= thresh) { + if (inp >= thresh) { return asf->nver[a]; } } @@ -813,7 +816,7 @@ static void autosmooth(Render *UNUSED(re), ObjectRen *obr, float mat[][4], int d float thresh; int a, b, totvert; - if(obr->totvert==0) return; + if (obr->totvert==0) return; asverts= MEM_callocN(sizeof(ASvert)*obr->totvert, "all smooth verts"); thresh= cosf(DEG2RADF((0.5f + (float)degr))); @@ -822,43 +825,43 @@ static void autosmooth(Render *UNUSED(re), ObjectRen *obr, float mat[][4], int d /* step one: construct listbase of all vertices and pointers to faces */ - for(a=0; a<obr->totvlak; a++) { + for (a=0; a<obr->totvlak; a++) { vlr= RE_findOrAddVlak(obr, a); /* skip wire faces */ - if(vlr->v2 != vlr->v3) { + if (vlr->v2 != vlr->v3) { as_addvert(asverts+vlr->v1->index, vlr->v1, vlr); as_addvert(asverts+vlr->v2->index, vlr->v2, vlr); as_addvert(asverts+vlr->v3->index, vlr->v3, vlr); - if(vlr->v4) + if (vlr->v4) as_addvert(asverts+vlr->v4->index, vlr->v4, vlr); } } totvert= obr->totvert; /* we now test all vertices, when faces have a normal too much different: they get a new vertex */ - for(a=0, asv=asverts; a<totvert; a++, asv++) { - if(asv && asv->totface>1) { + for (a=0, asv=asverts; a<totvert; a++, asv++) { + if (asv && asv->totface>1) { ver= RE_findOrAddVert(obr, a); asf= asv->faces.first; while(asf) { - for(b=0; b<4; b++) { + for (b=0; b<4; b++) { /* is there a reason to make a new vertex? */ vlr= asf->vlr[b]; - if( as_testvertex(vlr, ver, asv, thresh) ) { + if ( as_testvertex(vlr, ver, asv, thresh) ) { /* already made a new vertex within threshold? */ v1= as_findvertex(vlr, ver, asv, thresh); - if(v1==NULL) { + if (v1==NULL) { /* make a new vertex */ v1= RE_vertren_copy(obr, ver); } asf->nver[b]= v1; - if(vlr->v1==ver) vlr->v1= v1; - if(vlr->v2==ver) vlr->v2= v1; - if(vlr->v3==ver) vlr->v3= v1; - if(vlr->v4==ver) vlr->v4= v1; + if (vlr->v1==ver) vlr->v1= v1; + if (vlr->v2==ver) vlr->v2= v1; + if (vlr->v3==ver) vlr->v3= v1; + if (vlr->v4==ver) vlr->v4= v1; } } asf= asf->next; @@ -867,22 +870,22 @@ static void autosmooth(Render *UNUSED(re), ObjectRen *obr, float mat[][4], int d } /* free */ - for(a=0; a<totvert; a++) { + for (a=0; a<totvert; a++) { BLI_freelistN(&asverts[a].faces); } MEM_freeN(asverts); /* rotate vertices and calculate normal of faces */ - for(a=0; a<obr->totvert; a++) { + for (a=0; a<obr->totvert; a++) { ver= RE_findOrAddVert(obr, a); mul_m4_v3(mat, ver->co); } - for(a=0; a<obr->totvlak; a++) { + for (a=0; a<obr->totvlak; a++) { vlr= RE_findOrAddVlak(obr, a); /* skip wire faces */ - if(vlr->v2 != vlr->v3) { - if(vlr->v4) + if (vlr->v2 != vlr->v3) { + if (vlr->v4) normal_quad_v3( vlr->n,vlr->v4->co, vlr->v3->co, vlr->v2->co, vlr->v1->co); else normal_tri_v3( vlr->n,vlr->v3->co, vlr->v2->co, vlr->v1->co); @@ -906,7 +909,8 @@ static float *get_object_orco(Render *re, Object *ob) if (!orco) { if (ELEM(ob->type, OB_CURVE, OB_FONT)) { orco = make_orco_curve(re->scene, ob); - } else if (ob->type==OB_SURF) { + } + else if (ob->type==OB_SURF) { orco = make_orco_surf(ob); } @@ -942,16 +946,16 @@ static void check_material_mapto(Material *ma) * this can avoid a bit of time spent iterating through all the texture slots, map inputs and map tos * every time a property which may or may not be textured is accessed */ - for(a=0; a<MAX_MTEX; a++) { - if(ma->mtex[a] && ma->mtex[a]->tex) { + for (a=0; a<MAX_MTEX; a++) { + if (ma->mtex[a] && ma->mtex[a]->tex) { /* currently used only in volume render, so we'll check for those flags */ - if(ma->mtex[a]->mapto & MAP_DENSITY) ma->mapto_textured |= MAP_DENSITY; - if(ma->mtex[a]->mapto & MAP_EMISSION) ma->mapto_textured |= MAP_EMISSION; - if(ma->mtex[a]->mapto & MAP_EMISSION_COL) ma->mapto_textured |= MAP_EMISSION_COL; - if(ma->mtex[a]->mapto & MAP_SCATTERING) ma->mapto_textured |= MAP_SCATTERING; - if(ma->mtex[a]->mapto & MAP_TRANSMISSION_COL) ma->mapto_textured |= MAP_TRANSMISSION_COL; - if(ma->mtex[a]->mapto & MAP_REFLECTION) ma->mapto_textured |= MAP_REFLECTION; - if(ma->mtex[a]->mapto & MAP_REFLECTION_COL) ma->mapto_textured |= MAP_REFLECTION_COL; + if (ma->mtex[a]->mapto & MAP_DENSITY) ma->mapto_textured |= MAP_DENSITY; + if (ma->mtex[a]->mapto & MAP_EMISSION) ma->mapto_textured |= MAP_EMISSION; + if (ma->mtex[a]->mapto & MAP_EMISSION_COL) ma->mapto_textured |= MAP_EMISSION_COL; + if (ma->mtex[a]->mapto & MAP_SCATTERING) ma->mapto_textured |= MAP_SCATTERING; + if (ma->mtex[a]->mapto & MAP_TRANSMISSION_COL) ma->mapto_textured |= MAP_TRANSMISSION_COL; + if (ma->mtex[a]->mapto & MAP_REFLECTION) ma->mapto_textured |= MAP_REFLECTION; + if (ma->mtex[a]->mapto & MAP_REFLECTION_COL) ma->mapto_textured |= MAP_REFLECTION_COL; } } } @@ -959,17 +963,17 @@ static void flag_render_node_material(Render *re, bNodeTree *ntree) { bNode *node; - for(node=ntree->nodes.first; node; node= node->next) { - if(node->id) { - if(GS(node->id->name)==ID_MA) { + for (node=ntree->nodes.first; node; node= node->next) { + if (node->id) { + if (GS(node->id->name)==ID_MA) { Material *ma= (Material *)node->id; - if((ma->mode & MA_TRANSP) && (ma->mode & MA_ZTRANSP)) + if ((ma->mode & MA_TRANSP) && (ma->mode & MA_ZTRANSP)) re->flag |= R_ZTRA; ma->flag |= MA_IS_USED; } - else if(node->type==NODE_GROUP) + else if (node->type==NODE_GROUP) flag_render_node_material(re, (bNodeTree *)node->id); } } @@ -981,22 +985,22 @@ static Material *give_render_material(Render *re, Object *ob, short nr) Material *ma; ma= give_current_material(ob, nr); - if(ma==NULL) + if (ma==NULL) ma= &defmaterial; - if(re->r.mode & R_SPEED) ma->texco |= NEED_UV; + if (re->r.mode & R_SPEED) ma->texco |= NEED_UV; - if(ma->material_type == MA_TYPE_VOLUME) { + if (ma->material_type == MA_TYPE_VOLUME) { ma->mode |= MA_TRANSP; ma->mode &= ~MA_SHADBUF; } - if((ma->mode & MA_TRANSP) && (ma->mode & MA_ZTRANSP)) + if ((ma->mode & MA_TRANSP) && (ma->mode & MA_ZTRANSP)) re->flag |= R_ZTRA; /* for light groups and SSS */ ma->flag |= MA_IS_USED; - if(ma->nodetree && ma->use_nodes) + if (ma->nodetree && ma->use_nodes) flag_render_node_material(re, ma->nodetree); check_material_mapto(ma); @@ -1036,10 +1040,10 @@ static void static_particle_strand(Render *re, ObjectRen *obr, Material *ma, Par dy= re->winy*cross[1]*re->winmat[1][1]; w= sqrt(dx*dx + dy*dy)/w; - if(w!=0.0f) { + if (w!=0.0f) { float fac; - if(ma->strand_ease!=0.0f) { - if(ma->strand_ease<0.0f) + if (ma->strand_ease!=0.0f) { + if (ma->strand_ease<0.0f) fac= pow(sd->time, 1.0f+ma->strand_ease); else fac= pow(sd->time, 1.0f/(1.0f-ma->strand_ease)); @@ -1049,11 +1053,11 @@ static void static_particle_strand(Render *re, ObjectRen *obr, Material *ma, Par width= ((1.0f-fac)*ma->strand_sta + (fac)*ma->strand_end); /* use actual Blender units for strand width and fall back to minimum width */ - if(ma->mode & MA_STR_B_UNITS){ + if (ma->mode & MA_STR_B_UNITS) { crosslen= len_v3(cross); w= 2.0f*crosslen*ma->strand_min/w; - if(width < w) + if (width < w) width= w; /*cross is the radius of the strand so we want it to be half of full width */ @@ -1065,17 +1069,17 @@ static void static_particle_strand(Render *re, ObjectRen *obr, Material *ma, Par mul_v3_fl(cross, width); } - if(ma->mode & MA_TANGENT_STR) + if (ma->mode & MA_TANGENT_STR) flag= R_SMOOTH|R_TANGENT; else flag= R_SMOOTH; /* only 1 pixel wide strands filled in as quads now, otherwise zbuf errors */ - if(ma->strand_sta==1.0f) + if (ma->strand_sta==1.0f) flag |= R_STRAND; /* single face line */ - if(sd->line) { + if (sd->line) { vlr= RE_findOrAddVlak(obr, obr->totvlak++); vlr->flag= flag; vlr->v1= RE_findOrAddVert(obr, obr->totvert++); @@ -1112,13 +1116,13 @@ static void static_particle_strand(Render *re, ObjectRen *obr, Material *ma, Par vlr->mat= ma; vlr->ec= ME_V2V3; - if(sd->surfnor) { + if (sd->surfnor) { float *snor= RE_vlakren_get_surfnor(obr, vlr, 1); copy_v3_v3(snor, sd->surfnor); } - if(sd->uvco){ - for(i=0; i<sd->totuv; i++){ + if (sd->uvco) { + for (i=0; i<sd->totuv; i++) { MTFace *mtf; mtf=RE_vlakren_get_tface(obr,vlr,i,NULL,1); mtf->uv[0][0]=mtf->uv[1][0]= @@ -1126,7 +1130,7 @@ static void static_particle_strand(Render *re, ObjectRen *obr, Material *ma, Par mtf->uv[0][1]=mtf->uv[1][1]= mtf->uv[2][1]=mtf->uv[3][1]=(sd->uvco+2*i)[1]; } - if(sd->override_uv>=0){ + if (sd->override_uv>=0) { MTFace *mtf; mtf=RE_vlakren_get_tface(obr,vlr,sd->override_uv,NULL,0); @@ -1137,8 +1141,8 @@ static void static_particle_strand(Render *re, ObjectRen *obr, Material *ma, Par mtf->uv[2][1]=mtf->uv[3][1]=1.0f; } } - if(sd->mcol){ - for(i=0; i<sd->totcol; i++){ + if (sd->mcol) { + for (i=0; i<sd->totcol; i++) { MCol *mc; mc=RE_vlakren_get_mcol(obr,vlr,i,NULL,1); mc[0]=mc[1]=mc[2]=mc[3]=sd->mcol[i]; @@ -1147,8 +1151,8 @@ static void static_particle_strand(Render *re, ObjectRen *obr, Material *ma, Par } } /* first two vertices of a strand */ - else if(sd->first) { - if(sd->adapt){ + else if (sd->first) { + if (sd->adapt) { copy_v3_v3(anor, nor); copy_v3_v3(avec, vec); second=1; @@ -1171,7 +1175,7 @@ static void static_particle_strand(Render *re, ObjectRen *obr, Material *ma, Par } /* more vertices & faces to strand */ else { - if(sd->adapt==0 || second){ + if (sd->adapt==0 || second) { vlr= RE_findOrAddVlak(obr, obr->totvlak++); vlr->flag= flag; vlr->v1= v1; @@ -1183,14 +1187,14 @@ static void static_particle_strand(Render *re, ObjectRen *obr, Material *ma, Par v2= vlr->v3; // cycle - if(sd->adapt){ + if (sd->adapt) { second=0; copy_v3_v3(anor,nor); copy_v3_v3(avec,vec); } } - else if(sd->adapt){ + else if (sd->adapt) { float dvec[3],pvec[3]; sub_v3_v3v3(dvec,avec,vec); project_v3_v3v3(pvec,dvec,vec); @@ -1200,7 +1204,7 @@ static void static_particle_strand(Render *re, ObjectRen *obr, Material *ma, Par dx= re->winx*dvec[0]*re->winmat[0][0]/w; dy= re->winy*dvec[1]*re->winmat[1][1]/w; w= sqrt(dx*dx + dy*dy); - if(dot_v3v3(anor,nor)<sd->adapt_angle && w>sd->adapt_pix){ + if (dot_v3v3(anor,nor)<sd->adapt_angle && w>sd->adapt_pix) { vlr= RE_findOrAddVlak(obr, obr->totvlak++); vlr->flag= flag; vlr->v1= v1; @@ -1214,7 +1218,7 @@ static void static_particle_strand(Render *re, ObjectRen *obr, Material *ma, Par copy_v3_v3(anor,nor); copy_v3_v3(avec,vec); } - else{ + else { vlr= RE_findOrAddVlak(obr, obr->totvlak-1); } } @@ -1236,13 +1240,13 @@ static void static_particle_strand(Render *re, ObjectRen *obr, Material *ma, Par vlr->mat= ma; vlr->ec= ME_V2V3; - if(sd->surfnor) { + if (sd->surfnor) { float *snor= RE_vlakren_get_surfnor(obr, vlr, 1); copy_v3_v3(snor, sd->surfnor); } - if(sd->uvco){ - for(i=0; i<sd->totuv; i++){ + if (sd->uvco) { + for (i=0; i<sd->totuv; i++) { MTFace *mtf; mtf=RE_vlakren_get_tface(obr,vlr,i,NULL,1); mtf->uv[0][0]=mtf->uv[1][0]= @@ -1250,7 +1254,7 @@ static void static_particle_strand(Render *re, ObjectRen *obr, Material *ma, Par mtf->uv[0][1]=mtf->uv[1][1]= mtf->uv[2][1]=mtf->uv[3][1]=(sd->uvco+2*i)[1]; } - if(sd->override_uv>=0){ + if (sd->override_uv>=0) { MTFace *mtf; mtf=RE_vlakren_get_tface(obr,vlr,sd->override_uv,NULL,0); @@ -1261,8 +1265,8 @@ static void static_particle_strand(Render *re, ObjectRen *obr, Material *ma, Par mtf->uv[2][1]=mtf->uv[3][1]=(vlr->v3->accum+1.0f)/2.0f; } } - if(sd->mcol){ - for(i=0; i<sd->totcol; i++){ + if (sd->mcol) { + for (i=0; i<sd->totcol; i++) { MCol *mc; mc=RE_vlakren_get_mcol(obr,vlr,i,NULL,1); mc[0]=mc[1]=mc[2]=mc[3]=sd->mcol[i]; @@ -1277,7 +1281,7 @@ static void static_particle_wire(ObjectRen *obr, Material *ma, const float vec[3 VlakRen *vlr; static VertRen *v1; - if(line) { + if (line) { vlr= RE_findOrAddVlak(obr, obr->totvlak++); vlr->v1= RE_findOrAddVert(obr, obr->totvert++); vlr->v2= RE_findOrAddVert(obr, obr->totvert++); @@ -1296,7 +1300,7 @@ static void static_particle_wire(ObjectRen *obr, Material *ma, const float vec[3 vlr->ec= ME_V1V2; } - else if(first) { + else if (first) { v1= RE_findOrAddVert(obr, obr->totvert++); copy_v3_v3(v1->co, vec); } @@ -1324,11 +1328,11 @@ static void particle_curve(Render *re, ObjectRen *obr, DerivedMesh *dm, Material { HaloRen *har=0; - if(ma->material_type == MA_TYPE_WIRE) + if (ma->material_type == MA_TYPE_WIRE) static_particle_wire(obr, ma, loc, loc1, sd->first, sd->line); - else if(ma->material_type == MA_TYPE_HALO) { + else if (ma->material_type == MA_TYPE_HALO) { har= RE_inithalo_particle(re, obr, dm, ma, loc, loc1, sd->orco, sd->uvco, sd->size, 1.0, seed, pa_co); - if(har) har->lay= obr->ob->lay; + if (har) har->lay= obr->ob->lay; } else static_particle_strand(re, obr, ma, sd, loc, loc1); @@ -1377,17 +1381,17 @@ static void particle_billboard(Render *re, ObjectRen *obr, Material *ma, Particl vlr->mat= ma; vlr->ec= ME_V2V3; - if(bb->uv_split > 1){ + if (bb->uv_split > 1) { uvdx = uvdy = 1.0f / (float)bb->uv_split; - if(ELEM(bb->anim, PART_BB_ANIM_AGE, PART_BB_ANIM_FRAME)) { - if(bb->anim == PART_BB_ANIM_FRAME) + if (ELEM(bb->anim, PART_BB_ANIM_AGE, PART_BB_ANIM_FRAME)) { + if (bb->anim == PART_BB_ANIM_FRAME) time = ((int)(bb->time * bb->lifetime) % totsplit)/(float)totsplit; else time = bb->time; } - else if(bb->anim == PART_BB_ANIM_ANGLE) { - if(bb->align == PART_BB_VIEW) { + else if (bb->anim == PART_BB_ANIM_ANGLE) { + if (bb->align == PART_BB_VIEW) { time = (float)fmod((bb->tilt + 1.0f) / 2.0f, 1.0); } else { @@ -1397,23 +1401,23 @@ static void particle_billboard(Render *re, ObjectRen *obr, Material *ma, Particl axis1[(bb->align + 1) % 3] = 1.0f; axis2[(bb->align + 2) % 3] = 1.0f; - if(bb->lock == 0) { + if (bb->lock == 0) { zvec[bb->align] = 0.0f; normalize_v3(zvec); } time = saacos(dot_v3v3(zvec, axis1)) / (float)M_PI; - if(dot_v3v3(zvec, axis2) < 0.0f) + if (dot_v3v3(zvec, axis2) < 0.0f) time = 1.0f - time / 2.0f; else time /= 2.0f; } } - if(bb->split_offset == PART_BB_OFF_LINEAR) + if (bb->split_offset == PART_BB_OFF_LINEAR) time = (float)fmod(time + (float)bb->num / (float)totsplit, 1.0f); - else if(bb->split_offset==PART_BB_OFF_RANDOM) + else if (bb->split_offset==PART_BB_OFF_RANDOM) time = (float)fmod(time + bb->random, 1.0f); /* Find the coordinates in tile space (integer), then convert to UV @@ -1427,7 +1431,7 @@ static void particle_billboard(Render *re, ObjectRen *obr, Material *ma, Particl } /* normal UVs */ - if(bb->uv[0] >= 0){ + if (bb->uv[0] >= 0) { mtf = RE_vlakren_get_tface(obr, vlr, bb->uv[0], NULL, 1); mtf->uv[0][0] = 1.0f; mtf->uv[0][1] = 1.0f; @@ -1440,14 +1444,14 @@ static void particle_billboard(Render *re, ObjectRen *obr, Material *ma, Particl } /* time-index UVs */ - if(bb->uv[1] >= 0){ + if (bb->uv[1] >= 0) { mtf = RE_vlakren_get_tface(obr, vlr, bb->uv[1], NULL, 1); mtf->uv[0][0] = mtf->uv[1][0] = mtf->uv[2][0] = mtf->uv[3][0] = bb->time; mtf->uv[0][1] = mtf->uv[1][1] = mtf->uv[2][1] = mtf->uv[3][1] = (float)bb->num/(float)bb->totnum; } /* split UVs */ - if(bb->uv_split > 1 && bb->uv[2] >= 0){ + if (bb->uv_split > 1 && bb->uv[2] >= 0) { mtf = RE_vlakren_get_tface(obr, vlr, bb->uv[2], NULL, 1); mtf->uv[0][0] = uvx + uvdx; mtf->uv[0][1] = uvy + uvdy; @@ -1465,7 +1469,7 @@ static void particle_normal_ren(short ren_as, ParticleSettings *part, Render *re copy_v3_v3(loc, state->co); - if(ren_as != PART_DRAW_BB) + if (ren_as != PART_DRAW_BB) mul_m4_v3(re->viewmat, loc); switch(ren_as) { @@ -1478,7 +1482,7 @@ static void particle_normal_ren(short ren_as, ParticleSettings *part, Render *re mul_mat3_m4_v3(re->viewmat, vel); normalize_v3(vel); - if(part->draw & PART_DRAW_VEL_LENGTH) + if (part->draw & PART_DRAW_VEL_LENGTH) mul_v3_fl(vel, len_v3(state->vel)); madd_v3_v3v3fl(loc0, loc, vel, -part->draw_line[0]); @@ -1503,7 +1507,7 @@ static void particle_normal_ren(short ren_as, ParticleSettings *part, Render *re har = RE_inithalo_particle(re, obr, dm, ma, loc, NULL, sd->orco, sd->uvco, hasize, 0.0, seed, pa_co); - if(har) har->lay= obr->ob->lay; + if (har) har->lay= obr->ob->lay; break; } @@ -1514,9 +1518,9 @@ static void get_particle_uvco_mcol(short from, DerivedMesh *dm, float *fuv, int int i; /* get uvco */ - if(sd->uvco && ELEM(from,PART_FROM_FACE,PART_FROM_VOLUME)) { - for(i=0; i<sd->totuv; i++) { - if(num != DMCACHE_NOTFOUND) { + if (sd->uvco && ELEM(from,PART_FROM_FACE,PART_FROM_VOLUME)) { + for (i=0; i<sd->totuv; i++) { + if (num != DMCACHE_NOTFOUND) { MFace *mface = dm->getTessFaceData(dm, num, CD_MFACE); MTFace *mtface = (MTFace*)CustomData_get_layer_n(&dm->faceData, CD_MTFACE, i); mtface += num; @@ -1531,9 +1535,9 @@ static void get_particle_uvco_mcol(short from, DerivedMesh *dm, float *fuv, int } /* get mcol */ - if(sd->mcol && ELEM(from,PART_FROM_FACE,PART_FROM_VOLUME)) { - for(i=0; i<sd->totcol; i++) { - if(num != DMCACHE_NOTFOUND) { + if (sd->mcol && ELEM(from,PART_FROM_FACE,PART_FROM_VOLUME)) { + for (i=0; i<sd->totcol; i++) { + if (num != DMCACHE_NOTFOUND) { MFace *mface = dm->getTessFaceData(dm, num, CD_MFACE); MCol *mc = (MCol*)CustomData_get_layer_n(&dm->faceData, CD_MCOL, i); mc += num * 4; @@ -1578,23 +1582,23 @@ static int render_new_particle_system(Render *re, ObjectRen *obr, ParticleSystem char **uv_name=0; /* 1. check that everything is ok & updated */ - if(psys==NULL) + if (psys==NULL) return 0; part=psys->part; pars=psys->particles; - if(part==NULL || pars==NULL || !psys_check_enabled(ob, psys)) + if (part==NULL || pars==NULL || !psys_check_enabled(ob, psys)) return 0; - if(part->ren_as==PART_DRAW_OB || part->ren_as==PART_DRAW_GR || part->ren_as==PART_DRAW_NOT) + if (part->ren_as==PART_DRAW_OB || part->ren_as==PART_DRAW_GR || part->ren_as==PART_DRAW_NOT) return 1; /* 2. start initializing things */ /* last possibility to bail out! */ psmd = psys_get_modifier(ob,psys); - if(!(psmd->modifier.mode & eModifierMode_Render)) + if (!(psmd->modifier.mode & eModifierMode_Render)) return 0; sim.scene= re->scene; @@ -1602,16 +1606,16 @@ static int render_new_particle_system(Render *re, ObjectRen *obr, ParticleSystem sim.psys= psys; sim.psmd= psmd; - if(part->phystype==PART_PHYS_KEYED) + if (part->phystype==PART_PHYS_KEYED) psys_count_keyed_targets(&sim); totchild=psys->totchild; /* can happen for disconnected/global hair */ - if(part->type==PART_HAIR && !psys->childcache) + if (part->type==PART_HAIR && !psys->childcache) totchild= 0; - if(G.rendering == 0) { /* preview render */ + if (G.rendering == 0) { /* preview render */ totchild = (int)((float)totchild * (float)part->disp / 100.0f); } @@ -1628,7 +1632,7 @@ static int render_new_particle_system(Render *re, ObjectRen *obr, ParticleSystem ma= give_render_material(re, ob, part->omat); #if 0 // XXX old animation system - if(ma->ipo){ + if (ma->ipo) { calc_ipo(ma->ipo, cfra); execute_ipo((ID *)ma, ma->ipo); } @@ -1643,10 +1647,10 @@ static int render_new_particle_system(Render *re, ObjectRen *obr, ParticleSystem sd.totuv = CustomData_number_of_layers(&psmd->dm->faceData, CD_MTFACE); sd.totcol = CustomData_number_of_layers(&psmd->dm->faceData, CD_MCOL); - if(ma->texco & TEXCO_UV && sd.totuv) { + if (ma->texco & TEXCO_UV && sd.totuv) { sd.uvco = MEM_callocN(sd.totuv * 2 * sizeof(float), "particle_uvs"); - if(ma->strand_uvname[0]) { + if (ma->strand_uvname[0]) { sd.override_uv = CustomData_get_named_layer_index(&psmd->dm->faceData, CD_MTFACE, ma->strand_uvname); sd.override_uv -= CustomData_get_layer_index(&psmd->dm->faceData, CD_MTFACE); } @@ -1654,22 +1658,22 @@ static int render_new_particle_system(Render *re, ObjectRen *obr, ParticleSystem else sd.uvco = NULL; - if(sd.totcol) + if (sd.totcol) sd.mcol = MEM_callocN(sd.totcol * sizeof(MCol), "particle_mcols"); /* 2.2 setup billboards */ - if(part->ren_as == PART_DRAW_BB) { + if (part->ren_as == PART_DRAW_BB) { int first_uv = CustomData_get_layer_index(&psmd->dm->faceData, CD_MTFACE); bb.uv[0] = CustomData_get_named_layer_index(&psmd->dm->faceData, CD_MTFACE, psys->bb_uvname[0]); - if(bb.uv[0] < 0) + if (bb.uv[0] < 0) bb.uv[0] = CustomData_get_active_layer_index(&psmd->dm->faceData, CD_MTFACE); bb.uv[1] = CustomData_get_named_layer_index(&psmd->dm->faceData, CD_MTFACE, psys->bb_uvname[1]); bb.uv[2] = CustomData_get_named_layer_index(&psmd->dm->faceData, CD_MTFACE, psys->bb_uvname[2]); - if(first_uv >= 0) { + if (first_uv >= 0) { bb.uv[0] -= first_uv; bb.uv[1] -= first_uv; bb.uv[2] -= first_uv; @@ -1690,24 +1694,24 @@ static int render_new_particle_system(Render *re, ObjectRen *obr, ParticleSystem copy_m3_m4(nmat, ob->imat); transpose_m3(nmat); - if(psys->flag & PSYS_USE_IMAT) { + if (psys->flag & PSYS_USE_IMAT) { /* psys->imat is the original emitter's inverse matrix, ob->obmat is the duplicated object's matrix */ mult_m4_m4m4(duplimat, ob->obmat, psys->imat); use_duplimat = 1; } /* 2.6 setup strand rendering */ - if(part->ren_as == PART_DRAW_PATH && psys->pathcache){ + if (part->ren_as == PART_DRAW_PATH && psys->pathcache) { path_nbr=(int)pow(2.0,(double) part->ren_step); - if(path_nbr) { - if(!ELEM(ma->material_type, MA_TYPE_HALO, MA_TYPE_WIRE)) { + if (path_nbr) { + if (!ELEM(ma->material_type, MA_TYPE_HALO, MA_TYPE_WIRE)) { sd.orco = MEM_mallocN(3*sizeof(float)*(totpart+totchild), "particle orcos"); set_object_orco(re, psys, sd.orco); } } - if(part->draw & PART_DRAW_REN_ADAPT) { + if (part->draw & PART_DRAW_REN_ADAPT) { sd.adapt = 1; sd.adapt_pix = (float)part->adapt_pix; sd.adapt_angle = cosf(DEG2RADF((float)part->adapt_angle)); @@ -1725,29 +1729,29 @@ static int render_new_particle_system(Render *re, ObjectRen *obr, ParticleSystem strandbuf->overrideuv= sd.override_uv; strandbuf->minwidth= ma->strand_min; - if(ma->strand_widthfade == 0.0f) + if (ma->strand_widthfade == 0.0f) strandbuf->widthfade= 0.0f; - else if(ma->strand_widthfade >= 1.0f) + else if (ma->strand_widthfade >= 1.0f) strandbuf->widthfade= 2.0f - ma->strand_widthfade; else strandbuf->widthfade= 1.0f/MAX2(ma->strand_widthfade, 1e-5f); - if(part->flag & PART_HAIR_BSPLINE) + if (part->flag & PART_HAIR_BSPLINE) strandbuf->flag |= R_STRAND_BSPLINE; - if(ma->mode & MA_STR_B_UNITS) + if (ma->mode & MA_STR_B_UNITS) strandbuf->flag |= R_STRAND_B_UNITS; svert= strandbuf->vert; - if(re->r.mode & R_SPEED) + if (re->r.mode & R_SPEED) dosurfacecache= 1; - else if((re->wrld.mode & (WO_AMB_OCC|WO_ENV_LIGHT|WO_INDIRECT_LIGHT)) && (re->wrld.ao_gather_method == WO_AOGATHER_APPROX)) - if(ma->amb != 0.0f) + else if ((re->wrld.mode & (WO_AMB_OCC|WO_ENV_LIGHT|WO_INDIRECT_LIGHT)) && (re->wrld.ao_gather_method == WO_AOGATHER_APPROX)) + if (ma->amb != 0.0f) dosurfacecache= 1; totface= psmd->dm->getNumTessFaces(psmd->dm); origindex= psmd->dm->getTessFaceDataArray(psmd->dm, CD_ORIGINDEX); - for(a=0; a<totface; a++) + for (a=0; a<totface; a++) strandbuf->totbound= MAX2(strandbuf->totbound, (origindex)? origindex[a]: a); strandbuf->totbound++; @@ -1757,20 +1761,20 @@ static int render_new_particle_system(Render *re, ObjectRen *obr, ParticleSystem } } - if(sd.orco == 0) { + if (sd.orco == 0) { sd.orco = MEM_mallocN(3 * sizeof(float), "particle orco"); orco1 = 1; } - if(path_nbr == 0) + if (path_nbr == 0) psys->lattice = psys_get_lattice(&sim); /* 3. start creating renderable things */ - for(a=0,pa=pars; a<totpart+totchild; a++, pa++, seed++) { + for (a=0,pa=pars; a<totpart+totchild; a++, pa++, seed++) { random = rng_getFloat(rng); /* setup per particle individual stuff */ - if(a<totpart){ - if(pa->flag & PARS_UNEXIST) continue; + if (a<totpart) { + if (pa->flag & PARS_UNEXIST) continue; pa_time=(cfra-pa->time)/pa->lifetime; pa_birthtime = pa->time; @@ -1779,7 +1783,7 @@ static int render_new_particle_system(Render *re, ObjectRen *obr, ParticleSystem hasize = ma->hasize; /* get orco */ - if(tpsys && part->phystype==PART_PHYS_NO){ + if (tpsys && part->phystype==PART_PHYS_NO) { tpa=tpsys->particles+pa->num; psys_particle_on_emitter(psmd,tpart->from,tpa->num,pa->num_dmcache,tpa->fuv,tpa->foffset,co,nor,0,0,sd.orco,0); } @@ -1789,8 +1793,8 @@ static int render_new_particle_system(Render *re, ObjectRen *obr, ParticleSystem /* get uvco & mcol */ num= pa->num_dmcache; - if(num == DMCACHE_NOTFOUND) - if(pa->num < psmd->dm->getNumTessFaces(psmd->dm)) + if (num == DMCACHE_NOTFOUND) + if (pa->num < psmd->dm->getNumTessFaces(psmd->dm)) num= pa->num; get_particle_uvco_mcol(part->from, psmd->dm, pa->fuv, num, &sd); @@ -1800,20 +1804,20 @@ static int render_new_particle_system(Render *re, ObjectRen *obr, ParticleSystem r_tilt = 2.0f*(PSYS_FRAND(a) - 0.5f); r_length = PSYS_FRAND(a+1); - if(path_nbr) { + if (path_nbr) { cache = psys->pathcache[a]; max_k = (int)cache->steps; } - if(totchild && (part->draw&PART_DRAW_PARENT)==0) continue; + if (totchild && (part->draw&PART_DRAW_PARENT)==0) continue; } else { ChildParticle *cpa= psys->child+a-totpart; - if(path_nbr) { + if (path_nbr) { cache = psys->childcache[a-totpart]; - if(cache->steps < 0) + if (cache->steps < 0) continue; max_k = (int)cache->steps; @@ -1828,7 +1832,7 @@ static int render_new_particle_system(Render *re, ObjectRen *obr, ParticleSystem num = cpa->num; /* get orco */ - if(part->childtype == PART_CHILD_FACES) { + if (part->childtype == PART_CHILD_FACES) { psys_particle_on_emitter(psmd, PART_FROM_FACE, cpa->num,DMCACHE_ISCHILD, cpa->fuv,cpa->foffset,co,nor,0,0,sd.orco,0); @@ -1841,15 +1845,15 @@ static int render_new_particle_system(Render *re, ObjectRen *obr, ParticleSystem } /* get uvco & mcol */ - if(part->childtype==PART_CHILD_FACES) { + if (part->childtype==PART_CHILD_FACES) { get_particle_uvco_mcol(PART_FROM_FACE, psmd->dm, cpa->fuv, cpa->num, &sd); } else { ParticleData *parent = psys->particles + cpa->parent; num = parent->num_dmcache; - if(num == DMCACHE_NOTFOUND) - if(parent->num < psmd->dm->getNumTessFaces(psmd->dm)) + if (num == DMCACHE_NOTFOUND) + if (parent->num < psmd->dm->getNumTessFaces(psmd->dm)) num = parent->num; get_particle_uvco_mcol(part->from, psmd->dm, parent->fuv, num, &sd); @@ -1857,10 +1861,10 @@ static int render_new_particle_system(Render *re, ObjectRen *obr, ParticleSystem dosimplify = psys_render_simplify_params(psys, cpa, simplify); - if(strandbuf) { + if (strandbuf) { int orignum= (origindex)? origindex[cpa->num]: cpa->num; - if(orignum > sbound - strandbuf->bound) { + if (orignum > sbound - strandbuf->bound) { sbound= strandbuf->bound + orignum; sbound->start= sbound->end= obr->totstrand; } @@ -1873,7 +1877,7 @@ static int render_new_particle_system(Render *re, ObjectRen *obr, ParticleSystem pa_co[2] = 0.f; /* surface normal shading setup */ - if(ma->mode_l & MA_STR_SURFDIFF) { + if (ma->mode_l & MA_STR_SURFDIFF) { mul_m3_v3(nmat, nor); sd.surfnor= nor; } @@ -1881,31 +1885,31 @@ static int render_new_particle_system(Render *re, ObjectRen *obr, ParticleSystem sd.surfnor= NULL; /* strand render setup */ - if(strandbuf) { + if (strandbuf) { strand= RE_findOrAddStrand(obr, obr->totstrand++); strand->buffer= strandbuf; strand->vert= svert; copy_v3_v3(strand->orco, sd.orco); - if(dosimplify) { + if (dosimplify) { float *ssimplify= RE_strandren_get_simplify(obr, strand, 1); ssimplify[0]= simplify[0]; ssimplify[1]= simplify[1]; } - if(sd.surfnor) { + if (sd.surfnor) { float *snor= RE_strandren_get_surfnor(obr, strand, 1); copy_v3_v3(snor, sd.surfnor); } - if(dosurfacecache && num >= 0) { + if (dosurfacecache && num >= 0) { int *facenum= RE_strandren_get_face(obr, strand, 1); *facenum= num; } - if(sd.uvco) { - for(i=0; i<sd.totuv; i++) { - if(i != sd.override_uv) { + if (sd.uvco) { + for (i=0; i<sd.totuv; i++) { + if (i != sd.override_uv) { float *uv= RE_strandren_get_uv(obr, strand, i, NULL, 1); uv[0]= sd.uvco[2*i]; @@ -1913,8 +1917,8 @@ static int render_new_particle_system(Render *re, ObjectRen *obr, ParticleSystem } } } - if(sd.mcol) { - for(i=0; i<sd.totcol; i++) { + if (sd.mcol) { + for (i=0; i<sd.totcol; i++) { MCol *mc= RE_strandren_get_mcol(obr, strand, i, NULL, 1); *mc = sd.mcol[i]; } @@ -1924,43 +1928,43 @@ static int render_new_particle_system(Render *re, ObjectRen *obr, ParticleSystem } /* strandco computation setup */ - if(path_nbr) { + if (path_nbr) { strandlen= 0.0f; curlen= 0.0f; - for(k=1; k<=path_nbr; k++) - if(k<=max_k) + for (k=1; k<=path_nbr; k++) + if (k<=max_k) strandlen += len_v3v3((cache+k-1)->co, (cache+k)->co); } - if(path_nbr) { + if (path_nbr) { /* render strands */ - for(k=0; k<=path_nbr; k++){ + for (k=0; k<=path_nbr; k++) { float time; - if(k<=max_k){ + if (k<=max_k) { copy_v3_v3(state.co,(cache+k)->co); copy_v3_v3(state.vel,(cache+k)->vel); } else continue; - if(k > 0) + if (k > 0) curlen += len_v3v3((cache+k-1)->co, (cache+k)->co); time= curlen/strandlen; copy_v3_v3(loc,state.co); mul_m4_v3(re->viewmat,loc); - if(strandbuf) { + if (strandbuf) { copy_v3_v3(svert->co, loc); svert->strandco= -1.0f + 2.0f*time; svert++; strand->totvert++; } - else{ + else { sd.size = hasize; - if(k==1){ + if (k==1) { sd.first = 1; sd.time = 0.0f; sub_v3_v3v3(loc0,loc1,loc); @@ -1972,7 +1976,7 @@ static int render_new_particle_system(Render *re, ObjectRen *obr, ParticleSystem sd.first = 0; sd.time = time; - if(k) + if (k) particle_curve(re, obr, psmd->dm, ma, &sd, loc, loc1, seed, pa_co); copy_v3_v3(loc1,loc); @@ -1982,7 +1986,7 @@ static int render_new_particle_system(Render *re, ObjectRen *obr, ParticleSystem } else { /* render normal particles */ - if(part->trail_count > 1) { + if (part->trail_count > 1) { float length = part->path_end * (1.0f - part->randlength * r_length); int trail_count = part->trail_count * (1.0f - part->randlength * r_length); float ct = (part->draw & PART_ABS_PATH_TIME) ? cfra : pa_time; @@ -1991,24 +1995,24 @@ static int render_new_particle_system(Render *re, ObjectRen *obr, ParticleSystem /* make sure we have pointcache in memory before getting particle on path */ psys_make_temp_pointcache(ob, psys); - for(i=0; i < trail_count; i++, ct -= dt) { - if(part->draw & PART_ABS_PATH_TIME) { - if(ct < pa_birthtime || ct > pa_dietime) + for (i=0; i < trail_count; i++, ct -= dt) { + if (part->draw & PART_ABS_PATH_TIME) { + if (ct < pa_birthtime || ct > pa_dietime) continue; } - else if(ct < 0.0f || ct > 1.0f) + else if (ct < 0.0f || ct > 1.0f) continue; state.time = (part->draw & PART_ABS_PATH_TIME) ? -ct : ct; psys_get_particle_on_path(&sim,a,&state,1); - if(psys->parent) + if (psys->parent) mul_m4_v3(psys->parent->obmat, state.co); - if(use_duplimat) + if (use_duplimat) mul_m4_v4(duplimat, state.co); - if(part->ren_as == PART_DRAW_BB) { + if (part->ren_as == PART_DRAW_BB) { bb.random = random; bb.offset[0] = part->bb_offset[0]; bb.offset[1] = part->bb_offset[1]; @@ -2037,16 +2041,16 @@ static int render_new_particle_system(Render *re, ObjectRen *obr, ParticleSystem } else { state.time=cfra; - if(psys_get_particle_state(&sim,a,&state,0)==0) + if (psys_get_particle_state(&sim,a,&state,0)==0) continue; - if(psys->parent) + if (psys->parent) mul_m4_v3(psys->parent->obmat, state.co); - if(use_duplimat) + if (use_duplimat) mul_m4_v3(duplimat, state.co); - if(part->ren_as == PART_DRAW_BB) { + if (part->ren_as == PART_DRAW_BB) { bb.random = random; bb.offset[0] = part->bb_offset[0]; bb.offset[1] = part->bb_offset[1]; @@ -2072,46 +2076,46 @@ static int render_new_particle_system(Render *re, ObjectRen *obr, ParticleSystem } } - if(orco1==0) + if (orco1==0) sd.orco+=3; - if(re->test_break(re->tbh)) + if (re->test_break(re->tbh)) break; } - if(dosurfacecache) + if (dosurfacecache) strandbuf->surface= cache_strand_surface(re, obr, psmd->dm, mat, timeoffset); /* 4. clean up */ #if 0 // XXX old animation system - if(ma) do_mat_ipo(re->scene, ma); + if (ma) do_mat_ipo(re->scene, ma); #endif // XXX old animation system - if(orco1) + if (orco1) MEM_freeN(sd.orco); - if(sd.uvco) + if (sd.uvco) MEM_freeN(sd.uvco); - if(sd.mcol) + if (sd.mcol) MEM_freeN(sd.mcol); - if(uv_name) + if (uv_name) MEM_freeN(uv_name); - if(states) + if (states) MEM_freeN(states); rng_free(rng); psys->flag &= ~PSYS_DRAWING; - if(psys->lattice){ + if (psys->lattice) { end_latt_deform(psys->lattice); psys->lattice= NULL; } - if(path_nbr && (ma->mode_l & MA_TANGENT_STR)==0) + if (path_nbr && (ma->mode_l & MA_TANGENT_STR)==0) calc_vertexnormals(re, obr, 0, 0); return 1; @@ -2134,16 +2138,16 @@ static void make_render_halos(Render *re, ObjectRen *obr, Mesh *UNUSED(me), int re->flag |= R_HALO; - for(a=0; a<totvert; a++, mvert++) { + for (a=0; a<totvert; a++, mvert++) { ok= 1; - if(ok) { + if (ok) { hasize= ma->hasize; copy_v3_v3(vec, mvert->co); mul_m4_v3(mat, vec); - if(ma->mode & MA_HALOPUNO) { + if (ma->mode & MA_HALOPUNO) { xn= mvert->no[0]; yn= mvert->no[1]; zn= mvert->no[2]; @@ -2158,15 +2162,15 @@ static void make_render_halos(Render *re, ObjectRen *obr, Mesh *UNUSED(me), int normalize_v3(view); zn = dot_v3v3(nor, view); - if(zn>=0.0f) hasize= 0.0f; + if (zn>=0.0f) hasize= 0.0f; else hasize*= zn*zn*zn*zn; } - if(orco) har= RE_inithalo(re, obr, ma, vec, NULL, orco, hasize, 0.0, seed); + if (orco) har= RE_inithalo(re, obr, ma, vec, NULL, orco, hasize, 0.0, seed); else har= RE_inithalo(re, obr, ma, vec, NULL, mvert->co, hasize, 0.0, seed); - if(har) har->lay= ob->lay; + if (har) har->lay= ob->lay; } - if(orco) orco+= 3; + if (orco) orco+= 3; seed++; } } @@ -2176,8 +2180,8 @@ static int verghalo(const void *a1, const void *a2) const HaloRen *har1= *(const HaloRen**)a1; const HaloRen *har2= *(const HaloRen**)a2; - if(har1->zs < har2->zs) return 1; - else if(har1->zs > har2->zs) return -1; + if (har1->zs < har2->zs) return 1; + else if (har1->zs > har2->zs) return -1; return 0; } @@ -2187,14 +2191,14 @@ static void sort_halos(Render *re, int totsort) HaloRen *har= NULL, **haso; int a; - if(re->tothalo==0) return; + if (re->tothalo==0) return; re->sortedhalos= MEM_callocN(sizeof(HaloRen*)*re->tothalo, "sorthalos"); haso= re->sortedhalos; - for(obr=re->objecttable.first; obr; obr=obr->next) { - for(a=0; a<obr->tothalo; a++) { - if((a & 255)==0) har= obr->bloha[a>>8]; + for (obr=re->objecttable.first; obr; obr=obr->next) { + for (a=0; a<obr->tothalo; a++) { + if ((a & 255)==0) har= obr->bloha[a>>8]; else har++; *(haso++)= har; @@ -2217,7 +2221,7 @@ static short test_for_displace(Render *re, Object *ob) for (i=1; i<=ob->totcol; i++) { ma=give_render_material(re, ob, i); /* ma->mapto is ORed total of all mapto channels */ - if(ma && (ma->mapto & MAP_DISPLACE)) return 1; + if (ma && (ma->mapto & MAP_DISPLACE)) return 1; } return 0; } @@ -2235,10 +2239,10 @@ static void displace_render_vert(Render *re, ObjectRen *obr, ShadeInput *shi, Ve /* vertex normal is used for textures type 'col' and 'var' */ copy_v3_v3(shi->vn, vr->n); - if(mat) + if (mat) mul_m4_v3(mat, shi->co); - if(imat) { + if (imat) { shi->vn[0] = dot_v3v3(imat[0], vr->n); shi->vn[1] = dot_v3v3(imat[1], vr->n); shi->vn[2] = dot_v3v3(imat[2], vr->n); @@ -2266,7 +2270,7 @@ static void displace_render_vert(Render *re, ObjectRen *obr, ShadeInput *shi, Ve } if (texco & TEXCO_STICKY) { float *sticky= RE_vertren_get_sticky(obr, vr, 0); - if(sticky) { + if (sticky) { shi->sticky[0]= sticky[0]; shi->sticky[1]= sticky[1]; shi->sticky[2]= 0.0f; @@ -2279,15 +2283,15 @@ static void displace_render_vert(Render *re, ObjectRen *obr, ShadeInput *shi, Ve if (texco & TEXCO_NORM) { copy_v3_v3(shi->orn, shi->vn); } - if(texco & TEXCO_REFL) { + if (texco & TEXCO_REFL) { /* not (yet?) */ } - if(texco & TEXCO_STRESS) { + if (texco & TEXCO_STRESS) { float *s= RE_vertren_get_stress(obr, vr, 0); - if(s) { + if (s) { shi->stress= *s; - if(shi->stress<1.0f) shi->stress-= 1.0f; + if (shi->stress<1.0f) shi->stress-= 1.0f; else shi->stress= (shi->stress-1.0f)/shi->stress; } else @@ -2305,7 +2309,7 @@ static void displace_render_vert(Render *re, ObjectRen *obr, ShadeInput *shi, Ve displace[1]= shi->displace[1] * scale[1]; displace[2]= shi->displace[2] * scale[2]; - if(mat) + if (mat) mul_m3_v3(imat, displace); /* 0.5 could become button once? */ @@ -2377,7 +2381,7 @@ static void displace_render_face(Render *re, ObjectRen *obr, VlakRen *vlr, float } /* Recalculate the face normal - if flipped before, flip now */ - if(vlr->v4) { + if (vlr->v4) { normal_quad_v3( vlr->n,vlr->v4->co, vlr->v3->co, vlr->v2->co, vlr->v1->co); } else { @@ -2396,19 +2400,19 @@ static void do_displacement(Render *re, ObjectRen *obr, float mat[][4], float im /* Object Size with parenting */ obt=obr->ob; - while(obt){ + while(obt) { mul_v3_v3v3(temp, obt->size, obt->dscale); scale[0]*=temp[0]; scale[1]*=temp[1]; scale[2]*=temp[2]; obt=obt->parent; } /* Clear all flags */ - for(i=0; i<obr->totvert; i++){ + for (i=0; i<obr->totvert; i++) { vr= RE_findOrAddVert(obr, i); vr->flag= 0; } - for(i=0; i<obr->totvlak; i++){ + for (i=0; i<obr->totvlak; i++) { vlr=RE_findOrAddVlak(obr, i); displace_render_face(re, obr, vlr, scale, mat, imat); } @@ -2443,17 +2447,17 @@ static void init_render_mball(Render *re, ObjectRen *obr) ma= give_render_material(re, ob, 1); need_orco= 0; - if(ma->texco & TEXCO_ORCO) { + if (ma->texco & TEXCO_ORCO) { need_orco= 1; } makeDispListMBall_forRender(re->scene, ob, &dispbase); dl= dispbase.first; - if(dl==0) return; + if (dl==0) return; data= dl->verts; nors= dl->nors; - if(need_orco) { + if (need_orco) { orco= get_object_orco(re, ob); if (!orco) { @@ -2463,7 +2467,7 @@ static void init_render_mball(Render *re, ObjectRen *obr) } } - for(a=0; a<dl->nr; a++, data+=3, nors+=3) { + for (a=0; a<dl->nr; a++, data+=3, nors+=3) { ver= RE_findOrAddVert(obr, obr->totvert++); copy_v3_v3(ver->co, data); @@ -2481,14 +2485,14 @@ static void init_render_mball(Render *re, ObjectRen *obr) normalize_v3(ver->n); //if(ob->transflag & OB_NEG_SCALE) negate_v3(ver->n); - if(need_orco) { + if (need_orco) { ver->orco= orco; orco+=3; } } index= dl->index; - for(a=0; a<dl->parts; a++, index+=4) { + for (a=0; a<dl->parts; a++, index+=4) { vlr= RE_findOrAddVlak(obr, obr->totvlak++); vlr->v1= RE_findOrAddVert(obr, index[0]); @@ -2496,7 +2500,7 @@ static void init_render_mball(Render *re, ObjectRen *obr) vlr->v3= RE_findOrAddVert(obr, index[2]); vlr->v4= 0; - if(negative_scale) + if (negative_scale) normal_tri_v3( vlr->n,vlr->v1->co, vlr->v2->co, vlr->v3->co); else normal_tri_v3( vlr->n,vlr->v3->co, vlr->v2->co, vlr->v1->co); @@ -2506,14 +2510,14 @@ static void init_render_mball(Render *re, ObjectRen *obr) vlr->ec= 0; /* mball -too bad- always has triangles, because quads can be non-planar */ - if(index[3] && index[3]!=index[2]) { + if (index[3] && index[3]!=index[2]) { vlr1= RE_findOrAddVlak(obr, obr->totvlak++); vlakindex= vlr1->index; *vlr1= *vlr; vlr1->index= vlakindex; vlr1->v2= vlr1->v3; vlr1->v3= RE_findOrAddVert(obr, index[3]); - if(negative_scale) + if (negative_scale) normal_tri_v3( vlr1->n,vlr1->v1->co, vlr1->v2->co, vlr1->v3->co); else normal_tri_v3( vlr1->n,vlr1->v3->co, vlr1->v2->co, vlr1->v1->co); @@ -2546,7 +2550,7 @@ static int dl_surf_to_renderdata(ObjectRen *obr, DispList *dl, Material **matar, for (u = 0; u < sizeu; u++) { v1 = RE_findOrAddVert(obr, obr->totvert++); /* save this for possible V wrapping */ copy_v3_v3(v1->co, data); data += 3; - if(orco) { + if (orco) { v1->orco= orco; orco+= 3; orcoret++; } mul_m4_v3(mat, v1->co); @@ -2554,7 +2558,7 @@ static int dl_surf_to_renderdata(ObjectRen *obr, DispList *dl, Material **matar, for (v = 1; v < sizev; v++) { ver= RE_findOrAddVert(obr, obr->totvert++); copy_v3_v3(ver->co, data); data += 3; - if(orco) { + if (orco) { ver->orco= orco; orco+= 3; orcoret++; } mul_m4_v3(mat, ver->co); @@ -2563,7 +2567,7 @@ static int dl_surf_to_renderdata(ObjectRen *obr, DispList *dl, Material **matar, if (dl->flag & DL_CYCL_U) { ver= RE_findOrAddVert(obr, obr->totvert++); copy_v3_v3(ver->co, v1->co); - if(orco) { + if (orco) { ver->orco= orco; orco+=3; orcoret++; //orcobase + 3*(u*sizev + 0); } } @@ -2579,7 +2583,7 @@ static int dl_surf_to_renderdata(ObjectRen *obr, DispList *dl, Material **matar, v1= RE_findOrAddVert(obr, startvert + v); ver= RE_findOrAddVert(obr, obr->totvert++); copy_v3_v3(ver->co, v1->co); - if(orco) { + if (orco) { ver->orco= orco; orco+=3; orcoret++; //ver->orco= orcobase + 3*(0*sizev + v); } } @@ -2590,13 +2594,13 @@ static int dl_surf_to_renderdata(ObjectRen *obr, DispList *dl, Material **matar, startvlak= obr->totvlak; - for(u = 0; u < sizeu - 1; u++) { + for (u = 0; u < sizeu - 1; u++) { p1 = startvert + u * sizev; /* walk through face list */ p2 = p1 + 1; p3 = p2 + sizev; p4 = p3 - 1; - for(v = 0; v < sizev - 1; v++) { + for (v = 0; v < sizev - 1; v++) { v1= RE_findOrAddVert(obr, p1); v2= RE_findOrAddVert(obr, p2); v3= RE_findOrAddVert(obr, p3); @@ -2680,7 +2684,7 @@ static int dl_surf_to_renderdata(ObjectRen *obr, DispList *dl, Material **matar, copy_v3_v3(vlr2->v2->n, n1); copy_v3_v3(vlr3->v4->n, n1); } - for(a = startvert; a < obr->totvert; a++) { + for (a = startvert; a < obr->totvert; a++) { ver= RE_findOrAddVert(obr, a); normalize_v3(ver->n); } @@ -2705,18 +2709,18 @@ static void init_render_dm(DerivedMesh *dm, Render *re, ObjectRen *obr, mvert= dm->getVertArray(dm); totvert= dm->getNumVerts(dm); - for(a=0; a<totvert; a++, mvert++) { + for (a=0; a<totvert; a++, mvert++) { ver= RE_findOrAddVert(obr, obr->totvert++); copy_v3_v3(ver->co, mvert->co); mul_m4_v3(mat, ver->co); - if(orco) { + if (orco) { ver->orco= orco; orco+=3; } } - if(!timeoffset) { + if (!timeoffset) { /* store customdata names, because DerivedMesh is freed */ RE_set_customdata_names(obr, &dm->faceData); @@ -2724,16 +2728,16 @@ static void init_render_dm(DerivedMesh *dm, Render *re, ObjectRen *obr, /* faces in order of color blocks */ vertofs= obr->totvert - totvert; - for(mat_iter= 0; (mat_iter < ob->totcol || (mat_iter==0 && ob->totcol==0)); mat_iter++) { + for (mat_iter= 0; (mat_iter < ob->totcol || (mat_iter==0 && ob->totcol==0)); mat_iter++) { ma= give_render_material(re, ob, mat_iter+1); end= dm->getNumTessFaces(dm); mface= dm->getTessFaceArray(dm); - for(a=0; a<end; a++, mface++) { + for (a=0; a<end; a++, mface++) { int v1, v2, v3, v4, flag; - if(mface->mat_nr == mat_iter) { + if (mface->mat_nr == mat_iter) { float len; v1= mface->v1; @@ -2746,11 +2750,11 @@ static void init_render_dm(DerivedMesh *dm, Render *re, ObjectRen *obr, vlr->v1= RE_findOrAddVert(obr, vertofs+v1); vlr->v2= RE_findOrAddVert(obr, vertofs+v2); vlr->v3= RE_findOrAddVert(obr, vertofs+v3); - if(v4) vlr->v4= RE_findOrAddVert(obr, vertofs+v4); + if (v4) vlr->v4= RE_findOrAddVert(obr, vertofs+v4); else vlr->v4= 0; /* render normals are inverted in render */ - if(vlr->v4) + if (vlr->v4) len= normal_quad_v3( vlr->n,vlr->v4->co, vlr->v3->co, vlr->v2->co, vlr->v1->co); else len= normal_tri_v3( vlr->n,vlr->v3->co, vlr->v2->co, vlr->v1->co); @@ -2759,7 +2763,7 @@ static void init_render_dm(DerivedMesh *dm, Render *re, ObjectRen *obr, vlr->flag= flag; vlr->ec= 0; /* mesh edges rendered separately */ - if(len==0) obr->totvlak--; + if (len==0) obr->totvlak--; else { CustomDataLayer *layer; MTFace *mtface, *mtf; @@ -2767,16 +2771,16 @@ static void init_render_dm(DerivedMesh *dm, Render *re, ObjectRen *obr, int index, mtfn= 0, mcn= 0; char *name; - for(index=0; index<dm->faceData.totlayer; index++) { + for (index=0; index<dm->faceData.totlayer; index++) { layer= &dm->faceData.layers[index]; name= layer->name; - if(layer->type == CD_MTFACE && mtfn < MAX_MTFACE) { + if (layer->type == CD_MTFACE && mtfn < MAX_MTFACE) { mtf= RE_vlakren_get_tface(obr, vlr, mtfn++, &name, 1); mtface= (MTFace*)layer->data; *mtf= mtface[a]; } - else if(layer->type == CD_MCOL && mcn < MAX_MCOL) { + else if (layer->type == CD_MCOL && mcn < MAX_MCOL) { mc= RE_vlakren_get_mcol(obr, vlr, mcn++, &name, 1); mcol= (MCol*)layer->data; memcpy(mc, &mcol[a*4], sizeof(MCol)*4); @@ -2807,7 +2811,7 @@ static void init_render_surf(Render *re, ObjectRen *obr, int timeoffset) cu= ob->data; nu= cu->nurb.first; - if(nu==0) return; + if (nu==0) return; mult_m4_m4m4(mat, re->viewmat, ob->obmat); invert_m4_m4(ob->imat, mat); @@ -2816,36 +2820,37 @@ static void init_render_surf(Render *re, ObjectRen *obr, int timeoffset) totmat= ob->totcol+1; matar= MEM_callocN(sizeof(Material*)*totmat, "init_render_surf matar"); - for(a=0; a<totmat; a++) { + for (a=0; a<totmat; a++) { matar[a]= give_render_material(re, ob, a+1); - if(matar[a] && matar[a]->texco & TEXCO_ORCO) + if (matar[a] && matar[a]->texco & TEXCO_ORCO) need_orco= 1; } - if(ob->parent && (ob->parent->type==OB_LATTICE)) need_orco= 1; + if (ob->parent && (ob->parent->type==OB_LATTICE)) need_orco= 1; makeDispListSurf(re->scene, ob, &displist, &dm, 1, 0); if (dm) { - if(need_orco) { + if (need_orco) { orco= makeOrcoDispList(re->scene, ob, dm, 1); - if(orco) { + if (orco) { set_object_orco(re, ob, orco); } } init_render_dm(dm, re, obr, timeoffset, orco, mat); dm->release(dm); - } else { - if(need_orco) { + } + else { + if (need_orco) { orco= get_object_orco(re, ob); } /* walk along displaylist and create rendervertices/-faces */ - for(dl=displist.first; dl; dl=dl->next) { + for (dl=displist.first; dl; dl=dl->next) { /* watch out: u ^= y, v ^= x !! */ - if(dl->type==DL_SURF) + if (dl->type==DL_SURF) orco+= 3*dl_surf_to_renderdata(obr, dl, matar, orco, mat); } } @@ -2871,12 +2876,12 @@ static void init_render_curve(Render *re, ObjectRen *obr, int timeoffset) int need_orco=0, totmat; cu= ob->data; - if(ob->type==OB_FONT && cu->str==NULL) return; - else if(ob->type==OB_CURVE && cu->nurb.first==NULL) return; + if (ob->type==OB_FONT && cu->str==NULL) return; + else if (ob->type==OB_CURVE && cu->nurb.first==NULL) return; makeDispListCurveTypes_forRender(re->scene, ob, &disp, &dm, 0); dl= disp.first; - if(dl==NULL) return; + if (dl==NULL) return; mult_m4_m4m4(mat, re->viewmat, ob->obmat); invert_m4_m4(ob->imat, mat); @@ -2885,39 +2890,40 @@ static void init_render_curve(Render *re, ObjectRen *obr, int timeoffset) totmat= ob->totcol+1; matar= MEM_callocN(sizeof(Material*)*totmat, "init_render_surf matar"); - for(a=0; a<totmat; a++) { + for (a=0; a<totmat; a++) { matar[a]= give_render_material(re, ob, a+1); - if(matar[a] && matar[a]->texco & TEXCO_ORCO) + if (matar[a] && matar[a]->texco & TEXCO_ORCO) need_orco= 1; } if (dm) { - if(need_orco) { + if (need_orco) { orco= makeOrcoDispList(re->scene, ob, dm, 1); - if(orco) { + if (orco) { set_object_orco(re, ob, orco); } } init_render_dm(dm, re, obr, timeoffset, orco, mat); dm->release(dm); - } else { - if(need_orco) { + } + else { + if (need_orco) { orco= get_object_orco(re, ob); } while(dl) { - if(dl->col > ob->totcol) { + if (dl->col > ob->totcol) { /* pass */ } - else if(dl->type==DL_INDEX3) { + else if (dl->type==DL_INDEX3) { int *index; startvert= obr->totvert; data= dl->verts; - for(a=0; a<dl->nr; a++, data+=3) { + for (a=0; a<dl->nr; a++, data+=3) { ver= RE_findOrAddVert(obr, obr->totvert++); copy_v3_v3(ver->co, data); @@ -2929,20 +2935,20 @@ static void init_render_curve(Render *re, ObjectRen *obr, int timeoffset) } } - if(timeoffset==0) { + if (timeoffset==0) { float tmp[3]; const int startvlak= obr->totvlak; zero_v3(n); index= dl->index; - for(a=0; a<dl->parts; a++, index+=3) { + for (a=0; a<dl->parts; a++, index+=3) { vlr= RE_findOrAddVlak(obr, obr->totvlak++); vlr->v1= RE_findOrAddVert(obr, startvert+index[0]); vlr->v2= RE_findOrAddVert(obr, startvert+index[1]); vlr->v3= RE_findOrAddVert(obr, startvert+index[2]); vlr->v4= NULL; - if(area_tri_v3(vlr->v3->co, vlr->v2->co, vlr->v1->co)>FLT_EPSILON) { + if (area_tri_v3(vlr->v3->co, vlr->v2->co, vlr->v1->co)>FLT_EPSILON) { normal_tri_v3(tmp, vlr->v3->co, vlr->v2->co, vlr->v1->co); add_v3_v3(n, tmp); } @@ -2955,7 +2961,7 @@ static void init_render_curve(Render *re, ObjectRen *obr, int timeoffset) normalize_v3(n); /* vertex normals */ - for(a= startvlak; a<obr->totvlak; a++) { + for (a= startvlak; a<obr->totvlak; a++) { vlr= RE_findOrAddVlak(obr, a); copy_v3_v3(vlr->n, n); @@ -2963,7 +2969,7 @@ static void init_render_curve(Render *re, ObjectRen *obr, int timeoffset) add_v3_v3(vlr->v3->n, vlr->n); add_v3_v3(vlr->v2->n, vlr->n); } - for(a=startvert; a<obr->totvert; a++) { + for (a=startvert; a<obr->totvert; a++) { ver= RE_findOrAddVert(obr, a); normalize_v3(ver->n); } @@ -2995,10 +3001,10 @@ static void init_render_curve(Render *re, ObjectRen *obr, int timeoffset) } } - if(dl->bevelSplitFlag || timeoffset==0) { + if (dl->bevelSplitFlag || timeoffset==0) { const int startvlak= obr->totvlak; - for(a=0; a<dl->parts; a++) { + for (a=0; a<dl->parts; a++) { if (surfindex_displist(dl, a, &b, &p1, &p2, &p3, &p4)==0) break; @@ -3008,7 +3014,7 @@ static void init_render_curve(Render *re, ObjectRen *obr, int timeoffset) p3+= startvert; p4+= startvert; - for(; b<dl->nr; b++) { + for (; b<dl->nr; b++) { vlr= RE_findOrAddVlak(obr, obr->totvlak++); /* important 1 offset in order is kept [#24913] */ vlr->v1= RE_findOrAddVert(obr, p2); @@ -3016,7 +3022,7 @@ static void init_render_curve(Render *re, ObjectRen *obr, int timeoffset) vlr->v3= RE_findOrAddVert(obr, p3); vlr->v4= RE_findOrAddVert(obr, p4); vlr->ec= ME_V2V3+ME_V3V4; - if(a==0) vlr->ec+= ME_V1V2; + if (a==0) vlr->ec+= ME_V1V2; vlr->flag= dl->rt; @@ -3031,13 +3037,13 @@ static void init_render_curve(Render *re, ObjectRen *obr, int timeoffset) } if (dl->bevelSplitFlag) { - for(a=0; a<dl->parts-1+!!(dl->flag&DL_CYCL_V); a++) - if(dl->bevelSplitFlag[a>>5]&(1<<(a&0x1F))) + for (a=0; a<dl->parts-1+!!(dl->flag&DL_CYCL_V); a++) + if (dl->bevelSplitFlag[a>>5]&(1<<(a&0x1F))) split_v_renderfaces(obr, startvlak, startvert, dl->parts, dl->nr, a, dl->flag&DL_CYCL_V, dl->flag&DL_CYCL_U); } /* vertex normals */ - for(a= startvlak; a<obr->totvlak; a++) { + for (a= startvlak; a<obr->totvlak; a++) { vlr= RE_findOrAddVlak(obr, a); add_v3_v3(vlr->v1->n, vlr->n); @@ -3045,7 +3051,7 @@ static void init_render_curve(Render *re, ObjectRen *obr, int timeoffset) add_v3_v3(vlr->v2->n, vlr->n); add_v3_v3(vlr->v4->n, vlr->n); } - for(a=startvert; a<obr->totvert; a++) { + for (a=startvert; a<obr->totvert; a++) { ver= RE_findOrAddVert(obr, a); normalize_v3(ver->n); } @@ -3093,10 +3099,10 @@ static int vergedgesort(const void *v1, const void *v2) { const struct edgesort *x1=v1, *x2=v2; - if( x1->v1 > x2->v1) return 1; - else if( x1->v1 < x2->v1) return -1; - else if( x1->v2 > x2->v2) return 1; - else if( x1->v2 < x2->v2) return -1; + if ( x1->v1 > x2->v1) return 1; + else if ( x1->v1 < x2->v1) return -1; + else if ( x1->v2 > x2->v2) return 1; + else if ( x1->v2 < x2->v2) return -1; return 0; } @@ -3114,27 +3120,27 @@ static struct edgesort *make_mesh_edge_lookup(DerivedMesh *dm, int *totedgesort) tface= dm->getTessFaceDataArray(dm, CD_MTFACE); mcol= dm->getTessFaceDataArray(dm, CD_MCOL); - if(mcol==NULL && tface==NULL) return NULL; + if (mcol==NULL && tface==NULL) return NULL; /* make sorted table with edges and face indices in it */ - for(a= totface, mf= mface; a>0; a--, mf++) { - if(mf->v4) totedge+=4; - else if(mf->v3) totedge+=3; + for (a= totface, mf= mface; a>0; a--, mf++) { + if (mf->v4) totedge+=4; + else if (mf->v3) totedge+=3; } - if(totedge==0) + if (totedge==0) return NULL; ed= edsort= MEM_callocN(totedge*sizeof(struct edgesort), "edgesort"); - for(a=0, mf=mface; a<totface; a++, mf++) { + for (a=0, mf=mface; a<totface; a++, mf++) { to_edgesort(ed++, 0, 1, mf->v1, mf->v2, a); to_edgesort(ed++, 1, 2, mf->v2, mf->v3, a); - if(mf->v4) { + if (mf->v4) { to_edgesort(ed++, 2, 3, mf->v3, mf->v4, a); to_edgesort(ed++, 3, 0, mf->v4, mf->v1, a); } - else if(mf->v3) + else if (mf->v3) to_edgesort(ed++, 2, 3, mf->v3, mf->v1, a); } @@ -3154,7 +3160,7 @@ static void use_mesh_edge_lookup(ObjectRen *obr, DerivedMesh *dm, MEdge *medge, int index, mtfn, mcn; char *name; - if(medge->v1 < medge->v2) { + if (medge->v1 < medge->v2) { ed.v1= medge->v1; ed.v2= medge->v2; } @@ -3166,14 +3172,14 @@ static void use_mesh_edge_lookup(ObjectRen *obr, DerivedMesh *dm, MEdge *medge, edp= bsearch(&ed, edgetable, totedge, sizeof(struct edgesort), vergedgesort); /* since edges have different index ordering, we have to duplicate mcol and tface */ - if(edp) { + if (edp) { mtfn= mcn= 0; - for(index=0; index<dm->faceData.totlayer; index++) { + for (index=0; index<dm->faceData.totlayer; index++) { layer= &dm->faceData.layers[index]; name= layer->name; - if(layer->type == CD_MTFACE && mtfn < MAX_MTFACE) { + if (layer->type == CD_MTFACE && mtfn < MAX_MTFACE) { mtface= &((MTFace*)layer->data)[edp->f]; mtf= RE_vlakren_get_tface(obr, vlr, mtfn++, &name, 1); @@ -3184,7 +3190,7 @@ static void use_mesh_edge_lookup(ObjectRen *obr, DerivedMesh *dm, MEdge *medge, memcpy(mtf->uv[2], mtface->uv[1], sizeof(float)*2); memcpy(mtf->uv[3], mtface->uv[1], sizeof(float)*2); } - else if(layer->type == CD_MCOL && mcn < MAX_MCOL) { + else if (layer->type == CD_MCOL && mcn < MAX_MCOL) { mcol= &((MCol*)layer->data)[edp->f*4]; mc= RE_vlakren_get_mcol(obr, vlr, mcn++, &name, 1); @@ -3206,8 +3212,8 @@ static void init_camera_inside_volumes(Render *re) VolumeOb *vo; float co[3] = {0.f, 0.f, 0.f}; - for(vo= re->volumes.first; vo; vo= vo->next) { - for(obi= re->instancetable.first; obi; obi= obi->next) { + for (vo= re->volumes.first; vo; vo= vo->next) { + for (obi= re->instancetable.first; obi; obi= obi->next) { if (obi->obr == vo->obr) { if (point_inside_volume_objectinstance(re, obi, co)) { MatInside *mi; @@ -3270,25 +3276,25 @@ static void init_render_mesh(Render *re, ObjectRen *obr, int timeoffset) copy_m3_m4(imat, ob->imat); negative_scale= is_negative_m4(mat); - if(me->totvert==0) + if (me->totvert==0) return; need_orco= 0; - for(a=1; a<=ob->totcol; a++) { + for (a=1; a<=ob->totcol; a++) { ma= give_render_material(re, ob, a); - if(ma) { - if(ma->texco & (TEXCO_ORCO|TEXCO_STRESS)) + if (ma) { + if (ma->texco & (TEXCO_ORCO|TEXCO_STRESS)) need_orco= 1; - if(ma->texco & TEXCO_STRESS) + if (ma->texco & TEXCO_STRESS) need_stress= 1; /* normalmaps, test if tangents needed, separated from shading */ - if(ma->mode_l & MA_TANGENT_V) { + if (ma->mode_l & MA_TANGENT_V) { need_tangent= 1; - if(me->mtface==NULL) + if (me->mtface==NULL) need_orco= 1; } - if(ma->mode_l & MA_NORMAP_TANG) { - if(me->mtface==NULL) { + if (ma->mode_l & MA_NORMAP_TANG) { + if (me->mtface==NULL) { need_orco= 1; need_tangent= 1; } @@ -3297,9 +3303,9 @@ static void init_render_mesh(Render *re, ObjectRen *obr, int timeoffset) } } - if(re->flag & R_NEED_TANGENT) { + if (re->flag & R_NEED_TANGENT) { /* exception for tangent space baking */ - if(me->mtface==NULL) { + if (me->mtface==NULL) { need_orco= 1; need_tangent= 1; } @@ -3308,22 +3314,22 @@ static void init_render_mesh(Render *re, ObjectRen *obr, int timeoffset) /* check autosmooth and displacement, we then have to skip only-verts optimize */ do_autosmooth |= (me->flag & ME_AUTOSMOOTH); - if(do_autosmooth) + if (do_autosmooth) timeoffset= 0; - if(test_for_displace(re, ob ) ) + if (test_for_displace(re, ob ) ) timeoffset= 0; mask= CD_MASK_BAREMESH|CD_MASK_MTFACE|CD_MASK_MCOL; - if(!timeoffset) - if(need_orco) + if (!timeoffset) + if (need_orco) mask |= CD_MASK_ORCO; dm= mesh_create_derived_render(re->scene, ob, mask); - if(dm==NULL) return; /* in case duplicated object fails? */ + if (dm==NULL) return; /* in case duplicated object fails? */ - if(mask & CD_MASK_ORCO) { + if (mask & CD_MASK_ORCO) { orco= dm->getVertDataArray(dm, CD_ORCO); - if(orco) { + if (orco) { orco= MEM_dupallocN(orco); set_object_orco(re, ob, orco); } @@ -3333,7 +3339,7 @@ static void init_render_mesh(Render *re, ObjectRen *obr, int timeoffset) totvert= dm->getNumVerts(dm); /* attempt to autsmooth on original mesh, only without subsurf */ - if(do_autosmooth && me->totvert==totvert && me->totface==dm->getNumTessFaces(dm)) + if (do_autosmooth && me->totvert==totvert && me->totface==dm->getNumTessFaces(dm)) use_original_normals= 1; ms = (totvert==me->totvert)?me->msticky:NULL; @@ -3341,15 +3347,15 @@ static void init_render_mesh(Render *re, ObjectRen *obr, int timeoffset) ma= give_render_material(re, ob, 1); - if(ma->material_type == MA_TYPE_HALO) { + if (ma->material_type == MA_TYPE_HALO) { make_render_halos(re, obr, me, totvert, mvert, ma, orco); } else { - for(a=0; a<totvert; a++, mvert++) { + for (a=0; a<totvert; a++, mvert++) { ver= RE_findOrAddVert(obr, obr->totvert++); copy_v3_v3(ver->co, mvert->co); - if(do_autosmooth==0) { /* autosmooth on original unrotated data to prevent differences between frames */ + if (do_autosmooth==0) { /* autosmooth on original unrotated data to prevent differences between frames */ normal_short_to_float_v3(ver->n, mvert->no); mul_m4_v3(mat, ver->co); mul_transposed_m3_v3(imat, ver->n); @@ -3357,59 +3363,59 @@ static void init_render_mesh(Render *re, ObjectRen *obr, int timeoffset) negate_v3(ver->n); } - if(orco) { + if (orco) { ver->orco= orco; orco+=3; } - if(ms) { + if (ms) { float *sticky= RE_vertren_get_sticky(obr, ver, 1); copy_v2_v2(sticky, ms->co); ms++; } } - if(!timeoffset) { + if (!timeoffset) { /* store customdata names, because DerivedMesh is freed */ RE_set_customdata_names(obr, &dm->faceData); /* add tangent layer if we need one */ - if(need_nmap_tangent!=0 && CustomData_get_layer_index(&dm->faceData, CD_TANGENT) == -1) + if (need_nmap_tangent!=0 && CustomData_get_layer_index(&dm->faceData, CD_TANGENT) == -1) DM_add_tangent_layer(dm); /* still to do for keys: the correct local texture coordinate */ /* faces in order of color blocks */ vertofs= obr->totvert - totvert; - for(a1=0; (a1<ob->totcol || (a1==0 && ob->totcol==0)); a1++) { + for (a1=0; (a1<ob->totcol || (a1==0 && ob->totcol==0)); a1++) { ma= give_render_material(re, ob, a1+1); /* test for 100% transparant */ ok= 1; - if(ma->alpha==0.0f && ma->spectra==0.0f && ma->filter==0.0f && (ma->mode & MA_TRANSP) && (ma->mode & MA_RAYMIRROR)==0) { + if (ma->alpha==0.0f && ma->spectra==0.0f && ma->filter==0.0f && (ma->mode & MA_TRANSP) && (ma->mode & MA_RAYMIRROR)==0) { ok= 0; /* texture on transparency? */ - for(a=0; a<MAX_MTEX; a++) { - if(ma->mtex[a] && ma->mtex[a]->tex) { - if(ma->mtex[a]->mapto & MAP_ALPHA) ok= 1; + for (a=0; a<MAX_MTEX; a++) { + if (ma->mtex[a] && ma->mtex[a]->tex) { + if (ma->mtex[a]->mapto & MAP_ALPHA) ok= 1; } } } /* if wire material, and we got edges, don't do the faces */ - if(ma->material_type == MA_TYPE_WIRE) { + if (ma->material_type == MA_TYPE_WIRE) { end= dm->getNumEdges(dm); - if(end) ok= 0; + if (end) ok= 0; } - if(ok) { + if (ok) { end= dm->getNumTessFaces(dm); mface= dm->getTessFaceArray(dm); - for(a=0; a<end; a++, mface++) { + for (a=0; a<end; a++, mface++) { int v1, v2, v3, v4, flag; - if( mface->mat_nr==a1 ) { + if ( mface->mat_nr==a1 ) { float len; int reverse_verts = negative_scale!=0 && do_autosmooth==0; int rev_tab[] = {reverse_verts==0 ? 0 : 2, 1, reverse_verts==0 ? 2 : 0, 3}; @@ -3423,21 +3429,21 @@ static void init_render_mesh(Render *re, ObjectRen *obr, int timeoffset) vlr->v1= RE_findOrAddVert(obr, vertofs+v1); vlr->v2= RE_findOrAddVert(obr, vertofs+v2); vlr->v3= RE_findOrAddVert(obr, vertofs+v3); - if(v4) vlr->v4= RE_findOrAddVert(obr, vertofs+v4); + if (v4) vlr->v4= RE_findOrAddVert(obr, vertofs+v4); else vlr->v4= 0; /* render normals are inverted in render */ - if(use_original_normals) { + if (use_original_normals) { MFace *mf= me->mface+a; MVert *mv= me->mvert; - if(vlr->v4) + if (vlr->v4) len= normal_quad_v3( vlr->n, mv[mf->v4].co, mv[mf->v3].co, mv[mf->v2].co, mv[mf->v1].co); else len= normal_tri_v3( vlr->n,mv[mf->v3].co, mv[mf->v2].co, mv[mf->v1].co); } else { - if(vlr->v4) + if (vlr->v4) len= normal_quad_v3( vlr->n,vlr->v4->co, vlr->v3->co, vlr->v2->co, vlr->v1->co); else len= normal_tri_v3( vlr->n,vlr->v3->co, vlr->v2->co, vlr->v1->co); @@ -3447,7 +3453,7 @@ static void init_render_mesh(Render *re, ObjectRen *obr, int timeoffset) vlr->flag= flag; vlr->ec= 0; /* mesh edges rendered separately */ - if(len==0) obr->totvlak--; + if (len==0) obr->totvlak--; else { CustomDataLayer *layer; MTFace *mtface, *mtf; @@ -3456,30 +3462,30 @@ static void init_render_mesh(Render *re, ObjectRen *obr, int timeoffset) char *name; int nr_verts = v4!=0 ? 4 : 3; - for(index=0; index<dm->faceData.totlayer; index++) { + for (index=0; index<dm->faceData.totlayer; index++) { layer= &dm->faceData.layers[index]; name= layer->name; - if(layer->type == CD_MTFACE && mtfn < MAX_MTFACE) { + if (layer->type == CD_MTFACE && mtfn < MAX_MTFACE) { int t; mtf= RE_vlakren_get_tface(obr, vlr, mtfn++, &name, 1); mtface= (MTFace*)layer->data; *mtf= mtface[a]; // copy face info - for(vindex=0; vindex<nr_verts; vindex++) - for(t=0; t<2; t++) + for (vindex=0; vindex<nr_verts; vindex++) + for (t=0; t<2; t++) mtf->uv[vindex][t]=mtface[a].uv[rev_tab[vindex]][t]; } - else if(layer->type == CD_MCOL && mcn < MAX_MCOL) { + else if (layer->type == CD_MCOL && mcn < MAX_MCOL) { mc= RE_vlakren_get_mcol(obr, vlr, mcn++, &name, 1); mcol= (MCol*)layer->data; - for(vindex=0; vindex<nr_verts; vindex++) + for (vindex=0; vindex<nr_verts; vindex++) mc[vindex]=mcol[a*4+rev_tab[vindex]]; } else if (layer->type == CD_TANGENT && mtng < 1) { if (need_nmap_tangent != 0) { const float * tangent = (const float *) layer->data; float * ftang = RE_vlakren_get_nmap_tangent(obr, vlr, 1); - for(vindex=0; vindex<nr_verts; vindex++) + for (vindex=0; vindex<nr_verts; vindex++) { copy_v4_v4(ftang+vindex*4, tangent+a*16+rev_tab[vindex]*4); mul_mat3_m4_v3(mat, ftang+vindex*4); @@ -3498,7 +3504,7 @@ static void init_render_mesh(Render *re, ObjectRen *obr, int timeoffset) end= dm->getNumEdges(dm); mvert= dm->getVertArray(dm); ma= give_render_material(re, ob, 1); - if(end && (ma->material_type == MA_TYPE_WIRE)) { + if (end && (ma->material_type == MA_TYPE_WIRE)) { MEdge *medge; struct edgesort *edgetable; int totedge= 0; @@ -3509,7 +3515,7 @@ static void init_render_mesh(Render *re, ObjectRen *obr, int timeoffset) /* we want edges to have UV and vcol too... */ edgetable= make_mesh_edge_lookup(dm, &totedge); - for(a1=0; a1<end; a1++, medge++) { + for (a1=0; a1<end; a1++, medge++) { if (medge->flag&ME_EDGERENDER) { MVert *v0 = &mvert[medge->v1]; MVert *v1 = &mvert[medge->v2]; @@ -3520,7 +3526,7 @@ static void init_render_mesh(Render *re, ObjectRen *obr, int timeoffset) vlr->v3= vlr->v2; vlr->v4= NULL; - if(edgetable) + if (edgetable) use_mesh_edge_lookup(obr, dm, medge, vlr, edgetable, totedge); xn= -(v0->no[0]+v1->no[0]); @@ -3537,31 +3543,31 @@ static void init_render_mesh(Render *re, ObjectRen *obr, int timeoffset) vlr->ec= ME_V1V2; } } - if(edgetable) + if (edgetable) MEM_freeN(edgetable); } } } - if(!timeoffset) { - if(need_stress) + if (!timeoffset) { + if (need_stress) calc_edge_stress(re, obr, me); if (test_for_displace(re, ob ) ) { recalc_normals= 1; calc_vertexnormals(re, obr, 0, 0); - if(do_autosmooth) + if (do_autosmooth) do_displacement(re, obr, mat, imat); else do_displacement(re, obr, NULL, NULL); } - if(do_autosmooth) { + if (do_autosmooth) { recalc_normals= 1; autosmooth(re, obr, mat, me->smoothresh); } - if(recalc_normals!=0 || need_tangent!=0) + if (recalc_normals!=0 || need_tangent!=0) calc_vertexnormals(re, obr, need_tangent, need_nmap_tangent); } @@ -3583,15 +3589,15 @@ static void initshadowbuf(Render *re, LampRen *lar, float mat[][4]) shb= (struct ShadBuf *)MEM_callocN( sizeof(struct ShadBuf),"initshadbuf"); lar->shb= shb; - if(shb==NULL) return; + if (shb==NULL) return; VECCOPY(shb->co, lar->co); /* int copy */ /* percentage render: keep track of min and max */ shb->size= (lar->bufsize*re->r.size)/100; - if(shb->size<512) shb->size= 512; - else if(shb->size > lar->bufsize) shb->size= lar->bufsize; + if (shb->size<512) shb->size= 512; + else if (shb->size > lar->bufsize) shb->size= lar->bufsize; shb->size &= ~15; /* make sure its multiples of 16 */ @@ -3616,7 +3622,7 @@ static void initshadowbuf(Render *re, LampRen *lar, float mat[][4]) shb->bias= (0.02f*lar->bias)*0x7FFFFFFF; /* halfway method (average of first and 2nd z) reduces bias issues */ - if(ELEM(lar->buftype, LA_SHADBUF_HALFWAY, LA_SHADBUF_DEEP)) + if (ELEM(lar->buftype, LA_SHADBUF_HALFWAY, LA_SHADBUF_DEEP)) shb->bias= 0.1f*shb->bias; shb->compressthresh= lar->compressthresh; @@ -3665,11 +3671,11 @@ static GroupObject *add_render_lamp(Render *re, Object *ob) int c; /* previewrender sets this to zero... prevent accidents */ - if(la==NULL) return NULL; + if (la==NULL) return NULL; /* prevent only shadow from rendering light */ - if(la->mode & LA_ONLYSHADOW) - if((re->r.mode & R_SHADOW)==0) + if (la->mode & LA_ONLYSHADOW) + if ((re->r.mode & R_SHADOW)==0) return NULL; re->totlamp++; @@ -3692,7 +3698,7 @@ static GroupObject *add_render_lamp(Render *re, Object *ob) lar->bufsize = la->bufsize; lar->samp = la->samp; lar->buffers= la->buffers; - if(lar->buffers==0) lar->buffers= 1; + if (lar->buffers==0) lar->buffers= 1; lar->buftype= la->buftype; lar->filtertype= la->filtertype; lar->soft = la->soft; @@ -3707,7 +3713,7 @@ static GroupObject *add_render_lamp(Render *re, Object *ob) lar->mode= la->mode; lar->energy= la->energy; - if(la->mode & LA_NEG) lar->energy= -lar->energy; + if (la->mode & LA_NEG) lar->energy= -lar->energy; lar->vec[0]= -mat[2][0]; lar->vec[1]= -mat[2][1]; @@ -3740,7 +3746,7 @@ static GroupObject *add_render_lamp(Render *re, Object *ob) /* Annoying, lamp UI does this, but the UI might not have been used? - add here too. * make sure this matches buttons_shading.c's logic */ - if(ELEM4(la->type, LA_AREA, LA_SPOT, LA_SUN, LA_LOCAL) && (la->mode & LA_SHAD_RAY)) + if (ELEM4(la->type, LA_AREA, LA_SPOT, LA_SUN, LA_LOCAL) && (la->mode & LA_SHAD_RAY)) if (ELEM3(la->type, LA_SPOT, LA_SUN, LA_LOCAL)) if (la->ray_samp_method == LA_SAMP_CONSTANT) la->ray_samp_method = LA_SAMP_HALTON; @@ -3750,12 +3756,12 @@ static GroupObject *add_render_lamp(Render *re, Object *ob) lar->adapt_thresh= la->adapt_thresh; lar->sunsky = NULL; - if( ELEM(lar->type, LA_SPOT, LA_LOCAL)) { + if ( ELEM(lar->type, LA_SPOT, LA_LOCAL)) { lar->ray_totsamp= lar->ray_samp*lar->ray_samp; lar->area_shape = LA_AREA_SQUARE; lar->area_sizey= lar->area_size; } - else if(lar->type==LA_AREA) { + else if (lar->type==LA_AREA) { switch(lar->area_shape) { case LA_AREA_SQUARE: lar->ray_totsamp= lar->ray_samp*lar->ray_samp; @@ -3780,13 +3786,13 @@ static GroupObject *add_render_lamp(Render *re, Object *ob) area_lamp_vectors(lar); init_jitter_plane(lar); // subsamples } - else if(lar->type==LA_SUN){ + else if (lar->type==LA_SUN) { lar->ray_totsamp= lar->ray_samp*lar->ray_samp; lar->area_shape = LA_AREA_SQUARE; lar->area_sizey= lar->area_size; - if((la->sun_effect_type & LA_SUN_EFFECT_SKY) || - (la->sun_effect_type & LA_SUN_EFFECT_AP)){ + if ((la->sun_effect_type & LA_SUN_EFFECT_SKY) || + (la->sun_effect_type & LA_SUN_EFFECT_AP)) { lar->sunsky = (struct SunSky*)MEM_callocN(sizeof(struct SunSky), "sunskyren"); lar->sunsky->effect_type = la->sun_effect_type; @@ -3804,8 +3810,8 @@ static GroupObject *add_render_lamp(Render *re, Object *ob) else lar->ray_totsamp= 0; lar->spotsi= la->spotsize; - if(lar->mode & LA_HALO) { - if(lar->spotsi>170.0f) lar->spotsi= 170.0f; + if (lar->mode & LA_HALO) { + if (lar->spotsi>170.0f) lar->spotsi= 170.0f; } lar->spotsi= cosf( (float)M_PI*lar->spotsi/360.0f ); lar->spotbl= (1.0f-lar->spotsi)*la->spotblend; @@ -3819,7 +3825,7 @@ static GroupObject *add_render_lamp(Render *re, Object *ob) lar->ld2= la->att2; lar->curfalloff = curvemapping_copy(la->curfalloff); - if(lar->type==LA_SPOT) { + if (lar->type==LA_SPOT) { normalize_v3(lar->imat[0]); normalize_v3(lar->imat[1]); @@ -3829,15 +3835,15 @@ static GroupObject *add_render_lamp(Render *re, Object *ob) xn= sin(xn)/cos(xn); lar->spottexfac= 1.0f/(xn); - if(lar->mode & LA_ONLYSHADOW) { - if((lar->mode & (LA_SHAD_BUF|LA_SHAD_RAY))==0) lar->mode -= LA_ONLYSHADOW; + if (lar->mode & LA_ONLYSHADOW) { + if ((lar->mode & (LA_SHAD_BUF|LA_SHAD_RAY))==0) lar->mode -= LA_ONLYSHADOW; } } /* set flag for spothalo en initvars */ - if(la->type==LA_SPOT && (la->mode & LA_HALO) && (la->buftype != LA_SHADBUF_DEEP)) { - if(la->haint>0.0f) { + if (la->type==LA_SPOT && (la->mode & LA_HALO) && (la->buftype != LA_SHADBUF_DEEP)) { + if (la->haint>0.0f) { re->flag |= R_LAMPHALO; /* camera position (0,0,0) rotate around lamp */ @@ -3855,25 +3861,25 @@ static GroupObject *add_render_lamp(Render *re, Object *ob) lar->sh_invcampos[2]*= lar->sh_zfac; /* halfway shadow buffer doesn't work for volumetric effects */ - if(lar->buftype == LA_SHADBUF_HALFWAY) + if (lar->buftype == LA_SHADBUF_HALFWAY) lar->buftype = LA_SHADBUF_REGULAR; } } - else if(la->type==LA_HEMI) { + else if (la->type==LA_HEMI) { lar->mode &= ~(LA_SHAD_RAY|LA_SHAD_BUF); } - for(c=0; c<MAX_MTEX; c++) { - if(la->mtex[c] && la->mtex[c]->tex) { + for (c=0; c<MAX_MTEX; c++) { + if (la->mtex[c] && la->mtex[c]->tex) { if (la->mtex[c]->mapto & LAMAP_COL) lar->mode |= LA_TEXTURE; if (la->mtex[c]->mapto & LAMAP_SHAD) lar->mode |= LA_SHAD_TEX; - if(G.rendering) { - if(re->osa) { - if(la->mtex[c]->tex->type==TEX_IMAGE) lar->mode |= LA_OSATEX; + if (G.rendering) { + if (re->osa) { + if (la->mtex[c]->tex->type==TEX_IMAGE) lar->mode |= LA_OSATEX; } } } @@ -3882,15 +3888,15 @@ static GroupObject *add_render_lamp(Render *re, Object *ob) /* old code checked for internal render (aka not yafray) */ { /* to make sure we can check ray shadow easily in the render code */ - if(lar->mode & LA_SHAD_RAY) { - if( (re->r.mode & R_RAYTRACE)==0) + if (lar->mode & LA_SHAD_RAY) { + if ( (re->r.mode & R_RAYTRACE)==0) lar->mode &= ~LA_SHAD_RAY; } - if(re->r.mode & R_SHADOW) { + if (re->r.mode & R_SHADOW) { - if(la->type==LA_AREA && (lar->mode & LA_SHAD_RAY) && (lar->ray_samp_method == LA_SAMP_CONSTANT)) { + if (la->type==LA_AREA && (lar->mode & LA_SHAD_RAY) && (lar->ray_samp_method == LA_SAMP_CONSTANT)) { init_jitter_plane(lar); } else if (la->type==LA_SPOT && (lar->mode & LA_SHAD_BUF) ) { @@ -3902,7 +3908,7 @@ static GroupObject *add_render_lamp(Render *re, Object *ob) /* this is the way used all over to check for shadow */ - if(lar->shb || (lar->mode & LA_SHAD_RAY)) { + if (lar->shb || (lar->mode & LA_SHAD_RAY)) { LampShadowSample *ls; LampShadowSubSample *lss; int a, b; @@ -3913,9 +3919,9 @@ static GroupObject *add_render_lamp(Render *re, Object *ob) ls= lar->shadsamp; /* shadfacs actually mean light, let's put them to 1 to prevent unitialized accidents */ - for(a=0; a<re->r.threads; a++, ls++) { + for (a=0; a<re->r.threads; a++, ls++) { lss= ls->s; - for(b=0; b<re->r.osa; b++, lss++) { + for (b=0; b<re->r.osa; b++, lss++) { lss->samplenr= -1; /* used to detect whether we store or read */ lss->shadfac[0]= 1.0f; lss->shadfac[1]= 1.0f; @@ -3939,20 +3945,20 @@ static void add_lightgroup(Render *re, Group *group, int exclusive) /* it's a bit too many loops in loops... but will survive */ /* note that 'exclusive' will remove it from the global list */ - for(go= group->gobject.first; go; go= go->next) { + for (go= group->gobject.first; go; go= go->next) { go->lampren= NULL; - if(go->ob->lay & re->lay) { - if(go->ob && go->ob->type==OB_LAMP) { - for(gol= re->lights.first; gol; gol= gol->next) { - if(gol->ob==go->ob) { + if (go->ob->lay & re->lay) { + if (go->ob && go->ob->type==OB_LAMP) { + for (gol= re->lights.first; gol; gol= gol->next) { + if (gol->ob==go->ob) { go->lampren= gol->lampren; break; } } - if(go->lampren==NULL) + if (go->lampren==NULL) gol= add_render_lamp(re, go->ob); - if(gol && exclusive) { + if (gol && exclusive) { BLI_remlink(&re->lights, gol); MEM_freeN(gol); } @@ -3967,16 +3973,16 @@ static void set_material_lightgroups(Render *re) Material *ma; /* not for preview render */ - if(re->scene->r.scemode & R_PREVIEWBUTS) + if (re->scene->r.scemode & R_PREVIEWBUTS) return; - for(group= re->main->group.first; group; group=group->id.next) + for (group= re->main->group.first; group; group=group->id.next) group->id.flag |= LIB_DOIT; /* it's a bit too many loops in loops... but will survive */ /* hola! materials not in use...? */ - for(ma= re->main->mat.first; ma; ma=ma->id.next) { - if(ma->group && (ma->group->id.flag & LIB_DOIT)) + for (ma= re->main->mat.first; ma; ma=ma->id.next) { + if (ma->group && (ma->group->id.flag & LIB_DOIT)) add_lightgroup(re, ma->group, ma->mode & MA_GROUP_NOLAY); } } @@ -3985,8 +3991,8 @@ static void set_renderlayer_lightgroups(Render *re, Scene *sce) { SceneRenderLayer *srl; - for(srl= sce->r.layers.first; srl; srl= srl->next) { - if(srl->light_override) + for (srl= sce->r.layers.first; srl; srl= srl->next) { + if (srl->light_override) add_lightgroup(re, srl->light_override, 0); } } @@ -4000,7 +4006,7 @@ void init_render_world(Render *re) int a; char *cp; - if(re->scene && re->scene->world) { + if (re->scene && re->scene->world) { re->wrld= *(re->scene->world); cp= (char *)&re->wrld.fastcol; @@ -4014,14 +4020,14 @@ void init_render_world(Render *re) normalize_v3(re->grvec); copy_m3_m4(re->imat, re->viewinv); - for(a=0; a<MAX_MTEX; a++) - if(re->wrld.mtex[a] && re->wrld.mtex[a]->tex) re->wrld.skytype |= WO_SKYTEX; + for (a=0; a<MAX_MTEX; a++) + if (re->wrld.mtex[a] && re->wrld.mtex[a]->tex) re->wrld.skytype |= WO_SKYTEX; /* AO samples should be OSA minimum */ - if(re->osa) + if (re->osa) while(re->wrld.aosamp*re->wrld.aosamp < re->osa) re->wrld.aosamp++; - if(!(re->r.mode & R_RAYTRACE) && (re->wrld.ao_gather_method == WO_AOGATHER_RAYTRACE)) + if (!(re->r.mode & R_RAYTRACE) && (re->wrld.ao_gather_method == WO_AOGATHER_RAYTRACE)) re->wrld.mode &= ~(WO_AMB_OCC|WO_ENV_LIGHT|WO_INDIRECT_LIGHT); } else { @@ -4057,37 +4063,37 @@ static void set_phong_threshold(ObjectRen *obr) * are taken into account. This threshold is meant to work on smooth geometry, not / for extreme cases (ton) */ - for(i=0; i<obr->totvlak; i++) { + for (i=0; i<obr->totvlak; i++) { vlr= RE_findOrAddVlak(obr, i); - if(vlr->flag & R_SMOOTH) { + if (vlr->flag & R_SMOOTH) { dot= dot_v3v3(vlr->n, vlr->v1->n); dot= ABS(dot); - if(dot>0.9f) { + if (dot>0.9f) { thresh+= dot; tot++; } dot= dot_v3v3(vlr->n, vlr->v2->n); dot= ABS(dot); - if(dot>0.9f) { + if (dot>0.9f) { thresh+= dot; tot++; } dot= dot_v3v3(vlr->n, vlr->v3->n); dot= ABS(dot); - if(dot>0.9f) { + if (dot>0.9f) { thresh+= dot; tot++; } - if(vlr->v4) { + if (vlr->v4) { dot= dot_v3v3(vlr->n, vlr->v4->n); dot= ABS(dot); - if(dot>0.9f) { + if (dot>0.9f) { thresh+= dot; tot++; } } } } - if(tot) { + if (tot) { thresh/= (float)tot; obr->ob->smoothresh= cosf(0.5f*(float)M_PI-saacos(thresh)); } @@ -4103,21 +4109,21 @@ static void set_fullsample_trace_flag(Render *re, ObjectRen *obr) osa= re->osa; trace= re->r.mode & R_RAYTRACE; - for(a=obr->totvlak-1; a>=0; a--) { + for (a=obr->totvlak-1; a>=0; a--) { vlr= RE_findOrAddVlak(obr, a); mode= vlr->mat->mode; - if(trace && (mode & MA_TRACEBLE)) + if (trace && (mode & MA_TRACEBLE)) vlr->flag |= R_TRACEBLE; - if(osa) { - if(mode & MA_FULL_OSA) { + if (osa) { + if (mode & MA_FULL_OSA) { vlr->flag |= R_FULL_OSA; } - else if(trace) { - if(mode & MA_SHLESS); - else if(vlr->mat->material_type == MA_TYPE_VOLUME); - else if((mode & MA_RAYMIRROR) || ((mode & MA_TRANSP) && (mode & MA_RAYTRANSP))) { + else if (trace) { + if (mode & MA_SHLESS); + else if (vlr->mat->material_type == MA_TYPE_VOLUME); + else if ((mode & MA_RAYMIRROR) || ((mode & MA_TRANSP) && (mode & MA_RAYTRANSP))) { /* for blurry reflect/refract, better to take more samples * inside the raytrace than as OSA samples */ if ((vlr->mat->gloss_mir == 1.0f) && (vlr->mat->gloss_tra == 1.0f)) @@ -4136,18 +4142,18 @@ static void split_quads(ObjectRen *obr, int dir) VlakRen *vlr, *vlr1; int a; - for(a=obr->totvlak-1; a>=0; a--) { + for (a=obr->totvlak-1; a>=0; a--) { vlr= RE_findOrAddVlak(obr, a); /* test if rendering as a quad or triangle, skip wire */ - if(vlr->v4 && (vlr->flag & R_STRAND)==0 && (vlr->mat->material_type != MA_TYPE_WIRE)) { + if (vlr->v4 && (vlr->flag & R_STRAND)==0 && (vlr->mat->material_type != MA_TYPE_WIRE)) { - if(vlr->v4) { + if (vlr->v4) { vlr1= RE_vlakren_copy(obr, vlr); vlr1->flag |= R_FACE_SPLIT; - if( dir==2 ) vlr->flag |= R_DIVIDE_24; + if ( dir==2 ) vlr->flag |= R_DIVIDE_24; else vlr->flag &= ~R_DIVIDE_24; /* new vertex pointers */ @@ -4186,11 +4192,11 @@ static void check_non_flat_quads(ObjectRen *obr) float nor[3], xn, flen; int a; - for(a=obr->totvlak-1; a>=0; a--) { + for (a=obr->totvlak-1; a>=0; a--) { vlr= RE_findOrAddVlak(obr, a); /* test if rendering as a quad or triangle, skip wire */ - if(vlr->v4 && (vlr->flag & R_STRAND)==0 && (vlr->mat->material_type != MA_TYPE_WIRE)) { + if (vlr->v4 && (vlr->flag & R_STRAND)==0 && (vlr->mat->material_type != MA_TYPE_WIRE)) { /* check if quad is actually triangle */ v1= vlr->v1; @@ -4198,7 +4204,7 @@ static void check_non_flat_quads(ObjectRen *obr) v3= vlr->v3; v4= vlr->v4; sub_v3_v3v3(nor, v1->co, v2->co); - if( ABS(nor[0])<FLT_EPSILON10 && ABS(nor[1])<FLT_EPSILON10 && ABS(nor[2])<FLT_EPSILON10 ) { + if ( ABS(nor[0])<FLT_EPSILON10 && ABS(nor[1])<FLT_EPSILON10 && ABS(nor[2])<FLT_EPSILON10 ) { vlr->v1= v2; vlr->v2= v3; vlr->v3= v4; @@ -4206,26 +4212,26 @@ static void check_non_flat_quads(ObjectRen *obr) } else { sub_v3_v3v3(nor, v2->co, v3->co); - if( ABS(nor[0])<FLT_EPSILON10 && ABS(nor[1])<FLT_EPSILON10 && ABS(nor[2])<FLT_EPSILON10 ) { + if ( ABS(nor[0])<FLT_EPSILON10 && ABS(nor[1])<FLT_EPSILON10 && ABS(nor[2])<FLT_EPSILON10 ) { vlr->v2= v3; vlr->v3= v4; vlr->v4= NULL; } else { sub_v3_v3v3(nor, v3->co, v4->co); - if( ABS(nor[0])<FLT_EPSILON10 && ABS(nor[1])<FLT_EPSILON10 && ABS(nor[2])<FLT_EPSILON10 ) { + if ( ABS(nor[0])<FLT_EPSILON10 && ABS(nor[1])<FLT_EPSILON10 && ABS(nor[2])<FLT_EPSILON10 ) { vlr->v4= NULL; } else { sub_v3_v3v3(nor, v4->co, v1->co); - if( ABS(nor[0])<FLT_EPSILON10 && ABS(nor[1])<FLT_EPSILON10 && ABS(nor[2])<FLT_EPSILON10 ) { + if ( ABS(nor[0])<FLT_EPSILON10 && ABS(nor[1])<FLT_EPSILON10 && ABS(nor[2])<FLT_EPSILON10 ) { vlr->v4= NULL; } } } } - if(vlr->v4) { + if (vlr->v4) { /* Face is divided along edge with the least gradient */ /* Flagged with R_DIVIDE_24 if divide is from vert 2 to 4 */ @@ -4236,11 +4242,11 @@ static void check_non_flat_quads(ObjectRen *obr) /* render normals are inverted in render! we calculate normal of single tria here */ flen= normal_tri_v3( nor,vlr->v4->co, vlr->v3->co, vlr->v1->co); - if(flen==0.0f) normal_tri_v3( nor,vlr->v4->co, vlr->v2->co, vlr->v1->co); + if (flen==0.0f) normal_tri_v3( nor,vlr->v4->co, vlr->v2->co, vlr->v1->co); xn = dot_v3v3(nor, vlr->n); - if(ABS(xn) < 0.999995f ) { // checked on noisy fractal grid + if (ABS(xn) < 0.999995f ) { // checked on noisy fractal grid float d1, d2; @@ -4254,7 +4260,7 @@ static void check_non_flat_quads(ObjectRen *obr) normal_tri_v3( nor,vlr->v2->co, vlr->v3->co, vlr->v4->co); d2 = dot_v3v3(nor, vlr->v2->n); - if( fabs(d1) < fabs(d2) ) vlr->flag |= R_DIVIDE_24; + if ( fabs(d1) < fabs(d2) ) vlr->flag |= R_DIVIDE_24; else vlr->flag &= ~R_DIVIDE_24; /* new vertex pointers */ @@ -4296,25 +4302,26 @@ static void finalize_render_object(Render *re, ObjectRen *obr, int timeoffset) float min[3], max[3], smin[3], smax[3]; int a, b; - if(obr->totvert || obr->totvlak || obr->tothalo || obr->totstrand) { + if (obr->totvert || obr->totvlak || obr->tothalo || obr->totstrand) { /* the exception below is because displace code now is in init_render_mesh call, I will look at means to have autosmooth enabled for all object types and have it as general postprocess, like displace */ - if(ob->type!=OB_MESH && test_for_displace(re, ob)) + if (ob->type!=OB_MESH && test_for_displace(re, ob)) do_displacement(re, obr, NULL, NULL); - if(!timeoffset) { + if (!timeoffset) { /* phong normal interpolation can cause error in tracing * (terminator problem) */ ob->smoothresh= 0.0; - if((re->r.mode & R_RAYTRACE) && (re->r.mode & R_SHADOW)) + if ((re->r.mode & R_RAYTRACE) && (re->r.mode & R_SHADOW)) set_phong_threshold(obr); if (re->flag & R_BAKING && re->r.bake_quad_split != 0) { /* Baking lets us define a quad split order */ split_quads(obr, re->r.bake_quad_split); - } else { - if((re->r.mode & R_SIMPLIFY && re->r.simplify_flag & R_SIMPLE_NO_TRIANGULATE) == 0) + } + else { + if ((re->r.mode & R_SIMPLIFY && re->r.simplify_flag & R_SIMPLE_NO_TRIANGULATE) == 0) check_non_flat_quads(obr); } @@ -4322,29 +4329,29 @@ static void finalize_render_object(Render *re, ObjectRen *obr, int timeoffset) /* compute bounding boxes for clipping */ INIT_MINMAX(min, max); - for(a=0; a<obr->totvert; a++) { - if((a & 255)==0) ver= obr->vertnodes[a>>8].vert; + for (a=0; a<obr->totvert; a++) { + if ((a & 255)==0) ver= obr->vertnodes[a>>8].vert; else ver++; DO_MINMAX(ver->co, min, max); } - if(obr->strandbuf) { + if (obr->strandbuf) { float width; /* compute average bounding box of strandpoint itself (width) */ - if(obr->strandbuf->flag & R_STRAND_B_UNITS) + if (obr->strandbuf->flag & R_STRAND_B_UNITS) obr->strandbuf->maxwidth= MAX2(obr->strandbuf->ma->strand_sta, obr->strandbuf->ma->strand_end); else obr->strandbuf->maxwidth= 0.0f; width= obr->strandbuf->maxwidth; sbound= obr->strandbuf->bound; - for(b=0; b<obr->strandbuf->totbound; b++, sbound++) { + for (b=0; b<obr->strandbuf->totbound; b++, sbound++) { INIT_MINMAX(smin, smax); - for(a=sbound->start; a<sbound->end; a++) { + for (a=sbound->start; a<sbound->end; a++) { strand= RE_findOrAddStrand(obr, a); strand_minmax(strand, smin, smax, width); } @@ -4384,8 +4391,8 @@ static void find_dupli_instances(Render *re, ObjectRen *obr) /* for objects instanced by dupliverts/faces/particles, we go over the * list of instances to find ones that instance obr, and setup their * matrices and obr pointer */ - for(obi=re->instancetable.last; obi; obi=obi->prev) { - if(!obi->obr && obi->ob == obr->ob && obi->psysindex == obr->psysindex) { + for (obi=re->instancetable.last; obi; obi=obi->prev) { + if (!obi->obr && obi->ob == obr->ob && obi->psysindex == obr->psysindex) { obi->obr= obr; /* compute difference between object matrix and @@ -4397,7 +4404,7 @@ static void find_dupli_instances(Render *re, ObjectRen *obr) invert_m3_m3(obi->nmat, nmat); transpose_m3(obi->nmat); - if(!first) { + if (!first) { re->totvert += obr->totvert; re->totvlak += obr->totvlak; re->tothalo += obr->tothalo; @@ -4439,13 +4446,13 @@ static ObjectRen *find_dupligroup_dupli(Render *re, Object *ob, int psysindex) /* if the object is itself instanced, we don't want to create an instance * for it */ - if(ob->transflag & OB_RENDER_DUPLI) + if (ob->transflag & OB_RENDER_DUPLI) return NULL; /* try to find an object that was already created so we can reuse it * and save memory */ - for(obr=re->objecttable.first; obr; obr=obr->next) - if(obr->ob == ob && obr->psysindex == psysindex && (obr->flag & R_INSTANCEABLE)) + for (obr=re->objecttable.first; obr; obr=obr->next) + if (obr->ob == ob && obr->psysindex == psysindex && (obr->flag & R_INSTANCEABLE)) return obr; return NULL; @@ -4461,14 +4468,14 @@ static void set_dupli_tex_mat(Render *re, ObjectInstanceRen *obi, DupliObject *d static int needtexmat= 0; /* init */ - if(!re) { + if (!re) { lastob= NULL; needtexmat= 0; return; } /* check if we actually need it */ - if(lastob != dob->ob) { + if (lastob != dob->ob) { Material ***material; short a, *totmaterial; @@ -4478,13 +4485,13 @@ static void set_dupli_tex_mat(Render *re, ObjectInstanceRen *obi, DupliObject *d totmaterial= give_totcolp(dob->ob); material= give_matarar(dob->ob); - if(totmaterial && material) - for(a= 0; a<*totmaterial; a++) - if((*material)[a] && (*material)[a]->texco & TEXCO_OBJECT) + if (totmaterial && material) + for (a= 0; a<*totmaterial; a++) + if ((*material)[a] && (*material)[a]->texco & TEXCO_OBJECT) needtexmat= 1; } - if(needtexmat) { + if (needtexmat) { float imat[4][4]; obi->duplitexmat= BLI_memarena_alloc(re->memArena, sizeof(float)*4*4); @@ -4499,8 +4506,8 @@ static void init_render_object_data(Render *re, ObjectRen *obr, int timeoffset) ParticleSystem *psys; int i; - if(obr->psysindex) { - if((!obr->prev || obr->prev->ob != ob || (obr->prev->flag & R_INSTANCEABLE)==0) && ob->type==OB_MESH) { + if (obr->psysindex) { + if ((!obr->prev || obr->prev->ob != ob || (obr->prev->flag & R_INSTANCEABLE)==0) && ob->type==OB_MESH) { /* the emitter mesh wasn't rendered so the modifier stack wasn't * evaluated with render settings */ DerivedMesh *dm; @@ -4508,7 +4515,7 @@ static void init_render_object_data(Render *re, ObjectRen *obr, int timeoffset) dm->release(dm); } - for(psys=ob->particlesystem.first, i=0; i<obr->psysindex-1; i++) + for (psys=ob->particlesystem.first, i=0; i<obr->psysindex-1; i++) psys= psys->next; render_new_particle_system(re, obr, psys, timeoffset); @@ -4516,11 +4523,11 @@ static void init_render_object_data(Render *re, ObjectRen *obr, int timeoffset) else { if ELEM(ob->type, OB_FONT, OB_CURVE) init_render_curve(re, obr, timeoffset); - else if(ob->type==OB_SURF) + else if (ob->type==OB_SURF) init_render_surf(re, obr, timeoffset); - else if(ob->type==OB_MESH) + else if (ob->type==OB_MESH) init_render_mesh(re, obr, timeoffset); - else if(ob->type==OB_MBALL) + else if (ob->type==OB_MBALL) init_render_mball(re, obr); } @@ -4543,31 +4550,31 @@ static void add_render_object(Render *re, Object *ob, Object *par, DupliObject * /* the emitter has to be processed first (render levels of modifiers) */ /* so here we only check if the emitter should be rendered */ - if(ob->particlesystem.first) { + if (ob->particlesystem.first) { show_emitter= 0; - for(psys=ob->particlesystem.first; psys; psys=psys->next) { + for (psys=ob->particlesystem.first; psys; psys=psys->next) { show_emitter += psys->part->draw & PART_DRAW_EMITTER; psys_render_set(ob, psys, re->viewmat, re->winmat, re->winx, re->winy, timeoffset); } /* if no psys has "show emitter" selected don't render emitter */ - if(show_emitter == 0) + if (show_emitter == 0) allow_render= 0; } /* one render object for the data itself */ - if(allow_render) { + if (allow_render) { obr= RE_addRenderObject(re, ob, par, index, 0, ob->lay); - if((dob && !dob->animated) || (ob->transflag & OB_RENDER_DUPLI)) { + if ((dob && !dob->animated) || (ob->transflag & OB_RENDER_DUPLI)) { obr->flag |= R_INSTANCEABLE; copy_m4_m4(obr->obmat, ob->obmat); } init_render_object_data(re, obr, timeoffset); /* only add instance for objects that have not been used for dupli */ - if(!(ob->transflag & OB_RENDER_DUPLI)) { + if (!(ob->transflag & OB_RENDER_DUPLI)) { obi= RE_addRenderInstance(re, obr, ob, par, index, 0, NULL, ob->lay); - if(dob) set_dupli_tex_mat(re, obi, dob); + if (dob) set_dupli_tex_mat(re, obi, dob); } else find_dupli_instances(re, obr); @@ -4580,24 +4587,24 @@ static void add_render_object(Render *re, Object *ob, Object *par, DupliObject * } /* and one render object per particle system */ - if(ob->particlesystem.first) { + if (ob->particlesystem.first) { psysindex= 1; - for(psys=ob->particlesystem.first; psys; psys=psys->next, psysindex++) { + for (psys=ob->particlesystem.first; psys; psys=psys->next, psysindex++) { obr= RE_addRenderObject(re, ob, par, index, psysindex, ob->lay); - if((dob && !dob->animated) || (ob->transflag & OB_RENDER_DUPLI)) { + if ((dob && !dob->animated) || (ob->transflag & OB_RENDER_DUPLI)) { obr->flag |= R_INSTANCEABLE; copy_m4_m4(obr->obmat, ob->obmat); } - if(dob) + if (dob) psys->flag |= PSYS_USE_IMAT; init_render_object_data(re, obr, timeoffset); psys_render_restore(ob, psys); psys->flag &= ~PSYS_USE_IMAT; /* only add instance for objects that have not been used for dupli */ - if(!(ob->transflag & OB_RENDER_DUPLI)) { + if (!(ob->transflag & OB_RENDER_DUPLI)) { obi= RE_addRenderInstance(re, obr, ob, par, index, psysindex, NULL, ob->lay); - if(dob) set_dupli_tex_mat(re, obi, dob); + if (dob) set_dupli_tex_mat(re, obi, dob); } else find_dupli_instances(re, obr); @@ -4613,9 +4620,9 @@ static void init_render_object(Render *re, Object *ob, Object *par, DupliObject double time; float mat[4][4]; - if(ob->type==OB_LAMP) + if (ob->type==OB_LAMP) add_render_lamp(re, ob); - else if(render_object_type(ob->type)) + else if (render_object_type(ob->type)) add_render_object(re, ob, par, dob, timeoffset); else { mult_m4_m4m4(mat, re->viewmat, ob->obmat); @@ -4623,7 +4630,7 @@ static void init_render_object(Render *re, Object *ob, Object *par, DupliObject } time= PIL_check_seconds_timer(); - if(time - lasttime > 1.0) { + if (time - lasttime > 1.0) { lasttime= time; /* clumsy copying still */ re->i.totvert= re->totvert; @@ -4642,8 +4649,8 @@ void RE_Database_Free(Render *re) LampRen *lar; /* statistics for debugging render memory usage */ - if((G.f & G_DEBUG) && (G.rendering)) { - if((re->r.scemode & R_PREVIEWBUTS)==0) { + if ((G.f & G_DEBUG) && (G.rendering)) { + if ((re->r.scemode & R_PREVIEWBUTS)==0) { BKE_image_print_memlist(); MEM_printmemlist_stats(); } @@ -4651,11 +4658,11 @@ void RE_Database_Free(Render *re) /* FREE */ - for(lar= re->lampren.first; lar; lar= lar->next) { + for (lar= re->lampren.first; lar; lar= lar->next) { freeshadowbuf(lar); - if(lar->jitter) MEM_freeN(lar->jitter); - if(lar->shadsamp) MEM_freeN(lar->shadsamp); - if(lar->sunsky) MEM_freeN(lar->sunsky); + if (lar->jitter) MEM_freeN(lar->jitter); + if (lar->shadsamp) MEM_freeN(lar->shadsamp); + if (lar->sunsky) MEM_freeN(lar->sunsky); curvemapping_free(lar->curfalloff); } @@ -4678,20 +4685,20 @@ void RE_Database_Free(Render *re) free_camera_inside_volumes(re); - if(re->wrld.aosphere) { + if (re->wrld.aosphere) { MEM_freeN(re->wrld.aosphere); re->wrld.aosphere= NULL; re->scene->world->aosphere= NULL; } - if(re->wrld.aotables) { + if (re->wrld.aotables) { MEM_freeN(re->wrld.aotables); re->wrld.aotables= NULL; re->scene->world->aotables= NULL; } - if(re->r.mode & R_RAYTRACE) + if (re->r.mode & R_RAYTRACE) free_render_qmcsampler(re); - if(re->r.mode & R_RAYTRACE) freeraytree(re); + if (re->r.mode & R_RAYTRACE) freeraytree(re); free_sss(re); free_occ(re); @@ -4702,12 +4709,12 @@ void RE_Database_Free(Render *re) re->bakebuf= NULL; - if(re->scene) - if(re->scene->r.scemode & R_FREE_IMAGE) - if((re->r.scemode & R_PREVIEWBUTS)==0) + if (re->scene) + if (re->scene->r.scemode & R_FREE_IMAGE) + if ((re->r.scemode & R_PREVIEWBUTS)==0) BKE_image_free_all_textures(); - if(re->memArena) { + if (re->memArena) { BLI_memarena_free(re->memArena); re->memArena = NULL; } @@ -4716,19 +4723,19 @@ void RE_Database_Free(Render *re) static int allow_render_object(Render *re, Object *ob, int nolamps, int onlyselected, Object *actob) { /* override not showing object when duplis are used with particles */ - if(ob->transflag & OB_DUPLIPARTS) + if (ob->transflag & OB_DUPLIPARTS) ; /* let particle system(s) handle showing vs. not showing */ - else if((ob->transflag & OB_DUPLI) && !(ob->transflag & OB_DUPLIFRAMES)) + else if ((ob->transflag & OB_DUPLI) && !(ob->transflag & OB_DUPLIFRAMES)) return 0; /* don't add non-basic meta objects, ends up having renderobjects with no geometry */ if (ob->type == OB_MBALL && ob!=find_basis_mball(re->scene, ob)) return 0; - if(nolamps && (ob->type==OB_LAMP)) + if (nolamps && (ob->type==OB_LAMP)) return 0; - if(onlyselected && (ob!=actob && !(ob->flag & SELECT))) + if (onlyselected && (ob!=actob && !(ob->flag & SELECT))) return 0; return 1; @@ -4744,16 +4751,16 @@ static int allow_render_dupli_instance(Render *UNUSED(re), DupliObject *dob, Obj * all halo's to sort them globally in advance */ totmaterial= give_totcolp(obd); - if(totmaterial) { - for(a= 0; a<*totmaterial; a++) { + if (totmaterial) { + for (a= 0; a<*totmaterial; a++) { ma= give_current_material(obd, a); - if(ma && (ma->material_type == MA_TYPE_HALO)) + if (ma && (ma->material_type == MA_TYPE_HALO)) return 0; } } - for(psys=obd->particlesystem.first; psys; psys=psys->next) - if(!ELEM5(psys->part->ren_as, PART_DRAW_BB, PART_DRAW_LINE, PART_DRAW_PATH, PART_DRAW_OB, PART_DRAW_GR)) + for (psys=obd->particlesystem.first; psys; psys=psys->next) + if (!ELEM5(psys->part->ren_as, PART_DRAW_BB, PART_DRAW_LINE, PART_DRAW_PATH, PART_DRAW_OB, PART_DRAW_GR)) return 0; /* don't allow lamp, animated duplis, or radio render */ @@ -4770,35 +4777,35 @@ static void dupli_render_particle_set(Render *re, Object *ob, int timeoffset, in ParticleSystem *psys; DerivedMesh *dm; - if(level >= MAX_DUPLI_RECUR) + if (level >= MAX_DUPLI_RECUR) return; - if(ob->transflag & OB_DUPLIPARTS) { - for(psys=ob->particlesystem.first; psys; psys=psys->next) { - if(ELEM(psys->part->ren_as, PART_DRAW_OB, PART_DRAW_GR)) { - if(enable) + if (ob->transflag & OB_DUPLIPARTS) { + for (psys=ob->particlesystem.first; psys; psys=psys->next) { + if (ELEM(psys->part->ren_as, PART_DRAW_OB, PART_DRAW_GR)) { + if (enable) psys_render_set(ob, psys, re->viewmat, re->winmat, re->winx, re->winy, timeoffset); else psys_render_restore(ob, psys); } } - if(enable) { + if (enable) { /* this is to make sure we get render level duplis in groups: * the derivedmesh must be created before init_render_mesh, * since object_duplilist does dupliparticles before that */ dm = mesh_create_derived_render(re->scene, ob, CD_MASK_BAREMESH|CD_MASK_MTFACE|CD_MASK_MCOL); dm->release(dm); - for(psys=ob->particlesystem.first; psys; psys=psys->next) + for (psys=ob->particlesystem.first; psys; psys=psys->next) psys_get_modifier(ob, psys)->flag &= ~eParticleSystemFlag_psys_updated; } } - if(ob->dup_group==NULL) return; + if (ob->dup_group==NULL) return; group= ob->dup_group; - for(go= group->gobject.first; go; go= go->next) + for (go= group->gobject.first; go; go= go->next) dupli_render_particle_set(re, go->ob, timeoffset, level+1, enable); } @@ -4807,8 +4814,8 @@ static int get_vector_renderlayers(Scene *sce) SceneRenderLayer *srl; unsigned int lay= 0; - for(srl= sce->r.layers.first; srl; srl= srl->next) - if(srl->passflag & SCE_PASS_VECTOR) + for (srl= sce->r.layers.first; srl; srl= srl->next) + if (srl->passflag & SCE_PASS_VECTOR) lay |= srl->lay; return lay; @@ -4820,20 +4827,20 @@ static void add_group_render_dupli_obs(Render *re, Group *group, int nolamps, in Object *ob; /* simple preventing of too deep nested groups */ - if(level>MAX_DUPLI_RECUR) return; + if (level>MAX_DUPLI_RECUR) return; /* recursively go into dupligroups to find objects with OB_RENDER_DUPLI * that were not created yet */ - for(go= group->gobject.first; go; go= go->next) { + for (go= group->gobject.first; go; go= go->next) { ob= go->ob; - if(ob->flag & OB_DONE) { - if(ob->transflag & OB_RENDER_DUPLI) { - if(allow_render_object(re, ob, nolamps, onlyselected, actob)) { + if (ob->flag & OB_DONE) { + if (ob->transflag & OB_RENDER_DUPLI) { + if (allow_render_object(re, ob, nolamps, onlyselected, actob)) { init_render_object(re, ob, NULL, 0, timeoffset); ob->transflag &= ~OB_RENDER_DUPLI; - if(ob->dup_group) + if (ob->dup_group) add_group_render_dupli_obs(re, ob->dup_group, nolamps, onlyselected, actob, timeoffset, level+1); } } @@ -4862,7 +4869,7 @@ static void database_init_objects(Render *re, unsigned int renderlay, int nolamp * mtex's for mapto objects but its easier just to set the * 'imat' / 'imat_ren' on all and unlikely to be a performance hit * See bug: [#28744] - campbell */ - for(ob= re->main->object.first; ob; ob= ob->id.next) { + for (ob= re->main->object.first; ob; ob= ob->id.next) { /* imat objects has to be done here, since displace can have texture using Object map-input */ mult_m4_m4m4(mat, re->viewmat, ob->obmat); invert_m4_m4(ob->imat_ren, mat); @@ -4872,7 +4879,7 @@ static void database_init_objects(Render *re, unsigned int renderlay, int nolamp ob->transflag &= ~OB_RENDER_DUPLI; } - for(SETLOOPER(re->scene, sce_iter, base)) { + for (SETLOOPER(re->scene, sce_iter, base)) { ob= base->object; /* in the prev/next pass for making speed vectors, avoid creating @@ -4882,21 +4889,21 @@ static void database_init_objects(Render *re, unsigned int renderlay, int nolamp lay= (timeoffset)? renderlay & vectorlay: renderlay; /* if the object has been restricted from rendering in the outliner, ignore it */ - if(ob->restrictflag & OB_RESTRICT_RENDER) continue; + if (ob->restrictflag & OB_RESTRICT_RENDER) continue; /* OB_DONE means the object itself got duplicated, so was already converted */ - if(ob->flag & OB_DONE) { + if (ob->flag & OB_DONE) { /* OB_RENDER_DUPLI means instances for it were already created, now * it still needs to create the ObjectRen containing the data */ - if(ob->transflag & OB_RENDER_DUPLI) { - if(allow_render_object(re, ob, nolamps, onlyselected, actob)) { + if (ob->transflag & OB_RENDER_DUPLI) { + if (allow_render_object(re, ob, nolamps, onlyselected, actob)) { init_render_object(re, ob, NULL, 0, timeoffset); ob->transflag &= ~OB_RENDER_DUPLI; } } } - else if((base->lay & lay) || (ob->type==OB_LAMP && (base->lay & re->lay)) ) { - if((ob->transflag & OB_DUPLI) && (ob->type!=OB_MBALL)) { + else if ((base->lay & lay) || (ob->type==OB_LAMP && (base->lay & re->lay)) ) { + if ((ob->transflag & OB_DUPLI) && (ob->type!=OB_MBALL)) { DupliObject *dob; ListBase *lb; @@ -4906,25 +4913,25 @@ static void database_init_objects(Render *re, unsigned int renderlay, int nolamp lb= object_duplilist(re->scene, ob); dupli_render_particle_set(re, ob, timeoffset, 0, 0); - for(dob= lb->first; dob; dob= dob->next) { + for (dob= lb->first; dob; dob= dob->next) { Object *obd= dob->ob; copy_m4_m4(obd->obmat, dob->mat); /* group duplis need to set ob matrices correct, for deform. so no_draw is part handled */ - if(!(obd->transflag & OB_RENDER_DUPLI) && dob->no_draw) + if (!(obd->transflag & OB_RENDER_DUPLI) && dob->no_draw) continue; - if(obd->restrictflag & OB_RESTRICT_RENDER) + if (obd->restrictflag & OB_RESTRICT_RENDER) continue; - if(obd->type==OB_MBALL) + if (obd->type==OB_MBALL) continue; - if(!allow_render_object(re, obd, nolamps, onlyselected, actob)) + if (!allow_render_object(re, obd, nolamps, onlyselected, actob)) continue; - if(allow_render_dupli_instance(re, dob, obd)) { + if (allow_render_dupli_instance(re, dob, obd)) { ParticleSystem *psys; ObjectRen *obr = NULL; int psysindex; @@ -4935,13 +4942,13 @@ static void database_init_objects(Render *re, unsigned int renderlay, int nolamp /* instances instead of the actual object are added in two cases, either * this is a duplivert/face/particle, or it is a non-animated object in * a dupligroup that has already been created before */ - if(dob->type != OB_DUPLIGROUP || (obr=find_dupligroup_dupli(re, obd, 0))) { + if (dob->type != OB_DUPLIGROUP || (obr=find_dupligroup_dupli(re, obd, 0))) { mult_m4_m4m4(mat, re->viewmat, dob->mat); obi= RE_addRenderInstance(re, NULL, obd, ob, dob->index, 0, mat, obd->lay); /* fill in instance variables for texturing */ set_dupli_tex_mat(re, obi, dob); - if(dob->type != OB_DUPLIGROUP) { + if (dob->type != OB_DUPLIGROUP) { copy_v3_v3(obi->dupliorco, dob->orco); obi->dupliuv[0]= dob->uv[0]; obi->dupliuv[1]= dob->uv[1]; @@ -4952,7 +4959,7 @@ static void database_init_objects(Render *re, unsigned int renderlay, int nolamp * itself was duplicated. for the first case find_dupli_instances * will be called later. */ assign_dupligroup_dupli(re, obi, obr); - if(obd->transflag & OB_RENDER_DUPLI) + if (obd->transflag & OB_RENDER_DUPLI) find_dupli_instances(re, obr); } } @@ -4960,31 +4967,31 @@ static void database_init_objects(Render *re, unsigned int renderlay, int nolamp /* same logic for particles, each particle system has it's own object, so * need to go over them separately */ psysindex= 1; - for(psys=obd->particlesystem.first; psys; psys=psys->next) { - if(dob->type != OB_DUPLIGROUP || (obr=find_dupligroup_dupli(re, obd, psysindex))) { - if(obi == NULL) + for (psys=obd->particlesystem.first; psys; psys=psys->next) { + if (dob->type != OB_DUPLIGROUP || (obr=find_dupligroup_dupli(re, obd, psysindex))) { + if (obi == NULL) mult_m4_m4m4(mat, re->viewmat, dob->mat); obi= RE_addRenderInstance(re, NULL, obd, ob, dob->index, psysindex++, mat, obd->lay); set_dupli_tex_mat(re, obi, dob); - if(dob->type != OB_DUPLIGROUP) { + if (dob->type != OB_DUPLIGROUP) { copy_v3_v3(obi->dupliorco, dob->orco); obi->dupliuv[0]= dob->uv[0]; obi->dupliuv[1]= dob->uv[1]; } else { assign_dupligroup_dupli(re, obi, obr); - if(obd->transflag & OB_RENDER_DUPLI) + if (obd->transflag & OB_RENDER_DUPLI) find_dupli_instances(re, obr); } } } - if(obi==NULL) + if (obi==NULL) /* can't instance, just create the object */ init_render_object(re, obd, ob, dob, timeoffset); - if(dob->type != OB_DUPLIGROUP) { + if (dob->type != OB_DUPLIGROUP) { obd->flag |= OB_DONE; obd->transflag |= OB_RENDER_DUPLI; } @@ -4992,26 +4999,26 @@ static void database_init_objects(Render *re, unsigned int renderlay, int nolamp else init_render_object(re, obd, ob, dob, timeoffset); - if(re->test_break(re->tbh)) break; + if (re->test_break(re->tbh)) break; } free_object_duplilist(lb); - if(allow_render_object(re, ob, nolamps, onlyselected, actob)) + if (allow_render_object(re, ob, nolamps, onlyselected, actob)) init_render_object(re, ob, NULL, 0, timeoffset); } - else if(allow_render_object(re, ob, nolamps, onlyselected, actob)) + else if (allow_render_object(re, ob, nolamps, onlyselected, actob)) init_render_object(re, ob, NULL, 0, timeoffset); } - if(re->test_break(re->tbh)) break; + if (re->test_break(re->tbh)) break; } /* objects in groups with OB_RENDER_DUPLI set still need to be created, * since they may not be part of the scene */ - for(group= re->main->group.first; group; group=group->id.next) + for (group= re->main->group.first; group; group=group->id.next) add_group_render_dupli_obs(re, group, nolamps, onlyselected, actob, timeoffset, 0); - if(!re->test_break(re->tbh)) + if (!re->test_break(re->tbh)) RE_makeRenderInstances(re); } @@ -5043,15 +5050,15 @@ void RE_Database_FromScene(Render *re, Main *bmain, Scene *scene, unsigned int l re->i.partsdone= 0; /* signal now in use for previewrender */ /* in localview, lamps are using normal layers, objects only local bits */ - if(re->lay & 0xFF000000) + if (re->lay & 0xFF000000) lay &= 0xFF000000; /* applies changes fully */ - if((re->r.scemode & (R_NO_FRAME_UPDATE|R_PREVIEWBUTS))==0) + if ((re->r.scemode & (R_NO_FRAME_UPDATE|R_PREVIEWBUTS))==0) scene_update_for_newframe(re->main, re->scene, lay); /* if no camera, viewmat should have been set! */ - if(use_camera_view && camera) { + if (use_camera_view && camera) { /* called before but need to call again in case of lens animation from the * above call to scene_update_for_newframe, fixes bug. [#22702]. * following calls don't depend on 'RE_SetCamera' */ @@ -5064,10 +5071,10 @@ void RE_Database_FromScene(Render *re, Main *bmain, Scene *scene, unsigned int l } init_render_world(re); /* do first, because of ambient. also requires re->osa set correct */ - if(re->r.mode & R_RAYTRACE) { + if (re->r.mode & R_RAYTRACE) { init_render_qmcsampler(re); - if(re->wrld.mode & (WO_AMB_OCC|WO_ENV_LIGHT|WO_INDIRECT_LIGHT)) + if (re->wrld.mode & (WO_AMB_OCC|WO_ENV_LIGHT|WO_INDIRECT_LIGHT)) if (re->wrld.ao_samp_method == WO_AOSAMP_CONSTANT) init_ao_sphere(&re->wrld); } @@ -5081,11 +5088,11 @@ void RE_Database_FromScene(Render *re, Main *bmain, Scene *scene, unsigned int l /* MAKE RENDER DATA */ database_init_objects(re, lay, 0, 0, 0, 0); - if(!re->test_break(re->tbh)) { + if (!re->test_break(re->tbh)) { int tothalo; set_material_lightgroups(re); - for(sce= re->scene; sce; sce= sce->set) + for (sce= re->scene; sce; sce= sce->set) set_renderlayer_lightgroups(re, sce); slurph_opt= 1; @@ -5100,8 +5107,8 @@ void RE_Database_FromScene(Render *re, Main *bmain, Scene *scene, unsigned int l /* don't sort stars */ tothalo= re->tothalo; - if(!re->test_break(re->tbh)) { - if(re->wrld.mode & WO_STARS) { + if (!re->test_break(re->tbh)) { + if (re->wrld.mode & WO_STARS) { re->i.infostr= "Creating Starfield"; re->stats_draw(re->sdh, &re->i); RE_make_stars(re, NULL, NULL, NULL, NULL); @@ -5120,43 +5127,43 @@ void RE_Database_FromScene(Render *re, Main *bmain, Scene *scene, unsigned int l /* old code checked for internal render (aka not yafray) */ { /* raytree */ - if(!re->test_break(re->tbh)) { - if(re->r.mode & R_RAYTRACE) { + if (!re->test_break(re->tbh)) { + if (re->r.mode & R_RAYTRACE) { makeraytree(re); } } /* ENVIRONMENT MAPS */ - if(!re->test_break(re->tbh)) + if (!re->test_break(re->tbh)) make_envmaps(re); /* point density texture */ - if(!re->test_break(re->tbh)) + if (!re->test_break(re->tbh)) make_pointdensities(re); /* voxel data texture */ - if(!re->test_break(re->tbh)) + if (!re->test_break(re->tbh)) make_voxeldata(re); } - if(!re->test_break(re->tbh)) + if (!re->test_break(re->tbh)) project_renderdata(re, projectverto, re->r.mode & R_PANORAMA, 0, 1); /* Occlusion */ - if((re->wrld.mode & (WO_AMB_OCC|WO_ENV_LIGHT|WO_INDIRECT_LIGHT)) && !re->test_break(re->tbh)) - if(re->wrld.ao_gather_method == WO_AOGATHER_APPROX) - if(re->r.mode & R_SHADOW) + if ((re->wrld.mode & (WO_AMB_OCC|WO_ENV_LIGHT|WO_INDIRECT_LIGHT)) && !re->test_break(re->tbh)) + if (re->wrld.ao_gather_method == WO_AOGATHER_APPROX) + if (re->r.mode & R_SHADOW) make_occ_tree(re); /* SSS */ - if((re->r.mode & R_SSS) && !re->test_break(re->tbh)) + if ((re->r.mode & R_SSS) && !re->test_break(re->tbh)) make_sss_tree(re); - if(!re->test_break(re->tbh)) - if(re->r.mode & R_RAYTRACE) + if (!re->test_break(re->tbh)) + if (re->r.mode & R_RAYTRACE) volume_precache(re); } - if(re->test_break(re->tbh)) + if (re->test_break(re->tbh)) RE_Database_Free(re); else re->i.convertdone= 1; @@ -5198,7 +5205,7 @@ static void database_fromscene_vectors(Render *re, Scene *scene, unsigned int la slurph_opt= 0; /* in localview, lamps are using normal layers, objects only local bits */ - if(re->lay & 0xFF000000) + if (re->lay & 0xFF000000) lay &= 0xFF000000; /* applies changes fully */ @@ -5206,7 +5213,7 @@ static void database_fromscene_vectors(Render *re, Scene *scene, unsigned int la scene_update_for_newframe(re->main, re->scene, lay); /* if no camera, viewmat should have been set! */ - if(camera) { + if (camera) { normalize_m4(camera->obmat); invert_m4_m4(mat, camera->obmat); RE_SetView(re, mat); @@ -5215,7 +5222,7 @@ static void database_fromscene_vectors(Render *re, Scene *scene, unsigned int la /* MAKE RENDER DATA */ database_init_objects(re, lay, 0, 0, 0, timeoffset); - if(!re->test_break(re->tbh)) + if (!re->test_break(re->tbh)) project_renderdata(re, projectverto, re->r.mode & R_PANORAMA, 0, 1); /* do this in end, particles for example need cfra */ @@ -5230,11 +5237,11 @@ static void speedvector_project(Render *re, float zco[2], const float co[3], con float div; /* initialize */ - if(re) { + if (re) { pano= re->r.mode & R_PANORAMA; /* precalculate amount of radians 1 pixel rotates */ - if(pano) { + if (pano) { /* size of 1 pixel mapped to viewplane coords */ float psize= (re->viewplane.xmax-re->viewplane.xmin)/(float)re->winx; /* x angle of a pixel */ @@ -5251,17 +5258,17 @@ static void speedvector_project(Render *re, float zco[2], const float co[3], con } /* now map hocos to screenspace, uses very primitive clip still */ - if(ho[3]<0.1f) div= 10.0f; + if (ho[3]<0.1f) div= 10.0f; else div= 1.0f/ho[3]; /* use cylinder projection */ - if(pano) { + if (pano) { float vec[3], ang; /* angle between (0,0,-1) and (co) */ copy_v3_v3(vec, co); ang= saacos(-vec[2]/sqrtf(vec[0]*vec[0] + vec[2]*vec[2])); - if(vec[0]<0.0f) ang= -ang; + if (vec[0]<0.0f) ang= -ang; zco[0]= ang/pixelphix + zmulx; ang= 0.5f*(float)M_PI - saacos(vec[1] / len_v3(vec)); @@ -5284,21 +5291,21 @@ static void calculate_speedvector(const float vectors[2], int step, float winsq, zco[1]= vectors[1] - zco[1]; /* enable nice masks for hardly moving stuff or float inaccuracy */ - if(zco[0]<0.1f && zco[0]>-0.1f && zco[1]<0.1f && zco[1]>-0.1f ) { + if (zco[0]<0.1f && zco[0]>-0.1f && zco[1]<0.1f && zco[1]>-0.1f ) { zco[0]= 0.0f; zco[1]= 0.0f; } /* maximize speed for image width, otherwise it never looks good */ len= zco[0]*zco[0] + zco[1]*zco[1]; - if(len > winsq) { + if (len > winsq) { len= winroot/sqrtf(len); zco[0]*= len; zco[1]*= len; } /* note; in main vecblur loop speedvec is negated again */ - if(step) { + if (step) { speed[2]= -zco[0]; speed[3]= -zco[1]; } @@ -5310,21 +5317,21 @@ static void calculate_speedvector(const float vectors[2], int step, float winsq, static float *calculate_strandsurface_speedvectors(Render *re, ObjectInstanceRen *obi, StrandSurface *mesh) { - if(mesh->co && mesh->prevco && mesh->nextco) { + if (mesh->co && mesh->prevco && mesh->nextco) { float winsq= (float)re->winx*(float)re->winy; /* int's can wrap on large images */ float winroot= sqrt(winsq); float (*winspeed)[4]; float ho[4], prevho[4], nextho[4], winmat[4][4], vec[2]; int a; - if(obi->flag & R_TRANSFORMED) + if (obi->flag & R_TRANSFORMED) mult_m4_m4m4(winmat, re->winmat, obi->mat); else copy_m4_m4(winmat, re->winmat); winspeed= MEM_callocN(sizeof(float)*4*mesh->totvert, "StrandSurfWin"); - for(a=0; a<mesh->totvert; a++) { + for (a=0; a<mesh->totvert; a++) { projectvert(mesh->co[a], winmat, ho); projectvert(mesh->prevco[a], winmat, prevho); @@ -5354,14 +5361,14 @@ static void calculate_speedvectors(Render *re, ObjectInstanceRen *obi, float *ve float winsq= (float)re->winx*(float)re->winy, winroot= sqrt(winsq); /* int's can wrap on large images */ int a, *face, *index; - if(obi->flag & R_TRANSFORMED) + if (obi->flag & R_TRANSFORMED) mult_m4_m4m4(winmat, re->winmat, obi->mat); else copy_m4_m4(winmat, re->winmat); - if(obr->vertnodes) { - for(a=0; a<obr->totvert; a++, vectors+=2) { - if((a & 255)==0) ver= obr->vertnodes[a>>8].vert; + if (obr->vertnodes) { + for (a=0; a<obr->totvert; a++, vectors+=2) { + if ((a & 255)==0) ver= obr->vertnodes[a>>8].vert; else ver++; speed= RE_vertren_get_winspeed(obi, ver, 1); @@ -5370,21 +5377,21 @@ static void calculate_speedvectors(Render *re, ObjectInstanceRen *obi, float *ve } } - if(obr->strandnodes) { + if (obr->strandnodes) { strandbuf= obr->strandbuf; mesh= (strandbuf)? strandbuf->surface: NULL; /* compute speed vectors at surface vertices */ - if(mesh) + if (mesh) winspeed= (float(*)[4])calculate_strandsurface_speedvectors(re, obi, mesh); - if(winspeed) { - for(a=0; a<obr->totstrand; a++, vectors+=2) { - if((a & 255)==0) strand= obr->strandnodes[a>>8].strand; + if (winspeed) { + for (a=0; a<obr->totstrand; a++, vectors+=2) { + if ((a & 255)==0) strand= obr->strandnodes[a>>8].strand; else strand++; index= RE_strandren_get_face(obr, strand, 0); - if(index && *index < mesh->totface) { + if (index && *index < mesh->totface) { speed= RE_strandren_get_winspeed(obi, strand, 1); /* interpolate speed vectors from strand surface */ @@ -5401,7 +5408,7 @@ static void calculate_speedvectors(Render *re, ObjectInstanceRen *obi, float *ve madd_v4_v4fl(speed, winspeed[face[0]], w[0]); madd_v4_v4fl(speed, winspeed[face[1]], w[1]); madd_v4_v4fl(speed, winspeed[face[2]], w[2]); - if(face[3]) + if (face[3]) madd_v4_v4fl(speed, winspeed[face[3]], w[3]); } } @@ -5428,9 +5435,9 @@ static int load_fluidsimspeedvectors(Render *re, ObjectInstanceRen *obi, float * FluidVertexVelocity *velarray = NULL; /* only one step needed */ - if(step) return 1; + if (step) return 1; - if(fluidmd) + if (fluidmd) fss = fluidmd->fss; else return 0; @@ -5439,16 +5446,16 @@ static int load_fluidsimspeedvectors(Render *re, ObjectInstanceRen *obi, float * invert_m4_m4(imat, mat); /* set first vertex OK */ - if(!fss->meshVelocities) return 0; + if (!fss->meshVelocities) return 0; - if( obr->totvert != fss->totvert) { + if ( obr->totvert != fss->totvert) { //fprintf(stderr, "load_fluidsimspeedvectors - modified fluidsim mesh, not using speed vectors (%d,%d)...\n", obr->totvert, fsob->fluidsimSettings->meshSurface->totvert); // DEBUG return 0; } velarray = fss->meshVelocities; - if(obi->flag & R_TRANSFORMED) + if (obi->flag & R_TRANSFORMED) mult_m4_m4m4(winmat, re->winmat, obi->mat); else copy_m4_m4(winmat, re->winmat); @@ -5457,15 +5464,15 @@ static int load_fluidsimspeedvectors(Render *re, ObjectInstanceRen *obi, float * /* better solution would be fixing getVelocityAt() in intern/elbeem/intern/solver_util.cpp so that also small drops/little water volumes return a velocity != 0. But I had no luck in fixing that function - DG */ - for(a=0; a<obr->totvert; a++) { - for(j=0;j<3;j++) avgvel[j] += velarray[a].vel[j]; + for (a=0; a<obr->totvert; a++) { + for (j=0;j<3;j++) avgvel[j] += velarray[a].vel[j]; } - for(j=0;j<3;j++) avgvel[j] /= (float)(obr->totvert); + for (j=0;j<3;j++) avgvel[j] /= (float)(obr->totvert); - for(a=0; a<obr->totvert; a++, vectors+=2) { - if((a & 255)==0) + for (a=0; a<obr->totvert; a++, vectors+=2) { + if ((a & 255)==0) ver= obr->vertnodes[a>>8].vert; else ver++; @@ -5473,7 +5480,7 @@ static int load_fluidsimspeedvectors(Render *re, ObjectInstanceRen *obi, float * // get fluid velocity fsvec[3] = 0.; //fsvec[0] = fsvec[1] = fsvec[2] = fsvec[3] = 0.; fsvec[2] = 2.; // NT fixed test - for(j=0;j<3;j++) fsvec[j] = velarray[a].vel[j]; + for (j=0;j<3;j++) fsvec[j] = velarray[a].vel[j]; /* (bad) HACK insert average velocity if none is there (see previous comment) */ if ((fsvec[0] == 0.0f) && (fsvec[1] == 0.0f) && (fsvec[2] == 0.0f)) { @@ -5493,14 +5500,14 @@ static int load_fluidsimspeedvectors(Render *re, ObjectInstanceRen *obi, float * /* now map hocos to screenspace, uses very primitive clip still */ // use ho[3] of original vertex, xy component of vel. direction - if(ho[3]<0.1f) div= 10.0f; + if (ho[3]<0.1f) div= 10.0f; else div= 1.0f/ho[3]; zco[0]= zmulx*hoco[0]*div; zco[1]= zmuly*hoco[1]*div; // maximize speed as usual len= zco[0]*zco[0] + zco[1]*zco[1]; - if(len > winsq) { + if (len > winsq) { len= winroot/sqrtf(len); zco[0]*= len; zco[1]*= len; } @@ -5525,7 +5532,7 @@ static void copy_dbase_object_vectors(Render *re, ListBase *lb) float *vec, ho[4], winmat[4][4]; int a, totvector; - for(obi= re->instancetable.first; obi; obi= obi->next) { + for (obi= re->instancetable.first; obi; obi= obi->next) { obr= obi->obr; obilb= MEM_mallocN(sizeof(ObjectInstanceRen), "ObInstanceVector"); @@ -5534,16 +5541,16 @@ static void copy_dbase_object_vectors(Render *re, ListBase *lb) obilb->totvector= totvector= obr->totvert; - if(totvector > 0) { + if (totvector > 0) { vec= obilb->vectors= MEM_mallocN(2*sizeof(float)*totvector, "vector array"); - if(obi->flag & R_TRANSFORMED) + if (obi->flag & R_TRANSFORMED) mult_m4_m4m4(winmat, re->winmat, obi->mat); else copy_m4_m4(winmat, re->winmat); - for(a=0; a<obr->totvert; a++, vec+=2) { - if((a & 255)==0) ver= obr->vertnodes[a>>8].vert; + for (a=0; a<obr->totvert; a++, vec+=2) { + if ((a & 255)==0) ver= obr->vertnodes[a>>8].vert; else ver++; projectvert(ver->co, winmat, ho); @@ -5557,8 +5564,8 @@ static void free_dbase_object_vectors(ListBase *lb) { ObjectInstanceRen *obi; - for(obi= lb->first; obi; obi= obi->next) - if(obi->vectors) + for (obi= lb->first; obi; obi= obi->next) + if (obi->vectors) MEM_freeN(obi->vectors); BLI_freelistN(lb); } @@ -5589,7 +5596,7 @@ void RE_Database_FromScene_Vectors(Render *re, Main *bmain, Scene *sce, unsigned RE_Database_Free(re); re->strandsurface= strandsurface; - if(!re->test_break(re->tbh)) { + if (!re->test_break(re->tbh)) { /* creates entire dbase */ re->i.infostr= "Calculating next frame vectors"; @@ -5604,55 +5611,55 @@ void RE_Database_FromScene_Vectors(Render *re, Main *bmain, Scene *sce, unsigned RE_Database_Free(re); re->strandsurface= strandsurface; - if(!re->test_break(re->tbh)) + if (!re->test_break(re->tbh)) RE_Database_FromScene(re, bmain, sce, lay, 1); - if(!re->test_break(re->tbh)) { + if (!re->test_break(re->tbh)) { int vectorlay= get_vector_renderlayers(re->scene); - for(step= 0; step<2; step++) { + for (step= 0; step<2; step++) { - if(step) + if (step) table= &newtable; else table= &oldtable; oldobi= table->first; - for(obi= re->instancetable.first; obi && oldobi; obi= obi->next) { + for (obi= re->instancetable.first; obi && oldobi; obi= obi->next) { int ok= 1; FluidsimModifierData *fluidmd; - if(!(obi->lay & vectorlay)) + if (!(obi->lay & vectorlay)) continue; obi->totvector= obi->obr->totvert; /* find matching object in old table */ - if(oldobi->ob!=obi->ob || oldobi->par!=obi->par || oldobi->index!=obi->index || oldobi->psysindex!=obi->psysindex) { + if (oldobi->ob!=obi->ob || oldobi->par!=obi->par || oldobi->index!=obi->index || oldobi->psysindex!=obi->psysindex) { ok= 0; - for(oldobi= table->first; oldobi; oldobi= oldobi->next) - if(oldobi->ob==obi->ob && oldobi->par==obi->par && oldobi->index==obi->index && oldobi->psysindex==obi->psysindex) + for (oldobi= table->first; oldobi; oldobi= oldobi->next) + if (oldobi->ob==obi->ob && oldobi->par==obi->par && oldobi->index==obi->index && oldobi->psysindex==obi->psysindex) break; - if(oldobi==NULL) + if (oldobi==NULL) oldobi= table->first; else ok= 1; } - if(ok==0) { + if (ok==0) { printf("speed table: missing object %s\n", obi->ob->id.name+2); continue; } // NT check for fluidsim special treatment fluidmd = (FluidsimModifierData *)modifiers_findByType(obi->ob, eModifierType_Fluidsim); - if(fluidmd && fluidmd->fss && (fluidmd->fss->type & OB_FLUIDSIM_DOMAIN)) { + if (fluidmd && fluidmd->fss && (fluidmd->fss->type & OB_FLUIDSIM_DOMAIN)) { // use preloaded per vertex simulation data , only does calculation for step=1 // NOTE/FIXME - velocities and meshes loaded unnecessarily often during the database_fromscene_vectors calls... load_fluidsimspeedvectors(re, obi, oldobi->vectors, step); } else { /* check if both have same amounts of vertices */ - if(obi->totvector==oldobi->totvector) + if (obi->totvector==oldobi->totvector) calculate_speedvectors(re, obi, oldobi->vectors, step); else printf("Warning: object %s has different amount of vertices or strands on other frame\n", obi->ob->id.name+2); @@ -5666,12 +5673,12 @@ void RE_Database_FromScene_Vectors(Render *re, Main *bmain, Scene *sce, unsigned free_dbase_object_vectors(&oldtable); free_dbase_object_vectors(&newtable); - for(mesh=re->strandsurface.first; mesh; mesh=mesh->next) { - if(mesh->prevco) { + for (mesh=re->strandsurface.first; mesh; mesh=mesh->next) { + if (mesh->prevco) { MEM_freeN(mesh->prevco); mesh->prevco= NULL; } - if(mesh->nextco) { + if (mesh->nextco) { MEM_freeN(mesh->nextco); mesh->nextco= NULL; } @@ -5715,18 +5722,18 @@ void RE_Database_Baking(Render *re, Main *bmain, Scene *scene, unsigned int lay, re->flag |= R_BAKING; re->excludeob= actob; - if(actob) + if (actob) re->flag |= R_BAKE_TRACE; - if(type==RE_BAKE_NORMALS && re->r.bake_normal_space==R_BAKE_SPACE_TANGENT) + if (type==RE_BAKE_NORMALS && re->r.bake_normal_space==R_BAKE_SPACE_TANGENT) re->flag |= R_NEED_TANGENT; - if(!actob && ELEM4(type, RE_BAKE_LIGHT, RE_BAKE_NORMALS, RE_BAKE_TEXTURE, RE_BAKE_DISPLACEMENT)) { + if (!actob && ELEM4(type, RE_BAKE_LIGHT, RE_BAKE_NORMALS, RE_BAKE_TEXTURE, RE_BAKE_DISPLACEMENT)) { re->r.mode &= ~R_SHADOW; re->r.mode &= ~R_RAYTRACE; } - if(!actob && (type==RE_BAKE_SHADOW)) { + if (!actob && (type==RE_BAKE_SHADOW)) { re->r.mode |= R_SHADOW; } @@ -5738,13 +5745,13 @@ void RE_Database_Baking(Render *re, Main *bmain, Scene *scene, unsigned int lay, re->lampren.first= re->lampren.last= NULL; /* in localview, lamps are using normal layers, objects only local bits */ - if(re->lay & 0xFF000000) + if (re->lay & 0xFF000000) lay &= 0xFF000000; camera= RE_GetCamera(re); /* if no camera, set unit */ - if(camera) { + if (camera) { normalize_m4(camera->obmat); invert_m4_m4(mat, camera->obmat); RE_SetView(re, mat); @@ -5763,10 +5770,10 @@ void RE_Database_Baking(Render *re, Main *bmain, Scene *scene, unsigned int lay, /* done setting dummy values */ init_render_world(re); /* do first, because of ambient. also requires re->osa set correct */ - if(re->r.mode & R_RAYTRACE) { + if (re->r.mode & R_RAYTRACE) { init_render_qmcsampler(re); - if(re->wrld.mode & (WO_AMB_OCC|WO_ENV_LIGHT|WO_INDIRECT_LIGHT)) + if (re->wrld.mode & (WO_AMB_OCC|WO_ENV_LIGHT|WO_INDIRECT_LIGHT)) if (re->wrld.ao_samp_method == WO_AOSAMP_CONSTANT) init_ao_sphere(&re->wrld); } @@ -5785,27 +5792,27 @@ void RE_Database_Baking(Render *re, Main *bmain, Scene *scene, unsigned int lay, set_material_lightgroups(re); /* SHADOW BUFFER */ - if(type!=RE_BAKE_LIGHT) - if(re->r.mode & R_SHADOW) + if (type!=RE_BAKE_LIGHT) + if (re->r.mode & R_SHADOW) threaded_makeshadowbufs(re); /* raytree */ - if(!re->test_break(re->tbh)) - if(re->r.mode & R_RAYTRACE) + if (!re->test_break(re->tbh)) + if (re->r.mode & R_RAYTRACE) makeraytree(re); /* point density texture */ - if(!re->test_break(re->tbh)) + if (!re->test_break(re->tbh)) make_pointdensities(re); /* voxel data texture */ - if(!re->test_break(re->tbh)) + if (!re->test_break(re->tbh)) make_voxeldata(re); /* occlusion */ - if((re->wrld.mode & (WO_AMB_OCC|WO_ENV_LIGHT|WO_INDIRECT_LIGHT)) && !re->test_break(re->tbh)) - if(re->wrld.ao_gather_method == WO_AOGATHER_APPROX) - if(re->r.mode & R_SHADOW) + if ((re->wrld.mode & (WO_AMB_OCC|WO_ENV_LIGHT|WO_INDIRECT_LIGHT)) && !re->test_break(re->tbh)) + if (re->wrld.ao_gather_method == WO_AOGATHER_APPROX) + if (re->r.mode & R_SHADOW) make_occ_tree(re); } @@ -5825,19 +5832,19 @@ void RE_make_sticky(Scene *scene, View3D *v3d) int a; Object *camera= NULL; - if(v3d==NULL) { + if (v3d==NULL) { printf("Need a 3d view to make sticky\n"); return; } - if(v3d) camera= V3D_CAMERA_LOCAL(v3d); - if(camera == NULL) camera= scene->camera; + if (v3d) camera= V3D_CAMERA_LOCAL(v3d); + if (camera == NULL) camera= scene->camera; - if(camera==NULL) { + if (camera==NULL) { printf("Need camera to make sticky\n"); return; } - if(scene->obedit) { + if (scene->obedit) { printf("Unable to make sticky in Edit Mode\n"); return; } @@ -5853,14 +5860,14 @@ void RE_make_sticky(Scene *scene, View3D *v3d) invert_m4_m4(mat, camera->obmat); RE_SetView(re, mat); - for(base= FIRSTBASE; base; base= base->next) { + for (base= FIRSTBASE; base; base= base->next) { if TESTBASELIB(v3d, base) { - if(base->object->type==OB_MESH) { + if (base->object->type==OB_MESH) { ob= base->object; me= ob->data; mvert= me->mvert; - if(me->msticky) + if (me->msticky) CustomData_free_layer_active(&me->vdata, CD_MSTICKY, me->totvert); me->msticky= CustomData_add_layer(&me->vdata, CD_MSTICKY, CD_CALLOC, NULL, me->totvert); @@ -5869,7 +5876,7 @@ void RE_make_sticky(Scene *scene, View3D *v3d) mult_m4_m4m4(mat, re->viewmat, ob->obmat); ms= me->msticky; - for(a=0; a<me->totvert; a++, ms++, mvert++) { + for (a=0; a<me->totvert; a++, ms++, mvert++) { copy_v3_v3(ho, mvert->co); mul_m4_v3(mat, ho); projectverto(ho, re->winmat, ho); diff --git a/source/blender/render/intern/source/envmap.c b/source/blender/render/intern/source/envmap.c index 2f6934ba10f..59f8782e816 100644 --- a/source/blender/render/intern/source/envmap.c +++ b/source/blender/render/intern/source/envmap.c @@ -76,7 +76,7 @@ static void envmap_split_ima(EnvMap *env, ImBuf *ibuf) /* after lock we test cube[1], if set the other thread has done it fine */ BLI_lock_thread(LOCK_IMAGE); - if(env->cube[1]==NULL) { + if (env->cube[1]==NULL) { BKE_free_envmapdata(env); @@ -85,18 +85,20 @@ static void envmap_split_ima(EnvMap *env, ImBuf *ibuf) if (3*dx == ibuf->x) { env->type = ENV_CUBE; env->ok= ENV_OSA; - } else if (ibuf->x == ibuf->y) { + } + else if (ibuf->x == ibuf->y) { env->type = ENV_PLANE; env->ok= ENV_OSA; - } else { + } + else { printf("Incorrect envmap size\n"); env->ok= 0; env->ima->ok= 0; } - if(env->ok) { + if (env->ok) { if (env->type == ENV_CUBE) { - for(part=0; part<6; part++) { + for (part=0; part<6; part++) { env->cube[part]= IMB_allocImBuf(dx, dx, 24, IB_rect|IB_rectfloat); } IMB_float_from_rect(ibuf); @@ -214,19 +216,24 @@ static void envmap_transmatrix(float mat[][4], int part) eul[0]= eul[1]= eul[2]= 0.0; - if(part==0) { /* neg z */ + if (part==0) { /* neg z */ ; - } else if(part==1) { /* pos z */ + } + else if (part==1) { /* pos z */ eul[0]= M_PI; - } else if(part==2) { /* pos y */ + } + else if (part==2) { /* pos y */ eul[0]= M_PI/2.0; - } else if(part==3) { /* neg x */ + } + else if (part==3) { /* neg x */ eul[0]= M_PI/2.0; eul[2]= M_PI/2.0; - } else if(part==4) { /* neg y */ + } + else if (part==4) { /* neg y */ eul[0]= M_PI/2.0; eul[2]= M_PI; - } else { /* pos x */ + } + else { /* pos x */ eul[0]= M_PI/2.0; eul[2]= -M_PI/2.0; } @@ -250,7 +257,7 @@ static void env_rotate_scene(Render *re, float mat[][4], int mode) float imat[3][3], pmat[4][4], smat[4][4], tmat[4][4], cmat[3][3], tmpmat[4][4]; int a; - if(mode==0) { + if (mode==0) { invert_m4_m4(tmat, mat); copy_m3_m4(imat, tmat); } @@ -259,13 +266,13 @@ static void env_rotate_scene(Render *re, float mat[][4], int mode) copy_m3_m4(imat, mat); } - for(obi=re->instancetable.first; obi; obi=obi->next) { + for (obi=re->instancetable.first; obi; obi=obi->next) { /* append or set matrix depending on dupli */ - if(obi->flag & R_DUPLI_TRANSFORMED) { + if (obi->flag & R_DUPLI_TRANSFORMED) { copy_m4_m4(tmpmat, obi->mat); mult_m4_m4m4(obi->mat, tmat, tmpmat); } - else if(mode==1) + else if (mode==1) copy_m4_m4(obi->mat, tmat); else unit_m4(obi->mat); @@ -275,23 +282,23 @@ static void env_rotate_scene(Render *re, float mat[][4], int mode) transpose_m3(obi->nmat); /* indicate the renderer has to use transform matrices */ - if(mode==0) + if (mode==0) obi->flag &= ~R_ENV_TRANSFORMED; else obi->flag |= R_ENV_TRANSFORMED; } - for(obr=re->objecttable.first; obr; obr=obr->next) { - for(a=0; a<obr->tothalo; a++) { - if((a & 255)==0) har= obr->bloha[a>>8]; + for (obr=re->objecttable.first; obr; obr=obr->next) { + for (a=0; a<obr->tothalo; a++) { + if ((a & 255)==0) har= obr->bloha[a>>8]; else har++; mul_m4_v3(tmat, har->co); } } - for(go=re->lights.first; go; go= go->next) { + for (go=re->lights.first; go; go= go->next) { lar= go->lampren; /* removed here some horrible code of someone in NaN who tried to fix @@ -309,8 +316,8 @@ static void env_rotate_scene(Render *re, float mat[][4], int mode) mul_m3_v3(lar->imat, lar->sh_invcampos); lar->sh_invcampos[2]*= lar->sh_zfac; - if(lar->shb) { - if(mode==1) { + if (lar->shb) { + if (mode==1) { invert_m4_m4(pmat, mat); mult_m4_m4m4(smat, lar->shb->viewmat, pmat); mult_m4_m4m4(lar->shb->persmat, lar->shb->winmat, smat); @@ -339,10 +346,10 @@ static void env_layerflags(Render *re, unsigned int notlay) notlay= ~notlay; - for(obr=re->objecttable.first; obr; obr=obr->next) { - if((obr->lay & notlay)==0) { - for(a=0; a<obr->totvlak; a++) { - if((a & 255)==0) vlr= obr->vlaknodes[a>>8].vlak; + for (obr=re->objecttable.first; obr; obr=obr->next) { + if ((obr->lay & notlay)==0) { + for (a=0; a<obr->totvlak; a++) { + if ((a & 255)==0) vlr= obr->vlaknodes[a>>8].vlak; else vlr++; vlr->flag |= R_HIDDEN; @@ -357,12 +364,12 @@ static void env_hideobject(Render *re, Object *ob) VlakRen *vlr = NULL; int a; - for(obr=re->objecttable.first; obr; obr=obr->next) { - for(a=0; a<obr->totvlak; a++) { - if((a & 255)==0) vlr= obr->vlaknodes[a>>8].vlak; + for (obr=re->objecttable.first; obr; obr=obr->next) { + for (a=0; a<obr->totvlak; a++) { + if ((a & 255)==0) vlr= obr->vlaknodes[a>>8].vlak; else vlr++; - if(obr->ob == ob) + if (obr->ob == ob) vlr->flag |= R_HIDDEN; } } @@ -374,9 +381,9 @@ static void env_showobjects(Render *re) VlakRen *vlr = NULL; int a; - for(obr=re->objecttable.first; obr; obr=obr->next) { - for(a=0; a<obr->totvlak; a++) { - if((a & 255)==0) vlr= obr->vlaknodes[a>>8].vlak; + for (obr=re->objecttable.first; obr; obr=obr->next) { + for (a=0; a<obr->totvlak; a++) { + if ((a & 255)==0) vlr= obr->vlaknodes[a>>8].vlak; else vlr++; vlr->flag &= ~R_HIDDEN; @@ -426,8 +433,8 @@ static void render_envmap(Render *re, EnvMap *env) invert_m4_m4(tmat, mat); copy_m3_m4(env->obimat, tmat); - for(part=0; part<6; part++) { - if(env->type==ENV_PLANE && part!=1) + for (part=0; part<6; part++) { + if (env->type==ENV_PLANE && part!=1) continue; re->display_clear(re->dch, envre->result); @@ -451,7 +458,7 @@ static void render_envmap(Render *re, EnvMap *env) env_hideobject(envre, env->object); env_set_imats(envre); - if(re->test_break(re->tbh)==0) { + if (re->test_break(re->tbh)==0) { RE_TileProcessor(envre); } @@ -459,7 +466,7 @@ static void render_envmap(Render *re, EnvMap *env) env_showobjects(envre); env_rotate_scene(envre, tmat, 0); - if(re->test_break(re->tbh)==0) { + if (re->test_break(re->tbh)==0) { RenderLayer *rl= envre->result->layers.first; int y; float *alpha; @@ -472,19 +479,19 @@ static void render_envmap(Render *re, EnvMap *env) /* envmap renders without alpha */ alpha= ((float *)ibuf->rect_float)+3; - for(y= ibuf->x*ibuf->y - 1; y>=0; y--, alpha+=4) + for (y= ibuf->x*ibuf->y - 1; y>=0; y--, alpha+=4) *alpha= 1.0; env->cube[part]= ibuf; } - if(re->test_break(re->tbh)) break; + if (re->test_break(re->tbh)) break; } - if(re->test_break(re->tbh)) BKE_free_envmapdata(env); + if (re->test_break(re->tbh)) BKE_free_envmapdata(env); else { - if(envre->r.mode & R_OSA) env->ok= ENV_OSA; + if (envre->r.mode & R_OSA) env->ok= ENV_OSA; else env->ok= ENV_NORMAL; env->lastframe= re->scene->r.cfra; } @@ -515,12 +522,12 @@ void make_envmaps(Render *re) while(depth<5) { tex= re->main->tex.first; while(tex) { - if(tex->id.us && tex->type==TEX_ENVMAP) { - if(tex->env && tex->env->object) { + if (tex->id.us && tex->type==TEX_ENVMAP) { + if (tex->env && tex->env->object) { EnvMap *env= tex->env; - if(env->object->lay & re->lay) { - if(env->stype==ENV_LOAD) { + if (env->object->lay & re->lay) { + if (env->stype==ENV_LOAD) { float orthmat[4][4], mat[4][4], tmat[4][4]; /* precalc orthmat for object */ @@ -535,29 +542,29 @@ void make_envmaps(Render *re) else { /* decide if to render an envmap (again) */ - if(env->depth >= depth) { + if (env->depth >= depth) { /* set 'recalc' to make sure it does an entire loop of recalcs */ - if(env->ok) { + if (env->ok) { /* free when OSA, and old one isn't OSA */ - if((re->r.mode & R_OSA) && env->ok==ENV_NORMAL) + if ((re->r.mode & R_OSA) && env->ok==ENV_NORMAL) BKE_free_envmapdata(env); /* free when size larger */ - else if(env->lastsize < re->r.size) + else if (env->lastsize < re->r.size) BKE_free_envmapdata(env); /* free when env is in recalcmode */ - else if(env->recalc) + else if (env->recalc) BKE_free_envmapdata(env); } - if(env->ok==0 && depth==0) env->recalc= 1; + if (env->ok==0 && depth==0) env->recalc= 1; - if(env->ok==0) { + if (env->ok==0) { do_init= 1; render_envmap(re, env); - if(depth==env->depth) env->recalc= 0; + if (depth==env->depth) env->recalc= 0; } } } @@ -569,7 +576,7 @@ void make_envmaps(Render *re) depth++; } - if(do_init) { + if (do_init) { re->display_init(re->dih, re->result); re->display_clear(re->dch, re->result); // re->flag |= R_REDRAW_PRV; @@ -586,7 +593,7 @@ static int envcube_isect(EnvMap *env, float *vec, float *answ) float labda; int face; - if(env->type==ENV_PLANE) { + if (env->type==ENV_PLANE) { face= 1; labda= 1.0f/vec[2]; @@ -595,7 +602,7 @@ static int envcube_isect(EnvMap *env, float *vec, float *answ) } else { /* which face */ - if( vec[2] <= -fabsf(vec[0]) && vec[2] <= -fabsf(vec[1]) ) { + if ( vec[2] <= -fabsf(vec[0]) && vec[2] <= -fabsf(vec[1]) ) { face= 0; labda= -1.0f/vec[2]; answ[0]= labda*vec[0]; @@ -642,13 +649,13 @@ static int envcube_isect(EnvMap *env, float *vec, float *answ) static void set_dxtdyt(float *dxts, float *dyts, float *dxt, float *dyt, int face) { - if(face==2 || face==4) { + if (face==2 || face==4) { dxts[0]= dxt[0]; dyts[0]= dyt[0]; dxts[1]= dxt[2]; dyts[1]= dyt[2]; } - else if(face==3 || face==5) { + else if (face==3 || face==5) { dxts[0]= dxt[1]; dxts[1]= dxt[2]; dyts[0]= dyt[1]; @@ -674,17 +681,17 @@ int envmaptex(Tex *tex, float *texvec, float *dxt, float *dyt, int osatex, TexRe int face, face1; env= tex->env; - if(env==NULL || (env->stype!=ENV_LOAD && env->object==NULL)) { + if (env==NULL || (env->stype!=ENV_LOAD && env->object==NULL)) { texres->tin= 0.0; return 0; } - if(env->stype==ENV_LOAD) { + if (env->stype==ENV_LOAD) { env->ima= tex->ima; - if(env->ima && env->ima->ok) { - if(env->cube[1]==NULL) { + if (env->ima && env->ima->ok) { + if (env->cube[1]==NULL) { ImBuf *ibuf_ima= BKE_image_get_ibuf(env->ima, NULL); - if(ibuf_ima) + if (ibuf_ima) envmap_split_ima(env, ibuf_ima); else env->ok= 0; @@ -692,21 +699,21 @@ int envmaptex(Tex *tex, float *texvec, float *dxt, float *dyt, int osatex, TexRe } } - if(env->ok==0) { + if (env->ok==0) { texres->tin= 0.0; return 0; } /* rotate to envmap space, if object is set */ copy_v3_v3(vec, texvec); - if(env->object) mul_m3_v3(env->obimat, vec); + if (env->object) mul_m3_v3(env->obimat, vec); else mul_mat3_m4_v3(R.viewinv, vec); face= envcube_isect(env, vec, sco); ibuf= env->cube[face]; - if(osatex) { - if(env->object) { + if (osatex) { + if (env->object) { mul_m3_v3(env->obimat, dxt); mul_m3_v3(env->obimat, dyt); } @@ -719,7 +726,7 @@ int envmaptex(Tex *tex, float *texvec, float *dxt, float *dyt, int osatex, TexRe /* edges? */ - if(texres->ta<1.0f) { + if (texres->ta<1.0f) { TexResult texr1, texr2; texr1.nor= texr2.nor= NULL; @@ -729,7 +736,7 @@ int envmaptex(Tex *tex, float *texvec, float *dxt, float *dyt, int osatex, TexRe face1= envcube_isect(env, vec, sco); sub_v3_v3(vec, dxt); - if(face!=face1) { + if (face!=face1) { ibuf= env->cube[face1]; set_dxtdyt(dxts, dyts, dxt, dyt, face1); imagewraposa(tex, NULL, ibuf, sco, dxts, dyts, &texr1); @@ -742,7 +749,7 @@ int envmaptex(Tex *tex, float *texvec, float *dxt, float *dyt, int osatex, TexRe face1= envcube_isect(env, vec, sco); sub_v3_v3(vec, dyt); - if(face!=face1) { + if (face!=face1) { ibuf= env->cube[face1]; set_dxtdyt(dxts, dyts, dxt, dyt, face1); imagewraposa(tex, NULL, ibuf, sco, dxts, dyts, &texr2); @@ -750,7 +757,7 @@ int envmaptex(Tex *tex, float *texvec, float *dxt, float *dyt, int osatex, TexRe else texr2.tr= texr2.tg= texr2.tb= texr2.ta= 0.0; fac= (texres->ta+texr1.ta+texr2.ta); - if(fac!=0.0f) { + if (fac!=0.0f) { fac= 1.0f/fac; texres->tr= fac*(texres->ta*texres->tr + texr1.ta*texr1.tr + texr2.ta*texr2.tr ); diff --git a/source/blender/render/intern/source/external_engine.c b/source/blender/render/intern/source/external_engine.c index 6e2d33cdf10..ea352a16934 100644 --- a/source/blender/render/intern/source/external_engine.c +++ b/source/blender/render/intern/source/external_engine.c @@ -91,13 +91,13 @@ void RE_engines_exit(void) { RenderEngineType *type, *next; - for(type=R_engines.first; type; type=next) { + for (type=R_engines.first; type; type=next) { next= type->next; BLI_remlink(&R_engines, type); - if(!(type->flag & RE_INTERNAL)) { - if(type->ext.free) + if (!(type->flag & RE_INTERNAL)) { + if (type->ext.free) type->ext.free(type->ext.data); MEM_freeN(type); @@ -110,7 +110,7 @@ RenderEngineType *RE_engines_find(const char *idname) RenderEngineType *type; type= BLI_findstring(&R_engines, idname, offsetof(RenderEngineType, idname)); - if(!type) + if (!type) type= &internal_render_type; return type; @@ -135,12 +135,12 @@ RenderEngine *RE_engine_create(RenderEngineType *type) void RE_engine_free(RenderEngine *engine) { #ifdef WITH_PYTHON - if(engine->py_instance) { + if (engine->py_instance) { BPY_DECREF(engine->py_instance); } #endif - if(engine->text) + if (engine->text) MEM_freeN(engine->text); MEM_freeN(engine); @@ -160,9 +160,9 @@ RenderResult *RE_engine_begin_result(RenderEngine *engine, int x, int y, int w, CLAMP(w, 0, re->result->rectx); CLAMP(h, 0, re->result->recty); - if(x + w > re->result->rectx) + if (x + w > re->result->rectx) w= re->result->rectx - x; - if(y + h > re->result->recty) + if (y + h > re->result->recty) h= re->result->recty - y; /* allocate a render result */ @@ -186,7 +186,7 @@ void RE_engine_update_result(RenderEngine *engine, RenderResult *result) { Render *re= engine->re; - if(result) { + if (result) { result->renlay= result->layers.first; // weak, draws first layer always re->display_draw(re->ddh, result, NULL); } @@ -196,15 +196,15 @@ void RE_engine_end_result(RenderEngine *engine, RenderResult *result) { Render *re= engine->re; - if(!result) + if (!result) return; /* merge. on break, don't merge in result for preview renders, looks nicer */ - if(!(re->test_break(re->tbh) && (re->r.scemode & R_PREVIEWBUTS))) + if (!(re->test_break(re->tbh) && (re->r.scemode & R_PREVIEWBUTS))) render_result_merge(re->result, result); /* draw */ - if(!re->test_break(re->tbh)) { + if (!re->test_break(re->tbh)) { result->renlay= result->layers.first; // weak, draws first layer always re->display_draw(re->ddh, result, NULL); } @@ -219,7 +219,7 @@ int RE_engine_test_break(RenderEngine *engine) { Render *re= engine->re; - if(re) + if (re) return re->test_break(re->tbh); return 0; @@ -232,7 +232,7 @@ void RE_engine_update_stats(RenderEngine *engine, const char *stats, const char Render *re= engine->re; /* stats draw callback */ - if(re) { + if (re) { re->i.statstr= stats; re->i.infostr= info; re->stats_draw(re->sdh, &re->i); @@ -241,16 +241,16 @@ void RE_engine_update_stats(RenderEngine *engine, const char *stats, const char } /* set engine text */ - if(engine->text) { + if (engine->text) { MEM_freeN(engine->text); engine->text= NULL; } - if(stats && stats[0] && info && info[0]) + if (stats && stats[0] && info && info[0]) engine->text= BLI_sprintfN("%s | %s", stats, info); - else if(info && info[0]) + else if (info && info[0]) engine->text= BLI_strdup(info); - else if(stats && stats[0]) + else if (stats && stats[0]) engine->text= BLI_strdup(stats); } @@ -258,7 +258,7 @@ void RE_engine_update_progress(RenderEngine *engine, float progress) { Render *re= engine->re; - if(re) { + if (re) { CLAMP(progress, 0.0f, 1.0f); re->progress(re->prh, progress); } @@ -277,25 +277,25 @@ int RE_engine_render(Render *re, int do_all) RenderEngine *engine; /* verify if we can render */ - if(!type->render) + if (!type->render) return 0; - if((re->r.scemode & R_PREVIEWBUTS) && !(type->flag & RE_USE_PREVIEW)) + if ((re->r.scemode & R_PREVIEWBUTS) && !(type->flag & RE_USE_PREVIEW)) return 0; - if(do_all && !(type->flag & RE_USE_POSTPROCESS)) + if (do_all && !(type->flag & RE_USE_POSTPROCESS)) return 0; - if(!do_all && (type->flag & RE_USE_POSTPROCESS)) + if (!do_all && (type->flag & RE_USE_POSTPROCESS)) return 0; /* create render result */ BLI_rw_mutex_lock(&re->resultmutex, THREAD_LOCK_WRITE); - if(re->result==NULL || !(re->r.scemode & R_PREVIEWBUTS)) { - if(re->result) + if (re->result==NULL || !(re->r.scemode & R_PREVIEWBUTS)) { + if (re->result) render_result_free(re->result); re->result= render_result_new(re, &re->disprect, 0, 0); } BLI_rw_mutex_unlock(&re->resultmutex); - if(re->result==NULL) + if (re->result==NULL) return 1; /* set render info */ @@ -307,24 +307,24 @@ int RE_engine_render(Render *re, int do_all) engine = RE_engine_create(type); engine->re= re; - if(re->flag & R_ANIMATION) + if (re->flag & R_ANIMATION) engine->flag |= RE_ENGINE_ANIMATION; - if(re->r.scemode & R_PREVIEWBUTS) + if (re->r.scemode & R_PREVIEWBUTS) engine->flag |= RE_ENGINE_PREVIEW; - if((re->r.scemode & (R_NO_FRAME_UPDATE|R_PREVIEWBUTS))==0) + if ((re->r.scemode & (R_NO_FRAME_UPDATE|R_PREVIEWBUTS))==0) scene_update_for_newframe(re->main, re->scene, re->lay); - if(type->update) + if (type->update) type->update(engine, re->main, re->scene); - if(type->render) + if (type->render) type->render(engine, re->scene); render_result_free_list(&engine->fullresult, engine->fullresult.first); RE_engine_free(engine); - if(BKE_reports_contain(re->reports, RPT_ERROR)) + if (BKE_reports_contain(re->reports, RPT_ERROR)) G.afbreek = 1; return 1; diff --git a/source/blender/render/intern/source/imagetexture.c b/source/blender/render/intern/source/imagetexture.c index bbca11e09fd..6d8ae20985c 100644 --- a/source/blender/render/intern/source/imagetexture.c +++ b/source/blender/render/intern/source/imagetexture.c @@ -85,12 +85,12 @@ static void ibuf_get_color(float *col, struct ImBuf *ibuf, int x, int y) { int ofs = y * ibuf->x + x; - if(ibuf->rect_float) { - if(ibuf->channels==4) { + if (ibuf->rect_float) { + if (ibuf->channels==4) { float *fp= ibuf->rect_float + 4*ofs; copy_v4_v4(col, fp); } - else if(ibuf->channels==3) { + else if (ibuf->channels==3) { float *fp= ibuf->rect_float + 3*ofs; copy_v3_v3(col, fp); col[3]= 1.0f; @@ -122,23 +122,23 @@ int imagewrap(Tex *tex, Image *ima, ImBuf *ibuf, const float texvec[3], TexResul retval= texres->nor?3:1; /* quick tests */ - if(ibuf==NULL && ima==NULL) + if (ibuf==NULL && ima==NULL) return retval; - if(ima) { + if (ima) { /* hack for icon render */ - if(ima->ibufs.first==NULL && (R.r.scemode & R_NO_IMAGE_LOAD)) + if (ima->ibufs.first==NULL && (R.r.scemode & R_NO_IMAGE_LOAD)) return retval; ibuf= BKE_image_get_ibuf(ima, &tex->iuser); 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)) return retval; /* setup mapping */ - if(tex->imaflag & TEX_IMAROT) { + if (tex->imaflag & TEX_IMAROT) { fy= texvec[0]; fx= texvec[1]; } @@ -147,7 +147,7 @@ int imagewrap(Tex *tex, Image *ima, ImBuf *ibuf, const float texvec[3], TexResul fy= texvec[1]; } - if(tex->extend == TEX_CHECKER) { + if (tex->extend == TEX_CHECKER) { int xs, ys; xs= (int)floor(fx); @@ -155,14 +155,14 @@ int imagewrap(Tex *tex, Image *ima, ImBuf *ibuf, const float texvec[3], TexResul fx-= xs; fy-= ys; - if( (tex->flag & TEX_CHECKER_ODD)==0) { - if((xs+ys) & 1);else return retval; + if ( (tex->flag & TEX_CHECKER_ODD)==0) { + if ((xs+ys) & 1);else return retval; } - if( (tex->flag & TEX_CHECKER_EVEN)==0) { - if((xs+ys) & 1) return retval; + if ( (tex->flag & TEX_CHECKER_EVEN)==0) { + if ((xs+ys) & 1) return retval; } /* scale around center, (0.5, 0.5) */ - if(tex->checkerdist<1.0f) { + 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; } @@ -171,37 +171,37 @@ int imagewrap(Tex *tex, Image *ima, ImBuf *ibuf, const float texvec[3], TexResul 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 (tex->extend == TEX_CLIPCUBE) { + if (x<0 || y<0 || x>=ibuf->x || y>=ibuf->y || texvec[2]<-1.0f || texvec[2]>1.0f) { 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) { 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; + 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; + if (y<0) y+= ibuf->y; } } /* warning, no return before setting back! */ - if( (R.flag & R_SEC_FIELD) && (ibuf->flags & IB_fields) ) { + if ( (R.flag & R_SEC_FIELD) && (ibuf->flags & IB_fields) ) { ibuf->rect+= (ibuf->x*ibuf->y); } @@ -230,12 +230,12 @@ int imagewrap(Tex *tex, Image *ima, ImBuf *ibuf, const float texvec[3], TexResul ibuf_get_color(&texres->tr, ibuf, x, y); } - if( (R.flag & R_SEC_FIELD) && (ibuf->flags & IB_fields) ) { + if ( (R.flag & R_SEC_FIELD) && (ibuf->flags & IB_fields) ) { ibuf->rect-= (ibuf->x*ibuf->y); } - if(texres->nor) { - if(tex->imaflag & TEX_NORMALMAP) { + if (texres->nor) { + if (tex->imaflag & TEX_NORMALMAP) { // qdn: normal from color // The invert of the red channel is to make // the normal map compliant with the outside world. @@ -251,14 +251,14 @@ int imagewrap(Tex *tex, Image *ima, ImBuf *ibuf, const float texvec[3], TexResul /* bump: take three samples */ 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]); } else 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]); @@ -271,16 +271,16 @@ int imagewrap(Tex *tex, Image *ima, ImBuf *ibuf, const float texvec[3], TexResul } } - if(texres->talpha) texres->tin= texres->ta; - else if(tex->imaflag & TEX_CALCALPHA) { + if (texres->talpha) texres->tin= texres->ta; + else if (tex->imaflag & TEX_CALCALPHA) { texres->ta= texres->tin= MAX3(texres->tr, texres->tg, texres->tb); } else texres->ta= texres->tin= 1.0; - if(tex->flag & TEX_NEGALPHA) texres->ta= 1.0f-texres->ta; + if (tex->flag & TEX_NEGALPHA) texres->ta= 1.0f-texres->ta; /* de-premul, this is being premulled in shade_input_do_shade() */ - if(texres->ta!=1.0f && texres->ta>1e-4f) { + if (texres->ta!=1.0f && texres->ta>1e-4f) { fx= 1.0f/texres->ta; texres->tr*= fx; texres->tg*= fx; @@ -299,14 +299,14 @@ static void clipx_rctf_swap(rctf *stack, short *count, float x1, float x2) a= *count; rf= stack; - for(;a>0;a--) { - if(rf->xmin<x1) { - if(rf->xmax<x1) { + 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; + if (rf->xmax>x2) rf->xmax = x2; newrct= stack+ *count; (*count)++; @@ -315,18 +315,18 @@ static void clipx_rctf_swap(rctf *stack, short *count, float x1, float x2) 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) { + 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; + if (rf->xmin<x1) rf->xmin = x1; newrct= stack+ *count; (*count)++; @@ -335,7 +335,7 @@ static void clipx_rctf_swap(rctf *stack, short *count, float x1, float x2) newrct->ymin = rf->ymin; newrct->ymax = rf->ymax; - if(newrct->xmin ==newrct->xmax) (*count)--; + if (newrct->xmin ==newrct->xmax) (*count)--; rf->xmax = x2; } @@ -352,14 +352,14 @@ static void clipy_rctf_swap(rctf *stack, short *count, float y1, float y2) a= *count; rf= stack; - for(;a>0;a--) { - if(rf->ymin<y1) { - if(rf->ymax<y1) { + 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; + if (rf->ymax>y2) rf->ymax = y2; newrct= stack+ *count; (*count)++; @@ -368,18 +368,18 @@ static void clipy_rctf_swap(rctf *stack, short *count, float y1, float y2) 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) { + 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; + if (rf->ymin<y1) rf->ymin = y1; newrct= stack+ *count; (*count)++; @@ -388,7 +388,7 @@ static void clipy_rctf_swap(rctf *stack, short *count, float y1, float y2) newrct->xmin = rf->xmin; newrct->xmax = rf->xmax; - if(newrct->ymin==newrct->ymax) (*count)--; + if (newrct->ymin==newrct->ymax) (*count)--; rf->ymax = y2; } @@ -412,17 +412,17 @@ static float clipx_rctf(rctf *rf, float x1, float x2) size= rf->xmax - rf->xmin; - 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) { + if (rf->xmin > rf->xmax) { rf->xmin = rf->xmax; return 0.0; } - else if(size!=0.0f) { + else if (size!=0.0f) { return (rf->xmax - rf->xmin)/size; } return 1.0; @@ -434,18 +434,18 @@ static float clipy_rctf(rctf *rf, float y1, float y2) size= rf->ymax - rf->ymin; - if(rf->ymin<y1) { + if (rf->ymin<y1) { rf->ymin = y1; } - if(rf->ymax>y2) { + if (rf->ymax>y2) { rf->ymax = y2; } - if(rf->ymin > rf->ymax) { + if (rf->ymin > rf->ymax) { rf->ymin = rf->ymax; return 0.0; } - else if(size!=0.0f) { + else if (size!=0.0f) { return (rf->ymax - rf->ymin)/size; } return 1.0; @@ -465,27 +465,27 @@ static void boxsampleclip(struct ImBuf *ibuf, rctf *rf, TexResult *texres) 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++) { + for (y=starty; y<=endy; y++) { muly= 1.0; - if(starty==endy); + if (starty==endy); 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) { + if (startx==endx) { mulx= muly; ibuf_get_color(col, ibuf, startx, y); @@ -497,14 +497,14 @@ static void boxsampleclip(struct ImBuf *ibuf, rctf *rf, TexResult *texres) div+= mulx; } else { - for(x=startx; x<=endx; 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); + 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) { + if (mulx==1.0f) { texres->ta+= col[3]; texres->tr+= col[0]; texres->tg+= col[1]; @@ -522,7 +522,7 @@ static void boxsampleclip(struct ImBuf *ibuf, rctf *rf, TexResult *texres) } } - if(div!=0.0f) { + if (div!=0.0f) { div= 1.0f/div; texres->tb*= div; texres->tg*= div; @@ -559,37 +559,37 @@ static void boxsample(ImBuf *ibuf, float minx, float miny, float maxx, float max texr.talpha= texres->talpha; /* is read by boxsample_clip */ - if(imapextend) { + if (imapextend) { CLAMP(rf->xmin, 0.0f, ibuf->x-1); CLAMP(rf->xmax, 0.0f, ibuf->x-1); } - else if(imaprepeat) + else if (imaprepeat) clipx_rctf_swap(stack, &count, 0.0, (float)(ibuf->x)); else { alphaclip= clipx_rctf(rf, 0.0, (float)(ibuf->x)); - if(alphaclip<=0.0f) { + if (alphaclip<=0.0f) { texres->tr= texres->tb= texres->tg= texres->ta= 0.0; return; } } - if(imapextend) { + if (imapextend) { CLAMP(rf->ymin, 0.0f, ibuf->y-1); CLAMP(rf->ymax, 0.0f, ibuf->y-1); } - else if(imaprepeat) + else if (imaprepeat) clipy_rctf_swap(stack, &count, 0.0, (float)(ibuf->y)); else { alphaclip*= clipy_rctf(rf, 0.0, (float)(ibuf->y)); - if(alphaclip<=0.0f) { + if (alphaclip<=0.0f) { texres->tr= texres->tb= texres->tg= texres->ta= 0.0; return; } } - if(count>1) { + if (count>1) { tot= texres->tr= texres->tb= texres->tg= texres->ta= 0.0; while(count--) { boxsampleclip(ibuf, rf, &texr); @@ -600,22 +600,22 @@ static void boxsample(ImBuf *ibuf, float minx, float miny, float maxx, float max texres->tr+= opp*texr.tr; texres->tg+= opp*texr.tg; texres->tb+= opp*texr.tb; - if(texres->talpha) texres->ta+= opp*texr.ta; + if (texres->talpha) texres->ta+= opp*texr.ta; rf++; } - if(tot!= 0.0f) { + if (tot!= 0.0f) { texres->tr/= tot; texres->tg/= tot; texres->tb/= tot; - if(texres->talpha) texres->ta/= 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; @@ -978,7 +978,7 @@ static void alpha_clip_aniso(ImBuf *ibuf, float minx, float miny, float maxx, fl // TXF apha: we're doing the same alphaclip here as boxsample, but i'm doubting // if this is actually correct for the all the filtering algorithms .. - if(!(extflag == TXC_REPT || extflag == TXC_EXTD)) { + if (!(extflag == TXC_REPT || extflag == TXC_EXTD)) { rf.xmin = minx*(ibuf->x); rf.xmax = maxx*(ibuf->x); rf.ymin = miny*(ibuf->y); @@ -988,7 +988,7 @@ static void alpha_clip_aniso(ImBuf *ibuf, float minx, float miny, float maxx, fl alphaclip*= clipy_rctf(&rf, 0.0, (float)(ibuf->y)); alphaclip= MAX2(alphaclip, 0.0f); - if(alphaclip!=1.0f) { + if (alphaclip!=1.0f) { /* premul it all */ texres->tr*= alphaclip; texres->tg*= alphaclip; @@ -1213,9 +1213,9 @@ 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) + 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) + 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: @@ -1434,32 +1434,32 @@ int imagewraposa(Tex *tex, Image *ima, ImBuf *ibuf, const float texvec[3], const retval= texres->nor?3:1; /* quick tests */ - if(ibuf==NULL && ima==NULL) + if (ibuf==NULL && ima==NULL) return retval; - if(ima) { + if (ima) { /* hack for icon render */ - if(ima->ibufs.first==NULL && (R.r.scemode & R_NO_IMAGE_LOAD)) + if (ima->ibufs.first==NULL && (R.r.scemode & R_NO_IMAGE_LOAD)) return retval; ibuf= BKE_image_get_ibuf(ima, &tex->iuser); 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)) return retval; /* mipmap test */ image_mipmap_test(tex, ibuf); - if(tex->imaflag & TEX_USEALPHA) { - if(tex->imaflag & TEX_CALCALPHA); + if (tex->imaflag & TEX_USEALPHA) { + if (tex->imaflag & TEX_CALCALPHA); else texres->talpha= 1; } texr.talpha= texres->talpha; - if(tex->imaflag & TEX_IMAROT) { + if (tex->imaflag & TEX_IMAROT) { fy= texvec[0]; fx= texvec[1]; } @@ -1468,9 +1468,9 @@ int imagewraposa(Tex *tex, Image *ima, ImBuf *ibuf, const float texvec[3], const fy= texvec[1]; } - if(ibuf->flags & IB_fields) { - if(R.r.mode & R_FIELDS) { /* field render */ - if(R.flag & R_SEC_FIELD) { /* correction for 2nd field */ + if (ibuf->flags & IB_fields) { + if (R.r.mode & R_FIELDS) { /* field render */ + if (R.flag & R_SEC_FIELD) { /* correction for 2nd field */ /* fac1= 0.5/( (float)ibuf->y ); */ /* fy-= fac1; */ } @@ -1491,16 +1491,16 @@ int imagewraposa(Tex *tex, Image *ima, ImBuf *ibuf, const float texvec[3], const minx= (maxx-minx)/2.0f; miny= (maxy-miny)/2.0f; - if(tex->imaflag & TEX_FILTER_MIN) { + 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); - if(addval > minx) + if (addval > minx) minx= addval; - if(addval > miny) + if (addval > miny) miny= addval; } - else if(tex->filtersize!=1.0f) { + else if (tex->filtersize!=1.0f) { minx*= tex->filtersize; miny*= tex->filtersize; @@ -1510,33 +1510,33 @@ int imagewraposa(Tex *tex, Image *ima, ImBuf *ibuf, const float texvec[3], const dyt[1]*= tex->filtersize; } - if(tex->imaflag & TEX_IMAROT) SWAP(float, minx, miny); + 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); - if(tex->extend == TEX_REPEAT) { - if(tex->flag & (TEX_REPEAT_XMIR|TEX_REPEAT_YMIR)) { + if (tex->extend == TEX_REPEAT) { + if (tex->flag & (TEX_REPEAT_XMIR|TEX_REPEAT_YMIR)) { imaprepeat= 0; imapextend= 1; } } - if(tex->extend == TEX_CHECKER) { + if (tex->extend == TEX_CHECKER) { int xs, ys, xs1, ys1, xs2, ys2, boundary; 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) ) { + if ( (tex->flag & TEX_CHECKER_ODD) && (tex->flag & TEX_CHECKER_EVEN) ) { fx-= xs; fy-= ys; } @@ -1548,37 +1548,37 @@ int imagewraposa(Tex *tex, Image *ima, ImBuf *ibuf, const float texvec[3], const ys2= (int)floor(fy+miny); boundary= (xs1!=xs2) || (ys1!=ys2); - if(boundary==0) { - if( (tex->flag & TEX_CHECKER_ODD)==0) { - if((xs+ys) & 1); + if (boundary==0) { + if ( (tex->flag & TEX_CHECKER_ODD)==0) { + if ((xs+ys) & 1); else return retval; } - if( (tex->flag & TEX_CHECKER_EVEN)==0) { - if((xs+ys) & 1) return retval; + if ( (tex->flag & TEX_CHECKER_EVEN)==0) { + if ((xs+ys) & 1) return retval; } fx-= xs; fy-= ys; } else { - if(tex->flag & TEX_CHECKER_ODD) { - if((xs1+ys) & 1) fx-= xs2; + if (tex->flag & TEX_CHECKER_ODD) { + if ((xs1+ys) & 1) fx-= xs2; else fx-= xs1; - if((ys1+xs) & 1) fy-= ys2; + if ((ys1+xs) & 1) fy-= ys2; else fy-= ys1; } - if(tex->flag & TEX_CHECKER_EVEN) { - if((xs1+ys) & 1) fx-= xs1; + if (tex->flag & TEX_CHECKER_EVEN) { + if ((xs1+ys) & 1) fx-= xs1; else fx-= xs2; - if((ys1+xs) & 1) fy-= ys1; + if ((ys1+xs) & 1) fy-= ys1; else fy-= ys2; } } } /* scale around center, (0.5, 0.5) */ - if(tex->checkerdist<1.0f) { + 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); @@ -1586,74 +1586,74 @@ int imagewraposa(Tex *tex, Image *ima, ImBuf *ibuf, const float texvec[3], const } } - 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 (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) { 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) { return retval; } } else { - if(imapextend) { - if(fx>1.0f) fx = 1.0f; - else if(fx<0.0f) fx= 0.0f; + if (imapextend) { + 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 (imapextend) { + 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); } } /* warning no return! */ - if( (R.flag & R_SEC_FIELD) && (ibuf->flags & IB_fields) ) { + if ( (R.flag & R_SEC_FIELD) && (ibuf->flags & IB_fields) ) { ibuf->rect+= (ibuf->x*ibuf->y); } /* choice: */ - if(tex->imaflag & TEX_MIPMAP) { + if (tex->imaflag & TEX_MIPMAP) { ImBuf *previbuf, *curibuf; float bumpscale; dx= minx; dy= miny; maxd= MAX2(dx, dy); - if(maxd>0.5f) maxd= 0.5f; + if (maxd>0.5f) maxd= 0.5f; pixsize = 1.0f/ (float) MIN2(ibuf->x, ibuf->y); bumpscale= pixsize/maxd; - if(bumpscale>1.0f) bumpscale= 1.0f; + if (bumpscale>1.0f) bumpscale= 1.0f; else bumpscale*=bumpscale; curmap= 0; previbuf= curibuf= ibuf; while(curmap<IB_MIPMAP_LEVELS && ibuf->mipmap[curmap]) { - if(maxd < pixsize) break; + if (maxd < pixsize) break; 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; @@ -1669,13 +1669,13 @@ int imagewraposa(Tex *tex, Image *ima, ImBuf *ibuf, const float texvec[3], const 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); /* calc rgb */ dx= 2.0f*(pixsize-maxd)/pixsize; - if(dx>=1.0f) { + if (dx>=1.0f) { texres->ta= texr.ta; texres->tb= texr.tb; texres->tg= texr.tg; texres->tr= texr.tr; } @@ -1696,7 +1696,7 @@ int imagewraposa(Tex *tex, Image *ima, ImBuf *ibuf, const float texvec[3], const texres->nor[0]= (val1-val2); /* vals have been interpolated above! */ texres->nor[1]= (val1-val3); - if(dx<1.0f) { + if (dx<1.0f) { dy= 1.0f-dx; texres->tb= dy*texres->tb+ dx*texr.tb; texres->tg= dy*texres->tg+ dx*texr.tg; @@ -1715,15 +1715,16 @@ int imagewraposa(Tex *tex, Image *ima, ImBuf *ibuf, const float texvec[3], const 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; - if(fx>=1.0f) { + if (fx>=1.0f) { texres->ta= texr.ta; texres->tb= texr.tb; texres->tg= texr.tg; texres->tr= texr.tr; - } else { + } + else { fy= 1.0f-fx; texres->tb= fy*texres->tb+ fx*texr.tb; texres->tg= fy*texres->tg+ fx*texr.tg; @@ -1741,7 +1742,7 @@ 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) { + 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); @@ -1757,18 +1758,18 @@ int imagewraposa(Tex *tex, Image *ima, ImBuf *ibuf, const float texvec[3], const boxsample(ibuf, fx-minx, fy-miny, fx+minx, fy+miny, texres, imaprepeat, imapextend); } - if(tex->imaflag & TEX_CALCALPHA) { + if (tex->imaflag & TEX_CALCALPHA) { texres->ta= texres->tin= texres->ta*MAX3(texres->tr, texres->tg, texres->tb); } else 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( (R.flag & R_SEC_FIELD) && (ibuf->flags & IB_fields) ) { + if ( (R.flag & R_SEC_FIELD) && (ibuf->flags & IB_fields) ) { ibuf->rect-= (ibuf->x*ibuf->y); } - if(texres->nor && (tex->imaflag & TEX_NORMALMAP)) { + if (texres->nor && (tex->imaflag & TEX_NORMALMAP)) { // qdn: normal from color // The invert of the red channel is to make // the normal map compliant with the outside world. @@ -1782,7 +1783,7 @@ int imagewraposa(Tex *tex, Image *ima, ImBuf *ibuf, const float texvec[3], const } /* de-premul, this is being premulled in shade_input_do_shade() */ - if(texres->ta!=1.0f && texres->ta>1e-4f) { + if (texres->ta!=1.0f && texres->ta>1e-4f) { fx= 1.0f/texres->ta; texres->tr*= fx; texres->tg*= fx; @@ -1799,12 +1800,12 @@ void image_sample(Image *ima, float fx, float fy, float dx, float dy, float *res TexResult texres; ImBuf *ibuf= BKE_image_get_ibuf(ima, NULL); - if(ibuf==NULL) { + if (ibuf==NULL) { result[0]= result[1]= result[2]= result[3]= 0.0f; return; } - if( (R.flag & R_SEC_FIELD) && (ibuf->flags & IB_fields) ) + if ( (R.flag & R_SEC_FIELD) && (ibuf->flags & IB_fields) ) ibuf->rect+= (ibuf->x*ibuf->y); texres.talpha= 1; /* boxsample expects to be initialized */ @@ -1814,7 +1815,7 @@ void image_sample(Image *ima, float fx, float fy, float dx, float dy, float *res result[2]= texres.tb; result[3]= texres.ta; - if( (R.flag & R_SEC_FIELD) && (ibuf->flags & IB_fields) ) + if ( (R.flag & R_SEC_FIELD) && (ibuf->flags & IB_fields) ) ibuf->rect-= (ibuf->x*ibuf->y); ima->flag|= IMA_USED_FOR_RENDER; @@ -1825,7 +1826,7 @@ void ibuf_sample(ImBuf *ibuf, float fx, float fy, float dx, float dy, float *res TexResult texres; afdata_t AFD; - if(ibuf==NULL) { + if (ibuf==NULL) { return; } diff --git a/source/blender/render/intern/source/initrender.c b/source/blender/render/intern/source/initrender.c index 9b68d28e0cf..f7f592c9407 100644 --- a/source/blender/render/intern/source/initrender.c +++ b/source/blender/render/intern/source/initrender.c @@ -92,7 +92,7 @@ static void init_render_jit(Render *re) static int lastjit= 0; static int last_mblur_jit= 0; - if(lastjit!=re->r.osa || last_mblur_jit != re->r.mblur_samples) { + if (lastjit!=re->r.osa || last_mblur_jit != re->r.mblur_samples) { memset(jit, 0, sizeof(jit)); BLI_initjit(jit[0], re->r.osa); @@ -169,11 +169,11 @@ float RE_filter_value(int type, float x) switch(type) { case R_FILTER_BOX: - if(x>1.0f) return 0.0f; + if (x>1.0f) return 0.0f; return 1.0f; case R_FILTER_TENT: - if(x>1.0f) return 0.0f; + if (x>1.0f) return 0.0f; return 1.0f-x; case R_FILTER_GAUSS: @@ -200,7 +200,7 @@ static float calc_weight(Render *re, float *weight, int i, int j) float x, y, dist, totw= 0.0; int a; - for(a=0; a<re->osa; a++) { + for (a=0; a<re->osa; a++) { x= re->jit[a][0] + i; y= re->jit[a][1] + j; dist= sqrt(x*x+y*y); @@ -210,11 +210,11 @@ static float calc_weight(Render *re, float *weight, int i, int j) /* Weighting choices */ switch(re->r.filtertype) { case R_FILTER_BOX: - if(i==0 && j==0) weight[a]= 1.0; + if (i==0 && j==0) weight[a]= 1.0; break; case R_FILTER_TENT: - if(dist < re->r.gauss) + if (dist < re->r.gauss) weight[a]= re->r.gauss - dist; break; @@ -251,8 +251,8 @@ void free_sample_tables(Render *re) { int a; - if(re->samples) { - for(a=0; a<9; a++) { + if (re->samples) { + for (a=0; a<9; a++) { MEM_freeN(re->samples->fmask1[a]); MEM_freeN(re->samples->fmask2[a]); } @@ -273,7 +273,7 @@ void make_sample_tables(Render *re) int i, j, a; /* optimization tables, only once */ - if(firsttime) { + if (firsttime) { firsttime= 0; } @@ -281,7 +281,7 @@ void make_sample_tables(Render *re) init_render_jit(re); /* needed for mblur too */ - if(re->osa==0) { + if (re->osa==0) { /* just prevents cpu cycles for larger render and copying */ re->r.filtertype= 0; return; @@ -289,78 +289,78 @@ void make_sample_tables(Render *re) st= re->samples= MEM_callocN(sizeof(SampleTables), "sample tables"); - for(a=0; a<9;a++) { + for (a=0; a<9;a++) { st->fmask1[a]= MEM_callocN(256*sizeof(float), "initfilt"); st->fmask2[a]= MEM_callocN(256*sizeof(float), "initfilt"); } - for(a=0; a<256; a++) { + for (a=0; a<256; a++) { st->cmask[a]= 0; - if(a & 1) st->cmask[a]++; - if(a & 2) st->cmask[a]++; - if(a & 4) st->cmask[a]++; - if(a & 8) st->cmask[a]++; - if(a & 16) st->cmask[a]++; - if(a & 32) st->cmask[a]++; - if(a & 64) st->cmask[a]++; - if(a & 128) st->cmask[a]++; + if (a & 1) st->cmask[a]++; + if (a & 2) st->cmask[a]++; + if (a & 4) st->cmask[a]++; + if (a & 8) st->cmask[a]++; + if (a & 16) st->cmask[a]++; + if (a & 32) st->cmask[a]++; + if (a & 64) st->cmask[a]++; + if (a & 128) st->cmask[a]++; } st->centmask= MEM_mallocN((1<<re->osa), "Initfilt3"); - for(a=0; a<16; a++) { + for (a=0; a<16; a++) { st->centLut[a]= -0.45f+((float)a)/16.0f; } /* calculate totw */ totw= 0.0; - for(j= -1; j<2; j++) { - for(i= -1; i<2; i++) { + for (j= -1; j<2; j++) { + for (i= -1; i<2; i++) { totw+= calc_weight(re, weight, i, j); } } - for(j= -1; j<2; j++) { - for(i= -1; i<2; i++) { + for (j= -1; j<2; j++) { + for (i= -1; i<2; i++) { /* calculate using jit, with offset the weights */ memset(weight, 0, sizeof(weight)); calc_weight(re, weight, i, j); - for(a=0; a<16; a++) flweight[a]= weight[a]*(1.0f/totw); + for (a=0; a<16; a++) flweight[a]= weight[a]*(1.0f/totw); m3= st->fmask1[ 3*(j+1)+i+1 ]; m4= st->fmask2[ 3*(j+1)+i+1 ]; - for(a=0; a<256; a++) { - if(a & 1) { + for (a=0; a<256; a++) { + if (a & 1) { m3[a]+= flweight[0]; m4[a]+= flweight[8]; } - if(a & 2) { + if (a & 2) { m3[a]+= flweight[1]; m4[a]+= flweight[9]; } - if(a & 4) { + if (a & 4) { m3[a]+= flweight[2]; m4[a]+= flweight[10]; } - if(a & 8) { + if (a & 8) { m3[a]+= flweight[3]; m4[a]+= flweight[11]; } - if(a & 16) { + if (a & 16) { m3[a]+= flweight[4]; m4[a]+= flweight[12]; } - if(a & 32) { + if (a & 32) { m3[a]+= flweight[5]; m4[a]+= flweight[13]; } - if(a & 64) { + if (a & 64) { m3[a]+= flweight[6]; m4[a]+= flweight[14]; } - if(a & 128) { + if (a & 128) { m3[a]+= flweight[7]; m4[a]+= flweight[15]; } @@ -374,52 +374,52 @@ void make_sample_tables(Render *re) fpx2= MEM_mallocN(256*sizeof(float), "initgauss4"); fpy1= MEM_mallocN(256*sizeof(float), "initgauss4"); fpy2= MEM_mallocN(256*sizeof(float), "initgauss4"); - for(a=0; a<256; a++) { + for (a=0; a<256; a++) { fpx1[a]= fpx2[a]= 0.0; fpy1[a]= fpy2[a]= 0.0; - if(a & 1) { + if (a & 1) { fpx1[a]+= re->jit[0][0]; fpy1[a]+= re->jit[0][1]; fpx2[a]+= re->jit[8][0]; fpy2[a]+= re->jit[8][1]; } - if(a & 2) { + if (a & 2) { fpx1[a]+= re->jit[1][0]; fpy1[a]+= re->jit[1][1]; fpx2[a]+= re->jit[9][0]; fpy2[a]+= re->jit[9][1]; } - if(a & 4) { + if (a & 4) { fpx1[a]+= re->jit[2][0]; fpy1[a]+= re->jit[2][1]; fpx2[a]+= re->jit[10][0]; fpy2[a]+= re->jit[10][1]; } - if(a & 8) { + if (a & 8) { fpx1[a]+= re->jit[3][0]; fpy1[a]+= re->jit[3][1]; fpx2[a]+= re->jit[11][0]; fpy2[a]+= re->jit[11][1]; } - if(a & 16) { + if (a & 16) { fpx1[a]+= re->jit[4][0]; fpy1[a]+= re->jit[4][1]; fpx2[a]+= re->jit[12][0]; fpy2[a]+= re->jit[12][1]; } - if(a & 32) { + if (a & 32) { fpx1[a]+= re->jit[5][0]; fpy1[a]+= re->jit[5][1]; fpx2[a]+= re->jit[13][0]; fpy2[a]+= re->jit[13][1]; } - if(a & 64) { + if (a & 64) { fpx1[a]+= re->jit[6][0]; fpy1[a]+= re->jit[6][1]; fpx2[a]+= re->jit[14][0]; fpy2[a]+= re->jit[14][1]; } - if(a & 128) { + if (a & 128) { fpx1[a]+= re->jit[7][0]; fpy1[a]+= re->jit[7][1]; fpx2[a]+= re->jit[15][0]; @@ -427,7 +427,7 @@ void make_sample_tables(Render *re) } } - for(a= (1<<re->osa)-1; a>0; a--) { + for (a= (1<<re->osa)-1; a>0; a--) { val= st->cmask[a & 255] + st->cmask[a>>8]; i= 8+(15.9f*(fpy1[a & 255]+fpy2[a>>8])/val); CLAMP(i, 0, 15); @@ -531,9 +531,9 @@ void freeparts(Render *re) { RenderPart *part= re->parts.first; - while(part) { - if(part->rectp) MEM_freeN(part->rectp); - if(part->rectz) MEM_freeN(part->rectz); + while (part) { + if (part->rectp) MEM_freeN(part->rectp); + if (part->rectz) MEM_freeN(part->rectz); part= part->next; } BLI_freelistN(&re->parts); @@ -561,16 +561,16 @@ void initparts(Render *re) yparts= re->r.yparts; /* mininum part size, but for exr tile saving it was checked already */ - if(!(re->r.scemode & (R_EXR_TILE_FILE|R_FULL_SAMPLE))) { - if(re->r.mode & R_PANORAMA) { - if(ceil(re->rectx/(float)xparts) < 8) + if (!(re->r.scemode & (R_EXR_TILE_FILE|R_FULL_SAMPLE))) { + if (re->r.mode & R_PANORAMA) { + if (ceil(re->rectx/(float)xparts) < 8) xparts= 1 + re->rectx/8; } else - if(ceil(re->rectx/(float)xparts) < 64) + if (ceil(re->rectx/(float)xparts) < 64) xparts= 1 + re->rectx/64; - if(ceil(re->recty/(float)yparts) < 64) + if (ceil(re->recty/(float)yparts) < 64) yparts= 1 + re->recty/64; } @@ -584,10 +584,10 @@ void initparts(Render *re) re->party= party; /* calculate rotation factor of 1 pixel */ - if(re->r.mode & R_PANORAMA) + if (re->r.mode & R_PANORAMA) re->panophi= panorama_pixel_rot(re); - for(nr=0; nr<xparts*yparts; nr++) { + for (nr=0; nr<xparts*yparts; nr++) { rcti disprect; int rectx, recty; @@ -598,16 +598,16 @@ void initparts(Render *re) disprect.ymin = yminb+ yd*party; /* ensure we cover the entire picture, so last parts go to end */ - if(xd<xparts-1) { + if (xd<xparts-1) { disprect.xmax = disprect.xmin + partx; - if(disprect.xmax > xmaxb) + if (disprect.xmax > xmaxb) disprect.xmax = xmaxb; } else disprect.xmax = xmaxb; - if(yd<yparts-1) { + if (yd<yparts-1) { disprect.ymax = disprect.ymin + party; - if(disprect.ymax > ymaxb) + if (disprect.ymax > ymaxb) disprect.ymax = ymaxb; } else disprect.ymax = ymaxb; @@ -616,11 +616,11 @@ void initparts(Render *re) recty= disprect.ymax - disprect.ymin; /* so, now can we add this part? */ - if(rectx>0 && recty>0) { + if (rectx>0 && recty>0) { RenderPart *pa= MEM_callocN(sizeof(RenderPart), "new part"); /* Non-box filters need 2 pixels extra to work */ - if((re->r.filtertype || (re->r.mode & R_EDGE))) { + if ((re->r.filtertype || (re->r.mode & R_EDGE))) { pa->crop= 2; disprect.xmin -= pa->crop; disprect.ymin -= pa->crop; diff --git a/source/blender/render/intern/source/occlusion.c b/source/blender/render/intern/source/occlusion.c index 6ebd84d6635..532d384ec26 100644 --- a/source/blender/render/intern/source/occlusion.c +++ b/source/blender/render/intern/source/occlusion.c @@ -148,7 +148,7 @@ static void occ_shade(ShadeSample *ssamp, ObjectInstanceRen *obi, VlakRen *vlr, float l, u, v, *v1, *v2, *v3; /* init */ - if(vlr->v4) { + if (vlr->v4) { shi->u= u= 0.5f; shi->v= v= 0.5f; } @@ -184,13 +184,13 @@ static void occ_shade(ShadeSample *ssamp, ObjectInstanceRen *obi, VlakRen *vlr, shade_input_set_normals(shi); /* no normal flip */ - if(shi->flippednor) + if (shi->flippednor) shade_input_flip_normals(shi); madd_v3_v3fl(shi->co, shi->vn, 0.0001f); /* ugly.. */ /* not a pretty solution, but fixes common cases */ - if(shi->obr->ob && shi->obr->ob->transflag & OB_NEG_SCALE) { + if (shi->obr->ob && shi->obr->ob->transflag & OB_NEG_SCALE) { negate_v3(shi->vn); negate_v3(shi->vno); negate_v3(shi->nmapnorm); @@ -224,7 +224,7 @@ static void occ_build_shade(Render *re, OcclusionTree *tree) ssamp.shi[0].combinedflag= ~(SCE_PASS_SPEC); ssamp.tot= 1; - for(a=0; a<tree->totface; a++) { + for (a=0; a<tree->totface; a++) { obi= &R.objectinstance[tree->face[a].obi]; vlr= RE_findOrAddVlak(obi->obr, tree->face[a].facenr); @@ -248,7 +248,7 @@ static void sh_mul(float *sh, float f) { int i; - for(i=0; i<9; i++) + for (i=0; i<9; i++) sh[i] *= f; } @@ -256,7 +256,7 @@ static void sh_add(float *shresult, float *sh1, float *sh2) { int i; - for(i=0; i<9; i++) + for (i=0; i<9; i++) shresult[i]= sh1[i] + sh2[i]; } @@ -319,40 +319,40 @@ static void occ_face(const OccFace *face, float co[3], float normal[3], float *a obi= &R.objectinstance[face->obi]; vlr= RE_findOrAddVlak(obi->obr, face->facenr); - if(co) { - if(vlr->v4) + if (co) { + if (vlr->v4) mid_v3_v3v3(co, vlr->v1->co, vlr->v3->co); else cent_tri_v3(co, vlr->v1->co, vlr->v2->co, vlr->v3->co); - if(obi->flag & R_TRANSFORMED) + if (obi->flag & R_TRANSFORMED) mul_m4_v3(obi->mat, co); } - if(normal) { + if (normal) { normal[0]= -vlr->n[0]; normal[1]= -vlr->n[1]; normal[2]= -vlr->n[2]; - if(obi->flag & R_TRANSFORMED) + if (obi->flag & R_TRANSFORMED) mul_m3_v3(obi->nmat, normal); } - if(area) { + if (area) { copy_v3_v3(v1, vlr->v1->co); copy_v3_v3(v2, vlr->v2->co); copy_v3_v3(v3, vlr->v3->co); - if(vlr->v4) copy_v3_v3(v4, vlr->v4->co); + if (vlr->v4) copy_v3_v3(v4, vlr->v4->co); - if(obi->flag & R_TRANSFORMED) { + if (obi->flag & R_TRANSFORMED) { mul_m4_v3(obi->mat, v1); mul_m4_v3(obi->mat, v2); mul_m4_v3(obi->mat, v3); - if(vlr->v4) mul_m4_v3(obi->mat, v4); + if (vlr->v4) mul_m4_v3(obi->mat, v4); } /* todo: correct area for instances */ - if(vlr->v4) + if (vlr->v4) *area= area_quad_v3(v1, v2, v3, v4); else *area= area_tri_v3(v1, v2, v3); @@ -367,33 +367,33 @@ static void occ_sum_occlusion(OcclusionTree *tree, OccNode *node) occ= 0.0f; totarea= 0.0f; - if(indirect) zero_v3(rad); + if (indirect) zero_v3(rad); - for(b=0; b<TOTCHILD; b++) { - if(node->childflag & (1<<b)) { + for (b=0; b<TOTCHILD; b++) { + if (node->childflag & (1<<b)) { a= node->child[b].face; occ_face(&tree->face[a], 0, 0, &area); occ += area*tree->occlusion[a]; - if(indirect) madd_v3_v3fl(rad, tree->rad[a], area); + if (indirect) madd_v3_v3fl(rad, tree->rad[a], area); totarea += area; } - else if(node->child[b].node) { + else if (node->child[b].node) { child= node->child[b].node; occ_sum_occlusion(tree, child); occ += child->area*child->occlusion; - if(indirect) madd_v3_v3fl(rad, child->rad, child->area); + if (indirect) madd_v3_v3fl(rad, child->rad, child->area); totarea += child->area; } } - if(totarea != 0.0f) { + if (totarea != 0.0f) { occ /= totarea; - if(indirect) mul_v3_fl(rad, 1.0f/totarea); + if (indirect) mul_v3_fl(rad, 1.0f/totarea); } node->occlusion= occ; - if(indirect) copy_v3_v3(node->rad, rad); + if (indirect) copy_v3_v3(node->rad, rad); } static int occ_find_bbox_axis(OcclusionTree *tree, int begin, int end, float *min, float *max) @@ -407,10 +407,10 @@ static int occ_find_bbox_axis(OcclusionTree *tree, int begin, int end, float *mi DO_MINMAX(tree->co[a], min, max); } - for(a=0; a<3; a++) { + for (a=0; a<3; a++) { len= max[a] - min[a]; - if(len > maxlen) { + if (len > maxlen) { maxlen= len; axis= a; } @@ -431,13 +431,13 @@ static void occ_node_from_face(OccFace *face, OccNode *node) static void occ_build_dco(OcclusionTree *tree, OccNode *node, const float co[3], float *dco) { int b; - for(b=0; b<TOTCHILD; b++) { + for (b=0; b<TOTCHILD; b++) { float dist, d[3], nco[3]; - if(node->childflag & (1<<b)) { + if (node->childflag & (1<<b)) { occ_face(tree->face+node->child[b].face, nco, NULL, NULL); } - else if(node->child[b].node) { + else if (node->child[b].node) { OccNode *child= node->child[b].node; occ_build_dco(tree, child, co, dco); copy_v3_v3(nco, child->co); @@ -448,7 +448,7 @@ static void occ_build_dco(OcclusionTree *tree, OccNode *node, const float co[3], sub_v3_v3v3(d, nco, co); dist= dot_v3v3(d, d); - if(dist > *dco) + if (dist > *dco) *dco= dist; } } @@ -467,7 +467,7 @@ static void occ_build_split(OcclusionTree *tree, int begin, int end, int *split) a= begin; enda= end; while(a<enda) { - if(tree->co[a][axis] > mid) { + if (tree->co[a][axis] > mid) { enda--; SWAP(OccFace, tree->face[a], tree->face[enda]); SWAP(float, tree->co[a][0], tree->co[enda][0]); @@ -489,7 +489,7 @@ static void occ_build_8_split(OcclusionTree *tree, int begin, int end, int *offs occ_build_split(tree, begin, end, &splitx); /* force split if none found, to deal with degenerate geometry */ - if(splitx == begin || splitx == end) + if (splitx == begin || splitx == end) splitx= (begin+end)/2; occ_build_split(tree, begin, splitx, &splity[0]); @@ -509,7 +509,7 @@ static void occ_build_8_split(OcclusionTree *tree, int begin, int end, int *offs offset[6]= splity[1]; offset[7]= splitz[3]; - for(b=0; b<7; b++) + for (b=0; b<7; b++) count[b]= offset[b+1] - offset[b]; count[7]= end - offset[7]; } @@ -537,8 +537,8 @@ static void occ_build_recursive(OcclusionTree *tree, OccNode *node, int begin, i node->occlusion= 1.0f; /* leaf node with only children */ - if(end - begin <= TOTCHILD) { - for(a=begin, b=0; a<end; a++, b++) { + if (end - begin <= TOTCHILD) { + for (a=begin, b=0; a<end; a++, b++) { /* face= &tree->face[a]; */ node->child[b].face= a; node->childflag |= (1<<b); @@ -548,33 +548,33 @@ static void occ_build_recursive(OcclusionTree *tree, OccNode *node, int begin, i /* order faces */ occ_build_8_split(tree, begin, end, offset, count); - if(depth == 1 && tree->dothreadedbuild) + if (depth == 1 && tree->dothreadedbuild) BLI_init_threads(&threads, exec_occ_build, tree->totbuildthread); - for(b=0; b<TOTCHILD; b++) { - if(count[b] == 0) { + for (b=0; b<TOTCHILD; b++) { + if (count[b] == 0) { node->child[b].node= NULL; } - else if(count[b] == 1) { + else if (count[b] == 1) { /* face= &tree->face[offset[b]]; */ node->child[b].face= offset[b]; node->childflag |= (1<<b); } else { - if(tree->dothreadedbuild) + if (tree->dothreadedbuild) BLI_lock_thread(LOCK_CUSTOM1); child= BLI_memarena_alloc(tree->arena, sizeof(OccNode)); node->child[b].node= child; /* keep track of maximum depth for stack */ - if(depth+1 > tree->maxdepth) + if (depth+1 > tree->maxdepth) tree->maxdepth= depth+1; - if(tree->dothreadedbuild) + if (tree->dothreadedbuild) BLI_unlock_thread(LOCK_CUSTOM1); - if(depth == 1 && tree->dothreadedbuild) { + if (depth == 1 && tree->dothreadedbuild) { othreads[totthread].tree= tree; othreads[totthread].node= child; othreads[totthread].begin= offset[b]; @@ -588,13 +588,13 @@ static void occ_build_recursive(OcclusionTree *tree, OccNode *node, int begin, i } } - if(depth == 1 && tree->dothreadedbuild) + if (depth == 1 && tree->dothreadedbuild) BLI_end_threads(&threads); } /* combine area, position and sh */ - for(b=0; b<TOTCHILD; b++) { - if(node->childflag & (1<<b)) { + for (b=0; b<TOTCHILD; b++) { + if (node->childflag & (1<<b)) { child= &tmpnode; occ_node_from_face(tree->face+node->child[b].face, &tmpnode); } @@ -602,19 +602,19 @@ static void occ_build_recursive(OcclusionTree *tree, OccNode *node, int begin, i child= node->child[b].node; } - if(child) { + if (child) { node->area += child->area; sh_add(node->sh, node->sh, child->sh); madd_v3_v3fl(node->co, child->co, child->area); } } - if(node->area != 0.0f) + if (node->area != 0.0f) mul_v3_fl(node->co, 1.0f/node->area); /* compute maximum distance from center */ node->dco= 0.0f; - if(node->area > 0.0f) + if (node->area > 0.0f) occ_build_dco(tree, node, node->co, &node->dco); } @@ -624,12 +624,12 @@ static void occ_build_sh_normalize(OccNode *node) * we can clamp the dot product and then mutliply by area */ int b; - if(node->area != 0.0f) + if (node->area != 0.0f) sh_mul(node->sh, 1.0f/node->area); - for(b=0; b<TOTCHILD; b++) { - if(node->childflag & (1<<b)); - else if(node->child[b].node) + for (b=0; b<TOTCHILD; b++) { + if (node->childflag & (1<<b)); + else if (node->child[b].node) occ_build_sh_normalize(node->child[b].node); } } @@ -645,20 +645,20 @@ static OcclusionTree *occ_tree_build(Render *re) /* count */ totface= 0; - for(obi=re->instancetable.first; obi; obi=obi->next) { + for (obi=re->instancetable.first; obi; obi=obi->next) { obr= obi->obr; - for(a=0; a<obr->totvlak; a++) { - if((a & 255)==0) vlr= obr->vlaknodes[a>>8].vlak; + for (a=0; a<obr->totvlak; a++) { + if ((a & 255)==0) vlr= obr->vlaknodes[a>>8].vlak; else vlr++; ma= vlr->mat; - if((ma->shade_flag & MA_APPROX_OCCLUSION) && (ma->material_type == MA_TYPE_SURFACE)) + if ((ma->shade_flag & MA_APPROX_OCCLUSION) && (ma->material_type == MA_TYPE_SURFACE)) totface++; } } - if(totface == 0) + if (totface == 0) return NULL; tree= MEM_callocN(sizeof(OcclusionTree), "OcclusionTree"); @@ -673,26 +673,26 @@ static OcclusionTree *occ_tree_build(Render *re) tree->arena= BLI_memarena_new(0x8000 * sizeof(OccNode), "occ tree arena"); BLI_memarena_use_calloc(tree->arena); - if(re->wrld.aomode & WO_AOCACHE) + if (re->wrld.aomode & WO_AOCACHE) tree->cache= MEM_callocN(sizeof(OcclusionCache)*BLENDER_MAX_THREADS, "OcclusionCache"); tree->face= MEM_callocN(sizeof(OccFace)*totface, "OcclusionFace"); tree->co= MEM_callocN(sizeof(float)*3*totface, "OcclusionCo"); tree->occlusion= MEM_callocN(sizeof(float)*totface, "OcclusionOcclusion"); - if(tree->doindirect) + if (tree->doindirect) tree->rad= MEM_callocN(sizeof(float)*3*totface, "OcclusionRad"); /* make array of face pointers */ - for(b=0, c=0, obi=re->instancetable.first; obi; obi=obi->next, c++) { + for (b=0, c=0, obi=re->instancetable.first; obi; obi=obi->next, c++) { obr= obi->obr; - for(a=0; a<obr->totvlak; a++) { - if((a & 255)==0) vlr= obr->vlaknodes[a>>8].vlak; + for (a=0; a<obr->totvlak; a++) { + if ((a & 255)==0) vlr= obr->vlaknodes[a>>8].vlak; else vlr++; ma= vlr->mat; - if((ma->shade_flag & MA_APPROX_OCCLUSION) && (ma->material_type == MA_TYPE_SURFACE)) { + if ((ma->shade_flag & MA_APPROX_OCCLUSION) && (ma->material_type == MA_TYPE_SURFACE)) { tree->face[b].obi= c; tree->face[b].facenr= a; tree->occlusion[b]= 1.0f; @@ -711,7 +711,7 @@ static OcclusionTree *occ_tree_build(Render *re) tree->maxdepth= 1; occ_build_recursive(tree, tree->root, 0, totface, 1); - if(tree->doindirect) { + if (tree->doindirect) { occ_build_shade(re, tree); occ_sum_occlusion(tree, tree->root); } @@ -721,7 +721,7 @@ static OcclusionTree *occ_tree_build(Render *re) occ_build_sh_normalize(tree->root); - for(a=0; a<BLENDER_MAX_THREADS; a++) + for (a=0; a<BLENDER_MAX_THREADS; a++) tree->stack[a]= MEM_callocN(sizeof(OccNode)*TOTCHILD*(tree->maxdepth+1), "OccStack"); return tree; @@ -731,15 +731,15 @@ static void occ_free_tree(OcclusionTree *tree) { int a; - if(tree) { - if(tree->arena) BLI_memarena_free(tree->arena); - for(a=0; a<BLENDER_MAX_THREADS; a++) - if(tree->stack[a]) + if (tree) { + if (tree->arena) BLI_memarena_free(tree->arena); + for (a=0; a<BLENDER_MAX_THREADS; a++) + if (tree->stack[a]) MEM_freeN(tree->stack[a]); - if(tree->occlusion) MEM_freeN(tree->occlusion); - if(tree->cache) MEM_freeN(tree->cache); - if(tree->face) MEM_freeN(tree->face); - if(tree->rad) MEM_freeN(tree->rad); + if (tree->occlusion) MEM_freeN(tree->occlusion); + if (tree->cache) MEM_freeN(tree->cache); + if (tree->face) MEM_freeN(tree->face); + if (tree->rad) MEM_freeN(tree->rad); MEM_freeN(tree); } } @@ -782,20 +782,20 @@ static int occ_visible_quad(float *p, const float n[3], const float v0[3], const sd[1]= dot_v3v3(n, v1) - c; sd[2]= dot_v3v3(n, v2) - c; - if(fabsf(sd[0]) < epsilon) sd[0] = 0.0f; - if(fabsf(sd[1]) < epsilon) sd[1] = 0.0f; - if(fabsf(sd[2]) < epsilon) sd[2] = 0.0f; + if (fabsf(sd[0]) < epsilon) sd[0] = 0.0f; + if (fabsf(sd[1]) < epsilon) sd[1] = 0.0f; + if (fabsf(sd[2]) < epsilon) sd[2] = 0.0f; - if(sd[0] > 0) { - if(sd[1] > 0) { - if(sd[2] > 0) { + if (sd[0] > 0) { + if (sd[1] > 0) { + if (sd[2] > 0) { // +++ copy_v3_v3(q0, v0); copy_v3_v3(q1, v1); copy_v3_v3(q2, v2); copy_v3_v3(q3, q2); } - else if(sd[2] < 0) { + else if (sd[2] < 0) { // ++- copy_v3_v3(q0, v0); copy_v3_v3(q1, v1); @@ -810,15 +810,15 @@ static int occ_visible_quad(float *p, const float n[3], const float v0[3], const copy_v3_v3(q3, q2); } } - else if(sd[1] < 0) { - if(sd[2] > 0) { + else if (sd[1] < 0) { + if (sd[2] > 0) { // +-+ copy_v3_v3(q0, v0); VecAddDir(q1, v0, v1, (sd[0]/(sd[0]-sd[1]))); VecAddDir(q2, v1, v2, (sd[1]/(sd[1]-sd[2]))); copy_v3_v3(q3, v2); } - else if(sd[2] < 0) { + else if (sd[2] < 0) { // +-- copy_v3_v3(q0, v0); VecAddDir(q1, v0, v1, (sd[0]/(sd[0]-sd[1]))); @@ -834,14 +834,14 @@ static int occ_visible_quad(float *p, const float n[3], const float v0[3], const } } else { - if(sd[2] > 0) { + if (sd[2] > 0) { // +0+ copy_v3_v3(q0, v0); copy_v3_v3(q1, v1); copy_v3_v3(q2, v2); copy_v3_v3(q3, q2); } - else if(sd[2] < 0) { + else if (sd[2] < 0) { // +0- copy_v3_v3(q0, v0); copy_v3_v3(q1, v1); @@ -857,16 +857,16 @@ static int occ_visible_quad(float *p, const float n[3], const float v0[3], const } } } - else if(sd[0] < 0) { - if(sd[1] > 0) { - if(sd[2] > 0) { + else if (sd[0] < 0) { + if (sd[1] > 0) { + if (sd[2] > 0) { // -++ VecAddDir(q0, v0, v1, (sd[0]/(sd[0]-sd[1]))); copy_v3_v3(q1, v1); copy_v3_v3(q2, v2); VecAddDir(q3, v0, v2, (sd[0]/(sd[0]-sd[2]))); } - else if(sd[2] < 0) { + else if (sd[2] < 0) { // -+- VecAddDir(q0, v0, v1, (sd[0]/(sd[0]-sd[1]))); copy_v3_v3(q1, v1); @@ -881,15 +881,15 @@ static int occ_visible_quad(float *p, const float n[3], const float v0[3], const copy_v3_v3(q3, q2); } } - else if(sd[1] < 0) { - if(sd[2] > 0) { + else if (sd[1] < 0) { + if (sd[2] > 0) { // --+ VecAddDir(q0, v0, v2, (sd[0]/(sd[0]-sd[2]))); VecAddDir(q1, v1, v2, (sd[1]/(sd[1]-sd[2]))); copy_v3_v3(q2, v2); copy_v3_v3(q3, q2); } - else if(sd[2] < 0) { + else if (sd[2] < 0) { // --- return 0; } @@ -899,14 +899,14 @@ static int occ_visible_quad(float *p, const float n[3], const float v0[3], const } } else { - if(sd[2] > 0) { + if (sd[2] > 0) { // -0+ VecAddDir(q0, v0, v2, (sd[0]/(sd[0]-sd[2]))); copy_v3_v3(q1, v1); copy_v3_v3(q2, v2); copy_v3_v3(q3, q2); } - else if(sd[2] < 0) { + else if (sd[2] < 0) { // -0- return 0; } @@ -917,15 +917,15 @@ static int occ_visible_quad(float *p, const float n[3], const float v0[3], const } } else { - if(sd[1] > 0) { - if(sd[2] > 0) { + if (sd[1] > 0) { + if (sd[2] > 0) { // 0++ copy_v3_v3(q0, v0); copy_v3_v3(q1, v1); copy_v3_v3(q2, v2); copy_v3_v3(q3, q2); } - else if(sd[2] < 0) { + else if (sd[2] < 0) { // 0+- copy_v3_v3(q0, v0); copy_v3_v3(q1, v1); @@ -940,15 +940,15 @@ static int occ_visible_quad(float *p, const float n[3], const float v0[3], const copy_v3_v3(q3, q2); } } - else if(sd[1] < 0) { - if(sd[2] > 0) { + else if (sd[1] < 0) { + if (sd[2] > 0) { // 0-+ copy_v3_v3(q0, v0); VecAddDir(q1, v1, v2, (sd[1]/(sd[1]-sd[2]))); copy_v3_v3(q2, v2); copy_v3_v3(q3, q2); } - else if(sd[2] < 0) { + else if (sd[2] < 0) { // 0-- return 0; } @@ -958,14 +958,14 @@ static int occ_visible_quad(float *p, const float n[3], const float v0[3], const } } else { - if(sd[2] > 0) { + if (sd[2] > 0) { // 00+ copy_v3_v3(q0, v0); copy_v3_v3(q1, v1); copy_v3_v3(q2, v2); copy_v3_v3(q3, q2); } - else if(sd[2] < 0) { + else if (sd[2] < 0) { // 00- return 0; } @@ -991,20 +991,20 @@ typedef union { static vFloat vec_splat_float(float val) { - return (vFloat){val, val, val, val}; + return (vFloat) {val, val, val, val}; } static float occ_quad_form_factor(float *p, float *n, float *q0, float *q1, float *q2, float *q3) { vFloat vcos, rlen, vrx, vry, vrz, vsrx, vsry, vsrz, gx, gy, gz, vangle; - vUInt8 rotate = (vUInt8){4,5,6,7,8,9,10,11,12,13,14,15,0,1,2,3}; + vUInt8 rotate = (vUInt8) {4,5,6,7,8,9,10,11,12,13,14,15,0,1,2,3}; vFloatResult vresult; float result; /* compute r* */ - vrx = (vFloat){q0[0], q1[0], q2[0], q3[0]} - vec_splat_float(p[0]); - vry = (vFloat){q0[1], q1[1], q2[1], q3[1]} - vec_splat_float(p[1]); - vrz = (vFloat){q0[2], q1[2], q2[2], q3[2]} - vec_splat_float(p[2]); + vrx = (vFloat) {q0[0], q1[0], q2[0], q3[0]} - vec_splat_float(p[0]); + vry = (vFloat) {q0[1], q1[1], q2[1], q3[1]} - vec_splat_float(p[1]); + vrz = (vFloat) {q0[2], q1[2], q2[2], q3[2]} - vec_splat_float(p[2]); /* normalize r* */ rlen = vec_rsqrte(vrx*vrx + vry*vry + vrz*vrz + vec_splat_float(1e-16f)); @@ -1120,7 +1120,7 @@ static void normalizef(float *n) d= dot_v3v3(n, n); - if(d > 1.0e-35F) { + if (d > 1.0e-35F) { d= 1.0f/sqrtf(d); n[0] *= d; @@ -1178,21 +1178,21 @@ static float occ_form_factor(OccFace *face, float *p, float *n) copy_v3_v3(v2, vlr->v2->co); copy_v3_v3(v3, vlr->v3->co); - if(obi->flag & R_TRANSFORMED) { + if (obi->flag & R_TRANSFORMED) { mul_m4_v3(obi->mat, v1); mul_m4_v3(obi->mat, v2); mul_m4_v3(obi->mat, v3); } - if(occ_visible_quad(p, n, v1, v2, v3, q0, q1, q2, q3)) + if (occ_visible_quad(p, n, v1, v2, v3, q0, q1, q2, q3)) contrib += occ_quad_form_factor(p, n, q0, q1, q2, q3); - if(vlr->v4) { + if (vlr->v4) { copy_v3_v3(v4, vlr->v4->co); - if(obi->flag & R_TRANSFORMED) + if (obi->flag & R_TRANSFORMED) mul_m4_v3(obi->mat, v4); - if(occ_visible_quad(p, n, v1, v3, v4, q0, q1, q2, q3)) + if (occ_visible_quad(p, n, v1, v3, v4, q0, q1, q2, q3)) contrib += occ_quad_form_factor(p, n, q0, q1, q2, q3); } @@ -1212,7 +1212,7 @@ static void occ_lookup(OcclusionTree *tree, int thread, OccFace *exclude, float copy_v3_v3(n, pn); madd_v3_v3fl(p, n, 1e-4f); - if(bentn) + if (bentn) copy_v3_v3(bentn, n); error= tree->error; @@ -1234,10 +1234,10 @@ static void occ_lookup(OcclusionTree *tree, int thread, OccFace *exclude, float d2= dot_v3v3(v, v) + 1e-16f; emitarea= MAX2(node->area, node->dco); - if(d2*error > emitarea) { - if(distfac != 0.0f) { + if (d2*error > emitarea) { + if (distfac != 0.0f) { fac= 1.0f/(1.0f + distfac*d2); - if(fac < 0.01f) + if (fac < 0.01f) continue; } else @@ -1247,12 +1247,12 @@ static void occ_lookup(OcclusionTree *tree, int thread, OccFace *exclude, float invd2 = 1.0f/sqrtf(d2); weight= occ_solid_angle(node, v, d2, invd2, n); - if(rad) + if (rad) madd_v3_v3fl(resultrad, node->rad, weight*fac); weight *= node->occlusion; - if(bentn) { + if (bentn) { bentn[0] -= weight*invd2*v[0]; bentn[1] -= weight*invd2*v[1]; bentn[2] -= weight*invd2*v[2]; @@ -1262,20 +1262,20 @@ static void occ_lookup(OcclusionTree *tree, int thread, OccFace *exclude, float } else { /* traverse into children */ - for(b=0; b<TOTCHILD; b++) { - if(node->childflag & (1<<b)) { + for (b=0; b<TOTCHILD; b++) { + if (node->childflag & (1<<b)) { f= node->child[b].face; face= &tree->face[f]; /* accumulate occlusion with face form factor */ - if(!exclude || !(face->obi == exclude->obi && face->facenr == exclude->facenr)) { - if(bentn || distfac != 0.0f) { + if (!exclude || !(face->obi == exclude->obi && face->facenr == exclude->facenr)) { + if (bentn || distfac != 0.0f) { occ_face(face, co, NULL, NULL); sub_v3_v3v3(v, co, p); d2= dot_v3v3(v, v) + 1e-16f; fac= (distfac == 0.0f)? 1.0f: 1.0f/(1.0f + distfac*d2); - if(fac < 0.01f) + if (fac < 0.01f) continue; } else @@ -1283,12 +1283,12 @@ static void occ_lookup(OcclusionTree *tree, int thread, OccFace *exclude, float weight= occ_form_factor(face, p, n); - if(rad) + if (rad) madd_v3_v3fl(resultrad, tree->rad[f], weight*fac); weight *= tree->occlusion[f]; - if(bentn) { + if (bentn) { invd2= 1.0f/sqrtf(d2); bentn[0] -= weight*invd2*v[0]; bentn[1] -= weight*invd2*v[1]; @@ -1298,7 +1298,7 @@ static void occ_lookup(OcclusionTree *tree, int thread, OccFace *exclude, float resultocc += weight*fac; } } - else if(node->child[b].node) { + else if (node->child[b].node) { /* push child on the stack */ stack[totstack++]= node->child[b].node; } @@ -1306,17 +1306,17 @@ static void occ_lookup(OcclusionTree *tree, int thread, OccFace *exclude, float } } - if(occ) *occ= resultocc; - if(rad) copy_v3_v3(rad, resultrad); + if (occ) *occ= resultocc; + if (rad) copy_v3_v3(rad, resultrad); #if 0 - if(rad && exclude) { + if (rad && exclude) { int a; - for(a=0; a<tree->totface; a++) - if((tree->face[a].obi == exclude->obi && tree->face[a].facenr == exclude->facenr)) + for (a=0; a<tree->totface; a++) + if ((tree->face[a].obi == exclude->obi && tree->face[a].facenr == exclude->facenr)) copy_v3_v3(rad, tree->rad[a]); } #endif - if(bentn) normalize_v3(bentn); + if (bentn) normalize_v3(bentn); } static void occ_compute_bounces(Render *re, OcclusionTree *tree, int totbounce) @@ -1327,8 +1327,8 @@ static void occ_compute_bounces(Render *re, OcclusionTree *tree, int totbounce) rad= MEM_callocN(sizeof(float)*3*tree->totface, "OcclusionBounceRad"); sum= MEM_dupallocN(tree->rad); - for(bounce=1; bounce<totbounce; bounce++) { - for(i=0; i<tree->totface; i++) { + for (bounce=1; bounce<totbounce; bounce++) { + for (i=0; i<tree->totface; i++) { occ_face(&tree->face[i], co, n, NULL); madd_v3_v3fl(co, n, 1e-8f); @@ -1338,11 +1338,11 @@ static void occ_compute_bounces(Render *re, OcclusionTree *tree, int totbounce) rad[i][2]= MAX2(rad[i][2], 0.0f); add_v3_v3(sum[i], rad[i]); - if(re->test_break(re->tbh)) + if (re->test_break(re->tbh)) break; } - if(re->test_break(re->tbh)) + if (re->test_break(re->tbh)) break; tmp= tree->rad; @@ -1356,7 +1356,7 @@ static void occ_compute_bounces(Render *re, OcclusionTree *tree, int totbounce) MEM_freeN(tree->rad); tree->rad= sum; - if(!re->test_break(re->tbh)) + if (!re->test_break(re->tbh)) occ_sum_occlusion(tree, tree->root); } @@ -1367,23 +1367,23 @@ static void occ_compute_passes(Render *re, OcclusionTree *tree, int totpass) occ= MEM_callocN(sizeof(float)*tree->totface, "OcclusionPassOcc"); - for(pass=0; pass<totpass; pass++) { - for(i=0; i<tree->totface; i++) { + for (pass=0; pass<totpass; pass++) { + for (i=0; i<tree->totface; i++) { occ_face(&tree->face[i], co, n, NULL); negate_v3(n); madd_v3_v3fl(co, n, 1e-8f); occ_lookup(tree, 0, &tree->face[i], co, n, &occ[i], NULL, NULL); - if(re->test_break(re->tbh)) + if (re->test_break(re->tbh)) break; } - if(re->test_break(re->tbh)) + if (re->test_break(re->tbh)) break; - for(i=0; i<tree->totface; i++) { + for (i=0; i<tree->totface; i++) { tree->occlusion[i] -= occ[i]; //MAX2(1.0f-occ[i], 0.0f); - if(tree->occlusion[i] < 0.0f) + if (tree->occlusion[i] < 0.0f) tree->occlusion[i]= 0.0f; } @@ -1399,7 +1399,7 @@ static void sample_occ_tree(Render *re, OcclusionTree *tree, OccFace *exclude, f int envcolor; envcolor= re->wrld.aocolor; - if(onlyshadow) + if (onlyshadow) envcolor= WO_AOPLAIN; negate_v3_v3(nn, n); @@ -1410,12 +1410,12 @@ static void sample_occ_tree(Render *re, OcclusionTree *tree, OccFace *exclude, f occlusion= (1.0f-correction)*(1.0f-occ); CLAMP(occlusion, 0.0f, 1.0f); - if(correction != 0.0f) + if (correction != 0.0f) occlusion += correction*expf(-occ); - if(env) { + if (env) { /* sky shading using bent normal */ - if(ELEM(envcolor, WO_AOSKYCOL, WO_AOSKYTEX)) { + if (ELEM(envcolor, WO_AOSKYCOL, WO_AOSKYTEX)) { fac= 0.5f * (1.0f + dot_v3v3(bn, re->grvec)); env[0]= (1.0f-fac)*re->wrld.horr + fac*re->wrld.zenr; env[1]= (1.0f-fac)*re->wrld.horg + fac*re->wrld.zeng; @@ -1442,13 +1442,13 @@ static void sample_occ_tree(Render *re, OcclusionTree *tree, OccFace *exclude, f #endif } - if(ao) { + if (ao) { ao[0]= occlusion; ao[1]= occlusion; ao[2]= occlusion; } - if(tree->doindirect) copy_v3_v3(indirect, rad); + if (tree->doindirect) copy_v3_v3(indirect, rad); else zero_v3(indirect); } @@ -1464,7 +1464,7 @@ static OcclusionCacheSample *find_occ_sample(OcclusionCache *cache, int x, int y x *= cache->step; y *= cache->step; - if(x < 0 || x >= cache->w || y < 0 || y >= cache->h) + if (x < 0 || x >= cache->w || y < 0 || y >= cache->h) return NULL; else return &cache->sample[y*cache->w + x]; @@ -1478,18 +1478,18 @@ static int sample_occ_cache(OcclusionTree *tree, float *co, float *n, int x, int float d[3], dist2; int i, x1, y1, x2, y2; - if(!tree->cache) + if (!tree->cache) return 0; /* first try to find a sample in the same pixel */ cache= &tree->cache[thread]; - if(cache->sample && cache->step) { + if (cache->sample && cache->step) { sample= &cache->sample[(y-cache->y)*cache->w + (x-cache->x)]; - if(sample->filled) { + if (sample->filled) { sub_v3_v3v3(d, sample->co, co); dist2= dot_v3v3(d, d); - if(dist2 < 0.5f*sample->dist2 && dot_v3v3(sample->n, n) > 0.98f) { + if (dist2 < 0.5f*sample->dist2 && dot_v3v3(sample->n, n) > 0.98f) { copy_v3_v3(ao, sample->ao); copy_v3_v3(env, sample->env); copy_v3_v3(indirect, sample->indirect); @@ -1506,15 +1506,15 @@ static int sample_occ_cache(OcclusionTree *tree, float *co, float *n, int x, int samples[2]= find_occ_sample(cache, x, y+cache->step); samples[3]= find_occ_sample(cache, x+cache->step, y+cache->step); - for(i=0; i<4; i++) - if(!samples[i] || !samples[i]->filled) + for (i=0; i<4; i++) + if (!samples[i] || !samples[i]->filled) return 0; /* require intensities not being too different */ mino= MIN4(samples[0]->intensity, samples[1]->intensity, samples[2]->intensity, samples[3]->intensity); maxo= MAX4(samples[0]->intensity, samples[1]->intensity, samples[2]->intensity, samples[3]->intensity); - if(maxo - mino > 0.05f) + if (maxo - mino > 0.05f) return 0; /* compute weighted interpolation between samples */ @@ -1536,7 +1536,7 @@ static int sample_occ_cache(OcclusionTree *tree, float *co, float *n, int x, int wb[1]= (1.0f-tx)*(ty); wb[0]= tx*ty; - for(i=0; i<4; i++) { + for (i=0; i<4; i++) { sub_v3_v3v3(d, samples[i]->co, co); //dist2= dot_v3v3(d, d); @@ -1551,7 +1551,7 @@ static int sample_occ_cache(OcclusionTree *tree, float *co, float *n, int x, int madd_v3_v3fl(indirect, samples[i]->indirect, w); } - if(totw >= 0.9f) { + if (totw >= 0.9f) { totw= 1.0f/totw; mul_v3_fl(ao, totw); mul_v3_fl(env, totw); @@ -1569,7 +1569,7 @@ static void sample_occ_surface(ShadeInput *shi) int *face, *index = RE_strandren_get_face(shi->obr, strand, 0); float w[4], *co1, *co2, *co3, *co4; - if(mesh && mesh->face && mesh->co && mesh->ao && index) { + if (mesh && mesh->face && mesh->co && mesh->ao && index) { face= mesh->face[*index]; co1= mesh->co[face[0]]; @@ -1592,7 +1592,7 @@ static void sample_occ_surface(ShadeInput *shi) madd_v3_v3fl(shi->ao, mesh->ao[face[2]], w[2]); madd_v3_v3fl(shi->env, mesh->env[face[2]], w[2]); madd_v3_v3fl(shi->indirect, mesh->indirect[face[2]], w[2]); - if(face[3]) { + if (face[3]) { madd_v3_v3fl(shi->ao, mesh->ao[face[3]], w[3]); madd_v3_v3fl(shi->env, mesh->env[face[3]], w[3]); madd_v3_v3fl(shi->indirect, mesh->indirect[face[3]], w[3]); @@ -1617,13 +1617,13 @@ static void *exec_strandsurface_sample(void *data) float ao[3], env[3], indirect[3], co[3], n[3], *co1, *co2, *co3, *co4; int a, *face; - for(a=othread->begin; a<othread->end; a++) { + for (a=othread->begin; a<othread->end; a++) { face= mesh->face[a]; co1= mesh->co[face[0]]; co2= mesh->co[face[1]]; co3= mesh->co[face[2]]; - if(face[3]) { + if (face[3]) { co4= mesh->co[face[3]]; mid_v3_v3v3(co, co1, co3); @@ -1661,14 +1661,14 @@ void make_occ_tree(Render *re) re->occlusiontree= tree= occ_tree_build(re); - if(tree) { - if(re->wrld.ao_approx_passes > 0) + if (tree) { + if (re->wrld.ao_approx_passes > 0) occ_compute_passes(re, tree, re->wrld.ao_approx_passes); - if(tree->doindirect && (re->wrld.mode & WO_INDIRECT_LIGHT)) + if (tree->doindirect && (re->wrld.mode & WO_INDIRECT_LIGHT)) occ_compute_bounces(re, tree, re->wrld.ao_indirect_bounces); - for(mesh=re->strandsurface.first; mesh; mesh=mesh->next) { - if(!mesh->face || !mesh->co || !mesh->ao) + for (mesh=re->strandsurface.first; mesh; mesh=mesh->next) { + if (!mesh->face || !mesh->co || !mesh->ao) continue; count= MEM_callocN(sizeof(int)*mesh->totvert, "OcclusionCount"); @@ -1678,7 +1678,7 @@ void make_occ_tree(Render *re) totthread= (mesh->totface > 10000)? re->r.threads: 1; totface= mesh->totface/totthread; - for(a=0; a<totthread; a++) { + for (a=0; a<totthread; a++) { othreads[a].re= re; othreads[a].faceao= faceao; othreads[a].faceenv= faceenv; @@ -1689,19 +1689,19 @@ void make_occ_tree(Render *re) othreads[a].end= (a == totthread-1)? mesh->totface: (a+1)*totface; } - if(totthread == 1) { + if (totthread == 1) { exec_strandsurface_sample(&othreads[0]); } else { BLI_init_threads(&threads, exec_strandsurface_sample, totthread); - for(a=0; a<totthread; a++) + for (a=0; a<totthread; a++) BLI_insert_thread(&threads, &othreads[a]); BLI_end_threads(&threads); } - for(a=0; a<mesh->totface; a++) { + for (a=0; a<mesh->totface; a++) { face= mesh->face[a]; copy_v3_v3(ao, faceao[a]); @@ -1721,7 +1721,7 @@ void make_occ_tree(Render *re) add_v3_v3(mesh->indirect[face[2]], indirect); count[face[2]]++; - if(face[3]) { + if (face[3]) { add_v3_v3(mesh->ao[face[3]], ao); add_v3_v3(mesh->env[face[3]], env); add_v3_v3(mesh->indirect[face[3]], indirect); @@ -1729,8 +1729,8 @@ void make_occ_tree(Render *re) } } - for(a=0; a<mesh->totvert; a++) { - if(count[a]) { + for (a=0; a<mesh->totvert; a++) { + if (count[a]) { mul_v3_fl(mesh->ao[a], 1.0f/count[a]); mul_v3_fl(mesh->env[a], 1.0f/count[a]); mul_v3_fl(mesh->indirect[a], 1.0f/count[a]); @@ -1747,7 +1747,7 @@ void make_occ_tree(Render *re) void free_occ(Render *re) { - if(re->occlusiontree) { + if (re->occlusiontree) { occ_free_tree(re->occlusiontree); re->occlusiontree = NULL; } @@ -1761,12 +1761,12 @@ void sample_occ(Render *re, ShadeInput *shi) OccFace exclude; int onlyshadow; - if(tree) { - if(shi->strand) { + if (tree) { + if (shi->strand) { sample_occ_surface(shi); } /* try to get result from the cache if possible */ - else if(shi->depth!=0 || !sample_occ_cache(tree, shi->co, shi->vno, shi->xs, shi->ys, shi->thread, shi->ao, shi->env, shi->indirect)) { + else if (shi->depth!=0 || !sample_occ_cache(tree, shi->co, shi->vno, shi->xs, shi->ys, shi->thread, shi->ao, shi->env, shi->indirect)) { /* no luck, let's sample the occlusion */ exclude.obi= shi->obi - re->objectinstance; exclude.facenr= shi->vlr->index; @@ -1774,10 +1774,10 @@ void sample_occ(Render *re, ShadeInput *shi) sample_occ_tree(re, tree, &exclude, shi->co, shi->vno, shi->thread, onlyshadow, shi->ao, shi->env, shi->indirect); /* fill result into sample, each time */ - if(tree->cache) { + if (tree->cache) { cache= &tree->cache[shi->thread]; - if(cache->sample && cache->step) { + if (cache->sample && cache->step) { sample= &cache->sample[(shi->ys-cache->y)*cache->w + (shi->xs-cache->x)]; copy_v3_v3(sample->co, shi->co); copy_v3_v3(sample->n, shi->vno); @@ -1820,7 +1820,7 @@ void cache_occ_samples(Render *re, RenderPart *pa, ShadeSample *ssamp) int *ro=NULL, *rp=NULL, *rz=NULL, onlyshadow; int x, y, step = CACHE_STEP; - if(!tree->cache) + if (!tree->cache) return; cache= &tree->cache[pa->thread]; @@ -1832,7 +1832,7 @@ void cache_occ_samples(Render *re, RenderPart *pa, ShadeSample *ssamp) cache->sample= MEM_callocN(sizeof(OcclusionCacheSample)*cache->w*cache->h, "OcclusionCacheSample"); sample= cache->sample; - if(re->osa) { + if (re->osa) { rd= pa->rectdaps; } else { @@ -1846,20 +1846,20 @@ void cache_occ_samples(Render *re, RenderPart *pa, ShadeSample *ssamp) } /* compute a sample at every step pixels */ - for(y=pa->disprect.ymin; y<pa->disprect.ymax; y++) { - for(x=pa->disprect.xmin; x<pa->disprect.xmax; x++, sample++, rd++, ro++, rp++, rz++) { - if(!(((x - pa->disprect.xmin + step) % step) == 0 || x == pa->disprect.xmax-1)) + for (y=pa->disprect.ymin; y<pa->disprect.ymax; y++) { + for (x=pa->disprect.xmin; x<pa->disprect.xmax; x++, sample++, rd++, ro++, rp++, rz++) { + if (!(((x - pa->disprect.xmin + step) % step) == 0 || x == pa->disprect.xmax-1)) continue; - if(!(((y - pa->disprect.ymin + step) % step) == 0 || y == pa->disprect.ymax-1)) + if (!(((y - pa->disprect.ymin + step) % step) == 0 || y == pa->disprect.ymax-1)) continue; - if(re->osa) { - if(!*rd) continue; + if (re->osa) { + if (!*rd) continue; shade_samples_fill_with_ps(ssamp, (PixStr *)(*rd), x, y); } else { - if(!*rp) continue; + if (!*rp) continue; ps.obi= *ro; ps.facenr= *rp; @@ -1868,7 +1868,7 @@ void cache_occ_samples(Render *re, RenderPart *pa, ShadeSample *ssamp) } shi= ssamp->shi; - if(shi->vlr) { + if (shi->vlr) { onlyshadow= (shi->mat->mode & MA_ONLYSHADOW); exclude.obi= shi->obi - re->objectinstance; exclude.facenr= shi->vlr->index; @@ -1888,7 +1888,7 @@ void cache_occ_samples(Render *re, RenderPart *pa, ShadeSample *ssamp) sample->filled= 1; } - if(re->test_break(re->tbh)) + if (re->test_break(re->tbh)) break; } } @@ -1899,10 +1899,10 @@ void free_occ_samples(Render *re, RenderPart *pa) OcclusionTree *tree= re->occlusiontree; OcclusionCache *cache; - if(tree->cache) { + if (tree->cache) { cache= &tree->cache[pa->thread]; - if(cache->sample) + if (cache->sample) MEM_freeN(cache->sample); cache->w= 0; diff --git a/source/blender/render/intern/source/pipeline.c b/source/blender/render/intern/source/pipeline.c index b2092f94af8..aa475e8aef0 100644 --- a/source/blender/render/intern/source/pipeline.c +++ b/source/blender/render/intern/source/pipeline.c @@ -158,16 +158,16 @@ static void stats_background(void *UNUSED(arg), RenderStats *rs) fprintf(stdout, "Fra:%d Mem:%.2fM (%.2fM, peak %.2fM) ", rs->cfra, megs_used_memory, mmap_used_memory, megs_peak_memory); - if(rs->curfield) + if (rs->curfield) fprintf(stdout, "Field %d ", rs->curfield); - if(rs->curblur) + if (rs->curblur) fprintf(stdout, "Blur %d ", rs->curblur); - if(rs->infostr) { + if (rs->infostr) { fprintf(stdout, "| %s", rs->infostr); } else { - if(rs->tothalo) + if (rs->tothalo) fprintf(stdout, "Sce: %s Ve:%d Fa:%d Ha:%d La:%d", rs->scenename, rs->totvert, rs->totface, rs->tothalo, rs->totlamp); else fprintf(stdout, "Sce: %s Ve:%d Fa:%d La:%d", rs->scenename, rs->totvert, rs->totface, rs->totlamp); @@ -188,8 +188,8 @@ float *RE_RenderLayerGetPass(RenderLayer *rl, int passtype) { RenderPass *rpass; - for(rpass=rl->passes.first; rpass; rpass= rpass->next) - if(rpass->passtype== passtype) + for (rpass=rl->passes.first; rpass; rpass= rpass->next) + if (rpass->passtype== passtype) return rpass->rect; return NULL; } @@ -198,10 +198,10 @@ RenderLayer *RE_GetRenderLayer(RenderResult *rr, const char *name) { RenderLayer *rl; - if(rr==NULL) return NULL; + if (rr==NULL) return NULL; - for(rl= rr->layers.first; rl; rl= rl->next) - if(strncmp(rl->name, name, RE_MAXNAME)==0) + for (rl= rr->layers.first; rl; rl= rl->next) + if (strncmp(rl->name, name, RE_MAXNAME)==0) return rl; return NULL; } @@ -215,7 +215,7 @@ RenderLayer *render_get_active_layer(Render *re, RenderResult *rr) { RenderLayer *rl= BLI_findlink(&rr->layers, re->r.actlay); - if(rl) + if (rl) return rl; else return rr->layers.first; @@ -225,9 +225,9 @@ static int render_scene_needs_vector(Render *re) { SceneRenderLayer *srl; - for(srl= re->scene->r.layers.first; srl; srl= srl->next) - if(!(srl->layflag & SCE_LAY_DISABLE)) - if(srl->passflag & SCE_PASS_VECTOR) + for (srl= re->scene->r.layers.first; srl; srl= srl->next) + if (!(srl->layflag & SCE_LAY_DISABLE)) + if (srl->passflag & SCE_PASS_VECTOR) return 1; return 0; @@ -240,8 +240,8 @@ Render *RE_GetRender(const char *name) Render *re; /* search for existing renders */ - for(re= RenderGlobal.renderlist.first; re; re= re->next) - if(strncmp(re->name, name, RE_MAXNAME)==0) + for (re= RenderGlobal.renderlist.first; re; re= re->next) + if (strncmp(re->name, name, RE_MAXNAME)==0) break; return re; @@ -250,7 +250,7 @@ Render *RE_GetRender(const char *name) /* if you want to know exactly what has been done */ RenderResult *RE_AcquireResultRead(Render *re) { - if(re) { + if (re) { BLI_rw_mutex_lock(&re->resultmutex, THREAD_LOCK_READ); return re->result; } @@ -260,7 +260,7 @@ RenderResult *RE_AcquireResultRead(Render *re) RenderResult *RE_AcquireResultWrite(Render *re) { - if(re) { + if (re) { BLI_rw_mutex_lock(&re->resultmutex, THREAD_LOCK_WRITE); return re->result; } @@ -271,7 +271,7 @@ RenderResult *RE_AcquireResultWrite(Render *re) void RE_SwapResult(Render *re, RenderResult **rr) { /* for keeping render buffers */ - if(re) { + if (re) { SWAP(RenderResult*, re->result, *rr); } } @@ -279,14 +279,14 @@ void RE_SwapResult(Render *re, RenderResult **rr) void RE_ReleaseResult(Render *re) { - if(re) + if (re) BLI_rw_mutex_unlock(&re->resultmutex); } /* displist.c util.... */ Scene *RE_GetScene(Render *re) { - if(re) + if (re) return re->scene; return NULL; } @@ -296,10 +296,10 @@ void RE_AcquireResultImage(Render *re, RenderResult *rr) { memset(rr, 0, sizeof(RenderResult)); - if(re) { + if (re) { BLI_rw_mutex_lock(&re->resultmutex, THREAD_LOCK_READ); - if(re->result) { + if (re->result) { RenderLayer *rl; rr->rectx= re->result->rectx; @@ -312,10 +312,10 @@ void RE_AcquireResultImage(Render *re, RenderResult *rr) /* active layer */ rl= render_get_active_layer(re, re->result); - if(rl) { - if(rr->rectf==NULL) + if (rl) { + if (rr->rectf==NULL) rr->rectf= rl->rectf; - if(rr->rectz==NULL) + if (rr->rectz==NULL) rr->rectz= RE_RenderLayerGetPass(rl, SCE_PASS_Z); } @@ -327,7 +327,7 @@ void RE_AcquireResultImage(Render *re, RenderResult *rr) void RE_ReleaseResultImage(Render *re) { - if(re) + if (re) BLI_rw_mutex_unlock(&re->resultmutex); } @@ -352,7 +352,7 @@ Render *RE_NewRender(const char *name) /* only one render per name exists */ re= RE_GetRender(name); - if(re==NULL) { + if (re==NULL) { /* new render data struct */ re= MEM_callocN(sizeof(Render), "new render"); @@ -379,7 +379,7 @@ void RE_InitRenderCB(Render *re) re->display_draw= result_rcti_nothing; re->progress= float_nothing; re->test_break= default_break; - if(G.background) + if (G.background) re->stats_draw= stats_background; else re->stats_draw= stats_nothing; @@ -424,7 +424,7 @@ void RE_InitState(Render *re, Render *source, RenderData *rd, SceneRenderLayer * re->winx= winx; re->winy= winy; - if(disprect) { + if (disprect) { re->disprect= *disprect; re->rectx= disprect->xmax-disprect->xmin; re->recty= disprect->ymax-disprect->ymin; @@ -437,18 +437,18 @@ void RE_InitState(Render *re, Render *source, RenderData *rd, SceneRenderLayer * re->recty= winy; } - if(re->rectx < 2 || re->recty < 2 || (BKE_imtype_is_movie(rd->im_format.imtype) && + if (re->rectx < 2 || re->recty < 2 || (BKE_imtype_is_movie(rd->im_format.imtype) && (re->rectx < 16 || re->recty < 16) )) { BKE_report(re->reports, RPT_ERROR, "Image too small"); re->ok= 0; return; } - if((re->r.mode & (R_OSA))==0) + if ((re->r.mode & (R_OSA))==0) re->r.scemode &= ~R_FULL_SAMPLE; #ifdef WITH_OPENEXR - if(re->r.scemode & R_FULL_SAMPLE) + if (re->r.scemode & R_FULL_SAMPLE) re->r.scemode |= R_EXR_TILE_FILE; /* enable automatic */ /* Until use_border is made compatible with save_buffers/full_sample, render without the later instead of not rendering at all.*/ @@ -462,18 +462,18 @@ void RE_InitState(Render *re, Render *source, RenderData *rd, SceneRenderLayer * #endif /* fullsample wants uniform osa levels */ - if(source && (re->r.scemode & R_FULL_SAMPLE)) { + if (source && (re->r.scemode & R_FULL_SAMPLE)) { /* but, if source has no full sample we disable it */ - if((source->r.scemode & R_FULL_SAMPLE)==0) + if ((source->r.scemode & R_FULL_SAMPLE)==0) re->r.scemode &= ~R_FULL_SAMPLE; else re->r.osa= re->osa= source->osa; } else { /* check state variables, osa? */ - if(re->r.mode & (R_OSA)) { + if (re->r.mode & (R_OSA)) { re->osa= re->r.osa; - if(re->osa>16) re->osa= 16; + if (re->osa>16) re->osa= 16; } else re->osa= 0; } @@ -492,8 +492,8 @@ void RE_InitState(Render *re, Render *source, RenderData *rd, SceneRenderLayer * /* if preview render, we try to keep old result */ BLI_rw_mutex_lock(&re->resultmutex, THREAD_LOCK_WRITE); - if(re->r.scemode & R_PREVIEWBUTS) { - if(re->result && re->result->rectx==re->rectx && re->result->recty==re->recty); + if (re->r.scemode & R_PREVIEWBUTS) { + if (re->result && re->result->rectx==re->rectx && re->result->recty==re->recty); else { render_result_free(re->result); re->result= NULL; @@ -606,7 +606,7 @@ void RE_AddObject(Render *UNUSED(re), Object *UNUSED(ob)) static int render_display_draw_enabled(Render *re) { /* don't show preprocess for previewrender sss */ - if(re->sss_points) + if (re->sss_points) return !(re->r.scemode & R_PREVIEWBUTS); else return 1; @@ -618,27 +618,27 @@ static void *do_part_thread(void *pa_v) RenderPart *pa= pa_v; /* need to return nicely all parts on esc */ - if(R.test_break(R.tbh)==0) { + if (R.test_break(R.tbh)==0) { - if(!R.sss_points && (R.r.scemode & R_FULL_SAMPLE)) + if (!R.sss_points && (R.r.scemode & R_FULL_SAMPLE)) pa->result= render_result_new_full_sample(&R, &pa->fullresult, &pa->disprect, pa->crop, RR_USE_MEM); else pa->result= render_result_new(&R, &pa->disprect, pa->crop, RR_USE_MEM); - if(R.sss_points) + if (R.sss_points) zbufshade_sss_tile(pa); - else if(R.osa) + else if (R.osa) zbufshadeDA_tile(pa); else zbufshade_tile(pa); /* merge too on break! */ - if(R.result->exrhandle) { + if (R.result->exrhandle) { render_result_exr_file_merge(R.result, pa->result); } - else if(render_display_draw_enabled(&R)) { + else if (render_display_draw_enabled(&R)) { /* on break, don't merge in result for preview renders, looks nicer */ - if(R.test_break(R.tbh) && (R.r.scemode & R_PREVIEWBUTS)); + if (R.test_break(R.tbh) && (R.r.scemode & R_PREVIEWBUTS)); else render_result_merge(R.result, pa->result); } } @@ -682,16 +682,16 @@ static RenderPart *find_next_pano_slice(Render *re, int *minx, rctf *viewplane) *minx= re->winx; /* most left part of the non-rendering parts */ - for(pa= re->parts.first; pa; pa= pa->next) { - if(pa->ready==0 && pa->nr==0) { - if(pa->disprect.xmin < *minx) { + for (pa= re->parts.first; pa; pa= pa->next) { + if (pa->ready==0 && pa->nr==0) { + if (pa->disprect.xmin < *minx) { best= pa; *minx= pa->disprect.xmin; } } } - if(best) { + if (best) { float phi= panorama_pixel_rot(re); R.panodxp= (re->winx - (best->disprect.xmin + best->disprect.xmax) )/2; @@ -720,8 +720,8 @@ static RenderPart *find_next_part(Render *re, int minx) long long int mindist= (long long int)re->winx * (long long int)re->winy; /* find center of rendered parts, image center counts for 1 too */ - for(pa= re->parts.first; pa; pa= pa->next) { - if(pa->ready) { + for (pa= re->parts.first; pa; pa= pa->next) { + if (pa->ready) { centx+= (pa->disprect.xmin+pa->disprect.xmax)/2; centy+= (pa->disprect.ymin+pa->disprect.ymax)/2; tot++; @@ -731,14 +731,14 @@ static RenderPart *find_next_part(Render *re, int minx) centy/=tot; /* closest of the non-rendering parts */ - for(pa= re->parts.first; pa; pa= pa->next) { - if(pa->ready==0 && pa->nr==0) { + for (pa= re->parts.first; pa; pa= pa->next) { + if (pa->ready==0 && pa->nr==0) { long long int distx= centx - (pa->disprect.xmin+pa->disprect.xmax)/2; long long int disty= centy - (pa->disprect.ymin+pa->disprect.ymax)/2; distx= (long long int)sqrt(distx*distx + disty*disty); - if(distx<mindist) { - if(re->r.mode & R_PANORAMA) { - if(pa->disprect.xmin==minx) { + if (distx<mindist) { + if (re->r.mode & R_PANORAMA) { + if (pa->disprect.xmin==minx) { best= pa; mindist= distx; } @@ -773,12 +773,12 @@ static void threaded_tile_processor(Render *re) BLI_rw_mutex_lock(&re->resultmutex, THREAD_LOCK_WRITE); /* first step; free the entire render result, make new, and/or prepare exr buffer saving */ - if(re->result==NULL || !(re->r.scemode & R_PREVIEWBUTS)) { + if (re->result==NULL || !(re->r.scemode & R_PREVIEWBUTS)) { render_result_free(re->result); - if(re->sss_points && render_display_draw_enabled(re)) + if (re->sss_points && render_display_draw_enabled(re)) re->result= render_result_new(re, &re->disprect, 0, RR_USE_MEM); - else if(re->r.scemode & R_FULL_SAMPLE) + else if (re->r.scemode & R_FULL_SAMPLE) re->result= render_result_new_full_sample(re, &re->fullresult, &re->disprect, 0, RR_USE_EXR); else re->result= render_result_new(re, &re->disprect, 0, @@ -787,14 +787,14 @@ static void threaded_tile_processor(Render *re) BLI_rw_mutex_unlock(&re->resultmutex); - if(re->result==NULL) + if (re->result==NULL) return; /* warning; no return here without closing exr file */ initparts(re); - if(re->result->exrhandle) + if (re->result->exrhandle) render_result_exr_file_begin(re); BLI_init_threads(&threads, do_part_thread, re->r.threads); @@ -806,16 +806,16 @@ static void threaded_tile_processor(Render *re) R.test_break= thread_break; /* timer loop demands to sleep when no parts are left, so we enter loop with a part */ - if(re->r.mode & R_PANORAMA) + if (re->r.mode & R_PANORAMA) nextpa= find_next_pano_slice(re, &minx, &viewplane); else nextpa= find_next_part(re, 0); while(rendering) { - if(re->test_break(re->tbh)) + if (re->test_break(re->tbh)) PIL_sleep_ms(50); - else if(nextpa && BLI_available_threads(&threads)) { + else if (nextpa && BLI_available_threads(&threads)) { drawtimer= 0; nextpa->nr= counter++; /* for nicest part, and for stats */ nextpa->thread= BLI_available_thread_index(&threads); /* sample index */ @@ -823,8 +823,8 @@ static void threaded_tile_processor(Render *re) nextpa= find_next_part(re, minx); } - else if(re->r.mode & R_PANORAMA) { - if(nextpa==NULL && BLI_available_threads(&threads)==re->r.threads) + else if (re->r.mode & R_PANORAMA) { + if (nextpa==NULL && BLI_available_threads(&threads)==re->r.threads) nextpa= find_next_pano_slice(re, &minx, &viewplane); else { PIL_sleep_ms(50); @@ -839,13 +839,13 @@ static void threaded_tile_processor(Render *re) /* check for ready ones to display, and if we need to continue */ rendering= 0; hasdrawn= 0; - for(pa= re->parts.first; pa; pa= pa->next) { - if(pa->ready) { + for (pa= re->parts.first; pa; pa= pa->next) { + if (pa->ready) { BLI_remove_thread(&threads, pa); - if(pa->result) { - if(render_display_draw_enabled(re)) + if (pa->result) { + if (render_display_draw_enabled(re)) re->display_draw(re->ddh, pa->result, NULL); print_part_stats(re, pa); @@ -858,23 +858,23 @@ static void threaded_tile_processor(Render *re) } else { rendering= 1; - if(pa->nr && pa->result && drawtimer>20) { - if(render_display_draw_enabled(re)) + if (pa->nr && pa->result && drawtimer>20) { + if (render_display_draw_enabled(re)) re->display_draw(re->ddh, pa->result, &pa->result->renrect); hasdrawn= 1; } } } - if(hasdrawn) + if (hasdrawn) drawtimer= 0; /* on break, wait for all slots to get freed */ - if( (g_break=re->test_break(re->tbh)) && BLI_available_threads(&threads)==re->r.threads) + if ( (g_break=re->test_break(re->tbh)) && BLI_available_threads(&threads)==re->r.threads) rendering= 0; } - if(re->result->exrhandle) { + if (re->result->exrhandle) { BLI_rw_mutex_lock(&re->resultmutex, THREAD_LOCK_WRITE); render_result_exr_file_end(re); BLI_rw_mutex_unlock(&re->resultmutex); @@ -899,7 +899,7 @@ void RE_TileProcessor(Render *re) static void do_render_3d(Render *re) { /* try external */ - if(RE_engine_render(re, 0)) + if (RE_engine_render(re, 0)) return; /* internal */ @@ -908,24 +908,24 @@ static void do_render_3d(Render *re) re->scene->r.subframe = re->mblur_offs + re->field_offs; /* lock drawing in UI during data phase */ - if(re->draw_lock) + if (re->draw_lock) re->draw_lock(re->dlh, 1); /* make render verts/faces/halos/lamps */ - if(render_scene_needs_vector(re)) + if (render_scene_needs_vector(re)) RE_Database_FromScene_Vectors(re, re->main, re->scene, re->lay); else RE_Database_FromScene(re, re->main, re->scene, re->lay, 1); /* clear UI drawing locks */ - if(re->draw_lock) + if (re->draw_lock) re->draw_lock(re->dlh, 0); threaded_tile_processor(re); /* do left-over 3d post effects (flares) */ - if(re->flag & R_HALO) - if(!re->test_break(re->tbh)) + if (re->flag & R_HALO) + if (!re->test_break(re->tbh)) add_halo_flare(re); /* free all render verts etc */ @@ -941,17 +941,17 @@ static void addblur_rect_key(RenderResult *rr, float *rectf, float *rectf1, floa int a, b, stride= 4*rr->rectx; int len= stride*sizeof(float); - for(a=0; a<rr->recty; a++) { - if(blurfac==1.0f) { + for (a=0; a<rr->recty; a++) { + if (blurfac==1.0f) { memcpy(rectf, rectf1, len); } else { float *rf= rectf, *rf1= rectf1; - for( b= rr->rectx; b>0; b--, rf+=4, rf1+=4) { - if(rf1[3]<0.01f) + for ( b= rr->rectx; b>0; b--, rf+=4, rf1+=4) { + if (rf1[3]<0.01f) rf[3]= mfac*rf[3]; - else if(rf[3]<0.01f) { + else if (rf[3]<0.01f) { rf[0]= rf1[0]; rf[1]= rf1[1]; rf[2]= rf1[2]; @@ -977,14 +977,14 @@ static void addblur_rect(RenderResult *rr, float *rectf, float *rectf1, float bl int a, b, stride= channels*rr->rectx; int len= stride*sizeof(float); - for(a=0; a<rr->recty; a++) { - if(blurfac==1.0f) { + for (a=0; a<rr->recty; a++) { + if (blurfac==1.0f) { memcpy(rectf, rectf1, len); } else { float *rf= rectf, *rf1= rectf1; - for( b= rr->rectx*channels; b>0; b--, rf++, rf1++) { + for ( b= rr->rectx*channels; b>0; b--, rf++, rf1++) { rf[0]= mfac*rf[0] + blurfac*rf1[0]; } } @@ -1001,11 +1001,11 @@ static void merge_renderresult_blur(RenderResult *rr, RenderResult *brr, float b RenderPass *rpass, *rpass1; rl1= brr->layers.first; - for(rl= rr->layers.first; rl && rl1; rl= rl->next, rl1= rl1->next) { + for (rl= rr->layers.first; rl && rl1; rl= rl->next, rl1= rl1->next) { /* combined */ - if(rl->rectf && rl1->rectf) { - if(key_alpha) + if (rl->rectf && rl1->rectf) { + if (key_alpha) addblur_rect_key(rr, rl->rectf, rl1->rectf, blurfac); else addblur_rect(rr, rl->rectf, rl1->rectf, blurfac, 4); @@ -1013,7 +1013,7 @@ static void merge_renderresult_blur(RenderResult *rr, RenderResult *brr, float b /* passes are allocated in sync */ rpass1= rl1->passes.first; - for(rpass= rl->passes.first; rpass && rpass1; rpass= rpass->next, rpass1= rpass1->next) { + for (rpass= rl->passes.first; rpass && rpass1; rpass= rpass->next, rpass1= rpass1->next) { addblur_rect(rr, rpass->rect, rpass1->rect, blurfac, rpass->channels); } } @@ -1040,7 +1040,7 @@ static void do_render_blur_3d(Render *re) blurfac= 1.0f/(float)(re->r.mblur_samples-blur); merge_renderresult_blur(rres, re->result, blurfac, re->r.alphamode & R_ALPHAKEY); - if(re->test_break(re->tbh)) break; + if (re->test_break(re->tbh)) break; } /* swap results */ @@ -1064,7 +1064,7 @@ static void interleave_rect(RenderResult *rr, float *rectf, float *rectf1, float int a, stride= channels*rr->rectx; int len= stride*sizeof(float); - for(a=0; a<rr->recty; a+=2) { + for (a=0; a<rr->recty; a+=2) { memcpy(rectf, rectf1, len); rectf+= stride; rectf1+= stride; @@ -1082,16 +1082,16 @@ static void merge_renderresult_fields(RenderResult *rr, RenderResult *rr1, Rende rl1= rr1->layers.first; rl2= rr2->layers.first; - for(rl= rr->layers.first; rl && rl1 && rl2; rl= rl->next, rl1= rl1->next, rl2= rl2->next) { + for (rl= rr->layers.first; rl && rl1 && rl2; rl= rl->next, rl1= rl1->next, rl2= rl2->next) { /* combined */ - if(rl->rectf && rl1->rectf && rl2->rectf) + if (rl->rectf && rl1->rectf && rl2->rectf) interleave_rect(rr, rl->rectf, rl1->rectf, rl2->rectf, 4); /* passes are allocated in sync */ rpass1= rl1->passes.first; rpass2= rl2->passes.first; - for(rpass= rl->passes.first; rpass && rpass1 && rpass2; rpass= rpass->next, rpass1= rpass1->next, rpass2= rpass2->next) { + for (rpass= rl->passes.first; rpass && rpass1 && rpass2; rpass= rpass->next, rpass1= rpass1->next, rpass2= rpass2->next) { interleave_rect(rr, rpass->rect, rpass1->rect, rpass2->rect, rpass->channels); } } @@ -1114,7 +1114,7 @@ static void do_render_fields_3d(Render *re) /* first field, we have to call camera routine for correct aspect and subpixel offset */ RE_SetCamera(re, camera); - if(re->r.mode & R_MBLUR && (re->r.scemode & R_FULL_SAMPLE)==0) + if (re->r.mode & R_MBLUR && (re->r.scemode & R_FULL_SAMPLE)==0) do_render_blur_3d(re); else do_render_3d(re); @@ -1125,16 +1125,16 @@ static void do_render_fields_3d(Render *re) BLI_rw_mutex_unlock(&re->resultmutex); /* second field */ - if(!re->test_break(re->tbh)) { + if (!re->test_break(re->tbh)) { re->i.curfield= 2; /* stats */ re->flag |= R_SEC_FIELD; - if((re->r.mode & R_FIELDSTILL)==0) { + if ((re->r.mode & R_FIELDSTILL)==0) { re->field_offs = 0.5f; } RE_SetCamera(re, camera); - if(re->r.mode & R_MBLUR && (re->r.scemode & R_FULL_SAMPLE)==0) + if (re->r.mode & R_MBLUR && (re->r.scemode & R_FULL_SAMPLE)==0) do_render_blur_3d(re); else do_render_3d(re); @@ -1154,8 +1154,8 @@ static void do_render_fields_3d(Render *re) BLI_rw_mutex_lock(&re->resultmutex, THREAD_LOCK_WRITE); re->result= render_result_new(re, &re->disprect, 0, RR_USE_MEM); - if(rr2) { - if(re->r.mode & R_ODDFIELD) + if (rr2) { + if (re->r.mode & R_ODDFIELD) merge_renderresult_fields(re->result, rr2, rr1); else merge_renderresult_fields(re->result, rr1, rr2); @@ -1180,7 +1180,7 @@ static void do_render_fields_blur_3d(Render *re) { Object *camera= RE_GetCamera(re); /* also check for camera here */ - if(camera == NULL) { + if (camera == NULL) { printf("ERROR: Cannot render, no camera\n"); G.afbreek= 1; return; @@ -1189,17 +1189,17 @@ static void do_render_fields_blur_3d(Render *re) /* now use renderdata and camera to set viewplane */ RE_SetCamera(re, camera); - if(re->r.mode & R_FIELDS) + if (re->r.mode & R_FIELDS) do_render_fields_3d(re); - else if(re->r.mode & R_MBLUR && (re->r.scemode & R_FULL_SAMPLE)==0) + else if (re->r.mode & R_MBLUR && (re->r.scemode & R_FULL_SAMPLE)==0) do_render_blur_3d(re); else do_render_3d(re); /* when border render, check if we have to insert it in black */ - if(re->result) { - if(re->r.mode & R_BORDER) { - if((re->r.mode & R_CROP)==0) { + if (re->result) { + if (re->r.mode & R_BORDER) { + if ((re->r.mode & R_CROP)==0) { RenderResult *rres; BLI_rw_mutex_lock(&re->resultmutex, THREAD_LOCK_WRITE); @@ -1252,7 +1252,7 @@ static void render_scene(Render *re, Scene *sce, int cfra) scene_camera_switch_update(sce); /* exception: scene uses own size (unfinished code) */ - if(0) { + if (0) { winx= (sce->r.size*sce->r.xsch)/100; winy= (sce->r.size*sce->r.ysch)/100; } @@ -1285,13 +1285,13 @@ static int composite_needs_render(Scene *sce, int this_scene) bNodeTree *ntree= sce->nodetree; bNode *node; - if(ntree==NULL) return 1; - if(sce->use_nodes==0) return 1; - if((sce->r.scemode & R_DOCOMP)==0) return 1; + if (ntree==NULL) return 1; + if (sce->use_nodes==0) return 1; + if ((sce->r.scemode & R_DOCOMP)==0) return 1; - for(node= ntree->nodes.first; node; node= node->next) { - if(node->type==CMP_NODE_R_LAYERS) - if(this_scene==0 || node->id==NULL || node->id==&sce->id) + for (node= ntree->nodes.first; node; node= node->next) { + if (node->type==CMP_NODE_R_LAYERS) + if (this_scene==0 || node->id==NULL || node->id==&sce->id) return 1; } return 0; @@ -1302,19 +1302,19 @@ static void tag_scenes_for_render(Render *re) bNode *node; Scene *sce; - for(sce= re->main->scene.first; sce; sce= sce->id.next) + for (sce= re->main->scene.first; sce; sce= sce->id.next) sce->id.flag &= ~LIB_DOIT; - if(RE_GetCamera(re) && composite_needs_render(re->scene, 1)) + if (RE_GetCamera(re) && composite_needs_render(re->scene, 1)) re->scene->id.flag |= LIB_DOIT; - if(re->scene->nodetree==NULL) return; + if (re->scene->nodetree==NULL) return; /* check for render-layers nodes using other scenes, we tag them LIB_DOIT */ - for(node= re->scene->nodetree->nodes.first; node; node= node->next) { - if(node->type==CMP_NODE_R_LAYERS) { - if(node->id) { - if(node->id != (ID *)re->scene) + for (node= re->scene->nodetree->nodes.first; node; node= node->next) { + if (node->type==CMP_NODE_R_LAYERS) { + if (node->id) { + if (node->id != (ID *)re->scene) node->id->flag |= LIB_DOIT; } } @@ -1328,16 +1328,16 @@ static void ntree_render_scenes(Render *re) int cfra= re->scene->r.cfra; int restore_scene= 0; - if(re->scene->nodetree==NULL) return; + if (re->scene->nodetree==NULL) return; tag_scenes_for_render(re); /* now foreach render-result node tagged we do a full render */ /* results are stored in a way compisitor will find it */ - for(node= re->scene->nodetree->nodes.first; node; node= node->next) { - if(node->type==CMP_NODE_R_LAYERS) { - if(node->id && node->id != (ID *)re->scene) { - if(node->id->flag & LIB_DOIT) { + for (node= re->scene->nodetree->nodes.first; node; node= node->next) { + if (node->type==CMP_NODE_R_LAYERS) { + if (node->id && node->id != (ID *)re->scene) { + if (node->id->flag & LIB_DOIT) { Scene *scene = (Scene*)node->id; render_scene(re, scene, cfra); @@ -1351,7 +1351,7 @@ static void ntree_render_scenes(Render *re) } /* restore scene if we rendered another last */ - if(restore_scene) + if (restore_scene) set_scene_bg(re->main, re->scene); } @@ -1371,7 +1371,7 @@ static void do_merge_fullsample(Render *re, bNodeTree *ntree) int sample; /* interaction callbacks */ - if(ntree) { + if (ntree) { ntree->stats_draw= render_composit_stats; ntree->test_break= re->test_break; ntree->progress= re->progress; @@ -1386,7 +1386,7 @@ static void do_merge_fullsample(Render *re, bNodeTree *ntree) /* we accumulate in here */ rectf= MEM_mapallocN(re->rectx*re->recty*sizeof(float)*4, "fullsample rgba"); - for(sample=0; sample<re->r.osa; sample++) { + for (sample=0; sample<re->r.osa; sample++) { Render *re1; RenderResult rres; int x, y, mask; @@ -1398,10 +1398,10 @@ static void do_merge_fullsample(Render *re, bNodeTree *ntree) /* also function below assumes this */ tag_scenes_for_render(re); - for(re1= RenderGlobal.renderlist.first; re1; re1= re1->next) { - if(re1->scene->id.flag & LIB_DOIT) { - if(re1->r.scemode & R_FULL_SAMPLE) { - if(sample) { + for (re1= RenderGlobal.renderlist.first; re1; re1= re1->next) { + if (re1->scene->id.flag & LIB_DOIT) { + if (re1->r.scemode & R_FULL_SAMPLE) { + if (sample) { BLI_rw_mutex_lock(&re->resultmutex, THREAD_LOCK_WRITE); render_result_exr_file_read(re1, sample); BLI_rw_mutex_unlock(&re->resultmutex); @@ -1412,7 +1412,7 @@ static void do_merge_fullsample(Render *re, bNodeTree *ntree) } /* composite */ - if(ntree) { + if (ntree) { ntreeCompositTagRender(re->scene); ntreeCompositTagAnimated(ntree); @@ -1426,15 +1426,15 @@ static void do_merge_fullsample(Render *re, bNodeTree *ntree) mask= (1<<sample); mask_array(mask, filt); - for(y=0; y<re->recty; y++) { + for (y=0; y<re->recty; y++) { float *rf= rectf + 4*y*re->rectx; float *col= rres.rectf + 4*y*re->rectx; - for(x=0; x<re->rectx; x++, rf+=4, col+=4) { + for (x=0; x<re->rectx; x++, rf+=4, col+=4) { /* clamping to 1.0 is needed for correct AA */ - if(col[0]<0.0f) col[0]=0.0f; else if(col[0] > 1.0f) col[0]= 1.0f; - if(col[1]<0.0f) col[1]=0.0f; else if(col[1] > 1.0f) col[1]= 1.0f; - if(col[2]<0.0f) col[2]=0.0f; else if(col[2] > 1.0f) col[2]= 1.0f; + if (col[0]<0.0f) col[0]=0.0f; else if (col[0] > 1.0f) col[0]= 1.0f; + if (col[1]<0.0f) col[1]=0.0f; else if (col[1] > 1.0f) col[1]= 1.0f; + if (col[2]<0.0f) col[2]=0.0f; else if (col[2] > 1.0f) col[2]= 1.0f; add_filt_fmask_coord(filt, col, rf, re->rectx, re->recty, x, y); } @@ -1443,18 +1443,18 @@ static void do_merge_fullsample(Render *re, bNodeTree *ntree) RE_ReleaseResultImage(re); /* show stuff */ - if(sample!=re->osa-1) { + if (sample!=re->osa-1) { /* weak... the display callback wants an active renderlayer pointer... */ re->result->renlay= render_get_active_layer(re, re->result); re->display_draw(re->ddh, re->result, NULL); } - if(re->test_break(re->tbh)) + if (re->test_break(re->tbh)) break; } /* clear interaction callbacks */ - if(ntree) { + if (ntree) { ntree->stats_draw= NULL; ntree->test_break= NULL; ntree->progress= NULL; @@ -1465,7 +1465,7 @@ static void do_merge_fullsample(Render *re, bNodeTree *ntree) R.i.curfsa= 0; BLI_rw_mutex_lock(&re->resultmutex, THREAD_LOCK_WRITE); - if(re->result->rectf) + if (re->result->rectf) MEM_freeN(re->result->rectf); re->result->rectf= rectf; BLI_rw_mutex_unlock(&re->resultmutex); @@ -1486,15 +1486,15 @@ void RE_MergeFullSample(Render *re, Main *bmain, Scene *sce, bNodeTree *ntree) /* first call RE_ReadRenderResult on every renderlayer scene. this creates Render structs */ /* tag scenes unread */ - for(scene= re->main->scene.first; scene; scene= scene->id.next) + for (scene= re->main->scene.first; scene; scene= scene->id.next) scene->id.flag |= LIB_DOIT; - for(node= ntree->nodes.first; node; node= node->next) { - if(node->type==CMP_NODE_R_LAYERS) { + for (node= ntree->nodes.first; node; node= node->next) { + if (node->type==CMP_NODE_R_LAYERS) { Scene *nodescene= (Scene *)node->id; - if(nodescene==NULL) nodescene= sce; - if(nodescene->id.flag & LIB_DOIT) { + if (nodescene==NULL) nodescene= sce; + if (nodescene->id.flag & LIB_DOIT) { nodescene->r.mode |= R_OSA; /* render struct needs tables */ RE_ReadRenderResult(sce, nodescene); nodescene->id.flag &= ~LIB_DOIT; @@ -1503,7 +1503,7 @@ void RE_MergeFullSample(Render *re, Main *bmain, Scene *sce, bNodeTree *ntree) } /* own render result should be read/allocated */ - if(re->scene->id.flag & LIB_DOIT) { + if (re->scene->id.flag & LIB_DOIT) { RE_ReadRenderResult(re->scene, re->scene); re->scene->id.flag &= ~LIB_DOIT; } @@ -1524,7 +1524,7 @@ static void do_render_composite_fields_blur_3d(Render *re) /* INIT seeding, compositor can use random texture */ BLI_srandom(re->r.cfra); - if(composite_needs_render(re->scene, 1)) { + if (composite_needs_render(re->scene, 1)) { /* save memory... free all cached images */ ntreeFreeCache(ntree); @@ -1544,25 +1544,25 @@ static void do_render_composite_fields_blur_3d(Render *re) } /* swap render result */ - if(re->r.scemode & R_SINGLE_LAYER) { + if (re->r.scemode & R_SINGLE_LAYER) { BLI_rw_mutex_lock(&re->resultmutex, THREAD_LOCK_WRITE); render_result_single_layer_end(re); BLI_rw_mutex_unlock(&re->resultmutex); } - if(!re->test_break(re->tbh)) { + if (!re->test_break(re->tbh)) { - if(ntree) { + if (ntree) { ntreeCompositTagRender(re->scene); ntreeCompositTagAnimated(ntree); } - if(ntree && re->scene->use_nodes && re->r.scemode & R_DOCOMP) { + if (ntree && re->scene->use_nodes && re->r.scemode & R_DOCOMP) { /* checks if there are render-result nodes that need scene */ - if((re->r.scemode & R_SINGLE_LAYER)==0) + if ((re->r.scemode & R_SINGLE_LAYER)==0) ntree_render_scenes(re); - if(!re->test_break(re->tbh)) { + if (!re->test_break(re->tbh)) { ntree->stats_draw= render_composit_stats; ntree->test_break= re->test_break; ntree->progress= re->progress; @@ -1577,7 +1577,7 @@ static void do_render_composite_fields_blur_3d(Render *re) if (update_newframe) scene_update_for_newframe(re->main, re->scene, re->lay); - if(re->r.scemode & R_FULL_SAMPLE) + if (re->r.scemode & R_FULL_SAMPLE) do_merge_fullsample(re, ntree); else { ntreeCompositExecTree(ntree, &re->r, G.background==0); @@ -1589,7 +1589,7 @@ static void do_render_composite_fields_blur_3d(Render *re) ntree->tbh= ntree->sdh= ntree->prh= NULL; } } - else if(re->r.scemode & R_FULL_SAMPLE) + else if (re->r.scemode & R_FULL_SAMPLE) do_merge_fullsample(re, NULL); } @@ -1636,20 +1636,21 @@ static void do_render_seq(Render * re) re->i.cfra= cfra; - if(recurs_depth==0) { + if (recurs_depth==0) { /* otherwise sequencer animation isn't updated */ BKE_animsys_evaluate_all_animation(re->main, re->scene, (float)cfra); // XXX, was BKE_curframe(re->scene) } recurs_depth++; - if((re->r.mode & R_BORDER) && (re->r.mode & R_CROP)==0) { + if ((re->r.mode & R_BORDER) && (re->r.mode & R_CROP)==0) { /* if border rendering is used and cropping is disabled, final buffer should * be as large as the whole frame */ context = seq_new_render_data(re->main, re->scene, re->winx, re->winy, 100); - } else { + } + else { context = seq_new_render_data(re->main, re->scene, re->result->rectx, re->result->recty, 100); @@ -1663,7 +1664,7 @@ static void do_render_seq(Render * re) BLI_rw_mutex_lock(&re->resultmutex, THREAD_LOCK_WRITE); - if(ibuf) { + if (ibuf) { /* copy ibuf into combined pixel rect */ render_result_rect_from_ibuf(rr, &re->r, ibuf); @@ -1685,7 +1686,7 @@ static void do_render_seq(Render * re) re->r.scemode |= R_DOSEQ; /* set overall progress of sequence rendering */ - if(re->r.efra!=re->r.sfra) + if (re->r.efra!=re->r.sfra) re->progress(re->prh, (float)(cfra-re->r.sfra) / (re->r.efra-re->r.sfra)); else re->progress(re->prh, 1.0f); @@ -1703,12 +1704,12 @@ static void do_render_all_options(Render *re) /* ensure no images are in memory from previous animated sequences */ BKE_image_all_free_anim_ibufs(re->r.cfra); - if(RE_engine_render(re, 1)) { + if (RE_engine_render(re, 1)) { /* in this case external render overrides all */ } - else if(RE_seq_render_active(re->scene, &re->r)) { + else if (RE_seq_render_active(re->scene, &re->r)) { /* note: do_render_seq() frees rect32 when sequencer returns float images */ - if(!re->test_break(re->tbh)) + if (!re->test_break(re->tbh)) do_render_seq(re); re->stats_draw(re->sdh, &re->i); @@ -1723,7 +1724,7 @@ static void do_render_all_options(Render *re) re->stats_draw(re->sdh, &re->i); /* stamp image info here */ - if((re->r.stamp & R_STAMP_ALL) && (re->r.stamp & R_STAMP_DRAW)) { + if ((re->r.stamp & R_STAMP_ALL) && (re->r.stamp & R_STAMP_DRAW)) { renderresult_stampinfo(re); re->display_draw(re->ddh, re->result, NULL); } @@ -1736,20 +1737,21 @@ static int check_valid_camera(Scene *scene, Object *camera_override) if (camera_override == NULL && scene->camera == NULL) scene->camera= scene_find_camera(scene); - if(scene->r.scemode&R_DOSEQ) { - if(scene->ed) { + if (scene->r.scemode&R_DOSEQ) { + if (scene->ed) { Sequence *seq= scene->ed->seqbase.first; check_comp= 0; while(seq) { - if(seq->type == SEQ_SCENE && seq->scene) { - if(!seq->scene_camera) { - if(!seq->scene->camera && !scene_find_camera(seq->scene)) { - if(seq->scene == scene) { + if (seq->type == SEQ_SCENE && seq->scene) { + if (!seq->scene_camera) { + if (!seq->scene->camera && !scene_find_camera(seq->scene)) { + if (seq->scene == scene) { /* for current scene camera could be unneeded due to compisite nodes */ check_comp= 1; - } else { + } + else { /* for other scenes camera is necessary */ return 0; } @@ -1762,15 +1764,15 @@ static int check_valid_camera(Scene *scene, Object *camera_override) } } - if(check_comp) { /* no sequencer or sequencer depends on compositor */ - if(scene->r.scemode&R_DOCOMP && scene->use_nodes) { + if (check_comp) { /* no sequencer or sequencer depends on compositor */ + if (scene->r.scemode&R_DOCOMP && scene->use_nodes) { bNode *node= scene->nodetree->nodes.first; while(node) { - if(node->type == CMP_NODE_R_LAYERS) { + if (node->type == CMP_NODE_R_LAYERS) { Scene *sce= node->id ? (Scene*)node->id : scene; - if(!sce->camera && !scene_find_camera(sce)) { + if (!sce->camera && !scene_find_camera(sce)) { /* all render layers nodes need camera */ return 0; } @@ -1778,7 +1780,8 @@ static int check_valid_camera(Scene *scene, Object *camera_override) node= node->next; } - } else { + } + else { return (camera_override != NULL || scene->camera != NULL); } } @@ -1790,15 +1793,15 @@ int RE_is_rendering_allowed(Scene *scene, Object *camera_override, ReportList *r { SceneRenderLayer *srl; - if(scene->r.mode & R_BORDER) { - if(scene->r.border.xmax <= scene->r.border.xmin || + if (scene->r.mode & R_BORDER) { + if (scene->r.border.xmax <= scene->r.border.xmin || scene->r.border.ymax <= scene->r.border.ymin) { BKE_report(reports, RPT_ERROR, "No border area selected."); return 0; } } - if(scene->r.scemode & (R_EXR_TILE_FILE|R_FULL_SAMPLE)) { + if (scene->r.scemode & (R_EXR_TILE_FILE|R_FULL_SAMPLE)) { char str[FILE_MAX]; render_result_exr_file_path(scene, 0, str); @@ -1809,7 +1812,7 @@ int RE_is_rendering_allowed(Scene *scene, Object *camera_override, ReportList *r } /* no fullsample and edge */ - if((scene->r.scemode & R_FULL_SAMPLE) && (scene->r.mode & R_EDGE)) { + if ((scene->r.scemode & R_FULL_SAMPLE) && (scene->r.mode & R_EDGE)) { BKE_report(reports, RPT_ERROR, "Full Sample doesn't support Edge Enhance"); return 0; } @@ -1818,27 +1821,27 @@ int RE_is_rendering_allowed(Scene *scene, Object *camera_override, ReportList *r else scene->r.scemode &= ~R_FULL_SAMPLE; /* clear to be sure */ - if(scene->r.scemode & R_DOCOMP) { - if(scene->use_nodes) { + if (scene->r.scemode & R_DOCOMP) { + if (scene->use_nodes) { bNodeTree *ntree= scene->nodetree; bNode *node; - if(ntree==NULL) { + if (ntree==NULL) { BKE_report(reports, RPT_ERROR, "No Nodetree in Scene"); return 0; } - for(node= ntree->nodes.first; node; node= node->next) - if(node->type==CMP_NODE_COMPOSITE) + for (node= ntree->nodes.first; node; node= node->next) + if (node->type==CMP_NODE_COMPOSITE) break; - if(node==NULL) { + if (node==NULL) { BKE_report(reports, RPT_ERROR, "No Render Output Node in Scene"); return 0; } - if(scene->r.scemode & R_FULL_SAMPLE) { - if(composite_needs_render(scene, 0)==0) { + if (scene->r.scemode & R_FULL_SAMPLE) { + if (composite_needs_render(scene, 0)==0) { BKE_report(reports, RPT_ERROR, "Full Sample AA not supported without 3d rendering"); return 0; } @@ -1847,7 +1850,7 @@ int RE_is_rendering_allowed(Scene *scene, Object *camera_override, ReportList *r } /* check valid camera, without camera render is OK (compo, seq) */ - if(!check_valid_camera(scene, camera_override)) { + if (!check_valid_camera(scene, camera_override)) { BKE_report(reports, RPT_ERROR, "No camera"); return 0; } @@ -1856,24 +1859,24 @@ int RE_is_rendering_allowed(Scene *scene, Object *camera_override, ReportList *r object_camera_mode(&scene->r, camera_override ? camera_override : scene->camera); /* forbidden combinations */ - if(scene->r.mode & R_PANORAMA) { - if(scene->r.mode & R_ORTHO) { + if (scene->r.mode & R_PANORAMA) { + if (scene->r.mode & R_ORTHO) { BKE_report(reports, RPT_ERROR, "No Ortho render possible for Panorama"); return 0; } } /* layer flag tests */ - if(scene->r.scemode & R_SINGLE_LAYER) { + if (scene->r.scemode & R_SINGLE_LAYER) { srl= BLI_findlink(&scene->r.layers, scene->r.actlay); /* force layer to be enabled */ srl->layflag &= ~SCE_LAY_DISABLE; } - for(srl= scene->r.layers.first; srl; srl= srl->next) - if(!(srl->layflag & SCE_LAY_DISABLE)) + for (srl= scene->r.layers.first; srl; srl= srl->next) + if (!(srl->layflag & SCE_LAY_DISABLE)) break; - if(srl==NULL) { + if (srl==NULL) { BKE_report(reports, RPT_ERROR, "All RenderLayers are disabled"); return 0; } @@ -1883,13 +1886,14 @@ int RE_is_rendering_allowed(Scene *scene, Object *camera_override, ReportList *r static void validate_render_settings(Render *re) { - if(re->r.scemode & (R_EXR_TILE_FILE|R_FULL_SAMPLE)) { + if (re->r.scemode & (R_EXR_TILE_FILE|R_FULL_SAMPLE)) { /* no osa + fullsample won't work... */ - if(re->r.osa==0) + if (re->r.osa==0) re->r.scemode &= ~R_FULL_SAMPLE; - } else re->r.scemode &= ~R_FULL_SAMPLE; /* clear to be sure */ + } + else re->r.scemode &= ~R_FULL_SAMPLE; /* clear to be sure */ - if(RE_engine_is_external(re)) { + if (RE_engine_is_external(re)) { /* not supported yet */ re->r.scemode &= ~(R_EXR_TILE_FILE|R_FULL_SAMPLE); re->r.mode &= ~(R_FIELDS|R_MBLUR); @@ -1927,7 +1931,7 @@ static int render_initialize_from_main(Render *re, Main *bmain, Scene *scene, Sc winy= (scene->r.size*scene->r.ysch)/100; /* we always render smaller part, inserting it in larger image is compositor bizz, it uses disprect for it */ - if(scene->r.mode & R_BORDER) { + if (scene->r.mode & R_BORDER) { disprect.xmin = scene->r.border.xmin*winx; disprect.xmax = scene->r.border.xmax*winx; @@ -1946,7 +1950,7 @@ static int render_initialize_from_main(Render *re, Main *bmain, Scene *scene, Sc re->lay= lay; /* not too nice, but it survives anim-border render */ - if(anim) { + if (anim) { re->disprect= disprect; return 1; } @@ -1959,19 +1963,19 @@ static int render_initialize_from_main(Render *re, Main *bmain, Scene *scene, Sc * can be later set as render profile option * and default for background render. */ - if(0) { + if (0) { /* make sure dynamics are up to date */ update_physics_cache(re, scene, anim_init); } - if(srl || scene->r.scemode & R_SINGLE_LAYER) { + if (srl || scene->r.scemode & R_SINGLE_LAYER) { BLI_rw_mutex_lock(&re->resultmutex, THREAD_LOCK_WRITE); render_result_single_layer_begin(re); BLI_rw_mutex_unlock(&re->resultmutex); } RE_InitState(re, NULL, &scene->r, srl, winx, winy, &disprect); - if(!re->ok) /* if an error was printed, abort */ + if (!re->ok) /* if an error was printed, abort */ return 0; /* initstate makes new result, have to send changed tags around */ @@ -1998,15 +2002,15 @@ void RE_BlenderFrame(Render *re, Main *bmain, Scene *scene, SceneRenderLayer *sr scene->r.cfra= frame; - if(render_initialize_from_main(re, bmain, scene, srl, camera_override, lay, 0, 0)) { + if (render_initialize_from_main(re, bmain, scene, srl, camera_override, lay, 0, 0)) { MEM_reset_peak_memory(); BLI_exec_cb(re->main, (ID *)scene, BLI_CB_EVT_RENDER_PRE); do_render_all_options(re); - if(write_still && !G.afbreek) { - if(BKE_imtype_is_movie(scene->r.im_format.imtype)) { + if (write_still && !G.afbreek) { + if (BKE_imtype_is_movie(scene->r.im_format.imtype)) { /* operator checks this but in case its called from elsewhere */ printf("Error: cant write single images with a movie format!\n"); } @@ -2038,11 +2042,11 @@ static int do_write_image_or_movie(Render *re, Main *bmain, Scene *scene, bMovie RE_AcquireResultImage(re, &rres); /* write movie or image */ - if(BKE_imtype_is_movie(scene->r.im_format.imtype)) { + if (BKE_imtype_is_movie(scene->r.im_format.imtype)) { int dofree = 0; unsigned int *rect32 = (unsigned int *)rres.rect32; /* note; the way it gets 32 bits rects is weak... */ - if(rres.rect32 == NULL) { + if (rres.rect32 == NULL) { rect32 = MEM_mapallocN(sizeof(int)*rres.rectx*rres.recty, "temp 32 bits rect"); RE_ResultGet32(re, rect32); dofree = 1; @@ -2050,19 +2054,19 @@ static int do_write_image_or_movie(Render *re, Main *bmain, Scene *scene, bMovie ok= mh->append_movie(&re->r, scene->r.sfra, scene->r.cfra, (int *)rect32, rres.rectx, rres.recty, re->reports); - if(dofree) { + if (dofree) { MEM_freeN(rect32); } printf("Append frame %d", scene->r.cfra); } else { - if(name_override) + if (name_override) BLI_strncpy(name, name_override, sizeof(name)); else BKE_makepicstring(name, scene->r.pic, bmain->name, scene->r.cfra, scene->r.im_format.imtype, scene->r.scemode & R_EXTENSION, TRUE); - if(re->r.im_format.imtype==R_IMF_IMTYPE_MULTILAYER) { - if(re->result) { + if (re->r.im_format.imtype==R_IMF_IMTYPE_MULTILAYER) { + if (re->result) { RE_WriteRenderResult(re->reports, re->result, name, scene->r.im_format.exr_codec); printf("Saved: %s", name); } @@ -2072,17 +2076,17 @@ static int do_write_image_or_movie(Render *re, Main *bmain, Scene *scene, bMovie ok= BKE_write_ibuf_stamp(scene, camera, ibuf, name, &scene->r.im_format); - if(ok==0) { + if (ok==0) { printf("Render error: cannot save %s\n", name); } else printf("Saved: %s", name); /* optional preview images for exr */ - if(ok && scene->r.im_format.imtype==R_IMF_IMTYPE_OPENEXR && (scene->r.im_format.flag & R_IMF_FLAG_PREVIEW_JPG)) { + if (ok && scene->r.im_format.imtype==R_IMF_IMTYPE_OPENEXR && (scene->r.im_format.flag & R_IMF_FLAG_PREVIEW_JPG)) { ImageFormatData imf= scene->r.im_format; imf.imtype= R_IMF_IMTYPE_JPEG90; - if(BLI_testextensie(name, ".exr")) + if (BLI_testextensie(name, ".exr")) name[strlen(name)-4]= 0; BKE_add_image_extension(name, R_IMF_IMTYPE_JPEG90); ibuf->planes= 24; @@ -2116,7 +2120,7 @@ void RE_BlenderAnim(Render *re, Main *bmain, Scene *scene, Object *camera_overri int nfra, totrendered= 0, totskipped= 0; /* do not fully call for each frame, it initializes & pops output window */ - if(!render_initialize_from_main(re, bmain, scene, NULL, camera_override, lay, 0, 1)) + if (!render_initialize_from_main(re, bmain, scene, NULL, camera_override, lay, 0, 1)) return; /* ugly global still... is to prevent renderwin events and signal subsurfs etc to make full resol */ @@ -2125,8 +2129,8 @@ void RE_BlenderAnim(Render *re, Main *bmain, Scene *scene, Object *camera_overri re->flag |= R_ANIMATION; - if(BKE_imtype_is_movie(scene->r.im_format.imtype)) - if(!mh->start_movie(scene, &re->r, re->rectx, re->recty, re->reports)) + if (BKE_imtype_is_movie(scene->r.im_format.imtype)) + if (!mh->start_movie(scene, &re->r, re->rectx, re->recty, re->reports)) G.afbreek= 1; if (mh->get_next_frame) { @@ -2140,28 +2144,29 @@ void RE_BlenderAnim(Render *re, Main *bmain, Scene *scene, Object *camera_overri do_render_all_options(re); totrendered++; - if(re->test_break(re->tbh) == 0) { - if(!do_write_image_or_movie(re, bmain, scene, mh, NULL)) + if (re->test_break(re->tbh) == 0) { + if (!do_write_image_or_movie(re, bmain, scene, mh, NULL)) G.afbreek= 1; } - if(G.afbreek == 0) { + if (G.afbreek == 0) { BLI_exec_cb(re->main, (ID *)scene, BLI_CB_EVT_RENDER_POST); /* keep after file save */ } } else { - if(re->test_break(re->tbh)) + if (re->test_break(re->tbh)) G.afbreek= 1; } } - } else { - for(nfra= sfra, scene->r.cfra= sfra; scene->r.cfra<=efra; scene->r.cfra++) { + } + else { + for (nfra= sfra, scene->r.cfra= sfra; scene->r.cfra<=efra; scene->r.cfra++) { char name[FILE_MAX]; /* only border now, todo: camera lens. (ton) */ render_initialize_from_main(re, bmain, scene, NULL, camera_override, lay, 1, 0); - if(nfra!=scene->r.cfra) { + if (nfra!=scene->r.cfra) { /* * Skip this frame, but update for physics and particles system. * From convertblender.c: @@ -2169,7 +2174,7 @@ void RE_BlenderAnim(Render *re, Main *bmain, Scene *scene, Object *camera_overri */ unsigned int updatelay; - if(re->lay & 0xFF000000) + if (re->lay & 0xFF000000) updatelay= re->lay & 0xFF000000; else updatelay= re->lay; @@ -2181,16 +2186,16 @@ void RE_BlenderAnim(Render *re, Main *bmain, Scene *scene, Object *camera_overri nfra+= tfra; /* Touch/NoOverwrite options are only valid for image's */ - if(BKE_imtype_is_movie(scene->r.im_format.imtype) == 0) { - if(scene->r.mode & (R_NO_OVERWRITE | R_TOUCH)) + if (BKE_imtype_is_movie(scene->r.im_format.imtype) == 0) { + if (scene->r.mode & (R_NO_OVERWRITE | R_TOUCH)) BKE_makepicstring(name, scene->r.pic, bmain->name, scene->r.cfra, scene->r.im_format.imtype, scene->r.scemode & R_EXTENSION, TRUE); - if(scene->r.mode & R_NO_OVERWRITE && BLI_exists(name)) { + if (scene->r.mode & R_NO_OVERWRITE && BLI_exists(name)) { printf("skipping existing frame \"%s\"\n", name); totskipped++; continue; } - if(scene->r.mode & R_TOUCH && !BLI_exists(name)) { + if (scene->r.mode & R_TOUCH && !BLI_exists(name)) { BLI_make_existing_file(name); /* makes the dir if its not there */ BLI_file_touch(name); } @@ -2205,17 +2210,17 @@ void RE_BlenderAnim(Render *re, Main *bmain, Scene *scene, Object *camera_overri do_render_all_options(re); totrendered++; - if(re->test_break(re->tbh) == 0) { - if(!G.afbreek) - if(!do_write_image_or_movie(re, bmain, scene, mh, NULL)) + if (re->test_break(re->tbh) == 0) { + if (!G.afbreek) + if (!do_write_image_or_movie(re, bmain, scene, mh, NULL)) G.afbreek= 1; } else G.afbreek= 1; - if(G.afbreek==1) { + if (G.afbreek==1) { /* remove touched file */ - if(BKE_imtype_is_movie(scene->r.im_format.imtype) == 0) { + if (BKE_imtype_is_movie(scene->r.im_format.imtype) == 0) { if (scene->r.mode & R_TOUCH && BLI_exists(name) && BLI_file_size(name) == 0) { BLI_delete(name, 0, 0); } @@ -2224,17 +2229,17 @@ void RE_BlenderAnim(Render *re, Main *bmain, Scene *scene, Object *camera_overri break; } - if(G.afbreek==0) { + if (G.afbreek==0) { BLI_exec_cb(re->main, (ID *)scene, BLI_CB_EVT_RENDER_POST); /* keep after file save */ } } } /* end movie */ - if(BKE_imtype_is_movie(scene->r.im_format.imtype)) + if (BKE_imtype_is_movie(scene->r.im_format.imtype)) mh->end_movie(); - if(totskipped && totrendered == 0) + if (totskipped && totrendered == 0) BKE_report(re->reports, RPT_INFO, "No frames rendered, skipped to not overwrite"); scene->r.cfra= cfrao; @@ -2281,7 +2286,7 @@ int RE_ReadRenderResult(Scene *scene, Scene *scenode) winy= (scene->r.size*scene->r.ysch)/100; /* only in movie case we render smaller part */ - if(scene->r.mode & R_BORDER) { + if (scene->r.mode & R_BORDER) { disprect.xmin = scene->r.border.xmin*winx; disprect.xmax = scene->r.border.xmax*winx; @@ -2294,12 +2299,12 @@ int RE_ReadRenderResult(Scene *scene, Scene *scenode) disprect.ymax = winy; } - if(scenode) + if (scenode) scene= scenode; /* get render: it can be called from UI with draw callbacks */ re= RE_GetRender(scene->id.name); - if(re==NULL) + if (re==NULL) re= RE_NewRender(scene->id.name); RE_InitState(re, NULL, &scene->r, NULL, winx, winy, &disprect); re->scene= scene; @@ -2315,18 +2320,21 @@ void RE_set_max_threads(int threads) { if (threads==0) { RenderGlobal.threads = BLI_system_thread_count(); - } else if(threads>=1 && threads<=BLENDER_MAX_THREADS) { + } + else if (threads>=1 && threads<=BLENDER_MAX_THREADS) { RenderGlobal.threads= threads; - } else { + } + else { printf("Error, threads has to be in range 0-%d\n", BLENDER_MAX_THREADS); } } void RE_init_threadcount(Render *re) { - if(RenderGlobal.threads >= 1) { /* only set as an arg in background mode */ + if (RenderGlobal.threads >= 1) { /* only set as an arg in background mode */ re->r.threads= MIN2(RenderGlobal.threads, BLENDER_MAX_THREADS); - } else if ((re->r.mode & R_FIXED_THREADS)==0 || RenderGlobal.threads == 0) { /* Automatic threads */ + } + else if ((re->r.mode & R_FIXED_THREADS)==0 || RenderGlobal.threads == 0) { /* Automatic threads */ re->r.threads = BLI_system_thread_count(); } } @@ -2337,21 +2345,22 @@ void RE_layer_load_from_file(RenderLayer *layer, ReportList *reports, const char { ImBuf *ibuf = IMB_loadiffname(filename, IB_rect); - if(ibuf && (ibuf->rect || ibuf->rect_float)) { + if (ibuf && (ibuf->rect || ibuf->rect_float)) { if (ibuf->x == layer->rectx && ibuf->y == layer->recty) { - if(ibuf->rect_float==NULL) + if (ibuf->rect_float==NULL) IMB_float_from_rect(ibuf); memcpy(layer->rectf, ibuf->rect_float, sizeof(float)*4*layer->rectx*layer->recty); - } else { + } + else { if ((ibuf->x - x >= layer->rectx) && (ibuf->y - y >= layer->recty)) { ImBuf *ibuf_clip; - if(ibuf->rect_float==NULL) + if (ibuf->rect_float==NULL) IMB_float_from_rect(ibuf); ibuf_clip = IMB_allocImBuf(layer->rectx, layer->recty, 32, IB_rectfloat); - if(ibuf_clip) { + if (ibuf_clip) { IMB_rectcpy(ibuf_clip, ibuf, 0,0, x,y, layer->rectx, layer->recty); memcpy(layer->rectf, ibuf_clip->rect_float, sizeof(float)*4*layer->rectx*layer->recty); @@ -2375,7 +2384,7 @@ void RE_layer_load_from_file(RenderLayer *layer, ReportList *reports, const char void RE_result_load_from_file(RenderResult *result, ReportList *reports, const char *filename) { - if(!render_result_exr_file_read_path(result, filename)) { + if (!render_result_exr_file_read_path(result, filename)) { BKE_reportf(reports, RPT_ERROR, "RE_result_rect_from_file: failed to load '%s'\n", filename); return; } @@ -2392,7 +2401,7 @@ int RE_WriteEnvmapResult(struct ReportList *reports, Scene *scene, EnvMap *env, int maxX=0,maxY=0,i=0; char filepath[FILE_MAX]; - if(env->cube[1]==NULL) { + if (env->cube[1]==NULL) { BKE_report(reports, RPT_ERROR, "There is no generated environment map available to save"); return 0; } @@ -2434,7 +2443,7 @@ int RE_WriteEnvmapResult(struct ReportList *reports, Scene *scene, EnvMap *env, IMB_freeImBuf(ibuf); - if(ok) { + if (ok) { return TRUE; } else { diff --git a/source/blender/render/intern/source/pixelblending.c b/source/blender/render/intern/source/pixelblending.c index 0a8a59a860c..41b12171b2c 100644 --- a/source/blender/render/intern/source/pixelblending.c +++ b/source/blender/render/intern/source/pixelblending.c @@ -119,28 +119,28 @@ void addalphaAddfacFloat(float *dest, float *source, char addfac) /* blend colors*/ c= (m * dest[0]) + source[0]; #ifdef RE_FLOAT_COLOR_CLIPPING - if(c >= RE_FULL_COLOR_FLOAT) dest[0] = RE_FULL_COLOR_FLOAT; + if (c >= RE_FULL_COLOR_FLOAT) dest[0] = RE_FULL_COLOR_FLOAT; else #endif dest[0]= c; c= (m * dest[1]) + source[1]; #ifdef RE_FLOAT_COLOR_CLIPPING - if(c >= RE_FULL_COLOR_FLOAT) dest[1] = RE_FULL_COLOR_FLOAT; + if (c >= RE_FULL_COLOR_FLOAT) dest[1] = RE_FULL_COLOR_FLOAT; else #endif dest[1]= c; c= (m * dest[2]) + source[2]; #ifdef RE_FLOAT_COLOR_CLIPPING - if(c >= RE_FULL_COLOR_FLOAT) dest[2] = RE_FULL_COLOR_FLOAT; + if (c >= RE_FULL_COLOR_FLOAT) dest[2] = RE_FULL_COLOR_FLOAT; else #endif dest[2]= c; c= (m * dest[3]) + source[3]; #ifdef RE_ALPHA_CLIPPING - if(c >= RE_FULL_COLOR_FLOAT) dest[3] = RE_FULL_COLOR_FLOAT; + if (c >= RE_FULL_COLOR_FLOAT) dest[3] = RE_FULL_COLOR_FLOAT; else #endif dest[3]= c; @@ -172,12 +172,12 @@ void add_filt_fmask(unsigned int mask, float *col, float *rowbuf, int row_w) maskand= (mask & 255); maskshift= (mask >>8); - for(j=2; j>=0; j--) { + for (j=2; j>=0; j--) { a= j; val= *(fmask1[a] +maskand) + *(fmask2[a] +maskshift); - if(val!=0.0f) { + if (val!=0.0f) { rb1[0]+= val*r; rb1[1]+= val*g; rb1[2]+= val*b; @@ -186,7 +186,7 @@ void add_filt_fmask(unsigned int mask, float *col, float *rowbuf, int row_w) a+=3; val= *(fmask1[a] +maskand) + *(fmask2[a] +maskshift); - if(val!=0.0f) { + if (val!=0.0f) { rb2[0]+= val*r; rb2[1]+= val*g; rb2[2]+= val*b; @@ -195,7 +195,7 @@ void add_filt_fmask(unsigned int mask, float *col, float *rowbuf, int row_w) a+=3; val= *(fmask1[a] +maskand) + *(fmask2[a] +maskshift); - if(val!=0.0f) { + if (val!=0.0f) { rb3[0]+= val*r; rb3[1]+= val*g; rb3[2]+= val*b; @@ -216,7 +216,7 @@ void mask_array(unsigned int mask, float filt[][3]) unsigned int maskshift= (mask >>8); int a, j; - for(j=2; j>=0; j--) { + for (j=2; j>=0; j--) { a= j; @@ -269,7 +269,7 @@ void add_filt_fmask_coord(float filt[][3], float *col, float *rowbuf, int row_w, fpoin[1][2]= fpoin[1][1] + 4; fpoin[2][2]= fpoin[2][1] + 4; - if(y==0) { + if (y==0) { fpoin[0][0]= fpoin[1][0]; fpoin[0][1]= fpoin[1][1]; fpoin[0][2]= fpoin[1][2]; @@ -278,7 +278,7 @@ void add_filt_fmask_coord(float filt[][3], float *col, float *rowbuf, int row_w, lfilt[0][1]= filt[2][1]; lfilt[0][2]= filt[2][2]; } - else if(y==col_h-1) { + else if (y==col_h-1) { fpoin[2][0]= fpoin[1][0]; fpoin[2][1]= fpoin[1][1]; fpoin[2][2]= fpoin[1][2]; @@ -288,7 +288,7 @@ void add_filt_fmask_coord(float filt[][3], float *col, float *rowbuf, int row_w, lfilt[2][2]= filt[0][2]; } - if(x==0) { + if (x==0) { fpoin[2][0]= fpoin[2][1]; fpoin[1][0]= fpoin[1][1]; fpoin[0][0]= fpoin[0][1]; @@ -297,7 +297,7 @@ void add_filt_fmask_coord(float filt[][3], float *col, float *rowbuf, int row_w, lfilt[1][0]= filt[1][2]; lfilt[0][0]= filt[0][2]; } - else if(x==row_w-1) { + else if (x==row_w-1) { fpoin[2][2]= fpoin[2][1]; fpoin[1][2]= fpoin[1][1]; fpoin[0][2]= fpoin[0][1]; @@ -338,27 +338,27 @@ void add_filt_fmask_pixsize(unsigned int mask, float *in, float *rowbuf, int row maskand= (mask & 255); maskshift= (mask >>8); - for(j=2; j>=0; j--) { + for (j=2; j>=0; j--) { a= j; val= *(fmask1[a] +maskand) + *(fmask2[a] +maskshift); - if(val!=0.0f) { - for(i= 0; i<pixsize; i++) + if (val!=0.0f) { + for (i= 0; i<pixsize; i++) rb1[i]+= val*in[i]; } a+=3; val= *(fmask1[a] +maskand) + *(fmask2[a] +maskshift); - if(val!=0.0f) { - for(i= 0; i<pixsize; i++) + if (val!=0.0f) { + for (i= 0; i<pixsize; i++) rb2[i]+= val*in[i]; } a+=3; val= *(fmask1[a] +maskand) + *(fmask2[a] +maskshift); - if(val!=0.0f) { - for(i= 0; i<pixsize; i++) + if (val!=0.0f) { + for (i= 0; i<pixsize; i++) rb3[i]+= val*in[i]; } @@ -373,7 +373,7 @@ void addalphaAddFloat(float *dest, float *source) { /* Makes me wonder whether this is required... */ - if( dest[3] < RE_EMPTY_COLOR_FLOAT) { + if ( dest[3] < RE_EMPTY_COLOR_FLOAT) { dest[0] = source[0]; dest[1] = source[1]; dest[2] = source[2]; diff --git a/source/blender/render/intern/source/pixelshading.c b/source/blender/render/intern/source/pixelshading.c index 965abb361fd..98578c8dc70 100644 --- a/source/blender/render/intern/source/pixelshading.c +++ b/source/blender/render/intern/source/pixelshading.c @@ -89,14 +89,14 @@ static void render_lighting_halo(HaloRen *har, float col_r[3]) vn= har->no; - for(go=R.lights.first; go; go= go->next) { + for (go=R.lights.first; go; go= go->next) { lar= go->lampren; /* test for lamplayer */ - if(lar->mode & LA_LAYER) if((lar->lay & har->lay)==0) continue; + if (lar->mode & LA_LAYER) if((lar->lay & har->lay)==0) continue; /* lampdist cacluation */ - if(lar->type==LA_SUN || lar->type==LA_HEMI) { + if (lar->type==LA_SUN || lar->type==LA_HEMI) { copy_v3_v3(lv, lar->vec); lampdist= 1.0; } @@ -111,11 +111,11 @@ static void render_lighting_halo(HaloRen *har, float col_r[3]) /* ld is re-used further on (texco's) */ - if(lar->mode & LA_QUAD) { + if (lar->mode & LA_QUAD) { t= 1.0; - if(lar->ld1>0.0f) + if (lar->ld1>0.0f) t= lar->dist/(lar->dist+lar->ld1*ld); - if(lar->ld2>0.0f) + if (lar->ld2>0.0f) t*= lar->distkw/(lar->distkw+lar->ld2*ld*ld); lampdist= t; @@ -124,9 +124,9 @@ static void render_lighting_halo(HaloRen *har, float col_r[3]) lampdist= (lar->dist/(lar->dist+ld)); } - if(lar->mode & LA_SPHERE) { + if (lar->mode & LA_SPHERE) { t= lar->dist - ld; - if(t<0.0f) continue; + if (t<0.0f) continue; t/= lar->dist; lampdist*= (t); @@ -138,7 +138,7 @@ static void render_lighting_halo(HaloRen *har, float col_r[3]) lacol[1]= lar->g; lacol[2]= lar->b; - if(lar->mode & LA_TEXTURE) { + if (lar->mode & LA_TEXTURE) { ShadeInput shi; /* Warning, This is not that nice, and possibly a bit slow, @@ -152,10 +152,10 @@ static void render_lighting_halo(HaloRen *har, float col_r[3]) do_lamp_tex(lar, lv, &shi, lacol, LA_TEXTURE); } - if(lar->type==LA_SPOT) { + if (lar->type==LA_SPOT) { - if(lar->mode & LA_SQUARE) { - if(lv[0]*lar->vec[0]+lv[1]*lar->vec[1]+lv[2]*lar->vec[2]>0.0f) { + if (lar->mode & LA_SQUARE) { + if (lv[0]*lar->vec[0]+lv[1]*lar->vec[1]+lv[2]*lar->vec[2]>0.0f) { float x, lvrot[3]; /* rotate view to lampspace */ @@ -174,25 +174,25 @@ static void render_lighting_halo(HaloRen *har, float col_r[3]) } t= lar->spotsi; - if(inpr<t) continue; + if (inpr<t) continue; else { t= inpr-t; soft= 1.0; - if(t<lar->spotbl && lar->spotbl!=0.0f) { + if (t<lar->spotbl && lar->spotbl!=0.0f) { /* soft area */ i= t/lar->spotbl; t= i*i; soft= (3.0f*t-2.0f*t*i); inpr*= soft; } - if(lar->mode & LA_ONLYSHADOW) { + if (lar->mode & LA_ONLYSHADOW) { /* if(ma->mode & MA_SHADOW) { */ /* dot product positive: front side face! */ inp= vn[0]*lv[0] + vn[1]*lv[1] + vn[2]*lv[2]; - if(inp>0.0f) { + if (inp>0.0f) { /* testshadowbuf==0.0 : 100% shadow */ shadfac = testshadowbuf(&R, lar->shb, rco, dco, dco, inp, 0.0f); - if( shadfac>0.0f ) { + if ( shadfac>0.0f ) { shadfac*= inp*soft*lar->energy; ir -= shadfac; ig -= shadfac; @@ -205,7 +205,7 @@ static void render_lighting_halo(HaloRen *har, float col_r[3]) } lampdist*=inpr; } - if(lar->mode & LA_ONLYSHADOW) continue; + if (lar->mode & LA_ONLYSHADOW) continue; } @@ -217,32 +217,32 @@ static void render_lighting_halo(HaloRen *har, float col_r[3]) i= inp; - if(lar->type==LA_HEMI) { + if (lar->type==LA_HEMI) { i= 0.5f*i+0.5f; } - if(i>0.0f) { + if (i>0.0f) { i*= lampdist; } /* shadow */ - if(i> -0.41f) { /* heuristic valua! */ - if(lar->shb) { + if (i> -0.41f) { /* heuristic valua! */ + if (lar->shb) { shadfac = testshadowbuf(&R, lar->shb, rco, dco, dco, inp, 0.0f); - if(shadfac==0.0f) continue; + if (shadfac==0.0f) continue; i*= shadfac; } } - if(i>0.0f) { + if (i>0.0f) { ir+= i*lacol[0]; ig+= i*lacol[1]; ib+= i*lacol[2]; } } - if(ir<0.0f) ir= 0.0f; - if(ig<0.0f) ig= 0.0f; - if(ib<0.0f) ib= 0.0f; + if (ir<0.0f) ir= 0.0f; + if (ig<0.0f) ig= 0.0f; + if (ib<0.0f) ib= 0.0f; col_r[0]*= ir; col_r[1]*= ig; @@ -260,11 +260,11 @@ static float haloZtoDist(int z) { float zco = 0; - if(z >= 0x7FFFFF) + if (z >= 0x7FFFFF) return 10e10; else { zco = (float)z/(float)0x7FFFFF; - if(R.r.mode & R_ORTHO) + if (R.r.mode & R_ORTHO) return (R.winmat[3][2] - zco*R.winmat[3][3])/(R.winmat[2][2]); else return (R.winmat[3][2])/(R.winmat[2][2] - R.winmat[2][3]*zco); @@ -287,8 +287,8 @@ int shadeHaloFloat(HaloRen *har, float *col, int zz, float t, zn, radist, ringf=0.0f, linef=0.0f, alpha, si, co; int a; - if(R.wrld.mode & WO_MIST) { - if(har->type & HA_ONLYSKY) { + if (R.wrld.mode & WO_MIST) { + if (har->type & HA_ONLYSKY) { /* stars but no mist */ alpha= har->alfa; } @@ -299,37 +299,37 @@ int shadeHaloFloat(HaloRen *har, float *col, int zz, } else alpha= har->alfa; - if(alpha==0.0f) + if (alpha==0.0f) return 0; /* soften the halo if it intersects geometry */ - if(har->mat && har->mat->mode & MA_HALO_SOFT) { + if (har->mat && har->mat->mode & MA_HALO_SOFT) { float segment_length, halo_depth, distance_from_z /* , visible_depth */ /* UNUSED */, soften; /* calculate halo depth */ segment_length= har->hasize*sasqrt(1.0f - dist/(har->rad*har->rad)); halo_depth= 2.0f*segment_length; - if(halo_depth < FLT_EPSILON) + if (halo_depth < FLT_EPSILON) return 0; /* calculate how much of this depth is visible */ distance_from_z = haloZtoDist(zz) - haloZtoDist(har->zs); /* visible_depth = halo_depth; */ /* UNUSED */ - if(distance_from_z < segment_length) { + if (distance_from_z < segment_length) { soften= (segment_length + distance_from_z)/halo_depth; /* apply softening to alpha */ - if(soften < 1.0f) + if (soften < 1.0f) alpha *= soften; - if(alpha <= 0.0f) + if (alpha <= 0.0f) return 0; } } else { /* not a soft halo. use the old softening code */ /* halo being intersected? */ - if(har->zs> zz-har->zd) { + if (har->zs> zz-har->zd) { t= ((float)(zz-har->zs))/(float)har->zd; alpha*= sqrtf(sqrtf(t)); } @@ -338,31 +338,31 @@ int shadeHaloFloat(HaloRen *har, float *col, int zz, radist= sqrt(dist); /* watch it: not used nicely: flarec is set at zero in pixstruct */ - if(flarec) har->pixels+= (int)(har->rad-radist); + if (flarec) har->pixels+= (int)(har->rad-radist); - if(har->ringc) { + if (har->ringc) { float *rc, fac; int ofs; /* per ring an antialised circle */ ofs= har->seed; - for(a= har->ringc; a>0; a--, ofs+=2) { + for (a= har->ringc; a>0; a--, ofs+=2) { rc= hashvectf + (ofs % 768); fac= fabsf( rc[1]*(har->rad*fabsf(rc[0]) - radist) ); - if(fac< 1.0f) { + if (fac< 1.0f) { ringf+= (1.0f-fac); } } } - if(har->type & HA_VECT) { + if (har->type & HA_VECT) { dist= fabsf( har->cos*(yn) - har->sin*(xn) )/har->rad; - if(dist>1.0f) dist= 1.0f; - if(har->tex) { + if (dist>1.0f) dist= 1.0f; + if (har->tex) { zn= har->sin*xn - har->cos*yn; yn= har->cos*xn + har->sin*yn; xn= zn; @@ -370,49 +370,49 @@ int shadeHaloFloat(HaloRen *har, float *col, int zz, } else dist= dist/har->radsq; - if(har->type & HA_FLARECIRC) { + if (har->type & HA_FLARECIRC) { dist= 0.5+fabs(dist-0.5f); } - if(har->hard>=30) { + if (har->hard>=30) { dist= sqrt(dist); - if(har->hard>=40) { + if (har->hard>=40) { dist= sinf(dist*(float)M_PI_2); - if(har->hard>=50) { + if (har->hard>=50) { dist= sqrt(dist); } } } - else if(har->hard<20) dist*=dist; + else if (har->hard<20) dist*=dist; - if(dist < 1.0f) + if (dist < 1.0f) dist= (1.0f-dist); else dist= 0.0f; - if(har->linec) { + if (har->linec) { float *rc, fac; int ofs; /* per starpoint an antialiased line */ ofs= har->seed; - for(a= har->linec; a>0; a--, ofs+=3) { + for (a= har->linec; a>0; a--, ofs+=3) { rc= hashvectf + (ofs % 768); fac= fabs( (xn)*rc[0]+(yn)*rc[1]); - if(fac< 1.0f ) + if (fac< 1.0f ) linef+= (1.0f-fac); } linef*= dist; } - if(har->starpoints) { + if (har->starpoints) { float ster, angle; /* rotation */ angle= atan2(yn, xn); @@ -424,15 +424,15 @@ int shadeHaloFloat(HaloRen *har, float *col, int zz, angle= (co*xn+si*yn)*(co*yn-si*xn); ster= fabs(angle); - if(ster>1.0f) { + if (ster>1.0f) { ster= (har->rad)/(ster); - if(ster<1.0f) dist*= sqrtf(ster); + if (ster<1.0f) dist*= sqrtf(ster); } } /* disputable optimize... (ton) */ - if(dist<=0.00001f) + if (dist<=0.00001f) return 0; dist*= alpha; @@ -441,7 +441,7 @@ int shadeHaloFloat(HaloRen *har, float *col, int zz, /* The color is either the rgb spec-ed by the user, or extracted from */ /* the texture */ - if(har->tex) { + if (har->tex) { col[0]= har->r; col[1]= har->g; col[2]= har->b; @@ -458,41 +458,41 @@ int shadeHaloFloat(HaloRen *har, float *col, int zz, col[0]= dist*har->r; col[1]= dist*har->g; col[2]= dist*har->b; - if(har->type & HA_XALPHA) col[3]= dist*dist; + if (har->type & HA_XALPHA) col[3]= dist*dist; else col[3]= dist; } - if(har->mat) { - if(har->mat->mode & MA_HALO_SHADE) { + if (har->mat) { + if (har->mat->mode & MA_HALO_SHADE) { /* we test for lights because of preview... */ - if(R.lights.first) render_lighting_halo(har, col); + if (R.lights.first) render_lighting_halo(har, col); } /* Next, we do the line and ring factor modifications. */ - if(linef!=0.0f) { + if (linef!=0.0f) { Material *ma= har->mat; col[0]+= linef * ma->specr; col[1]+= linef * ma->specg; col[2]+= linef * ma->specb; - if(har->type & HA_XALPHA) col[3]+= linef*linef; + if (har->type & HA_XALPHA) col[3]+= linef*linef; else col[3]+= linef; } - if(ringf!=0.0f) { + if (ringf!=0.0f) { Material *ma= har->mat; col[0]+= ringf * ma->mirr; col[1]+= ringf * ma->mirg; col[2]+= ringf * ma->mirb; - if(har->type & HA_XALPHA) col[3]+= ringf*ringf; + if (har->type & HA_XALPHA) col[3]+= ringf*ringf; else col[3]+= ringf; } } /* alpha requires clip, gives black dots */ - if(col[3] > 1.0f) + if (col[3] > 1.0f) col[3]= 1.0f; return 1; @@ -510,15 +510,15 @@ void shadeSkyView(float col_r[3], const float rco[3], const float view[3], const skyflag = WO_ZENUP; /* Some view vector stuff. */ - if(R.wrld.skytype & WO_SKYREAL) { + if (R.wrld.skytype & WO_SKYREAL) { blend = dot_v3v3(view, R.grvec); - if(blend<0.0f) skyflag= 0; + if (blend<0.0f) skyflag= 0; blend= fabs(blend); } - else if(R.wrld.skytype & WO_SKYPAPER) { + else if (R.wrld.skytype & WO_SKYPAPER) { blend= 0.5f + 0.5f * view[1]; } else { @@ -531,9 +531,9 @@ void shadeSkyView(float col_r[3], const float rco[3], const float view[3], const /* Careful: SKYTEX and SKYBLEND are NOT mutually exclusive! If */ /* SKYBLEND is active, the texture and color blend are added. */ - if(R.wrld.skytype & WO_SKYTEX) { + if (R.wrld.skytype & WO_SKYTEX) { copy_v3_v3(lo, view); - if(R.wrld.skytype & WO_SKYREAL) { + if (R.wrld.skytype & WO_SKYREAL) { mul_m3_v3(R.imat, lo); @@ -543,15 +543,16 @@ void shadeSkyView(float col_r[3], const float rco[3], const float view[3], const do_sky_tex(rco, lo, dxyview, hor, zen, &blend, skyflag, thread); } - if(blend>1.0f) blend= 1.0f; + if (blend>1.0f) blend= 1.0f; blendm= 1.0f-blend; /* No clipping, no conversion! */ - if(R.wrld.skytype & WO_SKYBLEND) { + if (R.wrld.skytype & WO_SKYBLEND) { col_r[0] = (blendm*hor[0] + blend*zen[0]); col_r[1] = (blendm*hor[1] + blend*zen[1]); col_r[2] = (blendm*hor[2] + blend*zen[2]); - } else { + } + else { /* Done when a texture was grabbed. */ col_r[0]= hor[0]; col_r[1]= hor[1]; @@ -567,13 +568,13 @@ void shadeSunView(float col_r[3], const float view[3]) float sview[3]; int do_init= 1; - for(go=R.lights.first; go; go= go->next) { + for (go=R.lights.first; go; go= go->next) { lar= go->lampren; - if(lar->type==LA_SUN && lar->sunsky && (lar->sunsky->effect_type & LA_SUN_EFFECT_SKY)){ + if (lar->type==LA_SUN && lar->sunsky && (lar->sunsky->effect_type & LA_SUN_EFFECT_SKY)) { float sun_collector[3]; float colorxyz[3]; - if(do_init) { + if (do_init) { normalize_v3_v3(sview, view); mul_m3_v3(R.imat, sview); @@ -608,7 +609,7 @@ void shadeSkyPixel(float collector[4], float fx, float fy, short thread) float fac; - if((R.wrld.skytype & (WO_SKYBLEND+WO_SKYTEX))==0) { + if ((R.wrld.skytype & (WO_SKYBLEND+WO_SKYTEX))==0) { /* 1. solid color */ copy_v3_v3(collector, &R.wrld.horr); @@ -618,7 +619,7 @@ void shadeSkyPixel(float collector[4], float fx, float fy, short thread) /* 2. */ /* This one true because of the context of this routine */ - if(R.wrld.skytype & WO_SKYPAPER) { + if (R.wrld.skytype & WO_SKYPAPER) { view[0]= -1.0f + 2.0f*(fx/(float)R.winx); view[1]= -1.0f + 2.0f*(fy/(float)R.winy); view[2]= 0.0; @@ -630,7 +631,7 @@ void shadeSkyPixel(float collector[4], float fx, float fy, short thread) calc_view_vector(view, fx, fy); fac= normalize_v3(view); - if(R.wrld.skytype & WO_SKYTEX) { + if (R.wrld.skytype & WO_SKYTEX) { dxyview[0]= -R.viewdx/fac; dxyview[1]= -R.viewdy/fac; } diff --git a/source/blender/render/intern/source/pointdensity.c b/source/blender/render/intern/source/pointdensity.c index 1904d5dce63..5d4f9db9a02 100644 --- a/source/blender/render/intern/source/pointdensity.c +++ b/source/blender/render/intern/source/pointdensity.c @@ -151,7 +151,7 @@ static void pointdensity_cache_psys(Render *re, PointDensity *pd, Object *ob, Pa for (i=0, pa=psys->particles; i < total_particles; i++, pa++) { state.time = cfra; - if(psys_get_particle_state(&sim, i, &state, 0)) { + if (psys_get_particle_state(&sim, i, &state, 0)) { copy_v3_v3(partco, state.co); @@ -159,7 +159,8 @@ static void pointdensity_cache_psys(Render *re, PointDensity *pd, Object *ob, Pa mul_m4_v3(ob->imat, partco); else if (pd->psys_cache_space == TEX_PD_OBJECTLOC) { sub_v3_v3(partco, ob->loc); - } else { + } + else { /* TEX_PD_WORLDSPACE */ } @@ -175,7 +176,8 @@ static void pointdensity_cache_psys(Render *re, PointDensity *pd, Object *ob, Pa if (i < psys->totpart) { pa_time = (cfra - pa->time)/pa->lifetime; - } else { + } + else { ChildParticle *cpa= (psys->child + i) - psys->totpart; float pa_birthtime, pa_dietime; @@ -191,7 +193,7 @@ static void pointdensity_cache_psys(Render *re, PointDensity *pd, Object *ob, Pa BLI_bvhtree_balance(pd->point_tree); dm->release(dm); - if(psys->lattice){ + if (psys->lattice) { end_latt_deform(psys->lattice); psys->lattice=0; } @@ -214,7 +216,7 @@ static void pointdensity_cache_object(Render *re, PointDensity *pd, Object *ob) pd->point_tree = BLI_bvhtree_new(pd->totpoints, 0.0, 4, 6); - for(i=0; i < pd->totpoints; i++, mvert++) { + for (i=0; i < pd->totpoints; i++, mvert++) { float co[3]; copy_v3_v3(co, mvert->co); @@ -243,7 +245,7 @@ void cache_pointdensity(Render *re, Tex *tex) { PointDensity *pd = tex->pd; - if(!pd) + if (!pd) return; if (pd->point_tree) { @@ -293,14 +295,14 @@ void make_pointdensities(Render *re) { Tex *tex; - if(re->scene->r.scemode & R_PREVIEWBUTS) + if (re->scene->r.scemode & R_PREVIEWBUTS) return; re->i.infostr= "Caching Point Densities"; re->stats_draw(re->sdh, &re->i); for (tex= re->main->tex.first; tex; tex= tex->id.next) { - if(tex->id.us && tex->type==TEX_POINTDENSITY) { + if (tex->id.us && tex->type==TEX_POINTDENSITY) { cache_pointdensity(re, tex); } } @@ -313,11 +315,11 @@ void free_pointdensities(Render *re) { Tex *tex; - if(re->scene->r.scemode & R_PREVIEWBUTS) + if (re->scene->r.scemode & R_PREVIEWBUTS) return; for (tex= re->main->tex.first; tex; tex= tex->id.next) { - if(tex->id.us && tex->type==TEX_POINTDENSITY) { + if (tex->id.us && tex->type==TEX_POINTDENSITY) { free_pointdensity(re, tex); } } diff --git a/source/blender/render/intern/source/rayshade.c b/source/blender/render/intern/source/rayshade.c index 355bae0d2d8..1222dd121a7 100644 --- a/source/blender/render/intern/source/rayshade.c +++ b/source/blender/render/intern/source/rayshade.c @@ -87,7 +87,7 @@ static int test_break(void *data) static void RE_rayobject_config_control(RayObject *r, Render *re) { - if(RE_rayobject_isRayAPI(r)) + if (RE_rayobject_isRayAPI(r)) { r = RE_rayobject_align( r ); r->control.data = re; @@ -99,7 +99,7 @@ static RayObject* RE_rayobject_create(Render *re, int type, int size) { RayObject * res = NULL; - if(type == R_RAYSTRUCTURE_AUTO) + if (type == R_RAYSTRUCTURE_AUTO) { //TODO //if(detect_simd()) @@ -111,7 +111,7 @@ static RayObject* RE_rayobject_create(Render *re, int type, int size) } #ifndef __SSE__ - if(type == R_RAYSTRUCTURE_SIMD_SVBVH || type == R_RAYSTRUCTURE_SIMD_QBVH) + if (type == R_RAYSTRUCTURE_SIMD_SVBVH || type == R_RAYSTRUCTURE_SIMD_QBVH) { puts("Warning: Using VBVH (SSE was disabled at compile time)"); type = R_RAYSTRUCTURE_VBVH; @@ -119,21 +119,21 @@ static RayObject* RE_rayobject_create(Render *re, int type, int size) #endif - if(type == R_RAYSTRUCTURE_OCTREE) //TODO dynamic ocres + if (type == R_RAYSTRUCTURE_OCTREE) //TODO dynamic ocres res = RE_rayobject_octree_create(re->r.ocres, size); - else if(type == R_RAYSTRUCTURE_BLIBVH) + else if (type == R_RAYSTRUCTURE_BLIBVH) res = RE_rayobject_blibvh_create(size); - else if(type == R_RAYSTRUCTURE_VBVH) + else if (type == R_RAYSTRUCTURE_VBVH) res = RE_rayobject_vbvh_create(size); - else if(type == R_RAYSTRUCTURE_SIMD_SVBVH) + else if (type == R_RAYSTRUCTURE_SIMD_SVBVH) res = RE_rayobject_svbvh_create(size); - else if(type == R_RAYSTRUCTURE_SIMD_QBVH) + else if (type == R_RAYSTRUCTURE_SIMD_QBVH) res = RE_rayobject_qbvh_create(size); else res = RE_rayobject_vbvh_create(size); //Fallback - if(res) + if (res) RE_rayobject_config_control(res, re); return res; @@ -148,36 +148,36 @@ void freeraytree(Render *re) { ObjectInstanceRen *obi; - if(re->raytree) + if (re->raytree) { RE_rayobject_free(re->raytree); re->raytree = NULL; } - if(re->rayfaces) + if (re->rayfaces) { MEM_freeN(re->rayfaces); re->rayfaces = NULL; } - if(re->rayprimitives) + if (re->rayprimitives) { MEM_freeN(re->rayprimitives); re->rayprimitives = NULL; } - for(obi=re->instancetable.first; obi; obi=obi->next) + for (obi=re->instancetable.first; obi; obi=obi->next) { ObjectRen *obr = obi->obr; - if(obr->raytree) + if (obr->raytree) { RE_rayobject_free(obr->raytree); obr->raytree = NULL; } - if(obr->rayfaces) + if (obr->rayfaces) { MEM_freeN(obr->rayfaces); obr->rayfaces = NULL; } - if(obi->raytree) + if (obi->raytree) { RE_rayobject_free(obi->raytree); obi->raytree = NULL; @@ -189,7 +189,7 @@ void freeraytree(Render *re) RayCounter sum; memset( &sum, 0, sizeof(sum) ); int i; - for(i=0; i<BLENDER_MAX_THREADS; i++) + for (i=0; i<BLENDER_MAX_THREADS; i++) RE_RC_MERGE(&sum, re_rc_counter+i); RE_RC_INFO(&sum); } @@ -199,8 +199,8 @@ void freeraytree(Render *re) static int is_raytraceable_vlr(Render *re, VlakRen *vlr) { /* note: volumetric must be tracable, wire must not */ - if((re->flag & R_BAKE_TRACE) || (vlr->flag & R_TRACEBLE) || (vlr->mat->material_type == MA_TYPE_VOLUME)) - if(vlr->mat->material_type != MA_TYPE_WIRE) + if ((re->flag & R_BAKE_TRACE) || (vlr->flag & R_TRACEBLE) || (vlr->mat->material_type == MA_TYPE_VOLUME)) + if (vlr->mat->material_type != MA_TYPE_WIRE) return 1; return 0; } @@ -210,13 +210,13 @@ static int is_raytraceable(Render *re, ObjectInstanceRen *obi) int v; ObjectRen *obr = obi->obr; - if(re->excludeob && obr->ob == re->excludeob) + if (re->excludeob && obr->ob == re->excludeob) return 0; - for(v=0;v<obr->totvlak;v++) { + for (v=0;v<obr->totvlak;v++) { VlakRen *vlr = obr->vlaknodes[v>>8].vlak + (v&255); - if(is_raytraceable_vlr(re, vlr)) + if (is_raytraceable_vlr(re, vlr)) return 1; } @@ -232,7 +232,7 @@ RayObject* makeraytree_object(Render *re, ObjectInstanceRen *obi) // update render stats ObjectRen *obr = obi->obr; - if(obr->raytree == NULL) + if (obr->raytree == NULL) { RayObject *raytree; RayFace *face = NULL; @@ -241,10 +241,10 @@ RayObject* makeraytree_object(Render *re, ObjectInstanceRen *obi) //Count faces int faces = 0; - for(v=0;v<obr->totvlak;v++) + for (v=0;v<obr->totvlak;v++) { VlakRen *vlr = obr->vlaknodes[v>>8].vlak + (v&255); - if(is_raytraceable_vlr(re, vlr)) + if (is_raytraceable_vlr(re, vlr)) faces++; } @@ -253,17 +253,17 @@ RayObject* makeraytree_object(Render *re, ObjectInstanceRen *obi) //Create Ray cast accelaration structure raytree = RE_rayobject_create( re, re->r.raytrace_structure, faces ); - if( (re->r.raytrace_options & R_RAYTRACE_USE_LOCAL_COORDS) ) + if ( (re->r.raytrace_options & R_RAYTRACE_USE_LOCAL_COORDS) ) vlakprimitive = obr->rayprimitives = (VlakPrimitive*)MEM_callocN(faces*sizeof(VlakPrimitive), "ObjectRen primitives"); else face = obr->rayfaces = (RayFace*)MEM_callocN(faces*sizeof(RayFace), "ObjectRen faces"); obr->rayobi = obi; - for(v=0;v<obr->totvlak;v++) + for (v=0;v<obr->totvlak;v++) { VlakRen *vlr = obr->vlaknodes[v>>8].vlak + (v&255); - if(is_raytraceable_vlr(re, vlr)) + if (is_raytraceable_vlr(re, vlr)) { if ((re->r.raytrace_options & R_RAYTRACE_USE_LOCAL_COORDS)) { RE_rayobject_add( raytree, RE_vlakprimitive_from_vlak( vlakprimitive, obi, vlr ) ); @@ -279,38 +279,38 @@ RayObject* makeraytree_object(Render *re, ObjectInstanceRen *obi) RE_rayobject_done( raytree ); /* in case of cancel during build, raytree is not usable */ - if(test_break(re)) + if (test_break(re)) RE_rayobject_free(raytree); else obr->raytree= raytree; } - if(obr->raytree) { - if((obi->flag & R_TRANSFORMED) && obi->raytree == NULL) + if (obr->raytree) { + if ((obi->flag & R_TRANSFORMED) && obi->raytree == NULL) { obi->transform_primitives = 0; obi->raytree = RE_rayobject_instance_create( obr->raytree, obi->mat, obi, obi->obr->rayobi ); } } - if(obi->raytree) return obi->raytree; + if (obi->raytree) return obi->raytree; return obi->obr->raytree; } static int has_special_rayobject(Render *re, ObjectInstanceRen *obi) { - if( (obi->flag & R_TRANSFORMED) && (re->r.raytrace_options & R_RAYTRACE_USE_INSTANCES) ) + if ( (obi->flag & R_TRANSFORMED) && (re->r.raytrace_options & R_RAYTRACE_USE_INSTANCES) ) { ObjectRen *obr = obi->obr; int v, faces = 0; - for(v=0;v<obr->totvlak;v++) + for (v=0;v<obr->totvlak;v++) { VlakRen *vlr = obr->vlaknodes[v>>8].vlak + (v&255); - if(is_raytraceable_vlr(re, vlr)) + if (is_raytraceable_vlr(re, vlr)) { faces++; - if(faces > 4) + if (faces > 4) return 1; } } @@ -328,8 +328,8 @@ static void makeraytree_single(Render *re) VlakPrimitive *vlakprimitive = NULL; int faces = 0, obs = 0, special = 0; - for(obi=re->instancetable.first; obi; obi=obi->next) - if(is_raytraceable(re, obi)) + for (obi=re->instancetable.first; obi; obi=obi->next) + if (is_raytraceable(re, obi)) { ObjectRen *obr = obi->obr; obs++; @@ -339,16 +339,16 @@ static void makeraytree_single(Render *re) } else { int v; - for(v=0;v<obr->totvlak;v++) + for (v=0;v<obr->totvlak;v++) { VlakRen *vlr = obr->vlaknodes[v>>8].vlak + (v&255); - if(is_raytraceable_vlr(re, vlr)) + if (is_raytraceable_vlr(re, vlr)) faces++; } } } - if(faces + special == 0) + if (faces + special == 0) { re->raytree = RE_rayobject_empty_create(); return; @@ -357,7 +357,7 @@ static void makeraytree_single(Render *re) //Create raytree raytree = re->raytree = RE_rayobject_create( re, re->r.raytrace_structure, faces+special ); - if( (re->r.raytrace_options & R_RAYTRACE_USE_LOCAL_COORDS) ) + if ( (re->r.raytrace_options & R_RAYTRACE_USE_LOCAL_COORDS) ) { vlakprimitive = re->rayprimitives = (VlakPrimitive*)MEM_callocN(faces*sizeof(VlakPrimitive), "Raytrace vlak-primitives"); } @@ -365,16 +365,16 @@ static void makeraytree_single(Render *re) face = re->rayfaces = (RayFace*)MEM_callocN(faces*sizeof(RayFace), "Render ray faces"); } - for(obi=re->instancetable.first; obi; obi=obi->next) - if(is_raytraceable(re, obi)) + for (obi=re->instancetable.first; obi; obi=obi->next) + if (is_raytraceable(re, obi)) { - if(test_break(re)) + if (test_break(re)) break; if (has_special_rayobject(re, obi)) { RayObject *obj = makeraytree_object(re, obi); - if(test_break(re)) + if (test_break(re)) break; if (obj) @@ -384,12 +384,12 @@ static void makeraytree_single(Render *re) int v; ObjectRen *obr = obi->obr; - if(obi->flag & R_TRANSFORMED) + if (obi->flag & R_TRANSFORMED) { obi->transform_primitives = 1; } - for(v=0;v<obr->totvlak;v++) + for (v=0;v<obr->totvlak;v++) { VlakRen *vlr = obr->vlaknodes[v>>8].vlak + (v&255); if (is_raytraceable_vlr(re, vlr)) { @@ -400,12 +400,12 @@ static void makeraytree_single(Render *re) } else { RE_rayface_from_vlak(face, obi, vlr); - if((obi->flag & R_TRANSFORMED)) + if ((obi->flag & R_TRANSFORMED)) { mul_m4_v3(obi->mat, face->v1); mul_m4_v3(obi->mat, face->v2); mul_m4_v3(obi->mat, face->v3); - if(RE_rayface_isQuad(face)) + if (RE_rayface_isQuad(face)) mul_m4_v3(obi->mat, face->v4); } @@ -417,7 +417,7 @@ static void makeraytree_single(Render *re) } } - if(!test_break(re)) + if (!test_break(re)) { re->i.infostr= "Raytree.. building"; re->stats_draw(re->sdh, &re->i); @@ -436,7 +436,7 @@ void makeraytree(Render *re) /* disable options not yet supported by octree, * they might actually never be supported (unless people really need it) */ - if(re->r.raytrace_structure == R_RAYSTRUCTURE_OCTREE) + if (re->r.raytrace_structure == R_RAYSTRUCTURE_OCTREE) re->r.raytrace_options &= ~( R_RAYTRACE_USE_INSTANCES | R_RAYTRACE_USE_LOCAL_COORDS); makeraytree_single(re); @@ -452,7 +452,7 @@ void makeraytree(Render *re) //This is ONLY needed to kept a bogus behavior of SUN and HEMI lights INIT_MINMAX(min, max); RE_rayobject_merge_bb( re->raytree, min, max ); - for(i=0; i<3; i++) + for (i=0; i<3; i++) { min[i] += 0.01f; max[i] += 0.01f; @@ -460,7 +460,7 @@ void makeraytree(Render *re) } re->maxdist = dot_v3v3(sub, sub); - if(re->maxdist > 0.0f) re->maxdist= sqrt(re->maxdist); + if (re->maxdist > 0.0f) re->maxdist= sqrt(re->maxdist); re->i.infostr= "Raytree finished"; re->stats_draw(re->sdh, &re->i); @@ -471,7 +471,7 @@ void makeraytree(Render *re) #endif } -/* if(shi->osatex) */ +/* if (shi->osatex) */ static void shade_ray_set_derivative(ShadeInput *shi) { float detsh, t00, t10, t01, t11; @@ -481,7 +481,7 @@ static void shade_ray_set_derivative(ShadeInput *shi) axis_dominant_v3(&axis1, &axis2, shi->facenor); /* compute u,v and derivatives */ - if(shi->obi->flag & R_TRANSFORMED) { + if (shi->obi->flag & R_TRANSFORMED) { float v1[3], v2[3], v3[3]; mul_v3_m3v3(v1, shi->obi->nmat, shi->v1->co); @@ -535,7 +535,7 @@ void shade_ray(Isect *is, ShadeInput *shi, ShadeResult *shr) shi->mat= vlr->mat; shade_input_init_material(shi); - if(is->isect==2) + if (is->isect==2) shade_input_set_triangle_i(shi, obi, vlr, 0, 2, 3); else shade_input_set_triangle_i(shi, obi, vlr, 0, 1, 2); @@ -544,21 +544,22 @@ void shade_ray(Isect *is, ShadeInput *shi, ShadeResult *shr) shi->v= is->v; shi->dx_u= shi->dx_v= shi->dy_u= shi->dy_v= 0.0f; - if(shi->osatex) + if (shi->osatex) shade_ray_set_derivative(shi); shade_input_set_normals(shi); shade_input_set_shade_texco(shi); if (shi->mat->material_type == MA_TYPE_VOLUME) { - if(ELEM(is->mode, RE_RAY_SHADOW, RE_RAY_SHADOW_TRA)) { + if (ELEM(is->mode, RE_RAY_SHADOW, RE_RAY_SHADOW_TRA)) { shade_volume_shadow(shi, shr, is); - } else { + } + else { shade_volume_outside(shi, shr); } } - else if(is->mode==RE_RAY_SHADOW_TRA) { + else if (is->mode==RE_RAY_SHADOW_TRA) { /* temp hack to prevent recursion */ - if(shi->nodes==0 && shi->mat->nodetree && shi->mat->use_nodes) { + if (shi->nodes==0 && shi->mat->nodetree && shi->mat->use_nodes) { ntreeShaderExecTree(shi->mat->nodetree, shi, shr); shi->mat= vlr->mat; /* shi->mat is being set in nodetree */ } @@ -566,7 +567,7 @@ void shade_ray(Isect *is, ShadeInput *shi, ShadeResult *shr) shade_color(shi, shr); } else { - if(shi->mat->nodetree && shi->mat->use_nodes) { + if (shi->mat->nodetree && shi->mat->use_nodes) { ntreeShaderExecTree(shi->mat->nodetree, shi, shr); shi->mat= vlr->mat; /* shi->mat is being set in nodetree */ } @@ -588,15 +589,15 @@ static int refraction(float refract[3], const float n[3], const float view[3], f dot = dot_v3v3(view, n); - if(dot>0.0f) { + if (dot>0.0f) { index = 1.0f/index; fac= 1.0f - (1.0f - dot*dot)*index*index; - if(fac<= 0.0f) return 0; + if (fac<= 0.0f) return 0; fac= -dot*index + sqrtf(fac); } else { fac= 1.0f - (1.0f - dot*dot)*index*index; - if(fac<= 0.0f) return 0; + if (fac<= 0.0f) return 0; fac= -dot*index - sqrtf(fac); } @@ -622,7 +623,7 @@ static void reflection(float ref[3], float n[3], const float view[3], const floa /* test phong normals, then we should prevent vector going to the back */ f1= dot_v3v3(ref, orn); - if(f1>0.0f) { + if (f1>0.0f) { f1+= 0.01f; ref[0]-= f1*orn[0]; ref[1]-= f1*orn[1]; @@ -672,7 +673,7 @@ static float shade_by_transmission(Isect *is, ShadeInput *shi, ShadeResult *shr) d= shi->mat->tx_limit; p = shi->mat->tx_falloff; - if(p < 0.0f) p= 0.0f; + if (p < 0.0f) p= 0.0f; else if (p > 10.0f) p= 10.0f; shr->alpha *= powf(d, p); @@ -688,7 +689,8 @@ static void ray_fadeout_endcolor(float col[3], ShadeInput *origshi, ShadeInput * /* un-intersected rays get either rendered material color or sky color */ if (origshi->mat->fadeto_mir == MA_RAYMIR_FADETOMAT) { copy_v3_v3(col, shr->combined); - } else if (origshi->mat->fadeto_mir == MA_RAYMIR_FADETOSKY) { + } + else if (origshi->mat->fadeto_mir == MA_RAYMIR_FADETOSKY) { copy_v3_v3(shi->view, vec); normalize_v3(shi->view); @@ -729,7 +731,7 @@ static void traceray(ShadeInput *origshi, ShadeResult *origshr, short depth, con isec.orig.face = vlr; RE_RC_INIT(isec, shi); - if(RE_rayobject_raycast(R.raytree, &isec)) { + if (RE_rayobject_raycast(R.raytree, &isec)) { ShadeResult shr= {{0}}; float d= 1.0f; @@ -756,10 +758,10 @@ static void traceray(ShadeInput *origshi, ShadeResult *origshr, short depth, con if (traflag & RAY_INSIDE) d= shade_by_transmission(&isec, &shi, &shr); - if(depth>0) { + if (depth>0) { float fr, fg, fb, f, f1; - if((shi.mat->mode_l & MA_TRANSP) && shr.alpha < 1.0f && (shi.mat->mode_l & (MA_ZTRANSP | MA_RAYTRANSP))) { + if ((shi.mat->mode_l & MA_TRANSP) && shr.alpha < 1.0f && (shi.mat->mode_l & (MA_ZTRANSP | MA_RAYTRANSP))) { float nf, f, refract[3], tracol[4]; tracol[0]= shi.r; @@ -767,11 +769,11 @@ static void traceray(ShadeInput *origshi, ShadeResult *origshr, short depth, con tracol[2]= shi.b; tracol[3]= col[3]; // we pass on and accumulate alpha - if((shi.mat->mode & MA_TRANSP) && (shi.mat->mode & MA_RAYTRANSP)) { + if ((shi.mat->mode & MA_TRANSP) && (shi.mat->mode & MA_RAYTRANSP)) { /* don't overwrite traflag, it's value is used in mirror reflection */ int new_traflag = traflag; - if(new_traflag & RAY_INSIDE) { + if (new_traflag & RAY_INSIDE) { /* inside the material, so use inverse normal */ float norm[3]; norm[0]= - shi.vn[0]; @@ -820,13 +822,13 @@ static void traceray(ShadeInput *origshi, ShadeResult *origshr, short depth, con else col[3]= 1.0f; - if(shi.mat->mode_l & MA_RAYMIRROR) { + if (shi.mat->mode_l & MA_RAYMIRROR) { f= shi.ray_mirror; - if(f!=0.0f) f*= fresnel_fac(shi.view, shi.vn, shi.mat->fresnel_mir_i, shi.mat->fresnel_mir); + if (f!=0.0f) f*= fresnel_fac(shi.view, shi.vn, shi.mat->fresnel_mir_i, shi.mat->fresnel_mir); } else f= 0.0f; - if(f!=0.0f) { + if (f!=0.0f) { float mircol[4]; float ref[3]; @@ -891,16 +893,16 @@ static void DP_energy(float *table, float vec[2], int tot, float xsize, float ys min*= min; result[0]= result[1]= 0.0f; - for(y= -1; y<2; y++) { + for (y= -1; y<2; y++) { dy= ysize*y; - for(x= -1; x<2; x++) { + for (x= -1; x<2; x++) { dx= xsize*x; fp= table; - for(a=0; a<tot; a++, fp+= 2) { + for (a=0; a<tot; a++, fp+= 2) { force[0]= vec[0] - fp[0]-dx; force[1]= vec[1] - fp[1]-dy; dist= force[0]*force[0] + force[1]*force[1]; - if(dist < min && dist>0.0f) { + if (dist < min && dist>0.0f) { result[0]+= force[0]/dist; result[1]+= force[1]/dist; } @@ -922,11 +924,11 @@ static void jitter_plane_offset(float *jitter1, float *jitter2, int tot, float s float hsizex= 0.5f*sizex, hsizey= 0.5f*sizey; int x; - for(x=tot; x>0; x--, jitter1+=2, jitter2+=2) { + for (x=tot; x>0; x--, jitter1+=2, jitter2+=2) { jitter2[0]= jitter1[0] + dsizex; jitter2[1]= jitter1[1] + dsizey; - if(jitter2[0] > hsizex) jitter2[0]-= sizex; - if(jitter2[1] > hsizey) jitter2[1]-= sizey; + if (jitter2[0] > hsizex) jitter2[0]-= sizex; + if (jitter2[1] > hsizey) jitter2[1]-= sizey; } } @@ -938,29 +940,29 @@ void init_jitter_plane(LampRen *lar) int x, tot= lar->ray_totsamp; /* test if already initialized */ - if(lar->jitter) return; + if (lar->jitter) return; /* at least 4, or max threads+1 tables */ - if(BLENDER_MAX_THREADS < 4) x= 4; + if (BLENDER_MAX_THREADS < 4) x= 4; else x= BLENDER_MAX_THREADS+1; fp= lar->jitter= MEM_callocN(x*tot*2*sizeof(float), "lamp jitter tab"); /* if 1 sample, we leave table to be zero's */ - if(tot>1) { + if (tot>1) { int iter=12; /* set per-lamp fixed seed */ BLI_srandom(tot); /* fill table with random locations, area_size large */ - for(x=0; x<tot; x++, fp+=2) { + for (x=0; x<tot; x++, fp+=2) { fp[0]= (BLI_frand()-0.5f)*lar->area_size; fp[1]= (BLI_frand()-0.5f)*lar->area_sizey; } - while(iter--) { + while (iter--) { fp= lar->jitter; - for(x=tot; x>0; x--, fp+=2) { + for (x=tot; x>0; x--, fp+=2) { DP_energy(lar->jitter, fp, tot, lar->area_size, lar->area_sizey); } } @@ -978,17 +980,17 @@ static float *give_jitter_plane(LampRen *lar, int thread, int xs, int ys) tot= lar->ray_totsamp; - if(lar->ray_samp_type & LA_SAMP_JITTER) { + if (lar->ray_samp_type & LA_SAMP_JITTER) { /* made it threadsafe */ - if(lar->xold[thread]!=xs || lar->yold[thread]!=ys) { + if (lar->xold[thread]!=xs || lar->yold[thread]!=ys) { jitter_plane_offset(lar->jitter, lar->jitter+2*(thread+1)*tot, tot, lar->area_size, lar->area_sizey, BLI_thread_frand(thread), BLI_thread_frand(thread)); lar->xold[thread]= xs; lar->yold[thread]= ys; } return lar->jitter+2*(thread+1)*tot; } - if(lar->ray_samp_type & LA_SAMP_DITHER) { + if (lar->ray_samp_type & LA_SAMP_DITHER) { return lar->jitter + 2*tot*((xs & 1)+2*(ys & 1)); } @@ -1203,8 +1205,8 @@ static QMCSampler *get_thread_qmcsampler(Render *re, int thread, int type, int t /* create qmc samplers as needed, since recursion makes it hard to * predict how many are needed */ - for(qsa=re->qmcsamplers[thread].first; qsa; qsa=qsa->next) { - if(qsa->type == type && qsa->tot == tot && !qsa->used) { + for (qsa=re->qmcsamplers[thread].first; qsa; qsa=qsa->next) { + if (qsa->type == type && qsa->tot == tot && !qsa->used) { qsa->used= 1; return qsa; } @@ -1224,11 +1226,11 @@ static void release_thread_qmcsampler(Render *UNUSED(re), int UNUSED(thread), QM void free_render_qmcsampler(Render *re) { - if(re->qmcsamplers) { + if (re->qmcsamplers) { QMCSampler *qsa, *next; int a; - for(a=0; a<BLENDER_MAX_THREADS; a++) { - for(qsa=re->qmcsamplers[a].first; qsa; qsa=next) { + for (a=0; a<BLENDER_MAX_THREADS; a++) { + for (qsa=re->qmcsamplers[a].first; qsa; qsa=next) { next= qsa->next; QMC_freeSampler(qsa); } @@ -1270,7 +1272,8 @@ static int adaptive_sample_contrast_val(int samples, float prev, float val, floa * going to be the same is wasting effort */ if (fabsf( prev/(float)(samples-1) - val/(float)samples ) < thresh) { return 1; - } else + } + else return 0; } @@ -1318,16 +1321,18 @@ static void trace_refract(float col[4], ShadeInput *shi, ShadeResult *shr) /* all samples are generated per pixel */ qsa = get_thread_qmcsampler(&R, shi->thread, samp_type, max_samples); QMC_initPixel(qsa, shi->thread); - } else + } + else max_samples = 1; while (samples < max_samples) { - if(refraction(v_refract, shi->vn, shi->view, shi->ang)) { + if (refraction(v_refract, shi->vn, shi->view, shi->ang)) { traflag |= RAY_INSIDE; - } else { + } + else { /* total external reflection can happen for materials with IOR < 1.0 */ - if((shi->vlr->flag & R_SMOOTH)) + if ((shi->vlr->flag & R_SMOOTH)) reflection(v_refract, shi->vn, shi->view, shi->facenor); else reflection_simple(v_refract, shi->vn, shi->view); @@ -1349,7 +1354,8 @@ static void trace_refract(float col[4], ShadeInput *shi, ShadeResult *shr) add_v3_v3(v_refract_new, orthy); normalize_v3(v_refract_new); - } else { + } + else { /* no blurriness, use the original normal */ copy_v3_v3(v_refract_new, v_refract); } @@ -1417,7 +1423,8 @@ static void trace_reflect(float col[3], ShadeInput *shi, ShadeResult *shr, float /* all samples are generated per pixel */ qsa = get_thread_qmcsampler(&R, shi->thread, samp_type, max_samples); QMC_initPixel(qsa, shi->thread); - } else + } + else max_samples = 1; while (samples < max_samples) { @@ -1433,7 +1440,8 @@ static void trace_reflect(float col[3], ShadeInput *shi, ShadeResult *shr, float copy_v3_v3(orthy, shi->tang); mul_v3_fl(orthx, samp3d[0]); mul_v3_fl(orthy, samp3d[1]*aniso); - } else { + } + else { ortho_basis_v3v3_v3( orthx, orthy,shi->vn); mul_v3_fl(orthx, samp3d[0]); mul_v3_fl(orthy, samp3d[1]); @@ -1443,12 +1451,13 @@ static void trace_reflect(float col[3], ShadeInput *shi, ShadeResult *shr, float add_v3_v3v3(v_nor_new, shi->vn, orthx); add_v3_v3(v_nor_new, orthy); normalize_v3(v_nor_new); - } else { + } + else { /* no blurriness, use the original normal */ copy_v3_v3(v_nor_new, shi->vn); } - if((shi->vlr->flag & R_SMOOTH)) + if ((shi->vlr->flag & R_SMOOTH)) reflection(v_reflect, v_nor_new, shi->view, shi->facenor); else reflection_simple(v_reflect, v_nor_new, shi->view); @@ -1511,12 +1520,12 @@ void ray_trace(ShadeInput *shi, ShadeResult *shr) do_mir= ((shi->mat->mode & MA_RAYMIRROR) && shi->ray_mirror!=0.0f && (shi->depth <= shi->mat->ray_depth)); /* raytrace mirror and refract like to separate the spec color */ - if(shi->combinedflag & SCE_PASS_SPEC) + if (shi->combinedflag & SCE_PASS_SPEC) sub_v3_v3v3(diff, shr->combined, shr->spec); else copy_v3_v3(diff, shr->combined); - if(do_tra) { + if (do_tra) { float olddiff[3], f; trace_refract(tracol, shi, shr); @@ -1533,18 +1542,18 @@ void ray_trace(ShadeInput *shi, ShadeResult *shr) diff[1]= f*diff[1] + f1*fg*tracol[1]; diff[2]= f*diff[2] + f1*fb*tracol[2]; - if(shi->passflag & SCE_PASS_REFRACT) + if (shi->passflag & SCE_PASS_REFRACT) sub_v3_v3v3(shr->refr, diff, olddiff); - if(!(shi->combinedflag & SCE_PASS_REFRACT)) + if (!(shi->combinedflag & SCE_PASS_REFRACT)) sub_v3_v3v3(diff, diff, shr->refr); shr->alpha= MIN2(1.0f, tracol[3]); } - if(do_mir) { + if (do_mir) { const float i= shi->ray_mirror*fresnel_fac(shi->view, shi->vn, shi->mat->fresnel_mir_i, shi->mat->fresnel_mir); - if(i!=0.0f) { + if (i!=0.0f) { trace_reflect(mircol, shi, shr, i); @@ -1552,14 +1561,14 @@ void ray_trace(ShadeInput *shi, ShadeResult *shr) fg= i*shi->mirg; fb= i*shi->mirb; - if(shi->passflag & SCE_PASS_REFLECT) { + if (shi->passflag & SCE_PASS_REFLECT) { /* mirror pass is not blocked out with spec */ shr->refl[0]= fr*mircol[0] - fr*diff[0]; shr->refl[1]= fg*mircol[1] - fg*diff[1]; shr->refl[2]= fb*mircol[2] - fb*diff[2]; } - if(shi->combinedflag & SCE_PASS_REFLECT) { + if (shi->combinedflag & SCE_PASS_REFLECT) { /* values in shr->spec can be greater then 1.0. * In this case the mircol uses a zero blending factor, so ignoring it is ok. * Fixes bug #18837 - when the spec is higher then 1.0, @@ -1571,14 +1580,14 @@ void ray_trace(ShadeInput *shi, ShadeResult *shr) diff[1] *= f1; diff[2] *= f1; - if(shr->spec[0]<1.0f) diff[0] += mircol[0] * (fr*(1.0f-shr->spec[0])); - if(shr->spec[1]<1.0f) diff[1] += mircol[1] * (fg*(1.0f-shr->spec[1])); - if(shr->spec[2]<1.0f) diff[2] += mircol[2] * (fb*(1.0f-shr->spec[2])); + if (shr->spec[0]<1.0f) diff[0] += mircol[0] * (fr*(1.0f-shr->spec[0])); + if (shr->spec[1]<1.0f) diff[1] += mircol[1] * (fg*(1.0f-shr->spec[1])); + if (shr->spec[2]<1.0f) diff[2] += mircol[2] * (fb*(1.0f-shr->spec[2])); } } } /* put back together */ - if(shi->combinedflag & SCE_PASS_SPEC) + if (shi->combinedflag & SCE_PASS_SPEC) add_v3_v3v3(shr->combined, diff, shr->spec); else copy_v3_v3(shr->combined, diff); @@ -1607,7 +1616,7 @@ static void ray_trace_shadow_tra(Isect *is, ShadeInput *origshi, int depth, int * if it has col[3]>0.0f continue. so exit when alpha is full */ const float initial_dist = is->dist; - if(RE_rayobject_raycast(R.raytree, is)) { + if (RE_rayobject_raycast(R.raytree, is)) { /* Warning regarding initializing to zero's, This is not that nice, * and possibly a bit slow for every ray, however some variables were * not initialized properly in, unless using @@ -1637,7 +1646,8 @@ static void ray_trace_shadow_tra(Isect *is, ShadeInput *origshi, int depth, int 1.0f; /* mix colors based on shadfac (rgb + amount of light factor) */ addAlphaLight(col, shr.diff, shr.alpha, d*shi.mat->filter); - } else if (shi.mat->material_type == MA_TYPE_VOLUME) { + } + else if (shi.mat->material_type == MA_TYPE_VOLUME) { const float a = col[3]; col[0] = a*col[0] + shr.alpha*shr.combined[0]; @@ -1647,7 +1657,7 @@ static void ray_trace_shadow_tra(Isect *is, ShadeInput *origshi, int depth, int col[3] = (1.0f - shr.alpha)*a; } - if(depth>0 && col[3]>0.0f) { + if (depth>0 && col[3]>0.0f) { /* adapt isect struct */ copy_v3_v3(is->start, shi.co); @@ -1676,7 +1686,7 @@ static int UNUSED_FUNCTION(ray_trace_shadow_rad)(ShadeInput *ship, ShadeResult * assert(0); - if(only_one) { + if (only_one) { return 0; } only_one= 1; @@ -1691,7 +1701,7 @@ static int UNUSED_FUNCTION(ray_trace_shadow_rad)(ShadeInput *ship, ShadeResult * RE_RC_INIT(isec, shi); - for(a=0; a<8*8; a++) { + for (a=0; a<8*8; a++) { counter+=3; counter %= 768; @@ -1705,7 +1715,7 @@ static int UNUSED_FUNCTION(ray_trace_shadow_rad)(ShadeInput *ship, ShadeResult * copy_v3_v3(isec.dir, vec ); isec.dist = RE_RAYTRACE_MAXDIST; - if(RE_rayobject_raycast(R.raytree, &isec)) { + if (RE_rayobject_raycast(R.raytree, &isec)) { float fac; /* Warning, This is not that nice, and possibly a bit slow for every ray, @@ -1724,7 +1734,7 @@ static int UNUSED_FUNCTION(ray_trace_shadow_rad)(ShadeInput *ship, ShadeResult * else div+= 1.0f; } - if(div!=0.0f) { + if (div!=0.0f) { shr->diff[0]+= accum[0]/div; shr->diff[1]+= accum[1]/div; shr->diff[2]+= accum[2]/div; @@ -1757,10 +1767,10 @@ static void DS_energy(float *sphere, int tot, float vec[3]) res[0]= res[1]= res[2]= 0.0f; - for(a=0, fp=sphere; a<tot; a++, fp+=3) { + for (a=0, fp=sphere; a<tot; a++, fp+=3) { sub_v3_v3v3(force, vec, fp); fac = dot_v3v3(force, force); - if(fac!=0.0f) { + if (fac!=0.0f) { fac= 1.0f/fac; res[0]+= fac*force[0]; res[1]+= fac*force[1]; @@ -1792,12 +1802,12 @@ void init_ao_sphere(World *wrld) /* init */ fp= wrld->aosphere; - for(a=0; a<tot; a++, fp+= 3) { + for (a=0; a<tot; a++, fp+= 3) { RandomSpherical(fp); } - while(iter--) { - for(a=0, fp= wrld->aosphere; a<tot; a++, fp+= 3) { + while (iter--) { + for (a=0, fp= wrld->aosphere; a<tot; a++, fp+= 3) { DS_energy(wrld->aosphere, tot, fp); } } @@ -1812,14 +1822,14 @@ static float *threadsafe_table_sphere(int test, int thread, int xs, int ys, int static int xso[BLENDER_MAX_THREADS], yso[BLENDER_MAX_THREADS]; static int firsttime= 1; - if(firsttime) { + if (firsttime) { memset(xso, 255, sizeof(xso)); memset(yso, 255, sizeof(yso)); firsttime= 0; } - if(xs==xso[thread] && ys==yso[thread]) return R.wrld.aotables+ thread*tot*3; - if(test) return NULL; + if (xs==xso[thread] && ys==yso[thread]) return R.wrld.aotables+ thread*tot*3; + if (test) return NULL; xso[thread]= xs; yso[thread]= ys; return R.wrld.aotables+ thread*tot*3; } @@ -1852,7 +1862,7 @@ static float *sphere_sampler(int type, int resol, int thread, int xs, int ys, in // returns table if xs and ys were equal to last call, and not resetting sphere= (reset)? NULL: threadsafe_table_sphere(1, thread, xs, ys, tot); - if(sphere==NULL) { + if (sphere==NULL) { float cosfi, sinfi, cost, sint; float ang; int a; @@ -1920,16 +1930,16 @@ static void ray_ao_qmc(ShadeInput *shi, float ao[3], float env[3]) /* prevent sky colors to be added for only shadow (shadow becomes alpha) */ envcolor= R.wrld.aocolor; - if(shi->mat->mode & MA_ONLYSHADOW) + if (shi->mat->mode & MA_ONLYSHADOW) envcolor= WO_AOPLAIN; - if(envcolor == WO_AOSKYTEX) { + if (envcolor == WO_AOSKYTEX) { dxyview[0]= 1.0f/(float)R.wrld.aosamp; dxyview[1]= 1.0f/(float)R.wrld.aosamp; dxyview[2]= 0.0f; } - if(shi->vlr->flag & R_SMOOTH) { + if (shi->vlr->flag & R_SMOOTH) { copy_v3_v3(nrm, shi->vn); } else { @@ -1948,7 +1958,8 @@ static void ray_ao_qmc(ShadeInput *shi, float ao[3], float env[3]) if (max_samples < 5) max_samples = 5; qsa = get_thread_qmcsampler(&R, shi->thread, SAMP_TYPE_HALTON, max_samples); - } else if (R.wrld.ao_samp_method==WO_AOSAMP_HAMMERSLEY) + } + else if (R.wrld.ao_samp_method==WO_AOSAMP_HAMMERSLEY) qsa = get_thread_qmcsampler(&R, shi->thread, SAMP_TYPE_HAMMERSLEY, max_samples); QMC_initPixel(qsa, shi->thread); @@ -1971,11 +1982,11 @@ static void ray_ao_qmc(ShadeInput *shi, float ao[3], float env[3]) prev = fac; - if(RE_rayobject_raycast(R.raytree, &isec)) { + if (RE_rayobject_raycast(R.raytree, &isec)) { if (R.wrld.aomode & WO_AODIST) fac+= expf(-isec.dist*R.wrld.aodistfac); else fac+= 1.0f; } - else if(envcolor!=WO_AOPLAIN) { + else if (envcolor!=WO_AOPLAIN) { float skycol[4]; float view[3]; @@ -1984,7 +1995,7 @@ static void ray_ao_qmc(ShadeInput *shi, float ao[3], float env[3]) view[2]= -dir[2]; normalize_v3(view); - if(envcolor==WO_AOSKYCOL) { + if (envcolor==WO_AOSKYCOL) { const float skyfac= 0.5f * (1.0f + dot_v3v3(view, R.grvec)); env[0]+= (1.0f-skyfac)*R.wrld.horr + skyfac*R.wrld.zenr; env[1]+= (1.0f-skyfac)*R.wrld.horg + skyfac*R.wrld.zeng; @@ -2016,7 +2027,7 @@ static void ray_ao_qmc(ShadeInput *shi, float ao[3], float env[3]) /* average color times distances/hits formula */ ao[0]= ao[1]= ao[2]= 1.0f - fac/(float)samples; - if(envcolor!=WO_AOPLAIN && skyadded) + if (envcolor!=WO_AOPLAIN && skyadded) mul_v3_fl(env, (1.0f - fac/(float)samples)/((float)skyadded)); else copy_v3_v3(env, ao); @@ -2058,7 +2069,7 @@ static void ray_ao_spheresamp(ShadeInput *shi, float ao[3], float env[3]) zero_v3(env); /* bias prevents smoothed faces to appear flat */ - if(shi->vlr->flag & R_SMOOTH) { + if (shi->vlr->flag & R_SMOOTH) { bias= R.wrld.aobias; nrm= shi->vn; } @@ -2069,10 +2080,10 @@ static void ray_ao_spheresamp(ShadeInput *shi, float ao[3], float env[3]) /* prevent sky colors to be added for only shadow (shadow becomes alpha) */ envcolor= R.wrld.aocolor; - if(shi->mat->mode & MA_ONLYSHADOW) + if (shi->mat->mode & MA_ONLYSHADOW) envcolor= WO_AOPLAIN; - if(resol>32) resol= 32; + if (resol>32) resol= 32; /* get sphere samples. for faces we get the same samples for sample x/y values, * for strand render we always require a new sampler because x/y are not set */ @@ -2081,20 +2092,20 @@ static void ray_ao_spheresamp(ShadeInput *shi, float ao[3], float env[3]) // warning: since we use full sphere now, and dotproduct is below, we do twice as much tot= 2*resol*resol; - if(envcolor == WO_AOSKYTEX) { + if (envcolor == WO_AOSKYTEX) { dxyview[0]= 1.0f/(float)resol; dxyview[1]= 1.0f/(float)resol; dxyview[2]= 0.0f; } - while(tot--) { + while (tot--) { if (dot_v3v3(vec, nrm) > bias) { /* only ao samples for mask */ - if(R.r.mode & R_OSA) { + if (R.r.mode & R_OSA) { j++; - if(j==R.osa) j= 0; - if(!(shi->mask & (1<<j))) { + if (j==R.osa) j= 0; + if (!(shi->mask & (1<<j))) { vec+=3; continue; } @@ -2109,11 +2120,11 @@ static void ray_ao_spheresamp(ShadeInput *shi, float ao[3], float env[3]) isec.dist = maxdist; /* do the trace */ - if(RE_rayobject_raycast(R.raytree, &isec)) { + if (RE_rayobject_raycast(R.raytree, &isec)) { if (R.wrld.aomode & WO_AODIST) sh+= expf(-isec.dist*R.wrld.aodistfac); else sh+= 1.0f; } - else if(envcolor!=WO_AOPLAIN) { + else if (envcolor!=WO_AOPLAIN) { float skycol[4]; float view[3]; @@ -2122,7 +2133,7 @@ static void ray_ao_spheresamp(ShadeInput *shi, float ao[3], float env[3]) view[2]= -vec[2]; normalize_v3(view); - if(envcolor==WO_AOSKYCOL) { + if (envcolor==WO_AOSKYCOL) { const float fac = 0.5f * (1.0f + dot_v3v3(view, R.grvec)); env[0]+= (1.0f-fac)*R.wrld.horr + fac*R.wrld.zenr; env[1]+= (1.0f-fac)*R.wrld.horg + fac*R.wrld.zeng; @@ -2142,13 +2153,13 @@ static void ray_ao_spheresamp(ShadeInput *shi, float ao[3], float env[3]) vec+= 3; } - if(actual==0) sh= 1.0f; + if (actual==0) sh= 1.0f; else sh = 1.0f - sh/((float)actual); /* average color times distances/hits formula */ ao[0]= ao[1]= ao[2]= sh; - if(envcolor!=WO_AOPLAIN && skyadded) + if (envcolor!=WO_AOPLAIN && skyadded) mul_v3_fl(env, sh/((float)skyadded)); else copy_v3_v3(env, ao); @@ -2177,17 +2188,17 @@ static void ray_shadow_jittered_coords(ShadeInput *shi, int max, float jitco[RE_ /* for better antialising shadow samples are distributed over the subpixel * sample coordinates, this only works for raytracing depth 0 though */ - if(!shi->strand && shi->depth == 0 && count > 1 && count <= max) { + if (!shi->strand && shi->depth == 0 && count > 1 && count <= max) { float xs, ys, zs, view[3]; int samp, ordsamp, tot= 0; - for(samp=0; samp<R.osa; samp++) { - if(R.osa == 8) ordsamp = order8[samp]; - else if(R.osa == 11) ordsamp = order11[samp]; - else if(R.osa == 16) ordsamp = order16[samp]; + for (samp=0; samp<R.osa; samp++) { + if (R.osa == 8) ordsamp = order8[samp]; + else if (R.osa == 11) ordsamp = order11[samp]; + else if (R.osa == 16) ordsamp = order16[samp]; else ordsamp = samp; - if(shi->mask & (1<<ordsamp)) { + if (shi->mask & (1<<ordsamp)) { /* zbuffer has this inverse corrected, ensures xs,ys are inside pixel */ xs= (float)shi->scanco[0] + R.jit[ordsamp][0] + 0.5f; ys= (float)shi->scanco[1] + R.jit[ordsamp][1] + 0.5f; @@ -2226,9 +2237,10 @@ static void ray_shadow_qmc(ShadeInput *shi, LampRen *lar, const float lampco[3], int totjitco; colsq[0] = colsq[1] = colsq[2] = 0.0; - if(isec->mode==RE_RAY_SHADOW_TRA) { + if (isec->mode==RE_RAY_SHADOW_TRA) { shadfac[0]= shadfac[1]= shadfac[2]= shadfac[3]= 0.0f; - } else + } + else shadfac[3]= 1.0f; if (lar->ray_totsamp < 2) do_soft = 0; @@ -2237,7 +2249,8 @@ static void ray_shadow_qmc(ShadeInput *shi, LampRen *lar, const float lampco[3], if (full_osa) { if (do_soft) max_samples = max_samples/R.osa + 1; else max_samples = 1; - } else { + } + else { if (do_soft) max_samples = lar->ray_totsamp; else if (shi->depth == 0) max_samples = (R.osa > 4)?R.osa:5; else max_samples = 1; @@ -2254,7 +2267,7 @@ static void ray_shadow_qmc(ShadeInput *shi, LampRen *lar, const float lampco[3], QMC_initPixel(qsa, shi->thread); INIT_MINMAX(min, max); - for(i=0; i<totjitco; i++) + for (i=0; i<totjitco; i++) { DO_MINMAX(jitco[i], min, max); } @@ -2305,11 +2318,12 @@ static void ray_shadow_qmc(ShadeInput *shi, LampRen *lar, const float lampco[3], end[0] = vec[0]+samp3d[0]; end[1] = vec[1]+samp3d[1]; end[2] = vec[2]+samp3d[2]; - } else { + } + else { copy_v3_v3(end, vec); } - if(shi->strand) { + if (shi->strand) { /* bias away somewhat to avoid self intersection */ float jitbias= 0.5f*(len_v3(shi->dxco) + len_v3(shi->dyco)); float v[3]; @@ -2329,7 +2343,7 @@ static void ray_shadow_qmc(ShadeInput *shi, LampRen *lar, const float lampco[3], isec->dist = normalize_v3(isec->dir); /* trace the ray */ - if(isec->mode==RE_RAY_SHADOW_TRA) { + if (isec->mode==RE_RAY_SHADOW_TRA) { float col[4] = {1.0f, 1.0f, 1.0f, 1.0f}; ray_trace_shadow_tra(isec, shi, DEPTH_SHADOW_TRA, 0, col); @@ -2344,7 +2358,7 @@ static void ray_shadow_qmc(ShadeInput *shi, LampRen *lar, const float lampco[3], colsq[2] += col[2]*col[2]; } else { - if( RE_rayobject_raycast(R.raytree, isec) ) fac+= 1.0f; + if ( RE_rayobject_raycast(R.raytree, isec) ) fac+= 1.0f; } samples++; @@ -2358,7 +2372,8 @@ static void ray_shadow_qmc(ShadeInput *shi, LampRen *lar, const float lampco[3], break; else if (adaptive_sample_variance(samples, shadfac, colsq, adapt_thresh)) break; - } else { + } + else { if ((fac / samples > (1.0f-adapt_thresh)) || (fac / samples < adapt_thresh)) break; } @@ -2366,12 +2381,13 @@ static void ray_shadow_qmc(ShadeInput *shi, LampRen *lar, const float lampco[3], } } - if(isec->mode==RE_RAY_SHADOW_TRA) { + if (isec->mode==RE_RAY_SHADOW_TRA) { shadfac[0] /= samples; shadfac[1] /= samples; shadfac[2] /= samples; shadfac[3] /= samples; - } else + } + else shadfac[3]= 1.0f-fac/samples; if (qsa) @@ -2386,7 +2402,7 @@ static void ray_shadow_jitter(ShadeInput *shi, LampRen *lar, const float lampco[ int a, j= -1, mask; RayHint point_hint; - if(isec->mode==RE_RAY_SHADOW_TRA) { + if (isec->mode==RE_RAY_SHADOW_TRA) { shadfac[0]= shadfac[1]= shadfac[2]= shadfac[3]= 0.0f; } else shadfac[3]= 1.0f; @@ -2398,8 +2414,8 @@ static void ray_shadow_jitter(ShadeInput *shi, LampRen *lar, const float lampco[ /* this correction to make sure we always take at least 1 sample */ mask= shi->mask; - if(a==4) mask |= (mask>>4)|(mask>>8); - else if(a==9) mask |= (mask>>9); + if (a==4) mask |= (mask>>4)|(mask>>8); + else if (a==9) mask |= (mask>>9); copy_v3_v3(isec->start, shi->co); isec->orig.ob = shi->obi; @@ -2407,12 +2423,12 @@ static void ray_shadow_jitter(ShadeInput *shi, LampRen *lar, const float lampco[ RE_rayobject_hint_bb( R.raytree, &point_hint, isec->start, isec->start ); isec->hint = &point_hint; - while(a--) { + while (a--) { - if(R.r.mode & R_OSA) { + if (R.r.mode & R_OSA) { j++; - if(j>=R.osa) j= 0; - if(!(mask & (1<<j))) { + if (j>=R.osa) j= 0; + if (!(mask & (1<<j))) { jitlamp+= 2; continue; } @@ -2431,7 +2447,7 @@ static void ray_shadow_jitter(ShadeInput *shi, LampRen *lar, const float lampco[ isec->check = RE_CHECK_VLR_RENDER; isec->skip = RE_SKIP_VLR_NEIGHBOUR; - if(isec->mode==RE_RAY_SHADOW_TRA) { + if (isec->mode==RE_RAY_SHADOW_TRA) { /* isec.col is like shadfac, so defines amount of light (0.0 is full shadow) */ float col[4] = {1.0f, 1.0f, 1.0f, 1.0f}; @@ -2441,13 +2457,13 @@ static void ray_shadow_jitter(ShadeInput *shi, LampRen *lar, const float lampco[ shadfac[2] += col[2]; shadfac[3] += col[3]; } - else if( RE_rayobject_raycast(R.raytree, isec) ) fac+= 1.0f; + else if ( RE_rayobject_raycast(R.raytree, isec) ) fac+= 1.0f; div+= 1.0f; jitlamp+= 2; } - if(isec->mode==RE_RAY_SHADOW_TRA) { + if (isec->mode==RE_RAY_SHADOW_TRA) { shadfac[0] /= div; shadfac[1] /= div; shadfac[2] /= div; @@ -2455,7 +2471,7 @@ static void ray_shadow_jitter(ShadeInput *shi, LampRen *lar, const float lampco[ } else { // sqrt makes nice umbra effect - if(lar->ray_samp_type & LA_SAMP_UMBRA) + if (lar->ray_samp_type & LA_SAMP_UMBRA) shadfac[3]= sqrt(1.0f-fac/div); else shadfac[3]= 1.0f-fac/div; @@ -2469,24 +2485,24 @@ void ray_shadow(ShadeInput *shi, LampRen *lar, float shadfac[4]) /* setup isec */ RE_RC_INIT(isec, *shi); - if(shi->mat->mode & MA_SHADOW_TRA) isec.mode= RE_RAY_SHADOW_TRA; + if (shi->mat->mode & MA_SHADOW_TRA) isec.mode= RE_RAY_SHADOW_TRA; else isec.mode= RE_RAY_SHADOW; isec.hint = 0; - if(lar->mode & (LA_LAYER|LA_LAYER_SHADOW)) + if (lar->mode & (LA_LAYER|LA_LAYER_SHADOW)) isec.lay= lar->lay; else isec.lay= -1; /* only when not mir tracing, first hit optimm */ - if(shi->depth==0) { + if (shi->depth==0) { isec.last_hit = lar->last_hit[shi->thread]; } else { isec.last_hit = NULL; } - if(lar->type==LA_SUN || lar->type==LA_HEMI) { + if (lar->type==LA_SUN || lar->type==LA_HEMI) { /* jitter and QMC sampling add a displace vector to the lamp position * that's incorrect because a SUN lamp does not has an exact position * and the displace should be done at the ray vector instead of the @@ -2512,8 +2528,9 @@ void ray_shadow(ShadeInput *shi, LampRen *lar, float shadfac[4]) ray_shadow_qmc(shi, lar, lampco, shadfac, &isec); - } else { - if(lar->ray_totsamp<2) { + } + else { + if (lar->ray_totsamp<2) { isec.orig.ob = shi->obi; isec.orig.face = shi->vlr; @@ -2525,14 +2542,14 @@ void ray_shadow(ShadeInput *shi, LampRen *lar, float shadfac[4]) sub_v3_v3v3(isec.dir, lampco, isec.start); isec.dist = normalize_v3(isec.dir); - if(isec.mode==RE_RAY_SHADOW_TRA) { + if (isec.mode==RE_RAY_SHADOW_TRA) { /* isec.col is like shadfac, so defines amount of light (0.0 is full shadow) */ float col[4] = {1.0f, 1.0f, 1.0f, 1.0f}; ray_trace_shadow_tra(&isec, shi, DEPTH_SHADOW_TRA, 0, col); copy_v4_v4(shadfac, col); } - else if(RE_rayobject_raycast(R.raytree, &isec)) + else if (RE_rayobject_raycast(R.raytree, &isec)) shadfac[3]= 0.0f; } else { @@ -2541,7 +2558,7 @@ void ray_shadow(ShadeInput *shi, LampRen *lar, float shadfac[4]) } /* for first hit optim, set last interesected shadow face */ - if(shi->depth==0) { + if (shi->depth==0) { lar->last_hit[shi->thread] = isec.last_hit; } @@ -2561,9 +2578,9 @@ static void ray_translucent(ShadeInput *shi, LampRen *lar, float *distfac, float isec.mode= RE_RAY_SHADOW_TRA; isec.hint = 0; - if(lar->mode & LA_LAYER) isec.lay= lar->lay; else isec.lay= -1; + if (lar->mode & LA_LAYER) isec.lay= lar->lay; else isec.lay= -1; - if(lar->type==LA_SUN || lar->type==LA_HEMI) { + if (lar->type==LA_SUN || lar->type==LA_HEMI) { lampco[0]= shi->co[0] - RE_RAYTRACE_MAXDIST*lar->vec[0]; lampco[1]= shi->co[1] - RE_RAYTRACE_MAXDIST*lar->vec[1]; lampco[2]= shi->co[2] - RE_RAYTRACE_MAXDIST*lar->vec[2]; @@ -2579,7 +2596,7 @@ static void ray_translucent(ShadeInput *shi, LampRen *lar, float *distfac, float copy_v3_v3(isec.start, shi->co); copy_v3_v3(isec.end, lampco); - if(RE_rayobject_raycast(R.raytree, &isec)) { + if (RE_rayobject_raycast(R.raytree, &isec)) { /* we got a face */ /* render co */ diff --git a/source/blender/render/intern/source/render_result.c b/source/blender/render/intern/source/render_result.c index 2cf5346fdd7..37d6479e7bc 100644 --- a/source/blender/render/intern/source/render_result.c +++ b/source/blender/render/intern/source/render_result.c @@ -60,19 +60,19 @@ void render_result_free(RenderResult *res) { - if(res==NULL) return; + if (res==NULL) return; - while(res->layers.first) { + while (res->layers.first) { RenderLayer *rl= res->layers.first; - if(rl->rectf) MEM_freeN(rl->rectf); + if (rl->rectf) MEM_freeN(rl->rectf); /* acolrect and scolrect are optionally allocated in shade_tile, only free here since it can be used for drawing */ - if(rl->acolrect) MEM_freeN(rl->acolrect); - if(rl->scolrect) MEM_freeN(rl->scolrect); + if (rl->acolrect) MEM_freeN(rl->acolrect); + if (rl->scolrect) MEM_freeN(rl->scolrect); - while(rl->passes.first) { + while (rl->passes.first) { RenderPass *rpass= rl->passes.first; - if(rpass->rect) MEM_freeN(rpass->rect); + if (rpass->rect) MEM_freeN(rpass->rect); BLI_remlink(&rl->passes, rpass); MEM_freeN(rpass); } @@ -80,13 +80,13 @@ void render_result_free(RenderResult *res) MEM_freeN(rl); } - if(res->rect32) + if (res->rect32) MEM_freeN(res->rect32); - if(res->rectz) + if (res->rectz) MEM_freeN(res->rectz); - if(res->rectf) + if (res->rectf) MEM_freeN(res->rectf); - if(res->text) + if (res->text) MEM_freeN(res->text); MEM_freeN(res); @@ -97,10 +97,10 @@ void render_result_free_list(ListBase *lb, RenderResult *rr) { RenderResult *rrnext; - for(; rr; rr= rrnext) { + for (; rr; rr= rrnext) { rrnext= rr->next; - if(lb && lb->first) + if (lb && lb->first) BLI_remlink(lb, rr); render_result_free(rr); @@ -114,167 +114,167 @@ void render_result_free_list(ListBase *lb, RenderResult *rr) static const char *get_pass_name(int passtype, int channel) { - if(passtype == SCE_PASS_COMBINED) { - if(channel==-1) return "Combined"; - if(channel==0) return "Combined.R"; - if(channel==1) return "Combined.G"; - if(channel==2) return "Combined.B"; + if (passtype == SCE_PASS_COMBINED) { + if (channel==-1) return "Combined"; + if (channel==0) return "Combined.R"; + if (channel==1) return "Combined.G"; + if (channel==2) return "Combined.B"; return "Combined.A"; } - if(passtype == SCE_PASS_Z) { - if(channel==-1) return "Depth"; + if (passtype == SCE_PASS_Z) { + if (channel==-1) return "Depth"; return "Depth.Z"; } - if(passtype == SCE_PASS_VECTOR) { - if(channel==-1) return "Vector"; - if(channel==0) return "Vector.X"; - if(channel==1) return "Vector.Y"; - if(channel==2) return "Vector.Z"; + if (passtype == SCE_PASS_VECTOR) { + if (channel==-1) return "Vector"; + if (channel==0) return "Vector.X"; + if (channel==1) return "Vector.Y"; + if (channel==2) return "Vector.Z"; return "Vector.W"; } - if(passtype == SCE_PASS_NORMAL) { - if(channel==-1) return "Normal"; - if(channel==0) return "Normal.X"; - if(channel==1) return "Normal.Y"; + if (passtype == SCE_PASS_NORMAL) { + if (channel==-1) return "Normal"; + if (channel==0) return "Normal.X"; + if (channel==1) return "Normal.Y"; return "Normal.Z"; } - if(passtype == SCE_PASS_UV) { - if(channel==-1) return "UV"; - if(channel==0) return "UV.U"; - if(channel==1) return "UV.V"; + if (passtype == SCE_PASS_UV) { + if (channel==-1) return "UV"; + if (channel==0) return "UV.U"; + if (channel==1) return "UV.V"; return "UV.A"; } - if(passtype == SCE_PASS_RGBA) { - if(channel==-1) return "Color"; - if(channel==0) return "Color.R"; - if(channel==1) return "Color.G"; - if(channel==2) return "Color.B"; + if (passtype == SCE_PASS_RGBA) { + if (channel==-1) return "Color"; + if (channel==0) return "Color.R"; + if (channel==1) return "Color.G"; + if (channel==2) return "Color.B"; return "Color.A"; } - if(passtype == SCE_PASS_EMIT) { - if(channel==-1) return "Emit"; - if(channel==0) return "Emit.R"; - if(channel==1) return "Emit.G"; + if (passtype == SCE_PASS_EMIT) { + if (channel==-1) return "Emit"; + if (channel==0) return "Emit.R"; + if (channel==1) return "Emit.G"; return "Emit.B"; } - if(passtype == SCE_PASS_DIFFUSE) { - if(channel==-1) return "Diffuse"; - if(channel==0) return "Diffuse.R"; - if(channel==1) return "Diffuse.G"; + if (passtype == SCE_PASS_DIFFUSE) { + if (channel==-1) return "Diffuse"; + if (channel==0) return "Diffuse.R"; + if (channel==1) return "Diffuse.G"; return "Diffuse.B"; } - if(passtype == SCE_PASS_SPEC) { - if(channel==-1) return "Spec"; - if(channel==0) return "Spec.R"; - if(channel==1) return "Spec.G"; + if (passtype == SCE_PASS_SPEC) { + if (channel==-1) return "Spec"; + if (channel==0) return "Spec.R"; + if (channel==1) return "Spec.G"; return "Spec.B"; } - if(passtype == SCE_PASS_SHADOW) { - if(channel==-1) return "Shadow"; - if(channel==0) return "Shadow.R"; - if(channel==1) return "Shadow.G"; + if (passtype == SCE_PASS_SHADOW) { + if (channel==-1) return "Shadow"; + if (channel==0) return "Shadow.R"; + if (channel==1) return "Shadow.G"; return "Shadow.B"; } - if(passtype == SCE_PASS_AO) { - if(channel==-1) return "AO"; - if(channel==0) return "AO.R"; - if(channel==1) return "AO.G"; + if (passtype == SCE_PASS_AO) { + if (channel==-1) return "AO"; + if (channel==0) return "AO.R"; + if (channel==1) return "AO.G"; return "AO.B"; } - if(passtype == SCE_PASS_ENVIRONMENT) { - if(channel==-1) return "Env"; - if(channel==0) return "Env.R"; - if(channel==1) return "Env.G"; + if (passtype == SCE_PASS_ENVIRONMENT) { + if (channel==-1) return "Env"; + if (channel==0) return "Env.R"; + if (channel==1) return "Env.G"; return "Env.B"; } - if(passtype == SCE_PASS_INDIRECT) { - if(channel==-1) return "Indirect"; - if(channel==0) return "Indirect.R"; - if(channel==1) return "Indirect.G"; + if (passtype == SCE_PASS_INDIRECT) { + if (channel==-1) return "Indirect"; + if (channel==0) return "Indirect.R"; + if (channel==1) return "Indirect.G"; return "Indirect.B"; } - if(passtype == SCE_PASS_REFLECT) { - if(channel==-1) return "Reflect"; - if(channel==0) return "Reflect.R"; - if(channel==1) return "Reflect.G"; + if (passtype == SCE_PASS_REFLECT) { + if (channel==-1) return "Reflect"; + if (channel==0) return "Reflect.R"; + if (channel==1) return "Reflect.G"; return "Reflect.B"; } - if(passtype == SCE_PASS_REFRACT) { - if(channel==-1) return "Refract"; - if(channel==0) return "Refract.R"; - if(channel==1) return "Refract.G"; + if (passtype == SCE_PASS_REFRACT) { + if (channel==-1) return "Refract"; + if (channel==0) return "Refract.R"; + if (channel==1) return "Refract.G"; return "Refract.B"; } - if(passtype == SCE_PASS_INDEXOB) { - if(channel==-1) return "IndexOB"; + if (passtype == SCE_PASS_INDEXOB) { + if (channel==-1) return "IndexOB"; return "IndexOB.X"; } - if(passtype == SCE_PASS_INDEXMA) { - if(channel==-1) return "IndexMA"; + if (passtype == SCE_PASS_INDEXMA) { + if (channel==-1) return "IndexMA"; return "IndexMA.X"; } - if(passtype == SCE_PASS_MIST) { - if(channel==-1) return "Mist"; + if (passtype == SCE_PASS_MIST) { + if (channel==-1) return "Mist"; return "Mist.Z"; } - if(passtype == SCE_PASS_RAYHITS) { - if(channel==-1) return "Rayhits"; - if(channel==0) return "Rayhits.R"; - if(channel==1) return "Rayhits.G"; + if (passtype == SCE_PASS_RAYHITS) { + if (channel==-1) return "Rayhits"; + if (channel==0) return "Rayhits.R"; + if (channel==1) return "Rayhits.G"; return "Rayhits.B"; } - if(passtype == SCE_PASS_DIFFUSE_DIRECT) { - if(channel==-1) return "DiffDir"; - if(channel==0) return "DiffDir.R"; - if(channel==1) return "DiffDir.G"; + if (passtype == SCE_PASS_DIFFUSE_DIRECT) { + if (channel==-1) return "DiffDir"; + if (channel==0) return "DiffDir.R"; + if (channel==1) return "DiffDir.G"; return "DiffDir.B"; } - if(passtype == SCE_PASS_DIFFUSE_INDIRECT) { - if(channel==-1) return "DiffInd"; - if(channel==0) return "DiffInd.R"; - if(channel==1) return "DiffInd.G"; + if (passtype == SCE_PASS_DIFFUSE_INDIRECT) { + if (channel==-1) return "DiffInd"; + if (channel==0) return "DiffInd.R"; + if (channel==1) return "DiffInd.G"; return "DiffInd.B"; } - if(passtype == SCE_PASS_DIFFUSE_COLOR) { - if(channel==-1) return "DiffCol"; - if(channel==0) return "DiffCol.R"; - if(channel==1) return "DiffCol.G"; + if (passtype == SCE_PASS_DIFFUSE_COLOR) { + if (channel==-1) return "DiffCol"; + if (channel==0) return "DiffCol.R"; + if (channel==1) return "DiffCol.G"; return "DiffCol.B"; } - if(passtype == SCE_PASS_GLOSSY_DIRECT) { - if(channel==-1) return "GlossDir"; - if(channel==0) return "GlossDir.R"; - if(channel==1) return "GlossDir.G"; + if (passtype == SCE_PASS_GLOSSY_DIRECT) { + if (channel==-1) return "GlossDir"; + if (channel==0) return "GlossDir.R"; + if (channel==1) return "GlossDir.G"; return "GlossDir.B"; } - if(passtype == SCE_PASS_GLOSSY_INDIRECT) { - if(channel==-1) return "GlossInd"; - if(channel==0) return "GlossInd.R"; - if(channel==1) return "GlossInd.G"; + if (passtype == SCE_PASS_GLOSSY_INDIRECT) { + if (channel==-1) return "GlossInd"; + if (channel==0) return "GlossInd.R"; + if (channel==1) return "GlossInd.G"; return "GlossInd.B"; } - if(passtype == SCE_PASS_GLOSSY_COLOR) { - if(channel==-1) return "GlossCol"; - if(channel==0) return "GlossCol.R"; - if(channel==1) return "GlossCol.G"; + if (passtype == SCE_PASS_GLOSSY_COLOR) { + if (channel==-1) return "GlossCol"; + if (channel==0) return "GlossCol.R"; + if (channel==1) return "GlossCol.G"; return "GlossCol.B"; } - if(passtype == SCE_PASS_TRANSM_DIRECT) { - if(channel==-1) return "TransDir"; - if(channel==0) return "TransDir.R"; - if(channel==1) return "TransDir.G"; + if (passtype == SCE_PASS_TRANSM_DIRECT) { + if (channel==-1) return "TransDir"; + if (channel==0) return "TransDir.R"; + if (channel==1) return "TransDir.G"; return "TransDir.B"; } - if(passtype == SCE_PASS_TRANSM_INDIRECT) { - if(channel==-1) return "TransInd"; - if(channel==0) return "TransInd.R"; - if(channel==1) return "TransInd.G"; + if (passtype == SCE_PASS_TRANSM_INDIRECT) { + if (channel==-1) return "TransInd"; + if (channel==0) return "TransInd.R"; + if (channel==1) return "TransInd.G"; return "TransInd.B"; } - if(passtype == SCE_PASS_TRANSM_COLOR) { - if(channel==-1) return "TransCol"; - if(channel==0) return "TransCol.R"; - if(channel==1) return "TransCol.G"; + if (passtype == SCE_PASS_TRANSM_COLOR) { + if (channel==-1) return "TransCol"; + if (channel==0) return "TransCol.R"; + if (channel==1) return "TransCol.G"; return "TransCol.B"; } return "Unknown"; @@ -283,88 +283,88 @@ static const char *get_pass_name(int passtype, int channel) static int passtype_from_name(const char *str) { - if(strcmp(str, "Combined")==0) + if (strcmp(str, "Combined")==0) return SCE_PASS_COMBINED; - if(strcmp(str, "Depth")==0) + if (strcmp(str, "Depth")==0) return SCE_PASS_Z; - if(strcmp(str, "Vector")==0) + if (strcmp(str, "Vector")==0) return SCE_PASS_VECTOR; - if(strcmp(str, "Normal")==0) + if (strcmp(str, "Normal")==0) return SCE_PASS_NORMAL; - if(strcmp(str, "UV")==0) + if (strcmp(str, "UV")==0) return SCE_PASS_UV; - if(strcmp(str, "Color")==0) + if (strcmp(str, "Color")==0) return SCE_PASS_RGBA; - if(strcmp(str, "Emit")==0) + if (strcmp(str, "Emit")==0) return SCE_PASS_EMIT; - if(strcmp(str, "Diffuse")==0) + if (strcmp(str, "Diffuse")==0) return SCE_PASS_DIFFUSE; - if(strcmp(str, "Spec")==0) + if (strcmp(str, "Spec")==0) return SCE_PASS_SPEC; - if(strcmp(str, "Shadow")==0) + if (strcmp(str, "Shadow")==0) return SCE_PASS_SHADOW; - if(strcmp(str, "AO")==0) + if (strcmp(str, "AO")==0) return SCE_PASS_AO; - if(strcmp(str, "Env")==0) + if (strcmp(str, "Env")==0) return SCE_PASS_ENVIRONMENT; - if(strcmp(str, "Indirect")==0) + if (strcmp(str, "Indirect")==0) return SCE_PASS_INDIRECT; - if(strcmp(str, "Reflect")==0) + if (strcmp(str, "Reflect")==0) return SCE_PASS_REFLECT; - if(strcmp(str, "Refract")==0) + if (strcmp(str, "Refract")==0) return SCE_PASS_REFRACT; - if(strcmp(str, "IndexOB")==0) + if (strcmp(str, "IndexOB")==0) return SCE_PASS_INDEXOB; - if(strcmp(str, "IndexMA")==0) + if (strcmp(str, "IndexMA")==0) return SCE_PASS_INDEXMA; - if(strcmp(str, "Mist")==0) + if (strcmp(str, "Mist")==0) return SCE_PASS_MIST; - if(strcmp(str, "RayHits")==0) + if (strcmp(str, "RayHits")==0) return SCE_PASS_RAYHITS; - if(strcmp(str, "DiffDir")==0) + if (strcmp(str, "DiffDir")==0) return SCE_PASS_DIFFUSE_DIRECT; - if(strcmp(str, "DiffInd")==0) + if (strcmp(str, "DiffInd")==0) return SCE_PASS_DIFFUSE_INDIRECT; - if(strcmp(str, "DiffCol")==0) + if (strcmp(str, "DiffCol")==0) return SCE_PASS_DIFFUSE_COLOR; - if(strcmp(str, "GlossDir")==0) + if (strcmp(str, "GlossDir")==0) return SCE_PASS_GLOSSY_DIRECT; - if(strcmp(str, "GlossInd")==0) + if (strcmp(str, "GlossInd")==0) return SCE_PASS_GLOSSY_INDIRECT; - if(strcmp(str, "GlossCol")==0) + if (strcmp(str, "GlossCol")==0) return SCE_PASS_GLOSSY_COLOR; - if(strcmp(str, "TransDir")==0) + if (strcmp(str, "TransDir")==0) return SCE_PASS_TRANSM_DIRECT; - if(strcmp(str, "TransInd")==0) + if (strcmp(str, "TransInd")==0) return SCE_PASS_TRANSM_INDIRECT; - if(strcmp(str, "TransCol")==0) + if (strcmp(str, "TransCol")==0) return SCE_PASS_TRANSM_COLOR; return 0; @@ -385,9 +385,9 @@ static void render_layer_add_pass(RenderResult *rr, RenderLayer *rl, int channel rpass->recty= rl->recty; BLI_strncpy(rpass->name, get_pass_name(rpass->passtype, -1), sizeof(rpass->name)); - if(rr->exrhandle) { + if (rr->exrhandle) { int a; - for(a=0; a<channels; a++) + for (a=0; a<channels; a++) IMB_exr_add_channel(rr->exrhandle, rl->name, get_pass_name(passtype, a), 0, 0, NULL); } else { @@ -396,15 +396,15 @@ static void render_layer_add_pass(RenderResult *rr, RenderLayer *rl, int channel rpass->rect= MEM_mapallocN(sizeof(float)*rectsize, typestr); - if(passtype==SCE_PASS_VECTOR) { + if (passtype==SCE_PASS_VECTOR) { /* initialize to max speed */ rect= rpass->rect; - for(x= rectsize-1; x>=0; x--) + for (x= rectsize-1; x>=0; x--) rect[x]= PASS_VECTOR_MAX; } - else if(passtype==SCE_PASS_Z) { + else if (passtype==SCE_PASS_Z) { rect= rpass->rect; - for(x= rectsize-1; x>=0; x--) + for (x= rectsize-1; x>=0; x--) rect[x]= 10e10; } } @@ -424,7 +424,7 @@ RenderResult *render_result_new(Render *re, rcti *partrct, int crop, int savebuf rectx= partrct->xmax - partrct->xmin; recty= partrct->ymax - partrct->ymin; - if(rectx<=0 || recty<=0) + if (rectx<=0 || recty<=0) return NULL; rr= MEM_callocN(sizeof(RenderResult), "new render result"); @@ -440,16 +440,16 @@ RenderResult *render_result_new(Render *re, rcti *partrct, int crop, int savebuf rr->tilerect.ymin = partrct->ymin - re->disprect.ymin; rr->tilerect.ymax = partrct->ymax - re->disprect.ymax; - if(savebuffers) { + if (savebuffers) { rr->exrhandle= IMB_exr_get_handle(); } /* check renderdata for amount of layers */ - for(nr=0, srl= re->r.layers.first; srl; srl= srl->next, nr++) { + for (nr=0, srl= re->r.layers.first; srl; srl= srl->next, nr++) { - if((re->r.scemode & R_SINGLE_LAYER) && nr!=re->r.actlay) + if ((re->r.scemode & R_SINGLE_LAYER) && nr!=re->r.actlay) continue; - if(srl->layflag & SCE_LAY_DISABLE) + if (srl->layflag & SCE_LAY_DISABLE) continue; rl= MEM_callocN(sizeof(RenderLayer), "new render layer"); @@ -466,7 +466,7 @@ RenderResult *render_result_new(Render *re, rcti *partrct, int crop, int savebuf rl->rectx= rectx; rl->recty= recty; - if(rr->exrhandle) { + if (rr->exrhandle) { IMB_exr_add_channel(rr->exrhandle, rl->name, "Combined.R", 0, 0, NULL); IMB_exr_add_channel(rr->exrhandle, rl->name, "Combined.G", 0, 0, NULL); IMB_exr_add_channel(rr->exrhandle, rl->name, "Combined.B", 0, 0, NULL); @@ -475,64 +475,64 @@ RenderResult *render_result_new(Render *re, rcti *partrct, int crop, int savebuf else rl->rectf= MEM_mapallocN(rectx*recty*sizeof(float)*4, "Combined rgba"); - if(srl->passflag & SCE_PASS_Z) + if (srl->passflag & SCE_PASS_Z) render_layer_add_pass(rr, rl, 1, SCE_PASS_Z); - if(srl->passflag & SCE_PASS_VECTOR) + if (srl->passflag & SCE_PASS_VECTOR) render_layer_add_pass(rr, rl, 4, SCE_PASS_VECTOR); - if(srl->passflag & SCE_PASS_NORMAL) + if (srl->passflag & SCE_PASS_NORMAL) render_layer_add_pass(rr, rl, 3, SCE_PASS_NORMAL); - if(srl->passflag & SCE_PASS_UV) + if (srl->passflag & SCE_PASS_UV) render_layer_add_pass(rr, rl, 3, SCE_PASS_UV); - if(srl->passflag & SCE_PASS_RGBA) + if (srl->passflag & SCE_PASS_RGBA) render_layer_add_pass(rr, rl, 4, SCE_PASS_RGBA); - if(srl->passflag & SCE_PASS_EMIT) + if (srl->passflag & SCE_PASS_EMIT) render_layer_add_pass(rr, rl, 3, SCE_PASS_EMIT); - if(srl->passflag & SCE_PASS_DIFFUSE) + if (srl->passflag & SCE_PASS_DIFFUSE) render_layer_add_pass(rr, rl, 3, SCE_PASS_DIFFUSE); - if(srl->passflag & SCE_PASS_SPEC) + if (srl->passflag & SCE_PASS_SPEC) render_layer_add_pass(rr, rl, 3, SCE_PASS_SPEC); - if(srl->passflag & SCE_PASS_AO) + if (srl->passflag & SCE_PASS_AO) render_layer_add_pass(rr, rl, 3, SCE_PASS_AO); - if(srl->passflag & SCE_PASS_ENVIRONMENT) + if (srl->passflag & SCE_PASS_ENVIRONMENT) render_layer_add_pass(rr, rl, 3, SCE_PASS_ENVIRONMENT); - if(srl->passflag & SCE_PASS_INDIRECT) + if (srl->passflag & SCE_PASS_INDIRECT) render_layer_add_pass(rr, rl, 3, SCE_PASS_INDIRECT); - if(srl->passflag & SCE_PASS_SHADOW) + if (srl->passflag & SCE_PASS_SHADOW) render_layer_add_pass(rr, rl, 3, SCE_PASS_SHADOW); - if(srl->passflag & SCE_PASS_REFLECT) + if (srl->passflag & SCE_PASS_REFLECT) render_layer_add_pass(rr, rl, 3, SCE_PASS_REFLECT); - if(srl->passflag & SCE_PASS_REFRACT) + if (srl->passflag & SCE_PASS_REFRACT) render_layer_add_pass(rr, rl, 3, SCE_PASS_REFRACT); - if(srl->passflag & SCE_PASS_INDEXOB) + if (srl->passflag & SCE_PASS_INDEXOB) render_layer_add_pass(rr, rl, 1, SCE_PASS_INDEXOB); - if(srl->passflag & SCE_PASS_INDEXMA) + if (srl->passflag & SCE_PASS_INDEXMA) render_layer_add_pass(rr, rl, 1, SCE_PASS_INDEXMA); - if(srl->passflag & SCE_PASS_MIST) + if (srl->passflag & SCE_PASS_MIST) render_layer_add_pass(rr, rl, 1, SCE_PASS_MIST); - if(rl->passflag & SCE_PASS_RAYHITS) + if (rl->passflag & SCE_PASS_RAYHITS) render_layer_add_pass(rr, rl, 4, SCE_PASS_RAYHITS); - if(srl->passflag & SCE_PASS_DIFFUSE_DIRECT) + if (srl->passflag & SCE_PASS_DIFFUSE_DIRECT) render_layer_add_pass(rr, rl, 3, SCE_PASS_DIFFUSE_DIRECT); - if(srl->passflag & SCE_PASS_DIFFUSE_INDIRECT) + if (srl->passflag & SCE_PASS_DIFFUSE_INDIRECT) render_layer_add_pass(rr, rl, 3, SCE_PASS_DIFFUSE_INDIRECT); - if(srl->passflag & SCE_PASS_DIFFUSE_COLOR) + if (srl->passflag & SCE_PASS_DIFFUSE_COLOR) render_layer_add_pass(rr, rl, 3, SCE_PASS_DIFFUSE_COLOR); - if(srl->passflag & SCE_PASS_GLOSSY_DIRECT) + if (srl->passflag & SCE_PASS_GLOSSY_DIRECT) render_layer_add_pass(rr, rl, 3, SCE_PASS_GLOSSY_DIRECT); - if(srl->passflag & SCE_PASS_GLOSSY_INDIRECT) + if (srl->passflag & SCE_PASS_GLOSSY_INDIRECT) render_layer_add_pass(rr, rl, 3, SCE_PASS_GLOSSY_INDIRECT); - if(srl->passflag & SCE_PASS_GLOSSY_COLOR) + if (srl->passflag & SCE_PASS_GLOSSY_COLOR) render_layer_add_pass(rr, rl, 3, SCE_PASS_GLOSSY_COLOR); - if(srl->passflag & SCE_PASS_TRANSM_DIRECT) + if (srl->passflag & SCE_PASS_TRANSM_DIRECT) render_layer_add_pass(rr, rl, 3, SCE_PASS_TRANSM_DIRECT); - if(srl->passflag & SCE_PASS_TRANSM_INDIRECT) + if (srl->passflag & SCE_PASS_TRANSM_INDIRECT) render_layer_add_pass(rr, rl, 3, SCE_PASS_TRANSM_INDIRECT); - if(srl->passflag & SCE_PASS_TRANSM_COLOR) + if (srl->passflag & SCE_PASS_TRANSM_COLOR) render_layer_add_pass(rr, rl, 3, SCE_PASS_TRANSM_COLOR); } /* sss, previewrender and envmap don't do layers, so we make a default one */ - if(rr->layers.first==NULL) { + if (rr->layers.first==NULL) { rl= MEM_callocN(sizeof(RenderLayer), "new render layer"); BLI_addtail(&rr->layers, rl); @@ -540,7 +540,7 @@ RenderResult *render_result_new(Render *re, rcti *partrct, int crop, int savebuf rl->recty= recty; /* duplicate code... */ - if(rr->exrhandle) { + if (rr->exrhandle) { IMB_exr_add_channel(rr->exrhandle, rl->name, "Combined.R", 0, 0, NULL); IMB_exr_add_channel(rr->exrhandle, rl->name, "Combined.G", 0, 0, NULL); IMB_exr_add_channel(rr->exrhandle, rl->name, "Combined.B", 0, 0, NULL); @@ -569,10 +569,10 @@ RenderResult *render_result_new_full_sample(Render *re, ListBase *lb, rcti *part { int a; - if(re->osa==0) + if (re->osa==0) return render_result_new(re, partrct, crop, savebuffers); - for(a=0; a<re->osa; a++) { + for (a=0; a<re->osa; a++) { RenderResult *rr= render_result_new(re, partrct, crop, savebuffers); BLI_addtail(lb, rr); rr->sample_nr= a; @@ -604,12 +604,12 @@ static void ml_addpass_cb(void *UNUSED(base), void *lay, char *str, float *rect, rpass->channels= totchan; rpass->passtype= passtype_from_name(str); - if(rpass->passtype==0) printf("unknown pass %s\n", str); + if (rpass->passtype==0) printf("unknown pass %s\n", str); rl->passflag |= rpass->passtype; BLI_strncpy(rpass->name, str, EXR_PASS_MAXNAME); /* channel id chars */ - for(a=0; a<totchan; a++) + for (a=0; a<totchan; a++) rpass->chan_id[a]= chan_id[a]; rpass->rect= rect; @@ -627,11 +627,11 @@ RenderResult *render_result_new_from_exr(void *exrhandle, int rectx, int recty) IMB_exr_multilayer_convert(exrhandle, rr, ml_addlayer_cb, ml_addpass_cb); - for(rl=rr->layers.first; rl; rl=rl->next) { + for (rl=rr->layers.first; rl; rl=rl->next) { rl->rectx= rectx; rl->recty= recty; - for(rpass=rl->passes.first; rpass; rpass=rpass->next) { + for (rpass=rl->passes.first; rpass; rpass=rpass->next) { rpass->rectx= rectx; rpass->recty= recty; } @@ -649,7 +649,7 @@ static void do_merge_tile(RenderResult *rr, RenderResult *rrpart, float *target, copylen= tilex= rrpart->rectx; tiley= rrpart->recty; - if(rrpart->crop) { /* filters add pixel extra */ + if (rrpart->crop) { /* filters add pixel extra */ tile+= pixsize*(rrpart->crop + rrpart->crop*tilex); copylen= tilex - 2*rrpart->crop; @@ -667,7 +667,7 @@ static void do_merge_tile(RenderResult *rr, RenderResult *rrpart, float *target, tilex *= pixsize; ofs= pixsize*rr->rectx; - for(y=0; y<tiley; y++) { + for (y=0; y<tiley; y++) { memcpy(target, tile, copylen); target+= ofs; tile+= tilex; @@ -682,14 +682,14 @@ void render_result_merge(RenderResult *rr, RenderResult *rrpart) RenderLayer *rl, *rlp; RenderPass *rpass, *rpassp; - for(rl= rr->layers.first, rlp= rrpart->layers.first; rl && rlp; rl= rl->next, rlp= rlp->next) { + for (rl= rr->layers.first, rlp= rrpart->layers.first; rl && rlp; rl= rl->next, rlp= rlp->next) { /* combined */ - if(rl->rectf && rlp->rectf) + if (rl->rectf && rlp->rectf) do_merge_tile(rr, rrpart, rl->rectf, rlp->rectf, 4); /* passes are allocated in sync */ - for(rpass= rl->passes.first, rpassp= rlp->passes.first; rpass && rpassp; rpass= rpass->next, rpassp= rpassp->next) { + for (rpass= rl->passes.first, rpassp= rlp->passes.first; rpass && rpassp; rpass= rpass->next, rpassp= rpassp->next) { do_merge_tile(rr, rrpart, rpass->rect, rpassp->rect, rpass->channels); } } @@ -722,7 +722,7 @@ int RE_WriteRenderResult(ReportList *reports, RenderResult *rr, const char *file BLI_make_existing_file(filename); /* composite result */ - if(rr->rectf) { + if (rr->rectf) { IMB_exr_add_channel(exrhandle, "Composite", "Combined.R", 4, 4*rr->rectx, rr->rectf); IMB_exr_add_channel(exrhandle, "Composite", "Combined.G", 4, 4*rr->rectx, rr->rectf+1); IMB_exr_add_channel(exrhandle, "Composite", "Combined.B", 4, 4*rr->rectx, rr->rectf+2); @@ -730,21 +730,21 @@ int RE_WriteRenderResult(ReportList *reports, RenderResult *rr, const char *file } /* add layers/passes and assign channels */ - for(rl= rr->layers.first; rl; rl= rl->next) { + for (rl= rr->layers.first; rl; rl= rl->next) { /* combined */ - if(rl->rectf) { + if (rl->rectf) { int a, xstride= 4; - for(a=0; a<xstride; a++) + for (a=0; a<xstride; a++) IMB_exr_add_channel(exrhandle, rl->name, get_pass_name(SCE_PASS_COMBINED, a), xstride, xstride*rr->rectx, rl->rectf+a); } /* passes are allocated in sync */ - for(rpass= rl->passes.first; rpass; rpass= rpass->next) { + for (rpass= rl->passes.first; rpass; rpass= rpass->next) { int a, xstride= rpass->channels; - for(a=0; a<xstride; a++) { - if(rpass->passtype) + for (a=0; a<xstride; a++) { + if (rpass->passtype) IMB_exr_add_channel(exrhandle, rl->name, get_pass_name(rpass->passtype, a), xstride, xstride*rr->rectx, rpass->rect+a); else @@ -755,7 +755,7 @@ int RE_WriteRenderResult(ReportList *reports, RenderResult *rr, const char *file } /* when the filename has no permissions, this can fail */ - if(IMB_exr_begin_write(exrhandle, filename, rr->rectx, rr->recty, compress)) { + if (IMB_exr_begin_write(exrhandle, filename, rr->rectx, rr->recty, compress)) { IMB_exr_write_channels(exrhandle); success= TRUE; } @@ -790,15 +790,15 @@ void render_result_single_layer_end(Render *re) RenderLayer *rl; int nr; - if(re->result==NULL) { + if (re->result==NULL) { printf("pop render result error; no current result!\n"); return; } - if(!re->pushedresult) + if (!re->pushedresult) return; - if(re->pushedresult->rectx==re->result->rectx && re->pushedresult->recty==re->result->recty) { + if (re->pushedresult->rectx==re->result->rectx && re->pushedresult->recty==re->result->recty) { /* find which layer in re->pushedresult should be replaced */ rl= re->result->layers.first; @@ -806,12 +806,12 @@ void render_result_single_layer_end(Render *re) BLI_remlink(&re->result->layers, rl); /* reconstruct render result layers */ - for(nr=0, srl= re->scene->r.layers.first; srl; srl= srl->next, nr++) { - if(nr==re->r.actlay) + for (nr=0, srl= re->scene->r.layers.first; srl; srl= srl->next, nr++) { + if (nr==re->r.actlay) BLI_addtail(&re->result->layers, rl); else { rlpush= RE_GetRenderLayer(re->pushedresult, srl->name); - if(rlpush) { + if (rlpush) { BLI_remlink(&re->pushedresult->layers, rlpush); BLI_addtail(&re->result->layers, rlpush); } @@ -833,9 +833,9 @@ static void save_render_result_tile(RenderResult *rr, RenderResult *rrpart) BLI_lock_thread(LOCK_IMAGE); - for(rlp= rrpart->layers.first; rlp; rlp= rlp->next) { + for (rlp= rrpart->layers.first; rlp; rlp= rlp->next) { - if(rrpart->crop) { /* filters add pixel extra */ + if (rrpart->crop) { /* filters add pixel extra */ offs= (rrpart->crop + rrpart->crop*rrpart->rectx); } else { @@ -843,17 +843,17 @@ static void save_render_result_tile(RenderResult *rr, RenderResult *rrpart) } /* combined */ - if(rlp->rectf) { + if (rlp->rectf) { int a, xstride= 4; - for(a=0; a<xstride; a++) + for (a=0; a<xstride; a++) IMB_exr_set_channel(rr->exrhandle, rlp->name, get_pass_name(SCE_PASS_COMBINED, a), xstride, xstride*rrpart->rectx, rlp->rectf+a + xstride*offs); } /* passes are allocated in sync */ - for(rpassp= rlp->passes.first; rpassp; rpassp= rpassp->next) { + for (rpassp= rlp->passes.first; rpassp; rpassp= rpassp->next) { int a, xstride= rpassp->channels; - for(a=0; a<xstride; a++) + for (a=0; a<xstride; a++) IMB_exr_set_channel(rr->exrhandle, rlp->name, get_pass_name(rpassp->passtype, a), xstride, xstride*rrpart->rectx, rpassp->rect+a + xstride*offs); } @@ -872,11 +872,11 @@ static void save_empty_result_tiles(Render *re) RenderPart *pa; RenderResult *rr; - for(rr= re->result; rr; rr= rr->next) { + for (rr= re->result; rr; rr= rr->next) { IMB_exrtile_clear_channels(rr->exrhandle); - for(pa= re->parts.first; pa; pa= pa->next) { - if(pa->ready==0) { + for (pa= re->parts.first; pa; pa= pa->next) { + if (pa->ready==0) { int party= pa->disprect.ymin - re->disprect.ymin + pa->crop; int partx= pa->disprect.xmin - re->disprect.xmin + pa->crop; IMB_exrtile_write_channels(rr->exrhandle, partx, party, 0); @@ -891,7 +891,7 @@ void render_result_exr_file_begin(Render *re) RenderResult *rr; char str[FILE_MAX]; - for(rr= re->result; rr; rr= rr->next) { + for (rr= re->result; rr; rr= rr->next) { render_result_exr_file_path(re->scene, rr->sample_nr, str); printf("write exr tmp file, %dx%d, %s\n", rr->rectx, rr->recty, str); @@ -906,7 +906,7 @@ void render_result_exr_file_end(Render *re) save_empty_result_tiles(re); - for(rr= re->result; rr; rr= rr->next) { + for (rr= re->result; rr; rr= rr->next) { IMB_exr_close(rr->exrhandle); rr->exrhandle= NULL; } @@ -920,7 +920,7 @@ void render_result_exr_file_end(Render *re) /* save part into exr file */ void render_result_exr_file_merge(RenderResult *rr, RenderResult *rrpart) { - for(; rr && rrpart; rr= rr->next, rrpart= rrpart->next) + for (; rr && rrpart; rr= rr->next, rrpart= rrpart->next) save_render_result_tile(rr, rrpart); } @@ -932,7 +932,7 @@ void render_result_exr_file_path(Scene *scene, int sample, char *filepath) BLI_strncpy(di, G.main->name, FILE_MAX); BLI_splitdirstring(di, fi); - if(sample==0) + if (sample==0) BLI_snprintf(name, sizeof(name), "%s_%s.exr", fi, scene->id.name+2); else BLI_snprintf(name, sizeof(name), "%s_%s%d.exr", fi, scene->id.name+2, sample); @@ -952,7 +952,7 @@ int render_result_exr_file_read(Render *re, int sample) render_result_exr_file_path(re->scene, sample, str); printf("read exr tmp file: %s\n", str); - if(render_result_exr_file_read_path(re->result, str)) { + if (render_result_exr_file_read_path(re->result, str)) { success= TRUE; } else { @@ -972,14 +972,14 @@ int render_result_exr_file_read_path(RenderResult *rr, const char *filepath) void *exrhandle= IMB_exr_get_handle(); int rectx, recty; - if(IMB_exr_begin_read(exrhandle, filepath, &rectx, &recty)==0) { + if (IMB_exr_begin_read(exrhandle, filepath, &rectx, &recty)==0) { printf("failed being read %s\n", filepath); IMB_exr_close(exrhandle); return 0; } - if(rr == NULL || rectx!=rr->rectx || recty!=rr->recty) { - if(rr) + if (rr == NULL || rectx!=rr->rectx || recty!=rr->recty) { + if (rr) printf("error in reading render result: dimensions don't match\n"); else printf("error in reading render result: NULL result pointer\n"); @@ -987,19 +987,19 @@ int render_result_exr_file_read_path(RenderResult *rr, const char *filepath) return 0; } - for(rl= rr->layers.first; rl; rl= rl->next) { + for (rl= rr->layers.first; rl; rl= rl->next) { /* combined */ - if(rl->rectf) { + if (rl->rectf) { int a, xstride= 4; - for(a=0; a<xstride; a++) + for (a=0; a<xstride; a++) IMB_exr_set_channel(exrhandle, rl->name, get_pass_name(SCE_PASS_COMBINED, a), xstride, xstride*rectx, rl->rectf+a); } /* passes are allocated in sync */ - for(rpass= rl->passes.first; rpass; rpass= rpass->next) { + for (rpass= rl->passes.first; rpass; rpass= rpass->next) { int a, xstride= rpass->channels; - for(a=0; a<xstride; a++) + for (a=0; a<xstride; a++) IMB_exr_set_channel(exrhandle, rl->name, get_pass_name(rpass->passtype, a), xstride, xstride*rectx, rpass->rect+a); @@ -1035,14 +1035,15 @@ ImBuf *render_result_rect_to_ibuf(RenderResult *rr, RenderData *rd) ibuf->profile = IB_PROFILE_SRGB; if (BKE_imtype_valid_depths(rd->im_format.imtype) & (R_IMF_CHAN_DEPTH_12|R_IMF_CHAN_DEPTH_16|R_IMF_CHAN_DEPTH_24|R_IMF_CHAN_DEPTH_32)) IMB_float_from_rect(ibuf); - } else { + } + else { ibuf->profile = IB_PROFILE_LINEAR_RGB; } } /* color -> greyscale */ /* editing directly would alter the render view */ - if(rd->im_format.planes == R_IMF_PLANES_BW) { + if (rd->im_format.planes == R_IMF_PLANES_BW) { ImBuf *ibuf_bw= IMB_dupImBuf(ibuf); IMB_color_to_bw(ibuf_bw); IMB_freeImBuf(ibuf); @@ -1054,7 +1055,7 @@ ImBuf *render_result_rect_to_ibuf(RenderResult *rr, RenderData *rd) void render_result_rect_from_ibuf(RenderResult *rr, RenderData *rd, ImBuf *ibuf) { - if(ibuf->rect_float) { + if (ibuf->rect_float) { /* color management: when off ensure rectf is non-lin, since thats what the internal * render engine delivers */ int profile_to= (rd->color_mgt_flag & R_COLOR_MANAGEMENT)? IB_PROFILE_LINEAR_RGB: IB_PROFILE_SRGB; @@ -1070,19 +1071,19 @@ void render_result_rect_from_ibuf(RenderResult *rr, RenderData *rd, ImBuf *ibuf) /* TSK! Since sequence render doesn't free the *rr render result, the old rect32 * can hang around when sequence render has rendered a 32 bits one before */ - if(rr->rect32) { + if (rr->rect32) { MEM_freeN(rr->rect32); rr->rect32= NULL; } } - else if(ibuf->rect) { + else if (ibuf->rect) { if (!rr->rect32) rr->rect32= MEM_mallocN(sizeof(int)*rr->rectx*rr->recty, "render_seq rect"); memcpy(rr->rect32, ibuf->rect, 4*rr->rectx*rr->recty); /* Same things as above, old rectf can hang around from previous render. */ - if(rr->rectf) { + if (rr->rectf) { MEM_freeN(rr->rectf); rr->rectf= NULL; } @@ -1101,10 +1102,10 @@ void render_result_rect_fill_zero(RenderResult *rr) void render_result_rect_get_pixels(RenderResult *rr, RenderData *rd, unsigned int *rect, int rectx, int recty) { - if(rr->rect32) { + if (rr->rect32) { memcpy(rect, rr->rect32, sizeof(int)*rr->rectx*rr->recty); } - else if(rr->rectf) { + else if (rr->rectf) { int profile_from= (rd->color_mgt_flag & R_COLOR_MANAGEMENT)? IB_PROFILE_LINEAR_RGB: IB_PROFILE_SRGB; int predivide= (rd->color_mgt_flag & R_COLOR_MANAGEMENT_PREDIVIDE); int dither= 0; diff --git a/source/blender/render/intern/source/render_texture.c b/source/blender/render/intern/source/render_texture.c index ede314a42e1..7e1ff53d4e7 100644 --- a/source/blender/render/intern/source/render_texture.c +++ b/source/blender/render/intern/source/render_texture.c @@ -96,39 +96,39 @@ static void init_render_texture(Render *re, Tex *tex) { int cfra= re->scene->r.cfra; - if(re) cfra= re->r.cfra; + if (re) cfra= re->r.cfra; /* imap test */ - if(tex->ima && ELEM(tex->ima->source, IMA_SRC_MOVIE, IMA_SRC_SEQUENCE)) { + if (tex->ima && ELEM(tex->ima->source, IMA_SRC_MOVIE, IMA_SRC_SEQUENCE)) { BKE_image_user_calc_frame(&tex->iuser, cfra, re?re->flag & R_SEC_FIELD:0); } - if(tex->type==TEX_PLUGIN) { - if(tex->plugin && tex->plugin->doit) { - if(tex->plugin->cfra) { + if (tex->type==TEX_PLUGIN) { + if (tex->plugin && tex->plugin->doit) { + if (tex->plugin->cfra) { *(tex->plugin->cfra)= (float)cfra; //BKE_curframe(re->scene); // XXX old animsys - timing stuff to be fixed } } } - else if(tex->type==TEX_ENVMAP) { + else if (tex->type==TEX_ENVMAP) { /* just in case */ tex->imaflag |= TEX_INTERPOL | TEX_MIPMAP; tex->extend= TEX_CLIP; - if(tex->env) { - if(tex->env->type==ENV_PLANE) + if (tex->env) { + if (tex->env->type==ENV_PLANE) tex->extend= TEX_EXTEND; /* only free envmap when rendermode was set to render envmaps, for previewrender */ - if(G.rendering && re) { + if (G.rendering && re) { if (re->r.mode & R_ENVMAP) - if(tex->env->stype==ENV_ANIM) + if (tex->env->stype==ENV_ANIM) BKE_free_envmapdata(tex->env); } } } - if(tex->nodetree && tex->use_nodes) { + if (tex->nodetree && tex->use_nodes) { ntreeTexBeginExecTree(tex->nodetree, 1); /* has internal flag to detect it only does it once */ } } @@ -141,22 +141,22 @@ void init_render_textures(Render *re) tex= re->main->tex.first; while(tex) { - if(tex->id.us) init_render_texture(re, tex); + if (tex->id.us) init_render_texture(re, tex); tex= tex->id.next; } } static void end_render_texture(Tex *tex) { - if(tex && tex->use_nodes && tex->nodetree && tex->nodetree->execdata) + if (tex && tex->use_nodes && tex->nodetree && tex->nodetree->execdata) ntreeTexEndExecTree(tex->nodetree->execdata, 1); } void end_render_textures(Render *re) { Tex *tex; - for(tex= re->main->tex.first; tex; tex= tex->id.next) - if(tex->id.us) + for (tex= re->main->tex.first; tex; tex= tex->id.next) + if (tex->id.us) end_render_texture(tex); } @@ -197,7 +197,7 @@ static int blend(Tex *tex, float *texvec, TexResult *texres) { float x, y, t; - if(tex->flag & TEX_FLIPBLEND) { + if (tex->flag & TEX_FLIPBLEND) { x= texvec[1]; y= texvec[0]; } @@ -206,33 +206,33 @@ static int blend(Tex *tex, float *texvec, TexResult *texres) y= texvec[1]; } - if(tex->stype==TEX_LIN) { /* lin */ + if (tex->stype==TEX_LIN) { /* lin */ texres->tin= (1.0f+x)/2.0f; } - else if(tex->stype==TEX_QUAD) { /* quad */ + else if (tex->stype==TEX_QUAD) { /* quad */ texres->tin= (1.0f+x)/2.0f; - if(texres->tin<0.0f) texres->tin= 0.0f; + if (texres->tin<0.0f) texres->tin= 0.0f; else texres->tin*= texres->tin; } - else if(tex->stype==TEX_EASE) { /* ease */ + 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; + 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); } } - else if(tex->stype==TEX_DIAG) { /* diag */ + 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= (atan2(y,x) / (2*M_PI) + 0.5); } else { /* sphere TEX_SPHERE */ texres->tin= 1.0-sqrt(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; @@ -426,37 +426,37 @@ static int magic(Tex *tex, float *texvec, TexResult *texres) x= sin( ( texvec[0]+texvec[1]+texvec[2])*5.0f ); y= cos( (-texvec[0]+texvec[1]-texvec[2])*5.0f ); z= -cos( (-texvec[0]-texvec[1]+texvec[2])*5.0f ); - if(n>0) { + if (n>0) { x*= turb; y*= turb; z*= turb; y= -cos(x-y+z); y*= turb; - if(n>1) { + if (n>1) { x= cos(x-y-z); x*= turb; - if(n>2) { + if (n>2) { z= sin(-x-y-z); z*= turb; - if(n>3) { + if (n>3) { x= -cos(-x+y-z); x*= turb; - if(n>4) { + if (n>4) { y= -sin(-x+y+z); y*= turb; - if(n>5) { + if (n>5) { y= -cos(-x+y+z); y*= turb; - if(n>6) { + if (n>6) { x= cos(x+y+z); x*= turb; - if(n>7) { + if (n>7) { z= sin(x+y-z); z*= turb; - if(n>8) { + if (n>8) { x= -cos(-x-y+z); x*= turb; - if(n>9) { + if (n>9) { y= -sin(x-y+z); y*= turb; } @@ -470,7 +470,7 @@ static int magic(Tex *tex, float *texvec, TexResult *texres) } } - if(turb!=0.0f) { + if (turb!=0.0f) { turb*= 2.0f; x/= turb; y/= turb; @@ -500,19 +500,19 @@ static int stucci(Tex *tex, float *texvec, TexResult *texres) ofs= tex->turbul/200.0f; - if(tex->stype) ofs*=(b2*b2); + 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]; - if(texres->nor) { + if (texres->nor) { copy_v3_v3(texres->nor, nor); tex_normal_derivate(tex, texres); - if(tex->stype==TEX_WALLOUT) { + if (tex->stype==TEX_WALLOUT) { texres->nor[0]= -texres->nor[0]; texres->nor[1]= -texres->nor[1]; texres->nor[2]= -texres->nor[2]; @@ -521,10 +521,10 @@ static int stucci(Tex *tex, float *texvec, TexResult *texres) retval |= TEX_NOR; } - if(tex->stype==TEX_WALLOUT) + if (tex->stype==TEX_WALLOUT) texres->tin= 1.0f-texres->tin; - if(texres->tin<0.0f) + if (texres->tin<0.0f) texres->tin= 0.0f; return retval; @@ -756,21 +756,23 @@ static int plugintex(Tex *tex, float *texvec, float *dxt, float *dyt, int osatex texres->tin= 0.0; pit= tex->plugin; - if(pit && pit->doit) { - if(texres->nor) { + if (pit && pit->doit) { + if (texres->nor) { if (pit->version < 6) { copy_v3_v3(pit->result+5, texres->nor); - } else { + } + else { copy_v3_v3(result+5, texres->nor); } } if (pit->version < 6) { - if(osatex) rgbnor= ((TexDoitold)pit->doit)(tex->stype, + if (osatex) rgbnor= ((TexDoitold)pit->doit)(tex->stype, pit->data, texvec, dxt, dyt); else rgbnor= ((TexDoitold)pit->doit)(tex->stype, pit->data, texvec, NULL, NULL); - } else { - if(osatex) rgbnor= ((TexDoit)pit->doit)(tex->stype, + } + else { + if (osatex) rgbnor= ((TexDoit)pit->doit)(tex->stype, pit->data, texvec, dxt, dyt, result); else rgbnor= ((TexDoit)pit->doit)(tex->stype, pit->data, texvec, NULL, NULL, result); @@ -778,27 +780,30 @@ static int plugintex(Tex *tex, float *texvec, float *dxt, float *dyt, int osatex if (pit->version < 6) { texres->tin = pit->result[0]; - } else { + } + else { texres->tin = result[0]; /* XXX, assigning garbage value, fixme! */ } - if(rgbnor & TEX_NOR) { - if(texres->nor) { + if (rgbnor & TEX_NOR) { + if (texres->nor) { if (pit->version < 6) { copy_v3_v3(texres->nor, pit->result+5); - } else { + } + else { copy_v3_v3(texres->nor, result+5); } } } - if(rgbnor & TEX_RGB) { + if (rgbnor & TEX_RGB) { if (pit->version < 6) { texres->tr = pit->result[1]; texres->tg = pit->result[2]; texres->tb = pit->result[3]; texres->ta = pit->result[4]; - } else { + } + else { texres->tr = result[1]; texres->tg = result[2]; texres->tb = result[3]; @@ -820,7 +825,7 @@ static int cubemap_glob(float *n, float x, float y, float z, float *adr1, float float x1, y1, z1, nor[3]; int ret; - if(n==NULL) { + if (n==NULL) { nor[0]= x; nor[1]= y; nor[2]= z; // use local render coord } else { @@ -832,12 +837,12 @@ static int cubemap_glob(float *n, float x, float y, float z, float *adr1, float y1= fabs(nor[1]); z1= fabs(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; } - 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; @@ -857,24 +862,24 @@ static int cubemap(MTex *mtex, VlakRen *vlr, float *n, float x, float y, float z { int proj[4]={0, ME_PROJXY, ME_PROJXZ, ME_PROJYZ}, ret= 0; - if(vlr) { + if (vlr) { int index; /* Mesh vertices have such flags, for others we calculate it once based on orco */ - if((vlr->puno & (ME_PROJXY|ME_PROJXZ|ME_PROJYZ))==0) { + if ((vlr->puno & (ME_PROJXY|ME_PROJXZ|ME_PROJYZ))==0) { /* test for v1, vlr can be faked for baking */ - if(vlr->v1 && vlr->v1->orco) { + if (vlr->v1 && vlr->v1->orco) { float nor[3]; normal_tri_v3( nor,vlr->v1->orco, vlr->v2->orco, vlr->v3->orco); - if( fabs(nor[0])<fabs(nor[2]) && fabs(nor[1])<fabs(nor[2]) ) vlr->puno |= ME_PROJXY; - else if( fabs(nor[0])<fabs(nor[1]) && fabs(nor[2])<fabs(nor[1]) ) vlr->puno |= ME_PROJXZ; + if ( fabs(nor[0])<fabs(nor[2]) && fabs(nor[1])<fabs(nor[2]) ) vlr->puno |= ME_PROJXY; + else if ( fabs(nor[0])<fabs(nor[1]) && fabs(nor[2])<fabs(nor[1]) ) vlr->puno |= ME_PROJXZ; else vlr->puno |= ME_PROJYZ; } else return cubemap_glob(n, x, y, z, adr1, adr2); } - if(mtex) { + if (mtex) { /* the mtex->proj{xyz} have type char. maybe this should be wider? */ /* casting to int ensures that the index type is right. */ index = (int) mtex->projx; @@ -887,11 +892,11 @@ static int cubemap(MTex *mtex, VlakRen *vlr, float *n, float x, float y, float z proj[index]= ME_PROJYZ; } - if(vlr->puno & proj[1]) { + if (vlr->puno & proj[1]) { *adr1 = (x + 1.0f) / 2.0f; *adr2 = (y + 1.0f) / 2.0f; } - else if(vlr->puno & proj[2]) { + else if (vlr->puno & proj[2]) { *adr1 = (x + 1.0f) / 2.0f; *adr2 = (z + 1.0f) / 2.0f; ret= 1; @@ -916,21 +921,21 @@ static int cubemap_ob(Object *ob, float *n, float x, float y, float z, float *ad float x1, y1, z1, nor[3]; int ret; - if(n==NULL) return 0; + if (n==NULL) return 0; copy_v3_v3(nor, n); - if(ob) mul_mat3_m4_v3(ob->imat, nor); + if (ob) mul_mat3_m4_v3(ob->imat, nor); x1= fabs(nor[0]); y1= fabs(nor[1]); z1= fabs(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; } - 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; @@ -958,53 +963,53 @@ static void do_2d_mapping(MTex *mtex, float *t, VlakRen *vlr, float *n, float *d ob= mtex->object; texco= mtex->texco; - if(R.osa==0) { + if (R.osa==0) { - if(wrap==MTEX_FLAT) { + if (wrap==MTEX_FLAT) { fx = (t[0] + 1.0f) / 2.0f; fy = (t[1] + 1.0f) / 2.0f; } - else if(wrap==MTEX_TUBE) map_to_tube( &fx, &fy,t[0], t[1], t[2]); - else if(wrap==MTEX_SPHERE) map_to_sphere( &fx, &fy,t[0], t[1], t[2]); + else if (wrap==MTEX_TUBE) map_to_tube( &fx, &fy,t[0], t[1], t[2]); + else if (wrap==MTEX_SPHERE) map_to_sphere( &fx, &fy,t[0], t[1], t[2]); else { - if(texco==TEXCO_OBJECT) cubemap_ob(ob, n, t[0], t[1], t[2], &fx, &fy); - else if(texco==TEXCO_GLOB) cubemap_glob(n, t[0], t[1], t[2], &fx, &fy); + if (texco==TEXCO_OBJECT) cubemap_ob(ob, n, t[0], t[1], t[2], &fx, &fy); + else if (texco==TEXCO_GLOB) cubemap_glob(n, t[0], t[1], t[2], &fx, &fy); else cubemap(mtex, vlr, n, t[0], t[1], t[2], &fx, &fy); } /* repeat */ - if(tex->extend==TEX_REPEAT) { - if(tex->xrepeat>1) { + 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) { + if (tex->flag & TEX_REPEAT_XMIR) { int orig= (int)floor(origf); - if(orig & 1) + if (orig & 1) fx= 1.0f-fx; } } - if(tex->yrepeat>1) { + 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) { + if (tex->flag & TEX_REPEAT_YMIR) { int orig= (int)floor(origf); - if(orig & 1) + if (orig & 1) fy= 1.0f-fy; } } } /* crop */ - if(tex->cropxmin!=0.0f || tex->cropxmax!=1.0f) { + 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) { + if (tex->cropymin!=0.0f || tex->cropymax!=1.0f) { fac1= tex->cropymax - tex->cropymin; fy= tex->cropymin+ fy*fac1; } @@ -1014,7 +1019,7 @@ static void do_2d_mapping(MTex *mtex, float *t, VlakRen *vlr, float *n, float *d } else { - if(wrap==MTEX_FLAT) { + if (wrap==MTEX_FLAT) { fx= (t[0] + 1.0f) / 2.0f; fy= (t[1] + 1.0f) / 2.0f; dxt[0]/= 2.0f; @@ -1027,15 +1032,15 @@ static void do_2d_mapping(MTex *mtex, float *t, VlakRen *vlr, float *n, float *d else if ELEM(wrap, MTEX_TUBE, MTEX_SPHERE) { /* exception: the seam behind (y<0.0) */ ok= 1; - if(t[1]<=0.0f) { + if (t[1]<=0.0f) { fx= t[0]+dxt[0]; fy= t[0]+dyt[0]; - if(fx>=0.0f && fy>=0.0f && t[0]>=0.0f); - else if(fx<=0.0f && fy<=0.0f && t[0]<=0.0f); + if (fx>=0.0f && fy>=0.0f && t[0]>=0.0f); + else if (fx<=0.0f && fy<=0.0f && t[0]<=0.0f); else ok= 0; } - if(ok) { - if(wrap==MTEX_TUBE) { + if (ok) { + if (wrap==MTEX_TUBE) { map_to_tube( area, area+1,t[0], t[1], t[2]); map_to_tube( area+2, area+3,t[0]+dxt[0], t[1]+dxt[1], t[2]+dxt[2]); map_to_tube( area+4, area+5,t[0]+dyt[0], t[1]+dyt[1], t[2]+dyt[2]); @@ -1048,7 +1053,7 @@ static void do_2d_mapping(MTex *mtex, float *t, VlakRen *vlr, float *n, float *d areaflag= 1; } else { - if(wrap==MTEX_TUBE) map_to_tube( &fx, &fy,t[0], t[1], t[2]); + if (wrap==MTEX_TUBE) map_to_tube( &fx, &fy,t[0], t[1], t[2]); else map_to_sphere( &fx, &fy,t[0], t[1], t[2]); dxt[0]/= 2.0f; dxt[1]/= 2.0f; @@ -1058,15 +1063,15 @@ static void do_2d_mapping(MTex *mtex, float *t, VlakRen *vlr, float *n, float *d } else { - if(texco==TEXCO_OBJECT) proj = cubemap_ob(ob, n, t[0], t[1], t[2], &fx, &fy); + if (texco==TEXCO_OBJECT) proj = cubemap_ob(ob, n, t[0], t[1], t[2], &fx, &fy); else if (texco==TEXCO_GLOB) proj = cubemap_glob(n, t[0], t[1], t[2], &fx, &fy); else proj = cubemap(mtex, vlr, n, t[0], t[1], t[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) { + else if (proj==2) { float f1= dxt[0], f2= dyt[0]; dxt[0]= dxt[1]; dyt[0]= dyt[1]; @@ -1087,7 +1092,7 @@ static void do_2d_mapping(MTex *mtex, float *t, VlakRen *vlr, float *n, float *d } /* if area, then reacalculate dxt[] and dyt[] */ - if(areaflag) { + if (areaflag) { fx= area[0]; fy= area[1]; dxt[0]= area[2]-fx; @@ -1097,19 +1102,19 @@ static void do_2d_mapping(MTex *mtex, float *t, VlakRen *vlr, float *n, float *d } /* repeat */ - if(tex->extend==TEX_REPEAT) { + if (tex->extend==TEX_REPEAT) { float max= 1.0f; - if(tex->xrepeat>1) { + 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) { + if (tex->flag & TEX_REPEAT_XMIR) { int orig= (int)floor(origf); - if(orig & 1) + if (orig & 1) fx= 1.0f-fx; } } @@ -1119,41 +1124,41 @@ static void do_2d_mapping(MTex *mtex, float *t, VlakRen *vlr, float *n, float *d dxt[0]*= tex->xrepeat; dyt[0]*= tex->xrepeat; } - if(tex->yrepeat>1) { + 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) { + if (tex->flag & TEX_REPEAT_YMIR) { int orig= (int)floor(origf); - if(orig & 1) + if (orig & 1) fy= 1.0f-fy; } } - if(max<tex->yrepeat) + if (max<tex->yrepeat) max= tex->yrepeat; dxt[1]*= tex->yrepeat; dyt[1]*= tex->yrepeat; } - if(max!=1.0f) { + if (max!=1.0f) { dxt[2]*= max; dyt[2]*= max; } } /* crop */ - if(tex->cropxmin!=0.0f || tex->cropxmax!=1.0f) { + 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) { + if (tex->cropymin!=0.0f || tex->cropymax!=1.0f) { fac1= tex->cropymax - tex->cropymin; fy= tex->cropymin+ fy*fac1; dxt[1]*= fac1; @@ -1175,7 +1180,7 @@ static int multitex(Tex *tex, float *texvec, float *dxt, float *dyt, int osatex, texres->talpha= 0; /* is set when image texture returns alpha (considered premul) */ - if(tex->use_nodes && tex->nodetree) { + if (tex->use_nodes && tex->nodetree) { retval = ntreeTexExecTree(tex->nodetree, texres, texvec, dxt, dyt, osatex, thread, tex, which_output, R.r.cfra, (R.r.scemode & R_TEXNODE_PREVIEW) != 0, NULL, NULL); } @@ -1207,7 +1212,7 @@ static int multitex(Tex *tex, float *texvec, float *dxt, float *dyt, int osatex, retval= texnoise(tex, texres); break; case TEX_IMAGE: - if(osatex) retval= imagewraposa(tex, tex->ima, NULL, texvec, dxt, dyt, texres); + if (osatex) retval= imagewraposa(tex, tex->ima, NULL, texvec, dxt, dyt, texres); else retval= imagewrap(tex, tex->ima, NULL, texvec, texres); tag_image_time(tex->ima); /* tag image as having being used */ break; @@ -1287,27 +1292,27 @@ static int multitex(Tex *tex, float *texvec, float *dxt, float *dyt, int osatex, /* this is called from the shader and texture nodes */ int multitex_nodes(Tex *tex, float *texvec, float *dxt, float *dyt, int osatex, TexResult *texres, short thread, short which_output, ShadeInput *shi, MTex *mtex) { - if(tex==NULL) { + if (tex==NULL) { memset(texres, 0, sizeof(TexResult)); return 0; } - if(mtex) + if (mtex) which_output= mtex->which_output; - if(tex->type==TEX_IMAGE) { + if (tex->type==TEX_IMAGE) { int rgbnor; - if(mtex) { + if (mtex) { /* we have mtex, use it for 2d mapping images only */ do_2d_mapping(mtex, texvec, shi->vlr, shi->facenor, dxt, dyt); rgbnor= multitex(tex, texvec, dxt, dyt, osatex, texres, thread, which_output); - if(mtex->mapto & (MAP_COL+MAP_COLSPEC+MAP_COLMIR)) { + if (mtex->mapto & (MAP_COL+MAP_COLSPEC+MAP_COLMIR)) { ImBuf *ibuf = BKE_image_get_ibuf(tex->ima, &tex->iuser); /* don't linearize float buffers, assumed to be linear */ - if(ibuf && !(ibuf->rect_float) && R.r.color_mgt_flag & R_COLOR_MANAGEMENT) + if (ibuf && !(ibuf->rect_float) && R.r.color_mgt_flag & R_COLOR_MANAGEMENT) srgb_to_linearrgb_v3_v3(&texres->tr, &texres->tr); } } @@ -1322,7 +1327,7 @@ int multitex_nodes(Tex *tex, float *texvec, float *dxt, float *dyt, int osatex, localmtex.texco= TEXCO_ORCO; copy_v3_v3(texvec_l, texvec); - if(dxt && dyt) { + if (dxt && dyt) { copy_v3_v3(dxt_l, dxt); copy_v3_v3(dyt_l, dyt); } @@ -1346,7 +1351,7 @@ int multitex_mtex(ShadeInput *shi, MTex *mtex, float *texvec, float *dxt, float { Tex *tex= mtex->tex; - if(tex->use_nodes && tex->nodetree) { + if (tex->use_nodes && tex->nodetree) { /* stupid exception here .. but we have to pass shi and mtex to * textures nodes for 2d mapping and color management for images */ return ntreeTexExecTree(tex->nodetree, texres, texvec, dxt, dyt, shi->osatex, shi->thread, @@ -1414,15 +1419,15 @@ void texture_rgb_blend(float in[3], const float tex[3], const float out[3], floa fact*= facg; facm= 1.0f-facg; - if(out[0] < 0.5f) + if (out[0] < 0.5f) 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]); - if(out[1] < 0.5f) + if (out[1] < 0.5f) 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]); - if(out[2] < 0.5f) + if (out[2] < 0.5f) 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]); @@ -1441,11 +1446,11 @@ void texture_rgb_blend(float in[3], const float tex[3], const float out[3], floa fact*= facg; facm= 1.0f-fact; - if(tex[0]!=0.0f) + if (tex[0]!=0.0f) in[0]= facm*out[0] + fact*out[0]/tex[0]; - if(tex[1]!=0.0f) + if (tex[1]!=0.0f) in[1]= facm*out[1] + fact*out[1]/tex[1]; - if(tex[2]!=0.0f) + if (tex[2]!=0.0f) in[2]= facm*out[2] + fact*out[2]/tex[2]; break; @@ -1463,22 +1468,22 @@ void texture_rgb_blend(float in[3], const float tex[3], const float out[3], floa facm= 1.0f-fact; col= tex[0]+((1-tex[0])*facm); - if(col < out[0]) in[0]= col; else in[0]= out[0]; + if (col < out[0]) in[0]= col; else in[0]= out[0]; col= tex[1]+((1-tex[1])*facm); - if(col < out[1]) in[1]= col; else in[1]= out[1]; + if (col < out[1]) in[1]= col; else in[1]= out[1]; col= tex[2]+((1-tex[2])*facm); - if(col < out[2]) in[2]= col; else in[2]= out[2]; + if (col < out[2]) in[2]= col; else in[2]= out[2]; break; case MTEX_LIGHT: fact*= facg; col= fact*tex[0]; - if(col > out[0]) in[0]= col; else in[0]= out[0]; + if (col > out[0]) in[0]= col; else in[0]= out[0]; col= fact*tex[1]; - if(col > out[1]) in[1]= col; else in[1]= out[1]; + if (col > out[1]) in[1]= col; else in[1]= out[1]; col= fact*tex[2]; - if(col > out[2]) in[2]= col; else in[2]= out[2]; + if (col > out[2]) in[2]= col; else in[2]= out[2]; break; case MTEX_BLEND_HUE: @@ -1523,7 +1528,7 @@ float texture_value_blend(float tex, float out, float fact, float facg, int blen fact*= facg; facm= 1.0f-fact; - if(flip) SWAP(float, fact, facm); + if (flip) SWAP(float, fact, facm); switch(blendtype) { case MTEX_BLEND: @@ -1542,7 +1547,7 @@ float texture_value_blend(float tex, float out, float fact, float facg, int blen case MTEX_OVERLAY: facm= 1.0f-facg; - if(out < 0.5f) + if (out < 0.5f) in = out * (facm + 2.0f*fact*tex); else in = 1.0f - (facm + 2.0f*fact*(1.0f - tex)) * (1.0f - out); @@ -1555,7 +1560,7 @@ float texture_value_blend(float tex, float out, float fact, float facg, int blen break; case MTEX_DIV: - if(tex!=0.0f) + if (tex!=0.0f) in= facm*out + fact*out/tex; break; @@ -1565,12 +1570,12 @@ float texture_value_blend(float tex, float out, float fact, float facg, int blen case MTEX_DARK: col= fact*tex; - if(col < out) in= col; else in= out; + if (col < out) in= col; else in= out; break; case MTEX_LIGHT: col= fact*tex; - if(col > out) in= col; else in= out; + if (col > out) in= col; else in= out; break; case MTEX_SOFT_LIGHT: @@ -1702,14 +1707,14 @@ static void compatible_bump_uv_derivs(CompatibleBump *compat_bump, ShadeInput *s // NOTE: test for shi->obr->ob here, since vlr/obr/obi can be 'fake' when called from fastshade(), another reason to move it.. // NOTE: shi->v1 is NULL when called from displace_render_vert, assigning verts in this case is not trivial because the shi quad face side is not know. if ((mtex->texflag & MTEX_COMPAT_BUMP) && shi->obr && shi->obr->ob && shi->v1) { - if(mtex->mapto & (MAP_NORM|MAP_WARP) && !((mtex->tex->type==TEX_IMAGE) && (mtex->tex->imaflag & TEX_NORMALMAP))) { + if (mtex->mapto & (MAP_NORM|MAP_WARP) && !((mtex->tex->type==TEX_IMAGE) && (mtex->tex->imaflag & TEX_NORMALMAP))) { MTFace* tf = RE_vlakren_get_tface(shi->obr, shi->vlr, i, NULL, 0); int j1 = shi->i1, j2 = shi->i2, j3 = shi->i3; vlr_set_uv_indices(shi->vlr, &j1, &j2, &j3); // compute ortho basis around normal - if(!compat_bump->nunvdone) { + if (!compat_bump->nunvdone) { // render normal is negated compat_bump->nn[0] = -shi->vn[0]; compat_bump->nn[1] = -shi->vn[1]; @@ -1763,7 +1768,7 @@ static int compatible_bump_compute(CompatibleBump *compat_bump, ShadeInput *shi, du = dv = 0.01f; // compute ortho basis around normal - if(!compat_bump->nunvdone) { + if (!compat_bump->nunvdone) { // render normal is negated negate_v3_v3(compat_bump->nn, shi->vn); ortho_basis_v3v3_v3(compat_bump->nu, compat_bump->nv, compat_bump->nn); @@ -1932,15 +1937,16 @@ static int ntap_bump_compute(NTapBump *ntap_bump, ShadeInput *shi, MTex *mtex, T float *nvec = texres->nor; texres->nor = NULL; - if(found_deriv_map==0) { - if( mtex->texflag & MTEX_BUMP_TEXTURESPACE ) { - if(tex->ima) + if (found_deriv_map==0) { + if ( mtex->texflag & MTEX_BUMP_TEXTURESPACE ) { + if (tex->ima) Hscale *= 13.0f; // appears to be a sensible default value - } else + } + else Hscale *= 0.1f; // factor 0.1 proved to look like the previous bump code } - if( !ntap_bump->init_done ) { + if ( !ntap_bump->init_done ) { copy_v3_v3(ntap_bump->vNacc, shi->vn); copy_v3_v3(ntap_bump->vNorg, shi->vn); ntap_bump->fPrevMagnitude = 1.0f; @@ -1950,7 +1956,7 @@ static int ntap_bump_compute(NTapBump *ntap_bump, ShadeInput *shi, MTex *mtex, T } // resolve image dimensions - if(found_deriv_map || (mtex->texflag&MTEX_BUMP_TEXTURESPACE)!=0) { + if (found_deriv_map || (mtex->texflag&MTEX_BUMP_TEXTURESPACE)!=0) { ImBuf* ibuf = BKE_image_get_ibuf(tex->ima, &tex->iuser); if (ibuf) { dimx = ibuf->x; @@ -1959,13 +1965,13 @@ static int ntap_bump_compute(NTapBump *ntap_bump, ShadeInput *shi, MTex *mtex, T } } - if(found_deriv_map) { + if (found_deriv_map) { float dBdu, dBdv, auto_bump = 1.0f; float s = 1; // negate this if flipped texture coordinate texco_mapping(shi, tex, mtex, co, dx, dy, texvec, dxt, dyt); rgbnor = multitex_mtex(shi, mtex, texvec, dxt, dyt, texres); - if(shi->obr->ob->derivedFinal) { + if (shi->obr->ob->derivedFinal) { auto_bump = shi->obr->ob->derivedFinal->auto_bump_scale; } @@ -1982,14 +1988,14 @@ static int ntap_bump_compute(NTapBump *ntap_bump, ShadeInput *shi, MTex *mtex, T dHdx = dBdu*dxt[0] + s * dBdv*dxt[1]; dHdy = dBdu*dyt[0] + s * dBdv*dyt[1]; } - else if(!(mtex->texflag & MTEX_5TAP_BUMP)) { + else if (!(mtex->texflag & MTEX_5TAP_BUMP)) { // compute height derivatives with respect to output image pixel coordinates x and y float STll[3], STlr[3], STul[3]; float Hll, Hlr, Hul; texco_mapping(shi, tex, mtex, co, dx, dy, texvec, dxt, dyt); - for(c=0; c<nr_channels; c++) { + for (c=0; c<nr_channels; c++) { // dx contains the derivatives (du/dx, dv/dx) // dy contains the derivatives (du/dy, dv/dy) STll[c] = texvec[c]; @@ -1998,7 +2004,7 @@ static int ntap_bump_compute(NTapBump *ntap_bump, ShadeInput *shi, MTex *mtex, T } // clear unused derivatives - for(c=nr_channels; c<3; c++) { + for (c=nr_channels; c<3; c++) { STll[c] = 0.0f; STlr[c] = 0.0f; STul[c] = 0.0f; @@ -2025,7 +2031,7 @@ static int ntap_bump_compute(NTapBump *ntap_bump, ShadeInput *shi, MTex *mtex, T texco_mapping(shi, tex, mtex, co, dx, dy, texvec, dxt, dyt); - for(c=0; c<nr_channels; c++) { + for (c=0; c<nr_channels; c++) { STc[c] = texvec[c]; STl[c] = texvec[c] - 0.5f*dxt[c]; STr[c] = texvec[c] + 0.5f*dxt[c]; @@ -2034,7 +2040,7 @@ static int ntap_bump_compute(NTapBump *ntap_bump, ShadeInput *shi, MTex *mtex, T } // clear unused derivatives - for(c=nr_channels; c<3; c++) { + for (c=nr_channels; c<3; c++) { STc[c] = 0.0f; STl[c] = 0.0f; STr[c] = 0.0f; @@ -2067,14 +2073,14 @@ static int ntap_bump_compute(NTapBump *ntap_bump, ShadeInput *shi, MTex *mtex, T * [Mik10] Mikkelsen M. S.: Bump Mapping Unparametrized Surfaces on the GPU. * -> http://jbit.net/~sparky/sfgrad_bump/mm_sfgrad_bump.pdf */ - if( mtex->texflag & MTEX_BUMP_OBJECTSPACE ) + if ( mtex->texflag & MTEX_BUMP_OBJECTSPACE ) iBumpSpace = 1; - else if( mtex->texflag & MTEX_BUMP_TEXTURESPACE ) + else if ( mtex->texflag & MTEX_BUMP_TEXTURESPACE ) iBumpSpace = 2; else iBumpSpace = 4; // ViewSpace - if( ntap_bump->iPrevBumpSpace != iBumpSpace ) { + if ( ntap_bump->iPrevBumpSpace != iBumpSpace ) { // initialize normal perturbation vectors int xyz; @@ -2087,7 +2093,7 @@ static int ntap_bump_compute(NTapBump *ntap_bump, ShadeInput *shi, MTex *mtex, T copy_v3_v3(dPdy, shi->dyco); copy_v3_v3(vN, ntap_bump->vNorg); - if( mtex->texflag & MTEX_BUMP_OBJECTSPACE ) { + if ( mtex->texflag & MTEX_BUMP_OBJECTSPACE ) { // TODO: these calculations happen for every pixel! // -> move to shi->obi mult_m4_m4m4(tmp, R.viewmat, shi->obr->ob->obmat); @@ -2108,8 +2114,8 @@ static int ntap_bump_compute(NTapBump *ntap_bump, ShadeInput *shi, MTex *mtex, T ntap_bump->sgn_det = (fDet < 0)? -1.0f: 1.0f; abs_fDet = ntap_bump->sgn_det * fDet; - if( mtex->texflag & MTEX_BUMP_TEXTURESPACE ) { - if(tex->ima) { + if ( mtex->texflag & MTEX_BUMP_TEXTURESPACE ) { + if (tex->ima) { // crazy hack solution that gives results similar to normal mapping - part 1 normalize_v3(ntap_bump->vR1); normalize_v3(ntap_bump->vR2); @@ -2118,7 +2124,7 @@ static int ntap_bump_compute(NTapBump *ntap_bump, ShadeInput *shi, MTex *mtex, T } fMagnitude = abs_fDet; - if( mtex->texflag & MTEX_BUMP_OBJECTSPACE ) { + if ( mtex->texflag & MTEX_BUMP_OBJECTSPACE ) { // pre do transform of texres->nor by the inverse transposed of obj2view mul_transposed_m3_v3( view2obj, vN ); mul_transposed_m3_v3( view2obj, ntap_bump->vR1 ); @@ -2127,16 +2133,16 @@ static int ntap_bump_compute(NTapBump *ntap_bump, ShadeInput *shi, MTex *mtex, T fMagnitude *= len_v3(vN); } - if(ntap_bump->fPrevMagnitude > 0.0f) - for(xyz=0; xyz<3; xyz++) + if (ntap_bump->fPrevMagnitude > 0.0f) + for (xyz=0; xyz<3; xyz++) ntap_bump->vNacc[xyz] *= fMagnitude / ntap_bump->fPrevMagnitude; ntap_bump->fPrevMagnitude = fMagnitude; ntap_bump->iPrevBumpSpace = iBumpSpace; } - if( mtex->texflag & MTEX_BUMP_TEXTURESPACE ) { - if(tex->ima) { + if ( mtex->texflag & MTEX_BUMP_TEXTURESPACE ) { + if (tex->ima) { // crazy hack solution that gives results similar to normal mapping - part 2 float vec[2]; const float imag_tspace_dimension_y = aspect*imag_tspace_dimension_x; @@ -2151,7 +2157,7 @@ static int ntap_bump_compute(NTapBump *ntap_bump, ShadeInput *shi, MTex *mtex, T } // subtract the surface gradient from vNacc - for(c=0; c<3; c++) { + for (c=0; c<3; c++) { float vSurfGrad_compi = ntap_bump->sgn_det * (dHdx * ntap_bump->vR1[c] + dHdy * ntap_bump->vR2[c]); ntap_bump->vNacc[c] -= vSurfGrad_compi; texres->nor[c] = ntap_bump->vNacc[c]; // copy @@ -2182,42 +2188,42 @@ void do_material_tex(ShadeInput *shi, Render *re) if (re->r.scemode & R_NO_TEX) return; /* here: test flag if there's a tex (todo) */ - for(tex_nr=0; tex_nr<MAX_MTEX; tex_nr++) { + for (tex_nr=0; tex_nr<MAX_MTEX; tex_nr++) { /* separate tex switching */ - if(shi->mat->septex & (1<<tex_nr)) continue; + if (shi->mat->septex & (1<<tex_nr)) continue; - if(shi->mat->mtex[tex_nr]) { + if (shi->mat->mtex[tex_nr]) { mtex= shi->mat->mtex[tex_nr]; tex= mtex->tex; - if(tex==0) continue; + if (tex==0) continue; found_deriv_map = (tex->type==TEX_IMAGE) && (tex->imaflag & TEX_DERIVATIVEMAP); use_compat_bump= (mtex->texflag & MTEX_COMPAT_BUMP); use_ntap_bump= ((mtex->texflag & (MTEX_3TAP_BUMP|MTEX_5TAP_BUMP|MTEX_BICUBIC_BUMP))!=0 || found_deriv_map!=0) ? 1 : 0; /* XXX texture node trees don't work for this yet */ - if(tex->nodetree && tex->use_nodes) { + if (tex->nodetree && tex->use_nodes) { use_compat_bump = 0; use_ntap_bump = 0; } /* case displacement mapping */ - if(shi->osatex==0 && use_ntap_bump) { + if (shi->osatex==0 && use_ntap_bump) { use_ntap_bump = 0; use_compat_bump = 1; } /* case ocean */ - if(tex->type == TEX_OCEAN) { + if (tex->type == TEX_OCEAN) { use_ntap_bump = 0; use_compat_bump = 0; } /* which coords */ - if(mtex->texco==TEXCO_ORCO) { - if(mtex->texflag & MTEX_DUPLI_MAPTO) { + if (mtex->texco==TEXCO_ORCO) { + if (mtex->texflag & MTEX_DUPLI_MAPTO) { co= shi->duplilo; dx= dxt; dy= dyt; dxt[0]= dxt[1]= dxt[2]= 0.0f; dyt[0]= dyt[1]= dyt[2]= 0.0f; @@ -2226,21 +2232,21 @@ void do_material_tex(ShadeInput *shi, Render *re) co= shi->lo; dx= shi->dxlo; dy= shi->dylo; } } - else if(mtex->texco==TEXCO_STICKY) { + else if (mtex->texco==TEXCO_STICKY) { co= shi->sticky; dx= shi->dxsticky; dy= shi->dysticky; } - else if(mtex->texco==TEXCO_OBJECT) { + else if (mtex->texco==TEXCO_OBJECT) { Object *ob= mtex->object; - if(ob) { + if (ob) { co= tempvec; dx= dxt; dy= dyt; copy_v3_v3(tempvec, shi->co); - if(mtex->texflag & MTEX_OB_DUPLI_ORIG) - if(shi->obi && shi->obi->duplitexmat) + if (mtex->texflag & MTEX_OB_DUPLI_ORIG) + if (shi->obi && shi->obi->duplitexmat) mul_m4_v3(shi->obi->duplitexmat, tempvec); mul_m4_v3(ob->imat_ren, tempvec); - if(shi->osatex) { + if (shi->osatex) { copy_v3_v3(dxt, shi->dxco); copy_v3_v3(dyt, shi->dyco); mul_mat3_m4_v3(ob->imat_ren, dxt); @@ -2253,21 +2259,21 @@ void do_material_tex(ShadeInput *shi, Render *re) dx= shi->dxco; dy= shi->dyco; } } - else if(mtex->texco==TEXCO_REFL) { + else if (mtex->texco==TEXCO_REFL) { calc_R_ref(shi); co= shi->ref; dx= shi->dxref; dy= shi->dyref; } - else if(mtex->texco==TEXCO_NORM) { + else if (mtex->texco==TEXCO_NORM) { co= shi->orn; dx= shi->dxno; dy= shi->dyno; } - else if(mtex->texco==TEXCO_TANGENT) { + else if (mtex->texco==TEXCO_TANGENT) { co= shi->tang; dx= shi->dxno; dy= shi->dyno; } - else if(mtex->texco==TEXCO_GLOB) { + else if (mtex->texco==TEXCO_GLOB) { co= shi->gl; dx= shi->dxgl; dy= shi->dygl; } - else if(mtex->texco==TEXCO_UV) { - if(mtex->texflag & MTEX_DUPLI_MAPTO) { + else if (mtex->texco==TEXCO_UV) { + if (mtex->texflag & MTEX_DUPLI_MAPTO) { co= shi->dupliuv; dx= dxt; dy= dyt; dxt[0]= dxt[1]= dxt[2]= 0.0f; dyt[0]= dyt[1]= dyt[2]= 0.0f; @@ -2276,9 +2282,9 @@ void do_material_tex(ShadeInput *shi, Render *re) ShadeInputUV *suv= &shi->uv[shi->actuv]; int i = shi->actuv; - if(mtex->uvname[0] != 0) { - for(i = 0; i < shi->totuv; i++) { - if(strcmp(shi->uv[i].name, mtex->uvname)==0) { + if (mtex->uvname[0] != 0) { + for (i = 0; i < shi->totuv; i++) { + if (strcmp(shi->uv[i].name, mtex->uvname)==0) { suv= &shi->uv[i]; break; } @@ -2292,10 +2298,10 @@ void do_material_tex(ShadeInput *shi, Render *re) compatible_bump_uv_derivs(&compat_bump, shi, mtex, i); } } - else if(mtex->texco==TEXCO_WINDOW) { + else if (mtex->texco==TEXCO_WINDOW) { co= shi->winco; dx= shi->dxwin; dy= shi->dywin; } - else if(mtex->texco==TEXCO_STRAND) { + else if (mtex->texco==TEXCO_STRAND) { co= tempvec; dx= dxt; dy= dyt; co[0]= shi->strandco; co[1]= co[2]= 0.0f; @@ -2304,7 +2310,7 @@ void do_material_tex(ShadeInput *shi, Render *re) dy[0]= shi->dystrand; dy[1]= dy[2]= 0.0f; } - else if(mtex->texco==TEXCO_STRESS) { + else if (mtex->texco==TEXCO_STRESS) { co= tempvec; dx= dxt; dy= dyt; co[0]= shi->stress; co[1]= co[2]= 0.0f; @@ -2316,24 +2322,24 @@ void do_material_tex(ShadeInput *shi, Render *re) else continue; // can happen when texco defines disappear and it renders old files /* the pointer defines if bumping happens */ - if(mtex->mapto & (MAP_NORM|MAP_WARP)) { + if (mtex->mapto & (MAP_NORM|MAP_WARP)) { texres.nor= norvec; norvec[0]= norvec[1]= norvec[2]= 0.0; } else texres.nor= NULL; - if(warpdone) { + if (warpdone) { add_v3_v3v3(tempvec, co, warpvec); co= tempvec; } /* XXX texture node trees don't work for this yet */ - if(texres.nor && !((tex->type==TEX_IMAGE) && (tex->imaflag & TEX_NORMALMAP))) { - if(use_compat_bump) { + if (texres.nor && !((tex->type==TEX_IMAGE) && (tex->imaflag & TEX_NORMALMAP))) { + if (use_compat_bump) { rgbnor = compatible_bump_compute(&compat_bump, shi, mtex, tex, &texres, Tnor*stencilTin, co, dx, dy, texvec, dxt, dyt); } - else if(use_ntap_bump) { + else if (use_ntap_bump) { rgbnor = ntap_bump_compute(&ntap_bump, shi, mtex, tex, &texres, Tnor*stencilTin, co, dx, dy, texvec, dxt, dyt); } @@ -2349,20 +2355,20 @@ void do_material_tex(ShadeInput *shi, Render *re) /* texture output */ - if( (rgbnor & TEX_RGB) && (mtex->texflag & MTEX_RGBTOINT)) { + if ( (rgbnor & TEX_RGB) && (mtex->texflag & MTEX_RGBTOINT)) { texres.tin= (0.35f*texres.tr+0.45f*texres.tg+0.2f*texres.tb); rgbnor-= TEX_RGB; } - if(mtex->texflag & MTEX_NEGATIVE) { - if(rgbnor & TEX_RGB) { + if (mtex->texflag & MTEX_NEGATIVE) { + if (rgbnor & TEX_RGB) { texres.tr= 1.0f-texres.tr; texres.tg= 1.0f-texres.tg; texres.tb= 1.0f-texres.tb; } texres.tin= 1.0f-texres.tin; } - if(mtex->texflag & MTEX_STENCIL) { - if(rgbnor & TEX_RGB) { + if (mtex->texflag & MTEX_STENCIL) { + if (rgbnor & TEX_RGB) { fact= texres.ta; texres.ta*= stencilTin; stencilTin*= fact; @@ -2377,10 +2383,10 @@ void do_material_tex(ShadeInput *shi, Render *re) Tnor*= stencilTin; } - if(texres.nor) { - if((rgbnor & TEX_NOR)==0) { + if (texres.nor) { + if ((rgbnor & TEX_NOR)==0) { /* make our own normal */ - if(rgbnor & TEX_RGB) { + if (rgbnor & TEX_RGB) { texres.nor[0]= texres.tr; texres.nor[1]= texres.tg; texres.nor[2]= texres.tb; @@ -2400,10 +2406,10 @@ void do_material_tex(ShadeInput *shi, Render *re) } } // warping, local space - if(mtex->mapto & MAP_WARP) { + if (mtex->mapto & MAP_WARP) { float *warpnor= texres.nor, warpnor_[3]; - if(use_ntap_bump) { + if (use_ntap_bump) { copy_v3_v3(warpnor_, texres.nor); warpnor= warpnor_; normalize_v3(warpnor_); @@ -2414,10 +2420,10 @@ void do_material_tex(ShadeInput *shi, Render *re) warpdone= 1; } #if 0 - if(mtex->texflag & MTEX_VIEWSPACE) { + if (mtex->texflag & MTEX_VIEWSPACE) { // rotate to global coords - if(mtex->texco==TEXCO_ORCO || mtex->texco==TEXCO_UV) { - if(shi->vlr && shi->obr && shi->obr->ob) { + if (mtex->texco==TEXCO_ORCO || mtex->texco==TEXCO_UV) { + if (shi->vlr && shi->obr && shi->obr->ob) { float len= normalize_v3(texres.nor); // can be optimized... (ton) mul_mat3_m4_v3(shi->obr->ob->obmat, texres.nor); @@ -2431,19 +2437,19 @@ void do_material_tex(ShadeInput *shi, Render *re) } /* mapping */ - if(mtex->mapto & (MAP_COL+MAP_COLSPEC+MAP_COLMIR)) { + if (mtex->mapto & (MAP_COL+MAP_COLSPEC+MAP_COLMIR)) { float tcol[3]; /* stencil maps on the texture control slider, not texture intensity value */ tcol[0]=texres.tr; tcol[1]=texres.tg; tcol[2]=texres.tb; - if((rgbnor & TEX_RGB)==0) { + if ((rgbnor & TEX_RGB)==0) { tcol[0]= mtex->r; tcol[1]= mtex->g; tcol[2]= mtex->b; } - else if(mtex->mapto & MAP_ALPHA) { + else if (mtex->mapto & MAP_ALPHA) { texres.tin= stencilTin; } else texres.tin= texres.ta; @@ -2458,19 +2464,19 @@ void do_material_tex(ShadeInput *shi, Render *re) srgb_to_linearrgb_v3_v3(tcol, tcol); } - if(mtex->mapto & MAP_COL) { + if (mtex->mapto & MAP_COL) { float colfac= mtex->colfac*stencilTin; texture_rgb_blend(&shi->r, tcol, &shi->r, texres.tin, colfac, mtex->blendtype); } - if(mtex->mapto & MAP_COLSPEC) { + if (mtex->mapto & MAP_COLSPEC) { float colspecfac= mtex->colspecfac*stencilTin; texture_rgb_blend(&shi->specr, tcol, &shi->specr, texres.tin, colspecfac, mtex->blendtype); } - if(mtex->mapto & MAP_COLMIR) { + if (mtex->mapto & MAP_COLMIR) { float mirrfac= mtex->mirrfac*stencilTin; // exception for envmap only - if(tex->type==TEX_ENVMAP && mtex->blendtype==MTEX_BLEND) { + if (tex->type==TEX_ENVMAP && mtex->blendtype==MTEX_BLEND) { fact= texres.tin*mirrfac; facm= 1.0f- fact; shi->refcol[0]= fact + facm*shi->refcol[0]; @@ -2483,8 +2489,8 @@ void do_material_tex(ShadeInput *shi, Render *re) } } } - if( (mtex->mapto & MAP_NORM) ) { - if(texres.nor) { + if ( (mtex->mapto & MAP_NORM) ) { + if (texres.nor) { float norfac= mtex->norfac; /* we need to code blending modes for normals too once.. now 1 exception hardcoded */ @@ -2502,7 +2508,7 @@ void do_material_tex(ShadeInput *shi, Render *re) fact = Tnor*fabsf(norfac); if (fact>1.f) fact = 1.f; facm = 1.f-fact; - if(mtex->normapspace == MTEX_NSPACE_TANGENT) { + if (mtex->normapspace == MTEX_NSPACE_TANGENT) { /* qdn: tangent space */ float B[3], tv[3]; const float * no = iFirstTimeNMap!=0 ? shi->nmapnorm : shi->vn; @@ -2522,12 +2528,12 @@ void do_material_tex(ShadeInput *shi, Render *re) copy_v3_v3(nor, texres.nor); - if(mtex->normapspace == MTEX_NSPACE_CAMERA); - else if(mtex->normapspace == MTEX_NSPACE_WORLD) { + if (mtex->normapspace == MTEX_NSPACE_CAMERA); + else if (mtex->normapspace == MTEX_NSPACE_WORLD) { mul_mat3_m4_v3(re->viewmat, nor); } - else if(mtex->normapspace == MTEX_NSPACE_OBJECT) { - if(shi->obr && shi->obr->ob) + else if (mtex->normapspace == MTEX_NSPACE_OBJECT) { + if (shi->obr && shi->obr->ob) mul_mat3_m4_v3(shi->obr->ob->obmat, nor); mul_mat3_m4_v3(re->viewmat, nor); } @@ -2550,7 +2556,7 @@ void do_material_tex(ShadeInput *shi, Render *re) else { float nor[3], dot; - if(shi->mat->mode & MA_TANGENT_V) { + if (shi->mat->mode & MA_TANGENT_V) { shi->tang[0]+= Tnor*norfac*texres.nor[0]; shi->tang[1]+= Tnor*norfac*texres.nor[1]; shi->tang[2]+= Tnor*norfac*texres.nor[2]; @@ -2577,10 +2583,10 @@ void do_material_tex(ShadeInput *shi, Render *re) } } - if( mtex->mapto & MAP_DISPLACE ) { + if ( mtex->mapto & MAP_DISPLACE ) { /* Now that most textures offer both Nor and Intensity, allow */ /* both to work, and let user select with slider. */ - if(texres.nor) { + if (texres.nor) { float norfac= mtex->norfac; shi->displace[0]+= 0.2f*Tnor*norfac*texres.nor[0]; @@ -2588,94 +2594,94 @@ void do_material_tex(ShadeInput *shi, Render *re) shi->displace[2]+= 0.2f*Tnor*norfac*texres.nor[2]; } - if(rgbnor & TEX_RGB) { + if (rgbnor & TEX_RGB) { texres.tin= (0.35f*texres.tr+0.45f*texres.tg+0.2f*texres.tb); } factt= (0.5f-texres.tin)*mtex->dispfac*stencilTin; facmm= 1.0f-factt; - if(mtex->blendtype==MTEX_BLEND) { + if (mtex->blendtype==MTEX_BLEND) { shi->displace[0]= factt*shi->vn[0] + facmm*shi->displace[0]; shi->displace[1]= factt*shi->vn[1] + facmm*shi->displace[1]; shi->displace[2]= factt*shi->vn[2] + facmm*shi->displace[2]; } - else if(mtex->blendtype==MTEX_MUL) { + else if (mtex->blendtype==MTEX_MUL) { shi->displace[0]*= factt*shi->vn[0]; shi->displace[1]*= factt*shi->vn[1]; shi->displace[2]*= factt*shi->vn[2]; } else { /* add or sub */ - if(mtex->blendtype==MTEX_SUB) factt= -factt; + if (mtex->blendtype==MTEX_SUB) factt= -factt; shi->displace[0]+= factt*shi->vn[0]; shi->displace[1]+= factt*shi->vn[1]; shi->displace[2]+= factt*shi->vn[2]; } } - if(mtex->mapto & MAP_VARS) { + if (mtex->mapto & MAP_VARS) { /* stencil maps on the texture control slider, not texture intensity value */ - if(rgbnor & TEX_RGB) { - if(texres.talpha) texres.tin= texres.ta; + if (rgbnor & TEX_RGB) { + if (texres.talpha) texres.tin= texres.ta; else texres.tin= (0.35f*texres.tr+0.45f*texres.tg+0.2f*texres.tb); } - if(mtex->mapto & MAP_REF) { + if (mtex->mapto & MAP_REF) { float difffac= mtex->difffac*stencilTin; shi->refl= texture_value_blend(mtex->def_var, shi->refl, texres.tin, difffac, mtex->blendtype); - if(shi->refl<0.0f) shi->refl= 0.0f; + if (shi->refl<0.0f) shi->refl= 0.0f; } - if(mtex->mapto & MAP_SPEC) { + if (mtex->mapto & MAP_SPEC) { float specfac= mtex->specfac*stencilTin; shi->spec= texture_value_blend(mtex->def_var, shi->spec, texres.tin, specfac, mtex->blendtype); - if(shi->spec<0.0f) shi->spec= 0.0f; + if (shi->spec<0.0f) shi->spec= 0.0f; } - if(mtex->mapto & MAP_EMIT) { + if (mtex->mapto & MAP_EMIT) { float emitfac= mtex->emitfac*stencilTin; shi->emit= texture_value_blend(mtex->def_var, shi->emit, texres.tin, emitfac, mtex->blendtype); - if(shi->emit<0.0f) shi->emit= 0.0f; + if (shi->emit<0.0f) shi->emit= 0.0f; } - if(mtex->mapto & MAP_ALPHA) { + if (mtex->mapto & MAP_ALPHA) { float alphafac= mtex->alphafac*stencilTin; shi->alpha= texture_value_blend(mtex->def_var, shi->alpha, texres.tin, alphafac, mtex->blendtype); - if(shi->alpha<0.0f) shi->alpha= 0.0f; - else if(shi->alpha>1.0f) shi->alpha= 1.0f; + if (shi->alpha<0.0f) shi->alpha= 0.0f; + else if (shi->alpha>1.0f) shi->alpha= 1.0f; } - if(mtex->mapto & MAP_HAR) { + if (mtex->mapto & MAP_HAR) { float har; // have to map to 0-1 float hardfac= mtex->hardfac*stencilTin; har= ((float)shi->har)/128.0f; har= 128.0f*texture_value_blend(mtex->def_var, har, texres.tin, hardfac, mtex->blendtype); - if(har<1.0f) shi->har= 1; - else if(har>511) shi->har= 511; + if (har<1.0f) shi->har= 1; + else if (har>511) shi->har= 511; else shi->har= (int)har; } - if(mtex->mapto & MAP_RAYMIRR) { + if (mtex->mapto & MAP_RAYMIRR) { float raymirrfac= mtex->raymirrfac*stencilTin; shi->ray_mirror= texture_value_blend(mtex->def_var, shi->ray_mirror, texres.tin, raymirrfac, mtex->blendtype); - if(shi->ray_mirror<0.0f) shi->ray_mirror= 0.0f; - else if(shi->ray_mirror>1.0f) shi->ray_mirror= 1.0f; + if (shi->ray_mirror<0.0f) shi->ray_mirror= 0.0f; + else if (shi->ray_mirror>1.0f) shi->ray_mirror= 1.0f; } - if(mtex->mapto & MAP_TRANSLU) { + if (mtex->mapto & MAP_TRANSLU) { float translfac= mtex->translfac*stencilTin; shi->translucency= texture_value_blend(mtex->def_var, shi->translucency, texres.tin, translfac, mtex->blendtype); - if(shi->translucency<0.0f) shi->translucency= 0.0f; - else if(shi->translucency>1.0f) shi->translucency= 1.0f; + if (shi->translucency<0.0f) shi->translucency= 0.0f; + else if (shi->translucency>1.0f) shi->translucency= 1.0f; } - if(mtex->mapto & MAP_AMB) { + if (mtex->mapto & MAP_AMB) { float ambfac= mtex->ambfac*stencilTin; shi->amb= texture_value_blend(mtex->def_var, shi->amb, texres.tin, ambfac, mtex->blendtype); - if(shi->amb<0.0f) shi->amb= 0.0f; - else if(shi->amb>1.0f) shi->amb= 1.0f; + if (shi->amb<0.0f) shi->amb= 0.0f; + else if (shi->amb>1.0f) shi->amb= 1.0f; shi->ambr= shi->amb*re->wrld.ambr; shi->ambg= shi->amb*re->wrld.ambg; @@ -2705,35 +2711,35 @@ void do_volume_tex(ShadeInput *shi, const float *xyz, int mapto_flag, float *col if (re->r.scemode & R_NO_TEX) return; /* here: test flag if there's a tex (todo) */ - for(tex_nr=0; tex_nr<MAX_MTEX; tex_nr++) { + for (tex_nr=0; tex_nr<MAX_MTEX; tex_nr++) { /* separate tex switching */ - if(shi->mat->septex & (1<<tex_nr)) continue; + if (shi->mat->septex & (1<<tex_nr)) continue; - if(shi->mat->mtex[tex_nr]) { + if (shi->mat->mtex[tex_nr]) { mtex= shi->mat->mtex[tex_nr]; tex= mtex->tex; - if(tex==0) continue; + if (tex==0) continue; /* only process if this texture is mapped * to one that we're interested in */ if (!(mtex->mapto & mapto_flag)) continue; /* which coords */ - if(mtex->texco==TEXCO_OBJECT) { + if (mtex->texco==TEXCO_OBJECT) { Object *ob= mtex->object; - if(ob) { + if (ob) { copy_v3_v3(co, xyz); - if(mtex->texflag & MTEX_OB_DUPLI_ORIG) { - if(shi->obi && shi->obi->duplitexmat) + if (mtex->texflag & MTEX_OB_DUPLI_ORIG) { + if (shi->obi && shi->obi->duplitexmat) mul_m4_v3(shi->obi->duplitexmat, co); } mul_m4_v3(ob->imat_ren, co); } } /* not really orco, but 'local' */ - else if(mtex->texco==TEXCO_ORCO) { + else if (mtex->texco==TEXCO_ORCO) { - if(mtex->texflag & MTEX_DUPLI_MAPTO) { + if (mtex->texflag & MTEX_DUPLI_MAPTO) { copy_v3_v3(co, shi->duplilo); } else { @@ -2742,7 +2748,7 @@ void do_volume_tex(ShadeInput *shi, const float *xyz, int mapto_flag, float *col mul_m4_v3(ob->imat_ren, co); } } - else if(mtex->texco==TEXCO_GLOB) { + else if (mtex->texco==TEXCO_GLOB) { copy_v3_v3(co, xyz); mul_m4_v3(re->viewinv, co); } @@ -2750,19 +2756,19 @@ void do_volume_tex(ShadeInput *shi, const float *xyz, int mapto_flag, float *col texres.nor= NULL; - if(tex->type==TEX_IMAGE) { + if (tex->type==TEX_IMAGE) { continue; /* not supported yet */ //do_2d_mapping(mtex, texvec, NULL, NULL, dxt, dyt); } else { /* placement */ - if(mtex->projx) texvec[0]= mtex->size[0]*(co[mtex->projx-1]+mtex->ofs[0]); + if (mtex->projx) texvec[0]= mtex->size[0]*(co[mtex->projx-1]+mtex->ofs[0]); else texvec[0]= mtex->size[0]*(mtex->ofs[0]); - if(mtex->projy) texvec[1]= mtex->size[1]*(co[mtex->projy-1]+mtex->ofs[1]); + if (mtex->projy) texvec[1]= mtex->size[1]*(co[mtex->projy-1]+mtex->ofs[1]); else texvec[1]= mtex->size[1]*(mtex->ofs[1]); - if(mtex->projz) texvec[2]= mtex->size[2]*(co[mtex->projz-1]+mtex->ofs[2]); + if (mtex->projz) texvec[2]= mtex->size[2]*(co[mtex->projz-1]+mtex->ofs[2]); else texvec[2]= mtex->size[2]*(mtex->ofs[2]); } @@ -2770,20 +2776,20 @@ void do_volume_tex(ShadeInput *shi, const float *xyz, int mapto_flag, float *col /* texture output */ - if( (rgbnor & TEX_RGB) && (mtex->texflag & MTEX_RGBTOINT)) { + if ( (rgbnor & TEX_RGB) && (mtex->texflag & MTEX_RGBTOINT)) { texres.tin= (0.35f*texres.tr+0.45f*texres.tg+0.2f*texres.tb); rgbnor-= TEX_RGB; } - if(mtex->texflag & MTEX_NEGATIVE) { - if(rgbnor & TEX_RGB) { + if (mtex->texflag & MTEX_NEGATIVE) { + if (rgbnor & TEX_RGB) { texres.tr= 1.0f-texres.tr; texres.tg= 1.0f-texres.tg; texres.tb= 1.0f-texres.tb; } texres.tin= 1.0f-texres.tin; } - if(mtex->texflag & MTEX_STENCIL) { - if(rgbnor & TEX_RGB) { + if (mtex->texflag & MTEX_STENCIL) { + if (rgbnor & TEX_RGB) { fact= texres.ta; texres.ta*= stencilTin; stencilTin*= fact; @@ -2796,70 +2802,71 @@ void do_volume_tex(ShadeInput *shi, const float *xyz, int mapto_flag, float *col } - if((mapto_flag & (MAP_EMISSION_COL+MAP_TRANSMISSION_COL+MAP_REFLECTION_COL)) && (mtex->mapto & (MAP_EMISSION_COL+MAP_TRANSMISSION_COL+MAP_REFLECTION_COL))) { + if ((mapto_flag & (MAP_EMISSION_COL+MAP_TRANSMISSION_COL+MAP_REFLECTION_COL)) && (mtex->mapto & (MAP_EMISSION_COL+MAP_TRANSMISSION_COL+MAP_REFLECTION_COL))) { float tcol[3]; /* stencil maps on the texture control slider, not texture intensity value */ - if((rgbnor & TEX_RGB)==0) { + if ((rgbnor & TEX_RGB)==0) { tcol[0]= mtex->r; tcol[1]= mtex->g; tcol[2]= mtex->b; - } else { + } + else { tcol[0]=texres.tr; tcol[1]=texres.tg; tcol[2]=texres.tb; - if(texres.talpha) + if (texres.talpha) texres.tin= texres.ta; } /* used for emit */ - if((mapto_flag & MAP_EMISSION_COL) && (mtex->mapto & MAP_EMISSION_COL)) { + if ((mapto_flag & MAP_EMISSION_COL) && (mtex->mapto & MAP_EMISSION_COL)) { float colemitfac= mtex->colemitfac*stencilTin; texture_rgb_blend(col, tcol, col, texres.tin, colemitfac, mtex->blendtype); } - if((mapto_flag & MAP_REFLECTION_COL) && (mtex->mapto & MAP_REFLECTION_COL)) { + if ((mapto_flag & MAP_REFLECTION_COL) && (mtex->mapto & MAP_REFLECTION_COL)) { float colreflfac= mtex->colreflfac*stencilTin; texture_rgb_blend(col, tcol, col, texres.tin, colreflfac, mtex->blendtype); } - if((mapto_flag & MAP_TRANSMISSION_COL) && (mtex->mapto & MAP_TRANSMISSION_COL)) { + if ((mapto_flag & MAP_TRANSMISSION_COL) && (mtex->mapto & MAP_TRANSMISSION_COL)) { float coltransfac= mtex->coltransfac*stencilTin; texture_rgb_blend(col, tcol, col, texres.tin, coltransfac, mtex->blendtype); } } - if((mapto_flag & MAP_VARS) && (mtex->mapto & MAP_VARS)) { + if ((mapto_flag & MAP_VARS) && (mtex->mapto & MAP_VARS)) { /* stencil maps on the texture control slider, not texture intensity value */ /* convert RGB to intensity if intensity info isn't provided */ if (!(rgbnor & TEX_INT)) { if (rgbnor & TEX_RGB) { - if(texres.talpha) texres.tin= texres.ta; + if (texres.talpha) texres.tin= texres.ta; else texres.tin= (0.35f*texres.tr+0.45f*texres.tg+0.2f*texres.tb); } } - if((mapto_flag & MAP_EMISSION) && (mtex->mapto & MAP_EMISSION)) { + if ((mapto_flag & MAP_EMISSION) && (mtex->mapto & MAP_EMISSION)) { float emitfac= mtex->emitfac*stencilTin; *val = texture_value_blend(mtex->def_var, *val, texres.tin, emitfac, mtex->blendtype); - if(*val<0.0f) *val= 0.0f; + if (*val<0.0f) *val= 0.0f; } - if((mapto_flag & MAP_DENSITY) && (mtex->mapto & MAP_DENSITY)) { + if ((mapto_flag & MAP_DENSITY) && (mtex->mapto & MAP_DENSITY)) { float densfac= mtex->densfac*stencilTin; *val = texture_value_blend(mtex->def_var, *val, texres.tin, densfac, mtex->blendtype); CLAMP(*val, 0.0f, 1.0f); } - if((mapto_flag & MAP_SCATTERING) && (mtex->mapto & MAP_SCATTERING)) { + if ((mapto_flag & MAP_SCATTERING) && (mtex->mapto & MAP_SCATTERING)) { float scatterfac= mtex->scatterfac*stencilTin; *val = texture_value_blend(mtex->def_var, *val, texres.tin, scatterfac, mtex->blendtype); CLAMP(*val, 0.0f, 1.0f); } - if((mapto_flag & MAP_REFLECTION) && (mtex->mapto & MAP_REFLECTION)) { + if ((mapto_flag & MAP_REFLECTION) && (mtex->mapto & MAP_REFLECTION)) { float reflfac= mtex->reflfac*stencilTin; *val = texture_value_blend(mtex->def_var, *val, texres.tin, reflfac, mtex->blendtype); @@ -2883,8 +2890,8 @@ void do_halo_tex(HaloRen *har, float xn, float yn, float col_r[4]) if (R.r.scemode & R_NO_TEX) return; mtex= har->mat->mtex[0]; - if(har->mat->septex & (1<<0)) return; - if(mtex->tex==NULL) return; + if (har->mat->septex & (1<<0)) return; + if (mtex->tex==NULL) return; /* no normal mapping */ texres.nor= NULL; @@ -2896,32 +2903,32 @@ void do_halo_tex(HaloRen *har, float xn, float yn, float col_r[4]) osatex= (har->mat->texco & TEXCO_OSA); /* placement */ - if(mtex->projx) texvec[0]= mtex->size[0]*(texvec[mtex->projx-1]+mtex->ofs[0]); + if (mtex->projx) texvec[0]= mtex->size[0]*(texvec[mtex->projx-1]+mtex->ofs[0]); else texvec[0]= mtex->size[0]*(mtex->ofs[0]); - if(mtex->projy) texvec[1]= mtex->size[1]*(texvec[mtex->projy-1]+mtex->ofs[1]); + if (mtex->projy) texvec[1]= mtex->size[1]*(texvec[mtex->projy-1]+mtex->ofs[1]); else texvec[1]= mtex->size[1]*(mtex->ofs[1]); - if(mtex->projz) texvec[2]= mtex->size[2]*(texvec[mtex->projz-1]+mtex->ofs[2]); + if (mtex->projz) texvec[2]= mtex->size[2]*(texvec[mtex->projz-1]+mtex->ofs[2]); else texvec[2]= mtex->size[2]*(mtex->ofs[2]); - if(osatex) { + if (osatex) { dx= 1.0f/har->rad; - if(mtex->projx) { + if (mtex->projx) { dxt[0]= mtex->size[0]*dx; dyt[0]= mtex->size[0]*dx; } else dxt[0]= dyt[0]= 0.0; - if(mtex->projy) { + if (mtex->projy) { dxt[1]= mtex->size[1]*dx; dyt[1]= mtex->size[1]*dx; } else dxt[1]= dyt[1]= 0.0; - if(mtex->projz) { + if (mtex->projz) { dxt[2]= 0.0; dyt[2]= 0.0; } @@ -2929,17 +2936,17 @@ void do_halo_tex(HaloRen *har, float xn, float yn, float col_r[4]) } - if(mtex->tex->type==TEX_IMAGE) do_2d_mapping(mtex, texvec, NULL, NULL, dxt, dyt); + if (mtex->tex->type==TEX_IMAGE) do_2d_mapping(mtex, texvec, NULL, NULL, dxt, dyt); rgb= multitex(mtex->tex, texvec, dxt, dyt, osatex, &texres, 0, mtex->which_output); /* texture output */ - if(rgb && (mtex->texflag & MTEX_RGBTOINT)) { + if (rgb && (mtex->texflag & MTEX_RGBTOINT)) { texres.tin= (0.35f*texres.tr+0.45f*texres.tg+0.2f*texres.tb); rgb= 0; } - if(mtex->texflag & MTEX_NEGATIVE) { - if(rgb) { + if (mtex->texflag & MTEX_NEGATIVE) { + if (rgb) { texres.tr= 1.0f-texres.tr; texres.tg= 1.0f-texres.tg; texres.tb= 1.0f-texres.tb; @@ -2948,14 +2955,14 @@ void do_halo_tex(HaloRen *har, float xn, float yn, float col_r[4]) } /* mapping */ - if(mtex->mapto & MAP_COL) { + if (mtex->mapto & MAP_COL) { - if(rgb==0) { + if (rgb==0) { texres.tr= mtex->r; texres.tg= mtex->g; texres.tb= mtex->b; } - else if(mtex->mapto & MAP_ALPHA) { + else if (mtex->mapto & MAP_ALPHA) { texres.tin= 1.0; } else texres.tin= texres.ta; @@ -2973,18 +2980,18 @@ void do_halo_tex(HaloRen *har, float xn, float yn, float col_r[4]) fact= texres.tin*mtex->colfac; facm= 1.0f-fact; - if(mtex->blendtype==MTEX_MUL) { + if (mtex->blendtype==MTEX_MUL) { facm= 1.0f-mtex->colfac; } - if(mtex->blendtype==MTEX_SUB) fact= -fact; + if (mtex->blendtype==MTEX_SUB) fact= -fact; - if(mtex->blendtype==MTEX_BLEND) { + if (mtex->blendtype==MTEX_BLEND) { col_r[0]= (fact*texres.tr + facm*har->r); col_r[1]= (fact*texres.tg + facm*har->g); col_r[2]= (fact*texres.tb + facm*har->b); } - else if(mtex->blendtype==MTEX_MUL) { + else if (mtex->blendtype==MTEX_MUL) { col_r[0]= (facm+fact*texres.tr)*har->r; col_r[1]= (facm+fact*texres.tg)*har->g; col_r[2]= (facm+fact*texres.tb)*har->b; @@ -2999,9 +3006,9 @@ void do_halo_tex(HaloRen *har, float xn, float yn, float col_r[4]) CLAMP(col_r[2], 0.0f, 1.0f); } } - if(mtex->mapto & MAP_ALPHA) { - if(rgb) { - if(texres.talpha) texres.tin= texres.ta; + if (mtex->mapto & MAP_ALPHA) { + if (rgb) { + if (texres.talpha) texres.tin= texres.ta; else texres.tin= (0.35f*texres.tr+0.45f*texres.tg+0.2f*texres.tb); } @@ -3025,19 +3032,19 @@ void do_sky_tex(const float rco[3], float lo[3], const float dxyview[2], float h /* todo: add flag to test if there's a tex */ texres.nor= NULL; - for(tex_nr=0; tex_nr<MAX_MTEX; tex_nr++) { - if(R.wrld.mtex[tex_nr]) { + for (tex_nr=0; tex_nr<MAX_MTEX; tex_nr++) { + if (R.wrld.mtex[tex_nr]) { mtex= R.wrld.mtex[tex_nr]; tex= mtex->tex; - if(tex==0) continue; + if (tex==0) continue; /* if(mtex->mapto==0) continue; */ /* which coords */ co= lo; /* dxt dyt just from 1 value */ - if(dxyview) { + if (dxyview) { dxt[0]= dxt[1]= dxt[2]= dxyview[0]; dyt[0]= dyt[1]= dyt[2]= dxyview[1]; } @@ -3051,7 +3058,7 @@ void do_sky_tex(const float rco[3], float lo[3], const float dxyview[2], float h case TEXCO_ANGMAP: /* only works with texture being "real" */ /* use saacos(), fixes bug [#22398], float precision caused lo[2] to be slightly less then -1.0 */ - if(lo[0] || lo[1]) { /* check for zero case [#24807] */ + if (lo[0] || lo[1]) { /* check for zero case [#24807] */ fact= (1.0f/(float)M_PI)*saacos(lo[2])/(sqrtf(lo[0]*lo[0] + lo[1]*lo[1])); tempvec[0]= lo[0]*fact; tempvec[1]= lo[1]*fact; @@ -3069,8 +3076,8 @@ void do_sky_tex(const float rco[3], float lo[3], const float dxyview[2], float h case TEXCO_H_SPHEREMAP: case TEXCO_H_TUBEMAP: - if(skyflag & WO_ZENUP) { - if(mtex->texco==TEXCO_H_TUBEMAP) map_to_tube( tempvec, tempvec+1,lo[0], lo[2], lo[1]); + if (skyflag & WO_ZENUP) { + if (mtex->texco==TEXCO_H_TUBEMAP) map_to_tube( tempvec, tempvec+1,lo[0], lo[2], lo[1]); else map_to_sphere( tempvec, tempvec+1,lo[0], lo[2], lo[1]); /* tube/spheremap maps for outside view, not inside */ tempvec[0]= 1.0f-tempvec[0]; @@ -3094,7 +3101,7 @@ void do_sky_tex(const float rco[3], float lo[3], const float dxyview[2], float h co= tempvec; break; case TEXCO_OBJECT: - if(mtex->object) { + if (mtex->object) { copy_v3_v3(tempvec, lo); mul_m4_v3(mtex->object->imat_ren, tempvec); co= tempvec; @@ -3102,7 +3109,7 @@ void do_sky_tex(const float rco[3], float lo[3], const float dxyview[2], float h break; case TEXCO_GLOB: - if(rco) { + if (rco) { copy_v3_v3(tempvec, rco); mul_m4_v3(R.viewinv, tempvec); co= tempvec; @@ -3118,35 +3125,35 @@ void do_sky_tex(const float rco[3], float lo[3], const float dxyview[2], float h } /* placement */ - if(mtex->projx) texvec[0]= mtex->size[0]*(co[mtex->projx-1]+mtex->ofs[0]); + if (mtex->projx) texvec[0]= mtex->size[0]*(co[mtex->projx-1]+mtex->ofs[0]); else texvec[0]= mtex->size[0]*(mtex->ofs[0]); - if(mtex->projy) texvec[1]= mtex->size[1]*(co[mtex->projy-1]+mtex->ofs[1]); + if (mtex->projy) texvec[1]= mtex->size[1]*(co[mtex->projy-1]+mtex->ofs[1]); else texvec[1]= mtex->size[1]*(mtex->ofs[1]); - if(mtex->projz) texvec[2]= mtex->size[2]*(co[mtex->projz-1]+mtex->ofs[2]); + if (mtex->projz) texvec[2]= mtex->size[2]*(co[mtex->projz-1]+mtex->ofs[2]); else texvec[2]= mtex->size[2]*(mtex->ofs[2]); /* texture */ - if(tex->type==TEX_IMAGE) do_2d_mapping(mtex, texvec, NULL, NULL, dxt, dyt); + if (tex->type==TEX_IMAGE) do_2d_mapping(mtex, texvec, NULL, NULL, dxt, dyt); rgb= multitex(mtex->tex, texvec, dxt, dyt, R.osa, &texres, thread, mtex->which_output); /* texture output */ - if(rgb && (mtex->texflag & MTEX_RGBTOINT)) { + if (rgb && (mtex->texflag & MTEX_RGBTOINT)) { texres.tin= (0.35f*texres.tr+0.45f*texres.tg+0.2f*texres.tb); rgb= 0; } - if(mtex->texflag & MTEX_NEGATIVE) { - if(rgb) { + if (mtex->texflag & MTEX_NEGATIVE) { + if (rgb) { texres.tr= 1.0f-texres.tr; texres.tg= 1.0f-texres.tg; texres.tb= 1.0f-texres.tb; } else texres.tin= 1.0f-texres.tin; } - if(mtex->texflag & MTEX_STENCIL) { - if(rgb) { + if (mtex->texflag & MTEX_STENCIL) { + if (rgb) { fact= texres.ta; texres.ta*= stencilTin; stencilTin*= fact; @@ -3158,15 +3165,15 @@ void do_sky_tex(const float rco[3], float lo[3], const float dxyview[2], float h } } else { - if(rgb) texres.ta *= stencilTin; + if (rgb) texres.ta *= stencilTin; else texres.tin*= stencilTin; } /* color mapping */ - if(mtex->mapto & (WOMAP_HORIZ+WOMAP_ZENUP+WOMAP_ZENDOWN)) { + if (mtex->mapto & (WOMAP_HORIZ+WOMAP_ZENUP+WOMAP_ZENDOWN)) { float tcol[3]; - if(rgb==0) { + if (rgb==0) { texres.tr= mtex->r; texres.tg= mtex->g; texres.tb= mtex->b; @@ -3185,29 +3192,29 @@ void do_sky_tex(const float rco[3], float lo[3], const float dxyview[2], float h srgb_to_linearrgb_v3_v3(tcol, tcol); } - if(mtex->mapto & WOMAP_HORIZ) { + if (mtex->mapto & WOMAP_HORIZ) { texture_rgb_blend(hor, tcol, hor, texres.tin, mtex->colfac, mtex->blendtype); } - if(mtex->mapto & (WOMAP_ZENUP+WOMAP_ZENDOWN)) { + if (mtex->mapto & (WOMAP_ZENUP+WOMAP_ZENDOWN)) { float zenfac = 0.0f; - if(R.wrld.skytype & WO_SKYREAL) { - if((skyflag & WO_ZENUP)) { - if(mtex->mapto & WOMAP_ZENUP) zenfac= mtex->zenupfac; + if (R.wrld.skytype & WO_SKYREAL) { + if ((skyflag & WO_ZENUP)) { + if (mtex->mapto & WOMAP_ZENUP) zenfac= mtex->zenupfac; } - else if(mtex->mapto & WOMAP_ZENDOWN) zenfac= mtex->zendownfac; + else if (mtex->mapto & WOMAP_ZENDOWN) zenfac= mtex->zendownfac; } else { - if(mtex->mapto & WOMAP_ZENUP) zenfac= mtex->zenupfac; - else if(mtex->mapto & WOMAP_ZENDOWN) zenfac= mtex->zendownfac; + if (mtex->mapto & WOMAP_ZENUP) zenfac= mtex->zenupfac; + else if (mtex->mapto & WOMAP_ZENDOWN) zenfac= mtex->zendownfac; } - if(zenfac != 0.0f) + if (zenfac != 0.0f) texture_rgb_blend(zen, tcol, zen, texres.tin, zenfac, mtex->blendtype); } } - if(mtex->mapto & WOMAP_BLEND) { - if(rgb) texres.tin= (0.35f*texres.tr+0.45f*texres.tg+0.2f*texres.tb); + if (mtex->mapto & WOMAP_BLEND) { + if (rgb) texres.tin= (0.35f*texres.tr+0.45f*texres.tg+0.2f*texres.tb); *blend= texture_value_blend(mtex->def_var, *blend, texres.tin, mtex->blendfac, mtex->blendtype); } @@ -3231,25 +3238,25 @@ void do_lamp_tex(LampRen *la, const float lavec[3], ShadeInput *shi, float col_r if (R.r.scemode & R_NO_TEX) return; tex_nr= 0; - for(; tex_nr<MAX_MTEX; tex_nr++) { + for (; tex_nr<MAX_MTEX; tex_nr++) { - if(la->mtex[tex_nr]) { + if (la->mtex[tex_nr]) { mtex= la->mtex[tex_nr]; tex= mtex->tex; - if(tex==NULL) continue; + if (tex==NULL) continue; texres.nor= NULL; /* which coords */ - if(mtex->texco==TEXCO_OBJECT) { + if (mtex->texco==TEXCO_OBJECT) { ob= mtex->object; - if(ob) { + if (ob) { co= tempvec; dx= dxt; dy= dyt; copy_v3_v3(tempvec, shi->co); mul_m4_v3(ob->imat_ren, tempvec); - if(shi->osatex) { + if (shi->osatex) { copy_v3_v3(dxt, shi->dxco); copy_v3_v3(dyt, shi->dyco); mul_mat3_m4_v3(ob->imat_ren, dxt); @@ -3261,17 +3268,17 @@ void do_lamp_tex(LampRen *la, const float lavec[3], ShadeInput *shi, float col_r dx= shi->dxco; dy= shi->dyco; } } - else if(mtex->texco==TEXCO_GLOB) { + else if (mtex->texco==TEXCO_GLOB) { co= shi->gl; dx= shi->dxco; dy= shi->dyco; copy_v3_v3(shi->gl, shi->co); mul_m4_v3(R.viewinv, shi->gl); } - else if(mtex->texco==TEXCO_VIEW) { + else if (mtex->texco==TEXCO_VIEW) { copy_v3_v3(tempvec, lavec); mul_m3_v3(la->imat, tempvec); - if(la->type==LA_SPOT) { + if (la->type==LA_SPOT) { tempvec[0]*= la->spottexfac; tempvec[1]*= la->spottexfac; /* project from 3d to 2d */ @@ -3281,7 +3288,7 @@ void do_lamp_tex(LampRen *la, const float lavec[3], ShadeInput *shi, float col_r co= tempvec; dx= dxt; dy= dyt; - if(shi->osatex) { + if (shi->osatex) { copy_v3_v3(dxt, shi->dxlv); copy_v3_v3(dyt, shi->dylv); /* need some matrix conversion here? la->imat is a [3][3] matrix!!! **/ @@ -3295,39 +3302,43 @@ void do_lamp_tex(LampRen *la, const float lavec[3], ShadeInput *shi, float col_r /* placement */ - if(mtex->projx && co) texvec[0]= mtex->size[0]*(co[mtex->projx-1]+mtex->ofs[0]); + if (mtex->projx && co) texvec[0]= mtex->size[0]*(co[mtex->projx-1]+mtex->ofs[0]); else texvec[0]= mtex->size[0]*(mtex->ofs[0]); - if(mtex->projy && co) texvec[1]= mtex->size[1]*(co[mtex->projy-1]+mtex->ofs[1]); + if (mtex->projy && co) texvec[1]= mtex->size[1]*(co[mtex->projy-1]+mtex->ofs[1]); else texvec[1]= mtex->size[1]*(mtex->ofs[1]); - if(mtex->projz && co) texvec[2]= mtex->size[2]*(co[mtex->projz-1]+mtex->ofs[2]); + if (mtex->projz && co) texvec[2]= mtex->size[2]*(co[mtex->projz-1]+mtex->ofs[2]); else texvec[2]= mtex->size[2]*(mtex->ofs[2]); - if(shi->osatex) { + if (shi->osatex) { if (!dx) { - for(i=0;i<2;i++) { + for (i=0;i<2;i++) { dxt[i] = dyt[i] = 0.0; } - } else { - if(mtex->projx) { + } + else { + if (mtex->projx) { dxt[0]= mtex->size[0]*dx[mtex->projx-1]; dyt[0]= mtex->size[0]*dy[mtex->projx-1]; - } else { + } + else { dxt[0]= 0.0; dyt[0]= 0.0; } - if(mtex->projy) { + if (mtex->projy) { dxt[1]= mtex->size[1]*dx[mtex->projy-1]; dyt[1]= mtex->size[1]*dy[mtex->projy-1]; - } else { + } + else { dxt[1]= 0.0; dyt[1]= 0.0; } - if(mtex->projz) { + if (mtex->projz) { dxt[2]= mtex->size[2]*dx[mtex->projz-1]; dyt[2]= mtex->size[2]*dy[mtex->projz-1]; - } else { + } + else { dxt[2]= 0.0; dyt[2]= 0.0; } @@ -3335,27 +3346,27 @@ void do_lamp_tex(LampRen *la, const float lavec[3], ShadeInput *shi, float col_r } /* texture */ - if(tex->type==TEX_IMAGE) { + if (tex->type==TEX_IMAGE) { do_2d_mapping(mtex, texvec, NULL, NULL, dxt, dyt); } rgb= multitex(tex, texvec, dxt, dyt, shi->osatex, &texres, shi->thread, mtex->which_output); /* texture output */ - if(rgb && (mtex->texflag & MTEX_RGBTOINT)) { + if (rgb && (mtex->texflag & MTEX_RGBTOINT)) { texres.tin= (0.35f*texres.tr+0.45f*texres.tg+0.2f*texres.tb); rgb= 0; } - if(mtex->texflag & MTEX_NEGATIVE) { - if(rgb) { + if (mtex->texflag & MTEX_NEGATIVE) { + if (rgb) { texres.tr= 1.0f-texres.tr; texres.tg= 1.0f-texres.tg; texres.tb= 1.0f-texres.tb; } else texres.tin= 1.0f-texres.tin; } - if(mtex->texflag & MTEX_STENCIL) { - if(rgb) { + if (mtex->texflag & MTEX_STENCIL) { + if (rgb) { fact= texres.ta; texres.ta*= stencilTin; stencilTin*= fact; @@ -3367,20 +3378,20 @@ void do_lamp_tex(LampRen *la, const float lavec[3], ShadeInput *shi, float col_r } } else { - if(rgb) texres.ta*= stencilTin; + if (rgb) texres.ta*= stencilTin; else texres.tin*= stencilTin; } /* mapping */ - if(((mtex->mapto & LAMAP_COL) && (effect & LA_TEXTURE))||((mtex->mapto & LAMAP_SHAD) && (effect & LA_SHAD_TEX))) { + if (((mtex->mapto & LAMAP_COL) && (effect & LA_TEXTURE))||((mtex->mapto & LAMAP_SHAD) && (effect & LA_SHAD_TEX))) { float col[3]; - if(rgb==0) { + if (rgb==0) { texres.tr= mtex->r; texres.tg= mtex->g; texres.tb= mtex->b; } - else if(mtex->mapto & MAP_ALPHA) { + else if (mtex->mapto & MAP_ALPHA) { texres.tin= stencilTin; } else texres.tin= texres.ta; @@ -3416,27 +3427,27 @@ int externtex(MTex *mtex, const float vec[3], float *tin, float *tr, float *tg, int rgb; tex= mtex->tex; - if(tex==NULL) return 0; + if (tex==NULL) return 0; texr.nor= NULL; /* placement */ - if(mtex->projx) texvec[0]= mtex->size[0]*(vec[mtex->projx-1]+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]); + 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]); + 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, NULL, dxt, dyt); } rgb= multitex(tex, texvec, dxt, dyt, 0, &texr, thread, mtex->which_output); - if(rgb) { + if (rgb) { texr.tin= (0.35f*texr.tr+0.45f*texr.tg+0.2f*texr.tb); } else { @@ -3467,12 +3478,12 @@ void render_realtime_texture(ShadeInput *shi, Image *ima) ShadeInputUV *suv= &shi->uv[shi->actuv]; int a; - if(R.r.scemode & R_NO_TEX) return; + if (R.r.scemode & R_NO_TEX) return; - if(firsttime) { + if (firsttime) { BLI_lock_thread(LOCK_IMAGE); - if(firsttime) { - for(a=0; a<BLENDER_MAX_THREADS; a++) { + if (firsttime) { + for (a=0; a<BLENDER_MAX_THREADS; a++) { memset(&imatex[a], 0, sizeof(Tex)); default_tex(&imatex[a]); imatex[a].type= TEX_IMAGE; @@ -3489,7 +3500,7 @@ void render_realtime_texture(ShadeInput *shi, Image *ima) texvec[0]= 0.5f+0.5f*suv->uv[0]; texvec[1]= 0.5f+0.5f*suv->uv[1]; texvec[2] = 0.0f; // initalize it because imagewrap looks at it. - if(shi->osatex) { + if (shi->osatex) { dx[0]= 0.5f*suv->dxuv[0]; dx[1]= 0.5f*suv->dxuv[1]; dy[0]= 0.5f*suv->dyuv[0]; @@ -3498,7 +3509,7 @@ void render_realtime_texture(ShadeInput *shi, Image *ima) texr.nor= NULL; - if(shi->osatex) imagewraposa(tex, ima, NULL, texvec, dx, dy, &texr); + if (shi->osatex) imagewraposa(tex, ima, NULL, texvec, dx, dy, &texr); else imagewrap(tex, ima, NULL, texvec, &texr); shi->vcol[0]*= texr.tr; @@ -3550,13 +3561,13 @@ Material *RE_init_sample_material(Material *orig_mat, Scene *scene) BKE_animsys_evaluate_animdata(scene, &mat->id, mat->adt, BKE_curframe(scene), ADT_RECALC_ANIM); /* strip material copy from unsupported flags */ - for(tex_nr=0; tex_nr<MAX_MTEX; tex_nr++) { - if(mat->septex & (1<<tex_nr)) continue; + for (tex_nr=0; tex_nr<MAX_MTEX; tex_nr++) { + if (mat->septex & (1<<tex_nr)) continue; - if(mat->mtex[tex_nr]) { + if (mat->mtex[tex_nr]) { MTex *mtex = mat->mtex[tex_nr]; - if(!mtex->tex) continue; + if (!mtex->tex) continue; /* only keep compatible texflags */ mtex->texflag = mtex->texflag & (MTEX_RGBTOINT | MTEX_STENCIL | MTEX_NEGATIVE | MTEX_ALPHAMIX); @@ -3582,9 +3593,9 @@ Material *RE_init_sample_material(Material *orig_mat, Scene *scene) } /* if mapped to an object, calculate inverse matrices */ - if(mtex->texco==TEXCO_OBJECT) { + if (mtex->texco==TEXCO_OBJECT) { Object *ob= mtex->object; - if(ob) { + if (ob) { invert_m4_m4(ob->imat, ob->obmat); copy_m4_m4(ob->imat_ren, ob->imat); } @@ -3597,10 +3608,10 @@ Material *RE_init_sample_material(Material *orig_mat, Scene *scene) BKE_animsys_evaluate_animdata(scene, &tex->id, tex->adt, BKE_curframe(scene), ADT_RECALC_ANIM); /* update texture cache if required */ - if(tex->type==TEX_VOXELDATA) { + if (tex->type==TEX_VOXELDATA) { cache_voxeldata(tex, (int)scene->r.cfra); } - if(tex->type==TEX_POINTDENSITY) { + if (tex->type==TEX_POINTDENSITY) { /* set dummy values for render and do cache */ Render dummy_re = {0}; dummy_re.scene = scene; @@ -3612,8 +3623,8 @@ Material *RE_init_sample_material(Material *orig_mat, Scene *scene) } /* update image sequences and movies */ - if(tex->ima && ELEM(tex->ima->source, IMA_SRC_MOVIE, IMA_SRC_SEQUENCE)) { - if(tex->iuser.flag & IMA_ANIM_ALWAYS) + if (tex->ima && ELEM(tex->ima->source, IMA_SRC_MOVIE, IMA_SRC_SEQUENCE)) { + if (tex->iuser.flag & IMA_ANIM_ALWAYS) BKE_image_user_calc_frame(&tex->iuser, (int)scene->r.cfra, 0); } } @@ -3627,12 +3638,12 @@ void RE_free_sample_material(Material *mat) int tex_nr; /* free textures */ - for(tex_nr=0; tex_nr<MAX_MTEX; tex_nr++) { - if(mat->septex & (1<<tex_nr)) continue; - if(mat->mtex[tex_nr]) { + for (tex_nr=0; tex_nr<MAX_MTEX; tex_nr++) { + if (mat->septex & (1<<tex_nr)) continue; + if (mat->mtex[tex_nr]) { MTex *mtex= mat->mtex[tex_nr]; - if(mtex->tex) { + if (mtex->tex) { free_texture(mtex->tex); MEM_freeN(mtex->tex); mtex->tex = NULL; @@ -3703,7 +3714,7 @@ void RE_sample_material_color(Material *mat, float color[3], float *alpha, const /* for every uv map set coords and name */ for (i=0; i<layers; i++) { - if(layer_index >= 0) { + if (layer_index >= 0) { float *uv1, *uv2, *uv3; float l; CustomData *data = &orcoDm->faceData; diff --git a/source/blender/render/intern/source/rendercore.c b/source/blender/render/intern/source/rendercore.c index da598cb4733..6f0ffcb8470 100644 --- a/source/blender/render/intern/source/rendercore.c +++ b/source/blender/render/intern/source/rendercore.c @@ -97,12 +97,12 @@ void calc_view_vector(float *view, float x, float y) view[2]= -ABS(R.clipsta); - if(R.r.mode & R_ORTHO) { + if (R.r.mode & R_ORTHO) { view[0]= view[1]= 0.0f; } else { - if(R.r.mode & R_PANORAMA) { + if (R.r.mode & R_PANORAMA) { x-= R.panodxp; } @@ -113,13 +113,13 @@ void calc_view_vector(float *view, float x, float y) y= (y/(float)R.winy); view[1]= R.viewplane.ymin + y*(R.viewplane.ymax - R.viewplane.ymin); -// if(R.flag & R_SEC_FIELD) { -// if(R.r.mode & R_ODDFIELD) view[1]= (y+R.ystart)*R.ycor; +// if (R.flag & R_SEC_FIELD) { +// if (R.r.mode & R_ODDFIELD) view[1]= (y+R.ystart)*R.ycor; // else view[1]= (y+R.ystart+1.0)*R.ycor; // } // else view[1]= (y+R.ystart+R.bluroffsy+0.5)*R.ycor; - if(R.r.mode & R_PANORAMA) { + if (R.r.mode & R_PANORAMA) { float u= view[0] + R.panodxv; float v= view[2]; view[0]= R.panoco*u + R.panosi*v; view[2]= -R.panosi*u + R.panoco*v; @@ -157,7 +157,7 @@ void calc_renderco_zbuf(float co[3], const float view[3], int z) /* also used in zbuf.c and shadbuf.c */ int count_mask(unsigned short mask) { - if(R.samples) + if (R.samples) return (R.samples->cmask[mask & 255]+R.samples->cmask[mask>>8]); return 0; } @@ -165,8 +165,8 @@ int count_mask(unsigned short mask) static int calchalo_z(HaloRen *har, int zz) { - if(har->type & HA_ONLYSKY) { - if(zz < 0x7FFFFFF0) zz= - 0x7FFFFF; /* edge render messes zvalues */ + if (har->type & HA_ONLYSKY) { + if (zz < 0x7FFFFFF0) zz= - 0x7FFFFF; /* edge render messes zvalues */ } else { zz= (zz>>8); @@ -186,18 +186,18 @@ static void halo_pixelstruct(HaloRen *har, RenderLayer **rlpp, int totsample, in accol[0]=accol[1]=accol[2]=accol[3]= 0.0f; flarec= har->flarec; - while(ps) { + while (ps) { amountm= count_mask(ps->mask); amount+= amountm; zz= calchalo_z(har, ps->z); - if((zz> har->zs) || (har->mat && (har->mat->mode & MA_HALO_SOFT))) { - if(shadeHaloFloat(har, col, zz, dist, xn, yn, flarec)) { + if ((zz> har->zs) || (har->mat && (har->mat->mode & MA_HALO_SOFT))) { + if (shadeHaloFloat(har, col, zz, dist, xn, yn, flarec)) { flarec= 0; - if(fullsample) { - for(sample=0; sample<totsample; sample++) - if(ps->mask & (1 << sample)) + if (fullsample) { + for (sample=0; sample<totsample; sample++) + if (ps->mask & (1 << sample)) addalphaAddfacFloat(rlpp[sample]->rectf + od*4, col, har->add); } else { @@ -216,9 +216,9 @@ static void halo_pixelstruct(HaloRen *har, RenderLayer **rlpp, int totsample, in /* now do the sky sub-pixels */ amount= R.osa-amount; - if(amount) { - if(shadeHaloFloat(har, col, 0x7FFFFF, dist, xn, yn, flarec)) { - if(!fullsample) { + if (amount) { + if (shadeHaloFloat(har, col, 0x7FFFFF, dist, xn, yn, flarec)) { + if (!fullsample) { fac= ((float)amount)/(float)R.osa; accol[0]+= fac*col[0]; accol[1]+= fac*col[1]; @@ -228,9 +228,9 @@ static void halo_pixelstruct(HaloRen *har, RenderLayer **rlpp, int totsample, in } } - if(fullsample) { - for(sample=0; sample<totsample; sample++) - if(!(mask & (1 << sample))) + if (fullsample) { + for (sample=0; sample<totsample; sample++) + if (!(mask & (1 << sample))) addalphaAddfacFloat(rlpp[sample]->rectf + od*4, col, har->add); } else { @@ -239,7 +239,7 @@ static void halo_pixelstruct(HaloRen *har, RenderLayer **rlpp, int totsample, in col[2]= accol[2]; col[3]= accol[3]; - for(sample=0; sample<totsample; sample++) + for (sample=0; sample<totsample; sample++) addalphaAddfacFloat(rlpp[sample]->rectf + od*4, col, har->add); } } @@ -257,7 +257,7 @@ static void halo_tile(RenderPart *pa, RenderLayer *rl) unsigned int lay= rl->lay; /* we don't render halos in the cropped area, gives errors in flare counter */ - if(pa->crop) { + if (pa->crop) { testrect.xmin+= pa->crop; testrect.xmax-= pa->crop; testrect.ymin+= pa->crop; @@ -266,20 +266,20 @@ static void halo_tile(RenderPart *pa, RenderLayer *rl) totsample= get_sample_layers(pa, rl, rlpp); - for(a=0; a<R.tothalo; a++) { + for (a=0; a<R.tothalo; a++) { har= R.sortedhalos[a]; /* layer test, clip halo with y */ - if((har->lay & lay)==0); - else if(testrect.ymin > har->maxy); - else if(testrect.ymax < har->miny); + if ((har->lay & lay)==0); + else if (testrect.ymin > har->maxy); + else if (testrect.ymax < har->miny); else { minx= floor(har->xs-har->rad); maxx= ceil(har->xs+har->rad); - if(testrect.xmin > maxx); - else if(testrect.xmax < minx); + if (testrect.xmin > maxx); + else if (testrect.xmax < minx); else { minx= MAX2(minx, testrect.xmin); @@ -288,41 +288,41 @@ static void halo_tile(RenderPart *pa, RenderLayer *rl) miny= MAX2(har->miny, testrect.ymin); maxy= MIN2(har->maxy, testrect.ymax); - for(y=miny; y<maxy; y++) { + for (y=miny; y<maxy; y++) { int rectofs= (y-disprect.ymin)*pa->rectx + (minx - disprect.xmin); rz= pa->rectz + rectofs; od= rectofs; - if(pa->rectdaps) + if (pa->rectdaps) rd= pa->rectdaps + rectofs; yn= (y-har->ys)*R.ycor; ysq= yn*yn; - for(x=minx; x<maxx; x++, rz++, od++) { + for (x=minx; x<maxx; x++, rz++, od++) { xn= x- har->xs; xsq= xn*xn; dist= xsq+ysq; - if(dist<har->radsq) { - if(rd && *rd) { + if (dist<har->radsq) { + if (rd && *rd) { halo_pixelstruct(har, rlpp, totsample, od, dist, xn, yn, (PixStr *)*rd); } else { zz= calchalo_z(har, *rz); - if((zz> har->zs) || (har->mat && (har->mat->mode & MA_HALO_SOFT))) { - if(shadeHaloFloat(har, col, zz, dist, xn, yn, har->flarec)) { - for(sample=0; sample<totsample; sample++) + if ((zz> har->zs) || (har->mat && (har->mat->mode & MA_HALO_SOFT))) { + if (shadeHaloFloat(har, col, zz, dist, xn, yn, har->flarec)) { + for (sample=0; sample<totsample; sample++) addalphaAddfacFloat(rlpp[sample]->rectf + od*4, col, har->add); } } } } - if(rd) rd++; + if (rd) rd++; } } } } - if(R.test_break(R.tbh) ) break; + if (R.test_break(R.tbh) ) break; } } @@ -341,17 +341,17 @@ static void lamphalo_tile(RenderPart *pa, RenderLayer *rl) shade_input_initialize(&shi, pa, rl, 0); /* this zero's ShadeInput for us */ - for(od=0, y=pa->disprect.ymin; y<pa->disprect.ymax; y++) { - for(x=pa->disprect.xmin; x<pa->disprect.xmax; x++, rz++, od++) { + for (od=0, y=pa->disprect.ymin; y<pa->disprect.ymax; y++) { + for (x=pa->disprect.xmin; x<pa->disprect.xmax; x++, rz++, od++) { calc_view_vector(shi.view, x, y); - if(rd && *rd) { + if (rd && *rd) { PixStr *ps= (PixStr *)*rd; int count, totsamp= 0, mask= 0; - while(ps) { - if(R.r.mode & R_ORTHO) + while (ps) { + if (R.r.mode & R_ORTHO) calc_renderco_ortho(shi.co, (float)x, (float)y, ps->z); else calc_renderco_zbuf(shi.co, shi.view, ps->z); @@ -362,15 +362,15 @@ static void lamphalo_tile(RenderPart *pa, RenderLayer *rl) col[0]= col[1]= col[2]= col[3]= 0.0f; renderspothalo(&shi, col, 1.0f); - if(fullsample) { - for(sample=0; sample<totsample; sample++) { - if(ps->mask & (1 << sample)) { + if (fullsample) { + for (sample=0; sample<totsample; sample++) { + if (ps->mask & (1 << sample)) { pass= rlpp[sample]->rectf + od*4; pass[0]+= col[0]; pass[1]+= col[1]; pass[2]+= col[2]; pass[3]+= col[3]; - if(pass[3]>1.0f) pass[3]= 1.0f; + if (pass[3]>1.0f) pass[3]= 1.0f; } } } @@ -381,27 +381,27 @@ static void lamphalo_tile(RenderPart *pa, RenderLayer *rl) pass[1]+= fac*col[1]; pass[2]+= fac*col[2]; pass[3]+= fac*col[3]; - if(pass[3]>1.0f) pass[3]= 1.0f; + if (pass[3]>1.0f) pass[3]= 1.0f; } ps= ps->next; } - if(totsamp<R.osa) { + if (totsamp<R.osa) { shi.co[2]= 0.0f; col[0]= col[1]= col[2]= col[3]= 0.0f; renderspothalo(&shi, col, 1.0f); - if(fullsample) { - for(sample=0; sample<totsample; sample++) { - if(!(mask & (1 << sample))) { + if (fullsample) { + for (sample=0; sample<totsample; sample++) { + if (!(mask & (1 << sample))) { pass= rlpp[sample]->rectf + od*4; pass[0]+= col[0]; pass[1]+= col[1]; pass[2]+= col[2]; pass[3]+= col[3]; - if(pass[3]>1.0f) pass[3]= 1.0f; + if (pass[3]>1.0f) pass[3]= 1.0f; } } } @@ -412,12 +412,12 @@ static void lamphalo_tile(RenderPart *pa, RenderLayer *rl) pass[1]+= fac*col[1]; pass[2]+= fac*col[2]; pass[3]+= fac*col[3]; - if(pass[3]>1.0f) pass[3]= 1.0f; + if (pass[3]>1.0f) pass[3]= 1.0f; } } } else { - if(R.r.mode & R_ORTHO) + if (R.r.mode & R_ORTHO) calc_renderco_ortho(shi.co, (float)x, (float)y, *rz); else calc_renderco_zbuf(shi.co, shi.view, *rz); @@ -425,20 +425,20 @@ static void lamphalo_tile(RenderPart *pa, RenderLayer *rl) col[0]= col[1]= col[2]= col[3]= 0.0f; renderspothalo(&shi, col, 1.0f); - for(sample=0; sample<totsample; sample++) { + for (sample=0; sample<totsample; sample++) { pass= rlpp[sample]->rectf + od*4; pass[0]+= col[0]; pass[1]+= col[1]; pass[2]+= col[2]; pass[3]+= col[3]; - if(pass[3]>1.0f) pass[3]= 1.0f; + if (pass[3]>1.0f) pass[3]= 1.0f; } } - if(rd) rd++; + if (rd) rd++; } - if(y&1) - if(R.test_break(R.tbh)) break; + if (y&1) + if (R.test_break(R.tbh)) break; } } @@ -453,7 +453,7 @@ static void add_filt_passes(RenderLayer *rl, int curmask, int rectx, int offset, /* combined rgb */ add_filt_fmask(curmask, shr->combined, rl->rectf + 4*offset, rectx); - for(rpass= rl->passes.first; rpass; rpass= rpass->next) { + for (rpass= rl->passes.first; rpass; rpass= rpass->next) { float *fp, *col= NULL; int pixsize= 3; @@ -498,7 +498,7 @@ static void add_filt_passes(RenderLayer *rl, int curmask, int rectx, int offset, break; case SCE_PASS_UV: /* box filter only, gauss will screwup UV too much */ - if(shi->totuv) { + if (shi->totuv) { float mult= (float)count_mask(curmask)/(float)R.osa; fp= rpass->rect + 3*offset; fp[0]+= mult*(0.5f + 0.5f*shi->uv[shi->actuv].uv[0]); @@ -508,17 +508,17 @@ static void add_filt_passes(RenderLayer *rl, int curmask, int rectx, int offset, break; case SCE_PASS_INDEXOB: /* no filter */ - if(shi->vlr) { + if (shi->vlr) { fp= rpass->rect + offset; - if(*fp==0.0f) + if (*fp==0.0f) *fp= (float)shi->obr->ob->index; } break; case SCE_PASS_INDEXMA: /* no filter */ - if(shi->vlr) { + if (shi->vlr) { fp= rpass->rect + offset; - if(*fp==0.0f) + if (*fp==0.0f) *fp= (float)shi->mat->index; } break; @@ -532,11 +532,11 @@ static void add_filt_passes(RenderLayer *rl, int curmask, int rectx, int offset, { /* add minimum speed in pixel, no filter */ fp= rpass->rect + 4*offset; - if( (ABS(shr->winspeed[0]) + ABS(shr->winspeed[1]))< (ABS(fp[0]) + ABS(fp[1])) ) { + if ( (ABS(shr->winspeed[0]) + ABS(shr->winspeed[1]))< (ABS(fp[0]) + ABS(fp[1])) ) { fp[0]= shr->winspeed[0]; fp[1]= shr->winspeed[1]; } - if( (ABS(shr->winspeed[2]) + ABS(shr->winspeed[3]))< (ABS(fp[2]) + ABS(fp[3])) ) { + if ( (ABS(shr->winspeed[2]) + ABS(shr->winspeed[3]))< (ABS(fp[2]) + ABS(fp[3])) ) { fp[2]= shr->winspeed[2]; fp[3]= shr->winspeed[3]; } @@ -549,7 +549,7 @@ static void add_filt_passes(RenderLayer *rl, int curmask, int rectx, int offset, pixsize= 4; break; } - if(col) { + if (col) { fp= rpass->rect + pixsize*offset; add_filt_fmask_pixsize(curmask, col, fp, rectx, pixsize); } @@ -565,7 +565,7 @@ static void add_passes(RenderLayer *rl, int offset, ShadeInput *shi, ShadeResult fp= rl->rectf + 4*offset; copy_v4_v4(fp, shr->combined); - for(rpass= rl->passes.first; rpass; rpass= rpass->next) { + for (rpass= rl->passes.first; rpass; rpass= rpass->next) { float *col= NULL, uvcol[3]; int a, pixsize= 3; @@ -609,7 +609,7 @@ static void add_passes(RenderLayer *rl, int offset, ShadeInput *shi, ShadeResult col= shr->nor; break; case SCE_PASS_UV: - if(shi->totuv) { + if (shi->totuv) { uvcol[0]= 0.5f + 0.5f*shi->uv[shi->actuv].uv[0]; uvcol[1]= 0.5f + 0.5f*shi->uv[shi->actuv].uv[1]; uvcol[2]= 1.0f; @@ -621,13 +621,13 @@ static void add_passes(RenderLayer *rl, int offset, ShadeInput *shi, ShadeResult pixsize= 4; break; case SCE_PASS_INDEXOB: - if(shi->vlr) { + if (shi->vlr) { fp= rpass->rect + offset; *fp= (float)shi->obr->ob->index; } break; case SCE_PASS_INDEXMA: - if(shi->vlr) { + if (shi->vlr) { fp= rpass->rect + offset; *fp= (float)shi->mat->index; } @@ -641,9 +641,9 @@ static void add_passes(RenderLayer *rl, int offset, ShadeInput *shi, ShadeResult pixsize= 4; break; } - if(col) { + if (col) { fp= rpass->rect + pixsize*offset; - for(a=0; a<pixsize; a++) + for (a=0; a<pixsize; a++) fp[a]= col[a]; } } @@ -652,10 +652,10 @@ static void add_passes(RenderLayer *rl, int offset, ShadeInput *shi, ShadeResult int get_sample_layers(RenderPart *pa, RenderLayer *rl, RenderLayer **rlpp) { - if(pa->fullresult.first) { + if (pa->fullresult.first) { int sample, nr= BLI_findindex(&pa->result->layers, rl); - for(sample=0; sample<R.osa; sample++) { + for (sample=0; sample<R.osa; sample++) { RenderResult *rr= BLI_findlink(&pa->fullresult, sample); rlpp[sample]= BLI_findlink(&rr->layers, nr); @@ -675,27 +675,27 @@ static void sky_tile(RenderPart *pa, RenderLayer *rl) RenderLayer *rlpp[RE_MAX_OSA]; int x, y, od=0, totsample; - if(R.r.alphamode!=R_ADDSKY) + if (R.r.alphamode!=R_ADDSKY) return; totsample= get_sample_layers(pa, rl, rlpp); - for(y=pa->disprect.ymin; y<pa->disprect.ymax; y++) { - for(x=pa->disprect.xmin; x<pa->disprect.xmax; x++, od+=4) { + for (y=pa->disprect.ymin; y<pa->disprect.ymax; y++) { + for (x=pa->disprect.xmin; x<pa->disprect.xmax; x++, od+=4) { float col[4]; int sample, done= 0; - for(sample= 0; sample<totsample; sample++) { + for (sample= 0; sample<totsample; sample++) { float *pass= rlpp[sample]->rectf + od; - if(pass[3]<1.0f) { + if (pass[3]<1.0f) { - if(done==0) { + if (done==0) { shadeSkyPixel(col, x, y, pa->thread); done= 1; } - if(pass[3]==0.0f) { + if (pass[3]==0.0f) { copy_v4_v4(pass, col); } else { @@ -705,8 +705,8 @@ static void sky_tile(RenderPart *pa, RenderLayer *rl) } } - if(y&1) - if(R.test_break(R.tbh)) break; + if (y&1) + if (R.test_break(R.tbh)) break; } } @@ -722,67 +722,67 @@ static void atm_tile(RenderPart *pa, RenderLayer *rl) totsample= get_sample_layers(pa, rl, rlpp); /* check that z pass is enabled */ - if(pa->rectz==NULL) return; - for(zpass= rl->passes.first; zpass; zpass= zpass->next) - if(zpass->passtype==SCE_PASS_Z) + if (pa->rectz==NULL) return; + for (zpass= rl->passes.first; zpass; zpass= zpass->next) + if (zpass->passtype==SCE_PASS_Z) break; - if(zpass==NULL) return; + if (zpass==NULL) return; /* check for at least one sun lamp that its atmosphere flag is enabled */ - for(go=R.lights.first; go; go= go->next) { + for (go=R.lights.first; go; go= go->next) { lar= go->lampren; - if(lar->type==LA_SUN && lar->sunsky && (lar->sunsky->effect_type & LA_SUN_EFFECT_AP)) + if (lar->type==LA_SUN && lar->sunsky && (lar->sunsky->effect_type & LA_SUN_EFFECT_AP)) break; } /* do nothign and return if there is no sun lamp */ - if(go==NULL) + if (go==NULL) return; /* for each x,y and each sample, and each sun lamp*/ - for(y=pa->disprect.ymin; y<pa->disprect.ymax; y++) { - for(x=pa->disprect.xmin; x<pa->disprect.xmax; x++, od++) { + for (y=pa->disprect.ymin; y<pa->disprect.ymax; y++) { + for (x=pa->disprect.xmin; x<pa->disprect.xmax; x++, od++) { int sample; - for(sample=0; sample<totsample; sample++) { + for (sample=0; sample<totsample; sample++) { float *zrect= RE_RenderLayerGetPass(rlpp[sample], SCE_PASS_Z) + od; float *rgbrect = rlpp[sample]->rectf + 4*od; float rgb[3] = {0}; int done= 0; - for(go=R.lights.first; go; go= go->next) { + for (go=R.lights.first; go; go= go->next) { lar= go->lampren; - if(lar->type==LA_SUN && lar->sunsky) { + if (lar->type==LA_SUN && lar->sunsky) { /* if it's sky continue and don't apply atmosphere effect on it */ - if(*zrect >= 9.9e10f || rgbrect[3]==0.0f) { + if (*zrect >= 9.9e10f || rgbrect[3]==0.0f) { continue; } - if((lar->sunsky->effect_type & LA_SUN_EFFECT_AP)) { + if ((lar->sunsky->effect_type & LA_SUN_EFFECT_AP)) { float tmp_rgb[3]; /* skip if worldspace lamp vector is below horizon */ - if(go->ob->obmat[2][2] < 0.f) { + if (go->ob->obmat[2][2] < 0.f) { continue; } copy_v3_v3(tmp_rgb, rgbrect); - if(rgbrect[3]!=1.0f) { /* de-premul */ + if (rgbrect[3]!=1.0f) { /* de-premul */ mul_v3_fl(tmp_rgb, 1.0f/rgbrect[3]); } shadeAtmPixel(lar->sunsky, tmp_rgb, x, y, *zrect); - if(rgbrect[3]!=1.0f) { /* premul */ + if (rgbrect[3]!=1.0f) { /* premul */ mul_v3_fl(tmp_rgb, rgbrect[3]); } - if(done==0) { + if (done==0) { copy_v3_v3(rgb, tmp_rgb); done = 1; } - else{ + else { rgb[0] = 0.5f*rgb[0] + 0.5f*tmp_rgb[0]; rgb[1] = 0.5f*rgb[1] + 0.5f*tmp_rgb[1]; rgb[2] = 0.5f*rgb[2] + 0.5f*tmp_rgb[2]; @@ -792,7 +792,7 @@ static void atm_tile(RenderPart *pa, RenderLayer *rl) } /* if at least for one sun lamp aerial perspective was applied*/ - if(done) { + if (done) { copy_v3_v3(rgbrect, rgb); } } @@ -808,10 +808,10 @@ static void shadeDA_tile(RenderPart *pa, RenderLayer *rl) int samp; int x, y, seed, crop=0, offs=0, od; - if(R.test_break(R.tbh)) return; + if (R.test_break(R.tbh)) return; /* irregular shadowb buffer creation */ - if(R.r.mode & R_SHADOW) + if (R.r.mode & R_SHADOW) ISB_create(pa, NULL); /* we set per pixel a fixed seed, for random AO and shadow samples */ @@ -821,11 +821,11 @@ static void shadeDA_tile(RenderPart *pa, RenderLayer *rl) shade_sample_initialize(&ssamp, pa, rl); /* occlusion caching */ - if(R.occlusiontree) + if (R.occlusiontree) cache_occ_samples(&R, pa, &ssamp); /* filtered render, for now we assume only 1 filter size */ - if(pa->crop) { + if (pa->crop) { crop= 1; rectdaps+= pa->rectx + 1; offs= pa->rectx + 1; @@ -836,30 +836,30 @@ static void shadeDA_tile(RenderPart *pa, RenderLayer *rl) rr->renrect.ymax = -2*crop; rr->renlay= rl; - for(y=pa->disprect.ymin+crop; y<pa->disprect.ymax-crop; y++, rr->renrect.ymax++) { + for (y=pa->disprect.ymin+crop; y<pa->disprect.ymax-crop; y++, rr->renrect.ymax++) { rd= rectdaps; od= offs; - for(x=pa->disprect.xmin+crop; x<pa->disprect.xmax-crop; x++, rd++, od++) { + for (x=pa->disprect.xmin+crop; x<pa->disprect.xmax-crop; x++, rd++, od++) { BLI_thread_srandom(pa->thread, seed++); - if(*rd) { - if(shade_samples(&ssamp, (PixStr *)(*rd), x, y)) { + if (*rd) { + if (shade_samples(&ssamp, (PixStr *)(*rd), x, y)) { /* multisample buffers or filtered mask filling? */ - if(pa->fullresult.first) { + if (pa->fullresult.first) { int a; - for(samp=0; samp<ssamp.tot; samp++) { + for (samp=0; samp<ssamp.tot; samp++) { int smask= ssamp.shi[samp].mask; - for(a=0; a<R.osa; a++) { + for (a=0; a<R.osa; a++) { int mask= 1<<a; - if(smask & mask) + if (smask & mask) add_passes(ssamp.rlpp[a], od, &ssamp.shi[samp], &ssamp.shr[samp]); } } } else { - for(samp=0; samp<ssamp.tot; samp++) + for (samp=0; samp<ssamp.tot; samp++) add_filt_passes(rl, ssamp.shi[samp].mask, pa->rectx, od, &ssamp.shi[samp], &ssamp.shr[samp]); } } @@ -869,16 +869,16 @@ static void shadeDA_tile(RenderPart *pa, RenderLayer *rl) rectdaps+= pa->rectx; offs+= pa->rectx; - if(y&1) if(R.test_break(R.tbh)) break; + if (y&1) if(R.test_break(R.tbh)) break; } /* disable scanline updating */ rr->renlay= NULL; - if(R.r.mode & R_SHADOW) + if (R.r.mode & R_SHADOW) ISB_free(pa); - if(R.occlusiontree) + if (R.occlusiontree) free_occ_samples(&R, pa); } @@ -902,9 +902,9 @@ static void freeps(ListBase *lb) { PixStrMain *psm, *psmnext; - for(psm= lb->first; psm; psm= psmnext) { + for (psm= lb->first; psm; psm= psmnext) { psmnext= psm->next; - if(psm->ps) + if (psm->ps) MEM_freeN(psm->ps); MEM_freeN(psm); } @@ -916,11 +916,11 @@ static void addps(ListBase *lb, intptr_t *rd, int obi, int facenr, int z, int ma PixStrMain *psm; PixStr *ps, *last= NULL; - if(*rd) { + if (*rd) { ps= (PixStr *)(*rd); - while(ps) { - if( ps->obi == obi && ps->facenr == facenr ) { + while (ps) { + if ( ps->obi == obi && ps->facenr == facenr ) { ps->mask |= mask; return; } @@ -932,12 +932,12 @@ static void addps(ListBase *lb, intptr_t *rd, int obi, int facenr, int z, int ma /* make new PS (pixel struct) */ psm= lb->last; - if(psm->counter==4095) + if (psm->counter==4095) psm= addpsmain(lb); ps= psm->ps + psm->counter++; - if(last) last->next= ps; + if (last) last->next= ps; else *rd= (intptr_t)ps; ps->next= NULL; @@ -954,11 +954,11 @@ static void edge_enhance_add(RenderPart *pa, float *rectf, float *arect) float addcol[4]; int pix; - if(arect==NULL) + if (arect==NULL) return; - for(pix= pa->rectx*pa->recty; pix>0; pix--, arect++, rectf+=4) { - if(*arect != 0.0f) { + for (pix= pa->rectx*pa->recty; pix>0; pix--, arect++, rectf+=4) { + if (*arect != 0.0f) { addcol[0]= *arect * R.r.edgeR; addcol[1]= *arect * R.r.edgeG; addcol[2]= *arect * R.r.edgeB; @@ -975,12 +975,12 @@ static void convert_to_key_alpha(RenderPart *pa, RenderLayer *rl) totsample= get_sample_layers(pa, rl, rlpp); - for(sample= 0; sample<totsample; sample++) { + for (sample= 0; sample<totsample; sample++) { float *rectf= rlpp[sample]->rectf; - for(y= pa->rectx*pa->recty; y>0; y--, rectf+=4) { - if(rectf[3] >= 1.0f); - else if(rectf[3] > 0.0f) { + for (y= pa->rectx*pa->recty; y>0; y--, rectf+=4) { + if (rectf[3] >= 1.0f); + else if (rectf[3] > 0.0f) { rectf[0] /= rectf[3]; rectf[1] /= rectf[3]; rectf[2] /= rectf[3]; @@ -999,10 +999,10 @@ static void edge_enhance_tile(RenderPart *pa, float *rectf, int *rectz) /* shift values in zbuffer 4 to the right (anti overflows), for filter we need multiplying with 12 max */ rz= rectz; - if(rz==NULL) return; + if (rz==NULL) return; - for(y=0; y<pa->recty; y++) - for(x=0; x<pa->rectx; x++, rz++) (*rz)>>= 4; + for (y=0; y<pa->recty; y++) + for (x=0; x<pa->rectx; x++, rz++) (*rz)>>= 4; rz1= rectz; rz2= rz1+pa->rectx; @@ -1010,8 +1010,8 @@ static void edge_enhance_tile(RenderPart *pa, float *rectf, int *rectz) rf= rectf+pa->rectx+1; - for(y=0; y<pa->recty-2; y++) { - for(x=0; x<pa->rectx-2; x++, rz1++, rz2++, rz3++, rf++) { + for (y=0; y<pa->recty-2; y++) { + for (x=0; x<pa->rectx-2; x++, rz1++, rz2++, rz3++, rf++) { /* prevent overflow with sky z values */ zval1= rz1[0] + 2*rz1[1] + rz1[2]; @@ -1019,19 +1019,19 @@ static void edge_enhance_tile(RenderPart *pa, float *rectf, int *rectz) zval3= rz3[0] + 2*rz3[1] + rz3[2]; col= ( 4*rz2[1] - (zval1 + zval2 + zval3)/3 ); - if(col<0) col= -col; + if (col<0) col= -col; col >>= 5; - if(col > (1<<16)) col= (1<<16); + if (col > (1<<16)) col= (1<<16); else col= (R.r.edgeint*col)>>8; - if(col>0) { + if (col>0) { float fcol; - if(col>255) fcol= 1.0f; + if (col>255) fcol= 1.0f; else fcol= (float)col/255.0f; - if(R.osa) + if (R.osa) *rf+= fcol/(float)R.osa; else *rf= fcol; @@ -1045,8 +1045,8 @@ static void edge_enhance_tile(RenderPart *pa, float *rectf, int *rectz) /* shift back zbuf values, we might need it still */ rz= rectz; - for(y=0; y<pa->recty; y++) - for(x=0; x<pa->rectx; x++, rz++) (*rz)<<= 4; + for (y=0; y<pa->recty; y++) + for (x=0; x<pa->rectx; x++, rz++) (*rz)<<= 4; } @@ -1059,12 +1059,12 @@ static void reset_sky_speed(RenderPart *pa, RenderLayer *rl) totsample= get_sample_layers(pa, rl, rlpp); - for(sample= 0; sample<totsample; sample++) { + for (sample= 0; sample<totsample; sample++) { fp= RE_RenderLayerGetPass(rlpp[sample], SCE_PASS_VECTOR); - if(fp==NULL) break; + if (fp==NULL) break; - for(a= 4*pa->rectx*pa->recty - 1; a>=0; a--) - if(fp[a] == PASS_VECTOR_MAX) fp[a]= 0.0f; + for (a= 4*pa->rectx*pa->recty - 1; a>=0; a--) + if (fp[a] == PASS_VECTOR_MAX) fp[a]= 0.0f; } } @@ -1074,16 +1074,16 @@ static unsigned short *make_solid_mask(RenderPart *pa) unsigned short *solidmask, *sp; int x; - if(rd==NULL) return NULL; + if (rd==NULL) return NULL; sp=solidmask= MEM_mallocN(sizeof(short)*pa->rectx*pa->recty, "solidmask"); - for(x=pa->rectx*pa->recty; x>0; x--, rd++, sp++) { - if(*rd) { + for (x=pa->rectx*pa->recty; x>0; x--, rd++, sp++) { + if (*rd) { PixStr *ps= (PixStr *)*rd; *sp= ps->mask; - for(ps= ps->next; ps; ps= ps->next) + for (ps= ps->next; ps; ps= ps->next) *sp |= ps->mask; } else @@ -1098,10 +1098,10 @@ static void addAlphaOverFloatMask(float *dest, float *source, unsigned short dma unsigned short shared= dmask & smask; float mul= 1.0f - source[3]; - if(shared) { /* overlapping masks */ + if (shared) { /* overlapping masks */ /* masks differ, we make a mixture of 'add' and 'over' */ - if(shared!=dmask) { + if (shared!=dmask) { float shared_bits= (float)count_mask(shared); /* alpha over */ float tot_bits= (float)count_mask(smask|dmask); /* alpha add */ @@ -1109,7 +1109,7 @@ static void addAlphaOverFloatMask(float *dest, float *source, unsigned short dma mul= add + (1.0f-add)*mul; } } - else if(dmask && smask) { + else if (dmask && smask) { /* works for premul only, of course */ dest[0]+= source[0]; dest[1]+= source[1]; @@ -1143,16 +1143,16 @@ static void make_pixelstructs(RenderPart *pa, ZSpan *zspan, int sample, void *da int x, y; int mask= 1<<sample; - for(y=0; y<pa->recty; y++) { - for(x=0; x<pa->rectx; x++, rd++, rp++, ro++, rz++, rm++) { - if(*rp) { + for (y=0; y<pa->recty; y++) { + for (x=0; x<pa->rectx; x++, rd++, rp++, ro++, rz++, rm++) { + if (*rp) { addps(lb, rd, *ro, *rp, *rz, (zspan->rectmask)? *rm: 0, mask); } } } - if(sdata->rl->layflag & SCE_LAY_EDGE) - if(R.r.mode & R_EDGE) + if (sdata->rl->layflag & SCE_LAY_EDGE) + if (R.r.mode & R_EDGE) edge_enhance_tile(pa, sdata->edgerect, zspan->rectz); } @@ -1170,47 +1170,47 @@ void zbufshadeDA_tile(RenderPart *pa) pa->recto= MEM_mallocN(sizeof(int)*pa->rectx*pa->recty, "recto"); pa->rectp= MEM_mallocN(sizeof(int)*pa->rectx*pa->recty, "rectp"); pa->rectz= MEM_mallocN(sizeof(int)*pa->rectx*pa->recty, "rectz"); - for(rl= rr->layers.first; rl; rl= rl->next) { - if((rl->layflag & SCE_LAY_ZMASK) && (rl->layflag & SCE_LAY_NEG_ZMASK)) + for (rl= rr->layers.first; rl; rl= rl->next) { + if ((rl->layflag & SCE_LAY_ZMASK) && (rl->layflag & SCE_LAY_NEG_ZMASK)) pa->rectmask= MEM_mallocN(sizeof(int)*pa->rectx*pa->recty, "rectmask"); /* initialize pixelstructs and edge buffer */ addpsmain(&psmlist); pa->rectdaps= MEM_callocN(sizeof(intptr_t)*pa->rectx*pa->recty+4, "zbufDArectd"); - if(rl->layflag & SCE_LAY_EDGE) - if(R.r.mode & R_EDGE) + if (rl->layflag & SCE_LAY_EDGE) + if (R.r.mode & R_EDGE) edgerect= MEM_callocN(sizeof(float)*pa->rectx*pa->recty, "rectedge"); /* always fill visibility */ - for(pa->sample=0; pa->sample<R.osa; pa->sample+=4) { + for (pa->sample=0; pa->sample<R.osa; pa->sample+=4) { ZbufSolidData sdata; sdata.rl= rl; sdata.psmlist= &psmlist; sdata.edgerect= edgerect; zbuffer_solid(pa, rl, make_pixelstructs, &sdata); - if(R.test_break(R.tbh)) break; + if (R.test_break(R.tbh)) break; } /* shades solid */ - if(rl->layflag & SCE_LAY_SOLID) + if (rl->layflag & SCE_LAY_SOLID) shadeDA_tile(pa, rl); /* lamphalo after solid, before ztra, looks nicest because ztra does own halo */ - if(R.flag & R_LAMPHALO) - if(rl->layflag & SCE_LAY_HALO) + if (R.flag & R_LAMPHALO) + if (rl->layflag & SCE_LAY_HALO) lamphalo_tile(pa, rl); /* halo before ztra, because ztra fills in zbuffer now */ - if(R.flag & R_HALO) - if(rl->layflag & SCE_LAY_HALO) + if (R.flag & R_HALO) + if (rl->layflag & SCE_LAY_HALO) halo_tile(pa, rl); /* transp layer */ - if(R.flag & R_ZTRA || R.totstrand) { - if(rl->layflag & (SCE_LAY_ZTRA|SCE_LAY_STRAND)) { - if(pa->fullresult.first) { + if (R.flag & R_ZTRA || R.totstrand) { + if (rl->layflag & (SCE_LAY_ZTRA|SCE_LAY_STRAND)) { + if (pa->fullresult.first) { zbuffer_transp_shade(pa, rl, rl->rectf, &psmlist); } else { @@ -1225,17 +1225,17 @@ void zbufshadeDA_tile(RenderPart *pa) SWAP(float *, rl->acolrect, rl->rectf); /* zbuffer transp only returns ztramask if there's solid rendered */ - if(ztramask) + if (ztramask) solidmask= make_solid_mask(pa); - if(ztramask && solidmask) { + if (ztramask && solidmask) { unsigned short *sps= solidmask, *spz= ztramask; unsigned short fullmask= (1<<R.osa)-1; float *fcol= rl->rectf; float *acol= rl->acolrect; int x; - for(x=pa->rectx*pa->recty; x>0; x--, acol+=4, fcol+=4, sps++, spz++) { - if(*sps == fullmask) + for (x=pa->rectx*pa->recty; x>0; x--, acol+=4, fcol+=4, sps++, spz++) { + if (*sps == fullmask) addAlphaOverFloat(fcol, acol); else addAlphaOverFloatMask(fcol, acol, *sps, *spz); @@ -1244,44 +1244,44 @@ void zbufshadeDA_tile(RenderPart *pa) else { float *fcol= rl->rectf; float *acol= rl->acolrect; int x; - for(x=pa->rectx*pa->recty; x>0; x--, acol+=4, fcol+=4) { + for (x=pa->rectx*pa->recty; x>0; x--, acol+=4, fcol+=4) { addAlphaOverFloat(fcol, acol); } } - if(solidmask) MEM_freeN(solidmask); - if(ztramask) MEM_freeN(ztramask); + if (solidmask) MEM_freeN(solidmask); + if (ztramask) MEM_freeN(ztramask); } } } /* sun/sky */ - if(rl->layflag & SCE_LAY_SKY) + if (rl->layflag & SCE_LAY_SKY) atm_tile(pa, rl); /* sky before edge */ - if(rl->layflag & SCE_LAY_SKY) + if (rl->layflag & SCE_LAY_SKY) sky_tile(pa, rl); /* extra layers */ - if(rl->layflag & SCE_LAY_EDGE) - if(R.r.mode & R_EDGE) + if (rl->layflag & SCE_LAY_EDGE) + if (R.r.mode & R_EDGE) edge_enhance_add(pa, rl->rectf, edgerect); - if(rl->passflag & SCE_PASS_VECTOR) + if (rl->passflag & SCE_PASS_VECTOR) reset_sky_speed(pa, rl); /* de-premul alpha */ - if(R.r.alphamode & R_ALPHAKEY) + if (R.r.alphamode & R_ALPHAKEY) convert_to_key_alpha(pa, rl); /* free stuff within loop! */ MEM_freeN(pa->rectdaps); pa->rectdaps= NULL; freeps(&psmlist); - if(edgerect) MEM_freeN(edgerect); + if (edgerect) MEM_freeN(edgerect); edgerect= NULL; - if(pa->rectmask) { + if (pa->rectmask) { MEM_freeN(pa->rectmask); pa->rectmask= NULL; } @@ -1319,8 +1319,8 @@ void zbufshade_tile(RenderPart *pa) pa->rectp= MEM_mallocN(sizeof(int)*pa->rectx*pa->recty, "rectp"); pa->rectz= MEM_mallocN(sizeof(int)*pa->rectx*pa->recty, "rectz"); - for(rl= rr->layers.first; rl; rl= rl->next) { - if((rl->layflag & SCE_LAY_ZMASK) && (rl->layflag & SCE_LAY_NEG_ZMASK)) + for (rl= rr->layers.first; rl; rl= rl->next) { + if ((rl->layflag & SCE_LAY_ZMASK) && (rl->layflag & SCE_LAY_NEG_ZMASK)) pa->rectmask= MEM_mallocN(sizeof(int)*pa->rectx*pa->recty, "rectmask"); /* general shader info, passes */ @@ -1328,11 +1328,11 @@ void zbufshade_tile(RenderPart *pa) zbuffer_solid(pa, rl, NULL, NULL); - if(!R.test_break(R.tbh)) { /* NOTE: this if() is not consistent */ + if (!R.test_break(R.tbh)) { /* NOTE: this if() is not consistent */ /* edges only for solid part, ztransp doesn't support it yet anti-aliased */ - if(rl->layflag & SCE_LAY_EDGE) { - if(R.r.mode & R_EDGE) { + if (rl->layflag & SCE_LAY_EDGE) { + if (R.r.mode & R_EDGE) { edgerect= MEM_callocN(sizeof(float)*pa->rectx*pa->recty, "rectedge"); edge_enhance_tile(pa, edgerect, pa->rectz); } @@ -1342,7 +1342,7 @@ void zbufshade_tile(RenderPart *pa) rr->renrect.ymin = 0; rr->renlay= rl; - if(rl->layflag & SCE_LAY_SOLID) { + if (rl->layflag & SCE_LAY_SOLID) { float *fcol= rl->rectf; int *ro= pa->recto, *rp= pa->rectp, *rz= pa->rectz; int x, y, offs=0, seed; @@ -1351,35 +1351,35 @@ void zbufshade_tile(RenderPart *pa) seed= pa->rectx*pa->disprect.ymin; /* irregular shadowb buffer creation */ - if(R.r.mode & R_SHADOW) + if (R.r.mode & R_SHADOW) ISB_create(pa, NULL); - if(R.occlusiontree) + if (R.occlusiontree) cache_occ_samples(&R, pa, &ssamp); - for(y=pa->disprect.ymin; y<pa->disprect.ymax; y++, rr->renrect.ymax++) { - for(x=pa->disprect.xmin; x<pa->disprect.xmax; x++, ro++, rz++, rp++, fcol+=4, offs++) { + for (y=pa->disprect.ymin; y<pa->disprect.ymax; y++, rr->renrect.ymax++) { + for (x=pa->disprect.xmin; x<pa->disprect.xmax; x++, ro++, rz++, rp++, fcol+=4, offs++) { /* per pixel fixed seed */ BLI_thread_srandom(pa->thread, seed++); - if(*rp) { + if (*rp) { ps.obi= *ro; ps.facenr= *rp; ps.z= *rz; - if(shade_samples(&ssamp, &ps, x, y)) { + if (shade_samples(&ssamp, &ps, x, y)) { /* combined and passes */ add_passes(rl, offs, ssamp.shi, ssamp.shr); } } } - if(y&1) - if(R.test_break(R.tbh)) break; + if (y&1) + if (R.test_break(R.tbh)) break; } - if(R.occlusiontree) + if (R.occlusiontree) free_occ_samples(&R, pa); - if(R.r.mode & R_SHADOW) + if (R.r.mode & R_SHADOW) ISB_free(pa); } @@ -1388,17 +1388,17 @@ void zbufshade_tile(RenderPart *pa) } /* lamphalo after solid, before ztra, looks nicest because ztra does own halo */ - if(R.flag & R_LAMPHALO) - if(rl->layflag & SCE_LAY_HALO) + if (R.flag & R_LAMPHALO) + if (rl->layflag & SCE_LAY_HALO) lamphalo_tile(pa, rl); /* halo before ztra, because ztra fills in zbuffer now */ - if(R.flag & R_HALO) - if(rl->layflag & SCE_LAY_HALO) + if (R.flag & R_HALO) + if (rl->layflag & SCE_LAY_HALO) halo_tile(pa, rl); - if(R.flag & R_ZTRA || R.totstrand) { - if(rl->layflag & (SCE_LAY_ZTRA|SCE_LAY_STRAND)) { + if (R.flag & R_ZTRA || R.totstrand) { + if (rl->layflag & (SCE_LAY_ZTRA|SCE_LAY_STRAND)) { float *fcol, *acol; int x; @@ -1411,37 +1411,37 @@ void zbufshade_tile(RenderPart *pa) SWAP(float *, rl->acolrect, rl->rectf); fcol= rl->rectf; acol= rl->acolrect; - for(x=pa->rectx*pa->recty; x>0; x--, acol+=4, fcol+=4) { + for (x=pa->rectx*pa->recty; x>0; x--, acol+=4, fcol+=4) { addAlphaOverFloat(fcol, acol); } } } /* sun/sky */ - if(rl->layflag & SCE_LAY_SKY) + if (rl->layflag & SCE_LAY_SKY) atm_tile(pa, rl); /* sky before edge */ - if(rl->layflag & SCE_LAY_SKY) + if (rl->layflag & SCE_LAY_SKY) sky_tile(pa, rl); - if(!R.test_break(R.tbh)) { - if(rl->layflag & SCE_LAY_EDGE) - if(R.r.mode & R_EDGE) + if (!R.test_break(R.tbh)) { + if (rl->layflag & SCE_LAY_EDGE) + if (R.r.mode & R_EDGE) edge_enhance_add(pa, rl->rectf, edgerect); } - if(rl->passflag & SCE_PASS_VECTOR) + if (rl->passflag & SCE_PASS_VECTOR) reset_sky_speed(pa, rl); /* de-premul alpha */ - if(R.r.alphamode & R_ALPHAKEY) + if (R.r.alphamode & R_ALPHAKEY) convert_to_key_alpha(pa, rl); - if(edgerect) MEM_freeN(edgerect); + if (edgerect) MEM_freeN(edgerect); edgerect= NULL; - if(pa->rectmask) { + if (pa->rectmask) { MEM_freeN(pa->rectmask); pa->rectmask= NULL; } @@ -1470,37 +1470,37 @@ static void addps_sss(void *cb_handle, int obi, int facenr, int x, int y, int z) /* extra border for filter gives double samples on part edges, * don't use those */ - if(x<pa->crop || x>=pa->rectx-pa->crop) + if (x<pa->crop || x>=pa->rectx-pa->crop) return; - if(y<pa->crop || y>=pa->recty-pa->crop) + if (y<pa->crop || y>=pa->recty-pa->crop) return; - if(pa->rectall) { + if (pa->rectall) { intptr_t *rs= pa->rectall + pa->rectx*y + x; addps(&handle->psmlist, rs, obi, facenr, z, 0, 0); handle->totps++; } - if(pa->rectz) { + if (pa->rectz) { int *rz= pa->rectz + pa->rectx*y + x; int *rp= pa->rectp + pa->rectx*y + x; int *ro= pa->recto + pa->rectx*y + x; - if(z < *rz) { - if(*rp == 0) + if (z < *rz) { + if (*rp == 0) handle->totps++; *rz= z; *rp= facenr; *ro= obi; } } - if(pa->rectbackz) { + if (pa->rectbackz) { int *rz= pa->rectbackz + pa->rectx*y + x; int *rp= pa->rectbackp + pa->rectx*y + x; int *ro= pa->rectbacko + pa->rectx*y + x; - if(z >= *rz) { - if(*rp == 0) + if (z >= *rz) { + if (*rp == 0) handle->totps++; *rz= z; *rp= facenr; @@ -1518,7 +1518,7 @@ static void shade_sample_sss(ShadeSample *ssamp, Material *mat, ObjectInstanceRe /* cache for shadow */ shi->samplenr= R.shadowsamplenr[shi->thread]++; - if(quad) + if (quad) shade_input_set_triangle_i(shi, obi, vlr, 0, 2, 3); else shade_input_set_triangle_i(shi, obi, vlr, 0, 1, 2); @@ -1548,11 +1548,11 @@ static void shade_sample_sss(ShadeSample *ssamp, Material *mat, ObjectInstanceRe shade_input_set_normals(shi); /* we don't want flipped normals, they screw up back scattering */ - if(shi->flippednor) + if (shi->flippednor) shade_input_flip_normals(shi); /* not a pretty solution, but fixes common cases */ - if(shi->obr->ob && shi->obr->ob->transflag & OB_NEG_SCALE) { + if (shi->obr->ob && shi->obr->ob->transflag & OB_NEG_SCALE) { negate_v3(shi->vn); negate_v3(shi->vno); negate_v3(shi->nmapnorm); @@ -1560,7 +1560,7 @@ static void shade_sample_sss(ShadeSample *ssamp, Material *mat, ObjectInstanceRe /* if nodetree, use the material that we are currently preprocessing * instead of the node material */ - if(shi->mat->nodetree && shi->mat->use_nodes) + if (shi->mat->nodetree && shi->mat->use_nodes) shi->mat= mat; /* init material vars */ @@ -1638,7 +1638,7 @@ void zbufshade_sss_tile(RenderPart *pa) shade_sample_initialize(&ssamp, pa, rr->layers.first); ssamp.tot= 1; - for(rl=rr->layers.first; rl; rl=rl->next) { + for (rl=rr->layers.first; rl; rl=rl->next) { ssamp.shi[0].lay |= rl->lay; ssamp.shi[0].layflag |= rl->layflag; ssamp.shi[0].passflag |= rl->passflag; @@ -1655,7 +1655,7 @@ void zbufshade_sss_tile(RenderPart *pa) /* create the pixelstrs to be used later */ zbuffer_sss(pa, lay, &handle, addps_sss); - if(handle.totps==0) { + if (handle.totps==0) { zbufshade_sss_free(pa); return; } @@ -1668,11 +1668,11 @@ void zbufshade_sss_tile(RenderPart *pa) #if 0 /* create ISB (does not work currently!) */ - if(re->r.mode & R_SHADOW) + if (re->r.mode & R_SHADOW) ISB_create(pa, NULL); #endif - if(display) { + if (display) { /* initialize scanline updates for main thread */ rr->renrect.ymin = 0; rr->renlay= rl; @@ -1691,15 +1691,15 @@ void zbufshade_sss_tile(RenderPart *pa) #endif totpoint= 0; - for(y=pa->disprect.ymin; y<pa->disprect.ymax; y++, rr->renrect.ymax++) { - for(x=pa->disprect.xmin; x<pa->disprect.xmax; x++, fcol+=4) { + for (y=pa->disprect.ymin; y<pa->disprect.ymax; y++, rr->renrect.ymax++) { + for (x=pa->disprect.xmin; x<pa->disprect.xmax; x++, fcol+=4) { /* per pixel fixed seed */ BLI_thread_srandom(pa->thread, seed++); #if 0 - if(rs) { + if (rs) { /* for each sample in this pixel, shade it */ - for(ps=(PixStr*)*rs; ps; ps=ps->next) { + for (ps=(PixStr*)*rs; ps; ps=ps->next) { ObjectInstanceRen *obi= &re->objectinstance[ps->obi]; ObjectRen *obr= obi->obr; vlr= RE_findOrAddVlak(obr, (ps->facenr-1) & RE_QUAD_MASK); @@ -1718,8 +1718,8 @@ void zbufshade_sss_tile(RenderPart *pa) rs++; } #else - if(rp) { - if(*rp != 0) { + if (rp) { + if (*rp != 0) { ObjectInstanceRen *obi= &re->objectinstance[*ro]; ObjectRen *obr= obi->obr; @@ -1738,8 +1738,8 @@ void zbufshade_sss_tile(RenderPart *pa) rp++; rz++; ro++; } - if(rbp) { - if(*rbp != 0 && !(*rbp == *(rp-1) && *rbo == *(ro-1))) { + if (rbp) { + if (*rbp != 0 && !(*rbp == *(rp-1) && *rbo == *(ro-1))) { ObjectInstanceRen *obi= &re->objectinstance[*rbo]; ObjectRen *obr= obi->obr; @@ -1763,12 +1763,12 @@ void zbufshade_sss_tile(RenderPart *pa) #endif } - if(y&1) - if(re->test_break(re->tbh)) break; + if (y&1) + if (re->test_break(re->tbh)) break; } /* note: after adding we do not free these arrays, sss keeps them */ - if(totpoint > 0) { + if (totpoint > 0) { sss_add_points(re, co, color, area, totpoint); } else { @@ -1778,11 +1778,11 @@ void zbufshade_sss_tile(RenderPart *pa) } #if 0 - if(re->r.mode & R_SHADOW) + if (re->r.mode & R_SHADOW) ISB_free(pa); #endif - if(display) { + if (display) { /* display active layer */ rr->renrect.ymin=rr->renrect.ymax = 0; rr->renlay= render_get_active_layer(&R, rr); @@ -1806,37 +1806,37 @@ static void renderhalo_post(RenderResult *rr, float *rectf, HaloRen *har) /* pos har->miny= miny= haloys - har->rad/R.ycor; har->maxy= maxy= haloys + har->rad/R.ycor; - if(maxy<0); - else if(rr->recty<miny); + if (maxy<0); + else if (rr->recty<miny); else { minx= floor(haloxs-har->rad); maxx= ceil(haloxs+har->rad); - if(maxx<0); - else if(rr->rectx<minx); + if (maxx<0); + else if (rr->rectx<minx); else { - if(minx<0) minx= 0; - if(maxx>=rr->rectx) maxx= rr->rectx-1; - if(miny<0) miny= 0; - if(maxy>rr->recty) maxy= rr->recty; + if (minx<0) minx= 0; + if (maxx>=rr->rectx) maxx= rr->rectx-1; + if (miny<0) miny= 0; + if (maxy>rr->recty) maxy= rr->recty; rectft= rectf+ 4*rr->rectx*miny; - for(y=miny; y<maxy; y++) { + for (y=miny; y<maxy; y++) { rtf= rectft+4*minx; yn= (y - haloys)*R.ycor; ysq= yn*yn; - for(x=minx; x<=maxx; x++) { + for (x=minx; x<=maxx; x++) { xn= x - haloxs; xsq= xn*xn; dist= xsq+ysq; - if(dist<har->radsq) { + if (dist<har->radsq) { - if(shadeHaloFloat(har, colf, 0x7FFFFF, dist, xn, yn, har->flarec)) + if (shadeHaloFloat(har, colf, 0x7FFFFF, dist, xn, yn, har->flarec)) addalphaAddfacFloat(rtf, colf, har->add); } rtf+=4; @@ -1844,7 +1844,7 @@ static void renderhalo_post(RenderResult *rr, float *rectf, HaloRen *har) /* pos rectft+= 4*rr->rectx; - if(R.test_break(R.tbh)) break; + if (R.test_break(R.tbh)) break; } } } @@ -1885,7 +1885,7 @@ static void renderflare(RenderResult *rr, float *rectf, HaloRen *har) /* next halo's: the flares */ rc= hashvectf + ma->seed2; - for(b=1; b<har->flarec; b++) { + for (b=1; b<har->flarec; b++) { fla.r= fabs(rc[0]); fla.g= fabs(rc[1]); @@ -1898,7 +1898,7 @@ static void renderflare(RenderResult *rr, float *rectf, HaloRen *har) fla.rad= ma->subsize*sqrtf(fabs(2.0f*har->rad*rc[4])); - if(type==3) { + if (type==3) { fla.rad*= 3.0f; fla.rad+= R.rectx/10; } @@ -1912,16 +1912,16 @@ static void renderflare(RenderResult *rr, float *rectf, HaloRen *har) fla.xs= R.winx/2 + vec[0] + (1.2f+rc[8])*R.rectx*vec[0]/vec[2]; fla.ys= R.winy/2 + vec[1] + (1.2f+rc[8])*R.rectx*vec[1]/vec[2]; - if(R.flag & R_SEC_FIELD) { - if(R.r.mode & R_ODDFIELD) fla.ys += 0.5f; + if (R.flag & R_SEC_FIELD) { + if (R.r.mode & R_ODDFIELD) fla.ys += 0.5f; else fla.ys -= 0.5f; } - if(type & 1) fla.type= HA_FLARECIRC; + if (type & 1) fla.type= HA_FLARECIRC; else fla.type= 0; renderhalo_post(rr, rectf, &fla); fla.alfa*= 0.5f; - if(type & 2) fla.type= HA_FLARECIRC; + if (type & 2) fla.type= HA_FLARECIRC; else fla.type= 0; renderhalo_post(rr, rectf, &fla); @@ -1938,11 +1938,11 @@ void add_halo_flare(Render *re) int a, mode, do_draw=0; /* for now, we get the first renderlayer in list with halos set */ - for(rl= rr->layers.first; rl; rl= rl->next) - if(rl->layflag & SCE_LAY_HALO) + for (rl= rr->layers.first; rl; rl= rl->next) + if (rl->layflag & SCE_LAY_HALO) break; - if(rl==NULL || rl->rectf==NULL) + if (rl==NULL || rl->rectf==NULL) return; mode= R.r.mode; @@ -1950,16 +1950,16 @@ void add_halo_flare(Render *re) project_renderdata(&R, projectverto, 0, 0, 0); - for(a=0; a<R.tothalo; a++) { + for (a=0; a<R.tothalo; a++) { har= R.sortedhalos[a]; - if(har->flarec) { + if (har->flarec) { do_draw= 1; renderflare(rr, rl->rectf, har); } } - if(do_draw) { + if (do_draw) { /* weak... the display callback wants an active renderlayer pointer... */ rr->renlay= rl; re->display_draw(re->ddh, rr, NULL); @@ -1998,7 +1998,7 @@ typedef struct BakeShade { static void bake_set_shade_input(ObjectInstanceRen *obi, VlakRen *vlr, ShadeInput *shi, int quad, int UNUSED(isect), int x, int y, float u, float v) { - if(quad) + if (quad) shade_input_set_triangle_i(shi, obi, vlr, 0, 2, 3); else shade_input_set_triangle_i(shi, obi, vlr, 0, 1, 2); @@ -2017,7 +2017,7 @@ static void bake_set_shade_input(ObjectInstanceRen *obi, VlakRen *vlr, ShadeInpu shade_input_set_normals(shi); /* no normal flip */ - if(shi->flippednor) + if (shi->flippednor) shade_input_flip_normals(shi); /* set up view vector to look right at the surface (note that the normal @@ -2036,10 +2036,10 @@ static void bake_shade(void *handle, Object *ob, ShadeInput *shi, int UNUSED(qua shade_input_init_material(shi); - if(bs->type==RE_BAKE_AO) { + if (bs->type==RE_BAKE_AO) { ambient_occlusion(shi); - if(R.r.bake_flag & R_BAKE_NORMALIZE) { + if (R.r.bake_flag & R_BAKE_NORMALIZE) { copy_v3_v3(shr.combined, shi->ao); } else { @@ -2055,27 +2055,27 @@ static void bake_shade(void *handle, Object *ob, ShadeInput *shi, int UNUSED(qua /* only do AO for a full bake (and obviously AO bakes) * AO for light bakes is a leftover and might not be needed */ - if( ELEM3(bs->type, RE_BAKE_ALL, RE_BAKE_AO, RE_BAKE_LIGHT)) + if ( ELEM3(bs->type, RE_BAKE_ALL, RE_BAKE_AO, RE_BAKE_LIGHT)) shade_samples_do_AO(ssamp); - if(shi->mat->nodetree && shi->mat->use_nodes) { + if (shi->mat->nodetree && shi->mat->use_nodes) { ntreeShaderExecTree(shi->mat->nodetree, shi, &shr); shi->mat= vlr->mat; /* shi->mat is being set in nodetree */ } else shade_material_loop(shi, &shr); - if(bs->type==RE_BAKE_NORMALS) { + if (bs->type==RE_BAKE_NORMALS) { float nor[3]; copy_v3_v3(nor, shi->vn); - if(R.r.bake_normal_space == R_BAKE_SPACE_CAMERA); - else if(R.r.bake_normal_space == R_BAKE_SPACE_TANGENT) { + if (R.r.bake_normal_space == R_BAKE_SPACE_CAMERA); + else if (R.r.bake_normal_space == R_BAKE_SPACE_TANGENT) { float mat[3][3], imat[3][3]; /* bitangent */ - if(tvn && ttang) { + if (tvn && ttang) { copy_v3_v3(mat[0], ttang); cross_v3_v3v3(mat[1], tvn, ttang); mul_v3_fl(mat[1], ttang[3]); @@ -2091,9 +2091,9 @@ static void bake_shade(void *handle, Object *ob, ShadeInput *shi, int UNUSED(qua invert_m3_m3(imat, mat); mul_m3_v3(imat, nor); } - else if(R.r.bake_normal_space == R_BAKE_SPACE_OBJECT) + else if (R.r.bake_normal_space == R_BAKE_SPACE_OBJECT) mul_mat3_m4_v3(ob->imat_ren, nor); /* ob->imat_ren includes viewinv! */ - else if(R.r.bake_normal_space == R_BAKE_SPACE_WORLD) + else if (R.r.bake_normal_space == R_BAKE_SPACE_WORLD) mul_mat3_m4_v3(R.viewinv, nor); normalize_v3(nor); /* in case object has scaling */ @@ -2108,47 +2108,47 @@ static void bake_shade(void *handle, Object *ob, ShadeInput *shi, int UNUSED(qua shr.combined[1]= nor[1]/2.0f + 0.5f; shr.combined[2]= nor[2]/2.0f + 0.5f; } - else if(bs->type==RE_BAKE_TEXTURE) { + else if (bs->type==RE_BAKE_TEXTURE) { shr.combined[0]= shi->r; shr.combined[1]= shi->g; shr.combined[2]= shi->b; shr.alpha = shi->alpha; } - else if(bs->type==RE_BAKE_SHADOW) { + else if (bs->type==RE_BAKE_SHADOW) { copy_v3_v3(shr.combined, shr.shad); shr.alpha = shi->alpha; } - else if(bs->type==RE_BAKE_SPEC_COLOR) { + else if (bs->type==RE_BAKE_SPEC_COLOR) { shr.combined[0]= shi->specr; shr.combined[1]= shi->specg; shr.combined[2]= shi->specb; shr.alpha = 1.0f; } - else if(bs->type==RE_BAKE_SPEC_INTENSITY) { + else if (bs->type==RE_BAKE_SPEC_INTENSITY) { shr.combined[0]= shr.combined[1]= shr.combined[2]= shi->spec; shr.alpha = 1.0f; } - else if(bs->type==RE_BAKE_MIRROR_COLOR) { + else if (bs->type==RE_BAKE_MIRROR_COLOR) { shr.combined[0]= shi->mirr; shr.combined[1]= shi->mirg; shr.combined[2]= shi->mirb; shr.alpha = 1.0f; } - else if(bs->type==RE_BAKE_MIRROR_INTENSITY) { + else if (bs->type==RE_BAKE_MIRROR_INTENSITY) { shr.combined[0]= shr.combined[1]= shr.combined[2]= shi->ray_mirror; shr.alpha = 1.0f; } - else if(bs->type==RE_BAKE_ALPHA) { + else if (bs->type==RE_BAKE_ALPHA) { shr.combined[0]= shr.combined[1]= shr.combined[2]= shi->alpha; shr.alpha = 1.0f; } - else if(bs->type==RE_BAKE_EMIT) { + else if (bs->type==RE_BAKE_EMIT) { shr.combined[0]= shr.combined[1]= shr.combined[2]= shi->emit; @@ -2156,12 +2156,13 @@ static void bake_shade(void *handle, Object *ob, ShadeInput *shi, int UNUSED(qua } } - if(bs->rect_float) { + if (bs->rect_float) { float *col= bs->rect_float + 4*(bs->rectx*y + x); copy_v3_v3(col, shr.combined); if (bs->type==RE_BAKE_ALL || bs->type==RE_BAKE_TEXTURE) { col[3]= shr.alpha; - } else { + } + else { col[3]= 1.0; } } @@ -2177,7 +2178,8 @@ static void bake_shade(void *handle, Object *ob, ShadeInput *shi, int UNUSED(qua if (ELEM(bs->type, RE_BAKE_ALL, RE_BAKE_TEXTURE)) { col[3]= FTOCHAR(shr.alpha); - } else { + } + else { col[3]= 255; } } @@ -2192,17 +2194,19 @@ static void bake_displacement(void *handle, ShadeInput *UNUSED(shi), float dist, BakeShade *bs= handle; float disp; - if(R.r.bake_flag & R_BAKE_NORMALIZE && R.r.bake_maxdist) { + if (R.r.bake_flag & R_BAKE_NORMALIZE && R.r.bake_maxdist) { disp = (dist+R.r.bake_maxdist) / (R.r.bake_maxdist*2); /* alter the range from [-bake_maxdist, bake_maxdist] to [0, 1]*/ - } else { + } + else { disp = 0.5f + dist; /* alter the range from [-0.5,0.5] to [0,1]*/ } - if(bs->rect_float) { + if (bs->rect_float) { float *col= bs->rect_float + 4*(bs->rectx*y + x); col[0] = col[1] = col[2] = disp; col[3]= 1.0f; - } else { + } + else { char *col= (char *)(bs->rect + bs->rectx*y + x); col[0] = col[1] = col[2] = FTOCHAR(disp); col[3]= 255; @@ -2218,7 +2222,7 @@ static int bake_intersect_tree(RayObject* raytree, Isect* isect, float *start, f int hit; /* might be useful to make a user setting for maxsize*/ - if(R.r.bake_maxdist > 0.0f) + if (R.r.bake_maxdist > 0.0f) maxdist= R.r.bake_maxdist; else maxdist= RE_RAYTRACE_MAXDIST + R.r.bake_biasdist; @@ -2231,7 +2235,7 @@ static int bake_intersect_tree(RayObject* raytree, Isect* isect, float *start, f isect->dist = maxdist; hit = RE_rayobject_raycast(raytree, isect); - if(hit) { + if (hit) { madd_v3_v3v3fl(hitco, isect->start, isect->dir, isect->dist); *dist= isect->dist; @@ -2245,7 +2249,7 @@ static void bake_set_vlr_dxyco(BakeShade *bs, float *uv1, float *uv2, float *uv3 VlakRen *vlr= bs->vlr; float A, d1, d2, d3, *v1, *v2, *v3; - if(bs->quad) { + if (bs->quad) { v1= vlr->v1->co; v2= vlr->v3->co; v3= vlr->v4->co; @@ -2261,7 +2265,7 @@ static void bake_set_vlr_dxyco(BakeShade *bs, float *uv1, float *uv2, float *uv3 * then taking u and v partial derivatives to get dxco and dyco */ A= (uv2[0] - uv1[0])*(uv3[1] - uv1[1]) - (uv3[0] - uv1[0])*(uv2[1] - uv1[1]); - if(fabsf(A) > FLT_EPSILON) { + if (fabsf(A) > FLT_EPSILON) { A= 0.5f/A; d1= uv2[1] - uv3[1]; @@ -2283,7 +2287,7 @@ static void bake_set_vlr_dxyco(BakeShade *bs, float *uv1, float *uv2, float *uv3 bs->dyco[0]= bs->dyco[1]= bs->dyco[2]= 0.0f; } - if(bs->obi->flag & R_TRANSFORMED) { + if (bs->obi->flag & R_TRANSFORMED) { mul_m3_v3(bs->obi->nmat, bs->dxco); mul_m3_v3(bs->obi->nmat, bs->dyco); } @@ -2301,11 +2305,11 @@ static void do_bake_shade(void *handle, int x, int y, float u, float v) ShadeInput *shi= ssamp->shi; /* fast threadsafe break test */ - if(R.test_break(R.tbh)) + if (R.test_break(R.tbh)) return; /* setup render coordinates */ - if(bs->quad) { + if (bs->quad) { v1= vlr->v1->co; v2= vlr->v3->co; v3= vlr->v4->co; @@ -2323,7 +2327,7 @@ static void do_bake_shade(void *handle, int x, int y, float u, float v) shi->co[1]= l*v3[1]+u*v1[1]+v*v2[1]; shi->co[2]= l*v3[2]+u*v1[2]+v*v2[2]; - if(obi->flag & R_TRANSFORMED) + if (obi->flag & R_TRANSFORMED) mul_m4_v3(obi->mat, shi->co); copy_v3_v3(shi->dxco, bs->dxco); @@ -2332,14 +2336,14 @@ static void do_bake_shade(void *handle, int x, int y, float u, float v) quad= bs->quad; bake_set_shade_input(obi, vlr, shi, quad, 0, x, y, u, v); - if(bs->type==RE_BAKE_NORMALS && R.r.bake_normal_space==R_BAKE_SPACE_TANGENT) { + if (bs->type==RE_BAKE_NORMALS && R.r.bake_normal_space==R_BAKE_SPACE_TANGENT) { shade_input_set_shade_texco(shi); copy_v3_v3(tvn, shi->nmapnorm); copy_v4_v4(ttang, shi->nmaptang); } /* if we are doing selected to active baking, find point on other face */ - if(bs->actob) { + if (bs->actob) { Isect isec, minisec; float co[3], minco[3], dist, mindist=0.0f; int hit, sign, dir=1; @@ -2351,7 +2355,7 @@ static void do_bake_shade(void *handle, int x, int y, float u, float v) copy_v3_v3(bs->dir, shi->vn); - for(sign=-1; sign<=1; sign+=2) { + for (sign=-1; sign<=1; sign+=2) { memset(&isec, 0, sizeof(isec)); isec.mode= RE_RAY_MIRROR; @@ -2361,8 +2365,8 @@ static void do_bake_shade(void *handle, int x, int y, float u, float v) isec.check = RE_CHECK_VLR_BAKE; isec.skip = RE_SKIP_VLR_NEIGHBOUR; - if(bake_intersect_tree(R.raytree, &isec, shi->co, shi->vn, sign, co, &dist)) { - if(!hit || len_squared_v3v3(shi->co, co) < len_squared_v3v3(shi->co, minco)) { + if (bake_intersect_tree(R.raytree, &isec, shi->co, shi->vn, sign, co, &dist)) { + if (!hit || len_squared_v3v3(shi->co, co) < len_squared_v3v3(shi->co, minco)) { minisec= isec; mindist= dist; copy_v3_v3(minco, co); @@ -2373,7 +2377,7 @@ static void do_bake_shade(void *handle, int x, int y, float u, float v) } if (bs->type==RE_BAKE_DISPLACEMENT) { - if(hit) + if (hit) bake_displacement(handle, shi, (dir==-1)? mindist:-mindist, x, y); else bake_displacement(handle, shi, 0.0f, x, y); @@ -2381,7 +2385,7 @@ static void do_bake_shade(void *handle, int x, int y, float u, float v) } /* if hit, we shade from the new point, otherwise from point one starting face */ - if(hit) { + if (hit) { obi= (ObjectInstanceRen*)minisec.hit.ob; vlr= (VlakRen*)minisec.hit.face; quad= (minisec.isect == 2); @@ -2393,7 +2397,7 @@ static void do_bake_shade(void *handle, int x, int y, float u, float v) } } - if(bs->type==RE_BAKE_NORMALS && R.r.bake_normal_space==R_BAKE_SPACE_TANGENT) + if (bs->type==RE_BAKE_NORMALS && R.r.bake_normal_space==R_BAKE_SPACE_TANGENT) bake_shade(handle, ob, shi, quad, x, y, u, v, tvn, ttang); else bake_shade(handle, ob, shi, quad, x, y, u, v, 0, 0); @@ -2407,7 +2411,7 @@ static int get_next_bake_face(BakeShade *bs) static int v= 0, vdone= 0; static ObjectInstanceRen *obi= NULL; - if(bs==NULL) { + if (bs==NULL) { vlr= NULL; v= vdone= 0; obi= R.instancetable.first; @@ -2416,44 +2420,44 @@ static int get_next_bake_face(BakeShade *bs) BLI_lock_thread(LOCK_CUSTOM1); - for(; obi; obi=obi->next, v=0) { + for (; obi; obi=obi->next, v=0) { obr= obi->obr; - for(; v<obr->totvlak; v++) { + for (; v<obr->totvlak; v++) { vlr= RE_findOrAddVlak(obr, v); - if((bs->actob && bs->actob == obr->ob) || (!bs->actob && (obr->ob->flag & SELECT))) { + if ((bs->actob && bs->actob == obr->ob) || (!bs->actob && (obr->ob->flag & SELECT))) { tface= RE_vlakren_get_tface(obr, vlr, obr->bakemtface, NULL, 0); - if(tface && tface->tpage) { + if (tface && tface->tpage) { Image *ima= tface->tpage; ImBuf *ibuf= BKE_image_get_ibuf(ima, NULL); const float vec_alpha[4]= {0.0f, 0.0f, 0.0f, 0.0f}; const float vec_solid[4]= {0.0f, 0.0f, 0.0f, 1.0f}; - if(ibuf==NULL) + if (ibuf==NULL) continue; - if(ibuf->rect==NULL && ibuf->rect_float==NULL) + if (ibuf->rect==NULL && ibuf->rect_float==NULL) continue; - if(ibuf->rect_float && !(ibuf->channels==0 || ibuf->channels==4)) + if (ibuf->rect_float && !(ibuf->channels==0 || ibuf->channels==4)) continue; - if(ima->flag & IMA_USED_FOR_RENDER) { + if (ima->flag & IMA_USED_FOR_RENDER) { ima->id.flag &= ~LIB_DOIT; continue; } /* find the image for the first time? */ - if(ima->id.flag & LIB_DOIT) { + if (ima->id.flag & LIB_DOIT) { ima->id.flag &= ~LIB_DOIT; /* we either fill in float or char, this ensures things go fine */ - if(ibuf->rect_float) + if (ibuf->rect_float) imb_freerectImBuf(ibuf); /* clear image */ - if(R.r.bake_flag & R_BAKE_CLEAR) + if (R.r.bake_flag & R_BAKE_CLEAR) IMB_rectfill(ibuf, (ibuf->planes == R_IMF_PLANES_RGBA) ? vec_alpha : vec_solid); /* might be read by UI to set active image for display */ @@ -2489,7 +2493,7 @@ static void shade_tface(BakeShade *bs) int a, i1, i2, i3; /* check valid zspan */ - if(ima!=bs->ima) { + if (ima!=bs->ima) { bs->ima= ima; bs->ibuf= BKE_image_get_ibuf(ima, NULL); /* note, these calls only free/fill contents of zspan struct, not zspan itself */ @@ -2510,13 +2514,14 @@ static void shade_tface(BakeShade *bs) bs->ibuf->userdata = (void *)MEM_callocN(sizeof(char)*bs->rectx*bs->recty, "BakeMask"); bs->rect_mask= (char *)bs->ibuf->userdata; BLI_unlock_thread(LOCK_CUSTOM1); - } else { + } + else { bs->rect_mask= (char *)bs->ibuf->userdata; } } /* get pixel level vertex coordinates */ - for(a=0; a<4; a++) { + for (a=0; a<4; a++) { /* Note, workaround for pixel aligned UVs which are common and can screw up our intersection tests * where a pixel gets in between 2 faces or the middle of a quad, * camera aligned quads also have this problem but they are less common. @@ -2531,7 +2536,7 @@ static void shade_tface(BakeShade *bs) bake_set_vlr_dxyco(bs, vec[i1], vec[i2], vec[i3]); zspan_scanconvert(bs->zspan, bs, vec[i1], vec[i2], vec[i3], do_bake_shade); - if(vlr->v4) { + if (vlr->v4) { bs->quad= 1; bake_set_vlr_dxyco(bs, vec[0], vec[2], vec[3]); zspan_scanconvert(bs->zspan, bs, vec[0], vec[2], vec[3], do_bake_shade); @@ -2542,16 +2547,16 @@ static void *do_bake_thread(void *bs_v) { BakeShade *bs= bs_v; - while(get_next_bake_face(bs)) { + while (get_next_bake_face(bs)) { shade_tface(bs); /* fast threadsafe break test */ - if(R.test_break(R.tbh)) + if (R.test_break(R.tbh)) break; /* access is not threadsafe but since its just true/false probably ok * only used for interactive baking */ - if(bs->do_update) + if (bs->do_update) *bs->do_update= TRUE; } bs->ready= 1; @@ -2565,16 +2570,16 @@ void RE_bake_ibuf_filter(ImBuf *ibuf, char *mask, const int filter) const short is_new_alpha= (ibuf->planes != R_IMF_PLANES_RGBA) && BKE_alphatest_ibuf(ibuf); /* Margin */ - if(filter) { + if (filter) { IMB_filter_extend(ibuf, mask, filter); } /* if the bake results in new alpha then change the image setting */ - if(is_new_alpha) { + if (is_new_alpha) { ibuf->planes= R_IMF_PLANES_RGBA; } else { - if(filter && ibuf->planes != R_IMF_PLANES_RGBA) { + if (filter && ibuf->planes != R_IMF_PLANES_RGBA) { /* clear alpha added by filtering */ IMB_rectfill_alpha(ibuf, 1.0f); } @@ -2603,13 +2608,13 @@ int RE_bake_shade_all_selected(Render *re, int type, Object *actob, short *do_up usemask = 1; /* baker uses this flag to detect if image was initialized */ - for(ima= G.main->image.first; ima; ima= ima->id.next) { + for (ima= G.main->image.first; ima; ima= ima->id.next) { ImBuf *ibuf= BKE_image_get_ibuf(ima, NULL); ima->id.flag |= LIB_DOIT; ima->flag&= ~IMA_USED_FOR_RENDER; - if(ibuf) { + if (ibuf) { ibuf->userdata = NULL; /* use for masking if needed */ - if(ibuf->rect_float) + if (ibuf->rect_float) ibuf->profile = IB_PROFILE_LINEAR_RGB; } } @@ -2619,13 +2624,14 @@ int RE_bake_shade_all_selected(Render *re, int type, Object *actob, short *do_up handles= MEM_callocN(sizeof(BakeShade)*re->r.threads, "BakeShade"); /* get the threads running */ - for(a=0; a<re->r.threads; a++) { + for (a=0; a<re->r.threads; a++) { /* set defaults in handles */ handles[a].ssamp.shi[0].lay= re->lay; if (type==RE_BAKE_SHADOW) { handles[a].ssamp.shi[0].passflag= SCE_PASS_SHADOW; - } else { + } + else { handles[a].ssamp.shi[0].passflag= SCE_PASS_COMBINED; } handles[a].ssamp.shi[0].combinedflag= ~(SCE_PASS_SPEC); @@ -2645,30 +2651,30 @@ int RE_bake_shade_all_selected(Render *re, int type, Object *actob, short *do_up /* wait for everything to be done */ a= 0; - while(a!=re->r.threads) { + while (a!=re->r.threads) { PIL_sleep_ms(50); /* calculate progress */ - for(vdone=0, a=0; a<re->r.threads; a++) + for (vdone=0, a=0; a<re->r.threads; a++) vdone+= handles[a].vdone; if (progress) *progress = (float)(vdone / (float)re->totvlak); - for(a=0; a<re->r.threads; a++) { - if(handles[a].ready==0) + for (a=0; a<re->r.threads; a++) { + if (handles[a].ready==0) break; } } /* filter and refresh images */ - for(ima= G.main->image.first; ima; ima= ima->id.next) { - if((ima->id.flag & LIB_DOIT)==0) { + for (ima= G.main->image.first; ima; ima= ima->id.next) { + if ((ima->id.flag & LIB_DOIT)==0) { ImBuf *ibuf= BKE_image_get_ibuf(ima, NULL); - if(ima->flag & IMA_USED_FOR_RENDER) + if (ima->flag & IMA_USED_FOR_RENDER) result= BAKE_RESULT_FEEDBACK_LOOP; - if(!ibuf) + if (!ibuf) continue; RE_bake_ibuf_filter(ibuf, (char *)ibuf->userdata, re->r.bake_filter); @@ -2679,7 +2685,7 @@ int RE_bake_shade_all_selected(Render *re, int type, Object *actob, short *do_up } /* calculate return value */ - for(a=0; a<re->r.threads; a++) { + for (a=0; a<re->r.threads; a++) { zbuf_free_span(handles[a].zspan); MEM_freeN(handles[a].zspan); } @@ -2688,7 +2694,7 @@ int RE_bake_shade_all_selected(Render *re, int type, Object *actob, short *do_up BLI_end_threads(&threads); - if(vdone==0) + if (vdone==0) result= BAKE_RESULT_NO_OBJECTS; return result; diff --git a/source/blender/render/intern/source/renderdatabase.c b/source/blender/render/intern/source/renderdatabase.c index 81e8b5d73fe..f28931f7b16 100644 --- a/source/blender/render/intern/source/renderdatabase.c +++ b/source/blender/render/intern/source/renderdatabase.c @@ -120,8 +120,8 @@ float *RE_vertren_get_sticky(ObjectRen *obr, VertRen *ver, int verify) int nr= ver->index>>8; sticky= obr->vertnodes[nr].sticky; - if(sticky==NULL) { - if(verify) + if (sticky==NULL) { + if (verify) sticky= obr->vertnodes[nr].sticky= MEM_mallocN(256*RE_STICKY_ELEMS*sizeof(float), "sticky table"); else return NULL; @@ -135,8 +135,8 @@ float *RE_vertren_get_stress(ObjectRen *obr, VertRen *ver, int verify) int nr= ver->index>>8; stress= obr->vertnodes[nr].stress; - if(stress==NULL) { - if(verify) + if (stress==NULL) { + if (verify) stress= obr->vertnodes[nr].stress= MEM_mallocN(256*RE_STRESS_ELEMS*sizeof(float), "stress table"); else return NULL; @@ -151,8 +151,8 @@ float *RE_vertren_get_rad(ObjectRen *obr, VertRen *ver, int verify) int nr= ver->index>>8; rad= obr->vertnodes[nr].rad; - if(rad==NULL) { - if(verify) + if (rad==NULL) { + if (verify) rad= obr->vertnodes[nr].rad= MEM_callocN(256*RE_RAD_ELEMS*sizeof(float), "rad table"); else return NULL; @@ -166,8 +166,8 @@ float *RE_vertren_get_strand(ObjectRen *obr, VertRen *ver, int verify) int nr= ver->index>>8; strand= obr->vertnodes[nr].strand; - if(strand==NULL) { - if(verify) + if (strand==NULL) { + if (verify) strand= obr->vertnodes[nr].strand= MEM_mallocN(256*RE_STRAND_ELEMS*sizeof(float), "strand table"); else return NULL; @@ -182,8 +182,8 @@ float *RE_vertren_get_tangent(ObjectRen *obr, VertRen *ver, int verify) int nr= ver->index>>8; tangent= obr->vertnodes[nr].tangent; - if(tangent==NULL) { - if(verify) + if (tangent==NULL) { + if (verify) tangent= obr->vertnodes[nr].tangent= MEM_callocN(256*RE_TANGENT_ELEMS*sizeof(float), "tangent table"); else return NULL; @@ -199,8 +199,8 @@ float *RE_vertren_get_winspeed(ObjectInstanceRen *obi, VertRen *ver, int verify) int totvector; winspeed= obi->vectors; - if(winspeed==NULL) { - if(verify) { + if (winspeed==NULL) { + if (verify) { totvector= obi->obr->totvert + obi->obr->totstrand; winspeed= obi->vectors= MEM_callocN(totvector*RE_WINSPEED_ELEMS*sizeof(float), "winspeed table"); } @@ -220,27 +220,27 @@ VertRen *RE_vertren_copy(ObjectRen *obr, VertRen *ver) v1->index= index; fp1= RE_vertren_get_sticky(obr, ver, 0); - if(fp1) { + if (fp1) { fp2= RE_vertren_get_sticky(obr, v1, 1); memcpy(fp2, fp1, RE_STICKY_ELEMS*sizeof(float)); } fp1= RE_vertren_get_stress(obr, ver, 0); - if(fp1) { + if (fp1) { fp2= RE_vertren_get_stress(obr, v1, 1); memcpy(fp2, fp1, RE_STRESS_ELEMS*sizeof(float)); } fp1= RE_vertren_get_rad(obr, ver, 0); - if(fp1) { + if (fp1) { fp2= RE_vertren_get_rad(obr, v1, 1); memcpy(fp2, fp1, RE_RAD_ELEMS*sizeof(float)); } fp1= RE_vertren_get_strand(obr, ver, 0); - if(fp1) { + if (fp1) { fp2= RE_vertren_get_strand(obr, v1, 1); memcpy(fp2, fp1, RE_STRAND_ELEMS*sizeof(float)); } fp1= RE_vertren_get_tangent(obr, ver, 0); - if(fp1) { + if (fp1) { fp2= RE_vertren_get_tangent(obr, v1, 1); memcpy(fp2, fp1, RE_TANGENT_ELEMS*sizeof(float)); } @@ -253,7 +253,7 @@ VertRen *RE_findOrAddVert(ObjectRen *obr, int nr) VertRen *v; int a; - if(nr<0) { + if (nr<0) { printf("error in findOrAddVert: %d\n",nr); return NULL; } @@ -263,21 +263,21 @@ VertRen *RE_findOrAddVert(ObjectRen *obr, int nr) temp= obr->vertnodes; obr->vertnodes= MEM_mallocN(sizeof(VertTableNode)*(obr->vertnodeslen+TABLEINITSIZE) , "vertnodes"); - if(temp) memcpy(obr->vertnodes, temp, obr->vertnodeslen*sizeof(VertTableNode)); + if (temp) memcpy(obr->vertnodes, temp, obr->vertnodeslen*sizeof(VertTableNode)); memset(obr->vertnodes+obr->vertnodeslen, 0, TABLEINITSIZE*sizeof(VertTableNode)); obr->vertnodeslen+=TABLEINITSIZE; - if(temp) MEM_freeN(temp); + if (temp) MEM_freeN(temp); } v= obr->vertnodes[a].vert; - if(v==NULL) { + if (v==NULL) { int i; v= (VertRen *)MEM_callocN(256*sizeof(VertRen),"findOrAddVert"); obr->vertnodes[a].vert= v; - for(i= (nr & 0xFFFFFF00), a=0; a<256; a++, i++) { + for (i= (nr & 0xFFFFFF00), a=0; a<256; a++, i++) { v[a].index= i; } } @@ -295,14 +295,14 @@ MTFace *RE_vlakren_get_tface(ObjectRen *obr, VlakRen *vlr, int n, char **name, i node= &obr->vlaknodes[nr]; - if(verify) { - if(n>=node->totmtface) { + if (verify) { + if (n>=node->totmtface) { MTFace *mtface= node->mtface; int size= (n+1)*256; node->mtface= MEM_callocN(size*sizeof(MTFace), "Vlak mtface"); - if(mtface) { + if (mtface) { size= node->totmtface*256; memcpy(node->mtface, mtface, size*sizeof(MTFace)); MEM_freeN(mtface); @@ -312,10 +312,10 @@ MTFace *RE_vlakren_get_tface(ObjectRen *obr, VlakRen *vlr, int n, char **name, i } } else { - if(n>=node->totmtface) + if (n>=node->totmtface) return NULL; - if(name) *name= obr->mtface[n]; + if (name) *name= obr->mtface[n]; } return node->mtface + index; @@ -329,14 +329,14 @@ MCol *RE_vlakren_get_mcol(ObjectRen *obr, VlakRen *vlr, int n, char **name, int node= &obr->vlaknodes[nr]; - if(verify) { - if(n>=node->totmcol) { + if (verify) { + if (n>=node->totmcol) { MCol *mcol= node->mcol; int size= (n+1)*256; node->mcol= MEM_callocN(size*sizeof(MCol)*RE_MCOL_ELEMS, "Vlak mcol"); - if(mcol) { + if (mcol) { size= node->totmcol*256; memcpy(node->mcol, mcol, size*sizeof(MCol)*RE_MCOL_ELEMS); MEM_freeN(mcol); @@ -346,10 +346,10 @@ MCol *RE_vlakren_get_mcol(ObjectRen *obr, VlakRen *vlr, int n, char **name, int } } else { - if(n>=node->totmcol) + if (n>=node->totmcol) return NULL; - if(name) *name= obr->mcol[n]; + if (name) *name= obr->mcol[n]; } return node->mcol + index*RE_MCOL_ELEMS; @@ -361,8 +361,8 @@ float *RE_vlakren_get_surfnor(ObjectRen *obr, VlakRen *vlak, int verify) int nr= vlak->index>>8; surfnor= obr->vlaknodes[nr].surfnor; - if(surfnor==NULL) { - if(verify) + if (surfnor==NULL) { + if (verify) surfnor= obr->vlaknodes[nr].surfnor= MEM_callocN(256*RE_SURFNOR_ELEMS*sizeof(float), "surfnor table"); else return NULL; @@ -376,8 +376,8 @@ float *RE_vlakren_get_nmap_tangent(ObjectRen *obr, VlakRen *vlak, int verify) int nr= vlak->index>>8; tangent= obr->vlaknodes[nr].tangent; - if(tangent==NULL) { - if(verify) + if (tangent==NULL) { + if (verify) tangent= obr->vlaknodes[nr].tangent= MEM_callocN(256*RE_NMAP_TANGENT_ELEMS*sizeof(float), "tangent table"); else return NULL; @@ -391,8 +391,8 @@ RadFace **RE_vlakren_get_radface(ObjectRen *obr, VlakRen *vlak, int verify) int nr= vlak->index>>8; radface= obr->vlaknodes[nr].radface; - if(radface==NULL) { - if(verify) + if (radface==NULL) { + if (verify) radface= obr->vlaknodes[nr].radface= MEM_callocN(256*RE_RADFACE_ELEMS*sizeof(void*), "radface table"); else return NULL; @@ -424,19 +424,19 @@ VlakRen *RE_vlakren_copy(ObjectRen *obr, VlakRen *vlr) } surfnor= RE_vlakren_get_surfnor(obr, vlr, 0); - if(surfnor) { + if (surfnor) { surfnor1= RE_vlakren_get_surfnor(obr, vlr1, 1); copy_v3_v3(surfnor1, surfnor); } tangent= RE_vlakren_get_nmap_tangent(obr, vlr, 0); - if(tangent) { + if (tangent) { tangent1= RE_vlakren_get_nmap_tangent(obr, vlr1, 1); memcpy(tangent1, tangent, sizeof(float)*RE_NMAP_TANGENT_ELEMS); } radface= RE_vlakren_get_radface(obr, vlr, 0); - if(radface) { + if (radface) { radface1= RE_vlakren_get_radface(obr, vlr1, 1); *radface1= *radface; } @@ -448,7 +448,7 @@ void RE_vlakren_get_normal(Render *UNUSED(re), ObjectInstanceRen *obi, VlakRen * { float (*nmat)[3]= obi->nmat; - if(obi->flag & R_TRANSFORMED) { + if (obi->flag & R_TRANSFORMED) { mul_v3_m3v3(nor, nmat, vlr->n); normalize_v3(nor); } @@ -496,32 +496,32 @@ VlakRen *RE_findOrAddVlak(ObjectRen *obr, int nr) VlakRen *v; int a; - if(nr<0) { + if (nr<0) { printf("error in findOrAddVlak: %d\n",nr); return obr->vlaknodes[0].vlak; } a= nr>>8; - if (a>=obr->vlaknodeslen-1){ /* Need to allocate more columns..., and keep last element NULL for free loop */ + if (a>=obr->vlaknodeslen-1) { /* Need to allocate more columns..., and keep last element NULL for free loop */ temp= obr->vlaknodes; obr->vlaknodes= MEM_mallocN(sizeof(VlakTableNode)*(obr->vlaknodeslen+TABLEINITSIZE) , "vlaknodes"); - if(temp) memcpy(obr->vlaknodes, temp, obr->vlaknodeslen*sizeof(VlakTableNode)); + if (temp) memcpy(obr->vlaknodes, temp, obr->vlaknodeslen*sizeof(VlakTableNode)); memset(obr->vlaknodes+obr->vlaknodeslen, 0, TABLEINITSIZE*sizeof(VlakTableNode)); obr->vlaknodeslen+=TABLEINITSIZE; /*Does this really need to be power of 2?*/ - if(temp) MEM_freeN(temp); + if (temp) MEM_freeN(temp); } v= obr->vlaknodes[a].vlak; - if(v==NULL) { + if (v==NULL) { int i; v= (VlakRen *)MEM_callocN(256*sizeof(VlakRen),"findOrAddVlak"); obr->vlaknodes[a].vlak= v; - for(i= (nr & 0xFFFFFF00), a=0; a<256; a++, i++) + for (i= (nr & 0xFFFFFF00), a=0; a<256; a++, i++) v[a].index= i; } v+= (nr & 255); @@ -536,8 +536,8 @@ float *RE_strandren_get_surfnor(ObjectRen *obr, StrandRen *strand, int verify) int nr= strand->index>>8; surfnor= obr->strandnodes[nr].surfnor; - if(surfnor==NULL) { - if(verify) + if (surfnor==NULL) { + if (verify) surfnor= obr->strandnodes[nr].surfnor= MEM_callocN(256*RE_SURFNOR_ELEMS*sizeof(float), "surfnor strand table"); else return NULL; @@ -553,14 +553,14 @@ float *RE_strandren_get_uv(ObjectRen *obr, StrandRen *strand, int n, char **name node= &obr->strandnodes[nr]; - if(verify) { - if(n>=node->totuv) { + if (verify) { + if (n>=node->totuv) { float *uv= node->uv; int size= (n+1)*256; node->uv= MEM_callocN(size*sizeof(float)*RE_UV_ELEMS, "strand uv table"); - if(uv) { + if (uv) { size= node->totuv*256; memcpy(node->uv, uv, size*sizeof(float)*RE_UV_ELEMS); MEM_freeN(uv); @@ -570,10 +570,10 @@ float *RE_strandren_get_uv(ObjectRen *obr, StrandRen *strand, int n, char **name } } else { - if(n>=node->totuv) + if (n>=node->totuv) return NULL; - if(name) *name= obr->mtface[n]; + if (name) *name= obr->mtface[n]; } return node->uv + index*RE_UV_ELEMS; @@ -587,14 +587,14 @@ MCol *RE_strandren_get_mcol(ObjectRen *obr, StrandRen *strand, int n, char **nam node= &obr->strandnodes[nr]; - if(verify) { - if(n>=node->totmcol) { + if (verify) { + if (n>=node->totmcol) { MCol *mcol= node->mcol; int size= (n+1)*256; node->mcol= MEM_callocN(size*sizeof(MCol)*RE_MCOL_ELEMS, "strand mcol table"); - if(mcol) { + if (mcol) { size= node->totmcol*256; memcpy(node->mcol, mcol, size*sizeof(MCol)*RE_MCOL_ELEMS); MEM_freeN(mcol); @@ -604,10 +604,10 @@ MCol *RE_strandren_get_mcol(ObjectRen *obr, StrandRen *strand, int n, char **nam } } else { - if(n>=node->totmcol) + if (n>=node->totmcol) return NULL; - if(name) *name= obr->mcol[n]; + if (name) *name= obr->mcol[n]; } return node->mcol + index*RE_MCOL_ELEMS; @@ -619,8 +619,8 @@ float *RE_strandren_get_simplify(struct ObjectRen *obr, struct StrandRen *strand int nr= strand->index>>8; simplify= obr->strandnodes[nr].simplify; - if(simplify==NULL) { - if(verify) + if (simplify==NULL) { + if (verify) simplify= obr->strandnodes[nr].simplify= MEM_callocN(256*RE_SIMPLIFY_ELEMS*sizeof(float), "simplify strand table"); else return NULL; @@ -634,8 +634,8 @@ int *RE_strandren_get_face(ObjectRen *obr, StrandRen *strand, int verify) int nr= strand->index>>8; face= obr->strandnodes[nr].face; - if(face==NULL) { - if(verify) + if (face==NULL) { + if (verify) face= obr->strandnodes[nr].face= MEM_callocN(256*RE_FACE_ELEMS*sizeof(int), "face strand table"); else return NULL; @@ -650,8 +650,8 @@ float *RE_strandren_get_winspeed(ObjectInstanceRen *obi, StrandRen *strand, int int totvector; winspeed= obi->vectors; - if(winspeed==NULL) { - if(verify) { + if (winspeed==NULL) { + if (verify) { totvector= obi->obr->totvert + obi->obr->totstrand; winspeed= obi->vectors= MEM_callocN(totvector*RE_WINSPEED_ELEMS*sizeof(float), "winspeed strand table"); } @@ -667,32 +667,32 @@ StrandRen *RE_findOrAddStrand(ObjectRen *obr, int nr) StrandRen *v; int a; - if(nr<0) { + if (nr<0) { printf("error in findOrAddStrand: %d\n",nr); return obr->strandnodes[0].strand; } a= nr>>8; - if (a>=obr->strandnodeslen-1){ /* Need to allocate more columns..., and keep last element NULL for free loop */ + if (a>=obr->strandnodeslen-1) { /* Need to allocate more columns..., and keep last element NULL for free loop */ temp= obr->strandnodes; obr->strandnodes= MEM_mallocN(sizeof(StrandTableNode)*(obr->strandnodeslen+TABLEINITSIZE) , "strandnodes"); - if(temp) memcpy(obr->strandnodes, temp, obr->strandnodeslen*sizeof(StrandTableNode)); + if (temp) memcpy(obr->strandnodes, temp, obr->strandnodeslen*sizeof(StrandTableNode)); memset(obr->strandnodes+obr->strandnodeslen, 0, TABLEINITSIZE*sizeof(StrandTableNode)); obr->strandnodeslen+=TABLEINITSIZE; /*Does this really need to be power of 2?*/ - if(temp) MEM_freeN(temp); + if (temp) MEM_freeN(temp); } v= obr->strandnodes[a].strand; - if(v==NULL) { + if (v==NULL) { int i; v= (StrandRen *)MEM_callocN(256*sizeof(StrandRen),"findOrAddStrand"); obr->strandnodes[a].strand= v; - for(i= (nr & 0xFFFFFF00), a=0; a<256; a++, i++) + for (i= (nr & 0xFFFFFF00), a=0; a<256; a++, i++) v[a].index= i; } v+= (nr & 255); @@ -733,22 +733,22 @@ void free_renderdata_vertnodes(VertTableNode *vertnodes) { int a; - if(vertnodes==NULL) return; + if (vertnodes==NULL) return; - for(a=0; vertnodes[a].vert; a++) { + for (a=0; vertnodes[a].vert; a++) { MEM_freeN(vertnodes[a].vert); - if(vertnodes[a].rad) + if (vertnodes[a].rad) MEM_freeN(vertnodes[a].rad); - if(vertnodes[a].sticky) + if (vertnodes[a].sticky) MEM_freeN(vertnodes[a].sticky); - if(vertnodes[a].strand) + if (vertnodes[a].strand) MEM_freeN(vertnodes[a].strand); - if(vertnodes[a].tangent) + if (vertnodes[a].tangent) MEM_freeN(vertnodes[a].tangent); - if(vertnodes[a].stress) + if (vertnodes[a].stress) MEM_freeN(vertnodes[a].stress); - if(vertnodes[a].winspeed) + if (vertnodes[a].winspeed) MEM_freeN(vertnodes[a].winspeed); } @@ -759,20 +759,20 @@ void free_renderdata_vlaknodes(VlakTableNode *vlaknodes) { int a; - if(vlaknodes==NULL) return; + if (vlaknodes==NULL) return; - for(a=0; vlaknodes[a].vlak; a++) { + for (a=0; vlaknodes[a].vlak; a++) { MEM_freeN(vlaknodes[a].vlak); - if(vlaknodes[a].mtface) + if (vlaknodes[a].mtface) MEM_freeN(vlaknodes[a].mtface); - if(vlaknodes[a].mcol) + if (vlaknodes[a].mcol) MEM_freeN(vlaknodes[a].mcol); - if(vlaknodes[a].surfnor) + if (vlaknodes[a].surfnor) MEM_freeN(vlaknodes[a].surfnor); - if(vlaknodes[a].tangent) + if (vlaknodes[a].tangent) MEM_freeN(vlaknodes[a].tangent); - if(vlaknodes[a].radface) + if (vlaknodes[a].radface) MEM_freeN(vlaknodes[a].radface); } @@ -783,22 +783,22 @@ static void free_renderdata_strandnodes(StrandTableNode *strandnodes) { int a; - if(strandnodes==NULL) return; + if (strandnodes==NULL) return; - for(a=0; strandnodes[a].strand; a++) { + for (a=0; strandnodes[a].strand; a++) { MEM_freeN(strandnodes[a].strand); - if(strandnodes[a].uv) + if (strandnodes[a].uv) MEM_freeN(strandnodes[a].uv); - if(strandnodes[a].mcol) + if (strandnodes[a].mcol) MEM_freeN(strandnodes[a].mcol); - if(strandnodes[a].winspeed) + if (strandnodes[a].winspeed) MEM_freeN(strandnodes[a].winspeed); - if(strandnodes[a].surfnor) + if (strandnodes[a].surfnor) MEM_freeN(strandnodes[a].surfnor); - if(strandnodes[a].simplify) + if (strandnodes[a].simplify) MEM_freeN(strandnodes[a].simplify); - if(strandnodes[a].face) + if (strandnodes[a].face) MEM_freeN(strandnodes[a].face); } @@ -812,7 +812,7 @@ void free_renderdata_tables(Render *re) StrandBuffer *strandbuf; int a=0; - for(obr=re->objecttable.first; obr; obr=obr->next) { + for (obr=re->objecttable.first; obr; obr=obr->next) { if (obr->vertnodes) { free_renderdata_vertnodes(obr->vertnodes); obr->vertnodes= NULL; @@ -827,7 +827,7 @@ void free_renderdata_tables(Render *re) } if (obr->bloha) { - for(a=0; obr->bloha[a]; a++) + for (a=0; obr->bloha[a]; a++) MEM_freeN(obr->bloha[a]); MEM_freeN(obr->bloha); @@ -842,9 +842,9 @@ void free_renderdata_tables(Render *re) } strandbuf= obr->strandbuf; - if(strandbuf) { - if(strandbuf->vert) MEM_freeN(strandbuf->vert); - if(strandbuf->bound) MEM_freeN(strandbuf->bound); + if (strandbuf) { + if (strandbuf->vert) MEM_freeN(strandbuf->vert); + if (strandbuf->bound) MEM_freeN(strandbuf->bound); MEM_freeN(strandbuf); } @@ -870,13 +870,13 @@ void free_renderdata_tables(Render *re) } } - if(re->objectinstance) { - for(obi=re->instancetable.first; obi; obi=obi->next) + if (re->objectinstance) { + for (obi=re->instancetable.first; obi; obi=obi->next) { - if(obi->vectors) + if (obi->vectors) MEM_freeN(obi->vectors); - if(obi->raytree) + if (obi->raytree) RE_rayobject_free(obi->raytree); } @@ -886,7 +886,7 @@ void free_renderdata_tables(Render *re) re->instancetable.first= re->instancetable.last= NULL; } - if(re->sortedhalos) { + if (re->sortedhalos) { MEM_freeN(re->sortedhalos); re->sortedhalos= NULL; } @@ -903,26 +903,26 @@ HaloRen *RE_findOrAddHalo(ObjectRen *obr, int nr) HaloRen *h, **temp; int a; - if(nr<0) { + if (nr<0) { printf("error in findOrAddHalo: %d\n",nr); return NULL; } a= nr>>8; - if (a>=obr->blohalen-1){ /* Need to allocate more columns..., and keep last element NULL for free loop */ + if (a>=obr->blohalen-1) { /* Need to allocate more columns..., and keep last element NULL for free loop */ //printf("Allocating %i more halo groups. %i total.\n", // TABLEINITSIZE, obr->blohalen+TABLEINITSIZE ); temp=obr->bloha; obr->bloha=(HaloRen**)MEM_callocN(sizeof(void*)*(obr->blohalen+TABLEINITSIZE) , "Bloha"); - if(temp) memcpy(obr->bloha, temp, obr->blohalen*sizeof(void*)); + if (temp) memcpy(obr->bloha, temp, obr->blohalen*sizeof(void*)); memset(&(obr->bloha[obr->blohalen]), 0, TABLEINITSIZE*sizeof(void*)); obr->blohalen+=TABLEINITSIZE; /*Does this really need to be power of 2?*/ - if(temp) MEM_freeN(temp); + if (temp) MEM_freeN(temp); } h= obr->bloha[a]; - if(h==NULL) { + if (h==NULL) { h= (HaloRen *)MEM_callocN(256*sizeof(HaloRen),"findOrAdHalo"); obr->bloha[a]= h; } @@ -940,13 +940,13 @@ HaloRen *RE_inithalo(Render *re, ObjectRen *obr, Material *ma, float *vec, f float tin, tr, tg, tb, ta; float xn, yn, zn, texvec[3], hoco[4], hoco1[4]; - if(hasize==0.0f) return NULL; + if (hasize==0.0f) return NULL; projectverto(vec, re->winmat, hoco); - if(hoco[3]==0.0f) return NULL; - if(vec1) { + if (hoco[3]==0.0f) return NULL; + if (vec1) { projectverto(vec1, re->winmat, hoco1); - if(hoco1[3]==0.0f) return NULL; + if (hoco1[3]==0.0f) return NULL; } har= RE_findOrAddHalo(obr, obr->tothalo++); @@ -963,13 +963,13 @@ HaloRen *RE_inithalo(Render *re, ObjectRen *obr, Material *ma, float *vec, f har->zBufDist = 0x7FFFFFFF*(hoco[2]/zn); /* halovect */ - if(vec1) { + if (vec1) { har->type |= HA_VECT; xn= har->xs - 0.5f*re->winx*(hoco1[0]/hoco1[3]); yn= har->ys - 0.5f*re->winy*(hoco1[1]/hoco1[3]); - if(xn==0.0f || (xn==0.0f && yn==0.0f)) zn= 0.0f; + if (xn==0.0f || (xn==0.0f && yn==0.0f)) zn= 0.0f; else zn= atan2(yn, xn); har->sin= sin(zn); @@ -982,7 +982,7 @@ HaloRen *RE_inithalo(Render *re, ObjectRen *obr, Material *ma, float *vec, f normalize_v3(har->no); } - if(ma->mode & MA_HALO_XALPHA) har->type |= HA_XALPHA; + if (ma->mode & MA_HALO_XALPHA) har->type |= HA_XALPHA; har->alfa= ma->alpha; har->r= ma->r; @@ -993,32 +993,32 @@ HaloRen *RE_inithalo(Render *re, ObjectRen *obr, Material *ma, float *vec, f har->hard= ma->har; har->seed= seed % 256; - if(ma->mode & MA_STAR) har->starpoints= ma->starc; - if(ma->mode & MA_HALO_LINES) har->linec= ma->linec; - if(ma->mode & MA_HALO_RINGS) har->ringc= ma->ringc; - if(ma->mode & MA_HALO_FLARE) har->flarec= ma->flarec; + if (ma->mode & MA_STAR) har->starpoints= ma->starc; + if (ma->mode & MA_HALO_LINES) har->linec= ma->linec; + if (ma->mode & MA_HALO_RINGS) har->ringc= ma->ringc; + if (ma->mode & MA_HALO_FLARE) har->flarec= ma->flarec; - if(ma->mtex[0]) { + if (ma->mtex[0]) { - if( (ma->mode & MA_HALOTEX) ) har->tex= 1; - else if(har->mat->septex & (1<<0)); /* only 1 level textures */ + if ( (ma->mode & MA_HALOTEX) ) har->tex= 1; + else if (har->mat->septex & (1<<0)); /* only 1 level textures */ else { mtex= ma->mtex[0]; copy_v3_v3(texvec, vec); - if(mtex->texco & TEXCO_NORM) { + if (mtex->texco & TEXCO_NORM) { ; } - else if(mtex->texco & TEXCO_OBJECT) { + else if (mtex->texco & TEXCO_OBJECT) { /* texvec[0]+= imatbase->ivec[0]; */ /* texvec[1]+= imatbase->ivec[1]; */ /* texvec[2]+= imatbase->ivec[2]; */ /* mul_m3_v3(imatbase->imat, texvec); */ } else { - if(orco) { + if (orco) { copy_v3_v3(texvec, orco); } } @@ -1028,16 +1028,16 @@ HaloRen *RE_inithalo(Render *re, ObjectRen *obr, Material *ma, float *vec, f yn= tin*mtex->colfac; //zn= tin*mtex->alphafac; - if(mtex->mapto & MAP_COL) { + if (mtex->mapto & MAP_COL) { zn= 1.0f-yn; har->r= (yn*tr+ zn*ma->r); har->g= (yn*tg+ zn*ma->g); har->b= (yn*tb+ zn*ma->b); } - if(mtex->texco & TEXCO_UV) { + if (mtex->texco & TEXCO_UV) { har->alfa= tin; } - if(mtex->mapto & MAP_ALPHA) + if (mtex->mapto & MAP_ALPHA) har->alfa= tin; } } @@ -1054,13 +1054,13 @@ HaloRen *RE_inithalo_particle(Render *re, ObjectRen *obr, DerivedMesh *dm, Mater float xn, yn, zn, texvec[3], hoco[4], hoco1[4], in[3],tex[3],out[3]; int i, hasrgb; - if(hasize==0.0f) return NULL; + if (hasize==0.0f) return NULL; projectverto(vec, re->winmat, hoco); - if(hoco[3]==0.0f) return NULL; - if(vec1) { + if (hoco[3]==0.0f) return NULL; + if (vec1) { projectverto(vec1, re->winmat, hoco1); - if(hoco1[3]==0.0f) return NULL; + if (hoco1[3]==0.0f) return NULL; } har= RE_findOrAddHalo(obr, obr->tothalo++); @@ -1077,13 +1077,13 @@ HaloRen *RE_inithalo_particle(Render *re, ObjectRen *obr, DerivedMesh *dm, Mater har->zBufDist = 0x7FFFFFFF*(hoco[2]/zn); /* halovect */ - if(vec1) { + if (vec1) { har->type |= HA_VECT; xn= har->xs - 0.5f*re->winx*(hoco1[0]/hoco1[3]); yn= har->ys - 0.5f*re->winy*(hoco1[1]/hoco1[3]); - if(xn==0.0f || (xn==0.0f && yn==0.0f)) zn= 0.0; + if (xn==0.0f || (xn==0.0f && yn==0.0f)) zn= 0.0; else zn= atan2(yn, xn); har->sin= sin(zn); @@ -1096,7 +1096,7 @@ HaloRen *RE_inithalo_particle(Render *re, ObjectRen *obr, DerivedMesh *dm, Mater normalize_v3(har->no); } - if(ma->mode & MA_HALO_XALPHA) har->type |= HA_XALPHA; + if (ma->mode & MA_HALO_XALPHA) har->type |= HA_XALPHA; har->alfa= ma->alpha; har->r= ma->r; @@ -1107,32 +1107,32 @@ HaloRen *RE_inithalo_particle(Render *re, ObjectRen *obr, DerivedMesh *dm, Mater har->hard= ma->har; har->seed= seed % 256; - if(ma->mode & MA_STAR) har->starpoints= ma->starc; - if(ma->mode & MA_HALO_LINES) har->linec= ma->linec; - if(ma->mode & MA_HALO_RINGS) har->ringc= ma->ringc; - if(ma->mode & MA_HALO_FLARE) har->flarec= ma->flarec; + if (ma->mode & MA_STAR) har->starpoints= ma->starc; + if (ma->mode & MA_HALO_LINES) har->linec= ma->linec; + if (ma->mode & MA_HALO_RINGS) har->ringc= ma->ringc; + if (ma->mode & MA_HALO_FLARE) har->flarec= ma->flarec; - if((ma->mode & MA_HALOTEX) && ma->mtex[0]) + if ((ma->mode & MA_HALOTEX) && ma->mtex[0]) har->tex= 1; - for(i=0; i<MAX_MTEX; i++) - if(ma->mtex[i] && (ma->septex & (1<<i))==0) { + for (i=0; i<MAX_MTEX; i++) + if (ma->mtex[i] && (ma->septex & (1<<i))==0) { mtex= ma->mtex[i]; copy_v3_v3(texvec, vec); - if(mtex->texco & TEXCO_NORM) { + if (mtex->texco & TEXCO_NORM) { ; } - else if(mtex->texco & TEXCO_OBJECT) { - if(mtex->object) + else if (mtex->texco & TEXCO_OBJECT) { + if (mtex->object) mul_m4_v3(mtex->object->imat_ren,texvec); } - else if(mtex->texco & TEXCO_GLOB){ + else if (mtex->texco & TEXCO_GLOB) { copy_v3_v3(texvec,vec); } - else if(mtex->texco & TEXCO_UV && uvco){ + else if (mtex->texco & TEXCO_UV && uvco) { int uv_index=CustomData_get_named_layer_index(&dm->faceData,CD_MTFACE,mtex->uvname); - if(uv_index<0) + if (uv_index<0) uv_index=CustomData_get_active_layer_index(&dm->faceData,CD_MTFACE); uv_index-=CustomData_get_layer_index(&dm->faceData,CD_MTFACE); @@ -1141,13 +1141,13 @@ HaloRen *RE_inithalo_particle(Render *re, ObjectRen *obr, DerivedMesh *dm, Mater texvec[1]=2.0f*uvco[2*uv_index+1]-1.0f; texvec[2]=0.0f; } - else if(mtex->texco & TEXCO_PARTICLE) { + else if (mtex->texco & TEXCO_PARTICLE) { /* particle coordinates in range [0,1] */ texvec[0] = 2.f * pa_co[0] - 1.f; texvec[1] = 2.f * pa_co[1] - 1.f; texvec[2] = pa_co[2]; } - else if(orco) { + else if (orco) { copy_v3_v3(texvec, orco); } @@ -1155,7 +1155,7 @@ HaloRen *RE_inithalo_particle(Render *re, ObjectRen *obr, DerivedMesh *dm, Mater //yn= tin*mtex->colfac; //zn= tin*mtex->alphafac; - if(mtex->mapto & MAP_COL) { + if (mtex->mapto & MAP_COL) { tex[0]=tr; tex[1]=tg; tex[2]=tb; @@ -1174,16 +1174,16 @@ HaloRen *RE_inithalo_particle(Render *re, ObjectRen *obr, DerivedMesh *dm, Mater } /* alpha returned, so let's use it instead of intensity */ - if(hasrgb) + if (hasrgb) tin = ta; - if(mtex->mapto & MAP_ALPHA) + if (mtex->mapto & MAP_ALPHA) har->alfa = texture_value_blend(mtex->def_var,har->alfa,tin,mtex->alphafac,mtex->blendtype); - if(mtex->mapto & MAP_HAR) + if (mtex->mapto & MAP_HAR) har->hard = 1.0f+126.0f*texture_value_blend(mtex->def_var,((float)har->hard)/127.0f,tin,mtex->hardfac,mtex->blendtype); - if(mtex->mapto & MAP_RAYMIRR) + if (mtex->mapto & MAP_RAYMIRR) har->hasize = 100.0f*texture_value_blend(mtex->def_var,har->hasize/100.0f,tin,mtex->raymirrfac,mtex->blendtype); - if(mtex->mapto & MAP_TRANSLU) { + if (mtex->mapto & MAP_TRANSLU) { float add = texture_value_blend(mtex->def_var,(float)har->add/255.0f,tin,mtex->translfac,mtex->blendtype); CLAMP(add, 0.f, 1.f); har->add = 255.0f*add; @@ -1206,19 +1206,19 @@ static int panotestclip(Render *re, int do_pano, float *v) float abs4; short c=0; - if(do_pano==0) return testclip(v); + if (do_pano==0) return testclip(v); abs4= fabs(v[3]); - if(v[2]< -abs4) c=16; /* this used to be " if(v[2]<0) ", see clippz() */ - else if(v[2]> abs4) c+= 32; + if (v[2]< -abs4) c=16; /* this used to be " if(v[2]<0) ", see clippz() */ + else if (v[2]> abs4) c+= 32; - if( v[1]>abs4) c+=4; - else if( v[1]< -abs4) c+=8; + if ( v[1]>abs4) c+=4; + else if ( v[1]< -abs4) c+=8; abs4*= re->xparts; - if( v[0]>abs4) c+=2; - else if( v[0]< -abs4) c+=1; + if ( v[0]>abs4) c+=2; + else if ( v[0]< -abs4) c+=1; return c; } @@ -1240,20 +1240,20 @@ void project_renderdata(Render *re, void (*projectfunc)(const float *, float mat float zn, vec[3], hoco[4]; int a; - if(do_pano) { + if (do_pano) { float panophi= xoffs; re->panosi= sin(panophi); re->panoco= cos(panophi); } - for(obr=re->objecttable.first; obr; obr=obr->next) { + for (obr=re->objecttable.first; obr; obr=obr->next) { /* calculate view coordinates (and zbuffer value) */ - for(a=0; a<obr->tothalo; a++) { - if((a & 255)==0) har= obr->bloha[a>>8]; + for (a=0; a<obr->tothalo; a++) { + if ((a & 255)==0) har= obr->bloha[a>>8]; else har++; - if(do_pano) { + if (do_pano) { vec[0]= re->panoco*har->co[0] + re->panosi*har->co[2]; vec[1]= har->co[1]; vec[2]= -re->panosi*har->co[0] + re->panoco*har->co[2]; @@ -1268,10 +1268,10 @@ void project_renderdata(Render *re, void (*projectfunc)(const float *, float mat hoco[0]*= 0.5f; hoco[1]*= 0.5f; - if( panotestclip(re, do_pano, hoco) ) { + if ( panotestclip(re, do_pano, hoco) ) { har->miny= har->maxy= -10000; /* that way render clips it */ } - else if(hoco[3]<0.0f) { + else if (hoco[3]<0.0f) { har->miny= har->maxy= -10000; /* render clips it */ } else /* do the projection...*/ @@ -1296,8 +1296,8 @@ void project_renderdata(Render *re, void (*projectfunc)(const float *, float mat har->rad= fabsf(har->xs- 0.5f*re->winx*(1.0f+hoco[0]/zn)); /* this clip is not really OK, to prevent stars to become too large */ - if(har->type & HA_ONLYSKY) { - if(har->rad>3.0f) har->rad= 3.0f; + if (har->type & HA_ONLYSKY) { + if (har->rad>3.0f) har->rad= 3.0f; } har->radsq= har->rad*har->rad; @@ -1334,7 +1334,7 @@ ObjectInstanceRen *RE_addRenderInstance(Render *re, ObjectRen *obr, Object *ob, obi->psysindex= psysindex; obi->lay= lay; - if(mat) { + if (mat) { copy_m4_m4(obi->mat, mat); copy_m3_m4(mat3, mat); invert_m3_m3(obi->nmat, mat3); @@ -1360,10 +1360,10 @@ void RE_makeRenderInstances(Render *re) newlist.first= newlist.last= NULL; obi= re->objectinstance; - for(oldobi=re->instancetable.first; oldobi; oldobi=oldobi->next) { + for (oldobi=re->instancetable.first; oldobi; oldobi=oldobi->next) { *obi= *oldobi; - if(obi->obr) { + if (obi->obr) { obi->prev= obi->next= NULL; BLI_addtail(&newlist, obi); obi++; @@ -1383,7 +1383,7 @@ int clip_render_object(float boundbox[][3], float *bounds, float winmat[][4]) copy_m4_m4(mat, winmat); - for(a=0; a<8; a++) { + for (a=0; a<8; a++) { vec[0]= (a & 1)? boundbox[0][0]: boundbox[1][0]; vec[1]= (a & 2)? boundbox[0][1]: boundbox[1][1]; vec[2]= (a & 4)? boundbox[0][2]: boundbox[1][2]; @@ -1391,25 +1391,25 @@ int clip_render_object(float boundbox[][3], float *bounds, float winmat[][4]) mul_m4_v4(mat, vec); fl= 0; - if(bounds) { - if(vec[0] < bounds[0]*vec[3]) fl |= 1; - else if(vec[0] > bounds[1]*vec[3]) fl |= 2; + if (bounds) { + if (vec[0] < bounds[0]*vec[3]) fl |= 1; + else if (vec[0] > bounds[1]*vec[3]) fl |= 2; - if(vec[1] > bounds[3]*vec[3]) fl |= 4; - else if(vec[1]< bounds[2]*vec[3]) fl |= 8; + if (vec[1] > bounds[3]*vec[3]) fl |= 4; + else if (vec[1]< bounds[2]*vec[3]) fl |= 8; } else { - if(vec[0] < -vec[3]) fl |= 1; - else if(vec[0] > vec[3]) fl |= 2; + if (vec[0] < -vec[3]) fl |= 1; + else if (vec[0] > vec[3]) fl |= 2; - if(vec[1] > vec[3]) fl |= 4; - else if(vec[1] < -vec[3]) fl |= 8; + if (vec[1] > vec[3]) fl |= 4; + else if (vec[1] < -vec[3]) fl |= 8; } - if(vec[2] < -vec[3]) fl |= 16; - else if(vec[2] > vec[3]) fl |= 32; + if (vec[2] < -vec[3]) fl |= 16; + else if (vec[2] > vec[3]) fl |= 32; flag &= fl; - if(flag==0) return 0; + if (flag==0) return 0; } return flag; diff --git a/source/blender/render/intern/source/shadbuf.c b/source/blender/render/intern/source/shadbuf.c index 49e331cc44c..25705a9fc99 100644 --- a/source/blender/render/intern/source/shadbuf.c +++ b/source/blender/render/intern/source/shadbuf.c @@ -91,14 +91,14 @@ static void copy_to_ztile(int *rectz, int size, int x1, int y1, int tile, char * x2= x1+tile; y2= y1+tile; - if(x2>=size) x2= size-1; - if(y2>=size) y2= size-1; + if (x2>=size) x2= size-1; + if (y2>=size) y2= size-1; - if(x1>=x2 || y1>=y2) return; + if (x1>=x2 || y1>=y2) return; len4= 4*(x2- x1); rz= rectz + size*y1 + x1; - for(; y1<y2; y1++) { + for (; y1<y2; y1++) { memcpy(r1, rz, len4); rz+= size; r1+= len4; @@ -132,12 +132,12 @@ static float *give_jitter_tab(int samp) static char ctab[17]= {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; int a, offset=0; - if(samp<2) samp= 2; - else if(samp>16) samp= 16; + if (samp<2) samp= 2; + else if (samp>16) samp= 16; - for(a=0; a<samp-1; a++) offset+= tab[a]; + for (a=0; a<samp-1; a++) offset+= tab[a]; - if(ctab[samp]==0) { + if (ctab[samp]==0) { ctab[samp]= 1; BLI_initjit(jit[offset], samp*samp); } @@ -154,10 +154,10 @@ static void make_jitter_weight_tab(Render *re, ShadBuf *shb, short filtertype) shb->weight= MEM_mallocN(sizeof(float)*tot, "weight tab lamp"); - for(jit= shb->jit, a=0; a<tot; a++, jit+=2) { - if(filtertype==LA_SHADBUF_TENT) + for (jit= shb->jit, a=0; a<tot; a++, jit+=2) { + if (filtertype==LA_SHADBUF_TENT) shb->weight[a]= 0.71f - sqrt(jit[0]*jit[0] + jit[1]*jit[1]); - else if(filtertype==LA_SHADBUF_GAUSS) + else if (filtertype==LA_SHADBUF_GAUSS) shb->weight[a]= RE_filter_value(R_FILTER_GAUSS, 1.8f*sqrt(jit[0]*jit[0] + jit[1]*jit[1])); else shb->weight[a]= 1.0f; @@ -166,7 +166,7 @@ static void make_jitter_weight_tab(Render *re, ShadBuf *shb, short filtertype) } totw= 1.0f/totw; - for(a=0; a<tot; a++) { + for (a=0; a<tot; a++) { shb->weight[a]*= totw; } } @@ -176,8 +176,8 @@ static int verg_deepsample(const void *poin1, const void *poin2) const DeepSample *ds1= (const DeepSample*)poin1; const DeepSample *ds2= (const DeepSample*)poin2; - if(ds1->z < ds2->z) return -1; - else if(ds1->z == ds2->z) return 0; + if (ds1->z < ds2->z) return -1; + else if (ds1->z == ds2->z) return 0; else return 1; } @@ -191,8 +191,8 @@ static int compress_deepsamples(DeepSample *dsample, int tot, float epsilon) int a, first, z, newtot= 0; #if 0 - if(print) { - for(a=0, ds=dsample; a<tot; a++, ds++) + if (print) { + for (a=0, ds=dsample; a<tot; a++, ds++) printf("%lf,%f ", ds->z/(double)0x7FFFFFFF, ds->v); printf("\n"); } @@ -204,17 +204,17 @@ static int compress_deepsamples(DeepSample *dsample, int tot, float epsilon) a= 0; /* as long as we are not at the end of the array */ - for(a++, ds++; a<tot; a++, ds++) { + for (a++, ds++; a<tot; a++, ds++) { slopemin= 0.0f; slopemax= 0.0f; first= 1; - for(; a<tot; a++, ds++) { + for (; a<tot; a++, ds++) { //dz= ds->z - newds->z; - if(ds->z == newds->z) { + if (ds->z == newds->z) { /* still in same z position, simply check * visibility difference against epsilon */ - if(!(fabs(newds->v - ds->v) <= epsilon)) { + if (!(fabs(newds->v - ds->v) <= epsilon)) { break; } } @@ -225,7 +225,7 @@ static int compress_deepsamples(DeepSample *dsample, int tot, float epsilon) max= ((ds->v + epsilon) - newds->v)*div; /* adapt existing slopes */ - if(first) { + if (first) { newmin= min; newmax= max; first= 0; @@ -235,7 +235,7 @@ static int compress_deepsamples(DeepSample *dsample, int tot, float epsilon) newmax= MIN2(slopemax, max); /* verify if there is still space between the slopes */ - if(newmin > newmax) { + if (newmin > newmax) { ds--; a--; break; @@ -247,7 +247,7 @@ static int compress_deepsamples(DeepSample *dsample, int tot, float epsilon) } } - if(a == tot) { + if (a == tot) { ds--; a--; } @@ -255,7 +255,7 @@ static int compress_deepsamples(DeepSample *dsample, int tot, float epsilon) /* always previous z */ z= ds->z; - if(first || a==tot-1) { + if (first || a==tot-1) { /* if slopes were not initialized, use last visibility */ v= ds->v; } @@ -272,12 +272,12 @@ static int compress_deepsamples(DeepSample *dsample, int tot, float epsilon) newds->v= v; } - if(newtot == 0 || (newds->v != (newds-1)->v)) + if (newtot == 0 || (newds->v != (newds-1)->v)) newtot++; #if 0 - if(print) { - for(a=0, ds=dsample; a<newtot; a++, ds++) + if (print) { + for (a=0, ds=dsample; a<newtot; a++, ds++) printf("%lf,%f ", ds->z/(double)0x7FFFFFFF, ds->v); printf("\n"); } @@ -291,7 +291,7 @@ static float deep_alpha(Render *re, int obinr, int facenr, int strand) ObjectInstanceRen *obi= &re->objectinstance[obinr]; Material *ma; - if(strand) { + if (strand) { StrandRen *strand= RE_findOrAddStrand(obi->obr, facenr-1); ma= strand->buffer->ma; } @@ -327,32 +327,32 @@ static void compress_deepshadowbuf(Render *re, ShadBuf *shb, APixstr *apixbuf, A ap= apixbuf; aps= apixbufstrand; - for(a=0; a<size*size; a++, ap++, aps++) { + for (a=0; a<size*size; a++, ap++, aps++) { /* count number of samples */ - for(c=0; c<totbuf; c++) + for (c=0; c<totbuf; c++) sampletot[c]= 0; tot= 0; - for(apn=ap; apn; apn=apn->next) - for(b=0; b<4; b++) - if(apn->p[b]) - for(c=0; c<totbuf; c++) - if(apn->mask[b] & (1<<c)) + for (apn=ap; apn; apn=apn->next) + for (b=0; b<4; b++) + if (apn->p[b]) + for (c=0; c<totbuf; c++) + if (apn->mask[b] & (1<<c)) sampletot[c]++; - if(apixbufstrand) { - for(apns=aps; apns; apns=apns->next) - for(b=0; b<4; b++) - if(apns->p[b]) - for(c=0; c<totbuf; c++) - if(apns->mask[b] & (1<<c)) + if (apixbufstrand) { + for (apns=aps; apns; apns=apns->next) + for (b=0; b<4; b++) + if (apns->p[b]) + for (c=0; c<totbuf; c++) + if (apns->mask[b] & (1<<c)) sampletot[c]++; } - for(c=0; c<totbuf; c++) + for (c=0; c<totbuf; c++) tot += sampletot[c]; - if(tot == 0) { + if (tot == 0) { shsample->deepbuf[a]= NULL; shsample->totbuf[a]= 0; continue; @@ -360,14 +360,14 @@ static void compress_deepshadowbuf(Render *re, ShadBuf *shb, APixstr *apixbuf, A /* fill samples */ ds[0]= sampleds[0]= MEM_callocN(sizeof(DeepSample)*tot*2, "deepsample"); - for(c=1; c<totbuf; c++) + for (c=1; c<totbuf; c++) ds[c]= sampleds[c]= sampleds[c-1] + sampletot[c-1]*2; - for(apn=ap; apn; apn=apn->next) { - for(b=0; b<4; b++) { - if(apn->p[b]) { - for(c=0; c<totbuf; c++) { - if(apn->mask[b] & (1<<c)) { + for (apn=ap; apn; apn=apn->next) { + for (b=0; b<4; b++) { + if (apn->p[b]) { + for (c=0; c<totbuf; c++) { + if (apn->mask[b] & (1<<c)) { /* two entries to create step profile */ ds[c]->z= apn->z[b]; ds[c]->v= 1.0f; /* not used */ @@ -381,12 +381,12 @@ static void compress_deepshadowbuf(Render *re, ShadBuf *shb, APixstr *apixbuf, A } } - if(apixbufstrand) { - for(apns=aps; apns; apns=apns->next) { - for(b=0; b<4; b++) { - if(apns->p[b]) { - for(c=0; c<totbuf; c++) { - if(apns->mask[b] & (1<<c)) { + if (apixbufstrand) { + for (apns=aps; apns; apns=apns->next) { + for (b=0; b<4; b++) { + if (apns->p[b]) { + for (c=0; c<totbuf; c++) { + if (apns->mask[b] & (1<<c)) { /* two entries to create step profile */ ds[c]->z= apns->z[b]; ds[c]->v= 1.0f; /* not used */ @@ -401,7 +401,7 @@ static void compress_deepshadowbuf(Render *re, ShadBuf *shb, APixstr *apixbuf, A } } - for(c=0; c<totbuf; c++) { + for (c=0; c<totbuf; c++) { /* sort by increasing z */ qsort(sampleds[c], sampletot[c], sizeof(DeepSample)*2, verg_deepsample); @@ -409,7 +409,7 @@ static void compress_deepshadowbuf(Render *re, ShadBuf *shb, APixstr *apixbuf, A visibility= 1.0f; ds[c]= sampleds[c]; - for(b=0; b<sampletot[c]; b++) { + for (b=0; b<sampletot[c]; b++) { /* two entries creating step profile */ ds[c]->v= visibility; ds[c]++; @@ -421,8 +421,8 @@ static void compress_deepshadowbuf(Render *re, ShadBuf *shb, APixstr *apixbuf, A /* halfway trick, probably won't work well for volumes? */ ds[c]= sampleds[c]; - for(b=0; b<sampletot[c]; b++) { - if(b+1 < sampletot[c]) { + for (b=0; b<sampletot[c]; b++) { + if (b+1 < sampletot[c]) { ds[c]->z= (ds[c]->z>>1) + ((ds[c]+2)->z>>1); ds[c]++; ds[c]->z= (ds[c]->z>>1) + ((ds[c]+2)->z>>1); @@ -450,27 +450,27 @@ static void compress_deepshadowbuf(Render *re, ShadBuf *shb, APixstr *apixbuf, A minz= 0; found= 0; - for(c=0; c<totbuf; c++) { - if(sampletot[c] && (!found || ds[c]->z < minz)) { + for (c=0; c<totbuf; c++) { + if (sampletot[c] && (!found || ds[c]->z < minz)) { minz= ds[c]->z; found= 1; } } - if(!found) + if (!found) break; dsb->z= minz; dsb->v= 0.0f; visibility= 0.0f; - for(c=0; c<totbuf; c++) { - if(sampletot[c] && ds[c]->z == minz) { + for (c=0; c<totbuf; c++) { + if (sampletot[c] && ds[c]->z == minz) { ds[c]++; sampletot[c]--; } - if(sampleds[c] == ds[c]) + if (sampleds[c] == ds[c]) visibility += totbuf_f_inv; else visibility += (ds[c]-1)->v / totbuf_f; @@ -488,7 +488,7 @@ static void compress_deepshadowbuf(Render *re, ShadBuf *shb, APixstr *apixbuf, A shsample->totbuf[a]= newtot; totsamplec += newtot; - if(newtot < prevtot) { + if (newtot < prevtot) { newbuf= MEM_mallocN(sizeof(DeepSample)*newtot, "cdeepsample"); memcpy(newbuf, shsample->deepbuf[a], sizeof(DeepSample)*newtot); MEM_freeN(shsample->deepbuf[a]); @@ -523,20 +523,20 @@ static void compress_shadowbuf(ShadBuf *shb, int *rectz, int square) /* help buffer */ rcline= MEM_mallocN(256*4+sizeof(int), "makeshadbuf2"); - for(y=0; y<size; y+=16) { - if(y< size/2) miny= y+15-size/2; + for (y=0; y<size; y+=16) { + if (y< size/2) miny= y+15-size/2; else miny= y-size/2; - for(x=0; x<size; x+=16) { + for (x=0; x<size; x+=16) { /* is tile within spotbundle? */ a= size/2; - if(x< a) minx= x+15-a; + if (x< a) minx= x+15-a; else minx= x-a; dist= sqrt( (float)(minx*minx+miny*miny) ); - if(square==0 && dist>(float)(a+12)) { /* 12, tested with a onlyshadow lamp */ + if (square==0 && dist>(float)(a+12)) { /* 12, tested with a onlyshadow lamp */ a= 256; verg= 0; /* 0x80000000; */ /* 0x7FFFFFFF; */ rz1= (&verg)+1; } @@ -546,11 +546,11 @@ static void compress_shadowbuf(ShadBuf *shb, int *rectz, int square) verg= (*rz1 & 0xFFFFFF00); - for(a=0;a<256;a++,rz1++) { - if( (*rz1 & 0xFFFFFF00) !=verg) break; + for (a=0;a<256;a++,rz1++) { + if ( (*rz1 & 0xFFFFFF00) !=verg) break; } } - if(a==256) { /* complete empty tile */ + if (a==256) { /* complete empty tile */ *ctile= 0; *ztile= *(rz1-1); } @@ -564,13 +564,13 @@ static void compress_shadowbuf(ShadBuf *shb, int *rectz, int square) verg1= rc[BCOMP]; rc+= 4; byt1= 1; byt2= 1; - for(a=1;a<256;a++,rc+=4) { + for (a=1;a<256;a++,rc+=4) { byt1 &= (verg==rc[ACOMP]); byt2 &= (verg1==rc[BCOMP]); - if(byt1==0) break; + if (byt1==0) break; } - if(byt1 && byt2) { /* only store byte */ + if (byt1 && byt2) { /* only store byte */ *ctile= 1; *ztile= (uintptr_t)MEM_mallocN(256+4, "tile1"); rz= (int *)*ztile; @@ -578,9 +578,9 @@ static void compress_shadowbuf(ShadBuf *shb, int *rectz, int square) zt= (char *)(rz+1); rc= rcline; - for(a=0; a<256; a++, zt++, rc+=4) *zt= rc[GCOMP]; + for (a=0; a<256; a++, zt++, rc+=4) *zt= rc[GCOMP]; } - else if(byt1) { /* only store short */ + else if (byt1) { /* only store short */ *ctile= 2; *ztile= (uintptr_t)MEM_mallocN(2*256+4,"Tile2"); rz= (int *)*ztile; @@ -588,7 +588,7 @@ static void compress_shadowbuf(ShadBuf *shb, int *rectz, int square) zt= (char *)(rz+1); rc= rcline; - for(a=0; a<256; a++, zt+=2, rc+=4) { + for (a=0; a<256; a++, zt+=2, rc+=4) { zt[0]= rc[BCOMP]; zt[1]= rc[GCOMP]; } @@ -599,7 +599,7 @@ static void compress_shadowbuf(ShadBuf *shb, int *rectz, int square) zt= (char *)*ztile; rc= rcline; - for(a=0; a<256; a++, zt+=3, rc+=4) { + for (a=0; a<256; a++, zt+=3, rc+=4) { zt[0]= rc[ACOMP]; zt[1]= rc[BCOMP]; zt[2]= rc[GCOMP]; @@ -630,19 +630,19 @@ static void shadowbuf_autoclip(Render *re, LampRen *lar) minz= 1.0e30f; maxz= -1.0e30f; copy_m4_m4(viewmat, lar->shb->viewmat); - if(lar->mode & (LA_LAYER|LA_LAYER_SHADOW)) lay= lar->lay; + if (lar->mode & (LA_LAYER|LA_LAYER_SHADOW)) lay= lar->lay; maxtotvert= 0; - for(obr=re->objecttable.first; obr; obr=obr->next) + for (obr=re->objecttable.first; obr; obr=obr->next) maxtotvert= MAX2(obr->totvert, maxtotvert); clipflag= MEM_callocN(sizeof(char)*maxtotvert, "autoclipflag"); /* set clip in vertices when face visible */ - for(i=0, obi=re->instancetable.first; obi; i++, obi=obi->next) { + for (i=0, obi=re->instancetable.first; obi; i++, obi=obi->next) { obr= obi->obr; - if(obi->flag & R_TRANSFORMED) + if (obi->flag & R_TRANSFORMED) mult_m4_m4m4(obviewmat, viewmat, obi->mat); else copy_m4_m4(obviewmat, viewmat); @@ -650,35 +650,35 @@ static void shadowbuf_autoclip(Render *re, LampRen *lar) memset(clipflag, 0, sizeof(char)*obr->totvert); /* clear clip, is being set if face is visible (clip is calculated for real later) */ - for(a=0; a<obr->totvlak; a++) { - if((a & 255)==0) vlr= obr->vlaknodes[a>>8].vlak; + for (a=0; a<obr->totvlak; a++) { + if ((a & 255)==0) vlr= obr->vlaknodes[a>>8].vlak; else vlr++; /* note; these conditions are copied from zbuffer_shadow() */ - if(vlr->mat!= ma) { + if (vlr->mat!= ma) { ma= vlr->mat; ok= 1; - if((ma->mode & MA_SHADBUF)==0) ok= 0; + if ((ma->mode & MA_SHADBUF)==0) ok= 0; } - if(ok && (obi->lay & lay)) { + if (ok && (obi->lay & lay)) { clipflag[vlr->v1->index]= 1; clipflag[vlr->v2->index]= 1; clipflag[vlr->v3->index]= 1; - if(vlr->v4) clipflag[vlr->v4->index]= 1; + if (vlr->v4) clipflag[vlr->v4->index]= 1; } } /* calculate min and max */ - for(a=0; a< obr->totvert;a++) { - if((a & 255)==0) ver= RE_findOrAddVert(obr, a); + for (a=0; a< obr->totvert;a++) { + if ((a & 255)==0) ver= RE_findOrAddVert(obr, a); else ver++; - if(clipflag[a]) { + if (clipflag[a]) { copy_v3_v3(vec, ver->co); mul_m4_v3(obviewmat, vec); /* Z on visible side of lamp space */ - if(vec[2] < 0.0f) { + if (vec[2] < 0.0f) { float inpr, z= -vec[2]; /* since vec is rotated in lampspace, this is how to get the cosine of angle */ @@ -687,9 +687,9 @@ static void shadowbuf_autoclip(Render *re, LampRen *lar) normalize_v3(vec); inpr= - vec[2]; - if(inpr>=lar->spotsi) { - if(z<minz) minz= z; - if(z>maxz) maxz= z; + if (inpr>=lar->spotsi) { + if (z<minz) minz= z; + if (z>maxz) maxz= z; } } } @@ -699,13 +699,13 @@ static void shadowbuf_autoclip(Render *re, LampRen *lar) MEM_freeN(clipflag); /* set clipping min and max */ - if(minz < maxz) { + if (minz < maxz) { float delta= (maxz - minz); /* threshold to prevent precision issues */ //printf("minz %f maxz %f delta %f\n", minz, maxz, delta); - if(lar->bufflag & LA_SHADBUF_AUTO_START) + if (lar->bufflag & LA_SHADBUF_AUTO_START) lar->shb->d= minz - delta*0.02f; /* 0.02 is arbitrary... needs more thinking! */ - if(lar->bufflag & LA_SHADBUF_AUTO_END) + if (lar->bufflag & LA_SHADBUF_AUTO_END) lar->shb->clipend= maxz + delta*0.1f; /* bias was calculated as percentage, we scale it to prevent animation issues */ @@ -723,12 +723,12 @@ static void makeflatshadowbuf(Render *re, LampRen *lar, float *jitbuf) /* zbuffering */ rectz= MEM_mapallocN(sizeof(int)*shb->size*shb->size, "makeshadbuf"); - for(samples=0; samples<shb->totbuf; samples++) { + for (samples=0; samples<shb->totbuf; samples++) { zbuffer_shadow(re, shb->persmat, lar, rectz, shb->size, jitbuf[2*samples], jitbuf[2*samples+1]); /* create Z tiles (for compression): this system is 24 bits!!! */ compress_shadowbuf(shb, rectz, lar->mode & LA_SQUARE); - if(re->test_break(re->tbh)) + if (re->test_break(re->tbh)) break; } @@ -744,7 +744,7 @@ static void makedeepshadowbuf(Render *re, LampRen *lar, float *jitbuf) /* zbuffering */ apixbuf= MEM_callocN(sizeof(APixstr)*shb->size*shb->size, "APixbuf"); - if(re->totstrand) + if (re->totstrand) apixbufstrand= MEM_callocN(sizeof(APixstrand)*shb->size*shb->size, "APixbufstrand"); zbuffer_abuf_shadow(re, lar, shb->persmat, apixbuf, apixbufstrand, &apsmbase, shb->size, @@ -754,7 +754,7 @@ static void makedeepshadowbuf(Render *re, LampRen *lar, float *jitbuf) compress_deepshadowbuf(re, shb, apixbuf, apixbufstrand); MEM_freeN(apixbuf); - if(apixbufstrand) + if (apixbufstrand) MEM_freeN(apixbufstrand); freepsA(&apsmbase); } @@ -764,11 +764,11 @@ void makeshadowbuf(Render *re, LampRen *lar) ShadBuf *shb= lar->shb; float wsize, *jitbuf, twozero[2]= {0.0f, 0.0f}, angle, temp; - if(lar->bufflag & (LA_SHADBUF_AUTO_START|LA_SHADBUF_AUTO_END)) + if (lar->bufflag & (LA_SHADBUF_AUTO_START|LA_SHADBUF_AUTO_END)) shadowbuf_autoclip(re, lar); /* just to enforce identical behavior of all irregular buffers */ - if(lar->buftype==LA_SHADBUF_IRREGULAR) + if (lar->buftype==LA_SHADBUF_IRREGULAR) shb->size= 1024; /* matrices and window: in winmat the transformation is being put, @@ -782,7 +782,7 @@ void makeshadowbuf(Render *re, LampRen *lar) perspective_m4( shb->winmat,-wsize, wsize, -wsize, wsize, shb->d, shb->clipend); mult_m4_m4m4(shb->persmat, shb->winmat, shb->viewmat); - if(ELEM3(lar->buftype, LA_SHADBUF_REGULAR, LA_SHADBUF_HALFWAY, LA_SHADBUF_DEEP)) { + if (ELEM3(lar->buftype, LA_SHADBUF_REGULAR, LA_SHADBUF_HALFWAY, LA_SHADBUF_DEEP)) { shb->totbuf= lar->buffers; /* jitter, weights - not threadsafe! */ @@ -791,12 +791,12 @@ void makeshadowbuf(Render *re, LampRen *lar) make_jitter_weight_tab(re, shb, lar->filtertype); BLI_unlock_thread(LOCK_CUSTOM1); - if(shb->totbuf==4) jitbuf= give_jitter_tab(2); - else if(shb->totbuf==9) jitbuf= give_jitter_tab(3); + if (shb->totbuf==4) jitbuf= give_jitter_tab(2); + else if (shb->totbuf==9) jitbuf= give_jitter_tab(3); else jitbuf= twozero; /* zbuffering */ - if(lar->buftype == LA_SHADBUF_DEEP) { + if (lar->buftype == LA_SHADBUF_DEEP) { makedeepshadowbuf(re, lar, jitbuf); shb->totbuf= 1; } @@ -814,8 +814,8 @@ static void *do_shadow_thread(void *re_v) do { BLI_lock_thread(LOCK_CUSTOM1); - for(lar=re->lampren.first; lar; lar=lar->next) { - if(lar->shb && !lar->thread_assigned) { + for (lar=re->lampren.first; lar; lar=lar->next) { + if (lar->shb && !lar->thread_assigned) { lar->thread_assigned= 1; break; } @@ -823,7 +823,7 @@ static void *do_shadow_thread(void *re_v) BLI_unlock_thread(LOCK_CUSTOM1); /* if type is irregular, this only sets the perspective matrix and autoclips */ - if(lar) { + if (lar) { makeshadowbuf(re, lar); BLI_lock_thread(LOCK_CUSTOM1); lar->thread_ready= 1; @@ -848,9 +848,9 @@ void threaded_makeshadowbufs(Render *re) int (*test_break)(void *); /* count number of threads to use */ - if(G.rendering) { - for(lar=re->lampren.first; lar; lar= lar->next) - if(lar->shb) + if (G.rendering) { + for (lar=re->lampren.first; lar; lar= lar->next) + if (lar->shb) totthread++; totthread= MIN2(totthread, re->r.threads); @@ -858,10 +858,10 @@ void threaded_makeshadowbufs(Render *re) else totthread= 1; /* preview render */ - if(totthread <= 1) { - for(lar=re->lampren.first; lar; lar= lar->next) { - if(re->test_break(re->tbh)) break; - if(lar->shb) { + if (totthread <= 1) { + for (lar=re->lampren.first; lar; lar= lar->next) { + if (re->test_break(re->tbh)) break; + if (lar->shb) { /* if type is irregular, this only sets the perspective matrix and autoclips */ makeshadowbuf(re, lar); } @@ -872,26 +872,26 @@ void threaded_makeshadowbufs(Render *re) test_break= re->test_break; re->test_break= thread_break; - for(lar=re->lampren.first; lar; lar= lar->next) { + for (lar=re->lampren.first; lar; lar= lar->next) { lar->thread_assigned= 0; lar->thread_ready= 0; } BLI_init_threads(&threads, do_shadow_thread, totthread); - for(a=0; a<totthread; a++) + for (a=0; a<totthread; a++) BLI_insert_thread(&threads, re); /* keep rendering as long as there are shadow buffers not ready */ do { - if((g_break=test_break(re->tbh))) + if ((g_break=test_break(re->tbh))) break; PIL_sleep_ms(50); BLI_lock_thread(LOCK_CUSTOM1); - for(lar=re->lampren.first; lar; lar= lar->next) - if(lar->shb && !lar->thread_ready) + for (lar=re->lampren.first; lar; lar= lar->next) + if (lar->shb && !lar->thread_ready) break; BLI_unlock_thread(LOCK_CUSTOM1); } while(lar); @@ -906,16 +906,16 @@ void threaded_makeshadowbufs(Render *re) void freeshadowbuf(LampRen *lar) { - if(lar->shb) { + if (lar->shb) { ShadBuf *shb= lar->shb; ShadSampleBuf *shsample; int b, v; - for(shsample= shb->buffers.first; shsample; shsample= shsample->next) { - if(shsample->deepbuf) { + for (shsample= shb->buffers.first; shsample; shsample= shsample->next) { + if (shsample->deepbuf) { v= shb->size*shb->size; - for(b=0; b<v; b++) - if(shsample->deepbuf[b]) + for (b=0; b<v; b++) + if (shsample->deepbuf[b]) MEM_freeN(shsample->deepbuf[b]); MEM_freeN(shsample->deepbuf); @@ -926,8 +926,8 @@ void freeshadowbuf(LampRen *lar) char *ctile= shsample->cbuf; v= (shb->size*shb->size)/256; - for(b=0; b<v; b++, ztile++, ctile++) - if(*ctile) MEM_freeN((void *) *ztile); + for (b=0; b<v; b++, ztile++, ctile++) + if (*ctile) MEM_freeN((void *) *ztile); MEM_freeN(shsample->zbuf); MEM_freeN(shsample->cbuf); @@ -935,7 +935,7 @@ void freeshadowbuf(LampRen *lar) } BLI_freelistN(&shb->buffers); - if(shb->weight) MEM_freeN(shb->weight); + if (shb->weight) MEM_freeN(shb->weight); MEM_freeN(lar->shb); lar->shb= NULL; @@ -949,22 +949,22 @@ static int firstreadshadbuf(ShadBuf *shb, ShadSampleBuf *shsample, int **rz, int int ofs; char *ct; - if(shsample->deepbuf) + if (shsample->deepbuf) return 0; /* always test borders of shadowbuffer */ - if(xs<0) xs= 0; else if(xs>=shb->size) xs= shb->size-1; - if(ys<0) ys= 0; else if(ys>=shb->size) ys= shb->size-1; + if (xs<0) xs= 0; else if (xs>=shb->size) xs= shb->size-1; + if (ys<0) ys= 0; else if (ys>=shb->size) ys= shb->size-1; /* calc z */ ofs= (ys>>4)*(shb->size>>4) + (xs>>4); ct= shsample->cbuf+ofs; - if(*ct==0) { - if(nr==0) { + if (*ct==0) { + if (nr==0) { *rz= *( (int **)(shsample->zbuf+ofs) ); return 1; } - else if(*rz!= *( (int **)(shsample->zbuf+ofs) )) return 0; + else if (*rz!= *( (int **)(shsample->zbuf+ofs) )) return 0; return 1; } @@ -983,21 +983,21 @@ static float readdeepvisibility(DeepSample *dsample, int tot, int z, int bias, f ds= dsample; for (a=0; a<tot && (z-bias > ds->z); a++, ds++) {} - if(a == tot) { - if(biast) + if (a == tot) { + if (biast) *biast= 0.0f; return (ds-1)->v; /* completely behind all samples */ } /* check if this read needs bias blending */ - if(biast) { - if(z > ds->z) + if (biast) { + if (z > ds->z) *biast= (float)(z - ds->z)/(float)bias; else *biast= 0.0f; } - if(a == 0) + if (a == 0) return 1.0f; /* completely in front of all samples */ /* converting to float early here because ds->z - prevds->z can overflow */ @@ -1011,18 +1011,18 @@ static float readdeepshadowbuf(ShadBuf *shb, ShadSampleBuf *shsample, int bias, float v, biasv, biast; int ofs, tot; - if(zs < - 0x7FFFFE00 + bias) + if (zs < - 0x7FFFFE00 + bias) return 1.0; /* extreme close to clipstart */ /* calc z */ ofs= ys*shb->size + xs; tot= shsample->totbuf[ofs]; - if(tot == 0) + if (tot == 0) return 1.0f; v= readdeepvisibility(shsample->deepbuf[ofs], tot, zs, bias, &biast); - if(biast != 0.0f) { + if (biast != 0.0f) { /* in soft bias area */ biasv= readdeepvisibility(shsample->deepbuf[ofs], tot, zs, 0, 0); @@ -1046,10 +1046,10 @@ static float readshadowbuf(ShadBuf *shb, ShadSampleBuf *shsample, int bias, int /* if(xs>=shb->size || ys>=shb->size) return 1.0; */ /* always test borders of shadowbuffer */ - if(xs<0) xs= 0; else if(xs>=shb->size) xs= shb->size-1; - if(ys<0) ys= 0; else if(ys>=shb->size) ys= shb->size-1; + if (xs<0) xs= 0; else if (xs>=shb->size) xs= shb->size-1; + if (ys<0) ys= 0; else if (ys>=shb->size) ys= shb->size-1; - if(shsample->deepbuf) + if (shsample->deepbuf) return readdeepshadowbuf(shb, shsample, bias, xs, ys, zs); /* calc z */ @@ -1057,14 +1057,14 @@ static float readshadowbuf(ShadBuf *shb, ShadSampleBuf *shsample, int bias, int ct= shsample->cbuf+ofs; rz= *( (int **)(shsample->zbuf+ofs) ); - if(*ct==3) { + if (*ct==3) { ct= ((char *)rz)+3*16*(ys & 15)+3*(xs & 15); cz= (char *)&zsamp; cz[ACOMP]= ct[0]; cz[BCOMP]= ct[1]; cz[GCOMP]= ct[2]; } - else if(*ct==2) { + else if (*ct==2) { ct= ((char *)rz); ct+= 4+2*16*(ys & 15)+2*(xs & 15); zsamp= *rz; @@ -1073,7 +1073,7 @@ static float readshadowbuf(ShadBuf *shb, ShadSampleBuf *shsample, int bias, int cz[BCOMP]= ct[0]; cz[GCOMP]= ct[1]; } - else if(*ct==1) { + else if (*ct==1) { ct= ((char *)rz); ct+= 4+16*(ys & 15)+(xs & 15); zsamp= *rz; @@ -1090,9 +1090,9 @@ static float readshadowbuf(ShadBuf *shb, ShadSampleBuf *shsample, int bias, int /* tricky stuff here; we use ints which can overflow easily with bias values */ - if(zsamp > zs) return 1.0; /* absolute no shadow */ - else if(zs < - 0x7FFFFE00 + bias) return 1.0; /* extreme close to clipstart */ - else if(zsamp < zs-bias) return 0.0 ; /* absolute in shadow */ + if (zsamp > zs) return 1.0; /* absolute no shadow */ + else if (zs < - 0x7FFFFE00 + bias) return 1.0; /* extreme close to clipstart */ + else if (zsamp < zs-bias) return 0.0; /* absolute in shadow */ else { /* soft area */ temp= ( (float)(zs- zsamp) )/(float)bias; @@ -1112,7 +1112,7 @@ static void shadowbuf_project_co(float *x, float *y, float *z, ShadBuf *shb, con *x= size*(1.0f+hco[0]/hco[3]); *y= size*(1.0f+hco[1]/hco[3]); - if(z) *z= (hco[2]/hco[3]); + if (z) *z= (hco[2]/hco[3]); } /* the externally called shadow testing (reading) function */ @@ -1126,11 +1126,11 @@ float testshadowbuf(Render *re, ShadBuf *shb, const float co[3], const float dxc short a, num; /* crash preventer */ - if(shb->buffers.first==NULL) + if (shb->buffers.first==NULL) return 1.0f; /* when facing away, assume fully in shadow */ - if(inp <= 0.0f) + if (inp <= 0.0f) return 0.0f; /* project coordinate to pixel space */ @@ -1138,9 +1138,9 @@ float testshadowbuf(Render *re, ShadBuf *shb, const float co[3], const float dxc /* clip z coordinate, z is projected so that (-1.0, 1.0) matches * (clipstart, clipend), so we can do this simple test */ - if(zs1>=1.0f) + if (zs1>=1.0f) return 0.0f; - else if(zs1<= -1.0f) + else if (zs1<= -1.0f) return 1.0f; zs= ((float)0x7FFFFFFF)*zs1; @@ -1151,15 +1151,15 @@ float testshadowbuf(Render *re, ShadBuf *shb, const float co[3], const float dxc fac= shb->soft; /* compute z bias */ - if(mat_bias!=0.0f) biasf= shb->bias*mat_bias; + if (mat_bias!=0.0f) biasf= shb->bias*mat_bias; else biasf= shb->bias; /* with inp==1.0, bias is half the size. correction value was 1.1, giving errors * on cube edges, with one side being almost frontal lighted (ton) */ bias= (1.5f-inp*inp)*biasf; /* in case of no filtering we can do things simpler */ - if(num==1) { - for(shsample= shb->buffers.first; shsample; shsample= shsample->next) + if (num==1) { + for (shsample= shb->buffers.first; shsample; shsample= shsample->next) shadfac += readshadowbuf(shb, shsample, bias, (int)xs1, (int)ys1, zs); return shadfac/(float)shb->totbuf; @@ -1178,20 +1178,20 @@ float testshadowbuf(Render *re, ShadBuf *shb, const float co[3], const float dxc xres= fac*(fabs(dx[0]) + fabs(dy[0])); yres= fac*(fabs(dx[1]) + fabs(dy[1])); - if(xres<1.0f) xres= 1.0f; - if(yres<1.0f) yres= 1.0f; + if (xres<1.0f) xres= 1.0f; + if (yres<1.0f) yres= 1.0f; /* make xs1/xs1 corner of sample area */ xs1 -= xres*0.5f; ys1 -= yres*0.5f; /* in case we have a constant value in a tile, we can do quicker lookup */ - if(xres<16.0f && yres<16.0f) { + if (xres<16.0f && yres<16.0f) { shsample= shb->buffers.first; - if(firstreadshadbuf(shb, shsample, &rz, (int)xs1, (int)ys1, 0)) { - if(firstreadshadbuf(shb, shsample, &rz, (int)(xs1+xres), (int)ys1, 1)) { - if(firstreadshadbuf(shb, shsample, &rz, (int)xs1, (int)(ys1+yres), 1)) { - if(firstreadshadbuf(shb, shsample, &rz, (int)(xs1+xres), (int)(ys1+yres), 1)) { + if (firstreadshadbuf(shb, shsample, &rz, (int)xs1, (int)ys1, 0)) { + if (firstreadshadbuf(shb, shsample, &rz, (int)(xs1+xres), (int)ys1, 1)) { + if (firstreadshadbuf(shb, shsample, &rz, (int)xs1, (int)(ys1+yres), 1)) { + if (firstreadshadbuf(shb, shsample, &rz, (int)(xs1+xres), (int)(ys1+yres), 1)) { return readshadowbuf(shb, shsample, bias,(int)xs1, (int)ys1, zs); } } @@ -1200,11 +1200,11 @@ float testshadowbuf(Render *re, ShadBuf *shb, const float co[3], const float dxc } /* full jittered shadow buffer lookup */ - for(shsample= shb->buffers.first; shsample; shsample= shsample->next) { + for (shsample= shb->buffers.first; shsample; shsample= shsample->next) { jit= shb->jit; weight= shb->weight; - for(a=num; a>0; a--, jit+=2, weight++) { + for (a=num; a>0; a--, jit+=2, weight++) { /* instead of jit i tried random: ugly! */ /* note: the plus 0.5 gives best sampling results, jit goes from -0.5 to 0.5 */ /* xs1 and ys1 are already corrected to be corner of sample area */ @@ -1232,15 +1232,15 @@ static float readshadowbuf_halo(ShadBuf *shb, ShadSampleBuf *shsample, int xs, i bias= -shb->bias; /* simpleclip */ - if(xs<0 || ys<0) return 0.0; - if(xs>=shb->size || ys>=shb->size) return 0.0; + if (xs<0 || ys<0) return 0.0; + if (xs>=shb->size || ys>=shb->size) return 0.0; /* calc z */ ofs= (ys>>4)*(shb->size>>4) + (xs>>4); ct= shsample->cbuf+ofs; rz= *( (int **)(shsample->zbuf+ofs) ); - if(*ct==3) { + if (*ct==3) { ct= ((char *)rz)+3*16*(ys & 15)+3*(xs & 15); cz= (char *)&zsamp; zsamp= 0; @@ -1248,7 +1248,7 @@ static float readshadowbuf_halo(ShadBuf *shb, ShadSampleBuf *shsample, int xs, i cz[BCOMP]= ct[1]; cz[GCOMP]= ct[2]; } - else if(*ct==2) { + else if (*ct==2) { ct= ((char *)rz); ct+= 4+2*16*(ys & 15)+2*(xs & 15); zsamp= *rz; @@ -1257,7 +1257,7 @@ static float readshadowbuf_halo(ShadBuf *shb, ShadSampleBuf *shsample, int xs, i cz[BCOMP]= ct[0]; cz[GCOMP]= ct[1]; } - else if(*ct==1) { + else if (*ct==1) { ct= ((char *)rz); ct+= 4+16*(ys & 15)+(xs & 15); zsamp= *rz; @@ -1274,16 +1274,16 @@ static float readshadowbuf_halo(ShadBuf *shb, ShadSampleBuf *shsample, int xs, i /* NO schadow when sampled at 'eternal' distance */ - if(zsamp >= 0x7FFFFE00) return 1.0; + if (zsamp >= 0x7FFFFE00) return 1.0; - if(zsamp > zs) return 1.0; /* absolute no shadww */ + if (zsamp > zs) return 1.0; /* absolute no shadww */ else { /* bias is negative, so the (zs-bias) can be beyond 0x7fffffff */ zbias= 0x7fffffff - zs; - if(zbias > -bias) { - if( zsamp < zs-bias) return 0.0 ; /* absolute in shadow */ + if (zbias > -bias) { + if ( zsamp < zs-bias) return 0.0; /* absolute in shadow */ } - else return 0.0 ; /* absolute shadow */ + else return 0.0; /* absolute shadow */ } /* soft area */ @@ -1331,8 +1331,8 @@ float shadow_halo(LampRen *lar, const float p1[3], const float p2[3]) xs1= (int)xf1; ys1= (int)yf1; - if(xf1 != xf2) { - if(xf2-xf1 > 0.0f) { + if (xf1 != xf2) { + if (xf2-xf1 > 0.0f) { labdax= (xf1-xs1-1.0f)/(xf1-xf2); ldx= -shb->shadhalostep/(xf1-xf2); dx= shb->shadhalostep; @@ -1348,8 +1348,8 @@ float shadow_halo(LampRen *lar, const float p1[3], const float p2[3]) ldx= 0.0; } - if(yf1 != yf2) { - if(yf2-yf1 > 0.0f) { + if (yf1 != yf2) { + if (yf2-yf1 > 0.0f) { labday= (yf1-ys1-1.0f)/(yf1-yf2); ldy= -shb->shadhalostep/(yf1-yf2); dy= shb->shadhalostep; @@ -1374,42 +1374,43 @@ float shadow_halo(LampRen *lar, const float p1[3], const float p2[3]) while(1) { labdao= labda; - if(labdax==labday) { + if (labdax==labday) { labdax+= ldx; x+= dx; labday+= ldy; y+= dy; } else { - if(labdax<labday) { + if (labdax<labday) { labdax+= ldx; x+= dx; - } else { + } + else { labday+= ldy; y+= dy; } } labda= MIN2(labdax, labday); - if(labda==labdao || labda>=1.0f) break; + if (labda==labdao || labda>=1.0f) break; zf= zf1 + labda*(zf2-zf1); count+= (float)shb->totbuf; - if(zf<= -1.0f) lightcount += 1.0f; /* close to the spot */ + if (zf<= -1.0f) lightcount += 1.0f; /* close to the spot */ else { /* make sure, behind the clipend we extend halolines. */ - if(zf>=1.0f) z= 0x7FFFF000; + if (zf>=1.0f) z= 0x7FFFF000; else z= (int)(0x7FFFF000*zf); - for(shsample= shb->buffers.first; shsample; shsample= shsample->next) + for (shsample= shb->buffers.first; shsample; shsample= shsample->next) lightcount+= readshadowbuf_halo(shb, shsample, x, y, z); } } - if(count!=0.0f) return (lightcount/count); + if (count!=0.0f) return (lightcount/count); return 0.0f; } @@ -1473,21 +1474,21 @@ static void init_box(Boxf *box) /* use v1 to calculate boundbox */ static void bound_boxf(Boxf *box, const float v1[3]) { - if(v1[0] < box->xmin) box->xmin = v1[0]; - if(v1[0] > box->xmax) box->xmax = v1[0]; - if(v1[1] < box->ymin) box->ymin = v1[1]; - if(v1[1] > box->ymax) box->ymax = v1[1]; - if(v1[2] < box->zmin) box->zmin= v1[2]; - if(v1[2] > box->zmax) box->zmax= v1[2]; + if (v1[0] < box->xmin) box->xmin = v1[0]; + if (v1[0] > box->xmax) box->xmax = v1[0]; + if (v1[1] < box->ymin) box->ymin = v1[1]; + if (v1[1] > box->ymax) box->ymax = v1[1]; + if (v1[2] < box->zmin) box->zmin= v1[2]; + if (v1[2] > box->zmax) box->zmax= v1[2]; } /* use v1 to calculate boundbox */ static void bound_rectf(rctf *box, const float v1[2]) { - if(v1[0] < box->xmin) box->xmin = v1[0]; - if(v1[0] > box->xmax) box->xmax = v1[0]; - if(v1[1] < box->ymin) box->ymin = v1[1]; - if(v1[1] > box->ymax) box->ymax = v1[1]; + if (v1[0] < box->xmin) box->xmin = v1[0]; + if (v1[0] > box->xmax) box->xmax = v1[0]; + if (v1[1] < box->ymin) box->ymin = v1[1]; + if (v1[1] > box->ymax) box->ymax = v1[1]; } @@ -1496,7 +1497,7 @@ static void isb_bsp_split_init(ISBBranch *root, MemArena *mem, int level) { /* if level > 0 we create new branches and go deeper*/ - if(level > 0) { + if (level > 0) { ISBBranch *left, *right; int i; @@ -1505,7 +1506,7 @@ static void isb_bsp_split_init(ISBBranch *root, MemArena *mem, int level) root->divider[1]= 0.5f*(root->box.ymin+root->box.ymax); /* find best splitpoint */ - if(root->box.xmax-root->box.xmin > root->box.ymax-root->box.ymin) + if (root->box.xmax-root->box.xmin > root->box.ymax-root->box.ymin) i= root->index= 0; else i= root->index= 1; @@ -1516,7 +1517,7 @@ static void isb_bsp_split_init(ISBBranch *root, MemArena *mem, int level) /* box info */ left->box= root->box; right->box= root->box; - if(i==0) { + if (i==0) { left->box.xmax = root->divider[0]; right->box.xmin = root->divider[0]; } @@ -1542,7 +1543,7 @@ static void isb_bsp_split(ISBBranch *root, MemArena *mem) /* splitpoint */ root->divider[0]= root->divider[1]= 0.0f; - for(a=BSPMAX_SAMPLE-1; a>=0; a--) { + for (a=BSPMAX_SAMPLE-1; a>=0; a--) { root->divider[0]+= root->samples[a]->zco[0]; root->divider[1]+= root->samples[a]->zco[1]; } @@ -1550,7 +1551,7 @@ static void isb_bsp_split(ISBBranch *root, MemArena *mem) root->divider[1]/= BSPMAX_SAMPLE; /* find best splitpoint */ - if(root->box.xmax-root->box.xmin > root->box.ymax-root->box.ymin) + if (root->box.xmax-root->box.xmin > root->box.ymax-root->box.ymin) i= root->index= 0; else i= root->index= 1; @@ -1564,15 +1565,15 @@ static void isb_bsp_split(ISBBranch *root, MemArena *mem) right->samples= samples; // tmp /* split samples */ - for(a=BSPMAX_SAMPLE-1; a>=0; a--) { + for (a=BSPMAX_SAMPLE-1; a>=0; a--) { int comp= 0; /* this prevents adding samples all to 1 branch when divider is equal to samples */ - if(root->samples[a]->zco[i] == root->divider[i]) + if (root->samples[a]->zco[i] == root->divider[i]) comp= a & 1; - else if(root->samples[a]->zco[i] < root->divider[i]) + else if (root->samples[a]->zco[i] < root->divider[i]) comp= 1; - if(comp==1) { + if (comp==1) { left->samples[left->totsamp]= root->samples[a]; left->totsamp++; } @@ -1590,7 +1591,7 @@ static void isb_bsp_split(ISBBranch *root, MemArena *mem) /* box info */ left->box= root->box; right->box= root->box; - if(i==0) { + if (i==0) { left->box.xmax = root->divider[0]; right->box.xmin = root->divider[0]; } @@ -1613,7 +1614,7 @@ static int isb_bsp_insert(ISBBranch *root, MemArena *memarena, ISBSample *sample /* going over branches until last one found */ while(bspn->left) { - if(zco[bspn->index] <= bspn->divider[bspn->index]) + if (zco[bspn->index] <= bspn->divider[bspn->index]) bspn= bspn->left; else bspn= bspn->right; @@ -1621,7 +1622,7 @@ static int isb_bsp_insert(ISBBranch *root, MemArena *memarena, ISBSample *sample } /* bspn now is the last branch */ - if(bspn->totsamp==BSPMAX_SAMPLE) { + if (bspn->totsamp==BSPMAX_SAMPLE) { printf("error in bsp branch\n"); /* only for debug, cannot happen */ return 1; } @@ -1631,8 +1632,8 @@ static int isb_bsp_insert(ISBBranch *root, MemArena *memarena, ISBSample *sample bspn->totsamp++; /* split if allowed and needed */ - if(bspn->totsamp==BSPMAX_SAMPLE) { - if(i==BSPMAX_DEPTH) { + if (bspn->totsamp==BSPMAX_SAMPLE) { + if (i==BSPMAX_DEPTH) { bspn->totsamp--; /* stop filling in... will give errors */ return 1; } @@ -1648,7 +1649,7 @@ static void bspface_init_strand(BSPFace *face) face->radline= 0.5f* len_v2v2(face->v1, face->v2); mid_v3_v3v3(face->vec1, face->v1, face->v2); - if(face->v4) + if (face->v4) mid_v3_v3v3(face->vec2, face->v3, face->v4); else copy_v3_v3(face->vec2, face->v3); @@ -1659,7 +1660,7 @@ static void bspface_init_strand(BSPFace *face) face->len= face->rc[0]*face->rc[0]+ face->rc[1]*face->rc[1]; - if(face->len!=0.0f) { + if (face->len!=0.0f) { face->radline_end= face->radline/sqrt(face->len); face->len= 1.0f/face->len; } @@ -1673,18 +1674,18 @@ static int point_behind_strand(const float p[3], BSPFace *face) /* using code from dist_to_line_segment_v2(), distance vec to line-piece */ - if(face->len==0.0f) { + if (face->len==0.0f) { rc[0]= p[0]-face->vec1[0]; rc[1]= p[1]-face->vec1[1]; dist= (float)(sqrt(rc[0]*rc[0]+ rc[1]*rc[1])); - if(dist < face->radline) + if (dist < face->radline) return 1; } else { float labda= ( face->rc[0]*(p[0]-face->vec1[0]) + face->rc[1]*(p[1]-face->vec1[1]) )*face->len; - if(labda > -face->radline_end && labda < 1.0f+face->radline_end) { + if (labda > -face->radline_end && labda < 1.0f+face->radline_end) { /* hesse for dist: */ //dist= (float)(fabs( (p[0]-vec2[0])*rc[1] + (p[1]-vec2[1])*rc[0])/len); @@ -1695,9 +1696,9 @@ static int point_behind_strand(const float p[3], BSPFace *face) rc[1]= pt[1]-p[1]; dist= (float)sqrt(rc[0]*rc[0]+ rc[1]*rc[1]); - if(dist < face->radline) { + if (dist < face->radline) { float zval= face->vec1[2] + labda*face->rc[2]; - if(p[2] > zval) + if (p[2] > zval) return 1; } } @@ -1718,7 +1719,7 @@ static int point_behind_tria2d(const float p[3], const float v1[3], const float c[1] = v3[1] - v1[1]; div = a[0]*c[1] - a[1]*c[0]; - if(div==0.0f) + if (div==0.0f) return 0; h[0] = p[0] - v1[0]; @@ -1727,13 +1728,13 @@ static int point_behind_tria2d(const float p[3], const float v1[3], const float div = 1.0f/div; u = (h[0]*c[1] - h[1]*c[0])*div; - if(u >= 0.0f) { + if (u >= 0.0f) { v = (a[0]*h[1] - a[1]*h[0])*div; - if(v >= 0.0f) { - if( u + v <= 1.0f) { + if (v >= 0.0f) { + if ( u + v <= 1.0f) { /* inside, now check if point p is behind */ float z= (1.0f-u-v)*v1[2] + u*v2[2] + v*v3[2]; - if(z <= p[2]) + if (z <= p[2]) return 1; } } @@ -1758,10 +1759,10 @@ static int rect_outside_line(rctf *rect, const float v1[3], const float v2[3], c side= a*v3[0] + b*v3[1] + c < 0.0f; /* the four quad points */ - if( side==(rect->xmin*a + rect->ymin*b + c >= 0.0f) ) - if( side==(rect->xmax*a + rect->ymin*b + c >= 0.0f) ) - if( side==(rect->xmax*a + rect->ymax*b + c >= 0.0f) ) - if( side==(rect->xmin*a + rect->ymax*b + c >= 0.0f) ) + if ( side==(rect->xmin*a + rect->ymin*b + c >= 0.0f) ) + if ( side==(rect->xmax*a + rect->ymin*b + c >= 0.0f) ) + if ( side==(rect->xmax*a + rect->ymax*b + c >= 0.0f) ) + if ( side==(rect->xmin*a + rect->ymax*b + c >= 0.0f) ) return 1; return 0; } @@ -1769,11 +1770,11 @@ static int rect_outside_line(rctf *rect, const float v1[3], const float v2[3], c /* check if one of the triangle edges separates all rect points on 1 side */ static int rect_isect_tria(rctf *rect, const float v1[3], const float v2[3], const float v3[3]) { - if(rect_outside_line(rect, v1, v2, v3)) + if (rect_outside_line(rect, v1, v2, v3)) return 0; - if(rect_outside_line(rect, v2, v3, v1)) + if (rect_outside_line(rect, v2, v3, v1)) return 0; - if(rect_outside_line(rect, v3, v1, v2)) + if (rect_outside_line(rect, v3, v1, v2)) return 0; return 1; } @@ -1784,18 +1785,18 @@ static void isb_bsp_face_inside(ISBBranch *bspn, BSPFace *face) { /* are we descending? */ - if(bspn->left) { + if (bspn->left) { /* hrmf, the box struct cannot be addressed with index */ - if(bspn->index==0) { - if(face->box.xmin <= bspn->divider[0]) + if (bspn->index==0) { + if (face->box.xmin <= bspn->divider[0]) isb_bsp_face_inside(bspn->left, face); - if(face->box.xmax > bspn->divider[0]) + if (face->box.xmax > bspn->divider[0]) isb_bsp_face_inside(bspn->right, face); } else { - if(face->box.ymin <= bspn->divider[1]) + if (face->box.ymin <= bspn->divider[1]) isb_bsp_face_inside(bspn->left, face); - if(face->box.ymax > bspn->divider[1]) + if (face->box.ymax > bspn->divider[1]) isb_bsp_face_inside(bspn->right, face); } } @@ -1803,42 +1804,42 @@ static void isb_bsp_face_inside(ISBBranch *bspn, BSPFace *face) /* else: end branch reached */ int a; - if(bspn->totsamp==0) return; + if (bspn->totsamp==0) return; /* check for nodes entirely in shadow, can be skipped */ - if(bspn->totsamp==bspn->full) + if (bspn->totsamp==bspn->full) return; /* if bsp node is entirely in front of face, give up */ - if(bspn->box.zmax < face->box.zmin) + if (bspn->box.zmax < face->box.zmin) return; /* if face boundbox is outside of branch rect, give up */ - if(0==BLI_isect_rctf((rctf *)&face->box, (rctf *)&bspn->box, NULL)) + if (0==BLI_isect_rctf((rctf *)&face->box, (rctf *)&bspn->box, NULL)) return; /* test all points inside branch */ - for(a=bspn->totsamp-1; a>=0; a--) { + for (a=bspn->totsamp-1; a>=0; a--) { ISBSample *samp= bspn->samples[a]; - if((samp->facenr!=face->facenr || samp->obi!=face->obi) && samp->shadfac) { - if(face->box.zmin < samp->zco[2]) { - if(BLI_in_rctf((rctf *)&face->box, samp->zco[0], samp->zco[1])) { + if ((samp->facenr!=face->facenr || samp->obi!=face->obi) && samp->shadfac) { + if (face->box.zmin < samp->zco[2]) { + if (BLI_in_rctf((rctf *)&face->box, samp->zco[0], samp->zco[1])) { int inshadow= 0; - if(face->type) { - if(point_behind_strand(samp->zco, face)) + if (face->type) { + if (point_behind_strand(samp->zco, face)) inshadow= 1; } - else if( point_behind_tria2d(samp->zco, face->v1, face->v2, face->v3)) + else if ( point_behind_tria2d(samp->zco, face->v1, face->v2, face->v3)) inshadow= 1; - else if(face->v4 && point_behind_tria2d(samp->zco, face->v1, face->v3, face->v4)) + else if (face->v4 && point_behind_tria2d(samp->zco, face->v1, face->v3, face->v4)) inshadow= 1; - if(inshadow) { + if (inshadow) { *(samp->shadfac) += face->shad_alpha; /* optimize; is_full means shad_alpha==4096 */ - if(*(samp->shadfac) >= 4096 || face->is_full) { + if (*(samp->shadfac) >= 4096 || face->is_full) { bspn->full++; samp->shadfac= NULL; } @@ -1853,15 +1854,15 @@ static void isb_bsp_face_inside(ISBBranch *bspn, BSPFace *face) /* based on available samples, recalculate the bounding box for bsp nodes, recursive */ static void isb_bsp_recalc_box(ISBBranch *root) { - if(root->left) { + if (root->left) { isb_bsp_recalc_box(root->left); isb_bsp_recalc_box(root->right); } - else if(root->totsamp) { + else if (root->totsamp) { int a; init_box(&root->box); - for(a=root->totsamp-1; a>=0; a--) + for (a=root->totsamp-1; a>=0; a--) bound_boxf(&root->box, root->samples[a]->zco); } } @@ -1878,7 +1879,7 @@ static void isb_bsp_test_strand(ZSpan *zspan, int obi, int zvlnr, float *v1, flo face.obi= obi; face.facenr= zvlnr & ~RE_QUAD_OFFS; face.type= R_STRAND; - if(R.osa) + if (R.osa) face.shad_alpha= (short)ceil(4096.0f*zspan->shad_alpha/(float)R.osa); else face.shad_alpha= (short)ceil(4096.0f*zspan->shad_alpha); @@ -1890,7 +1891,7 @@ static void isb_bsp_test_strand(ZSpan *zspan, int obi, int zvlnr, float *v1, flo bound_boxf(&face.box, v1); bound_boxf(&face.box, v2); bound_boxf(&face.box, v3); - if(v4) + if (v4) bound_boxf(&face.box, v4); /* optimize values */ @@ -1912,7 +1913,7 @@ static void isb_bsp_test_face(ZSpan *zspan, int obi, int zvlnr, float *v1, float face.obi= obi; face.facenr= zvlnr & ~RE_QUAD_OFFS; face.type= 0; - if(R.osa) + if (R.osa) face.shad_alpha= (short)ceil(4096.0f*zspan->shad_alpha/(float)R.osa); else face.shad_alpha= (short)ceil(4096.0f*zspan->shad_alpha); @@ -1924,7 +1925,7 @@ static void isb_bsp_test_face(ZSpan *zspan, int obi, int zvlnr, float *v1, float bound_boxf(&face.box, v1); bound_boxf(&face.box, v2); bound_boxf(&face.box, v3); - if(v4) + if (v4) bound_boxf(&face.box, v4); isb_bsp_face_inside((ISBBranch *)zspan->rectz, &face); @@ -1935,11 +1936,11 @@ static int testclip_minmax(const float ho[4], const float minmax[4]) float wco= ho[3]; int flag= 0; - if( ho[0] > minmax[1]*wco) flag = 1; - else if( ho[0]< minmax[0]*wco) flag = 2; + if ( ho[0] > minmax[1]*wco) flag = 1; + else if ( ho[0]< minmax[0]*wco) flag = 2; - if( ho[1] > minmax[3]*wco) flag |= 4; - else if( ho[1]< minmax[2]*wco) flag |= 8; + if ( ho[1] > minmax[3]*wco) flag |= 4; + else if ( ho[1]< minmax[2]*wco) flag |= 8; return flag; } @@ -1966,7 +1967,7 @@ static void isb_bsp_fillfaces(Render *re, LampRen *lar, ISBBranch *root) minmaxf[2]= (2.0f*root->box.ymin - size-2.0f)/size; minmaxf[3]= (2.0f*root->box.ymax - size+2.0f)/size; - if(lar->mode & (LA_LAYER|LA_LAYER_SHADOW)) lay= lar->lay; + if (lar->mode & (LA_LAYER|LA_LAYER_SHADOW)) lay= lar->lay; /* (ab)use zspan, since we use zbuffer clipping code */ zbuf_alloc_span(&zspan, size, size, re->clipcrop); @@ -1985,29 +1986,29 @@ static void isb_bsp_fillfaces(Render *re, LampRen *lar, ISBBranch *root) zspan.zbuffunc= isb_bsp_test_face; zspanstrand.zbuffunc= isb_bsp_test_strand; - for(i=0, obi=re->instancetable.first; obi; i++, obi=obi->next) { + for (i=0, obi=re->instancetable.first; obi; i++, obi=obi->next) { obr= obi->obr; - if(obi->flag & R_TRANSFORMED) + if (obi->flag & R_TRANSFORMED) mult_m4_m4m4(winmat, shb->persmat, obi->mat); else copy_m4_m4(winmat, shb->persmat); - for(a=0; a<obr->totvlak; a++) { + for (a=0; a<obr->totvlak; a++) { - if((a & 255)==0) vlr= obr->vlaknodes[a>>8].vlak; + if ((a & 255)==0) vlr= obr->vlaknodes[a>>8].vlak; else vlr++; /* note, these conditions are copied in shadowbuf_autoclip() */ - if(vlr->mat!= ma) { + if (vlr->mat!= ma) { ma= vlr->mat; ok= 1; - if((ma->mode & MA_SHADBUF)==0) ok= 0; - if(ma->material_type == MA_TYPE_WIRE) ok= 0; + if ((ma->mode & MA_SHADBUF)==0) ok= 0; + if (ma->material_type == MA_TYPE_WIRE) ok= 0; zspanstrand.shad_alpha= zspan.shad_alpha= ma->shad_alpha; } - if(ok && (obi->lay & lay)) { + if (ok && (obi->lay & lay)) { float hoco[4][4]; int c1, c2, c3, c4=0; int d1, d2, d3, d4=0; @@ -2017,32 +2018,32 @@ static void isb_bsp_fillfaces(Render *re, LampRen *lar, ISBBranch *root) projectvert(vlr->v1->co, winmat, hoco[0]); d1= testclip_minmax(hoco[0], minmaxf); projectvert(vlr->v2->co, winmat, hoco[1]); d2= testclip_minmax(hoco[1], minmaxf); projectvert(vlr->v3->co, winmat, hoco[2]); d3= testclip_minmax(hoco[2], minmaxf); - if(vlr->v4) { + if (vlr->v4) { projectvert(vlr->v4->co, winmat, hoco[3]); d4= testclip_minmax(hoco[3], minmaxf); } /* minmax clipping */ - if(vlr->v4) partclip= d1 & d2 & d3 & d4; + if (vlr->v4) partclip= d1 & d2 & d3 & d4; else partclip= d1 & d2 & d3; - if(partclip==0) { + if (partclip==0) { /* window clipping */ c1= testclip(hoco[0]); c2= testclip(hoco[1]); c3= testclip(hoco[2]); - if(vlr->v4) + if (vlr->v4) c4= testclip(hoco[3]); /* ***** NO WIRE YET */ - if(ma->material_type == MA_TYPE_WIRE) { - if(vlr->v4) + if (ma->material_type == MA_TYPE_WIRE) { + if (vlr->v4) zbufclipwire(&zspan, i, a+1, vlr->ec, hoco[0], hoco[1], hoco[2], hoco[3], c1, c2, c3, c4); else zbufclipwire(&zspan, i, a+1, vlr->ec, hoco[0], hoco[1], hoco[2], 0, c1, c2, c3, 0); } - else if(vlr->v4) { - if(vlr->flag & R_STRAND) + else if (vlr->v4) { + if (vlr->flag & R_STRAND) zbufclip4(&zspanstrand, i, a+1, hoco[0], hoco[1], hoco[2], hoco[3], c1, c2, c3, c4); else zbufclip4(&zspan, i, a+1, hoco[0], hoco[1], hoco[2], hoco[3], c1, c2, c3, c4); @@ -2066,7 +2067,7 @@ static int viewpixel_to_lampbuf(ShadBuf *shb, ObjectInstanceRen *obi, VlakRen *v RE_vlakren_get_normal(&R, obi, vlr, nor); copy_v3_v3(v1, vlr->v1->co); - if(obi->flag & R_TRANSFORMED) + if (obi->flag & R_TRANSFORMED) mul_m4_v3(obi->mat, v1); /* from shadepixel() */ @@ -2074,7 +2075,7 @@ static int viewpixel_to_lampbuf(ShadBuf *shb, ObjectInstanceRen *obi, VlakRen *v hoco[3]= 1.0f; /* ortho viewplane cannot intersect using view vector originating in (0,0,0) */ - if(R.r.mode & R_ORTHO) { + if (R.r.mode & R_ORTHO) { /* x and y 3d coordinate can be derived from pixel coord and winmat */ float fx= 2.0f/(R.winx*R.winmat[0][0]); float fy= 2.0f/(R.winy*R.winmat[1][1]); @@ -2083,7 +2084,7 @@ static int viewpixel_to_lampbuf(ShadBuf *shb, ObjectInstanceRen *obi, VlakRen *v hoco[1]= (y - 0.5f*R.winy)*fy - R.winmat[3][1]/R.winmat[1][1]; /* using a*x + b*y + c*z = d equation, (a b c) is normal */ - if(nor[2]!=0.0f) + if (nor[2]!=0.0f) hoco[2]= (dface - nor[0]*hoco[0] - nor[1]*hoco[1])/nor[2]; else hoco[2]= 0.0f; @@ -2110,11 +2111,11 @@ static int viewpixel_to_lampbuf(ShadBuf *shb, ObjectInstanceRen *obi, VlakRen *v /* clip We can test for -1.0/1.0 because of the properties of the * coordinate transformations. */ fac= fabs(hoco[3]); - if(hoco[0]<-fac || hoco[0]>fac) + if (hoco[0]<-fac || hoco[0]>fac) return 0; - if(hoco[1]<-fac || hoco[1]>fac) + if (hoco[1]<-fac || hoco[1]>fac) return 0; - if(hoco[2]<-fac || hoco[2]>fac) + if (hoco[2]<-fac || hoco[2]>fac) return 0; siz= 0.5f*(float)shb->size; @@ -2135,7 +2136,7 @@ static void isb_add_shadfac(ISBShadfacA **isbsapp, MemArena *mem, int obi, int f float shadfacf; /* in osa case, the samples were filled in with factor 1.0/R.osa. if fewer samples we have to correct */ - if(R.osa) + if (R.osa) shadfacf= ((float)shadfac*R.osa)/(4096.0f*samples); else shadfacf= ((float)shadfac)/(4096.0f); @@ -2144,7 +2145,7 @@ static void isb_add_shadfac(ISBShadfacA **isbsapp, MemArena *mem, int obi, int f new->obi= obi; new->facenr= facenr & ~RE_QUAD_OFFS; new->shadfac= shadfacf; - if(*isbsapp) + if (*isbsapp) new->next= (*isbsapp); else new->next= NULL; @@ -2161,25 +2162,25 @@ static int isb_add_samples(RenderPart *pa, ISBBranch *root, MemArena *memarena, /* bsp split doesn't like to handle regular sequences */ xcos= MEM_mallocN( pa->rectx*sizeof(int), "xcos"); ycos= MEM_mallocN( pa->recty*sizeof(int), "ycos"); - for(xi=0; xi<pa->rectx; xi++) + for (xi=0; xi<pa->rectx; xi++) xcos[xi]= xi; - for(yi=0; yi<pa->recty; yi++) + for (yi=0; yi<pa->recty; yi++) ycos[yi]= yi; BLI_array_randomize(xcos, sizeof(int), pa->rectx, 12345); BLI_array_randomize(ycos, sizeof(int), pa->recty, 54321); - for(sample=0; sample<(R.osa?R.osa:1); sample++) { + for (sample=0; sample<(R.osa?R.osa:1); sample++) { ISBSample *samp= samplebuf[sample], *samp1; - for(yi=0; yi<pa->recty; yi++) { + for (yi=0; yi<pa->recty; yi++) { int y= ycos[yi]; - for(xi=0; xi<pa->rectx; xi++) { + for (xi=0; xi<pa->rectx; xi++) { int x= xcos[xi]; samp1= samp + y*pa->rectx + x; - if(samp1->facenr) + if (samp1->facenr) bsp_err |= isb_bsp_insert(root, memarena, samp1); } - if(bsp_err) break; + if (bsp_err) break; } } @@ -2215,11 +2216,11 @@ static void isb_make_buffer(RenderPart *pa, LampRen *lar) BLI_memarena_use_calloc(memarena); /* samplebuf is in camera view space (pixels) */ - for(sample=0; sample<(R.osa?R.osa:1); sample++) + for (sample=0; sample<(R.osa?R.osa:1); sample++) samplebuf[sample]= MEM_callocN(sizeof(ISBSample)*pa->rectx*pa->recty, "isb samplebuf"); /* for end result, ISBSamples point to this in non OSA case, otherwise to pixstruct->shadfac */ - if(R.osa==0) + if (R.osa==0) isbdata->shadfacs= MEM_callocN(pa->rectx*pa->recty*sizeof(short), "isb shadfacs"); /* setup bsp root */ @@ -2228,34 +2229,34 @@ static void isb_make_buffer(RenderPart *pa, LampRen *lar) root.box.ymin = (float)shb->size; /* create the sample buffers */ - for(sindex=0, y=0; y<pa->recty; y++) { - for(x=0; x<pa->rectx; x++, sindex++) { + for (sindex=0, y=0; y<pa->recty; y++) { + for (x=0; x<pa->rectx; x++, sindex++) { /* this makes it a long function, but splitting it out would mean 10+ arguments */ /* first check OSA case */ - if(R.osa) { + if (R.osa) { rd= pa->rectdaps + sindex; - if(*rd) { + if (*rd) { float xs= (float)(x + pa->disprect.xmin); float ys= (float)(y + pa->disprect.ymin); - for(sample=0; sample<R.osa; sample++) { + for (sample=0; sample<R.osa; sample++) { PixStr *ps= (PixStr *)(*rd); int mask= (1<<sample); while(ps) { - if(ps->mask & mask) + if (ps->mask & mask) break; ps= ps->next; } - if(ps && ps->facenr>0) { + if (ps && ps->facenr>0) { ObjectInstanceRen *obi= &R.objectinstance[ps->obi]; ObjectRen *obr= obi->obr; VlakRen *vlr= RE_findOrAddVlak(obr, (ps->facenr-1) & RE_QUAD_MASK); samp= samplebuf[sample] + sindex; /* convert image plane pixel location to lamp buffer space */ - if(viewpixel_to_lampbuf(shb, obi, vlr, xs + R.jit[sample][0], ys + R.jit[sample][1], samp->zco)) { + if (viewpixel_to_lampbuf(shb, obi, vlr, xs + R.jit[sample][0], ys + R.jit[sample][1], samp->zco)) { samp->obi= ps->obi; samp->facenr= ps->facenr & ~RE_QUAD_OFFS; ps->shadfac= 0; @@ -2269,7 +2270,7 @@ static void isb_make_buffer(RenderPart *pa, LampRen *lar) else { rectp= pa->rectp + sindex; recto= pa->recto + sindex; - if(*rectp>0) { + if (*rectp>0) { ObjectInstanceRen *obi= &R.objectinstance[*recto]; ObjectRen *obr= obi->obr; VlakRen *vlr= RE_findOrAddVlak(obr, (*rectp-1) & RE_QUAD_MASK); @@ -2278,7 +2279,7 @@ static void isb_make_buffer(RenderPart *pa, LampRen *lar) samp= samplebuf[0] + sindex; /* convert image plane pixel location to lamp buffer space */ - if(viewpixel_to_lampbuf(shb, obi, vlr, xs, ys, samp->zco)) { + if (viewpixel_to_lampbuf(shb, obi, vlr, xs, ys, samp->zco)) { samp->obi= *recto; samp->facenr= *rectp & ~RE_QUAD_OFFS; samp->shadfac= isbdata->shadfacs + sindex; @@ -2290,7 +2291,7 @@ static void isb_make_buffer(RenderPart *pa, LampRen *lar) } /* simple method to see if we have samples */ - if(root.box.xmin != (float)shb->size) { + if (root.box.xmin != (float)shb->size) { /* now create a regular split, root.box has the initial bounding box of all pixels */ /* split bsp 8 levels deep, in regular grid (16 x 16) */ isb_bsp_split_init(&root, memarena, 8); @@ -2298,24 +2299,24 @@ static void isb_make_buffer(RenderPart *pa, LampRen *lar) /* insert all samples in BSP now */ bsp_err= isb_add_samples(pa, &root, memarena, samplebuf); - if(bsp_err==0) { + if (bsp_err==0) { /* go over all faces and fill in shadow values */ isb_bsp_fillfaces(&R, lar, &root); /* shb->persmat should have been calculated */ /* copy shadow samples to persistent buffer, reduce memory overhead */ - if(R.osa) { + if (R.osa) { ISBShadfacA **isbsa= isbdata->shadfaca= MEM_callocN(pa->rectx*pa->recty*sizeof(void *), "isb shadfacs"); isbdata->memarena = BLI_memarena_new(0x8000 * sizeof(ISBSampleA), "isb arena"); BLI_memarena_use_calloc(isbdata->memarena); - for(rd= pa->rectdaps, x=pa->rectx*pa->recty; x>0; x--, rd++, isbsa++) { + for (rd= pa->rectdaps, x=pa->rectx*pa->recty; x>0; x--, rd++, isbsa++) { - if(*rd) { + if (*rd) { PixStr *ps= (PixStr *)(*rd); while(ps) { - if(ps->shadfac) + if (ps->shadfac) isb_add_shadfac(isbsa, isbdata->memarena, ps->obi, ps->facenr, ps->shadfac, count_mask(ps->mask)); ps= ps->next; } @@ -2325,7 +2326,7 @@ static void isb_make_buffer(RenderPart *pa, LampRen *lar) } } else { - if(isbdata->shadfacs) { + if (isbdata->shadfacs) { MEM_freeN(isbdata->shadfacs); isbdata->shadfacs= NULL; } @@ -2335,10 +2336,10 @@ static void isb_make_buffer(RenderPart *pa, LampRen *lar) BLI_memarena_free(memarena); /* free samples */ - for(x=0; x<(R.osa?R.osa:1); x++) + for (x=0; x<(R.osa?R.osa:1); x++) MEM_freeN(samplebuf[x]); - if(bsp_err) printf("error in filling bsp\n"); + if (bsp_err) printf("error in filling bsp\n"); } /* add sample to buffer, isbsa is the root sample in a buffer */ @@ -2347,7 +2348,7 @@ static ISBSampleA *isb_alloc_sample_transp(ISBSampleA **isbsa, MemArena *mem) ISBSampleA *new; new= BLI_memarena_alloc(mem, sizeof(ISBSampleA)); - if(*isbsa) + if (*isbsa) new->next= (*isbsa); else new->next= NULL; @@ -2365,19 +2366,19 @@ static int isb_add_samples_transp(RenderPart *pa, ISBBranch *root, MemArena *mem /* bsp split doesn't like to handle regular sequences */ xcos= MEM_mallocN( pa->rectx*sizeof(int), "xcos"); ycos= MEM_mallocN( pa->recty*sizeof(int), "ycos"); - for(xi=0; xi<pa->rectx; xi++) + for (xi=0; xi<pa->rectx; xi++) xcos[xi]= xi; - for(yi=0; yi<pa->recty; yi++) + for (yi=0; yi<pa->recty; yi++) ycos[yi]= yi; BLI_array_randomize(xcos, sizeof(int), pa->rectx, 12345); BLI_array_randomize(ycos, sizeof(int), pa->recty, 54321); - for(sample=0; sample<(R.osa?R.osa:1); sample++) { + for (sample=0; sample<(R.osa?R.osa:1); sample++) { ISBSampleA **samp= samplebuf[sample], *samp1; - for(yi=0; yi<pa->recty; yi++) { + for (yi=0; yi<pa->recty; yi++) { int y= ycos[yi]; - for(xi=0; xi<pa->rectx; xi++) { + for (xi=0; xi<pa->rectx; xi++) { int x= xcos[xi]; samp1= *(samp + y*pa->rectx + x); @@ -2386,7 +2387,7 @@ static int isb_add_samples_transp(RenderPart *pa, ISBBranch *root, MemArena *mem samp1= samp1->next; } } - if(bsp_err) break; + if (bsp_err) break; } } @@ -2423,7 +2424,7 @@ static void isb_make_buffer_transp(RenderPart *pa, APixstr *apixbuf, LampRen *la BLI_memarena_use_calloc(memarena); /* samplebuf is in camera view space (pixels) */ - for(sample=0; sample<(R.osa?R.osa:1); sample++) + for (sample=0; sample<(R.osa?R.osa:1); sample++) samplebuf[sample]= MEM_callocN(sizeof(void *)*pa->rectx*pa->recty, "isb alpha samplebuf"); /* setup bsp root */ @@ -2432,18 +2433,18 @@ static void isb_make_buffer_transp(RenderPart *pa, APixstr *apixbuf, LampRen *la root.box.ymin = (float)shb->size; /* create the sample buffers */ - for(ap= apixbuf, sindex=0, y=0; y<pa->recty; y++) { - for(x=0; x<pa->rectx; x++, sindex++, ap++) { + for (ap= apixbuf, sindex=0, y=0; y<pa->recty; y++) { + for (x=0; x<pa->rectx; x++, sindex++, ap++) { - if(ap->p[0]) { + if (ap->p[0]) { APixstr *apn; float xs= (float)(x + pa->disprect.xmin); float ys= (float)(y + pa->disprect.ymin); - for(apn=ap; apn; apn= apn->next) { + for (apn=ap; apn; apn= apn->next) { int a; - for(a=0; a<4; a++) { - if(apn->p[a]) { + for (a=0; a<4; a++) { + if (apn->p[a]) { ObjectInstanceRen *obi= &R.objectinstance[apn->obi[a]]; ObjectRen *obr= obi->obr; VlakRen *vlr= RE_findOrAddVlak(obr, (apn->p[a]-1) & RE_QUAD_MASK); @@ -2452,14 +2453,14 @@ static void isb_make_buffer_transp(RenderPart *pa, APixstr *apixbuf, LampRen *la /* here we store shadfac, easier to create the end storage buffer. needs zero'ed, multiple shadowbufs use it */ apn->shadfac[a]= 0; - if(R.osa) { - for(sample=0; sample<R.osa; sample++) { + if (R.osa) { + for (sample=0; sample<R.osa; sample++) { int mask= (1<<sample); - if(apn->mask[a] & mask) { + if (apn->mask[a] & mask) { /* convert image plane pixel location to lamp buffer space */ - if(viewpixel_to_lampbuf(shb, obi, vlr, xs + R.jit[sample][0], ys + R.jit[sample][1], zco)) { + if (viewpixel_to_lampbuf(shb, obi, vlr, xs + R.jit[sample][0], ys + R.jit[sample][1], zco)) { samp= isb_alloc_sample_transp(samplebuf[sample] + sindex, memarena); samp->obi= apn->obi[a]; samp->facenr= apn->p[a] & ~RE_QUAD_OFFS; @@ -2474,7 +2475,7 @@ static void isb_make_buffer_transp(RenderPart *pa, APixstr *apixbuf, LampRen *la else { /* convert image plane pixel location to lamp buffer space */ - if(viewpixel_to_lampbuf(shb, obi, vlr, xs, ys, zco)) { + if (viewpixel_to_lampbuf(shb, obi, vlr, xs, ys, zco)) { samp= isb_alloc_sample_transp(samplebuf[0] + sindex, memarena); samp->obi= apn->obi[a]; @@ -2493,7 +2494,7 @@ static void isb_make_buffer_transp(RenderPart *pa, APixstr *apixbuf, LampRen *la } /* simple method to see if we have samples */ - if(root.box.xmin != (float)shb->size) { + if (root.box.xmin != (float)shb->size) { /* now create a regular split, root.box has the initial bounding box of all pixels */ /* split bsp 8 levels deep, in regular grid (16 x 16) */ isb_bsp_split_init(&root, memarena, 8); @@ -2501,7 +2502,7 @@ static void isb_make_buffer_transp(RenderPart *pa, APixstr *apixbuf, LampRen *la /* insert all samples in BSP now */ bsp_err= isb_add_samples_transp(pa, &root, memarena, samplebuf); - if(bsp_err==0) { + if (bsp_err==0) { ISBShadfacA **isbsa; /* go over all faces and fill in shadow values */ @@ -2512,15 +2513,15 @@ static void isb_make_buffer_transp(RenderPart *pa, APixstr *apixbuf, LampRen *la isbdata->memarena = BLI_memarena_new(0x8000 * sizeof(ISBSampleA), "isb arena"); - for(ap= apixbuf, x=pa->rectx*pa->recty; x>0; x--, ap++, isbsa++) { + for (ap= apixbuf, x=pa->rectx*pa->recty; x>0; x--, ap++, isbsa++) { - if(ap->p[0]) { + if (ap->p[0]) { APixstr *apn; - for(apn=ap; apn; apn= apn->next) { + for (apn=ap; apn; apn= apn->next) { int a; - for(a=0; a<4; a++) { - if(apn->p[a] && apn->shadfac[a]) { - if(R.osa) + for (a=0; a<4; a++) { + if (apn->p[a] && apn->shadfac[a]) { + if (R.osa) isb_add_shadfac(isbsa, isbdata->memarena, apn->obi[a], apn->p[a], apn->shadfac[a], count_mask(apn->mask[a])); else isb_add_shadfac(isbsa, isbdata->memarena, apn->obi[a], apn->p[a], apn->shadfac[a], 0); @@ -2536,10 +2537,10 @@ static void isb_make_buffer_transp(RenderPart *pa, APixstr *apixbuf, LampRen *la BLI_memarena_free(memarena); /* free samples */ - for(x=0; x<(R.osa?R.osa:1); x++) + for (x=0; x<(R.osa?R.osa:1); x++) MEM_freeN(samplebuf[x]); - if(bsp_err) printf("error in filling bsp\n"); + if (bsp_err) printf("error in filling bsp\n"); } @@ -2551,18 +2552,18 @@ static void isb_make_buffer_transp(RenderPart *pa, APixstr *apixbuf, LampRen *la float ISB_getshadow(ShadeInput *shi, ShadBuf *shb) { /* if raytracing, we can't accept irregular shadow */ - if(shi->depth==0) { + if (shi->depth==0) { ISBData *isbdata= shb->isb_result[shi->thread]; - if(isbdata) { - if(isbdata->shadfacs || isbdata->shadfaca) { + if (isbdata) { + if (isbdata->shadfacs || isbdata->shadfaca) { int x= shi->xs - isbdata->minx; - if(x >= 0 && x < isbdata->rectx) { + if (x >= 0 && x < isbdata->rectx) { int y= shi->ys - isbdata->miny; - if(y >= 0 && y < isbdata->recty) { - if(isbdata->shadfacs) { + if (y >= 0 && y < isbdata->recty) { + if (isbdata->shadfacs) { short *sp= isbdata->shadfacs + y*isbdata->rectx + x; return *sp>=4096?0.0f:1.0f - ((float)*sp)/4096.0f; } @@ -2572,7 +2573,7 @@ float ISB_getshadow(ShadeInput *shi, ShadBuf *shb) ISBShadfacA *isbsa= *(isbdata->shadfaca + sindex); while(isbsa) { - if(isbsa->facenr==shi->facenr+1 && isbsa->obi==obi) + if (isbsa->facenr==shi->facenr+1 && isbsa->obi==obi) return isbsa->shadfac>=1.0f?0.0f:1.0f - isbsa->shadfac; isbsa= isbsa->next; } @@ -2591,15 +2592,15 @@ void ISB_create(RenderPart *pa, APixstr *apixbuf) GroupObject *go; /* go over all lamps, and make the irregular buffers */ - for(go=R.lights.first; go; go= go->next) { + for (go=R.lights.first; go; go= go->next) { LampRen *lar= go->lampren; - if(lar->type==LA_SPOT && lar->shb && lar->buftype==LA_SHADBUF_IRREGULAR) { + if (lar->type==LA_SPOT && lar->shb && lar->buftype==LA_SHADBUF_IRREGULAR) { /* create storage for shadow, per thread */ lar->shb->isb_result[pa->thread]= MEM_callocN(sizeof(ISBData), "isb data"); - if(apixbuf) + if (apixbuf) isb_make_buffer_transp(pa, apixbuf, lar); else isb_make_buffer(pa, lar); @@ -2614,19 +2615,19 @@ void ISB_free(RenderPart *pa) GroupObject *go; /* go over all lamps, and free the irregular buffers */ - for(go=R.lights.first; go; go= go->next) { + for (go=R.lights.first; go; go= go->next) { LampRen *lar= go->lampren; - if(lar->type==LA_SPOT && lar->shb && lar->buftype==LA_SHADBUF_IRREGULAR) { + if (lar->type==LA_SPOT && lar->shb && lar->buftype==LA_SHADBUF_IRREGULAR) { ISBData *isbdata= lar->shb->isb_result[pa->thread]; - if(isbdata) { - if(isbdata->shadfacs) + if (isbdata) { + if (isbdata->shadfacs) MEM_freeN(isbdata->shadfacs); - if(isbdata->shadfaca) + if (isbdata->shadfaca) MEM_freeN(isbdata->shadfaca); - if(isbdata->memarena) + if (isbdata->memarena) BLI_memarena_free(isbdata->memarena); MEM_freeN(isbdata); diff --git a/source/blender/render/intern/source/shadeinput.c b/source/blender/render/intern/source/shadeinput.c index 29c1318727c..611c21cf0f2 100644 --- a/source/blender/render/intern/source/shadeinput.c +++ b/source/blender/render/intern/source/shadeinput.c @@ -108,7 +108,7 @@ void shade_material_loop(ShadeInput *shi, ShadeResult *shr) shade_lamp_loop(shi, shr); /* clears shr */ - if(shi->translucency!=0.0f) { + if (shi->translucency!=0.0f) { ShadeResult shr_t; float fac= shi->translucency; @@ -121,11 +121,11 @@ void shade_material_loop(ShadeInput *shi, ShadeResult *shr) /* a couple of passes */ VECADDISFAC(shr->combined, shr_t.combined, fac); - if(shi->passflag & SCE_PASS_SPEC) + if (shi->passflag & SCE_PASS_SPEC) VECADDISFAC(shr->spec, shr_t.spec, fac); - if(shi->passflag & SCE_PASS_DIFFUSE) + if (shi->passflag & SCE_PASS_DIFFUSE) VECADDISFAC(shr->diff, shr_t.diff, fac); - if(shi->passflag & SCE_PASS_SHADOW) + if (shi->passflag & SCE_PASS_SHADOW) VECADDISFAC(shr->shad, shr_t.shad, fac); negate_v3(shi->vn); @@ -133,20 +133,20 @@ void shade_material_loop(ShadeInput *shi, ShadeResult *shr) } /* depth >= 1 when ray-shading */ - if(shi->depth==0 || shi->volume_depth > 0) { - if(R.r.mode & R_RAYTRACE) { - if(shi->ray_mirror!=0.0f || ((shi->mode & MA_TRANSP) && (shi->mode & MA_RAYTRANSP) && shr->alpha!=1.0f)) { + if (shi->depth==0 || shi->volume_depth > 0) { + if (R.r.mode & R_RAYTRACE) { + if (shi->ray_mirror!=0.0f || ((shi->mode & MA_TRANSP) && (shi->mode & MA_RAYTRANSP) && shr->alpha!=1.0f)) { /* ray trace works on combined, but gives pass info */ ray_trace(shi, shr); } } /* disable adding of sky for raytransp */ - if((shi->mode & MA_TRANSP) && (shi->mode & MA_RAYTRANSP)) - if((shi->layflag & SCE_LAY_SKY) && (R.r.alphamode==R_ADDSKY)) + if ((shi->mode & MA_TRANSP) && (shi->mode & MA_RAYTRANSP)) + if ((shi->layflag & SCE_LAY_SKY) && (R.r.alphamode==R_ADDSKY)) shr->alpha= 1.0f; } - if(R.r.mode & R_RAYTRACE) { + if (R.r.mode & R_RAYTRACE) { if (R.render_volumes_inside.first) shade_volume_inside(shi, shr); } @@ -163,7 +163,7 @@ void shade_input_do_shade(ShadeInput *shi, ShadeResult *shr) memset(&shi->raycounter, 0, sizeof(shi->raycounter)); #endif - if(shi->mat->nodetree && shi->mat->use_nodes) { + if (shi->mat->nodetree && shi->mat->use_nodes) { ntreeShaderExecTree(shi->mat->nodetree, shi, shr); } else { @@ -171,36 +171,37 @@ void shade_input_do_shade(ShadeInput *shi, ShadeResult *shr) shade_input_init_material(shi); if (shi->mat->material_type == MA_TYPE_VOLUME) { - if(R.r.mode & R_RAYTRACE) { + if (R.r.mode & R_RAYTRACE) { shade_volume_outside(shi, shr); } - } else { /* MA_TYPE_SURFACE, MA_TYPE_WIRE */ + } + else { /* MA_TYPE_SURFACE, MA_TYPE_WIRE */ shade_material_loop(shi, shr); } } /* copy additional passes */ - if(shi->passflag & (SCE_PASS_VECTOR|SCE_PASS_NORMAL)) { + if (shi->passflag & (SCE_PASS_VECTOR|SCE_PASS_NORMAL)) { copy_v4_v4(shr->winspeed, shi->winspeed); copy_v3_v3(shr->nor, shi->vn); } /* MIST */ - if((shi->passflag & SCE_PASS_MIST) || ((R.wrld.mode & WO_MIST) && (shi->mat->mode & MA_NOMIST)==0)) { - if(R.r.mode & R_ORTHO) + if ((shi->passflag & SCE_PASS_MIST) || ((R.wrld.mode & WO_MIST) && (shi->mat->mode & MA_NOMIST)==0)) { + if (R.r.mode & R_ORTHO) shr->mist= mistfactor(-shi->co[2], shi->co); else shr->mist= mistfactor(len_v3(shi->co), shi->co); } else shr->mist= 0.0f; - if((R.wrld.mode & WO_MIST) && (shi->mat->mode & MA_NOMIST)==0 ) { + if ((R.wrld.mode & WO_MIST) && (shi->mat->mode & MA_NOMIST)==0 ) { alpha= shr->mist; } else alpha= 1.0f; /* add mist and premul color */ - if(shr->alpha!=1.0f || alpha!=1.0f) { + if (shr->alpha!=1.0f || alpha!=1.0f) { float fac= alpha*(shr->alpha); shr->combined[3]= fac; @@ -215,7 +216,7 @@ void shade_input_do_shade(ShadeInput *shi, ShadeResult *shr) /* RAYHITS */ #if 0 - if(1 || shi->passflag & SCE_PASS_RAYHITS) { + if (1 || shi->passflag & SCE_PASS_RAYHITS) { shr->rayhits[0] = (float)shi->raycounter.faces.test; shr->rayhits[1] = (float)shi->raycounter.bb.hit; shr->rayhits[2] = 0.0; @@ -240,15 +241,15 @@ void vlr_set_uv_indices(VlakRen *vlr, int *i1, int *i2, int *i3) /* 1---2 1---2 0 = orig face, 1 = new face */ /* Update vert nums to point to correct verts of original face */ - if(vlr->flag & R_DIVIDE_24) { - if(vlr->flag & R_FACE_SPLIT) { + if (vlr->flag & R_DIVIDE_24) { + if (vlr->flag & R_FACE_SPLIT) { (*i1)++; (*i2)++; (*i3)++; } else { (*i3)++; } } - else if(vlr->flag & R_FACE_SPLIT) { + else if (vlr->flag & R_FACE_SPLIT) { (*i2)++; (*i3)++; } } @@ -282,12 +283,12 @@ void shade_input_set_triangle_i(ShadeInput *shi, ObjectInstanceRen *obi, VlakRen RE_vlakren_get_normal(&R, obi, vlr, shi->facenor); /* calculate vertexnormals */ - if(vlr->flag & R_SMOOTH) { + if (vlr->flag & R_SMOOTH) { copy_v3_v3(shi->n1, shi->v1->n); copy_v3_v3(shi->n2, shi->v2->n); copy_v3_v3(shi->n3, shi->v3->n); - if(obi->flag & R_TRANSFORMED) { + if (obi->flag & R_TRANSFORMED) { mul_m3_v3(obi->nmat, shi->n1); normalize_v3(shi->n1); mul_m3_v3(obi->nmat, shi->n2); normalize_v3(shi->n2); mul_m3_v3(obi->nmat, shi->n3); normalize_v3(shi->n3); @@ -302,14 +303,14 @@ void shade_input_set_triangle_i(ShadeInput *shi, ObjectInstanceRen *obi, VlakRen /* copy data from face to ShadeInput, scanline case */ void shade_input_set_triangle(ShadeInput *shi, volatile int obi, volatile int facenr, int UNUSED(normal_flip)) { - if(facenr>0) { + if (facenr>0) { shi->obi= &R.objectinstance[obi]; shi->obr= shi->obi->obr; shi->facenr= (facenr-1) & RE_QUAD_MASK; - if( shi->facenr < shi->obr->totvlak ) { + if ( shi->facenr < shi->obr->totvlak ) { VlakRen *vlr= RE_findOrAddVlak(shi->obr, shi->facenr); - if(facenr & RE_QUAD_OFFS) + if (facenr & RE_QUAD_OFFS) shade_input_set_triangle_i(shi, shi->obi, vlr, 0, 2, 3); else shade_input_set_triangle_i(shi, shi->obi, vlr, 0, 1, 2); @@ -345,7 +346,7 @@ void shade_input_set_strand(ShadeInput *shi, StrandRen *strand, StrandPoint *spo shi->xs= (int)spoint->x; shi->ys= (int)spoint->y; - if(shi->osatex || (R.r.mode & R_SHADOW)) { + if (shi->osatex || (R.r.mode & R_SHADOW)) { copy_v3_v3(shi->dxco, spoint->dtco); copy_v3_v3(shi->dyco, spoint->dsco); } @@ -356,7 +357,7 @@ void shade_input_set_strand(ShadeInput *shi, StrandRen *strand, StrandPoint *spo copy_v3_v3(shi->facenor, spoint->nor); /* shade_input_set_normals equivalent */ - if(shi->mat->mode & MA_TANGENT_STR) { + if (shi->mat->mode & MA_TANGENT_STR) { copy_v3_v3(shi->vn, spoint->tan); } else { @@ -366,7 +367,7 @@ void shade_input_set_strand(ShadeInput *shi, StrandRen *strand, StrandPoint *spo cross_v3_v3v3(shi->vn, cross, spoint->tan); normalize_v3(shi->vn); - if(dot_v3v3(shi->vn, shi->view) < 0.0f) + if (dot_v3v3(shi->vn, shi->view) < 0.0f) negate_v3(shi->vn); } @@ -381,57 +382,57 @@ void shade_input_set_strand_texco(ShadeInput *shi, StrandRen *strand, StrandVert int mode= shi->mode; /* or-ed result for all nodes */ short texco= shi->mat->texco; - if((shi->mat->texco & TEXCO_REFL)) { + if ((shi->mat->texco & TEXCO_REFL)) { /* shi->dxview, shi->dyview, not supported */ } - if(shi->osatex && (texco & (TEXCO_NORM|TEXCO_REFL))) { + if (shi->osatex && (texco & (TEXCO_NORM|TEXCO_REFL))) { /* not supported */ } - if(mode & (MA_TANGENT_V|MA_NORMAP_TANG)) { + if (mode & (MA_TANGENT_V|MA_NORMAP_TANG)) { copy_v3_v3(shi->tang, spoint->tan); copy_v3_v3(shi->nmaptang, spoint->tan); } - if(mode & MA_STR_SURFDIFF) { + if (mode & MA_STR_SURFDIFF) { float *surfnor= RE_strandren_get_surfnor(obr, strand, 0); - if(surfnor) + if (surfnor) copy_v3_v3(shi->surfnor, surfnor); else copy_v3_v3(shi->surfnor, shi->vn); - if(shi->mat->strand_surfnor > 0.0f) { + if (shi->mat->strand_surfnor > 0.0f) { shi->surfdist= 0.0f; - for(sv=strand->vert; sv!=svert; sv++) + for (sv=strand->vert; sv!=svert; sv++) shi->surfdist+=len_v3v3(sv->co, (sv+1)->co); shi->surfdist += spoint->t*len_v3v3(sv->co, (sv+1)->co); } } - if(R.r.mode & R_SPEED) { + if (R.r.mode & R_SPEED) { float *speed; speed= RE_strandren_get_winspeed(shi->obi, strand, 0); - if(speed) + if (speed) copy_v4_v4(shi->winspeed, speed); else shi->winspeed[0]= shi->winspeed[1]= shi->winspeed[2]= shi->winspeed[3]= 0.0f; } /* shade_input_set_shade_texco equivalent */ - if(texco & NEED_UV) { - if(texco & TEXCO_ORCO) { + if (texco & NEED_UV) { + if (texco & TEXCO_ORCO) { copy_v3_v3(shi->lo, strand->orco); /* no shi->osatex, orco derivatives are zero */ } - if(texco & TEXCO_GLOB) { + if (texco & TEXCO_GLOB) { copy_v3_v3(shi->gl, shi->co); mul_m4_v3(R.viewinv, shi->gl); - if(shi->osatex) { + if (shi->osatex) { copy_v3_v3(shi->dxgl, shi->dxco); mul_mat3_m4_v3(R.viewinv, shi->dxgl); copy_v3_v3(shi->dygl, shi->dyco); @@ -439,16 +440,16 @@ void shade_input_set_strand_texco(ShadeInput *shi, StrandRen *strand, StrandVert } } - if(texco & TEXCO_STRAND) { + if (texco & TEXCO_STRAND) { shi->strandco= spoint->strandco; - if(shi->osatex) { + if (shi->osatex) { shi->dxstrand= spoint->dtstrandco; shi->dystrand= 0.0f; } } - if((texco & TEXCO_UV) || (mode & (MA_VERTEXCOL|MA_VERTEXCOLP|MA_FACETEXTURE))) { + if ((texco & TEXCO_UV) || (mode & (MA_VERTEXCOL|MA_VERTEXCOLP|MA_FACETEXTURE))) { MCol *mcol; float *uv; char *name; @@ -459,7 +460,7 @@ void shade_input_set_strand_texco(ShadeInput *shi, StrandRen *strand, StrandVert shi->actuv= obr->actmtface; shi->actcol= obr->actmcol; - if(mode & (MA_VERTEXCOL|MA_VERTEXCOLP)) { + if (mode & (MA_VERTEXCOL|MA_VERTEXCOLP)) { for (i=0; (mcol=RE_strandren_get_mcol(obr, strand, i, &name, 0)); i++) { ShadeInputCol *scol= &shi->col[i]; char *cp= (char*)mcol; @@ -473,7 +474,7 @@ void shade_input_set_strand_texco(ShadeInput *shi, StrandRen *strand, StrandVert scol->col[3]= cp[0]/255.0f; } - if(shi->totcol) { + if (shi->totcol) { shi->vcol[0]= shi->col[shi->actcol].col[0]; shi->vcol[1]= shi->col[shi->actcol].col[1]; shi->vcol[2]= shi->col[shi->actcol].col[2]; @@ -493,7 +494,7 @@ void shade_input_set_strand_texco(ShadeInput *shi, StrandRen *strand, StrandVert shi->totuv++; suv->name= name; - if(strandbuf->overrideuv == i) { + if (strandbuf->overrideuv == i) { suv->uv[0]= -1.0f; suv->uv[1]= spoint->strandco; suv->uv[2]= 0.0f; @@ -504,15 +505,15 @@ void shade_input_set_strand_texco(ShadeInput *shi, StrandRen *strand, StrandVert suv->uv[2]= 0.0f; /* texture.c assumes there are 3 coords */ } - if(shi->osatex) { + if (shi->osatex) { suv->dxuv[0]= 0.0f; suv->dxuv[1]= 0.0f; suv->dyuv[0]= 0.0f; suv->dyuv[1]= 0.0f; } - if((mode & MA_FACETEXTURE) && i==obr->actmtface) { - if((mode & (MA_VERTEXCOL|MA_VERTEXCOLP))==0) { + if ((mode & MA_FACETEXTURE) && i==obr->actmtface) { + if ((mode & (MA_VERTEXCOL|MA_VERTEXCOLP))==0) { shi->vcol[0]= 1.0f; shi->vcol[1]= 1.0f; shi->vcol[2]= 1.0f; @@ -521,14 +522,14 @@ void shade_input_set_strand_texco(ShadeInput *shi, StrandRen *strand, StrandVert } } - if(shi->totuv == 0) { + if (shi->totuv == 0) { ShadeInputUV *suv= &shi->uv[0]; suv->uv[0]= 0.0f; suv->uv[1]= spoint->strandco; suv->uv[2]= 0.0f; /* texture.c assumes there are 3 coords */ - if(mode & MA_FACETEXTURE) { + if (mode & MA_FACETEXTURE) { /* no tface? set at 1.0f */ shi->vcol[0]= 1.0f; shi->vcol[1]= 1.0f; @@ -539,18 +540,18 @@ void shade_input_set_strand_texco(ShadeInput *shi, StrandRen *strand, StrandVert } - if(texco & TEXCO_NORM) { + if (texco & TEXCO_NORM) { shi->orn[0]= -shi->vn[0]; shi->orn[1]= -shi->vn[1]; shi->orn[2]= -shi->vn[2]; } - if(texco & TEXCO_STRESS) { + if (texco & TEXCO_STRESS) { /* not supported */ } - if(texco & TEXCO_TANGENT) { - if((mode & MA_TANGENT_V)==0) { + if (texco & TEXCO_TANGENT) { + if ((mode & MA_TANGENT_V)==0) { /* just prevent surprises */ shi->tang[0]= shi->tang[1]= shi->tang[2]= 0.0f; shi->nmaptang[0]= shi->nmaptang[1]= shi->nmaptang[2]= 0.0f; @@ -559,14 +560,14 @@ void shade_input_set_strand_texco(ShadeInput *shi, StrandRen *strand, StrandVert } /* this only avalailable for scanline renders */ - if(shi->depth==0) { - if(texco & TEXCO_WINDOW) { + if (shi->depth==0) { + if (texco & TEXCO_WINDOW) { shi->winco[0]= -1.0f + 2.0f*spoint->x/(float)R.winx; shi->winco[1]= -1.0f + 2.0f*spoint->y/(float)R.winy; shi->winco[2]= 0.0f; /* not supported */ - if(shi->osatex) { + if (shi->osatex) { shi->dxwin[0]= 0.0f; shi->dywin[1]= 0.0f; shi->dxwin[0]= 0.0f; @@ -574,13 +575,13 @@ void shade_input_set_strand_texco(ShadeInput *shi, StrandRen *strand, StrandVert } } - if(texco & TEXCO_STICKY) { + if (texco & TEXCO_STICKY) { /* not supported */ } } if (shi->do_manage) { - if(mode & (MA_VERTEXCOL|MA_VERTEXCOLP|MA_FACETEXTURE)) { + if (mode & (MA_VERTEXCOL|MA_VERTEXCOLP|MA_FACETEXTURE)) { srgb_to_linearrgb_v3_v3(shi->vcol, shi->vcol); } } @@ -593,10 +594,10 @@ void shade_input_calc_viewco(ShadeInput *shi, float x, float y, float z, float v /* returns not normalized, so is in viewplane coords */ calc_view_vector(view, x, y); - if(shi->mat->material_type == MA_TYPE_WIRE) { + if (shi->mat->material_type == MA_TYPE_WIRE) { /* wire cannot use normal for calculating shi->co, so * we reconstruct the coordinate less accurate */ - if(R.r.mode & R_ORTHO) + if (R.r.mode & R_ORTHO) calc_renderco_ortho(co, x, y, z); else calc_renderco_zbuf(co, view, z); @@ -606,13 +607,13 @@ void shade_input_calc_viewco(ShadeInput *shi, float x, float y, float z, float v float fac, dface, v1[3]; copy_v3_v3(v1, shi->v1->co); - if(shi->obi->flag & R_TRANSFORMED) + if (shi->obi->flag & R_TRANSFORMED) mul_m4_v3(shi->obi->mat, v1); dface = dot_v3v3(v1, shi->facenor); /* ortho viewplane cannot intersect using view vector originating in (0,0,0) */ - if(R.r.mode & R_ORTHO) { + if (R.r.mode & R_ORTHO) { /* x and y 3d coordinate can be derived from pixel coord and winmat */ float fx= 2.0f/(R.winx*R.winmat[0][0]); float fy= 2.0f/(R.winy*R.winmat[1][1]); @@ -621,28 +622,28 @@ void shade_input_calc_viewco(ShadeInput *shi, float x, float y, float z, float v co[1]= (y - 0.5f*R.winy)*fy - R.winmat[3][1]/R.winmat[1][1]; /* using a*x + b*y + c*z = d equation, (a b c) is normal */ - if(shi->facenor[2]!=0.0f) + if (shi->facenor[2]!=0.0f) co[2]= (dface - shi->facenor[0]*co[0] - shi->facenor[1]*co[1])/shi->facenor[2]; else co[2]= 0.0f; - if(dxco && dyco) { + if (dxco && dyco) { dxco[0]= fx; dxco[1]= 0.0f; - if(shi->facenor[2]!=0.0f) + if (shi->facenor[2]!=0.0f) dxco[2]= -(shi->facenor[0]*fx)/shi->facenor[2]; else dxco[2]= 0.0f; dyco[0]= 0.0f; dyco[1]= fy; - if(shi->facenor[2]!=0.0f) + if (shi->facenor[2]!=0.0f) dyco[2]= -(shi->facenor[1]*fy)/shi->facenor[2]; else dyco[2]= 0.0f; - if(dxyview) { - if(co[2]!=0.0f) fac= 1.0f/co[2]; else fac= 0.0f; + if (dxyview) { + if (co[2]!=0.0f) fac= 1.0f/co[2]; else fac= 0.0f; dxyview[0]= -R.viewdx*fac; dxyview[1]= -R.viewdy*fac; } @@ -660,7 +661,7 @@ void shade_input_calc_viewco(ShadeInput *shi, float x, float y, float z, float v co[2]= fac*view[2]; /* pixel dx/dy for render coord */ - if(dxco && dyco) { + if (dxco && dyco) { float u= dface/(div - R.viewdx*shi->facenor[0]); float v= dface/(div - R.viewdy*shi->facenor[1]); @@ -672,8 +673,8 @@ void shade_input_calc_viewco(ShadeInput *shi, float x, float y, float z, float v dyco[1]= co[1]- (view[1]-R.viewdy)*v; dyco[2]= co[2]- (view[2])*v; - if(dxyview) { - if(fac!=0.0f) fac= 1.0f/fac; + if (dxyview) { + if (fac!=0.0f) fac= 1.0f/fac; dxyview[0]= -R.viewdx*fac; dxyview[1]= -R.viewdy*fac; } @@ -704,11 +705,11 @@ void shade_input_set_viewco(ShadeInput *shi, float x, float y, float xs, float y shi->scanco[2]= z; /* check if we need derivatives */ - if(shi->osatex || (R.r.mode & R_SHADOW)) { + if (shi->osatex || (R.r.mode & R_SHADOW)) { dxco= shi->dxco; dyco= shi->dyco; - if((shi->mat->texco & TEXCO_REFL)) + if ((shi->mat->texco & TEXCO_REFL)) dxyview= &shi->dxview; } @@ -720,27 +721,27 @@ void shade_input_set_uv(ShadeInput *shi) { VlakRen *vlr= shi->vlr; - if((vlr->flag & R_SMOOTH) || (shi->mat->texco & NEED_UV) || (shi->passflag & SCE_PASS_UV)) { + if ((vlr->flag & R_SMOOTH) || (shi->mat->texco & NEED_UV) || (shi->passflag & SCE_PASS_UV)) { float v1[3], v2[3], v3[3]; copy_v3_v3(v1, shi->v1->co); copy_v3_v3(v2, shi->v2->co); copy_v3_v3(v3, shi->v3->co); - if(shi->obi->flag & R_TRANSFORMED) { + if (shi->obi->flag & R_TRANSFORMED) { mul_m4_v3(shi->obi->mat, v1); mul_m4_v3(shi->obi->mat, v2); mul_m4_v3(shi->obi->mat, v3); } /* exception case for wire render of edge */ - if(vlr->v2==vlr->v3) { + if (vlr->v2==vlr->v3) { float lend, lenc; lend= len_v3v3(v2, v1); lenc= len_v3v3(shi->co, v1); - if(lend==0.0f) { + if (lend==0.0f) { shi->u=shi->v= 0.0f; } else { @@ -748,7 +749,7 @@ void shade_input_set_uv(ShadeInput *shi) shi->v= 0.0f; } - if(shi->osatex) { + if (shi->osatex) { shi->dx_u= 0.0f; shi->dx_v= 0.0f; shi->dy_u= 0.0f; @@ -774,7 +775,7 @@ void shade_input_set_uv(ShadeInput *shi) shi->u= (shi->co[axis1]-v3[axis1])*t11-(shi->co[axis2]-v3[axis2])*t10; shi->v= (shi->co[axis2]-v3[axis2])*t00-(shi->co[axis1]-v3[axis1])*t01; - if(shi->osatex) { + if (shi->osatex) { shi->dx_u= shi->dxco[axis1]*t11- shi->dxco[axis2]*t10; shi->dx_v= shi->dxco[axis2]*t00- shi->dxco[axis1]*t01; shi->dy_u= shi->dyco[axis1]*t11- shi->dyco[axis2]*t10; @@ -796,18 +797,18 @@ void shade_input_set_normals(ShadeInput *shi) shi->flippednor = 0; /* test flip normals to viewing direction */ - if(!(shi->vlr->flag & R_TANGENT)) { - if(dot_v3v3(shi->facenor, shi->view) < 0.0f) { + if (!(shi->vlr->flag & R_TANGENT)) { + if (dot_v3v3(shi->facenor, shi->view) < 0.0f) { negate_v3(shi->facenor); shi->flippednor= 1; } } /* calculate vertexnormals */ - if(shi->vlr->flag & R_SMOOTH) { + if (shi->vlr->flag & R_SMOOTH) { float *n1= shi->n1, *n2= shi->n2, *n3= shi->n3; - if(shi->flippednor) { + if (shi->flippednor) { negate_v3(n1); negate_v3(n2); negate_v3(n3); @@ -831,8 +832,8 @@ void shade_input_set_normals(ShadeInput *shi) copy_v3_v3(shi->vno, shi->vn); /* flip normals to viewing direction */ - if(!(shi->vlr->flag & R_TANGENT)) - if(dot_v3v3(shi->facenor, shi->view) < 0.0f) + if (!(shi->vlr->flag & R_TANGENT)) + if (dot_v3v3(shi->facenor, shi->view) < 0.0f) shade_input_flip_normals(shi); } @@ -843,7 +844,7 @@ void shade_input_set_vertex_normals(ShadeInput *shi) float l= 1.0f+u+v; /* calculate vertexnormals */ - if(shi->vlr->flag & R_SMOOTH) { + if (shi->vlr->flag & R_SMOOTH) { float *n1= shi->n1, *n2= shi->n2, *n3= shi->n3; shi->vn[0]= l*n3[0]-u*n1[0]-v*n2[0]; @@ -898,9 +899,9 @@ void shade_input_set_shade_texco(ShadeInput *shi) short texco= shi->mat->texco; /* calculate dxno */ - if(shi->vlr->flag & R_SMOOTH) { + if (shi->vlr->flag & R_SMOOTH) { - if(shi->osatex && (texco & (TEXCO_NORM|TEXCO_REFL)) ) { + if (shi->osatex && (texco & (TEXCO_NORM|TEXCO_REFL)) ) { float *n1= shi->n1, *n2= shi->n2, *n3= shi->n3; dl= shi->dx_u+shi->dx_v; @@ -920,7 +921,7 @@ void shade_input_set_shade_texco(ShadeInput *shi) float *tangent, *s1, *s2, *s3; float tl, tu, tv; - if(shi->vlr->flag & R_SMOOTH) { + if (shi->vlr->flag & R_SMOOTH) { tl= l; tu= u; tv= v; @@ -936,17 +937,17 @@ void shade_input_set_shade_texco(ShadeInput *shi) shi->tang[0]= shi->tang[1]= shi->tang[2]= 0.0f; shi->nmaptang[0]= shi->nmaptang[1]= shi->nmaptang[2]= 0.0f; - if(mode & MA_TANGENT_V) { + if (mode & MA_TANGENT_V) { s1 = RE_vertren_get_tangent(obr, v1, 0); s2 = RE_vertren_get_tangent(obr, v2, 0); s3 = RE_vertren_get_tangent(obr, v3, 0); - if(s1 && s2 && s3) { + if (s1 && s2 && s3) { shi->tang[0]= (tl*s3[0] - tu*s1[0] - tv*s2[0]); shi->tang[1]= (tl*s3[1] - tu*s1[1] - tv*s2[1]); shi->tang[2]= (tl*s3[2] - tu*s1[2] - tv*s2[2]); - if(obi->flag & R_TRANSFORMED) + if (obi->flag & R_TRANSFORMED) mul_m3_v3(obi->nmat, shi->tang); normalize_v3(shi->tang); @@ -954,10 +955,10 @@ void shade_input_set_shade_texco(ShadeInput *shi) } } - if(mode & MA_NORMAP_TANG || R.flag & R_NEED_TANGENT) { + if (mode & MA_NORMAP_TANG || R.flag & R_NEED_TANGENT) { tangent= RE_vlakren_get_nmap_tangent(obr, shi->vlr, 0); - if(tangent) { + if (tangent) { int j1= shi->i1, j2= shi->i2, j3= shi->i3; float c0[3], c1[3], c2[3]; @@ -988,12 +989,12 @@ void shade_input_set_shade_texco(ShadeInput *shi) } } - if(mode & MA_STR_SURFDIFF) { + if (mode & MA_STR_SURFDIFF) { float *surfnor= RE_vlakren_get_surfnor(obr, shi->vlr, 0); - if(surfnor) { + if (surfnor) { copy_v3_v3(shi->surfnor, surfnor); - if(obi->flag & R_TRANSFORMED) + if (obi->flag & R_TRANSFORMED) mul_m3_v3(obi->nmat, shi->surfnor); } else @@ -1002,13 +1003,13 @@ void shade_input_set_shade_texco(ShadeInput *shi) shi->surfdist= 0.0f; } - if(R.r.mode & R_SPEED) { + if (R.r.mode & R_SPEED) { float *s1, *s2, *s3; s1= RE_vertren_get_winspeed(obi, v1, 0); s2= RE_vertren_get_winspeed(obi, v2, 0); s3= RE_vertren_get_winspeed(obi, v3, 0); - if(s1 && s2 && s3) { + if (s1 && s2 && s3) { shi->winspeed[0]= (l*s3[0] - u*s1[0] - v*s2[0]); shi->winspeed[1]= (l*s3[1] - u*s1[1] - v*s2[1]); shi->winspeed[2]= (l*s3[2] - u*s1[2] - v*s2[2]); @@ -1020,14 +1021,14 @@ void shade_input_set_shade_texco(ShadeInput *shi) } /* pass option forces UV calc */ - if(shi->passflag & SCE_PASS_UV) + if (shi->passflag & SCE_PASS_UV) texco |= (NEED_UV|TEXCO_UV); /* texture coordinates. shi->dxuv shi->dyuv have been set */ - if(texco & NEED_UV) { + if (texco & NEED_UV) { - if(texco & TEXCO_ORCO) { - if(v1->orco) { + if (texco & TEXCO_ORCO) { + if (v1->orco) { float *o1, *o2, *o3; o1= v1->orco; @@ -1038,7 +1039,7 @@ void shade_input_set_shade_texco(ShadeInput *shi) shi->lo[1]= l*o3[1]-u*o1[1]-v*o2[1]; shi->lo[2]= l*o3[2]-u*o1[2]-v*o2[2]; - if(shi->osatex) { + if (shi->osatex) { dl= shi->dx_u+shi->dx_v; shi->dxlo[0]= dl*o3[0]-shi->dx_u*o1[0]-shi->dx_v*o2[0]; shi->dxlo[1]= dl*o3[1]-shi->dx_u*o1[1]-shi->dx_v*o2[1]; @@ -1053,10 +1054,10 @@ void shade_input_set_shade_texco(ShadeInput *shi) copy_v3_v3(shi->duplilo, obi->dupliorco); } - if(texco & TEXCO_GLOB) { + if (texco & TEXCO_GLOB) { copy_v3_v3(shi->gl, shi->co); mul_m4_v3(R.viewinv, shi->gl); - if(shi->osatex) { + if (shi->osatex) { copy_v3_v3(shi->dxgl, shi->dxco); mul_mat3_m4_v3(R.viewinv, shi->dxgl); copy_v3_v3(shi->dygl, shi->dyco); @@ -1064,9 +1065,9 @@ void shade_input_set_shade_texco(ShadeInput *shi) } } - if(texco & TEXCO_STRAND) { + if (texco & TEXCO_STRAND) { shi->strandco= (l*v3->accum - u*v1->accum - v*v2->accum); - if(shi->osatex) { + if (shi->osatex) { dl= shi->dx_u+shi->dx_v; shi->dxstrand= dl*v3->accum-shi->dx_u*v1->accum-shi->dx_v*v2->accum; dl= shi->dy_u+shi->dy_v; @@ -1074,7 +1075,7 @@ void shade_input_set_shade_texco(ShadeInput *shi) } } - if((texco & TEXCO_UV) || (mode & (MA_VERTEXCOL|MA_VERTEXCOLP|MA_FACETEXTURE))) { + if ((texco & TEXCO_UV) || (mode & (MA_VERTEXCOL|MA_VERTEXCOLP|MA_FACETEXTURE))) { VlakRen *vlr= shi->vlr; MTFace *tface; MCol *mcol; @@ -1089,7 +1090,7 @@ void shade_input_set_shade_texco(ShadeInput *shi) shi->actuv= obr->actmtface; shi->actcol= obr->actmcol; - if(mode & (MA_VERTEXCOL|MA_VERTEXCOLP)) { + if (mode & (MA_VERTEXCOL|MA_VERTEXCOLP)) { for (i=0; (mcol=RE_vlakren_get_mcol(obr, vlr, i, &name, 0)); i++) { ShadeInputCol *scol= &shi->col[i]; char *cp1, *cp2, *cp3; @@ -1119,7 +1120,7 @@ void shade_input_set_shade_texco(ShadeInput *shi) } } - if(shi->totcol) { + if (shi->totcol) { shi->vcol[0]= shi->col[shi->actcol].col[0]; shi->vcol[1]= shi->col[shi->actcol].col[1]; shi->vcol[2]= shi->col[shi->actcol].col[2]; @@ -1148,7 +1149,7 @@ void shade_input_set_shade_texco(ShadeInput *shi) suv->uv[1]= -1.0f + 2.0f*(l*uv3[1]-u*uv1[1]-v*uv2[1]); suv->uv[2]= 0.0f; /* texture.c assumes there are 3 coords */ - if(shi->osatex) { + if (shi->osatex) { float duv[2]; dl= shi->dx_u+shi->dx_v; @@ -1166,14 +1167,14 @@ void shade_input_set_shade_texco(ShadeInput *shi) suv->dyuv[1]= 2.0f*(dl*uv3[1]-duv[0]*uv1[1]-duv[1]*uv2[1]); } - if((mode & MA_FACETEXTURE) && i==obr->actmtface) { - if((mode & (MA_VERTEXCOL|MA_VERTEXCOLP))==0) { + if ((mode & MA_FACETEXTURE) && i==obr->actmtface) { + if ((mode & (MA_VERTEXCOL|MA_VERTEXCOLP))==0) { shi->vcol[0]= 1.0f; shi->vcol[1]= 1.0f; shi->vcol[2]= 1.0f; shi->vcol[3]= 1.0f; } - if(tface->tpage) { + if (tface->tpage) { render_realtime_texture(shi, tface->tpage); } } @@ -1185,14 +1186,14 @@ void shade_input_set_shade_texco(ShadeInput *shi) shi->dupliuv[1]= -1.0f + 2.0f*obi->dupliuv[1]; shi->dupliuv[2]= 0.0f; - if(shi->totuv == 0) { + if (shi->totuv == 0) { ShadeInputUV *suv= &shi->uv[0]; suv->uv[0]= 2.0f*(u+.5f); suv->uv[1]= 2.0f*(v+.5f); suv->uv[2]= 0.0f; /* texture.c assumes there are 3 coords */ - if(mode & MA_FACETEXTURE) { + if (mode & MA_FACETEXTURE) { /* no tface? set at 1.0f */ shi->vcol[0]= 1.0f; shi->vcol[1]= 1.0f; @@ -1202,28 +1203,28 @@ void shade_input_set_shade_texco(ShadeInput *shi) } } - if(texco & TEXCO_NORM) { + if (texco & TEXCO_NORM) { shi->orn[0]= -shi->vn[0]; shi->orn[1]= -shi->vn[1]; shi->orn[2]= -shi->vn[2]; } - if(texco & TEXCO_STRESS) { + if (texco & TEXCO_STRESS) { float *s1, *s2, *s3; s1= RE_vertren_get_stress(obr, v1, 0); s2= RE_vertren_get_stress(obr, v2, 0); s3= RE_vertren_get_stress(obr, v3, 0); - if(s1 && s2 && s3) { + if (s1 && s2 && s3) { shi->stress= l*s3[0] - u*s1[0] - v*s2[0]; - if(shi->stress<1.0f) shi->stress-= 1.0f; + if (shi->stress<1.0f) shi->stress-= 1.0f; else shi->stress= (shi->stress-1.0f)/shi->stress; } else shi->stress= 0.0f; } - if(texco & TEXCO_TANGENT) { - if((mode & MA_TANGENT_V)==0) { + if (texco & TEXCO_TANGENT) { + if ((mode & MA_TANGENT_V)==0) { /* just prevent surprises */ shi->tang[0]= shi->tang[1]= shi->tang[2]= 0.0f; shi->nmaptang[0]= shi->nmaptang[1]= shi->nmaptang[2]= 0.0f; @@ -1232,15 +1233,15 @@ void shade_input_set_shade_texco(ShadeInput *shi) } /* this only avalailable for scanline renders */ - if(shi->depth==0) { + if (shi->depth==0) { float x= shi->xs; float y= shi->ys; - if(texco & TEXCO_WINDOW) { + if (texco & TEXCO_WINDOW) { shi->winco[0]= -1.0f + 2.0f*x/(float)R.winx; shi->winco[1]= -1.0f + 2.0f*y/(float)R.winy; shi->winco[2]= 0.0f; - if(shi->osatex) { + if (shi->osatex) { shi->dxwin[0]= 2.0f/(float)R.winx; shi->dywin[1]= 2.0f/(float)R.winy; shi->dxwin[1]= shi->dxwin[2]= 0.0f; @@ -1248,14 +1249,14 @@ void shade_input_set_shade_texco(ShadeInput *shi) } } - if(texco & TEXCO_STICKY) { + if (texco & TEXCO_STICKY) { float *s1, *s2, *s3; s1= RE_vertren_get_sticky(obr, v1, 0); s2= RE_vertren_get_sticky(obr, v2, 0); s3= RE_vertren_get_sticky(obr, v3, 0); - if(s1 && s2 && s3) { + if (s1 && s2 && s3) { float obwinmat[4][4], winmat[4][4], ho1[4], ho2[4], ho3[4]; float Zmulx, Zmuly; float hox, hoy, l, dl, u, v; @@ -1265,7 +1266,7 @@ void shade_input_set_shade_texco(ShadeInput *shi) Zmulx= ((float)R.winx)/2.0f; Zmuly= ((float)R.winy)/2.0f; zbuf_make_winmat(&R, winmat); - if(shi->obi->flag & R_TRANSFORMED) + if (shi->obi->flag & R_TRANSFORMED) mult_m4_m4m4(obwinmat, winmat, obi->mat); else copy_m4_m4(obwinmat, winmat); @@ -1295,7 +1296,7 @@ void shade_input_set_shade_texco(ShadeInput *shi) shi->sticky[1]= l*s3[1]-u*s1[1]-v*s2[1]; shi->sticky[2]= 0.0f; - if(shi->osatex) { + if (shi->osatex) { float dxuv[2], dyuv[2]; dxuv[0]= s11/Zmulx; dxuv[1]= - s01/Zmulx; @@ -1318,7 +1319,7 @@ void shade_input_set_shade_texco(ShadeInput *shi) * else un-initialized values are used */ if (shi->do_manage) { - if(mode & (MA_VERTEXCOL|MA_VERTEXCOLP|MA_FACETEXTURE)) { + if (mode & (MA_VERTEXCOL|MA_VERTEXCOLP|MA_FACETEXTURE)) { srgb_to_linearrgb_v3_v3(shi->vcol, shi->vcol); } } @@ -1355,7 +1356,7 @@ void shade_sample_initialize(ShadeSample *ssamp, RenderPart *pa, RenderLayer *rl tot= R.osa==0?1:R.osa; - for(a=0; a<tot; a++) { + for (a=0; a<tot; a++) { shade_input_initialize(&ssamp->shi[a], pa, rl, a); memset(&ssamp->shr[a], 0, sizeof(ShadeResult)); } @@ -1366,19 +1367,19 @@ void shade_sample_initialize(ShadeSample *ssamp, RenderPart *pa, RenderLayer *rl /* Do AO or (future) GI */ void shade_samples_do_AO(ShadeSample *ssamp) { - if(!(R.r.mode & R_SHADOW)) + if (!(R.r.mode & R_SHADOW)) return; - if(!(R.r.mode & R_RAYTRACE) && !(R.wrld.ao_gather_method == WO_AOGATHER_APPROX)) + if (!(R.r.mode & R_RAYTRACE) && !(R.wrld.ao_gather_method == WO_AOGATHER_APPROX)) return; - if(R.wrld.mode & (WO_AMB_OCC|WO_ENV_LIGHT|WO_INDIRECT_LIGHT)) { + if (R.wrld.mode & (WO_AMB_OCC|WO_ENV_LIGHT|WO_INDIRECT_LIGHT)) { ShadeInput *shi= &ssamp->shi[0]; int sample; - if(((shi->passflag & SCE_PASS_COMBINED) && (shi->combinedflag & (SCE_PASS_AO|SCE_PASS_ENVIRONMENT|SCE_PASS_INDIRECT))) + if (((shi->passflag & SCE_PASS_COMBINED) && (shi->combinedflag & (SCE_PASS_AO|SCE_PASS_ENVIRONMENT|SCE_PASS_INDIRECT))) || (shi->passflag & (SCE_PASS_AO|SCE_PASS_ENVIRONMENT|SCE_PASS_INDIRECT))) - for(sample=0; sample<ssamp->tot; shi++, sample++) - if(!(shi->mode & MA_SHLESS)) + for (sample=0; sample<ssamp->tot; shi++, sample++) + if (!(shi->mode & MA_SHLESS)) ambient_occlusion(shi); /* stores in shi->ao[] */ } } @@ -1391,23 +1392,23 @@ void shade_samples_fill_with_ps(ShadeSample *ssamp, PixStr *ps, int x, int y) ssamp->tot= 0; - for(shi= ssamp->shi; ps; ps= ps->next) { + for (shi= ssamp->shi; ps; ps= ps->next) { shade_input_set_triangle(shi, ps->obi, ps->facenr, 1); - if(shi->vlr) { /* NULL happens for env material or for 'all z' */ + if (shi->vlr) { /* NULL happens for env material or for 'all z' */ unsigned short curmask= ps->mask; /* full osa is only set for OSA renders */ - if(shi->vlr->flag & R_FULL_OSA) { + if (shi->vlr->flag & R_FULL_OSA) { short shi_cp= 0, samp; - for(samp=0; samp<R.osa; samp++) { - if(curmask & (1<<samp)) { + for (samp=0; samp<R.osa; samp++) { + if (curmask & (1<<samp)) { /* zbuffer has this inverse corrected, ensures xs,ys are inside pixel */ xs= (float)x + R.jit[samp][0] + 0.5f; ys= (float)y + R.jit[samp][1] + 0.5f; - if(shi_cp) + if (shi_cp) shade_input_copy_triangle(shi, shi-1); shi->mask= (1<<samp); @@ -1415,7 +1416,7 @@ void shade_samples_fill_with_ps(ShadeSample *ssamp, PixStr *ps, int x, int y) shi->samplenr= R.shadowsamplenr[shi->thread]++; /* this counter is not being reset per pixel */ shade_input_set_viewco(shi, x, y, xs, ys, (float)ps->z); shade_input_set_uv(shi); - if(shi_cp==0) + if (shi_cp==0) shade_input_set_normals(shi); else /* XXX shi->flippednor messes up otherwise */ shade_input_set_vertex_normals(shi); @@ -1426,7 +1427,7 @@ void shade_samples_fill_with_ps(ShadeSample *ssamp, PixStr *ps, int x, int y) } } else { - if(R.osa) { + if (R.osa) { short b= R.samples->centmask[curmask]; xs= (float)x + R.samples->centLut[b & 15] + 0.5f; ys= (float)y + R.samples->centLut[b>>4] + 0.5f; @@ -1445,7 +1446,7 @@ void shade_samples_fill_with_ps(ShadeSample *ssamp, PixStr *ps, int x, int y) } /* total sample amount, shi->sample is static set in initialize */ - if(shi!=ssamp->shi) + if (shi!=ssamp->shi) ssamp->tot= (shi-1)->sample + 1; } } @@ -1456,7 +1457,7 @@ int shade_samples(ShadeSample *ssamp, PixStr *ps, int x, int y) { shade_samples_fill_with_ps(ssamp, ps, x, y); - if(ssamp->tot) { + if (ssamp->tot) { ShadeInput *shi= ssamp->shi; ShadeResult *shr= ssamp->shr; int samp; @@ -1465,15 +1466,15 @@ int shade_samples(ShadeSample *ssamp, PixStr *ps, int x, int y) shade_samples_do_AO(ssamp); /* if shade (all shadepinputs have same passflag) */ - if(ssamp->shi[0].passflag & ~(SCE_PASS_Z|SCE_PASS_INDEXOB|SCE_PASS_INDEXMA)) { + if (ssamp->shi[0].passflag & ~(SCE_PASS_Z|SCE_PASS_INDEXOB|SCE_PASS_INDEXMA)) { - for(samp=0; samp<ssamp->tot; samp++, shi++, shr++) { + for (samp=0; samp<ssamp->tot; samp++, shi++, shr++) { shade_input_set_shade_texco(shi); shade_input_do_shade(shi, shr); } } - else if(shi->passflag & SCE_PASS_Z) { - for(samp=0; samp<ssamp->tot; samp++, shi++, shr++) + else if (shi->passflag & SCE_PASS_Z) { + for (samp=0; samp<ssamp->tot; samp++, shi++, shr++) shr->z= -shi->co[2]; } diff --git a/source/blender/render/intern/source/shadeoutput.c b/source/blender/render/intern/source/shadeoutput.c index 04fde7bf0b9..ece6e464bdf 100644 --- a/source/blender/render/intern/source/shadeoutput.c +++ b/source/blender/render/intern/source/shadeoutput.c @@ -66,11 +66,11 @@ extern struct Render R; ListBase *get_lights(ShadeInput *shi) { - if(R.r.scemode & R_PREVIEWBUTS) + if (R.r.scemode & R_PREVIEWBUTS) return &R.lights; - if(shi->light_override) + if (shi->light_override) return &shi->light_override->gobject; - if(shi->mat && shi->mat->group) + if (shi->mat && shi->mat->group) return &shi->mat->group->gobject; return &R.lights; @@ -96,7 +96,7 @@ static void fogcolor(float *colf, float *rco, float *view) dview[2]= -stepsize; startdist= -rco[2] + BLI_frand(); - for(dist= startdist; dist>R.wrld.miststa; dist-= stepsize) { + for (dist= startdist; dist>R.wrld.miststa; dist-= stepsize) { hor[0]= R.wrld.horr; hor[1]= R.wrld.horg; hor[2]= R.wrld.horb; alpha= 1.0f; @@ -127,13 +127,13 @@ float mistfactor(float zcor, float const co[3]) /* fac= -co[2]-R.wrld.miststa; */ - if(fac>0.0f) { - if(fac< R.wrld.mistdist) { + if (fac>0.0f) { + if (fac< R.wrld.mistdist) { fac= (fac/(R.wrld.mistdist)); - if(R.wrld.mistype==0) fac*= fac; - else if(R.wrld.mistype==1); + if (R.wrld.mistype==0) fac*= fac; + else if (R.wrld.mistype==1); else fac= sqrt(fac); } else fac= 1.0f; @@ -141,13 +141,13 @@ float mistfactor(float zcor, float const co[3]) else fac= 0.0f; /* height switched off mist */ - if(R.wrld.misthi!=0.0f && fac!=0.0f) { + if (R.wrld.misthi!=0.0f && fac!=0.0f) { /* at height misthi the mist is completely gone */ hi= R.viewinv[0][2]*co[0]+R.viewinv[1][2]*co[1]+R.viewinv[2][2]*co[2]+R.viewinv[3][2]; - if(hi>R.wrld.misthi) fac= 0.0f; - else if(hi>0.0f) { + if (hi>R.wrld.misthi) fac= 0.0f; + else if (hi>0.0f) { hi= (R.wrld.misthi-hi)/R.wrld.misthi; fac*= hi*hi; } @@ -166,7 +166,7 @@ static void spothalo(struct LampRen *lar, ShadeInput *shi, float *intens) *intens= 0.0f; haint= lar->haint; - if(R.r.mode & R_ORTHO) { + if (R.r.mode & R_ORTHO) { /* camera pos (view vector) cannot be used... */ /* camera position (cox,coy,0) rotate around lamp */ p1[0]= shi->co[0]-lar->co[0]; @@ -186,17 +186,17 @@ static void spothalo(struct LampRen *lar, ShadeInput *shi, float *intens) copy_v3db_v3fl(nray, shi->view); mul_m3_v3_double(lar->imat, nray); - if(R.wrld.mode & WO_MIST) { + if (R.wrld.mode & WO_MIST) { /* patchy... */ haint *= mistfactor(-lar->co[2], lar->co); - if(haint==0.0f) { + if (haint==0.0f) { return; } } /* rotate maxz */ - if(shi->co[2]==0.0f) doclip= 0; /* for when halo at sky */ + if (shi->co[2]==0.0f) doclip= 0; /* for when halo at sky */ else { p1[0]= shi->co[0]-lar->co[0]; p1[1]= shi->co[1]-lar->co[1]; @@ -206,7 +206,7 @@ static void spothalo(struct LampRen *lar, ShadeInput *shi, float *intens) maxz*= lar->sh_zfac; maxy= lar->imat[0][1]*p1[0]+lar->imat[1][1]*p1[1]+lar->imat[2][1]*p1[2]; - if( fabs(nray[2]) < FLT_EPSILON ) use_yco= 1; + if ( fabs(nray[2]) < FLT_EPSILON ) use_yco= 1; } /* scale z to make sure volume is normalized */ @@ -230,7 +230,7 @@ static void spothalo(struct LampRen *lar, ShadeInput *shi, float *intens) else { disc = b*b - a*c; - if(disc==0.0) { + if (disc==0.0) { t1=t2= (-b)/ a; snijp= 2; } @@ -241,11 +241,11 @@ static void spothalo(struct LampRen *lar, ShadeInput *shi, float *intens) snijp= 2; } } - if(snijp==2) { + if (snijp==2) { int ok1=0, ok2=0; /* sort */ - if(t1>t2) { + if (t1>t2) { a= t1; t1= t2; t2= a; } @@ -254,52 +254,52 @@ static void spothalo(struct LampRen *lar, ShadeInput *shi, float *intens) p2[2]= npos[2] + t2*nray[2]; /* evaluate both points */ - if(p1[2]<=0.0f) ok1= 1; - if(p2[2]<=0.0f && t1!=t2) ok2= 1; + if (p1[2]<=0.0f) ok1= 1; + if (p2[2]<=0.0f && t1!=t2) ok2= 1; /* at least 1 point with negative z */ - if(ok1==0 && ok2==0) return; + if (ok1==0 && ok2==0) return; /* intersction point with -ladist, the bottom of the cone */ - if(use_yco==0) { + if (use_yco==0) { t3= ((double)(-ladist)-npos[2])/nray[2]; /* de we have to replace one of the intersection points? */ - if(ok1) { - if(p1[2]<-ladist) t1= t3; + if (ok1) { + if (p1[2]<-ladist) t1= t3; } else { t1= t3; } - if(ok2) { - if(p2[2]<-ladist) t2= t3; + if (ok2) { + if (p2[2]<-ladist) t2= t3; } else { t2= t3; } } - else if(ok1==0 || ok2==0) return; + else if (ok1==0 || ok2==0) return; /* at least 1 visible interesction point */ - if(t1<0.0 && t2<0.0) return; + if (t1<0.0 && t2<0.0) return; - if(t1<0.0) t1= 0.0; - if(t2<0.0) t2= 0.0; + if (t1<0.0) t1= 0.0; + if (t2<0.0) t2= 0.0; - if(t1==t2) return; + if (t1==t2) return; /* sort again to be sure */ - if(t1>t2) { + if (t1>t2) { a= t1; t1= t2; t2= a; } /* calculate t0: is the maximum visible z (when halo is intersected by face) */ - if(doclip) { - if(use_yco==0) t0= (maxz-npos[2])/nray[2]; + if (doclip) { + if (use_yco==0) t0= (maxz-npos[2])/nray[2]; else t0= (maxy-npos[1])/nray[1]; - if(t0<t1) return; - if(t0<t2) t2= t0; + if (t0<t1) return; + if (t0<t2) t2= t0; } /* calc points */ @@ -327,7 +327,7 @@ static void spothalo(struct LampRen *lar, ShadeInput *shi, float *intens) /* WATCH IT: do not clip a,b en c at 1.0, this gives nasty little overflows * at the edges (especially with narrow halos) */ - if(*intens<=0.0f) return; + if (*intens<=0.0f) return; /* soft area */ /* not needed because t0 has been used for p1/p2 as well */ @@ -337,7 +337,7 @@ static void spothalo(struct LampRen *lar, ShadeInput *shi, float *intens) *intens *= haint; - if(lar->shb && lar->shb->shadhalostep) { + if (lar->shb && lar->shb->shadhalostep) { *intens *= shadow_halo(lar, p1, p2); } @@ -351,23 +351,23 @@ void renderspothalo(ShadeInput *shi, float col[4], float alpha) LampRen *lar; float i; - if(alpha==0.0f) return; + if (alpha==0.0f) return; lights= get_lights(shi); - for(go=lights->first; go; go= go->next) { + for (go=lights->first; go; go= go->next) { lar= go->lampren; - if(lar==NULL) continue; + if (lar==NULL) continue; - if(lar->type==LA_SPOT && (lar->mode & LA_HALO) && (lar->buftype != LA_SHADBUF_DEEP) && lar->haint>0) { + if (lar->type==LA_SPOT && (lar->mode & LA_HALO) && (lar->buftype != LA_SHADBUF_DEEP) && lar->haint>0) { - if(lar->mode & LA_LAYER) - if(shi->vlr && (lar->lay & shi->obi->lay)==0) + if (lar->mode & LA_LAYER) + if (shi->vlr && (lar->lay & shi->obi->lay)==0) continue; - if((lar->lay & shi->lay)==0) + if ((lar->lay & shi->lay)==0) continue; spothalo(lar, shi, &i); - if(i>0.0f) { + if (i>0.0f) { col[3]+= i*alpha; // all premul col[0]+= i*lar->r*alpha; col[1]+= i*lar->g*alpha; @@ -376,7 +376,7 @@ void renderspothalo(ShadeInput *shi, float col[4], float alpha) } } /* clip alpha, is needed for unified 'alpha threshold' (vanillaRenderPipe.c) */ - if(col[3]>1.0f) col[3]= 1.0f; + if (col[3]>1.0f) col[3]= 1.0f; } @@ -389,13 +389,14 @@ static double Normalize_d(double *n) d= n[0]*n[0]+n[1]*n[1]+n[2]*n[2]; - if(d>0.00000000000000001) { + if (d>0.00000000000000001) { d= sqrt(d); n[0]/=d; n[1]/=d; n[2]/=d; - } else { + } + else { n[0]=n[1]=n[2]= 0.0; d= 0.0; } @@ -407,23 +408,23 @@ float fresnel_fac(float *view, float *vn, float grad, float fac) { float t1, t2; - if(fac==0.0f) return 1.0f; + if (fac==0.0f) return 1.0f; t1= (view[0]*vn[0] + view[1]*vn[1] + view[2]*vn[2]); - if(t1>0.0f) t2= 1.0f+t1; + if (t1>0.0f) t2= 1.0f+t1; else t2= 1.0f-t1; t2= grad + (1.0f-grad)*powf(t2, fac); - if(t2<0.0f) return 0.0f; - else if(t2>1.0f) return 1.0f; + if (t2<0.0f) return 0.0f; + else if (t2>1.0f) return 1.0f; return t2; } static double saacos_d(double fac) { - if(fac<= -1.0) return M_PI; - else if(fac>=1.0) return 0.0; + if (fac<= -1.0) return M_PI; + else if (fac>=1.0) return 0.0; else return acos(fac); } @@ -473,7 +474,7 @@ static float area_lamp_energy(float (*area)[3], float *co, float *vn) fac+= rad[2]*(vn[0]*cross[2][0]+ vn[1]*cross[2][1]+ vn[2]*cross[2][2]); fac+= rad[3]*(vn[0]*cross[3][0]+ vn[1]*cross[3][1]+ vn[2]*cross[3][2]); - if(fac<=0.0) return 0.0; + if (fac<=0.0) return 0.0; return fac; } @@ -486,10 +487,10 @@ static float area_lamp_energy_multisample(LampRen *lar, float *co, float *vn) /* test if co is behind lamp */ sub_v3_v3v3(vec, co, lar->co); - if(dot_v3v3(vec, lar->vec) < 0.0f) + if (dot_v3v3(vec, lar->vec) < 0.0f) return 0.0f; - while(a--) { + while (a--) { vec[0]= jitlamp[0]; vec[1]= jitlamp[1]; vec[2]= 0.0f; @@ -513,35 +514,35 @@ static float spec(float inp, int hard) { float b1; - if(inp>=1.0f) return 1.0f; + if (inp>=1.0f) return 1.0f; else if (inp<=0.0f) return 0.0f; b1= inp*inp; /* avoid FPE */ - if(b1<0.01f) b1= 0.01f; + if (b1<0.01f) b1= 0.01f; - if((hard & 1)==0) inp= 1.0f; - if(hard & 2) inp*= b1; + if ((hard & 1)==0) inp= 1.0f; + if (hard & 2) inp*= b1; b1*= b1; - if(hard & 4) inp*= b1; + if (hard & 4) inp*= b1; b1*= b1; - if(hard & 8) inp*= b1; + if (hard & 8) inp*= b1; b1*= b1; - if(hard & 16) inp*= b1; + if (hard & 16) inp*= b1; b1*= b1; /* avoid FPE */ - if(b1<0.001f) b1= 0.0f; + if (b1<0.001f) b1= 0.0f; - if(hard & 32) inp*= b1; + if (hard & 32) inp*= b1; b1*= b1; - if(hard & 64) inp*=b1; + if (hard & 64) inp*=b1; b1*= b1; - if(hard & 128) inp*=b1; + if (hard & 128) inp*=b1; - if(b1<0.001f) b1= 0.0f; + if (b1<0.001f) b1= 0.0f; - if(hard & 256) { + if (hard & 256) { b1*= b1; inp*=b1; } @@ -560,9 +561,9 @@ static float Phong_Spec( float *n, float *l, float *v, int hard, int tangent ) normalize_v3(h); rslt = h[0]*n[0] + h[1]*n[1] + h[2]*n[2]; - if(tangent) rslt= sasqrt(1.0f - rslt*rslt); + if (tangent) rslt= sasqrt(1.0f - rslt*rslt); - if( rslt > 0.0f ) rslt= spec(rslt, hard); + if ( rslt > 0.0f ) rslt= spec(rslt, hard); else rslt = 0.0f; return rslt; @@ -580,12 +581,12 @@ static float CookTorr_Spec(float *n, float *l, float *v, int hard, int tangent) normalize_v3(h); nh= n[0]*h[0]+n[1]*h[1]+n[2]*h[2]; - if(tangent) nh= sasqrt(1.0f - nh*nh); - else if(nh<0.0f) return 0.0f; + if (tangent) nh= sasqrt(1.0f - nh*nh); + else if (nh<0.0f) return 0.0f; nv= n[0]*v[0]+n[1]*v[1]+n[2]*v[2]; - if(tangent) nv= sasqrt(1.0f - nv*nv); - else if(nv<0.0f) nv= 0.0f; + if (tangent) nv= sasqrt(1.0f - nv*nv); + else if (nv<0.0f) nv= 0.0f; i= spec(nh, hard); @@ -599,11 +600,11 @@ static float Blinn_Spec(float *n, float *l, float *v, float refrac, float spec_p float i, nh, nv, nl, vh, h[3]; float a, b, c, g=0.0f, p, f, ang; - if(refrac < 1.0f) return 0.0f; - if(spec_power == 0.0f) return 0.0f; + if (refrac < 1.0f) return 0.0f; + if (spec_power == 0.0f) return 0.0f; /* conversion from 'hardness' (1-255) to 'spec_power' (50 maps at 0.1) */ - if(spec_power<100.0f) + if (spec_power<100.0f) spec_power= sqrt(1.0f/spec_power); else spec_power= 10.0f/spec_power; @@ -613,36 +614,36 @@ static float Blinn_Spec(float *n, float *l, float *v, float refrac, float spec_p normalize_v3(h); nh= n[0]*h[0]+n[1]*h[1]+n[2]*h[2]; /* Dot product between surface normal and half-way vector */ - if(tangent) nh= sasqrt(1.0f - nh*nh); - else if(nh<0.0f) return 0.0f; + if (tangent) nh= sasqrt(1.0f - nh*nh); + else if (nh<0.0f) return 0.0f; nv= n[0]*v[0]+n[1]*v[1]+n[2]*v[2]; /* Dot product between surface normal and view vector */ - if(tangent) nv= sasqrt(1.0f - nv*nv); - if(nv<=0.01f) nv= 0.01f; /* hrms... */ + if (tangent) nv= sasqrt(1.0f - nv*nv); + if (nv<=0.01f) nv= 0.01f; /* hrms... */ nl= n[0]*l[0]+n[1]*l[1]+n[2]*l[2]; /* Dot product between surface normal and light vector */ - if(tangent) nl= sasqrt(1.0f - nl*nl); - if(nl<=0.01f) { + if (tangent) nl= sasqrt(1.0f - nl*nl); + if (nl<=0.01f) { return 0.0f; } vh= v[0]*h[0]+v[1]*h[1]+v[2]*h[2]; /* Dot product between view vector and half-way vector */ - if(vh<=0.0f) vh= 0.01f; + if (vh<=0.0f) vh= 0.01f; a = 1.0f; b = (2.0f*nh*nv)/vh; c = (2.0f*nh*nl)/vh; - if( a < b && a < c ) g = a; - else if( b < a && b < c ) g = b; - else if( c < a && c < b ) g = c; + if ( a < b && a < c ) g = a; + else if ( b < a && b < c ) g = b; + else if ( c < a && c < b ) g = c; p = sqrt( (double)((refrac * refrac)+(vh*vh)-1.0f) ); f = (((p-vh)*(p-vh))/((p+vh)*(p+vh)))*(1+((((vh*(p+vh))-1.0f)*((vh*(p+vh))-1.0f))/(((vh*(p-vh))+1.0f)*((vh*(p-vh))+1.0f)))); ang = saacos(nh); i= f * g * exp((double)(-(ang*ang) / (2.0f*spec_power*spec_power))); - if(i<0.0f) i= 0.0f; + if (i<0.0f) i= 0.0f; return i; } @@ -660,12 +661,12 @@ static float Toon_Spec( float *n, float *l, float *v, float size, float smooth, normalize_v3(h); rslt = h[0]*n[0] + h[1]*n[1] + h[2]*n[2]; - if(tangent) rslt = sasqrt(1.0f - rslt*rslt); + if (tangent) rslt = sasqrt(1.0f - rslt*rslt); ang = saacos( rslt ); - if( ang < size ) rslt = 1.0f; - else if( ang >= (size + smooth) || smooth == 0.0f ) rslt = 0.0f; + if ( ang < size ) rslt = 1.0f; + else if ( ang >= (size + smooth) || smooth == 0.0f ) rslt = 0.0f; else rslt = 1.0f - ((ang - size) / smooth); return rslt; @@ -684,16 +685,16 @@ static float WardIso_Spec( float *n, float *l, float *v, float rms, int tangent) normalize_v3(h); nh = n[0]*h[0]+n[1]*h[1]+n[2]*h[2]; /* Dot product between surface normal and half-way vector */ - if(tangent) nh = sasqrt(1.0f - nh*nh); - if(nh<=0.0f) nh = 0.001f; + if (tangent) nh = sasqrt(1.0f - nh*nh); + if (nh<=0.0f) nh = 0.001f; nv = n[0]*v[0]+n[1]*v[1]+n[2]*v[2]; /* Dot product between surface normal and view vector */ - if(tangent) nv = sasqrt(1.0f - nv*nv); - if(nv<=0.0f) nv = 0.001f; + if (tangent) nv = sasqrt(1.0f - nv*nv); + if (nv<=0.0f) nv = 0.001f; nl = n[0]*l[0]+n[1]*l[1]+n[2]*l[2]; /* Dot product between surface normal and light vector */ - if(tangent) nl = sasqrt(1.0f - nl*nl); - if(nl<=0.0f) nl = 0.001f; + if (tangent) nl = sasqrt(1.0f - nl*nl); + if (nl<=0.0f) nl = 0.001f; angle = tan(saacos(nh)); alpha = MAX2(rms, 0.001f); @@ -712,8 +713,8 @@ static float Toon_Diff( float *n, float *l, float *UNUSED(v), float size, float ang = saacos( (double)(rslt) ); - if( ang < size ) rslt = 1.0f; - else if( ang >= (size + smooth) || smooth == 0.0f ) rslt = 0.0f; + if ( ang < size ) rslt = 1.0f; + else if ( ang >= (size + smooth) || smooth == 0.0f ) rslt = 0.0f; else rslt = 1.0f - ((ang - size) / smooth); return rslt; @@ -738,11 +739,11 @@ static float OrenNayar_Diff(float nl, float *n, float *l, float *v, float rough /* if(nh<0.0f) nh = 0.0f; */ nv= n[0]*v[0]+n[1]*v[1]+n[2]*v[2]; /* Dot product between surface normal and view vector */ - if(nv<=0.0f) nv= 0.0f; + if (nv<=0.0f) nv= 0.0f; realnl= n[0]*l[0]+n[1]*l[1]+n[2]*l[2]; /* Dot product between surface normal and light vector */ - if(realnl<=0.0f) return 0.0f; - if(nl<0.0f) return 0.0f; /* value from area light */ + if (realnl<=0.0f) return 0.0f; + if (nl<0.0f) return 0.0f; /* value from area light */ /* vh= v[0]*h[0]+v[1]*h[1]+v[2]*h[2]; */ /* Dot product between view vector and halfway vector */ /* if(vh<=0.0f) vh= 0.0f; */ @@ -761,9 +762,9 @@ static float OrenNayar_Diff(float nl, float *n, float *l, float *v, float rough normalize_v3( View_B ); t = Lit_B[0]*View_B[0] + Lit_B[1]*View_B[1] + Lit_B[2]*View_B[2]; - if( t < 0 ) t = 0; + if ( t < 0 ) t = 0; - if( Lit_A > View_A ) { + if ( Lit_A > View_A ) { a = Lit_A; b = View_A; } @@ -822,8 +823,8 @@ void calc_R_ref(ShadeInput *shi) shi->ref[0]= (shi->view[0]+i*shi->vn[0]); shi->ref[1]= (shi->view[1]+i*shi->vn[1]); shi->ref[2]= (shi->view[2]+i*shi->vn[2]); - if(shi->osatex) { - if(shi->vlr->flag & R_SMOOTH) { + if (shi->osatex) { + if (shi->vlr->flag & R_SMOOTH) { i= -2*( (shi->vn[0]+shi->dxno[0])*(shi->view[0]+shi->dxview) + (shi->vn[1]+shi->dxno[1])*shi->view[1]+ (shi->vn[2]+shi->dxno[2])*shi->view[2] ); @@ -864,24 +865,24 @@ void shade_color(ShadeInput *shi, ShadeResult *shr) { Material *ma= shi->mat; - if(ma->mode & (MA_FACETEXTURE)) { + if (ma->mode & (MA_FACETEXTURE)) { shi->r= shi->vcol[0]; shi->g= shi->vcol[1]; shi->b= shi->vcol[2]; - if(ma->mode & (MA_FACETEXTURE_ALPHA)) + if (ma->mode & (MA_FACETEXTURE_ALPHA)) shi->alpha= shi->vcol[3]; } - else if(ma->mode & (MA_VERTEXCOLP)) { + else if (ma->mode & (MA_VERTEXCOLP)) { float neg_alpha = 1.0f - shi->vcol[3]; shi->r= shi->r*neg_alpha + shi->vcol[0]*shi->vcol[3]; shi->g= shi->g*neg_alpha + shi->vcol[1]*shi->vcol[3]; shi->b= shi->b*neg_alpha + shi->vcol[2]*shi->vcol[3]; } - if(ma->texco) + if (ma->texco) do_material_tex(shi, &R); - if(ma->fresnel_tra!=0.0f) + if (ma->fresnel_tra!=0.0f) shi->alpha*= fresnel_fac(shi->view, shi->vn, ma->fresnel_tra_i, ma->fresnel_tra); if (!(shi->mode & MA_TRANSP)) shi->alpha= 1.0f; @@ -898,8 +899,8 @@ static void ramp_diffuse_result(float *diff, ShadeInput *shi) Material *ma= shi->mat; float col[4]; - if(ma->ramp_col) { - if(ma->rampin_col==MA_RAMP_IN_RESULT) { + if (ma->ramp_col) { + if (ma->rampin_col==MA_RAMP_IN_RESULT) { float fac = rgb_to_grayscale(diff); do_colorband(ma->ramp_col, fac, col); @@ -916,10 +917,10 @@ static void add_to_diffuse(float *diff, ShadeInput *shi, float is, float r, floa { Material *ma= shi->mat; - if(ma->ramp_col && (ma->mode & MA_RAMP_COL)) { + if (ma->ramp_col && (ma->mode & MA_RAMP_COL)) { /* MA_RAMP_IN_RESULT is exceptional */ - if(ma->rampin_col==MA_RAMP_IN_RESULT) { + if (ma->rampin_col==MA_RAMP_IN_RESULT) { // normal add diff[0] += r * shi->r; diff[1] += g * shi->g; @@ -973,7 +974,7 @@ static void ramp_spec_result(float spec_col[3], ShadeInput *shi) { Material *ma= shi->mat; - if(ma->ramp_spec && (ma->rampin_spec==MA_RAMP_IN_RESULT)) { + if (ma->ramp_spec && (ma->rampin_spec==MA_RAMP_IN_RESULT)) { float col[4]; float fac = rgb_to_grayscale(spec_col); @@ -997,7 +998,7 @@ static void do_specular_ramp(ShadeInput *shi, float is, float t, float spec[3]) spec[2]= shi->specb; /* MA_RAMP_IN_RESULT is exception */ - if(ma->ramp_spec && (ma->rampin_spec!=MA_RAMP_IN_RESULT)) { + if (ma->ramp_spec && (ma->rampin_spec!=MA_RAMP_IN_RESULT)) { float fac; float col[4]; @@ -1030,10 +1031,10 @@ static void do_specular_ramp(ShadeInput *shi, float is, float t, float spec[3]) /* preprocess, textures were not done, don't use shi->amb for that reason */ void ambient_occlusion(ShadeInput *shi) { - if((R.wrld.ao_gather_method == WO_AOGATHER_APPROX) && shi->mat->amb!=0.0f) { + if ((R.wrld.ao_gather_method == WO_AOGATHER_APPROX) && shi->mat->amb!=0.0f) { sample_occ(&R, shi); } - else if((R.r.mode & R_RAYTRACE) && shi->mat->amb!=0.0f) { + else if ((R.r.mode & R_RAYTRACE) && shi->mat->amb!=0.0f) { ray_ao(shi, shi->ao, shi->env); } else { @@ -1050,21 +1051,21 @@ static void ambient_occlusion_apply(ShadeInput *shi, ShadeResult *shr) float f= R.wrld.aoenergy; float tmp[3], tmpspec[3]; - if(!((R.r.mode & R_RAYTRACE) || R.wrld.ao_gather_method == WO_AOGATHER_APPROX)) + if (!((R.r.mode & R_RAYTRACE) || R.wrld.ao_gather_method == WO_AOGATHER_APPROX)) return; - if(f == 0.0f) + if (f == 0.0f) return; - if(R.wrld.aomix==WO_AOADD) { + if (R.wrld.aomix==WO_AOADD) { shr->combined[0] += shi->ao[0]*shi->r*shi->refl*f; shr->combined[1] += shi->ao[1]*shi->g*shi->refl*f; shr->combined[2] += shi->ao[2]*shi->b*shi->refl*f; } - else if(R.wrld.aomix==WO_AOMUL) { + else if (R.wrld.aomix==WO_AOMUL) { mul_v3_v3v3(tmp, shr->combined, shi->ao); mul_v3_v3v3(tmpspec, shr->spec, shi->ao); - if(f == 1.0f) { + if (f == 1.0f) { copy_v3_v3(shr->combined, tmp); copy_v3_v3(shr->spec, tmpspec); } @@ -1079,9 +1080,9 @@ void environment_lighting_apply(ShadeInput *shi, ShadeResult *shr) { float f= R.wrld.ao_env_energy*shi->amb; - if(!((R.r.mode & R_RAYTRACE) || R.wrld.ao_gather_method == WO_AOGATHER_APPROX)) + if (!((R.r.mode & R_RAYTRACE) || R.wrld.ao_gather_method == WO_AOGATHER_APPROX)) return; - if(f == 0.0f) + if (f == 0.0f) return; shr->combined[0] += shi->env[0]*shi->r*shi->refl*f; @@ -1093,9 +1094,9 @@ static void indirect_lighting_apply(ShadeInput *shi, ShadeResult *shr) { float f= R.wrld.ao_indirect_energy; - if(!((R.r.mode & R_RAYTRACE) || R.wrld.ao_gather_method == WO_AOGATHER_APPROX)) + if (!((R.r.mode & R_RAYTRACE) || R.wrld.ao_gather_method == WO_AOGATHER_APPROX)) return; - if(f == 0.0f) + if (f == 0.0f) return; shr->combined[0] += shi->indirect[0]*shi->r*shi->refl*f; @@ -1108,21 +1109,21 @@ void lamp_get_shadow(LampRen *lar, ShadeInput *shi, float inp, float shadfac[4], { LampShadowSubSample *lss= &(lar->shadsamp[shi->thread].s[shi->sample]); - if(do_real || lss->samplenr!=shi->samplenr) { + if (do_real || lss->samplenr!=shi->samplenr) { shadfac[0]= shadfac[1]= shadfac[2]= shadfac[3]= 1.0f; - if(lar->shb) { - if(lar->buftype==LA_SHADBUF_IRREGULAR) + if (lar->shb) { + if (lar->buftype==LA_SHADBUF_IRREGULAR) shadfac[3]= ISB_getshadow(shi, lar->shb); else shadfac[3] = testshadowbuf(&R, lar->shb, shi->co, shi->dxco, shi->dyco, inp, shi->mat->lbias); } - else if(lar->mode & LA_SHAD_RAY) { + else if (lar->mode & LA_SHAD_RAY) { ray_shadow(shi, lar, shadfac); } - if(shi->depth==0) { + if (shi->depth==0) { copy_v4_v4(lss->shadfac, shadfac); lss->samplenr= shi->samplenr; } @@ -1135,7 +1136,7 @@ void lamp_get_shadow(LampRen *lar, ShadeInput *shi, float inp, float shadfac[4], /* lampdistance and spot angle, writes in lv and dist */ float lamp_get_visibility(LampRen *lar, const float co[3], float lv[3], float *dist) { - if(lar->type==LA_SUN || lar->type==LA_HEMI) { + if (lar->type==LA_SUN || lar->type==LA_HEMI) { *dist= 1.0f; copy_v3_v3(lv, lar->vec); return 1.0f; @@ -1149,7 +1150,7 @@ float lamp_get_visibility(LampRen *lar, const float co[3], float lv[3], float *d mul_v3_fl(lv, t); /* area type has no quad or sphere option */ - if(lar->type==LA_AREA) { + if (lar->type==LA_AREA) { /* area is single sided */ //if(dot_v3v3(lv, lar->vec) > 0.0f) // visifac= 1.0f; @@ -1174,9 +1175,9 @@ float lamp_get_visibility(LampRen *lar, const float co[3], float lv[3], float *d visifac = lar->dist / (lar->dist + dist[0]*dist[0]); break; case LA_FALLOFF_SLIDERS: - if(lar->ld1>0.0f) + if (lar->ld1>0.0f) visifac= lar->dist/(lar->dist+lar->ld1*dist[0]); - if(lar->ld2>0.0f) + if (lar->ld2>0.0f) visifac*= lar->distkw/(lar->distkw+lar->ld2*dist[0]*dist[0]); break; case LA_FALLOFF_CURVE: @@ -1184,20 +1185,20 @@ float lamp_get_visibility(LampRen *lar, const float co[3], float lv[3], float *d break; } - if(lar->mode & LA_SPHERE) { + if (lar->mode & LA_SPHERE) { float t= lar->dist - dist[0]; - if(t<=0.0f) + if (t<=0.0f) visifac= 0.0f; else visifac*= t/lar->dist; } - if(visifac > 0.0f) { - if(lar->type==LA_SPOT) { + if (visifac > 0.0f) { + if (lar->type==LA_SPOT) { float inpr; - if(lar->mode & LA_SQUARE) { - if(dot_v3v3(lv, lar->vec) > 0.0f) { + if (lar->mode & LA_SQUARE) { + if (dot_v3v3(lv, lar->vec) > 0.0f) { float lvrot[3], x; /* rotate view to lampspace */ @@ -1216,11 +1217,11 @@ float lamp_get_visibility(LampRen *lar, const float co[3], float lv[3], float *d } t= lar->spotsi; - if(inpr<=t) + if (inpr<=t) visifac= 0.0f; else { t= inpr-t; - if(t<lar->spotbl && lar->spotbl!=0.0f) { + if (t<lar->spotbl && lar->spotbl!=0.0f) { /* soft area */ float i= t/lar->spotbl; t= i*i; @@ -1259,11 +1260,11 @@ static void shade_one_light(LampRen *lar, ShadeInput *shi, ShadeResult *shr, int /* lampdist, spot angle, area side, ... */ visifac= lamp_get_visibility(lar, shi->co, lv, &lampdist); - if(visifac==0.0f) + if (visifac==0.0f) return; - if(lar->type==LA_SPOT) { - if(lar->mode & LA_OSATEX) { + if (lar->type==LA_SPOT) { + if (lar->mode & LA_OSATEX) { shi->osatex= 1; /* signal for multitex() */ shi->dxlv[0]= lv[0] - (shi->co[0]-lar->co[0]+shi->dxco[0])/lampdist; @@ -1285,15 +1286,15 @@ static void shade_one_light(LampRen *lar, ShadeInput *shi, ShadeResult *shr, int lashdw[1]= lar->shdwg; lashdw[2]= lar->shdwb; - if(lar->mode & LA_TEXTURE) do_lamp_tex(lar, lv, shi, lacol, LA_TEXTURE); - if(lar->mode & LA_SHAD_TEX) do_lamp_tex(lar, lv, shi, lashdw, LA_SHAD_TEX); + if (lar->mode & LA_TEXTURE) do_lamp_tex(lar, lv, shi, lacol, LA_TEXTURE); + if (lar->mode & LA_SHAD_TEX) do_lamp_tex(lar, lv, shi, lashdw, LA_SHAD_TEX); /* tangent case; calculate fake face normal, aligned with lampvector */ /* note, vnor==vn is used as tangent trigger for buffer shadow */ - if(vlr->flag & R_TANGENT) { + if (vlr->flag & R_TANGENT) { float cross[3], nstrand[3], blend; - if(ma->mode & MA_STR_SURFDIFF) { + if (ma->mode & MA_STR_SURFDIFF) { cross_v3_v3v3(cross, shi->surfnor, vn); cross_v3_v3v3(nstrand, vn, cross); @@ -1310,8 +1311,8 @@ static void shade_one_light(LampRen *lar, ShadeInput *shi, ShadeResult *shr, int normalize_v3(vnor); } - if(ma->strand_surfnor > 0.0f) { - if(ma->strand_surfnor > shi->surfdist) { + if (ma->strand_surfnor > 0.0f) { + if (ma->strand_surfnor > shi->surfdist) { blend= (ma->strand_surfnor - shi->surfdist)/ma->strand_surfnor; interp_v3_v3v3(vnor, vnor, shi->surfnor, blend); normalize_v3(vnor); @@ -1336,18 +1337,18 @@ static void shade_one_light(LampRen *lar, ShadeInput *shi, ShadeResult *shr, int /* phong threshold to prevent backfacing faces having artefacts on ray shadow (terminator problem) */ /* this complex construction screams for a nicer implementation! (ton) */ - if(R.r.mode & R_SHADOW) { - if(ma->mode & MA_SHADOW) { - if(lar->type==LA_HEMI || lar->type==LA_AREA); - else if((ma->mode & MA_RAYBIAS) && (lar->mode & LA_SHAD_RAY) && (vlr->flag & R_SMOOTH)) { + if (R.r.mode & R_SHADOW) { + if (ma->mode & MA_SHADOW) { + if (lar->type==LA_HEMI || lar->type==LA_AREA); + else if ((ma->mode & MA_RAYBIAS) && (lar->mode & LA_SHAD_RAY) && (vlr->flag & R_SMOOTH)) { float thresh= shi->obr->ob->smoothresh; - if(inp>thresh) + if (inp>thresh) phongcorr= (inp-thresh)/(inp*(1.0f-thresh)); else phongcorr= 0.0f; } - else if(ma->sbias!=0.0f && ((lar->mode & LA_SHAD_RAY) || lar->shb)) { - if(inp>ma->sbias) + else if (ma->sbias!=0.0f && ((lar->mode & LA_SHAD_RAY) || lar->shb)) { + if (inp>ma->sbias) phongcorr= (inp-ma->sbias)/(inp*(1.0f-ma->sbias)); else phongcorr= 0.0f; @@ -1356,57 +1357,57 @@ static void shade_one_light(LampRen *lar, ShadeInput *shi, ShadeResult *shr, int } /* diffuse shaders */ - if(lar->mode & LA_NO_DIFF) { + if (lar->mode & LA_NO_DIFF) { is= 0.0f; // skip shaders } - else if(lar->type==LA_HEMI) { + else if (lar->type==LA_HEMI) { is= 0.5f*inp + 0.5f; } else { - if(lar->type==LA_AREA) + if (lar->type==LA_AREA) inp= area_lamp_energy_multisample(lar, shi->co, vn); /* diffuse shaders (oren nayer gets inp from area light) */ - if(ma->diff_shader==MA_DIFF_ORENNAYAR) is= OrenNayar_Diff(inp, vn, lv, view, ma->roughness); - else if(ma->diff_shader==MA_DIFF_TOON) is= Toon_Diff(vn, lv, view, ma->param[0], ma->param[1]); - else if(ma->diff_shader==MA_DIFF_MINNAERT) is= Minnaert_Diff(inp, vn, view, ma->darkness); - else if(ma->diff_shader==MA_DIFF_FRESNEL) is= Fresnel_Diff(vn, lv, view, ma->param[0], ma->param[1]); + if (ma->diff_shader==MA_DIFF_ORENNAYAR) is= OrenNayar_Diff(inp, vn, lv, view, ma->roughness); + else if (ma->diff_shader==MA_DIFF_TOON) is= Toon_Diff(vn, lv, view, ma->param[0], ma->param[1]); + else if (ma->diff_shader==MA_DIFF_MINNAERT) is= Minnaert_Diff(inp, vn, view, ma->darkness); + else if (ma->diff_shader==MA_DIFF_FRESNEL) is= Fresnel_Diff(vn, lv, view, ma->param[0], ma->param[1]); else is= inp; // Lambert } /* 'is' is diffuse */ - if((ma->shade_flag & MA_CUBIC) && is>0.0f && is<1.0f) + if ((ma->shade_flag & MA_CUBIC) && is>0.0f && is<1.0f) is= 3.0f*is*is - 2.0f*is*is*is; // nicer termination of shades i= is*phongcorr; - if(i>0.0f) { + if (i>0.0f) { i*= visifac*shi->refl; } i_noshad= i; vn= shi->vn; // bring back original vector, we use special specular shaders for tangent - if(ma->mode & MA_TANGENT_V) + if (ma->mode & MA_TANGENT_V) vn= shi->tang; /* init transp shadow */ shadfac[0]= shadfac[1]= shadfac[2]= shadfac[3]= 1.0f; /* shadow and spec, (visifac==0 outside spot) */ - if(visifac> 0.0f) { + if (visifac> 0.0f) { - if((R.r.mode & R_SHADOW)) { - if(ma->mode & MA_SHADOW) { - if(lar->shb || (lar->mode & LA_SHAD_RAY)) { + if ((R.r.mode & R_SHADOW)) { + if (ma->mode & MA_SHADOW) { + if (lar->shb || (lar->mode & LA_SHAD_RAY)) { - if(vn==vnor) /* tangent trigger */ + if (vn==vnor) /* tangent trigger */ lamp_get_shadow(lar, shi, dot_v3v3(shi->vn, lv), shadfac, shi->depth); else lamp_get_shadow(lar, shi, inp, shadfac, shi->depth); /* warning, here it skips the loop */ - if((lar->mode & LA_ONLYSHADOW) && i>0.0f) { + if ((lar->mode & LA_ONLYSHADOW) && i>0.0f) { shadfac[3]= i*lar->energy*(1.0f-shadfac[3]); shr->shad[0] -= shadfac[3]*shi->r*(1.0f-lashdw[0]); @@ -1427,9 +1428,9 @@ static void shade_one_light(LampRen *lar, ShadeInput *shi, ShadeResult *shr, int } /* in case 'no diffuse' we still do most calculus, spec can be in shadow.*/ - if(!(lar->mode & LA_NO_DIFF)) { - if(i>0.0f) { - if(ma->mode & MA_SHADOW_TRA) + if (!(lar->mode & LA_NO_DIFF)) { + if (i>0.0f) { + if (ma->mode & MA_SHADOW_TRA) add_to_diffuse(shr->shad, shi, is, i*shadfac[0]*lacol[0], i*shadfac[1]*lacol[1], i*shadfac[2]*lacol[2]); else add_to_diffuse(shr->shad, shi, is, i*lacol[0], i*lacol[1], i*lacol[2]); @@ -1438,8 +1439,8 @@ static void shade_one_light(LampRen *lar, ShadeInput *shi, ShadeResult *shr, int if (i_noshad>i && !(lashdw[0]==0 && lashdw[1]==0 && lashdw[2]==0)) { add_to_diffuse(shr->shad, shi, is, lashdw[0]*(i_noshad-i)*lacol[0], lashdw[1]*(i_noshad-i)*lacol[1], lashdw[2]*(i_noshad-i)*lacol[2]); } - if(i_noshad>0.0f) { - if(passflag & (SCE_PASS_DIFFUSE|SCE_PASS_SHADOW)) { + if (i_noshad>0.0f) { + if (passflag & (SCE_PASS_DIFFUSE|SCE_PASS_SHADOW)) { add_to_diffuse(shr->diff, shi, is, i_noshad*lacol[0], i_noshad*lacol[1], i_noshad*lacol[2]); } else @@ -1450,10 +1451,10 @@ static void shade_one_light(LampRen *lar, ShadeInput *shi, ShadeResult *shr, int /* specularity */ shadfac[3]*= phongcorr; /* note, shadfac not allowed to be stored nonlocal */ - if(shadfac[3]>0.0f && shi->spec!=0.0f && !(lar->mode & LA_NO_SPEC) && !(lar->mode & LA_ONLYSHADOW)) { + if (shadfac[3]>0.0f && shi->spec!=0.0f && !(lar->mode & LA_NO_SPEC) && !(lar->mode & LA_ONLYSHADOW)) { - if(!(passflag & (SCE_PASS_COMBINED|SCE_PASS_SPEC))); - else if(lar->type==LA_HEMI) { + if (!(passflag & (SCE_PASS_COMBINED|SCE_PASS_SPEC))); + else if (lar->type==LA_HEMI) { float t; /* hemi uses no spec shaders (yet) */ @@ -1465,7 +1466,7 @@ static void shade_one_light(LampRen *lar, ShadeInput *shi, ShadeResult *shr, int t= vn[0]*lv[0]+vn[1]*lv[1]+vn[2]*lv[2]; - if(lar->type==LA_HEMI) { + if (lar->type==LA_HEMI) { t= 0.5f*t+0.5f; } @@ -1479,23 +1480,23 @@ static void shade_one_light(LampRen *lar, ShadeInput *shi, ShadeResult *shr, int /* specular shaders */ float specfac, t; - if(ma->spec_shader==MA_SPEC_PHONG) + if (ma->spec_shader==MA_SPEC_PHONG) specfac= Phong_Spec(vn, lv, view, shi->har, (vlr->flag & R_TANGENT) || (ma->mode & MA_TANGENT_V)); - else if(ma->spec_shader==MA_SPEC_COOKTORR) + else if (ma->spec_shader==MA_SPEC_COOKTORR) specfac= CookTorr_Spec(vn, lv, view, shi->har, (vlr->flag & R_TANGENT) || (ma->mode & MA_TANGENT_V)); - else if(ma->spec_shader==MA_SPEC_BLINN) + else if (ma->spec_shader==MA_SPEC_BLINN) specfac= Blinn_Spec(vn, lv, view, ma->refrac, (float)shi->har, (vlr->flag & R_TANGENT) || (ma->mode & MA_TANGENT_V)); - else if(ma->spec_shader==MA_SPEC_WARDISO) + else if (ma->spec_shader==MA_SPEC_WARDISO) specfac= WardIso_Spec( vn, lv, view, ma->rms, (vlr->flag & R_TANGENT) || (ma->mode & MA_TANGENT_V)); else specfac= Toon_Spec(vn, lv, view, ma->param[2], ma->param[3], (vlr->flag & R_TANGENT) || (ma->mode & MA_TANGENT_V)); /* area lamp correction */ - if(lar->type==LA_AREA) specfac*= inp; + if (lar->type==LA_AREA) specfac*= inp; t= shadfac[3]*shi->spec*visifac*specfac; - if(ma->mode & MA_RAMP_SPEC) { + if (ma->mode & MA_RAMP_SPEC) { float spec[3]; do_specular_ramp(shi, specfac, t, spec); shr->spec[0]+= t*(lacol[0] * spec[0]); @@ -1515,7 +1516,7 @@ static void shade_one_light(LampRen *lar, ShadeInput *shi, ShadeResult *shr, int static void shade_lamp_loop_only_shadow(ShadeInput *shi, ShadeResult *shr) { - if(R.r.mode & R_SHADOW) { + if (R.r.mode & R_SHADOW) { ListBase *lights; LampRen *lar; GroupObject *go; @@ -1529,28 +1530,28 @@ static void shade_lamp_loop_only_shadow(ShadeInput *shi, ShadeResult *shr) accum= ir= 0.0f; lights= get_lights(shi); - for(go=lights->first; go; go= go->next) { + for (go=lights->first; go; go= go->next) { lar= go->lampren; - if(lar==NULL) continue; + if (lar==NULL) continue; /* yafray: ignore shading by photonlights, not used in Blender */ if (lar->type==LA_YF_PHOTON) continue; - if(lar->mode & LA_LAYER) if((lar->lay & shi->obi->lay)==0) continue; - if((lar->lay & shi->lay)==0) continue; + if (lar->mode & LA_LAYER) if((lar->lay & shi->obi->lay)==0) continue; + if ((lar->lay & shi->lay)==0) continue; - if(lar->shb || (lar->mode & LA_SHAD_RAY)) { + if (lar->shb || (lar->mode & LA_SHAD_RAY)) { visifac= lamp_get_visibility(lar, shi->co, lv, &lampdist); ir+= 1.0f; - if(visifac <= 0.0f) { + if (visifac <= 0.0f) { if (shi->mat->shadowonly_flag == MA_SO_OLD) accum+= 1.0f; continue; } inpr= dot_v3v3(shi->vn, lv); - if(inpr <= 0.0f) { + if (inpr <= 0.0f) { if (shi->mat->shadowonly_flag == MA_SO_OLD) accum+= 1.0f; @@ -1574,7 +1575,7 @@ static void shade_lamp_loop_only_shadow(ShadeInput *shi, ShadeResult *shr) } /* Apply shadows as alpha */ - if(ir>0.0f) { + if (ir>0.0f) { if (shi->mat->shadowonly_flag == MA_SO_OLD) { accum = 1.0f - accum/ir; } @@ -1604,13 +1605,13 @@ static void shade_lamp_loop_only_shadow(ShadeInput *shi, ShadeResult *shr) } /* quite disputable this... also note it doesn't mirror-raytrace */ - if((R.wrld.mode & (WO_AMB_OCC|WO_ENV_LIGHT)) && shi->amb!=0.0f) { + if ((R.wrld.mode & (WO_AMB_OCC|WO_ENV_LIGHT)) && shi->amb!=0.0f) { float f; - if(R.wrld.mode & WO_AMB_OCC) { + if (R.wrld.mode & WO_AMB_OCC) { f= R.wrld.aoenergy*shi->amb; - if(R.wrld.aomix==WO_AOADD) { + if (R.wrld.aomix==WO_AOADD) { if (shi->mat->shadowonly_flag == MA_SO_OLD) { f= f*(1.0f - rgb_to_grayscale(shi->ao)); shr->alpha= (shr->alpha + f)*f; @@ -1624,7 +1625,7 @@ static void shade_lamp_loop_only_shadow(ShadeInput *shi, ShadeResult *shr) shr->alpha= (1.0f - f)*shr->alpha + f*(1.0f - (1.0f - shr->alpha)*rgb_to_grayscale(shi->ao)); } - if(R.wrld.mode & WO_ENV_LIGHT) { + if (R.wrld.mode & WO_ENV_LIGHT) { if (shi->mat->shadowonly_flag == MA_SO_OLD) { f= R.wrld.ao_env_energy*shi->amb*(1.0f - rgb_to_grayscale(shi->env)); shr->alpha= (shr->alpha + f)*f; @@ -1654,10 +1655,10 @@ void shade_lamp_loop(ShadeInput *shi, ShadeResult *shr) memset(shr, 0, sizeof(ShadeResult)); - if(!(shi->mode & MA_TRANSP)) shi->alpha = 1.0f; + if (!(shi->mode & MA_TRANSP)) shi->alpha = 1.0f; /* separate loop */ - if(ma->mode & MA_ONLYSHADOW) { + if (ma->mode & MA_ONLYSHADOW) { shade_lamp_loop_only_shadow(shi, shr); return; } @@ -1666,21 +1667,21 @@ void shade_lamp_loop(ShadeInput *shi, ShadeResult *shr) shi->refcol[0]= shi->refcol[1]= shi->refcol[2]= shi->refcol[3]= 0.0f; /* material color itself */ - if(passflag & (SCE_PASS_COMBINED|SCE_PASS_RGBA)) { - if(ma->mode & (MA_FACETEXTURE)) { + if (passflag & (SCE_PASS_COMBINED|SCE_PASS_RGBA)) { + if (ma->mode & (MA_FACETEXTURE)) { shi->r= shi->vcol[0]; shi->g= shi->vcol[1]; shi->b= shi->vcol[2]; - if(ma->mode & (MA_FACETEXTURE_ALPHA)) + if (ma->mode & (MA_FACETEXTURE_ALPHA)) shi->alpha= shi->vcol[3]; } - else if(ma->mode & (MA_VERTEXCOLP)) { + else if (ma->mode & (MA_VERTEXCOLP)) { float neg_alpha = 1.0f - shi->vcol[3]; shi->r= shi->r*neg_alpha + shi->vcol[0]*shi->vcol[3]; shi->g= shi->g*neg_alpha + shi->vcol[1]*shi->vcol[3]; shi->b= shi->b*neg_alpha + shi->vcol[2]*shi->vcol[3]; } - if(ma->texco){ + if (ma->texco) { do_material_tex(shi, &R); if (!(shi->mode & MA_TRANSP)) shi->alpha = 1.0f; } @@ -1690,8 +1691,8 @@ void shade_lamp_loop(ShadeInput *shi, ShadeResult *shr) shr->col[2]= shi->b*shi->alpha; shr->col[3]= shi->alpha; - if((ma->sss_flag & MA_DIFF_SSS) && !sss_pass_done(&R, ma)) { - if(ma->sss_texfac == 0.0f) { + if ((ma->sss_flag & MA_DIFF_SSS) && !sss_pass_done(&R, ma)) { + if (ma->sss_texfac == 0.0f) { shi->r= shi->g= shi->b= shi->alpha= 1.0f; shr->col[0]= shr->col[1]= shr->col[2]= shr->col[3]= 1.0f; } @@ -1709,7 +1710,7 @@ void shade_lamp_loop(ShadeInput *shi, ShadeResult *shr) } } - if(ma->mode & MA_SHLESS) { + if (ma->mode & MA_SHLESS) { shr->combined[0]= shi->r; shr->combined[1]= shi->g; shr->combined[2]= shi->b; @@ -1717,7 +1718,7 @@ void shade_lamp_loop(ShadeInput *shi, ShadeResult *shr) return; } - if( (ma->mode & (MA_VERTEXCOL|MA_VERTEXCOLP))== MA_VERTEXCOL ) { // vertexcolor light + if ( (ma->mode & (MA_VERTEXCOL|MA_VERTEXCOLP))== MA_VERTEXCOL ) { // vertexcolor light shr->emit[0]= shi->r*(shi->emit+shi->vcol[0]*shi->vcol[3]); shr->emit[1]= shi->g*(shi->emit+shi->vcol[1]*shi->vcol[3]); shr->emit[2]= shi->b*(shi->emit+shi->vcol[2]*shi->vcol[3]); @@ -1729,12 +1730,12 @@ void shade_lamp_loop(ShadeInput *shi, ShadeResult *shr) } /* AO pass */ - if(R.wrld.mode & (WO_AMB_OCC|WO_ENV_LIGHT|WO_INDIRECT_LIGHT)) { - if(((passflag & SCE_PASS_COMBINED) && (shi->combinedflag & (SCE_PASS_AO|SCE_PASS_ENVIRONMENT|SCE_PASS_INDIRECT))) + if (R.wrld.mode & (WO_AMB_OCC|WO_ENV_LIGHT|WO_INDIRECT_LIGHT)) { + if (((passflag & SCE_PASS_COMBINED) && (shi->combinedflag & (SCE_PASS_AO|SCE_PASS_ENVIRONMENT|SCE_PASS_INDIRECT))) || (passflag & (SCE_PASS_AO|SCE_PASS_ENVIRONMENT|SCE_PASS_INDIRECT))) { - if(R.r.mode & R_SHADOW) { + if (R.r.mode & R_SHADOW) { /* AO was calculated for scanline already */ - if(shi->depth || shi->volume_depth) + if (shi->depth || shi->volume_depth) ambient_occlusion(shi); copy_v3_v3(shr->ao, shi->ao); copy_v3_v3(shr->env, shi->env); // XXX multiply @@ -1744,22 +1745,22 @@ void shade_lamp_loop(ShadeInput *shi, ShadeResult *shr) } /* lighting pass */ - if(passflag & (SCE_PASS_COMBINED|SCE_PASS_DIFFUSE|SCE_PASS_SPEC|SCE_PASS_SHADOW)) { + if (passflag & (SCE_PASS_COMBINED|SCE_PASS_DIFFUSE|SCE_PASS_SPEC|SCE_PASS_SHADOW)) { GroupObject *go; ListBase *lights; LampRen *lar; lights= get_lights(shi); - for(go=lights->first; go; go= go->next) { + for (go=lights->first; go; go= go->next) { lar= go->lampren; - if(lar==NULL) continue; + if (lar==NULL) continue; /* yafray: ignore shading by photonlights, not used in Blender */ if (lar->type==LA_YF_PHOTON) continue; /* test for lamp layer */ - if(lar->mode & LA_LAYER) if((lar->lay & shi->obi->lay)==0) continue; - if((lar->lay & shi->lay)==0) continue; + if (lar->mode & LA_LAYER) if((lar->lay & shi->obi->lay)==0) continue; + if ((lar->lay & shi->lay)==0) continue; /* accumulates in shr->diff and shr->spec and shr->shad (diffuse with shadow!) */ shade_one_light(lar, shi, shr, passflag); @@ -1775,18 +1776,18 @@ void shade_lamp_loop(ShadeInput *shi, ShadeResult *shr) if (shr->shad[1] < 0) shr->shad[1] = 0; if (shr->shad[2] < 0) shr->shad[2] = 0; - if(ma->sss_flag & MA_DIFF_SSS) { + if (ma->sss_flag & MA_DIFF_SSS) { float sss[3], col[3], invalpha, texfac= ma->sss_texfac; /* this will return false in the preprocess stage */ - if(sample_sss(&R, ma, shi->co, sss)) { + if (sample_sss(&R, ma, shi->co, sss)) { invalpha= (shr->col[3] > FLT_EPSILON)? 1.0f/shr->col[3]: 1.0f; - if(texfac==0.0f) { + if (texfac==0.0f) { copy_v3_v3(col, shr->col); mul_v3_fl(col, invalpha); } - else if(texfac==1.0f) { + else if (texfac==1.0f) { col[0]= col[1]= col[2]= 1.0f; mul_v3_fl(col, invalpha); } @@ -1802,7 +1803,7 @@ void shade_lamp_loop(ShadeInput *shi, ShadeResult *shr) shr->diff[1]= sss[1]*col[1]; shr->diff[2]= sss[2]*col[2]; - if(shi->combinedflag & SCE_PASS_SHADOW) { + if (shi->combinedflag & SCE_PASS_SHADOW) { shr->shad[0]= shr->diff[0]; shr->shad[1]= shr->diff[1]; shr->shad[2]= shr->diff[2]; @@ -1810,43 +1811,43 @@ void shade_lamp_loop(ShadeInput *shi, ShadeResult *shr) } } - if(shi->combinedflag & SCE_PASS_SHADOW) + if (shi->combinedflag & SCE_PASS_SHADOW) copy_v3_v3(shr->combined, shr->shad); /* note, no ';' ! */ else copy_v3_v3(shr->combined, shr->diff); /* calculate shadow pass, we use a multiplication mask */ /* if diff = 0,0,0 it doesn't matter what the shadow pass is, so leave it as is */ - if(passflag & SCE_PASS_SHADOW && !(shr->diff[0]==0.0f && shr->diff[1]==0.0f && shr->diff[2]==0.0f)) { - if(shr->diff[0]!=0.0f) shr->shad[0]= shr->shad[0]/shr->diff[0]; + if (passflag & SCE_PASS_SHADOW && !(shr->diff[0]==0.0f && shr->diff[1]==0.0f && shr->diff[2]==0.0f)) { + if (shr->diff[0]!=0.0f) shr->shad[0]= shr->shad[0]/shr->diff[0]; /* can't determine proper shadow from shad/diff (0/0), so use shadow intensity */ - else if(shr->shad[0]==0.0f) shr->shad[0]= shr->shad[3]; + else if (shr->shad[0]==0.0f) shr->shad[0]= shr->shad[3]; - if(shr->diff[1]!=0.0f) shr->shad[1]= shr->shad[1]/shr->diff[1]; - else if(shr->shad[1]==0.0f) shr->shad[1]= shr->shad[3]; + if (shr->diff[1]!=0.0f) shr->shad[1]= shr->shad[1]/shr->diff[1]; + else if (shr->shad[1]==0.0f) shr->shad[1]= shr->shad[3]; - if(shr->diff[2]!=0.0f) shr->shad[2]= shr->shad[2]/shr->diff[2]; - else if(shr->shad[2]==0.0f) shr->shad[2]= shr->shad[3]; + if (shr->diff[2]!=0.0f) shr->shad[2]= shr->shad[2]/shr->diff[2]; + else if (shr->shad[2]==0.0f) shr->shad[2]= shr->shad[3]; } /* exposure correction */ - if((R.wrld.exp!=0.0f || R.wrld.range!=1.0f) && !R.sss_points) { + if ((R.wrld.exp!=0.0f || R.wrld.range!=1.0f) && !R.sss_points) { wrld_exposure_correct(shr->combined); /* has no spec! */ wrld_exposure_correct(shr->spec); } } /* alpha in end, spec can influence it */ - if(passflag & (SCE_PASS_COMBINED)) { - if((ma->fresnel_tra!=0.0f) && (shi->mode & MA_TRANSP)) + if (passflag & (SCE_PASS_COMBINED)) { + if ((ma->fresnel_tra!=0.0f) && (shi->mode & MA_TRANSP)) shi->alpha*= fresnel_fac(shi->view, shi->vn, ma->fresnel_tra_i, ma->fresnel_tra); /* note: shi->mode! */ - if(shi->mode & MA_TRANSP && (shi->mode & (MA_ZTRANSP|MA_RAYTRANSP))) { - if(shi->spectra!=0.0f) { + if (shi->mode & MA_TRANSP && (shi->mode & (MA_ZTRANSP|MA_RAYTRANSP))) { + if (shi->spectra!=0.0f) { float t = MAX3(shr->spec[0], shr->spec[1], shr->spec[2]); t *= shi->spectra; - if(t>1.0f) t= 1.0f; + if (t>1.0f) t= 1.0f; shi->alpha= (1.0f-t)*shi->alpha+t; } } @@ -1854,19 +1855,19 @@ void shade_lamp_loop(ShadeInput *shi, ShadeResult *shr) shr->alpha= shi->alpha; /* from now stuff everything in shr->combined: ambient, AO, radio, ramps, exposure */ - if(!(ma->sss_flag & MA_DIFF_SSS) || !sss_pass_done(&R, ma)) { - if(R.r.mode & R_SHADOW) { + if (!(ma->sss_flag & MA_DIFF_SSS) || !sss_pass_done(&R, ma)) { + if (R.r.mode & R_SHADOW) { /* add AO in combined? */ - if(R.wrld.mode & WO_AMB_OCC) - if(shi->combinedflag & SCE_PASS_AO) + if (R.wrld.mode & WO_AMB_OCC) + if (shi->combinedflag & SCE_PASS_AO) ambient_occlusion_apply(shi, shr); - if(R.wrld.mode & WO_ENV_LIGHT) - if(shi->combinedflag & SCE_PASS_ENVIRONMENT) + if (R.wrld.mode & WO_ENV_LIGHT) + if (shi->combinedflag & SCE_PASS_ENVIRONMENT) environment_lighting_apply(shi, shr); - if(R.wrld.mode & WO_INDIRECT_LIGHT) - if(shi->combinedflag & SCE_PASS_INDIRECT) + if (R.wrld.mode & WO_INDIRECT_LIGHT) + if (shi->combinedflag & SCE_PASS_INDIRECT) indirect_lighting_apply(shi, shr); } @@ -1874,36 +1875,36 @@ void shade_lamp_loop(ShadeInput *shi, ShadeResult *shr) shr->combined[1]+= shi->ambg; shr->combined[2]+= shi->ambb; - if(ma->mode & MA_RAMP_COL) ramp_diffuse_result(shr->combined, shi); + if (ma->mode & MA_RAMP_COL) ramp_diffuse_result(shr->combined, shi); } - if(ma->mode & MA_RAMP_SPEC) ramp_spec_result(shr->spec, shi); + if (ma->mode & MA_RAMP_SPEC) ramp_spec_result(shr->spec, shi); /* refcol is for envmap only */ - if(shi->refcol[0]!=0.0f) { + if (shi->refcol[0]!=0.0f) { float result[3]; result[0]= shi->mirr*shi->refcol[1] + (1.0f - shi->mirr*shi->refcol[0])*shr->combined[0]; result[1]= shi->mirg*shi->refcol[2] + (1.0f - shi->mirg*shi->refcol[0])*shr->combined[1]; result[2]= shi->mirb*shi->refcol[3] + (1.0f - shi->mirb*shi->refcol[0])*shr->combined[2]; - if(passflag & SCE_PASS_REFLECT) + if (passflag & SCE_PASS_REFLECT) sub_v3_v3v3(shr->refl, result, shr->combined); - if(shi->combinedflag & SCE_PASS_REFLECT) + if (shi->combinedflag & SCE_PASS_REFLECT) copy_v3_v3(shr->combined, result); } /* and add emit and spec */ - if(shi->combinedflag & SCE_PASS_EMIT) + if (shi->combinedflag & SCE_PASS_EMIT) add_v3_v3(shr->combined, shr->emit); - if(shi->combinedflag & SCE_PASS_SPEC) + if (shi->combinedflag & SCE_PASS_SPEC) add_v3_v3(shr->combined, shr->spec); /* modulate by the object color */ - if((ma->shade_flag & MA_OBCOLOR) && shi->obr->ob) { - if(!(ma->sss_flag & MA_DIFF_SSS) || !sss_pass_done(&R, ma)) { + if ((ma->shade_flag & MA_OBCOLOR) && shi->obr->ob) { + if (!(ma->sss_flag & MA_DIFF_SSS) || !sss_pass_done(&R, ma)) { float obcol[4]; copy_v4_v4(obcol, shi->obr->ob->col); diff --git a/source/blender/render/intern/source/sss.c b/source/blender/render/intern/source/sss.c index 6e37c81b882..dd1bddc5020 100644 --- a/source/blender/render/intern/source/sss.c +++ b/source/blender/render/intern/source/sss.c @@ -184,26 +184,26 @@ static float compute_reduced_albedo(ScatterSettings *ss) fxn= f_Rd(xn, ss->A, ss->ro); fxn_1= f_Rd(xn_1, ss->A, ss->ro); - for(i= 0; i < max_iteration_count; i++) { + for (i= 0; i < max_iteration_count; i++) { fsub= (fxn - fxn_1); - if(fabsf(fsub) < tolerance) + if (fabsf(fsub) < tolerance) break; d= ((xn - xn_1)/fsub)*fxn; - if(fabsf(d) < tolerance) + if (fabsf(d) < tolerance) break; xn_1= xn; fxn_1= fxn; xn= xn - d; - if(xn > 1.0f) xn= 1.0f; - if(xn_1 > 1.0f) xn_1= 1.0f; + if (xn > 1.0f) xn= 1.0f; + if (xn_1 > 1.0f) xn_1= 1.0f; fxn= f_Rd(xn, ss->A, ss->ro); } /* avoid division by zero later */ - if(xn <= 0.0f) + if (xn <= 0.0f) xn= 0.00001f; return xn; @@ -240,15 +240,15 @@ static void approximate_Rd_rgb(ScatterSettings **ss, float rr, float *rd) float indexf, t, idxf; int index; - if(rr > (RD_TABLE_RANGE_2*RD_TABLE_RANGE_2)); - else if(rr > RD_TABLE_RANGE) { + if (rr > (RD_TABLE_RANGE_2*RD_TABLE_RANGE_2)); + else if (rr > RD_TABLE_RANGE) { rr= sqrt(rr); indexf= rr*(RD_TABLE_SIZE/RD_TABLE_RANGE_2); index= (int)indexf; idxf= (float)index; t= indexf - idxf; - if(index >= 0 && index < RD_TABLE_SIZE) { + if (index >= 0 && index < RD_TABLE_SIZE) { rd[0]= (ss[0]->tableRd2[index]*(1-t) + ss[0]->tableRd2[index+1]*t); rd[1]= (ss[1]->tableRd2[index]*(1-t) + ss[1]->tableRd2[index+1]*t); rd[2]= (ss[2]->tableRd2[index]*(1-t) + ss[2]->tableRd2[index+1]*t); @@ -261,7 +261,7 @@ static void approximate_Rd_rgb(ScatterSettings **ss, float rr, float *rd) idxf= (float)index; t= indexf - idxf; - if(index >= 0 && index < RD_TABLE_SIZE) { + if (index >= 0 && index < RD_TABLE_SIZE) { rd[0]= (ss[0]->tableRd[index]*(1-t) + ss[0]->tableRd[index+1]*t); rd[1]= (ss[1]->tableRd[index]*(1-t) + ss[1]->tableRd[index+1]*t); rd[2]= (ss[2]->tableRd[index]*(1-t) + ss[2]->tableRd[index+1]*t); @@ -283,7 +283,7 @@ static void build_Rd_table(ScatterSettings *ss) ss->tableRd= MEM_mallocN(sizeof(float)*size, "scatterTableRd"); ss->tableRd2= MEM_mallocN(sizeof(float)*size, "scatterTableRd"); - for(i= 0; i < size; i++) { + for (i= 0; i < size; i++) { r= i*(RD_TABLE_RANGE/RD_TABLE_SIZE); /*if(r < ss->invsigma_t_*ss->invsigma_t_) r= ss->invsigma_t_*ss->invsigma_t_;*/ @@ -353,7 +353,7 @@ static void add_radiance(ScatterTree *tree, float *frontrad, float *backrad, flo approximate_Rd_rgb(tree->ss, rr, rd); - if(frontrad && area) { + if (frontrad && area) { frontrd[0] = rd[0]*area; frontrd[1] = rd[1]*area; frontrd[2] = rd[2]*area; @@ -366,7 +366,7 @@ static void add_radiance(ScatterTree *tree, float *frontrad, float *backrad, flo result->rdsum[1] += frontrd[1]; result->rdsum[2] += frontrd[2]; } - if(backrad && backarea) { + if (backrad && backarea) { backrd[0] = rd[0]*backarea; backrd[1] = rd[1]*backarea; backrd[2] = rd[2]*backarea; @@ -386,15 +386,15 @@ static void traverse_octree(ScatterTree *tree, ScatterNode *node, float *co, int float sub[3], dist; int i, index = 0; - if(node->totpoint > 0) { + if (node->totpoint > 0) { /* leaf - add radiance from all samples */ - for(i=0; i<node->totpoint; i++) { + for (i=0; i<node->totpoint; i++) { ScatterPoint *p= &node->points[i]; sub_v3_v3v3(sub, co, p->co); dist= dot_v3v3(sub, sub); - if(p->back) + if (p->back) add_radiance(tree, NULL, p->rad, 0.0f, p->area, dist, result); else add_radiance(tree, p->rad, NULL, p->area, 0.0f, dist, result); @@ -405,11 +405,11 @@ static void traverse_octree(ScatterTree *tree, ScatterNode *node, float *co, int if (self) index = SUBNODE_INDEX(co, node->split); - for(i=0; i<8; i++) { - if(node->child[i]) { + for (i=0; i<8; i++) { + if (node->child[i]) { ScatterNode *subnode= node->child[i]; - if(self && index == i) { + if (self && index == i) { /* always traverse node containing the point */ traverse_octree(tree, subnode, co, 1, result); } @@ -419,7 +419,7 @@ static void traverse_octree(ScatterTree *tree, ScatterNode *node, float *co, int dist= dot_v3v3(sub, sub); /* actually area/dist > error, but this avoids division */ - if(subnode->area+subnode->backarea>tree->error*dist) { + if (subnode->area+subnode->backarea>tree->error*dist) { traverse_octree(tree, subnode, co, 0, result); } else { @@ -456,13 +456,13 @@ static void compute_radiance(ScatterTree *tree, float *co, float *rad) copy_v3_v3(rdsum, result.rdsum); add_v3_v3v3(backrdsum, result.rdsum, result.backrdsum); - if(rdsum[0] > 1e-16f) rad[0]= tree->ss[0]->color*rad[0]/rdsum[0]; - if(rdsum[1] > 1e-16f) rad[1]= tree->ss[1]->color*rad[1]/rdsum[1]; - if(rdsum[2] > 1e-16f) rad[2]= tree->ss[2]->color*rad[2]/rdsum[2]; + if (rdsum[0] > 1e-16f) rad[0]= tree->ss[0]->color*rad[0]/rdsum[0]; + if (rdsum[1] > 1e-16f) rad[1]= tree->ss[1]->color*rad[1]/rdsum[1]; + if (rdsum[2] > 1e-16f) rad[2]= tree->ss[2]->color*rad[2]/rdsum[2]; - if(backrdsum[0] > 1e-16f) backrad[0]= tree->ss[0]->color*backrad[0]/backrdsum[0]; - if(backrdsum[1] > 1e-16f) backrad[1]= tree->ss[1]->color*backrad[1]/backrdsum[1]; - if(backrdsum[2] > 1e-16f) backrad[2]= tree->ss[2]->color*backrad[2]/backrdsum[2]; + if (backrdsum[0] > 1e-16f) backrad[0]= tree->ss[0]->color*backrad[0]/backrdsum[0]; + if (backrdsum[1] > 1e-16f) backrad[1]= tree->ss[1]->color*backrad[1]/backrdsum[1]; + if (backrdsum[2] > 1e-16f) backrad[2]= tree->ss[2]->color*backrad[2]/backrdsum[2]; rad[0]= MAX2(rad[0], backrad[0]); rad[1]= MAX2(rad[1], backrad[1]); @@ -483,7 +483,7 @@ static void sum_leaf_radiance(ScatterTree *UNUSED(tree), ScatterNode *node) /* compute total rad, rad weighted average position, * and total area */ - for(i=0; i<node->totpoint; i++) { + for (i=0; i<node->totpoint; i++) { p= &node->points[i]; rad= p->area*fabsf(p->rad[0] + p->rad[1] + p->rad[2]); @@ -493,7 +493,7 @@ static void sum_leaf_radiance(ScatterTree *UNUSED(tree), ScatterNode *node) node->co[1] += rad*p->co[1]; node->co[2] += rad*p->co[2]; - if(p->back) { + if (p->back) { node->backrad[0] += p->rad[0]*p->area; node->backrad[1] += p->rad[1]*p->area; node->backrad[2] += p->rad[2]*p->area; @@ -509,20 +509,20 @@ static void sum_leaf_radiance(ScatterTree *UNUSED(tree), ScatterNode *node) } } - if(node->area > 1e-16f) { + if (node->area > 1e-16f) { inv= 1.0f/node->area; node->rad[0] *= inv; node->rad[1] *= inv; node->rad[2] *= inv; } - if(node->backarea > 1e-16f) { + if (node->backarea > 1e-16f) { inv= 1.0f/node->backarea; node->backrad[0] *= inv; node->backrad[1] *= inv; node->backrad[2] *= inv; } - if(totrad > 1e-16f) { + if (totrad > 1e-16f) { inv= 1.0f/totrad; node->co[0] *= inv; node->co[1] *= inv; @@ -531,7 +531,7 @@ static void sum_leaf_radiance(ScatterTree *UNUSED(tree), ScatterNode *node) else { /* make sure that if radiance is 0.0f, we still have these points in * the tree at a good position, they count for rdsum too */ - for(i=0; i<node->totpoint; i++) { + for (i=0; i<node->totpoint; i++) { p= &node->points[i]; node->co[0] += p->co[0]; @@ -557,8 +557,8 @@ static void sum_branch_radiance(ScatterTree *UNUSED(tree), ScatterNode *node) /* compute total rad, rad weighted average position, * and total area */ - for(i=0; i<8; i++) { - if(node->child[i] == NULL) + for (i=0; i<8; i++) { + if (node->child[i] == NULL) continue; subnode= node->child[i]; @@ -583,20 +583,20 @@ static void sum_branch_radiance(ScatterTree *UNUSED(tree), ScatterNode *node) node->backarea += subnode->backarea; } - if(node->area > 1e-16f) { + if (node->area > 1e-16f) { inv= 1.0f/node->area; node->rad[0] *= inv; node->rad[1] *= inv; node->rad[2] *= inv; } - if(node->backarea > 1e-16f) { + if (node->backarea > 1e-16f) { inv= 1.0f/node->backarea; node->backrad[0] *= inv; node->backrad[1] *= inv; node->backrad[2] *= inv; } - if(totrad > 1e-16f) { + if (totrad > 1e-16f) { inv= 1.0f/totrad; node->co[0] *= inv; node->co[1] *= inv; @@ -607,8 +607,8 @@ static void sum_branch_radiance(ScatterTree *UNUSED(tree), ScatterNode *node) * the tree at a good position, they count for rdsum too */ totnode= 0; - for(i=0; i<8; i++) { - if(node->child[i]) { + for (i=0; i<8; i++) { + if (node->child[i]) { subnode= node->child[i]; node->co[0] += subnode->co[0]; @@ -627,14 +627,14 @@ static void sum_branch_radiance(ScatterTree *UNUSED(tree), ScatterNode *node) static void sum_radiance(ScatterTree *tree, ScatterNode *node) { - if(node->totpoint > 0) { + if (node->totpoint > 0) { sum_leaf_radiance(tree, node); } else { int i; - for(i=0; i<8; i++) - if(node->child[i]) + for (i=0; i<8; i++) + if (node->child[i]) sum_radiance(tree, node->child[i]); sum_branch_radiance(tree, node); @@ -658,8 +658,8 @@ static void create_octree_node(ScatterTree *tree, ScatterNode *node, float *mid, float submid[3], subsize[3]; /* stopping condition */ - if(node->totpoint <= MAX_OCTREE_NODE_POINTS || depth == MAX_OCTREE_DEPTH) { - for(i=0; i<node->totpoint; i++) + if (node->totpoint <= MAX_OCTREE_NODE_POINTS || depth == MAX_OCTREE_DEPTH) { + for (i=0; i<node->totpoint; i++) node->points[i]= *(refpoints[i]); return; @@ -677,7 +677,7 @@ static void create_octree_node(ScatterTree *tree, ScatterNode *node, float *mid, memset(noffset, 0, sizeof(noffset)); /* count points in subnodes */ - for(i=0; i<node->totpoint; i++) { + for (i=0; i<node->totpoint; i++) { index= SUBNODE_INDEX(refpoints[i]->co, node->split); tmppoints[i]= refpoints[i]; nsize[index]++; @@ -686,31 +686,31 @@ static void create_octree_node(ScatterTree *tree, ScatterNode *node, float *mid, /* here we check if only one subnode is used. if this is the case, we don't * create a new node, but rather call this function again, with different * size and middle position for the same node. */ - for(usedi=0, usednodes=0, i=0; i<8; i++) { - if(nsize[i]) { + for (usedi=0, usednodes=0, i=0; i<8; i++) { + if (nsize[i]) { usednodes++; usedi = i; } - if(i != 0) + if (i != 0) noffset[i]= noffset[i-1]+nsize[i-1]; } - if(usednodes<=1) { + if (usednodes<=1) { subnode_middle(usedi, mid, subsize, submid); create_octree_node(tree, node, submid, subsize, refpoints, depth+1); return; } /* reorder refpoints by subnode */ - for(i=0; i<node->totpoint; i++) { + for (i=0; i<node->totpoint; i++) { index= SUBNODE_INDEX(tmppoints[i]->co, node->split); refpoints[noffset[index]]= tmppoints[i]; noffset[index]++; } /* create subnodes */ - for(subco=0, i=0; i<8; subco+=nsize[i], i++) { - if(nsize[i] > 0) { + for (subco=0, i=0; i<8; subco+=nsize[i], i++) { + if (nsize[i] > 0) { subnode= BLI_memarena_alloc(tree->arena, sizeof(ScatterNode)); node->child[i]= subnode; subnode->points= node->points + subco; @@ -758,7 +758,7 @@ ScatterTree *scatter_tree_new(ScatterSettings *ss[3], float scale, float error, /* build points */ INIT_MINMAX(tree->min, tree->max); - for(i=0; i<totpoint; i++) { + for (i=0; i<totpoint; i++) { copy_v3_v3(points[i].co, co[i]); copy_v3_v3(points[i].rad, color[i]); points[i].area= fabsf(area[i])/(tree->scale*tree->scale); @@ -857,7 +857,7 @@ static void sss_create_tree_mat(Render *re, Material *mat) float (*co)[3] = NULL, (*color)[3] = NULL, *area = NULL; int totpoint = 0, osa, osaflag, partsdone; - if(re->test_break(re->tbh)) + if (re->test_break(re->tbh)) return; points.first= points.last= NULL; @@ -878,14 +878,14 @@ static void sss_create_tree_mat(Render *re, Material *mat) re->sss_mat= mat; re->i.partsdone= 0; - if(!(re->r.scemode & R_PREVIEWBUTS)) + if (!(re->r.scemode & R_PREVIEWBUTS)) re->result= NULL; BLI_rw_mutex_unlock(&re->resultmutex); RE_TileProcessor(re); BLI_rw_mutex_lock(&re->resultmutex, THREAD_LOCK_WRITE); - if(!(re->r.scemode & R_PREVIEWBUTS)) { + if (!(re->r.scemode & R_PREVIEWBUTS)) { RE_FreeRenderResult(re->result); re->result= rr; } @@ -898,19 +898,19 @@ static void sss_create_tree_mat(Render *re, Material *mat) if (osaflag) re->r.mode |= R_OSA; /* no points? no tree */ - if(!points.first) + if (!points.first) return; /* merge points together into a single buffer */ - if(!re->test_break(re->tbh)) { - for(totpoint=0, p=points.first; p; p=p->next) + if (!re->test_break(re->tbh)) { + for (totpoint=0, p=points.first; p; p=p->next) totpoint += p->totpoint; co= MEM_mallocN(sizeof(*co)*totpoint, "SSSCo"); color= MEM_mallocN(sizeof(*color)*totpoint, "SSSColor"); area= MEM_mallocN(sizeof(*area)*totpoint, "SSSArea"); - for(totpoint=0, p=points.first; p; p=p->next) { + for (totpoint=0, p=points.first; p; p=p->next) { memcpy(co+totpoint, p->co, sizeof(*co)*p->totpoint); memcpy(color+totpoint, p->color, sizeof(*color)*p->totpoint); memcpy(area+totpoint, p->area, sizeof(*area)*p->totpoint); @@ -919,7 +919,7 @@ static void sss_create_tree_mat(Render *re, Material *mat) } /* free points */ - for(p=points.first; p; p=p->next) { + for (p=points.first; p; p=p->next) { MEM_freeN(p->co); MEM_freeN(p->color); MEM_freeN(p->area); @@ -927,7 +927,7 @@ static void sss_create_tree_mat(Render *re, Material *mat) BLI_freelistN(&points); /* build tree */ - if(!re->test_break(re->tbh)) { + if (!re->test_break(re->tbh)) { SSSData *sss= MEM_callocN(sizeof(*sss), "SSSData"); float ior= mat->sss_ior, cfac= mat->sss_colfac; float *radius= mat->sss_radius; @@ -935,7 +935,7 @@ static void sss_create_tree_mat(Render *re, Material *mat) float error = mat->sss_error; error= get_render_aosss_error(&re->r, error); - if((re->r.scemode & R_PREVIEWBUTS) && error < 0.5f) + if ((re->r.scemode & R_PREVIEWBUTS) && error < 0.5f) error= 0.5f; sss->ss[0]= scatter_settings_new(mat->sss_col[0], radius[0], ior, cfac, fw, bw); @@ -963,7 +963,7 @@ void sss_add_points(Render *re, float (*co)[3], float (*color)[3], float *area, { SSSPoints *p; - if(totpoint > 0) { + if (totpoint > 0) { p= MEM_callocN(sizeof(SSSPoints), "SSSPoints"); p->co= co; @@ -997,15 +997,15 @@ void make_sss_tree(Render *re) re->i.infostr= "SSS preprocessing"; re->stats_draw(re->sdh, &re->i); - for(mat= re->main->mat.first; mat; mat= mat->id.next) - if(mat->id.us && (mat->flag & MA_IS_USED) && (mat->sss_flag & MA_DIFF_SSS)) + for (mat= re->main->mat.first; mat; mat= mat->id.next) + if (mat->id.us && (mat->flag & MA_IS_USED) && (mat->sss_flag & MA_DIFF_SSS)) sss_create_tree_mat(re, mat); /* XXX preview exception */ /* localizing preview render data is not fun for node trees :( */ - if(re->main!=G.main) { - for(mat= G.main->mat.first; mat; mat= mat->id.next) - if(mat->id.us && (mat->flag & MA_IS_USED) && (mat->sss_flag & MA_DIFF_SSS)) + if (re->main!=G.main) { + for (mat= G.main->mat.first; mat; mat= mat->id.next) + if (mat->id.us && (mat->flag & MA_IS_USED) && (mat->sss_flag & MA_DIFF_SSS)) sss_create_tree_mat(re, mat); } @@ -1013,10 +1013,10 @@ void make_sss_tree(Render *re) void free_sss(Render *re) { - if(re->sss_hash) { + if (re->sss_hash) { GHashIterator *it= BLI_ghashIterator_new(re->sss_hash); - while(!BLI_ghashIterator_isDone(it)) { + while (!BLI_ghashIterator_isDone(it)) { sss_free_tree(BLI_ghashIterator_getValue(it)); BLI_ghashIterator_step(it); } @@ -1029,10 +1029,10 @@ void free_sss(Render *re) int sample_sss(Render *re, Material *mat, float *co, float *color) { - if(re->sss_hash) { + if (re->sss_hash) { SSSData *sss= BLI_ghash_lookup(re->sss_hash, mat); - if(sss) { + if (sss) { scatter_tree_sample(sss->tree, co, color); return 1; } diff --git a/source/blender/render/intern/source/strand.c b/source/blender/render/intern/source/strand.c index b5ace10fc07..9a24e1dbe75 100644 --- a/source/blender/render/intern/source/strand.c +++ b/source/blender/render/intern/source/strand.c @@ -74,8 +74,8 @@ static float strand_eval_width(Material *ma, float strandco) strandco= 0.5f*(strandco + 1.0f); - if(ma->strand_ease!=0.0f) { - if(ma->strand_ease<0.0f) + if (ma->strand_ease!=0.0f) { + if (ma->strand_ease<0.0f) fac= pow(strandco, 1.0f+ma->strand_ease); else fac= pow(strandco, 1.0f/(1.0f-ma->strand_ease)); @@ -103,27 +103,27 @@ void strand_eval_point(StrandSegment *sseg, StrandPoint *spoint) copy_v3_v3(p[2], sseg->v[2]->co); copy_v3_v3(p[3], sseg->v[3]->co); - if(sseg->obi->flag & R_TRANSFORMED) { + if (sseg->obi->flag & R_TRANSFORMED) { mul_m4_v3(sseg->obi->mat, p[0]); mul_m4_v3(sseg->obi->mat, p[1]); mul_m4_v3(sseg->obi->mat, p[2]); mul_m4_v3(sseg->obi->mat, p[3]); } - if(t == 0.0f) { + if (t == 0.0f) { copy_v3_v3(spoint->co, p[1]); spoint->strandco= sseg->v[1]->strandco; spoint->dtstrandco= (sseg->v[2]->strandco - sseg->v[0]->strandco); - if(sseg->v[0] != sseg->v[1]) + if (sseg->v[0] != sseg->v[1]) spoint->dtstrandco *= 0.5f; } - else if(t == 1.0f) { + else if (t == 1.0f) { copy_v3_v3(spoint->co, p[2]); spoint->strandco= sseg->v[2]->strandco; spoint->dtstrandco= (sseg->v[3]->strandco - sseg->v[1]->strandco); - if(sseg->v[3] != sseg->v[2]) + if (sseg->v[3] != sseg->v[2]) spoint->dtstrandco *= 0.5f; } else { @@ -157,17 +157,17 @@ void strand_eval_point(StrandSegment *sseg, StrandPoint *spoint) dy= strandbuf->winy*cross[1]*strandbuf->winmat[1][1]/w; w= sqrt(dx*dx + dy*dy); - if(w > 0.0f) { - if(strandbuf->flag & R_STRAND_B_UNITS) { + if (w > 0.0f) { + if (strandbuf->flag & R_STRAND_B_UNITS) { const float crosslen= len_v3(cross); w= 2.0f*crosslen*strandbuf->minwidth/w; - if(spoint->width < w) { + if (spoint->width < w) { spoint->alpha= spoint->width/w; spoint->width= w; } - if(simplify) + if (simplify) /* squared because we only change width, not length */ spoint->width *= simplify[0]*simplify[0]; @@ -211,45 +211,45 @@ static void interpolate_shade_result(ShadeResult *shr1, ShadeResult *shr2, float interpolate_vec4(shr1->combined, shr2->combined, t, negt, shr->combined); - if(addpassflag & SCE_PASS_VECTOR) { + if (addpassflag & SCE_PASS_VECTOR) { interpolate_vec4(shr1->winspeed, shr2->winspeed, t, negt, shr->winspeed); } /* optim... */ - if(addpassflag & ~(SCE_PASS_VECTOR)) { - if(addpassflag & SCE_PASS_Z) + if (addpassflag & ~(SCE_PASS_VECTOR)) { + if (addpassflag & SCE_PASS_Z) interpolate_vec1(&shr1->z, &shr2->z, t, negt, &shr->z); - if(addpassflag & SCE_PASS_RGBA) + if (addpassflag & SCE_PASS_RGBA) interpolate_vec4(shr1->col, shr2->col, t, negt, shr->col); - if(addpassflag & SCE_PASS_NORMAL) { + if (addpassflag & SCE_PASS_NORMAL) { interpolate_vec3(shr1->nor, shr2->nor, t, negt, shr->nor); normalize_v3(shr->nor); } - if(addpassflag & SCE_PASS_EMIT) + if (addpassflag & SCE_PASS_EMIT) interpolate_vec3(shr1->emit, shr2->emit, t, negt, shr->emit); - if(addpassflag & SCE_PASS_DIFFUSE) + if (addpassflag & SCE_PASS_DIFFUSE) interpolate_vec3(shr1->diff, shr2->diff, t, negt, shr->diff); - if(addpassflag & SCE_PASS_SPEC) + if (addpassflag & SCE_PASS_SPEC) interpolate_vec3(shr1->spec, shr2->spec, t, negt, shr->spec); - if(addpassflag & SCE_PASS_SHADOW) + if (addpassflag & SCE_PASS_SHADOW) interpolate_vec3(shr1->shad, shr2->shad, t, negt, shr->shad); - if(addpassflag & SCE_PASS_AO) + if (addpassflag & SCE_PASS_AO) interpolate_vec3(shr1->ao, shr2->ao, t, negt, shr->ao); - if(addpassflag & SCE_PASS_ENVIRONMENT) + if (addpassflag & SCE_PASS_ENVIRONMENT) interpolate_vec3(shr1->env, shr2->env, t, negt, shr->env); - if(addpassflag & SCE_PASS_INDIRECT) + if (addpassflag & SCE_PASS_INDIRECT) interpolate_vec3(shr1->indirect, shr2->indirect, t, negt, shr->indirect); - if(addpassflag & SCE_PASS_REFLECT) + if (addpassflag & SCE_PASS_REFLECT) interpolate_vec3(shr1->refl, shr2->refl, t, negt, shr->refl); - if(addpassflag & SCE_PASS_REFRACT) + if (addpassflag & SCE_PASS_REFRACT) interpolate_vec3(shr1->refr, shr2->refr, t, negt, shr->refr); - if(addpassflag & SCE_PASS_MIST) + if (addpassflag & SCE_PASS_MIST) interpolate_vec1(&shr1->mist, &shr2->mist, t, negt, &shr->mist); } } static void strand_apply_shaderesult_alpha(ShadeResult *shr, float alpha) { - if(alpha < 1.0f) { + if (alpha < 1.0f) { shr->combined[0] *= alpha; shr->combined[1] *= alpha; shr->combined[2] *= alpha; @@ -273,7 +273,7 @@ static void strand_shade_point(Render *re, ShadeSample *ssamp, StrandSegment *ss memset(&vlr, 0, sizeof(vlr)); vlr.flag= R_SMOOTH; - if(sseg->buffer->ma->mode & MA_TANGENT_STR) + if (sseg->buffer->ma->mode & MA_TANGENT_STR) vlr.flag |= R_TANGENT; shi->vlr= &vlr; @@ -308,8 +308,8 @@ static void strand_shade_point(Render *re, ShadeSample *ssamp, StrandSegment *ss strand_apply_shaderesult_alpha(shr, spoint->alpha); /* include lamphalos for strand, since halo layer was added already */ - if(re->flag & R_LAMPHALO) - if(shi->layflag & SCE_LAY_HALO) + if (re->flag & R_LAMPHALO) + if (shi->layflag & SCE_LAY_HALO) renderspothalo(shi, shr->combined, shr->combined[3]); shi->strand= NULL; @@ -352,7 +352,7 @@ static void strand_shade_get(Render *re, StrandShadeCache *cache, ShadeSample *s hashshr= BLI_ghash_lookup(cache->resulthash, svert); refcount= BLI_ghash_lookup(cache->refcounthash, svert); - if(!hashshr) { + if (!hashshr) { /* not shaded yet, shade and insert into hash */ p.t= (sseg->v[1] == svert)? 0.0f: 1.0f; strand_eval_point(sseg, &p); @@ -368,7 +368,7 @@ static void strand_shade_get(Render *re, StrandShadeCache *cache, ShadeSample *s /* lower reference count and remove if not needed anymore by any samples */ (*refcount)--; - if(*refcount == 0) { + if (*refcount == 0) { BLI_ghash_remove(cache->resulthash, svert, NULL, (GHashValFreeFP)MEM_freeN); BLI_ghash_remove(cache->refcounthash, svert, NULL, NULL); } @@ -387,7 +387,7 @@ void strand_shade_segment(Render *re, StrandShadeCache *cache, StrandSegment *ss interpolate_shade_result(&shr1, &shr2, t, ssamp->shr, addpassflag); /* apply alpha along width */ - if(sseg->buffer->widthfade != 0.0f) { + if (sseg->buffer->widthfade != 0.0f) { s = 1.0f - pow(fabs(s), sseg->buffer->widthfade); strand_apply_shaderesult_alpha(ssamp->shr, s); @@ -402,7 +402,7 @@ void strand_shade_unref(StrandShadeCache *cache, StrandVert *svert) refcount= BLI_ghash_lookup(cache->refcounthash, svert); (*refcount)--; - if(*refcount == 0) { + if (*refcount == 0) { BLI_ghash_remove(cache->resulthash, svert, NULL, (GHashValFreeFP)MEM_freeN); BLI_ghash_remove(cache->refcounthash, svert, NULL, NULL); } @@ -412,7 +412,7 @@ static void strand_shade_refcount(StrandShadeCache *cache, StrandVert *svert) { int *refcount= BLI_ghash_lookup(cache->refcounthash, svert); - if(!refcount) { + if (!refcount) { refcount= BLI_memarena_alloc(cache->memarena, sizeof(int)); *refcount= 1; BLI_ghash_insert(cache->refcounthash, svert, refcount); @@ -454,9 +454,9 @@ static int compare_strand_segment(const void *poin1, const void *poin2) const StrandSortSegment *seg1= (const StrandSortSegment*)poin1; const StrandSortSegment *seg2= (const StrandSortSegment*)poin2; - if(seg1->z < seg2->z) + if (seg1->z < seg2->z) return -1; - else if(seg1->z == seg2->z) + else if (seg1->z == seg2->z) return 0; else return 1; @@ -493,7 +493,7 @@ static APixstrand *addpsmainAstrand(ListBase *lb) static APixstrand *addpsAstrand(ZSpan *zspan) { /* make new PS */ - if(zspan->apstrandmcounter==0) { + if (zspan->apstrandmcounter==0) { zspan->curpstrand= addpsmainAstrand(zspan->apsmbase); zspan->apstrandmcounter= 4095; } @@ -524,19 +524,19 @@ static void do_strand_fillac(void *handle, int x, int y, float u, float v, float /* check against solid z-buffer */ zverg= (int)z; - if(spart->rectdaps) { + if (spart->rectdaps) { /* find the z of the sample */ PixStr *ps; intptr_t *rd= spart->rectdaps + offset; bufferz= 0x7FFFFFFF; - if(spart->rectmask) maskz= 0x7FFFFFFF; + if (spart->rectmask) maskz= 0x7FFFFFFF; - if(*rd) { - for(ps= (PixStr *)(*rd); ps; ps= ps->next) { - if(mask & ps->mask) { + if (*rd) { + for (ps= (PixStr *)(*rd); ps; ps= ps->next) { + if (mask & ps->mask) { bufferz= ps->z; - if(spart->rectmask) + if (spart->rectmask) maskz= ps->maskz; break; } @@ -545,25 +545,25 @@ static void do_strand_fillac(void *handle, int x, int y, float u, float v, float } else { bufferz= (spart->rectz)? spart->rectz[offset]: 0x7FFFFFFF; - if(spart->rectmask) + if (spart->rectmask) maskz= spart->rectmask[offset]; } #define CHECK_ADD(n) \ - if(apn->p[n]==strnr && apn->obi[n]==obi && apn->seg[n]==seg) \ + if (apn->p[n]==strnr && apn->obi[n]==obi && apn->seg[n]==seg) \ { if(!(apn->mask[n] & mask)) { apn->mask[n] |= mask; apn->v[n] += t; apn->u[n] += s; } break; } #define CHECK_ASSIGN(n) \ - if(apn->p[n]==0) \ + if (apn->p[n]==0) \ {apn->obi[n]= obi; apn->p[n]= strnr; apn->z[n]= zverg; apn->mask[n]= mask; apn->v[n]= t; apn->u[n]= s; apn->seg[n]= seg; break; } /* add to pixel list */ - if(zverg < bufferz && (spart->totapixbuf[offset] < MAX_ZROW)) { - if(!spart->rectmask || zverg > maskz) { + if (zverg < bufferz && (spart->totapixbuf[offset] < MAX_ZROW)) { + if (!spart->rectmask || zverg > maskz) { t = u*spart->t[0] + v*spart->t[1] + (1.0f-u-v)*spart->t[2]; s = fabs(u*spart->s[0] + v*spart->s[1] + (1.0f-u-v)*spart->s[2]); apn= spart->apixbuf + offset; - while(apn) { + while (apn) { CHECK_ADD(0); CHECK_ADD(1); CHECK_ADD(2); @@ -579,7 +579,7 @@ static void do_strand_fillac(void *handle, int x, int y, float u, float v, float CHECK_ASSIGN(0); } - if(cache) { + if (cache) { strand_shade_refcount(cache, sseg->v[1]); strand_shade_refcount(cache, sseg->v[2]); } @@ -599,11 +599,11 @@ static int strand_test_clip(float winmat[][4], ZSpan *UNUSED(zspan), float *boun /* we compare z without perspective division for segment sorting */ *zcomp= hoco[2]; - if(hoco[0]+widthx < bounds[0]*hoco[3]) clipflag |= 1; - else if(hoco[0]-widthx > bounds[1]*hoco[3]) clipflag |= 2; + if (hoco[0]+widthx < bounds[0]*hoco[3]) clipflag |= 1; + else if (hoco[0]-widthx > bounds[1]*hoco[3]) clipflag |= 2; - if(hoco[1]-widthy > bounds[3]*hoco[3]) clipflag |= 4; - else if(hoco[1]+widthy < bounds[2]*hoco[3]) clipflag |= 8; + if (hoco[1]-widthy > bounds[3]*hoco[3]) clipflag |= 4; + else if (hoco[1]+widthy < bounds[2]*hoco[3]) clipflag |= 8; clipflag |= testclip(hoco); @@ -619,7 +619,7 @@ static void do_scanconvert_strand(Render *UNUSED(re), StrandPart *spart, ZSpan * copy_v3_v3(jco3, co3); copy_v3_v3(jco4, co4); - if(spart->jit) { + if (spart->jit) { jx= -spart->jit[sample][0]; jy= -spart->jit[sample][1]; @@ -651,13 +651,13 @@ static void do_scanconvert_strand(Render *UNUSED(re), StrandPart *spart, ZSpan * static void strand_render(Render *re, StrandSegment *sseg, float winmat[][4], StrandPart *spart, ZSpan *zspan, int totzspan, StrandPoint *p1, StrandPoint *p2) { - if(spart) { + if (spart) { float t= p2->t; float dt= p2->t - p1->t; int a; - if(re->osa) { - for(a=0; a<re->osa; a++) + if (re->osa) { + for (a=0; a<re->osa; a++) do_scanconvert_strand(re, spart, zspan, t, dt, p1->zco2, p1->zco1, p2->zco1, p2->zco2, a); } else @@ -674,7 +674,7 @@ static void strand_render(Render *re, StrandSegment *sseg, float winmat[][4], St projectvert(p2->co, winmat, hoco2); - for(a=0; a<totzspan; a++) { + for (a=0; a<totzspan; a++) { #if 0 /* render both strand and single pixel wire to counter aliasing */ zbufclip4(re, &zspan[a], obi, index, p1->hoco2, p1->hoco1, p2->hoco1, p2->hoco2, p1->clip2, p1->clip1, p2->clip1, p2->clip2); @@ -692,7 +692,7 @@ static int strand_segment_recursive(Render *re, float winmat[][4], StrandPart *s StrandBuffer *buffer= sseg->buffer; float dot, d1[2], d2[2], len1, len2; - if(depth == buffer->maxdepth) + if (depth == buffer->maxdepth) return 0; p.t= (p1->t + p2->t)*0.5f; @@ -707,14 +707,14 @@ static int strand_segment_recursive(Render *re, float winmat[][4], StrandPart *s d2[1]= (p2->y - p.y); len2= d2[0]*d2[0] + d2[1]*d2[1]; - if(len1 == 0.0f || len2 == 0.0f) + if (len1 == 0.0f || len2 == 0.0f) return 0; dot= d1[0]*d2[0] + d1[1]*d2[1]; - if(dot*dot > sseg->sqadaptcos*len1*len2) + if (dot*dot > sseg->sqadaptcos*len1*len2) return 0; - if(spart) { + if (spart) { do_strand_point_project(winmat, zspan, p.co1, p.hoco1, p.zco1); do_strand_point_project(winmat, zspan, p.co2, p.hoco2, p.zco2); } @@ -727,9 +727,9 @@ static int strand_segment_recursive(Render *re, float winmat[][4], StrandPart *s #endif } - if(!strand_segment_recursive(re, winmat, spart, zspan, totzspan, sseg, p1, &p, depth+1)) + if (!strand_segment_recursive(re, winmat, spart, zspan, totzspan, sseg, p1, &p, depth+1)) strand_render(re, sseg, winmat, spart, zspan, totzspan, p1, &p); - if(!strand_segment_recursive(re, winmat, spart, zspan, totzspan, sseg, &p, p2, depth+1)) + if (!strand_segment_recursive(re, winmat, spart, zspan, totzspan, sseg, &p, p2, depth+1)) strand_render(re, sseg, winmat, spart, zspan, totzspan, &p, p2); return 1; @@ -749,7 +749,7 @@ void render_strand_segment(Render *re, float winmat[][4], StrandPart *spart, ZSp strand_eval_point(sseg, p2); strand_project_point(buffer->winmat, buffer->winx, buffer->winy, p2); - if(spart) { + if (spart) { do_strand_point_project(winmat, zspan, p1->co1, p1->hoco1, p1->zco1); do_strand_point_project(winmat, zspan, p1->co2, p1->hoco2, p1->zco2); do_strand_point_project(winmat, zspan, p2->co1, p2->hoco1, p2->zco1); @@ -768,7 +768,7 @@ void render_strand_segment(Render *re, float winmat[][4], StrandPart *spart, ZSp #endif } - if(!strand_segment_recursive(re, winmat, spart, zspan, totzspan, sseg, p1, p2, 0)) + if (!strand_segment_recursive(re, winmat, spart, zspan, totzspan, sseg, p1, p2, 0)) strand_render(re, sseg, winmat, spart, zspan, totzspan, p1, p2); } @@ -788,9 +788,9 @@ int zbuffer_strands_abuf(Render *re, RenderPart *pa, APixstrand *apixbuf, ListBa float z[4], bounds[4], obwinmat[4][4]; int a, b, c, i, totsegment, clip[4]; - if(re->test_break(re->tbh)) + if (re->test_break(re->tbh)) return 0; - if(re->totstrand == 0) + if (re->totstrand == 0) return 0; /* setup StrandPart */ @@ -818,7 +818,7 @@ int zbuffer_strands_abuf(Render *re, RenderPart *pa, APixstrand *apixbuf, ListBa zspan.zofsy= -pa->disprect.ymin; /* to center the sample position */ - if(!shadow) { + if (!shadow) { zspan.zofsx -= 0.5f; zspan.zofsy -= 0.5f; } @@ -836,17 +836,17 @@ int zbuffer_strands_abuf(Render *re, RenderPart *pa, APixstrand *apixbuf, ListBa totsegment= 0; /* for all object instances */ - for(obi=re->instancetable.first, i=0; obi; obi=obi->next, i++) { + for (obi=re->instancetable.first, i=0; obi; obi=obi->next, i++) { Material *ma; float widthx, widthy; obr= obi->obr; - if(!obr->strandbuf || !(obr->strandbuf->lay & lay)) + if (!obr->strandbuf || !(obr->strandbuf->lay & lay)) continue; /* compute matrix and try clipping whole object */ - if(obi->flag & R_TRANSFORMED) + if (obi->flag & R_TRANSFORMED) mult_m4_m4m4(obwinmat, winmat, obi->mat); else copy_m4_m4(obwinmat, winmat); @@ -854,12 +854,12 @@ int zbuffer_strands_abuf(Render *re, RenderPart *pa, APixstrand *apixbuf, ListBa /* test if we should skip it */ ma = obr->strandbuf->ma; - if(shadow && !(ma->mode & MA_SHADBUF)) + if (shadow && !(ma->mode & MA_SHADBUF)) continue; - else if(!shadow && (ma->mode & MA_ONLYCAST)) + else if (!shadow && (ma->mode & MA_ONLYCAST)) continue; - if(clip_render_object(obi->obr->boundbox, bounds, obwinmat)) + if (clip_render_object(obi->obr->boundbox, bounds, obwinmat)) continue; widthx= obr->strandbuf->maxwidth*obwinmat[0][0]; @@ -867,12 +867,12 @@ int zbuffer_strands_abuf(Render *re, RenderPart *pa, APixstrand *apixbuf, ListBa /* for each bounding box containing a number of strands */ sbound= obr->strandbuf->bound; - for(c=0; c<obr->strandbuf->totbound; c++, sbound++) { - if(clip_render_object(sbound->boundbox, bounds, obwinmat)) + for (c=0; c<obr->strandbuf->totbound; c++, sbound++) { + if (clip_render_object(sbound->boundbox, bounds, obwinmat)) continue; /* for each strand in this bounding box */ - for(a=sbound->start; a<sbound->end; a++) { + for (a=sbound->start; a<sbound->end; a++) { strand= RE_findOrAddStrand(obr, a); svert= strand->vert; @@ -881,9 +881,9 @@ int zbuffer_strands_abuf(Render *re, RenderPart *pa, APixstrand *apixbuf, ListBa clip[2]= strand_test_clip(obwinmat, &zspan, bounds, (svert+1)->co, &z[2], widthx, widthy); clip[0]= clip[1]; z[0]= z[1]; - for(b=0; b<strand->totvert-1; b++, svert++) { + for (b=0; b<strand->totvert-1; b++, svert++) { /* compute 4th point clipping and z depth */ - if(b < strand->totvert-2) { + if (b < strand->totvert-2) { clip[3]= strand_test_clip(obwinmat, &zspan, bounds, (svert+2)->co, &z[3], widthx, widthy); } else { @@ -891,7 +891,7 @@ int zbuffer_strands_abuf(Render *re, RenderPart *pa, APixstrand *apixbuf, ListBa } /* check clipping and add to sortsegments buffer */ - if(!(clip[0] & clip[1] & clip[2] & clip[3])) { + if (!(clip[0] & clip[1] & clip[2] & clip[3])) { sortseg= BLI_memarena_alloc(memarena, sizeof(StrandSortSegment)); sortseg->obi= i; sortseg->strand= strand->index; @@ -913,10 +913,10 @@ int zbuffer_strands_abuf(Render *re, RenderPart *pa, APixstrand *apixbuf, ListBa } } - if(!re->test_break(re->tbh)) { + if (!re->test_break(re->tbh)) { /* convert list to array and sort */ sortsegments= MEM_mallocN(sizeof(StrandSortSegment)*totsegment, "StrandSortSegment"); - for(a=0, sortseg=firstseg; a<totsegment; a++, sortseg=sortseg->next) + for (a=0, sortseg=firstseg; a<totsegment; a++, sortseg=sortseg->next) sortsegments[a]= *sortseg; qsort(sortsegments, totsegment, sizeof(StrandSortSegment), compare_strand_segment); } @@ -925,11 +925,11 @@ int zbuffer_strands_abuf(Render *re, RenderPart *pa, APixstrand *apixbuf, ListBa spart.totapixbuf= MEM_callocN(sizeof(int)*pa->rectx*pa->recty, "totapixbuf"); - if(!re->test_break(re->tbh)) { + if (!re->test_break(re->tbh)) { /* render segments in sorted order */ sortseg= sortsegments; - for(a=0; a<totsegment; a++, sortseg++) { - if(re->test_break(re->tbh)) + for (a=0; a<totsegment; a++, sortseg++) { + if (re->test_break(re->tbh)) break; obi= &re->objectinstance[sortseg->obi]; @@ -954,7 +954,7 @@ int zbuffer_strands_abuf(Render *re, RenderPart *pa, APixstrand *apixbuf, ListBa } } - if(sortsegments) + if (sortsegments) MEM_freeN(sortsegments); MEM_freeN(spart.totapixbuf); @@ -976,12 +976,12 @@ StrandSurface *cache_strand_surface(Render *re, ObjectRen *obr, DerivedMesh *dm, totvert= dm->getNumVerts(dm); totface= dm->getNumTessFaces(dm); - for(mesh=re->strandsurface.first; mesh; mesh=mesh->next) - if(mesh->obr.ob == obr->ob && mesh->obr.par == obr->par + for (mesh=re->strandsurface.first; mesh; mesh=mesh->next) + if (mesh->obr.ob == obr->ob && mesh->obr.par == obr->par && mesh->obr.index == obr->index && mesh->totvert==totvert && mesh->totface==totface) break; - if(!mesh) { + if (!mesh) { mesh= MEM_callocN(sizeof(StrandSurface), "StrandSurface"); mesh->obr= *obr; mesh->totvert= totvert; @@ -993,23 +993,23 @@ StrandSurface *cache_strand_surface(Render *re, ObjectRen *obr, DerivedMesh *dm, BLI_addtail(&re->strandsurface, mesh); } - if(timeoffset == -1 && !mesh->prevco) + if (timeoffset == -1 && !mesh->prevco) mesh->prevco= co= MEM_callocN(sizeof(float)*3*mesh->totvert, "StrandSurfCo"); - else if(timeoffset == 0 && !mesh->co) + else if (timeoffset == 0 && !mesh->co) mesh->co= co= MEM_callocN(sizeof(float)*3*mesh->totvert, "StrandSurfCo"); - else if(timeoffset == 1 && !mesh->nextco) + else if (timeoffset == 1 && !mesh->nextco) mesh->nextco= co= MEM_callocN(sizeof(float)*3*mesh->totvert, "StrandSurfCo"); else return mesh; mvert= dm->getVertArray(dm); - for(a=0; a<mesh->totvert; a++, mvert++) { + for (a=0; a<mesh->totvert; a++, mvert++) { copy_v3_v3(co[a], mvert->co); mul_m4_v3(mat, co[a]); } mface= dm->getTessFaceArray(dm); - for(a=0; a<mesh->totface; a++, mface++) { + for (a=0; a<mesh->totface; a++, mface++) { mesh->face[a][0]= mface->v1; mesh->face[a][1]= mface->v2; mesh->face[a][2]= mface->v3; @@ -1023,14 +1023,14 @@ void free_strand_surface(Render *re) { StrandSurface *mesh; - for(mesh=re->strandsurface.first; mesh; mesh=mesh->next) { - if(mesh->co) MEM_freeN(mesh->co); - if(mesh->prevco) MEM_freeN(mesh->prevco); - if(mesh->nextco) MEM_freeN(mesh->nextco); - if(mesh->ao) MEM_freeN(mesh->ao); - if(mesh->env) MEM_freeN(mesh->env); - if(mesh->indirect) MEM_freeN(mesh->indirect); - if(mesh->face) MEM_freeN(mesh->face); + for (mesh=re->strandsurface.first; mesh; mesh=mesh->next) { + if (mesh->co) MEM_freeN(mesh->co); + if (mesh->prevco) MEM_freeN(mesh->prevco); + if (mesh->nextco) MEM_freeN(mesh->nextco); + if (mesh->ao) MEM_freeN(mesh->ao); + if (mesh->env) MEM_freeN(mesh->env); + if (mesh->indirect) MEM_freeN(mesh->indirect); + if (mesh->face) MEM_freeN(mesh->face); } BLI_freelistN(&re->strandsurface); @@ -1042,11 +1042,11 @@ void strand_minmax(StrandRen *strand, float *min, float *max, float width) float vec[3], width2= 2.0f*width; int a; - for(a=0, svert=strand->vert; a<strand->totvert; a++, svert++) { + for (a=0, svert=strand->vert; a<strand->totvert; a++, svert++) { copy_v3_v3(vec, svert->co); DO_MINMAX(vec, min, max); - if(width!=0.0f) { + if (width!=0.0f) { vec[0]+= width; vec[1]+= width; vec[2]+= width; DO_MINMAX(vec, min, max); vec[0]-= width2; vec[1]-= width2; vec[2]-= width2; diff --git a/source/blender/render/intern/source/sunsky.c b/source/blender/render/intern/source/sunsky.c index 1ecf197f694..1fa18c4ebb4 100644 --- a/source/blender/render/intern/source/sunsky.c +++ b/source/blender/render/intern/source/sunsky.c @@ -273,7 +273,7 @@ void GetSkyXYZRadiance(struct SunSky* sunsky, float theta, float phi, float colo y = PerezFunction(sunsky, sunsky->perez_y, theta, gamma, sunsky->zenith_y); Y = 6.666666667e-5f * nfade * hfade * PerezFunction(sunsky, sunsky->perez_Y, theta, gamma, sunsky->zenith_Y); - if(sunsky->sky_exposure!=0.0f) + if (sunsky->sky_exposure!=0.0f) Y = 1.0 - exp(Y*sunsky->sky_exposure); X = (x / y) * Y; @@ -335,7 +335,7 @@ static void ComputeAttenuatedSunlight(float theta, int turbidity, float fTau[3]) m = 1.0f/(cosf(theta) + 0.15f*powf(93.885f-theta/(float)M_PI*180.0f,-1.253f)); - for(i = 0; i < 3; i++) + for (i = 0; i < 3; i++) { // Rayleigh Scattering fTauR = expf( -m * 0.008735f * powf(fLambda[i], (float)(-4.08f))); diff --git a/source/blender/render/intern/source/volume_precache.c b/source/blender/render/intern/source/volume_precache.c index f99eb0298bf..bd01c75ef3f 100644 --- a/source/blender/render/intern/source/volume_precache.c +++ b/source/blender/render/intern/source/volume_precache.c @@ -89,7 +89,8 @@ static int intersect_outside_volume(RayObject *tree, Isect *isect, float *offset isect->orig.ob= isect->hit.ob; return intersect_outside_volume(tree, isect, offset, limit-1, depth+1); - } else { + } + else { return depth; } } @@ -140,14 +141,14 @@ void global_bounds_obi(Render *re, ObjectInstanceRen *obi, float *bbmin, float * INIT_MINMAX(bbmin, bbmax); - for(a=0; a<obr->totvert; a++) { - if((a & 255)==0) ver= obr->vertnodes[a>>8].vert; + for (a=0; a<obr->totvert; a++) { + if ((a & 255)==0) ver= obr->vertnodes[a>>8].vert; else ver++; copy_v3_v3(co, ver->co); /* transformed object instance in camera space */ - if(obi->flag & R_TRANSFORMED) + if (obi->flag & R_TRANSFORMED) mul_m4_v3(obi->mat, co); /* convert to global space */ @@ -409,7 +410,7 @@ static void multiple_scattering_diffusion(Render *re, VolumePrecache *vp, Materi sb[j] += vp->data_b[i]; /* Displays progress every second */ - if(time-lasttime>1.0) { + if (time-lasttime>1.0) { char str[64]; BLI_snprintf(str, sizeof(str), "Simulating multiple scattering: %d%%", (int)(100.0f * (c / total))); re->i.infostr= str; @@ -446,7 +447,8 @@ static void multiple_scattering_diffusion(Render *re, VolumePrecache *vp, Materi /* conserve energy - half single, half multiple */ origf = 0.5f; fac *= 0.5f; - } else { + } + else { origf = 0.0f; } @@ -735,25 +737,25 @@ static void vol_precache_objectinstance_threads(Render *re, ObjectInstanceRen *o queue.done = BLI_thread_queue_init(); BLI_thread_queue_nowait(queue.work); - for(pa= re->volume_precache_parts.first; pa; pa= pa->next) + for (pa= re->volume_precache_parts.first; pa; pa= pa->next) BLI_thread_queue_push(queue.work, pa); /* launch threads */ BLI_init_threads(&threads, vol_precache_part, totthread); - for(thread= 0; thread<totthread; thread++) + for (thread= 0; thread<totthread; thread++) BLI_insert_thread(&threads, &queue); /* loop waiting for work to be done */ - while(counter < totparts) { - if(re->test_break && re->test_break(re->tbh)) + while (counter < totparts) { + if (re->test_break && re->test_break(re->tbh)) break; - if(BLI_thread_queue_pop_timeout(queue.done, 50)) + if (BLI_thread_queue_pop_timeout(queue.done, 50)) counter++; time= PIL_check_seconds_timer(); - if(time-lasttime>1.0) { + if (time-lasttime>1.0) { char str[64]; BLI_snprintf(str, sizeof(str), "Precaching volume: %d%%", (int)(100.0f * ((float)counter / (float)totparts))); re->i.infostr= str; @@ -769,7 +771,7 @@ static void vol_precache_objectinstance_threads(Render *re, ObjectInstanceRen *o BLI_thread_queue_free(queue.done); BLI_freelistN(&re->volume_precache_parts); - if(tree) { + if (tree) { //TODO: makeraytree_object creates a tree and saves it on OBI, if we free this tree we should also clear other pointers to it //RE_rayobject_free(tree); //tree= NULL; @@ -799,18 +801,18 @@ void volume_precache(Render *re) re->i.infostr= "Volume preprocessing"; re->stats_draw(re->sdh, &re->i); - for(vo= re->volumes.first; vo; vo= vo->next) { + for (vo= re->volumes.first; vo; vo= vo->next) { if (using_lightcache(vo->ma)) { - for(obi= re->instancetable.first; obi; obi= obi->next) { + for (obi= re->instancetable.first; obi; obi= obi->next) { if (obi->obr == vo->obr) { vol_precache_objectinstance_threads(re, obi, vo->ma); - if(re->test_break && re->test_break(re->tbh)) + if (re->test_break && re->test_break(re->tbh)) break; } } - if(re->test_break && re->test_break(re->tbh)) + if (re->test_break && re->test_break(re->tbh)) break; } } @@ -823,7 +825,7 @@ void free_volume_precache(Render *re) { ObjectInstanceRen *obi; - for(obi= re->instancetable.first; obi; obi= obi->next) { + for (obi= re->instancetable.first; obi; obi= obi->next) { if (obi->volume_precache != NULL) { MEM_freeN(obi->volume_precache->data_r); MEM_freeN(obi->volume_precache->data_g); diff --git a/source/blender/render/intern/source/volumetric.c b/source/blender/render/intern/source/volumetric.c index 17c4601264a..9c4afaea0fe 100644 --- a/source/blender/render/intern/source/volumetric.c +++ b/source/blender/render/intern/source/volumetric.c @@ -79,21 +79,23 @@ static float vol_get_shadow(ShadeInput *shi, LampRen *lar, const float co[3]) { float visibility = 1.f; - if(lar->shb) { + if (lar->shb) { float dxco[3]={0.f, 0.f, 0.f}, dyco[3]={0.f, 0.f, 0.f}; visibility = testshadowbuf(&R, lar->shb, co, dxco, dyco, 1.0, 0.0); - } else if (lar->mode & LA_SHAD_RAY) { + } + else if (lar->mode & LA_SHAD_RAY) { /* trace shadow manually, no good lamp api atm */ Isect is; copy_v3_v3(is.start, co); - if(lar->type==LA_SUN || lar->type==LA_HEMI) { + if (lar->type==LA_SUN || lar->type==LA_HEMI) { is.dir[0] = -lar->vec[0]; is.dir[1] = -lar->vec[1]; is.dir[2] = -lar->vec[2]; is.dist = R.maxdist; - } else { + } + else { sub_v3_v3v3(is.dir, lar->co, is.start); is.dist = normalize_v3( is.dir ); } @@ -102,7 +104,7 @@ static float vol_get_shadow(ShadeInput *shi, LampRen *lar, const float co[3]) is.check = RE_CHECK_VLR_NON_SOLID_MATERIAL; is.skip = 0; - if(lar->mode & (LA_LAYER|LA_LAYER_SHADOW)) + if (lar->mode & (LA_LAYER|LA_LAYER_SHADOW)) is.lay= lar->lay; else is.lay= -1; @@ -111,7 +113,7 @@ static float vol_get_shadow(ShadeInput *shi, LampRen *lar, const float co[3]) is.orig.face = NULL; is.last_hit = lar->last_hit[shi->thread]; - if(RE_rayobject_raycast(R.raytree,&is)) { + if (RE_rayobject_raycast(R.raytree,&is)) { visibility = 0.f; } @@ -142,7 +144,7 @@ static int vol_get_bounds(ShadeInput *shi, const float co[3], const float vec[3] isect->orig.ob = NULL; } - if(RE_rayobject_raycast(R.raytree, isect)) { + if (RE_rayobject_raycast(R.raytree, isect)) { hitco[0] = isect->start[0] + isect->dist*isect->dir[0]; hitco[1] = isect->start[1] + isect->dist*isect->dir[1]; hitco[2] = isect->start[2] + isect->dist*isect->dir[2]; @@ -203,9 +205,10 @@ static void vol_trace_behind(ShadeInput *shi, VlakRen *vlr, const float co[3], f isect.lay= -1; /* check to see if there's anything behind the volume, otherwise shade the sky */ - if(RE_rayobject_raycast(R.raytree, &isect)) { + if (RE_rayobject_raycast(R.raytree, &isect)) { shade_intersection(shi, col_r, &isect); - } else { + } + else { shadeSkyView(col_r, co, shi->view, NULL, shi->thread); shadeSunView(col_r, shi->view); } @@ -377,7 +380,8 @@ static float vol_get_phasefunc(ShadeInput *UNUSED(shi), float g, const float w[3 if (g == 0.f) { /* isotropic */ return normalize * 1.f; - } else { /* schlick */ + } + else { /* schlick */ const float k = 1.55f * g - .55f * g * g * g; const float kcostheta = k * dot_v3v3(w, wp); return normalize * (1.f - k*k) / ((1.f - kcostheta) * (1.f - kcostheta)); @@ -479,7 +483,7 @@ static void vol_shade_one_lamp(struct ShadeInput *shi, const float co[3], const copy_v3_v3(lacol, &lar->r); - if(lar->mode & LA_TEXTURE) { + if (lar->mode & LA_TEXTURE) { shi->osatex= 0; do_lamp_tex(lar, lv, shi, lacol, LA_TEXTURE); } @@ -517,7 +521,8 @@ static void vol_shade_one_lamp(struct ShadeInput *shi, const float co[3], const atten_co = hitco; else if ( lampdist < dist ) { atten_co = lar->co; - } else + } + else atten_co = hitco; vol_get_transmittance(shi, tr, co, atten_co); @@ -554,7 +559,7 @@ void vol_get_scattering(ShadeInput *shi, float scatter_col[3], const float co[3] zero_v3(scatter_col); lights= get_lights(shi); - for(go=lights->first; go; go= go->next) + for (go=lights->first; go; go= go->next) { float lacol[3] = {0.f, 0.f, 0.f}; lar= go->lampren; @@ -627,7 +632,8 @@ static void volumeintegrate(struct ShadeInput *shi, float col[4], const float co p2[2] = p[2] + (step_vec[2] * 0.5f); vol_get_precached_scattering(&R, shi, scatter_col, p2); - } else + } + else vol_get_scattering(shi, scatter_col, p, shi->view); radiance[0] += stepd * tr[0] * (emit_col[0] + scatter_col[0]); @@ -694,7 +700,8 @@ static void volume_trace(struct ShadeInput *shi, struct ShadeResult *shr, int in if (!ztransp) /* trace behind the volume object */ vol_trace_behind(shi, shi->vlr, endco, col); - } else { + } + else { /* we're tracing through the volume between the camera * and a solid surface, so use that pre-shaded radiance */ copy_v4_v4(col, shr->combined); @@ -716,7 +723,8 @@ static void volume_trace(struct ShadeInput *shi, struct ShadeResult *shr, int in if (vlr->mat == shi->mat) { /* trace behind the 2nd (raytrace) hit point */ vol_trace_behind(shi, (VlakRen *)is.hit.face, endco, col); - } else { + } + else { shade_intersection(shi, col, &is); } } diff --git a/source/blender/render/intern/source/voxeldata.c b/source/blender/render/intern/source/voxeldata.c index 6b625d1a59a..1f49b654ef8 100644 --- a/source/blender/render/intern/source/voxeldata.c +++ b/source/blender/render/intern/source/voxeldata.c @@ -83,15 +83,15 @@ static int load_frame_blendervoxel(VoxelData *vd, FILE *fp, int frame) const size_t size = vd_resol_size(vd); size_t offset = sizeof(VoxelDataHeader); - if(is_vd_res_ok(vd) == FALSE) + if (is_vd_res_ok(vd) == FALSE) return 0; vd->dataset = MEM_mapallocN(sizeof(float)*size, "voxel dataset"); - if(vd->dataset == NULL) return 0; + if (vd->dataset == NULL) return 0; - if(fseek(fp, frame*size*sizeof(float)+offset, 0) == -1) + if (fseek(fp, frame*size*sizeof(float)+offset, 0) == -1) return 0; - if(fread(vd->dataset, sizeof(float), size, fp) != size) + if (fread(vd->dataset, sizeof(float), size, fp) != size) return 0; vd->cachedframe = frame; @@ -105,25 +105,25 @@ static int load_frame_raw8(VoxelData *vd, FILE *fp, int frame) char *data_c; int i; - if(is_vd_res_ok(vd) == FALSE) + if (is_vd_res_ok(vd) == FALSE) return 0; vd->dataset = MEM_mapallocN(sizeof(float)*size, "voxel dataset"); - if(vd->dataset == NULL) return 0; + if (vd->dataset == NULL) return 0; data_c = (char *)MEM_mallocN(sizeof(char)*size, "temporary voxel file reading storage"); - if(data_c == NULL) { + if (data_c == NULL) { MEM_freeN(vd->dataset); vd->dataset= NULL; return 0; } - if(fseek(fp,(frame-1)*size*sizeof(char),0) == -1) { + if (fseek(fp,(frame-1)*size*sizeof(char),0) == -1) { MEM_freeN(data_c); MEM_freeN(vd->dataset); vd->dataset= NULL; return 0; } - if(fread(data_c, sizeof(char), size, fp) != size) { + if (fread(data_c, sizeof(char), size, fp) != size) { MEM_freeN(data_c); MEM_freeN(vd->dataset); vd->dataset= NULL; @@ -204,7 +204,7 @@ static int read_voxeldata_header(FILE *fp, struct VoxelData *vd) VoxelDataHeader *h=(VoxelDataHeader *)MEM_mallocN(sizeof(VoxelDataHeader), "voxel data header"); rewind(fp); - if(fread(h,sizeof(VoxelDataHeader),1,fp) != 1) { + if (fread(h,sizeof(VoxelDataHeader),1,fp) != 1) { MEM_freeN(h); return 0; } @@ -232,8 +232,8 @@ static void init_frame_smoke(VoxelData *vd, float cfra) SmokeModifierData *smd = (SmokeModifierData *)md; - if(smd->domain && smd->domain->fluid) { - if(cfra < smd->domain->point_cache[0]->startframe) + if (smd->domain && smd->domain->fluid) { + if (cfra < smd->domain->point_cache[0]->startframe) ; /* don't show smoke before simulation starts, this could be made an option in the future */ else if (vd->smoked_type == TEX_VD_SMOKEHEAT) { size_t totRes; @@ -284,7 +284,8 @@ static void init_frame_smoke(VoxelData *vd, float cfra) if (smd->domain->flags & MOD_SMOKE_HIGHRES) { smoke_turbulence_get_res(smd->domain->wt, vd->resol); density = smoke_turbulence_get_density(smd->domain->wt); - } else { + } + else { copy_v3_v3_int(vd->resol, smd->domain->res); density = smoke_get_density(smd->domain->fluid); } @@ -345,7 +346,7 @@ void cache_voxeldata(Tex *tex, int scene_frame) fp = BLI_fopen(path,"rb"); if (!fp) return; - if(read_voxeldata_header(fp, vd)) + if (read_voxeldata_header(fp, vd)) load_frame_blendervoxel(vd, fp, curframe-1); fclose(fp); @@ -371,7 +372,7 @@ void make_voxeldata(struct Render *re) /* XXX: should be doing only textures used in this render */ for (tex= re->main->tex.first; tex; tex= tex->id.next) { - if(tex->id.us && tex->type==TEX_VOXELDATA) { + if (tex->id.us && tex->type==TEX_VOXELDATA) { cache_voxeldata(tex, re->r.cfra); } } diff --git a/source/blender/render/intern/source/zbuf.c b/source/blender/render/intern/source/zbuf.c index 46520001d2d..e3068d12265 100644 --- a/source/blender/render/intern/source/zbuf.c +++ b/source/blender/render/intern/source/zbuf.c @@ -101,9 +101,9 @@ void zbuf_alloc_span(ZSpan *zspan, int rectx, int recty, float clipcrop) void zbuf_free_span(ZSpan *zspan) { - if(zspan) { - if(zspan->span1) MEM_freeN(zspan->span1); - if(zspan->span2) MEM_freeN(zspan->span2); + if (zspan) { + if (zspan->span1) MEM_freeN(zspan->span1); + if (zspan->span2) MEM_freeN(zspan->span2); zspan->span1= zspan->span2= NULL; } } @@ -122,7 +122,7 @@ static void zbuf_add_to_span(ZSpan *zspan, float *v1, float *v2) float xx1, dx0, xs0; int y, my0, my2; - if(v1[1]<v2[1]) { + if (v1[1]<v2[1]) { minv= v1; maxv= v2; } else { @@ -132,18 +132,18 @@ static void zbuf_add_to_span(ZSpan *zspan, float *v1, float *v2) 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) { + if (xx1>FLT_EPSILON) { dx0= (minv[0]-maxv[0])/xx1; xs0= dx0*(minv[1]-my2) + minv[0]; } @@ -153,11 +153,11 @@ static void zbuf_add_to_span(ZSpan *zspan, float *v1, float *v2) } /* empty span */ - if(zspan->maxp1 == NULL) { + if (zspan->maxp1 == NULL) { span= zspan->span1; } else { /* does it complete left span? */ - if( maxv == zspan->minp1 || minv==zspan->maxp1) { + if ( maxv == zspan->minp1 || minv==zspan->maxp1) { span= zspan->span1; } else { @@ -165,30 +165,30 @@ static void zbuf_add_to_span(ZSpan *zspan, float *v1, float *v2) } } - 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] ) { + if (zspan->minp1==NULL || zspan->minp1[1] > minv[1] ) { zspan->minp1= minv; } - if(zspan->maxp1==NULL || zspan->maxp1[1] < maxv[1] ) { + 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] ) { + if (zspan->minp2==NULL || zspan->minp2[1] > minv[1] ) { zspan->minp2= minv; } - if(zspan->maxp2==NULL || zspan->maxp2[1] < maxv[1] ) { + 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; } @@ -204,7 +204,7 @@ void fillrect(int *rect, int x, int y, int val) len= x*y; drect= rect; - while(len>0) { + while (len>0) { len--; *drect= val; drect++; @@ -216,24 +216,24 @@ static short cliptestf(float a, float b, float c, float d, float *u1, float *u2) { float p= a + b, q= c + d, r; - if(p<0.0f) { - if(q<p) return 0; - else if(q<0.0f) { + if (p<0.0f) { + if (q<p) return 0; + else if (q<0.0f) { r= q/p; - if(r>*u2) return 0; - else if(r>*u1) *u1=r; + if (r>*u2) return 0; + else if (r>*u1) *u1=r; } } else { - if(p>0.0f) { - if(q<0.0f) return 0; - else if(q<p) { + if (p>0.0f) { + if (q<0.0f) return 0; + else if (q<p) { r= q/p; - if(r<*u1) return 0; - else if(r<*u2) *u2=r; + if (r<*u1) return 0; + else if (r<*u2) *u2=r; } } - else if(q<0.0f) return 0; + else if (q<0.0f) return 0; } return 1; } @@ -247,14 +247,14 @@ int testclip(const float v[4]) * prevents issues with vertices lying exact on borders */ abs4= fabsf(v[3]) + FLT_EPSILON; - if( v[0] < -abs4) c+=1; - else if( v[0] > abs4) c+=2; + if ( v[0] < -abs4) c+=1; + else if ( v[0] > abs4) c+=2; - if( v[1] > abs4) c+=4; - else if( v[1] < -abs4) c+=8; + if ( v[1] > abs4) c+=4; + else if ( v[1] < -abs4) c+=8; - if(v[2] < -abs4) c+=16; /* this used to be " if(v[2]<0) ", see clippz() */ - else if(v[2]> abs4) c+= 32; + if (v[2] < -abs4) c+=16; /* this used to be " if(v[2]<0) ", see clippz() */ + else if (v[2]> abs4) c+= 32; return c; } @@ -279,9 +279,9 @@ void freepsA(ListBase *lb) { APixstrMain *psm, *psmnext; - for(psm= lb->first; psm; psm= psmnext) { + for (psm= lb->first; psm; psm= psmnext) { psmnext= psm->next; - if(psm->ps) + if (psm->ps) MEM_freeN(psm->ps); MEM_freeN(psm); } @@ -290,7 +290,7 @@ void freepsA(ListBase *lb) static APixstr *addpsA(ZSpan *zspan) { /* make new PS */ - if(zspan->apsmcounter==0) { + if (zspan->apsmcounter==0) { zspan->curpstr= addpsmainA(zspan->apsmbase); zspan->apsmcounter= 4095; } @@ -317,7 +317,7 @@ static void zbuffillAc4(ZSpan *zspan, int obi, int zvlnr, float *v1, float *v2, /* set spans */ zbuf_add_to_span(zspan, v1, v2); zbuf_add_to_span(zspan, v2, v3); - if(v4) { + if (v4) { zbuf_add_to_span(zspan, v3, v4); zbuf_add_to_span(zspan, v4, v1); } @@ -325,12 +325,12 @@ static void zbuffillAc4(ZSpan *zspan, int obi, int zvlnr, float *v1, float *v2, zbuf_add_to_span(zspan, v3, v1); /* clipped */ - if(zspan->minp2==NULL || zspan->maxp2==NULL) return; + if (zspan->minp2==NULL || zspan->maxp2==NULL) return; - if(zspan->miny1 < zspan->miny2) my0= zspan->miny2; else my0= zspan->miny1; - if(zspan->maxy1 > zspan->maxy2) my2= zspan->maxy2; else my2= zspan->maxy1; + if (zspan->miny1 < zspan->miny2) my0= zspan->miny2; else my0= zspan->miny1; + if (zspan->maxy1 > zspan->maxy2) my2= zspan->maxy2; else my2= zspan->maxy1; - if(my2<my0) return; + if (my2<my0) return; /* ZBUF DX DY, in floats still */ x1= v1[0]- v2[0]; @@ -343,7 +343,7 @@ static void zbuffillAc4(ZSpan *zspan, int obi, int zvlnr, float *v1, float *v2, 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 + v1[2]; @@ -360,7 +360,7 @@ static void zbuffillAc4(ZSpan *zspan, int obi, int zvlnr, float *v1, float *v2, /* correct span */ sn1= (my0 + my2)/2; - if(zspan->span1[sn1] < zspan->span2[sn1]) { + if (zspan->span1[sn1] < zspan->span2[sn1]) { span1= zspan->span1+my2; span2= zspan->span2+my2; } @@ -369,16 +369,16 @@ static void zbuffillAc4(ZSpan *zspan, int obi, int zvlnr, float *v1, float *v2, span2= zspan->span1+my2; } - for(y=my2; y>=my0; y--, span1--, span2--) { + for (y=my2; y>=my0; y--, span1--, span2--) { sn1= floor(*span1); sn2= floor(*span2); sn1++; - if(sn2>=rectx) sn2= rectx-1; - if(sn1<0) sn1= 0; + if (sn2>=rectx) sn2= rectx-1; + if (sn1<0) sn1= 0; - if(sn2>=sn1) { + if (sn2>=sn1) { int intzverg; zverg= (double)sn1*zxd + zy0; @@ -389,23 +389,23 @@ static void zbuffillAc4(ZSpan *zspan, int obi, int zvlnr, float *v1, float *v2, zverg-= zspan->polygon_offset; - while(x>=0) { + while (x>=0) { intzverg= (int)CLAMPIS(zverg, INT_MIN, INT_MAX); - if( intzverg < *rz) { - if(!zspan->rectmask || intzverg > *rm) { + if ( intzverg < *rz) { + if (!zspan->rectmask || intzverg > *rm) { apn= ap; - while(apn) { - if(apn->p[0]==0) {apn->obi[0]= obi; apn->p[0]= zvlnr; apn->z[0]= intzverg; apn->mask[0]= mask; break; } - if(apn->p[0]==zvlnr && apn->obi[0]==obi) {apn->mask[0]|= mask; break; } - if(apn->p[1]==0) {apn->obi[1]= obi; apn->p[1]= zvlnr; apn->z[1]= intzverg; apn->mask[1]= mask; break; } - if(apn->p[1]==zvlnr && apn->obi[1]==obi) {apn->mask[1]|= mask; break; } - if(apn->p[2]==0) {apn->obi[2]= obi; apn->p[2]= zvlnr; apn->z[2]= intzverg; apn->mask[2]= mask; break; } - if(apn->p[2]==zvlnr && apn->obi[2]==obi) {apn->mask[2]|= mask; break; } - if(apn->p[3]==0) {apn->obi[3]= obi; apn->p[3]= zvlnr; apn->z[3]= intzverg; apn->mask[3]= mask; break; } - if(apn->p[3]==zvlnr && apn->obi[3]==obi) {apn->mask[3]|= mask; break; } - if(apn->next==NULL) apn->next= addpsA(zspan); + while (apn) { + if (apn->p[0]==0) {apn->obi[0]= obi; apn->p[0]= zvlnr; apn->z[0]= intzverg; apn->mask[0]= mask; break; } + if (apn->p[0]==zvlnr && apn->obi[0]==obi) {apn->mask[0]|= mask; break; } + if (apn->p[1]==0) {apn->obi[1]= obi; apn->p[1]= zvlnr; apn->z[1]= intzverg; apn->mask[1]= mask; break; } + if (apn->p[1]==zvlnr && apn->obi[1]==obi) {apn->mask[1]|= mask; break; } + if (apn->p[2]==0) {apn->obi[2]= obi; apn->p[2]= zvlnr; apn->z[2]= intzverg; apn->mask[2]= mask; break; } + if (apn->p[2]==zvlnr && apn->obi[2]==obi) {apn->mask[2]|= mask; break; } + if (apn->p[3]==0) {apn->obi[3]= obi; apn->p[3]= zvlnr; apn->z[3]= intzverg; apn->mask[3]= mask; break; } + if (apn->p[3]==zvlnr && apn->obi[3]==obi) {apn->mask[3]|= mask; break; } + if (apn->next==NULL) apn->next= addpsA(zspan); apn= apn->next; } } @@ -441,10 +441,10 @@ static void zbuflineAc(ZSpan *zspan, int obi, int zvlnr, float *vec1, float *vec mask= zspan->mask; - if(fabs(dx) > fabs(dy)) { + if (fabs(dx) > fabs(dy)) { /* all lines from left to right */ - if(vec1[0]<vec2[0]) { + if (vec1[0]<vec2[0]) { copy_v3_v3(v1, vec1); copy_v3_v3(v2, vec2); } @@ -456,7 +456,7 @@ static void zbuflineAc(ZSpan *zspan, int obi, int zvlnr, float *vec1, float *vec start= floor(v1[0]); end= start+floor(dx); - if(end>=zspan->rectx) end= zspan->rectx-1; + if (end>=zspan->rectx) end= zspan->rectx-1; oldy= floor(v1[1]); dy/= dx; @@ -464,40 +464,40 @@ static void zbuflineAc(ZSpan *zspan, int obi, int zvlnr, float *vec1, float *vec vergz= v1[2]; vergz-= zspan->polygon_offset; dz= (v2[2]-v1[2])/dx; - if(vergz>0x50000000 && dz>0) maxtest= 1; // prevent overflow + if (vergz>0x50000000 && dz>0) maxtest= 1; // prevent overflow rectz= (int *)(zspan->arectz+zspan->rectx*(oldy) +start); rectmask= (int *)(zspan->rectmask+zspan->rectx*(oldy) +start); ap= (zspan->apixbuf+ zspan->rectx*(oldy) +start); - if(dy<0) ofs= -zspan->rectx; + if (dy<0) ofs= -zspan->rectx; else ofs= zspan->rectx; - for(x= start; x<=end; x++, rectz++, rectmask++, ap++) { + for (x= start; x<=end; x++, rectz++, rectmask++, ap++) { y= floor(v1[1]); - if(y!=oldy) { + if (y!=oldy) { oldy= y; rectz+= ofs; rectmask+= ofs; ap+= ofs; } - if(x>=0 && y>=0 && y<zspan->recty) { - if(vergz<*rectz) { - if(!zspan->rectmask || vergz>*rectmask) { + if (x>=0 && y>=0 && y<zspan->recty) { + if (vergz<*rectz) { + if (!zspan->rectmask || vergz>*rectmask) { apn= ap; - while(apn) { /* loop unrolled */ - if(apn->p[0]==0) {apn->obi[0]= obi; apn->p[0]= zvlnr; apn->z[0]= vergz; apn->mask[0]= mask; break; } - if(apn->p[0]==zvlnr && apn->obi[0]==obi) {apn->mask[0]|= mask; break; } - if(apn->p[1]==0) {apn->obi[1]= obi; apn->p[1]= zvlnr; apn->z[1]= vergz; apn->mask[1]= mask; break; } - if(apn->p[1]==zvlnr && apn->obi[1]==obi) {apn->mask[1]|= mask; break; } - if(apn->p[2]==0) {apn->obi[2]= obi; apn->p[2]= zvlnr; apn->z[2]= vergz; apn->mask[2]= mask; break; } - if(apn->p[2]==zvlnr && apn->obi[2]==obi) {apn->mask[2]|= mask; break; } - if(apn->p[3]==0) {apn->obi[3]= obi; apn->p[3]= zvlnr; apn->z[3]= vergz; apn->mask[3]= mask; break; } - if(apn->p[3]==zvlnr && apn->obi[3]==obi) {apn->mask[3]|= mask; break; } - if(apn->next==0) apn->next= addpsA(zspan); + while (apn) { /* loop unrolled */ + if (apn->p[0]==0) {apn->obi[0]= obi; apn->p[0]= zvlnr; apn->z[0]= vergz; apn->mask[0]= mask; break; } + if (apn->p[0]==zvlnr && apn->obi[0]==obi) {apn->mask[0]|= mask; break; } + if (apn->p[1]==0) {apn->obi[1]= obi; apn->p[1]= zvlnr; apn->z[1]= vergz; apn->mask[1]= mask; break; } + if (apn->p[1]==zvlnr && apn->obi[1]==obi) {apn->mask[1]|= mask; break; } + if (apn->p[2]==0) {apn->obi[2]= obi; apn->p[2]= zvlnr; apn->z[2]= vergz; apn->mask[2]= mask; break; } + if (apn->p[2]==zvlnr && apn->obi[2]==obi) {apn->mask[2]|= mask; break; } + if (apn->p[3]==0) {apn->obi[3]= obi; apn->p[3]= zvlnr; apn->z[3]= vergz; apn->mask[3]= mask; break; } + if (apn->p[3]==zvlnr && apn->obi[3]==obi) {apn->mask[3]|= mask; break; } + if (apn->next==0) apn->next= addpsA(zspan); apn= apn->next; } } @@ -505,14 +505,14 @@ static void zbuflineAc(ZSpan *zspan, int obi, int zvlnr, float *vec1, float *vec } v1[1]+= dy; - if(maxtest && (vergz > 0x7FFFFFF0 - dz)) vergz= 0x7FFFFFF0; + if (maxtest && (vergz > 0x7FFFFFF0 - dz)) vergz= 0x7FFFFFF0; else vergz+= dz; } } else { /* all lines from top to bottom */ - if(vec1[1]<vec2[1]) { + if (vec1[1]<vec2[1]) { copy_v3_v3(v1, vec1); copy_v3_v3(v2, vec2); } @@ -525,9 +525,9 @@ static void zbuflineAc(ZSpan *zspan, int obi, int zvlnr, float *vec1, float *vec start= floor(v1[1]); end= start+floor(dy); - if(start>=zspan->recty || end<0) return; + if (start>=zspan->recty || end<0) return; - if(end>=zspan->recty) end= zspan->recty-1; + if (end>=zspan->recty) end= zspan->recty-1; oldx= floor(v1[0]); dx/= dy; @@ -535,40 +535,40 @@ static void zbuflineAc(ZSpan *zspan, int obi, int zvlnr, float *vec1, float *vec vergz= v1[2]; vergz-= zspan->polygon_offset; dz= (v2[2]-v1[2])/dy; - if(vergz>0x50000000 && dz>0) maxtest= 1; // prevent overflow + if (vergz>0x50000000 && dz>0) maxtest= 1; // prevent overflow rectz= (int *)( zspan->arectz+ (start)*zspan->rectx+ oldx ); rectmask= (int *)( zspan->rectmask+ (start)*zspan->rectx+ oldx ); ap= (zspan->apixbuf+ zspan->rectx*(start) +oldx); - if(dx<0) ofs= -1; + if (dx<0) ofs= -1; else ofs= 1; - for(y= start; y<=end; y++, rectz+=zspan->rectx, rectmask+=zspan->rectx, ap+=zspan->rectx) { + for (y= start; y<=end; y++, rectz+=zspan->rectx, rectmask+=zspan->rectx, ap+=zspan->rectx) { x= floor(v1[0]); - if(x!=oldx) { + if (x!=oldx) { oldx= x; rectz+= ofs; rectmask+= ofs; ap+= ofs; } - if(x>=0 && y>=0 && x<zspan->rectx) { - if(vergz<*rectz) { - if(!zspan->rectmask || vergz>*rectmask) { + if (x>=0 && y>=0 && x<zspan->rectx) { + if (vergz<*rectz) { + if (!zspan->rectmask || vergz>*rectmask) { apn= ap; - while(apn) { /* loop unrolled */ - if(apn->p[0]==0) {apn->obi[0]= obi; apn->p[0]= zvlnr; apn->z[0]= vergz; apn->mask[0]= mask; break; } - if(apn->p[0]==zvlnr) {apn->mask[0]|= mask; break; } - if(apn->p[1]==0) {apn->obi[1]= obi; apn->p[1]= zvlnr; apn->z[1]= vergz; apn->mask[1]= mask; break; } - if(apn->p[1]==zvlnr) {apn->mask[1]|= mask; break; } - if(apn->p[2]==0) {apn->obi[2]= obi; apn->p[2]= zvlnr; apn->z[2]= vergz; apn->mask[2]= mask; break; } - if(apn->p[2]==zvlnr) {apn->mask[2]|= mask; break; } - if(apn->p[3]==0) {apn->obi[3]= obi; apn->p[3]= zvlnr; apn->z[3]= vergz; apn->mask[3]= mask; break; } - if(apn->p[3]==zvlnr) {apn->mask[3]|= mask; break; } - if(apn->next==0) apn->next= addpsA(zspan); + while (apn) { /* loop unrolled */ + if (apn->p[0]==0) {apn->obi[0]= obi; apn->p[0]= zvlnr; apn->z[0]= vergz; apn->mask[0]= mask; break; } + if (apn->p[0]==zvlnr) {apn->mask[0]|= mask; break; } + if (apn->p[1]==0) {apn->obi[1]= obi; apn->p[1]= zvlnr; apn->z[1]= vergz; apn->mask[1]= mask; break; } + if (apn->p[1]==zvlnr) {apn->mask[1]|= mask; break; } + if (apn->p[2]==0) {apn->obi[2]= obi; apn->p[2]= zvlnr; apn->z[2]= vergz; apn->mask[2]= mask; break; } + if (apn->p[2]==zvlnr) {apn->mask[2]|= mask; break; } + if (apn->p[3]==0) {apn->obi[3]= obi; apn->p[3]= zvlnr; apn->z[3]= vergz; apn->mask[3]= mask; break; } + if (apn->p[3]==zvlnr) {apn->mask[3]|= mask; break; } + if (apn->next==0) apn->next= addpsA(zspan); apn= apn->next; } } @@ -576,7 +576,7 @@ static void zbuflineAc(ZSpan *zspan, int obi, int zvlnr, float *vec1, float *vec } v1[0]+= dx; - if(maxtest && (vergz > 0x7FFFFFF0 - dz)) vergz= 0x7FFFFFF0; + if (maxtest && (vergz > 0x7FFFFFF0 - dz)) vergz= 0x7FFFFFF0; else vergz+= dz; } } @@ -595,10 +595,10 @@ static void zbufline(ZSpan *zspan, int obi, int zvlnr, float *vec1, float *vec2) dx= vec2[0]-vec1[0]; dy= vec2[1]-vec1[1]; - if(fabs(dx) > fabs(dy)) { + if (fabs(dx) > fabs(dy)) { /* all lines from left to right */ - if(vec1[0]<vec2[0]) { + if (vec1[0]<vec2[0]) { copy_v3_v3(v1, vec1); copy_v3_v3(v2, vec2); } @@ -610,27 +610,27 @@ static void zbufline(ZSpan *zspan, int obi, int zvlnr, float *vec1, float *vec2) start= floor(v1[0]); end= start+floor(dx); - if(end>=zspan->rectx) end= zspan->rectx-1; + if (end>=zspan->rectx) end= zspan->rectx-1; oldy= floor(v1[1]); dy/= dx; vergz= floor(v1[2]); dz= floor((v2[2]-v1[2])/dx); - if(vergz>0x50000000 && dz>0) maxtest= 1; // prevent overflow + if (vergz>0x50000000 && dz>0) maxtest= 1; // prevent overflow rectz= zspan->rectz + oldy*zspan->rectx+ start; rectp= zspan->rectp + oldy*zspan->rectx+ start; recto= zspan->recto + oldy*zspan->rectx+ start; rectmask= zspan->rectmask + oldy*zspan->rectx+ start; - if(dy<0) ofs= -zspan->rectx; + if (dy<0) ofs= -zspan->rectx; else ofs= zspan->rectx; - for(x= start; x<=end; x++, rectz++, rectp++, recto++, rectmask++) { + for (x= start; x<=end; x++, rectz++, rectp++, recto++, rectmask++) { y= floor(v1[1]); - if(y!=oldy) { + if (y!=oldy) { oldy= y; rectz+= ofs; rectp+= ofs; @@ -638,9 +638,9 @@ static void zbufline(ZSpan *zspan, int obi, int zvlnr, float *vec1, float *vec2) rectmask+= ofs; } - if(x>=0 && y>=0 && y<zspan->recty) { - if(vergz<*rectz) { - if(!zspan->rectmask || vergz>*rectmask) { + if (x>=0 && y>=0 && y<zspan->recty) { + if (vergz<*rectz) { + if (!zspan->rectmask || vergz>*rectmask) { *recto= obi; *rectz= vergz; *rectp= zvlnr; @@ -650,13 +650,13 @@ static void zbufline(ZSpan *zspan, int obi, int zvlnr, float *vec1, float *vec2) v1[1]+= dy; - if(maxtest && (vergz > 0x7FFFFFF0 - dz)) vergz= 0x7FFFFFF0; + if (maxtest && (vergz > 0x7FFFFFF0 - dz)) vergz= 0x7FFFFFF0; else vergz+= dz; } } else { /* all lines from top to bottom */ - if(vec1[1]<vec2[1]) { + if (vec1[1]<vec2[1]) { copy_v3_v3(v1, vec1); copy_v3_v3(v2, vec2); } @@ -669,27 +669,27 @@ static void zbufline(ZSpan *zspan, int obi, int zvlnr, float *vec1, float *vec2) start= floor(v1[1]); end= start+floor(dy); - if(end>=zspan->recty) end= zspan->recty-1; + if (end>=zspan->recty) end= zspan->recty-1; oldx= floor(v1[0]); dx/= dy; vergz= floor(v1[2]); dz= floor((v2[2]-v1[2])/dy); - if(vergz>0x50000000 && dz>0) maxtest= 1; // prevent overflow + if (vergz>0x50000000 && dz>0) maxtest= 1; // prevent overflow rectz= zspan->rectz + start*zspan->rectx+ oldx; rectp= zspan->rectp + start*zspan->rectx+ oldx; recto= zspan->recto + start*zspan->rectx+ oldx; rectmask= zspan->rectmask + start*zspan->rectx+ oldx; - if(dx<0) ofs= -1; + if (dx<0) ofs= -1; else ofs= 1; - for(y= start; y<=end; y++, rectz+=zspan->rectx, rectp+=zspan->rectx, recto+=zspan->rectx, rectmask+=zspan->rectx) { + for (y= start; y<=end; y++, rectz+=zspan->rectx, rectp+=zspan->rectx, recto+=zspan->rectx, rectmask+=zspan->rectx) { x= floor(v1[0]); - if(x!=oldx) { + if (x!=oldx) { oldx= x; rectz+= ofs; rectp+= ofs; @@ -697,9 +697,9 @@ static void zbufline(ZSpan *zspan, int obi, int zvlnr, float *vec1, float *vec2) rectmask+= ofs; } - if(x>=0 && y>=0 && x<zspan->rectx) { - if(vergz<*rectz) { - if(!zspan->rectmask || vergz>*rectmask) { + if (x>=0 && y>=0 && x<zspan->rectx) { + if (vergz<*rectz) { + if (!zspan->rectmask || vergz>*rectmask) { *rectz= vergz; *rectp= zvlnr; *recto= obi; @@ -708,7 +708,7 @@ static void zbufline(ZSpan *zspan, int obi, int zvlnr, float *vec1, float *vec2) } v1[0]+= dx; - if(maxtest && (vergz > 0x7FFFFFF0 - dz)) vergz= 0x7FFFFFF0; + if (maxtest && (vergz > 0x7FFFFFF0 - dz)) vergz= 0x7FFFFFF0; else vergz+= dz; } } @@ -725,10 +725,10 @@ static void zbufline_onlyZ(ZSpan *zspan, int UNUSED(obi), int UNUSED(zvlnr), flo dx= vec2[0]-vec1[0]; dy= vec2[1]-vec1[1]; - if(fabs(dx) > fabs(dy)) { + if (fabs(dx) > fabs(dy)) { /* all lines from left to right */ - if(vec1[0]<vec2[0]) { + if (vec1[0]<vec2[0]) { copy_v3_v3(v1, vec1); copy_v3_v3(v2, vec2); } @@ -740,51 +740,51 @@ static void zbufline_onlyZ(ZSpan *zspan, int UNUSED(obi), int UNUSED(zvlnr), flo start= floor(v1[0]); end= start+floor(dx); - if(end>=zspan->rectx) end= zspan->rectx-1; + if (end>=zspan->rectx) end= zspan->rectx-1; oldy= floor(v1[1]); dy/= dx; vergz= floor(v1[2]); dz= floor((v2[2]-v1[2])/dx); - if(vergz>0x50000000 && dz>0) maxtest= 1; // prevent overflow + if (vergz>0x50000000 && dz>0) maxtest= 1; // prevent overflow rectz= zspan->rectz + oldy*zspan->rectx+ start; - if(zspan->rectz1) + if (zspan->rectz1) rectz1= zspan->rectz1 + oldy*zspan->rectx+ start; - if(dy<0) ofs= -zspan->rectx; + if (dy<0) ofs= -zspan->rectx; else ofs= zspan->rectx; - for(x= start; x<=end; x++, rectz++) { + for (x= start; x<=end; x++, rectz++) { y= floor(v1[1]); - if(y!=oldy) { + if (y!=oldy) { oldy= y; rectz+= ofs; - if(rectz1) rectz1+= ofs; + if (rectz1) rectz1+= ofs; } - if(x>=0 && y>=0 && y<zspan->recty) { - if(vergz < *rectz) { - if(rectz1) *rectz1= *rectz; + if (x>=0 && y>=0 && y<zspan->recty) { + if (vergz < *rectz) { + if (rectz1) *rectz1= *rectz; *rectz= vergz; } - else if(rectz1 && vergz < *rectz1) + else if (rectz1 && vergz < *rectz1) *rectz1= vergz; } v1[1]+= dy; - if(maxtest && (vergz > 0x7FFFFFF0 - dz)) vergz= 0x7FFFFFF0; + if (maxtest && (vergz > 0x7FFFFFF0 - dz)) vergz= 0x7FFFFFF0; else vergz+= dz; - if(rectz1) rectz1++; + if (rectz1) rectz1++; } } else { /* all lines from top to bottom */ - if(vec1[1]<vec2[1]) { + if (vec1[1]<vec2[1]) { copy_v3_v3(v1, vec1); copy_v3_v3(v2, vec2); } @@ -797,45 +797,45 @@ static void zbufline_onlyZ(ZSpan *zspan, int UNUSED(obi), int UNUSED(zvlnr), flo start= floor(v1[1]); end= start+floor(dy); - if(end>=zspan->recty) end= zspan->recty-1; + if (end>=zspan->recty) end= zspan->recty-1; oldx= floor(v1[0]); dx/= dy; vergz= floor(v1[2]); dz= floor((v2[2]-v1[2])/dy); - if(vergz>0x50000000 && dz>0) maxtest= 1; // prevent overflow + if (vergz>0x50000000 && dz>0) maxtest= 1; // prevent overflow rectz= zspan->rectz + start*zspan->rectx+ oldx; - if(zspan->rectz1) + if (zspan->rectz1) rectz1= zspan->rectz1 + start*zspan->rectx+ oldx; - if(dx<0) ofs= -1; + if (dx<0) ofs= -1; else ofs= 1; - for(y= start; y<=end; y++, rectz+=zspan->rectx) { + for (y= start; y<=end; y++, rectz+=zspan->rectx) { x= floor(v1[0]); - if(x!=oldx) { + if (x!=oldx) { oldx= x; rectz+= ofs; - if(rectz1) rectz1+= ofs; + if (rectz1) rectz1+= ofs; } - if(x>=0 && y>=0 && x<zspan->rectx) { - if(vergz < *rectz) { - if(rectz1) *rectz1= *rectz; + if (x>=0 && y>=0 && x<zspan->rectx) { + if (vergz < *rectz) { + if (rectz1) *rectz1= *rectz; *rectz= vergz; } - else if(rectz1 && vergz < *rectz1) + else if (rectz1 && vergz < *rectz1) *rectz1= vergz; } v1[0]+= dx; - if(maxtest && (vergz > 0x7FFFFFF0 - dz)) vergz= 0x7FFFFFF0; + if (maxtest && (vergz > 0x7FFFFFF0 - dz)) vergz= 0x7FFFFFF0; else vergz+= dz; - if(rectz1) + if (rectz1) rectz1+=zspan->rectx; } } @@ -854,28 +854,28 @@ static int clipline(float v1[4], float v2[4]) /* return 0: do not draw */ * filled in with zbufwire correctly when rendering in parts. otherwise * you see line endings at edges... */ - if(cliptestf(-dz, -dw, v1[3], v1[2], &u1,&u2)) { - if(cliptestf(dz, -dw, v1[3], -v1[2], &u1,&u2)) { + if (cliptestf(-dz, -dw, v1[3], v1[2], &u1,&u2)) { + if (cliptestf(dz, -dw, v1[3], -v1[2], &u1,&u2)) { dx= v2[0]-v1[0]; dz= 1.01f*(v2[3]-v1[3]); v13= 1.01f*v1[3]; - if(cliptestf(-dx, -dz, v1[0], v13, &u1,&u2)) { - if(cliptestf(dx, -dz, v13, -v1[0], &u1,&u2)) { + if (cliptestf(-dx, -dz, v1[0], v13, &u1,&u2)) { + if (cliptestf(dx, -dz, v13, -v1[0], &u1,&u2)) { dy= v2[1]-v1[1]; - if(cliptestf(-dy, -dz, v1[1], v13, &u1,&u2)) { - if(cliptestf(dy, -dz, v13, -v1[1], &u1,&u2)) { + if (cliptestf(-dy, -dz, v1[1], v13, &u1,&u2)) { + if (cliptestf(dy, -dz, v13, -v1[1], &u1,&u2)) { - if(u2<1.0f) { + if (u2<1.0f) { v2[0]= v1[0]+u2*dx; v2[1]= v1[1]+u2*dy; v2[2]= v1[2]+u2*dz; v2[3]= v1[3]+u2*dw; } - if(u1>0.0f) { + if (u1>0.0f) { v1[0]= v1[0]+u1*dx; v1[1]= v1[1]+u1*dy; v1[2]= v1[2]+u1*dz; @@ -908,9 +908,9 @@ void zbufclipwire(ZSpan *zspan, int obi, int zvlnr, int ec, float *ho1, float *h int and, or; /* edgecode: 1= draw */ - if(ec==0) return; + if (ec==0) return; - if(ho4) { + if (ho4) { and= (c1 & c2 & c3 & c4); or= (c1 | c2 | c3 | c4); } @@ -919,44 +919,44 @@ void zbufclipwire(ZSpan *zspan, int obi, int zvlnr, int ec, float *ho1, float *h or= (c1 | c2 | c3); } - if(or) { /* not in the middle */ - if(and) { /* out completely */ + if (or) { /* not in the middle */ + if (and) { /* out completely */ return; } else { /* clipping */ - if(ec & ME_V1V2) { + if (ec & ME_V1V2) { copy_v4_v4(vez, ho1); copy_v4_v4(vez+4, ho2); - if( clipline(vez, vez+4)) { + if ( clipline(vez, vez+4)) { hoco_to_zco(zspan, vez, vez); hoco_to_zco(zspan, vez+4, vez+4); zspan->zbuflinefunc(zspan, obi, zvlnr, vez, vez+4); } } - if(ec & ME_V2V3) { + if (ec & ME_V2V3) { copy_v4_v4(vez, ho2); copy_v4_v4(vez+4, ho3); - if( clipline(vez, vez+4)) { + if ( clipline(vez, vez+4)) { hoco_to_zco(zspan, vez, vez); hoco_to_zco(zspan, vez+4, vez+4); zspan->zbuflinefunc(zspan, obi, zvlnr, vez, vez+4); } } - if(ho4) { - if(ec & ME_V3V4) { + if (ho4) { + if (ec & ME_V3V4) { copy_v4_v4(vez, ho3); copy_v4_v4(vez+4, ho4); - if( clipline(vez, vez+4)) { + if ( clipline(vez, vez+4)) { hoco_to_zco(zspan, vez, vez); hoco_to_zco(zspan, vez+4, vez+4); zspan->zbuflinefunc(zspan, obi, zvlnr, vez, vez+4); } } - if(ec & ME_V4V1) { + if (ec & ME_V4V1) { copy_v4_v4(vez, ho4); copy_v4_v4(vez+4, ho1); - if( clipline(vez, vez+4)) { + if ( clipline(vez, vez+4)) { hoco_to_zco(zspan, vez, vez); hoco_to_zco(zspan, vez+4, vez+4); zspan->zbuflinefunc(zspan, obi, zvlnr, vez, vez+4); @@ -964,10 +964,10 @@ void zbufclipwire(ZSpan *zspan, int obi, int zvlnr, int ec, float *ho1, float *h } } else { - if(ec & ME_V3V1) { + if (ec & ME_V3V1) { copy_v4_v4(vez, ho3); copy_v4_v4(vez+4, ho1); - if( clipline(vez, vez+4)) { + if ( clipline(vez, vez+4)) { hoco_to_zco(zspan, vez, vez); hoco_to_zco(zspan, vez+4, vez+4); zspan->zbuflinefunc(zspan, obi, zvlnr, vez, vez+4); @@ -982,18 +982,18 @@ void zbufclipwire(ZSpan *zspan, int obi, int zvlnr, int ec, float *ho1, float *h hoco_to_zco(zspan, vez, ho1); hoco_to_zco(zspan, vez+4, ho2); hoco_to_zco(zspan, vez+8, ho3); - if(ho4) { + if (ho4) { hoco_to_zco(zspan, vez+12, ho4); - if(ec & ME_V3V4) zspan->zbuflinefunc(zspan, obi, zvlnr, vez+8, vez+12); - if(ec & ME_V4V1) zspan->zbuflinefunc(zspan, obi, zvlnr, vez+12, vez); + if (ec & ME_V3V4) zspan->zbuflinefunc(zspan, obi, zvlnr, vez+8, vez+12); + if (ec & ME_V4V1) zspan->zbuflinefunc(zspan, obi, zvlnr, vez+12, vez); } else { - if(ec & ME_V3V1) zspan->zbuflinefunc(zspan, obi, zvlnr, vez+8, vez); + if (ec & ME_V3V1) zspan->zbuflinefunc(zspan, obi, zvlnr, vez+8, vez); } - if(ec & ME_V1V2) zspan->zbuflinefunc(zspan, obi, zvlnr, vez, vez+4); - if(ec & ME_V2V3) zspan->zbuflinefunc(zspan, obi, zvlnr, vez+4, vez+8); + if (ec & ME_V1V2) zspan->zbuflinefunc(zspan, obi, zvlnr, vez, vez+4); + if (ec & ME_V2V3) zspan->zbuflinefunc(zspan, obi, zvlnr, vez+4, vez+8); } @@ -1005,12 +1005,12 @@ void zbufsinglewire(ZSpan *zspan, int obi, int zvlnr, const float ho1[4], const c1= testclip(ho1); c2= testclip(ho2); - if(c1 | c2) { /* not in the middle */ - if(!(c1 & c2)) { /* not out completely */ + if (c1 | c2) { /* not in the middle */ + if (!(c1 & c2)) { /* not out completely */ copy_v4_v4(f1, ho1); copy_v4_v4(f2, ho2); - if(clipline(f1, f2)) { + if (clipline(f1, f2)) { hoco_to_zco(zspan, f1, f1); hoco_to_zco(zspan, f2, f2); zspan->zbuflinefunc(zspan, obi, zvlnr, f1, f2); @@ -1057,7 +1057,7 @@ static void zbuffillGLinv4(ZSpan *zspan, int obi, int zvlnr, float *v1, float *v /* set spans */ zbuf_add_to_span(zspan, v1, v2); zbuf_add_to_span(zspan, v2, v3); - if(v4) { + if (v4) { zbuf_add_to_span(zspan, v3, v4); zbuf_add_to_span(zspan, v4, v1); } @@ -1065,13 +1065,13 @@ static void zbuffillGLinv4(ZSpan *zspan, int obi, int zvlnr, float *v1, float *v zbuf_add_to_span(zspan, v3, v1); /* clipped */ - if(zspan->minp2==NULL || zspan->maxp2==NULL) return; + if (zspan->minp2==NULL || zspan->maxp2==NULL) return; - if(zspan->miny1 < zspan->miny2) my0= zspan->miny2; else my0= zspan->miny1; - if(zspan->maxy1 > zspan->maxy2) my2= zspan->maxy2; else my2= zspan->maxy1; + if (zspan->miny1 < zspan->miny2) my0= zspan->miny2; else my0= zspan->miny1; + if (zspan->maxy1 > zspan->maxy2) my2= zspan->maxy2; else my2= zspan->maxy1; // printf("my %d %d\n", my0, my2); - if(my2<my0) return; + if (my2<my0) return; /* ZBUF DX DY, in floats still */ @@ -1085,7 +1085,7 @@ static void zbuffillGLinv4(ZSpan *zspan, int obi, int zvlnr, float *v1, float *v 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 + v1[2]; @@ -1102,7 +1102,7 @@ static void zbuffillGLinv4(ZSpan *zspan, int obi, int zvlnr, float *v1, float *v /* correct span */ sn1= (my0 + my2)/2; - if(zspan->span1[sn1] < zspan->span2[sn1]) { + if (zspan->span1[sn1] < zspan->span2[sn1]) { span1= zspan->span1+my2; span2= zspan->span2+my2; } @@ -1111,16 +1111,16 @@ static void zbuffillGLinv4(ZSpan *zspan, int obi, int zvlnr, float *v1, float *v span2= zspan->span1+my2; } - for(y=my2; y>=my0; y--, span1--, span2--) { + for (y=my2; y>=my0; y--, span1--, span2--) { sn1= floor(*span1); sn2= floor(*span2); sn1++; - if(sn2>=rectx) sn2= rectx-1; - if(sn1<0) sn1= 0; + if (sn2>=rectx) sn2= rectx-1; + if (sn1<0) sn1= 0; - if(sn2>=sn1) { + if (sn2>=sn1) { int intzverg; zverg= (double)sn1*zxd + zy0; @@ -1130,11 +1130,11 @@ static void zbuffillGLinv4(ZSpan *zspan, int obi, int zvlnr, float *v1, float *v rm= rectmaskofs+sn1; x= sn2-sn1; - while(x>=0) { + while (x>=0) { intzverg= (int)CLAMPIS(zverg, INT_MIN, INT_MAX); - if( intzverg > *rz || *rz==0x7FFFFFFF) { /* UNIQUE LINE: see comment above */ - if(!zspan->rectmask || intzverg > *rm) { + if ( intzverg > *rz || *rz==0x7FFFFFFF) { /* UNIQUE LINE: see comment above */ + if (!zspan->rectmask || intzverg > *rm) { *ro= obi; /* UNIQUE LINE: see comment above (order differs) */ *rz= intzverg; *rp= zvlnr; @@ -1179,7 +1179,7 @@ static void zbuffillGL4(ZSpan *zspan, int obi, int zvlnr, float *v1, float *v2, /* set spans */ zbuf_add_to_span(zspan, v1, v2); zbuf_add_to_span(zspan, v2, v3); - if(v4) { + if (v4) { zbuf_add_to_span(zspan, v3, v4); zbuf_add_to_span(zspan, v4, v1); } @@ -1187,13 +1187,13 @@ static void zbuffillGL4(ZSpan *zspan, int obi, int zvlnr, float *v1, float *v2, zbuf_add_to_span(zspan, v3, v1); /* clipped */ - if(zspan->minp2==NULL || zspan->maxp2==NULL) return; + if (zspan->minp2==NULL || zspan->maxp2==NULL) return; - if(zspan->miny1 < zspan->miny2) my0= zspan->miny2; else my0= zspan->miny1; - if(zspan->maxy1 > zspan->maxy2) my2= zspan->maxy2; else my2= zspan->maxy1; + if (zspan->miny1 < zspan->miny2) my0= zspan->miny2; else my0= zspan->miny1; + if (zspan->maxy1 > zspan->maxy2) my2= zspan->maxy2; else my2= zspan->maxy1; // printf("my %d %d\n", my0, my2); - if(my2<my0) return; + if (my2<my0) return; /* ZBUF DX DY, in floats still */ @@ -1207,7 +1207,7 @@ static void zbuffillGL4(ZSpan *zspan, int obi, int zvlnr, float *v1, float *v2, 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 + v1[2]; @@ -1224,7 +1224,7 @@ static void zbuffillGL4(ZSpan *zspan, int obi, int zvlnr, float *v1, float *v2, /* correct span */ sn1= (my0 + my2)/2; - if(zspan->span1[sn1] < zspan->span2[sn1]) { + if (zspan->span1[sn1] < zspan->span2[sn1]) { span1= zspan->span1+my2; span2= zspan->span2+my2; } @@ -1233,16 +1233,16 @@ static void zbuffillGL4(ZSpan *zspan, int obi, int zvlnr, float *v1, float *v2, span2= zspan->span1+my2; } - for(y=my2; y>=my0; y--, span1--, span2--) { + for (y=my2; y>=my0; y--, span1--, span2--) { sn1= floor(*span1); sn2= floor(*span2); sn1++; - if(sn2>=rectx) sn2= rectx-1; - if(sn1<0) sn1= 0; + if (sn2>=rectx) sn2= rectx-1; + if (sn1<0) sn1= 0; - if(sn2>=sn1) { + if (sn2>=sn1) { int intzverg; zverg= (double)sn1*zxd + zy0; @@ -1252,11 +1252,11 @@ static void zbuffillGL4(ZSpan *zspan, int obi, int zvlnr, float *v1, float *v2, rm= rectmaskofs+sn1; x= sn2-sn1; - while(x>=0) { + while (x>=0) { intzverg= (int)CLAMPIS(zverg, INT_MIN, INT_MAX); - if(intzverg < *rz) { /* ONLY UNIQUE LINE: see comment above */ - if(!zspan->rectmask || intzverg > *rm) { + if (intzverg < *rz) { /* ONLY UNIQUE LINE: see comment above */ + if (!zspan->rectmask || intzverg > *rm) { *rz= intzverg; *rp= zvlnr; *ro= obi; /* UNIQUE LINE: see comment above (order differs) */ @@ -1306,7 +1306,7 @@ static void zbuffillGL_onlyZ(ZSpan *zspan, int UNUSED(obi), int UNUSED(zvlnr), f /* set spans */ zbuf_add_to_span(zspan, v1, v2); zbuf_add_to_span(zspan, v2, v3); - if(v4) { + if (v4) { zbuf_add_to_span(zspan, v3, v4); zbuf_add_to_span(zspan, v4, v1); } @@ -1314,13 +1314,13 @@ static void zbuffillGL_onlyZ(ZSpan *zspan, int UNUSED(obi), int UNUSED(zvlnr), f zbuf_add_to_span(zspan, v3, v1); /* clipped */ - if(zspan->minp2==NULL || zspan->maxp2==NULL) return; + if (zspan->minp2==NULL || zspan->maxp2==NULL) return; - if(zspan->miny1 < zspan->miny2) my0= zspan->miny2; else my0= zspan->miny1; - if(zspan->maxy1 > zspan->maxy2) my2= zspan->maxy2; else my2= zspan->maxy1; + if (zspan->miny1 < zspan->miny2) my0= zspan->miny2; else my0= zspan->miny1; + if (zspan->maxy1 > zspan->maxy2) my2= zspan->maxy2; else my2= zspan->maxy1; // printf("my %d %d\n", my0, my2); - if(my2<my0) return; + if (my2<my0) return; /* ZBUF DX DY, in floats still */ @@ -1334,7 +1334,7 @@ static void zbuffillGL_onlyZ(ZSpan *zspan, int UNUSED(obi), int UNUSED(zvlnr), f 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 + v1[2]; @@ -1345,12 +1345,12 @@ static void zbuffillGL_onlyZ(ZSpan *zspan, int UNUSED(obi), int UNUSED(zvlnr), f /* start-offset in rect */ rectx= zspan->rectx; rectzofs= (zspan->rectz+rectx*my2); - if(zspan->rectz1) + if (zspan->rectz1) rectzofs1= (zspan->rectz1+rectx*my2); /* correct span */ sn1= (my0 + my2)/2; - if(zspan->span1[sn1] < zspan->span2[sn1]) { + if (zspan->span1[sn1] < zspan->span2[sn1]) { span1= zspan->span1+my2; span2= zspan->span2+my2; } @@ -1359,30 +1359,30 @@ static void zbuffillGL_onlyZ(ZSpan *zspan, int UNUSED(obi), int UNUSED(zvlnr), f span2= zspan->span1+my2; } - for(y=my2; y>=my0; y--, span1--, span2--) { + for (y=my2; y>=my0; y--, span1--, span2--) { sn1= floor(*span1); sn2= floor(*span2); sn1++; - if(sn2>=rectx) sn2= rectx-1; - if(sn1<0) sn1= 0; + if (sn2>=rectx) sn2= rectx-1; + if (sn1<0) sn1= 0; - if(sn2>=sn1) { + if (sn2>=sn1) { zverg= (double)sn1*zxd + zy0; rz= rectzofs+sn1; rz1= rectzofs1+sn1; x= sn2-sn1; - while(x>=0) { + while (x>=0) { int zvergi= (int)CLAMPIS(zverg, INT_MIN, INT_MAX); /* option: maintain two depth values, closest and 2nd closest */ - if(zvergi < *rz) { - if(rectzofs1) *rz1= *rz; + if (zvergi < *rz) { + if (rectzofs1) *rz1= *rz; *rz= zvergi; } - else if(rectzofs1 && zvergi < *rz1) + else if (rectzofs1 && zvergi < *rz1) *rz1= zvergi; zverg+= zxd; @@ -1395,7 +1395,7 @@ static void zbuffillGL_onlyZ(ZSpan *zspan, int UNUSED(obi), int UNUSED(zvlnr), f zy0-=zyd; rectzofs-= rectx; - if(rectzofs1) rectzofs1-= rectx; + if (rectzofs1) rectzofs1-= rectx; } } @@ -1416,13 +1416,13 @@ void zspan_scanconvert_strand(ZSpan *zspan, void *handle, float *v1, float *v2, zbuf_add_to_span(zspan, v3, v1); /* clipped */ - if(zspan->minp2==NULL || zspan->maxp2==NULL) return; + if (zspan->minp2==NULL || zspan->maxp2==NULL) return; - if(zspan->miny1 < zspan->miny2) my0= zspan->miny2; else my0= zspan->miny1; - if(zspan->maxy1 > zspan->maxy2) my2= zspan->maxy2; else my2= zspan->maxy1; + if (zspan->miny1 < zspan->miny2) my0= zspan->miny2; else my0= zspan->miny1; + if (zspan->maxy1 > zspan->maxy2) my2= zspan->maxy2; else my2= zspan->maxy1; // 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]; @@ -1436,7 +1436,7 @@ void zspan_scanconvert_strand(ZSpan *zspan, void *handle, float *v1, float *v2, 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 + v1[2]; zxd= -(double)x0/(double)z0; @@ -1467,7 +1467,7 @@ void zspan_scanconvert_strand(ZSpan *zspan, void *handle, float *v1, float *v2, /* correct span */ sn1= (my0 + my2)/2; - if(zspan->span1[sn1] < zspan->span2[sn1]) { + if (zspan->span1[sn1] < zspan->span2[sn1]) { span1= zspan->span1+my2; span2= zspan->span2+my2; } @@ -1476,20 +1476,20 @@ void zspan_scanconvert_strand(ZSpan *zspan, void *handle, float *v1, float *v2, span2= zspan->span1+my2; } - for(y=my2; y>=my0; y--, span1--, span2--) { + for (y=my2; y>=my0; y--, span1--, span2--) { sn1= floor(*span1); sn2= floor(*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; v= (double)sn1*vxd + vy0; z= (double)sn1*zxd + zy0; - for(x= sn1; x<=sn2; x++, u+=uxd, v+=vxd, z+=zxd) + for (x= sn1; x<=sn2; x++, u+=uxd, v+=vxd, z+=zxd) func(handle, x, y, u, v, z); uy0 -= uyd; @@ -1516,13 +1516,13 @@ 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; - if(zspan->miny1 < zspan->miny2) my0= zspan->miny2; else my0= zspan->miny1; - if(zspan->maxy1 > zspan->maxy2) my2= zspan->maxy2; else my2= zspan->maxy1; + if (zspan->miny1 < zspan->miny2) my0= zspan->miny2; else my0= zspan->miny1; + if (zspan->maxy1 > zspan->maxy2) my2= zspan->maxy2; else my2= zspan->maxy1; // 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]; @@ -1537,7 +1537,7 @@ void zspan_scanconvert(ZSpan *zspan, void *handle, float *v1, float *v2, float * 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; @@ -1557,7 +1557,7 @@ void zspan_scanconvert(ZSpan *zspan, void *handle, float *v1, float *v2, float * /* correct span */ sn1= (my0 + my2)/2; - if(zspan->span1[sn1] < zspan->span2[sn1]) { + if (zspan->span1[sn1] < zspan->span2[sn1]) { span1= zspan->span1+my2; span2= zspan->span2+my2; } @@ -1566,19 +1566,19 @@ void zspan_scanconvert(ZSpan *zspan, void *handle, float *v1, float *v2, float * span2= zspan->span1+my2; } - for(y=my2; y>=my0; y--, span1--, span2--) { + for (y=my2; y>=my0; y--, span1--, span2--) { sn1= floor(*span1); sn2= floor(*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; v= (double)sn1*vxd + vy0; - for(x= sn1; x<=sn2; x++, u+=uxd, v+=vxd) + for (x= sn1; x<=sn2; x++, u+=uxd, v+=vxd) func(handle, x, y, u, v); uy0 -= uyd; @@ -1612,7 +1612,7 @@ static void clippyra(float *labda, float *v1, float *v2, int *b2, int *b3, int a da= v2[a]-v1[a]; /* prob; we clip slightly larger, osa renders add 2 pixels on edges, should become variable? */ /* or better; increase r.winx/y size, but thats quite a complex one. do it later */ - if(a==2) { + if (a==2) { dw= (v2[3]-v1[3]); v13= v1[3]; } @@ -1627,18 +1627,21 @@ static void clippyra(float *labda, float *v1, float *v2, int *b2, int *b3, int a * who would have thought that of L&B! */ - if(cliptestf(-da, -dw, v13, v1[a], &u1,&u2)) { - if(cliptestf(da, -dw, v13, -v1[a], &u1,&u2)) { + if (cliptestf(-da, -dw, v13, v1[a], &u1,&u2)) { + if (cliptestf(da, -dw, v13, -v1[a], &u1,&u2)) { *b3=1; - if(u2<1.0f) { + if (u2<1.0f) { labda[1]= u2; *b2=1; } else labda[1]=1.0; /* u2 */ - if(u1>0.0f) { - labda[0]= u1; - *b2=1; - } else labda[0]=0.0; + if (u1>0.0f) { + labda[0] = u1; + *b2 = 1; + } + else { + labda[0] = 0.0; + } } } } @@ -1665,8 +1668,8 @@ static void makevertpyra(float *vez, float *labda, float **trias, float *v1, flo l1= labda[0]; l2= labda[1]; - if(l1!= -1.0f) { - if(l1!= 0.0f) { + if (l1!= -1.0f) { + if (l1!= 0.0f) { adr= vez+4*(*clve); trias[*b1]=adr; (*clve)++; @@ -1679,8 +1682,8 @@ static void makevertpyra(float *vez, float *labda, float **trias, float *v1, flo (*b1)++; } - if(l2!= -1.0f) { - if(l2!= 1.0f) { + if (l2!= -1.0f) { + if (l2!= 1.0f) { adr= vez+4*(*clve); trias[*b1]=adr; (*clve)++; @@ -1740,11 +1743,11 @@ static void zbuf_project_cache_clear(ZbufProjectCache *cache, int size) { int i; - if(size > ZBUF_PROJECT_CACHE_SIZE) + if (size > ZBUF_PROJECT_CACHE_SIZE) size= ZBUF_PROJECT_CACHE_SIZE; memset(cache, 0, sizeof(ZbufProjectCache)*size); - for(i=0; i<size; i++) + for (i=0; i<size; i++) cache[i].index= -1; } @@ -1752,7 +1755,7 @@ static int zbuf_shadow_project(ZbufProjectCache *cache, int index, float winmat[ { int cindex= index & 255; - if(cache[cindex].index == index) { + if (cache[cindex].index == index) { copy_v4_v4(ho, cache[cindex].ho); return cache[cindex].clip; } @@ -1782,7 +1785,7 @@ static int zbuf_part_project(ZbufProjectCache *cache, int index, float winmat[][ float vec[3]; int cindex= index & 255; - if(cache[cindex].index == index) { + if (cache[cindex].index == index) { copy_v4_v4(ho, cache[cindex].ho); return cache[cindex].clip; } @@ -1793,10 +1796,10 @@ static int zbuf_part_project(ZbufProjectCache *cache, int index, float winmat[][ projectvert(co, winmat, ho); wco= ho[3]; - if(ho[0] < bounds[0]*wco) clipflag |= 1; - else if(ho[0] > bounds[1]*wco) clipflag |= 2; - if(ho[1] > bounds[3]*wco) clipflag |= 4; - else if(ho[1] < bounds[2]*wco) clipflag |= 8; + if (ho[0] < bounds[0]*wco) clipflag |= 1; + else if (ho[0] > bounds[1]*wco) clipflag |= 2; + if (ho[1] > bounds[3]*wco) clipflag |= 4; + else if (ho[1] < bounds[2]*wco) clipflag |= 8; copy_v4_v4(cache[cindex].ho, ho); cache[cindex].clip= clipflag; @@ -1816,7 +1819,7 @@ void zbuf_render_project(float winmat[][4], const float co[3], float ho[4]) void zbuf_make_winmat(Render *re, float winmat[][4]) { - if(re->r.mode & R_PANORAMA) { + if (re->r.mode & R_PANORAMA) { float panomat[4][4]= MAT4_UNITY; panomat[0][0]= re->panoco; @@ -1837,10 +1840,11 @@ void zbufclip(ZSpan *zspan, int obi, int zvlnr, float *f1, float *f2, float *f3, float *vlzp[32][3], labda[3][2]; float vez[400], *trias[40]; - if(c1 | c2 | c3) { /* not in middle */ - if(c1 & c2 & c3) { /* completely out */ + if (c1 | c2 | c3) { /* not in middle */ + if (c1 & c2 & c3) { /* completely out */ return; - } else { /* clipping */ + } + else { /* clipping */ int arg, v, b, clipflag[3], b1, b2, b3, c4, clve=3, clvlo, clvl=1; vez[0]= f1[0]; vez[1]= f1[1]; vez[2]= f1[2]; vez[3]= f1[3]; @@ -1852,24 +1856,24 @@ void zbufclip(ZSpan *zspan, int obi, int zvlnr, float *f1, float *f2, float *f3, vlzp[0][2]= vez+8; clipflag[0]= ( (c1 & 48) | (c2 & 48) | (c3 & 48) ); - if(clipflag[0]==0) { /* othwerwise it needs to be calculated again, after the first (z) clip */ + if (clipflag[0]==0) { /* othwerwise it needs to be calculated again, after the first (z) clip */ clipflag[1]= ( (c1 & 3) | (c2 & 3) | (c3 & 3) ); clipflag[2]= ( (c1 & 12) | (c2 & 12) | (c3 & 12) ); } else clipflag[1]=clipflag[2]= 0; - for(b=0;b<3;b++) { + for (b=0;b<3;b++) { - if(clipflag[b]) { + if (clipflag[b]) { clvlo= clvl; - for(v=0; v<clvlo; v++) { + for (v=0; v<clvlo; v++) { - if(vlzp[v][0]!=NULL) { /* face is still there */ + if (vlzp[v][0]!=NULL) { /* face is still there */ b2= b3 =0; /* clip flags */ - if(b==0) arg= 2; + if (b==0) arg= 2; else if (b==1) arg= 0; else arg= 1; @@ -1877,27 +1881,29 @@ void zbufclip(ZSpan *zspan, int obi, int zvlnr, float *f1, float *f2, float *f3, clippyra(labda[1], vlzp[v][1],vlzp[v][2], &b2,&b3, arg, zspan->clipcrop); clippyra(labda[2], vlzp[v][2],vlzp[v][0], &b2,&b3, arg, zspan->clipcrop); - if(b2==0 && b3==1) { + if (b2==0 && b3==1) { /* completely 'in', but we copy because of last for() loop in this section */; vlzp[clvl][0]= vlzp[v][0]; vlzp[clvl][1]= vlzp[v][1]; vlzp[clvl][2]= vlzp[v][2]; vlzp[v][0]= NULL; clvl++; - } else if(b3==0) { + } + else if (b3==0) { vlzp[v][0]= NULL; /* completely 'out' */; - } else { + } + else { b1=0; makevertpyra(vez, labda[0], trias, vlzp[v][0],vlzp[v][1], &b1,&clve); makevertpyra(vez, labda[1], trias, vlzp[v][1],vlzp[v][2], &b1,&clve); makevertpyra(vez, labda[2], trias, vlzp[v][2],vlzp[v][0], &b1,&clve); /* after front clip done: now set clip flags */ - if(b==0) { + if (b==0) { clipflag[1]= clipflag[2]= 0; f1= vez; - for(b3=0; b3<clve; b3++) { + for (b3=0; b3<clve; b3++) { c4= testclip(f1); clipflag[1] |= (c4 & 3); clipflag[2] |= (c4 & 12); @@ -1906,8 +1912,8 @@ void zbufclip(ZSpan *zspan, int obi, int zvlnr, float *f1, float *f2, float *f3, } vlzp[v][0]= NULL; - if(b1>2) { - for(b3=3; b3<=b1; b3++) { + if (b1>2) { + for (b3=3; b3<=b1; b3++) { vlzp[clvl][0]= trias[0]; vlzp[clvl][1]= trias[b3-2]; vlzp[clvl][2]= trias[b3-1]; @@ -1921,16 +1927,16 @@ void zbufclip(ZSpan *zspan, int obi, int zvlnr, float *f1, float *f2, float *f3, } /* warning, this should never happen! */ - if(clve>38 || clvl>31) printf("clip overflow: clve clvl %d %d\n",clve,clvl); + if (clve>38 || clvl>31) printf("clip overflow: clve clvl %d %d\n",clve,clvl); /* perspective division */ f1=vez; - for(c1=0;c1<clve;c1++) { + for (c1=0;c1<clve;c1++) { hoco_to_zco(zspan, f1, f1); f1+=4; } - for(b=1;b<clvl;b++) { - if(vlzp[b][0]) { + for (b=1;b<clvl;b++) { + if (vlzp[b][0]) { zspan->zbuffunc(zspan, obi, zvlnr, vlzp[b][0],vlzp[b][1],vlzp[b][2], NULL); } } @@ -1949,10 +1955,11 @@ void zbufclip4(ZSpan *zspan, int obi, int zvlnr, float *f1, float *f2, float *f3 { float vez[16]; - if(c1 | c2 | c3 | c4) { /* not in middle */ - if(c1 & c2 & c3 & c4) { /* completely out */ + if (c1 | c2 | c3 | c4) { /* not in middle */ + if (c1 & c2 & c3 & c4) { /* completely out */ return; - } else { /* clipping */ + } + else { /* clipping */ zbufclip(zspan, obi, zvlnr, f1, f2, f3, c1, c2, c3); zbufclip(zspan, obi, zvlnr, f1, f3, f4, c1, c3, c4); } @@ -1970,7 +1977,7 @@ void zbufclip4(ZSpan *zspan, int obi, int zvlnr, float *f1, float *f2, float *f3 /* ************** ZMASK ******************************** */ -#define EXTEND_PIXEL(a) if(temprectp[a]) {z+= rectz[a]; tot++;} +#define EXTEND_PIXEL(a) if (temprectp[a]) {z+= rectz[a]; tot++;} /* changes the zbuffer to be ready for z-masking: applies an extend-filter, and then clears */ static void zmask_rect(int *rectz, int *rectp, int xs, int ys, int neg) @@ -1983,21 +1990,21 @@ static void zmask_rect(int *rectz, int *rectp, int xs, int ys, int neg) /* extend: if pixel is not filled in, we check surrounding pixels and average z value */ - for(y=1; y<=ys; y++) { + for (y=1; y<=ys; y++) { /* setup row indices */ row1= (y-2)*xs; row2= row1 + xs; row3= row2 + xs; - if(y==1) + if (y==1) row1= row2; - else if(y==ys) + else if (y==ys) row3= row2; curp= rectp + (y-1)*xs; curz= rectz + (y-1)*xs; - for(x=0; x<xs; x++, curp++, curz++) { - if(curp[0]==0) { + for (x=0; x<xs; x++, curp++, curz++) { + if (curp[0]==0) { int tot= 0; float z= 0.0f; @@ -2006,19 +2013,19 @@ static void zmask_rect(int *rectz, int *rectp, int xs, int ys, int neg) EXTEND_PIXEL(row3); EXTEND_PIXEL(row1 + 1); EXTEND_PIXEL(row3 + 1); - if(x!=xs-1) { + if (x!=xs-1) { EXTEND_PIXEL(row1 + 2); EXTEND_PIXEL(row2 + 2); EXTEND_PIXEL(row3 + 2); } - if(tot) { + if (tot) { len++; curz[0]= (int)(z/(float)tot); curp[0]= -1; /* env */ } } - if(x!=0) { + if (x!=0) { row1++; row2++; row3++; } } @@ -2026,11 +2033,11 @@ static void zmask_rect(int *rectz, int *rectp, int xs, int ys, int neg) MEM_freeN(temprectp); - if(neg); /* z values for negative are already correct */ + if (neg); /* z values for negative are already correct */ else { /* clear not filled z values */ - for(len= xs*ys -1; len>=0; len--) { - if(rectp[len]==0) { + for (len= xs*ys -1; len>=0; len--) { + if (rectp[len]==0) { rectz[len] = -0x7FFFFFFF; rectp[len]= -1; /* env code */ } @@ -2065,7 +2072,7 @@ void zbuffer_solid(RenderPart *pa, RenderLayer *rl, void(*fillfunc)(RenderPart*, samples= (R.osa? R.osa: 1); samples= MIN2(4, samples-pa->sample); - for(zsample=0; zsample<samples; zsample++) { + for (zsample=0; zsample<samples; zsample++) { zspan= &zspans[zsample]; zbuffer_part_bounds(R.winx, R.winy, pa, bounds); @@ -2075,11 +2082,11 @@ void zbuffer_solid(RenderPart *pa, RenderLayer *rl, void(*fillfunc)(RenderPart*, zspan->zmulx= ((float)R.winx)/2.0f; zspan->zmuly= ((float)R.winy)/2.0f; - if(R.osa) { + if (R.osa) { zspan->zofsx= -pa->disprect.xmin - R.jit[pa->sample+zsample][0]; zspan->zofsy= -pa->disprect.ymin - R.jit[pa->sample+zsample][1]; } - else if(R.i.curblur) { + else if (R.i.curblur) { zspan->zofsx= -pa->disprect.xmin - R.mblur_jit[R.i.curblur-1][0]; zspan->zofsy= -pa->disprect.ymin - R.mblur_jit[R.i.curblur-1][1]; } @@ -2092,11 +2099,11 @@ void zbuffer_solid(RenderPart *pa, RenderLayer *rl, void(*fillfunc)(RenderPart*, zspan->zofsy -= 0.5f; /* the buffers */ - if(zsample == samples-1) { + if (zsample == samples-1) { zspan->rectp= pa->rectp; zspan->recto= pa->recto; - if(neg_zmask) + if (neg_zmask) zspan->rectz= pa->rectmask; else zspan->rectz= pa->rectz; @@ -2113,17 +2120,17 @@ void zbuffer_solid(RenderPart *pa, RenderLayer *rl, void(*fillfunc)(RenderPart*, } /* in case zmask we fill Z for objects in lay_zmask first, then clear Z, and then do normal zbuffering */ - if(rl->layflag & SCE_LAY_ZMASK) + if (rl->layflag & SCE_LAY_ZMASK) zmaskpass= 1; - for(; zmaskpass >=0; zmaskpass--) { + for (; zmaskpass >=0; zmaskpass--) { ma= NULL; /* filling methods */ - for(zsample=0; zsample<samples; zsample++) { + for (zsample=0; zsample<samples; zsample++) { zspan= &zspans[zsample]; - if(zmaskpass && neg_zmask) + if (zmaskpass && neg_zmask) zspan->zbuffunc= zbuffillGLinv4; else zspan->zbuffunc= zbuffillGL4; @@ -2131,48 +2138,48 @@ void zbuffer_solid(RenderPart *pa, RenderLayer *rl, void(*fillfunc)(RenderPart*, } /* regular zbuffering loop, does all sample buffers */ - for(i=0, obi=R.instancetable.first; obi; i++, obi=obi->next) { + for (i=0, obi=R.instancetable.first; obi; i++, obi=obi->next) { obr= obi->obr; /* continue happens in 2 different ways... zmaskpass only does lay_zmask stuff */ - if(zmaskpass) { - if((obi->lay & lay_zmask)==0) + if (zmaskpass) { + if ((obi->lay & lay_zmask)==0) continue; } - else if(!all_z && !(obi->lay & (lay|lay_zmask))) + else if (!all_z && !(obi->lay & (lay|lay_zmask))) continue; - if(obi->flag & R_TRANSFORMED) + if (obi->flag & R_TRANSFORMED) mult_m4_m4m4(obwinmat, winmat, obi->mat); else copy_m4_m4(obwinmat, winmat); - if(clip_render_object(obi->obr->boundbox, bounds, obwinmat)) + if (clip_render_object(obi->obr->boundbox, bounds, obwinmat)) continue; zbuf_project_cache_clear(cache, obr->totvert); - for(v=0; v<obr->totvlak; v++) { - if((v & 255)==0) vlr= obr->vlaknodes[v>>8].vlak; + for (v=0; v<obr->totvlak; v++) { + if ((v & 255)==0) vlr= obr->vlaknodes[v>>8].vlak; else vlr++; /* the cases: visible for render, only z values, zmask, nothing */ - if(obi->lay & lay) { - if(vlr->mat!=ma) { + if (obi->lay & lay) { + if (vlr->mat!=ma) { ma= vlr->mat; nofill= (ma->mode & MA_ONLYCAST) || ((ma->mode & MA_TRANSP) && (ma->mode & MA_ZTRANSP)); env= (ma->mode & MA_ENV); wire= (ma->material_type == MA_TYPE_WIRE); - for(zsample=0; zsample<samples; zsample++) { - if(ma->mode & MA_ZINV || (zmaskpass && neg_zmask)) + for (zsample=0; zsample<samples; zsample++) { + if (ma->mode & MA_ZINV || (zmaskpass && neg_zmask)) zspans[zsample].zbuffunc= zbuffillGLinv4; else zspans[zsample].zbuffunc= zbuffillGL4; } } } - else if(all_z || (obi->lay & lay_zmask)) { + else if (all_z || (obi->lay & lay_zmask)) { env= 1; nofill= 0; ma= NULL; @@ -2182,7 +2189,7 @@ void zbuffer_solid(RenderPart *pa, RenderLayer *rl, void(*fillfunc)(RenderPart*, ma= NULL; /* otherwise nofill can hang */ } - if(!(vlr->flag & R_HIDDEN) && nofill==0) { + if (!(vlr->flag & R_HIDDEN) && nofill==0) { unsigned short partclip; v1= vlr->v1; @@ -2196,39 +2203,39 @@ void zbuffer_solid(RenderPart *pa, RenderLayer *rl, void(*fillfunc)(RenderPart*, /* partclipping doesn't need viewplane clipping */ partclip= c1 & c2 & c3; - if(v4) { + if (v4) { c4= zbuf_part_project(cache, v4->index, obwinmat, bounds, v4->co, ho4); partclip &= c4; } - if(partclip==0) { + if (partclip==0) { - if(env) zvlnr= -1; + if (env) zvlnr= -1; else zvlnr= v+1; c1= testclip(ho1); c2= testclip(ho2); c3= testclip(ho3); - if(v4) + if (v4) c4= testclip(ho4); - for(zsample=0; zsample<samples; zsample++) { + for (zsample=0; zsample<samples; zsample++) { zspan= &zspans[zsample]; - if(wire) { - if(v4) + if (wire) { + if (v4) zbufclipwire(zspan, i, zvlnr, vlr->ec, ho1, ho2, ho3, ho4, c1, c2, c3, c4); else zbufclipwire(zspan, i, zvlnr, vlr->ec, ho1, ho2, ho3, 0, c1, c2, c3, 0); } else { /* strands allow to be filled in as quad */ - if(v4 && (vlr->flag & R_STRAND)) { + if (v4 && (vlr->flag & R_STRAND)) { zbufclip4(zspan, i, zvlnr, ho1, ho2, ho3, ho4, c1, c2, c3, c4); } else { zbufclip(zspan, i, zvlnr, ho1, ho2, ho3, c1, c2, c3); - if(v4) + if (v4) zbufclip(zspan, i, (env)? zvlnr: zvlnr+RE_QUAD_OFFS, ho1, ho3, ho4, c1, c3, c4); } } @@ -2239,13 +2246,13 @@ void zbuffer_solid(RenderPart *pa, RenderLayer *rl, void(*fillfunc)(RenderPart*, } /* clear all z to close value, so it works as mask for next passes (ztra+strand) */ - if(zmaskpass) { - for(zsample=0; zsample<samples; zsample++) { + if (zmaskpass) { + for (zsample=0; zsample<samples; zsample++) { zspan= &zspans[zsample]; - if(neg_zmask) { + if (neg_zmask) { zspan->rectmask= zspan->rectz; - if(zsample == samples-1) + if (zsample == samples-1) zspan->rectz= pa->rectz; else zspan->rectz= MEM_mallocN(sizeof(int)*pa->rectx*pa->recty, "rectz"); @@ -2259,17 +2266,17 @@ void zbuffer_solid(RenderPart *pa, RenderLayer *rl, void(*fillfunc)(RenderPart*, } } - for(zsample=0; zsample<samples; zsample++) { + for (zsample=0; zsample<samples; zsample++) { zspan= &zspans[zsample]; - if(fillfunc) + if (fillfunc) fillfunc(pa, zspan, pa->sample+zsample, data); - if(zsample != samples-1) { + if (zsample != samples-1) { MEM_freeN(zspan->rectz); MEM_freeN(zspan->rectp); MEM_freeN(zspan->recto); - if(zspan->rectmask) + if (zspan->rectmask) MEM_freeN(zspan->rectmask); } @@ -2292,7 +2299,7 @@ void zbuffer_shadow(Render *re, float winmat[][4], LampRen *lar, int *rectz, int float obwinmat[4][4], ho1[4], ho2[4], ho3[4], ho4[4]; int a, b, c, i, c1, c2, c3, c4, ok=1, lay= -1; - if(lar->mode & (LA_LAYER|LA_LAYER_SHADOW)) lay= lar->lay; + if (lar->mode & (LA_LAYER|LA_LAYER_SHADOW)) lay= lar->lay; /* 1.0f for clipping in clippyra()... bad stuff actually */ zbuf_alloc_span(&zspan, size, size, 1.0f); @@ -2305,7 +2312,7 @@ void zbuffer_shadow(Render *re, float winmat[][4], LampRen *lar, int *rectz, int /* the buffers */ zspan.rectz= rectz; fillrect(rectz, size, size, 0x7FFFFFFE); - if(lar->buftype==LA_SHADBUF_HALFWAY) { + if (lar->buftype==LA_SHADBUF_HALFWAY) { zspan.rectz1= MEM_mallocN(size*size*sizeof(int), "seconday z buffer"); fillrect(zspan.rectz1, size, size, 0x7FFFFFFE); } @@ -2314,44 +2321,44 @@ void zbuffer_shadow(Render *re, float winmat[][4], LampRen *lar, int *rectz, int zspan.zbuflinefunc= zbufline_onlyZ; zspan.zbuffunc= zbuffillGL_onlyZ; - for(i=0, obi=re->instancetable.first; obi; i++, obi=obi->next) { + for (i=0, obi=re->instancetable.first; obi; i++, obi=obi->next) { obr= obi->obr; - if(obr->ob==re->excludeob) + if (obr->ob==re->excludeob) continue; - else if(!(obi->lay & lay)) + else if (!(obi->lay & lay)) continue; - if(obi->flag & R_TRANSFORMED) + if (obi->flag & R_TRANSFORMED) mult_m4_m4m4(obwinmat, winmat, obi->mat); else copy_m4_m4(obwinmat, winmat); - if(clip_render_object(obi->obr->boundbox, NULL, obwinmat)) + if (clip_render_object(obi->obr->boundbox, NULL, obwinmat)) continue; zbuf_project_cache_clear(cache, obr->totvert); /* faces */ - for(a=0; a<obr->totvlak; a++) { + for (a=0; a<obr->totvlak; a++) { - if((a & 255)==0) vlr= obr->vlaknodes[a>>8].vlak; + if ((a & 255)==0) vlr= obr->vlaknodes[a>>8].vlak; else vlr++; /* note, these conditions are copied in shadowbuf_autoclip() */ - if(vlr->mat!= ma) { + if (vlr->mat!= ma) { ma= vlr->mat; ok= 1; - if((ma->mode & MA_SHADBUF)==0) ok= 0; + if ((ma->mode & MA_SHADBUF)==0) ok= 0; } - if(ok && (obi->lay & lay) && !(vlr->flag & R_HIDDEN)) { + if (ok && (obi->lay & lay) && !(vlr->flag & R_HIDDEN)) { c1= zbuf_shadow_project(cache, vlr->v1->index, obwinmat, vlr->v1->co, ho1); c2= zbuf_shadow_project(cache, vlr->v2->index, obwinmat, vlr->v2->co, ho2); c3= zbuf_shadow_project(cache, vlr->v3->index, obwinmat, vlr->v3->co, ho3); - if((ma->material_type == MA_TYPE_WIRE) || (vlr->flag & R_STRAND)) { - if(vlr->v4) { + if ((ma->material_type == MA_TYPE_WIRE) || (vlr->flag & R_STRAND)) { + if (vlr->v4) { c4= zbuf_shadow_project(cache, vlr->v4->index, obwinmat, vlr->v4->co, ho4); zbufclipwire(&zspan, 0, a+1, vlr->ec, ho1, ho2, ho3, ho4, c1, c2, c3, c4); } @@ -2359,7 +2366,7 @@ void zbuffer_shadow(Render *re, float winmat[][4], LampRen *lar, int *rectz, int zbufclipwire(&zspan, 0, a+1, vlr->ec, ho1, ho2, ho3, 0, c1, c2, c3, 0); } else { - if(vlr->v4) { + if (vlr->v4) { c4= zbuf_shadow_project(cache, vlr->v4->index, obwinmat, vlr->v4->co, ho4); zbufclip4(&zspan, 0, 0, ho1, ho2, ho3, ho4, c1, c2, c3, c4); } @@ -2368,20 +2375,20 @@ void zbuffer_shadow(Render *re, float winmat[][4], LampRen *lar, int *rectz, int } } - if((a & 255)==255 && re->test_break(re->tbh)) + if ((a & 255)==255 && re->test_break(re->tbh)) break; } /* strands */ - if(obr->strandbuf) { + if (obr->strandbuf) { /* for each bounding box containing a number of strands */ sbound= obr->strandbuf->bound; - for(c=0; c<obr->strandbuf->totbound; c++, sbound++) { - if(clip_render_object(sbound->boundbox, NULL, obwinmat)) + for (c=0; c<obr->strandbuf->totbound; c++, sbound++) { + if (clip_render_object(sbound->boundbox, NULL, obwinmat)) continue; /* for each strand in this bounding box */ - for(a=sbound->start; a<sbound->end; a++) { + for (a=sbound->start; a<sbound->end; a++) { strand= RE_findOrAddStrand(obr, a); sseg.obi= obi; @@ -2392,16 +2399,16 @@ void zbuffer_shadow(Render *re, float winmat[][4], LampRen *lar, int *rectz, int svert= strand->vert; /* note, these conditions are copied in shadowbuf_autoclip() */ - if(sseg.buffer->ma!= ma) { + if (sseg.buffer->ma!= ma) { ma= sseg.buffer->ma; ok= 1; - if((ma->mode & MA_SHADBUF)==0) ok= 0; + if ((ma->mode & MA_SHADBUF)==0) ok= 0; } - if(ok && (sseg.buffer->lay & lay)) { + if (ok && (sseg.buffer->lay & lay)) { zbuf_project_cache_clear(cache, strand->totvert); - for(b=0; b<strand->totvert-1; b++, svert++) { + for (b=0; b<strand->totvert-1; b++, svert++) { sseg.v[0]= (b > 0)? (svert-1): svert; sseg.v[1]= svert; sseg.v[2]= svert+1; @@ -2412,24 +2419,24 @@ void zbuffer_shadow(Render *re, float winmat[][4], LampRen *lar, int *rectz, int c3= zbuf_shadow_project(cache, sseg.v[2]-strand->vert, obwinmat, sseg.v[2]->co, ho3); c4= zbuf_shadow_project(cache, sseg.v[3]-strand->vert, obwinmat, sseg.v[3]->co, ho4); - if(!(c1 & c2 & c3 & c4)) + if (!(c1 & c2 & c3 & c4)) render_strand_segment(re, winmat, NULL, &zspan, 1, &sseg); } } - if((a & 255)==255 && re->test_break(re->tbh)) + if ((a & 255)==255 && re->test_break(re->tbh)) break; } } } - if(re->test_break(re->tbh)) + if (re->test_break(re->tbh)) break; } /* merge buffers */ - if(lar->buftype==LA_SHADBUF_HALFWAY) { - for(a=size*size -1; a>=0; a--) + if (lar->buftype==LA_SHADBUF_HALFWAY) { + for (a=size*size -1; a>=0; a--) rectz[a]= (rectz[a]>>1) + (zspan.rectz1[a]>>1); MEM_freeN(zspan.rectz1); @@ -2449,7 +2456,7 @@ static void zbuffill_sss(ZSpan *zspan, int obi, int zvlnr, float *v1, float *v2, /* set spans */ zbuf_add_to_span(zspan, v1, v2); zbuf_add_to_span(zspan, v2, v3); - if(v4) { + if (v4) { zbuf_add_to_span(zspan, v3, v4); zbuf_add_to_span(zspan, v4, v1); } @@ -2457,12 +2464,12 @@ static void zbuffill_sss(ZSpan *zspan, int obi, int zvlnr, float *v1, float *v2, zbuf_add_to_span(zspan, v3, v1); /* clipped */ - if(zspan->minp2==NULL || zspan->maxp2==NULL) return; + if (zspan->minp2==NULL || zspan->maxp2==NULL) return; - if(zspan->miny1 < zspan->miny2) my0= zspan->miny2; else my0= zspan->miny1; - if(zspan->maxy1 > zspan->maxy2) my2= zspan->maxy2; else my2= zspan->maxy1; + if (zspan->miny1 < zspan->miny2) my0= zspan->miny2; else my0= zspan->miny1; + if (zspan->maxy1 > zspan->maxy2) my2= zspan->maxy2; else my2= zspan->maxy1; - if(my2<my0) return; + if (my2<my0) return; /* ZBUF DX DY, in floats still */ x1= v1[0]- v2[0]; @@ -2476,7 +2483,7 @@ static void zbuffill_sss(ZSpan *zspan, int obi, int zvlnr, float *v1, float *v2, 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 + v1[2]; zxd= -(double)x0/(double)z0; @@ -2485,7 +2492,7 @@ static void zbuffill_sss(ZSpan *zspan, int obi, int zvlnr, float *v1, float *v2, /* correct span */ sn1= (my0 + my2)/2; - if(zspan->span1[sn1] < zspan->span2[sn1]) { + if (zspan->span1[sn1] < zspan->span2[sn1]) { span1= zspan->span1+my2; span2= zspan->span2+my2; } @@ -2494,17 +2501,17 @@ static void zbuffill_sss(ZSpan *zspan, int obi, int zvlnr, float *v1, float *v2, span2= zspan->span1+my2; } - for(y=my2; y>=my0; y--, span1--, span2--) { + for (y=my2; y>=my0; y--, span1--, span2--) { sn1= floor(*span1); sn2= floor(*span2); sn1++; - if(sn2>=rectx) sn2= rectx-1; - if(sn1<0) sn1= 0; + if (sn2>=rectx) sn2= rectx-1; + if (sn1<0) sn1= 0; z= (double)sn1*zxd + zy0; - for(x= sn1; x<=sn2; x++, z+=zxd) + for (x= sn1; x<=sn2; x++, z+=zxd) zspan->sss_func(zspan->sss_handle, obi, zvlnr, x, y, z); zy0 -= zyd; @@ -2544,41 +2551,41 @@ void zbuffer_sss(RenderPart *pa, unsigned int lay, void *handle, void (*func)(vo zspan.zbuffunc= zbuffill_sss; /* fill front and back zbuffer */ - if(pa->rectz) { + if (pa->rectz) { fillrect(pa->recto, pa->rectx, pa->recty, 0); fillrect(pa->rectp, pa->rectx, pa->recty, 0); fillrect(pa->rectz, pa->rectx, pa->recty, 0x7FFFFFFF); } - if(pa->rectbackz) { + if (pa->rectbackz) { fillrect(pa->rectbacko, pa->rectx, pa->recty, 0); fillrect(pa->rectbackp, pa->rectx, pa->recty, 0); fillrect(pa->rectbackz, pa->rectx, pa->recty, -0x7FFFFFFF); } - for(i=0, obi=R.instancetable.first; obi; i++, obi=obi->next) { + for (i=0, obi=R.instancetable.first; obi; i++, obi=obi->next) { obr= obi->obr; - if(!(obi->lay & lay)) + if (!(obi->lay & lay)) continue; - if(obi->flag & R_TRANSFORMED) + if (obi->flag & R_TRANSFORMED) mult_m4_m4m4(obwinmat, winmat, obi->mat); else copy_m4_m4(obwinmat, winmat); - if(clip_render_object(obi->obr->boundbox, bounds, obwinmat)) + if (clip_render_object(obi->obr->boundbox, bounds, obwinmat)) continue; zbuf_project_cache_clear(cache, obr->totvert); - for(v=0; v<obr->totvlak; v++) { - if((v & 255)==0) vlr= obr->vlaknodes[v>>8].vlak; + for (v=0; v<obr->totvlak; v++) { + if ((v & 255)==0) vlr= obr->vlaknodes[v>>8].vlak; else vlr++; - if(material_in_material(vlr->mat, sss_ma)) { + if (material_in_material(vlr->mat, sss_ma)) { /* three cases, visible for render, only z values and nothing */ - if(obi->lay & lay) { - if(vlr->mat!=ma) { + if (obi->lay & lay) { + if (vlr->mat!=ma) { ma= vlr->mat; nofill= ma->mode & MA_ONLYCAST; env= (ma->mode & MA_ENV); @@ -2590,7 +2597,7 @@ void zbuffer_sss(RenderPart *pa, unsigned int lay, void *handle, void (*func)(vo ma= NULL; /* otherwise nofill can hang */ } - if(nofill==0 && wire==0 && env==0) { + if (nofill==0 && wire==0 && env==0) { unsigned short partclip; v1= vlr->v1; @@ -2604,19 +2611,19 @@ void zbuffer_sss(RenderPart *pa, unsigned int lay, void *handle, void (*func)(vo /* partclipping doesn't need viewplane clipping */ partclip= c1 & c2 & c3; - if(v4) { + if (v4) { c4= zbuf_part_project(cache, v4->index, obwinmat, bounds, v4->co, ho4); partclip &= c4; } - if(partclip==0) { + if (partclip==0) { c1= testclip(ho1); c2= testclip(ho2); c3= testclip(ho3); zvlnr= v+1; zbufclip(&zspan, i, zvlnr, ho1, ho2, ho3, c1, c2, c3); - if(v4) { + if (v4) { c4= testclip(ho4); zbufclip(&zspan, i, zvlnr+RE_QUAD_OFFS, ho1, ho3, ho4, c1, c3, c4); } @@ -2658,13 +2665,13 @@ static void zbuf_fill_in_rgba(ZSpan *zspan, DrawBufPixel *col, float *v1, float zbuf_add_to_span(zspan, v4, v1); /* clipped */ - if(zspan->minp2==NULL || zspan->maxp2==NULL) return; + if (zspan->minp2==NULL || zspan->maxp2==NULL) return; - if(zspan->miny1 < zspan->miny2) my0= zspan->miny2; else my0= zspan->miny1; - if(zspan->maxy1 > zspan->maxy2) my2= zspan->maxy2; else my2= zspan->maxy1; + if (zspan->miny1 < zspan->miny2) my0= zspan->miny2; else my0= zspan->miny1; + if (zspan->maxy1 > zspan->maxy2) my2= zspan->maxy2; else my2= zspan->maxy1; // 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]; @@ -2677,7 +2684,7 @@ static void zbuf_fill_in_rgba(ZSpan *zspan, DrawBufPixel *col, float *v1, float 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 + v1[2]; @@ -2692,7 +2699,7 @@ static void zbuf_fill_in_rgba(ZSpan *zspan, DrawBufPixel *col, float *v1, float /* correct span */ sn1= (my0 + my2)/2; - if(zspan->span1[sn1] < zspan->span2[sn1]) { + if (zspan->span1[sn1] < zspan->span2[sn1]) { span1= zspan->span1+my2; span2= zspan->span2+my2; } @@ -2701,23 +2708,23 @@ static void zbuf_fill_in_rgba(ZSpan *zspan, DrawBufPixel *col, float *v1, float span2= zspan->span1+my2; } - for(y=my2; y>=my0; y--, span1--, span2--) { + for (y=my2; y>=my0; y--, span1--, span2--) { sn1= floor(*span1); sn2= floor(*span2); sn1++; - if(sn2>=rectx) sn2= rectx-1; - if(sn1<0) sn1= 0; + if (sn2>=rectx) sn2= rectx-1; + if (sn1<0) sn1= 0; - if(sn2>=sn1) { + if (sn2>=sn1) { zverg= (double)sn1*zxd + zy0; rz= rectzofs+sn1; rp= rectpofs+sn1; x= sn2-sn1; - while(x>=0) { - if( zverg < *rz) { + while (x>=0) { + if ( zverg < *rz) { *rz= zverg; *rp= *col; } @@ -2743,14 +2750,14 @@ void antialias_tagbuf(int xsize, int ysize, char *rectmove) int a, x, y, step; /* 1: tag pixels to be candidate for AA */ - for(y=2; y<ysize; y++) { + for (y=2; y<ysize; y++) { /* setup rows */ row1= rectmove + (y-2)*xsize; row2= row1 + xsize; row3= row2 + xsize; - for(x=2; x<xsize; x++, row1++, row2++, row3++) { - if(row2[1]) { - if(row2[0]==0 || row2[2]==0 || row1[1]==0 || row3[1]==0) + for (x=2; x<xsize; x++, row1++, row2++, row3++) { + if (row2[1]) { + if (row2[0]==0 || row2[2]==0 || row1[1]==0 || row3[1]==0) row2[1]= 128; } } @@ -2758,22 +2765,22 @@ void antialias_tagbuf(int xsize, int ysize, char *rectmove) /* 2: evaluate horizontal scanlines and calculate alphas */ row1= rectmove; - for(y=0; y<ysize; y++) { + for (y=0; y<ysize; y++) { row1++; - for(x=1; x<xsize; x++, row1++) { - if(row1[0]==128 && row1[1]==128) { + for (x=1; x<xsize; x++, row1++) { + if (row1[0]==128 && row1[1]==128) { /* find previous color and next color and amount of steps to blend */ prev= row1[-1]; step= 1; - while(x+step<xsize && row1[step]==128) + while (x+step<xsize && row1[step]==128) step++; - if(x+step!=xsize) { + if (x+step!=xsize) { /* now we can blend values */ next= row1[step]; /* note, prev value can be next value, but we do this loop to clear 128 then */ - for(a=0; a<step; a++) { + for (a=0; a<step; a++) { int fac, mfac; fac= ((a+1)<<8)/(step+1); @@ -2788,22 +2795,22 @@ void antialias_tagbuf(int xsize, int ysize, char *rectmove) /* 3: evaluate vertical scanlines and calculate alphas */ /* use for reading a copy of the original tagged buffer */ - for(x=0; x<xsize; x++) { + for (x=0; x<xsize; x++) { row1= rectmove + x+xsize; - for(y=1; y<ysize; y++, row1+=xsize) { - if(row1[0]==128 && row1[xsize]==128) { + for (y=1; y<ysize; y++, row1+=xsize) { + if (row1[0]==128 && row1[xsize]==128) { /* find previous color and next color and amount of steps to blend */ prev= row1[-xsize]; step= 1; - while(y+step<ysize && row1[step*xsize]==128) + while (y+step<ysize && row1[step*xsize]==128) step++; - if(y+step!=ysize) { + if (y+step!=ysize) { /* now we can blend values */ next= row1[step*xsize]; /* note, prev value can be next value, but we do this loop to clear 128 then */ - for(a=0; a<step; a++) { + for (a=0; a<step; a++) { int fac, mfac; fac= ((a+1)<<8)/(step+1); @@ -2817,14 +2824,14 @@ void antialias_tagbuf(int xsize, int ysize, char *rectmove) } /* last: pixels with 0 we fill in zbuffer, with 1 we skip for mask */ - for(y=2; y<ysize; y++) { + for (y=2; y<ysize; y++) { /* setup rows */ row1= rectmove + (y-2)*xsize; row2= row1 + xsize; row3= row2 + xsize; - for(x=2; x<xsize; x++, row1++, row2++, row3++) { - if(row2[1]==0) { - if(row2[0]>1 || row2[2]>1 || row1[1]>1 || row3[1]>1) + for (x=2; x<xsize; x++, row1++, row2++, row3++) { + if (row2[1]==0) { + if (row2[0]>1 || row2[2]>1 || row1[1]>1 || row3[1]>1) row2[1]= 1; } } @@ -2895,16 +2902,16 @@ void RE_zbuf_accumulate_vecblur(NodeBlurData *nbd, int xsize, int ysize, float * /* debug... check if PASS_VECTOR_MAX still is in buffers */ dvec1= vecbufrect; - for(x= 4*xsize*ysize; x>0; x--, dvec1++) { - if(dvec1[0]==PASS_VECTOR_MAX) { + for (x= 4*xsize*ysize; x>0; x--, dvec1++) { + if (dvec1[0]==PASS_VECTOR_MAX) { dvec1[0]= 0.0f; tsktsk= 1; } } - if(tsktsk) printf("Found uninitialized speed in vector buffer... fixed.\n"); + if (tsktsk) printf("Found uninitialized speed in vector buffer... fixed.\n"); /* min speed? then copy speedbuffer to recalculate speed vectors */ - if(nbd->minspeed) { + if (nbd->minspeed) { float minspeed= (float)nbd->minspeed; float minspeedsq= minspeed*minspeed; @@ -2912,14 +2919,14 @@ void RE_zbuf_accumulate_vecblur(NodeBlurData *nbd, int xsize, int ysize, float * dvec1= vecbufrect; dvec2= minvecbufrect; - for(x= 2*xsize*ysize; x>0; x--, dvec1+=2, dvec2+=2) { - if(dvec1[0]==0.0f && dvec1[1]==0.0f) { + for (x= 2*xsize*ysize; x>0; x--, dvec1+=2, dvec2+=2) { + if (dvec1[0]==0.0f && dvec1[1]==0.0f) { dvec2[0]= dvec1[0]; dvec2[1]= dvec1[1]; } else { float speedsq= dvec1[0]*dvec1[0] + dvec1[1]*dvec1[1]; - if(speedsq <= minspeedsq) { + if (speedsq <= minspeedsq) { dvec2[0]= 0.0f; dvec2[1]= 0.0f; } @@ -2936,70 +2943,70 @@ void RE_zbuf_accumulate_vecblur(NodeBlurData *nbd, int xsize, int ysize, float * /* make vertex buffer with averaged speed and zvalues */ rectvz= MEM_mapallocN(4*sizeof(float)*(xsize+1)*(ysize+1), "vertices"); dvz= rectvz; - for(y=0; y<=ysize; y++) { + for (y=0; y<=ysize; y++) { - if(y==0) + if (y==0) dvec1= vecbufrect + 4*y*xsize; else dvec1= vecbufrect + 4*(y-1)*xsize; - if(y==ysize) + if (y==ysize) dvec2= vecbufrect + 4*(y-1)*xsize; else dvec2= vecbufrect + 4*y*xsize; - for(x=0; x<=xsize; x++) { + for (x=0; x<=xsize; x++) { /* two vectors, so a step loop */ - for(step=0; step<2; step++, dvec1+=2, dvec2+=2, dvz+=2) { + for (step=0; step<2; step++, dvec1+=2, dvec2+=2, dvz+=2) { /* average on minimal speed */ int div= 0; - if(x!=0) { - if(dvec1[-4]!=0.0f || dvec1[-3]!=0.0f) { + if (x!=0) { + if (dvec1[-4]!=0.0f || dvec1[-3]!=0.0f) { dvz[0]= dvec1[-4]; dvz[1]= dvec1[-3]; div++; } - if(dvec2[-4]!=0.0f || dvec2[-3]!=0.0f) { - if(div==0) { + if (dvec2[-4]!=0.0f || dvec2[-3]!=0.0f) { + if (div==0) { dvz[0]= dvec2[-4]; dvz[1]= dvec2[-3]; div++; } - else if( (ABS(dvec2[-4]) + ABS(dvec2[-3]))< (ABS(dvz[0]) + ABS(dvz[1])) ) { + else if ( (ABS(dvec2[-4]) + ABS(dvec2[-3]))< (ABS(dvz[0]) + ABS(dvz[1])) ) { dvz[0]= dvec2[-4]; dvz[1]= dvec2[-3]; } } } - if(x!=xsize) { - if(dvec1[0]!=0.0f || dvec1[1]!=0.0f) { - if(div==0) { + if (x!=xsize) { + if (dvec1[0]!=0.0f || dvec1[1]!=0.0f) { + if (div==0) { dvz[0]= dvec1[0]; dvz[1]= dvec1[1]; div++; } - else if( (ABS(dvec1[0]) + ABS(dvec1[1]))< (ABS(dvz[0]) + ABS(dvz[1])) ) { + else if ( (ABS(dvec1[0]) + ABS(dvec1[1]))< (ABS(dvz[0]) + ABS(dvz[1])) ) { dvz[0]= dvec1[0]; dvz[1]= dvec1[1]; } } - if(dvec2[0]!=0.0f || dvec2[1]!=0.0f) { - if(div==0) { + if (dvec2[0]!=0.0f || dvec2[1]!=0.0f) { + if (div==0) { dvz[0]= dvec2[0]; dvz[1]= dvec2[1]; } - else if( (ABS(dvec2[0]) + ABS(dvec2[1]))< (ABS(dvz[0]) + ABS(dvz[1])) ) { + else if ( (ABS(dvec2[0]) + ABS(dvec2[1]))< (ABS(dvz[0]) + ABS(dvz[1])) ) { dvz[0]= dvec2[0]; dvz[1]= dvec2[1]; } } } - if(maxspeed) { + if (maxspeed) { float speedsq= dvz[0]*dvz[0] + dvz[1]*dvz[1]; - if(speedsq > maxspeedsq) { + if (speedsq > maxspeedsq) { speedsq= (float)maxspeed/sqrt(speedsq); dvz[0]*= speedsq; dvz[1]*= speedsq; @@ -3012,7 +3019,7 @@ void RE_zbuf_accumulate_vecblur(NodeBlurData *nbd, int xsize, int ysize, float * /* set border speeds to keep border speeds on border */ dz1= rectvz; dz2= rectvz+4*(ysize)*(xsize+1); - for(x=0; x<=xsize; x++, dz1+=4, dz2+=4) { + for (x=0; x<=xsize; x++, dz1+=4, dz2+=4) { dz1[1]= 0.0f; dz2[1]= 0.0f; dz1[3]= 0.0f; @@ -3020,7 +3027,7 @@ void RE_zbuf_accumulate_vecblur(NodeBlurData *nbd, int xsize, int ysize, float * } dz1= rectvz; dz2= rectvz+4*(xsize); - for(y=0; y<=ysize; y++, dz1+=4*(xsize+1), dz2+=4*(xsize+1)) { + for (y=0; y<=ysize; y++, dz1+=4*(xsize+1), dz2+=4*(xsize+1)) { dz1[0]= 0.0f; dz2[0]= 0.0f; dz1[2]= 0.0f; @@ -3030,15 +3037,15 @@ void RE_zbuf_accumulate_vecblur(NodeBlurData *nbd, int xsize, int ysize, float * /* tag moving pixels, only these faces we draw */ dm= rectmove; dvec1= vecbufrect; - for(x=xsize*ysize; x>0; x--, dm++, dvec1+=4) { - if((dvec1[0]!=0.0f || dvec1[1]!=0.0f || dvec1[2]!=0.0f || dvec1[3]!=0.0f)) + for (x=xsize*ysize; x>0; x--, dm++, dvec1+=4) { + if ((dvec1[0]!=0.0f || dvec1[1]!=0.0f || dvec1[2]!=0.0f || dvec1[3]!=0.0f)) *dm= 255; } antialias_tagbuf(xsize, ysize, rectmove); /* has to become static, the init-jit calls a random-seed, screwing up texture noise node */ - if(firsttime) { + if (firsttime) { firsttime= 0; BLI_initjit(jit[0], 256); } @@ -3047,26 +3054,26 @@ void RE_zbuf_accumulate_vecblur(NodeBlurData *nbd, int xsize, int ysize, float * /* accumulate */ samples/= 2; - for(step= 1; step<=samples; step++) { + for (step= 1; step<=samples; step++) { float speedfac= 0.5f*nbd->fac*(float)step/(float)(samples+1); int side; - for(side=0; side<2; side++) { + for (side=0; side<2; side++) { float blendfac, ipodata[4]; /* clear zbuf, if we draw future we fill in not moving pixels */ - if(0) - for(x= xsize*ysize-1; x>=0; x--) rectz[x]= 10e16; + if (0) + for (x= xsize*ysize-1; x>=0; x--) rectz[x]= 10e16; else - for(x= xsize*ysize-1; x>=0; x--) { - if(rectmove[x]==0) + for (x= xsize*ysize-1; x>=0; x--) { + if (rectmove[x]==0) rectz[x]= zbufrect[x]; else rectz[x]= 10e16; } /* clear drawing buffer */ - for(x= xsize*ysize-1; x>=0; x--) rectdraw[x].colpoin= NULL; + for (x= xsize*ysize-1; x>=0; x--) rectdraw[x].colpoin= NULL; dimg= imgrect; dm= rectmove; @@ -3074,8 +3081,8 @@ void RE_zbuf_accumulate_vecblur(NodeBlurData *nbd, int xsize, int ysize, float * dz1= rectvz; dz2= rectvz + 4*(xsize + 1); - if(side) { - if(nbd->curved==0) { + if (side) { + if (nbd->curved==0) { dz1+= 2; dz2+= 2; } @@ -3084,15 +3091,15 @@ void RE_zbuf_accumulate_vecblur(NodeBlurData *nbd, int xsize, int ysize, float * set_quad_bezier_ipo(0.5f + 0.5f*speedfac, ipodata); - for(fy= -0.5f+jit[step & 255][0], y=0; y<ysize; y++, fy+=1.0f) { - for(fx= -0.5f+jit[step & 255][1], x=0; x<xsize; x++, fx+=1.0f, dimg+=4, dz1+=4, dz2+=4, dm++, dz++) { - if(*dm>1) { + for (fy= -0.5f+jit[step & 255][0], y=0; y<ysize; y++, fy+=1.0f) { + for (fx= -0.5f+jit[step & 255][1], x=0; x<xsize; x++, fx+=1.0f, dimg+=4, dz1+=4, dz2+=4, dm++, dz++) { + if (*dm>1) { float jfx = fx + 0.5f; float jfy = fy + 0.5f; DrawBufPixel col; /* make vertices */ - if(nbd->curved) { /* curved */ + if (nbd->curved) { /* curved */ quad_bezier_2d(v1, dz1, dz1+2, ipodata); v1[0]+= jfx; v1[1]+= jfy; v1[2]= *dz; @@ -3111,8 +3118,8 @@ void RE_zbuf_accumulate_vecblur(NodeBlurData *nbd, int xsize, int ysize, float * v3[0]= speedfac*dz2[4]+jfx+1.0f; v3[1]= speedfac*dz2[5]+jfy+1.0f; v3[2]= *dz; v4[0]= speedfac*dz2[0]+jfx; v4[1]= speedfac*dz2[1]+jfy+1.0f; v4[2]= *dz; } - if(*dm==255) col.alpha= 1.0f; - else if(*dm<2) col.alpha= 0.0f; + if (*dm==255) col.alpha= 1.0f; + else if (*dm<2) col.alpha= 0.0f; else col.alpha= ((float)*dm)/255.0f; col.colpoin= dimg; @@ -3137,8 +3144,8 @@ void RE_zbuf_accumulate_vecblur(NodeBlurData *nbd, int xsize, int ysize, float * /* accum */ rw= rectweight; rm= rectmax; - for(dr= rectdraw, dz2=newrect, x= xsize*ysize-1; x>=0; x--, dr++, dz2+=4, rw++, rm++) { - if(dr->colpoin) { + for (dr= rectdraw, dz2=newrect, x= xsize*ysize-1; x>=0; x--, dr++, dz2+=4, rw++, rm++) { + if (dr->colpoin) { float bfac= dr->alpha*blendfac; dz2[0] += bfac*dr->colpoin[0]; @@ -3158,7 +3165,7 @@ void RE_zbuf_accumulate_vecblur(NodeBlurData *nbd, int xsize, int ysize, float * rm= rectmax; ro= imgrect; dm= rectmove; - for(dz2=newrect, x= xsize*ysize-1; x>=0; x--, dz2+=4, ro+=4, rw++, rm++, dm++) { + for (dz2=newrect, x= xsize*ysize-1; x>=0; x--, dz2+=4, ro+=4, rw++, rm++, dm++) { float mfac = *rm; float fac = (*rw == 0.0f)? 0.0f: mfac/(*rw); float nfac = 1.0f - mfac; @@ -3175,7 +3182,7 @@ void RE_zbuf_accumulate_vecblur(NodeBlurData *nbd, int xsize, int ysize, float * MEM_freeN(rectvz); MEM_freeN(rectweight); MEM_freeN(rectmax); - if(minvecbufrect) MEM_freeN(vecbufrect); /* rects were swapped! */ + if (minvecbufrect) MEM_freeN(vecbufrect); /* rects were swapped! */ zbuf_free_span(&zspan); } @@ -3191,18 +3198,18 @@ static void copyto_abufz(RenderPart *pa, int *arectz, int *rectmask, int sample) int x, y, *rza, *rma; intptr_t *rd; - if(R.osa==0) { - if(!pa->rectz) + if (R.osa==0) { + if (!pa->rectz) fillrect(arectz, pa->rectx, pa->recty, 0x7FFFFFFE); else memcpy(arectz, pa->rectz, sizeof(int)*pa->rectx*pa->recty); - if(rectmask && pa->rectmask) + if (rectmask && pa->rectmask) memcpy(rectmask, pa->rectmask, sizeof(int)*pa->rectx*pa->recty); return; } - else if(!pa->rectdaps) { + else if (!pa->rectdaps) { fillrect(arectz, pa->rectx, pa->recty, 0x7FFFFFFE); return; } @@ -3213,17 +3220,17 @@ static void copyto_abufz(RenderPart *pa, int *arectz, int *rectmask, int sample) sample= (1<<sample); - for(y=0; y<pa->recty; y++) { - for(x=0; x<pa->rectx; x++) { + for (y=0; y<pa->recty; y++) { + for (x=0; x<pa->rectx; x++) { *rza= 0x7FFFFFFF; - if(rectmask) *rma= 0x7FFFFFFF; - if(*rd) { + if (rectmask) *rma= 0x7FFFFFFF; + if (*rd) { /* when there's a sky pixstruct, fill in sky-Z, otherwise solid Z */ - for(ps= (PixStr *)(*rd); ps; ps= ps->next) { - if(sample & ps->mask) { + for (ps= (PixStr *)(*rd); ps; ps= ps->next) { + if (sample & ps->mask) { *rza= ps->z; - if(rectmask) *rma= ps->maskz; + if (rectmask) *rma= ps->maskz; break; } } @@ -3257,7 +3264,7 @@ static int zbuffer_abuf(Render *re, RenderPart *pa, APixstr *APixbuf, ListBase * zbuffer_part_bounds(winx, winy, pa, bounds); - for(zsample=0; zsample<samples; zsample++) { + for (zsample=0; zsample<samples; zsample++) { zspan= &zspans[zsample]; zbuf_alloc_span(zspan, pa->rectx, pa->recty, re->clipcrop); @@ -3271,7 +3278,7 @@ static int zbuffer_abuf(Render *re, RenderPart *pa, APixstr *APixbuf, ListBase * zspan->apixbuf= APixbuf; zspan->apsmbase= apsmbase; - if(negzmask) + if (negzmask) zspan->rectmask= MEM_mallocN(sizeof(int)*pa->rectx*pa->recty, "Arectmask"); /* filling methods */ @@ -3281,7 +3288,7 @@ static int zbuffer_abuf(Render *re, RenderPart *pa, APixstr *APixbuf, ListBase * copyto_abufz(pa, zspan->arectz, zspan->rectmask, zsample); /* init zbuffer */ zspan->mask= 1<<zsample; - if(jit) { + if (jit) { zspan->zofsx= -pa->disprect.xmin - jit[zsample][0]; zspan->zofsy= -pa->disprect.ymin - jit[zsample][1]; } @@ -3298,37 +3305,37 @@ static int zbuffer_abuf(Render *re, RenderPart *pa, APixstr *APixbuf, ListBase * /* we use this to test if nothing was filled in */ zvlnr= 0; - for(i=0, obi=re->instancetable.first; obi; i++, obi=obi->next) { + for (i=0, obi=re->instancetable.first; obi; i++, obi=obi->next) { obr= obi->obr; - if(!(obi->lay & lay)) + if (!(obi->lay & lay)) continue; - if(obi->flag & R_TRANSFORMED) + if (obi->flag & R_TRANSFORMED) mult_m4_m4m4(obwinmat, winmat, obi->mat); else copy_m4_m4(obwinmat, winmat); - if(clip_render_object(obi->obr->boundbox, bounds, obwinmat)) + if (clip_render_object(obi->obr->boundbox, bounds, obwinmat)) continue; zbuf_project_cache_clear(cache, obr->totvert); - for(v=0; v<obr->totvlak; v++) { - if((v & 255)==0) + for (v=0; v<obr->totvlak; v++) { + if ((v & 255)==0) vlr= obr->vlaknodes[v>>8].vlak; else vlr++; - if(vlr->mat!=ma) { + if (vlr->mat!=ma) { ma= vlr->mat; - if(shadow) + if (shadow) dofill= (ma->mode & MA_SHADBUF); else dofill= (((ma->mode & MA_TRANSP) && (ma->mode & MA_ZTRANSP)) && !(ma->mode & MA_ONLYCAST)); } - if(dofill) { - if(!(vlr->flag & R_HIDDEN) && (obi->lay & lay)) { + if (dofill) { + if (!(vlr->flag & R_HIDDEN) && (obi->lay & lay)) { unsigned short partclip; v1= vlr->v1; @@ -3342,14 +3349,14 @@ static int zbuffer_abuf(Render *re, RenderPart *pa, APixstr *APixbuf, ListBase * /* partclipping doesn't need viewplane clipping */ partclip= c1 & c2 & c3; - if(v4) { + if (v4) { c4= zbuf_part_project(cache, v4->index, obwinmat, bounds, v4->co, ho4); partclip &= c4; } - if(partclip==0) { + if (partclip==0) { /* a little advantage for transp rendering (a z offset) */ - if(!shadow && ma->zoffs != 0.0f) { + if (!shadow && ma->zoffs != 0.0f) { mul= 0x7FFFFFFF; zval= mul*(1.0f+ho1[2]/ho1[3]); @@ -3368,45 +3375,45 @@ static int zbuffer_abuf(Render *re, RenderPart *pa, APixstr *APixbuf, ListBase * c1= testclip(ho1); c2= testclip(ho2); c3= testclip(ho3); - if(v4) + if (v4) c4= testclip(ho4); - for(zsample=0; zsample<samples; zsample++) { + for (zsample=0; zsample<samples; zsample++) { zspan= &zspans[zsample]; zspan->polygon_offset= polygon_offset; - if(ma->material_type == MA_TYPE_WIRE) { - if(v4) + if (ma->material_type == MA_TYPE_WIRE) { + if (v4) zbufclipwire(zspan, i, zvlnr, vlr->ec, ho1, ho2, ho3, ho4, c1, c2, c3, c4); else zbufclipwire(zspan, i, zvlnr, vlr->ec, ho1, ho2, ho3, 0, c1, c2, c3, 0); } else { - if(v4 && (vlr->flag & R_STRAND)) { + if (v4 && (vlr->flag & R_STRAND)) { zbufclip4(zspan, i, zvlnr, ho1, ho2, ho3, ho4, c1, c2, c3, c4); } else { zbufclip(zspan, i, zvlnr, ho1, ho2, ho3, c1, c2, c3); - if(v4) + if (v4) zbufclip(zspan, i, zvlnr+RE_QUAD_OFFS, ho1, ho3, ho4, c1, c3, c4); } } } } - if((v & 255)==255) - if(re->test_break(re->tbh)) + if ((v & 255)==255) + if (re->test_break(re->tbh)) break; } } } - if(re->test_break(re->tbh)) break; + if (re->test_break(re->tbh)) break; } - for(zsample=0; zsample<samples; zsample++) { + for (zsample=0; zsample<samples; zsample++) { zspan= &zspans[zsample]; MEM_freeN(zspan->arectz); - if(zspan->rectmask) + if (zspan->rectmask) MEM_freeN(zspan->rectmask); zbuf_free_span(zspan); } @@ -3422,18 +3429,18 @@ static int zbuffer_abuf_render(RenderPart *pa, APixstr *APixbuf, APixstrand *APi samples= (R.osa)? R.osa: 1; negzmask= ((rl->layflag & SCE_LAY_ZMASK) && (rl->layflag & SCE_LAY_NEG_ZMASK)); - if(R.osa) + if (R.osa) jit= R.jit; - else if(R.i.curblur) + else if (R.i.curblur) jit= &R.mblur_jit[R.i.curblur-1]; else jit= NULL; zbuf_make_winmat(&R, winmat); - if(rl->layflag & SCE_LAY_ZTRA) + if (rl->layflag & SCE_LAY_ZTRA) doztra+= zbuffer_abuf(&R, pa, APixbuf, apsmbase, rl->lay, negzmask, winmat, R.winx, R.winy, samples, jit, R.clipcrop, 0); - if((rl->layflag & SCE_LAY_STRAND) && APixbufstrand) + if ((rl->layflag & SCE_LAY_STRAND) && APixbufstrand) doztra+= zbuffer_strands_abuf(&R, pa, APixbufstrand, apsmbase, rl->lay, negzmask, winmat, R.winx, R.winy, samples, jit, R.clipcrop, 0, sscache); return doztra; @@ -3444,7 +3451,7 @@ void zbuffer_abuf_shadow(Render *re, LampRen *lar, float winmat[][4], APixstr *A RenderPart pa; int lay= -1; - if(lar->mode & LA_LAYER) lay= lar->lay; + if (lar->mode & LA_LAYER) lay= lar->lay; memset(&pa, 0, sizeof(RenderPart)); pa.rectx= size; @@ -3455,7 +3462,7 @@ void zbuffer_abuf_shadow(Render *re, LampRen *lar, float winmat[][4], APixstr *A pa.disprect.ymax = size; zbuffer_abuf(re, &pa, APixbuf, apsmbase, lay, 0, winmat, size, size, samples, jit, 1.0f, 1); - if(APixbufstrand) + if (APixbufstrand) zbuffer_strands_abuf(re, &pa, APixbufstrand, apsmbase, lay, 0, winmat, size, size, samples, jit, 1.0f, 1, NULL); } @@ -3467,27 +3474,27 @@ void add_transp_speed(RenderLayer *rl, int offset, float *speed, float alpha, in { RenderPass *rpass; - for(rpass= rl->passes.first; rpass; rpass= rpass->next) { - if(rpass->passtype==SCE_PASS_VECTOR) { + for (rpass= rl->passes.first; rpass; rpass= rpass->next) { + if (rpass->passtype==SCE_PASS_VECTOR) { float *fp= rpass->rect + 4*offset; - if(speed==NULL) { + if (speed==NULL) { /* clear */ - if(fp[0]==PASS_VECTOR_MAX) fp[0]= 0.0f; - if(fp[1]==PASS_VECTOR_MAX) fp[1]= 0.0f; - if(fp[2]==PASS_VECTOR_MAX) fp[2]= 0.0f; - if(fp[3]==PASS_VECTOR_MAX) fp[3]= 0.0f; + if (fp[0]==PASS_VECTOR_MAX) fp[0]= 0.0f; + if (fp[1]==PASS_VECTOR_MAX) fp[1]= 0.0f; + if (fp[2]==PASS_VECTOR_MAX) fp[2]= 0.0f; + if (fp[3]==PASS_VECTOR_MAX) fp[3]= 0.0f; } - else if(rdrect==NULL || rdrect[offset]==0 || alpha>0.95f) { + else if (rdrect==NULL || rdrect[offset]==0 || alpha>0.95f) { copy_v4_v4(fp, speed); } else { /* add minimum speed in pixel */ - if( (ABS(speed[0]) + ABS(speed[1]))< (ABS(fp[0]) + ABS(fp[1])) ) { + if ( (ABS(speed[0]) + ABS(speed[1]))< (ABS(fp[0]) + ABS(fp[1])) ) { fp[0]= speed[0]; fp[1]= speed[1]; } - if( (ABS(speed[2]) + ABS(speed[3]))< (ABS(fp[2]) + ABS(fp[3])) ) { + if ( (ABS(speed[2]) + ABS(speed[3]))< (ABS(fp[2]) + ABS(fp[3])) ) { fp[2]= speed[2]; fp[3]= speed[3]; } @@ -3501,8 +3508,8 @@ static void add_transp_obindex(RenderLayer *rl, int offset, Object *ob) { RenderPass *rpass; - for(rpass= rl->passes.first; rpass; rpass= rpass->next) { - if(rpass->passtype == SCE_PASS_INDEXOB||rpass->passtype == SCE_PASS_INDEXMA) { + for (rpass= rl->passes.first; rpass; rpass= rpass->next) { + if (rpass->passtype == SCE_PASS_INDEXOB||rpass->passtype == SCE_PASS_INDEXMA) { float *fp= rpass->rect + offset; *fp= (float)ob->index; break; @@ -3518,7 +3525,7 @@ void merge_transp_passes(RenderLayer *rl, ShadeResult *shr) float weight= 1.0f/((float)R.osa); int delta= sizeof(ShadeResult)/4; - for(rpass= rl->passes.first; rpass; rpass= rpass->next) { + for (rpass= rl->passes.first; rpass; rpass= rpass->next) { float *col= NULL; int pixsize= 3; @@ -3573,16 +3580,16 @@ void merge_transp_passes(RenderLayer *rl, ShadeResult *shr) int samp; /* add minimum speed in pixel */ - for(samp= 1; samp<R.osa; samp++, shr_t++) { + for (samp= 1; samp<R.osa; samp++, shr_t++) { - if(shr_t->combined[3] > 0.0f) { + if (shr_t->combined[3] > 0.0f) { float *speed= shr_t->winspeed; - if( (ABS(speed[0]) + ABS(speed[1]))< (ABS(fp[0]) + ABS(fp[1])) ) { + if ( (ABS(speed[0]) + ABS(speed[1]))< (ABS(fp[0]) + ABS(fp[1])) ) { fp[0]= speed[0]; fp[1]= speed[1]; } - if( (ABS(speed[2]) + ABS(speed[3]))< (ABS(fp[2]) + ABS(fp[3])) ) { + if ( (ABS(speed[2]) + ABS(speed[3]))< (ABS(fp[2]) + ABS(fp[3])) ) { fp[2]= speed[2]; fp[3]= speed[3]; } @@ -3591,23 +3598,23 @@ void merge_transp_passes(RenderLayer *rl, ShadeResult *shr) } break; } - if(col) { + if (col) { float *fp= col+delta; int samp; - for(samp= 1; samp<R.osa; samp++, fp+=delta) { + for (samp= 1; samp<R.osa; samp++, fp+=delta) { col[0]+= fp[0]; - if(pixsize>1) { + if (pixsize>1) { col[1]+= fp[1]; col[2]+= fp[2]; - if(pixsize==4) col[3]+= fp[3]; + if (pixsize==4) col[3]+= fp[3]; } } col[0]*= weight; - if(pixsize>1) { + if (pixsize>1) { col[1]*= weight; col[2]*= weight; - if(pixsize==4) col[3]*= weight; + if (pixsize==4) col[3]*= weight; } } } @@ -3618,14 +3625,14 @@ void add_transp_passes(RenderLayer *rl, int offset, ShadeResult *shr, float alph { RenderPass *rpass; - for(rpass= rl->passes.first; rpass; rpass= rpass->next) { + for (rpass= rl->passes.first; rpass; rpass= rpass->next) { float *fp, *col= NULL; int pixsize= 3; switch(rpass->passtype) { case SCE_PASS_Z: fp= rpass->rect + offset; - if(shr->z < *fp) + if (shr->z < *fp) *fp= shr->z; break; case SCE_PASS_RGBA: @@ -3667,11 +3674,11 @@ void add_transp_passes(RenderLayer *rl, int offset, ShadeResult *shr, float alph pixsize= 1; break; } - if(col) { + if (col) { fp= rpass->rect + pixsize*offset; fp[0]= col[0] + (1.0f-alpha)*fp[0]; - if(pixsize==3) { + if (pixsize==3) { fp[1]= col[1] + (1.0f-alpha)*fp[1]; fp[2]= col[2] + (1.0f-alpha)*fp[2]; } @@ -3692,8 +3699,8 @@ static int vergzvlak(const void *a1, const void *a2) { const ZTranspRow *r1 = a1, *r2 = a2; - if(r1->z < r2->z) return 1; - else if(r1->z > r2->z) return -1; + if (r1->z < r2->z) return 1; + else if (r1->z > r2->z) return -1; return 0; } @@ -3732,10 +3739,10 @@ static void unref_strand_samples(StrandShadeCache *cache, ZTranspRow *row, int t /* remove references to samples that are not being rendered, but we still * need to remove them so that the reference count of strand vertex shade * samples correctly drops to zero */ - while(totface > 0) { + while (totface > 0) { totface--; - if(row[totface].segment != -1) { + if (row[totface].segment != -1) { obi= R.objectinstance + row[totface].obi; obr= obi->obr; strand= RE_findOrAddStrand(obr, row[totface].p-1); @@ -3757,18 +3764,18 @@ static void shade_tra_samples_fill(ShadeSample *ssamp, int x, int y, int z, int shade_input_set_triangle(shi, obi, facenr, 1); /* officially should always be true... we have no sky info */ - if(shi->vlr) { + if (shi->vlr) { /* full osa is only set for OSA renders */ - if(shi->vlr->flag & R_FULL_OSA) { + if (shi->vlr->flag & R_FULL_OSA) { short shi_inc= 0, samp; - for(samp=0; samp<R.osa; samp++) { - if(curmask & (1<<samp)) { + for (samp=0; samp<R.osa; samp++) { + if (curmask & (1<<samp)) { xs= (float)x + R.jit[samp][0] + 0.5f; /* zbuffer has this inverse corrected, ensures xs,ys are inside pixel */ ys= (float)y + R.jit[samp][1] + 0.5f; - if(shi_inc) { + if (shi_inc) { shade_input_copy_triangle(shi+1, shi); shi++; } @@ -3776,7 +3783,7 @@ static void shade_tra_samples_fill(ShadeSample *ssamp, int x, int y, int z, int shi->samplenr= R.shadowsamplenr[shi->thread]++; shade_input_set_viewco(shi, x, y, xs, ys, (float)z); shade_input_set_uv(shi); - if(shi_inc==0) + if (shi_inc==0) shade_input_set_normals(shi); else /* XXX shi->flippednor messes up otherwise */ shade_input_set_vertex_normals(shi); @@ -3786,7 +3793,7 @@ static void shade_tra_samples_fill(ShadeSample *ssamp, int x, int y, int z, int } } else { - if(R.osa) { + if (R.osa) { short b= R.samples->centmask[curmask]; xs= (float)x + R.samples->centLut[b & 15] + 0.5f; ys= (float)y + R.samples->centLut[b>>4] + 0.5f; @@ -3809,14 +3816,14 @@ static void shade_tra_samples_fill(ShadeSample *ssamp, int x, int y, int z, int static int shade_tra_samples(ShadeSample *ssamp, StrandShadeCache *cache, int x, int y, ZTranspRow *row, int addpassflag) { - if(row->segment != -1) { + if (row->segment != -1) { shade_strand_samples(cache, ssamp, x, y, row, addpassflag); return 1; } shade_tra_samples_fill(ssamp, x, y, row->z, row->obi, row->p, row->mask); - if(ssamp->tot) { + if (ssamp->tot) { ShadeInput *shi= ssamp->shi; ShadeResult *shr= ssamp->shr; int samp; @@ -3825,19 +3832,19 @@ static int shade_tra_samples(ShadeSample *ssamp, StrandShadeCache *cache, int x, shade_samples_do_AO(ssamp); /* if shade (all shadepinputs have same passflag) */ - if(shi->passflag & ~(SCE_PASS_Z|SCE_PASS_INDEXOB|SCE_PASS_INDEXMA)) { - for(samp=0; samp<ssamp->tot; samp++, shi++, shr++) { + if (shi->passflag & ~(SCE_PASS_Z|SCE_PASS_INDEXOB|SCE_PASS_INDEXMA)) { + for (samp=0; samp<ssamp->tot; samp++, shi++, shr++) { shade_input_set_shade_texco(shi); shade_input_do_shade(shi, shr); /* include lamphalos for ztra, since halo layer was added already */ - if(R.flag & R_LAMPHALO) - if(shi->layflag & SCE_LAY_HALO) + if (R.flag & R_LAMPHALO) + if (shi->layflag & SCE_LAY_HALO) renderspothalo(shi, shr->combined, shr->combined[3]); } } - else if(shi->passflag & SCE_PASS_Z) { - for(samp=0; samp<ssamp->tot; samp++, shi++, shr++) + else if (shi->passflag & SCE_PASS_Z) { + for (samp=0; samp<ssamp->tot; samp++, shi++, shr++) shr->z= -shi->co[2]; } @@ -3857,66 +3864,66 @@ static int addtosamp_shr(ShadeResult *samp_shr, ShadeSample *ssamp, int addpassf { int a, sample, osa = (R.osa? R.osa: 1), retval = osa; - for(a=0; a < osa; a++, samp_shr++) { + for (a=0; a < osa; a++, samp_shr++) { ShadeInput *shi= ssamp->shi; ShadeResult *shr= ssamp->shr; - for(sample=0; sample<ssamp->tot; sample++, shi++, shr++) { + for (sample=0; sample<ssamp->tot; sample++, shi++, shr++) { - if(shi->mask & (1<<a)) { + if (shi->mask & (1<<a)) { float fac= (1.0f - samp_shr->combined[3])*shr->combined[3]; addAlphaUnderFloat(samp_shr->combined, shr->combined); samp_shr->z= MIN2(samp_shr->z, shr->z); - if(addpassflag & SCE_PASS_VECTOR) { + if (addpassflag & SCE_PASS_VECTOR) { copy_v4_v4(samp_shr->winspeed, shr->winspeed); } /* optim... */ - if(addpassflag & ~(SCE_PASS_VECTOR)) { + if (addpassflag & ~(SCE_PASS_VECTOR)) { - if(addpassflag & SCE_PASS_RGBA) + if (addpassflag & SCE_PASS_RGBA) addAlphaUnderFloat(samp_shr->col, shr->col); - if(addpassflag & SCE_PASS_NORMAL) + if (addpassflag & SCE_PASS_NORMAL) addvecmul(samp_shr->nor, shr->nor, fac); - if(addpassflag & SCE_PASS_EMIT) + if (addpassflag & SCE_PASS_EMIT) addvecmul(samp_shr->emit, shr->emit, fac); - if(addpassflag & SCE_PASS_DIFFUSE) + if (addpassflag & SCE_PASS_DIFFUSE) addvecmul(samp_shr->diff, shr->diff, fac); - if(addpassflag & SCE_PASS_SPEC) + if (addpassflag & SCE_PASS_SPEC) addvecmul(samp_shr->spec, shr->spec, fac); - if(addpassflag & SCE_PASS_SHADOW) + if (addpassflag & SCE_PASS_SHADOW) addvecmul(samp_shr->shad, shr->shad, fac); - if(addpassflag & SCE_PASS_AO) + if (addpassflag & SCE_PASS_AO) addvecmul(samp_shr->ao, shr->ao, fac); - if(addpassflag & SCE_PASS_ENVIRONMENT) + if (addpassflag & SCE_PASS_ENVIRONMENT) addvecmul(samp_shr->env, shr->env, fac); - if(addpassflag & SCE_PASS_INDIRECT) + if (addpassflag & SCE_PASS_INDIRECT) addvecmul(samp_shr->indirect, shr->indirect, fac); - if(addpassflag & SCE_PASS_REFLECT) + if (addpassflag & SCE_PASS_REFLECT) addvecmul(samp_shr->refl, shr->refl, fac); - if(addpassflag & SCE_PASS_REFRACT) + if (addpassflag & SCE_PASS_REFRACT) addvecmul(samp_shr->refr, shr->refr, fac); - if(addpassflag & SCE_PASS_MIST) + if (addpassflag & SCE_PASS_MIST) samp_shr->mist= samp_shr->mist+fac*shr->mist; } } } - if(samp_shr->combined[3]>0.999f) retval--; + if (samp_shr->combined[3]>0.999f) retval--; } return retval; } @@ -3929,11 +3936,11 @@ static void reset_sky_speedvectors(RenderPart *pa, RenderLayer *rl, float *rectf int a; fp= RE_RenderLayerGetPass(rl, SCE_PASS_VECTOR); - if(fp==NULL) return; + if (fp==NULL) return; col= rectf+3; - for(a= 4*pa->rectx*pa->recty -4; a>=0; a-=4) { - if(col[a]==0.0f) { + for (a= 4*pa->rectx*pa->recty -4; a>=0; a-=4) { + if (col[a]==0.0f) { fp[a]= PASS_VECTOR_MAX; fp[a+1]= PASS_VECTOR_MAX; fp[a+2]= PASS_VECTOR_MAX; @@ -3966,17 +3973,17 @@ unsigned short *zbuffer_transp_shade(RenderPart *pa, RenderLayer *rl, float *pas unsigned short *ztramask= NULL, filled; /* looks nicer for calling code */ - if(R.test_break(R.tbh)) + if (R.test_break(R.tbh)) return NULL; - if(R.osa>16) { /* MAX_OSA */ + if (R.osa>16) { /* MAX_OSA */ printf("zbuffer_transp_shade: osa too large\n"); G.afbreek= 1; return NULL; } APixbuf= MEM_callocN(pa->rectx*pa->recty*sizeof(APixstr), "APixbuf"); - if(R.totstrand && (rl->layflag & SCE_LAY_STRAND)) { + if (R.totstrand && (rl->layflag & SCE_LAY_STRAND)) { APixbufstrand= MEM_callocN(pa->rectx*pa->recty*sizeof(APixstrand), "APixbufstrand"); sscache= strand_shade_cache_create(); } @@ -3985,7 +3992,7 @@ unsigned short *zbuffer_transp_shade(RenderPart *pa, RenderLayer *rl, float *pas shade_sample_initialize(&ssamp, pa, rl); addpassflag= rl->passflag & ~(SCE_PASS_COMBINED); - if(R.osa) + if (R.osa) sampalpha= 1.0f/(float)R.osa; else sampalpha= 1.0f; @@ -3993,12 +4000,12 @@ unsigned short *zbuffer_transp_shade(RenderPart *pa, RenderLayer *rl, float *pas /* fill the Apixbuf */ doztra= zbuffer_abuf_render(pa, APixbuf, APixbufstrand, &apsmbase, rl, sscache); - if(doztra == 0) { + if (doztra == 0) { /* nothing filled in */ MEM_freeN(APixbuf); - if(APixbufstrand) + if (APixbufstrand) MEM_freeN(APixbufstrand); - if(sscache) + if (sscache) strand_shade_cache_free(sscache); freepsA(&apsmbase); return NULL; @@ -4012,20 +4019,20 @@ unsigned short *zbuffer_transp_shade(RenderPart *pa, RenderLayer *rl, float *pas totfullsample= get_sample_layers(pa, rl, rlpp); /* irregular shadowb buffer creation */ - if(R.r.mode & R_SHADOW) + if (R.r.mode & R_SHADOW) ISB_create(pa, APixbuf); /* masks, to have correct alpha combine */ - if(R.osa && (rl->layflag & SCE_LAY_SOLID) && pa->fullresult.first==NULL) + if (R.osa && (rl->layflag & SCE_LAY_SOLID) && pa->fullresult.first==NULL) ztramask= MEM_callocN(pa->rectx*pa->recty*sizeof(short), "ztramask"); /* zero alpha pixels get speed vector max again */ - if(addpassflag & SCE_PASS_VECTOR) - if(rl->layflag & SCE_LAY_SOLID) + if (addpassflag & SCE_PASS_VECTOR) + if (rl->layflag & SCE_LAY_SOLID) reset_sky_speedvectors(pa, rl, rl->acolrect?rl->acolrect:rl->rectf); /* if acolrect is set we use it */ /* filtered render, for now we assume only 1 filter size */ - if(pa->crop) { + if (pa->crop) { crop= 1; offs= pa->rectx + 1; passrect+= 4*offs; @@ -4039,35 +4046,35 @@ unsigned short *zbuffer_transp_shade(RenderPart *pa, RenderLayer *rl, float *pas rr->renlay= rl; /* render the tile */ - for(y=pa->disprect.ymin+crop; y<pa->disprect.ymax-crop; y++, rr->renrect.ymax++) { + for (y=pa->disprect.ymin+crop; y<pa->disprect.ymax-crop; y++, rr->renrect.ymax++) { pass= passrect; ap= aprect; apstrand= aprectstrand; od= offs; - if(R.test_break(R.tbh)) + if (R.test_break(R.tbh)) break; - for(x=pa->disprect.xmin+crop; x<pa->disprect.xmax-crop; x++, ap++, apstrand++, pass+=4, od++) { + for (x=pa->disprect.xmin+crop; x<pa->disprect.xmax-crop; x++, ap++, apstrand++, pass+=4, od++) { - if(ap->p[0]==0 && (!APixbufstrand || apstrand->p[0]==0)) { - if(addpassflag & SCE_PASS_VECTOR) + if (ap->p[0]==0 && (!APixbufstrand || apstrand->p[0]==0)) { + if (addpassflag & SCE_PASS_VECTOR) add_transp_speed(rl, od, NULL, 0.0f, rdrect); } else { /* sort in z */ totface= 0; apn= ap; - while(apn) { - for(a=0; a<4; a++) { - if(apn->p[a]) { + while (apn) { + for (a=0; a<4; a++) { + if (apn->p[a]) { zrow[totface].obi= apn->obi[a]; zrow[totface].z= apn->z[a]; zrow[totface].p= apn->p[a]; zrow[totface].mask= apn->mask[a]; zrow[totface].segment= -1; totface++; - if(totface>=MAX_ZROW) totface= MAX_ZROW-1; + if (totface>=MAX_ZROW) totface= MAX_ZROW-1; } else break; } @@ -4075,19 +4082,19 @@ unsigned short *zbuffer_transp_shade(RenderPart *pa, RenderLayer *rl, float *pas } apnstrand= (APixbufstrand)? apstrand: NULL; - while(apnstrand) { - for(a=0; a<4; a++) { - if(apnstrand->p[a]) { + while (apnstrand) { + for (a=0; a<4; a++) { + if (apnstrand->p[a]) { zrow[totface].obi= apnstrand->obi[a]; zrow[totface].z= apnstrand->z[a]; zrow[totface].p= apnstrand->p[a]; zrow[totface].mask= apnstrand->mask[a]; zrow[totface].segment= apnstrand->seg[a]; - if(R.osa) { + if (R.osa) { totsample= 0; - for(b=0; b<R.osa; b++) - if(zrow[totface].mask & (1<<b)) + for (b=0; b<R.osa; b++) + if (zrow[totface].mask & (1<<b)) totsample++; } else @@ -4096,43 +4103,43 @@ unsigned short *zbuffer_transp_shade(RenderPart *pa, RenderLayer *rl, float *pas zrow[totface].u= apnstrand->u[a]/totsample; zrow[totface].v= apnstrand->v[a]/totsample; totface++; - if(totface>=MAX_ZROW) totface= MAX_ZROW-1; + if (totface>=MAX_ZROW) totface= MAX_ZROW-1; } } apnstrand= apnstrand->next; } - if(totface==2) { - if(zrow[0].z < zrow[1].z) { + if (totface==2) { + if (zrow[0].z < zrow[1].z) { SWAP(ZTranspRow, zrow[0], zrow[1]); } } - else if(totface>2) { + else if (totface>2) { qsort(zrow, totface, sizeof(ZTranspRow), vergzvlak); } /* front face does index pass for transparent, no AA or filters, but yes FSA */ - if(addpassflag & SCE_PASS_INDEXOB) { + if (addpassflag & SCE_PASS_INDEXOB) { ObjectRen *obr= R.objectinstance[zrow[totface-1].obi].obr; - if(obr->ob) { - for(a= 0; a<totfullsample; a++) + if (obr->ob) { + for (a= 0; a<totfullsample; a++) add_transp_obindex(rlpp[a], od, obr->ob); } } - if(addpassflag & SCE_PASS_INDEXMA) { + if (addpassflag & SCE_PASS_INDEXMA) { ObjectRen *obr= R.objectinstance[zrow[totface-1].obi].obr; - if(obr->ob) { - for(a= 0; a<totfullsample; a++) + if (obr->ob) { + for (a= 0; a<totfullsample; a++) add_transp_obindex(rlpp[a], od, obr->ob); } } /* for each mask-sample we alpha-under colors. then in end it's added using filter */ memset(samp_shr, 0, sizeof(ShadeResult)*osa); - for(a=0; a<osa; a++) { + for (a=0; a<osa; a++) { samp_shr[a].z= 10e10f; - if(addpassflag & SCE_PASS_VECTOR) { + if (addpassflag & SCE_PASS_VECTOR) { samp_shr[a].winspeed[0]= PASS_VECTOR_MAX; samp_shr[a].winspeed[1]= PASS_VECTOR_MAX; samp_shr[a].winspeed[2]= PASS_VECTOR_MAX; @@ -4140,16 +4147,16 @@ unsigned short *zbuffer_transp_shade(RenderPart *pa, RenderLayer *rl, float *pas } } - if(R.osa==0) { - while(totface>0) { + if (R.osa==0) { + while (totface>0) { totface--; - if(shade_tra_samples(&ssamp, sscache, x, y, &zrow[totface], addpassflag)) { + if (shade_tra_samples(&ssamp, sscache, x, y, &zrow[totface], addpassflag)) { filled= addtosamp_shr(samp_shr, &ssamp, addpassflag); addAlphaUnderFloat(pass, ssamp.shr[0].combined); - if(filled == 0) { - if(sscache) + if (filled == 0) { + if (sscache) unref_strand_samples(sscache, zrow, totface); break; } @@ -4157,25 +4164,25 @@ unsigned short *zbuffer_transp_shade(RenderPart *pa, RenderLayer *rl, float *pas } alpha= samp_shr->combined[3]; - if(alpha!=0.0f) { + if (alpha!=0.0f) { add_transp_passes(rl, od, samp_shr, alpha); - if(addpassflag & SCE_PASS_VECTOR) + if (addpassflag & SCE_PASS_VECTOR) add_transp_speed(rl, od, samp_shr->winspeed, alpha, rdrect); } } else { short *sp= (short *)(ztramask+od); - while(totface>0) { + while (totface>0) { totface--; - if(shade_tra_samples(&ssamp, sscache, x, y, &zrow[totface], addpassflag)) { + if (shade_tra_samples(&ssamp, sscache, x, y, &zrow[totface], addpassflag)) { filled= addtosamp_shr(samp_shr, &ssamp, addpassflag); - if(ztramask) + if (ztramask) *sp |= zrow[totface].mask; - if(filled==0) { - if(sscache) + if (filled==0) { + if (sscache) unref_strand_samples(sscache, zrow, totface); break; } @@ -4183,16 +4190,16 @@ unsigned short *zbuffer_transp_shade(RenderPart *pa, RenderLayer *rl, float *pas } /* multisample buffers or filtered mask filling? */ - if(pa->fullresult.first) { - for(a=0; a<R.osa; a++) { + if (pa->fullresult.first) { + for (a=0; a<R.osa; a++) { alpha= samp_shr[a].combined[3]; - if(alpha!=0.0f) { + if (alpha!=0.0f) { RenderLayer *rl= ssamp.rlpp[a]; addAlphaOverFloat(rl->rectf + 4*od, samp_shr[a].combined); add_transp_passes(rl, od, &samp_shr[a], alpha); - if(addpassflag & SCE_PASS_VECTOR) + if (addpassflag & SCE_PASS_VECTOR) add_transp_speed(rl, od, samp_shr[a].winspeed, alpha, rdrect); } } @@ -4201,19 +4208,19 @@ unsigned short *zbuffer_transp_shade(RenderPart *pa, RenderLayer *rl, float *pas alpha= 0.0f; /* note; cannot use pass[3] for alpha due to filtermask */ - for(a=0; a<R.osa; a++) { + for (a=0; a<R.osa; a++) { add_filt_fmask(1<<a, samp_shr[a].combined, pass, rr->rectx); alpha+= samp_shr[a].combined[3]; } - if(addpassflag) { + if (addpassflag) { alpha*= sampalpha; /* merge all in one, and then add */ merge_transp_passes(rl, samp_shr); add_transp_passes(rl, od, samp_shr, alpha); - if(addpassflag & SCE_PASS_VECTOR) + if (addpassflag & SCE_PASS_VECTOR) add_transp_speed(rl, od, samp_shr[0].winspeed, alpha, rdrect); } } @@ -4231,13 +4238,13 @@ unsigned short *zbuffer_transp_shade(RenderPart *pa, RenderLayer *rl, float *pas rr->renlay= NULL; MEM_freeN(APixbuf); - if(APixbufstrand) + if (APixbufstrand) MEM_freeN(APixbufstrand); - if(sscache) + if (sscache) strand_shade_cache_free(sscache); freepsA(&apsmbase); - if(R.r.mode & R_SHADOW) + if (R.r.mode & R_SHADOW) ISB_free(pa); return ztramask; |