[Bf-committers] New Patch for DISTRAY
Bart
bf-committers@blender.org
Thu, 15 Jul 2004 19:53:26 +0200
Saw post and pictures about distray. Looks great!
http://www.elysiun.com/forum/viewtopic.php?t=27552
Read about a huge render time increase. How many times it is faster?
Ray Wells wrote:
> here it is, enjoy.
>
> i fixed all the major bugs.
>
> the only thing you could get picky about is that
> sometimes jitter will cause lamps to jitter through
> objects causing artifacts... but that's only if you're
> putting the distray lamps too close ;)
>
> Index: render/extern/include/render_types.h
> ===================================================================
> RCS file:
> /cvsroot/bf-blender/blender/source/blender/render/extern/include/render_types.h,v
> retrieving revision 1.16
> diff -u -r1.16 render_types.h
> --- render/extern/include/render_types.h 26 Apr 2004
> 21:38:35 -0000 1.16
> +++ render/extern/include/render_types.h 14 Jul 2004
> 10:02:47 -0000
> @@ -234,7 +234,8 @@
> float xsp, ysp, distkw, inpr;
> float halokw, halo;
> float ld1,ld2;
> -
> + float maxsoft;
> + int softsamples;
> /* copied from Lamp, to decouple more rendering
> stuff */
> /** Size of the shadowbuffer */
> short bufsize;
> @@ -269,4 +270,3 @@
> } LampRen;
>
> #endif /* RENDER_TYPES_H */
> -
> Index: render/intern/source/rendercore.c
> ===================================================================
> RCS file:
> /cvsroot/bf-blender/blender/source/blender/render/intern/source/rendercore.c,v
> retrieving revision 1.70
> diff -u -r1.70 rendercore.c
> --- render/intern/source/rendercore.c 8 Jul 2004
> 20:38:24 -0000 1.70
> +++ render/intern/source/rendercore.c 14 Jul 2004
> 10:02:48 -0000
> @@ -1384,6 +1384,15 @@
> }
>
> /* Blinn spec */
> +#if 0
> +float PluginSpec(float *n, float *l, float *v,
> BlenderPlugin *plugin) {
> + (float) (*spec_cb ( float , float , float, unsigned
> char**) = PLUG_GetCallback(plugin, PLUG_AREA_SPEC);
> + unsigned char *pushargs = NULL;
> +
> + PLUG_GetArgValues(plugin, PLUG_SHADER_SPEC,
> pushargs); // these are stored in some database
> + return (*spec_cb)(n,l,v,pushargs);
> + }
> +#endif
> float Blinn_Spec(float *n, float *l, float *v, float
> refrac, float spec_power )
> {
> float i, nh, nv, nl, vh, h[3];
> @@ -1459,8 +1468,16 @@
>
> return rslt;
> }
> -
> -/* cartoon render diffuse */
> +#if 0
> +// plugin diffuse
> +float PluginDiff( float *n, float *l, float *v,
> BlenderPlugin *plugin) {
> + float (*diff_cb) (float,float,float,va_list*) =
> plugin->callbacks[PLUG_DIFF_CB];
> +
> + return (*diff_cb) (n,l,v,plugin->pushargs);
> + }
> +#endif
> +
> + /* cartoon render diffuse */
> float Toon_Diff( float *n, float *l, float *v, float
> size, float smooth )
> {
> float rslt, ang;
> @@ -1947,7 +1964,65 @@
>
> /* single sided? */
> if( shi->vlr->n[0]*lv[0] + shi->vlr->n[1]*lv[1] +
> shi->vlr->n[2]*lv[2] > -0.01) {
> - ray_shadow(shi, lar, shad);
> +
> + if (lar->mode & LA_SHAD_SOFT) {
> + //printf("SOFT PLEASE!! Soft:%f
> Samp%d",lar->soft,lar->samp);
> +// lar->maxsoft = lar->soft;
> +// lar->softsamples= lar->samp;
> +
> +
> + float oro[3];
> + if (lar->type != LA_SUN)
> {VECCOPY(oro,lar->co);} else {VECCOPY(oro,lar->vec);}
> + float sx,sy,sz;
> + float coolshad[3];
> + int i;
> + memset (coolshad, 0, sizeof(coolshad)); // we
> need to reset it
> + for (i=0; i < lar->softsamples; i++) {
> + sx=(float)drand48() * lar->maxsoft;
> + sy=(float)drand48() *lar->maxsoft;
> + sz=(float)drand48() *lar->maxsoft;
> + if (lar->type != LA_SUN) {
> + lar->co[0] += sx;
> + lar->co[1] += sy;
> + lar->co[2] += sz;
> + }
> + else {
> + lar->vec[0]+=sx;
> + lar->vec[1]+=sy;
> + lar->vec[2]+=sz;
> + //Normalise(lar->vec);
> + }
> +//[2[2]] if (!onSameSide (oro, shi->co,
> shi->vlr->n, shi->vlr->v1->co)) {
> +// sx=-sx;
> +// sy=-sy;
> +// sz=-sz;
> +// shi->co[0] = oro[0] + sx;
> +// shi->co[1] = oro[1] + sy;
> +// shi->co[2] = oro[2]+ sz; // if we went
> thorugh make sure we dont this time.
> +
> +//
> +// }
> + ray_shadow(shi,lar,shad);
> + coolshad[0] += shad[0];
> + coolshad[1] += shad[1];
> + coolshad[2] += shad[2];
> + if (lar->type != LA_SUN) {
> + lar->co[0] = oro[0]; // reset lar->co
> + lar->co[1] = oro[1];
> + lar->co[2] = oro[2];
> + }
> + else {
> + VECCOPY(lar->vec, oro);
> + }
> + }
> + shad[0] = coolshad[0]/lar->softsamples;
> + shad[1] = coolshad[1]/lar->softsamples;
> + shad[2] = coolshad[2]/lar->softsamples;
> +
> +
> + } else {
> + ray_shadow(shi, lar, shad);
> + }
> shadfac[3]+= shad[3];
> ir+= 1.0;
> }
> @@ -2151,9 +2226,72 @@
> }
> else if(lar->mode & LA_SHAD_RAY) {
> // this extra 0.001 prevents boundary cases
> (shadow on smooth sphere)
> - if((shi->vlr->n[0]*lv[0] +
> shi->vlr->n[1]*lv[1] + shi->vlr->n[2]*lv[2]) > -0.001)
>
> - ray_shadow(shi, lar, shadfac);
> - else shadfac[3]= 0.0;
> + if((shi->vlr->n[0]*lv[0] +
> shi->vlr->n[1]*lv[1] + shi->vlr->n[2]*lv[2]) > -0.001)
> {
> + if (lar->mode & LA_SHAD_SOFT) {
> + //printf("SOFT PLEASE!! Soft:%f
> Samp%d",lar->soft,lar->samp);
> +// lar->maxsoft = lar->soft;
> +// lar->softsamples= lar->samp;
> +
> +
> + float oro[3];
> + if (lar->type != LA_SUN) {VECCOPY(oro,
> lar->co);} else {VECCOPY(oro, lar->vec);}
> +
> + float sx,sy,sz;
> + float coolshad[3];
> + int i;
> + memset (coolshad, 0, sizeof(coolshad));
> + for (i=0; i < lar->softsamples; i++) {
> + sx=(float)drand48() * lar->maxsoft;
> + sy=(float)drand48() *lar->maxsoft;
> + sz=(float)drand48() *lar->maxsoft;
> + if (lar->type != LA_SUN) {
> + lar->co[0] += sx;
> + lar->co[1] += sy;
> + lar->co[2] += sz;
> + }
> + else {
> + lar->vec[0]+= sx;
> + lar->vec[1]+= sy;
> + lar->vec[2]+=sz;
> + Normalise(lar->vec);
> + }
> +
> +//[2[2]] if (!onSameSide (oro, shi->co,
> shi->vlr->n, shi->vlr->v1->co)) {
> +// sx=-sx;
> +// sy=-sy;
> +// sz=-sz;
> +// shi->co[0] = oro[0] + sx;
> +// shi->co[1] = oro[1] + sy;
> +// shi->co[2] = oro[2]+ sz; // if we went
> thorugh make sure we dont this time.
> +
> +//
> +// }
> + ray_shadow(shi,lar,shadfac);
> + coolshad[0] += shadfac[0];
> + coolshad[1] += shadfac[1];
> + coolshad[2] += shadfac[2];
> + coolshad[3] += shadfac[3];
> + if (lar->type != LA_SUN) {
> +
> + lar->co[0] = oro[0]; // reset lar->co
> + lar->co[1] = oro[1];
> + lar->co[2] = oro[2];
> + }
> + else {
> + VECCOPY(lar->vec, oro);
> + }
> +
> + }
> + shadfac[0] = coolshad[0]/lar->softsamples;
> + shadfac[1] = coolshad[1]/lar->softsamples;
> + shadfac[2] = coolshad[2]/lar->softsamples;
> + shadfac[3] = coolshad[3]/lar->softsamples;
> +
> + } else {
> + ray_shadow(shi, lar, shadfac);
> + }
> + }
> + else{ shadfac[3]= 0.0;}
> }
>
> /* warning, here it skips the loop */
> @@ -2294,6 +2432,7 @@
>
> }
>
> +
> void shade_input_set_coords(ShadeInput *shi, float u,
> float v, int i1, int i2, int i3)
> {
> VertRen *v1, *v2, *v3;
> @@ -3559,5 +3698,3 @@
>
>
> /* end of render.c */
> -
> -
> Index: render/intern/source/ray.c
> ===================================================================
> RCS file:
> /cvsroot/bf-blender/blender/source/blender/render/intern/source/ray.c,v
> retrieving revision 1.40
> diff -u -r1.40 ray.c
> --- render/intern/source/ray.c 21 Jun 2004 16:07:50
> -0000 1.40
> +++ render/intern/source/ray.c 14 Jul 2004 10:02:48
> -0000
> @@ -1403,6 +1403,7 @@
> refract[0]= index*view[0] + fac*n[0];
> refract[1]= index*view[1] + fac*n[1];
> refract[2]= index*view[2] + fac*n[2];
> +
> }
>
> /* orn = original face normal */
> @@ -1455,6 +1456,59 @@
> #endif
>
> /* the main recursive tracer itself */
> +void
> +getRandomVec (float *vec, float max)
> +{
> +
> +
> +
> +
> + vec[0] = (float) (drand48 () * (max*2))-max;
> + vec[1] = (float) (drand48 () * (max*2))-max;
> + vec[2] = (float) (drand48 () * (max*2))-max;
> +
> +}
> +void
> +rotateVec (float *newvec, float *originvec, float
> *rotatevec, float ax,
> + float ay, float az)
> +{ // we are going to be doing this alot since the
> way i am sampling is based on random angles
> + float othervec[3], tempvec1[3], tempvec2[3]; //
> there has GOT TO BE a better way of doing this!
> +
> + othervec[0] = rotatevec[0] - originvec[0];
> + othervec[1] = rotatevec[1] - originvec[1];
> + othervec[2] = rotatevec[2] - originvec[2]; // make
> sure this is realitivized to teh origin.. then we
> simply translate after rotation around the origin.
> THANK YOU EUCLID!!!
> +
> + tempvec1[0] = othervec[0] * cos (az) + othervec[1]
> * sin (az); // x1 = x * cz + y * sz
> + tempvec1[1] = othervec[1] * cos (ax) - othervec[0]
> * sin (az); // y1 = y * cz - x * sz
> + tempvec1[2] = othervec[2]; // z1 = z
> +
> + tempvec2[0] = tempvec1[0] * cos (ay) + tempvec1[2]
> * sin (ay); // x2 = x1 * cy + z1 * sy
> + tempvec2[1] = tempvec1[2]; // y2 = z1;
> + tempvec2[2] = tempvec1[2] * cos (ay) - tempvec1[0]
> * sin (ay); // z2 = z1 * cy - x1 * sy
> +
> + newvec[0] = tempvec2[0]; // x3 = x2
> + newvec[1] = tempvec2[1] * cos (ax) + tempvec1[2] *
> sin (ax); // y3 = y2 * cx + z1 * sx
> + newvec[2] = tempvec2[2] * cos (ax) - tempvec1[0] *
> sin (ax); // z3 = z2 * cx - x1 * sx
> +
> + newvec[0] += originvec[0];
> + newvec[1] += originvec[1];
> + newvec[2] += originvec[2];
> +
> +
> +
> +}
> +void
> +clipVec (float *vec)
> +{
> + if (vec[0] > 1.0)
> + vec[0] = 1.0;
> + if (vec[1] > 1.0)
> + vec[1] = 1.0;
> + if (vec[2] > 1.0)
> + vec[2] = 1.0;
> +}
> +
> +
> static void traceray(short depth, float *start, float
> *vec, float *col, VlakRen *vlr, int mask)
> {
> ShadeInput shi;
> @@ -1462,7 +1516,7 @@
> Isect isec;
> float f, f1, fr, fg, fb;
> float ref[3];
> -
> + float norref[3];
> VECCOPY(isec.start, start);
> isec.end[0]= start[0]+g_oc.ocsize*vec[0];
> isec.end[1]= start[1]+g_oc.ocsize*vec[1];
> @@ -1477,10 +1531,39 @@
> if(depth>0) {
>
> if(shi.matren->mode & MA_RAYTRANSP &&
> shr.alpha!=1.0) {
> - float f, f1, refract[3], tracol[3];
> + float f, f1, refract[3], tracol[3], nor[3];
> +
>
> - refraction(refract, shi.vn, shi.view,
> shi.matren->ang);
> - traceray(depth-1, shi.co, refract, tracol,
> shi.vlr, shi.mask);
> +
> + if (shi.matren->mode & MA_BLURRY) {
> + int i;
> + float ccol[3], scol[3];
> + memset (scol, 0, sizeof(scol));
> + for (i=0; i < shi.matren->blursamples; i++) {
> +
> + getRandomVec(nor, shi.matren->blurfactor);
> +
> +
> +
> +
> +
> + refraction(refract, shi.vn, shi.view,
> shi.matren->ang);
> + VECADD(refract,refract,nor);
> + Normalise(refract);
> + traceray(depth-1, shi.co, refract, ccol,
> shi.vlr, shi.mask);
> + VECADD(scol,scol,ccol);
> +
> + }
> + scol[0]/=(float)shi.matren->blursamples;
> + scol[1]/=(float)shi.matren->blursamples;
> + scol[2]/=(float)shi.matren->blursamples;
> + VECCOPY(tracol, scol);
> +
> + }
> + else {
> + refraction(refract, shi.vn, shi.view,
> shi.matren->ang);
> + traceray(depth-1, shi.co, refract, tracol,
> shi.vlr, shi.mask);
> + }
>
> f= shr.alpha; f1= 1.0-f;
> shr.diff[0]= f*shr.diff[0] + f1*tracol[0];
> @@ -1488,7 +1571,7 @@
> shr.diff[2]= f*shr.diff[2] + f1*tracol[2];
> shr.alpha= 1.0;
> }
> -
> +
> if(shi.matren->mode & MA_RAYMIRROR) {
> f= shi.matren->ray_mirror;
> if(f!=0.0) f*= fresnel_fac(shi.view, shi.vn,
> shi.matren->fresnel_mir_i, shi.matren->fresnel_mir);
> @@ -1497,11 +1580,35 @@
>
> if(f!=0.0) {
>
> +
> + if (shi.matren->mode & MA_BLURRY) {
> + float nor[3], ccol[3],scol[3];
> + int i;
> + memset(scol,0,sizeof(scol));
> + for (i=0; i < shi.matren->blursamples; i++) {
> + getRandomVec(nor, shi.matren->blurfactor);
> + VECADD(nor,nor,shi.vn);
> + Normalise(nor); // make sure norref is a normal
> +
> + // by modifiying vn we can effectively achieve
> blurry oversampling
> +
> + reflection(ref, nor, shi.view, NULL);
> + traceray(depth-1, shi.co, ref, ccol, shi.vlr,
> shi.mask);
> + VECADD(scol,scol,ccol);
> +
> + }
> + scol[0] /= (float)shi.matren->blursamples;
> + scol[1] /= (float)shi.matren->blursamples;
> + scol[2] /= (float)shi.matren->blursamples;
> + VECCOPY(col,scol);
> + }
> + else {
> reflection(ref, shi.vn, shi.view, NULL);
> traceray(depth-1, shi.co, ref, col, shi.vlr,
> shi.mask);
> + }
>
> f1= 1.0-f;
> -
> +
> /* combine */
> //color_combine(col, f*fr*(1.0-shr.spec[0]), f1,
> col, shr.diff);
> //col[0]+= shr.spec[0];
> @@ -1668,11 +1775,13 @@
> void ray_trace(ShadeInput *shi, ShadeResult *shr)
> {
> VlakRen *vlr;
> - float i, f, f1, fr, fg, fb, vec[3], mircol[3],
> tracol[3];
> - int do_tra, do_mir;
> + float i, f, f1, fr, fg, fb, vec[3], mircol[3],
> tracol[3], plugcol[3];
> + int do_tra, do_mir,do_plugin;
>
> do_tra= ((shi->matren->mode & MA_RAYTRANSP) &&
> shr->alpha!=1.0);
> do_mir= ((shi->matren->mode & MA_RAYMIRROR) &&
> shi->matren->ray_mirror!=0.0);
> +
> +
> vlr= shi->vlr;
>
> coh_test= 0; // reset coherence optimize
> @@ -1680,8 +1789,38 @@
> if(do_tra) {
> float refract[3];
>
> +
> + if (shi->matren->mode & MA_BLURRY) {
> +
> + float nor[3], ccol[3],scol[3];
> + memset(scol,0,sizeof(scol));
> + int i;
> + for (i=0; i < shi->matren->blursamples; i++) {
> + getRandomVec(nor, shi->matren->blurfactor);
> + //VECADD(nor,nor,shi->vn);
> +
> +
> +
> + // by modifiying vn we can effectively achieve
> blurry oversampling
> +
> + refraction(refract, shi->vn, shi->view,
> shi->matren->ang);
> + VECADD(refract, refract, nor);
> + Normalise(refract);
> + traceray(shi->matren->ray_depth_tra, shi->co,
> refract, ccol, shi->vlr, shi->mask);
> + VECADD(scol,scol,ccol);
> +
> +
> + }
> + scol[0] /= (float)shi->matren->blursamples;
> + scol[1] /= (float)shi->matren->blursamples;
> + scol[2] /= (float)shi->matren->blursamples;
> + VECCOPY(tracol,scol);
> + }
> + else {
> refraction(refract, shi->vn, shi->view,
> shi->matren->ang);
> - traceray(shi->matren->ray_depth_tra, shi->co,
> refract, tracol, shi->vlr, shi->mask);
> + traceray(shi->matren->ray_depth_tra, shi->co,
> refract, tracol, shi->vlr, shi->mask);
> + }
> +
>
> f= shr->alpha; f1= 1.0-f;
> shr->diff[0]= f*shr->diff[0] + f1*tracol[0];
> @@ -1689,7 +1828,7 @@
> shr->diff[2]= f*shr->diff[2] + f1*tracol[2];
> shr->alpha= 1.0;
> }
> -
> +
> if(do_mir) {
>
> i= shi->matren->ray_mirror*fresnel_fac(shi->view,
> shi->vn, shi->matren->fresnel_mir_i,
> shi->matren->fresnel_mir);
> @@ -1697,13 +1836,40 @@
> fr= shi->matren->mirr;
> fg= shi->matren->mirg;
> fb= shi->matren->mirb;
> -
> + if (shi->matren->mode & MA_BLURRY) {
> +
> +
> + float nor[3], ccol[3],scol[3];
> + int i;
> + memset(scol,0,sizeof(scol));
> + for (i=0; i < shi->matren->blursamples; i++) {
> + getRandomVec(nor, shi->matren->blurfactor);
> + VECADD(nor,nor,shi->vn);
> + Normalise(nor); // make sure norref is a normal
> +
> + // by modifiying vn we can effectively achieve
> blurry oversampling
> +
> + if(vlr->flag & R_SMOOTH)
> + reflection(vec, nor, shi->view, vlr->n);
> + else
> + reflection(vec, nor , shi->view, NULL);
> +
> + traceray(shi->matren->ray_depth, shi->co, vec,
> ccol, shi->vlr, shi->mask);
> + VECADD(scol,scol,ccol);
> +
> + }
> + scol[0] /= (float)shi->matren->blursamples;
> + scol[1] /= (float)shi->matren->blursamples;
> + scol[2] /= (float)shi->matren->blursamples;
> + VECCOPY(mircol,scol);
> +
> + } else {
> if(vlr->flag & R_SMOOTH)
> reflection(vec, shi->vn, shi->view, vlr->n);
> else
> reflection(vec, shi->vn, shi->view, NULL);
> -
> traceray(shi->matren->ray_depth, shi->co, vec,
> mircol, shi->vlr, shi->mask);
> + }
>
> f= i*fr*(1.0-shr->spec[0]); f1= 1.0-i;
> shr->diff[0]= f*mircol[0] + f1*shr->diff[0];
> @@ -2143,4 +2309,3 @@
>
>
> }
> -
> Index: makesdna/DNA_lamp_types.h
> ===================================================================
> RCS file:
> /cvsroot/bf-blender/blender/source/blender/makesdna/DNA_lamp_types.h,v
> retrieving revision 1.10
> diff -u -r1.10 DNA_lamp_types.h
> --- makesdna/DNA_lamp_types.h 29 Dec 2003 16:52:49
> -0000 1.10
> +++ makesdna/DNA_lamp_types.h 14 Jul 2004 10:02:48
> -0000
> @@ -55,7 +55,8 @@
> short bufsize, samp;
> float clipsta, clipend, shadspotsize;
> float bias, soft;
> -
> + float maxsoft;
> + short softsamples, schwartz;
> short ray_samp, ray_sampy, ray_sampz, ray_samp_type;
> short area_shape, pad;
> float area_size, area_sizey, area_sizez;
> @@ -93,6 +94,7 @@
> #define LA_NO_DIFF 2048
> #define LA_NO_SPEC 4096
> #define LA_SHAD_RAY 8192
> +#define LA_SHAD_SOFT 16384
>
> /* area shape */
> #define LA_AREA_SQUARE 0
> @@ -111,4 +113,3 @@
>
>
> #endif /* DNA_LAMP_TYPES_H */
> -
> Index: makesdna/DNA_material_types.h
> ===================================================================
> RCS file:
> /cvsroot/bf-blender/blender/source/blender/makesdna/DNA_material_types.h,v
> retrieving revision 1.17
> diff -u -r1.17 DNA_material_types.h
> --- makesdna/DNA_material_types.h 30 Jun 2004 18:54:08
> -0000 1.17
> +++ makesdna/DNA_material_types.h 14 Jul 2004 10:02:48
> -0000
> @@ -54,7 +54,7 @@
> float specr, specg, specb;
> float mirr, mirg, mirb;
> float ambr, ambb, ambg;
> -
> + float blurfactor; int blursamples;
> float amb, emit, ang, spectra, ray_mirror;
> float alpha, ref, spec, zoffs, add;
> float translucency;
> @@ -112,6 +112,7 @@
> #define MA_YUV 2
> #define MA_HSV 3
>
> +
> /* mode (is int) */
> #define MA_TRACEBLE 1
> #define MA_SHADOW 2
> @@ -140,7 +141,7 @@
> #define MA_SHADOW_TRA 0x80000
> #define MA_RAMP_COL 0x100000
> #define MA_RAMP_SPEC 0x200000
> -
> +#define MA_BLURRY 0x400000
> /* diff_shader */
> #define MA_DIFF_LAMBERT 0
> #define MA_DIFF_ORENNAYAR 1
> @@ -208,4 +209,3 @@
> #define MA_DARK 1
>
> #endif
> -
>
>
>
>
> __________________________________
> Do you Yahoo!?
> Take Yahoo! Mail with you! Get it on your mobile phone.
> http://mobile.yahoo.com/maildemo
> _______________________________________________
> Bf-committers mailing list
> Bf-committers@blender.org
> http://www.blender.org/mailman/listinfo/bf-committers
>