edits to internal renderer - no functional changes.

- move some larger vars into a nested scope.
- replace memset with zero initializer.
- rempace VECCOPY macros with copy_v3v3
- change function args to give the float array length.
This commit is contained in:
2011-09-24 14:34:24 +00:00
parent e63c124e2b
commit cb6255fdf8
10 changed files with 178 additions and 166 deletions

View File

@@ -76,12 +76,12 @@ typedef struct PixStrMain
void calc_view_vector(float *view, float x, float y); void calc_view_vector(float *view, float x, float y);
float mistfactor(float zcor, float *co); /* dist and height, return alpha */ float mistfactor(float zcor, const float co[3]); /* dist and height, return alpha */
void renderspothalo(struct ShadeInput *shi, float *col, float alpha); void renderspothalo(struct ShadeInput *shi, float col[4], float alpha);
void add_halo_flare(Render *re); void add_halo_flare(Render *re);
void calc_renderco_zbuf(float co[3], float *view, int z); void calc_renderco_zbuf(float co[3], const float view[3], int z);
void calc_renderco_ortho(float co[3], float x, float y, int z); void calc_renderco_ortho(float co[3], float x, float y, int z);
int count_mask(unsigned short mask); int count_mask(unsigned short mask);
@@ -103,9 +103,9 @@ extern void freeraytree(Render *re);
extern void makeraytree(Render *re); extern void makeraytree(Render *re);
struct RayObject* makeraytree_object(Render *re, ObjectInstanceRen *obi); struct RayObject* makeraytree_object(Render *re, ObjectInstanceRen *obi);
extern void ray_shadow(ShadeInput *, LampRen *, float *); extern void ray_shadow(ShadeInput *shi, LampRen *lar, float shadfac[4]);
extern void ray_trace(ShadeInput *, ShadeResult *); extern void ray_trace(ShadeInput *shi, ShadeResult *);
extern void ray_ao(ShadeInput *, float *, float *); extern void ray_ao(ShadeInput *shi, float ao[3], float env[3]);
extern void init_jitter_plane(LampRen *lar); extern void init_jitter_plane(LampRen *lar);
extern void init_ao_sphere(struct World *wrld); extern void init_ao_sphere(struct World *wrld);
extern void init_render_qmcsampler(Render *re); extern void init_render_qmcsampler(Render *re);

View File

@@ -96,8 +96,8 @@ void ambient_occlusion(struct ShadeInput *shi);
void environment_lighting_apply(struct ShadeInput *shi, struct ShadeResult *shr); void environment_lighting_apply(struct ShadeInput *shi, struct ShadeResult *shr);
ListBase *get_lights(struct ShadeInput *shi); ListBase *get_lights(struct ShadeInput *shi);
float lamp_get_visibility(struct LampRen *lar, const float co[3], float *lv, float *dist); float lamp_get_visibility(struct LampRen *lar, const float co[3], float lv[3], float *dist);
void lamp_get_shadow(struct LampRen *lar, ShadeInput *shi, float inp, float *shadfac, int do_real); void lamp_get_shadow(struct LampRen *lar, ShadeInput *shi, float inp, float shadfac[4], int do_real);
float fresnel_fac(float *view, float *vn, float fresnel, float fac); float fresnel_fac(float *view, float *vn, float fresnel, float fac);

View File

