diff options
Diffstat (limited to 'source/blender/render/intern')
17 files changed, 873 insertions, 859 deletions
diff --git a/source/blender/render/intern/source/convertblender.c b/source/blender/render/intern/source/convertblender.c index d21a22f553b..cb6a0fd1198 100644 --- a/source/blender/render/intern/source/convertblender.c +++ b/source/blender/render/intern/source/convertblender.c @@ -525,7 +525,7 @@ typedef struct { } SRenderMeshToTangent; -// interface +/* interface */ #include "mikktspace.h" static int GetNumFaces(const SMikkTSpaceContext * pContext) @@ -1029,7 +1029,7 @@ static void static_particle_strand(Render *re, ObjectRen *obr, Material *ma, Par static int second=0; sub_v3_v3v3(nor, vec, vec1); - normalize_v3(nor); // nor needed as tangent + normalize_v3(nor); /* nor needed as tangent */ cross_v3_v3v3(cross, vec, nor); /* turn cross in pixelsize */ @@ -1089,7 +1089,7 @@ static void static_particle_strand(Render *re, ObjectRen *obr, Material *ma, Par add_v3_v3(vlr->v1->co, cross); copy_v3_v3(vlr->v1->n, nor); vlr->v1->orco= sd->orco; - vlr->v1->accum= -1.0f; // accum abuse for strand texco + vlr->v1->accum = -1.0f; /* accum abuse for strand texco */ copy_v3_v3(vlr->v2->co, vec); sub_v3_v3v3(vlr->v2->co, vlr->v2->co, cross); @@ -1101,8 +1101,8 @@ static void static_particle_strand(Render *re, ObjectRen *obr, Material *ma, Par add_v3_v3(vlr->v4->co, cross); copy_v3_v3(vlr->v4->n, nor); vlr->v4->orco= sd->orco; - vlr->v4->accum= 1.0f; // accum abuse for strand texco - + vlr->v4->accum = 1.0f; /* accum abuse for strand texco */ + copy_v3_v3(vlr->v3->co, vec1); sub_v3_v3v3(vlr->v3->co, vlr->v3->co, cross); copy_v3_v3(vlr->v3->n, nor); @@ -1163,7 +1163,7 @@ static void static_particle_strand(Render *re, ObjectRen *obr, Material *ma, Par add_v3_v3(v1->co, cross); copy_v3_v3(v1->n, nor); v1->orco= sd->orco; - v1->accum= -1.0f; // accum abuse for strand texco + v1->accum = -1.0f; /* accum abuse for strand texco */ copy_v3_v3(v2->co, vec); sub_v3_v3v3(v2->co, v2->co, cross); @@ -1180,11 +1180,11 @@ static void static_particle_strand(Render *re, ObjectRen *obr, Material *ma, Par vlr->v2= v2; vlr->v3= RE_findOrAddVert(obr, obr->totvert++); vlr->v4= RE_findOrAddVert(obr, obr->totvert++); - - v1= vlr->v4; // cycle - v2= vlr->v3; // cycle - + v1= vlr->v4; /* cycle */ + v2= vlr->v3; /* cycle */ + + if (sd->adapt) { second=0; copy_v3_v3(anor, nor); @@ -1209,9 +1209,9 @@ static void static_particle_strand(Render *re, ObjectRen *obr, Material *ma, Par vlr->v2= v2; vlr->v3= RE_findOrAddVert(obr, obr->totvert++); vlr->v4= RE_findOrAddVert(obr, obr->totvert++); - - v1= vlr->v4; // cycle - v2= vlr->v3; // cycle + + v1= vlr->v4; /* cycle */ + v2= vlr->v3; /* cycle */ copy_v3_v3(anor, nor); copy_v3_v3(avec, vec); @@ -1225,8 +1225,8 @@ static void static_particle_strand(Render *re, ObjectRen *obr, Material *ma, Par add_v3_v3(vlr->v4->co, cross); copy_v3_v3(vlr->v4->n, nor); vlr->v4->orco= sd->orco; - vlr->v4->accum= -1.0f + 2.0f*sd->time; // accum abuse for strand texco - + vlr->v4->accum= -1.0f + 2.0f * sd->time; /* accum abuse for strand texco */ + copy_v3_v3(vlr->v3->co, vec); sub_v3_v3v3(vlr->v3->co, vlr->v3->co, cross); copy_v3_v3(vlr->v3->n, nor); @@ -1309,7 +1309,7 @@ static void static_particle_wire(ObjectRen *obr, Material *ma, const float vec[3 vlr->v3= vlr->v2; vlr->v4= NULL; - v1= vlr->v2; // cycle + v1= vlr->v2; /* cycle */ copy_v3_v3(v1->co, vec); sub_v3_v3v3(vlr->n, vec, vec1); @@ -1630,12 +1630,12 @@ static int render_new_particle_system(Render *re, ObjectRen *obr, ParticleSystem /* 2.1 setup material stff */ ma= give_render_material(re, ob, part->omat); -#if 0 // XXX old animation system +#if 0 /* XXX old animation system */ if (ma->ipo) { calc_ipo(ma->ipo, cfra); execute_ipo((ID *)ma, ma->ipo); } -#endif // XXX old animation system +#endif /* XXX old animation system */ hasize = ma->hasize; seed = ma->seed1; @@ -2087,10 +2087,10 @@ static int render_new_particle_system(Render *re, ObjectRen *obr, ParticleSystem strandbuf->surface= cache_strand_surface(re, obr, psmd->dm, mat, timeoffset); /* 4. clean up */ -#if 0 // XXX old animation system +#if 0 /* XXX old animation system */ if (ma) do_mat_ipo(re->scene, ma); -#endif // XXX old animation system - +#endif /* XXX old animation system */ + if (orco1) MEM_freeN(sd.orco); @@ -3267,7 +3267,7 @@ static void init_render_mesh(Render *re, ObjectRen *obr, int timeoffset) int a, a1, ok, vertofs; int end, do_autosmooth = FALSE, totvert = 0; int use_original_normals = FALSE; - int recalc_normals = 0; // false by default + int recalc_normals = 0; /* false by default */ int negative_scale; me= ob->data; @@ -3471,7 +3471,7 @@ static void init_render_mesh(Render *re, ObjectRen *obr, int timeoffset) int t; mtf= RE_vlakren_get_tface(obr, vlr, mtfn++, &name, 1); mtface= (MTFace*)layer->data; - *mtf= mtface[a]; // copy face info + *mtf = mtface[a]; /* copy face info */ for (vindex=0; vindex<nr_verts; vindex++) for (t=0; t<2; t++) mtf->uv[vindex][t]=mtface[a].uv[rev_tab[vindex]][t]; @@ -3733,7 +3733,7 @@ static GroupObject *add_render_lamp(Render *re, Object *ob) lar->shdwb= la->shdwb; lar->k= la->k; - // area + /* area */ lar->ray_samp= la->ray_samp; lar->ray_sampy= la->ray_sampy; lar->ray_sampz= la->ray_sampz; @@ -3784,7 +3784,7 @@ static GroupObject *add_render_lamp(Render *re, Object *ob) } area_lamp_vectors(lar); - init_jitter_plane(lar); // subsamples + init_jitter_plane(lar); /* subsamples */ } else if (lar->type==LA_SUN) { lar->ray_totsamp= lar->ray_samp*lar->ray_samp; @@ -3819,7 +3819,7 @@ static GroupObject *add_render_lamp(Render *re, Object *ob) memcpy(lar->mtex, la->mtex, MAX_MTEX*sizeof(void *)); - lar->lay= ob->lay & 0xFFFFFF; // higher 8 bits are localview layers + lar->lay = ob->lay & 0xFFFFFF; /* higher 8 bits are localview layers */ lar->falloff_type = la->falloff_type; lar->ld1= la->att1; @@ -3904,7 +3904,7 @@ static GroupObject *add_render_lamp(Render *re, Object *ob) /* Per lamp, one shadow buffer is made. */ lar->bufflag= la->bufflag; copy_m4_m4(mat, ob->obmat); - initshadowbuf(re, lar, mat); // mat is altered + initshadowbuf(re, lar, mat); /* mat is altered */ } @@ -4247,8 +4247,8 @@ static void check_non_flat_quads(ObjectRen *obr) 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; vlr1= RE_vlakren_copy(obr, vlr); @@ -5478,7 +5478,7 @@ static int load_fluidsimspeedvectors(Render *re, ObjectInstanceRen *obi, float * else ver++; - // get fluid velocity + /* get fluid velocity */ fsvec[3] = 0.0f; //fsvec[0] = fsvec[1] = fsvec[2] = fsvec[3] = 0.0; fsvec[2] = 2.0f; // NT fixed test for (j=0;j<3;j++) fsvec[j] = velarray[a].vel[j]; @@ -5490,31 +5490,31 @@ static int load_fluidsimspeedvectors(Render *re, ObjectInstanceRen *obi, float * fsvec[2] = avgvel[2]; } - // transform (=rotate) to cam space + /* transform (=rotate) to cam space */ camco[0] = dot_v3v3(imat[0], fsvec); camco[1] = dot_v3v3(imat[1], fsvec); camco[2] = dot_v3v3(imat[2], fsvec); - // get homogenous coordinates + /* get homogenous coordinates */ projectvert(camco, winmat, hoco); projectvert(ver->co, winmat, ho); /* now map hocos to screenspace, uses very primitive clip still */ - // use ho[3] of original vertex, xy component of vel. direction + /* use ho[3] of original vertex, xy component of vel. direction */ 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 + /* maximize speed as usual */ len= zco[0]*zco[0] + zco[1]*zco[1]; if (len > winsq) { len= winroot/sqrtf(len); zco[0]*= len; zco[1]*= len; } - + speed= RE_vertren_get_winspeed(obi, ver, 1); - // set both to the same value + /* set both to the same value */ speed[0]= speed[2]= zco[0]; speed[1]= speed[3]= zco[1]; //if (a < 20) fprintf(stderr,"speed %d %f,%f | camco %f,%f,%f | hoco %f,%f,%f,%f\n", a, speed[0], speed[1], camco[0],camco[1], camco[2], hoco[0],hoco[1], hoco[2],hoco[3]); // NT DEBUG @@ -5651,7 +5651,7 @@ void RE_Database_FromScene_Vectors(Render *re, Main *bmain, Scene *sce, unsigned continue; } - // NT check for fluidsim special treatment + /* NT check for fluidsim special treatment */ fluidmd = (FluidsimModifierData *)modifiers_findByType(obi->ob, eModifierType_Fluidsim); if (fluidmd && fluidmd->fss && (fluidmd->fss->type & OB_FLUIDSIM_DOMAIN)) { /* use preloaded per vertex simulation data, only does calculation for step=1 */ @@ -5664,7 +5664,7 @@ void RE_Database_FromScene_Vectors(Render *re, Main *bmain, Scene *sce, unsigned 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); - } // not fluidsim + } /* not fluidsim */ oldobi= oldobi->next; } diff --git a/source/blender/render/intern/source/envmap.c b/source/blender/render/intern/source/envmap.c index 61de4d39585..5879a9bd66d 100644 --- a/source/blender/render/intern/source/envmap.c +++ b/source/blender/render/intern/source/envmap.c @@ -49,7 +49,7 @@ #include "BKE_library.h" #include "BKE_main.h" -#include "BKE_image.h" // BKE_imbuf_write +#include "BKE_image.h" /* BKE_imbuf_write */ #include "BKE_texture.h" @@ -579,7 +579,7 @@ void make_envmaps(Render *re) re->display_clear(re->dch, re->result); // re->flag |= R_REDRAW_PRV; } - // restore + /* restore */ re->r.mode |= trace; } diff --git a/source/blender/render/intern/source/external_engine.c b/source/blender/render/intern/source/external_engine.c index e3eab0c3b34..75206f10f84 100644 --- a/source/blender/render/intern/source/external_engine.c +++ b/source/blender/render/intern/source/external_engine.c @@ -192,7 +192,7 @@ void RE_engine_update_result(RenderEngine *engine, RenderResult *result) Render *re = engine->re; if (result) { - result->renlay = result->layers.first; // weak, draws first layer always + result->renlay = result->layers.first; /* weak, draws first layer always */ re->display_draw(re->ddh, result, NULL); } } @@ -210,7 +210,7 @@ void RE_engine_end_result(RenderEngine *engine, RenderResult *result) /* draw */ if (!re->test_break(re->tbh)) { - result->renlay = result->layers.first; // weak, draws first layer always + result->renlay = result->layers.first; /* weak, draws first layer always */ re->display_draw(re->ddh, result, NULL); } diff --git a/source/blender/render/intern/source/imagetexture.c b/source/blender/render/intern/source/imagetexture.c index dcc09c92bb0..a0ba2a82ead 100644 --- a/source/blender/render/intern/source/imagetexture.c +++ b/source/blender/render/intern/source/imagetexture.c @@ -231,13 +231,13 @@ int imagewrap(Tex *tex, Image *ima, ImBuf *ibuf, const float texvec[3], TexResul 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. - // It needs to be done because in Blender - // the normal used in the renderer points inward. It is generated - // this way in calc_vertexnormals(). Should this ever change - // this negate must be removed. + /* qdn: normal from color + * The invert of the red channel is to make + * the normal map compliant with the outside world. + * It needs to be done because in Blender + * the normal used in the renderer points inward. It is generated + * this way in calc_vertexnormals(). Should this ever change + * this negate must be removed. */ texres->nor[0] = -2.f*(texres->tr - 0.5f); texres->nor[1] = 2.f*(texres->tg - 0.5f); texres->nor[2] = 2.f*(texres->tb - 0.5f); @@ -619,36 +619,36 @@ static void boxsample(ImBuf *ibuf, float minx, float miny, float maxx, float max } } -//----------------------------------------------------------------------------------------------------------------- -// from here, some functions only used for the new filtering +/*----------------------------------------------------------------------------------------------------------------- + * from here, some functions only used for the new filtering */ -// anisotropic filters, data struct used instead of long line of (possibly unused) func args +/* anisotropic filters, data struct used instead of long line of (possibly unused) func args */ typedef struct afdata_t { float dxt[2], dyt[2]; int intpol, extflag; - // feline only + /* feline only */ float majrad, minrad, theta; int iProbes; float dusc, dvsc; } afdata_t; -// this only used here to make it easier to pass extend flags as single int -enum {TXC_XMIR=1, TXC_YMIR, TXC_REPT, TXC_EXTD}; +/* this only used here to make it easier to pass extend flags as single int */ +enum {TXC_XMIR = 1, TXC_YMIR, TXC_REPT, TXC_EXTD}; -// similar to ibuf_get_color() but clips/wraps coords according to repeat/extend flags -// returns true if out of range in clipmode +/* similar to ibuf_get_color() but clips/wraps coords according to repeat/extend flags + * returns true if out of range in clipmode */ static int ibuf_get_color_clip(float col[4], ImBuf *ibuf, int x, int y, int extflag) { int clip = 0; switch (extflag) { - case TXC_XMIR: // y rep + case TXC_XMIR: /* y rep */ x %= 2*ibuf->x; x += x < 0 ? 2*ibuf->x : 0; x = x >= ibuf->x ? 2*ibuf->x - x - 1 : x; y %= ibuf->y; y += y < 0 ? ibuf->y : 0; break; - case TXC_YMIR: // x rep + case TXC_YMIR: /* x rep */ x %= ibuf->x; x += x < 0 ? ibuf->x : 0; y %= 2*ibuf->y; @@ -665,11 +665,12 @@ static int ibuf_get_color_clip(float col[4], ImBuf *ibuf, int x, int y, int extf y %= ibuf->y; y += (y < 0) ? ibuf->y : 0; break; - default: { // as extend, if clipped, set alpha to 0.0 - if (x < 0) { x = 0; } // TXF alpha: clip = 1; } - if (x >= ibuf->x) { x = ibuf->x - 1; } // TXF alpha: clip = 1; } - if (y < 0) { y = 0; } // TXF alpha: clip = 1; } - if (y >= ibuf->y) { y = ibuf->y - 1; } // TXF alpha: clip = 1; } + default: + { /* as extend, if clipped, set alpha to 0.0 */ + if (x < 0) { x = 0; } /* TXF alpha: clip = 1; } */ + if (x >= ibuf->x) { x = ibuf->x - 1; } /* TXF alpha: clip = 1; } */ + if (y < 0) { y = 0; } /* TXF alpha: clip = 1; } */ + if (y >= ibuf->y) { y = ibuf->y - 1; } /* TXF alpha: clip = 1; } */ } } @@ -694,7 +695,7 @@ static int ibuf_get_color_clip(float col[4], ImBuf *ibuf, int x, int y, int extf return clip; } -// as above + bilerp +/* as above + bilerp */ static int ibuf_get_color_clip_bilerp(float col[4], ImBuf *ibuf, float u, float v, int intpol, int extflag) { if (intpol) { @@ -749,12 +750,12 @@ static void area_sample(TexResult* texr, ImBuf* ibuf, float fx, float fy, afdata texr->tr *= xsd; texr->tg *= xsd; texr->tb *= xsd; - // clipping can be ignored if alpha used, texr->ta already includes filtered edge + /* clipping can be ignored if alpha used, texr->ta already includes filtered edge */ texr->ta = texr->talpha ? texr->ta*xsd : (clip ? cw*xsd : 1.f); } -// table of (exp(ar) - exp(a)) / (1 - exp(a)) for r in range [0, 1] and a = -2 -// used instead of actual gaussian, otherwise at high texture magnifications circular artifacts are visible +/* table of (exp(ar) - exp(a)) / (1 - exp(a)) for r in range [0, 1] and a = -2 + * used instead of actual gaussian, otherwise at high texture magnifications circular artifacts are visible */ #define EWA_MAXIDX 255 static float EWA_WTS[EWA_MAXIDX + 1] = { 1.f, 0.990965f, 0.982f, 0.973105f, 0.96428f, 0.955524f, 0.946836f, 0.938216f, 0.929664f, @@ -791,9 +792,9 @@ static float EWA_WTS[EWA_MAXIDX + 1] = 0.00754159f, 0.00625989f, 0.00498819f, 0.00372644f, 0.00247454f, 0.00123242f, 0.f }; -// test if a float value is 'nan' -// there is a C99 function for this: isnan(), but blender seems to use C90 (according to gcc warns), -// and may not be supported by other compilers either +/* test if a float value is 'nan' + * there is a C99 function for this: isnan(), but blender seems to use C90 (according to gcc warns), + * and may not be supported by other compilers either */ #ifndef ISNAN #define ISNAN(x) ((x) != (x)) #endif @@ -802,7 +803,7 @@ static float EWA_WTS[EWA_MAXIDX + 1] = static void radangle2imp(float a2, float b2, float th, float* A, float* B, float* C, float* F) { float ct2 = cosf(th); - const float st2 = 1.f - ct2*ct2; // <- sin(th)^2 + const float st2 = 1.0f - ct2 * ct2; /* <- sin(th)^2 */ ct2 *= ct2; *A = a2*st2 + b2*ct2; *B = (b2 - a2)*sinf(2.f*th); @@ -810,10 +811,10 @@ static void radangle2imp(float a2, float b2, float th, float* A, float* B, float *F = a2*b2; } -// all tests here are done to make sure possible overflows are hopefully minimized +/* all tests here are done to make sure possible overflows are hopefully minimized */ static void imp2radangle(float A, float B, float C, float F, float* a, float* b, float* th, float* ecc) { - if (F <= 1e-5f) { // use arbitrary major radius, zero minor, infinite eccentricity + if (F <= 1e-5f) { /* use arbitrary major radius, zero minor, infinite eccentricity */ *a = sqrtf(A > C ? A : C); *b = 0.f; *ecc = 1e10f; @@ -833,31 +834,31 @@ static void imp2radangle(float A, float B, float C, float F, float* a, float* b, *b = sqrtf(F2 / d); *ecc = *a / *b; } - // incr theta by 0.5*pi (angle of major axis) + /* incr theta by 0.5*pi (angle of major axis) */ *th = 0.5f*(atan2f(B, AmC) + (float)M_PI); } } static void ewa_eval(TexResult* texr, ImBuf* ibuf, float fx, float fy, afdata_t* AFD) { - // scaling dxt/dyt by full resolution can cause overflow because of huge A/B/C and esp. F values, - // scaling by aspect ratio alone does the opposite, so try something in between instead... + /* scaling dxt/dyt by full resolution can cause overflow because of huge A/B/C and esp. F values, + * scaling by aspect ratio alone does the opposite, so try something in between instead... */ const float ff2 = ibuf->x, ff = sqrtf(ff2), q = ibuf->y / ff; const float Ux = AFD->dxt[0]*ff, Vx = AFD->dxt[1]*q, Uy = AFD->dyt[0]*ff, Vy = AFD->dyt[1]*q; float A = Vx*Vx + Vy*Vy; float B = -2.f*(Ux*Vx + Uy*Vy); float C = Ux*Ux + Uy*Uy; float F = A*C - B*B*0.25f; - float a, b, th, ecc, a2, b2, ue, ve, U0, V0, DDQ, U, ac1, ac2, BU, d; // TXF alpha: cw = 0.f; - int u, v, u1, u2, v1, v2; // TXF alpha: clip = 0; - - // The so-called 'high' quality ewa method simply adds a constant of 1 to both A & C, - // so the ellipse always covers at least some texels. But since the filter is now always larger, - // it also means that everywhere else it's also more blurry then ideally should be the case. - // So instead here the ellipse radii are modified instead whenever either is too low. - // Use a different radius based on interpolation switch, just enough to anti-alias when interpolation is off, - // and slightly larger to make result a bit smoother than bilinear interpolation when interpolation is on - // (minimum values: const float rmin = intpol ? 1.f : 0.5f;) + float a, b, th, ecc, a2, b2, ue, ve, U0, V0, DDQ, U, ac1, ac2, BU, d; /* TXF alpha: cw = 0.f; */ + int u, v, u1, u2, v1, v2; /* TXF alpha: clip = 0; */ + + /* The so-called 'high' quality ewa method simply adds a constant of 1 to both A & C, + * so the ellipse always covers at least some texels. But since the filter is now always larger, + * it also means that everywhere else it's also more blurry then ideally should be the case. + * So instead here the ellipse radii are modified instead whenever either is too low. + * Use a different radius based on interpolation switch, just enough to anti-alias when interpolation is off, + * and slightly larger to make result a bit smoother than bilinear interpolation when interpolation is on + * (minimum values: const float rmin = intpol ? 1.f : 0.5f;) */ const float rmin = (AFD->intpol ? 1.5625f : 0.765625f)/ff2; imp2radangle(A, B, C, F, &a, &b, &th, &ecc); if ((b2 = b*b) < rmin) { @@ -903,8 +904,8 @@ static void ewa_eval(TexResult* texr, ImBuf* ibuf, float fx, float fy, afdata_t* float tc[4]; const float wt = EWA_WTS[(Q < 0.f) ? 0 : (unsigned int)Q]; /*const int out =*/ ibuf_get_color_clip(tc, ibuf, u, v, AFD->extflag); - // TXF alpha: clip |= out; - // TXF alpha: cw += out ? 0.f : wt; + /* TXF alpha: clip |= out; + * TXF alpha: cw += out ? 0.f : wt; */ texr->tr += tc[0]*wt; texr->tg += tc[1]*wt; texr->tb += tc[2]*wt; @@ -916,13 +917,13 @@ static void ewa_eval(TexResult* texr, ImBuf* ibuf, float fx, float fy, afdata_t* } } - // d should hopefully never be zero anymore + /* d should hopefully never be zero anymore */ d = 1.f/d; texr->tr *= d; texr->tg *= d; texr->tb *= d; - // clipping can be ignored if alpha used, texr->ta already includes filtered edge - texr->ta = texr->talpha ? texr->ta*d : 1.f; // TXF alpha (clip ? cw*d : 1.f); + /* clipping can be ignored if alpha used, texr->ta already includes filtered edge */ + texr->ta = texr->talpha ? texr->ta*d : 1.f; /* TXF alpha (clip ? cw*d : 1.f); */ } static void feline_eval(TexResult* texr, ImBuf* ibuf, float fx, float fy, afdata_t* AFD) @@ -931,11 +932,11 @@ static void feline_eval(TexResult* texr, ImBuf* ibuf, float fx, float fy, afdata const float ll = ((AFD->majrad == AFD->minrad) ? 2.f*AFD->majrad : 2.f*(AFD->majrad - AFD->minrad)) / (maxn ? (float)maxn : 1.f); float du = maxn ? cosf(AFD->theta)*ll : 0.f; float dv = maxn ? sinf(AFD->theta)*ll : 0.f; - //const float D = -0.5f*(du*du + dv*dv) / (AFD->majrad*AFD->majrad); + /* const float D = -0.5f*(du*du + dv*dv) / (AFD->majrad*AFD->majrad); */ const float D = (EWA_MAXIDX + 1)*0.25f*(du*du + dv*dv) / (AFD->majrad*AFD->majrad); - float d; // TXF alpha: cw = 0.f; - int n; // TXF alpha: clip = 0; - // have to use same scaling for du/dv here as for Ux/Vx/Uy/Vy (*after* D calc.) + float d; /* TXF alpha: cw = 0.f; */ + int n; /* TXF alpha: clip = 0; */ + /* have to use same scaling for du/dv here as for Ux/Vx/Uy/Vy (*after* D calc.) */ du *= AFD->dusc; dv *= AFD->dvsc; d = texr->tr = texr->tb = texr->tg = texr->ta = 0.f; @@ -943,12 +944,12 @@ static void feline_eval(TexResult* texr, ImBuf* ibuf, float fx, float fy, afdata float tc[4]; const float hn = n*0.5f; const float u = fx + hn*du, v = fy + hn*dv; - //const float wt = expf(n*n*D); - // can use ewa table here too + /*const float wt = expf(n*n*D); + * can use ewa table here too */ const float wt = EWA_WTS[(int)(n*n*D)]; /*const int out =*/ ibuf_get_color_clip_bilerp(tc, ibuf, ibuf->x*u, ibuf->y*v, AFD->intpol, AFD->extflag); - // TXF alpha: clip |= out; - // TXF alpha: cw += out ? 0.f : wt; + /* TXF alpha: clip |= out; + * TXF alpha: cw += out ? 0.f : wt; */ texr->tr += tc[0]*wt; texr->tg += tc[1]*wt; texr->tb += tc[2]*wt; @@ -960,7 +961,7 @@ static void feline_eval(TexResult* texr, ImBuf* ibuf, float fx, float fy, afdata texr->tr *= d; texr->tg *= d; texr->tb *= d; - // clipping can be ignored if alpha used, texr->ta already includes filtered edge + /* clipping can be ignored if alpha used, texr->ta already includes filtered edge */ texr->ta = texr->talpha ? texr->ta*d : 1.f; // TXF alpha: (clip ? cw*d : 1.f); } #undef EWA_MAXIDX @@ -970,8 +971,8 @@ static void alpha_clip_aniso(ImBuf *ibuf, float minx, float miny, float maxx, fl float alphaclip; rctf rf; - // 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 .. + /* 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)) { rf.xmin = minx*(ibuf->x); @@ -1040,13 +1041,13 @@ static int imagewraposa_aniso(Tex *tex, Image *ima, ImBuf *ibuf, const float tex texres->tin = texres->ta = texres->tr = texres->tg = texres->tb = 0.f; - // we need to set retval OK, otherwise texture code generates normals itself... + /* we need to set retval OK, otherwise texture code generates normals itself... */ retval = texres->nor ? 3 : 1; - // quick tests + /* quick tests */ if (ibuf==NULL && ima==NULL) return retval; - if (ima) { // hack for icon render + if (ima) { /* hack for icon render */ if ((ima->ibufs.first == NULL) && (R.r.scemode & R_NO_IMAGE_LOAD)) return retval; ibuf = BKE_image_get_ibuf(ima, &tex->iuser); } @@ -1079,18 +1080,18 @@ static int imagewraposa_aniso(Tex *tex, Image *ima, ImBuf *ibuf, const float tex } } - // pixel coordinates + /* pixel coordinates */ minx = MIN3(dxt[0], dyt[0], dxt[0] + dyt[0]); maxx = MAX3(dxt[0], dyt[0], dxt[0] + dyt[0]); miny = MIN3(dxt[1], dyt[1], dxt[1] + dyt[1]); maxy = MAX3(dxt[1], dyt[1], dxt[1] + dyt[1]); - // tex_sharper has been removed + /* tex_sharper has been removed */ minx = (maxx - minx)*0.5f; miny = (maxy - miny)*0.5f; if (tex->imaflag & TEX_FILTER_MIN) { - // make sure the filtersize is minimal in pixels (normal, ref map can have miniature pixel dx/dy) + /* make sure the filtersize is minimal in pixels (normal, ref map can have miniature pixel dx/dy) */ const float addval = (0.5f * tex->filtersize) / (float)MIN2(ibuf->x, ibuf->y); if (addval > minx) minx = addval; if (addval > miny) miny = addval; @@ -1107,9 +1108,9 @@ static int imagewraposa_aniso(Tex *tex, Image *ima, ImBuf *ibuf, const float tex if (tex->imaflag & TEX_IMAROT) { float t; SWAP(float, minx, miny); - // must rotate dxt/dyt 90 deg - // yet another blender problem is that swapping X/Y axes (or any tex proj switches) should do something similar, - // but it doesn't, it only swaps coords, so filter area will be incorrect in those cases. + /* must rotate dxt/dyt 90 deg + * yet another blender problem is that swapping X/Y axes (or any tex proj switches) should do something similar, + * but it doesn't, it only swaps coords, so filter area will be incorrect in those cases. */ t = dxt[0]; dxt[0] = dxt[1]; dxt[1] = -t; @@ -1118,11 +1119,11 @@ static int imagewraposa_aniso(Tex *tex, Image *ima, ImBuf *ibuf, const float tex dyt[1] = -t; } - // side faces of unit-cube + /* side faces of unit-cube */ minx = (minx > 0.25f) ? 0.25f : ((minx < 1e-5f) ? 1e-5f : minx); miny = (miny > 0.25f) ? 0.25f : ((miny < 1e-5f) ? 1e-5f : miny); - // repeat and clip + /* repeat and clip */ if (tex->extend == TEX_REPEAT) { if ((tex->flag & (TEX_REPEAT_XMIR | TEX_REPEAT_YMIR)) == (TEX_REPEAT_XMIR | TEX_REPEAT_YMIR)) @@ -1139,7 +1140,7 @@ static int imagewraposa_aniso(Tex *tex, Image *ima, ImBuf *ibuf, const float tex if (tex->extend == TEX_CHECKER) { int xs = (int)floorf(fx), ys = (int)floorf(fy); - // both checkers available, no boundary exceptions, checkerdist will eat aliasing + /* both checkers available, no boundary exceptions, checkerdist will eat aliasing */ if ((tex->flag & TEX_CHECKER_ODD) && (tex->flag & TEX_CHECKER_EVEN)) { fx -= xs; fy -= ys; @@ -1166,7 +1167,7 @@ static int imagewraposa_aniso(Tex *tex, Image *ima, ImBuf *ibuf, const float tex fy -= ys; } } - // scale around center, (0.5, 0.5) + /* scale around center, (0.5, 0.5) */ if (tex->checkerdist < 1.f) { const float omcd = 1.f / (1.f - tex->checkerdist); fx = (fx - 0.5f)*omcd + 0.5f; @@ -1195,34 +1196,34 @@ static int imagewraposa_aniso(Tex *tex, Image *ima, ImBuf *ibuf, const float tex intpol = tex->imaflag & TEX_INTERPOL; - // warning no return! + /* warning no return! */ if ((R.flag & R_SEC_FIELD) && (ibuf->flags & IB_fields)) ibuf->rect += ibuf->x*ibuf->y; - // struct common data + /* struct common data */ copy_v2_v2(AFD.dxt, dxt); copy_v2_v2(AFD.dyt, dyt); AFD.intpol = intpol; AFD.extflag = extflag; - // 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 + /* brecht: added stupid clamping here, large dx/dy can give very large + * filter sizes which take ages to render, it may be better to do this + * more intelligently later in the code .. probably it's not noticeable */ if (AFD.dxt[0]*AFD.dxt[0] + AFD.dxt[1]*AFD.dxt[1] > 2.0f*2.0f) mul_v2_fl(AFD.dxt, 2.0f/len_v2(AFD.dxt)); if (AFD.dyt[0]*AFD.dyt[0] + AFD.dyt[1]*AFD.dyt[1] > 2.0f*2.0f) mul_v2_fl(AFD.dyt, 2.0f/len_v2(AFD.dyt)); - // choice: + /* choice: */ if (tex->imaflag & TEX_MIPMAP) { ImBuf *previbuf, *curibuf; float levf; int maxlev; ImBuf* mipmaps[IB_MIPMAP_LEVELS + 1]; - // modify ellipse minor axis if too eccentric, use for area sampling as well - // scaling dxt/dyt as done in pbrt is not the same - // (as in ewa_eval(), scale by sqrt(ibuf->x) to maximize precision) + /* modify ellipse minor axis if too eccentric, use for area sampling as well + * scaling dxt/dyt as done in pbrt is not the same + * (as in ewa_eval(), scale by sqrt(ibuf->x) to maximize precision) */ const float ff = sqrtf(ibuf->x), q = ibuf->y/ff; const float Ux = dxt[0]*ff, Vx = dxt[1]*q, Uy = dyt[0]*ff, Vy = dyt[1]*q; const float A = Vx*Vx + Vy*Vy; @@ -1248,7 +1249,7 @@ static int imagewraposa_aniso(Tex *tex, Image *ima, ImBuf *ibuf, const float tex AFD.dusc = 1.f/ff; AFD.dvsc = ff / (float)ibuf->y; } - else { // EWA & area + else { /* EWA & area */ if (ecc > (float)tex->afmax) b = a / (float)tex->afmax; b *= ff; } @@ -1264,8 +1265,8 @@ static int imagewraposa_aniso(Tex *tex, Image *ima, ImBuf *ibuf, const float tex curmap++; } - // mipmap level - if (levf < 0.f) { // original image only + /* mipmap level */ + if (levf < 0.f) { /* original image only */ previbuf = curibuf = mipmaps[0]; levf = 0.f; } @@ -1281,39 +1282,39 @@ static int imagewraposa_aniso(Tex *tex, Image *ima, ImBuf *ibuf, const float tex levf -= floorf(levf); } - // filter functions take care of interpolation themselves, no need to modify dxt/dyt here + /* filter functions take care of interpolation themselves, no need to modify dxt/dyt here */ if (texres->nor && ((tex->imaflag & TEX_NORMALMAP) == 0)) { - // color & normal + /* color & normal */ filterfunc(texres, curibuf, fx, fy, &AFD); val1 = texres->tr + texres->tg + texres->tb; filterfunc(&texr, curibuf, fx + dxt[0], fy + dxt[1], &AFD); val2 = texr.tr + texr.tg + texr.tb; filterfunc(&texr, curibuf, fx + dyt[0], fy + dyt[1], &AFD); val3 = texr.tr + texr.tg + texr.tb; - // don't switch x or y! + /* don't switch x or y! */ texres->nor[0] = val1 - val2; texres->nor[1] = val1 - val3; - if (previbuf != curibuf) { // interpolate + if (previbuf != curibuf) { /* interpolate */ filterfunc(&texr, previbuf, fx, fy, &AFD); - // rgb + /* rgb */ texres->tr += levf*(texr.tr - texres->tr); texres->tg += levf*(texr.tg - texres->tg); texres->tb += levf*(texr.tb - texres->tb); texres->ta += levf*(texr.ta - texres->ta); - // normal + /* normal */ val1 += levf*((texr.tr + texr.tg + texr.tb) - val1); filterfunc(&texr, previbuf, fx + dxt[0], fy + dxt[1], &AFD); val2 += levf*((texr.tr + texr.tg + texr.tb) - val2); filterfunc(&texr, previbuf, fx + dyt[0], fy + dyt[1], &AFD); val3 += levf*((texr.tr + texr.tg + texr.tb) - val3); - texres->nor[0] = val1 - val2; // vals have been interpolated above! + texres->nor[0] = val1 - val2; /* vals have been interpolated above! */ texres->nor[1] = val1 - val3; } } - else { // color + else { /* color */ filterfunc(texres, curibuf, fx, fy, &AFD); - if (previbuf != curibuf) { // interpolate + if (previbuf != curibuf) { /* interpolate */ filterfunc(&texr, previbuf, fx, fy, &AFD); texres->tr += levf*(texr.tr - texres->tr); texres->tg += levf*(texr.tg - texres->tg); @@ -1324,8 +1325,8 @@ static int imagewraposa_aniso(Tex *tex, Image *ima, ImBuf *ibuf, const float tex alpha_clip_aniso(ibuf, fx-minx, fy-miny, fx+minx, fy+miny, extflag, texres); } } - else { // no mipmap - // filter functions take care of interpolation themselves, no need to modify dxt/dyt here + else { /* no mipmap */ + /* filter functions take care of interpolation themselves, no need to modify dxt/dyt here */ if (tex->texfilter == TXF_FELINE) { const float ff = sqrtf(ibuf->x), q = ibuf->y/ff; const float Ux = dxt[0]*ff, Vx = dxt[1]*q, Uy = dyt[0]*ff, Vy = dyt[1]*q; @@ -1340,7 +1341,7 @@ static int imagewraposa_aniso(Tex *tex, Image *ima, ImBuf *ibuf, const float tex a = MAX2(a, 1.f); b = MAX2(b, 1.f); fProbes = 2.f*(a / b) - 1.f; - // no limit to number of Probes here + /* no limit to number of Probes here */ AFD.iProbes = (int)floorf(fProbes + 0.5f); if (AFD.iProbes < fProbes) b = 2.f*a / (float)(AFD.iProbes + 1); AFD.majrad = a/ff; @@ -1350,14 +1351,14 @@ static int imagewraposa_aniso(Tex *tex, Image *ima, ImBuf *ibuf, const float tex AFD.dvsc = ff / (float)ibuf->y; } if (texres->nor && ((tex->imaflag & TEX_NORMALMAP) == 0)) { - // color & normal + /* color & normal */ filterfunc(texres, ibuf, fx, fy, &AFD); val1 = texres->tr + texres->tg + texres->tb; filterfunc(&texr, ibuf, fx + dxt[0], fy + dxt[1], &AFD); val2 = texr.tr + texr.tg + texr.tb; filterfunc(&texr, ibuf, fx + dyt[0], fy + dyt[1], &AFD); val3 = texr.tr + texr.tg + texr.tb; - // don't switch x or y! + /* don't switch x or y! */ texres->nor[0] = val1 - val2; texres->nor[1] = val1 - val3; } @@ -1376,23 +1377,23 @@ static int imagewraposa_aniso(Tex *tex, Image *ima, ImBuf *ibuf, const float tex if ((R.flag & R_SEC_FIELD) && (ibuf->flags & IB_fields)) ibuf->rect -= ibuf->x*ibuf->y; - if (texres->nor && (tex->imaflag & TEX_NORMALMAP)) { // normal from color - // The invert of the red channel is to make - // the normal map compliant with the outside world. - // It needs to be done because in Blender - // the normal used in the renderer points inward. It is generated - // this way in calc_vertexnormals(). Should this ever change - // this negate must be removed. + if (texres->nor && (tex->imaflag & TEX_NORMALMAP)) { /* normal from color */ + /* The invert of the red channel is to make + * the normal map compliant with the outside world. + * It needs to be done because in Blender + * the normal used in the renderer points inward. It is generated + * this way in calc_vertexnormals(). Should this ever change + * this negate must be removed. */ texres->nor[0] = -2.f*(texres->tr - 0.5f); texres->nor[1] = 2.f*(texres->tg - 0.5f); texres->nor[2] = 2.f*(texres->tb - 0.5f); } - - // de-premul, this is being premulled in shade_input_do_shade() - // TXF: this currently does not (yet?) work properly, destroys edge AA in clip/checker mode, so for now commented out - // also disabled in imagewraposa() to be able to compare results with blender's default texture filtering - // brecht: tried to fix this, see "TXF alpha" comments + /* de-premul, this is being premulled in shade_input_do_shade() + * TXF: this currently does not (yet?) work properly, destroys edge AA in clip/checker mode, so for now commented out + * also disabled in imagewraposa() to be able to compare results with blender's default texture filtering */ + + /* brecht: tried to fix this, see "TXF alpha" comments */ if (texres->ta != 1.f && (texres->ta > 1e-4f)) { fx = 1.f/texres->ta; @@ -1414,12 +1415,12 @@ int imagewraposa(Tex *tex, Image *ima, ImBuf *ibuf, const float texvec[3], const float maxd, pixsize, val1, val2, val3; int curmap, retval, imaprepeat, imapextend; - // TXF: since dxt/dyt might be modified here and since they might be needed after imagewraposa() call, - // make a local copy here so that original vecs remain untouched + /* TXF: since dxt/dyt might be modified here and since they might be needed after imagewraposa() call, + * make a local copy here so that original vecs remain untouched */ copy_v3_v3(dxt, DXT); copy_v3_v3(dyt, DYT); - // anisotropic filtering + /* anisotropic filtering */ if (tex->texfilter != TXF_BOX) return imagewraposa_aniso(tex, ima, ibuf, texvec, dxt, dyt, texres); @@ -1530,7 +1531,7 @@ int imagewraposa(Tex *tex, Image *ima, ImBuf *ibuf, const float texvec[3], const xs= (int)floor(fx); ys= (int)floor(fy); - // both checkers available, no boundary exceptions, checkerdist will eat aliasing + /* both checkers available, no boundary exceptions, checkerdist will eat aliasing */ if ( (tex->flag & TEX_CHECKER_ODD) && (tex->flag & TEX_CHECKER_EVEN) ) { fx-= xs; fy-= ys; @@ -1765,18 +1766,18 @@ int imagewraposa(Tex *tex, Image *ima, ImBuf *ibuf, const float texvec[3], const } 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. - // It needs to be done because in Blender - // the normal used in the renderer points inward. It is generated - // this way in calc_vertexnormals(). Should this ever change - // this negate must be removed. + /* qdn: normal from color + * The invert of the red channel is to make + * the normal map compliant with the outside world. + * It needs to be done because in Blender + * the normal used in the renderer points inward. It is generated + * this way in calc_vertexnormals(). Should this ever change + * this negate must be removed. */ texres->nor[0] = -2.f*(texres->tr - 0.5f); texres->nor[1] = 2.f*(texres->tg - 0.5f); texres->nor[2] = 2.f*(texres->tb - 0.5f); } - + /* de-premul, this is being premulled in shade_input_do_shade() */ if (texres->ta!=1.0f && texres->ta>1e-4f) { fx= 1.0f/texres->ta; diff --git a/source/blender/render/intern/source/occlusion.c b/source/blender/render/intern/source/occlusion.c index 8c7f9d9c349..e8765b4c3ac 100644 --- a/source/blender/render/intern/source/occlusion.c +++ b/source/blender/render/intern/source/occlusion.c @@ -96,11 +96,11 @@ typedef struct OccNode { typedef struct OcclusionTree { MemArena *arena; - float (*co)[3]; /* temporary during build */ + float (*co)[3]; /* temporary during build */ - OccFace *face; /* instance and face indices */ - float *occlusion; /* occlusion for faces */ - float (*rad)[3]; /* radiance for faces */ + OccFace *face; /* instance and face indices */ + float *occlusion; /* occlusion for faces */ + float (*rad)[3]; /* radiance for faces */ OccNode *root; @@ -137,35 +137,35 @@ typedef struct OcclusionBuildThread { /* ------------------------- Shading --------------------------- */ -extern Render R; // meh +extern Render R; /* meh */ static void occ_shade(ShadeSample *ssamp, ObjectInstanceRen *obi, VlakRen *vlr, float *rad) { - ShadeInput *shi= ssamp->shi; - ShadeResult *shr= ssamp->shr; + ShadeInput *shi = ssamp->shi; + ShadeResult *shr = ssamp->shr; float l, u, v, *v1, *v2, *v3; /* init */ if (vlr->v4) { - shi->u= u= 0.5f; - shi->v= v= 0.5f; + shi->u = u = 0.5f; + shi->v = v = 0.5f; } else { - shi->u= u= 1.0f/3.0f; - shi->v= v= 1.0f/3.0f; + shi->u = u = 1.0f / 3.0f; + shi->v = v = 1.0f / 3.0f; } /* setup render coordinates */ - v1= vlr->v1->co; - v2= vlr->v2->co; - v3= vlr->v3->co; + v1 = vlr->v1->co; + v2 = vlr->v2->co; + v3 = vlr->v3->co; /* renderco */ - l= 1.0f-u-v; + l = 1.0f - u - v; - shi->co[0]= l*v3[0]+u*v1[0]+v*v2[0]; - shi->co[1]= l*v3[1]+u*v1[1]+v*v2[1]; - shi->co[2]= l*v3[2]+u*v1[2]+v*v2[2]; + shi->co[0] = l * v3[0] + u * v1[0] + v * v2[0]; + shi->co[1] = l * v3[1] + u * v1[1] + v * v2[1]; + shi->co[2] = l * v3[2] + u * v1[2] + v * v2[2]; shade_input_set_triangle_i(shi, obi, vlr, 0, 1, 2); @@ -176,8 +176,8 @@ static void occ_shade(ShadeSample *ssamp, ObjectInstanceRen *obi, VlakRen *vlr, /* cache for shadow */ shi->samplenr++; - shi->xs= 0; /* TODO */ - shi->ys= 0; + shi->xs = 0; /* TODO */ + shi->ys = 0; shade_input_set_normals(shi); @@ -195,9 +195,9 @@ static void occ_shade(ShadeSample *ssamp, ObjectInstanceRen *obi, VlakRen *vlr, } /* init material vars */ - // note, keep this synced with render_types.h - memcpy(&shi->r, &shi->mat->r, 23*sizeof(float)); - shi->har= shi->mat->har; + /* note, keep this synced with render_types.h */ + memcpy(&shi->r, &shi->mat->r, 23 * sizeof(float)); + shi->har = shi->mat->har; /* render */ shade_input_set_shade_texco(shi); @@ -213,18 +213,18 @@ static void occ_build_shade(Render *re, OcclusionTree *tree) VlakRen *vlr; int a; - R= *re; + R = *re; /* setup shade sample with correct passes */ memset(&ssamp, 0, sizeof(ShadeSample)); - ssamp.shi[0].lay= re->lay; - ssamp.shi[0].passflag= SCE_PASS_DIFFUSE|SCE_PASS_RGBA; - ssamp.shi[0].combinedflag= ~(SCE_PASS_SPEC); - ssamp.tot= 1; + ssamp.shi[0].lay = re->lay; + ssamp.shi[0].passflag = SCE_PASS_DIFFUSE | SCE_PASS_RGBA; + ssamp.shi[0].combinedflag = ~(SCE_PASS_SPEC); + ssamp.tot = 1; - for (a=0; a<tree->totface; a++) { - obi= &R.objectinstance[tree->face[a].obi]; - vlr= RE_findOrAddVlak(obi->obr, tree->face[a].facenr); + for (a = 0; a < tree->totface; a++) { + obi = &R.objectinstance[tree->face[a].obi]; + vlr = RE_findOrAddVlak(obi->obr, tree->face[a].facenr); occ_shade(&ssamp, obi, vlr, tree->rad[a]); } @@ -233,20 +233,20 @@ static void occ_build_shade(Render *re, OcclusionTree *tree) /* ------------------------- Spherical Harmonics --------------------------- */ /* Use 2nd order SH => 9 coefficients, stored in this order: - * 0 = (0,0), - * 1 = (1,-1), 2 = (1,0), 3 = (1,1), - * 4 = (2,-2), 5 = (2,-1), 6 = (2,0), 7 = (2,1), 8 = (2,2) */ +* 0 = (0,0), +* 1 = (1,-1), 2 = (1,0), 3 = (1,1), +* 4 = (2,-2), 5 = (2,-1), 6 = (2,0), 7 = (2,1), 8 = (2,2) */ static void sh_copy(float *shresult, float *sh) { - memcpy(shresult, sh, sizeof(float)*9); + memcpy(shresult, sh, sizeof(float) * 9); } 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; } @@ -254,8 +254,8 @@ static void sh_add(float *shresult, float *sh1, float *sh2) { int i; - for (i=0; i<9; i++) - shresult[i]= sh1[i] + sh2[i]; + for (i = 0; i < 9; i++) + shresult[i] = sh1[i] + sh2[i]; } static void sh_from_disc(float *n, float area, float *shresult) @@ -264,21 +264,21 @@ static void sh_from_disc(float *n, float area, float *shresult) * "An Efficient Representation for Irradiance Environment Maps" */ float sh[9], x, y, z; - x= n[0]; - y= n[1]; - z= n[2]; + x = n[0]; + y = n[1]; + z = n[2]; - sh[0]= 0.282095f; + sh[0] = 0.282095f; - sh[1]= 0.488603f*y; - sh[2]= 0.488603f*z; - sh[3]= 0.488603f*x; - - sh[4]= 1.092548f*x*y; - sh[5]= 1.092548f*y*z; - sh[6]= 0.315392f*(3.0f*z*z - 1.0f); - sh[7]= 1.092548f*x*z; - sh[8]= 0.546274f*(x*x - y*y); + sh[1] = 0.488603f * y; + sh[2] = 0.488603f * z; + sh[3] = 0.488603f * x; + + sh[4] = 1.092548f * x * y; + sh[5] = 1.092548f * y * z; + sh[6] = 0.315392f * (3.0f * z * z - 1.0f); + sh[7] = 1.092548f * x * z; + sh[8] = 0.546274f * (x * x - y * y); sh_mul(sh, area); sh_copy(shresult, sh); @@ -292,16 +292,16 @@ static float sh_eval(float *sh, float *v) static const float c4 = 0.886227f, c5 = 0.247708f; float x, y, z, sum; - x= v[0]; - y= v[1]; - z= v[2]; + x = v[0]; + y = v[1]; + z = v[2]; - sum= c1*sh[8]*(x*x - y*y); - sum += c3*sh[6]*z*z; - sum += c4*sh[0]; - sum += -c5*sh[6]; - sum += 2.0f*c1*(sh[4]*x*y + sh[7]*x*z + sh[5]*y*z); - sum += 2.0f*c2*(sh[3]*x + sh[1]*y + sh[2]*z); + sum = c1 * sh[8] * (x * x - y * y); + sum += c3 * sh[6] * z * z; + sum += c4 * sh[0]; + sum += -c5 * sh[6]; + sum += 2.0f * c1 * (sh[4] * x * y + sh[7] * x * z + sh[5] * y * z); + sum += 2.0f * c2 * (sh[3] * x + sh[1] * y + sh[2] * z); return sum; } @@ -314,8 +314,8 @@ static void occ_face(const OccFace *face, float co[3], float normal[3], float *a VlakRen *vlr; float v1[3], v2[3], v3[3], v4[3]; - obi= &R.objectinstance[face->obi]; - vlr= RE_findOrAddVlak(obi->obr, face->facenr); + obi = &R.objectinstance[face->obi]; + vlr = RE_findOrAddVlak(obi->obr, face->facenr); if (co) { if (vlr->v4) @@ -328,9 +328,9 @@ static void occ_face(const OccFace *face, float co[3], float normal[3], float *a } if (normal) { - normal[0]= -vlr->n[0]; - normal[1]= -vlr->n[1]; - normal[2]= -vlr->n[2]; + normal[0] = -vlr->n[0]; + normal[1] = -vlr->n[1]; + normal[2] = -vlr->n[2]; if (obi->flag & R_TRANSFORMED) mul_m3_v3(obi->nmat, normal); @@ -351,9 +351,9 @@ static void occ_face(const OccFace *face, float co[3], float normal[3], float *a /* todo: correct area for instances */ if (vlr->v4) - *area= area_quad_v3(v1, v2, v3, v4); + *area = area_quad_v3(v1, v2, v3, v4); else - *area= area_tri_v3(v1, v2, v3); + *area = area_tri_v3(v1, v2, v3); } } @@ -361,25 +361,25 @@ static void occ_sum_occlusion(OcclusionTree *tree, OccNode *node) { OccNode *child; float occ, area, totarea, rad[3]; - int a, b, indirect= tree->doindirect; + int a, b, indirect = tree->doindirect; - occ= 0.0f; - totarea= 0.0f; + occ = 0.0f; + totarea = 0.0f; if (indirect) zero_v3(rad); - for (b=0; b<TOTCHILD; b++) { - if (node->childflag & (1<<b)) { - a= node->child[b].face; + 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]; + occ += area * tree->occlusion[a]; if (indirect) madd_v3_v3fl(rad, tree->rad[a], area); totarea += area; } else if (node->child[b].node) { - child= node->child[b].node; + child = node->child[b].node; occ_sum_occlusion(tree, child); - occ += child->area*child->occlusion; + occ += child->area * child->occlusion; if (indirect) madd_v3_v3fl(rad, child->rad, child->area); totarea += child->area; } @@ -387,16 +387,16 @@ static void occ_sum_occlusion(OcclusionTree *tree, OccNode *node) 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; + node->occlusion = occ; if (indirect) copy_v3_v3(node->rad, rad); } static int occ_find_bbox_axis(OcclusionTree *tree, int begin, int end, float *min, float *max) { - float len, maxlen= -1.0f; + float len, maxlen = -1.0f; int a, axis = 0; INIT_MINMAX(min, max); @@ -405,12 +405,12 @@ static int occ_find_bbox_axis(OcclusionTree *tree, int begin, int end, float *mi minmax_v3v3_v3(min, max, tree->co[a]); } - for (a=0; a<3; a++) { - len= max[a] - min[a]; + for (a = 0; a < 3; a++) { + len = max[a] - min[a]; if (len > maxlen) { - maxlen= len; - axis= a; + maxlen = len; + axis = a; } } @@ -422,21 +422,21 @@ static void occ_node_from_face(OccFace *face, OccNode *node) float n[3]; occ_face(face, node->co, n, &node->area); - node->dco= 0.0f; + node->dco = 0.0f; sh_from_disc(n, node->area, node->sh); } 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)) { - occ_face(tree->face+node->child[b].face, nco, NULL, NULL); + if (node->childflag & (1 << b)) { + occ_face(tree->face + node->child[b].face, nco, NULL, NULL); } else if (node->child[b].node) { - OccNode *child= node->child[b].node; + OccNode *child = node->child[b].node; occ_build_dco(tree, child, co, dco); copy_v3_v3(nco, child->co); } @@ -445,9 +445,9 @@ static void occ_build_dco(OcclusionTree *tree, OccNode *node, const float co[3], } sub_v3_v3v3(d, nco, co); - dist= dot_v3v3(d, d); + dist = dot_v3v3(d, d); if (dist > *dco) - *dco= dist; + *dco = dist; } } @@ -459,12 +459,12 @@ static void occ_build_split(OcclusionTree *tree, int begin, int end, int *split) /* split in middle of boundbox. this seems faster than median split * on complex scenes, possibly since it avoids two distant faces to * be in the same node better? */ - axis= occ_find_bbox_axis(tree, begin, end, min, max); - mid= 0.5f*(min[axis]+max[axis]); + axis = occ_find_bbox_axis(tree, begin, end, min, max); + mid = 0.5f * (min[axis] + max[axis]); - a= begin; - enda= end; - while (a<enda) { + a = begin; + enda = end; + while (a < enda) { if (tree->co[a][axis] > mid) { enda--; SWAP(OccFace, tree->face[a], tree->face[enda]); @@ -476,7 +476,7 @@ static void occ_build_split(OcclusionTree *tree, int begin, int end, int *split) a++; } - *split= enda; + *split = enda; } static void occ_build_8_split(OcclusionTree *tree, int begin, int end, int *offset, int *count) @@ -488,7 +488,7 @@ static void occ_build_8_split(OcclusionTree *tree, int begin, int end, int *offs /* force split if none found, to deal with degenerate geometry */ if (splitx == begin || splitx == end) - splitx= (begin+end)/2; + splitx = (begin + end) / 2; occ_build_split(tree, begin, splitx, &splity[0]); occ_build_split(tree, splitx, end, &splity[1]); @@ -498,25 +498,25 @@ static void occ_build_8_split(OcclusionTree *tree, int begin, int end, int *offs occ_build_split(tree, splitx, splity[1], &splitz[2]); occ_build_split(tree, splity[1], end, &splitz[3]); - offset[0]= begin; - offset[1]= splitz[0]; - offset[2]= splity[0]; - offset[3]= splitz[1]; - offset[4]= splitx; - offset[5]= splitz[2]; - offset[6]= splity[1]; - offset[7]= splitz[3]; - - for (b=0; b<7; b++) - count[b]= offset[b+1] - offset[b]; - count[7]= end - offset[7]; + offset[0] = begin; + offset[1] = splitz[0]; + offset[2] = splity[0]; + offset[3] = splitz[1]; + offset[4] = splitx; + offset[5] = splitz[2]; + offset[6] = splity[1]; + offset[7] = splitz[3]; + + for (b = 0; b < 7; b++) + count[b] = offset[b + 1] - offset[b]; + count[7] = end - offset[7]; } static void occ_build_recursive(OcclusionTree *tree, OccNode *node, int begin, int end, int depth); static void *exec_occ_build(void *data) { - OcclusionBuildThread *othread= (OcclusionBuildThread*)data; + OcclusionBuildThread *othread = (OcclusionBuildThread *)data; occ_build_recursive(othread->tree, othread->node, othread->begin, othread->end, othread->depth); @@ -529,17 +529,17 @@ static void occ_build_recursive(OcclusionTree *tree, OccNode *node, int begin, i OcclusionBuildThread othreads[BLENDER_MAX_THREADS]; OccNode *child, tmpnode; /* OccFace *face; */ - int a, b, totthread=0, offset[TOTCHILD], count[TOTCHILD]; + int a, b, totthread = 0, offset[TOTCHILD], count[TOTCHILD]; /* add a new node */ - node->occlusion= 1.0f; + node->occlusion = 1.0f; /* leaf node with only children */ if (end - begin <= TOTCHILD) { - for (a=begin, b=0; a<end; a++, b++) { + for (a = begin, b = 0; a < end; a++, b++) { /* face= &tree->face[a]; */ - node->child[b].face= a; - node->childflag |= (1<<b); + node->child[b].face = a; + node->childflag |= (1 << b); } } else { @@ -549,40 +549,40 @@ static void occ_build_recursive(OcclusionTree *tree, OccNode *node, int begin, i if (depth == 1 && tree->dothreadedbuild) BLI_init_threads(&threads, exec_occ_build, tree->totbuildthread); - for (b=0; b<TOTCHILD; b++) { + for (b = 0; b < TOTCHILD; b++) { if (count[b] == 0) { - node->child[b].node= NULL; + node->child[b].node = NULL; } else if (count[b] == 1) { /* face= &tree->face[offset[b]]; */ - node->child[b].face= offset[b]; - node->childflag |= (1<<b); + node->child[b].face = offset[b]; + node->childflag |= (1 << b); } else { if (tree->dothreadedbuild) BLI_lock_thread(LOCK_CUSTOM1); - child= BLI_memarena_alloc(tree->arena, sizeof(OccNode)); - node->child[b].node= child; + 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) - tree->maxdepth= depth+1; + if (depth + 1 > tree->maxdepth) + tree->maxdepth = depth + 1; if (tree->dothreadedbuild) BLI_unlock_thread(LOCK_CUSTOM1); if (depth == 1 && tree->dothreadedbuild) { - othreads[totthread].tree= tree; - othreads[totthread].node= child; - othreads[totthread].begin= offset[b]; - othreads[totthread].end= offset[b]+count[b]; - othreads[totthread].depth= depth+1; + othreads[totthread].tree = tree; + othreads[totthread].node = child; + othreads[totthread].begin = offset[b]; + othreads[totthread].end = offset[b] + count[b]; + othreads[totthread].depth = depth + 1; BLI_insert_thread(&threads, &othreads[totthread]); totthread++; } else - occ_build_recursive(tree, child, offset[b], offset[b]+count[b], depth+1); + occ_build_recursive(tree, child, offset[b], offset[b] + count[b], depth + 1); } } @@ -591,13 +591,13 @@ static void occ_build_recursive(OcclusionTree *tree, OccNode *node, int begin, i } /* combine area, position and sh */ - for (b=0; b<TOTCHILD; b++) { - if (node->childflag & (1<<b)) { - child= &tmpnode; - occ_node_from_face(tree->face+node->child[b].face, &tmpnode); + for (b = 0; b < TOTCHILD; b++) { + if (node->childflag & (1 << b)) { + child = &tmpnode; + occ_node_from_face(tree->face + node->child[b].face, &tmpnode); } else { - child= node->child[b].node; + child = node->child[b].node; } if (child) { @@ -608,10 +608,10 @@ static void occ_build_recursive(OcclusionTree *tree, OccNode *node, int begin, i } if (node->area != 0.0f) - mul_v3_fl(node->co, 1.0f/node->area); + mul_v3_fl(node->co, 1.0f / node->area); /* compute maximum distance from center */ - node->dco= 0.0f; + node->dco = 0.0f; if (node->area > 0.0f) occ_build_dco(tree, node, node->co, &node->dco); } @@ -623,10 +623,10 @@ static void occ_build_sh_normalize(OccNode *node) int b; if (node->area != 0.0f) - sh_mul(node->sh, 1.0f/node->area); + sh_mul(node->sh, 1.0f / node->area); - for (b=0; b<TOTCHILD; b++) { - if (node->childflag & (1<<b)); + 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); } @@ -638,18 +638,18 @@ static OcclusionTree *occ_tree_build(Render *re) ObjectInstanceRen *obi; ObjectRen *obr; Material *ma; - VlakRen *vlr= NULL; + VlakRen *vlr = NULL; int a, b, c, totface; /* count */ - totface= 0; - 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; + totface = 0; + 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; else vlr++; - ma= vlr->mat; + ma = vlr->mat; if ((ma->shade_flag & MA_APPROX_OCCLUSION) && (ma->material_type == MA_TYPE_SURFACE)) totface++; @@ -659,41 +659,41 @@ static OcclusionTree *occ_tree_build(Render *re) if (totface == 0) return NULL; - tree= MEM_callocN(sizeof(OcclusionTree), "OcclusionTree"); - tree->totface= totface; + tree = MEM_callocN(sizeof(OcclusionTree), "OcclusionTree"); + tree->totface = totface; /* parameters */ - tree->error= get_render_aosss_error(&re->r, re->wrld.ao_approx_error); - tree->distfac= (re->wrld.aomode & WO_AODIST)? re->wrld.aodistfac: 0.0f; - tree->doindirect= (re->wrld.ao_indirect_energy > 0.0f && re->wrld.ao_indirect_bounces > 0); + tree->error = get_render_aosss_error(&re->r, re->wrld.ao_approx_error); + tree->distfac = (re->wrld.aomode & WO_AODIST) ? re->wrld.aodistfac : 0.0f; + tree->doindirect = (re->wrld.ao_indirect_energy > 0.0f && re->wrld.ao_indirect_bounces > 0); /* allocation */ - tree->arena= BLI_memarena_new(0x8000 * sizeof(OccNode), "occ tree arena"); + tree->arena = BLI_memarena_new(0x8000 * sizeof(OccNode), "occ tree arena"); BLI_memarena_use_calloc(tree->arena); if (re->wrld.aomode & WO_AOCACHE) - tree->cache= MEM_callocN(sizeof(OcclusionCache)*BLENDER_MAX_THREADS, "OcclusionCache"); + 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"); + 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) - tree->rad= MEM_callocN(sizeof(float)*3*totface, "OcclusionRad"); + 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++) { - obr= obi->obr; - for (a=0; a<obr->totvlak; a++) { - if ((a & 255)==0) vlr= obr->vlaknodes[a>>8].vlak; + 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; else vlr++; - ma= vlr->mat; + ma = vlr->mat; 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; + tree->face[b].obi = c; + tree->face[b].facenr = a; + tree->occlusion[b] = 1.0f; occ_face(&tree->face[b], tree->co[b], NULL, NULL); b++; } @@ -701,12 +701,12 @@ static OcclusionTree *occ_tree_build(Render *re) } /* threads */ - tree->totbuildthread= (re->r.threads > 1 && totface > 10000)? 8: 1; - tree->dothreadedbuild= (tree->totbuildthread > 1); + tree->totbuildthread = (re->r.threads > 1 && totface > 10000) ? 8 : 1; + tree->dothreadedbuild = (tree->totbuildthread > 1); /* recurse */ - tree->root= BLI_memarena_alloc(tree->arena, sizeof(OccNode)); - tree->maxdepth= 1; + tree->root = BLI_memarena_alloc(tree->arena, sizeof(OccNode)); + tree->maxdepth = 1; occ_build_recursive(tree, tree->root, 0, totface, 1); if (tree->doindirect) { @@ -715,12 +715,12 @@ static OcclusionTree *occ_tree_build(Render *re) } MEM_freeN(tree->co); - tree->co= NULL; + tree->co = NULL; occ_build_sh_normalize(tree->root); - for (a=0; a<BLENDER_MAX_THREADS; a++) - tree->stack[a]= MEM_callocN(sizeof(OccNode)*TOTCHILD*(tree->maxdepth+1), "OccStack"); + for (a = 0; a < BLENDER_MAX_THREADS; a++) + tree->stack[a] = MEM_callocN(sizeof(OccNode) * TOTCHILD * (tree->maxdepth + 1), "OccStack"); return tree; } @@ -731,7 +731,7 @@ static void occ_free_tree(OcclusionTree *tree) if (tree) { if (tree->arena) BLI_memarena_free(tree->arena); - for (a=0; a<BLENDER_MAX_THREADS; a++) + for (a = 0; a < BLENDER_MAX_THREADS; a++) if (tree->stack[a]) MEM_freeN(tree->stack[a]); if (tree->occlusion) MEM_freeN(tree->occlusion); @@ -749,36 +749,38 @@ static float occ_solid_angle(OccNode *node, const float v[3], float d2, float in float dotreceive, dotemit; float ev[3]; - ev[0]= -v[0]*invd2; - ev[1]= -v[1]*invd2; - ev[2]= -v[2]*invd2; - dotemit= sh_eval(node->sh, ev); - dotreceive= dot_v3v3(receivenormal, v)*invd2; + ev[0] = -v[0] * invd2; + ev[1] = -v[1] * invd2; + ev[2] = -v[2] * invd2; + dotemit = sh_eval(node->sh, ev); + dotreceive = dot_v3v3(receivenormal, v) * invd2; CLAMP(dotemit, 0.0f, 1.0f); CLAMP(dotreceive, 0.0f, 1.0f); - return ((node->area*dotemit*dotreceive)/(d2 + node->area*INVPI))*INVPI; + return ((node->area * dotemit * dotreceive) / (d2 + node->area * INVPI)) * INVPI; } -static void VecAddDir(float result[3], const float v1[3], const float v2[3], const float fac) +static void vec_add_dir(float r[3], const float v1[3], const float v2[3], const float fac) { - result[0]= v1[0] + fac*(v2[0] - v1[0]); - result[1]= v1[1] + fac*(v2[1] - v1[1]); - result[2]= v1[2] + fac*(v2[2] - v1[2]); + r[0] = v1[0] + fac * (v2[0] - v1[0]); + r[1] = v1[1] + fac * (v2[1] - v1[1]); + r[2] = v1[2] + fac * (v2[2] - v1[2]); } -static int occ_visible_quad(float *p, const float n[3], const float v0[3], const float *v1, const float *v2, float q0[3], float q1[3], float q2[3], float q3[3]) +static int occ_visible_quad(const float p[3], const float n[3], + const float v0[3], const float v1[3], const float v2[3], + float q0[3], float q1[3], float q2[3], float q3[3]) { static const float epsilon = 1e-6f; float c, sd[3]; - c= dot_v3v3(n, p); + c = dot_v3v3(n, p); /* signed distances from the vertices to the plane. */ - sd[0]= dot_v3v3(n, v0) - c; - sd[1]= dot_v3v3(n, v1) - c; - sd[2]= dot_v3v3(n, v2) - c; + sd[0] = dot_v3v3(n, v0) - c; + 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; @@ -787,21 +789,21 @@ static int occ_visible_quad(float *p, const float n[3], const float v0[3], const 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) { - // ++- + /* ++- */ copy_v3_v3(q0, v0); copy_v3_v3(q1, v1); - VecAddDir(q2, v1, v2, (sd[1]/(sd[1]-sd[2]))); - VecAddDir(q3, v0, v2, (sd[0]/(sd[0]-sd[2]))); + vec_add_dir(q2, v1, v2, (sd[1] / (sd[1] - sd[2]))); + vec_add_dir(q3, v0, v2, (sd[0] / (sd[0] - sd[2]))); } else { - // ++0 + /* ++0 */ copy_v3_v3(q0, v0); copy_v3_v3(q1, v1); copy_v3_v3(q2, v2); @@ -810,44 +812,44 @@ 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) { - // +-+ + /* +-+ */ 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]))); + vec_add_dir(q1, v0, v1, (sd[0] / (sd[0] - sd[1]))); + vec_add_dir(q2, v1, v2, (sd[1] / (sd[1] - sd[2]))); copy_v3_v3(q3, v2); } else if (sd[2] < 0) { - // +-- + /* +-- */ copy_v3_v3(q0, v0); - VecAddDir(q1, v0, v1, (sd[0]/(sd[0]-sd[1]))); - VecAddDir(q2, v0, v2, (sd[0]/(sd[0]-sd[2]))); + vec_add_dir(q1, v0, v1, (sd[0] / (sd[0] - sd[1]))); + vec_add_dir(q2, v0, v2, (sd[0] / (sd[0] - sd[2]))); copy_v3_v3(q3, q2); } else { - // +-0 + /* +-0 */ copy_v3_v3(q0, v0); - VecAddDir(q1, v0, v1, (sd[0]/(sd[0]-sd[1]))); + vec_add_dir(q1, v0, v1, (sd[0] / (sd[0] - sd[1]))); copy_v3_v3(q2, v2); copy_v3_v3(q3, q2); } } else { if (sd[2] > 0) { - // +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) { - // +0- + /* +0- */ copy_v3_v3(q0, v0); copy_v3_v3(q1, v1); - VecAddDir(q2, v0, v2, (sd[0]/(sd[0]-sd[2]))); + vec_add_dir(q2, v0, v2, (sd[0] / (sd[0] - sd[2]))); copy_v3_v3(q3, q2); } else { - // +00 + /* +00 */ copy_v3_v3(q0, v0); copy_v3_v3(q1, v1); copy_v3_v3(q2, v2); @@ -858,22 +860,22 @@ 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) { - // -++ - VecAddDir(q0, v0, v1, (sd[0]/(sd[0]-sd[1]))); + /* -++ */ + vec_add_dir(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]))); + vec_add_dir(q3, v0, v2, (sd[0] / (sd[0] - sd[2]))); } else if (sd[2] < 0) { - // -+- - VecAddDir(q0, v0, v1, (sd[0]/(sd[0]-sd[1]))); + /* -+- */ + vec_add_dir(q0, v0, v1, (sd[0] / (sd[0] - sd[1]))); copy_v3_v3(q1, v1); - VecAddDir(q2, v1, v2, (sd[1]/(sd[1]-sd[2]))); + vec_add_dir(q2, v1, v2, (sd[1] / (sd[1] - sd[2]))); copy_v3_v3(q3, q2); } else { - // -+0 - VecAddDir(q0, v0, v1, (sd[0]/(sd[0]-sd[1]))); + /* -+0 */ + vec_add_dir(q0, v0, v1, (sd[0] / (sd[0] - sd[1]))); copy_v3_v3(q1, v1); copy_v3_v3(q2, v2); copy_v3_v3(q3, q2); @@ -881,35 +883,35 @@ 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) { - // --+ - VecAddDir(q0, v0, v2, (sd[0]/(sd[0]-sd[2]))); - VecAddDir(q1, v1, v2, (sd[1]/(sd[1]-sd[2]))); + /* --+ */ + vec_add_dir(q0, v0, v2, (sd[0] / (sd[0] - sd[2]))); + vec_add_dir(q1, v1, v2, (sd[1] / (sd[1] - sd[2]))); copy_v3_v3(q2, v2); copy_v3_v3(q3, q2); } else if (sd[2] < 0) { - // --- + /* --- */ return 0; } else { - // --0 + /* --0 */ return 0; } } else { if (sd[2] > 0) { - // -0+ - VecAddDir(q0, v0, v2, (sd[0]/(sd[0]-sd[2]))); + /* -0+ */ + vec_add_dir(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) { - // -0- + /* -0- */ return 0; } else { - // -00 + /* -00 */ return 0; } } @@ -917,21 +919,21 @@ 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) { - // 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) { - // 0+- + /* 0+- */ copy_v3_v3(q0, v0); copy_v3_v3(q1, v1); - VecAddDir(q2, v1, v2, (sd[1]/(sd[1]-sd[2]))); + vec_add_dir(q2, v1, v2, (sd[1] / (sd[1] - sd[2]))); copy_v3_v3(q3, q2); } else { - // 0+0 + /* 0+0 */ copy_v3_v3(q0, v0); copy_v3_v3(q1, v1); copy_v3_v3(q2, v2); @@ -940,35 +942,35 @@ 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) { - // 0-+ + /* 0-+ */ copy_v3_v3(q0, v0); - VecAddDir(q1, v1, v2, (sd[1]/(sd[1]-sd[2]))); + vec_add_dir(q1, v1, v2, (sd[1] / (sd[1] - sd[2]))); copy_v3_v3(q2, v2); copy_v3_v3(q3, q2); } else if (sd[2] < 0) { - // 0-- + /* 0-- */ return 0; } else { - // 0-0 + /* 0-0 */ return 0; } } else { if (sd[2] > 0) { - // 00+ + /* 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) { - // 00- + /* 00- */ return 0; } else { - // 000 + /* 000 */ return 0; } } @@ -995,49 +997,49 @@ static vFloat vec_splat_float(float 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)); - vrx = vrx*rlen; - vry = vry*rlen; - vrz = vrz*rlen; + rlen = vec_rsqrte(vrx * vrx + vry * vry + vrz * vrz + vec_splat_float(1e-16f)); + vrx = vrx * rlen; + vry = vry * rlen; + vrz = vrz * rlen; /* rotate r* for cross and dot */ - vsrx= vec_perm(vrx, vrx, rotate); - vsry= vec_perm(vry, vry, rotate); - vsrz= vec_perm(vrz, vrz, rotate); + vsrx = vec_perm(vrx, vrx, rotate); + vsry = vec_perm(vry, vry, rotate); + vsrz = vec_perm(vrz, vrz, rotate); /* cross product */ - gx = vsry*vrz - vsrz*vry; - gy = vsrz*vrx - vsrx*vrz; - gz = vsrx*vry - vsry*vrx; + gx = vsry * vrz - vsrz * vry; + gy = vsrz * vrx - vsrx * vrz; + gz = vsrx * vry - vsry * vrx; /* normalize */ - rlen = vec_rsqrte(gx*gx + gy*gy + gz*gz + vec_splat_float(1e-16f)); - gx = gx*rlen; - gy = gy*rlen; - gz = gz*rlen; + rlen = vec_rsqrte(gx * gx + gy * gy + gz * gz + vec_splat_float(1e-16f)); + gx = gx * rlen; + gy = gy * rlen; + gz = gz * rlen; /* angle */ - vcos = vrx*vsrx + vry*vsry + vrz*vsrz; - vcos= vec_max(vec_min(vcos, vec_splat_float(1.0f)), vec_splat_float(-1.0f)); - vangle= vacosf(vcos); + vcos = vrx * vsrx + vry * vsry + vrz * vsrz; + vcos = vec_max(vec_min(vcos, vec_splat_float(1.0f)), vec_splat_float(-1.0f)); + vangle = vacosf(vcos); /* dot */ - vresult.v = (vec_splat_float(n[0])*gx + - vec_splat_float(n[1])*gy + - vec_splat_float(n[2])*gz)*vangle; + vresult.v = (vec_splat_float(n[0]) * gx + + vec_splat_float(n[1]) * gy + + vec_splat_float(n[2]) * gz) * vangle; - result= (vresult.f[0] + vresult.f[1] + vresult.f[2] + vresult.f[3])*(0.5f/(float)M_PI); - result= MAX2(result, 0.0f); + result = (vresult.f[0] + vresult.f[1] + vresult.f[2] + vresult.f[3]) * (0.5f / (float)M_PI); + result = MAX2(result, 0.0f); return result; } @@ -1053,8 +1055,8 @@ static float occ_quad_form_factor(float *p, float *n, float *q0, float *q1, floa static __m128 sse_approx_acos(__m128 x) { /* needs a better approximation than taylor expansion of acos, since that - * gives big erros for near 1.0 values, sqrt(2*x)*acos(1-x) should work - * better, see http://www.tom.womack.net/projects/sse-fast-arctrig.html */ + * gives big erros for near 1.0 values, sqrt(2*x)*acos(1-x) should work + * better, see http://www.tom.womack.net/projects/sse-fast-arctrig.html */ return _mm_set_ps1(1.0f); } @@ -1076,36 +1078,36 @@ static float occ_quad_form_factor(float *p, float *n, float *q0, float *q1, floa rz = qz - _mm_set_ps1(p[2]); /* normalize r */ - rlen = _mm_rsqrt_ps(rx*rx + ry*ry + rz*rz + _mm_set_ps1(1e-16f)); - rx = rx*rlen; - ry = ry*rlen; - rz = rz*rlen; + rlen = _mm_rsqrt_ps(rx * rx + ry * ry + rz * rz + _mm_set_ps1(1e-16f)); + rx = rx * rlen; + ry = ry * rlen; + rz = rz * rlen; /* cross product */ - srx = _mm_shuffle_ps(rx, rx, _MM_SHUFFLE(0,3,2,1)); - sry = _mm_shuffle_ps(ry, ry, _MM_SHUFFLE(0,3,2,1)); - srz = _mm_shuffle_ps(rz, rz, _MM_SHUFFLE(0,3,2,1)); + srx = _mm_shuffle_ps(rx, rx, _MM_SHUFFLE(0, 3, 2, 1)); + sry = _mm_shuffle_ps(ry, ry, _MM_SHUFFLE(0, 3, 2, 1)); + srz = _mm_shuffle_ps(rz, rz, _MM_SHUFFLE(0, 3, 2, 1)); - gx = sry*rz - srz*ry; - gy = srz*rx - srx*rz; - gz = srx*ry - sry*rx; + gx = sry * rz - srz * ry; + gy = srz * rx - srx * rz; + gz = srx * ry - sry * rx; /* normalize g */ - glen = _mm_rsqrt_ps(gx*gx + gy*gy + gz*gz + _mm_set_ps1(1e-16f)); - gx = gx*glen; - gy = gy*glen; - gz = gz*glen; + glen = _mm_rsqrt_ps(gx * gx + gy * gy + gz * gz + _mm_set_ps1(1e-16f)); + gx = gx * glen; + gy = gy * glen; + gz = gz * glen; /* compute angle */ - rcos = rx*srx + ry*sry + rz*srz; - rcos= _mm_max_ps(_mm_min_ps(rcos, _mm_set_ps1(1.0f)), _mm_set_ps1(-1.0f)); + rcos = rx * srx + ry * sry + rz * srz; + rcos = _mm_max_ps(_mm_min_ps(rcos, _mm_set_ps1(1.0f)), _mm_set_ps1(-1.0f)); angle = sse_approx_cos(rcos); - aresult = (_mm_set_ps1(n[0])*gx + _mm_set_ps1(n[1])*gy + _mm_set_ps1(n[2])*gz)*angle; + aresult = (_mm_set_ps1(n[0]) * gx + _mm_set_ps1(n[1]) * gy + _mm_set_ps1(n[2]) * gz) * angle; /* sum together */ - result= (fresult[0] + fresult[1] + fresult[2] + fresult[3])*(0.5f/(float)M_PI); - result= MAX2(result, 0.0f); + result = (fresult[0] + fresult[1] + fresult[2] + fresult[3]) * (0.5f / (float)M_PI); + result = MAX2(result, 0.0f); return result; } @@ -1116,10 +1118,10 @@ static void normalizef(float *n) { float d; - d= dot_v3v3(n, n); + d = dot_v3v3(n, n); if (d > 1.0e-35F) { - d= 1.0f/sqrtf(d); + d = 1.0f / sqrtf(d); n[0] *= d; n[1] *= d; @@ -1147,18 +1149,18 @@ static float occ_quad_form_factor(const float p[3], const float n[3], const floa cross_v3_v3v3(g2, r3, r2); normalizef(g2); cross_v3_v3v3(g3, r0, r3); normalizef(g3); - a1= saacosf(dot_v3v3(r0, r1)); - a2= saacosf(dot_v3v3(r1, r2)); - a3= saacosf(dot_v3v3(r2, r3)); - a4= saacosf(dot_v3v3(r3, r0)); + a1 = saacosf(dot_v3v3(r0, r1)); + a2 = saacosf(dot_v3v3(r1, r2)); + a3 = saacosf(dot_v3v3(r2, r3)); + a4 = saacosf(dot_v3v3(r3, r0)); - dot1= dot_v3v3(n, g0); - dot2= dot_v3v3(n, g1); - dot3= dot_v3v3(n, g2); - dot4= dot_v3v3(n, g3); + dot1 = dot_v3v3(n, g0); + dot2 = dot_v3v3(n, g1); + dot3 = dot_v3v3(n, g2); + dot4 = dot_v3v3(n, g3); - result= (a1*dot1 + a2*dot2 + a3*dot3 + a4*dot4)*0.5f/(float)M_PI; - result= MAX2(result, 0.0f); + result = (a1 * dot1 + a2 * dot2 + a3 * dot3 + a4 * dot4) * 0.5f / (float)M_PI; + result = MAX2(result, 0.0f); return result; } @@ -1167,10 +1169,10 @@ static float occ_form_factor(OccFace *face, float *p, float *n) { ObjectInstanceRen *obi; VlakRen *vlr; - float v1[3], v2[3], v3[3], v4[3], q0[3], q1[3], q2[3], q3[3], contrib= 0.0f; + float v1[3], v2[3], v3[3], v4[3], q0[3], q1[3], q2[3], q3[3], contrib = 0.0f; - obi= &R.objectinstance[face->obi]; - vlr= RE_findOrAddVlak(obi->obr, face->facenr); + obi = &R.objectinstance[face->obi]; + vlr = RE_findOrAddVlak(obi->obr, face->facenr); copy_v3_v3(v1, vlr->v1->co); copy_v3_v3(v2, vlr->v2->co); @@ -1214,103 +1216,103 @@ static void occ_lookup(OcclusionTree *tree, int thread, OccFace *exclude, if (bentn) copy_v3_v3(bentn, n); - error= tree->error; - distfac= tree->distfac; + error = tree->error; + distfac = tree->distfac; - resultocc= 0.0f; + resultocc = 0.0f; zero_v3(resultrad); /* init stack */ - stack= tree->stack[thread]; - stack[0]= tree->root; - totstack= 1; + stack = tree->stack[thread]; + stack[0] = tree->root; + totstack = 1; while (totstack) { /* pop point off the stack */ - node= stack[--totstack]; + node = stack[--totstack]; sub_v3_v3v3(v, node->co, p); - d2= dot_v3v3(v, v) + 1e-16f; - emitarea= MAX2(node->area, node->dco); + d2 = dot_v3v3(v, v) + 1e-16f; + emitarea = MAX2(node->area, node->dco); - if (d2*error > emitarea) { + if (d2 * error > emitarea) { if (distfac != 0.0f) { - fac= 1.0f/(1.0f + distfac*d2); + fac = 1.0f / (1.0f + distfac * d2); if (fac < 0.01f) continue; } else - fac= 1.0f; + fac = 1.0f; /* accumulate occlusion from spherical harmonics */ - invd2 = 1.0f/sqrtf(d2); - weight= occ_solid_angle(node, v, d2, invd2, n); + invd2 = 1.0f / sqrtf(d2); + weight = occ_solid_angle(node, v, d2, invd2, n); if (rad) - madd_v3_v3fl(resultrad, node->rad, weight*fac); + madd_v3_v3fl(resultrad, node->rad, weight * fac); weight *= node->occlusion; if (bentn) { - bentn[0] -= weight*invd2*v[0]; - bentn[1] -= weight*invd2*v[1]; - bentn[2] -= weight*invd2*v[2]; + bentn[0] -= weight * invd2 * v[0]; + bentn[1] -= weight * invd2 * v[1]; + bentn[2] -= weight * invd2 * v[2]; } - resultocc += weight*fac; + resultocc += weight * fac; } else { /* traverse into children */ - for (b=0; b<TOTCHILD; b++) { - if (node->childflag & (1<<b)) { - f= node->child[b].face; - face= &tree->face[f]; + 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) { occ_face(face, co, NULL, NULL); sub_v3_v3v3(v, co, p); - d2= dot_v3v3(v, v) + 1e-16f; + d2 = dot_v3v3(v, v) + 1e-16f; - fac= (distfac == 0.0f)? 1.0f: 1.0f/(1.0f + distfac*d2); + fac = (distfac == 0.0f) ? 1.0f : 1.0f / (1.0f + distfac * d2); if (fac < 0.01f) continue; } else - fac= 1.0f; + fac = 1.0f; - weight= occ_form_factor(face, p, n); + weight = occ_form_factor(face, p, n); if (rad) - madd_v3_v3fl(resultrad, tree->rad[f], weight*fac); + madd_v3_v3fl(resultrad, tree->rad[f], weight * fac); weight *= tree->occlusion[f]; if (bentn) { - invd2= 1.0f/sqrtf(d2); - bentn[0] -= weight*invd2*v[0]; - bentn[1] -= weight*invd2*v[1]; - bentn[2] -= weight*invd2*v[2]; + invd2 = 1.0f / sqrtf(d2); + bentn[0] -= weight * invd2 * v[0]; + bentn[1] -= weight * invd2 * v[1]; + bentn[2] -= weight * invd2 * v[2]; } - resultocc += weight*fac; + resultocc += weight * fac; } } else if (node->child[b].node) { /* push child on the stack */ - stack[totstack++]= node->child[b].node; + stack[totstack++] = node->child[b].node; } } } } - if (occ) *occ= resultocc; + if (occ) *occ = resultocc; if (rad) copy_v3_v3(rad, resultrad); #if 0 if (rad && exclude) { int a; - for (a=0; a<tree->totface; a++) + 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]); } @@ -1323,18 +1325,18 @@ static void occ_compute_bounces(Render *re, OcclusionTree *tree, int totbounce) float (*rad)[3], (*sum)[3], (*tmp)[3], co[3], n[3], occ; int bounce, i; - rad= MEM_callocN(sizeof(float)*3*tree->totface, "OcclusionBounceRad"); - sum= MEM_dupallocN(tree->rad); + 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); occ_lookup(tree, 0, &tree->face[i], co, n, &occ, rad[i], NULL); - rad[i][0]= MAX2(rad[i][0], 0.0f); - rad[i][1]= MAX2(rad[i][1], 0.0f); - rad[i][2]= MAX2(rad[i][2], 0.0f); + rad[i][0] = MAX2(rad[i][0], 0.0f); + rad[i][1] = MAX2(rad[i][1], 0.0f); + rad[i][2] = MAX2(rad[i][2], 0.0f); add_v3_v3(sum[i], rad[i]); if (re->test_break(re->tbh)) @@ -1344,16 +1346,16 @@ static void occ_compute_bounces(Render *re, OcclusionTree *tree, int totbounce) if (re->test_break(re->tbh)) break; - tmp= tree->rad; - tree->rad= rad; - rad= tmp; + tmp = tree->rad; + tree->rad = rad; + rad = tmp; occ_sum_occlusion(tree, tree->root); } MEM_freeN(rad); MEM_freeN(tree->rad); - tree->rad= sum; + tree->rad = sum; if (!re->test_break(re->tbh)) occ_sum_occlusion(tree, tree->root); @@ -1364,10 +1366,10 @@ static void occ_compute_passes(Render *re, OcclusionTree *tree, int totpass) float *occ, co[3], n[3]; int pass, i; - occ= MEM_callocN(sizeof(float)*tree->totface, "OcclusionPassOcc"); + 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); @@ -1380,10 +1382,10 @@ static void occ_compute_passes(Render *re, OcclusionTree *tree, int totpass) 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) - tree->occlusion[i]= 0.0f; + tree->occlusion[i] = 0.0f; } occ_sum_occlusion(tree, tree->root); @@ -1399,25 +1401,25 @@ static void sample_occ_tree(Render *re, OcclusionTree *tree, OccFace *exclude, float nn[3], bn[3], fac, occ, occlusion, correction, rad[3]; int envcolor; - envcolor= re->wrld.aocolor; + envcolor = re->wrld.aocolor; if (onlyshadow) - envcolor= WO_AOPLAIN; + envcolor = WO_AOPLAIN; negate_v3_v3(nn, n); - occ_lookup(tree, thread, exclude, co, nn, &occ, (tree->doindirect)? rad: NULL, (env && envcolor)? bn: NULL); + occ_lookup(tree, thread, exclude, co, nn, &occ, (tree->doindirect) ? rad : NULL, (env && envcolor) ? bn : NULL); - correction= re->wrld.ao_approx_correction; + correction = re->wrld.ao_approx_correction; - occlusion= (1.0f-correction)*(1.0f-occ); + occlusion = (1.0f - correction) * (1.0f - occ); CLAMP(occlusion, 0.0f, 1.0f); if (correction != 0.0f) - occlusion += correction*expf(-occ); + occlusion += correction * expf(-occ); if (env) { /* sky shading using bent normal */ if (ELEM(envcolor, WO_AOSKYCOL, WO_AOSKYTEX)) { - fac= 0.5f * (1.0f + dot_v3v3(bn, re->grvec)); + fac = 0.5f * (1.0f + dot_v3v3(bn, re->grvec)); env[0] = (1.0f - fac) * re->wrld.horr + fac * re->wrld.zenr; env[1] = (1.0f - fac) * re->wrld.horg + fac * re->wrld.zeng; env[2] = (1.0f - fac) * re->wrld.horb + fac * re->wrld.zenb; @@ -1425,28 +1427,28 @@ static void sample_occ_tree(Render *re, OcclusionTree *tree, OccFace *exclude, mul_v3_fl(env, occlusion); } else { - env[0]= occlusion; - env[1]= occlusion; - env[2]= occlusion; + env[0] = occlusion; + env[1] = occlusion; + env[2] = occlusion; } #if 0 - else { /* WO_AOSKYTEX */ + else { /* WO_AOSKYTEX */ float dxyview[3]; - bn[0]= -bn[0]; - bn[1]= -bn[1]; - bn[2]= -bn[2]; - dxyview[0]= 1.0f; - dxyview[1]= 1.0f; - dxyview[2]= 0.0f; + bn[0] = -bn[0]; + bn[1] = -bn[1]; + bn[2] = -bn[2]; + dxyview[0] = 1.0f; + dxyview[1] = 1.0f; + dxyview[2] = 0.0f; shadeSkyView(ao, co, bn, dxyview); } #endif } if (ao) { - ao[0]= occlusion; - ao[1]= occlusion; - ao[2]= occlusion; + ao[0] = occlusion; + ao[1] = occlusion; + ao[2] = occlusion; } if (tree->doindirect) copy_v3_v3(indirect, rad); @@ -1468,7 +1470,7 @@ static OcclusionCacheSample *find_occ_sample(OcclusionCache *cache, int x, int y if (x < 0 || x >= cache->w || y < 0 || y >= cache->h) return NULL; else - return &cache->sample[y*cache->w + x]; + return &cache->sample[y * cache->w + x]; } static int sample_occ_cache(OcclusionTree *tree, float *co, float *n, int x, int y, int thread, float *ao, float *env, float *indirect) @@ -1483,14 +1485,14 @@ static int sample_occ_cache(OcclusionTree *tree, float *co, float *n, int x, int return 0; /* first try to find a sample in the same pixel */ - cache= &tree->cache[thread]; + cache = &tree->cache[thread]; if (cache->sample && cache->step) { - sample= &cache->sample[(y-cache->y)*cache->w + (x-cache->x)]; + sample = &cache->sample[(y - cache->y) * cache->w + (x - cache->x)]; 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) { + dist2 = dot_v3v3(d, d); + 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); @@ -1502,18 +1504,18 @@ static int sample_occ_cache(OcclusionTree *tree, float *co, float *n, int x, int return 0; /* try to interpolate between 4 neighboring pixels */ - samples[0]= find_occ_sample(cache, x, y); - samples[1]= find_occ_sample(cache, x+cache->step, y); - samples[2]= find_occ_sample(cache, x, y+cache->step); - samples[3]= find_occ_sample(cache, x+cache->step, y+cache->step); + samples[0] = find_occ_sample(cache, x, y); + samples[1] = find_occ_sample(cache, x + cache->step, y); + 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++) + 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); + 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) return 0; @@ -1522,29 +1524,29 @@ static int sample_occ_cache(OcclusionTree *tree, float *co, float *n, int x, int zero_v3(ao); zero_v3(env); zero_v3(indirect); - totw= 0.0f; + totw = 0.0f; - x1= samples[0]->x; - y1= samples[0]->y; - x2= samples[3]->x; - y2= samples[3]->y; + x1 = samples[0]->x; + y1 = samples[0]->y; + x2 = samples[3]->x; + y2 = samples[3]->y; - tx= (float)(x2 - x)/(float)(x2 - x1); - ty= (float)(y2 - y)/(float)(y2 - y1); + tx = (float)(x2 - x) / (float)(x2 - x1); + ty = (float)(y2 - y) / (float)(y2 - y1); - wb[3]= (1.0f-tx)*(1.0f-ty); - wb[2]= (tx)*(1.0f-ty); - wb[1]= (1.0f-tx)*(ty); - wb[0]= tx*ty; + wb[3] = (1.0f - tx) * (1.0f - ty); + wb[2] = (tx) * (1.0f - ty); + 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); - wz[i]= 1.0f; //(samples[i]->dist2/(1e-4f + dist2)); - wn[i]= pow(dot_v3v3(samples[i]->n, n), 32.0f); + wz[i] = 1.0f; //(samples[i]->dist2/(1e-4f + dist2)); + wn[i] = pow(dot_v3v3(samples[i]->n, n), 32.0f); - w= wb[i]*wn[i]*wz[i]; + w = wb[i] * wn[i] * wz[i]; totw += w; madd_v3_v3fl(ao, samples[i]->ao, w); @@ -1553,7 +1555,7 @@ static int sample_occ_cache(OcclusionTree *tree, float *co, float *n, int x, int } if (totw >= 0.9f) { - totw= 1.0f/totw; + totw = 1.0f / totw; mul_v3_fl(ao, totw); mul_v3_fl(env, totw); mul_v3_fl(indirect, totw); @@ -1565,18 +1567,18 @@ static int sample_occ_cache(OcclusionTree *tree, float *co, float *n, int x, int static void sample_occ_surface(ShadeInput *shi) { - StrandRen *strand= shi->strand; - StrandSurface *mesh= strand->buffer->surface; + StrandRen *strand = shi->strand; + StrandSurface *mesh = strand->buffer->surface; 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) { - face= mesh->face[*index]; + face = mesh->face[*index]; - co1= mesh->co[face[0]]; - co2= mesh->co[face[1]]; - co3= mesh->co[face[2]]; - co4= (face[3])? mesh->co[face[3]]: NULL; + co1 = mesh->co[face[0]]; + co2 = mesh->co[face[1]]; + co3 = mesh->co[face[2]]; + co4 = (face[3]) ? mesh->co[face[3]] : NULL; interp_weights_face_v3(w, co1, co2, co3, co4, strand->vert->co); @@ -1600,9 +1602,9 @@ static void sample_occ_surface(ShadeInput *shi) } } else { - shi->ao[0]= 1.0f; - shi->ao[1]= 1.0f; - shi->ao[2]= 1.0f; + shi->ao[0] = 1.0f; + shi->ao[1] = 1.0f; + shi->ao[2] = 1.0f; zero_v3(shi->env); zero_v3(shi->indirect); } @@ -1612,20 +1614,20 @@ static void sample_occ_surface(ShadeInput *shi) static void *exec_strandsurface_sample(void *data) { - OcclusionThread *othread= (OcclusionThread*)data; - Render *re= othread->re; - StrandSurface *mesh= othread->mesh; + OcclusionThread *othread = (OcclusionThread *)data; + Render *re = othread->re; + StrandSurface *mesh = othread->mesh; 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++) { - face= mesh->face[a]; - co1= mesh->co[face[0]]; - co2= mesh->co[face[1]]; - co3= mesh->co[face[2]]; + 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]) { - co4= mesh->co[face[3]]; + co4 = mesh->co[face[3]]; mid_v3_v3v3(co, co1, co3); normal_quad_v3(n, co1, co2, co3, co4); @@ -1655,12 +1657,12 @@ void make_occ_tree(Render *re) int a, totface, totthread, *face, *count; /* ugly, needed for occ_face */ - R= *re; + R = *re; - re->i.infostr= "Occlusion preprocessing"; + re->i.infostr = "Occlusion preprocessing"; re->stats_draw(re->sdh, &re->i); - re->occlusiontree= tree= occ_tree_build(re); + re->occlusiontree = tree = occ_tree_build(re); if (tree) { if (re->wrld.ao_approx_passes > 0) @@ -1668,26 +1670,26 @@ void make_occ_tree(Render *re) 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) { + 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"); - faceao= MEM_callocN(sizeof(float)*3*mesh->totface, "StrandSurfFaceAO"); - faceenv= MEM_callocN(sizeof(float)*3*mesh->totface, "StrandSurfFaceEnv"); - faceindirect= MEM_callocN(sizeof(float)*3*mesh->totface, "StrandSurfFaceIndirect"); - - totthread= (mesh->totface > 10000)? re->r.threads: 1; - totface= mesh->totface/totthread; - for (a=0; a<totthread; a++) { - othreads[a].re= re; - othreads[a].faceao= faceao; - othreads[a].faceenv= faceenv; - othreads[a].faceindirect= faceindirect; - othreads[a].thread= a; - othreads[a].mesh= mesh; - othreads[a].begin= a*totface; - othreads[a].end= (a == totthread-1)? mesh->totface: (a+1)*totface; + count = MEM_callocN(sizeof(int) * mesh->totvert, "OcclusionCount"); + faceao = MEM_callocN(sizeof(float) * 3 * mesh->totface, "StrandSurfFaceAO"); + faceenv = MEM_callocN(sizeof(float) * 3 * mesh->totface, "StrandSurfFaceEnv"); + faceindirect = MEM_callocN(sizeof(float) * 3 * mesh->totface, "StrandSurfFaceIndirect"); + + totthread = (mesh->totface > 10000) ? re->r.threads : 1; + totface = mesh->totface / totthread; + for (a = 0; a < totthread; a++) { + othreads[a].re = re; + othreads[a].faceao = faceao; + othreads[a].faceenv = faceenv; + othreads[a].faceindirect = faceindirect; + othreads[a].thread = a; + othreads[a].mesh = mesh; + othreads[a].begin = a * totface; + othreads[a].end = (a == totthread - 1) ? mesh->totface : (a + 1) * totface; } if (totthread == 1) { @@ -1696,14 +1698,14 @@ void make_occ_tree(Render *re) 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++) { - face= mesh->face[a]; + for (a = 0; a < mesh->totface; a++) { + face = mesh->face[a]; copy_v3_v3(ao, faceao[a]); copy_v3_v3(env, faceenv[a]); @@ -1730,11 +1732,11 @@ void make_occ_tree(Render *re) } } - for (a=0; a<mesh->totvert; 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]); + 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]); } } @@ -1756,7 +1758,7 @@ void free_occ(Render *re) void sample_occ(Render *re, ShadeInput *shi) { - OcclusionTree *tree= re->occlusiontree; + OcclusionTree *tree = re->occlusiontree; OcclusionCache *cache; OcclusionCacheSample *sample; OccFace exclude; @@ -1767,91 +1769,91 @@ void sample_occ(Render *re, ShadeInput *shi) 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; - onlyshadow= (shi->mat->mode & MA_ONLYSHADOW); + exclude.obi = shi->obi - re->objectinstance; + exclude.facenr = shi->vlr->index; + onlyshadow = (shi->mat->mode & MA_ONLYSHADOW); 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) { - cache= &tree->cache[shi->thread]; + cache = &tree->cache[shi->thread]; if (cache->sample && cache->step) { - sample= &cache->sample[(shi->ys-cache->y)*cache->w + (shi->xs-cache->x)]; + 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); copy_v3_v3(sample->ao, shi->ao); copy_v3_v3(sample->env, shi->env); copy_v3_v3(sample->indirect, shi->indirect); - sample->intensity= MAX3(sample->ao[0], sample->ao[1], sample->ao[2]); - sample->intensity= MAX2(sample->intensity, MAX3(sample->env[0], sample->env[1], sample->env[2])); - sample->intensity= MAX2(sample->intensity, MAX3(sample->indirect[0], sample->indirect[1], sample->indirect[2])); - sample->dist2= dot_v3v3(shi->dxco, shi->dxco) + dot_v3v3(shi->dyco, shi->dyco); - sample->filled= 1; + sample->intensity = MAX3(sample->ao[0], sample->ao[1], sample->ao[2]); + sample->intensity = MAX2(sample->intensity, MAX3(sample->env[0], sample->env[1], sample->env[2])); + sample->intensity = MAX2(sample->intensity, MAX3(sample->indirect[0], sample->indirect[1], sample->indirect[2])); + sample->dist2 = dot_v3v3(shi->dxco, shi->dxco) + dot_v3v3(shi->dyco, shi->dyco); + sample->filled = 1; } } } } else { - shi->ao[0]= 1.0f; - shi->ao[1]= 1.0f; - shi->ao[2]= 1.0f; + shi->ao[0] = 1.0f; + shi->ao[1] = 1.0f; + shi->ao[2] = 1.0f; - shi->env[0]= 0.0f; - shi->env[1]= 0.0f; - shi->env[2]= 0.0f; + shi->env[0] = 0.0f; + shi->env[1] = 0.0f; + shi->env[2] = 0.0f; - shi->indirect[0]= 0.0f; - shi->indirect[1]= 0.0f; - shi->indirect[2]= 0.0f; + shi->indirect[0] = 0.0f; + shi->indirect[1] = 0.0f; + shi->indirect[2] = 0.0f; } } void cache_occ_samples(Render *re, RenderPart *pa, ShadeSample *ssamp) { - OcclusionTree *tree= re->occlusiontree; + OcclusionTree *tree = re->occlusiontree; PixStr ps; OcclusionCache *cache; OcclusionCacheSample *sample; OccFace exclude; ShadeInput *shi; - intptr_t *rd=NULL; - int *ro=NULL, *rp=NULL, *rz=NULL, onlyshadow; + intptr_t *rd = NULL; + int *ro = NULL, *rp = NULL, *rz = NULL, onlyshadow; int x, y, step = CACHE_STEP; if (!tree->cache) return; - cache= &tree->cache[pa->thread]; - cache->w= pa->rectx; - cache->h= pa->recty; - cache->x= pa->disprect.xmin; - cache->y= pa->disprect.ymin; - cache->step= step; - cache->sample= MEM_callocN(sizeof(OcclusionCacheSample)*cache->w*cache->h, "OcclusionCacheSample"); - sample= cache->sample; + cache = &tree->cache[pa->thread]; + cache->w = pa->rectx; + cache->h = pa->recty; + cache->x = pa->disprect.xmin; + cache->y = pa->disprect.ymin; + cache->step = step; + cache->sample = MEM_callocN(sizeof(OcclusionCacheSample) * cache->w * cache->h, "OcclusionCacheSample"); + sample = cache->sample; if (re->osa) { - rd= pa->rectdaps; + rd = pa->rectdaps; } else { /* fake pixel struct for non-osa */ - ps.next= NULL; - ps.mask= 0xFFFF; + ps.next = NULL; + ps.mask = 0xFFFF; - ro= pa->recto; - rp= pa->rectp; - rz= pa->rectz; + ro = pa->recto; + rp = pa->rectp; + rz = pa->rectz; } /* 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) { @@ -1862,17 +1864,17 @@ void cache_occ_samples(Render *re, RenderPart *pa, ShadeSample *ssamp) else { if (!*rp) continue; - ps.obi= *ro; - ps.facenr= *rp; - ps.z= *rz; + ps.obi = *ro; + ps.facenr = *rp; + ps.z = *rz; shade_samples_fill_with_ps(ssamp, &ps, x, y); } - shi= ssamp->shi; + shi = ssamp->shi; if (shi->vlr) { - onlyshadow= (shi->mat->mode & MA_ONLYSHADOW); - exclude.obi= shi->obi - re->objectinstance; - exclude.facenr= shi->vlr->index; + onlyshadow = (shi->mat->mode & MA_ONLYSHADOW); + exclude.obi = shi->obi - re->objectinstance; + exclude.facenr = shi->vlr->index; sample_occ_tree(re, tree, &exclude, shi->co, shi->vno, shi->thread, onlyshadow, shi->ao, shi->env, shi->indirect); copy_v3_v3(sample->co, shi->co); @@ -1880,13 +1882,13 @@ void cache_occ_samples(Render *re, RenderPart *pa, ShadeSample *ssamp) copy_v3_v3(sample->ao, shi->ao); copy_v3_v3(sample->env, shi->env); copy_v3_v3(sample->indirect, shi->indirect); - sample->intensity= MAX3(sample->ao[0], sample->ao[1], sample->ao[2]); - sample->intensity= MAX2(sample->intensity, MAX3(sample->env[0], sample->env[1], sample->env[2])); - sample->intensity= MAX2(sample->intensity, MAX3(sample->indirect[0], sample->indirect[1], sample->indirect[2])); - sample->dist2= dot_v3v3(shi->dxco, shi->dxco) + dot_v3v3(shi->dyco, shi->dyco); - sample->x= shi->xs; - sample->y= shi->ys; - sample->filled= 1; + sample->intensity = MAX3(sample->ao[0], sample->ao[1], sample->ao[2]); + sample->intensity = MAX2(sample->intensity, MAX3(sample->env[0], sample->env[1], sample->env[2])); + sample->intensity = MAX2(sample->intensity, MAX3(sample->indirect[0], sample->indirect[1], sample->indirect[2])); + sample->dist2 = dot_v3v3(shi->dxco, shi->dxco) + dot_v3v3(shi->dyco, shi->dyco); + sample->x = shi->xs; + sample->y = shi->ys; + sample->filled = 1; } if (re->test_break(re->tbh)) @@ -1897,18 +1899,18 @@ void cache_occ_samples(Render *re, RenderPart *pa, ShadeSample *ssamp) void free_occ_samples(Render *re, RenderPart *pa) { - OcclusionTree *tree= re->occlusiontree; + OcclusionTree *tree = re->occlusiontree; OcclusionCache *cache; if (tree->cache) { - cache= &tree->cache[pa->thread]; + cache = &tree->cache[pa->thread]; if (cache->sample) MEM_freeN(cache->sample); - cache->w= 0; - cache->h= 0; - cache->step= 0; + cache->w = 0; + cache->h = 0; + cache->step = 0; } } diff --git a/source/blender/render/intern/source/rayshade.c b/source/blender/render/intern/source/rayshade.c index f11e5d22574..8a936545903 100644 --- a/source/blender/render/intern/source/rayshade.c +++ b/source/blender/render/intern/source/rayshade.c @@ -99,7 +99,7 @@ static RayObject* RE_rayobject_create(Render *re, int type, int size) RayObject * res = NULL; if (type == R_RAYSTRUCTURE_AUTO) { - //TODO + /* TODO */ //if (detect_simd()) #ifdef __SSE__ type = BLI_cpu_support_sse2()? R_RAYSTRUCTURE_SIMD_SVBVH: R_RAYSTRUCTURE_VBVH; @@ -216,12 +216,12 @@ static int is_raytraceable(Render *re, ObjectInstanceRen *obi) RayObject* makeraytree_object(Render *re, ObjectInstanceRen *obi) { - //TODO - // out-of-memory safeproof - // break render - // update render stats + /*TODO + * out-of-memory safeproof + * break render + * update render stats */ ObjectRen *obr = obi->obr; - + if (obr->raytree == NULL) { RayObject *raytree; RayFace *face = NULL; @@ -421,8 +421,8 @@ void makeraytree(Render *re) re->stats_draw(re->sdh, &re->i); } else { - //Calculate raytree max_size - //This is ONLY needed to kept a bogus behavior of SUN and HEMI lights + /* Calculate raytree max_size + * 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++) { @@ -739,8 +739,8 @@ static void traceray(ShadeInput *origshi, ShadeResult *origshr, short depth, con tracol[0]= shi.r; tracol[1]= shi.g; tracol[2]= shi.b; - tracol[3]= col[3]; // we pass on and accumulate alpha - + tracol[3]= col[3]; /* we pass on and accumulate alpha */ + 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; @@ -883,12 +883,12 @@ static void DP_energy(float *table, float vec[2], int tot, float xsize, float ys } vec[0] += 0.1f*min*result[0]/(float)tot; vec[1] += 0.1f*min*result[1]/(float)tot; - // cyclic clamping + /* cyclic clamping */ vec[0]= vec[0] - xsize*floorf(vec[0]/xsize + 0.5f); vec[1]= vec[1] - ysize*floorf(vec[1]/ysize + 0.5f); } -// random offset of 1 in 2 +/* random offset of 1 in 2 */ static void jitter_plane_offset(float *jitter1, float *jitter2, int tot, float sizex, float sizey, float ofsx, float ofsy) { float dsizex= sizex*ofsx; @@ -974,10 +974,10 @@ static float *give_jitter_plane(LampRen *lar, int thread, int xs, int ys) static void halton_sample(double *ht_invprimes, double *ht_nums, double *v) { - // incremental halton sequence generator, from: - // "Instant Radiosity", Keller A. + /* incremental halton sequence generator, from: + * "Instant Radiosity", Keller A. */ unsigned int i; - + for (i = 0; i < 2; i++) { double r = fabs((1.0 - ht_nums[i]) - 1e-10); @@ -1812,7 +1812,7 @@ static float *sphere_sampler(int type, int resol, int thread, int xs, int ys, in float *sphere; int a; - // always returns table + /* always returns table */ sphere= threadsafe_table_sphere(0, thread, xs, ys, tot); /* total random sampling. NOT THREADSAFE! (should be removed, is not useful) */ @@ -1827,7 +1827,7 @@ static float *sphere_sampler(int type, int resol, int thread, int xs, int ys, in float *sphere; float *vec1; - // returns table if xs and ys were equal to last call, and not resetting + /* 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) { float cosfi, sinfi, cost, sint; @@ -1836,7 +1836,7 @@ static float *sphere_sampler(int type, int resol, int thread, int xs, int ys, in sphere= threadsafe_table_sphere(0, thread, xs, ys, tot); - // random rotation + /* random rotation */ ang= BLI_thread_frand(thread); sinfi= sin(ang); cosfi= cos(ang); ang= BLI_thread_frand(thread); @@ -2056,7 +2056,7 @@ static void ray_ao_spheresamp(ShadeInput *shi, float ao[3], float env[3]) * for strand render we always require a new sampler because x/y are not set */ vec= sphere_sampler(R.wrld.aomode, resol, shi->thread, shi->xs, shi->ys, shi->strand != NULL); - // warning: since we use full sphere now, and dotproduct is below, we do twice as much + /* warning: since we use full sphere now, and dotproduct is below, we do twice as much */ tot= 2*resol*resol; if (envcolor == WO_AOSKYTEX) { @@ -2116,7 +2116,7 @@ static void ray_ao_spheresamp(ShadeInput *shi, float ao[3], float env[3]) skyadded++; } } - // samples + /* samples */ vec+= 3; } @@ -2436,7 +2436,7 @@ static void ray_shadow_jitter(ShadeInput *shi, LampRen *lar, const float lampco[ shadfac[3] /= div; } else { - // sqrt makes nice umbra effect + /* sqrt makes nice umbra effect */ if (lar->ray_samp_type & LA_SAMP_UMBRA) shadfac[3]= sqrt(1.0f-fac/div); else @@ -2501,8 +2501,8 @@ void ray_shadow(ShadeInput *shi, LampRen *lar, float shadfac[4]) isec.orig.ob = shi->obi; isec.orig.face = shi->vlr; - shadfac[3]= 1.0f; // 1.0=full light - + shadfac[3]= 1.0f; /* 1.0=full light */ + /* set up isec.dir */ copy_v3_v3(isec.start, shi->co); sub_v3_v3v3(isec.dir, lampco, isec.start); diff --git a/source/blender/render/intern/source/render_result.c b/source/blender/render/intern/source/render_result.c index 8e8483839b1..ddb24e134df 100644 --- a/source/blender/render/intern/source/render_result.c +++ b/source/blender/render/intern/source/render_result.c @@ -459,7 +459,7 @@ RenderResult *render_result_new(Render *re, rcti *partrct, int crop, int savebuf rl->lay_zmask = srl->lay_zmask; rl->lay_exclude = srl->lay_exclude; rl->layflag = srl->layflag; - rl->passflag = srl->passflag; // for debugging: srl->passflag|SCE_PASS_RAYHITS; + rl->passflag = srl->passflag; /* for debugging: srl->passflag | SCE_PASS_RAYHITS; */ rl->pass_xor = srl->pass_xor; rl->light_override = srl->light_override; rl->mat_override = srl->mat_override; diff --git a/source/blender/render/intern/source/render_texture.c b/source/blender/render/intern/source/render_texture.c index 39577bf8da8..c8ef3e4a8dd 100644 --- a/source/blender/render/intern/source/render_texture.c +++ b/source/blender/render/intern/source/render_texture.c @@ -244,7 +244,7 @@ static int clouds(Tex *tex, float *texvec, TexResult *texres) texres->tin = BLI_gTurbulence(tex->noisesize, texvec[0], texvec[1], texvec[2], tex->noisedepth, (tex->noisetype!=TEX_NOISESOFT), tex->noisebasis); if (texres->nor!=NULL) { - // calculate bumpnormal + /* calculate bumpnormal */ texres->nor[0] = BLI_gTurbulence(tex->noisesize, texvec[0] + tex->nabla, texvec[1], texvec[2], tex->noisedepth, (tex->noisetype!=TEX_NOISESOFT), tex->noisebasis); texres->nor[1] = BLI_gTurbulence(tex->noisesize, texvec[0], texvec[1] + tex->nabla, texvec[2], tex->noisedepth, (tex->noisetype!=TEX_NOISESOFT), tex->noisebasis); texres->nor[2] = BLI_gTurbulence(tex->noisesize, texvec[0], texvec[1], texvec[2] + tex->nabla, tex->noisedepth, (tex->noisetype!=TEX_NOISESOFT), tex->noisebasis); @@ -254,8 +254,8 @@ static int clouds(Tex *tex, float *texvec, TexResult *texres) } if (tex->stype==TEX_COLOR) { - // in this case, int. value should really be computed from color, - // and bumpnormal from that, would be too slow, looks ok as is + /* in this case, int. value should really be computed from color, + * and bumpnormal from that, would be too slow, looks ok as is */ texres->tr = texres->tin; texres->tg = BLI_gTurbulence(tex->noisesize, texvec[1], texvec[0], texvec[2], tex->noisedepth, (tex->noisetype!=TEX_NOISESOFT), tex->noisebasis); texres->tb = BLI_gTurbulence(tex->noisesize, texvec[1], texvec[2], texvec[0], tex->noisedepth, (tex->noisetype!=TEX_NOISESOFT), tex->noisebasis); @@ -538,8 +538,8 @@ static float mg_mFractalOrfBmTex(Tex *tex, float *texvec, TexResult *texres) texres->tin = tex->ns_outscale*mgravefunc(texvec[0], texvec[1], texvec[2], tex->mg_H, tex->mg_lacunarity, tex->mg_octaves, tex->noisebasis); if (texres->nor!=NULL) { - float offs= tex->nabla/tex->noisesize; // also scaling of texvec - + float offs= tex->nabla/tex->noisesize; /* also scaling of texvec */ + /* calculate bumpnormal */ texres->nor[0] = tex->ns_outscale*mgravefunc(texvec[0] + offs, texvec[1], texvec[2], tex->mg_H, tex->mg_lacunarity, tex->mg_octaves, tex->noisebasis); texres->nor[1] = tex->ns_outscale*mgravefunc(texvec[0], texvec[1] + offs, texvec[2], tex->mg_H, tex->mg_lacunarity, tex->mg_octaves, tex->noisebasis); @@ -568,8 +568,8 @@ static float mg_ridgedOrHybridMFTex(Tex *tex, float *texvec, TexResult *texres) texres->tin = tex->ns_outscale*mgravefunc(texvec[0], texvec[1], texvec[2], tex->mg_H, tex->mg_lacunarity, tex->mg_octaves, tex->mg_offset, tex->mg_gain, tex->noisebasis); if (texres->nor!=NULL) { - float offs= tex->nabla/tex->noisesize; // also scaling of texvec - + float offs= tex->nabla/tex->noisesize; /* also scaling of texvec */ + /* calculate bumpnormal */ texres->nor[0] = tex->ns_outscale*mgravefunc(texvec[0] + offs, texvec[1], texvec[2], tex->mg_H, tex->mg_lacunarity, tex->mg_octaves, tex->mg_offset, tex->mg_gain, tex->noisebasis); texres->nor[1] = tex->ns_outscale*mgravefunc(texvec[0], texvec[1] + offs, texvec[2], tex->mg_H, tex->mg_lacunarity, tex->mg_octaves, tex->mg_offset, tex->mg_gain, tex->noisebasis); @@ -593,8 +593,8 @@ static float mg_HTerrainTex(Tex *tex, float *texvec, TexResult *texres) texres->tin = tex->ns_outscale*mg_HeteroTerrain(texvec[0], texvec[1], texvec[2], tex->mg_H, tex->mg_lacunarity, tex->mg_octaves, tex->mg_offset, tex->noisebasis); if (texres->nor!=NULL) { - float offs= tex->nabla/tex->noisesize; // also scaling of texvec - + float offs= tex->nabla/tex->noisesize; /* also scaling of texvec */ + /* calculate bumpnormal */ texres->nor[0] = tex->ns_outscale*mg_HeteroTerrain(texvec[0] + offs, texvec[1], texvec[2], tex->mg_H, tex->mg_lacunarity, tex->mg_octaves, tex->mg_offset, tex->noisebasis); texres->nor[1] = tex->ns_outscale*mg_HeteroTerrain(texvec[0], texvec[1] + offs, texvec[2], tex->mg_H, tex->mg_lacunarity, tex->mg_octaves, tex->mg_offset, tex->noisebasis); @@ -618,8 +618,8 @@ static float mg_distNoiseTex(Tex *tex, float *texvec, TexResult *texres) texres->tin = mg_VLNoise(texvec[0], texvec[1], texvec[2], tex->dist_amount, tex->noisebasis, tex->noisebasis2); if (texres->nor!=NULL) { - float offs= tex->nabla/tex->noisesize; // also scaling of texvec - + float offs= tex->nabla/tex->noisesize; /* also scaling of texvec */ + /* calculate bumpnormal */ texres->nor[0] = mg_VLNoise(texvec[0] + offs, texvec[1], texvec[2], tex->dist_amount, tex->noisebasis, tex->noisebasis2); texres->nor[1] = mg_VLNoise(texvec[0], texvec[1] + offs, texvec[2], tex->dist_amount, tex->noisebasis, tex->noisebasis2); @@ -688,7 +688,7 @@ static float voronoiTex(Tex *tex, float *texvec, TexResult *texres) } if (texres->nor!=NULL) { - float offs= tex->nabla/tex->noisesize; // also scaling of texvec + float offs= tex->nabla/tex->noisesize; /* also scaling of texvec */ /* calculate bumpnormal */ voronoi(texvec[0] + offs, texvec[1], texvec[2], da, pa, tex->vn_mexp, tex->vn_distm); @@ -745,7 +745,7 @@ static int cubemap_glob(const float n[3], float x, float y, float z, float *adr1 int ret; if (n==NULL) { - nor[0]= x; nor[1]= y; nor[2]= z; // use local render coord + nor[0]= x; nor[1]= y; nor[2]= z; /* use local render coord */ } else { copy_v3_v3(nor, n); @@ -1026,7 +1026,7 @@ static void do_2d_mapping(MTex *mtex, float *t, VlakRen *vlr, const float n[3], if (tex->xrepeat>1) { float origf= fx *= tex->xrepeat; - // TXF: omit mirror here, see comments in do_material_tex() after do_2d_mapping() call + /* 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); @@ -1046,7 +1046,7 @@ static void do_2d_mapping(MTex *mtex, float *t, VlakRen *vlr, const float n[3], if (tex->yrepeat>1) { float origf= fy *= tex->yrepeat; - // TXF: omit mirror here, see comments in do_material_tex() after do_2d_mapping() call + /* 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); @@ -1512,9 +1512,9 @@ float texture_value_blend(float tex, float out, float fact, float facg, int blen static void texco_mapping(ShadeInput* shi, Tex* tex, MTex* mtex, float* co, float* dx, float* dy, float* texvec, float* dxt, float* dyt) { - // new: first swap coords, then map, then trans/scale + /* new: first swap coords, then map, then trans/scale */ if (tex->type == TEX_IMAGE) { - // placement + /* placement */ texvec[0] = mtex->projx ? co[mtex->projx - 1] : 0.f; texvec[1] = mtex->projy ? co[mtex->projy - 1] : 0.f; texvec[2] = mtex->projz ? co[mtex->projz - 1] : 0.f; @@ -1538,7 +1538,7 @@ static void texco_mapping(ShadeInput* shi, Tex* tex, MTex* mtex, float* co, floa } do_2d_mapping(mtex, texvec, shi->vlr, shi->facenor, dxt, dyt); - // translate and scale + /* translate and scale */ texvec[0] = mtex->size[0]*(texvec[0] - 0.5f) + mtex->ofs[0] + 0.5f; texvec[1] = mtex->size[1]*(texvec[1] - 0.5f) + mtex->ofs[1] + 0.5f; if (shi->osatex) { @@ -1549,13 +1549,13 @@ static void texco_mapping(ShadeInput* shi, Tex* tex, MTex* mtex, float* co, floa } /* problem: repeat-mirror is not a 'repeat' but 'extend' in imagetexture.c */ - // TXF: bug was here, only modify texvec when repeat mode set, old code affected other modes too. - // New texfilters solve mirroring differently so that it also works correctly when - // textures are scaled (sizeXYZ) as well as repeated. See also modification in do_2d_mapping(). - // (since currently only done in osa mode, results will look incorrect without osa TODO) + /* TXF: bug was here, only modify texvec when repeat mode set, old code affected other modes too. + * New texfilters solve mirroring differently so that it also works correctly when + * textures are scaled (sizeXYZ) as well as repeated. See also modification in do_2d_mapping(). + * (since currently only done in osa mode, results will look incorrect without osa TODO) */ if (tex->extend == TEX_REPEAT && (tex->flag & TEX_REPEAT_XMIR)) { if (tex->texfilter == TXF_BOX) - texvec[0] -= floorf(texvec[0]); // this line equivalent to old code, same below + texvec[0] -= floorf(texvec[0]); /* this line equivalent to old code, same below */ else if (texvec[0] < 0.f || texvec[0] > 1.f) { const float tx = 0.5f*texvec[0]; texvec[0] = 2.f*(tx - floorf(tx)); @@ -1573,8 +1573,8 @@ static void texco_mapping(ShadeInput* shi, Tex* tex, MTex* mtex, float* co, floa } } - else { // procedural - // placement + else { /* procedural */ + /* placement */ texvec[0] = mtex->size[0]*(mtex->projx ? (co[mtex->projx - 1] + mtex->ofs[0]) : mtex->ofs[0]); texvec[1] = mtex->size[1]*(mtex->projy ? (co[mtex->projy - 1] + mtex->ofs[1]) : mtex->ofs[1]); texvec[2] = mtex->size[2]*(mtex->projz ? (co[mtex->projz - 1] + mtex->ofs[2]) : mtex->ofs[2]); @@ -1617,11 +1617,16 @@ static void compatible_bump_init(CompatibleBump *compat_bump) static void compatible_bump_uv_derivs(CompatibleBump *compat_bump, ShadeInput *shi, MTex *mtex, int i) { - // uvmapping only, calculation of normal tangent u/v partial derivatives - // (should not be here, dudnu, dudnv, dvdnu & dvdnv should probably be part of ShadeInputUV struct, - // nu/nv in ShadeInput and this calculation should then move to shadeinput.c, shade_input_set_shade_texco() func.) - // 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. + /* uvmapping only, calculation of normal tangent u/v partial derivatives + * (should not be here, dudnu, dudnv, dvdnu & dvdnv should probably be part of ShadeInputUV struct, + * nu/nv in ShadeInput and this calculation should then move to shadeinput.c, + * shade_input_set_shade_texco() func.) */ + + /* 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))) { MTFace* tf = RE_vlakren_get_tface(shi->obr, shi->vlr, i, NULL, 0); @@ -1629,9 +1634,9 @@ static void compatible_bump_uv_derivs(CompatibleBump *compat_bump, ShadeInput *s vlr_set_uv_indices(shi->vlr, &j1, &j2, &j3); - // compute ortho basis around normal + /* compute ortho basis around normal */ if (!compat_bump->nunvdone) { - // render normal is negated + /* render normal is negated */ compat_bump->nn[0] = -shi->vn[0]; compat_bump->nn[1] = -shi->vn[1]; compat_bump->nn[2] = -shi->vn[2]; @@ -1672,32 +1677,32 @@ static void compatible_bump_uv_derivs(CompatibleBump *compat_bump, ShadeInput *s static int compatible_bump_compute(CompatibleBump *compat_bump, ShadeInput *shi, MTex *mtex, Tex *tex, TexResult *texres, float Tnor, float *co, float *dx, float *dy, float *texvec, float *dxt, float *dyt) { - TexResult ttexr = {0, 0, 0, 0, 0, texres->talpha, NULL}; // temp TexResult + TexResult ttexr = {0, 0, 0, 0, 0, texres->talpha, NULL}; /* temp TexResult */ float tco[3], texv[3], cd, ud, vd, du, dv, idu, idv; const int fromrgb = ((tex->type == TEX_IMAGE) || ((tex->flag & TEX_COLORBAND)!=0)); const float bf = -0.04f*Tnor*mtex->norfac; int rgbnor; - // disable internal bump eval + /* disable internal bump eval */ float* nvec = texres->nor; texres->nor = NULL; - // du & dv estimates, constant value defaults + /* du & dv estimates, constant value defaults */ du = dv = 0.01f; - // compute ortho basis around normal + /* compute ortho basis around normal */ if (!compat_bump->nunvdone) { - // render normal is negated + /* 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); compat_bump->nunvdone = TRUE; } - // two methods, either constant based on main image resolution, - // (which also works without osa, though of course not always good (or even very bad) results), - // or based on tex derivative max values (osa only). Not sure which is best... + /* two methods, either constant based on main image resolution, + * (which also works without osa, though of course not always good (or even very bad) results), + * or based on tex derivative max values (osa only). Not sure which is best... */ if (!shi->osatex && (tex->type == TEX_IMAGE) && tex->ima) { - // in case we have no proper derivatives, fall back to - // computing du/dv it based on image size + /* in case we have no proper derivatives, fall back to + * computing du/dv it based on image size */ ImBuf* ibuf = BKE_image_get_ibuf(tex->ima, &tex->iuser); if (ibuf) { du = 1.f/(float)ibuf->x; @@ -1705,14 +1710,14 @@ static int compatible_bump_compute(CompatibleBump *compat_bump, ShadeInput *shi, } } else if (shi->osatex) { - // we have derivatives, can compute proper du/dv - if (tex->type == TEX_IMAGE) { // 2d image, use u & v max. of dx/dy 2d vecs + /* we have derivatives, can compute proper du/dv */ + if (tex->type == TEX_IMAGE) { /* 2d image, use u & v max. of dx/dy 2d vecs */ const float adx[2] = {fabsf(dx[0]), fabsf(dx[1])}; const float ady[2] = {fabsf(dy[0]), fabsf(dy[1])}; du = MAX2(adx[0], ady[0]); dv = MAX2(adx[1], ady[1]); } - else { // 3d procedural, estimate from all dx/dy elems + else { /* 3d procedural, estimate from all dx/dy elems */ const float adx[3] = {fabsf(dx[0]), fabsf(dx[1]), fabsf(dx[2])}; const float ady[3] = {fabsf(dy[0]), fabsf(dy[1]), fabsf(dy[2])}; du = MAX3(adx[0], adx[1], adx[2]); @@ -1720,18 +1725,18 @@ static int compatible_bump_compute(CompatibleBump *compat_bump, ShadeInput *shi, } } - // center, main return value + /* center, main return value */ texco_mapping(shi, tex, mtex, co, dx, dy, texvec, dxt, dyt); rgbnor = multitex_mtex(shi, mtex, texvec, dxt, dyt, texres); cd = fromrgb ? (texres->tr + texres->tg + texres->tb)*0.33333333f : texres->tin; if (mtex->texco == TEXCO_UV) { - // for the uv case, use the same value for both du/dv, - // since individually scaling the normal derivatives makes them useless... + /* for the uv case, use the same value for both du/dv, + * since individually scaling the normal derivatives makes them useless... */ du = MIN2(du, dv); idu = (du < 1e-5f) ? bf : (bf/du); - // +u val + /* +u val */ tco[0] = co[0] + compat_bump->dudnu*du; tco[1] = co[1] + compat_bump->dvdnu*du; tco[2] = 0.f; @@ -1739,7 +1744,7 @@ static int compatible_bump_compute(CompatibleBump *compat_bump, ShadeInput *shi, multitex_mtex(shi, mtex, texv, dxt, dyt, &ttexr); ud = idu*(cd - (fromrgb ? (ttexr.tr + ttexr.tg + ttexr.tb)*0.33333333f : ttexr.tin)); - // +v val + /* +v val */ tco[0] = co[0] + compat_bump->dudnv*du; tco[1] = co[1] + compat_bump->dvdnv*du; tco[2] = 0.f; @@ -1773,7 +1778,7 @@ static int compatible_bump_compute(CompatibleBump *compat_bump, ShadeInput *shi, normalize_v3(tv); } - // +u val + /* +u val */ tco[0] = co[0] + tu[0]*du; tco[1] = co[1] + tu[1]*du; tco[2] = co[2] + tu[2]*du; @@ -1781,7 +1786,7 @@ static int compatible_bump_compute(CompatibleBump *compat_bump, ShadeInput *shi, multitex_mtex(shi, mtex, texv, dxt, dyt, &ttexr); ud = idu*(cd - (fromrgb ? (ttexr.tr + ttexr.tg + ttexr.tb)*0.33333333f : ttexr.tin)); - // +v val + /* +v val */ tco[0] = co[0] + tv[0]*dv; tco[1] = co[1] + tv[1]*dv; tco[2] = co[2] + tv[2]*dv; @@ -1790,7 +1795,7 @@ static int compatible_bump_compute(CompatibleBump *compat_bump, ShadeInput *shi, vd = idv*(cd - (fromrgb ? (ttexr.tr + ttexr.tg + ttexr.tb)*0.33333333f : ttexr.tin)); } - // bumped normal + /* bumped normal */ compat_bump->nu[0] += ud*compat_bump->nn[0]; compat_bump->nu[1] += ud*compat_bump->nn[1]; compat_bump->nu[2] += ud*compat_bump->nn[2]; @@ -1812,13 +1817,13 @@ static int compatible_bump_compute(CompatibleBump *compat_bump, ShadeInput *shi, typedef struct NTapBump { int init_done; - int iPrevBumpSpace; // 0: uninitialized, 1: objectspace, 2: texturespace, 4: viewspace - // bumpmapping - float vNorg[3]; // backup copy of shi->vn - float vNacc[3]; // original surface normal minus the surface gradient of every bump map which is encountered - float vR1[3], vR2[3]; // cross products (sigma_y, original_normal), (original_normal, sigma_x) - float sgn_det; // sign of the determinant of the matrix {sigma_x, sigma_y, original_normal} - float fPrevMagnitude; // copy of previous magnitude, used for multiple bumps in different spaces + int iPrevBumpSpace; /* 0: uninitialized, 1: objectspace, 2: texturespace, 4: viewspace */ + /* bumpmapping */ + float vNorg[3]; /* backup copy of shi->vn */ + float vNacc[3]; /* original surface normal minus the surface gradient of every bump map which is encountered */ + float vR1[3], vR2[3]; /* cross products (sigma_y, original_normal), (original_normal, sigma_x) */ + float sgn_det; /* sign of the determinant of the matrix {sigma_x, sigma_y, original_normal} */ + float fPrevMagnitude; /* copy of previous magnitude, used for multiple bumps in different spaces */ } NTapBump; static void ntap_bump_init(NTapBump *ntap_bump) @@ -1828,38 +1833,38 @@ static void ntap_bump_init(NTapBump *ntap_bump) static int ntap_bump_compute(NTapBump *ntap_bump, ShadeInput *shi, MTex *mtex, Tex *tex, TexResult *texres, float Tnor, float *co, float *dx, float *dy, float *texvec, float *dxt, float *dyt) { - TexResult ttexr = {0, 0, 0, 0, 0, texres->talpha, NULL}; // temp TexResult + TexResult ttexr = {0, 0, 0, 0, 0, texres->talpha, NULL}; /* temp TexResult */ const int fromrgb = ((tex->type == TEX_IMAGE) || ((tex->flag & TEX_COLORBAND)!=0)); - // The negate on Hscale is done because the - // normal in the renderer points inward which corresponds - // to inverting the bump map. The normals are generated - // this way in calc_vertexnormals(). Should this ever change - // this negate must be removed. + /* The negate on Hscale is done because the + * normal in the renderer points inward which corresponds + * to inverting the bump map. The normals are generated + * this way in calc_vertexnormals(). Should this ever change + * this negate must be removed. */ float Hscale = -Tnor*mtex->norfac; int dimx=512, dimy=512; - const int imag_tspace_dimension_x = 1024; // only used for texture space variant + const int imag_tspace_dimension_x = 1024; /* only used for texture space variant */ float aspect = 1.0f; - // 2 channels for 2D texture and 3 for 3D textures. + /* 2 channels for 2D texture and 3 for 3D textures. */ const int nr_channels = (mtex->texco == TEXCO_UV)? 2 : 3; int c, rgbnor, iBumpSpace; float dHdx, dHdy; int found_deriv_map = (tex->type==TEX_IMAGE) && (tex->imaflag & TEX_DERIVATIVEMAP); - // disable internal bump eval in sampler, save pointer + /* disable internal bump eval in sampler, save pointer */ float *nvec = texres->nor; texres->nor = NULL; if (found_deriv_map==0) { if ( mtex->texflag & MTEX_BUMP_TEXTURESPACE ) { if (tex->ima) - Hscale *= 13.0f; // appears to be a sensible default value + Hscale *= 13.0f; /* appears to be a sensible default value */ } else - Hscale *= 0.1f; // factor 0.1 proved to look like the previous bump code + Hscale *= 0.1f; /* factor 0.1 proved to look like the previous bump code */ } if ( !ntap_bump->init_done ) { @@ -1871,7 +1876,7 @@ static int ntap_bump_compute(NTapBump *ntap_bump, ShadeInput *shi, MTex *mtex, T ntap_bump->init_done = TRUE; } - // resolve image dimensions + /* resolve image dimensions */ if (found_deriv_map || (mtex->texflag&MTEX_BUMP_TEXTURESPACE)!=0) { ImBuf* ibuf = BKE_image_get_ibuf(tex->ima, &tex->iuser); if (ibuf) { @@ -1883,7 +1888,7 @@ static int ntap_bump_compute(NTapBump *ntap_bump, ShadeInput *shi, MTex *mtex, T if (found_deriv_map) { float dBdu, dBdv, auto_bump = 1.0f; - float s = 1; // negate this if flipped texture coordinate + 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); @@ -1895,9 +1900,9 @@ static int ntap_bump_compute(NTapBump *ntap_bump, ShadeInput *shi, MTex *mtex, T float fVirtDim = sqrtf(fabsf((float) (dimx*dimy)*mtex->size[0]*mtex->size[1])); auto_bump /= MAX2(fVirtDim, FLT_EPSILON); } - - // this variant using a derivative map is described here - // http://mmikkelsen3d.blogspot.com/2011/07/derivative-maps.html + + /* this variant using a derivative map is described here + * http://mmikkelsen3d.blogspot.com/2011/07/derivative-maps.html */ dBdu = auto_bump*Hscale*dimx*(2*texres->tr-1); dBdv = auto_bump*Hscale*dimy*(2*texres->tg-1); @@ -1905,32 +1910,32 @@ static int ntap_bump_compute(NTapBump *ntap_bump, ShadeInput *shi, MTex *mtex, T dHdy = dBdu*dyt[0] + s * dBdv*dyt[1]; } else if (!(mtex->texflag & MTEX_5TAP_BUMP)) { - // compute height derivatives with respect to output image pixel coordinates x and y + /* 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++) { - // dx contains the derivatives (du/dx, dv/dx) - // dy contains the derivatives (du/dy, dv/dy) + /* dx contains the derivatives (du/dx, dv/dx) + * dy contains the derivatives (du/dy, dv/dy) */ STll[c] = texvec[c]; STlr[c] = texvec[c]+dxt[c]; STul[c] = texvec[c]+dyt[c]; } - // clear unused derivatives + /* clear unused derivatives */ for (c=nr_channels; c<3; c++) { STll[c] = 0.0f; STlr[c] = 0.0f; STul[c] = 0.0f; } - // use texres for the center sample, set rgbnor + /* use texres for the center sample, set rgbnor */ rgbnor = multitex_mtex(shi, mtex, STll, dxt, dyt, texres); Hll = (fromrgb) ? rgb_to_grayscale(&texres->tr) : texres->tin; - // use ttexr for the other 2 taps + /* use ttexr for the other 2 taps */ multitex_mtex(shi, mtex, STlr, dxt, dyt, &ttexr); Hlr = (fromrgb) ? rgb_to_grayscale(&ttexr.tr) : ttexr.tin; @@ -1955,7 +1960,7 @@ static int ntap_bump_compute(NTapBump *ntap_bump, ShadeInput *shi, MTex *mtex, T STu[c] = texvec[c] + 0.5f*dyt[c]; } - // clear unused derivatives + /* clear unused derivatives */ for (c=nr_channels; c<3; c++) { STc[c] = 0.0f; STl[c] = 0.0f; @@ -1964,11 +1969,11 @@ static int ntap_bump_compute(NTapBump *ntap_bump, ShadeInput *shi, MTex *mtex, T STu[c] = 0.0f; } - // use texres for the center sample, set rgbnor + /* use texres for the center sample, set rgbnor */ rgbnor = multitex_mtex(shi, mtex, STc, dxt, dyt, texres); /* Hc = (fromrgb) ? rgb_to_grayscale(&texres->tr) : texres->tin; */ /* UNUSED */ - // use ttexr for the other taps + /* use ttexr for the other taps */ multitex_mtex(shi, mtex, STl, dxt, dyt, &ttexr); Hl = (fromrgb) ? rgb_to_grayscale(&ttexr.tr) : ttexr.tin; multitex_mtex(shi, mtex, STr, dxt, dyt, &ttexr); @@ -1982,7 +1987,7 @@ static int ntap_bump_compute(NTapBump *ntap_bump, ShadeInput *shi, MTex *mtex, T dHdy = Hscale*(Hu - Hd); } - // restore pointer + /* restore pointer */ texres->nor = nvec; /* replaced newbump with code based on listing 1 and 2 of @@ -1994,32 +1999,32 @@ static int ntap_bump_compute(NTapBump *ntap_bump, ShadeInput *shi, MTex *mtex, T else if ( mtex->texflag & MTEX_BUMP_TEXTURESPACE ) iBumpSpace = 2; else - iBumpSpace = 4; // ViewSpace - + iBumpSpace = 4; /* ViewSpace */ + if ( ntap_bump->iPrevBumpSpace != iBumpSpace ) { - - // initialize normal perturbation vectors + + /* initialize normal perturbation vectors */ int xyz; float fDet, abs_fDet, fMagnitude; - // object2view and inverted matrix + /* object2view and inverted matrix */ float obj2view[3][3], view2obj[3][3], tmp[4][4]; - // local copies of derivatives and normal + /* local copies of derivatives and normal */ float dPdx[3], dPdy[3], vN[3]; copy_v3_v3(dPdx, shi->dxco); copy_v3_v3(dPdy, shi->dyco); copy_v3_v3(vN, ntap_bump->vNorg); if ( mtex->texflag & MTEX_BUMP_OBJECTSPACE ) { - // TODO: these calculations happen for every pixel! - // -> move to shi->obi + /* TODO: these calculations happen for every pixel! + * -> move to shi->obi */ mult_m4_m4m4(tmp, R.viewmat, shi->obr->ob->obmat); - copy_m3_m4(obj2view, tmp); // use only upper left 3x3 matrix + copy_m3_m4(obj2view, tmp); /* use only upper left 3x3 matrix */ invert_m3_m3(view2obj, obj2view); - - // generate the surface derivatives in object space + + /* generate the surface derivatives in object space */ mul_m3_v3(view2obj, dPdx); mul_m3_v3(view2obj, dPdy); - // generate the unit normal in object space + /* generate the unit normal in object space */ mul_transposed_m3_v3(obj2view, vN); normalize_v3(vN); } @@ -2032,7 +2037,7 @@ static int ntap_bump_compute(NTapBump *ntap_bump, ShadeInput *shi, MTex *mtex, T if ( mtex->texflag & MTEX_BUMP_TEXTURESPACE ) { if (tex->ima) { - // crazy hack solution that gives results similar to normal mapping - part 1 + /* crazy hack solution that gives results similar to normal mapping - part 1 */ normalize_v3(ntap_bump->vR1); normalize_v3(ntap_bump->vR2); abs_fDet = 1.0f; @@ -2041,7 +2046,7 @@ static int ntap_bump_compute(NTapBump *ntap_bump, ShadeInput *shi, MTex *mtex, T fMagnitude = abs_fDet; if ( mtex->texflag & MTEX_BUMP_OBJECTSPACE ) { - // pre do transform of texres->nor by the inverse transposed of obj2view + /* 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); mul_transposed_m3_v3(view2obj, ntap_bump->vR2); @@ -2059,7 +2064,7 @@ static int ntap_bump_compute(NTapBump *ntap_bump, ShadeInput *shi, MTex *mtex, T if ( mtex->texflag & MTEX_BUMP_TEXTURESPACE ) { if (tex->ima) { - // crazy hack solution that gives results similar to normal mapping - part 2 + /* 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; @@ -2072,11 +2077,11 @@ static int ntap_bump_compute(NTapBump *ntap_bump, ShadeInput *shi, MTex *mtex, T } } - // subtract the surface gradient from vNacc + /* subtract the surface gradient from vNacc */ 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 + texres->nor[c] = ntap_bump->vNacc[c]; /* copy */ } rgbnor |= TEX_NOR; @@ -2235,7 +2240,9 @@ void do_material_tex(ShadeInput *shi, Render *re) dy[0]= 0.0f; dy[1]= dy[2]= 0.0f; } - else continue; // can happen when texco defines disappear and it renders old files + 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)) { @@ -2319,7 +2326,7 @@ void do_material_tex(ShadeInput *shi, Render *re) texres.nor[2]= f2*co_nor-f1*si; } } - // warping, local space + /* warping, local space */ if (mtex->mapto & MAP_WARP) { float *warpnor= texres.nor, warpnor_[3]; @@ -2335,11 +2342,11 @@ void do_material_tex(ShadeInput *shi, Render *re) } #if 0 if (mtex->texflag & MTEX_VIEWSPACE) { - // rotate to global coords + /* rotate to global coords */ 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) + /* can be optimized... (ton) */ mul_mat3_m4_v3(shi->obr->ob->obmat, texres.nor); mul_mat3_m4_v3(re->viewmat, texres.nor); normalize_v3(texres.nor); @@ -2388,7 +2395,7 @@ void do_material_tex(ShadeInput *shi, Render *re) if (mtex->mapto & MAP_COLMIR) { float mirrfac= mtex->mirrfac*stencilTin; - // exception for envmap only + /* exception for envmap only */ if (tex->type==TEX_ENVMAP && mtex->blendtype==MTEX_BLEND) { fact= texres.tin*mirrfac; facm= 1.0f- fact; @@ -2565,7 +2572,7 @@ void do_material_tex(ShadeInput *shi, Render *re) else if (shi->alpha>1.0f) shi->alpha= 1.0f; } if (mtex->mapto & MAP_HAR) { - float har; // have to map to 0-1 + float har; /* have to map to 0-1 */ float hardfac= mtex->hardfac*stencilTin; har= ((float)shi->har)/128.0f; @@ -2605,7 +2612,7 @@ void do_material_tex(ShadeInput *shi, Render *re) } if ((use_compat_bump || use_ntap_bump || found_nmapping) && (shi->mat->mode & MA_TANGENT_V) != 0) { const float fnegdot = -dot_v3v3(shi->vn, shi->tang); - // apply Gram-Schmidt projection + /* apply Gram-Schmidt projection */ madd_v3_v3fl(shi->tang, shi->vn, fnegdot); normalize_v3(shi->tang); } @@ -2665,12 +2672,14 @@ void do_volume_tex(ShadeInput *shi, const float *xyz, int mapto_flag, float col_ copy_v3_v3(co, xyz); mul_m4_v3(re->viewinv, co); } - else continue; // can happen when texco defines disappear and it renders old files + else { + continue; /* can happen when texco defines disappear and it renders old files */ + } texres.nor= NULL; - if (tex->type==TEX_IMAGE) { - continue; /* not supported yet */ + if (tex->type == TEX_IMAGE) { + continue; /* not supported yet */ //do_2d_mapping(mtex, texvec, NULL, NULL, dxt, dyt); } else { @@ -3381,7 +3390,7 @@ int externtex(MTex *mtex, const float vec[3], float *tin, float *tr, float *tg, void render_realtime_texture(ShadeInput *shi, Image *ima) { TexResult texr; - static Tex imatex[BLENDER_MAX_THREADS]; // threadsafe + static Tex imatex[BLENDER_MAX_THREADS]; /* threadsafe */ static int firsttime= 1; Tex *tex; float texvec[3], dx[2], dy[2]; @@ -3409,7 +3418,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. + texvec[2] = 0.0f; /* initalize it because imagewrap looks at it. */ if (shi->osatex) { dx[0]= 0.5f*suv->dxuv[0]; dx[1]= 0.5f*suv->dxuv[1]; diff --git a/source/blender/render/intern/source/rendercore.c b/source/blender/render/intern/source/rendercore.c index 03bea0122cf..63aa6cdd139 100644 --- a/source/blender/render/intern/source/rendercore.c +++ b/source/blender/render/intern/source/rendercore.c @@ -2098,12 +2098,12 @@ static void bake_shade(void *handle, Object *ob, ShadeInput *shi, int UNUSED(qua normalize_v3(nor); /* in case object has scaling */ - // The invert of the red channel is to make - // the normal map compliant with the outside world. - // It needs to be done because in Blender - // the normal used in the renderer points inward. It is generated - // this way in calc_vertexnormals(). Should this ever change - // this negate must be removed. + /* The invert of the red channel is to make + * the normal map compliant with the outside world. + * It needs to be done because in Blender + * the normal used in the renderer points inward. It is generated + * this way in calc_vertexnormals(). Should this ever change + * this negate must be removed. */ shr.combined[0]= (-nor[0])/2.0f + 0.5f; shr.combined[1]= nor[1]/2.0f + 0.5f; shr.combined[2]= nor[2]/2.0f + 0.5f; diff --git a/source/blender/render/intern/source/shadbuf.c b/source/blender/render/intern/source/shadbuf.c index 93587734e2b..f696f95781b 100644 --- a/source/blender/render/intern/source/shadbuf.c +++ b/source/blender/render/intern/source/shadbuf.c @@ -1561,9 +1561,9 @@ static void isb_bsp_split(ISBBranch *root, MemArena *mem) right= root->right= BLI_memarena_alloc(mem, sizeof(ISBBranch)); /* new sample array */ - left->samples= BLI_memarena_alloc(mem, BSPMAX_SAMPLE*sizeof(void *)); - right->samples= samples; // tmp - + left->samples = BLI_memarena_alloc(mem, BSPMAX_SAMPLE*sizeof(void *)); + right->samples = samples; /* tmp */ + /* split samples */ for (a=BSPMAX_SAMPLE-1; a>=0; a--) { int comp= 0; diff --git a/source/blender/render/intern/source/shadeinput.c b/source/blender/render/intern/source/shadeinput.c index f9b0de5b87d..5e80370a6f0 100644 --- a/source/blender/render/intern/source/shadeinput.c +++ b/source/blender/render/intern/source/shadeinput.c @@ -818,7 +818,7 @@ void shade_input_set_normals(ShadeInput *shi) shi->vn[1]= l*n3[1]-u*n1[1]-v*n2[1]; shi->vn[2]= l*n3[2]-u*n1[2]-v*n2[2]; - // use unnormalized normal (closer to games) + /* use unnormalized normal (closer to games) */ copy_v3_v3(shi->nmapnorm, shi->vn); normalize_v3(shi->vn); @@ -851,7 +851,7 @@ void shade_input_set_vertex_normals(ShadeInput *shi) shi->vn[1]= l*n3[1]-u*n1[1]-v*n2[1]; shi->vn[2]= l*n3[2]-u*n1[2]-v*n2[2]; - // use unnormalized normal (closer to games) + /* use unnormalized normal (closer to games) */ copy_v3_v3(shi->nmapnorm, shi->vn); normalize_v3(shi->vn); @@ -968,22 +968,22 @@ void shade_input_set_shade_texco(ShadeInput *shi) copy_v3_v3(c1, &tangent[j2*4]); copy_v3_v3(c2, &tangent[j3*4]); - // keeping tangents normalized at vertex level - // corresponds better to how it's done in game engines + /* keeping tangents normalized at vertex level + * corresponds better to how it's done in game engines */ if (obi->flag & R_TRANSFORMED) { mul_mat3_m4_v3(obi->mat, c0); normalize_v3(c0); mul_mat3_m4_v3(obi->mat, c1); normalize_v3(c1); mul_mat3_m4_v3(obi->mat, c2); normalize_v3(c2); } - - // we don't normalize the interpolated TBN tangent - // corresponds better to how it's done in game engines + + /* we don't normalize the interpolated TBN tangent + * corresponds better to how it's done in game engines */ shi->nmaptang[0]= (tl*c2[0] - tu*c0[0] - tv*c1[0]); shi->nmaptang[1]= (tl*c2[1] - tu*c0[1] - tv*c1[1]); shi->nmaptang[2]= (tl*c2[2] - tu*c0[2] - tv*c1[2]); - // the sign is the same for all 3 vertices of any - // non degenerate triangle. + /* the sign is the same for all 3 vertices of any + * non degenerate triangle. */ shi->nmaptang[3]= tangent[j1*4+3]; } } diff --git a/source/blender/render/intern/source/shadeoutput.c b/source/blender/render/intern/source/shadeoutput.c index b208df74de9..e209baa49a8 100644 --- a/source/blender/render/intern/source/shadeoutput.c +++ b/source/blender/render/intern/source/shadeoutput.c @@ -173,7 +173,7 @@ static void spothalo(struct LampRen *lar, ShadeInput *shi, float *intens) p1[1]= shi->co[1]-lar->co[1]; p1[2]= -lar->co[2]; mul_m3_v3(lar->imat, p1); - copy_v3db_v3fl(npos, p1); // npos is double! + copy_v3db_v3fl(npos, p1); /* npos is double! */ /* pre-scale */ npos[2] *= (double)lar->sh_zfac; @@ -371,11 +371,12 @@ void renderspothalo(ShadeInput *shi, float col[4], float alpha) continue; spothalo(lar, shi, &i); - if (i>0.0f) { - col[3]+= i*alpha; // all premul - col[0]+= i*lar->r*alpha; - col[1]+= i*lar->g*alpha; - col[2]+= i*lar->b*alpha; + if (i > 0.0f) { + const float i_alpha = i * alpha; + col[0] += i_alpha * lar->r; + col[1] += i_alpha * lar->g; + col[2] += i_alpha * lar->b; + col[3] += i_alpha; /* all premul */ } } } @@ -519,7 +520,7 @@ static float area_lamp_energy_multisample(LampRen *lar, const float co[3], float } intens /= (float)lar->ray_totsamp; - return pow(intens*lar->areasize, lar->k); // corrected for buttons size and lar->dist^2 + return pow(intens * lar->areasize, lar->k); /* corrected for buttons size and lar->dist^2 */ } static float spec(float inp, int hard) @@ -932,7 +933,7 @@ static void add_to_diffuse(float *diff, ShadeInput *shi, float is, float r, floa /* MA_RAMP_IN_RESULT is exceptional */ if (ma->rampin_col==MA_RAMP_IN_RESULT) { - // normal add + /* normal add */ diff[0] += r * shi->r; diff[1] += g * shi->g; diff[2] += b * shi->b; @@ -1368,10 +1369,10 @@ static void shade_one_light(LampRen *lar, ShadeInput *shi, ShadeResult *shr, int /* diffuse shaders */ if (lar->mode & LA_NO_DIFF) { - is= 0.0f; // skip shaders + is = 0.0f; /* skip shaders */ } else if (lar->type==LA_HEMI) { - is= 0.5f*inp + 0.5f; + is = 0.5f * inp + 0.5f; } else { @@ -1383,12 +1384,13 @@ static void shade_one_light(LampRen *lar, ShadeInput *shi, ShadeResult *shr, int 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 + else is= inp; /* Lambert */ } - + /* 'is' is diffuse */ - 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 + 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; @@ -1397,7 +1399,7 @@ static void shade_one_light(LampRen *lar, ShadeInput *shi, ShadeResult *shr, int } i_noshad= i; - vn= shi->vn; // bring back original vector, we use special specular shaders for tangent + vn = shi->vn; /* bring back original vector, we use special specular shaders for tangent */ if (ma->mode & MA_TANGENT_V) vn= shi->tang; @@ -1728,7 +1730,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]); @@ -1749,8 +1751,8 @@ void shade_lamp_loop(ShadeInput *shi, ShadeResult *shr) 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 - copy_v3_v3(shr->indirect, shi->indirect); // XXX multiply + copy_v3_v3(shr->env, shi->env); /* XXX multiply */ + copy_v3_v3(shr->indirect, shi->indirect); /* XXX multiply */ } } } diff --git a/source/blender/render/intern/source/sunsky.c b/source/blender/render/intern/source/sunsky.c index eeefaae856a..ddc7dff7b06 100644 --- a/source/blender/render/intern/source/sunsky.c +++ b/source/blender/render/intern/source/sunsky.c @@ -272,7 +272,7 @@ void GetSkyXYZRadiance(struct SunSky *sunsky, float theta, float phi, float colo gamma = AngleBetween(theta, phi, sunsky->theta, sunsky->phi); - // Compute xyY values + /* Compute xyY values */ x = PerezFunction(sunsky, sunsky->perez_x, theta, gamma, sunsky->zenith_x); 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); @@ -366,7 +366,7 @@ void InitAtmosphere(struct SunSky *sunSky, float sun_intens, float mief, float r float inscattf, float extincf, float disf) { const float pi = M_PI; - const float n = 1.003f; // refractive index + const float n = 1.003f; /* refractive index */ const float N = 2.545e25; const float pn = 0.035f; const float T = 2.0f; @@ -406,16 +406,16 @@ void InitAtmosphere(struct SunSky *sunSky, float sun_intens, float mief, float r vLambda4[1] = fLambda4[1]; vLambda4[2] = fLambda4[2]; - // Rayleigh scattering constants. + /* Rayleigh scattering constants. */ fTemp = pi * pi * (n * n - 1) * (n * n - 1) * (6 + 3 * pn) / (6 - 7 * pn) / N; fBeta = 8 * fTemp * pi / 3; - + VEC3OPF(sunSky->atm_BetaRay, vLambda4, *, fBeta); fBetaDash = fTemp / 2; VEC3OPF(sunSky->atm_BetaDashRay, vLambda4, *, fBetaDash); - - // Mie scattering constants. + + /* Mie scattering constants. */ fTemp2 = 0.434f * c * (2 * pi) * (2 * pi) * 0.5f; VEC3OPF(sunSky->atm_BetaDashMie, vLambda2, *, fTemp2); diff --git a/source/blender/render/intern/source/volume_precache.c b/source/blender/render/intern/source/volume_precache.c index c342f179bd1..8a92695a15e 100644 --- a/source/blender/render/intern/source/volume_precache.c +++ b/source/blender/render/intern/source/volume_precache.c @@ -465,7 +465,7 @@ static void multiple_scattering_diffusion(Render *re, VolumePrecache *vp, Materi -#if 0 // debug stuff +#if 0 /* debug stuff */ static void *vol_precache_part_test(void *data) { VolPrecachePart *pa = data; diff --git a/source/blender/render/intern/source/volumetric.c b/source/blender/render/intern/source/volumetric.c index e0d3325106a..67e453577e4 100644 --- a/source/blender/render/intern/source/volumetric.c +++ b/source/blender/render/intern/source/volumetric.c @@ -289,7 +289,7 @@ float vol_get_density(struct ShadeInput *shi, const float co[3]) if (shi->mat->mapto_textured & MAP_DENSITY) do_volume_tex(shi, co, MAP_DENSITY, NULL, &density, &R); - // if meta-object, modulate by metadensity without increasing it + /* if meta-object, modulate by metadensity without increasing it */ if (shi->obi->obr->ob->type == OB_MBALL) { const float md = metadensity(shi->obi->obr->ob, co); if (md < 1.f) density *= md; diff --git a/source/blender/render/intern/source/voxeldata.c b/source/blender/render/intern/source/voxeldata.c index ee766311a33..d73171648fb 100644 --- a/source/blender/render/intern/source/voxeldata.c +++ b/source/blender/render/intern/source/voxeldata.c @@ -290,7 +290,7 @@ static void init_frame_smoke(VoxelData *vd, float cfra) /* always store copy, as smoke internal data can change */ vd->dataset = MEM_mapallocN(sizeof(float) * (totRes), "smoke data"); memcpy(vd->dataset, density, sizeof(float) * totRes); - } // end of fluid condition + } /* end of fluid condition */ } } diff --git a/source/blender/render/intern/source/zbuf.c b/source/blender/render/intern/source/zbuf.c index fc3dae73d6b..1ebb963a790 100644 --- a/source/blender/render/intern/source/zbuf.c +++ b/source/blender/render/intern/source/zbuf.c @@ -466,7 +466,7 @@ static void zbuflineAc(ZSpan *zspan, int obi, int zvlnr, const float vec1[3], co 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); @@ -537,7 +537,7 @@ static void zbuflineAc(ZSpan *zspan, int obi, int zvlnr, const float vec1[3], co 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 ); @@ -619,7 +619,7 @@ static void zbufline(ZSpan *zspan, int obi, int zvlnr, const float vec1[3], cons 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; @@ -678,7 +678,7 @@ static void zbufline(ZSpan *zspan, int obi, int zvlnr, const float vec1[3], cons 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; @@ -749,7 +749,7 @@ static void zbufline_onlyZ(ZSpan *zspan, int UNUSED(obi), int UNUSED(zvlnr), con 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) @@ -806,8 +806,8 @@ static void zbufline_onlyZ(ZSpan *zspan, int UNUSED(obi), int UNUSED(zvlnr), con 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) rectz1= zspan->rectz1 + start*zspan->rectx+ oldx; |