diff options
author | Tamito Kajiyama <rd6t-kjym@asahi-net.or.jp> | 2012-07-14 03:23:06 +0400 |
---|---|---|
committer | Tamito Kajiyama <rd6t-kjym@asahi-net.or.jp> | 2012-07-14 03:23:06 +0400 |
commit | 065605e0da8ecd7add39f159db624ae9063ec476 (patch) | |
tree | 46cb2051e28dcef4a04a998e2d9ef82a7b36ecfa /source/blender/render | |
parent | b7b50298148ef502d14143b0a5fa01dfac2ecce4 (diff) | |
parent | 807ad1f0e0de49711d58ade2b660e74ec5452b2b (diff) |
Merged changes in the trunk up to revision 48893.
Conflicts resolved:
source/blender/blenkernel/CMakeLists.txt
source/blender/blenloader/intern/readfile.c
source/blender/editors/animation/anim_filter.c
source/blender/makesrna/RNA_enum_types.h
Diffstat (limited to 'source/blender/render')
22 files changed, 1409 insertions, 1403 deletions
diff --git a/source/blender/render/extern/include/RE_pipeline.h b/source/blender/render/extern/include/RE_pipeline.h index 9c7511c0c60..d6bd49f5621 100644 --- a/source/blender/render/extern/include/RE_pipeline.h +++ b/source/blender/render/extern/include/RE_pipeline.h @@ -51,8 +51,8 @@ struct EnvMap; /* this include is what is exposed of render to outside world */ /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ - -#define RE_MAXNAME 32 +/* length of the scene name + passname */ +#define RE_MAXNAME ((MAX_ID_NAME - 2) + 10) /* only used as handle */ typedef struct Render Render; @@ -81,7 +81,7 @@ typedef struct RenderLayer { struct RenderLayer *next, *prev; /* copy of RenderData */ - char name[RE_MAXNAME]; + char name[RE_MAXNAME]; unsigned int lay, lay_zmask, lay_exclude; int layflag, passflag, pass_xor; @@ -144,8 +144,7 @@ typedef struct RenderStats { short curfield, curblur, curpart, partsdone, convertdone, curfsa; double starttime, lastframetime; const char *infostr, *statstr; - char scenename[32]; - + char scene_name[MAX_ID_NAME - 2]; } RenderStats; /* *********************** API ******************** */ diff --git a/source/blender/render/intern/raytrace/rayobject_qbvh.cpp b/source/blender/render/intern/raytrace/rayobject_qbvh.cpp index 2e37782d047..16d70297a34 100644 --- a/source/blender/render/intern/raytrace/rayobject_qbvh.cpp +++ b/source/blender/render/intern/raytrace/rayobject_qbvh.cpp @@ -151,7 +151,7 @@ RayObject *RE_rayobject_qbvh_create(int size) #else -RayObject *RE_rayobject_qbvh_create(int size) +RayObject *RE_rayobject_qbvh_create(int UNUSED(size)) { puts("WARNING: SSE disabled at compile time\n"); return NULL; diff --git a/source/blender/render/intern/raytrace/rayobject_svbvh.cpp b/source/blender/render/intern/raytrace/rayobject_svbvh.cpp index 697ba9ad6e2..c1bdfa6c72c 100644 --- a/source/blender/render/intern/raytrace/rayobject_svbvh.cpp +++ b/source/blender/render/intern/raytrace/rayobject_svbvh.cpp @@ -183,7 +183,7 @@ RayObject *RE_rayobject_svbvh_create(int size) #else -RayObject *RE_rayobject_svbvh_create(int size) +RayObject *RE_rayobject_svbvh_create(int UNUSED(size)) { puts("WARNING: SSE disabled at compile time\n"); return NULL; diff --git a/source/blender/render/intern/source/convertblender.c b/source/blender/render/intern/source/convertblender.c index 19a474df342..2dcd0f7c70a 100644 --- a/source/blender/render/intern/source/convertblender.c +++ b/source/blender/render/intern/source/convertblender.c @@ -526,7 +526,7 @@ typedef struct { } SRenderMeshToTangent; -// interface +/* interface */ #include "mikktspace.h" static int GetNumFaces(const SMikkTSpaceContext * pContext) @@ -1030,7 +1030,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 */ @@ -1090,7 +1090,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); @@ -1102,8 +1102,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); @@ -1164,7 +1164,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); @@ -1181,11 +1181,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); @@ -1210,9 +1210,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); @@ -1226,8 +1226,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); @@ -1310,7 +1310,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); @@ -1631,12 +1631,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; @@ -2088,10 +2088,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); @@ -3286,7 +3286,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; @@ -3511,7 +3511,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]; @@ -3776,7 +3776,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; @@ -3827,7 +3827,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; @@ -3862,7 +3862,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; @@ -3947,7 +3947,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 */ } @@ -4290,8 +4290,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); @@ -5098,7 +5098,7 @@ void RE_Database_FromScene(Render *re, Main *bmain, Scene *scene, unsigned int l /* per second, per object, stats print this */ re->i.infostr= "Preparing Scene data"; re->i.cfra= scene->r.cfra; - BLI_strncpy(re->i.scenename, scene->id.name+2, sizeof(re->i.scenename)); + BLI_strncpy(re->i.scene_name, scene->id.name + 2, sizeof(re->i.scene_name)); /* XXX add test if dbase was filled already? */ @@ -5538,7 +5538,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]; @@ -5550,31 +5550,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 @@ -5711,7 +5711,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 */ @@ -5724,7 +5724,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..1180e74d391 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); } @@ -305,7 +305,7 @@ int RE_engine_render(Render *re, int do_all) /* set render info */ re->i.cfra = re->scene->r.cfra; - BLI_strncpy(re->i.scenename, re->scene->id.name + 2, sizeof(re->i.scenename)); + BLI_strncpy(re->i.scene_name, re->scene->id.name + 2, sizeof(re->i.scene_name)); re->i.totface = re->i.totvert = re->i.totstrand = re->i.totlamp = re->i.tothalo = 0; /* render */ 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 b3eb8c0fd5c..485dd005be7 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); @@ -175,9 +175,9 @@ 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,40 @@ 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]) +/* TODO: exact duplicate of ff_visible_quad() in math_geom.c + * why not de-duplicate? (also above helper func) */ +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 +791,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 +814,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 +862,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 +885,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 +921,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 +944,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 +999,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 +1057,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 +1080,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 +1120,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; @@ -1127,6 +1131,8 @@ static void normalizef(float *n) } } +/* TODO: exact duplicate of ff_quad_form_factor() in math_geom.c + * why not de-duplicate? (also above helper func) */ static float occ_quad_form_factor(const float p[3], const float n[3], const float q0[3], const float q1[3], const float q2[3], const float q3[3]) { float r0[3], r1[3], r2[3], r3[3], g0[3], g1[3], g2[3], g3[3]; @@ -1147,18 +1153,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 +1173,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 +1220,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 +1329,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 +1350,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 +1370,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 +1386,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 +1405,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 +1431,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 +1474,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 +1489,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 +1508,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 +1528,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 +1559,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 +1571,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 +1606,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 +1618,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 +1661,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 +1674,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 +1702,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 +1736,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 +1762,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 +1773,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 +1868,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 +1886,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 +1903,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/pipeline.c b/source/blender/render/intern/source/pipeline.c index e3ecfc49a4b..701d21fbbd0 100644 --- a/source/blender/render/intern/source/pipeline.c +++ b/source/blender/render/intern/source/pipeline.c @@ -169,9 +169,9 @@ static void stats_background(void *UNUSED(arg), RenderStats *rs) } else { if (rs->tothalo) - fprintf(stdout, "Sce: %s Ve:%d Fa:%d Ha:%d La:%d", rs->scenename, rs->totvert, rs->totface, rs->tothalo, rs->totlamp); + fprintf(stdout, "Sce: %s Ve:%d Fa:%d Ha:%d La:%d", rs->scene_name, rs->totvert, rs->totface, rs->tothalo, rs->totlamp); else - fprintf(stdout, "Sce: %s Ve:%d Fa:%d La:%d", rs->scenename, rs->totvert, rs->totface, rs->totlamp); + fprintf(stdout, "Sce: %s Ve:%d Fa:%d La:%d", rs->scene_name, rs->totvert, rs->totface, rs->totlamp); } BLI_callback_exec(G.main, NULL, BLI_CB_EVT_RENDER_STATS); 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 3fd59b5e67c..9eb3f78635f 100644 --- a/source/blender/render/intern/source/render_result.c +++ b/source/blender/render/intern/source/render_result.c @@ -461,7 +461,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; @@ -585,7 +585,7 @@ RenderResult *render_result_new_full_sample(Render *re, ListBase *lb, rcti *part } /* callbacks for render_result_new_from_exr */ -static void *ml_addlayer_cb(void *base, char *str) +static void *ml_addlayer_cb(void *base, const char *str) { RenderResult *rr = base; RenderLayer *rl; @@ -597,7 +597,7 @@ static void *ml_addlayer_cb(void *base, char *str) return rl; } -static void ml_addpass_cb(void *UNUSED(base), void *lay, char *str, float *rect, int totchan, char *chan_id) +static void ml_addpass_cb(void *UNUSED(base), void *lay, const char *str, float *rect, int totchan, const char *chan_id) { RenderLayer *rl = lay; RenderPass *rpass = MEM_callocN(sizeof(RenderPass), "loaded pass"); @@ -621,7 +621,7 @@ static void ml_addpass_cb(void *UNUSED(base), void *lay, char *str, float *rect, /* from imbuf, if a handle was returned we convert this to render result */ RenderResult *render_result_new_from_exr(void *exrhandle, int rectx, int recty) { - RenderResult *rr = MEM_callocN(sizeof(RenderResult), "loaded render result"); + RenderResult *rr = MEM_callocN(sizeof(RenderResult), __func__); RenderLayer *rl; RenderPass *rpass; 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..e13da98ecb4 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; @@ -1824,7 +1824,7 @@ static void isb_bsp_face_inside(ISBBranch *bspn, BSPFace *face) if ((samp->facenr!=face->facenr || samp->obi!=face->obi) && samp->shadfac) { if (face->box.zmin < samp->zco[2]) { - if (BLI_in_rctf((rctf *)&face->box, samp->zco[0], samp->zco[1])) { + if (BLI_in_rctf_v((rctf *)&face->box, samp->zco)) { int inshadow= 0; if (face->type) { diff --git a/source/blender/render/intern/source/shadeinput.c b/source/blender/render/intern/source/shadeinput.c index f9b0de5b87d..bbdcfbb5a73 100644 --- a/source/blender/render/intern/source/shadeinput.c +++ b/source/blender/render/intern/source/shadeinput.c @@ -97,8 +97,8 @@ extern struct Render R; void shade_input_init_material(ShadeInput *shi) { /* note, keep this synced with render_types.h */ - memcpy(&shi->r, &shi->mat->r, 23*sizeof(float)); - shi->har= shi->mat->har; + memcpy(&shi->r, &shi->mat->r, 23 * sizeof(float)); + shi->har = shi->mat->har; } /* also used as callback for nodes */ @@ -106,16 +106,16 @@ void shade_input_init_material(ShadeInput *shi) void shade_material_loop(ShadeInput *shi, ShadeResult *shr) { - shade_lamp_loop(shi, shr); /* clears shr */ + shade_lamp_loop(shi, shr); /* clears shr */ - if (shi->translucency!=0.0f) { + if (shi->translucency != 0.0f) { ShadeResult shr_t; - float fac= shi->translucency; + float fac = shi->translucency; shade_input_init_material(shi); negate_v3_v3(shi->vn, shi->vno); negate_v3(shi->facenor); - shi->depth++; /* hack to get real shadow now */ + shi->depth++; /* hack to get real shadow now */ shade_lamp_loop(shi, &shr_t); shi->depth--; @@ -133,17 +133,17 @@ void shade_material_loop(ShadeInput *shi, ShadeResult *shr) } /* depth >= 1 when ray-shading */ - if (shi->depth==0 || shi->volume_depth > 0) { + if (shi->depth == 0 || shi->volume_depth > 0) { if (R.r.mode & R_RAYTRACE) { - if (shi->ray_mirror!=0.0f || ((shi->mode & MA_TRANSP) && (shi->mode & MA_RAYTRANSP) && shr->alpha!=1.0f)) { + if (shi->ray_mirror != 0.0f || ((shi->mode & MA_TRANSP) && (shi->mode & MA_RAYTRANSP) && shr->alpha != 1.0f)) { /* ray trace works on combined, but gives pass info */ ray_trace(shi, shr); } } /* disable adding of sky for raytransp */ if ((shi->mode & MA_TRANSP) && (shi->mode & MA_RAYTRANSP)) - if ((shi->layflag & SCE_LAY_SKY) && (R.r.alphamode==R_ADDSKY)) - shr->alpha= 1.0f; + if ((shi->layflag & SCE_LAY_SKY) && (R.r.alphamode == R_ADDSKY)) + shr->alpha = 1.0f; } if (R.r.mode & R_RAYTRACE) { @@ -181,38 +181,38 @@ void shade_input_do_shade(ShadeInput *shi, ShadeResult *shr) } /* copy additional passes */ - if (shi->passflag & (SCE_PASS_VECTOR|SCE_PASS_NORMAL)) { + if (shi->passflag & (SCE_PASS_VECTOR | SCE_PASS_NORMAL)) { copy_v4_v4(shr->winspeed, shi->winspeed); copy_v3_v3(shr->nor, shi->vn); } /* MIST */ - if ((shi->passflag & SCE_PASS_MIST) || ((R.wrld.mode & WO_MIST) && (shi->mat->mode & MA_NOMIST)==0)) { + if ((shi->passflag & SCE_PASS_MIST) || ((R.wrld.mode & WO_MIST) && (shi->mat->mode & MA_NOMIST) == 0)) { if (R.r.mode & R_ORTHO) - shr->mist= mistfactor(-shi->co[2], shi->co); + shr->mist = mistfactor(-shi->co[2], shi->co); else - shr->mist= mistfactor(len_v3(shi->co), shi->co); + shr->mist = mistfactor(len_v3(shi->co), shi->co); } - else shr->mist= 0.0f; + else shr->mist = 0.0f; - if ((R.wrld.mode & WO_MIST) && (shi->mat->mode & MA_NOMIST)==0 ) { - alpha= shr->mist; + if ((R.wrld.mode & WO_MIST) && (shi->mat->mode & MA_NOMIST) == 0) { + alpha = shr->mist; } - else alpha= 1.0f; + else alpha = 1.0f; /* add mist and premul color */ - if (shr->alpha!=1.0f || alpha!=1.0f) { - float fac= alpha*(shr->alpha); - shr->combined[3]= fac; + if (shr->alpha != 1.0f || alpha != 1.0f) { + float fac = alpha * (shr->alpha); + shr->combined[3] = fac; - if (shi->mat->material_type!= MA_TYPE_VOLUME) + if (shi->mat->material_type != MA_TYPE_VOLUME) mul_v3_fl(shr->combined, fac); } else - shr->combined[3]= 1.0f; + shr->combined[3] = 1.0f; /* add z */ - shr->z= -shi->co[2]; + shr->z = -shi->co[2]; /* RAYHITS */ #if 0 @@ -258,28 +258,28 @@ void vlr_set_uv_indices(VlakRen *vlr, int *i1, int *i2, int *i3) /* indices 0 1 2 3 only */ void shade_input_set_triangle_i(ShadeInput *shi, ObjectInstanceRen *obi, VlakRen *vlr, short i1, short i2, short i3) { - VertRen **vpp= &vlr->v1; + VertRen **vpp = &vlr->v1; - shi->vlr= vlr; - shi->obi= obi; - shi->obr= obi->obr; + shi->vlr = vlr; + shi->obi = obi; + shi->obr = obi->obr; - shi->v1= vpp[i1]; - shi->v2= vpp[i2]; - shi->v3= vpp[i3]; - - shi->i1= i1; - shi->i2= i2; - shi->i3= i3; + shi->v1 = vpp[i1]; + shi->v2 = vpp[i2]; + shi->v3 = vpp[i3]; + + shi->i1 = i1; + shi->i2 = i2; + shi->i3 = i3; /* note, shi->mat is set in node shaders */ - shi->mat= shi->mat_override?shi->mat_override:vlr->mat; + shi->mat = shi->mat_override ? shi->mat_override : vlr->mat; - shi->osatex= (shi->mat->texco & TEXCO_OSA); - shi->mode= shi->mat->mode_l; /* or-ed result for all nodes */ + shi->osatex = (shi->mat->texco & TEXCO_OSA); + shi->mode = shi->mat->mode_l; /* or-ed result for all nodes */ /* facenormal copy, can get flipped */ - shi->flippednor= 0; + shi->flippednor = 0; RE_vlakren_get_normal(&R, obi, vlr, shi->facenor); /* calculate vertexnormals */ @@ -303,12 +303,12 @@ void shade_input_set_triangle_i(ShadeInput *shi, ObjectInstanceRen *obi, VlakRen /* copy data from face to ShadeInput, scanline case */ void shade_input_set_triangle(ShadeInput *shi, volatile int obi, volatile int facenr, int UNUSED(normal_flip)) { - if (facenr>0) { - shi->obi= &R.objectinstance[obi]; - shi->obr= shi->obi->obr; - shi->facenr= (facenr-1) & RE_QUAD_MASK; - if ( shi->facenr < shi->obr->totvlak ) { - VlakRen *vlr= RE_findOrAddVlak(shi->obr, shi->facenr); + if (facenr > 0) { + shi->obi = &R.objectinstance[obi]; + shi->obr = shi->obi->obr; + shi->facenr = (facenr - 1) & RE_QUAD_MASK; + if (shi->facenr < shi->obr->totvlak) { + VlakRen *vlr = RE_findOrAddVlak(shi->obr, shi->facenr); if (facenr & RE_QUAD_OFFS) shade_input_set_triangle_i(shi, shi->obi, vlr, 0, 2, 3); @@ -316,10 +316,10 @@ void shade_input_set_triangle(ShadeInput *shi, volatile int obi, volatile int fa shade_input_set_triangle_i(shi, shi->obi, vlr, 0, 1, 2); } else - shi->vlr= NULL; /* general signal we got sky */ + shi->vlr = NULL; /* general signal we got sky */ } else - shi->vlr= NULL; /* general signal we got sky */ + shi->vlr = NULL; /* general signal we got sky */ } /* full osa case: copy static info */ @@ -333,18 +333,18 @@ void shade_input_copy_triangle(ShadeInput *shi, ShadeInput *from) void shade_input_set_strand(ShadeInput *shi, StrandRen *strand, StrandPoint *spoint) { /* note, shi->mat is set in node shaders */ - shi->mat= shi->mat_override? shi->mat_override: strand->buffer->ma; + shi->mat = shi->mat_override ? shi->mat_override : strand->buffer->ma; - shi->osatex= (shi->mat->texco & TEXCO_OSA); - shi->mode= shi->mat->mode_l; /* or-ed result for all nodes */ + shi->osatex = (shi->mat->texco & TEXCO_OSA); + shi->mode = shi->mat->mode_l; /* or-ed result for all nodes */ /* shade_input_set_viewco equivalent */ copy_v3_v3(shi->co, spoint->co); copy_v3_v3(shi->view, shi->co); normalize_v3(shi->view); - shi->xs= (int)spoint->x; - shi->ys= (int)spoint->y; + shi->xs = (int)spoint->x; + shi->ys = (int)spoint->y; if (shi->osatex || (R.r.mode & R_SHADOW)) { copy_v3_v3(shi->dxco, spoint->dtco); @@ -376,27 +376,27 @@ void shade_input_set_strand(ShadeInput *shi, StrandRen *strand, StrandPoint *spo void shade_input_set_strand_texco(ShadeInput *shi, StrandRen *strand, StrandVert *svert, StrandPoint *spoint) { - StrandBuffer *strandbuf= strand->buffer; - ObjectRen *obr= strandbuf->obr; + StrandBuffer *strandbuf = strand->buffer; + ObjectRen *obr = strandbuf->obr; StrandVert *sv; - int mode= shi->mode; /* or-ed result for all nodes */ - short texco= shi->mat->texco; + int mode = shi->mode; /* or-ed result for all nodes */ + short texco = shi->mat->texco; if ((shi->mat->texco & TEXCO_REFL)) { /* shi->dxview, shi->dyview, not supported */ } - if (shi->osatex && (texco & (TEXCO_NORM|TEXCO_REFL))) { + if (shi->osatex && (texco & (TEXCO_NORM | TEXCO_REFL))) { /* not supported */ } - if (mode & (MA_TANGENT_V|MA_NORMAP_TANG)) { + if (mode & (MA_TANGENT_V | MA_NORMAP_TANG)) { copy_v3_v3(shi->tang, spoint->tan); copy_v3_v3(shi->nmaptang, spoint->tan); } if (mode & MA_STR_SURFDIFF) { - float *surfnor= RE_strandren_get_surfnor(obr, strand, 0); + float *surfnor = RE_strandren_get_surfnor(obr, strand, 0); if (surfnor) copy_v3_v3(shi->surfnor, surfnor); @@ -404,21 +404,21 @@ void shade_input_set_strand_texco(ShadeInput *shi, StrandRen *strand, StrandVert copy_v3_v3(shi->surfnor, shi->vn); if (shi->mat->strand_surfnor > 0.0f) { - shi->surfdist= 0.0f; - for (sv=strand->vert; sv!=svert; sv++) - shi->surfdist+=len_v3v3(sv->co, (sv+1)->co); - shi->surfdist += spoint->t*len_v3v3(sv->co, (sv+1)->co); + shi->surfdist = 0.0f; + for (sv = strand->vert; sv != svert; sv++) + shi->surfdist += len_v3v3(sv->co, (sv + 1)->co); + shi->surfdist += spoint->t * len_v3v3(sv->co, (sv + 1)->co); } } if (R.r.mode & R_SPEED) { float *speed; - speed= RE_strandren_get_winspeed(shi->obi, strand, 0); + speed = RE_strandren_get_winspeed(shi->obi, strand, 0); if (speed) copy_v4_v4(shi->winspeed, speed); else - shi->winspeed[0]= shi->winspeed[1]= shi->winspeed[2]= shi->winspeed[3]= 0.0f; + shi->winspeed[0] = shi->winspeed[1] = shi->winspeed[2] = shi->winspeed[3] = 0.0f; } /* shade_input_set_shade_texco equivalent */ @@ -441,109 +441,109 @@ void shade_input_set_strand_texco(ShadeInput *shi, StrandRen *strand, StrandVert } if (texco & TEXCO_STRAND) { - shi->strandco= spoint->strandco; + shi->strandco = spoint->strandco; if (shi->osatex) { - shi->dxstrand= spoint->dtstrandco; - shi->dystrand= 0.0f; + shi->dxstrand = spoint->dtstrandco; + shi->dystrand = 0.0f; } } - if ((texco & TEXCO_UV) || (mode & (MA_VERTEXCOL|MA_VERTEXCOLP|MA_FACETEXTURE))) { + if ((texco & TEXCO_UV) || (mode & (MA_VERTEXCOL | MA_VERTEXCOLP | MA_FACETEXTURE))) { MCol *mcol; float *uv; char *name; int i; - shi->totuv= 0; - shi->totcol= 0; - shi->actuv= obr->actmtface; - shi->actcol= obr->actmcol; + shi->totuv = 0; + shi->totcol = 0; + shi->actuv = obr->actmtface; + shi->actcol = obr->actmcol; - if (mode & (MA_VERTEXCOL|MA_VERTEXCOLP)) { - for (i=0; (mcol=RE_strandren_get_mcol(obr, strand, i, &name, 0)); i++) { - ShadeInputCol *scol= &shi->col[i]; - char *cp= (char*)mcol; + if (mode & (MA_VERTEXCOL | MA_VERTEXCOLP)) { + for (i = 0; (mcol = RE_strandren_get_mcol(obr, strand, i, &name, 0)); i++) { + ShadeInputCol *scol = &shi->col[i]; + char *cp = (char *)mcol; shi->totcol++; - scol->name= name; + scol->name = name; - scol->col[0]= cp[3]/255.0f; - scol->col[1]= cp[2]/255.0f; - scol->col[2]= cp[1]/255.0f; - scol->col[3]= cp[0]/255.0f; + scol->col[0] = cp[3] / 255.0f; + scol->col[1] = cp[2] / 255.0f; + scol->col[2] = cp[1] / 255.0f; + scol->col[3] = cp[0] / 255.0f; } if (shi->totcol) { - shi->vcol[0]= shi->col[shi->actcol].col[0]; - shi->vcol[1]= shi->col[shi->actcol].col[1]; - shi->vcol[2]= shi->col[shi->actcol].col[2]; - shi->vcol[3]= shi->col[shi->actcol].col[3]; + shi->vcol[0] = shi->col[shi->actcol].col[0]; + shi->vcol[1] = shi->col[shi->actcol].col[1]; + shi->vcol[2] = shi->col[shi->actcol].col[2]; + shi->vcol[3] = shi->col[shi->actcol].col[3]; } else { - shi->vcol[0]= 0.0f; - shi->vcol[1]= 0.0f; - shi->vcol[2]= 0.0f; - shi->vcol[3]= 0.0f; + shi->vcol[0] = 0.0f; + shi->vcol[1] = 0.0f; + shi->vcol[2] = 0.0f; + shi->vcol[3] = 0.0f; } } - for (i=0; (uv=RE_strandren_get_uv(obr, strand, i, &name, 0)); i++) { - ShadeInputUV *suv= &shi->uv[i]; + for (i = 0; (uv = RE_strandren_get_uv(obr, strand, i, &name, 0)); i++) { + ShadeInputUV *suv = &shi->uv[i]; shi->totuv++; - suv->name= name; + suv->name = name; if (strandbuf->overrideuv == i) { - suv->uv[0]= -1.0f; - suv->uv[1]= spoint->strandco; - suv->uv[2]= 0.0f; + suv->uv[0] = -1.0f; + suv->uv[1] = spoint->strandco; + suv->uv[2] = 0.0f; } else { - suv->uv[0]= -1.0f + 2.0f*uv[0]; - suv->uv[1]= -1.0f + 2.0f*uv[1]; - suv->uv[2]= 0.0f; /* texture.c assumes there are 3 coords */ + suv->uv[0] = -1.0f + 2.0f * uv[0]; + suv->uv[1] = -1.0f + 2.0f * uv[1]; + suv->uv[2] = 0.0f; /* texture.c assumes there are 3 coords */ } if (shi->osatex) { - suv->dxuv[0]= 0.0f; - suv->dxuv[1]= 0.0f; - suv->dyuv[0]= 0.0f; - suv->dyuv[1]= 0.0f; + suv->dxuv[0] = 0.0f; + suv->dxuv[1] = 0.0f; + suv->dyuv[0] = 0.0f; + suv->dyuv[1] = 0.0f; } - if ((mode & MA_FACETEXTURE) && i==obr->actmtface) { - if ((mode & (MA_VERTEXCOL|MA_VERTEXCOLP))==0) { - shi->vcol[0]= 1.0f; - shi->vcol[1]= 1.0f; - shi->vcol[2]= 1.0f; - shi->vcol[3]= 1.0f; + if ((mode & MA_FACETEXTURE) && i == obr->actmtface) { + if ((mode & (MA_VERTEXCOL | MA_VERTEXCOLP)) == 0) { + shi->vcol[0] = 1.0f; + shi->vcol[1] = 1.0f; + shi->vcol[2] = 1.0f; + shi->vcol[3] = 1.0f; } } } if (shi->totuv == 0) { - ShadeInputUV *suv= &shi->uv[0]; + ShadeInputUV *suv = &shi->uv[0]; - suv->uv[0]= 0.0f; - suv->uv[1]= spoint->strandco; - suv->uv[2]= 0.0f; /* texture.c assumes there are 3 coords */ + suv->uv[0] = 0.0f; + suv->uv[1] = spoint->strandco; + suv->uv[2] = 0.0f; /* texture.c assumes there are 3 coords */ if (mode & MA_FACETEXTURE) { /* no tface? set at 1.0f */ - shi->vcol[0]= 1.0f; - shi->vcol[1]= 1.0f; - shi->vcol[2]= 1.0f; - shi->vcol[3]= 1.0f; + shi->vcol[0] = 1.0f; + shi->vcol[1] = 1.0f; + shi->vcol[2] = 1.0f; + shi->vcol[3] = 1.0f; } } } if (texco & TEXCO_NORM) { - shi->orn[0]= -shi->vn[0]; - shi->orn[1]= -shi->vn[1]; - shi->orn[2]= -shi->vn[2]; + shi->orn[0] = -shi->vn[0]; + shi->orn[1] = -shi->vn[1]; + shi->orn[2] = -shi->vn[2]; } if (texco & TEXCO_STRESS) { @@ -551,27 +551,27 @@ void shade_input_set_strand_texco(ShadeInput *shi, StrandRen *strand, StrandVert } if (texco & TEXCO_TANGENT) { - if ((mode & MA_TANGENT_V)==0) { + if ((mode & MA_TANGENT_V) == 0) { /* just prevent surprises */ - shi->tang[0]= shi->tang[1]= shi->tang[2]= 0.0f; - shi->nmaptang[0]= shi->nmaptang[1]= shi->nmaptang[2]= 0.0f; + shi->tang[0] = shi->tang[1] = shi->tang[2] = 0.0f; + shi->nmaptang[0] = shi->nmaptang[1] = shi->nmaptang[2] = 0.0f; } } } /* this only avalailable for scanline renders */ - if (shi->depth==0) { + if (shi->depth == 0) { if (texco & TEXCO_WINDOW) { - shi->winco[0]= -1.0f + 2.0f*spoint->x/(float)R.winx; - shi->winco[1]= -1.0f + 2.0f*spoint->y/(float)R.winy; - shi->winco[2]= 0.0f; + shi->winco[0] = -1.0f + 2.0f * spoint->x / (float)R.winx; + shi->winco[1] = -1.0f + 2.0f * spoint->y / (float)R.winy; + shi->winco[2] = 0.0f; /* not supported */ if (shi->osatex) { - shi->dxwin[0]= 0.0f; - shi->dywin[1]= 0.0f; - shi->dxwin[0]= 0.0f; - shi->dywin[1]= 0.0f; + shi->dxwin[0] = 0.0f; + shi->dywin[1] = 0.0f; + shi->dxwin[0] = 0.0f; + shi->dywin[1] = 0.0f; } } @@ -581,7 +581,7 @@ void shade_input_set_strand_texco(ShadeInput *shi, StrandRen *strand, StrandVert } if (shi->do_manage) { - if (mode & (MA_VERTEXCOL|MA_VERTEXCOLP|MA_FACETEXTURE)) { + if (mode & (MA_VERTEXCOL | MA_VERTEXCOLP | MA_FACETEXTURE)) { srgb_to_linearrgb_v3_v3(shi->vcol, shi->vcol); } } @@ -615,37 +615,37 @@ void shade_input_calc_viewco(ShadeInput *shi, float x, float y, float z, float v /* ortho viewplane cannot intersect using view vector originating in (0,0,0) */ if (R.r.mode & R_ORTHO) { /* x and y 3d coordinate can be derived from pixel coord and winmat */ - float fx= 2.0f/(R.winx*R.winmat[0][0]); - float fy= 2.0f/(R.winy*R.winmat[1][1]); + float fx = 2.0f / (R.winx * R.winmat[0][0]); + float fy = 2.0f / (R.winy * R.winmat[1][1]); - co[0]= (x - 0.5f*R.winx)*fx - R.winmat[3][0]/R.winmat[0][0]; - co[1]= (y - 0.5f*R.winy)*fy - R.winmat[3][1]/R.winmat[1][1]; + co[0] = (x - 0.5f * R.winx) * fx - R.winmat[3][0] / R.winmat[0][0]; + co[1] = (y - 0.5f * R.winy) * fy - R.winmat[3][1] / R.winmat[1][1]; /* using a*x + b*y + c*z = d equation, (a b c) is normal */ - if (shi->facenor[2]!=0.0f) - co[2]= (dface - shi->facenor[0]*co[0] - shi->facenor[1]*co[1])/shi->facenor[2]; + if (shi->facenor[2] != 0.0f) + co[2] = (dface - shi->facenor[0] * co[0] - shi->facenor[1] * co[1]) / shi->facenor[2]; else - co[2]= 0.0f; + co[2] = 0.0f; if (dxco && dyco) { - dxco[0]= fx; - dxco[1]= 0.0f; - if (shi->facenor[2]!=0.0f) - dxco[2]= -(shi->facenor[0]*fx)/shi->facenor[2]; + dxco[0] = fx; + dxco[1] = 0.0f; + if (shi->facenor[2] != 0.0f) + dxco[2] = -(shi->facenor[0] * fx) / shi->facenor[2]; else - dxco[2]= 0.0f; + dxco[2] = 0.0f; - dyco[0]= 0.0f; - dyco[1]= fy; - if (shi->facenor[2]!=0.0f) - dyco[2]= -(shi->facenor[1]*fy)/shi->facenor[2]; + dyco[0] = 0.0f; + dyco[1] = fy; + if (shi->facenor[2] != 0.0f) + dyco[2] = -(shi->facenor[1] * fy) / shi->facenor[2]; else - dyco[2]= 0.0f; + dyco[2] = 0.0f; if (dxyview) { - if (co[2]!=0.0f) fac= 1.0f/co[2]; else fac= 0.0f; - dxyview[0]= -R.viewdx*fac; - dxyview[1]= -R.viewdy*fac; + if (co[2] != 0.0f) fac = 1.0f / co[2]; else fac = 0.0f; + dxyview[0] = -R.viewdx * fac; + dxyview[1] = -R.viewdy * fac; } } } @@ -653,30 +653,30 @@ void shade_input_calc_viewco(ShadeInput *shi, float x, float y, float z, float v float div; div = dot_v3v3(shi->facenor, view); - if (div!=0.0f) fac= dface/div; - else fac= 0.0f; + if (div != 0.0f) fac = dface / div; + else fac = 0.0f; - co[0]= fac*view[0]; - co[1]= fac*view[1]; - co[2]= fac*view[2]; + co[0] = fac * view[0]; + co[1] = fac * view[1]; + co[2] = fac * view[2]; /* pixel dx/dy for render coord */ if (dxco && dyco) { - float u= dface/(div - R.viewdx*shi->facenor[0]); - float v= dface/(div - R.viewdy*shi->facenor[1]); - - dxco[0]= co[0]- (view[0]-R.viewdx)*u; - dxco[1]= co[1]- (view[1])*u; - dxco[2]= co[2]- (view[2])*u; + float u = dface / (div - R.viewdx * shi->facenor[0]); + float v = dface / (div - R.viewdy * shi->facenor[1]); - dyco[0]= co[0]- (view[0])*v; - dyco[1]= co[1]- (view[1]-R.viewdy)*v; - dyco[2]= co[2]- (view[2])*v; + dxco[0] = co[0] - (view[0] - R.viewdx) * u; + dxco[1] = co[1] - (view[1]) * u; + dxco[2] = co[2] - (view[2]) * u; + + dyco[0] = co[0] - (view[0]) * v; + dyco[1] = co[1] - (view[1] - R.viewdy) * v; + dyco[2] = co[2] - (view[2]) * v; if (dxyview) { - if (fac!=0.0f) fac= 1.0f/fac; - dxyview[0]= -R.viewdx*fac; - dxyview[1]= -R.viewdy*fac; + if (fac != 0.0f) fac = 1.0f / fac; + dxyview[0] = -R.viewdx * fac; + dxyview[1] = -R.viewdy * fac; } } } @@ -693,24 +693,24 @@ void shade_input_calc_viewco(ShadeInput *shi, float x, float y, float z, float v /* from scanline pixel coordinates to 3d coordinates, requires set_triangle */ void shade_input_set_viewco(ShadeInput *shi, float x, float y, float xs, float ys, float z) { - float *dxyview= NULL, *dxco= NULL, *dyco= NULL; + float *dxyview = NULL, *dxco = NULL, *dyco = NULL; /* currently in use for dithering (soft shadow), node preview, irregular shad */ - shi->xs= (int)xs; - shi->ys= (int)ys; + shi->xs = (int)xs; + shi->ys = (int)ys; /* original scanline coordinate without jitter */ - shi->scanco[0]= x; - shi->scanco[1]= y; - shi->scanco[2]= z; + shi->scanco[0] = x; + shi->scanco[1] = y; + shi->scanco[2] = z; /* check if we need derivatives */ if (shi->osatex || (R.r.mode & R_SHADOW)) { - dxco= shi->dxco; - dyco= shi->dyco; + dxco = shi->dxco; + dyco = shi->dyco; if ((shi->mat->texco & TEXCO_REFL)) - dxyview= &shi->dxview; + dxyview = &shi->dxview; } shade_input_calc_viewco(shi, xs, ys, z, shi->view, dxyview, shi->co, dxco, dyco); @@ -719,7 +719,7 @@ void shade_input_set_viewco(ShadeInput *shi, float x, float y, float xs, float y /* calculate U and V, for scanline (silly render face u and v are in range -1 to 0) */ void shade_input_set_uv(ShadeInput *shi) { - VlakRen *vlr= shi->vlr; + VlakRen *vlr = shi->vlr; if ((vlr->flag & R_SMOOTH) || (shi->mat->texco & NEED_UV) || (shi->passflag & SCE_PASS_UV)) { float v1[3], v2[3], v3[3]; @@ -735,25 +735,25 @@ void shade_input_set_uv(ShadeInput *shi) } /* exception case for wire render of edge */ - if (vlr->v2==vlr->v3) { + if (vlr->v2 == vlr->v3) { float lend, lenc; - lend= len_v3v3(v2, v1); - lenc= len_v3v3(shi->co, v1); + lend = len_v3v3(v2, v1); + lenc = len_v3v3(shi->co, v1); - if (lend==0.0f) { - shi->u=shi->v= 0.0f; + if (lend == 0.0f) { + shi->u = shi->v = 0.0f; } else { - shi->u= - (1.0f - lenc/lend); - shi->v= 0.0f; + shi->u = -(1.0f - lenc / lend); + shi->v = 0.0f; } if (shi->osatex) { - shi->dx_u= 0.0f; - shi->dx_v= 0.0f; - shi->dy_u= 0.0f; - shi->dy_v= 0.0f; + shi->dx_u = 0.0f; + shi->dx_v = 0.0f; + shi->dy_u = 0.0f; + shi->dy_v = 0.0f; } } else { @@ -765,21 +765,21 @@ void shade_input_set_uv(ShadeInput *shi) axis_dominant_v3(&axis1, &axis2, shi->facenor); /* compute u,v and derivatives */ - t00= v3[axis1]-v1[axis1]; t01= v3[axis2]-v1[axis2]; - t10= v3[axis1]-v2[axis1]; t11= v3[axis2]-v2[axis2]; + t00 = v3[axis1] - v1[axis1]; t01 = v3[axis2] - v1[axis2]; + t10 = v3[axis1] - v2[axis1]; t11 = v3[axis2] - v2[axis2]; - detsh= (t00*t11-t10*t01); - detsh= (detsh != 0.0f)? 1.0f/detsh: 0.0f; - t00*= detsh; t01*=detsh; - t10*=detsh; t11*=detsh; + detsh = (t00 * t11 - t10 * t01); + detsh = (detsh != 0.0f) ? 1.0f / detsh : 0.0f; + t00 *= detsh; t01 *= detsh; + t10 *= detsh; t11 *= detsh; - shi->u= (shi->co[axis1]-v3[axis1])*t11-(shi->co[axis2]-v3[axis2])*t10; - shi->v= (shi->co[axis2]-v3[axis2])*t00-(shi->co[axis1]-v3[axis1])*t01; + shi->u = (shi->co[axis1] - v3[axis1]) * t11 - (shi->co[axis2] - v3[axis2]) * t10; + shi->v = (shi->co[axis2] - v3[axis2]) * t00 - (shi->co[axis1] - v3[axis1]) * t01; if (shi->osatex) { - shi->dx_u= shi->dxco[axis1]*t11- shi->dxco[axis2]*t10; - shi->dx_v= shi->dxco[axis2]*t00- shi->dxco[axis1]*t01; - shi->dy_u= shi->dyco[axis1]*t11- shi->dyco[axis2]*t10; - shi->dy_v= shi->dyco[axis2]*t00- shi->dyco[axis1]*t01; + shi->dx_u = shi->dxco[axis1] * t11 - shi->dxco[axis2] * t10; + shi->dx_v = shi->dxco[axis2] * t00 - shi->dxco[axis1] * t01; + shi->dy_u = shi->dyco[axis1] * t11 - shi->dyco[axis2] * t10; + shi->dy_v = shi->dyco[axis2] * t00 - shi->dyco[axis1] * t01; } /* u and v are in range -1 to 0, we allow a little bit extra but not too much, screws up speedvectors */ @@ -791,8 +791,8 @@ void shade_input_set_uv(ShadeInput *shi) void shade_input_set_normals(ShadeInput *shi) { - float u= shi->u, v= shi->v; - float l= 1.0f+u+v; + float u = shi->u, v = shi->v; + float l = 1.0f + u + v; shi->flippednor = 0; @@ -800,13 +800,13 @@ void shade_input_set_normals(ShadeInput *shi) if (!(shi->vlr->flag & R_TANGENT)) { if (dot_v3v3(shi->facenor, shi->view) < 0.0f) { negate_v3(shi->facenor); - shi->flippednor= 1; + shi->flippednor = 1; } } /* calculate vertexnormals */ if (shi->vlr->flag & R_SMOOTH) { - float *n1= shi->n1, *n2= shi->n2, *n3= shi->n3; + float *n1 = shi->n1, *n2 = shi->n2, *n3 = shi->n3; if (shi->flippednor) { negate_v3(n1); @@ -814,11 +814,11 @@ void shade_input_set_normals(ShadeInput *shi) negate_v3(n3); } - shi->vn[0]= l*n3[0]-u*n1[0]-v*n2[0]; - shi->vn[1]= l*n3[1]-u*n1[1]-v*n2[1]; - shi->vn[2]= l*n3[2]-u*n1[2]-v*n2[2]; + shi->vn[0] = l * n3[0] - u * n1[0] - v * n2[0]; + 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); @@ -840,18 +840,18 @@ void shade_input_set_normals(ShadeInput *shi) /* XXX shi->flippednor messes up otherwise */ void shade_input_set_vertex_normals(ShadeInput *shi) { - float u= shi->u, v= shi->v; - float l= 1.0f+u+v; + float u = shi->u, v = shi->v; + float l = 1.0f + u + v; /* calculate vertexnormals */ if (shi->vlr->flag & R_SMOOTH) { - float *n1= shi->n1, *n2= shi->n2, *n3= shi->n3; + const float *n1 = shi->n1, *n2 = shi->n2, *n3 = shi->n3; - shi->vn[0]= l*n3[0]-u*n1[0]-v*n2[0]; - shi->vn[1]= l*n3[1]-u*n1[1]-v*n2[1]; - shi->vn[2]= l*n3[2]-u*n1[2]-v*n2[2]; + shi->vn[0] = l * n3[0] - u * n1[0] - v * n2[0]; + 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); @@ -869,73 +869,61 @@ void shade_input_set_vertex_normals(ShadeInput *shi) /* use by raytrace, sss, bake to flip into the right direction */ void shade_input_flip_normals(ShadeInput *shi) { - shi->facenor[0]= -shi->facenor[0]; - shi->facenor[1]= -shi->facenor[1]; - shi->facenor[2]= -shi->facenor[2]; - - shi->vn[0]= -shi->vn[0]; - shi->vn[1]= -shi->vn[1]; - shi->vn[2]= -shi->vn[2]; - - shi->vno[0]= -shi->vno[0]; - shi->vno[1]= -shi->vno[1]; - shi->vno[2]= -shi->vno[2]; - - shi->nmapnorm[0] = -shi->nmapnorm[0]; - shi->nmapnorm[1] = -shi->nmapnorm[1]; - shi->nmapnorm[2] = -shi->nmapnorm[2]; - - shi->flippednor= !shi->flippednor; + negate_v3(shi->facenor); + negate_v3(shi->vn); + negate_v3(shi->vno); + negate_v3(shi->nmapnorm); + shi->flippednor = !shi->flippednor; } void shade_input_set_shade_texco(ShadeInput *shi) { - ObjectInstanceRen *obi= shi->obi; - ObjectRen *obr= shi->obr; - VertRen *v1= shi->v1, *v2= shi->v2, *v3= shi->v3; - float u= shi->u, v= shi->v; - float l= 1.0f+u+v, dl; - int mode= shi->mode; /* or-ed result for all nodes */ - short texco= shi->mat->texco; + ObjectInstanceRen *obi = shi->obi; + ObjectRen *obr = shi->obr; + VertRen *v1 = shi->v1, *v2 = shi->v2, *v3 = shi->v3; + float u = shi->u, v = shi->v; + float l = 1.0f + u + v, dl; + int mode = shi->mode; /* or-ed result for all nodes */ + short texco = shi->mat->texco; /* calculate dxno */ if (shi->vlr->flag & R_SMOOTH) { - if (shi->osatex && (texco & (TEXCO_NORM|TEXCO_REFL)) ) { - float *n1= shi->n1, *n2= shi->n2, *n3= shi->n3; + if (shi->osatex && (texco & (TEXCO_NORM | TEXCO_REFL)) ) { + float *n1 = shi->n1, *n2 = shi->n2, *n3 = shi->n3; - dl= shi->dx_u+shi->dx_v; - shi->dxno[0]= dl*n3[0]-shi->dx_u*n1[0]-shi->dx_v*n2[0]; - shi->dxno[1]= dl*n3[1]-shi->dx_u*n1[1]-shi->dx_v*n2[1]; - shi->dxno[2]= dl*n3[2]-shi->dx_u*n1[2]-shi->dx_v*n2[2]; - dl= shi->dy_u+shi->dy_v; - shi->dyno[0]= dl*n3[0]-shi->dy_u*n1[0]-shi->dy_v*n2[0]; - shi->dyno[1]= dl*n3[1]-shi->dy_u*n1[1]-shi->dy_v*n2[1]; - shi->dyno[2]= dl*n3[2]-shi->dy_u*n1[2]-shi->dy_v*n2[2]; + dl = shi->dx_u + shi->dx_v; + shi->dxno[0] = dl * n3[0] - shi->dx_u * n1[0] - shi->dx_v * n2[0]; + shi->dxno[1] = dl * n3[1] - shi->dx_u * n1[1] - shi->dx_v * n2[1]; + shi->dxno[2] = dl * n3[2] - shi->dx_u * n1[2] - shi->dx_v * n2[2]; + dl = shi->dy_u + shi->dy_v; + shi->dyno[0] = dl * n3[0] - shi->dy_u * n1[0] - shi->dy_v * n2[0]; + shi->dyno[1] = dl * n3[1] - shi->dy_u * n1[1] - shi->dy_v * n2[1]; + shi->dyno[2] = dl * n3[2] - shi->dy_u * n1[2] - shi->dy_v * n2[2]; } } /* calc tangents */ - if (mode & (MA_TANGENT_V|MA_NORMAP_TANG) || R.flag & R_NEED_TANGENT) { + if (mode & (MA_TANGENT_V | MA_NORMAP_TANG) || R.flag & R_NEED_TANGENT) { float *tangent, *s1, *s2, *s3; float tl, tu, tv; if (shi->vlr->flag & R_SMOOTH) { - tl= l; - tu= u; - tv= v; + tl = l; + tu = u; + tv = v; } else { /* qdn: flat faces have tangents too, * could pick either one, using average here */ - tl= 1.0f/3.0f; - tu= -1.0f/3.0f; - tv= -1.0f/3.0f; + tl = 1.0f / 3.0f; + tu = -1.0f / 3.0f; + tv = -1.0f / 3.0f; } - shi->tang[0]= shi->tang[1]= shi->tang[2]= 0.0f; - shi->nmaptang[0]= shi->nmaptang[1]= shi->nmaptang[2]= 0.0f; + shi->tang[0] = shi->tang[1] = shi->tang[2] = 0.0f; + shi->nmaptang[0] = shi->nmaptang[1] = shi->nmaptang[2] = 0.0f; if (mode & MA_TANGENT_V) { s1 = RE_vertren_get_tangent(obr, v1, 0); @@ -943,9 +931,9 @@ void shade_input_set_shade_texco(ShadeInput *shi) s3 = RE_vertren_get_tangent(obr, v3, 0); if (s1 && s2 && s3) { - shi->tang[0]= (tl*s3[0] - tu*s1[0] - tv*s2[0]); - shi->tang[1]= (tl*s3[1] - tu*s1[1] - tv*s2[1]); - shi->tang[2]= (tl*s3[2] - tu*s1[2] - tv*s2[2]); + shi->tang[0] = (tl * s3[0] - tu * s1[0] - tv * s2[0]); + shi->tang[1] = (tl * s3[1] - tu * s1[1] - tv * s2[1]); + shi->tang[2] = (tl * s3[2] - tu * s1[2] - tv * s2[2]); if (obi->flag & R_TRANSFORMED) mul_m3_v3(obi->nmat, shi->tang); @@ -956,41 +944,41 @@ void shade_input_set_shade_texco(ShadeInput *shi) } if (mode & MA_NORMAP_TANG || R.flag & R_NEED_TANGENT) { - tangent= RE_vlakren_get_nmap_tangent(obr, shi->vlr, 0); + tangent = RE_vlakren_get_nmap_tangent(obr, shi->vlr, 0); if (tangent) { - int j1= shi->i1, j2= shi->i2, j3= shi->i3; + int j1 = shi->i1, j2 = shi->i2, j3 = shi->i3; float c0[3], c1[3], c2[3]; vlr_set_uv_indices(shi->vlr, &j1, &j2, &j3); - copy_v3_v3(c0, &tangent[j1*4]); - copy_v3_v3(c1, &tangent[j2*4]); - copy_v3_v3(c2, &tangent[j3*4]); + copy_v3_v3(c0, &tangent[j1 * 4]); + 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 - 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. - shi->nmaptang[3]= tangent[j1*4+3]; + + /* 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. */ + shi->nmaptang[3] = tangent[j1 * 4 + 3]; } } } if (mode & MA_STR_SURFDIFF) { - float *surfnor= RE_vlakren_get_surfnor(obr, shi->vlr, 0); + float *surfnor = RE_vlakren_get_surfnor(obr, shi->vlr, 0); if (surfnor) { copy_v3_v3(shi->surfnor, surfnor); @@ -1000,29 +988,29 @@ void shade_input_set_shade_texco(ShadeInput *shi) else copy_v3_v3(shi->surfnor, shi->vn); - shi->surfdist= 0.0f; + shi->surfdist = 0.0f; } if (R.r.mode & R_SPEED) { float *s1, *s2, *s3; - s1= RE_vertren_get_winspeed(obi, v1, 0); - s2= RE_vertren_get_winspeed(obi, v2, 0); - s3= RE_vertren_get_winspeed(obi, v3, 0); + s1 = RE_vertren_get_winspeed(obi, v1, 0); + s2 = RE_vertren_get_winspeed(obi, v2, 0); + s3 = RE_vertren_get_winspeed(obi, v3, 0); if (s1 && s2 && s3) { - shi->winspeed[0]= (l*s3[0] - u*s1[0] - v*s2[0]); - shi->winspeed[1]= (l*s3[1] - u*s1[1] - v*s2[1]); - shi->winspeed[2]= (l*s3[2] - u*s1[2] - v*s2[2]); - shi->winspeed[3]= (l*s3[3] - u*s1[3] - v*s2[3]); + shi->winspeed[0] = (l * s3[0] - u * s1[0] - v * s2[0]); + shi->winspeed[1] = (l * s3[1] - u * s1[1] - v * s2[1]); + shi->winspeed[2] = (l * s3[2] - u * s1[2] - v * s2[2]); + shi->winspeed[3] = (l * s3[3] - u * s1[3] - v * s2[3]); } else { - shi->winspeed[0]= shi->winspeed[1]= shi->winspeed[2]= shi->winspeed[3]= 0.0f; + shi->winspeed[0] = shi->winspeed[1] = shi->winspeed[2] = shi->winspeed[3] = 0.0f; } } /* pass option forces UV calc */ if (shi->passflag & SCE_PASS_UV) - texco |= (NEED_UV|TEXCO_UV); + texco |= (NEED_UV | TEXCO_UV); /* texture coordinates. shi->dxuv shi->dyuv have been set */ if (texco & NEED_UV) { @@ -1031,23 +1019,23 @@ void shade_input_set_shade_texco(ShadeInput *shi) if (v1->orco) { float *o1, *o2, *o3; - o1= v1->orco; - o2= v2->orco; - o3= v3->orco; - - shi->lo[0]= l*o3[0]-u*o1[0]-v*o2[0]; - shi->lo[1]= l*o3[1]-u*o1[1]-v*o2[1]; - shi->lo[2]= l*o3[2]-u*o1[2]-v*o2[2]; + o1 = v1->orco; + o2 = v2->orco; + o3 = v3->orco; + + shi->lo[0] = l * o3[0] - u * o1[0] - v * o2[0]; + shi->lo[1] = l * o3[1] - u * o1[1] - v * o2[1]; + shi->lo[2] = l * o3[2] - u * o1[2] - v * o2[2]; if (shi->osatex) { - dl= shi->dx_u+shi->dx_v; - shi->dxlo[0]= dl*o3[0]-shi->dx_u*o1[0]-shi->dx_v*o2[0]; - shi->dxlo[1]= dl*o3[1]-shi->dx_u*o1[1]-shi->dx_v*o2[1]; - shi->dxlo[2]= dl*o3[2]-shi->dx_u*o1[2]-shi->dx_v*o2[2]; - dl= shi->dy_u+shi->dy_v; - shi->dylo[0]= dl*o3[0]-shi->dy_u*o1[0]-shi->dy_v*o2[0]; - shi->dylo[1]= dl*o3[1]-shi->dy_u*o1[1]-shi->dy_v*o2[1]; - shi->dylo[2]= dl*o3[2]-shi->dy_u*o1[2]-shi->dy_v*o2[2]; + dl = shi->dx_u + shi->dx_v; + shi->dxlo[0] = dl * o3[0] - shi->dx_u * o1[0] - shi->dx_v * o2[0]; + shi->dxlo[1] = dl * o3[1] - shi->dx_u * o1[1] - shi->dx_v * o2[1]; + shi->dxlo[2] = dl * o3[2] - shi->dx_u * o1[2] - shi->dx_v * o2[2]; + dl = shi->dy_u + shi->dy_v; + shi->dylo[0] = dl * o3[0] - shi->dy_u * o1[0] - shi->dy_v * o2[0]; + shi->dylo[1] = dl * o3[1] - shi->dy_u * o1[1] - shi->dy_v * o2[1]; + shi->dylo[2] = dl * o3[2] - shi->dy_u * o1[2] - shi->dy_v * o2[2]; } } @@ -1066,113 +1054,113 @@ void shade_input_set_shade_texco(ShadeInput *shi) } if (texco & TEXCO_STRAND) { - shi->strandco= (l*v3->accum - u*v1->accum - v*v2->accum); + shi->strandco = (l * v3->accum - u * v1->accum - v * v2->accum); if (shi->osatex) { - dl= shi->dx_u+shi->dx_v; - shi->dxstrand= dl*v3->accum-shi->dx_u*v1->accum-shi->dx_v*v2->accum; - dl= shi->dy_u+shi->dy_v; - shi->dystrand= dl*v3->accum-shi->dy_u*v1->accum-shi->dy_v*v2->accum; + dl = shi->dx_u + shi->dx_v; + shi->dxstrand = dl * v3->accum - shi->dx_u * v1->accum - shi->dx_v * v2->accum; + dl = shi->dy_u + shi->dy_v; + shi->dystrand = dl * v3->accum - shi->dy_u * v1->accum - shi->dy_v * v2->accum; } } - if ((texco & TEXCO_UV) || (mode & (MA_VERTEXCOL|MA_VERTEXCOLP|MA_FACETEXTURE))) { - VlakRen *vlr= shi->vlr; + if ((texco & TEXCO_UV) || (mode & (MA_VERTEXCOL | MA_VERTEXCOLP | MA_FACETEXTURE))) { + VlakRen *vlr = shi->vlr; MTFace *tface; MCol *mcol; char *name; - int i, j1=shi->i1, j2=shi->i2, j3=shi->i3; + int i, j1 = shi->i1, j2 = shi->i2, j3 = shi->i3; /* uv and vcols are not copied on split, so set them according vlr divide flag */ vlr_set_uv_indices(vlr, &j1, &j2, &j3); - shi->totuv= 0; - shi->totcol= 0; - shi->actuv= obr->actmtface; - shi->actcol= obr->actmcol; + shi->totuv = 0; + shi->totcol = 0; + shi->actuv = obr->actmtface; + shi->actcol = obr->actmcol; - if (mode & (MA_VERTEXCOL|MA_VERTEXCOLP)) { - for (i=0; (mcol=RE_vlakren_get_mcol(obr, vlr, i, &name, 0)); i++) { - ShadeInputCol *scol= &shi->col[i]; + if (mode & (MA_VERTEXCOL | MA_VERTEXCOLP)) { + for (i = 0; (mcol = RE_vlakren_get_mcol(obr, vlr, i, &name, 0)); i++) { + ShadeInputCol *scol = &shi->col[i]; char *cp1, *cp2, *cp3; float a[3]; shi->totcol++; - scol->name= name; + scol->name = name; - cp1= (char *)(mcol+j1); - cp2= (char *)(mcol+j2); - cp3= (char *)(mcol+j3); + cp1 = (char *)(mcol + j1); + cp2 = (char *)(mcol + j2); + cp3 = (char *)(mcol + j3); /* alpha values */ - a[0] = ((float)cp1[0])/255.f; - a[1] = ((float)cp2[0])/255.f; - a[2] = ((float)cp3[0])/255.f; - scol->col[3]= l*a[2] - u*a[0] - v*a[1]; + a[0] = ((float)cp1[0]) / 255.f; + a[1] = ((float)cp2[0]) / 255.f; + a[2] = ((float)cp3[0]) / 255.f; + scol->col[3] = l * a[2] - u * a[0] - v * a[1]; /* sample premultiplied color value */ - scol->col[0]= (l*((float)cp3[3])*a[2] - u*((float)cp1[3])*a[0] - v*((float)cp2[3])*a[1])/255.f; - scol->col[1]= (l*((float)cp3[2])*a[2] - u*((float)cp1[2])*a[0] - v*((float)cp2[2])*a[1])/255.f; - scol->col[2]= (l*((float)cp3[1])*a[2] - u*((float)cp1[1])*a[0] - v*((float)cp2[1])*a[1])/255.f; + scol->col[0] = (l * ((float)cp3[3]) * a[2] - u * ((float)cp1[3]) * a[0] - v * ((float)cp2[3]) * a[1]) / 255.f; + scol->col[1] = (l * ((float)cp3[2]) * a[2] - u * ((float)cp1[2]) * a[0] - v * ((float)cp2[2]) * a[1]) / 255.f; + scol->col[2] = (l * ((float)cp3[1]) * a[2] - u * ((float)cp1[1]) * a[0] - v * ((float)cp2[1]) * a[1]) / 255.f; /* if not zero alpha, restore non-multiplied color */ if (scol->col[3]) { - mul_v3_fl(scol->col, 1.0f/scol->col[3]); + mul_v3_fl(scol->col, 1.0f / scol->col[3]); } } if (shi->totcol) { - shi->vcol[0]= shi->col[shi->actcol].col[0]; - shi->vcol[1]= shi->col[shi->actcol].col[1]; - shi->vcol[2]= shi->col[shi->actcol].col[2]; - shi->vcol[3]= shi->col[shi->actcol].col[3]; + shi->vcol[0] = shi->col[shi->actcol].col[0]; + shi->vcol[1] = shi->col[shi->actcol].col[1]; + shi->vcol[2] = shi->col[shi->actcol].col[2]; + shi->vcol[3] = shi->col[shi->actcol].col[3]; } else { - shi->vcol[0]= 0.0f; - shi->vcol[1]= 0.0f; - shi->vcol[2]= 0.0f; - shi->vcol[3]= 1.0f; + shi->vcol[0] = 0.0f; + shi->vcol[1] = 0.0f; + shi->vcol[2] = 0.0f; + shi->vcol[3] = 1.0f; } } - for (i=0; (tface=RE_vlakren_get_tface(obr, vlr, i, &name, 0)); i++) { - ShadeInputUV *suv= &shi->uv[i]; + for (i = 0; (tface = RE_vlakren_get_tface(obr, vlr, i, &name, 0)); i++) { + ShadeInputUV *suv = &shi->uv[i]; float *uv1, *uv2, *uv3; shi->totuv++; - suv->name= name; - - uv1= tface->uv[j1]; - uv2= tface->uv[j2]; - uv3= tface->uv[j3]; + suv->name = name; - suv->uv[0]= -1.0f + 2.0f*(l*uv3[0]-u*uv1[0]-v*uv2[0]); - suv->uv[1]= -1.0f + 2.0f*(l*uv3[1]-u*uv1[1]-v*uv2[1]); - suv->uv[2]= 0.0f; /* texture.c assumes there are 3 coords */ + uv1 = tface->uv[j1]; + uv2 = tface->uv[j2]; + uv3 = tface->uv[j3]; + + suv->uv[0] = -1.0f + 2.0f * (l * uv3[0] - u * uv1[0] - v * uv2[0]); + suv->uv[1] = -1.0f + 2.0f * (l * uv3[1] - u * uv1[1] - v * uv2[1]); + suv->uv[2] = 0.0f; /* texture.c assumes there are 3 coords */ if (shi->osatex) { float duv[2]; - dl= shi->dx_u+shi->dx_v; - duv[0]= shi->dx_u; - duv[1]= shi->dx_v; - - suv->dxuv[0]= 2.0f*(dl*uv3[0]-duv[0]*uv1[0]-duv[1]*uv2[0]); - suv->dxuv[1]= 2.0f*(dl*uv3[1]-duv[0]*uv1[1]-duv[1]*uv2[1]); - - dl= shi->dy_u+shi->dy_v; - duv[0]= shi->dy_u; - duv[1]= shi->dy_v; - - suv->dyuv[0]= 2.0f*(dl*uv3[0]-duv[0]*uv1[0]-duv[1]*uv2[0]); - suv->dyuv[1]= 2.0f*(dl*uv3[1]-duv[0]*uv1[1]-duv[1]*uv2[1]); + dl = shi->dx_u + shi->dx_v; + duv[0] = shi->dx_u; + duv[1] = shi->dx_v; + + suv->dxuv[0] = 2.0f * (dl * uv3[0] - duv[0] * uv1[0] - duv[1] * uv2[0]); + suv->dxuv[1] = 2.0f * (dl * uv3[1] - duv[0] * uv1[1] - duv[1] * uv2[1]); + + dl = shi->dy_u + shi->dy_v; + duv[0] = shi->dy_u; + duv[1] = shi->dy_v; + + suv->dyuv[0] = 2.0f * (dl * uv3[0] - duv[0] * uv1[0] - duv[1] * uv2[0]); + suv->dyuv[1] = 2.0f * (dl * uv3[1] - duv[0] * uv1[1] - duv[1] * uv2[1]); } - if ((mode & MA_FACETEXTURE) && i==obr->actmtface) { - if ((mode & (MA_VERTEXCOL|MA_VERTEXCOLP))==0) { - shi->vcol[0]= 1.0f; - shi->vcol[1]= 1.0f; - shi->vcol[2]= 1.0f; - shi->vcol[3]= 1.0f; + if ((mode & MA_FACETEXTURE) && i == obr->actmtface) { + if ((mode & (MA_VERTEXCOL | MA_VERTEXCOLP)) == 0) { + shi->vcol[0] = 1.0f; + shi->vcol[1] = 1.0f; + shi->vcol[2] = 1.0f; + shi->vcol[3] = 1.0f; } if (tface->tpage) { render_realtime_texture(shi, tface->tpage); @@ -1182,79 +1170,79 @@ void shade_input_set_shade_texco(ShadeInput *shi) } - shi->dupliuv[0]= -1.0f + 2.0f*obi->dupliuv[0]; - shi->dupliuv[1]= -1.0f + 2.0f*obi->dupliuv[1]; - shi->dupliuv[2]= 0.0f; + shi->dupliuv[0] = -1.0f + 2.0f * obi->dupliuv[0]; + shi->dupliuv[1] = -1.0f + 2.0f * obi->dupliuv[1]; + shi->dupliuv[2] = 0.0f; if (shi->totuv == 0) { - ShadeInputUV *suv= &shi->uv[0]; + ShadeInputUV *suv = &shi->uv[0]; - suv->uv[0]= 2.0f*(u+.5f); - suv->uv[1]= 2.0f*(v+.5f); - suv->uv[2]= 0.0f; /* texture.c assumes there are 3 coords */ + suv->uv[0] = 2.0f * (u + .5f); + suv->uv[1] = 2.0f * (v + .5f); + suv->uv[2] = 0.0f; /* texture.c assumes there are 3 coords */ if (mode & MA_FACETEXTURE) { /* no tface? set at 1.0f */ - shi->vcol[0]= 1.0f; - shi->vcol[1]= 1.0f; - shi->vcol[2]= 1.0f; - shi->vcol[3]= 1.0f; + shi->vcol[0] = 1.0f; + shi->vcol[1] = 1.0f; + shi->vcol[2] = 1.0f; + shi->vcol[3] = 1.0f; } } } if (texco & TEXCO_NORM) { - shi->orn[0]= -shi->vn[0]; - shi->orn[1]= -shi->vn[1]; - shi->orn[2]= -shi->vn[2]; + shi->orn[0] = -shi->vn[0]; + shi->orn[1] = -shi->vn[1]; + shi->orn[2] = -shi->vn[2]; } if (texco & TEXCO_STRESS) { float *s1, *s2, *s3; - s1= RE_vertren_get_stress(obr, v1, 0); - s2= RE_vertren_get_stress(obr, v2, 0); - s3= RE_vertren_get_stress(obr, v3, 0); + s1 = RE_vertren_get_stress(obr, v1, 0); + s2 = RE_vertren_get_stress(obr, v2, 0); + s3 = RE_vertren_get_stress(obr, v3, 0); if (s1 && s2 && s3) { - shi->stress= l*s3[0] - u*s1[0] - v*s2[0]; - if (shi->stress<1.0f) shi->stress-= 1.0f; - else shi->stress= (shi->stress-1.0f)/shi->stress; + shi->stress = l * s3[0] - u * s1[0] - v * s2[0]; + if (shi->stress < 1.0f) shi->stress -= 1.0f; + else shi->stress = (shi->stress - 1.0f) / shi->stress; } - else shi->stress= 0.0f; + else shi->stress = 0.0f; } if (texco & TEXCO_TANGENT) { - if ((mode & MA_TANGENT_V)==0) { + if ((mode & MA_TANGENT_V) == 0) { /* just prevent surprises */ - shi->tang[0]= shi->tang[1]= shi->tang[2]= 0.0f; - shi->nmaptang[0]= shi->nmaptang[1]= shi->nmaptang[2]= 0.0f; + shi->tang[0] = shi->tang[1] = shi->tang[2] = 0.0f; + shi->nmaptang[0] = shi->nmaptang[1] = shi->nmaptang[2] = 0.0f; } } } /* this only avalailable for scanline renders */ - if (shi->depth==0) { - float x= shi->xs; - float y= shi->ys; + if (shi->depth == 0) { + float x = shi->xs; + float y = shi->ys; if (texco & TEXCO_WINDOW) { - shi->winco[0]= -1.0f + 2.0f*x/(float)R.winx; - shi->winco[1]= -1.0f + 2.0f*y/(float)R.winy; - shi->winco[2]= 0.0f; + shi->winco[0] = -1.0f + 2.0f * x / (float)R.winx; + shi->winco[1] = -1.0f + 2.0f * y / (float)R.winy; + shi->winco[2] = 0.0f; if (shi->osatex) { - shi->dxwin[0]= 2.0f/(float)R.winx; - shi->dywin[1]= 2.0f/(float)R.winy; - shi->dxwin[1]= shi->dxwin[2]= 0.0f; - shi->dywin[0]= shi->dywin[2]= 0.0f; + shi->dxwin[0] = 2.0f / (float)R.winx; + shi->dywin[1] = 2.0f / (float)R.winy; + shi->dxwin[1] = shi->dxwin[2] = 0.0f; + shi->dywin[0] = shi->dywin[2] = 0.0f; } } if (texco & TEXCO_STICKY) { float *s1, *s2, *s3; - s1= RE_vertren_get_sticky(obr, v1, 0); - s2= RE_vertren_get_sticky(obr, v2, 0); - s3= RE_vertren_get_sticky(obr, v3, 0); + s1 = RE_vertren_get_sticky(obr, v1, 0); + s2 = RE_vertren_get_sticky(obr, v2, 0); + s3 = RE_vertren_get_sticky(obr, v3, 0); if (s1 && s2 && s3) { float obwinmat[4][4], winmat[4][4], ho1[4], ho2[4], ho3[4]; @@ -1263,7 +1251,7 @@ void shade_input_set_shade_texco(ShadeInput *shi) float s00, s01, s10, s11, detsh; /* old globals, localized now */ - Zmulx= ((float)R.winx)/2.0f; Zmuly= ((float)R.winy)/2.0f; + Zmulx = ((float)R.winx) / 2.0f; Zmuly = ((float)R.winy) / 2.0f; zbuf_make_winmat(&R, winmat); if (shi->obi->flag & R_TRANSFORMED) @@ -1275,40 +1263,40 @@ void shade_input_set_shade_texco(ShadeInput *shi) zbuf_render_project(obwinmat, v2->co, ho2); zbuf_render_project(obwinmat, v3->co, ho3); - s00= ho3[0]/ho3[3] - ho1[0]/ho1[3]; - s01= ho3[1]/ho3[3] - ho1[1]/ho1[3]; - s10= ho3[0]/ho3[3] - ho2[0]/ho2[3]; - s11= ho3[1]/ho3[3] - ho2[1]/ho2[3]; - - detsh= s00*s11-s10*s01; - detsh= (detsh != 0.0f)? 1.0f/detsh: 0.0f; - s00*= detsh; s01*=detsh; - s10*=detsh; s11*=detsh; + s00 = ho3[0] / ho3[3] - ho1[0] / ho1[3]; + s01 = ho3[1] / ho3[3] - ho1[1] / ho1[3]; + s10 = ho3[0] / ho3[3] - ho2[0] / ho2[3]; + s11 = ho3[1] / ho3[3] - ho2[1] / ho2[3]; + + detsh = s00 * s11 - s10 * s01; + detsh = (detsh != 0.0f) ? 1.0f / detsh : 0.0f; + s00 *= detsh; s01 *= detsh; + s10 *= detsh; s11 *= detsh; /* recalc u and v again */ - hox= x/Zmulx -1.0f; - hoy= y/Zmuly -1.0f; - u= (hox - ho3[0]/ho3[3])*s11 - (hoy - ho3[1]/ho3[3])*s10; - v= (hoy - ho3[1]/ho3[3])*s00 - (hox - ho3[0]/ho3[3])*s01; - l= 1.0f+u+v; - - shi->sticky[0]= l*s3[0]-u*s1[0]-v*s2[0]; - shi->sticky[1]= l*s3[1]-u*s1[1]-v*s2[1]; - shi->sticky[2]= 0.0f; + hox = x / Zmulx - 1.0f; + hoy = y / Zmuly - 1.0f; + u = (hox - ho3[0] / ho3[3]) * s11 - (hoy - ho3[1] / ho3[3]) * s10; + v = (hoy - ho3[1] / ho3[3]) * s00 - (hox - ho3[0] / ho3[3]) * s01; + l = 1.0f + u + v; + + shi->sticky[0] = l * s3[0] - u * s1[0] - v * s2[0]; + shi->sticky[1] = l * s3[1] - u * s1[1] - v * s2[1]; + shi->sticky[2] = 0.0f; if (shi->osatex) { float dxuv[2], dyuv[2]; - dxuv[0]= s11/Zmulx; - dxuv[1]= - s01/Zmulx; - dyuv[0]= - s10/Zmuly; - dyuv[1]= s00/Zmuly; - - dl= dxuv[0] + dxuv[1]; - shi->dxsticky[0]= dl*s3[0] - dxuv[0]*s1[0] - dxuv[1]*s2[0]; - shi->dxsticky[1]= dl*s3[1] - dxuv[0]*s1[1] - dxuv[1]*s2[1]; - dl= dyuv[0] + dyuv[1]; - shi->dysticky[0]= dl*s3[0] - dyuv[0]*s1[0] - dyuv[1]*s2[0]; - shi->dysticky[1]= dl*s3[1] - dyuv[0]*s1[1] - dyuv[1]*s2[1]; + dxuv[0] = s11 / Zmulx; + dxuv[1] = -s01 / Zmulx; + dyuv[0] = -s10 / Zmuly; + dyuv[1] = s00 / Zmuly; + + dl = dxuv[0] + dxuv[1]; + shi->dxsticky[0] = dl * s3[0] - dxuv[0] * s1[0] - dxuv[1] * s2[0]; + shi->dxsticky[1] = dl * s3[1] - dxuv[0] * s1[1] - dxuv[1] * s2[1]; + dl = dyuv[0] + dyuv[1]; + shi->dysticky[0] = dl * s3[0] - dyuv[0] * s1[0] - dyuv[1] * s2[0]; + shi->dysticky[1] = dl * s3[1] - dyuv[0] * s1[1] - dyuv[1] * s2[1]; } } } @@ -1319,7 +1307,7 @@ void shade_input_set_shade_texco(ShadeInput *shi) * else un-initialized values are used */ if (shi->do_manage) { - if (mode & (MA_VERTEXCOL|MA_VERTEXCOLP|MA_FACETEXTURE)) { + if (mode & (MA_VERTEXCOL | MA_VERTEXCOLP | MA_FACETEXTURE)) { srgb_to_linearrgb_v3_v3(shi->vcol, shi->vcol); } } @@ -1334,16 +1322,16 @@ void shade_input_initialize(ShadeInput *shi, RenderPart *pa, RenderLayer *rl, in memset(shi, 0, sizeof(ShadeInput)); - shi->sample= sample; - shi->thread= pa->thread; - shi->do_preview= (R.r.scemode & R_MATNODE_PREVIEW) != 0; - shi->do_manage= (R.r.color_mgt_flag & R_COLOR_MANAGEMENT); - shi->lay= rl->lay; - shi->layflag= rl->layflag; - shi->passflag= rl->passflag; - shi->combinedflag= ~rl->pass_xor; - shi->mat_override= rl->mat_override; - shi->light_override= rl->light_override; + shi->sample = sample; + shi->thread = pa->thread; + shi->do_preview = (R.r.scemode & R_MATNODE_PREVIEW) != 0; + shi->do_manage = (R.r.color_mgt_flag & R_COLOR_MANAGEMENT); + shi->lay = rl->lay; + shi->layflag = rl->layflag; + shi->passflag = rl->passflag; + shi->combinedflag = ~rl->pass_xor; + shi->mat_override = rl->mat_override; + shi->light_override = rl->light_override; // shi->rl= rl; /* note shi.depth==0 means first hit, not raytracing */ @@ -1354,9 +1342,9 @@ void shade_sample_initialize(ShadeSample *ssamp, RenderPart *pa, RenderLayer *rl { int a, tot; - tot= R.osa==0?1:R.osa; + tot = R.osa == 0 ? 1 : R.osa; - for (a=0; a<tot; a++) { + for (a = 0; a < tot; a++) { shade_input_initialize(&ssamp->shi[a], pa, rl, a); memset(&ssamp->shr[a], 0, sizeof(ShadeResult)); } @@ -1372,16 +1360,16 @@ void shade_samples_do_AO(ShadeSample *ssamp) if (!(R.r.mode & R_RAYTRACE) && !(R.wrld.ao_gather_method == WO_AOGATHER_APPROX)) return; - if (R.wrld.mode & (WO_AMB_OCC|WO_ENV_LIGHT|WO_INDIRECT_LIGHT)) { - ShadeInput *shi= &ssamp->shi[0]; + if (R.wrld.mode & (WO_AMB_OCC | WO_ENV_LIGHT | WO_INDIRECT_LIGHT)) { + ShadeInput *shi = &ssamp->shi[0]; int sample; - if (((shi->passflag & SCE_PASS_COMBINED) && (shi->combinedflag & (SCE_PASS_AO|SCE_PASS_ENVIRONMENT|SCE_PASS_INDIRECT))) || - (shi->passflag & (SCE_PASS_AO|SCE_PASS_ENVIRONMENT|SCE_PASS_INDIRECT))) + if (((shi->passflag & SCE_PASS_COMBINED) && (shi->combinedflag & (SCE_PASS_AO | SCE_PASS_ENVIRONMENT | SCE_PASS_INDIRECT))) || + (shi->passflag & (SCE_PASS_AO | SCE_PASS_ENVIRONMENT | SCE_PASS_INDIRECT))) { - for (sample=0; sample<ssamp->tot; shi++, sample++) + for (sample = 0; sample < ssamp->tot; shi++, sample++) if (!(shi->mode & MA_SHLESS)) - ambient_occlusion(shi); /* stores in shi->ao[] */ + ambient_occlusion(shi); /* stores in shi->ao[] */ } } } @@ -1392,55 +1380,55 @@ void shade_samples_fill_with_ps(ShadeSample *ssamp, PixStr *ps, int x, int y) ShadeInput *shi; float xs, ys; - ssamp->tot= 0; + ssamp->tot = 0; - for (shi= ssamp->shi; ps; ps= ps->next) { + for (shi = ssamp->shi; ps; ps = ps->next) { shade_input_set_triangle(shi, ps->obi, ps->facenr, 1); - if (shi->vlr) { /* NULL happens for env material or for 'all z' */ - unsigned short curmask= ps->mask; + if (shi->vlr) { /* NULL happens for env material or for 'all z' */ + unsigned short curmask = ps->mask; /* full osa is only set for OSA renders */ if (shi->vlr->flag & R_FULL_OSA) { - short shi_cp= 0, samp; + short shi_cp = 0, samp; - for (samp=0; samp<R.osa; samp++) { - if (curmask & (1<<samp)) { + for (samp = 0; samp < R.osa; samp++) { + if (curmask & (1 << samp)) { /* zbuffer has this inverse corrected, ensures xs,ys are inside pixel */ - xs= (float)x + R.jit[samp][0] + 0.5f; - ys= (float)y + R.jit[samp][1] + 0.5f; + xs = (float)x + R.jit[samp][0] + 0.5f; + ys = (float)y + R.jit[samp][1] + 0.5f; if (shi_cp) - shade_input_copy_triangle(shi, shi-1); + shade_input_copy_triangle(shi, shi - 1); - shi->mask= (1<<samp); + shi->mask = (1 << samp); // shi->rl= ssamp->rlpp[samp]; - shi->samplenr= R.shadowsamplenr[shi->thread]++; /* this counter is not being reset per pixel */ + shi->samplenr = R.shadowsamplenr[shi->thread]++; /* this counter is not being reset per pixel */ shade_input_set_viewco(shi, x, y, xs, ys, (float)ps->z); shade_input_set_uv(shi); - if (shi_cp==0) + if (shi_cp == 0) shade_input_set_normals(shi); else /* XXX shi->flippednor messes up otherwise */ shade_input_set_vertex_normals(shi); - shi_cp= 1; + shi_cp = 1; shi++; } } } else { if (R.osa) { - short b= R.samples->centmask[curmask]; - xs= (float)x + R.samples->centLut[b & 15] + 0.5f; - ys= (float)y + R.samples->centLut[b>>4] + 0.5f; + short b = R.samples->centmask[curmask]; + xs = (float)x + R.samples->centLut[b & 15] + 0.5f; + ys = (float)y + R.samples->centLut[b >> 4] + 0.5f; } else { - xs= (float)x + 0.5f; - ys= (float)y + 0.5f; + xs = (float)x + 0.5f; + ys = (float)y + 0.5f; } - shi->mask= curmask; - shi->samplenr= R.shadowsamplenr[shi->thread]++; + shi->mask = curmask; + shi->samplenr = R.shadowsamplenr[shi->thread]++; shade_input_set_viewco(shi, x, y, xs, ys, (float)ps->z); shade_input_set_uv(shi); shade_input_set_normals(shi); @@ -1448,8 +1436,8 @@ void shade_samples_fill_with_ps(ShadeSample *ssamp, PixStr *ps, int x, int y) } /* total sample amount, shi->sample is static set in initialize */ - if (shi!=ssamp->shi) - ssamp->tot= (shi-1)->sample + 1; + if (shi != ssamp->shi) + ssamp->tot = (shi - 1)->sample + 1; } } } @@ -1460,24 +1448,24 @@ int shade_samples(ShadeSample *ssamp, PixStr *ps, int x, int y) shade_samples_fill_with_ps(ssamp, ps, x, y); if (ssamp->tot) { - ShadeInput *shi= ssamp->shi; - ShadeResult *shr= ssamp->shr; + ShadeInput *shi = ssamp->shi; + ShadeResult *shr = ssamp->shr; int samp; /* if shadow or AO? */ shade_samples_do_AO(ssamp); /* if shade (all shadepinputs have same passflag) */ - if (ssamp->shi[0].passflag & ~(SCE_PASS_Z|SCE_PASS_INDEXOB|SCE_PASS_INDEXMA)) { + if (ssamp->shi[0].passflag & ~(SCE_PASS_Z | SCE_PASS_INDEXOB | SCE_PASS_INDEXMA)) { - for (samp=0; samp<ssamp->tot; samp++, shi++, shr++) { + for (samp = 0; samp < ssamp->tot; samp++, shi++, shr++) { shade_input_set_shade_texco(shi); shade_input_do_shade(shi, shr); } } else if (shi->passflag & SCE_PASS_Z) { - for (samp=0; samp<ssamp->tot; samp++, shi++, shr++) - shr->z= -shi->co[2]; + for (samp = 0; samp < ssamp->tot; samp++, shi++, shr++) + shr->z = -shi->co[2]; } return 1; diff --git a/source/blender/render/intern/source/shadeoutput.c b/source/blender/render/intern/source/shadeoutput.c index c2e21af4ad2..75afeb78868 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; @@ -1734,7 +1736,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]); @@ -1755,8 +1757,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 9187bea641d..ddc7dff7b06 100644 --- a/source/blender/render/intern/source/sunsky.c +++ b/source/blender/render/intern/source/sunsky.c @@ -174,7 +174,7 @@ void InitSunSky(struct SunSky *sunsky, float turb, float *toSun, float horizon_b DirectionToThetaPhi(sunsky->toSun, &sunsky->theta, &sunsky->phi); - sunsky->sunSolidAngle = 0.25 * M_PI * 1.39 * 1.39 / (150 * 150); // = 6.7443e-05 + sunsky->sunSolidAngle = 0.25 * M_PI * 1.39 * 1.39 / (150 * 150); /* = 6.7443e-05 */ theta2 = sunsky->theta * sunsky->theta; theta3 = theta2 * sunsky->theta; @@ -183,7 +183,7 @@ void InitSunSky(struct SunSky *sunsky, float turb, float *toSun, float horizon_b chi = (4.0f / 9.0f - T / 120.0f) * ((float)M_PI - 2.0f * sunsky->theta); sunsky->zenith_Y = (4.0453f * T - 4.9710f) * tanf(chi) - 0.2155f * T + 2.4192f; - sunsky->zenith_Y *= 1000; // conversion from kcd/m^2 to cd/m^2 + sunsky->zenith_Y *= 1000; /* conversion from kcd/m^2 to cd/m^2 */ if (sunsky->zenith_Y <= 0) sunsky->zenith_Y = 1e-6; @@ -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); @@ -340,13 +340,13 @@ static void ComputeAttenuatedSunlight(float theta, int turbidity, float fTau[3]) m = 1.0f / (cosf(theta) + 0.15f * powf(93.885f - theta / (float)M_PI * 180.0f, -1.253f)); for (i = 0; i < 3; i++) { - // Rayleigh Scattering + /* Rayleigh Scattering */ fTauR = expf(-m * 0.008735f * powf(fLambda[i], (float)(-4.08f))); - // Aerosal (water + dust) attenuation + /* Aerosal (water + dust) attenuation */ fTauA = exp(-m * fBeta * powf(fLambda[i], -fAlpha)); - fTau[i] = fTauR * fTauA; + fTau[i] = fTauR * fTauA; } } @@ -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); @@ -457,23 +457,23 @@ void AtmospherePixleShader(struct SunSky *sunSky, float view[3], float s, float sunDirection[0] = sunSky->toSun[0]; sunDirection[1] = sunSky->toSun[1]; sunDirection[2] = sunSky->toSun[2]; - - costheta = dot_v3v3(view, sunDirection); // cos(theta) - Phase_1 = 1 + (costheta * costheta); // Phase_1 - + + costheta = dot_v3v3(view, sunDirection); /* cos(theta) */ + Phase_1 = 1 + (costheta * costheta); /* Phase_1 */ + VEC3OPF(sunSky->atm_BetaRay, sunSky->atm_BetaRay, *, sunSky->atm_BetaRayMultiplier); VEC3OPF(sunSky->atm_BetaMie, sunSky->atm_BetaMie, *, sunSky->atm_BetaMieMultiplier); VEC3OPV(sunSky->atm_BetaRM, sunSky->atm_BetaRay, +, sunSky->atm_BetaMie); - - //e^(-(beta_1 + beta_2) * s) = E1 + + /* e^(-(beta_1 + beta_2) * s) = E1 */ VEC3OPF(E1, sunSky->atm_BetaRM, *, -s / (float)M_LN2); E1[0] = exp(E1[0]); E1[1] = exp(E1[1]); E1[2] = exp(E1[2]); copy_v3_v3(E, E1); - - //Phase2(theta) = (1-g^2)/(1+g-2g*cos(theta))^(3/2) + + /* Phase2(theta) = (1-g^2)/(1+g-2g*cos(theta))^(3/2) */ fTemp = 1 + sunSky->atm_HGg - 2 * sunSky->atm_HGg * costheta; fTemp = fTemp * sqrtf(fTemp); Phase_2 = (1 - sunSky->atm_HGg * sunSky->atm_HGg) / fTemp; @@ -491,8 +491,8 @@ void AtmospherePixleShader(struct SunSky *sunSky, float view[3], float s, float VEC3OPF(I, I, *, sunSky->atm_InscatteringMultiplier); VEC3OPF(E, E, *, sunSky->atm_ExtinctionMultiplier); - - //scale to color sun + + /* scale to color sun */ ComputeAttenuatedSunlight(sunSky->theta, sunSky->turbidity, sunColor); VEC3OPV(E, E, *, sunColor); diff --git a/source/blender/render/intern/source/texture_ocean.c b/source/blender/render/intern/source/texture_ocean.c index 4ef88e4740a..5071303dff7 100644 --- a/source/blender/render/intern/source/texture_ocean.c +++ b/source/blender/render/intern/source/texture_ocean.c @@ -81,12 +81,12 @@ int ocean_texture(Tex *tex, float *texvec, TexResult *texres) if (omd->oceancache && omd->cached == TRUE) { CLAMP(cfra, omd->bakestart, omd->bakeend); - cfra -= omd->bakestart; // shift to 0 based + cfra -= omd->bakestart; /* shift to 0 based */ BKE_ocean_cache_eval_uv(omd->oceancache, &ocr, cfra, u, v); } - else { // non-cached + else { /* non-cached */ if (G.rendering) BKE_ocean_eval_uv_catrom(omd->ocean, &ocr, u, v); diff --git a/source/blender/render/intern/source/volume_precache.c b/source/blender/render/intern/source/volume_precache.c index ea6b9b890ac..8a92695a15e 100644 --- a/source/blender/render/intern/source/volume_precache.c +++ b/source/blender/render/intern/source/volume_precache.c @@ -261,14 +261,14 @@ static void lightcache_filter2(VolumePrecache *vp) } #endif -BLI_INLINE int ms_I(int x, int y, int z, int *n) //has a pad of 1 voxel surrounding the core for boundary simulation -{ +BLI_INLINE int ms_I(int x, int y, int z, int *n) /* has a pad of 1 voxel surrounding the core for boundary simulation */ +{ /* different ordering to light cache */ - return x*(n[1]+2)*(n[2]+2) + y*(n[2]+2) + z; + return x*(n[1]+2)*(n[2]+2) + y*(n[2]+2) + z; } -BLI_INLINE int v_I_pad(int x, int y, int z, int *n) //has a pad of 1 voxel surrounding the core for boundary simulation -{ +BLI_INLINE int v_I_pad(int x, int y, int z, int *n) /* has a pad of 1 voxel surrounding the core for boundary simulation */ +{ /* same ordering to light cache, with padding */ return z*(n[1]+2)*(n[0]+2) + y*(n[0]+2) + x; } @@ -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; @@ -526,10 +526,10 @@ static void *vol_precache_part(void *data) /* convert from world->camera space for shading */ mul_v3_m4v3(cco, pa->viewmat, co); - + i = BLI_VOXEL_INDEX(x, y, z, res); - - // don't bother if the point is not inside the volume mesh + + /* don't bother if the point is not inside the volume mesh */ if (!point_inside_obi(tree, obi, cco)) { obi->volume_precache->data_r[i] = -1.0f; obi->volume_precache->data_g[i] = -1.0f; @@ -563,7 +563,7 @@ static void precache_setup_shadeinput(Render *re, ObjectInstanceRen *obi, Materi shi->mask= 1; shi->mat = ma; shi->vlr = NULL; - memcpy(&shi->r, &shi->mat->r, 23*sizeof(float)); // note, keep this synced with render_types.h + memcpy(&shi->r, &shi->mat->r, 23*sizeof(float)); /* note, keep this synced with render_types.h */ shi->har= shi->mat->har; shi->obi= obi; shi->obr= obi->obr; @@ -757,7 +757,8 @@ static void vol_precache_objectinstance_threads(Render *re, ObjectInstanceRen *o BLI_freelistN(&re->volume_precache_parts); if (tree) { - //TODO: makeraytree_object creates a tree and saves it on OBI, if we free this tree we should also clear other pointers to it + /* TODO: makeraytree_object creates a tree and saves it on OBI, + * if we free this tree we should also clear other pointers to it */ //RE_rayobject_free(tree); //tree= NULL; } diff --git a/source/blender/render/intern/source/volumetric.c b/source/blender/render/intern/source/volumetric.c index c1f85914479..67e453577e4 100644 --- a/source/blender/render/intern/source/volumetric.c +++ b/source/blender/render/intern/source/volumetric.c @@ -253,9 +253,9 @@ static float metadensity(Object *ob, const float co[3]) /* element rotation transform */ float tp[3] = {ml->x - tco[0], ml->y - tco[1], ml->z - tco[2]}; quat_to_mat3(bmat, ml->quat); - transpose_m3(bmat); // rot.only, so inverse == transpose + transpose_m3(bmat); /* rot.only, so inverse == transpose */ mul_m3_v3(bmat, tp); - + /* MB_BALL default */ switch (ml->type) { case MB_ELIPSOID: @@ -263,14 +263,14 @@ static float metadensity(Object *ob, const float co[3]) break; case MB_CUBE: tp[2] = (tp[2] > ml->expz) ? (tp[2] - ml->expz) : ((tp[2] < -ml->expz) ? (tp[2] + ml->expz) : 0.f); - // no break, xy as plane + /* no break, xy as plane */ case MB_PLANE: tp[1] = (tp[1] > ml->expy) ? (tp[1] - ml->expy) : ((tp[1] < -ml->expy) ? (tp[1] + ml->expy) : 0.f); - // no break, x as tube + /* no break, x as tube */ case MB_TUBE: tp[0] = (tp[0] > ml->expx) ? (tp[0] - ml->expx) : ((tp[0] < -ml->expx) ? (tp[0] + ml->expx) : 0.f); } - + /* ml->rad2 is not set */ dist2 = 1.0f - (dot_v3v3(tp, tp) / (ml->rad * ml->rad)); if (dist2 > 0.f) @@ -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 7d54f77fc90..d73171648fb 100644 --- a/source/blender/render/intern/source/voxeldata.c +++ b/source/blender/render/intern/source/voxeldata.c @@ -240,7 +240,7 @@ static void init_frame_smoke(VoxelData *vd, float cfra) copy_v3_v3_int(vd->resol, smd->domain->res); totRes = vd_resol_size(vd); - // scaling heat values from -2.0-2.0 to 0.0-1.0 + /* scaling heat values from -2.0-2.0 to 0.0-1.0 */ vd->dataset = MEM_mapallocN(sizeof(float) * (totRes), "smoke data"); @@ -250,7 +250,7 @@ static void init_frame_smoke(VoxelData *vd, float cfra) vd->dataset[i] = (heat[i] + 2.0f) / 4.0f; } - //vd->dataset = smoke_get_heat(smd->domain->fluid); + /* vd->dataset = smoke_get_heat(smd->domain->fluid); */ } else if (vd->smoked_type == TEX_VD_SMOKEVEL) { size_t totRes; @@ -260,7 +260,7 @@ static void init_frame_smoke(VoxelData *vd, float cfra) copy_v3_v3_int(vd->resol, smd->domain->res); totRes = vd_resol_size(vd); - // scaling heat values from -2.0-2.0 to 0.0-1.0 + /* scaling heat values from -2.0-2.0 to 0.0-1.0 */ vd->dataset = MEM_mapallocN(sizeof(float) * (totRes), "smoke data"); xvel = smoke_get_velocity_x(smd->domain->fluid); @@ -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 c88858c44da..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; @@ -1447,21 +1447,21 @@ void zspan_scanconvert_strand(ZSpan *zspan, void *handle, float *v1, float *v2, zxd= -(double)x0/(double)z0; zyd= -(double)y0/(double)z0; zy0= ((double)my2)*zyd + (double)xx1; - - z1= 1.0f; // (u1 - u2) - z2= 0.0f; // (u2 - u3) + + z1= 1.0f; /* (u1 - u2) */ + z2= 0.0f; /* (u2 - u3) */ x0= y1*z2-z1*y2; y0= z1*x2-x1*z2; - - xx1= (x0*v1[0] + y0*v1[1])/z0 + 1.0f; + + xx1= (x0*v1[0] + y0*v1[1])/z0 + 1.0f; uxd= -(double)x0/(double)z0; uyd= -(double)y0/(double)z0; uy0= ((double)my2)*uyd + (double)xx1; - z1= -1.0f; // (v1 - v2) - z2= 1.0f; // (v2 - v3) - + z1= -1.0f; /* (v1 - v2) */ + z2= 1.0f; /* (v2 - v3) */ + x0= y1*z2-z1*y2; y0= z1*x2-x1*z2; @@ -1535,23 +1535,23 @@ void zspan_scanconvert(ZSpan *zspan, void *handle, float *v1, float *v2, float * y1= v1[1]- v2[1]; y2= v2[1]- v3[1]; - z1= 1.0f; // (u1 - u2) - z2= 0.0f; // (u2 - u3) - + z1= 1.0f; /* (u1 - u2) */ + z2= 0.0f; /* (u2 - u3) */ + x0= y1*z2-z1*y2; y0= z1*x2-x1*z2; z0= x1*y2-y1*x2; - + if (z0==0.0f) return; - - xx1= (x0*v1[0] + y0*v1[1])/z0 + 1.0f; + + xx1= (x0*v1[0] + y0*v1[1])/z0 + 1.0f; uxd= -(double)x0/(double)z0; uyd= -(double)y0/(double)z0; uy0= ((double)my2)*uyd + (double)xx1; - z1= -1.0f; // (v1 - v2) - z2= 1.0f; // (v2 - v3) - + z1= -1.0f; /* (v1 - v2) */ + z2= 1.0f; /* (v2 - v3) */ + x0= y1*z2-z1*y2; y0= z1*x2-x1*z2; |