@@ -5304,11 +5304,13 @@ static void calculate_speedvector(const float vectors[2], int step, float winsq,
static float *calculate_strandsurface_speedvectors(Render *re, ObjectInstanceRen *obi, StrandSurface *mesh) static float *calculate_strandsurface_speedvectors(Render *re, ObjectInstanceRen *obi, StrandSurface *mesh)
{ {
float winsq= (float)re->winx*(float)re->winy, winroot= sqrt(winsq), (*winspeed)[4]; /* int's can wrap on large images */
float ho[4], prevho[4], nextho[4], winmat[4][4], vec[2];
int a;
if(mesh->co && mesh->prevco && mesh->nextco) { if(mesh->co && mesh->prevco && mesh->nextco) {
float winsq= (float)re->winx*(float)re->winy; /* int's can wrap on large images */
float winroot= sqrt(winsq);
float (*winspeed)[4];
float ho[4], prevho[4], nextho[4], winmat[4][4], vec[2];
int a;
if(obi->flag & R_TRANSFORMED) if(obi->flag & R_TRANSFORMED)
mul_m4_m4m4(winmat, obi->mat, re->winmat); mul_m4_m4m4(winmat, obi->mat, re->winmat);
else else

View File

@@ -689,9 +689,9 @@ int envmaptex(Tex *tex, float *texvec, float *dxt, float *dyt, int osatex, TexRe
env->ima= tex->ima; env->ima= tex->ima;
if(env->ima && env->ima->ok) { if(env->ima && env->ima->ok) {
if(env->cube[1]==NULL) { if(env->cube[1]==NULL) {
ImBuf *ibuf= BKE_image_get_ibuf(env->ima, NULL); ImBuf *ibuf_ima= BKE_image_get_ibuf(env->ima, NULL);
if(ibuf) if(ibuf_ima)
envmap_split_ima(env, ibuf); envmap_split_ima(env, ibuf_ima);
else else
env->ok= 0; env->ok= 0;
} }

View File

@@ -334,7 +334,6 @@ static void makeraytree_single(Render *re)
for(obi=re->instancetable.first; obi; obi=obi->next) for(obi=re->instancetable.first; obi; obi=obi->next)
if(is_raytraceable(re, obi)) if(is_raytraceable(re, obi))
{ {
int v;
ObjectRen *obr = obi->obr; ObjectRen *obr = obi->obr;
obs++; obs++;
@@ -344,6 +343,7 @@ static void makeraytree_single(Render *re)
} }
else else
{ {
int v;
for(v=0;v<obr->totvlak;v++) for(v=0;v<obr->totvlak;v++)
{ {
VlakRen *vlr = obr->vlaknodes[v>>8].vlak + (v&255); VlakRen *vlr = obr->vlaknodes[v>>8].vlak + (v&255);
@@ -539,7 +539,7 @@ void shade_ray(Isect *is, ShadeInput *shi, ShadeResult *shr)
VlakRen *vlr= (VlakRen*)is->hit.face; VlakRen *vlr= (VlakRen*)is->hit.face;
/* set up view vector */ /* set up view vector */
VECCOPY(shi->view, is->dir); copy_v3_v3(shi->view, is->dir);
/* render co */ /* render co */
shi->co[0]= is->start[0]+is->dist*(shi->view[0]); shi->co[0]= is->start[0]+is->dist*(shi->view[0]);
@@ -594,16 +594,16 @@ void shade_ray(Isect *is, ShadeInput *shi, ShadeResult *shr)
} }
/* raytrace likes to separate the spec color */ /* raytrace likes to separate the spec color */
VECSUB(shr->diff, shr->combined, shr->spec); sub_v3_v3v3(shr->diff, shr->combined, shr->spec);
} }
} }
static int refraction(float *refract, float *n, float *view, float index) static int refraction(float refract[3], const float n[3], const float view[3], float index)
{ {
float dot, fac; float dot, fac;
VECCOPY(refract, view); copy_v3_v3(refract, view);
dot= view[0]*n[0] + view[1]*n[1] + view[2]*n[2]; dot= view[0]*n[0] + view[1]*n[1] + view[2]*n[2];
@@ -626,26 +626,26 @@ static int refraction(float *refract, float *n, float *view, float index)
return 1; return 1;
} }
static void reflection_simple(float ref[3], float n[3], const float view[3])
{
const float f1= -2.0f * dot_v3v3(n, view);
madd_v3_v3v3fl(ref, view, n, f1);
}
/* orn = original face normal */ /* orn = original face normal */
static void reflection(float *ref, float *n, float *view, float *orn) static void reflection(float ref[3], float n[3], const float view[3], const float orn[3])
{ {
float f1; float f1;
f1= -2.0f*(n[0]*view[0]+ n[1]*view[1]+ n[2]*view[2]); reflection_simple(ref, n, view);
ref[0]= (view[0]+f1*n[0]); /* test phong normals, then we should prevent vector going to the back */
ref[1]= (view[1]+f1*n[1]); f1= dot_v3v3(ref, orn);
ref[2]= (view[2]+f1*n[2]); if(f1>0.0f) {
f1+= 0.01f;
if(orn) { ref[0]-= f1*orn[0];
/* test phong normals, then we should prevent vector going to the back */ ref[1]-= f1*orn[1];
f1= ref[0]*orn[0]+ ref[1]*orn[1]+ ref[2]*orn[2]; ref[2]-= f1*orn[2];
if(f1>0.0f) {
f1+= .01f;
ref[0]-= f1*orn[0];
ref[1]-= f1*orn[1];
ref[2]-= f1*orn[2];
}
} }
} }
@@ -672,8 +672,7 @@ static void color_combine(float *result, float fac1, float fac2, float *col1, fl
static float shade_by_transmission(Isect *is, ShadeInput *shi, ShadeResult *shr) static float shade_by_transmission(Isect *is, ShadeInput *shi, ShadeResult *shr)
{ {
float dx, dy, dz, d, p; float d;
if (0 == (shi->mat->mode & MA_TRANSP)) if (0 == (shi->mat->mode & MA_TRANSP))
return -1; return -1;
@@ -681,10 +680,12 @@ static float shade_by_transmission(Isect *is, ShadeInput *shi, ShadeResult *shr)
d= 1.0f; d= 1.0f;
} }
else { else {
float p;
/* shi.co[] calculated by shade_ray() */ /* shi.co[] calculated by shade_ray() */
dx= shi->co[0] - is->start[0]; const float dx= shi->co[0] - is->start[0];
dy= shi->co[1] - is->start[1]; const float dy= shi->co[1] - is->start[1];
dz= shi->co[2] - is->start[2]; const float dz= shi->co[2] - is->start[2];
d= sqrt(dx*dx+dy*dy+dz*dz); d= sqrt(dx*dx+dy*dy+dz*dz);
if (d > shi->mat->tx_limit) if (d > shi->mat->tx_limit)
d= shi->mat->tx_limit; d= shi->mat->tx_limit;
@@ -701,13 +702,13 @@ static float shade_by_transmission(Isect *is, ShadeInput *shi, ShadeResult *shr)
return d; return d;
} }
static void ray_fadeout_endcolor(float *col, ShadeInput *origshi, ShadeInput *shi, ShadeResult *shr, Isect *isec, float *vec) static void ray_fadeout_endcolor(float col[3], ShadeInput *origshi, ShadeInput *shi, ShadeResult *shr, Isect *isec, const float vec[3])
{ {
/* un-intersected rays get either rendered material color or sky color */ /* un-intersected rays get either rendered material color or sky color */
if (origshi->mat->fadeto_mir == MA_RAYMIR_FADETOMAT) { if (origshi->mat->fadeto_mir == MA_RAYMIR_FADETOMAT) {
VECCOPY(col, shr->combined); copy_v3_v3(col, shr->combined);
} else if (origshi->mat->fadeto_mir == MA_RAYMIR_FADETOSKY) { } else if (origshi->mat->fadeto_mir == MA_RAYMIR_FADETOSKY) {
VECCOPY(shi->view, vec); copy_v3_v3(shi->view, vec);
normalize_v3(shi->view); normalize_v3(shi->view);
shadeSkyView(col, isec->start, shi->view, NULL, shi->thread); shadeSkyView(col, isec->start, shi->view, NULL, shi->thread);
@@ -715,7 +716,7 @@ static void ray_fadeout_endcolor(float *col, ShadeInput *origshi, ShadeInput *sh
} }
} }
static void ray_fadeout(Isect *is, ShadeInput *shi, float *col, float *blendcol, float dist_mir) static void ray_fadeout(Isect *is, ShadeInput *shi, float col[3], const float blendcol[3], float dist_mir)
{ {
/* if fading out, linear blend against fade color */ /* if fading out, linear blend against fade color */
float blendfac; float blendfac;
@@ -729,14 +730,14 @@ static void ray_fadeout(Isect *is, ShadeInput *shi, float *col, float *blendcol,
/* the main recursive tracer itself /* the main recursive tracer itself
* note: 'col' must be initialized */ * note: 'col' must be initialized */
static void traceray(ShadeInput *origshi, ShadeResult *origshr, short depth, float *start, float *dir, float *col, ObjectInstanceRen *obi, VlakRen *vlr, int traflag) static void traceray(ShadeInput *origshi, ShadeResult *origshr, short depth, const float start[3], const float dir[3], float col[4], ObjectInstanceRen *obi, VlakRen *vlr, int traflag)
{ {
ShadeInput shi= {0}; ShadeInput shi= {0};
Isect isec; Isect isec;
float dist_mir = origshi->mat->dist_mir; float dist_mir = origshi->mat->dist_mir;
VECCOPY(isec.start, start); copy_v3_v3(isec.start, start);
VECCOPY(isec.dir, dir ); copy_v3_v3(isec.dir, dir );
isec.dist = dist_mir > 0 ? dist_mir : RE_RAYTRACE_MAXDIST; isec.dist = dist_mir > 0 ? dist_mir : RE_RAYTRACE_MAXDIST;
isec.mode= RE_RAY_MIRROR; isec.mode= RE_RAY_MIRROR;
isec.check = RE_CHECK_VLR_RENDER; isec.check = RE_CHECK_VLR_RENDER;
@@ -752,8 +753,8 @@ static void traceray(ShadeInput *origshi, ShadeResult *origshr, short depth, flo
float d= 1.0f; float d= 1.0f;
/* for as long we don't have proper dx/dy transform for rays we copy over original */ /* for as long we don't have proper dx/dy transform for rays we copy over original */
VECCOPY(shi.dxco, origshi->dxco); copy_v3_v3(shi.dxco, origshi->dxco);
VECCOPY(shi.dyco, origshi->dyco); copy_v3_v3(shi.dyco, origshi->dyco);
shi.mask= origshi->mask; shi.mask= origshi->mask;
shi.osatex= origshi->osatex; shi.osatex= origshi->osatex;
@@ -845,7 +846,7 @@ static void traceray(ShadeInput *origshi, ShadeResult *origshr, short depth, flo
float mircol[4]; float mircol[4];
float ref[3]; float ref[3];
reflection(ref, shi.vn, shi.view, NULL); reflection_simple(ref, shi.vn, shi.view);
traceray(origshi, origshr, depth-1, shi.co, ref, mircol, shi.obi, shi.vlr, 0); traceray(origshi, origshr, depth-1, shi.co, ref, mircol, shi.obi, shi.vlr, 0);
f1= 1.0f-f; f1= 1.0f-f;
@@ -896,7 +897,7 @@ static void traceray(ShadeInput *origshi, ShadeResult *origshr, short depth, flo
/* calc distributed planar energy */ /* calc distributed planar energy */
static void DP_energy(float *table, float *vec, int tot, float xsize, float ysize) static void DP_energy(float *table, float vec[2], int tot, float xsize, float ysize)
{ {
int x, y, a; int x, y, a;
float *fp, force[3], result[3]; float *fp, force[3], result[3];
@@ -950,7 +951,7 @@ static void jitter_plane_offset(float *jitter1, float *jitter2, int tot, float s
void init_jitter_plane(LampRen *lar) void init_jitter_plane(LampRen *lar)
{ {
float *fp; float *fp;
int x, iter=12, tot= lar->ray_totsamp; int x, tot= lar->ray_totsamp;
/* test if already initialized */ /* test if already initialized */
if(lar->jitter) return; if(lar->jitter) return;
@@ -962,6 +963,7 @@ void init_jitter_plane(LampRen *lar)
/* if 1 sample, we leave table to be zero's */ /* if 1 sample, we leave table to be zero's */
if(tot>1) { if(tot>1) {
int iter=12;
/* set per-lamp fixed seed */ /* set per-lamp fixed seed */
BLI_srandom(tot); BLI_srandom(tot);
@@ -1125,7 +1127,7 @@ static void QMC_getSample(double *s, QMCSampler *qsa, int thread, int num)
} }
/* phong weighted disc using 'blur' for exponent, centred on 0,0 */ /* phong weighted disc using 'blur' for exponent, centred on 0,0 */
static void QMC_samplePhong(float *vec, QMCSampler *qsa, int thread, int num, float blur) static void QMC_samplePhong(float vec[3], QMCSampler *qsa, int thread, int num, float blur)
{ {
double s[2]; double s[2];
float phi, pz, sqr; float phi, pz, sqr;
@@ -1142,7 +1144,7 @@ static void QMC_samplePhong(float *vec, QMCSampler *qsa, int thread, int num, fl
} }
/* rect of edge lengths sizex, sizey, centred on 0.0,0.0 i.e. ranging from -sizex/2 to +sizey/2 */ /* rect of edge lengths sizex, sizey, centred on 0.0,0.0 i.e. ranging from -sizex/2 to +sizey/2 */
static void QMC_sampleRect(float *vec, QMCSampler *qsa, int thread, int num, float sizex, float sizey) static void QMC_sampleRect(float vec[3], QMCSampler *qsa, int thread, int num, float sizex, float sizey)
{ {
double s[2]; double s[2];
@@ -1154,7 +1156,7 @@ static void QMC_sampleRect(float *vec, QMCSampler *qsa, int thread, int num, flo
} }
/* disc of radius 'radius', centred on 0,0 */ /* disc of radius 'radius', centred on 0,0 */
static void QMC_sampleDisc(float *vec, QMCSampler *qsa, int thread, int num, float radius) static void QMC_sampleDisc(float vec[3], QMCSampler *qsa, int thread, int num, float radius)
{ {
double s[2]; double s[2];
float phi, sqr; float phi, sqr;
@@ -1170,7 +1172,7 @@ static void QMC_sampleDisc(float *vec, QMCSampler *qsa, int thread, int num, flo
} }
/* uniform hemisphere sampling */ /* uniform hemisphere sampling */
static void QMC_sampleHemi(float *vec, QMCSampler *qsa, int thread, int num) static void QMC_sampleHemi(float vec[3], QMCSampler *qsa, int thread, int num)
{ {
double s[2]; double s[2];
float phi, sqr; float phi, sqr;
@@ -1187,7 +1189,7 @@ static void QMC_sampleHemi(float *vec, QMCSampler *qsa, int thread, int num)
#if 0 /* currently not used */ #if 0 /* currently not used */
/* cosine weighted hemisphere sampling */ /* cosine weighted hemisphere sampling */
static void QMC_sampleHemiCosine(float *vec, QMCSampler *qsa, int thread, int num) static void QMC_sampleHemiCosine(float vec[3], QMCSampler *qsa, int thread, int num)
{ {
double s[2]; double s[2];
float phi, sqr; float phi, sqr;
@@ -1238,10 +1240,9 @@ static void release_thread_qmcsampler(Render *UNUSED(re), int UNUSED(thread), QM
void free_render_qmcsampler(Render *re) void free_render_qmcsampler(Render *re)
{ {
QMCSampler *qsa, *next;
int a;
if(re->qmcsamplers) { if(re->qmcsamplers) {
QMCSampler *qsa, *next;
int a;
for(a=0; a<BLENDER_MAX_THREADS; a++) { for(a=0; a<BLENDER_MAX_THREADS; a++) {
for(qsa=re->qmcsamplers[a].first; qsa; qsa=next) { for(qsa=re->qmcsamplers[a].first; qsa; qsa=next) {
next= qsa->next; next= qsa->next;
@@ -1256,7 +1257,7 @@ void free_render_qmcsampler(Render *re)
} }
} }
static int adaptive_sample_variance(int samples, float *col, float *colsq, float thresh) static int adaptive_sample_variance(int samples, const float col[3], const float colsq[3], float thresh)
{ {
float var[3], mean[3]; float var[3], mean[3];
@@ -1306,7 +1307,7 @@ static float get_avg_speed(ShadeInput *shi)
/* ***************** main calls ************** */ /* ***************** main calls ************** */
static void trace_refract(float *col, ShadeInput *shi, ShadeResult *shr) static void trace_refract(float col[4], ShadeInput *shi, ShadeResult *shr)
{ {
QMCSampler *qsa=NULL; QMCSampler *qsa=NULL;
int samp_type; int samp_type;
@@ -1345,7 +1346,7 @@ static void trace_refract(float *col, ShadeInput *shi, ShadeResult *shr)
if((shi->vlr->flag & R_SMOOTH)) if((shi->vlr->flag & R_SMOOTH))
reflection(v_refract, shi->vn, shi->view, shi->facenor); reflection(v_refract, shi->vn, shi->view, shi->facenor);
else else
reflection(v_refract, shi->vn, shi->view, NULL); reflection_simple(v_refract, shi->vn, shi->view);
/* can't blur total external reflection */ /* can't blur total external reflection */
max_samples = 1; max_samples = 1;
@@ -1366,7 +1367,7 @@ static void trace_refract(float *col, ShadeInput *shi, ShadeResult *shr)
normalize_v3(v_refract_new); normalize_v3(v_refract_new);
} else { } else {
/* no blurriness, use the original normal */ /* no blurriness, use the original normal */
VECCOPY(v_refract_new, v_refract); copy_v3_v3(v_refract_new, v_refract);
} }
sampcol[0]= sampcol[1]= sampcol[2]= sampcol[3]= 0.0f; sampcol[0]= sampcol[1]= sampcol[2]= sampcol[3]= 0.0f;
@@ -1406,7 +1407,7 @@ static void trace_refract(float *col, ShadeInput *shi, ShadeResult *shr)
release_thread_qmcsampler(&R, shi->thread, qsa); release_thread_qmcsampler(&R, shi->thread, qsa);
} }
static void trace_reflect(float *col, ShadeInput *shi, ShadeResult *shr, float fresnelfac) static void trace_reflect(float col[3], ShadeInput *shi, ShadeResult *shr, float fresnelfac)
{ {
QMCSampler *qsa=NULL; QMCSampler *qsa=NULL;
int samp_type; int samp_type;
@@ -1445,7 +1446,7 @@ static void trace_reflect(float *col, ShadeInput *shi, ShadeResult *shr, float f
* if tangent shading enabled */ * if tangent shading enabled */
if (shi->mat->mode & (MA_TANGENT_V)) { if (shi->mat->mode & (MA_TANGENT_V)) {
cross_v3_v3v3(orthx, shi->vn, shi->tang); // bitangent cross_v3_v3v3(orthx, shi->vn, shi->tang); // bitangent
VECCOPY(orthy, shi->tang); copy_v3_v3(orthy, shi->tang);
mul_v3_fl(orthx, samp3d[0]); mul_v3_fl(orthx, samp3d[0]);
mul_v3_fl(orthy, samp3d[1]*aniso); mul_v3_fl(orthy, samp3d[1]*aniso);
} else { } else {
@@ -1460,13 +1461,13 @@ static void trace_reflect(float *col, ShadeInput *shi, ShadeResult *shr, float f
normalize_v3(v_nor_new); normalize_v3(v_nor_new);
} else { } else {
/* no blurriness, use the original normal */ /* no blurriness, use the original normal */
VECCOPY(v_nor_new, shi->vn); copy_v3_v3(v_nor_new, shi->vn);
} }
if((shi->vlr->flag & R_SMOOTH)) if((shi->vlr->flag & R_SMOOTH))
reflection(v_reflect, v_nor_new, shi->view, shi->facenor); reflection(v_reflect, v_nor_new, shi->view, shi->facenor);
else else
reflection(v_reflect, v_nor_new, shi->view, NULL); reflection_simple(v_reflect, v_nor_new, shi->view);
sampcol[0]= sampcol[1]= sampcol[2]= sampcol[3]= 0.0f; sampcol[0]= sampcol[1]= sampcol[2]= sampcol[3]= 0.0f;
@@ -1517,7 +1518,7 @@ static void trace_reflect(float *col, ShadeInput *shi, ShadeResult *shr, float f
/* extern call from render loop */ /* extern call from render loop */
void ray_trace(ShadeInput *shi, ShadeResult *shr) void ray_trace(ShadeInput *shi, ShadeResult *shr)
{ {
float i, f, f1, fr, fg, fb; float f1, fr, fg, fb;
float mircol[4], tracol[4]; float mircol[4], tracol[4];
float diff[3]; float diff[3];
int do_tra, do_mir; int do_tra, do_mir;
@@ -1527,12 +1528,12 @@ void ray_trace(ShadeInput *shi, ShadeResult *shr)
/* raytrace mirror amd refract like to separate the spec color */ /* raytrace mirror amd refract like to separate the spec color */
if(shi->combinedflag & SCE_PASS_SPEC) if(shi->combinedflag & SCE_PASS_SPEC)
VECSUB(diff, shr->combined, shr->spec) /* no ; */ sub_v3_v3v3(diff, shr->combined, shr->spec);
else else
VECCOPY(diff, shr->combined); copy_v3_v3(diff, shr->combined);
if(do_tra) { if(do_tra) {
float olddiff[3]; float olddiff[3], f;
trace_refract(tracol, shi, shr); trace_refract(tracol, shi, shr);
@@ -1542,24 +1543,23 @@ void ray_trace(ShadeInput *shi, ShadeResult *shr)
fb= 1.0f+ shi->mat->filter*(shi->b-1.0f); fb= 1.0f+ shi->mat->filter*(shi->b-1.0f);
/* for refract pass */ /* for refract pass */
VECCOPY(olddiff, diff); copy_v3_v3(olddiff, diff);
diff[0]= f*diff[0] + f1*fr*tracol[0]; diff[0]= f*diff[0] + f1*fr*tracol[0];
diff[1]= f*diff[1] + f1*fg*tracol[1]; diff[1]= f*diff[1] + f1*fg*tracol[1];
diff[2]= f*diff[2] + f1*fb*tracol[2]; diff[2]= f*diff[2] + f1*fb*tracol[2];
if(shi->passflag & SCE_PASS_REFRACT) if(shi->passflag & SCE_PASS_REFRACT)
VECSUB(shr->refr, diff, olddiff); sub_v3_v3v3(shr->refr, diff, olddiff);
if(!(shi->combinedflag & SCE_PASS_REFRACT)) if(!(shi->combinedflag & SCE_PASS_REFRACT))
VECSUB(diff, diff, shr->refr); sub_v3_v3v3(diff, diff, shr->refr);
shr->alpha= MIN2(1.0f, tracol[3]); shr->alpha= MIN2(1.0f, tracol[3]);
} }
if(do_mir) { if(do_mir) {
const float i= shi->ray_mirror*fresnel_fac(shi->view, shi->vn, shi->mat->fresnel_mir_i, shi->mat->fresnel_mir);
i= shi->ray_mirror*fresnel_fac(shi->view, shi->vn, shi->mat->fresnel_mir_i, shi->mat->fresnel_mir);
if(i!=0.0f) { if(i!=0.0f) {
trace_reflect(mircol, shi, shr, i); trace_reflect(mircol, shi, shr, i);
@@ -1597,12 +1597,12 @@ void ray_trace(ShadeInput *shi, ShadeResult *shr)
if(shi->combinedflag & SCE_PASS_SPEC) if(shi->combinedflag & SCE_PASS_SPEC)
VECADD(shr->combined, diff, shr->spec) /* no ; */ VECADD(shr->combined, diff, shr->spec) /* no ; */
else else
VECCOPY(shr->combined, diff); copy_v3_v3(shr->combined, diff);
} }
/* color 'shadfac' passes through 'col' with alpha and filter */ /* color 'shadfac' passes through 'col' with alpha and filter */
/* filter is only applied on alpha defined transparent part */ /* filter is only applied on alpha defined transparent part */
static void addAlphaLight(float *shadfac, float *col, float alpha, float filter) static void addAlphaLight(float shadfac[4], const float col[3], float alpha, float filter)
{ {
float fr, fg, fb; float fr, fg, fb;
@@ -1621,19 +1621,20 @@ static void ray_trace_shadow_tra(Isect *is, ShadeInput *origshi, int depth, int
{ {
/* ray to lamp, find first face that intersects, check alpha properties, /* ray to lamp, find first face that intersects, check alpha properties,
if it has col[3]>0.0f continue. so exit when alpha is full */ if it has col[3]>0.0f continue. so exit when alpha is full */
ShadeInput shi; const float initial_dist = is->dist;
ShadeResult shr;
float initial_dist = is->dist;
if(RE_rayobject_raycast(R.raytree, is)) { if(RE_rayobject_raycast(R.raytree, is)) {
float d= 1.0f; /* Warning regarding initializing to zero's, This is not that nice,
/* we got a face */ * and possibly a bit slow for every ray, however some variables were
* not initialized properly in, unless using
/* Warning, This is not that nice, and possibly a bit slow for every ray, * shade_input_initialize(...), we need to zero them. */
however some variables were not initialized properly in, unless using shade_input_initialize(...), we need to do a memset */ ShadeInput shi= {NULL};
memset(&shi, 0, sizeof(ShadeInput));
/* end warning! - Campbell */ /* end warning! - Campbell */
ShadeResult shr;
/* we got a face */
shi.depth= origshi->depth + 1; /* only used to indicate tracing */ shi.depth= origshi->depth + 1; /* only used to indicate tracing */
shi.mask= origshi->mask; shi.mask= origshi->mask;
shi.thread= origshi->thread; shi.thread= origshi->thread;
@@ -1647,9 +1648,9 @@ static void ray_trace_shadow_tra(Isect *is, ShadeInput *origshi, int depth, int
shade_ray(is, &shi, &shr); shade_ray(is, &shi, &shr);
if (shi.mat->material_type == MA_TYPE_SURFACE) { if (shi.mat->material_type == MA_TYPE_SURFACE) {
if (traflag & RAY_TRA) const float d= (traflag & RAY_TRA) ?
d= shade_by_transmission(is, &shi, &shr); shade_by_transmission(is, &shi, &shr) :
1.0f;
/* mix colors based on shadfac (rgb + amount of light factor) */ /* mix colors based on shadfac (rgb + amount of light factor) */
addAlphaLight(col, shr.diff, shr.alpha, d*shi.mat->filter); addAlphaLight(col, shr.diff, shr.alpha, d*shi.mat->filter);
} else if (shi.mat->material_type == MA_TYPE_VOLUME) { } else if (shi.mat->material_type == MA_TYPE_VOLUME) {
@@ -1665,7 +1666,7 @@ static void ray_trace_shadow_tra(Isect *is, ShadeInput *origshi, int depth, int
if(depth>0 && col[3]>0.0f) { if(depth>0 && col[3]>0.0f) {
/* adapt isect struct */ /* adapt isect struct */
VECCOPY(is->start, shi.co); copy_v3_v3(is->start, shi.co);
is->dist = initial_dist-is->dist; is->dist = initial_dist-is->dist;
is->orig.ob = shi.obi; is->orig.ob = shi.obi;
is->orig.face = shi.vlr; is->orig.face = shi.vlr;
@@ -1702,7 +1703,7 @@ static int UNUSED_FUNCTION(ray_trace_shadow_rad)(ShadeInput *ship, ShadeResult *
isec.orig.face = ship->vlr; isec.orig.face = ship->vlr;
isec.hint = 0; isec.hint = 0;
VECCOPY(isec.start, ship->co); copy_v3_v3(isec.start, ship->co);
RE_RC_INIT(isec, shi); RE_RC_INIT(isec, shi);
@@ -1710,14 +1711,14 @@ static int UNUSED_FUNCTION(ray_trace_shadow_rad)(ShadeInput *ship, ShadeResult *
counter+=3; counter+=3;
counter %= 768; counter %= 768;
VECCOPY(vec, hashvectf+counter); copy_v3_v3(vec, hashvectf+counter);
if(ship->vn[0]*vec[0]+ship->vn[1]*vec[1]+ship->vn[2]*vec[2]>0.0f) { if(ship->vn[0]*vec[0]+ship->vn[1]*vec[1]+ship->vn[2]*vec[2]>0.0f) {
vec[0]-= vec[0]; vec[0]-= vec[0];
vec[1]-= vec[1]; vec[1]-= vec[1];
vec[2]-= vec[2]; vec[2]-= vec[2];
} }
VECCOPY(isec.dir, vec ); copy_v3_v3(isec.dir, vec );
isec.dist = RE_RAYTRACE_MAXDIST; isec.dist = RE_RAYTRACE_MAXDIST;
if(RE_rayobject_raycast(R.raytree, &isec)) { if(RE_rayobject_raycast(R.raytree, &isec)) {
@@ -1751,7 +1752,7 @@ static int UNUSED_FUNCTION(ray_trace_shadow_rad)(ShadeInput *ship, ShadeResult *
} }
/* aolight: function to create random unit sphere vectors for total random sampling */ /* aolight: function to create random unit sphere vectors for total random sampling */
static void RandomSpherical(float *v) static void RandomSpherical(float v[3])
{ {
float r; float r;
v[2] = 2.f*BLI_frand()-1.f; v[2] = 2.f*BLI_frand()-1.f;
@@ -1765,7 +1766,7 @@ static void RandomSpherical(float *v)
} }
/* calc distributed spherical energy */ /* calc distributed spherical energy */
static void DS_energy(float *sphere, int tot, float *vec) static void DS_energy(float *sphere, int tot, float vec[3])
{ {
float *fp, fac, force[3], res[3]; float *fp, fac, force[3], res[3];
int a; int a;
@@ -1863,13 +1864,15 @@ static float *sphere_sampler(int type, int resol, int thread, int xs, int ys, in
} }
else { else {
float *sphere; float *sphere;
float cosfi, sinfi, cost, sint; float *vec1;
float ang, *vec1;
int a;
// 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); sphere= (reset)? NULL: threadsafe_table_sphere(1, thread, xs, ys, tot);
if(sphere==NULL) { if(sphere==NULL) {
float cosfi, sinfi, cost, sint;
float ang;
int a;
sphere= threadsafe_table_sphere(0, thread, xs, ys, tot); sphere= threadsafe_table_sphere(0, thread, xs, ys, tot);
// random rotation // random rotation
@@ -1890,7 +1893,7 @@ static float *sphere_sampler(int type, int resol, int thread, int xs, int ys, in
} }
} }
static void ray_ao_qmc(ShadeInput *shi, float *ao, float *env) static void ray_ao_qmc(ShadeInput *shi, float ao[3], float env[3])
{ {
Isect isec; Isect isec;
RayHint point_hint; RayHint point_hint;
@@ -1924,7 +1927,7 @@ static void ray_ao_qmc(ShadeInput *shi, float *ao, float *env)
isec.mode= (R.wrld.aomode & WO_AODIST)?RE_RAY_SHADOW_TRA:RE_RAY_SHADOW; isec.mode= (R.wrld.aomode & WO_AODIST)?RE_RAY_SHADOW_TRA:RE_RAY_SHADOW;
isec.lay= -1; isec.lay= -1;
VECCOPY(isec.start, shi->co); copy_v3_v3(isec.start, shi->co);
RE_rayobject_hint_bb( R.raytree, &point_hint, isec.start, isec.start ); RE_rayobject_hint_bb( R.raytree, &point_hint, isec.start, isec.start );
isec.hint = &point_hint; isec.hint = &point_hint;
@@ -1943,10 +1946,10 @@ static void ray_ao_qmc(ShadeInput *shi, float *ao, float *env)
} }
if(shi->vlr->flag & R_SMOOTH) { if(shi->vlr->flag & R_SMOOTH) {
VECCOPY(nrm, shi->vn); copy_v3_v3(nrm, shi->vn);
} }
else { else {
VECCOPY(nrm, shi->facenor); copy_v3_v3(nrm, shi->facenor);
} }
ortho_basis_v3v3_v3( up, side,nrm); ortho_basis_v3v3_v3( up, side,nrm);
@@ -1990,7 +1993,7 @@ static void ray_ao_qmc(ShadeInput *shi, float *ao, float *env)
} }
else if(envcolor!=WO_AOPLAIN) { else if(envcolor!=WO_AOPLAIN) {
float skycol[4]; float skycol[4];
float skyfac, view[3]; float view[3];
view[0]= -dir[0]; view[0]= -dir[0];
view[1]= -dir[1]; view[1]= -dir[1];
@@ -1998,7 +2001,7 @@ static void ray_ao_qmc(ShadeInput *shi, float *ao, float *env)
normalize_v3(view); normalize_v3(view);
if(envcolor==WO_AOSKYCOL) { if(envcolor==WO_AOSKYCOL) {
skyfac= 0.5f*(1.0f+view[0]*R.grvec[0]+ view[1]*R.grvec[1]+ view[2]*R.grvec[2]); const float skyfac= 0.5f*(1.0f+view[0]*R.grvec[0]+ view[1]*R.grvec[1]+ view[2]*R.grvec[2]);
env[0]+= (1.0f-skyfac)*R.wrld.horr + skyfac*R.wrld.zenr; env[0]+= (1.0f-skyfac)*R.wrld.horr + skyfac*R.wrld.zenr;
env[1]+= (1.0f-skyfac)*R.wrld.horg + skyfac*R.wrld.zeng; env[1]+= (1.0f-skyfac)*R.wrld.horg + skyfac*R.wrld.zeng;
env[2]+= (1.0f-skyfac)*R.wrld.horb + skyfac*R.wrld.zenb; env[2]+= (1.0f-skyfac)*R.wrld.horb + skyfac*R.wrld.zenb;
@@ -2039,7 +2042,7 @@ static void ray_ao_qmc(ShadeInput *shi, float *ao, float *env)
} }
/* extern call from shade_lamp_loop, ambient occlusion calculus */ /* extern call from shade_lamp_loop, ambient occlusion calculus */
static void ray_ao_spheresamp(ShadeInput *shi, float *ao, float *env) static void ray_ao_spheresamp(ShadeInput *shi, float ao[3], float env[3])
{ {
Isect isec; Isect isec;
RayHint point_hint; RayHint point_hint;
@@ -2063,7 +2066,7 @@ static void ray_ao_spheresamp(ShadeInput *shi, float *ao, float *env)
isec.mode= (R.wrld.aomode & WO_AODIST)?RE_RAY_SHADOW_TRA:RE_RAY_SHADOW; isec.mode= (R.wrld.aomode & WO_AODIST)?RE_RAY_SHADOW_TRA:RE_RAY_SHADOW;
isec.lay= -1; isec.lay= -1;
VECCOPY(isec.start, shi->co); copy_v3_v3(isec.start, shi->co);
RE_rayobject_hint_bb( R.raytree, &point_hint, isec.start, isec.start ); RE_rayobject_hint_bb( R.raytree, &point_hint, isec.start, isec.start );
isec.hint = &point_hint; isec.hint = &point_hint;
@@ -2128,7 +2131,7 @@ static void ray_ao_spheresamp(ShadeInput *shi, float *ao, float *env)
} }
else if(envcolor!=WO_AOPLAIN) { else if(envcolor!=WO_AOPLAIN) {
float skycol[4]; float skycol[4];
float fac, view[3]; float view[3];
view[0]= -vec[0]; view[0]= -vec[0];
view[1]= -vec[1]; view[1]= -vec[1];
@@ -2136,7 +2139,7 @@ static void ray_ao_spheresamp(ShadeInput *shi, float *ao, float *env)
normalize_v3(view); normalize_v3(view);
if(envcolor==WO_AOSKYCOL) { if(envcolor==WO_AOSKYCOL) {
fac= 0.5f*(1.0f+view[0]*R.grvec[0]+ view[1]*R.grvec[1]+ view[2]*R.grvec[2]); const float fac= 0.5f*(1.0f+view[0]*R.grvec[0]+ view[1]*R.grvec[1]+ view[2]*R.grvec[2]);
env[0]+= (1.0f-fac)*R.wrld.horr + fac*R.wrld.zenr; env[0]+= (1.0f-fac)*R.wrld.horr + fac*R.wrld.zenr;
env[1]+= (1.0f-fac)*R.wrld.horg + fac*R.wrld.zeng; env[1]+= (1.0f-fac)*R.wrld.horg + fac*R.wrld.zeng;
env[2]+= (1.0f-fac)*R.wrld.horb + fac*R.wrld.zenb; env[2]+= (1.0f-fac)*R.wrld.horb + fac*R.wrld.zenb;
@@ -2167,7 +2170,7 @@ static void ray_ao_spheresamp(ShadeInput *shi, float *ao, float *env)
copy_v3_v3(env, ao); copy_v3_v3(env, ao);
} }
void ray_ao(ShadeInput *shi, float *ao, float *env) void ray_ao(ShadeInput *shi, float ao[3], float env[3])
{ {
/* Unfortunately, the unusual way that the sphere sampler calculates roughly twice as many /* Unfortunately, the unusual way that the sphere sampler calculates roughly twice as many
* samples as are actually traced, and skips them based on bias and OSA settings makes it very difficult * samples as are actually traced, and skips them based on bias and OSA settings makes it very difficult
@@ -2214,12 +2217,12 @@ static void ray_shadow_jittered_coords(ShadeInput *shi, int max, float jitco[RE_
*totjitco= tot; *totjitco= tot;
} }
else { else {
VECCOPY(jitco[0], shi->co); copy_v3_v3(jitco[0], shi->co);
*totjitco= 1; *totjitco= 1;
} }
} }
static void ray_shadow_qmc(ShadeInput *shi, LampRen *lar, float *lampco, float *shadfac, Isect *isec) static void ray_shadow_qmc(ShadeInput *shi, LampRen *lar, const float lampco[3], float shadfac[4], Isect *isec)
{ {
QMCSampler *qsa=NULL; QMCSampler *qsa=NULL;
int samples=0; int samples=0;
@@ -2276,7 +2279,7 @@ static void ray_shadow_qmc(ShadeInput *shi, LampRen *lar, float *lampco, float *
isec->hint = &bb_hint; isec->hint = &bb_hint;
isec->check = RE_CHECK_VLR_RENDER; isec->check = RE_CHECK_VLR_RENDER;
isec->skip = RE_SKIP_VLR_NEIGHBOUR; isec->skip = RE_SKIP_VLR_NEIGHBOUR;
VECCOPY(vec, lampco); copy_v3_v3(vec, lampco);
while (samples < max_samples) { while (samples < max_samples) {
@@ -2294,9 +2297,7 @@ static void ray_shadow_qmc(ShadeInput *shi, LampRen *lar, float *lampco, float *
float ru[3], rv[3], v[3], s[3]; float ru[3], rv[3], v[3], s[3];
/* calc tangent plane vectors */ /* calc tangent plane vectors */
v[0] = co[0] - lampco[0]; sub_v3_v3v3(v, co, lampco);
v[1] = co[1] - lampco[1];
v[2] = co[2] - lampco[2];
normalize_v3(v); normalize_v3(v);
ortho_basis_v3v3_v3( ru, rv,v); ortho_basis_v3v3_v3( ru, rv,v);
@@ -2308,7 +2309,7 @@ static void ray_shadow_qmc(ShadeInput *shi, LampRen *lar, float *lampco, float *
s[1] = samp3d[0]*ru[1] + samp3d[1]*rv[1]; s[1] = samp3d[0]*ru[1] + samp3d[1]*rv[1];
s[2] = samp3d[0]*ru[2] + samp3d[1]*rv[2]; s[2] = samp3d[0]*ru[2] + samp3d[1]*rv[2];
VECCOPY(samp3d, s); copy_v3_v3(samp3d, s);
} }
else { else {
/* sampling, returns quasi-random vector in [sizex,sizey]^2 plane */ /* sampling, returns quasi-random vector in [sizex,sizey]^2 plane */
@@ -2321,7 +2322,7 @@ static void ray_shadow_qmc(ShadeInput *shi, LampRen *lar, float *lampco, float *
end[1] = vec[1]+samp3d[1]; end[1] = vec[1]+samp3d[1];
end[2] = vec[2]+samp3d[2]; end[2] = vec[2]+samp3d[2];
} else { } else {
VECCOPY(end, vec); copy_v3_v3(end, vec);
} }
if(shi->strand) { if(shi->strand) {
@@ -2329,7 +2330,7 @@ static void ray_shadow_qmc(ShadeInput *shi, LampRen *lar, float *lampco, float *
float jitbias= 0.5f*(len_v3(shi->dxco) + len_v3(shi->dyco)); float jitbias= 0.5f*(len_v3(shi->dxco) + len_v3(shi->dyco));
float v[3]; float v[3];
VECSUB(v, co, end); sub_v3_v3v3(v, co, end);
normalize_v3(v); normalize_v3(v);
co[0] -= jitbias*v[0]; co[0] -= jitbias*v[0];
@@ -2337,7 +2338,7 @@ static void ray_shadow_qmc(ShadeInput *shi, LampRen *lar, float *lampco, float *
co[2] -= jitbias*v[2]; co[2] -= jitbias*v[2];
} }
VECCOPY(isec->start, co); copy_v3_v3(isec->start, co);
isec->dir[0] = end[0]-isec->start[0]; isec->dir[0] = end[0]-isec->start[0];
isec->dir[1] = end[1]-isec->start[1]; isec->dir[1] = end[1]-isec->start[1];
isec->dir[2] = end[2]-isec->start[2]; isec->dir[2] = end[2]-isec->start[2];
@@ -2393,7 +2394,7 @@ static void ray_shadow_qmc(ShadeInput *shi, LampRen *lar, float *lampco, float *
release_thread_qmcsampler(&R, shi->thread, qsa); release_thread_qmcsampler(&R, shi->thread, qsa);
} }
static void ray_shadow_jitter(ShadeInput *shi, LampRen *lar, float *lampco, float *shadfac, Isect *isec) static void ray_shadow_jitter(ShadeInput *shi, LampRen *lar, const float lampco[3], float shadfac[4], Isect *isec)
{ {
/* area soft shadow */ /* area soft shadow */
float *jitlamp; float *jitlamp;
@@ -2416,7 +2417,7 @@ static void ray_shadow_jitter(ShadeInput *shi, LampRen *lar, float *lampco, floa
if(a==4) mask |= (mask>>4)|(mask>>8); if(a==4) mask |= (mask>>4)|(mask>>8);
else if(a==9) mask |= (mask>>9); else if(a==9) mask |= (mask>>9);
VECCOPY(isec->start, shi->co); copy_v3_v3(isec->start, shi->co);
isec->orig.ob = shi->obi; isec->orig.ob = shi->obi;
isec->orig.face = shi->vlr; isec->orig.face = shi->vlr;
RE_rayobject_hint_bb( R.raytree, &point_hint, isec->start, isec->start ); RE_rayobject_hint_bb( R.raytree, &point_hint, isec->start, isec->start );
@@ -2477,7 +2478,7 @@ static void ray_shadow_jitter(ShadeInput *shi, LampRen *lar, float *lampco, floa
} }
} }
/* extern call from shade_lamp_loop */ /* extern call from shade_lamp_loop */
void ray_shadow(ShadeInput *shi, LampRen *lar, float *shadfac) void ray_shadow(ShadeInput *shi, LampRen *lar, float shadfac[4])
{ {
Isect isec; Isect isec;
float lampco[3]; float lampco[3];
@@ -2520,7 +2521,7 @@ void ray_shadow(ShadeInput *shi, LampRen *lar, float *shadfac)
lampco[2]= shi->co[2] - R.maxdist*lar->vec[2]; lampco[2]= shi->co[2] - R.maxdist*lar->vec[2];
} }
else { else {
VECCOPY(lampco, lar->co); copy_v3_v3(lampco, lar->co);
} }
if (ELEM(lar->ray_samp_method, LA_SAMP_HALTON, LA_SAMP_HAMMERSLEY)) { if (ELEM(lar->ray_samp_method, LA_SAMP_HALTON, LA_SAMP_HAMMERSLEY)) {
@@ -2536,8 +2537,8 @@ void ray_shadow(ShadeInput *shi, LampRen *lar, float *shadfac)
shadfac[3]= 1.0f; // 1.0=full light shadfac[3]= 1.0f; // 1.0=full light
/* set up isec.dir */ /* set up isec.dir */
VECCOPY(isec.start, shi->co); copy_v3_v3(isec.start, shi->co);
VECSUB(isec.dir, lampco, isec.start); sub_v3_v3v3(isec.dir, lampco, isec.start);
isec.dist = normalize_v3(isec.dir); isec.dist = normalize_v3(isec.dir);
if(isec.mode==RE_RAY_SHADOW_TRA) { if(isec.mode==RE_RAY_SHADOW_TRA) {
@@ -2545,7 +2546,7 @@ void ray_shadow(ShadeInput *shi, LampRen *lar, float *shadfac)
float col[4] = {1.0f, 1.0f, 1.0f, 1.0f}; float col[4] = {1.0f, 1.0f, 1.0f, 1.0f};
ray_trace_shadow_tra(&isec, shi, DEPTH_SHADOW_TRA, 0, col); ray_trace_shadow_tra(&isec, shi, DEPTH_SHADOW_TRA, 0, col);
QUATCOPY(shadfac, col); copy_v4_v4(shadfac, col);
} }
else if(RE_rayobject_raycast(R.raytree, &isec)) else if(RE_rayobject_raycast(R.raytree, &isec))
shadfac[3]= 0.0f; shadfac[3]= 0.0f;
@@ -2584,15 +2585,15 @@ static void ray_translucent(ShadeInput *shi, LampRen *lar, float *distfac, float
lampco[2]= shi->co[2] - RE_RAYTRACE_MAXDIST*lar->vec[2]; lampco[2]= shi->co[2] - RE_RAYTRACE_MAXDIST*lar->vec[2];
} }
else { else {
VECCOPY(lampco, lar->co); copy_v3_v3(lampco, lar->co);
} }
isec.orig.ob = shi->obi; isec.orig.ob = shi->obi;
isec.orig.face = shi->vlr; isec.orig.face = shi->vlr;
/* set up isec.dir */ /* set up isec.dir */
VECCOPY(isec.start, shi->co); copy_v3_v3(isec.start, shi->co);
VECCOPY(isec.end, lampco); copy_v3_v3(isec.end, lampco);
if(RE_rayobject_raycast(R.raytree, &isec)) { if(RE_rayobject_raycast(R.raytree, &isec)) {
/* we got a face */ /* we got a face */

View File

@@ -142,7 +142,7 @@ void calc_renderco_ortho(float co[3], float x, float y, int z)
co[2]= R.winmat[3][2]/( R.winmat[2][3]*zco - R.winmat[2][2] ); co[2]= R.winmat[3][2]/( R.winmat[2][3]*zco - R.winmat[2][2] );
} }
void calc_renderco_zbuf(float co[3], float *view, int z) void calc_renderco_zbuf(float co[3], const float view[3], int z)
{ {
float fac, zco; float fac, zco;

View File

@@ -1355,16 +1355,14 @@ void shade_sample_initialize(ShadeSample *ssamp, RenderPart *pa, RenderLayer *rl
/* Do AO or (future) GI */ /* Do AO or (future) GI */
void shade_samples_do_AO(ShadeSample *ssamp) void shade_samples_do_AO(ShadeSample *ssamp)
{ {
ShadeInput *shi;
int sample;
if(!(R.r.mode & R_SHADOW)) if(!(R.r.mode & R_SHADOW))
return; return;
if(!(R.r.mode & R_RAYTRACE) && !(R.wrld.ao_gather_method == WO_AOGATHER_APPROX)) if(!(R.r.mode & R_RAYTRACE) && !(R.wrld.ao_gather_method == WO_AOGATHER_APPROX))
return; return;
if(R.wrld.mode & (WO_AMB_OCC|WO_ENV_LIGHT|WO_INDIRECT_LIGHT)) { if(R.wrld.mode & (WO_AMB_OCC|WO_ENV_LIGHT|WO_INDIRECT_LIGHT)) {
shi= &ssamp->shi[0]; ShadeInput *shi= &ssamp->shi[0];
int sample;
if(((shi->passflag & SCE_PASS_COMBINED) && (shi->combinedflag & (SCE_PASS_AO|SCE_PASS_ENVIRONMENT|SCE_PASS_INDIRECT))) if(((shi->passflag & SCE_PASS_COMBINED) && (shi->combinedflag & (SCE_PASS_AO|SCE_PASS_ENVIRONMENT|SCE_PASS_INDIRECT)))
|| (shi->passflag & (SCE_PASS_AO|SCE_PASS_ENVIRONMENT|SCE_PASS_INDIRECT))) || (shi->passflag & (SCE_PASS_AO|SCE_PASS_ENVIRONMENT|SCE_PASS_INDIRECT)))

View File

@@ -119,7 +119,7 @@ static void fogcolor(float *colf, float *rco, float *view)
#endif #endif
/* zcor is distance, co the 3d coordinate in eye space, return alpha */ /* zcor is distance, co the 3d coordinate in eye space, return alpha */
float mistfactor(float zcor, float *co) float mistfactor(float zcor, float const co[3])
{ {
float fac, hi; float fac, hi;
@@ -162,7 +162,6 @@ static void spothalo(struct LampRen *lar, ShadeInput *shi, float *intens)
double t0, t1 = 0.0f, t2= 0.0f, t3; double t0, t1 = 0.0f, t2= 0.0f, t3;
float p1[3], p2[3], ladist, maxz = 0.0f, maxy = 0.0f, haint; float p1[3], p2[3], ladist, maxz = 0.0f, maxy = 0.0f, haint;
int snijp, doclip=1, use_yco=0; int snijp, doclip=1, use_yco=0;
int ok1=0, ok2=0;
*intens= 0.0f; *intens= 0.0f;
haint= lar->haint; haint= lar->haint;
@@ -243,6 +242,8 @@ static void spothalo(struct LampRen *lar, ShadeInput *shi, float *intens)
} }
} }
if(snijp==2) { if(snijp==2) {
int ok1=0, ok2=0;
/* sort */ /* sort */
if(t1>t2) { if(t1>t2) {
a= t1; t1= t2; t2= a; a= t1; t1= t2; t2= a;
@@ -345,7 +346,7 @@ static void spothalo(struct LampRen *lar, ShadeInput *shi, float *intens)
} }
} }
void renderspothalo(ShadeInput *shi, float *col, float alpha) void renderspothalo(ShadeInput *shi, float col[4], float alpha)
{ {
ListBase *lights; ListBase *lights;
GroupObject *go; GroupObject *go;
@@ -891,12 +892,11 @@ void shade_color(ShadeInput *shi, ShadeResult *shr)
static void ramp_diffuse_result(float *diff, ShadeInput *shi) static void ramp_diffuse_result(float *diff, ShadeInput *shi)
{ {
Material *ma= shi->mat; Material *ma= shi->mat;
float col[4], fac=0; float col[4];
if(ma->ramp_col) { if(ma->ramp_col) {
if(ma->rampin_col==MA_RAMP_IN_RESULT) { if(ma->rampin_col==MA_RAMP_IN_RESULT) {
float fac= 0.3f*diff[0] + 0.58f*diff[1] + 0.12f*diff[2];
fac= 0.3f*diff[0] + 0.58f*diff[1] + 0.12f*diff[2];
do_colorband(ma->ramp_col, fac, col); do_colorband(ma->ramp_col, fac, col);
/* blending method */ /* blending method */
@@ -911,7 +911,6 @@ static void ramp_diffuse_result(float *diff, ShadeInput *shi)
static void add_to_diffuse(float *diff, ShadeInput *shi, float is, float r, float g, float b) static void add_to_diffuse(float *diff, ShadeInput *shi, float is, float r, float g, float b)
{ {
Material *ma= shi->mat; Material *ma= shi->mat;
float col[4], colt[3], fac=0;
if(ma->ramp_col && (ma->mode & MA_RAMP_COL)) { if(ma->ramp_col && (ma->mode & MA_RAMP_COL)) {
@@ -923,6 +922,9 @@ static void add_to_diffuse(float *diff, ShadeInput *shi, float is, float r, floa
diff[2] += b * shi->b; diff[2] += b * shi->b;
} }
else { else {
float colt[3], col[4];
float fac;
/* input */ /* input */
switch(ma->rampin_col) { switch(ma->rampin_col) {
case MA_RAMP_IN_ENERGY: case MA_RAMP_IN_ENERGY:
@@ -934,6 +936,9 @@ static void add_to_diffuse(float *diff, ShadeInput *shi, float is, float r, floa
case MA_RAMP_IN_NOR: case MA_RAMP_IN_NOR:
fac= shi->view[0]*shi->vn[0] + shi->view[1]*shi->vn[1] + shi->view[2]*shi->vn[2]; fac= shi->view[0]*shi->vn[0] + shi->view[1]*shi->vn[1] + shi->view[2]*shi->vn[2];
break; break;
default:
fac= 0.0f;
break;
} }
do_colorband(ma->ramp_col, fac, col); do_colorband(ma->ramp_col, fac, col);
@@ -962,11 +967,11 @@ static void add_to_diffuse(float *diff, ShadeInput *shi, float is, float r, floa
static void ramp_spec_result(float *specr, float *specg, float *specb, ShadeInput *shi) static void ramp_spec_result(float *specr, float *specg, float *specb, ShadeInput *shi)
{ {
Material *ma= shi->mat; Material *ma= shi->mat;
float col[4];
float fac;
if(ma->ramp_spec && (ma->rampin_spec==MA_RAMP_IN_RESULT)) { if(ma->ramp_spec && (ma->rampin_spec==MA_RAMP_IN_RESULT)) {
fac= 0.3f*(*specr) + 0.58f*(*specg) + 0.12f*(*specb); float col[4];
float fac= 0.3f*(*specr) + 0.58f*(*specg) + 0.12f*(*specb);
do_colorband(ma->ramp_spec, fac, col); do_colorband(ma->ramp_spec, fac, col);
/* blending method */ /* blending method */
@@ -978,11 +983,9 @@ static void ramp_spec_result(float *specr, float *specg, float *specb, ShadeInpu
} }
/* is = dot product shade, t = spec energy */ /* is = dot product shade, t = spec energy */
static void do_specular_ramp(ShadeInput *shi, float is, float t, float *spec) static void do_specular_ramp(ShadeInput *shi, float is, float t, float spec[3])
{ {
Material *ma= shi->mat; Material *ma= shi->mat;
float col[4];
float fac=0.0f;
spec[0]= shi->specr; spec[0]= shi->specr;
spec[1]= shi->specg; spec[1]= shi->specg;
@@ -990,6 +993,8 @@ static void do_specular_ramp(ShadeInput *shi, float is, float t, float *spec)
/* MA_RAMP_IN_RESULT is exception */ /* MA_RAMP_IN_RESULT is exception */
if(ma->ramp_spec && (ma->rampin_spec!=MA_RAMP_IN_RESULT)) { if(ma->ramp_spec && (ma->rampin_spec!=MA_RAMP_IN_RESULT)) {
float fac;
float col[4];
/* input */ /* input */
switch(ma->rampin_spec) { switch(ma->rampin_spec) {
@@ -1002,6 +1007,9 @@ static void do_specular_ramp(ShadeInput *shi, float is, float t, float *spec)
case MA_RAMP_IN_NOR: case MA_RAMP_IN_NOR:
fac= shi->view[0]*shi->vn[0] + shi->view[1]*shi->vn[1] + shi->view[2]*shi->vn[2]; fac= shi->view[0]*shi->vn[0] + shi->view[1]*shi->vn[1] + shi->view[2]*shi->vn[2];
break; break;
default:
fac= 0.0f;
break;
} }
do_colorband(ma->ramp_spec, fac, col); do_colorband(ma->ramp_spec, fac, col);
@@ -1086,7 +1094,7 @@ static void indirect_lighting_apply(ShadeInput *shi, ShadeResult *shr)
} }
/* result written in shadfac */ /* result written in shadfac */
void lamp_get_shadow(LampRen *lar, ShadeInput *shi, float inp, float *shadfac, int do_real) void lamp_get_shadow(LampRen *lar, ShadeInput *shi, float inp, float shadfac[4], int do_real)
{ {
LampShadowSubSample *lss= &(lar->shadsamp[shi->thread].s[shi->sample]); LampShadowSubSample *lss= &(lar->shadsamp[shi->thread].s[shi->sample]);
@@ -1115,7 +1123,7 @@ void lamp_get_shadow(LampRen *lar, ShadeInput *shi, float inp, float *shadfac, i
} }
/* lampdistance and spot angle, writes in lv and dist */ /* lampdistance and spot angle, writes in lv and dist */
float lamp_get_visibility(LampRen *lar, float *co, float *lv, float *dist) float lamp_get_visibility(LampRen *lar, const float co[3], float lv[3], float *dist)
{ {
if(lar->type==LA_SUN || lar->type==LA_HEMI) { if(lar->type==LA_SUN || lar->type==LA_HEMI) {
*dist= 1.0f; *dist= 1.0f;
@@ -1621,7 +1629,7 @@ static void shade_lamp_loop_only_shadow(ShadeInput *shi, ShadeResult *shr)
} }
/* let's map negative light as if it mirrors positive light, otherwise negative values disappear */ /* let's map negative light as if it mirrors positive light, otherwise negative values disappear */
static void wrld_exposure_correct(float *diff) static void wrld_exposure_correct(float diff[3])
{ {
diff[0]= R.wrld.linfac*(1.0f-exp( diff[0]*R.wrld.logfac) ); diff[0]= R.wrld.linfac*(1.0f-exp( diff[0]*R.wrld.logfac) );

View File

@@ -92,7 +92,7 @@ void strand_eval_point(StrandSegment *sseg, StrandPoint *spoint)
Material *ma; Material *ma;
StrandBuffer *strandbuf; StrandBuffer *strandbuf;
float *simplify; float *simplify;
float p[4][3], data[4], cross[3], crosslen, w, dx, dy, t; float p[4][3], data[4], cross[3], w, dx, dy, t;
int type; int type;
strandbuf= sseg->buffer; strandbuf= sseg->buffer;
@@ -164,7 +164,7 @@ void strand_eval_point(StrandSegment *sseg, StrandPoint *spoint)
if(w > 0.0f) { if(w > 0.0f) {
if(strandbuf->flag & R_STRAND_B_UNITS) { if(strandbuf->flag & R_STRAND_B_UNITS) {
crosslen= len_v3(cross); const float crosslen= len_v3(cross);
w= 2.0f*crosslen*strandbuf->minwidth/w; w= 2.0f*crosslen*strandbuf->minwidth/w;
if(spoint->width < w) { if(spoint->width < w) {

View File

@@ -1747,13 +1747,14 @@ static void zbuf_project_cache_clear(ZbufProjectCache *cache, int size)
static int zbuf_shadow_project(ZbufProjectCache *cache, int index, float winmat[][4], float *co, float *ho) static int zbuf_shadow_project(ZbufProjectCache *cache, int index, float winmat[][4], float *co, float *ho)
{ {
int clipflag, cindex= index & 255; int cindex= index & 255;
if(cache[cindex].index == index) { if(cache[cindex].index == index) {
QUATCOPY(ho, cache[cindex].ho); QUATCOPY(ho, cache[cindex].ho);
return cache[cindex].clip; return cache[cindex].clip;
} }
else { else {
int clipflag;
projectvert(co, winmat, ho); projectvert(co, winmat, ho);
clipflag= testclip(ho); clipflag= testclip(ho);
@@ -1775,14 +1776,16 @@ static void zbuffer_part_bounds(int winx, int winy, RenderPart *pa, float *bound
static int zbuf_part_project(ZbufProjectCache *cache, int index, float winmat[][4], float *bounds, float *co, float *ho) static int zbuf_part_project(ZbufProjectCache *cache, int index, float winmat[][4], float *bounds, float *co, float *ho)
{ {
float vec[3], wco; float vec[3];
int clipflag= 0, cindex= index & 255; int cindex= index & 255;
if(cache[cindex].index == index) { if(cache[cindex].index == index) {
QUATCOPY(ho, cache[cindex].ho); QUATCOPY(ho, cache[cindex].ho);
return cache[cindex].clip; return cache[cindex].clip;
} }
else { else {
float wco;
int clipflag= 0;
VECCOPY(vec, co) VECCOPY(vec, co)
projectvert(co, winmat, ho); projectvert(co, winmat, ho);