diff options
Diffstat (limited to 'source/blender/render/intern/source/pixelshading.c')
-rw-r--r-- | source/blender/render/intern/source/pixelshading.c | 156 |
1 files changed, 78 insertions, 78 deletions
diff --git a/source/blender/render/intern/source/pixelshading.c b/source/blender/render/intern/source/pixelshading.c index f1323af2826..7f202629ce4 100644 --- a/source/blender/render/intern/source/pixelshading.c +++ b/source/blender/render/intern/source/pixelshading.c @@ -71,20 +71,20 @@ static void render_lighting_halo(HaloRen *har, float col_r[3]) LampRen *lar; float i, inp, inpr, rco[3], dco[3], lv[3], lampdist, ld, t, *vn; float ir, ig, ib, shadfac, soft, lacol[3]; - + ir= ig= ib= 0.0; - + copy_v3_v3(rco, har->co); dco[0]=dco[1]=dco[2]= 1.0f/har->rad; - + vn= har->no; - + for (go=R.lights.first; go; go= go->next) { lar= go->lampren; - + /* test for lamplayer */ if (lar->mode & LA_LAYER) if ((lar->lay & har->lay)==0) continue; - + /* lampdist cacluation */ if (lar->type==LA_SUN || lar->type==LA_HEMI) { copy_v3_v3(lv, lar->vec); @@ -98,63 +98,63 @@ static void render_lighting_halo(HaloRen *har, float col_r[3]) lv[0]/= ld; lv[1]/= ld; lv[2]/= ld; - + /* ld is re-used further on (texco's) */ - + if (lar->mode & LA_QUAD) { t= 1.0; if (lar->ld1>0.0f) t= lar->dist/(lar->dist+lar->ld1*ld); if (lar->ld2>0.0f) t*= lar->distkw/(lar->distkw+lar->ld2*ld*ld); - + lampdist= t; } else { lampdist= (lar->dist/(lar->dist+ld)); } - + if (lar->mode & LA_SPHERE) { t= lar->dist - ld; if (t<0.0f) continue; - + t/= lar->dist; lampdist*= (t); } - + } - + lacol[0]= lar->r; lacol[1]= lar->g; lacol[2]= lar->b; - + if (lar->mode & LA_TEXTURE) { ShadeInput shi; - + /* Warning, This is not that nice, and possibly a bit slow, * however some variables were not initialized properly in, unless using shade_input_initialize(...), * we need to do a memset */ - memset(&shi, 0, sizeof(ShadeInput)); + memset(&shi, 0, sizeof(ShadeInput)); /* end warning! - Campbell */ - + copy_v3_v3(shi.co, rco); shi.osatex= 0; do_lamp_tex(lar, lv, &shi, lacol, LA_TEXTURE); } - + if (lar->type==LA_SPOT) { - + if (lar->mode & LA_SQUARE) { if (lv[0]*lar->vec[0]+lv[1]*lar->vec[1]+lv[2]*lar->vec[2]>0.0f) { float x, lvrot[3]; - + /* rotate view to lampspace */ copy_v3_v3(lvrot, lv); mul_m3_v3(lar->imat, lvrot); - + x = max_ff(fabsf(lvrot[0]/lvrot[2]), fabsf(lvrot[1]/lvrot[2])); /* 1.0/(sqrt(1+x*x)) is equivalent to cos(atan(x)) */ - + inpr = 1.0f / (sqrtf(1.0f + x * x)); } else inpr= 0.0; @@ -162,7 +162,7 @@ static void render_lighting_halo(HaloRen *har, float col_r[3]) else { inpr= lv[0]*lar->vec[0]+lv[1]*lar->vec[1]+lv[2]*lar->vec[2]; } - + t= lar->spotsi; if (inpr<t) continue; else { @@ -187,7 +187,7 @@ static void render_lighting_halo(HaloRen *har, float col_r[3]) ir -= shadfac; ig -= shadfac; ib -= shadfac; - + continue; } } @@ -196,24 +196,24 @@ static void render_lighting_halo(HaloRen *har, float col_r[3]) lampdist*=inpr; } if (lar->mode & LA_ONLYSHADOW) continue; - + } - + /* dot product and reflectivity*/ - + inp = 1.0f - fabsf(dot_v3v3(vn, lv)); - + /* inp= cos(0.5*M_PI-acos(inp)); */ - + i= inp; - + if (lar->type==LA_HEMI) { i= 0.5f*i+0.5f; } if (i>0.0f) { i*= lampdist; } - + /* shadow */ if (i> -0.41f) { /* heuristic valua! */ if (lar->shb) { @@ -222,14 +222,14 @@ static void render_lighting_halo(HaloRen *har, float col_r[3]) i*= shadfac; } } - + if (i>0.0f) { ir+= i*lacol[0]; ig+= i*lacol[1]; ib+= i*lacol[2]; } } - + if (ir<0.0f) ir= 0.0f; if (ig<0.0f) ig= 0.0f; if (ib<0.0f) ib= 0.0f; @@ -237,7 +237,7 @@ static void render_lighting_halo(HaloRen *har, float col_r[3]) col_r[0]*= ir; col_r[1]*= ig; col_r[2]*= ib; - + } @@ -287,14 +287,14 @@ int shadeHaloFloat(HaloRen *har, float col[4], int zz, } } else alpha= har->alfa; - + if (alpha==0.0f) return 0; /* soften the halo if it intersects geometry */ if (har->mat && har->mat->mode & MA_HALO_SOFT) { float segment_length, halo_depth, distance_from_z /* , visible_depth */ /* UNUSED */, soften; - + /* calculate halo depth */ segment_length= har->hasize*sasqrt(1.0f - dist/(har->rad*har->rad)); halo_depth= 2.0f*segment_length; @@ -333,16 +333,16 @@ int shadeHaloFloat(HaloRen *har, float col[4], int zz, const float *rc; float fac; int ofs; - + /* per ring an antialised circle */ ofs= har->seed; - + for (a= har->ringc; a>0; a--, ofs+=2) { - + rc= hashvectf + (ofs % 768); - + fac = fabsf(rc[1] * (har->rad * fabsf(rc[0]) - radist)); - + if (fac< 1.0f) { ringf+= (1.0f-fac); } @@ -379,25 +379,25 @@ int shadeHaloFloat(HaloRen *har, float col[4], int zz, dist= (1.0f-dist); else dist= 0.0f; - + if (har->linec) { const float *rc; float fac; int ofs; - + /* per starpoint an antialiased line */ ofs= har->seed; - + for (a= har->linec; a>0; a--, ofs+=3) { - + rc= hashvectf + (ofs % 768); - + fac = fabsf((xn) * rc[0] + (yn) * rc[1]); - + if (fac< 1.0f ) linef+= (1.0f-fac); } - + linef*= dist; } @@ -406,16 +406,16 @@ int shadeHaloFloat(HaloRen *har, float col[4], int zz, /* rotation */ angle = atan2f(yn, xn); angle *= (1.0f+0.25f*har->starpoints); - + co= cosf(angle); si= sinf(angle); - + angle= (co*xn+si*yn)*(co*yn-si*xn); - + ster = fabsf(angle); if (ster>1.0f) { ster= (har->rad)/(ster); - + if (ster<1.0f) dist*= sqrtf(ster); } } @@ -423,25 +423,25 @@ int shadeHaloFloat(HaloRen *har, float col[4], int zz, /* disputable optimize... (ton) */ if (dist<=0.00001f) return 0; - + dist*= alpha; ringf*= dist; linef*= alpha; - + /* The color is either the rgb spec-ed by the user, or extracted from */ /* the texture */ if (har->tex) { - col[0]= har->r; - col[1]= har->g; + col[0]= har->r; + col[1]= har->g; col[2]= har->b; col[3]= dist; - + do_halo_tex(har, xn, yn, col); - + col[0]*= col[3]; col[1]*= col[3]; col[2]*= col[3]; - + } else { col[0]= dist*har->r; @@ -460,11 +460,11 @@ int shadeHaloFloat(HaloRen *har, float col[4], int zz, /* Next, we do the line and ring factor modifications. */ if (linef!=0.0f) { Material *ma= har->mat; - + col[0]+= linef * ma->specr; col[1]+= linef * ma->specg; col[2]+= linef * ma->specb; - + if (har->type & HA_XALPHA) col[3]+= linef*linef; else col[3]+= linef; } @@ -474,12 +474,12 @@ int shadeHaloFloat(HaloRen *har, float col[4], int zz, col[0]+= ringf * ma->mirr; col[1]+= ringf * ma->mirg; col[2]+= ringf * ma->mirb; - + if (har->type & HA_XALPHA) col[3]+= ringf*ringf; else col[3]+= ringf; } } - + /* alpha requires clip, gives black dots */ if (col[3] > 1.0f) col[3]= 1.0f; @@ -494,17 +494,17 @@ void shadeSkyView(float col_r[3], const float rco[3], const float view[3], const { float zen[3], hor[3], blend, blendm; int skyflag; - + /* flag indicating if we render the top hemisphere */ skyflag = WO_ZENUP; - + /* Some view vector stuff. */ if (R.wrld.skytype & WO_SKYREAL) { - + blend = dot_v3v3(view, R.grvec); - + if (blend<0.0f) skyflag= 0; - + blend = fabsf(blend); } else if (R.wrld.skytype & WO_SKYPAPER) { @@ -532,10 +532,10 @@ void shadeSkyView(float col_r[3], const float rco[3], const float view[3], const } do_sky_tex(rco, view, lo, dxyview, hor, zen, &blend, skyflag, thread); } - + if (blend>1.0f) blend= 1.0f; blendm= 1.0f-blend; - + /* No clipping, no conversion! */ if (R.wrld.skytype & WO_SKYBLEND) { col_r[0] = (blendm*hor[0] + blend*zen[0]); @@ -557,13 +557,13 @@ void shadeSunView(float col_r[3], const float view[3]) LampRen *lar; float sview[3]; bool do_init = true; - + for (go=R.lights.first; go; go= go->next) { lar= go->lampren; if (lar->type==LA_SUN && lar->sunsky && (lar->sunsky->effect_type & LA_SUN_EFFECT_SKY)) { float sun_collector[3]; float colorxyz[3]; - + if (do_init) { normalize_v3_v3(sview, view); @@ -573,11 +573,11 @@ void shadeSunView(float col_r[3], const float view[3]) normalize_v3(sview); do_init = false; } - + GetSkyXYZRadiancef(lar->sunsky, sview, colorxyz); xyz_to_rgb(colorxyz[0], colorxyz[1], colorxyz[2], &sun_collector[0], &sun_collector[1], &sun_collector[2], lar->sunsky->sky_colorspace); - + ramp_blend(lar->sunsky->skyblendtype, col_r, lar->sunsky->skyblendfac, sun_collector); } } @@ -613,25 +613,25 @@ void shadeSkyPixel(float collector[4], float fx, float fy, short thread) view[0]= -1.0f + 2.0f*(fx/(float)R.winx); view[1]= -1.0f + 2.0f*(fy/(float)R.winy); view[2]= 0.0; - + dxyview[0]= 1.0f/(float)R.winx; dxyview[1]= 1.0f/(float)R.winy; } else { calc_view_vector(view, fx, fy); fac= normalize_v3(view); - + if (R.wrld.skytype & WO_SKYTEX) { dxyview[0]= -R.viewdx/fac; dxyview[1]= -R.viewdy/fac; } } - + /* get sky color in the collector */ shadeSkyView(collector, NULL, view, dxyview, thread); collector[3] = 0.0f; } - + calc_view_vector(view, fx, fy); shadeSunView(collector, view); } |